FV3-JEDI
fv3jedi_vc_geosrst2bkg_mod.f90
Go to the documentation of this file.
1 ! (C) Copyright 2018-2019 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 
7 
8 use iso_c_binding
9 use fckit_configuration_module, only: fckit_configuration
10 use datetime_mod
11 
12 use fckit_log_module, only : fckit_log
13 
17 
19 
20 use wind_vt_mod, only: a2d, d2a
24 
25 implicit none
26 private
27 
28 public :: fv3jedi_vc_geosrst2bkg
29 public :: create
30 public :: delete
31 public :: changevar
32 public :: changevarinverse
33 
35  logical :: do_wind
36  logical :: do_temp
37  logical :: do_pres
38  logical :: do_clds
39  character(len=4) :: pres_var
41 
42 ! ------------------------------------------------------------------------------
43 
44 contains
45 
46 ! ------------------------------------------------------------------------------
47 
48 subroutine create(self, geom, conf)
49 
50 implicit none
51 type(fv3jedi_vc_geosrst2bkg), intent(inout) :: self
52 type(fv3jedi_geom), intent(inout) :: geom
53 type(fckit_configuration), intent(in) :: conf
54 
55 character(len=:), allocatable :: str
56 
57 ! Select which variables to transform
58 ! -----------------------------------
59 
60 if( .not. conf%get('do_wind', self%do_wind) ) self%do_wind = .true.
61 
62 if( .not. conf%get('do_temperature', self%do_temp) ) self%do_temp = .true.
63 
64 if( .not. conf%get('do_pressure', self%do_pres) ) self%do_pres = .true.
65 
66 if( .not. conf%get('do_clouds', self%do_clds) ) self%do_clds = .true.
67 
68 self%pres_var = 'delp'
69 if( conf%has('pres_var') ) then
70  call conf%get_or_die("pres_var",str)
71  self%pres_var = str
72  deallocate(str)
73 endif
74 
75 end subroutine create
76 
77 ! ------------------------------------------------------------------------------
78 
79 subroutine delete(self)
80 
81 implicit none
82 type(fv3jedi_vc_geosrst2bkg), intent(inout) :: self
83 
84 end subroutine delete
85 
86 ! ------------------------------------------------------------------------------
87 
88 subroutine changevar(self,geom,xr,xb)
89 
90 implicit none
91 type(fv3jedi_vc_geosrst2bkg), intent(inout) :: self
92 type(fv3jedi_geom), intent(inout) :: geom
93 type(fv3jedi_state), intent(in) :: xr
94 type(fv3jedi_state), intent(inout) :: xb
95 
96 logical :: have_fractions
97 
98 ! Poitners to restart state
99 real(kind=kind_real), pointer :: ud(:,:,:)
100 real(kind=kind_real), pointer :: vd(:,:,:)
101 real(kind=kind_real), pointer :: pe(:,:,:)
102 real(kind=kind_real), pointer :: pkz(:,:,:)
103 real(kind=kind_real), pointer :: pt(:,:,:)
104 real(kind=kind_real), pointer :: qils(:,:,:)
105 real(kind=kind_real), pointer :: qicn(:,:,:)
106 real(kind=kind_real), pointer :: qlls(:,:,:)
107 real(kind=kind_real), pointer :: qlcn(:,:,:)
108 
109 ! Pointers to background state
110 real(kind=kind_real), pointer :: ua(:,:,:)
111 real(kind=kind_real), pointer :: va(:,:,:)
112 real(kind=kind_real), pointer :: delp(:,:,:)
113 real(kind=kind_real), pointer :: ps(:,:,:)
114 real(kind=kind_real), pointer :: t(:,:,:)
115 real(kind=kind_real), pointer :: qi(:,:,:)
116 real(kind=kind_real), pointer :: ql(:,:,:)
117 real(kind=kind_real), pointer :: qilsf(:,:,:)
118 real(kind=kind_real), pointer :: qicnf(:,:,:)
119 
120 real(kind=kind_real), allocatable :: pe_tmp(:,:,:)
121 real(kind=kind_real), target, allocatable :: pkz_tmp(:,:,:)
122 
123 ! Identity part of the change of variables
124 ! ----------------------------------------
125 call copy_subset(xr%fields,xb%fields)
126 
127 
128 ! D-Grid to A-Grid
129 ! ----------------
130 
131 if (self%do_wind) then
132 
133  call xr%get_field('ud', ud)
134  call xr%get_field('vd', vd)
135 
136  call xb%get_field('ua', ua)
137  call xb%get_field('va', va)
138 
139  call d2a(geom, ud, vd, ua, va)
140 
141 endif
142 
143 ! Potential temperature to temperature
144 ! ------------------------------------
145 if (self%do_temp) then
146 
147  call xr%get_field('pt', pt)
148  call xb%get_field('t' , t )
149 
150  if (.not. xr%has_field('pkz')) then
151  if (xr%has_field( 'delp')) then
152  call xr%get_field('delp' , delp )
153  allocate(pe_tmp(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz+1))
154  allocate(pkz_tmp(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz))
155  call delp_to_pe(geom, delp, pe_tmp)
156  call pe_to_pk(geom, pe, pkz_tmp)
157  pkz => pkz_tmp
158  else
159  call abor1_ftn("No way of getting pressures needed to convert temperature")
160  endif
161  else
162  call xr%get_field('pkz' , pkz )
163  endif
164 
165  call pt_to_t(geom, pkz, pt, t)
166 
167 endif
168 
169 ! Pressure to pressure thickness
170 ! ------------------------------
171 if (self%do_pres) then
172 
173  call xr%get_field('pe' , pe)
174 
175  if (xb%has_field( 'delp')) then
176  call xb%get_field('delp', delp)
177  call pe_to_delp(geom,pe,delp)
178  endif
179 
180  if (xb%has_field( 'ps')) then
181  call xb%get_field('ps' , ps)
182  ps(:,:,1) = pe(:,:,geom%npz+1)
183  endif
184 
185 endif
186 
187 ! Four species of cloud to two species
188 ! ------------------------------------
189 
190 if (self%do_clds) then
191 
192  call xr%get_field('qils', qils)
193  call xr%get_field('qicn', qicn)
194  call xr%get_field('qlls', qlls)
195  call xr%get_field('qlcn', qlcn)
196 
197  call xb%get_field('ice_wat', qi)
198  call xb%get_field('liq_wat', ql)
199 
200  have_fractions = .true.
201  if (.not.xb%has_field( 'qilsf')) have_fractions = .false.
202  if (.not.xb%has_field( 'qicnf')) have_fractions = .false.
203 
204  if (have_fractions) then
205  call xb%get_field('qilsf', qilsf)
206  call xb%get_field('qicnf', qicnf)
207  endif
208 
209  if (have_fractions) then
210  call q4_to_q2(geom,qils,qicn,qlls,qlcn,qi,ql,qilsf,qicnf)
211  else
212  call q4_to_q2(geom,qils,qicn,qlls,qlcn,qi,ql)
213  endif
214 
215 endif
216 
217 ! Copy calendar infomation
218 ! ------------------------
219 xb%calendar_type = xr%calendar_type
220 xb%date_init = xr%date_init
221 
222 end subroutine changevar
223 
224 ! ------------------------------------------------------------------------------
225 
226 subroutine changevarinverse(self,geom,xb,xr)
227 
228 implicit none
229 type(fv3jedi_vc_geosrst2bkg), intent(inout) :: self
230 type(fv3jedi_geom), intent(inout) :: geom
231 type(fv3jedi_state), intent(in) :: xb
232 type(fv3jedi_state), intent(inout) :: xr
233 
234 character(len=32) :: field_name
235 
236 ! Poitners to restart state
237 real(kind=kind_real), pointer :: ud(:,:,:)
238 real(kind=kind_real), pointer :: vd(:,:,:)
239 real(kind=kind_real), pointer :: pe(:,:,:)
240 real(kind=kind_real), pointer :: pkz(:,:,:)
241 real(kind=kind_real), pointer :: pt(:,:,:)
242 real(kind=kind_real), pointer :: qils(:,:,:)
243 real(kind=kind_real), pointer :: qicn(:,:,:)
244 real(kind=kind_real), pointer :: qlls(:,:,:)
245 real(kind=kind_real), pointer :: qlcn(:,:,:)
246 
247 ! Pointers to background state
248 real(kind=kind_real), pointer :: ua(:,:,:)
249 real(kind=kind_real), pointer :: va(:,:,:)
250 real(kind=kind_real), pointer :: delp(:,:,:)
251 real(kind=kind_real), pointer :: ps(:,:,:)
252 real(kind=kind_real), pointer :: t(:,:,:)
253 real(kind=kind_real), pointer :: qi(:,:,:)
254 real(kind=kind_real), pointer :: ql(:,:,:)
255 real(kind=kind_real), pointer :: qilsf(:,:,:)
256 real(kind=kind_real), pointer :: qicnf(:,:,:)
257 
258 ! Temporary arrays to hold pressures
259 real(kind=kind_real), allocatable :: pe_tmp(:,:,:)
260 real(kind=kind_real), allocatable :: pkz_tmp(:,:,:)
261 
262 
263 ! Identity part of the change of variables
264 ! ----------------------------------------
265 call copy_subset(xb%fields, xr%fields)
266 
267 ! A-Grid to D-Grid
268 ! ----------------
269 
270 if (self%do_wind) then
271 
272  call xr%get_field('ud', ud)
273  call xr%get_field('vd', vd)
274 
275  call xb%get_field('ua', ua)
276  call xb%get_field('va', va)
277 
278  call a2d(geom, ua, va, ud, vd)
279 
280 endif
281 
282 ! Pressure to pressure thickness
283 ! ------------------------------
284 if (self%do_pres) then
285 
286  call xr%get_field('pe' , pe )
287  call xr%get_field('pkz' , pkz )
288 
289  if (trim(self%pres_var) == 'delp') then
290 
291  call xb%get_field('delp' , delp )
292  call delp_to_pe(geom, delp, pe)
293 
294  elseif (trim(self%pres_var) == 'ps') then
295 
296  call xb%get_field('ps' , ps )
297 
298  call ps_to_pe(geom, ps, pe)
299 
300  else
301 
302  call abor1_ftn("fv3jedi_vc_geosrst2bkg_mod.changevarinverse, must select a variable to set pe from. pres_var: ps or delp")
303 
304  endif
305 
306  ! Get p to the kappa
307  call pe_to_pk(geom, pe, pkz)
308 
309 endif
310 
311 ! Temperature to potential temperature
312 ! ------------------------------------
313 if (self%do_temp) then
314 
315  call xr%get_field('pt', pt)
316  call xb%get_field('t' , t )
317 
318  if (.not. self%do_pres) then
319 
320  allocate(pe_tmp(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz+1))
321  allocate(pkz_tmp(geom%isc:geom%iec,geom%jsc:geom%jec,1:geom%npz))
322 
323  call xb%get_field('delp' , delp )
324 
325  call delp_to_pe(geom, delp, pe_tmp)
326  call pe_to_pk(geom, pe_tmp, pkz_tmp)
327 
328  call t_to_pt(geom, pkz_tmp, t, pt)
329 
330  deallocate(pe_tmp,pkz_tmp)
331 
332  else
333 
334  call t_to_pt(geom, pkz, t, pt)
335 
336  endif
337 
338 endif
339 
340 ! Four species of cloud to two species
341 ! ------------------------------------
342 
343 if (self%do_clds) then
344 
345  call xr%get_field('qils', qils)
346  call xr%get_field('qicn', qicn)
347  call xr%get_field('qlls', qlls)
348  call xr%get_field('qlcn', qlcn)
349 
350  call xb%get_field('ice_wat', qi)
351  call xb%get_field('liq_wat', ql)
352  call xb%get_field('qilsf', qilsf)
353  call xb%get_field('qicnf', qicnf)
354 
355  call q2_to_q4(geom, qi, ql, qilsf, qicnf, qils, qicn, qlls, qlcn)
356 
357 endif
358 
359 ! Copy calendar infomation
360 ! ------------------------
361 xr%calendar_type = xb%calendar_type
362 xr%date_init = xb%date_init
363 
364 end subroutine changevarinverse
365 
366 ! ------------------------------------------------------------------------------
367 
fv3jedi_state_mod::fv3jedi_state
Fortran derived type to hold FV3JEDI state.
Definition: fv3jedi_state_mod.F90:30
fv3jedi_field_mod
Definition: fv3jedi_field_mod.f90:6
moisture_vt_mod
Definition: moisture_variables_mod.f90:6
pressure_vt_mod::delp_to_pe
subroutine, public delp_to_pe(geom, delp, pe)
Definition: pressure_variables_mod.f90:114
fv3jedi_vc_geosrst2bkg_mod::delete
subroutine, public delete(self)
Definition: fv3jedi_vc_geosrst2bkg_mod.f90:80
moisture_vt_mod::q2_to_q4
subroutine, public q2_to_q4(geom, qi, ql, qilsf, qicnf, qils, qicn, qlls, qlcn)
Definition: moisture_variables_mod.f90:419
fv3jedi_state_mod
Definition: fv3jedi_state_mod.F90:6
fv3jedi_field_mod::copy_subset
subroutine, public copy_subset(field_in, field_ou, not_copied)
Definition: fv3jedi_field_mod.f90:236
fv3jedi_geom_mod
Fortran module handling geometry for the FV3 model.
Definition: fv3jedi_geom_mod.f90:8
fv3jedi_geom_mod::fv3jedi_geom
Fortran derived type to hold geometry data for the FV3JEDI model.
Definition: fv3jedi_geom_mod.f90:46
pressure_vt_mod::pe_to_pk
subroutine, public pe_to_pk(geom, pe, pk)
Definition: pressure_variables_mod.f90:139
fv3jedi_vc_geosrst2bkg_mod::changevarinverse
subroutine, public changevarinverse(self, geom, xb, xr)
Definition: fv3jedi_vc_geosrst2bkg_mod.f90:227
wind_vt_mod
Definition: wind_variables_mod.f90:6
temperature_vt_mod
Definition: temperature_variables_mod.f90:6
fv3jedi_vc_geosrst2bkg_mod::fv3jedi_vc_geosrst2bkg
Definition: fv3jedi_vc_geosrst2bkg_mod.f90:34
fv3jedi_vc_geosrst2bkg_mod::changevar
subroutine, public changevar(self, geom, xr, xb)
Definition: fv3jedi_vc_geosrst2bkg_mod.f90:89
pressure_vt_mod
Definition: pressure_variables_mod.f90:6
temperature_vt_mod::t_to_pt
subroutine, public t_to_pt(geom, pkz, t, pt)
Definition: temperature_variables_mod.f90:179
fv3jedi_kinds_mod::kind_real
integer, parameter, public kind_real
Definition: fv3jedi_kinds_mod.f90:14
temperature_vt_mod::pt_to_t
subroutine, public pt_to_t(geom, pkz, pt, t)
Definition: temperature_variables_mod.f90:131
moisture_vt_mod::q4_to_q2
subroutine, public q4_to_q2(geom, qils, qicn, qlls, qlcn, qi, ql, qilsf, qicnf)
Definition: moisture_variables_mod.f90:387
wind_vt_mod::d2a
subroutine, public d2a(geom, u_comp, v_comp, ua_comp, va_comp)
Definition: wind_variables_mod.f90:1456
wind_vt_mod::a2d
subroutine, public a2d(geom, ua, va, ud, vd)
Definition: wind_variables_mod.f90:1023
fv3jedi_vc_geosrst2bkg_mod::create
subroutine, public create(self, geom, conf)
Definition: fv3jedi_vc_geosrst2bkg_mod.f90:49
fv3jedi_vc_geosrst2bkg_mod
Definition: fv3jedi_vc_geosrst2bkg_mod.f90:6
pressure_vt_mod::ps_to_pe
subroutine, public ps_to_pe(geom, ps, pe)
Definition: pressure_variables_mod.f90:171
fv3jedi_kinds_mod
Definition: fv3jedi_kinds_mod.f90:6
pressure_vt_mod::pe_to_delp
subroutine, public pe_to_delp(geom, pe, delp)
Definition: pressure_variables_mod.f90:90