3 !-----------------------------------------------------------------------
4 ! Purpose: update BC file from wrfvar output.
5 ! current version reads only wrf-netcdf file format
7 ! Y.-R. Guo, 03/18/2008:
8 ! 1) Fixed the bug for low_bdy_only;
9 ! 2) Introducing another namelist variable: update_lsm
10 ! update_lsm = .true. --- The LSM predicted variables:
11 ! TSLB, SMOIS, SNOW, SH2O, RHOSN, CANWAT, SNOWH
12 ! will be updated based on wrf_input file
13 ! = .false. -- no updated, default.
15 !-----------------------------------------------------------------------
17 use da_netcdf_interface
, only
: da_get_var_3d_real_cdf
, &
18 da_put_var_3d_real_cdf
, da_get_dims_cdf
, da_put_var_2d_real_cdf
, &
19 da_get_var_2d_real_cdf
, da_get_var_2d_int_cdf
, da_get_bdytimestr_cdf
, &
20 da_get_times_cdf
, da_get_bdyfrq
, stderr
, stdout
, da_put_var_2d_int_cdf
, &
21 da_get_var_1d_real_cdf
, da_get_gl_att_int_cdf
23 use da_module_couple_uv
, only
: da_couple_uv
29 integer, parameter :: max_3d_variables
= 20, &
32 character(len
=512) :: da_file
, &
37 character(len
=20) :: var_pref
, var_name
, vbt_name
39 character(len
=20) :: var3d(max_3d_variables
), &
40 varsf(max_2d_variables
)
42 character(len
=10), dimension(4) :: bdyname
, tenname
44 ! for WRF hybrid coordinate
45 integer :: nlevf
, nlevh
46 integer :: hybrid_opt
, use_theta_m
47 real, allocatable
:: c1f(:), c2f(:), c1h(:), c2h(:)
49 integer :: ids
, ide
, jds
, jde
, kds
, kde
50 integer :: num3d
, num2d
, ndims
52 integer :: i
,j
,k
,l
,m
,n
54 integer, dimension(4) :: dims
56 real, allocatable
, dimension(:,:,:) :: tend3d
, scnd3d
, frst3d
, full3d
, full3d2
58 real, allocatable
, dimension(:,:,:) :: u
, v
, u2
, v2
60 real, allocatable
, dimension(:, :) :: mu
, mub
, msfu
, msfv
, msfm
, &
61 mu2
, tend2d
, scnd2d
, frst2d
, full2d
63 real, allocatable
, dimension(:, :) :: tsk
, tsk_wrfvar
64 real, allocatable
, dimension(:,:) :: snow
, snowc
, snowh
66 integer, allocatable
, dimension(:,:) :: ivgtyp
, full2dint
68 character(len
=80), allocatable
, dimension(:) :: times
, &
69 thisbdytime
, nextbdytime
71 integer :: east_end
, north_end
, io_status
, cdfid
, varid
, domain_id
, iswater
72 integer :: iostatus(4)
74 logical :: debug
, update_lateral_bdy
, update_low_bdy
, update_lsm
, keep_tsk_wrf
75 logical :: keep_snow_wrf
, var4d_lbc
79 character(len
=512) :: wrfvar_output_file
! obsolete. Kept for backward compatibility
80 logical :: cycling
, low_bdy_only
! obsolete. Kept for backward compatibility
82 integer, parameter :: namelist_unit
= 7, &
86 namelist /control_param
/ da_file
, &
89 wrf_input
, domain_id
, var4d_lbc
, &
90 debug
, update_lateral_bdy
, update_low_bdy
, update_lsm
, &
91 keep_tsk_wrf
, keep_snow_wrf
, iswater
, &
92 wrfvar_output_file
, cycling
, low_bdy_only
94 da_file
= 'wrfvar_output'
96 wrf_bdy_file
= 'wrfbdy_d01'
97 wrf_input
= 'wrfinput_d01'
102 update_lateral_bdy
= .true
.
103 update_low_bdy
= .true
.
105 keep_tsk_wrf
= .true
.
106 keep_snow_wrf
= .true
.
107 iswater
= 16 ! USGS water index: 16, MODIS water index: 17
109 wrfvar_output_file
= 'OBSOLETE'
111 low_bdy_only
= .false
.
113 !---------------------------------------------------------------------
115 !---------------------------------------------------------------------
118 open(unit
= namelist_unit
, file
= 'parame.in', &
119 status
= 'old' , access
= 'sequential', &
120 form
= 'formatted', action
= 'read', &
123 if (io_status
/= 0) then
124 write(unit
=stdout
,fmt
=*) 'Error to open namelist file: parame.in.'
125 write(unit
=stdout
,fmt
=*) 'Will work for updating lateral boundary only.'
127 read(unit
=namelist_unit
, nml
= control_param
, iostat
= io_status
)
129 if (io_status
/= 0) then
130 write(unit
=stdout
,fmt
=*) 'Error to read control_param. Stopped.'
134 ! deal with the old namelist
135 if ( index(wrfvar_output_file
, 'OBSOLETE') <= 0 ) then
136 ! wrfvar_output_file is set in the user's parame.in
138 da_file
= wrfvar_output_file
139 if ( domain_id
> 1 ) then
140 low_bdy_only
= .true
.
142 if ( cycling
.and
. domain_id
== 1 ) then
143 update_lateral_bdy
= .true
.
144 update_low_bdy
= .true
.
146 if ( low_bdy_only
) then
147 update_lateral_bdy
= .false
.
148 update_low_bdy
= .true
.
150 update_lateral_bdy
= .true
.
151 update_low_bdy
= .false
.
156 WRITE(unit
=stdout
, fmt
='(2a)') &
157 'da_file = ', trim(da_file
), &
158 'da_file_02 = ', trim(da_file_02
), &
159 'wrf_bdy_file = ', trim(wrf_bdy_file
), &
160 'wrf_input = ', trim(wrf_input
)
162 WRITE(unit
=stdout
, fmt
='(2(a, L10))') &
163 'update_lateral_bdy = ', update_lateral_bdy
, &
164 'update_low_bdy = ', update_low_bdy
166 if ( update_lsm
) keep_snow_wrf
= .false
.
168 close(unit
=namelist_unit
)
206 if ( domain_id
> 1 ) then
207 write(unit
=stdout
, fmt
='(a,i2)') 'Nested domain ID=',domain_id
208 write(unit
=stdout
, fmt
='(a)') &
209 'No wrfbdy file needed, only low boundary need to be updated.'
210 if ( update_lateral_bdy
) then
211 write(unit
=stdout
, fmt
='(a)') &
212 'Re-setting update_lateral_bdy to be false for nested domain.'
213 update_lateral_bdy
= .false
.
215 update_low_bdy
= .true
.
218 if ( update_lateral_bdy
) then
219 ! First, the boundary times
220 call da_get_dims_cdf(wrf_bdy_file
, 'Times', dims
, ndims
, debug
)
223 write(unit
=stdout
, fmt
='(a,i2,2x,a,4i6)') &
224 'Times: ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
229 if (time_level
< 1) then
230 write(unit
=stdout
, fmt
='(a,i2/a)') &
231 'time_level = ', time_level
, &
232 'We need at least one time-level BDY.'
233 stop 'Wrong BDY file.'
236 allocate(times(dims(2)))
237 allocate(thisbdytime(dims(2)))
238 allocate(nextbdytime(dims(2)))
240 call da_get_times_cdf(wrf_bdy_file
, times
, dims(2), dims(2), debug
)
242 call da_get_bdytimestr_cdf(wrf_bdy_file
, 'thisbdytime', thisbdytime
, dims(2), debug
)
243 call da_get_bdytimestr_cdf(wrf_bdy_file
, 'nextbdytime', nextbdytime
, dims(2), debug
)
245 call da_get_bdyfrq(thisbdytime(1), nextbdytime(1), bdyfrq
, debug
)
249 write(unit
=stdout
, fmt
='(3(a, i2, 2a,2x))') &
250 ' times(', n
, ')=', trim(times(n
)), &
251 'thisbdytime (', n
, ')=', trim(thisbdytime(n
)), &
252 'nextbdytime (', n
, ')=', trim(nextbdytime(n
))
261 cdfid
= ncopn(da_file
, NCWRITE
, io_status
)
263 ! for WRF hybrid coordinate
265 call da_get_gl_att_int_cdf(da_file
, 'BOTTOM-TOP_PATCH_END_STAG', nlevf
, debug
, io_status
)
266 call da_get_gl_att_int_cdf(da_file
, 'BOTTOM-TOP_PATCH_END_UNSTAG', nlevh
, debug
, io_status
)
267 if ( io_status
/= NF_NOERR
.or
. nlevf
<= 0 .or
. nlevh
<= 0 ) then
268 write(unit
=stdout
,fmt
=*) 'Error finding the number of vertical levels'
271 allocate ( c1f(nlevf
) )
272 allocate ( c2f(nlevf
) )
273 allocate ( c1h(nlevh
) )
274 allocate ( c2h(nlevh
) )
277 ! initialize as use_theta_m = 0
279 call da_get_gl_att_int_cdf(da_file
, 'USE_THETA_M', use_theta_m
, debug
, io_status
)
280 write(stdout
,*) 'use_theta_m = ', use_theta_m
282 ! initialize as hybrid_opt = 0
289 call da_get_gl_att_int_cdf(da_file
, 'HYBRID_OPT', hybrid_opt
, debug
, io_status
)
290 if ( io_status
== NF_NOERR
.and
. hybrid_opt
> 0 ) then
291 ! when HYBRID_OPT is available from the file (V3.9 and later)
292 ! use C1F,C2F,C1H,C2H from the file
293 call da_get_var_1d_real_cdf( da_file
, 'C1F', c1f
, nlevf
, 1, debug
)
294 call da_get_var_1d_real_cdf( da_file
, 'C2F', c2f
, nlevf
, 1, debug
)
295 call da_get_var_1d_real_cdf( da_file
, 'C1H', c1h
, nlevh
, 1, debug
)
296 call da_get_var_1d_real_cdf( da_file
, 'C2H', c2h
, nlevh
, 1, debug
)
299 write(stdout
,*) 'hybrid_opt = ', hybrid_opt
301 write(stdout
,*) 'c1f = ', c1f
302 write(stdout
,*) 'c2f = ', c2f
303 write(stdout
,*) 'c1h = ', c1h
304 write(stdout
,*) 'c2h = ', c2f
308 ! Get mu, mub, msfu, and msfv
312 io_status
= nf_inq_varid(cdfid
, trim(varsf(n
)), varid
)
313 if (io_status
/= 0 ) then
314 print '(/"N=",i2," io_status=",i5,5x,"VAR=",a,a)', &
315 n
, io_status
, trim(varsf(n
)), " does not exist"
319 call da_get_dims_cdf( da_file
, trim(varsf(n
)), dims
, &
322 select
case(trim(varsf(n
)))
324 if ( .not
. update_lateral_bdy
) cycle
326 allocate(mu(dims(1), dims(2)))
328 call da_get_var_2d_real_cdf( da_file
, &
329 trim(varsf(n
)), mu
, dims(1), dims(2), 1, debug
)
334 if ( var4d_lbc
) then
335 allocate(mu2(dims(1), dims(2)))
337 call da_get_var_2d_real_cdf( da_file_02
, &
338 trim(varsf(n
)), mu2
, dims(1), dims(2), 1, debug
)
341 if ( .not
. update_lateral_bdy
) cycle
343 allocate(mub(dims(1), dims(2)))
345 call da_get_var_2d_real_cdf( da_file
, trim(varsf(n
)), mub
, &
346 dims(1), dims(2), 1, debug
)
348 if ( .not
. update_lateral_bdy
) cycle
350 allocate(msfu(dims(1), dims(2)))
352 call da_get_var_2d_real_cdf( da_file
, trim(varsf(n
)), msfu
, &
353 dims(1), dims(2), 1, debug
)
355 if ( .not
. update_lateral_bdy
) cycle
357 allocate(msfv(dims(1), dims(2)))
359 call da_get_var_2d_real_cdf( da_file
, trim(varsf(n
)), msfv
, &
360 dims(1), dims(2), 1, debug
)
362 if ( .not
. update_lateral_bdy
) cycle
364 allocate(msfm(dims(1), dims(2)))
366 call da_get_var_2d_real_cdf( da_file
, trim(varsf(n
)), msfm
, &
367 dims(1), dims(2), 1, debug
)
369 if ( .not
. update_low_bdy
) cycle
371 allocate(tsk(dims(1), dims(2)))
372 allocate(tsk_wrfvar(dims(1), dims(2)))
373 allocate(ivgtyp(dims(1), dims(2)))
375 call da_get_var_2d_real_cdf( wrf_input
, trim(varsf(n
)), tsk
, &
376 dims(1), dims(2), 1, debug
)
378 if ( keep_tsk_wrf
) then
379 call da_get_var_2d_real_cdf( da_file
, trim(varsf(n
)), tsk_wrfvar
, &
380 dims(1), dims(2), 1, debug
)
381 !hcl call da_get_var_2d_int_cdf( da_file, 'IVGTYP', ivgtyp, &
382 call da_get_var_2d_int_cdf( wrf_input
, 'IVGTYP', ivgtyp
, &
383 dims(1), dims(2), 1, debug
)
387 if (ivgtyp(i
,j
) /= iswater
) tsk(i
,j
)=tsk_wrfvar(i
,j
)
392 call da_put_var_2d_real_cdf( da_file
, trim(varsf(n
)), tsk
, &
393 dims(1), dims(2), 1, debug
)
396 deallocate(tsk_wrfvar
)
398 !hcl case ('TMN', 'SST', 'VEGFRA', 'ALBBCK', 'SEAICE') ;
399 case ('TMN', 'SST', 'VEGFRA', 'ALBBCK', 'SEAICE', 'LANDMASK', 'XLAND') ;
400 if ( .not
. update_low_bdy
) cycle
402 allocate(full2d(dims(1), dims(2)))
404 call da_get_var_2d_real_cdf( wrf_input
, trim(varsf(n
)), full2d
, &
405 dims(1), dims(2), 1, debug
)
407 call da_put_var_2d_real_cdf( da_file
, trim(varsf(n
)), full2d
, &
408 dims(1), dims(2), 1, debug
)
411 case ('IVGTYP', 'ISLTYP') ; !hcl add
412 if ( .not
. update_low_bdy
) cycle
414 allocate(full2dint(dims(1), dims(2)))
416 call da_get_var_2d_int_cdf( wrf_input
, trim(varsf(n
)), full2dint
, &
417 dims(1), dims(2), 1, debug
)
419 call da_put_var_2d_int_cdf( da_file
, trim(varsf(n
)), full2dint
, &
420 dims(1), dims(2), 1, debug
)
421 deallocate(full2dint
)
423 case ('SNOW', 'RHOSN', 'SNOWH', 'SNOWC') ;
424 if ( (.not
. update_lsm
) .and
. (.not
. update_low_bdy
) ) cycle
425 if ( keep_snow_wrf
) cycle
426 allocate(full2d(dims(1), dims(2)))
428 call da_get_var_2d_real_cdf( wrf_input
, trim(varsf(n
)), full2d
, &
429 dims(1), dims(2), 1, debug
)
431 call da_put_var_2d_real_cdf( da_file
, trim(varsf(n
)), full2d
, &
432 dims(1), dims(2), 1, debug
)
436 if ( .not
. update_lsm
) cycle
437 allocate(full2d(dims(1), dims(2)))
439 call da_get_var_2d_real_cdf( wrf_input
, trim(varsf(n
)), full2d
, &
440 dims(1), dims(2), 1, debug
)
441 ! print *,"sum(full2d^2)=", sum(full2d*full2d)
443 call da_put_var_2d_real_cdf( da_file
, trim(varsf(n
)), full2d
, &
444 dims(1), dims(2), 1, debug
)
447 case ('TSLB', 'SMOIS', 'SH2O') ;
448 if( .not
. update_lsm
) cycle
449 allocate(full3d(dims(1), dims(2), dims(3)))
451 call da_get_var_3d_real_cdf( wrf_input
, trim(varsf(n
)), full3d
, &
452 dims(1), dims(2), dims(3), 1, debug
)
453 ! print *,"sum(full3d^2)=", sum(full3d*full3d)
455 call da_put_var_3d_real_cdf( da_file
, trim(varsf(n
)), full3d
, &
456 dims(1), dims(2), dims(3), 1, debug
)
460 write(unit
=stdout
,fmt
=*) 'It is impossible here. varsf(n)=', trim(varsf(n
))
464 ! check for snow over water
465 iostatus(1) = nf_inq_varid(cdfid
, 'IVGTYP', varid
)
466 iostatus(2) = nf_inq_varid(cdfid
, 'SNOW', varid
)
467 iostatus(3) = nf_inq_varid(cdfid
, 'SNOWC', varid
)
468 iostatus(4) = nf_inq_varid(cdfid
, 'SNOWH', varid
)
469 if ( iostatus(1) == 0 ) then
470 allocate(snow(dims(1), dims(2)))
471 allocate(snowc(dims(1), dims(2)))
472 allocate(snowh(dims(1), dims(2)))
473 allocate(ivgtyp(dims(1), dims(2)))
474 if ( iostatus(1) == 0 ) then
475 call da_get_var_2d_int_cdf( da_file
, 'IVGTYP', ivgtyp
, &
476 dims(1), dims(2), 1, debug
)
478 if ( iostatus(2) == 0 ) then
479 call da_get_var_2d_real_cdf( da_file
, 'SNOW', snow
, &
480 dims(1), dims(2), 1, debug
)
482 if ( iostatus(3) == 0 ) then
483 call da_get_var_2d_real_cdf( da_file
, 'SNOWC', snowc
, &
484 dims(1), dims(2), 1, debug
)
486 if ( iostatus(4) == 0 ) then
487 call da_get_var_2d_real_cdf( da_file
, 'SNOWH', snowh
, &
488 dims(1), dims(2), 1, debug
)
490 if ( iostatus(2) == 0 ) then
493 if (ivgtyp(i
,j
) == iswater
) then
494 if ( snow(i
,j
) > 0.0 ) then
495 write(unit
=stdout
,fmt
=*) 'Remove snow over water at i, j = ', i
, j
496 if ( iostatus(2) == 0 ) snow(i
,j
) = 0.0
497 if ( iostatus(3) == 0 ) snowc(i
,j
) = 0.0
498 if ( iostatus(4) == 0 ) snowh(i
,j
) = 0.0
504 if ( iostatus(2) == 0 ) then
505 call da_put_var_2d_real_cdf( da_file
, 'SNOW', snow
, &
506 dims(1), dims(2), 1, debug
)
508 if ( iostatus(3) == 0 ) then
509 call da_put_var_2d_real_cdf( da_file
, 'SNOWC', snowc
, &
510 dims(1), dims(2), 1, debug
)
512 if ( iostatus(4) == 0 ) then
513 call da_put_var_2d_real_cdf( da_file
, 'SNOWH', snowh
, &
514 dims(1), dims(2), 1, debug
)
522 if ( update_lateral_bdy
) then
524 if (east_end
< 1 .or
. north_end
< 1) then
525 write(unit
=stdout
, fmt
='(a)') 'Wrong data for Boundary.'
529 write(unit
=stdout
,fmt
='(/a/)') 'Processing the lateral boundary condition:'
537 ! boundary tendancy variables
544 var_name
='MU' // trim(bdyname(m
))
545 vbt_name
='MU' // trim(tenname(m
))
547 call da_get_dims_cdf( wrf_bdy_file
, trim(var_name
), dims
, ndims
, debug
)
549 allocate(frst2d(dims(1), dims(2)))
550 allocate(scnd2d(dims(1), dims(2)))
551 allocate(tend2d(dims(1), dims(2)))
553 ! Get variable at second time level
554 if ( .not
. var4d_lbc
) then
555 if (time_level
> 1) then
556 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(var_name
), scnd2d
, &
557 dims(1), dims(2), 2, debug
)
559 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(var_name
), frst2d
, &
560 dims(1), dims(2), 1, debug
)
561 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend2d
, &
562 dims(1), dims(2), 1, debug
)
567 write(unit
=ori_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
568 'No.', m
, 'Variable: ', trim(vbt_name
), &
569 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
571 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend2d
, &
572 dims(1), dims(2), 1, debug
)
574 write(unit
=ori_unit
, fmt
='(a, 10i12)') &
575 ' old ', (i
, i
=1,dims(2))
577 write(unit
=ori_unit
, fmt
='(i4, 1x, 10e20.7)') &
578 j
, (tend2d(j
,i
), i
=1,dims(2))
582 ! calculate variable at first time level
584 case (1) ; ! West boundary
587 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
588 scnd2d(j
,l
)=frst2d(j
,l
)+tend2d(j
,l
)*bdyfrq
589 if (var4d_lbc
) scnd2d(j
,l
)=mu2(l
,j
)
593 case (2) ; ! East boundary
596 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
597 scnd2d(j
,l
)=frst2d(j
,l
)+tend2d(j
,l
)*bdyfrq
598 if (var4d_lbc
) scnd2d(j
,l
)=mu2(east_end
-l
,j
)
599 frst2d(j
,l
)=mu(east_end
-l
,j
)
602 case (3) ; ! South boundary
605 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
606 scnd2d(i
,l
)=frst2d(i
,l
)+tend2d(i
,l
)*bdyfrq
607 if (var4d_lbc
) scnd2d(i
,l
)=mu2(i
,l
)
611 case (4) ; ! North boundary
614 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
615 scnd2d(i
,l
)=frst2d(i
,l
)+tend2d(i
,l
)*bdyfrq
616 if (var4d_lbc
) scnd2d(i
,l
)=mu2(i
,north_end
-l
)
617 frst2d(i
,l
)=mu(i
,north_end
-l
)
621 write(unit
=stdout
,fmt
=*) 'It is impossible here. mu, m=', m
624 ! calculate new tendancy
627 tend2d(i
,l
)=(scnd2d(i
,l
)-frst2d(i
,l
))/bdyfrq
632 write(unit
=new_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
633 'No.', m
, 'Variable: ', trim(vbt_name
), &
634 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
636 write(unit
=new_unit
, fmt
='(a, 10i12)') &
637 ' new ', (i
, i
=1,dims(2))
640 write(unit
=new_unit
, fmt
='(i4, 1x, 10e20.7)') &
641 j
, (tend2d(j
,i
), i
=1,dims(2))
645 ! output new variable at first time level
646 call da_put_var_2d_real_cdf( wrf_bdy_file
, trim(var_name
), frst2d
, &
647 dims(1), dims(2), 1, debug
)
648 ! output new tendancy
649 call da_put_var_2d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend2d
, &
650 dims(1), dims(2), 1, debug
)
657 !---------------------------------------------------------------------
661 call da_get_dims_cdf( da_file
, 'U', dims
, ndims
, debug
)
663 ! call da_get_att_cdf( da_file, 'U', debug)
665 allocate(u(dims(1), dims(2), dims(3)))
674 call da_get_var_3d_real_cdf( da_file
, 'U', u
, &
675 dims(1), dims(2), dims(3), 1, debug
)
676 if ( var4d_lbc
) then
677 allocate(u2(dims(1), dims(2), dims(3)))
678 call da_get_var_3d_real_cdf( da_file_02
, 'U', u2
, &
679 dims(1), dims(2), dims(3), 1, debug
)
683 ! write(unit=stdout, fmt='(2(a,i5), a, f12.8)') &
684 ! 'u(', dims(1), ',', j, ',1)=', u(dims(1),j,1)
688 call da_get_dims_cdf( da_file
, 'V', dims
, ndims
, debug
)
690 ! call da_get_att_cdf( da_file, 'V', debug)
692 allocate(v(dims(1), dims(2), dims(3)))
694 call da_get_var_3d_real_cdf( da_file
, 'V', v
, &
695 dims(1), dims(2), dims(3), 1, debug
)
696 if ( var4d_lbc
) then
697 allocate(v2(dims(1), dims(2), dims(3)))
698 call da_get_var_3d_real_cdf( da_file_02
, 'V', v2
, &
699 dims(1), dims(2), dims(3), 1, debug
)
703 ! write(unit=stdout, fmt='(2(a,i5), a, f12.8)') &
704 ! 'v(', i, ',', dims(2), ',1)=', v(i,dims(2),1)
708 write(unit
=stdout
, fmt
='(a,e20.12,4x)') &
709 'Before couple Sample u=', u(dims(1)/2,dims(2)/2,dims(3)/2), &
710 'Before couple Sample v=', v(dims(1)/2,dims(2)/2,dims(3)/2)
713 !---------------------------------------------------------------------
715 call da_couple_uv ( u
, v
, mu
, mub
, msfu
, msfv
, c1h
, c2h
, ids
, ide
, jds
, jde
, kds
, kde
)
716 if ( var4d_lbc
) then
717 call da_couple_uv ( u2
, v2
, mu2
, mub
, msfu
, msfv
, c1h
, c2h
, ids
, ide
, jds
, jde
, kds
, kde
)
721 write(unit
=stdout
, fmt
='(a,e20.12,4x)') &
722 'After couple Sample u=', u(dims(1)/2,dims(2)/2,dims(3)/2), &
723 'After couple Sample v=', v(dims(1)/2,dims(2)/2,dims(3)/2)
726 !---------------------------------------------------------------------
730 write(unit
=stdout
, fmt
='(a, i3, 2a)') 'Processing: var3d(', n
, ')=', trim(var3d(n
))
732 call da_get_dims_cdf( da_file
, trim(var3d(n
)), dims
, ndims
, debug
)
734 allocate(full3d(dims(1), dims(2), dims(3)))
735 if ( var4d_lbc
) allocate(full3d2(dims(1), dims(2), dims(3)))
740 select
case(trim(var3d(n
)))
742 ! var_pref='R' // trim(var3d(n))
743 var_pref
=trim(var3d(n
))
744 full3d(:,:,:)=u(:,:,:)
745 if ( var4d_lbc
) full3d2(:,:,:)=u2(:,:,:)
747 ! var_pref='R' // trim(var3d(n))
748 var_pref
=trim(var3d(n
))
749 full3d(:,:,:)=v(:,:,:)
750 if ( var4d_lbc
) full3d2(:,:,:)=v2(:,:,:)
752 ! var_pref = 'R' // trim(var3d(n))
753 var_pref
= trim(var3d(n
))
755 call da_get_var_3d_real_cdf( da_file
, trim(var3d(n
)), &
756 full3d
, dims(1), dims(2), dims(3), 1, debug
)
758 call da_get_var_3d_real_cdf( da_file_02
, trim(var3d(n
)), &
759 full3d2
, dims(1), dims(2), dims(3), 1, debug
)
762 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
763 'Before couple Sample ', trim(var3d(n
)), &
764 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
770 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1f(k
)*(mu(i
,j
)+mub(i
,j
))+c2f(k
))/msfm(i
,j
)
771 if ( var4d_lbc
) full3d2(i
,j
,k
)=full3d2(i
,j
,k
)*(c1f(k
)*(mu2(i
,j
)+mub(i
,j
))+c2f(k
))/msfm(i
,j
)
777 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
778 'After couple Sample ', trim(var3d(n
)), &
779 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
782 var_pref
=trim(var3d(n
))
784 if ( use_theta_m
> 0 .and
. trim(var3d(n
)) == 'T' ) then
785 call da_get_var_3d_real_cdf( da_file
, 'THM', &
786 full3d
, dims(1), dims(2), dims(3), 1, debug
)
788 call da_get_var_3d_real_cdf( da_file_02
, 'THM', &
789 full3d2
, dims(1), dims(2), dims(3), 1, debug
)
791 call da_get_var_3d_real_cdf( da_file
, trim(var3d(n
)), &
792 full3d
, dims(1), dims(2), dims(3), 1, debug
)
794 call da_get_var_3d_real_cdf( da_file_02
, trim(var3d(n
)), &
795 full3d2
, dims(1), dims(2), dims(3), 1, debug
)
799 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
800 'Before couple Sample ', trim(var3d(n
)), &
801 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
804 if ( dims(3) == nlevf
) then
805 ! applying c1f and c2f for mu
809 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1f(k
)*(mu(i
,j
)+mub(i
,j
))+c2f(k
))
810 if ( var4d_lbc
) full3d2(i
,j
,k
)=full3d2(i
,j
,k
)*(c1f(k
)*(mu2(i
,j
)+mub(i
,j
))+c2f(k
))
814 else if ( dims(3) == nlevh
) then
815 ! applying c1h and c2h for mu
819 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1h(k
)*(mu(i
,j
)+mub(i
,j
))+c2h(k
))
820 if ( var4d_lbc
) full3d2(i
,j
,k
)=full3d2(i
,j
,k
)*(c1h(k
)*(mu2(i
,j
)+mub(i
,j
))+c2h(k
))
825 write(unit
=stdout
,fmt
=*) 'Error finding matched dimensions.'
830 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
831 'After couple Sample ', trim(var3d(n
)), &
832 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
834 case ('QVAPOR', 'QCLOUD', 'QRAIN', 'QICE', 'QSNOW', 'QGRAUP') ;
835 ! var_pref='R' // var3d(n)(1:2)
836 ! var_pref=var3d(n)(1:2)
839 call da_get_var_3d_real_cdf( da_file
, trim(var3d(n
)), &
840 full3d
, dims(1), dims(2), dims(3), 1, debug
)
842 call da_get_var_3d_real_cdf( da_file_02
, trim(var3d(n
)), &
843 full3d2
, dims(1), dims(2), dims(3), 1, debug
)
846 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
847 'Before couple Sample ', trim(var3d(n
)), &
848 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
854 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1h(k
)*(mu(i
,j
)+mub(i
,j
))+c2h(k
))
855 if ( var4d_lbc
) full3d2(i
,j
,k
)=full3d2(i
,j
,k
)*(c1h(k
)*(mu2(i
,j
)+mub(i
,j
))+c2h(k
))
861 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
862 'After couple Sample ', trim(var3d(n
)), &
863 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
866 write(unit
=stdout
,fmt
=*) 'It is impossible here. var3d(', n
, ')=', trim(var3d(n
))
870 var_name
=trim(var_pref
) // trim(bdyname(m
))
871 vbt_name
=trim(var_pref
) // trim(tenname(m
))
873 write(unit
=stdout
, fmt
='(a, i3, 2a)') &
874 'Processing: bdyname(', m
, ')=', trim(var_name
)
876 call da_get_dims_cdf( wrf_bdy_file
, trim(var_name
), dims
, ndims
, debug
)
878 allocate(frst3d(dims(1), dims(2), dims(3)))
879 allocate(scnd3d(dims(1), dims(2), dims(3)))
880 allocate(tend3d(dims(1), dims(2), dims(3)))
882 ! Get variable at second time level
883 if ( .not
. var4d_lbc
) then
884 if (time_level
> 1) then
885 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(var_name
), scnd3d
, &
886 dims(1), dims(2), dims(3), 2, debug
)
888 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(var_name
), frst3d
, &
889 dims(1), dims(2), dims(3), 1, debug
)
890 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend3d
, &
891 dims(1), dims(2), dims(3), 1, debug
)
896 write(unit
=ori_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
897 'No.', m
, 'Variable: ', trim(vbt_name
), &
898 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
900 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend3d
, &
901 dims(1), dims(2), dims(3), 1, debug
)
903 write(unit
=ori_unit
, fmt
='(a, 10i12)') &
904 ' old ', (i
, i
=1,dims(3))
906 write(unit
=ori_unit
, fmt
='(i4, 1x, 10e20.7)') &
907 j
, (tend3d(j
,dims(2)/2,i
), i
=1,dims(3))
911 select
case(trim(bdyname(m
)))
912 case ('_BXS') ; ! West boundary
916 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
917 scnd3d(j
,k
,l
)=frst3d(j
,k
,l
)+tend3d(j
,k
,l
)*bdyfrq
918 if ( var4d_lbc
) scnd3d(j
,k
,l
)=full3d2(l
,j
,k
)
919 frst3d(j
,k
,l
)=full3d(l
,j
,k
)
923 case ('_BXE') ; ! East boundary
927 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
928 scnd3d(j
,k
,l
)=frst3d(j
,k
,l
)+tend3d(j
,k
,l
)*bdyfrq
929 if ( var4d_lbc
) scnd3d(j
,k
,l
)=full3d2(east_end
-l
,j
,k
)
930 frst3d(j
,k
,l
)=full3d(east_end
-l
,j
,k
)
934 case ('_BYS') ; ! South boundary
938 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
939 scnd3d(i
,k
,l
)=frst3d(i
,k
,l
)+tend3d(i
,k
,l
)*bdyfrq
940 if ( var4d_lbc
)scnd3d(i
,k
,l
)=full3d2(i
,l
,k
)
941 frst3d(i
,k
,l
)=full3d(i
,l
,k
)
945 case ('_BYE') ; ! North boundary
949 if (time_level
< 2 .and
. .not
. var4d_lbc
) &
950 scnd3d(i
,k
,l
)=frst3d(i
,k
,l
)+tend3d(i
,k
,l
)*bdyfrq
951 if ( var4d_lbc
) scnd3d(i
,k
,l
)=full3d2(i
,north_end
-l
,k
)
952 frst3d(i
,k
,l
)=full3d(i
,north_end
-l
,k
)
957 write(unit
=stdout
,fmt
=*) 'It is impossible here.'
958 write(unit
=stdout
,fmt
=*) 'bdyname(', m
, ')=', trim(bdyname(m
))
962 write(unit
=stdout
, fmt
='(a, i3, 2a)') &
963 'cal. tend: bdyname(', m
, ')=', trim(vbt_name
)
965 ! calculate new tendancy
969 tend3d(i
,k
,l
)=(scnd3d(i
,k
,l
)-frst3d(i
,k
,l
))/bdyfrq
975 write(unit
=new_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
976 'No.', m
, 'Variable: ', trim(vbt_name
), &
977 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
979 write(unit
=new_unit
, fmt
='(a, 10i12)') &
980 ' new ', (i
, i
=1,dims(3))
983 write(unit
=new_unit
, fmt
='(i4, 1x, 10e20.7)') &
984 j
, (tend3d(j
,dims(2)/2,i
), i
=1,dims(3))
988 ! output new variable at first time level
989 call da_put_var_3d_real_cdf( wrf_bdy_file
, trim(var_name
), frst3d
, &
990 dims(1), dims(2), dims(3), 1, debug
)
991 call da_put_var_3d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend3d
, &
992 dims(1), dims(2), dims(3), 1, debug
)
1000 if ( var4d_lbc
) deallocate(full3d2
)
1004 if ( var4d_lbc
) deallocate(mu2
)
1006 if ( var4d_lbc
) deallocate(u2
)
1008 if ( var4d_lbc
) deallocate(v2
)
1010 !--------------------- second time level-----------------------------------------
1011 !- for var4d_lbc, we need to update the second time level LBC
1012 if ( var4d_lbc
.and
. update_lateral_bdy
.and
. time_level
> 1 ) then
1017 cdfid
= ncopn(da_file_02
, NCNOWRIT
, io_status
)
1020 ! Get mu, mub, msfu, and msfv
1023 io_status
= nf_inq_varid(cdfid
, trim(varsf(n
)), varid
)
1024 if (io_status
/= 0 ) then
1025 print '(/"N=",i2," io_status=",i5,5x,"VAR=",a,a)', &
1026 n
, io_status
, trim(varsf(n
)), " does not exist"
1030 call da_get_dims_cdf( da_file_02
, 'MU', dims
, &
1033 allocate(mu(dims(1), dims(2)))
1035 call da_get_var_2d_real_cdf( da_file_02
, &
1036 'MU', mu
, dims(1), dims(2), 1, debug
)
1041 if (east_end
< 1 .or
. north_end
< 1) then
1042 write(unit
=stdout
, fmt
='(a)') 'Wrong data for Boundary.'
1046 write(unit
=stdout
,fmt
='(/a/)') 'Processing the lateral boundary condition:'
1048 ! boundary variables
1054 ! boundary tendancy variables
1061 var_name
='MU' // trim(bdyname(m
))
1062 vbt_name
='MU' // trim(tenname(m
))
1064 call da_get_dims_cdf( wrf_bdy_file
, trim(var_name
), dims
, ndims
, debug
)
1066 allocate(frst2d(dims(1), dims(2)))
1067 allocate(scnd2d(dims(1), dims(2)))
1068 allocate(tend2d(dims(1), dims(2)))
1070 ! Get variable at third time level
1071 if (time_level
> 2) then
1072 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(var_name
), scnd2d
, &
1073 dims(1), dims(2), 3, debug
)
1075 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(var_name
), frst2d
, &
1076 dims(1), dims(2), 2, debug
)
1077 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend2d
, &
1078 dims(1), dims(2), 2, debug
)
1082 write(unit
=ori_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
1083 'No.', m
, 'Variable: ', trim(vbt_name
), &
1084 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
1086 call da_get_var_2d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend2d
, &
1087 dims(1), dims(2), 2, debug
)
1089 write(unit
=ori_unit
, fmt
='(a, 10i12)') &
1090 ' old ', (i
, i
=1,dims(2))
1092 write(unit
=ori_unit
, fmt
='(i4, 1x, 10e20.7)') &
1093 j
, (tend2d(j
,i
), i
=1,dims(2))
1097 ! calculate variable at second time level
1099 case (1) ; ! West boundary
1102 if (time_level
< 3) &
1103 scnd2d(j
,l
)=frst2d(j
,l
)+tend2d(j
,l
)*bdyfrq
1107 case (2) ; ! East boundary
1110 if (time_level
< 3) &
1111 scnd2d(j
,l
)=frst2d(j
,l
)+tend2d(j
,l
)*bdyfrq
1112 frst2d(j
,l
)=mu(east_end
-l
,j
)
1115 case (3) ; ! South boundary
1118 if (time_level
< 3) &
1119 scnd2d(i
,l
)=frst2d(i
,l
)+tend2d(i
,l
)*bdyfrq
1123 case (4) ; ! North boundary
1126 if (time_level
< 3) &
1127 scnd2d(i
,l
)=frst2d(i
,l
)+tend2d(i
,l
)*bdyfrq
1128 frst2d(i
,l
)=mu(i
,north_end
-l
)
1132 write(unit
=stdout
,fmt
=*) 'It is impossible here. mu, m=', m
1135 ! calculate new tendancy
1138 tend2d(i
,l
)=(scnd2d(i
,l
)-frst2d(i
,l
))/bdyfrq
1143 write(unit
=new_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
1144 'No.', m
, 'Variable: ', trim(vbt_name
), &
1145 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
1147 write(unit
=new_unit
, fmt
='(a, 10i12)') &
1148 ' new ', (i
, i
=1,dims(2))
1151 write(unit
=new_unit
, fmt
='(i4, 1x, 10e20.7)') &
1152 j
, (tend2d(j
,i
), i
=1,dims(2))
1156 ! output new variable at first time level
1157 call da_put_var_2d_real_cdf( wrf_bdy_file
, trim(var_name
), frst2d
, &
1158 dims(1), dims(2), 2, debug
)
1159 ! output new tendancy
1160 call da_put_var_2d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend2d
, &
1161 dims(1), dims(2), 2, debug
)
1168 !---------------------------------------------------------------------
1172 call da_get_dims_cdf( da_file_02
, 'U', dims
, ndims
, debug
)
1174 ! call da_get_att_cdf( da_file_02, 'U', debug)
1176 allocate(u(dims(1), dims(2), dims(3)))
1185 call da_get_var_3d_real_cdf( da_file_02
, 'U', u
, &
1186 dims(1), dims(2), dims(3), 1, debug
)
1189 call da_get_dims_cdf( da_file_02
, 'V', dims
, ndims
, debug
)
1191 allocate(v(dims(1), dims(2), dims(3)))
1193 call da_get_var_3d_real_cdf( da_file_02
, 'V', v
, &
1194 dims(1), dims(2), dims(3), 1, debug
)
1197 write(unit
=stdout
, fmt
='(a,e20.12,4x)') &
1198 'Before couple Sample u=', u(dims(1)/2,dims(2)/2,dims(3)/2), &
1199 'Before couple Sample v=', v(dims(1)/2,dims(2)/2,dims(3)/2)
1202 !---------------------------------------------------------------------
1204 call da_couple_uv ( u
, v
, mu
, mub
, msfu
, msfv
, c1h
, c2h
, ids
, ide
, jds
, jde
, kds
, kde
)
1207 write(unit
=stdout
, fmt
='(a,e20.12,4x)') &
1208 'After couple Sample u=', u(dims(1)/2,dims(2)/2,dims(3)/2), &
1209 'After couple Sample v=', v(dims(1)/2,dims(2)/2,dims(3)/2)
1212 !---------------------------------------------------------------------
1216 write(unit
=stdout
, fmt
='(a, i3, 2a)') 'Processing: var3d(', n
, ')=', trim(var3d(n
))
1218 call da_get_dims_cdf( da_file_02
, trim(var3d(n
)), dims
, ndims
, debug
)
1220 allocate(full3d(dims(1), dims(2), dims(3)))
1225 select
case(trim(var3d(n
)))
1227 ! var_pref='R' // trim(var3d(n))
1228 var_pref
=trim(var3d(n
))
1229 full3d(:,:,:)=u(:,:,:)
1231 ! var_pref='R' // trim(var3d(n))
1232 var_pref
=trim(var3d(n
))
1233 full3d(:,:,:)=v(:,:,:)
1235 ! var_pref = 'R' // trim(var3d(n))
1236 var_pref
= trim(var3d(n
))
1238 call da_get_var_3d_real_cdf( da_file_02
, trim(var3d(n
)), &
1239 full3d
, dims(1), dims(2), dims(3), 1, debug
)
1242 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
1243 'Before couple Sample ', trim(var3d(n
)), &
1244 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
1250 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1f(k
)*(mu(i
,j
)+mub(i
,j
))+c2f(k
))/msfm(i
,j
)
1256 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
1257 'After couple Sample ', trim(var3d(n
)), &
1258 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
1261 var_pref
=trim(var3d(n
))
1263 if ( use_theta_m
> 0 .and
. trim(var3d(n
)) == 'T' ) then
1264 call da_get_var_3d_real_cdf( da_file_02
, 'THM', &
1265 full3d
, dims(1), dims(2), dims(3), 1, debug
)
1267 call da_get_var_3d_real_cdf( da_file_02
, trim(var3d(n
)), &
1268 full3d
, dims(1), dims(2), dims(3), 1, debug
)
1272 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
1273 'Before couple Sample ', trim(var3d(n
)), &
1274 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
1277 if ( dims(3) == nlevf
) then
1278 ! applying c1f and c2f for mu
1282 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1f(k
)*(mu(i
,j
)+mub(i
,j
))+c2f(k
))
1286 else if ( dims(3) == nlevh
) then
1287 ! applying c1h and c2h for mu
1291 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1h(k
)*(mu(i
,j
)+mub(i
,j
))+c2h(k
))
1296 write(unit
=stdout
,fmt
=*) 'Error finding matched dimensions.'
1301 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
1302 'After couple Sample ', trim(var3d(n
)), &
1303 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
1305 case ('QVAPOR', 'QCLOUD', 'QRAIN', 'QICE', 'QSNOW', 'QGRAUP') ;
1306 ! var_pref='R' // var3d(n)(1:2)
1307 ! var_pref=var3d(n)(1:2)
1310 call da_get_var_3d_real_cdf( da_file_02
, trim(var3d(n
)), &
1311 full3d
, dims(1), dims(2), dims(3), 1, debug
)
1314 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
1315 'Before couple Sample ', trim(var3d(n
)), &
1316 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
1322 full3d(i
,j
,k
)=full3d(i
,j
,k
)*(c1h(k
)*(mu(i
,j
)+mub(i
,j
))+c2h(k
))
1328 write(unit
=stdout
, fmt
='(3a,e20.12,4x)') &
1329 'After couple Sample ', trim(var3d(n
)), &
1330 '=', full3d(dims(1)/2,dims(2)/2,dims(3)/2)
1333 write(unit
=stdout
,fmt
=*) 'It is impossible here. var3d(', n
, ')=', trim(var3d(n
))
1337 var_name
=trim(var_pref
) // trim(bdyname(m
))
1338 vbt_name
=trim(var_pref
) // trim(tenname(m
))
1340 write(unit
=stdout
, fmt
='(a, i3, 2a)') &
1341 'Processing: bdyname(', m
, ')=', trim(var_name
)
1343 call da_get_dims_cdf( wrf_bdy_file
, trim(var_name
), dims
, ndims
, debug
)
1345 allocate(frst3d(dims(1), dims(2), dims(3)))
1346 allocate(scnd3d(dims(1), dims(2), dims(3)))
1347 allocate(tend3d(dims(1), dims(2), dims(3)))
1349 ! Get variable at second time level
1350 if (time_level
> 2) then
1351 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(var_name
), scnd3d
, &
1352 dims(1), dims(2), dims(3), 3, debug
)
1354 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(var_name
), frst3d
, &
1355 dims(1), dims(2), dims(3), 2, debug
)
1356 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend3d
, &
1357 dims(1), dims(2), dims(3), 2, debug
)
1361 write(unit
=ori_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
1362 'No.', m
, 'Variable: ', trim(vbt_name
), &
1363 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
1365 call da_get_var_3d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend3d
, &
1366 dims(1), dims(2), dims(3), 2, debug
)
1368 write(unit
=ori_unit
, fmt
='(a, 10i12)') &
1369 ' old ', (i
, i
=1,dims(3))
1371 write(unit
=ori_unit
, fmt
='(i4, 1x, 10e20.7)') &
1372 j
, (tend3d(j
,dims(2)/2,i
), i
=1,dims(3))
1376 select
case(trim(bdyname(m
)))
1377 case ('_BXS') ; ! West boundary
1381 if (time_level
< 3) &
1382 scnd3d(j
,k
,l
)=frst3d(j
,k
,l
)+tend3d(j
,k
,l
)*bdyfrq
1383 frst3d(j
,k
,l
)=full3d(l
,j
,k
)
1387 case ('_BXE') ; ! East boundary
1391 if (time_level
< 3) &
1392 scnd3d(j
,k
,l
)=frst3d(j
,k
,l
)+tend3d(j
,k
,l
)*bdyfrq
1393 frst3d(j
,k
,l
)=full3d(east_end
-l
,j
,k
)
1397 case ('_BYS') ; ! South boundary
1401 if (time_level
< 3) &
1402 scnd3d(i
,k
,l
)=frst3d(i
,k
,l
)+tend3d(i
,k
,l
)*bdyfrq
1403 frst3d(i
,k
,l
)=full3d(i
,l
,k
)
1407 case ('_BYE') ; ! North boundary
1411 if (time_level
< 3) &
1412 scnd3d(i
,k
,l
)=frst3d(i
,k
,l
)+tend3d(i
,k
,l
)*bdyfrq
1413 frst3d(i
,k
,l
)=full3d(i
,north_end
-l
,k
)
1418 write(unit
=stdout
,fmt
=*) 'It is impossible here.'
1419 write(unit
=stdout
,fmt
=*) 'bdyname(', m
, ')=', trim(bdyname(m
))
1423 write(unit
=stdout
, fmt
='(a, i3, 2a)') &
1424 'cal. tend: bdyname(', m
, ')=', trim(vbt_name
)
1426 ! calculate new tendancy
1430 tend3d(i
,k
,l
)=(scnd3d(i
,k
,l
)-frst3d(i
,k
,l
))/bdyfrq
1436 write(unit
=new_unit
, fmt
='(a,i2,2x,2a/a,i2,2x,a,4i6)') &
1437 'No.', m
, 'Variable: ', trim(vbt_name
), &
1438 'ndims=', ndims
, 'dims=', (dims(i
), i
=1,ndims
)
1440 write(unit
=new_unit
, fmt
='(a, 10i12)') &
1441 ' new ', (i
, i
=1,dims(3))
1444 write(unit
=new_unit
, fmt
='(i4, 1x, 10e20.7)') &
1445 j
, (tend3d(j
,dims(2)/2,i
), i
=1,dims(3))
1449 ! output new variable at first time level
1450 call da_put_var_3d_real_cdf( wrf_bdy_file
, trim(var_name
), frst3d
, &
1451 dims(1), dims(2), dims(3), 2, debug
)
1452 call da_put_var_3d_real_cdf( wrf_bdy_file
, trim(vbt_name
), tend3d
, &
1453 dims(1), dims(2), dims(3), 2, debug
)
1467 end if ! end of update second time level LBC for var4d_lbc
1473 deallocate(thisbdytime
)
1474 deallocate(nextbdytime
)
1476 end if ! end if update_lateral_bdy
1483 write(unit
=stdout
,fmt
=*) &
1484 '=================================================================='
1485 if ( update_lateral_bdy
) then
1486 write(unit
=stdout
,fmt
=*) 'Lateral boundary tendency updated.'
1488 if ( update_low_bdy
) then
1489 write(unit
=stdout
,fmt
=*) 'Low boundary updated with wrf_input fields.'
1491 if ( update_lsm
) then
1492 write(unit
=stdout
,fmt
=*) 'LSM variables updated with wrf_input fields.'
1495 if (io_status
== 0) &
1496 write (unit
=stdout
,fmt
=*) "*** Update_bc completed successfully ***"
1498 end program da_update_bc