FV3 Bundle
ObsSpace.Example.interface.F90
Go to the documentation of this file.
1 ! (C) Copyright 2018 UCAR
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 
6 !> Fortran example module for for functions on the interface between C++ and Fortran
7 ! to handle observation space
8 
9 ! TODO: replace example with your_observation_space_name through the file
10 
12 
13 use iso_c_binding
14 use string_f_c_mod
15 use config_mod
16 use datetime_mod
17 use duration_mod
18 use ioda_locs_mod
20 use ioda_obs_vectors
22 use fckit_log_module, only : fckit_log
23 use kinds
24 
25 implicit none
26 private
27 
29 
30 ! ------------------------------------------------------------------------------
31 integer, parameter :: max_string=800
32 ! ------------------------------------------------------------------------------
33 
34 #define LISTED_TYPE ioda_obs_example
35 
36 !> Linked list interface - defines registry_t type
37 #include "../../linkedList_i.f"
38 
39 !> Global registry
40 type(registry_t) :: ioda_obs_example_registry
41 
42 ! ------------------------------------------------------------------------------
43 contains
44 ! ------------------------------------------------------------------------------
45 !> Linked list implementation
46 #include "../../linkedList_c.f"
47 
48 ! ------------------------------------------------------------------------------
49 
50 subroutine ioda_obsdb_example_setup_c(c_key_self, c_conf) bind(c,name='ioda_obsdb_example_setup_f90')
51 implicit none
52 integer(c_int), intent(inout) :: c_key_self
53 type(c_ptr), intent(in) :: c_conf !< configuration
54 
55 type(ioda_obs_example), pointer :: self
56 character(len=max_string) :: fin
57 character(len=max_string) :: MyObsType
58 character(len=255) :: record
59 
60 if (config_element_exists(c_conf,"ObsData.ObsDataIn")) then
61  fin = config_get_string(c_conf,max_string,"ObsData.ObsDataIn.obsfile")
62 else
63  fin = ""
64 endif
65 call fckit_log%info(record)
66 
67 call ioda_obs_example_registry%init()
68 call ioda_obs_example_registry%add(c_key_self)
69 call ioda_obs_example_registry%get(c_key_self, self)
70 if (trim(fin) /= "") then
71 ! TODO: replace with the call to your Fortran routine for reading observations
72 ! (defined in ioda_obs_<your_obs_space_name>_mod.F90)
73  call ioda_obs_example_read(fin, self)
74 endif
75 
76 end subroutine ioda_obsdb_example_setup_c
77 
78 ! ------------------------------------------------------------------------------
79 
80 subroutine ioda_obsdb_example_getlocations_c(c_key_self, c_t1, c_t2, c_key_locs) bind(c,name='ioda_obsdb_example_getlocations_f90')
81 implicit none
82 integer(c_int), intent(in) :: c_key_self
83 type(c_ptr), intent(in) :: c_t1, c_t2
84 integer(c_int), intent(inout) :: c_key_locs
85 
86 type(ioda_obs_example), pointer :: self
87 type(datetime) :: t1, t2
88 type(ioda_locs), pointer :: locs
89 
90 call ioda_obs_example_registry%get(c_key_self, self)
91 call c_f_datetime(c_t1, t1)
92 call c_f_datetime(c_t2, t2)
93 
94 call ioda_locs_registry%init()
95 call ioda_locs_registry%add(c_key_locs)
96 call ioda_locs_registry%get(c_key_locs,locs)
97 
98 ! TODO: replace with the call to your Fortran routine for getting locations of obs
99 ! (defined in ioda_obs_<your_obs_space_name>_mod.F90)
100 call ioda_obs_example_getlocs(self, locs)
101 
103 
104 ! ------------------------------------------------------------------------------
105 
106 subroutine ioda_obsdb_example_generate_c(c_key_self, c_conf, c_t1, c_t2) bind(c,name='ioda_obsdb_example_generate_f90')
107 implicit none
108 integer(c_int), intent(inout) :: c_key_self
109 type(c_ptr), intent(in) :: c_conf !< configuration
110 type(c_ptr), intent(in) :: c_t1, c_t2
111 
112 type(ioda_obs_example), pointer :: self
113 type(datetime) :: t1, t2
114 integer :: nobs
115 
116 call ioda_obs_example_registry%get(c_key_self, self)
117 call c_f_datetime(c_t1, t1)
118 call c_f_datetime(c_t2, t2)
119 
120 nobs = config_get_int(c_conf, "nobs")
121 
122 ! TODO: replace with the call to your Fortran routine for generating random observations
123 ! (defined in ioda_obs_<your_obs_space_name>_mod.F90)
124 call ioda_obs_example_generate(self, nobs)
125 
126 end subroutine ioda_obsdb_example_generate_c
127 
128 ! ------------------------------------------------------------------------------
129 
130 subroutine ioda_obsdb_example_nobs_c(c_key_self, kobs) bind(c,name='ioda_obsdb_example_nobs_f90')
131 implicit none
132 integer(c_int), intent(in) :: c_key_self
133 integer(c_int), intent(inout) :: kobs
134 type(ioda_obs_example), pointer :: self
135 
136 call ioda_obs_example_registry%get(c_key_self, self)
137 
138 !TODO: call your function to inquire nobs from obsspace
139 
140 end subroutine ioda_obsdb_example_nobs_c
141 
142 ! ------------------------------------------------------------------------------
143 
144 subroutine ioda_obsdb_example_delete_c(c_key_self) bind(c,name='ioda_obsdb_example_delete_f90')
145 implicit none
146 integer(c_int), intent(inout) :: c_key_self
147 type(ioda_obs_example), pointer :: self
148 
149 call ioda_obs_example_registry%get(c_key_self, self)
150 
151 ! TODO: replace with the call to your Fortran routine to destruct the obsspace
152 ! (defined in ioda_obs_<your_obs_space_name>_mod.F90)
153 call ioda_obs_example_delete(self)
154 
155 call ioda_obs_example_registry%remove(c_key_self)
156 
157 end subroutine ioda_obsdb_example_delete_c
158 
159 ! ------------------------------------------------------------------------------
160 
161 end module ioda_obs_example_mod_c
subroutine, public ioda_obs_example_read(filename, self)
type(registry_t), public ioda_obs_example_registry
Linked list interface - defines registry_t type.
integer, parameter max_string
Fortran example module for for functions on the interface between C++ and Fortran.
type(registry_t), public ioda_locs_registry
Linked list interface - defines registry_t type.
subroutine ioda_obsdb_example_setup_c(c_key_self, c_conf)
Linked list implementation.
subroutine, public ioda_obs_example_generate(self, nobs)
Fortran example module for observation space.
subroutine, public ioda_obs_example_getlocs(self, locs)
subroutine, public ioda_obs_example_delete(self)
subroutine ioda_obsdb_example_generate_c(c_key_self, c_conf, c_t1, c_t2)
Fortran module handling observation locations.
subroutine ioda_obsdb_example_nobs_c(c_key_self, kobs)
subroutine ioda_obsdb_example_delete_c(c_key_self)
subroutine ioda_obsdb_example_getlocations_c(c_key_self, c_t1, c_t2, c_key_locs)