SOCA
soca_state.interface.F90
Go to the documentation of this file.
1 ! (C) Copyright 2020-2021 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 !> C++ interfaces for soca_state_mod::soca_state
8 
9 use datetime_mod, only: datetime, c_f_datetime
10 use fckit_configuration_module, only: fckit_configuration
11 use iso_c_binding
12 use kinds, only: kind_real
13 use oops_variables_mod, only: oops_variables
14 
15 ! soca modules
17 use soca_geom_mod, only: soca_geom
20 use soca_state_mod, only: soca_state
22 
23 implicit none
24 private
25 
26 
27 ! ------------------------------------------------------------------------------
28 contains
29 ! ------------------------------------------------------------------------------
30 
31 
32 ! ------------------------------------------------------------------------------
33 !> C++ interface for soca_state_mod::soca_state version of
34 !! soca_fields_mod::soca_fields::create()
35 subroutine soca_state_create_c(c_key_self, c_key_geom, c_vars) bind(c,name='soca_state_create_f90')
36  integer(c_int), intent(inout) :: c_key_self !< Handle to field
37  integer(c_int), intent(in) :: c_key_geom !< Geometry
38  type(c_ptr),value, intent(in) :: c_vars !< List of variables
39 
40  type(soca_state),pointer :: self
41  type(soca_geom), pointer :: geom
42  type(oops_variables) :: vars
43 
44  call soca_geom_registry%get(c_key_geom, geom)
45  call soca_state_registry%init()
46  call soca_state_registry%add(c_key_self)
47  call soca_state_registry%get(c_key_self,self)
48 
49  vars = oops_variables(c_vars)
50  call self%create(geom, vars)
51 
52 end subroutine soca_state_create_c
53 
54 
55 ! ------------------------------------------------------------------------------
56 !> C++ interface for soca_state_mod::soca_state version of
57 !! soca_fields_mod::soca_fields::delete()
58 subroutine soca_state_delete_c(c_key_self) bind(c,name='soca_state_delete_f90')
59  integer(c_int), intent(inout) :: c_key_self
60 
61  type(soca_state), pointer :: self
62 
63  call soca_state_registry%get(c_key_self,self)
64  call self%delete( )
65  call soca_state_registry%remove(c_key_self)
66 
67 end subroutine soca_state_delete_c
68 
69 
70 ! ------------------------------------------------------------------------------
71 !> C++ interface for soca_state_mod::soca_state version of
72 !! soca_fields_mod::soca_fields::zeros()
73 subroutine soca_state_zero_c(c_key_self) bind(c,name='soca_state_zero_f90')
74  integer(c_int), intent(in) :: c_key_self
75 
76  type(soca_state), pointer :: self
77 
78  call soca_state_registry%get(c_key_self,self)
79  call self%zeros()
80 
81 end subroutine soca_state_zero_c
82 
83 
84 ! ------------------------------------------------------------------------------
85 !> C++ interface for soca_state_mod::soca_state version of
86 !! soca_fields_mod::soca_fields::copy()
87 subroutine soca_state_copy_c(c_key_self,c_key_rhs) bind(c,name='soca_state_copy_f90')
88  integer(c_int), intent(in) :: c_key_self
89  integer(c_int), intent(in) :: c_key_rhs
90 
91  type(soca_state), pointer :: self
92  type(soca_state), pointer :: rhs
93 
94  call soca_state_registry%get(c_key_self,self)
95  call soca_state_registry%get(c_key_rhs,rhs)
96 
97  call self%copy(rhs)
98 
99 end subroutine soca_state_copy_c
100 
101 
102 ! ------------------------------------------------------------------------------
103 !> C++ interface for soca_state_mod::soca_state version of
104 !! soca_fields_mod::soca_fields::axpy()
105 subroutine soca_state_axpy_c(c_key_self,c_zz,c_key_rhs) bind(c,name='soca_state_axpy_f90')
106  integer(c_int), intent(in) :: c_key_self
107  real(c_double), intent(in) :: c_zz
108  integer(c_int), intent(in) :: c_key_rhs
109 
110  type(soca_state), pointer :: self
111  real(kind=kind_real) :: zz
112  type(soca_state), pointer :: rhs
113 
114  call soca_state_registry%get(c_key_self,self)
115  call soca_state_registry%get(c_key_rhs,rhs)
116  zz = c_zz
117 
118  call self%axpy(zz,rhs)
119 
120 end subroutine soca_state_axpy_c
121 
122 
123 ! ------------------------------------------------------------------------------
124 !> C++ interface for soca_state_mod::soca_state::add_incr()
125 subroutine soca_state_add_incr_c(c_key_self,c_key_rhs) bind(c,name='soca_state_add_incr_f90')
126  integer(c_int), intent(in) :: c_key_self
127  integer(c_int), intent(in) :: c_key_rhs
128 
129  type(soca_state), pointer :: self
130  type(soca_increment), pointer :: rhs
131 
132  call soca_state_registry%get(c_key_self,self)
133  call soca_increment_registry%get(c_key_rhs,rhs)
134 
135  call self%add_incr(rhs)
136 
137 end subroutine soca_state_add_incr_c
138 
139 
140 ! ------------------------------------------------------------------------------
141 !> C++ interface for soca_state_mod::soca_state version of
142 !! soca_fields_mod::soca_fields::read()
143 subroutine soca_state_read_file_c(c_key_fld, c_conf, c_dt) bind(c,name='soca_state_read_file_f90')
144  integer(c_int), intent(in) :: c_key_fld !< Fields
145  type(c_ptr), intent(in) :: c_conf !< Configuration
146  type(c_ptr), intent(inout) :: c_dt !< DateTime
147 
148  type(soca_state), pointer :: fld
149  type(datetime) :: fdate
150 
151  call soca_state_registry%get(c_key_fld,fld)
152  call c_f_datetime(c_dt, fdate)
153  call fld%read(fckit_configuration(c_conf), fdate)
154 
155 end subroutine soca_state_read_file_c
156 
157 
158 ! ------------------------------------------------------------------------------
159 !> C++ interface for soca_state_mod::soca_state version of
160 !! soca_fields_mod::soca_fields::write_rst()
161 subroutine soca_state_write_file_c(c_key_fld, c_conf, c_dt) bind(c,name='soca_state_write_file_f90')
162  integer(c_int), intent(in) :: c_key_fld !< Fields
163  type(c_ptr), intent(in) :: c_conf !< Configuration
164  type(c_ptr), intent(in) :: c_dt !< DateTime
165 
166  type(soca_state), pointer :: fld
167  type(datetime) :: fdate
168 
169  call soca_state_registry%get(c_key_fld,fld)
170  call c_f_datetime(c_dt, fdate)
171  call fld%write_rst(fckit_configuration(c_conf), fdate)
172 
173 end subroutine soca_state_write_file_c
174 
175 
176 ! ------------------------------------------------------------------------------
177 !> C++ interface for soca_state_mod::soca_state version of
178 !! soca_fields_mod::soca_fields::gpnorm()
179 subroutine soca_state_gpnorm_c(c_key_fld, kf, pstat) bind(c,name='soca_state_gpnorm_f90')
180  integer(c_int), intent(in) :: c_key_fld
181  integer(c_int), intent(in) :: kf
182  real(c_double), intent(inout) :: pstat(3*kf)
183 
184  type(soca_state), pointer :: fld
185  real(kind=kind_real) :: zstat(3, kf)
186  integer :: jj, js, jf
187 
188  call soca_state_registry%get(c_key_fld,fld)
189 
190  call fld%gpnorm(kf, zstat)
191  jj=0
192  do jf = 1, kf
193  do js = 1, 3
194  jj=jj+1
195  pstat(jj) = zstat(js,jf)
196  enddo
197  enddo
198 
199 end subroutine soca_state_gpnorm_c
200 
201 
202 ! ------------------------------------------------------------------------------
203 !> C++ interface for soca_state_mod::soca_state RMS
204 subroutine soca_state_rms_c(c_key_fld, prms) bind(c,name='soca_state_rms_f90')
205  integer(c_int), intent(in) :: c_key_fld
206  real(c_double), intent(inout) :: prms
207 
208  type(soca_state), pointer :: fld
209  real(kind=kind_real) :: zz
210 
211  call soca_state_registry%get(c_key_fld,fld)
212 
213  call fld%dot_prod(fld, zz)
214  prms = sqrt(zz)
215 
216 end subroutine soca_state_rms_c
217 
218 
219 ! ------------------------------------------------------------------------------
220 !> C++ interface for soca_state_mod::soca_state::rotate()
221 subroutine soca_state_rotate2grid_c(c_key_self, c_uvars, c_vvars) bind(c,name='soca_state_rotate2grid_f90')
222  integer(c_int), intent(in) :: c_key_self
223  type(c_ptr), value, intent(in) :: c_uvars
224  type(c_ptr), value, intent(in) :: c_vvars
225 
226  type(soca_state), pointer :: self
227  type(oops_variables) :: uvars, vvars
228 
229  uvars = oops_variables(c_uvars)
230  vvars = oops_variables(c_vvars)
231 
232  call soca_state_registry%get(c_key_self,self)
233  call self%rotate(coordinate="grid", uvars=uvars, vvars=vvars)
234 
235 end subroutine soca_state_rotate2grid_c
236 
237 
238 ! ------------------------------------------------------------------------------
239 !> C++ interface for soca_state_mod::soca_state::rotate()
240 subroutine soca_state_rotate2north_c(c_key_self, c_uvars, c_vvars) bind(c,name='soca_state_rotate2north_f90')
241  integer(c_int), intent(in) :: c_key_self
242  type(c_ptr), value, intent(in) :: c_uvars
243  type(c_ptr), value, intent(in) :: c_vvars
244 
245  type(soca_state), pointer :: self
246  type(oops_variables) :: uvars, vvars
247 
248  uvars = oops_variables(c_uvars)
249  vvars = oops_variables(c_vvars)
250 
251  call soca_state_registry%get(c_key_self,self)
252  call self%rotate(coordinate="north", uvars=uvars, vvars=vvars)
253 
254 end subroutine soca_state_rotate2north_c
255 
256 
257 ! ------------------------------------------------------------------------------
258 !> C++ interface to get soca_state_mod::soca_state dimensions sizes
259 subroutine soca_state_sizes_c(c_key_fld, nx, ny, nzo, nf) bind(c,name='soca_state_sizes_f90')
260  integer(c_int), intent(in) :: c_key_fld
261  integer(kind=c_int), intent(inout) :: nx, ny, nzo, nf
262 
263  type(soca_state), pointer :: fld
264 
265  call soca_state_registry%get(c_key_fld,fld)
266 
267  nx = size(fld%geom%lon,1)
268  ny = size(fld%geom%lon,2)
269  nzo = fld%geom%nzo
270  nf = size(fld%fields)
271 
272 end subroutine soca_state_sizes_c
273 
274 
275 ! ------------------------------------------------------------------------------
276 !> C++ interface for soca_state_mod::soca_state::convert()
277 subroutine soca_state_change_resol_c(c_key_fld,c_key_rhs) bind(c,name='soca_state_change_resol_f90')
278  integer(c_int), intent(in) :: c_key_fld
279  integer(c_int), intent(in) :: c_key_rhs
280 
281  type(soca_state), pointer :: fld, rhs
282 
283  call soca_state_registry%get(c_key_fld,fld)
284  call soca_state_registry%get(c_key_rhs,rhs)
285 
286  ! TODO (Guillaume or Travis) implement == in geometry or something to that effect.
287  if (size(fld%geom%lon,1)==size(rhs%geom%lon,1) .and. size(fld%geom%lat,2)==size(rhs%geom%lat,2) .and. &
288  fld%geom%nzo==rhs%geom%nzo ) then
289  call fld%copy(rhs)
290  else
291  call fld%convert(rhs)
292  endif
293 
294 end subroutine soca_state_change_resol_c
295 
296 
297 ! ------------------------------------------------------------------------------
298 !> C++ interface for soca_state_mod::soca_state version of
299 !! soca_fields_mod::soca_fields::serial_size()
300 subroutine soca_state_serial_size_c(c_key_self,c_key_geom,c_vec_size) bind (c,name='soca_state_serial_size_f90')
301 
302  implicit none
303  integer(c_int), intent(in) :: c_key_self
304  integer(c_int), intent(in) :: c_key_geom
305  integer(c_size_t), intent(out) :: c_vec_size
306 
307  type(soca_state), pointer :: self
308  type(soca_geom), pointer :: geom
309  integer :: vec_size
310 
311  call soca_state_registry%get(c_key_self,self)
312  call soca_geom_registry%get(c_key_geom,geom)
313 
314  call self%serial_size(geom, vec_size)
315  c_vec_size = vec_size
316 
317 end subroutine soca_state_serial_size_c
318 
319 
320 ! ------------------------------------------------------------------------------
321 !> C++ interface for soca_state_mod::soca_state version of
322 !! soca_fields_mod::soca_fields::serialize()
323 subroutine soca_state_serialize_c(c_key_self,c_key_geom,c_vec_size,c_vec) bind (c,name='soca_state_serialize_f90')
324 
325  implicit none
326  integer(c_int), intent(in) :: c_key_self
327  integer(c_int), intent(in) :: c_key_geom
328  integer(c_size_t), intent(in) :: c_vec_size
329  real(c_double), intent(out) :: c_vec(c_vec_size)
330 
331  type(soca_state), pointer :: self
332  type(soca_geom), pointer :: geom
333 
334  integer :: vec_size
335 
336  vec_size = c_vec_size
337  call soca_state_registry%get(c_key_self,self)
338  call soca_geom_registry%get(c_key_geom,geom)
339 
340  call self%serialize(geom, vec_size, c_vec)
341 
342 end subroutine soca_state_serialize_c
343 
344 
345 ! ------------------------------------------------------------------------------
346 !> C++ interface for soca_state_mod::soca_state version of
347 !! soca_fields_mod::soca_fields::deserialize()
348 subroutine soca_state_deserialize_c(c_key_self,c_key_geom,c_vec_size,c_vec,c_index) bind (c,name='soca_state_deserialize_f90')
349 
350  implicit none
351  integer(c_int), intent(in) :: c_key_self
352  integer(c_int), intent(in) :: c_key_geom
353  integer(c_size_t), intent(in) :: c_vec_size
354  real(c_double), intent(in) :: c_vec(c_vec_size)
355  integer(c_size_t), intent(inout) :: c_index
356 
357  type(soca_state), pointer :: self
358  type(soca_geom), pointer :: geom
359  integer :: vec_size, idx
360 
361  vec_size = c_vec_size
362  idx = c_index
363  call soca_state_registry%get(c_key_self,self)
364  call soca_geom_registry%get(c_key_geom,geom)
365 
366  call self%deserialize(geom,vec_size,c_vec, idx)
367  c_index=idx
368 
369 end subroutine soca_state_deserialize_c
370 
371 
372 ! ------------------------------------------------------------------------------
373 !> C++ interface for soca_state_mod::soca_state::logexpon()
374 subroutine soca_state_logtrans_c(c_key_self, c_trvars) bind(c,name='soca_state_logtrans_f90')
375  integer(c_int), intent(in) :: c_key_self
376  type(c_ptr), value, intent(in) :: c_trvars
377 
378  type(soca_state), pointer :: self
379  type(oops_variables) :: trvars
380 
381  trvars = oops_variables(c_trvars)
382 
383  call soca_state_registry%get(c_key_self,self)
384  call self%logexpon(transfunc="log", trvars=trvars)
385 
386 end subroutine soca_state_logtrans_c
387 
388 
389 ! ------------------------------------------------------------------------------
390 !> C++ interface for soca_state_mod::soca_state::logexpon()
391 subroutine soca_state_expontrans_c(c_key_self, c_trvars) bind(c,name='soca_state_expontrans_f90')
392  integer(c_int), intent(in) :: c_key_self
393  type(c_ptr), value, intent(in) :: c_trvars
394 
395  type(soca_state), pointer :: self
396  type(oops_variables) :: trvars
397 
398  trvars = oops_variables(c_trvars)
399 
400  call soca_state_registry%get(c_key_self,self)
401  call self%logexpon(transfunc="expon", trvars=trvars)
402 
403 end subroutine soca_state_expontrans_c
404 
405 end module soca_state_mod_c
C++ interfaces for soca_geom_mod::soca_geom.
type(registry_t), public soca_geom_registry
Linked list interface - defines registry_t type.
Geometry module.
Increment fields.
registry for soca_increment_mod::soca_increment instances for use in Fortran/C++ interface of soca_in...
type(registry_t), public soca_increment_registry
Linked list interface - defines registry_t type.
C++ interfaces for soca_state_mod::soca_state.
subroutine soca_state_rotate2north_c(c_key_self, c_uvars, c_vvars)
C++ interface for soca_state_mod::soca_state::rotate()
subroutine soca_state_sizes_c(c_key_fld, nx, ny, nzo, nf)
C++ interface to get soca_state_mod::soca_state dimensions sizes.
subroutine soca_state_rotate2grid_c(c_key_self, c_uvars, c_vvars)
C++ interface for soca_state_mod::soca_state::rotate()
subroutine soca_state_serial_size_c(c_key_self, c_key_geom, c_vec_size)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::serial_size()
subroutine soca_state_copy_c(c_key_self, c_key_rhs)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::copy()
subroutine soca_state_write_file_c(c_key_fld, c_conf, c_dt)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::write_rst()
subroutine soca_state_expontrans_c(c_key_self, c_trvars)
C++ interface for soca_state_mod::soca_state::logexpon()
subroutine soca_state_deserialize_c(c_key_self, c_key_geom, c_vec_size, c_vec, c_index)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::deserialize()
subroutine soca_state_change_resol_c(c_key_fld, c_key_rhs)
C++ interface for soca_state_mod::soca_state::convert()
subroutine soca_state_axpy_c(c_key_self, c_zz, c_key_rhs)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::axpy()
subroutine soca_state_logtrans_c(c_key_self, c_trvars)
C++ interface for soca_state_mod::soca_state::logexpon()
subroutine soca_state_create_c(c_key_self, c_key_geom, c_vars)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::create()
subroutine soca_state_add_incr_c(c_key_self, c_key_rhs)
C++ interface for soca_state_mod::soca_state::add_incr()
subroutine soca_state_rms_c(c_key_fld, prms)
C++ interface for soca_state_mod::soca_state RMS.
subroutine soca_state_gpnorm_c(c_key_fld, kf, pstat)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::gpnorm()
subroutine soca_state_delete_c(c_key_self)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::delete()
subroutine soca_state_read_file_c(c_key_fld, c_conf, c_dt)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::read()
subroutine soca_state_serialize_c(c_key_self, c_key_geom, c_vec_size, c_vec)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::serialize()
subroutine soca_state_zero_c(c_key_self)
C++ interface for soca_state_mod::soca_state version of soca_fields_mod::soca_fields::zeros()
State fields.
registry for soca_state_mod::soca_state instances for use in Fortran/C++ interfaces of soca_state_mod...
type(registry_t), public soca_state_registry
Linked list interface - defines registry_t type.
Geometry data structure.