IODA
obsspace.F90
Go to the documentation of this file.
1 !
2 ! (C) Copyright 2019 UCAR
3 !
4 ! This software is licensed under the terms of the Apache Licence Version 2.0
5 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 !
7 !> Test interface for C++ ObsSpace called from Fortran
8 
9 #include <fckit/fctest.h>
10 
11 !> \cond
12 testsuite(obsspace_fortran)
13 
14 testsuite_init
15  use fckit_module
16  use liboops_mod
17 
18  call liboops_initialise()
19  call fckit_main%init()
20 end_testsuite_init
21 
22 testsuite_finalize
23  use fckit_module
24  use liboops_mod
25 
26  call fckit_main%final()
27  call liboops_finalise()
28 end_testsuite_finalize
29 
30 !> Test obsspace_construct
31 test(test_obsspace_construct)
32  use fckit_configuration_module
33  use fckit_pathname_module, only : fckit_pathname
34  use fckit_module
35  use datetime_mod
36  use obsspace_mod
37  use oops_variables_mod
38  use, intrinsic :: iso_c_binding
39  implicit none
40 
41  character(len=:), allocatable :: filename
42  type(fckit_configuration) :: config
43  type(fckit_configuration), allocatable :: obsconfigs(:)
44  type(fckit_configuration) :: obsconfig
45 
46  character(kind=c_char,len=:), allocatable :: winbgnstr
47  character(kind=c_char,len=:), allocatable :: winendstr
48  type(datetime) :: winbgn, winend
49 
50  type(c_ptr), allocatable, dimension(:) :: obsspace
51  integer :: nlocs, nlocs_ref
52  integer :: nvars, nvars_ref
53  integer :: iobstype
54  character(len=100) :: obsname
55  character(kind=c_char,len=:), allocatable :: obsname_ref
56  type(oops_variables) :: vars
57 
58  !> initialize winbgn, winend, get config
59  call fckit_resource("--config", "", filename)
60  config = fckit_yamlconfiguration(fckit_pathname(filename))
61  call config%get_or_die("window begin", winbgnstr)
62  call config%get_or_die("window end", winendstr)
63  call datetime_create(winbgnstr, winbgn)
64  call datetime_create(winendstr, winend)
65  !> allocate all ObsSpaces
66  call config%get_or_die("observations", obsconfigs)
67  allocate(obsspace(size(obsconfigs)))
68  do iobstype = 1, size(obsconfigs)
69  call obsconfigs(iobstype)%get_or_die("obs space", obsconfig)
70  !> construct obsspace
71  obsspace(iobstype) = obsspace_construct(obsconfig, winbgn, winend)
72  call obsspace_obsname(obsspace(iobstype), obsname)
73  !> test if obsname is the same as reference
74  call obsconfig%get_or_die("name", obsname_ref)
75  check_equal(obsname, obsname_ref)
76  !> test if nlocs and nvars are the same as reference
77  nlocs = obsspace_get_nlocs(obsspace(iobstype))
78  nvars = obsspace_get_nvars(obsspace(iobstype))
79  call obsconfig%get_or_die("test data.nlocs", nlocs_ref)
80  call obsconfig%get_or_die("test data.nvars", nvars_ref)
81  check_equal(nlocs, nlocs_ref)
82  check_equal(nvars, nvars_ref)
83  !> test if obsvariables nvars is the same
84  vars = obsspace_obsvariables(obsspace(iobstype))
85  call obsconfig%get_or_die("test data.nvars obsvars", nvars_ref)
86  check_equal(vars%nvars(), nvars_ref)
87  enddo
88  !> destruct all obsspaces
89  do iobstype = 1, size(obsspace)
90  call obsspace_destruct(obsspace(iobstype))
91  enddo
92  deallocate(obsspace, obsname_ref)
93 
94 end_test
95 
96 end_testsuite
97 !> \endcond
obsspace_mod::obsspace_obsname
subroutine, public obsspace_obsname(obss, obsname)
Get obsname from ObsSpace.
Definition: obsspace_mod.F90:85
obsspace_mod::obsspace_get_nvars
integer function, public obsspace_get_nvars(c_obss)
Return the number of observational variables.
Definition: obsspace_mod.F90:152
obsspace_mod::obsspace_obsvariables
type(oops_variables) function, public obsspace_obsvariables(obss)
Get obsvariables from ObsSpace.
Definition: obsspace_mod.F90:108
obsspace_mod::obsspace_destruct
subroutine, public obsspace_destruct(c_obss)
Definition: obsspace_mod.F90:73
obsspace_mod
Fortran interface to ObsSpace.
Definition: obsspace_mod.F90:9
obsspace_mod::obsspace_construct
type(c_ptr) function, public obsspace_construct(c_conf, tbegin, tend)
Definition: obsspace_mod.F90:58
obsspace_mod::obsspace_get_nlocs
integer function, public obsspace_get_nlocs(c_obss)
Return the number of observational locations in this ObsSpace object.
Definition: obsspace_mod.F90:130