OOPS
qg_obsdb_interface.F90
Go to the documentation of this file.
1 ! (C) Copyright 2009-2016 ECMWF.
2 ! (C) Copyright 2017-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 ! In applying this licence, ECMWF does not waive the privileges and immunities
7 ! granted to it by virtue of its status as an intergovernmental organisation nor
8 ! does it submit to any jurisdiction.
9 
11 
12 use atlas_module
13 use fckit_configuration_module, only: fckit_configuration
14 use datetime_mod
15 use duration_mod
16 use fckit_log_module, only: fckit_log
17 use iso_c_binding
18 use string_f_c_mod
19 use qg_locs_mod
20 use qg_obsdb_mod
21 use qg_obsvec_mod
22 use kinds
23 
24 private
25 ! ------------------------------------------------------------------------------
26 contains
27 ! ------------------------------------------------------------------------------
28 !> Setup observation data
29 subroutine qg_obsdb_setup_c(c_key_self,c_conf,c_winbgn,c_winend) bind(c,name='qg_obsdb_setup_f90')
30 
31 implicit none
32 
33 ! Passed variables
34 integer(c_int),intent(inout) :: c_key_self !< Observation data
35 type(c_ptr),value,intent(in) :: c_conf !< Configuration
36 type(c_ptr),value,intent(in) :: c_winbgn !< Start of window
37 type(c_ptr),value,intent(in) :: c_winend !< End of window
38 
39 ! Local variables
40 type(fckit_configuration) :: f_conf
41 type(qg_obsdb),pointer :: self
42 type(datetime) :: winbgn
43 type(datetime) :: winend
44 
45 ! Interface
46 f_conf = fckit_configuration(c_conf)
47 call qg_obsdb_registry%init()
48 call qg_obsdb_registry%add(c_key_self)
49 call qg_obsdb_registry%get(c_key_self,self)
50 call c_f_datetime(c_winbgn,winbgn)
51 call c_f_datetime(c_winend,winend)
52 
53 ! Call Fortran
54 call qg_obsdb_setup(self,f_conf,winbgn,winend)
55 
56 end subroutine qg_obsdb_setup_c
57 ! ------------------------------------------------------------------------------
58 !> Delete observation data
59 subroutine qg_obsdb_delete_c(c_key_self) bind(c,name='qg_obsdb_delete_f90')
60 
61 implicit none
62 
63 ! Passed variables
64 integer(c_int),intent(inout) :: c_key_self !< Observation data
65 
66 ! Local variables
67 type(qg_obsdb),pointer :: self
68 
69 ! Interface
70 call qg_obsdb_registry%get(c_key_self,self)
71 
72 ! Call Fortran
73 call qg_obsdb_delete(self)
74 
75 ! Clear interface
76 call qg_obsdb_registry%remove(c_key_self)
77 
78 end subroutine qg_obsdb_delete_c
79 ! ------------------------------------------------------------------------------
80 !> Get observation data
81 subroutine qg_obsdb_get_c(c_key_self,lgrp,c_grp,lcol,c_col,c_key_ovec) bind(c,name='qg_obsdb_get_f90')
82 
83 implicit none
84 
85 ! Passed variables
86 integer(c_int),intent(in) :: c_key_self !< Observation data
87 integer(c_int),intent(in) :: lgrp !< Group size
88 character(kind=c_char,len=1),intent(in) :: c_grp(lgrp+1) !< Group name
89 integer(c_int),intent(in) :: lcol !< Column size
90 character(kind=c_char,len=1),intent(in) :: c_col(lcol+1) !< Column name
91 integer(c_int),intent(in) :: c_key_ovec !< Observation vector
92 
93 ! Local variables
94 type(qg_obsdb),pointer :: self
95 type(qg_obsvec),pointer :: ovec
96 character(len=lgrp) :: grp
97 character(len=lcol) :: col
98 
99 ! Interface
100 call qg_obsdb_registry%get(c_key_self,self)
101 call c_f_string(c_grp,grp)
102 call c_f_string(c_col,col)
103 call qg_obsvec_registry%get(c_key_ovec,ovec)
104 
105 ! Call Fortran
106 call qg_obsdb_get(self,trim(grp),trim(col),ovec,.false.)
107 
108 end subroutine qg_obsdb_get_c
109 ! ------------------------------------------------------------------------------
110 !> Get observations data for a local subset
111 subroutine qg_obsdb_get_local_c(c_key_self,lgrp,c_grp,lcol,c_col,c_idxsize,c_idx,&
112  c_key_ovec) bind(c,name='qg_obsdb_get_local_f90')
113 implicit none
114 
115 ! Passed variables
116 integer(c_int),intent(in) :: c_key_self !< Observation data
117 integer(c_int),intent(in) :: lgrp !< Group size
118 character(kind=c_char,len=1),intent(in) :: c_grp(lgrp+1) !< Group name
119 integer(c_int),intent(in) :: lcol !< Column size
120 character(kind=c_char,len=1),intent(in) :: c_col(lcol+1) !< Column name
121 integer(c_int),intent(in) :: c_key_ovec !< Observation vector
122 integer(c_int),intent(in) :: c_idxsize !< size of local obs index vector
123 integer(c_int),intent(in) :: c_idx(c_idxsize) !< Index vector for local obs
124 
125 ! Local variables
126 type(qg_obsdb),pointer :: self
127 type(qg_obsvec),pointer :: ovec
128 character(len=lgrp) :: grp
129 character(len=lcol) :: col
130 
131 ! Interface
132 call qg_obsdb_registry%get(c_key_self,self)
133 call c_f_string(c_grp,grp)
134 call c_f_string(c_col,col)
135 call qg_obsvec_registry%get(c_key_ovec,ovec)
136 
137 ! Call Fortran
138 call qg_obsdb_get(self,trim(grp),trim(col),ovec,.true.,c_idx)
139 
140 end subroutine qg_obsdb_get_local_c
141 ! ------------------------------------------------------------------------------
142 !> Put observation data
143 subroutine qg_obsdb_put_c(c_key_self,lgrp,c_grp,lcol,c_col,c_key_ovec) bind(c,name='qg_obsdb_put_f90')
144 
145 implicit none
146 
147 ! Passed variables
148 integer(c_int),intent(in) :: c_key_self !< Observation data
149 integer(c_int),intent(in) :: lgrp !< Group size
150 character(kind=c_char,len=1),intent(in) :: c_grp(lgrp+1) !< Group name
151 integer(c_int),intent(in) :: lcol !< Column size
152 character(kind=c_char,len=1),intent(in) :: c_col(lcol+1) !< Column name
153 integer(c_int),intent(in) :: c_key_ovec !< Observation vector
154 
155 ! Local variables
156 type(qg_obsdb),pointer :: self
157 type(qg_obsvec),pointer :: ovec
158 character(len=lgrp) :: grp
159 character(len=lcol) :: col
160 
161 ! Interface
162 call qg_obsdb_registry%get(c_key_self,self)
163 call c_f_string(c_grp,grp)
164 call c_f_string(c_col,col)
165 call qg_obsvec_registry%get(c_key_ovec,ovec)
166 
167 ! Call Fortran
168 call qg_obsdb_put(self,trim(grp),trim(col),ovec)
169 
170 end subroutine qg_obsdb_put_c
171 ! ------------------------------------------------------------------------------
172 !> Test observation data existence
173 subroutine qg_obsdb_has_c(c_key_self,lgrp,c_grp,lcol,c_col,c_has) bind(c,name='qg_obsdb_has_f90')
174 
175 implicit none
176 
177 ! Passed variables
178 integer(c_int),intent(in) :: c_key_self !< Observation data
179 integer(c_int),intent(in) :: lgrp !< Group size
180 character(kind=c_char,len=1),intent(in) :: c_grp(lgrp+1) !< Group name
181 integer(c_int),intent(in) :: lcol !< Column size
182 character(kind=c_char,len=1),intent(in) :: c_col(lcol+1) !< Column name
183 integer(c_int),intent(out) :: c_has !< Test flag
184 
185 ! Local variables
186 type(qg_obsdb),pointer :: self
187 character(len=lgrp) :: grp
188 character(len=lcol) :: col
189 
190 ! Interface
191 call qg_obsdb_registry%get(c_key_self,self)
192 call c_f_string(c_grp,grp)
193 call c_f_string(c_col,col)
194 
195 ! Call Fortran
196 call qg_obsdb_has(self,trim(grp),trim(col),c_has)
197 
198 end subroutine qg_obsdb_has_c
199 ! ------------------------------------------------------------------------------
200 !> Get locations from observation data
201 subroutine qg_obsdb_locations_c(c_key_self,lgrp,c_grp,c_t1,c_t2,c_fields,c_times) bind(c,name='qg_obsdb_locations_f90')
202 
203 implicit none
204 
205 ! Passed variables
206 integer(c_int),intent(in) :: c_key_self !< Observation data
207 integer(c_int),intent(in) :: lgrp !< Group size
208 character(kind=c_char,len=1),intent(in) :: c_grp(lgrp+1) !< Group name
209 type(c_ptr),value,intent(in) :: c_t1 !< Time 1
210 type(c_ptr),value,intent(in) :: c_t2 !< Time 2
211 type(c_ptr), intent(in), value :: c_fields !< Locations fieldset
212 type(c_ptr), intent(in), value :: c_times !< times
213 
214 ! Local variables
215 type(qg_obsdb),pointer :: self
216 character(len=lgrp) :: grp
217 type(datetime) :: t1,t2
218 type(atlas_fieldset) :: fields
219 
220 ! Interface
221 call qg_obsdb_registry%get(c_key_self,self)
222 call c_f_string(c_grp,grp)
223 call c_f_datetime(c_t1,t1)
224 call c_f_datetime(c_t2,t2)
225 fields = atlas_fieldset(c_fields)
226 
227 ! Call Fortran
228 call qg_obsdb_locations(self,grp,t1,t2,fields,c_times)
229 
230 call fields%final()
231 
232 end subroutine qg_obsdb_locations_c
233 ! ------------------------------------------------------------------------------
234 !> Generate observation data
235 subroutine qg_obsdb_generate_c(c_key_self,lgrp,c_grp,c_conf,c_bgn,c_step,ktimes,kobs) bind(c,name='qg_obsdb_generate_f90')
236 
237 implicit none
238 
239 ! Passed variables
240 integer(c_int),intent(in) :: c_key_self !< Observation data
241 integer(c_int),intent(in) :: lgrp !< Group size
242 character(kind=c_char,len=1),intent(in) :: c_grp(lgrp+1) !< Group name
243 type(c_ptr),value,intent(in) :: c_conf !< Configuration
244 type(c_ptr),value,intent(in) :: c_bgn !< Start time
245 type(c_ptr),value,intent(in) :: c_step !< Time-step
246 integer(c_int),intent(in) :: ktimes !< Number of time-slots
247 integer(c_int),intent(inout) :: kobs !< Number of observations
248 
249 ! Mocal variables
250 type(fckit_configuration) :: f_conf
251 type(qg_obsdb),pointer :: self
252 character(len=lgrp) :: grp
253 type(datetime) :: bgn
254 type(duration) :: step
255 
256 ! Interface
257 f_conf = fckit_configuration(c_conf)
258 call qg_obsdb_registry%get(c_key_self,self)
259 call c_f_string(c_grp,grp)
260 call c_f_datetime(c_bgn,bgn)
261 call c_f_duration(c_step,step)
262 
263 ! Call Fortran
264 call qg_obsdb_generate(self,grp,f_conf,bgn,step,ktimes,kobs)
265 
266 end subroutine qg_obsdb_generate_c
267 ! ------------------------------------------------------------------------------
268 !> Get observation data size
269 subroutine qg_obsdb_nobs_c(c_key_self,lgrp,c_grp,kobs) bind(c,name='qg_obsdb_nobs_f90')
270 
271 implicit none
272 
273 ! Passed variables
274 integer(c_int),intent(in) :: c_key_self !< Observation data
275 integer(c_int),intent(in) :: lgrp !< Group size
276 character(kind=c_char,len=1),intent(in) :: c_grp(lgrp+1) !< Group name
277 integer(c_int),intent(inout) :: kobs !< Number of observations
278 
279 ! Local variables
280 type(qg_obsdb),pointer :: self
281 character(len=lgrp) :: grp
282 
283 ! Interface
284 call qg_obsdb_registry%get(c_key_self,self)
285 call c_f_string(c_grp,grp)
286 
287 ! Call Fortran
288 call qg_obsdb_nobs(self,grp,kobs)
289 
290 end subroutine qg_obsdb_nobs_c
291 ! ------------------------------------------------------------------------------
292 end module qg_obsdb_interface
qg_obsdb_mod::qg_obsdb_generate
subroutine, public qg_obsdb_generate(self, grp, f_conf, bgn, step, ktimes, kobs)
Generate observation data.
Definition: qg_obsdb_mod.F90:370
qg_obsdb_interface::qg_obsdb_nobs_c
subroutine qg_obsdb_nobs_c(c_key_self, lgrp, c_grp, kobs)
Get observation data size.
Definition: qg_obsdb_interface.F90:270
qg_obsdb_interface::qg_obsdb_delete_c
subroutine qg_obsdb_delete_c(c_key_self)
Delete observation data.
Definition: qg_obsdb_interface.F90:60
qg_obsdb_interface::qg_obsdb_has_c
subroutine qg_obsdb_has_c(c_key_self, lgrp, c_grp, lcol, c_col, c_has)
Test observation data existence.
Definition: qg_obsdb_interface.F90:174
qg_obsdb_mod::qg_obsdb_registry
type(registry_t), public qg_obsdb_registry
Linked list interface - defines registry_t type.
Definition: qg_obsdb_mod.F90:65
qg_obsdb_mod::qg_obsdb
Definition: qg_obsdb_mod.F90:52
qg_obsvec_mod
Definition: qg_obsvec_mod.F90:10
qg_obsdb_mod
Definition: qg_obsdb_mod.F90:10
qg_locs_mod
Definition: qg_locs_mod.F90:9
qg_obsdb_interface::qg_obsdb_setup_c
subroutine qg_obsdb_setup_c(c_key_self, c_conf, c_winbgn, c_winend)
Setup observation data.
Definition: qg_obsdb_interface.F90:30
qg_obsdb_interface::qg_obsdb_get_c
subroutine qg_obsdb_get_c(c_key_self, lgrp, c_grp, lcol, c_col, c_key_ovec)
Get observation data.
Definition: qg_obsdb_interface.F90:82
qg_obsdb_mod::qg_obsdb_delete
subroutine, public qg_obsdb_delete(self)
Delete observation data.
Definition: qg_obsdb_mod.F90:122
qg_obsdb_mod::qg_obsdb_setup
subroutine, public qg_obsdb_setup(self, f_conf, winbgn, winend)
Linked list implementation.
Definition: qg_obsdb_mod.F90:76
qg_obsdb_mod::qg_obsdb_locations
subroutine, public qg_obsdb_locations(self, grp, t1, t2, fields, c_times)
Get locations from observation data.
Definition: qg_obsdb_mod.F90:308
qg_obsdb_mod::qg_obsdb_nobs
subroutine, public qg_obsdb_nobs(self, grp, kobs)
Get observation data size.
Definition: qg_obsdb_mod.F90:417
qg_obsdb_interface::qg_obsdb_locations_c
subroutine qg_obsdb_locations_c(c_key_self, lgrp, c_grp, c_t1, c_t2, c_fields, c_times)
Get locations from observation data.
Definition: qg_obsdb_interface.F90:202
qg_obsdb_interface::qg_obsdb_get_local_c
subroutine qg_obsdb_get_local_c(c_key_self, lgrp, c_grp, lcol, c_col, c_idxsize, c_idx, c_key_ovec)
Get observations data for a local subset.
Definition: qg_obsdb_interface.F90:113
qg_obsvec_mod::qg_obsvec_registry
type(registry_t), public qg_obsvec_registry
Linked list interface - defines registry_t type.
Definition: qg_obsvec_mod.F90:47
qg_obsdb_mod::qg_obsdb_get
subroutine, public qg_obsdb_get(self, grp, col, ovec, local, idx)
Get observation data.
Definition: qg_obsdb_mod.F90:157
qg_obsdb_interface
Definition: qg_obsdb_interface.F90:10
qg_obsdb_mod::qg_obsdb_has
subroutine, public qg_obsdb_has(self, grp, col, has)
Test observation data existence.
Definition: qg_obsdb_mod.F90:280
qg_obsvec_mod::qg_obsvec
Definition: qg_obsvec_mod.F90:35
qg_obsdb_mod::qg_obsdb_put
subroutine, public qg_obsdb_put(self, grp, col, ovec)
Put observations data.
Definition: qg_obsdb_mod.F90:226
qg_obsdb_interface::qg_obsdb_put_c
subroutine qg_obsdb_put_c(c_key_self, lgrp, c_grp, lcol, c_col, c_key_ovec)
Put observation data.
Definition: qg_obsdb_interface.F90:144
qg_obsdb_interface::qg_obsdb_generate_c
subroutine qg_obsdb_generate_c(c_key_self, lgrp, c_grp, c_conf, c_bgn, c_step, ktimes, kobs)
Generate observation data.
Definition: qg_obsdb_interface.F90:236