FV3 Bundle
obsspace_mod.F90
Go to the documentation of this file.
1 !
2 ! (C) Copyright 2017 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 !> Fortran interface to ObsSpace.
8 
10 
11 use, intrinsic :: iso_c_binding
12 use kinds
13 use string_f_c_mod
14 
15 implicit none
16 
17 private
18 public obsspace_get_nobs
19 public obsspace_get_nlocs
20 public obsspace_get_db
21 public obsspace_put_db
22 
23 #include "obsspace_interface.f"
24 
25 !-------------------------------------------------------------------------------
26 
27 interface obsspace_get_db
28  module procedure obsspace_get_db_int32
29  module procedure obsspace_get_db_int64
30  module procedure obsspace_get_db_real32
31  module procedure obsspace_get_db_real64
32 end interface
33 
34 interface obsspace_put_db
35  module procedure obsspace_put_db_int32
36  module procedure obsspace_put_db_int64
37  module procedure obsspace_put_db_real32
38  module procedure obsspace_put_db_real64
39 end interface
40 
41 !-------------------------------------------------------------------------------
42 contains
43 !-------------------------------------------------------------------------------
44 
45 !> Return the number of observations
46 
47 integer function obsspace_get_nobs(c_dom)
48  implicit none
49  type(c_ptr), intent(in) :: c_dom
50 
52 end function obsspace_get_nobs
53 
54 !-------------------------------------------------------------------------------
55 
56 !> Return the number of observational locations
57 
58 integer function obsspace_get_nlocs(c_dom)
59  implicit none
60  type(c_ptr), intent(in) :: c_dom
61 
63 end function obsspace_get_nlocs
64 
65 !-------------------------------------------------------------------------------
66 
67 !> Get a variable from the ObsSapce database
68 
69 subroutine obsspace_get_db_int32(obss, group, vname, vect)
70  implicit none
71  type(c_ptr), value, intent(in) :: obss
72  character(len=*), intent(in) :: group
73  character(len=*), intent(in) :: vname
74  integer(c_int32_t), intent(inout) :: vect(:)
75 
76  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
77  integer(c_size_t) :: length
78 
79  ! Translate query from Fortran string to C++ char[].
80  call f_c_string(group, c_group)
81  call f_c_string(vname, c_vname)
82  length = size(vect)
83 
84  call c_obsspace_get_int32(obss, c_group, c_vname, length, vect)
85 
86  deallocate(c_group, c_vname)
87 
88 end subroutine obsspace_get_db_int32
89 
90 
91 !-------------------------------------------------------------------------------
92 
93 !> Get a variable from the ObsSapce database
94 
95 subroutine obsspace_get_db_int64(obss, group, vname, vect)
96  implicit none
97  type(c_ptr), value, intent(in) :: obss
98  character(len=*), intent(in) :: group
99  character(len=*), intent(in) :: vname
100  integer(c_int64_t), intent(inout) :: vect(:)
101 
102  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
103  integer(c_size_t) :: length
104 
105  ! Translate query from Fortran string to C++ char[].
106  call f_c_string(group, c_group)
107  call f_c_string(vname, c_vname)
108  length = size(vect)
109 
110  call c_obsspace_get_int64(obss, c_group, c_vname, length, vect)
111 
112  deallocate(c_group, c_vname)
113 
114 end subroutine obsspace_get_db_int64
115 
116 !-------------------------------------------------------------------------------
117 
118 !> Get a variable from the ObsSapce database
119 
120 subroutine obsspace_get_db_real32(obss, group, vname, vect)
121  implicit none
122  type(c_ptr), value, intent(in) :: obss
123  character(len=*), intent(in) :: group
124  character(len=*), intent(in) :: vname
125  real(c_float), intent(inout) :: vect(:)
126 
127  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
128  integer(c_size_t) :: length
129 
130  ! Translate query from Fortran string to C++ char[].
131  call f_c_string(group, c_group)
132  call f_c_string(vname, c_vname)
133  length = size(vect)
134 
135  call c_obsspace_get_real32(obss, c_group, c_vname, length, vect)
136 
137  deallocate(c_group, c_vname)
138 
139 end subroutine obsspace_get_db_real32
140 
141 !-------------------------------------------------------------------------------
142 
143 !> Get a variable from the ObsSapce database
144 
145 subroutine obsspace_get_db_real64(obss, group, vname, vect)
146  implicit none
147  type(c_ptr), value, intent(in) :: obss
148  character(len=*), intent(in) :: group
149  character(len=*), intent(in) :: vname
150  real(c_double), intent(inout) :: vect(:)
151 
152  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
153  integer(c_size_t) :: length
154 
155  ! Translate query from Fortran string to C++ char[].
156  call f_c_string(group, c_group)
157  call f_c_string(vname, c_vname)
158  length = size(vect)
159 
160  call c_obsspace_get_real64(obss, c_group, c_vname, length, vect)
161 
162  deallocate(c_group, c_vname)
163 
164 end subroutine obsspace_get_db_real64
165 
166 !-------------------------------------------------------------------------------
167 
168 !> Store a vector in ObsSpace database
169 
170 subroutine obsspace_put_db_int32(obss, group, vname, vect)
171  implicit none
172  type(c_ptr), intent(inout) :: obss
173  character(len=*), intent(in) :: group
174  character(len=*), intent(in) :: vname
175  integer(c_int32_t), intent(in) :: vect(:)
176 
177  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
178  integer(c_size_t) :: length
179 
180  ! Translate query from Fortran string to C++ char[].
181  call f_c_string(group, c_group)
182  call f_c_string(vname, c_vname)
183  length = size(vect)
184 
185  call c_obsspace_put_int32(obss, c_group, c_vname, length, vect)
186 
187  deallocate(c_group, c_vname)
188 
189 end subroutine obsspace_put_db_int32
190 
191 !-------------------------------------------------------------------------------
192 
193 !> Store a vector in ObsSpace database
194 
195 subroutine obsspace_put_db_int64(obss, group, vname, vect)
196  implicit none
197  type(c_ptr), intent(inout) :: obss
198  character(len=*), intent(in) :: group
199  character(len=*), intent(in) :: vname
200  integer(c_int64_t), intent(in) :: vect(:)
201 
202  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
203  integer(c_size_t) :: length
204 
205  ! Translate query from Fortran string to C++ char[].
206  call f_c_string(group, c_group)
207  call f_c_string(vname, c_vname)
208  length = size(vect)
209 
210  call c_obsspace_put_int64(obss, c_group, c_vname, length, vect)
211 
212  deallocate(c_group, c_vname)
213 
214 end subroutine obsspace_put_db_int64
215 
216 !-------------------------------------------------------------------------------
217 
218 !> Store a vector in ObsSpace database
219 
220 subroutine obsspace_put_db_real32(obss, group, vname, vect)
221  implicit none
222  type(c_ptr), intent(inout) :: obss
223  character(len=*), intent(in) :: group
224  character(len=*), intent(in) :: vname
225  real(c_float), intent(in) :: vect(:)
226 
227  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
228  integer(c_size_t) :: length
229 
230  ! Translate query from Fortran string to C++ char[].
231  call f_c_string(group, c_group)
232  call f_c_string(vname, c_vname)
233  length = size(vect)
234 
235  call c_obsspace_put_real32(obss, c_group, c_vname, length, vect)
236 
237  deallocate(c_group, c_vname)
238 
239 end subroutine obsspace_put_db_real32
240 
241 !-------------------------------------------------------------------------------
242 
243 !> Store a vector in ObsSpace database
244 
245 subroutine obsspace_put_db_real64(obss, group, vname, vect)
246  implicit none
247  type(c_ptr), intent(inout) :: obss
248  character(len=*), intent(in) :: group
249  character(len=*), intent(in) :: vname
250  real(c_double), intent(in) :: vect(:)
251 
252  character(kind=c_char,len=1), allocatable :: c_group(:), c_vname(:)
253  integer(c_size_t) :: length
254 
255  ! Translate query from Fortran string to C++ char[].
256  call f_c_string(group, c_group)
257  call f_c_string(vname, c_vname)
258  length = size(vect)
259 
260  call c_obsspace_put_real64(obss, c_group, c_vname, length, vect)
261 
262  deallocate(c_group, c_vname)
263 
264 end subroutine obsspace_put_db_real64
265 
266 !-------------------------------------------------------------------------------
267 
268 end module obsspace_mod
subroutine obsspace_put_db_int32(obss, group, vname, vect)
Store a vector in ObsSpace database.
subroutine obsspace_get_db_int32(obss, group, vname, vect)
Get a variable from the ObsSapce database.
subroutine obsspace_put_db_int64(obss, group, vname, vect)
Store a vector in ObsSpace database.
integer function, public obsspace_get_nobs(c_dom)
Return the number of observations.
subroutine obsspace_get_db_real32(obss, group, vname, vect)
Get a variable from the ObsSapce database.
Define interface for C++ ObsSpace code called from Fortran.
subroutine obsspace_put_db_real64(obss, group, vname, vect)
Store a vector in ObsSpace database.
subroutine obsspace_get_db_int64(obss, group, vname, vect)
Get a variable from the ObsSapce database.
subroutine obsspace_put_db_real32(obss, group, vname, vect)
Store a vector in ObsSpace database.
subroutine obsspace_get_db_real64(obss, group, vname, vect)
Get a variable from the ObsSapce database.
Fortran interface to ObsSpace.
Definition: obsspace_mod.F90:9
integer function, public obsspace_get_nlocs(c_dom)
Return the number of observational locations.