1 subroutine da_setup_flow_predictors( ix, jy, kz, ne, ep, its, ite, jts, jte, kts, kte )
3 !------------------------------------------------------------------------------
4 ! Purpose: Setup structures for flow-dependent information and read it in.
5 !------------------------------------------------------------------------------
9 integer, intent(in) :: ix, jy, kz ! EP grid dimensions.
10 integer, intent(in) :: its, jts, kts ! Tile start.
11 integer, intent(in) :: ite, jte, kte ! Tile end.
12 integer, intent(in) :: ne ! Ensemble size.
13 type (ep_type), intent(inout):: ep ! Flow-dependent info.
15 character(len=4), allocatable :: ep_dir_name(:) ! Input ep dir name
16 character*10 :: ce ! Member index -> character.
17 character(len=filename_len) :: filename ! Input filename.
18 character*10 :: var(1:5) ! Variable name.
19 integer :: ni, nj, nk ! Grid dimensions.
20 integer :: e ! Loop counter
21 logical :: ldum1, ldum2,nkdum ! Dummy.
22 real*4, allocatable :: temp3d_r4(:,:,:) ! Temporary, real*4 array
23 real*4, allocatable :: temp2d_r4(:,:) ! Temporary, real*4 array
24 real, allocatable :: temp3d(:,:,:) ! Temporary array
25 real, allocatable :: temp2d(:,:) ! Temporary array
27 real :: ens_scaling_inv ! Ensemble scaling of perturbations.
29 integer :: ep_unit,t,te,nte,it,ie
31 integer, parameter :: is_r8 = 1
32 integer, parameter :: is_r4 = 11
34 if (trace_use) call da_trace_entry("da_setup_flow_predictors")
36 call da_get_unit(ep_unit)
38 call da_message((/"Set up flow-dependent information"/))
44 if (ne > 1) ens_scaling_inv = 1.0 / sqrt(real(ne-1))
46 ! Decide which space we are introducing flow-dependence:
47 if (alphacv_method == alphacv_method_xa) then ! xa space (default)
53 if ( ep_format == is_r4 ) then
68 if ( num_fgat_time > 1 .and. use_4denvar ) then
69 nte = num_fgat_time * ne
70 allocate(ep_dir_name(num_fgat_time))
71 do it = 1, num_fgat_time
72 write(ep_dir_name(it), fmt='(a, i2.2)') 'ep', it !ep01,ep02,...
76 allocate(ep_dir_name(1))
80 if ( rootproc .and. ep_format == is_r4 ) then
81 allocate(temp3d_r4(1:ix,1:jy,1:kz))
82 allocate(temp2d_r4(1:ix,1:jy))
84 allocate(temp3d(1:ix,1:jy,1:kz))
85 allocate(temp2d(1:ix,1:jy))
87 !---------------------------------------------------------------------------
88 ! Input ensemble perturbations
89 !---------------------------------------------------------------------------
90 do te = 1, nte !loop over num_fgat_time*ne
92 it = te/ne + 1 ! retrieve time window index from nte
93 ie = mod(te, ne) ! retrieve ensemble memeber index from nte
98 !write(6,*) 'it, ie = ', it, ie
100 write(unit=ce,fmt='(i3.3)') ie
103 filename = trim(ep_dir_name(it))//'/'//trim(var(1))//'.e'//trim(ce)
105 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
106 read(unit=ep_unit) ni, nj, nk
108 if (ni /= ix .or. nj /= jy .or. nk /= kz) then
109 write(unit=message(1),fmt='(a)') &
110 'Inconsistent grid dimensions'
111 write(unit=message(2),fmt='(a,3i6)') &
112 ' Grid dims for analysis grid: ', ix, jy
113 write(unit=message(3),fmt='(a,3i6)') &
114 ' Grid dims for flow predictors: ', ni, nj
115 call da_warning(__FILE__,__LINE__,message(1:3))
118 if ( ep_format == is_r8 ) then
119 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
120 else if ( ep_format == is_r4 ) then
121 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
126 call wrf_dm_bcast_real(temp3d, ijk)
127 ep % v1(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * &
128 temp3d(its:ite,jts:jte,kts:kte)
131 filename = trim(ep_dir_name(it))//'/'//trim(var(2))//'.e'//trim(ce)
133 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
134 read(unit=ep_unit) ni, nj, nk
135 if ( ep_format == is_r8 ) then
136 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
137 else if ( ep_format == is_r4 ) then
138 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
143 call wrf_dm_bcast_real(temp3d, ijk)
144 ep % v2(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * &
145 temp3d(its:ite,jts:jte,kts:kte)
148 filename = trim(ep_dir_name(it))//'/'//trim(var(3))//'.e'//trim(ce)
150 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
151 read(unit=ep_unit) ni, nj, nk
152 if ( ep_format == is_r8 ) then
153 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
154 else if ( ep_format == is_r4 ) then
155 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
160 call wrf_dm_bcast_real(temp3d, ijk)
161 ep % v3(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * &
162 temp3d(its:ite,jts:jte,kts:kte)
165 filename = trim(ep_dir_name(it))//'/'//trim(var(4))//'.e'//trim(ce)
167 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
168 read(unit=ep_unit) ni, nj, nk
169 if ( ep_format == is_r8 ) then
170 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
171 else if ( ep_format == is_r4 ) then
172 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
177 call wrf_dm_bcast_real(temp3d, ijk)
178 ep % v4(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * &
179 temp3d(its:ite,jts:jte,kts:kte)
182 filename = trim(ep_dir_name(it))//'/'//trim(var(5))//'.e'//trim(ce)
184 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
185 read(unit=ep_unit) ni, nj, nkdum
186 if ( ep_format == is_r8 ) then
187 read(unit=ep_unit) temp2d(1:ix,1:jy)
188 else if ( ep_format == is_r4 ) then
189 read(unit=ep_unit) temp2d_r4(1:ix,1:jy)
194 call wrf_dm_bcast_real(temp2d, ix*jy)
195 ep % v5(its:ite,jts:jte,1,te) = ens_scaling_inv * temp2d(its:ite,jts:jte)
197 end do ! num_fgat_time*ne loop
199 ! Optional include hydrometeors:
201 if ( alphacv_method == alphacv_method_xa .and. alpha_hydrometeors ) then ! xa space
211 !write(6,*) 'it, ie = ', it, ie
213 write(unit=ce,fmt='(i3.3)') ie
215 if ( ep_format == is_r8 ) then
216 filename = trim(ep_dir_name(it))//'/'//'qcloud'//'.e'//trim(ce)
217 else if ( ep_format == is_r4 ) then
218 filename = trim(ep_dir_name(it))//'/'//'QCLOUD'//'.e'//trim(ce)
221 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
222 read(unit=ep_unit) ni, nj, nk
223 if ( ep_format == is_r8 ) then
224 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
225 else if ( ep_format == is_r4 ) then
226 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
231 call wrf_dm_bcast_real(temp3d, ijk)
232 ep % cw(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * temp3d(its:ite,jts:jte,kts:kte)
234 if ( ep_format == is_r8 ) then
235 filename = trim(ep_dir_name(it))//'/'//'qrain'//'.e'//trim(ce)
236 else if ( ep_format == is_r4 ) then
237 filename = trim(ep_dir_name(it))//'/'//'QRAIN'//'.e'//trim(ce)
240 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
241 read(unit=ep_unit) ni, nj, nk
242 if ( ep_format == is_r8 ) then
243 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
244 else if ( ep_format == is_r4 ) then
245 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
250 call wrf_dm_bcast_real(temp3d, ijk)
251 ep % rn(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * temp3d(its:ite,jts:jte,kts:kte)
253 if ( ep_format == is_r8 ) then
254 filename = trim(ep_dir_name(it))//'/'//'qice'//'.e'//trim(ce)
255 else if ( ep_format == is_r4 ) then
256 filename = trim(ep_dir_name(it))//'/'//'QICE'//'.e'//trim(ce)
259 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
260 read(unit=ep_unit) ni, nj, nk
261 if ( ep_format == is_r8 ) then
262 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
263 else if ( ep_format == is_r4 ) then
264 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
269 call wrf_dm_bcast_real(temp3d, ijk)
270 ep % ci(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * temp3d(its:ite,jts:jte,kts:kte)
272 if ( ep_format == is_r8 ) then
273 filename = trim(ep_dir_name(it))//'/'//'qsnow'//'.e'//trim(ce)
274 else if ( ep_format == is_r4 ) then
275 filename = trim(ep_dir_name(it))//'/'//'QSNOW'//'.e'//trim(ce)
278 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
279 read(unit=ep_unit) ni, nj, nk
280 if ( ep_format == is_r8 ) then
281 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
282 else if ( ep_format == is_r4 ) then
283 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
288 call wrf_dm_bcast_real(temp3d, ijk)
289 ep % sn(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * temp3d(its:ite,jts:jte,kts:kte)
291 if ( ep_format == is_r8 ) then
292 filename = trim(ep_dir_name(it))//'/'//'qgraup'//'.e'//trim(ce)
293 else if ( ep_format == is_r4 ) then
294 filename = trim(ep_dir_name(it))//'/'//'QGRAUP'//'.e'//trim(ce)
297 open(unit=ep_unit, file = filename, form = 'unformatted', status = 'old')
298 read(unit=ep_unit) ni, nj, nk
299 if ( ep_format == is_r8 ) then
300 read(unit=ep_unit) temp3d(1:ix,1:jy,1:kz)
301 else if ( ep_format == is_r4 ) then
302 read(unit=ep_unit) temp3d_r4(1:ix,1:jy,1:kz)
307 call wrf_dm_bcast_real(temp3d, ijk)
308 ep % gr(its:ite,jts:jte,kts:kte,te) = ens_scaling_inv * temp3d(its:ite,jts:jte,kts:kte)
310 end do ! num_fgat_time*ne loop
312 end if ! hydrometeors
314 if ( rootproc .and. ep_format == is_r4 ) then
315 deallocate(temp3d_r4)
316 deallocate(temp2d_r4)
321 write(unit=message(1),fmt='(a,e12.5)') &
322 ' Max U ep: ', maxval(ep % v1(its:ite,jts:jte,:,:))
323 write(unit=message(2),fmt='(a,e12.5)') &
324 ' Max V ep: ', maxval(ep % v2(its:ite,jts:jte,:,:))
325 write(unit=message(3),fmt='(a,e12.5)') &
326 ' Max T ep: ', maxval(ep % v3(its:ite,jts:jte,:,:))
327 write(unit=message(4),fmt='(a,e12.5)') &
328 ' Max Q ep: ', maxval(ep % v4(its:ite,jts:jte,:,:))
329 write(unit=message(5),fmt='(a,e12.5)') &
330 ' Max Psfc ep: ', maxval(ep % v5(its:ite,jts:jte,1,:))
331 call da_message(message(1:5))
333 if ( alphacv_method == alphacv_method_xa .and. alpha_hydrometeors ) then
334 write(unit=message(1),fmt='(a,e12.5)') &
335 ' Max QCLOUD ep: ', maxval(ep % cw(its:ite,jts:jte,:,:))
336 write(unit=message(2),fmt='(a,e12.5)') &
337 ' Max QRAIN ep: ', maxval(ep % rn(its:ite,jts:jte,:,:))
338 write(unit=message(3),fmt='(a,e12.5)') &
339 ' Max QICE ep: ', maxval(ep % ci(its:ite,jts:jte,:,:))
340 write(unit=message(4),fmt='(a,e12.5)') &
341 ' Max QSNOW ep: ', maxval(ep % sn(its:ite,jts:jte,:,:))
342 write(unit=message(5),fmt='(a,e12.5)') &
343 ' Max QGRAUP ep: ', maxval(ep % gr(its:ite,jts:jte,:,:))
344 call da_message(message(1:5))
347 deallocate(ep_dir_name)
348 call da_free_unit(ep_unit)
350 if (trace_use) call da_trace_exit("da_setup_flow_predictors")
352 end subroutine da_setup_flow_predictors