OOPS
qg_obsvec_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 iso_c_binding
13 use qg_obsvec_mod
14 
15 implicit none
16 
17 private
18 ! ------------------------------------------------------------------------------
19 contains
20 ! ------------------------------------------------------------------------------
21 !> Setup observation vector
22 subroutine qg_obsvec_setup_c(c_key_self,nlev,nobs) bind(c,name='qg_obsvec_setup_f90')
23 
24 implicit none
25 
26 ! Passed variables
27 integer(c_int),intent(inout) :: c_key_self !< Observation vector
28 integer(c_int),intent(in) :: nlev !< Number of levels
29 integer(c_int),intent(in) :: nobs !< Number of observations
30 
31 ! Local variables
32 type(qg_obsvec),pointer :: self
33 
34 ! Interface
35 call qg_obsvec_registry%init()
36 call qg_obsvec_registry%add(c_key_self)
37 call qg_obsvec_registry%get(c_key_self,self)
38 
39 ! Call Fortran
40 call qg_obsvec_setup(self,nlev,nobs)
41 
42 end subroutine qg_obsvec_setup_c
43 ! ------------------------------------------------------------------------------
44 !> Clone observation vector
45 subroutine qg_obsvec_clone_c(c_key_self,c_key_other) bind(c,name='qg_obsvec_clone_f90')
46 
47 implicit none
48 
49 ! Passed variables
50 integer(c_int),intent(inout) :: c_key_self !< Observation vector
51 integer(c_int),intent(in) :: c_key_other !< Other observation vector
52 
53 ! Local variables
54 type(qg_obsvec),pointer :: self,other
55 
56 ! Interface
57 call qg_obsvec_registry%get(c_key_other,other)
58 call qg_obsvec_registry%init()
59 call qg_obsvec_registry%add(c_key_self)
60 call qg_obsvec_registry%get(c_key_self,self)
61 
62 ! Call Fortran
63 call qg_obsvec_clone(self,other)
64 
65 end subroutine qg_obsvec_clone_c
66 ! ------------------------------------------------------------------------------
67 !> Delete observation vector
68 subroutine qg_obsvec_delete_c(c_key_self) bind(c,name='qg_obsvec_delete_f90')
69 
70 implicit none
71 
72 ! Passed variables
73 integer(c_int),intent(inout) :: c_key_self !< Observation vector
74 
75 ! Local variables
76 type(qg_obsvec),pointer :: self
77 
78 ! Interface
79 call qg_obsvec_registry%get(c_key_self,self)
80 
81 ! Call Fortran
82 call qg_obsvec_delete(self)
83 
84 ! Clear interface
85 call qg_obsvec_registry%remove(c_key_self)
86 
87 end subroutine qg_obsvec_delete_c
88 ! ------------------------------------------------------------------------------
89 !> Copy observation vector
90 subroutine qg_obsvec_copy_c(c_key_self,c_key_other) bind(c,name='qg_obsvec_copy_f90')
91 
92 implicit none
93 
94 ! Passed variables
95 integer(c_int),intent(in) :: c_key_self !< Observation vector
96 integer(c_int),intent(in) :: c_key_other !< Other observation vector
97 
98 ! Local variables
99 type(qg_obsvec),pointer :: self,other
100 
101 ! Interface
102 call qg_obsvec_registry%get(c_key_self,self)
103 call qg_obsvec_registry%get(c_key_other,other)
104 
105 ! Call Fortran
106 call qg_obsvec_copy(self,other)
107 
108 end subroutine qg_obsvec_copy_c
109 ! ------------------------------------------------------------------------------
110 !> Copy a local subset of the observation vector
111 subroutine qg_obsvec_copy_local_c(c_key_self,c_key_other, c_idxsize,c_idx) bind(c,name='qg_obsvec_copy_local_f90')
112 
113 implicit none
114 
115 ! Passed variables
116 integer(c_int),intent(in) :: c_key_self !< Observation vector
117 integer(c_int),intent(in) :: c_key_other !< Other observation vector
118 integer(c_int),intent(in) :: c_idxsize
119 integer(c_int),intent(in) :: c_idx(c_idxsize)
120 
121 ! Local variables
122 type(qg_obsvec),pointer :: self,other
123 
124 ! Interface
125 call qg_obsvec_registry%get(c_key_self,self)
126 call qg_obsvec_registry%get(c_key_other,other)
127 
128 ! Call Fortran
129 call qg_obsvec_copy_local(self,other,c_idx)
130 
131 end subroutine qg_obsvec_copy_local_c
132 ! ------------------------------------------------------------------------------
133 !> Set observation vector to zero
134 subroutine qg_obsvec_zero_c(c_key_self) bind(c,name='qg_obsvec_zero_f90')
135 
136 implicit none
137 
138 ! Passed variables
139 integer(c_int),intent(in) :: c_key_self !< Observation vector
140 
141 ! Local variables
142 type(qg_obsvec),pointer :: self
143 
144 ! Interface
145 call qg_obsvec_registry%get(c_key_self,self)
146 
147 ! Call Fortran
148 call qg_obsvec_zero(self)
149 
150 end subroutine qg_obsvec_zero_c
151 ! ------------------------------------------------------------------------------
152 !> Multiply observation vector with a scalar
153 subroutine qg_obsvec_mul_scal_c(c_key_self,zz) bind(c,name='qg_obsvec_mul_scal_f90')
154 
155 implicit none
156 
157 ! Passed variables
158 integer(c_int),intent(in) :: c_key_self !< Observation vector
159 real(c_double),intent(in) :: zz !< Multiplier
160 
161 ! Local variables
162 type(qg_obsvec),pointer :: self
163 
164 ! Interface
165 call qg_obsvec_registry%get(c_key_self,self)
166 
167 ! Call Fortran
168 call qg_obsvec_mul_scal(self,zz)
169 
170 end subroutine qg_obsvec_mul_scal_c
171 ! ------------------------------------------------------------------------------
172 !> Add observation vector
173 subroutine qg_obsvec_add_c(c_key_self,c_key_other) bind(c,name='qg_obsvec_add_f90')
174 
175 implicit none
176 
177 ! Passed variables
178 integer(c_int),intent(in) :: c_key_self !< Observation vector
179 integer(c_int),intent(in) :: c_key_other !< Other observation vector
180 
181 ! Local variables
182 type(qg_obsvec),pointer :: self,other
183 
184 ! Interface
185 call qg_obsvec_registry%get(c_key_self,self)
186 call qg_obsvec_registry%get(c_key_other,other)
187 
188 ! Call Fortran
189 call qg_obsvec_add(self,other)
190 
191 end subroutine qg_obsvec_add_c
192 ! ------------------------------------------------------------------------------
193 !> Subtract observation vector
194 subroutine qg_obsvec_sub_c(c_key_self,c_key_other) bind(c,name='qg_obsvec_sub_f90')
195 
196 implicit none
197 
198 ! Passed variables
199 integer(c_int),intent(in) :: c_key_self !< Observation vector
200 integer(c_int),intent(in) :: c_key_other !< Other observation vector
201 
202 ! Local variables
203 type(qg_obsvec),pointer :: self,other
204 
205 ! Interface
206 call qg_obsvec_registry%get(c_key_self,self)
207 call qg_obsvec_registry%get(c_key_other,other)
208 
209 ! Call Fortran
210 call qg_obsvec_sub(self,other)
211 
212 end subroutine qg_obsvec_sub_c
213 ! ------------------------------------------------------------------------------
214 !> Multiply observation vector
215 subroutine qg_obsvec_mul_c(c_key_self,c_key_other) bind(c,name='qg_obsvec_mul_f90')
216 
217 implicit none
218 
219 ! Passed variables
220 integer(c_int),intent(in) :: c_key_self !< Observation vector
221 integer(c_int),intent(in) :: c_key_other !< Other observation vector
222 
223 ! Local variables
224 type(qg_obsvec),pointer :: self,other
225 
226 ! Interface
227 call qg_obsvec_registry%get(c_key_self,self)
228 call qg_obsvec_registry%get(c_key_other,other)
229 
230 ! Call Fortran
231 call qg_obsvec_mul(self,other)
232 
233 end subroutine qg_obsvec_mul_c
234 ! ------------------------------------------------------------------------------
235 !> Divide observation vector
236 subroutine qg_obsvec_div_c(c_key_self,c_key_other) bind(c,name='qg_obsvec_div_f90')
237 
238 implicit none
239 
240 ! Passed variables
241 integer(c_int),intent(in) :: c_key_self !< Observation vector
242 integer(c_int),intent(in) :: c_key_other !< Other observation vector
243 
244 ! Local variables
245 type(qg_obsvec),pointer :: self,other
246 
247 ! Interface
248 call qg_obsvec_registry%get(c_key_self,self)
249 call qg_obsvec_registry%get(c_key_other,other)
250 
251 ! Call Fortran
252 call qg_obsvec_div(self,other)
253 
254 end subroutine qg_obsvec_div_c
255 ! ------------------------------------------------------------------------------
256 !> Apply axpy on observation vector
257 subroutine qg_obsvec_axpy_c(c_key_self,zz,c_key_other) bind(c,name='qg_obsvec_axpy_f90')
258 
259 implicit none
260 
261 ! Passed variables
262 integer(c_int),intent(in) :: c_key_self !< Observation vector
263 real(c_double),intent(in) :: zz !< Multiplier
264 integer(c_int),intent(in) :: c_key_other !< Other observation vector
265 
266 ! Local variables
267 type(qg_obsvec),pointer :: self,other
268 
269 ! Interface
270 call qg_obsvec_registry%get(c_key_self,self)
271 call qg_obsvec_registry%get(c_key_other,other)
272 
273 ! Call Fortran
274 call qg_obsvec_axpy(self,zz,other)
275 
276 end subroutine qg_obsvec_axpy_c
277 ! ------------------------------------------------------------------------------
278 !> Invert observation vector
279 subroutine qg_obsvec_invert_c(c_key_self) bind(c,name='qg_obsvec_invert_f90')
280 
281 implicit none
282 
283 ! Passed variables
284 integer(c_int),intent(in) :: c_key_self !< Observation vector
285 
286 ! Local variables
287 type(qg_obsvec),pointer :: self
288 
289 ! Interface
290 call qg_obsvec_registry%get(c_key_self,self)
291 
292 ! Call Fortran
293 call qg_obsvec_invert(self)
294 
295 end subroutine qg_obsvec_invert_c
296 ! ------------------------------------------------------------------------------
297 !> Generate random observation vector
298 subroutine qg_obsvec_random_c(c_odb,c_self) bind(c,name='qg_obsvec_random_f90')
299 
300 implicit none
301 
302 ! Passed variables
303 type(c_ptr),intent(in) :: c_odb !< Observation data base
304 integer(c_int),intent(in) :: c_self !< Observation vector
305 
306 ! Local variables
307 type(qg_obsvec),pointer :: self
308 
309 ! Interface
310 call qg_obsvec_registry%get(c_self,self)
311 
312 ! Call Fortran
313 call qg_obsvec_random(c_odb,self)
314 
315 end subroutine qg_obsvec_random_c
316 ! ------------------------------------------------------------------------------
317 !> Compute dot product between observation vectors
318 subroutine qg_obsvec_dotprod_c(c_key_obsvec1,c_key_obsvec2,zz) bind(c,name='qg_obsvec_dotprod_f90')
319 
320 implicit none
321 
322 ! Passed variables
323 integer(c_int),intent(in) :: c_key_obsvec1 !< Observation vector 1
324 integer(c_int),intent(in) :: c_key_obsvec2 !< Observation vector 2
325 real(c_double),intent(inout) :: zz !< Dot product
326 
327 ! Local variables
328 type(qg_obsvec),pointer :: obsvec1,obsvec2
329 
330 ! Interface
331 call qg_obsvec_registry%get(c_key_obsvec1,obsvec1)
332 call qg_obsvec_registry%get(c_key_obsvec2,obsvec2)
333 
334 ! Call Fortran
335 call qg_obsvec_dotprod(obsvec1,obsvec2,zz)
336 
337 end subroutine qg_obsvec_dotprod_c
338 ! ------------------------------------------------------------------------------
339 !> Compute observation vector statistics
340 subroutine qg_obsvec_stats_c(c_key_self,scaling,zmin,zmax,zavg) bind(c,name='qg_obsvec_stats_f90')
341 
342 implicit none
343 
344 ! Passed variables
345 integer(c_int),intent(in) :: c_key_self !< Observation vector
346 real(c_double),intent(inout) :: scaling !< Scaling
347 real(c_double),intent(inout) :: zmin !< Minimum
348 real(c_double),intent(inout) :: zmax !< Maximum
349 real(c_double),intent(inout) :: zavg !< Average
350 
351 ! Local variables
352 type(qg_obsvec),pointer :: self
353 
354 ! Interface
355 call qg_obsvec_registry%get(c_key_self,self)
356 
357 ! Call Fortran
358 call qg_obsvec_stats(self,scaling,zmin,zmax,zavg)
359 
360 end subroutine qg_obsvec_stats_c
361 ! ------------------------------------------------------------------------------
362 !> Get observation vector size
363 subroutine qg_obsvec_nobs_c(c_key_self,kobs) bind(c,name='qg_obsvec_nobs_f90')
364 
365 implicit none
366 
367 ! Passed variables
368 integer(c_int),intent(in) :: c_key_self !< Observation vector
369 integer(c_int),intent(inout) :: kobs !< Observation vector size
370 
371 ! Local vector
372 type(qg_obsvec),pointer :: self
373 
374 ! Interface
375 call qg_obsvec_registry%get(c_key_self,self)
376 
377 ! Call Fortran
378 call qg_obsvec_nobs(self,kobs)
379 
380 end subroutine qg_obsvec_nobs_c
381 
382 ! ------------------------------------------------------------------------------
383 !> Get observation value at iob location
384 subroutine qg_obsvec_getat_c(c_key_self,iob,val) bind(c,name='qg_obsvec_getat_f90')
385 
386 implicit none
387 
388 ! Passed variables
389 integer(c_int),intent(in) :: c_key_self !< Observation vector
390 integer(c_int),intent(in) :: iob !< Observation index
391 real(c_double),intent(out):: val !< ob. value
392 
393 ! Local vector
394 type(qg_obsvec),pointer :: self
395 
396 ! Interface
397 call qg_obsvec_registry%get(c_key_self,self)
398 
399 ! Call Fortran
400 call qg_obsvec_getat(self,iob,val)
401 
402 end subroutine qg_obsvec_getat_c
403 
404 ! ------------------------------------------------------------------------------
405 end module qg_obsvec_interface
qg_obsvec_interface::qg_obsvec_setup_c
subroutine qg_obsvec_setup_c(c_key_self, nlev, nobs)
Setup observation vector.
Definition: qg_obsvec_interface.F90:23
qg_obsvec_mod::qg_obsvec_copy
subroutine, public qg_obsvec_copy(self, other)
Copy observation vector.
Definition: qg_obsvec_mod.F90:114
qg_obsvec_mod::qg_obsvec_mul_scal
subroutine, public qg_obsvec_mul_scal(self, zz)
Multiply observation vector with a scalar.
Definition: qg_obsvec_mod.F90:185
qg_obsvec_interface::qg_obsvec_dotprod_c
subroutine qg_obsvec_dotprod_c(c_key_obsvec1, c_key_obsvec2, zz)
Compute dot product between observation vectors.
Definition: qg_obsvec_interface.F90:319
qg_obsvec_interface::qg_obsvec_mul_scal_c
subroutine qg_obsvec_mul_scal_c(c_key_self, zz)
Multiply observation vector with a scalar.
Definition: qg_obsvec_interface.F90:154
qg_obsvec_mod::qg_obsvec_dotprod
subroutine, public qg_obsvec_dotprod(obsvec1, obsvec2, zz)
Compute dot product between observation vectors.
Definition: qg_obsvec_mod.F90:303
qg_obsvec_mod::qg_obsvec_axpy
subroutine, public qg_obsvec_axpy(self, zz, other)
Apply axpy on observation vector.
Definition: qg_obsvec_mod.F90:255
qg_obsvec_mod::qg_obsvec_nobs
subroutine, public qg_obsvec_nobs(self, kobs)
Get observation vector size.
Definition: qg_obsvec_mod.F90:387
qg_obsvec_interface::qg_obsvec_delete_c
subroutine qg_obsvec_delete_c(c_key_self)
Delete observation vector.
Definition: qg_obsvec_interface.F90:69
qg_obsvec_mod
Definition: qg_obsvec_mod.F90:10
qg_obsvec_mod::qg_obsvec_sub
subroutine, public qg_obsvec_sub(self, other)
Subtract observation vector.
Definition: qg_obsvec_mod.F90:213
qg_obsvec_interface::qg_obsvec_mul_c
subroutine qg_obsvec_mul_c(c_key_self, c_key_other)
Multiply observation vector.
Definition: qg_obsvec_interface.F90:216
qg_obsvec_interface::qg_obsvec_random_c
subroutine qg_obsvec_random_c(c_odb, c_self)
Generate random observation vector.
Definition: qg_obsvec_interface.F90:299
qg_obsvec_interface::qg_obsvec_zero_c
subroutine qg_obsvec_zero_c(c_key_self)
Set observation vector to zero.
Definition: qg_obsvec_interface.F90:135
qg_obsvec_mod::qg_obsvec_zero
subroutine, public qg_obsvec_zero(self)
Set observation vector to zero.
Definition: qg_obsvec_mod.F90:172
qg_obsvec_mod::qg_obsvec_delete
subroutine, public qg_obsvec_delete(self)
Delete observation vector.
Definition: qg_obsvec_mod.F90:101
qg_obsvec_interface::qg_obsvec_axpy_c
subroutine qg_obsvec_axpy_c(c_key_self, zz, c_key_other)
Apply axpy on observation vector.
Definition: qg_obsvec_interface.F90:258
qg_obsvec_interface::qg_obsvec_stats_c
subroutine qg_obsvec_stats_c(c_key_self, scaling, zmin, zmax, zavg)
Compute observation vector statistics.
Definition: qg_obsvec_interface.F90:341
qg_obsvec_interface::qg_obsvec_sub_c
subroutine qg_obsvec_sub_c(c_key_self, c_key_other)
Subtract observation vector.
Definition: qg_obsvec_interface.F90:195
qg_obsvec_interface::qg_obsvec_copy_local_c
subroutine qg_obsvec_copy_local_c(c_key_self, c_key_other, c_idxsize, c_idx)
Copy a local subset of the observation vector.
Definition: qg_obsvec_interface.F90:112
qg_obsvec_mod::qg_obsvec_clone
subroutine, public qg_obsvec_clone(self, other)
Clone observation vector.
Definition: qg_obsvec_mod.F90:83
qg_obsvec_mod::qg_obsvec_mul
subroutine, public qg_obsvec_mul(self, other)
Multiply observation vector.
Definition: qg_obsvec_mod.F90:227
qg_obsvec_interface::qg_obsvec_nobs_c
subroutine qg_obsvec_nobs_c(c_key_self, kobs)
Get observation vector size.
Definition: qg_obsvec_interface.F90:364
qg_obsvec_interface
Definition: qg_obsvec_interface.F90:10
qg_obsvec_interface::qg_obsvec_copy_c
subroutine qg_obsvec_copy_c(c_key_self, c_key_other)
Copy observation vector.
Definition: qg_obsvec_interface.F90:91
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_obsvec_mod::qg_obsvec_random
subroutine, public qg_obsvec_random(c_odb, self)
Generate random observation vector.
Definition: qg_obsvec_mod.F90:283
qg_obsvec_interface::qg_obsvec_div_c
subroutine qg_obsvec_div_c(c_key_self, c_key_other)
Divide observation vector.
Definition: qg_obsvec_interface.F90:237
qg_obsvec_mod::qg_obsvec_copy_local
subroutine, public qg_obsvec_copy_local(self, other, idx)
Copy a local subset of the observation vector.
Definition: qg_obsvec_mod.F90:140
qg_obsvec_interface::qg_obsvec_getat_c
subroutine qg_obsvec_getat_c(c_key_self, iob, val)
Get observation value at iob location.
Definition: qg_obsvec_interface.F90:385
qg_obsvec_interface::qg_obsvec_invert_c
subroutine qg_obsvec_invert_c(c_key_self)
Invert observation vector.
Definition: qg_obsvec_interface.F90:280
qg_obsvec_mod::qg_obsvec_setup
subroutine, public qg_obsvec_setup(self, nlev, nobs)
Linked list implementation.
Definition: qg_obsvec_mod.F90:58
qg_obsvec_mod::qg_obsvec_div
subroutine, public qg_obsvec_div(self, other)
Divide observation vector.
Definition: qg_obsvec_mod.F90:241
qg_obsvec_mod::qg_obsvec_stats
subroutine, public qg_obsvec_stats(self, scaling, zmin, zmax, zavg)
Compute observation vector statistics.
Definition: qg_obsvec_mod.F90:331
qg_obsvec_interface::qg_obsvec_add_c
subroutine qg_obsvec_add_c(c_key_self, c_key_other)
Add observation vector.
Definition: qg_obsvec_interface.F90:174
qg_obsvec_mod::qg_obsvec_getat
subroutine, public qg_obsvec_getat(self, iob, val)
Get value from observation vector at location (iob)
Definition: qg_obsvec_mod.F90:402
qg_obsvec_mod::qg_obsvec
Definition: qg_obsvec_mod.F90:35
qg_obsvec_interface::qg_obsvec_clone_c
subroutine qg_obsvec_clone_c(c_key_self, c_key_other)
Clone observation vector.
Definition: qg_obsvec_interface.F90:46
qg_obsvec_mod::qg_obsvec_add
subroutine, public qg_obsvec_add(self, other)
Add observation vector.
Definition: qg_obsvec_mod.F90:199
qg_obsvec_mod::qg_obsvec_invert
subroutine, public qg_obsvec_invert(self)
Invert observation vector.
Definition: qg_obsvec_mod.F90:270