FV3-JEDI
fv3jedi_varcha_a2m_mod.f90
Go to the documentation of this file.
1 ! (C) Copyright 2018-2020 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 ! iso
9 use iso_c_binding
10 
11 ! fckit
12 use fckit_configuration_module, only: fckit_configuration
13 
14 ! oops
15 use datetime_mod
16 
17 ! fv3-jedi
24 use wind_vt_mod, only: a2d, d2a
25 
26 implicit none
27 private
28 public :: fv3jedi_varcha_a2m
29 
31  character(len=10) :: filetype !IO type
32  type(fv3jedi_io_gfs) :: gfs
33  type(fv3jedi_io_geos) :: geos
34  contains
35  procedure :: create
36  procedure :: delete
37  procedure :: changevar
38  procedure :: changevarinverse
39 end type fv3jedi_varcha_a2m
40 
41 ! --------------------------------------------------------------------------------------------------
42 
43 contains
44 
45 ! --------------------------------------------------------------------------------------------------
46 
47 subroutine create(self, geom, conf)
48 
49 implicit none
50 class(fv3jedi_varcha_a2m), intent(inout) :: self
51 type(fv3jedi_geom), intent(inout) :: geom
52 type(fckit_configuration), intent(in) :: conf
53 
54 character(len=:), allocatable :: str
55 
56 ! Get IO type to use
57 call conf%get_or_die("filetype", str)
58 self%filetype = str
59 
60 ! Setup IO from config
61 if (trim(self%filetype) == 'gfs') then
62  call self%gfs%setup_conf(conf)
63 elseif (trim(self%filetype) == 'geos') then
64  call self%geos%setup_conf(geom, conf)
65 else
66  call abor1_ftn("fv3jedi_varcha_a2m_mod: filetype must be geos or gfs")
67 endif
68 
69 end subroutine create
70 
71 ! --------------------------------------------------------------------------------------------------
72 
73 subroutine delete(self)
74 
75 implicit none
76 class(fv3jedi_varcha_a2m), intent(inout) :: self
77 
78 if (trim(self%filetype) == 'geos') call self%geos%delete()
79 
80 end subroutine delete
81 
82 ! --------------------------------------------------------------------------------------------------
83 
84 subroutine changevar(self,geom,xana,xmod,vdt)
85 
86 implicit none
87 class(fv3jedi_varcha_a2m), intent(inout) :: self
88 type(fv3jedi_geom), intent(inout) :: geom
89 type(fv3jedi_state), intent(in) :: xana
90 type(fv3jedi_state), intent(inout) :: xmod
91 type(datetime), intent(inout) :: vdt
92 
93 integer :: index_ana, index_mod, index_ana_found
94 integer :: k
95 logical :: failed
96 
97 real(kind=kind_real), pointer, dimension(:,:,:) :: xana_ua
98 real(kind=kind_real), pointer, dimension(:,:,:) :: xana_va
99 real(kind=kind_real), pointer, dimension(:,:,:) :: xana_ps
100 
101 real(kind=kind_real), pointer, dimension(:,:,:) :: xmod_ud
102 real(kind=kind_real), pointer, dimension(:,:,:) :: xmod_vd
103 real(kind=kind_real), pointer, dimension(:,:,:) :: xmod_delp
104 
105 do index_mod = 1, xmod%nf
106 
107  index_ana_found = -1
108  failed = .true.
109 
110  !Check analysis for presence of field
111  do index_ana = 1, xana%nf
112  if (xmod%fields(index_mod)%fv3jedi_name == xana%fields(index_ana)%fv3jedi_name) then
113  index_ana_found = index_ana
114  exit
115  endif
116  enddo
117 
118  if (index_ana_found >= 0) then
119 
120  !OK, direct copy
121  xmod%fields(index_mod)%array = xana%fields(index_ana_found)%array
122  failed = .false.
123  if (xmod%f_comm%rank() == 0) write(*,"(A, A10, A, A10)") &
124  "A2M ChangeVar: analysis state "//xana%fields(index_ana_found)%fv3jedi_name(1:10)&
125  //" => model state "//xmod%fields(index_mod)%fv3jedi_name(1:10)
126 
127  elseif (xmod%fields(index_mod)%fv3jedi_name == 'ud') then
128 
129  !Special case: A-grid analysis, D-Grid model
130  if (xana%has_field('ua')) then
131  call xana%get_field('ua', xana_ua)
132  call xana%get_field('va', xana_va)
133  call xmod%get_field('ud', xmod_ud)
134  call xmod%get_field('vd', xmod_vd)
135  call a2d(geom, xana_ua, xana_va, xmod_ud, xmod_vd)
136  xmod_ud(:,geom%jec+1,:) = 0.0_kind_real
137  xmod_vd(geom%iec+1,:,:) = 0.0_kind_real
138  failed = .false.
139  if (xmod%f_comm%rank() == 0) write(*,"(A)") &
140  "A2M ChangeVar: analysis state ua => model state ud"
141  endif
142 
143  elseif (xmod%fields(index_mod)%fv3jedi_name == 'vd') then
144 
145  !Special case: A-grid analysis, D-Grid model
146  if (xana%has_field('ua')) then
147  !Already done above
148  failed = .false.
149  if (xmod%f_comm%rank() == 0) write(*,"(A)") &
150  "A2M ChangeVar: analysis state va => model state vd"
151  endif
152 
153  elseif (xmod%fields(index_mod)%fv3jedi_name == 'delp') then
154 
155  !Special case: ps in analysis, delp in model
156  if (xana%has_field('ps')) then
157  call xana%get_field('ps', xana_ps)
158  call xmod%get_field('delp', xmod_delp)
159  do k = 1,geom%npz
160  xmod_delp(:,:,k) = (geom%ak(k+1)-geom%ak(k)) + (geom%bk(k+1)-geom%bk(k))*xana_ps(:,:,1)
161  enddo
162  failed = .false.
163  if (xmod%f_comm%rank() == 0) write(*,"(A)") &
164  "A2M ChangeVar: analysis state ps => model state delp"
165  endif
166 
167  endif
168 
169  if (failed) then
170 
171  if (xmod%f_comm%rank() == 0) write(*,"(A)") &
172  "Found no way of getting "//trim(xmod%fields(index_mod)%fv3jedi_name)//" from the analysis state."//&
173  "Attempting to read from file"
174 
175  if (trim(self%filetype) == 'gfs') then
176  call self%gfs%setup_date(vdt)
177  call self%gfs%read_fields( geom, xmod%fields(index_mod:index_mod) )
178  elseif (trim(self%filetype) == 'geos') then
179  call self%geos%setup_date(vdt)
180  call self%geos%read_fields(geom, xmod%fields(index_mod:index_mod))
181  endif
182 
183  endif
184 
185 enddo
186 
187 ! Copy calendar infomation
188 xmod%calendar_type = xana%calendar_type
189 xmod%date_init = xana%date_init
190 
191 end subroutine changevar
192 
193 ! --------------------------------------------------------------------------------------------------
194 
195 subroutine changevarinverse(self,geom,xmod,xana,vdt)
196 
197 implicit none
198 class(fv3jedi_varcha_a2m), intent(inout) :: self
199 type(fv3jedi_geom), intent(inout) :: geom
200 type(fv3jedi_state), intent(in) :: xmod
201 type(fv3jedi_state), intent(inout) :: xana
202 type(datetime), intent(inout) :: vdt
203 
204 integer :: index_ana, index_mod, index_mod_found
205 logical :: failed
206 
207 real(kind=kind_real), pointer, dimension(:,:,:) :: xana_ua
208 real(kind=kind_real), pointer, dimension(:,:,:) :: xana_va
209 real(kind=kind_real), pointer, dimension(:,:,:) :: xana_ps
210 
211 real(kind=kind_real), pointer, dimension(:,:,:) :: xmod_ud
212 real(kind=kind_real), pointer, dimension(:,:,:) :: xmod_vd
213 real(kind=kind_real), pointer, dimension(:,:,:) :: xmod_delp
214 
215 do index_ana = 1, xana%nf
216 
217  index_mod_found = -1
218  failed = .true.
219 
220  !Check analysis for presence of field
221  do index_mod = 1, xmod%nf
222  if (xana%fields(index_ana)%fv3jedi_name == xmod%fields(index_mod)%fv3jedi_name) then
223  index_mod_found = index_mod
224  exit
225  endif
226  enddo
227 
228  if (index_mod_found >= 0) then
229 
230  !OK, direct copy
231  failed = .false.
232  xana%fields(index_ana)%array = xmod%fields(index_mod_found)%array
233  if (xana%f_comm%rank() == 0) write(*,"(A, A10, A, A10)") &
234  "A2M ChangeVarInverse: model state "//xmod%fields(index_mod_found)%fv3jedi_name(1:10)&
235  //" => analysis state "//xana%fields(index_ana)%fv3jedi_name(1:10)
236 
237  elseif (xana%fields(index_ana)%fv3jedi_name == 'ua') then
238 
239  !Special case: A-grid analysis, D-Grid model
240  if (xmod%has_field('ud')) then
241  call xana%get_field('ua', xana_ua)
242  call xana%get_field('va', xana_va)
243  call xmod%get_field('ud', xmod_ud)
244  call xmod%get_field('vd', xmod_vd)
245  xmod_ud(:,geom%jec+1,:) = 0.0_kind_real
246  xmod_vd(geom%iec+1,:,:) = 0.0_kind_real
247  call d2a(geom, xmod_ud, xmod_vd, xana_ua, xana_va)
248  failed = .false.
249  if (xana%f_comm%rank() == 0) write(*,"(A)") &
250  "A2M ChangeVarInverse: model state ud => analysis state ua"
251  endif
252 
253  elseif (xana%fields(index_ana)%fv3jedi_name == 'va') then
254 
255  !Special case: A-grid analysis, D-Grid model
256  if (xmod%has_field('ud')) then
257  !Already done above
258  failed = .false.
259  if (xana%f_comm%rank() == 0) write(*,"(A)") &
260  "A2M ChangeVarInverse: model state vd => analysis state va"
261  endif
262 
263  elseif (xana%fields(index_ana)%fv3jedi_name == 'ps') then
264 
265  !Special case: ps in analysis, delp in model
266  if (xmod%has_field('delp')) then
267  call xana%get_field('ps', xana_ps)
268  call xmod%get_field('delp', xmod_delp)
269  xana_ps(:,:,1) = sum(xmod_delp,3)
270  failed = .false.
271  if (xana%f_comm%rank() == 0) write(*,"(A)") &
272  "A2M ChangeVarInverse: model state delp => analysis state ps"
273  endif
274 
275  endif
276 
277  if (failed) call abor1_ftn("fv3jedi_linvarcha_a2m_mod.changevarinverse: found no way of getting "//&
278  trim(xana%fields(index_ana)%fv3jedi_name)//" from the model state" )
279 
280 enddo
281 
282 ! Copy calendar infomation
283 xana%calendar_type = xmod%calendar_type
284 xana%date_init = xmod%date_init
285 
286 end subroutine changevarinverse
287 
288 ! --------------------------------------------------------------------------------------------------
289 
290 end module fv3jedi_varcha_a2m_mod
fv3jedi_varcha_a2m_mod::fv3jedi_varcha_a2m
Definition: fv3jedi_varcha_a2m_mod.f90:30
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
fv3jedi_varcha_a2m_mod::create
subroutine create(self, geom, conf)
Definition: fv3jedi_varcha_a2m_mod.f90:48
fv3jedi_varcha_a2m_mod::delete
subroutine delete(self)
Definition: fv3jedi_varcha_a2m_mod.f90:74
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_varcha_a2m_mod::changevarinverse
subroutine changevarinverse(self, geom, xmod, xana, vdt)
Definition: fv3jedi_varcha_a2m_mod.f90:196
fv3jedi_geom_mod
Fortran module handling geometry for the FV3 model.
Definition: fv3jedi_geom_mod.f90:8
fv3jedi_io_gfs_mod
Definition: fv3jedi_io_gfs_mod.f90:1
fv3jedi_geom_mod::fv3jedi_geom
Fortran derived type to hold geometry data for the FV3JEDI model.
Definition: fv3jedi_geom_mod.f90:46
wind_vt_mod
Definition: wind_variables_mod.f90:6
fv3jedi_io_gfs_mod::fv3jedi_io_gfs
Definition: fv3jedi_io_gfs_mod.f90:35
fv3jedi_varcha_a2m_mod::changevar
subroutine changevar(self, geom, xana, xmod, vdt)
Definition: fv3jedi_varcha_a2m_mod.f90:85
fv3jedi_kinds_mod::kind_real
integer, parameter, public kind_real
Definition: fv3jedi_kinds_mod.f90:14
fv3jedi_io_geos_mod
Definition: fv3jedi_io_geos_mod.f90:6
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_varcha_a2m_mod
Definition: fv3jedi_varcha_a2m_mod.f90:6
fv3jedi_io_geos_mod::fv3jedi_io_geos
Definition: fv3jedi_io_geos_mod.f90:36
fv3jedi_kinds_mod
Definition: fv3jedi_kinds_mod.f90:6