UFO
ufo_gnssro_bndropp2d_tlad_mod_stub.F90
Go to the documentation of this file.
1 ! (C) Copyright 2017-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 !> Stubbed Fortran module for gnssro bending angle ropp2d tangent linear and adjoint
7 !> following the ROPP (2018 Aug) implementation
8 
10 
11 use fckit_configuration_module, only: fckit_configuration
12 use kinds
13 use ufo_vars_mod
18 use obsspace_mod
20 use missing_values_mod
21 use fckit_log_module, only : fckit_log
22 
23 integer, parameter :: max_string=800
24 
25 !> Fortran derived type for gnssro trajectory
27  private
28  integer :: nval, nlocs
29  real(kind_real), allocatable :: prs(:,:), t(:,:), q(:,:), gph(:,:), gph_sfc(:,:)
30  integer :: n_horiz ! 2d points along ray path
31  integer :: iflip ! geoval ascending order flag
32  type(gnssro_conf) :: roconf ! ro configuration
33  real(kind_real), allocatable :: obslon2d(:), obslat2d(:) !2d locations - nobs*n_horiz
34  contains
35  procedure :: setup => ufo_gnssro_bndropp2d_tlad_setup
36  procedure :: delete => ufo_gnssro_bndropp2d_tlad_delete
37  procedure :: settraj => ufo_gnssro_bndropp2d_tlad_settraj
38  procedure :: simobs_tl => ufo_gnssro_bndropp2d_simobs_tl
39  procedure :: simobs_ad => ufo_gnssro_bndropp2d_simobs_ad
41 
42 contains
43 
44 ! ------------------------------------------------------------------------------
45 subroutine ufo_gnssro_bndropp2d_tlad_setup(self, f_conf)
46  implicit none
47  class(ufo_gnssro_bndropp2d_tlad), intent(inout) :: self
48  type(fckit_configuration), intent(in) :: f_conf
49 
50  call gnssro_conf_setup(self%roconf,f_conf)
51 
53 
54 ! ------------------------------------------------------------------------------
55 subroutine ufo_gnssro_bndropp2d_tlad_settraj(self, geovals, obss)
56 
57  implicit none
58  class(ufo_gnssro_bndropp2d_tlad), intent(inout) :: self
59  type(ufo_geovals), intent(in) :: geovals
60  type(c_ptr), value, intent(in) :: obss
61  character(len=*), parameter :: myname_="ufo_gnssro_bndropp2d_tlad_settraj"
62  character(max_string) :: err_msg
63  type(ufo_geoval), pointer :: t, q, prs, gph, gph_sfc
64  integer :: iobs
65 
66  write(err_msg,*) "TRACE: ufo_gnssro_bndropp2d_tlad_settraj: begin"
67  call fckit_log%info(err_msg)
68 
69 ! get model state variables from geovals
70  call ufo_geovals_get_var(geovals, var_ts, t) ! temperature
71  call ufo_geovals_get_var(geovals, var_q, q) ! specific humidity
72  call ufo_geovals_get_var(geovals, var_prs, prs) ! pressure
73  call ufo_geovals_get_var(geovals, var_z, gph) ! geopotential height
74 
75  call self%delete()
76 
77 ! Keep copy of dimensions
78  self%nval = prs%nval
79  self%nlocs = obsspace_get_nlocs(obss)
80 
81  allocate(self%t(self%nval,self%nlocs))
82  allocate(self%q(self%nval,self%nlocs))
83  allocate(self%prs(self%nval,self%nlocs))
84  allocate(self%gph(self%nval,self%nlocs))
85 
86 ! allocate
87  self%gph = gph%vals
88  self%t = t%vals
89  self%q = q%vals
90  self%prs = prs%vals
91 
92  self%ltraj = .true.
93 
95 
96 ! ------------------------------------------------------------------------------
97 ! ------------------------------------------------------------------------------
98 subroutine ufo_gnssro_bndropp2d_simobs_tl(self, geovals, hofx, obss)
99 
100  implicit none
101  class(ufo_gnssro_bndropp2d_tlad), intent(in) :: self
102  type(ufo_geovals), intent(in) :: geovals ! perturbed quantities
103  real(kind_real), intent(inout) :: hofx(:)
104  type(c_ptr), value, intent(in) :: obss
105 
106  integer :: iobs,nlev, nlocs, nvprof
107 
108  character(len=*), parameter :: myname_="ufo_gnssro_bndropp2d_simobs_tl"
109  character(max_string) :: err_msg
110  type(ufo_geoval), pointer :: t_d, q_d, prs_d
111 
112 ! hack - set local geopotential height to zero for ropp routines
113  real(kind_real), allocatable :: gph_d_zero(:)
114  real(kind_real) :: gph_sfc_d_zero
115  real(kind_real), allocatable :: obslat(:), obslon(:), obsimpp(:), obslocr(:), obsgeoid(:)
116 ! hack - set local geopotential height to zero for ropp routines
117  integer :: n_horiz
118 
119  n_horiz = self%roconf%n_horiz
120 
121  write(err_msg,*) "TRACE: ufo_gnssro_bndropp2d_simobs_tl_stub: begin"
122  call fckit_log%info(err_msg)
123 
124 ! check if trajectory was set
125  if (.not. self%ltraj) then
126  write(err_msg,*) myname_, ' trajectory wasnt set!'
127  call abor1_ftn(err_msg)
128  endif
129 
130 ! check if nlocs is consistent in geovals & hofx
131  if (geovals%nlocs /= size(hofx)*n_horiz) then
132  write(err_msg,*) myname_, ' error: nlocs inconsistent!'
133  call abor1_ftn(err_msg)
134  endif
135 
136 ! get variables from geovals
137  call ufo_geovals_get_var(geovals, var_ts, t_d) ! temperature
138  call ufo_geovals_get_var(geovals, var_q, q_d) ! specific humidity
139  call ufo_geovals_get_var(geovals, var_prs, prs_d) ! pressure
140 
141  nlev = self%nval
142  nlocs = self%nlocs ! number of observations
143 
144  allocate(gph_d_zero(nlev))
145  gph_d_zero = 0.0
146  gph_sfc_d_zero = 0.0
147 
148 ! set obs space struture
149  allocate(obslon(nlocs))
150  allocate(obslat(nlocs))
151  allocate(obsimpp(nlocs))
152  allocate(obslocr(nlocs))
153  allocate(obsgeoid(nlocs))
154  call obsspace_get_db(obss, "MetaData", "longitude", obslon)
155  call obsspace_get_db(obss, "MetaData", "latitude", obslat)
156  call obsspace_get_db(obss, "MetaData", "impact_parameter", obsimpp)
157  call obsspace_get_db(obss, "MetaData", "earth_radius_of_curvature", obslocr)
158  call obsspace_get_db(obss, "MetaData", "geoid_height_above_reference_ellipsoid", obsgeoid)
159 
160  nvprof = 1 ! no. of bending angles in profile
161 
162 ! tidy up - deallocate obsspace structures
163  deallocate(obslat)
164  deallocate(obslon)
165  deallocate(obsimpp)
166  deallocate(obslocr)
167  deallocate(obsgeoid)
168 
169  write(err_msg,*) "TRACE: ufo_gnssro_bndropp2d_simobs_tl_stub: complete"
170  call fckit_log%info(err_msg)
171 
172  return
173 
174 end subroutine ufo_gnssro_bndropp2d_simobs_tl
175 
176 ! ------------------------------------------------------------------------------
177 ! ------------------------------------------------------------------------------
178 subroutine ufo_gnssro_bndropp2d_simobs_ad(self, geovals, hofx, obss)
179 
180  implicit none
181  class(ufo_gnssro_bndropp2d_tlad), intent(in) :: self
182  type(ufo_geovals), intent(inout) :: geovals ! perturbed quantities
183  real(kind_real), intent(in) :: hofx(:)
184  type(c_ptr), value, intent(in) :: obss
185  real(c_double) :: missing
186 
187  type(ufo_geoval), pointer :: t_d, q_d, prs_d
188 ! set local geopotential height to zero for ropp routines
189  real(kind_real), parameter :: gph_sfc_d_zero = 0.0
190  real(kind_real), allocatable :: gph_d_zero(:)
191 
192  real(kind_real), allocatable :: obslat(:), obslon(:), obsimpp(:), obslocr(:), obsgeoid(:)
193  integer :: iobs,nlev, nlocs, nvprof
194  integer :: n_horiz
195  character(len=*), parameter :: myname_="ufo_gnssro_bndropp2d_simobs_ad"
196  character(max_string) :: err_msg
197 
198 
199  write(err_msg,*) "TRACE: ufo_gnssro_bndropp2d_simobs_ad_stub: begin"
200  call fckit_log%info(err_msg)
201 
202 ! check if trajectory was set
203  if (.not. self%ltraj) then
204  write(err_msg,*) myname_, ' trajectory wasnt set!'
205  call abor1_ftn(err_msg)
206  endif
207 
208  n_horiz = self%roconf%n_horiz
209 
210 ! check if nlocs is consistent in geovals & hofx
211  if (geovals%nlocs /= size(hofx)*n_horiz) then
212  write(err_msg,*) myname_, ' error: nlocs inconsistent!'
213  call abor1_ftn(err_msg)
214  endif
215 
216 ! get variables from geovals
217  call ufo_geovals_get_var(geovals, var_ts, t_d) ! temperature
218  call ufo_geovals_get_var(geovals, var_q, q_d) ! specific humidity
219  call ufo_geovals_get_var(geovals, var_prs, prs_d) ! pressure
220 
221  nlev = self%nval
222  nlocs = self%nlocs
223 
224  allocate(gph_d_zero(nlev))
225  gph_d_zero = 0.0
226 
227 ! set obs space struture
228  allocate(obslon(nlocs))
229  allocate(obslat(nlocs))
230  allocate(obsimpp(nlocs))
231  allocate(obslocr(nlocs))
232  allocate(obsgeoid(nlocs))
233 
234  call obsspace_get_db(obss, "MetaData", "longitude", obslon)
235  call obsspace_get_db(obss, "MetaData", "latitude", obslat)
236  call obsspace_get_db(obss, "MetaData", "impact_parameter", obsimpp)
237  call obsspace_get_db(obss, "MetaData", "earth_radius_of_curvature", obslocr)
238  call obsspace_get_db(obss, "MetaData", "geoid_height_above_reference_ellipsoid", obsgeoid)
239 
240  missing = missing_value(missing)
241 
242 ! tidy up - deallocate obsspace structures
243  deallocate(obslat)
244  deallocate(obslon)
245  deallocate(obsimpp)
246  deallocate(obslocr)
247  deallocate(obsgeoid)
248  deallocate(gph_d_zero)
249 
250  write(err_msg,*) "TRACE: ufo_gnssro_bndropp2d_simobs_ad_stub: complete"
251  call fckit_log%info(err_msg)
252 
253  return
254 
255 end subroutine ufo_gnssro_bndropp2d_simobs_ad
256 
257 !-------------------------------------------------------------------------
258 !-------------------------------------------------------------------------
259 subroutine ufo_gnssro_bndropp2d_tlad_delete(self)
260 
261  implicit none
262  class(ufo_gnssro_bndropp2d_tlad), intent(inout) :: self
263  character(len=*), parameter :: myname_="ufo_gnssro_bndropp_tlad_delete"
264 
265  self%nval = 0
266  if (allocated(self%prs)) deallocate(self%prs)
267  if (allocated(self%t)) deallocate(self%t)
268  if (allocated(self%q)) deallocate(self%q)
269  if (allocated(self%gph)) deallocate(self%gph)
270 ! if (allocated(self%gph_sfc)) deallocate(self%gph_sfc)
271 
272  self%ltraj = .false.
273 
275 
276 !-------------------------------------------------------------------------
277 
subroutine, public gnssro_conf_setup(roconf, f_conf)
type(registry_t), public ufo_geovals_registry
Linked list interface - defines registry_t type.
subroutine, public ufo_geovals_get_var(self, varname, geoval)
Fortran module for gnssro bending angle ropp2d tangent linear and adjoint following the ROPP (2018 Au...
subroutine ufo_gnssro_bndropp2d_simobs_ad(self, geovals, hofx, obss)
subroutine ufo_gnssro_bndropp2d_tlad_settraj(self, geovals, obss)
subroutine ufo_gnssro_bndropp2d_simobs_tl(self, geovals, hofx, obss)
subroutine ufo_gnssro_bndropp2d_tlad_setup(self, f_conf)
character(len=maxvarlen), parameter, public var_prs
character(len=maxvarlen), parameter, public var_q
character(len=maxvarlen), parameter, public var_z
character(len=maxvarlen), parameter, public var_ts
Fortran module to perform linear interpolation.
Definition: vert_interp.F90:8
type to hold interpolated field for one variable, one observation
type to hold interpolated fields required by the obs operators