50 integer,
parameter :: grads_vars_limit = 1000
51 integer,
parameter :: num_item_list = 25
52 integer,
parameter :: num_item_list_atom = 25
53 integer,
parameter :: num_item_list_land = 12
54 integer,
parameter :: num_item_list_ocean = 10
55 logical :: data_available(num_item_list_atom,3)
56 character(len=H_SHORT) :: item_list_atom (num_item_list_atom)
57 character(len=H_SHORT) :: item_list_land (num_item_list_land)
58 character(len=H_SHORT) :: item_list_ocean(num_item_list_ocean)
59 data item_list_atom /
'lon',
'lat',
'plev',
'DENS',
'U',
'V',
'W',
'T',
'HGT',
'QV',
'QC',
'QR',
'QI',
'QS',
'QG',
'RH', &
60 'MSLP',
'PSFC',
'U10',
'V10',
'T2',
'Q2',
'RH2',
'TOPO',
'RN222' /
61 data item_list_land /
'lsmask',
'lon',
'lat',
'lon_sfc',
'lat_sfc',
'llev', &
62 'STEMP',
'SMOISVC',
'SMOISDS',
'SKINT',
'TOPO',
'TOPO_sfc' /
63 data item_list_ocean /
'lsmask',
'lsmask_sst',
'lon',
'lat',
'lon_sfc',
'lat_sfc',
'lon_sst',
'lat_sst',
'SKINT',
'SST'/
65 integer,
parameter :: ia_lon = 1
66 integer,
parameter :: ia_lat = 2
67 integer,
parameter :: ia_p = 3
68 integer,
parameter :: ia_dens = 4
69 integer,
parameter :: ia_u = 5
70 integer,
parameter :: ia_v = 6
71 integer,
parameter :: ia_w = 7
72 integer,
parameter :: ia_t = 8
73 integer,
parameter :: ia_hgt = 9
74 integer,
parameter :: ia_qv = 10
75 integer,
parameter :: ia_qc = 11
76 integer,
parameter :: ia_qr = 12
77 integer,
parameter :: ia_qi = 13
78 integer,
parameter :: ia_qs = 14
79 integer,
parameter :: ia_qg = 15
80 integer,
parameter :: ia_rh = 16
81 integer,
parameter :: ia_slp = 17
82 integer,
parameter :: ia_ps = 18
83 integer,
parameter :: ia_u10 = 19
84 integer,
parameter :: ia_v10 = 20
85 integer,
parameter :: ia_t2 = 21
86 integer,
parameter :: ia_q2 = 22
87 integer,
parameter :: ia_rh2 = 23
88 integer,
parameter :: ia_topo = 24
89 integer,
parameter :: ia_rn222 = 25
91 integer,
parameter :: il_lsmask = 1
92 integer,
parameter :: il_lon = 2
93 integer,
parameter :: il_lat = 3
94 integer,
parameter :: il_lon_sfc = 4
95 integer,
parameter :: il_lat_sfc = 5
96 integer,
parameter :: il_lz = 6
97 integer,
parameter :: il_stemp = 7
98 integer,
parameter :: il_smoisvc = 8
99 integer,
parameter :: il_smoisds = 9
100 integer,
parameter :: il_skint = 10
101 integer,
parameter :: il_topo = 11
102 integer,
parameter :: il_topo_sfc= 12
104 integer,
parameter :: io_lsmask = 1
105 integer,
parameter :: io_lsmask_sst = 2
106 integer,
parameter :: io_lon = 3
107 integer,
parameter :: io_lat = 4
108 integer,
parameter :: io_lon_sfc = 5
109 integer,
parameter :: io_lat_sfc = 6
110 integer,
parameter :: io_lon_sst = 7
111 integer,
parameter :: io_lat_sst = 8
112 integer,
parameter :: io_skint = 9
113 integer,
parameter :: io_sst = 10
116 integer,
parameter :: lvars_limit = 1000
117 real(RP),
parameter :: large_number_one = 9.999e+15_rp
120 character(len=H_SHORT) :: upper_qv_type =
"ZERO" 124 character(len=H_SHORT) :: grads_item (num_item_list,3)
125 character(len=H_LONG) :: grads_dtype (num_item_list,3)
126 character(len=H_LONG) :: grads_fname (num_item_list,3)
127 character(len=H_SHORT) :: grads_fendian (num_item_list,3)
128 character(len=H_SHORT) :: grads_yrev (num_item_list,3)
129 real(RP) :: grads_swpoint (num_item_list,3)
130 real(RP) :: grads_dd (num_item_list,3)
131 integer :: grads_lnum (num_item_list,3)
132 real(RP) :: grads_lvars (lvars_limit,num_item_list,3)
133 integer :: grads_startrec(num_item_list,3)
134 integer :: grads_totalrec(num_item_list,3)
135 integer :: grads_knum (num_item_list,3)
136 real(SP) :: grads_missval (num_item_list,3)
138 real(SP),
allocatable :: gdata2d(:,:)
139 real(SP),
allocatable :: gdata3d(:,:,:)
140 real(SP),
allocatable :: gland2d(:,:)
141 real(SP),
allocatable :: gland3d(:,:,:)
142 real(SP),
allocatable :: gsst2d (:,:)
144 integer :: io_fid_grads_nml = -1
145 integer :: io_fid_grads_data = -1
149 integer :: outer_nx = -1
150 integer :: outer_ny = -1
151 integer :: outer_nz = -1
152 integer :: outer_nl = -1
154 integer :: outer_nx_sfc = -1
155 integer :: outer_ny_sfc = -1
157 integer :: outer_nx_sst = -1
158 integer :: outer_ny_sst = -1
160 namelist / nml_grads_grid / &
170 character(len=H_SHORT) :: item
172 character(len=H_SHORT) :: dtype
173 character(len=H_LONG) :: fname
177 real(RP) :: lvars(lvars_limit) = large_number_one
181 character(len=H_SHORT) :: fendian=
'big' 182 character(len=H_SHORT) :: yrev=
'off' 194 integer,
intent(out) :: dims(6)
195 character(len=*),
intent(in) :: basename
197 namelist / param_mkinit_real_grads / &
206 log_info(
"ParentAtmosSetupGrADS",*)
'Setup' 210 read(
io_fid_conf,nml=param_mkinit_real_grads,iostat=ierr)
213 log_error(
"ParentAtmosSetupGrADS",*)
'Not appropriate names in namelist PARAM_MKINIT_REAL_GrADS. Check!' 216 log_nml(param_mkinit_real_grads)
219 if ( len_trim(basename) == 0 )
then 220 log_error(
"ParentAtmosSetupGrADS",*)
'"BASENAME_ORG" is not specified in "PARAM_MKINIT_ATMOS_GRID_CARTESC_REAL_ATMOS"!', trim(basename)
226 open( io_fid_grads_nml, &
227 file = trim(basename), &
228 form =
'formatted', &
232 if ( ierr /= 0 )
then 233 log_error(
"ParentAtmosSetupGrADS",*)
'Input file is not found! ', trim(basename)
237 read(io_fid_grads_nml,nml=nml_grads_grid,iostat=ierr)
239 log_error(
"ParentAtmosSetupGrADS",*)
'Not appropriate names in nml_grads_grid in ', trim(basename),
'. Check!' 242 log_nml(nml_grads_grid)
253 allocate( gdata2d( dims(2), dims(3) ) )
254 allocate( gdata3d( dims(2), dims(3), dims(1) ) )
260 grads_swpoint(:,1), &
263 grads_lvars(:,:,1), &
264 grads_startrec(:,1), &
265 grads_totalrec(:,1), &
268 grads_fendian(:,1), &
269 grads_missval(:,1), &
270 data_available(:,1), &
272 num_item_list_atom, &
276 close( io_fid_grads_nml )
278 do ielem = 1, num_item_list_atom
279 item = item_list_atom(ielem)
281 select case(trim(item))
282 case(
'DENS',
'W',
'QC',
'QR',
'QI',
'QS',
'QG',
'MSLP',
'PSFC',
'U10',
'V10',
'T2',
'Q2',
'TOPO',
'RN222')
283 if (.not. data_available(ielem,1))
then 284 log_warn(
"ParentAtmosSetupGrADS",*) trim(item),
' is not found & will be estimated.' 288 if (.not. data_available(ia_qv,1))
then 289 if (.not.data_available(ia_rh,1))
then 290 log_error(
"ParentAtmosSetupGrADS",*)
'Not found in grads namelist! : QV and RH' 297 if (.not. data_available(ia_qv,1))
then 298 if(data_available(ia_rh,1))
then 299 if ((.not. data_available(ia_t,1)).or.(.not. data_available(ia_p,1)))
then 300 log_error(
"ParentAtmosSetupGrADS",*)
'Temperature and pressure are required to convert from RH to QV ! ' 306 log_error(
"ParentAtmosSetupGrADS",*)
'Not found in grads namelist! : QV and RH' 311 if ( data_available(ia_q2,1) )
then 314 if ( data_available(ia_rh2,1) )
then 315 if ((.not. data_available(ia_t2,1)).or.(.not. data_available(ia_ps,1)))
then 316 log_warn(
"ParentAtmosSetupGrADS",*)
'T2 and PSFC are required to convert from RH2 to Q2 !' 317 log_info_cont(*)
'Q2 will be copied from data at above level.' 318 data_available(ia_rh2,1) = .false.
322 log_warn(
"ParentAtmosSetupGrADS",*)
'Q2 and RH2 are not found, Q2 will be estimated.' 327 if ( .not. data_available(ielem,1) )
then 328 log_error(
"ParentAtmosSetupGrADS",*)
'Not found in grads namelist! : ',trim(item_list_atom(ielem))
381 psat => atmos_saturation_psat_liq
385 real(RP),
intent(out) :: velz_org(:,:,:)
386 real(RP),
intent(out) :: velx_org(:,:,:)
387 real(RP),
intent(out) :: vely_org(:,:,:)
388 real(RP),
intent(out) :: pres_org(:,:,:)
389 real(RP),
intent(out) :: dens_org(:,:,:)
390 real(RP),
intent(out) :: temp_org(:,:,:)
391 real(RP),
intent(out) :: qv_org (:,:,:)
392 real(RP),
intent(out) :: qhyd_org(:,:,:,:)
393 real(RP),
intent(out) :: RN222_org(:,:,:)
394 real(RP),
intent(out) :: lon_org(:,:)
395 real(RP),
intent(out) :: lat_org(:,:)
396 real(RP),
intent(out) :: cz_org(:,:,:)
397 character(len=*),
intent(in) :: basename_num
398 integer,
intent(in) :: dims(6)
399 integer,
intent(in) :: nt
401 real(RP) :: rhprs_org(dims(1)+2,dims(2),dims(3))
403 integer :: lm_layer(dims(2),dims(3))
405 character(len=H_LONG) :: gfile
407 real(RP) :: p_sat, qm, rhsfc, dz
408 logical :: pressure_coordinates
410 integer :: i, j, k, iq, ielem
413 dens_org(:,:,:) = undef
414 velz_org(:,:,:) = 0.0_rp
415 qv_org(:,:,:) = 0.0_rp
416 qhyd_org(:,:,:,:) = 0.0_rp
417 rn222_org(:,:,:) = 0.0_rp
420 loop_inputatmosgrads :
do ielem = 1, num_item_list_atom
422 if ( .not. data_available(ielem,1) ) cycle
424 item = grads_item(ielem,1)
425 dtype = grads_dtype(ielem,1)
426 fname = grads_fname(ielem,1)
427 lnum = grads_lnum(ielem,1)
428 missval = grads_missval(ielem,1)
430 if ( dims(1) < grads_knum(ielem,1) )
then 431 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be less than or equal to outer_nz. knum:',knum,
'> outer_nz:',dims(1),trim(item)
433 else if ( grads_knum(ielem,1) > 0 )
then 434 knum = grads_knum(ielem,1)
439 select case(trim(dtype))
441 swpoint = grads_swpoint(ielem,1)
442 dd = grads_dd(ielem,1)
443 if( (abs(swpoint-large_number_one)<eps).or.(abs(dd-large_number_one)<eps) )
then 444 log_error(
"ParentAtmosInputGrADS",*)
'"swpoint" is required in grads namelist! ',swpoint
445 log_error_cont(*)
'"dd" is required in grads namelist! ',dd
450 log_error(
"ParentAtmosInputGrADS",*)
'"lnum" is required in grads namelist for levels data! ' 454 lvars(k)=grads_lvars(k,ielem,1)
456 if(abs(lvars(1)-large_number_one)<eps)
then 457 log_error(
"ParentAtmosInputGrADS",*)
'"lvars" must be specified in grads namelist for levels data! ' 461 startrec = grads_startrec(ielem,1)
462 totalrec = grads_totalrec(ielem,1)
463 fendian = grads_fendian(ielem,1)
464 yrev = grads_yrev(ielem,1)
465 if( (startrec<0).or.(totalrec<0) )
then 466 log_error(
"ParentAtmosInputGrADS",*)
'"startrec" is required in grads namelist! ',startrec
467 log_error_cont(*)
'"totalrec" is required in grads namelist! ',totalrec
471 if(io_fid_grads_data < 0)
then 474 gfile=trim(fname)//trim(basename_num)//
'.grd' 475 if( len_trim(fname)==0 )
then 476 log_error(
"ParentAtmosInputGrADS",*)
'"fname" is required in grads namelist for map data! ',trim(fname)
482 select case(trim(item))
484 if ( trim(dtype) ==
"linear" )
then 487 lon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * D2R
490 else if ( trim(dtype) ==
"map" )
then 491 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,1,item,startrec,totalrec,yrev,gdata2d)
492 lon_org(:,:) =
real(gdata2D(:,:), kind=RP) * D2R
495 if ( trim(dtype) ==
"linear" )
then 498 lat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * D2R
501 else if ( trim(dtype) ==
"map" )
then 502 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,1,item,startrec,totalrec,yrev,gdata2d)
503 lat_org(:,:) =
real(gdata2D(:,:), kind=RP) * D2R
506 if(dims(1)/=knum)
then 507 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be equal to outer_nz for ',trim(item),
'. knum:',knum,
'> outer_nz:',dims(1)
510 if ( trim(dtype) ==
"levels" )
then 511 pressure_coordinates = .true.
512 if(dims(1)/=lnum)
then 513 log_error(
"ParentAtmosInputGrADS",*)
'lnum must be same as the outer_nz for plev! ',dims(1),lnum
519 pres_org(k+2,i,j) =
real(lvars(k), kind=
rp)
523 else if ( trim(dtype) ==
"map" )
then 524 pressure_coordinates = .false.
525 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),dims(1),nt,item,startrec,totalrec,yrev,gdata3d)
529 pres_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
531 if( abs( pres_org(k+2,i,j) - missval ) < eps )
then 532 pres_org(k+2,i,j) = undef
539 if(dims(1)/=knum)
then 540 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be equal to outer_nz for ',trim(item),
'. knum:',knum,
'> outer_nz:',dims(1)
543 if ( trim(dtype) ==
"map" )
then 544 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
548 dens_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
550 if( abs( dens_org(k+2,i,j) - missval ) < eps )
then 551 dens_org(k+2,i,j) = undef
558 if(dims(1)/=knum)
then 559 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be equal to outer_nz for ',trim(item),
'. knum:',knum,
'> outer_nz:',dims(1)
562 if ( trim(dtype) ==
"map" )
then 563 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
566 velx_org(1:2,i,j) = 0.0_rp
568 velx_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
570 if( abs( velx_org(k+2,i,j) - missval ) < eps )
then 571 velx_org(k+2,i,j) = undef
578 if(dims(1)/=knum)
then 579 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be equal to outer_nz for ',trim(item),
'. knum:',knum,
'> outer_nz:',dims(1)
582 if ( trim(dtype) ==
"map" )
then 583 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
586 vely_org(1:2,i,j) = 0.0_rp
588 vely_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
590 if( abs( vely_org(k+2,i,j) - missval ) < eps )
then 591 vely_org(k+2,i,j) = undef
598 if(dims(1)/=knum)
then 599 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be equal to outer_nz for ',trim(item),
'. knum:',knum,
'> outer_nz:',dims(1)
602 if ( trim(dtype) ==
"map" )
then 603 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
606 velz_org(1:2,i,j) = 0.0_rp
608 velz_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
610 if( abs( velz_org(k+2,i,j) - missval ) < eps )
then 611 velz_org(k+2,i,j) = undef
618 if(dims(1)/=knum)
then 619 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be equal to outer_nz for ',trim(item),
'. knum:',knum,
'> outer_nz:',dims(1)
622 if ( trim(dtype) ==
"map" )
then 623 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
627 temp_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
629 if( abs( temp_org(k+2,i,j) - missval ) < eps )
then 630 temp_org(k+2,i,j) = undef
637 if(dims(1)/=knum)
then 638 log_error(
"ParentAtmosInputGrADS",*)
'"knum" must be equal to outer_nz for ',trim(item),
'. knum:',knum,
'> outer_nz:',dims(1)
641 if ( trim(dtype) ==
"levels" )
then 642 if(dims(1)/=lnum)
then 643 log_error(
"ParentAtmosInputGrADS",*)
'lnum must be same as the outer_nz for HGT! ',dims(1),lnum
649 cz_org(k+2,i,j) =
real(lvars(k), kind=
rp)
651 cz_org(1,i,j) = 0.0_rp
654 else if ( trim(dtype) ==
"map" )
then 655 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),dims(1),nt,item,startrec,totalrec,yrev,gdata3d)
659 cz_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
661 if( abs( cz_org(k+2,i,j) - missval ) < eps )
then 662 cz_org(k+2,i,j) = undef
665 cz_org(1,i,j) = 0.0_rp
670 if ( trim(dtype) ==
"map" )
then 671 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
675 qv_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
677 if( abs( qv_org(k+2,i,j) - missval ) < eps )
then 678 qv_org(k+2,i,j) = undef
681 qv_org(1:2,i,j) = qv_org(3,i,j)
684 if( dims(1)>knum )
then 685 select case( upper_qv_type )
689 do k = knum+1, dims(1)
690 qv_org(k+2,i,j) = qv_org(knum+2,i,j)
697 log_error(
"ParentAtmosInputGrADS",*)
'upper_qv_type in PARAM_MKINIT_REAL_GrADS is invalid! ', upper_qv_type
703 if ( trim(dtype) ==
"map" )
then 704 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
708 qhyd_org(k+2,i,j,
i_hc) =
real(gdata3D(i,j,k), kind=
rp)
710 if( abs( qhyd_org(k+2,i,j,
i_hc) - missval ) < eps )
then 711 qhyd_org(k+2,i,j,
i_hc) = undef
714 qhyd_org(1:2,i,j,
i_hc) = qhyd_org(3,i,j,
i_hc)
720 if ( trim(dtype) ==
"map" )
then 721 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
725 qhyd_org(k+2,i,j,
i_hr) =
real(gdata3D(i,j,k), kind=
rp)
727 if( abs( qhyd_org(k+2,i,j,
i_hr) - missval ) < eps )
then 728 qhyd_org(k+2,i,j,
i_hr) = undef
731 qhyd_org(1:2,i,j,
i_hr) = qhyd_org(3,i,j,
i_hr)
737 if ( trim(dtype) ==
"map" )
then 738 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
742 qhyd_org(k+2,i,j,
i_hi) =
real(gdata3D(i,j,k), kind=
rp)
744 if( abs( qhyd_org(k+2,i,j,
i_hi) - missval ) < eps )
then 745 qhyd_org(k+2,i,j,
i_hi) = undef
748 qhyd_org(1:2,i,j,
i_hi) = qhyd_org(3,i,j,
i_hi)
754 if ( trim(dtype) ==
"map" )
then 755 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
759 qhyd_org(k+2,i,j,
i_hs) =
real(gdata3D(i,j,k), kind=
rp)
761 if( abs( qhyd_org(k+2,i,j,
i_hs) - missval ) < eps )
then 762 qhyd_org(k+2,i,j,
i_hs) = undef
765 qhyd_org(1:2,i,j,
i_hs) = qhyd_org(3,i,j,
i_hs)
771 if ( trim(dtype) ==
"map" )
then 772 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
776 qhyd_org(k+2,i,j,
i_hg) =
real(gdata3D(i,j,k), kind=
rp)
778 if( abs( qhyd_org(k+2,i,j,
i_hg) - missval ) < eps )
then 779 qhyd_org(k+2,i,j,
i_hg) = undef
782 qhyd_org(1:2,i,j,
i_hg) = qhyd_org(3,i,j,
i_hg)
788 if (data_available(ia_qv,1)) cycle
789 if ( trim(dtype) ==
"map" )
then 790 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
794 qv_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
796 if( abs( qv_org(k+2,i,j) - missval ) < eps )
then 797 qv_org(k+2,i,j) = undef
799 rhprs_org(k+2,i,j) = qv_org(k+2,i,j) / 100.0_rp
800 call psat( temp_org(k+2,i,j), p_sat )
801 qm = epsvap * rhprs_org(k+2,i,j) * p_sat &
802 / ( pres_org(k+2,i,j) - rhprs_org(k+2,i,j) * p_sat )
803 qv_org(k+2,i,j) = qm / ( 1.0_rp + qm )
806 qv_org(1:2,i,j) = qv_org(3,i,j)
809 if( dims(1)>knum )
then 810 select case( upper_qv_type )
814 do k = knum+1, dims(1)
815 rhprs_org(k+2,i,j) = rhprs_org(knum+2,i,j)
816 call psat( temp_org(k+2,i,j), p_sat )
817 qm = epsvap * rhprs_org(k+2,i,j) * p_sat &
818 / ( pres_org(k+2,i,j) - rhprs_org(k+2,i,j) * p_sat )
819 qv_org(k+2,i,j) = qm / ( 1.0_rp + qm )
820 qv_org(k+2,i,j) = min(qv_org(k+2,i,j),qv_org(k+1,i,j))
827 log_error(
"ParentAtmosInputGrADS",*)
'upper_qv_type in PARAM_MKINIT_REAL_GrADS is invalid! ', upper_qv_type
833 if ( trim(dtype) ==
"map" )
then 834 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
837 pres_org(1,i,j) =
real(gdata2D(i,j), kind=
rp)
839 if( abs( pres_org(1,i,j) - missval ) < eps )
then 840 pres_org(1,i,j) = undef
846 if ( trim(dtype) ==
"map" )
then 847 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
850 pres_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
852 if( abs( pres_org(2,i,j) - missval ) < eps )
then 853 pres_org(2,i,j) = undef
859 if ( trim(dtype) ==
"map" )
then 860 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
863 velx_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
865 if( abs( velx_org(2,i,j) - missval ) < eps )
then 866 velx_org(2,i,j) = undef
872 if ( trim(dtype) ==
"map" )
then 873 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
876 vely_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
878 if( abs( vely_org(2,i,j) - missval ) < eps )
then 879 vely_org(2,i,j) = undef
885 if ( trim(dtype) ==
"map" )
then 886 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
889 temp_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
891 if( abs( temp_org(2,i,j) - missval ) < eps )
then 892 temp_org(2,i,j) = undef
898 if ( trim(dtype) ==
"map" )
then 899 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
902 qv_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
904 if( abs( qv_org(2,i,j) - missval ) < eps )
then 905 qv_org(2,i,j) = undef
911 if (data_available(ia_q2,1)) cycle
912 if ( trim(dtype) ==
"map" )
then 913 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
916 qv_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
918 if( abs( qv_org(2,i,j) - missval ) < eps )
then 919 qv_org(2,i,j) = undef
921 rhsfc = qv_org(2,i,j) / 100.0_rp
922 call psat( temp_org(2,i,j), p_sat )
923 qm = epsvap * rhsfc * p_sat &
924 / ( pres_org(2,i,j) - rhsfc * p_sat )
925 qv_org(2,i,j) = qm / ( 1.0_rp + qm )
931 if ( trim(dtype) ==
"map" )
then 932 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
935 cz_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
937 if( abs( cz_org(2,i,j) - missval ) < eps )
then 938 cz_org(2,i,j) = undef
944 if ( trim(dtype) ==
'map' )
then 945 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
949 rn222_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
951 if( abs( rn222_org(k+2,i,j) - missval ) < eps )
then 952 rn222_org(k+2,i,j) = undef
955 rn222_org(1:2,i,j) = rn222_org(3,i,j)
960 enddo loop_inputatmosgrads
968 if( abs( pres_org(k,i,j) - undef ) < eps )
then 969 lm_layer(i,j) = k + 1
978 if ( .not. data_available(ia_dens,1) )
then 981 do k = lm_layer(i,j), dims(1)+2
982 rtot = rdry * ( 1.0_rp + epstvap * qv_org(k,i,j) )
983 dens_org(k,i,j) = pres_org(k,i,j) / ( rtot * temp_org(k,i,j) )
990 if ( data_available(ia_topo,1) )
then 991 if ( data_available(ia_t2,1) .and. data_available(ia_ps,1) )
then 994 rtot = rdry * ( 1.0_rp + epstvap * qv_org(2,i,j) )
995 dens_org(2,i,j) = pres_org(2,i,j) / ( rtot * temp_org(2,i,j) )
998 else if ( data_available(ia_ps,1) )
then 1002 dz = cz_org(k,i,j) - cz_org(2,i,j)
1003 dens_org(2,i,j) = - ( pres_org(k,i,j) - pres_org(2,i,j) ) * 2.0_rp / ( grav * dz ) &
1005 rtot = rdry * ( 1.0_rp + epstvap * qv_org(2,i,j) )
1006 temp_org(2,i,j) = pres_org(2,i,j) / ( rtot * dens_org(2,i,j) )
1009 else if ( data_available(ia_t2,1) )
then 1013 dz = cz_org(k,i,j) - cz_org(2,i,j)
1014 rtot = rdry * ( 1.0_rp + epstvap * qv_org(2,i,j) )
1015 dens_org(2,i,j) = ( pres_org(k,i,j) + grav * dens_org(k,i,j) * dz * 0.5_rp ) &
1016 / ( rtot * temp_org(2,i,j) - grav * dz * 0.5_rp )
1017 pres_org(2,i,j) = dens_org(2,i,j) * rtot * temp_org(2,i,j)
1024 dz = cz_org(k,i,j) - cz_org(2,i,j)
1025 temp_org(2,i,j) = temp_org(k,i,j) + laps * dz
1026 rtot = rdry * ( 1.0_rp + epstvap * qv_org(2,i,j) )
1027 dens_org(2,i,j) = ( pres_org(k,i,j) + grav * dens_org(k,i,j) * dz * 0.5_rp ) &
1028 / ( rtot * temp_org(2,i,j) - grav * dz * 0.5_rp )
1029 pres_org(2,i,j) = dens_org(2,i,j) * rtot * temp_org(2,i,j)
1038 cz_org(2,i,j) = cz_org(k,i,j)
1039 velz_org(2,i,j) = velz_org(k,i,j)
1040 velx_org(2,i,j) = velx_org(k,i,j)
1041 vely_org(2,i,j) = vely_org(k,i,j)
1042 pres_org(2,i,j) = pres_org(k,i,j)
1043 temp_org(2,i,j) = temp_org(k,i,j)
1044 dens_org(2,i,j) = dens_org(k,i,j)
1045 qv_org(2,i,j) = qv_org(k,i,j)
1046 qhyd_org(2,i,j,:) = qhyd_org(k,i,j,:)
1047 rn222_org(2,i,j) = rn222_org(k,i,j)
1069 temp_org(1,i,j) = temp_org(2,i,j) + laps * cz_org(2,i,j)
1072 if ( data_available(ia_slp,1) )
then 1075 dens_org(1,i,j) = pres_org(1,i,j) / ( rdry * temp_org(1,i,j) )
1081 dens_org(1,i,j) = ( pres_org(2,i,j) + grav * dens_org(2,i,j) * cz_org(2,i,j) * 0.5_rp ) &
1082 / ( rdry * temp_org(1,i,j) - grav * cz_org(2,i,j) * 0.5_rp )
1083 pres_org(1,i,j) = dens_org(1,i,j) * rdry * temp_org(1,i,j)
1089 if( pressure_coordinates )
then 1093 if( pres_org(k,i,j) > pres_org(2,i,j) )
then 1094 velz_org(k,i,j) = velz_org(2,i,j)
1095 velx_org(k,i,j) = velx_org(2,i,j)
1096 vely_org(k,i,j) = vely_org(2,i,j)
1097 pres_org(k,i,j) = pres_org(2,i,j)
1098 dens_org(k,i,j) = dens_org(2,i,j)
1099 temp_org(k,i,j) = temp_org(2,i,j)
1100 qv_org(k,i,j) = qv_org(2,i,j)
1101 qhyd_org(k,i,j,:) = qhyd_org(2,i,j,:)
1102 cz_org(k,i,j) = cz_org(2,i,j)
1104 rn222_org(k,i,j) = rn222_org(2,i,j)
1113 if( cz_org(k,i,j) < cz_org(2,i,j) )
then 1114 velz_org(k,i,j) = velz_org(2,i,j)
1115 velx_org(k,i,j) = velx_org(2,i,j)
1116 vely_org(k,i,j) = vely_org(2,i,j)
1117 pres_org(k,i,j) = pres_org(2,i,j)
1118 dens_org(k,i,j) = dens_org(2,i,j)
1119 temp_org(k,i,j) = temp_org(2,i,j)
1120 qv_org(k,i,j) = qv_org(2,i,j)
1121 qhyd_org(k,i,j,:) = qhyd_org(2,i,j,:)
1122 cz_org(k,i,j) = cz_org(2,i,j)
1123 rn222_org(k,i,j) = 0.0_rp
1138 use_file_landwater, &
1142 integer,
intent(out) :: ldims(3)
1143 logical,
intent(out) :: use_waterratio
1144 logical,
intent(in) :: use_file_landwater
1145 character(len=*),
intent(in) :: basename
1151 log_info(
"ParentLandSetupGrADS",*)
'Real Case/Land Input File Type: GrADS format' 1154 use_waterratio = .false.
1156 if ( len_trim(basename) == 0 )
then 1157 log_error(
"ParentLandSetupGrADS",*)
'"BASEMAAME" is not specified in "PARAM_MKINIT_ATMOS_GRID_CARTESC_REAL_ATOMS"!', trim(basename)
1163 open( io_fid_grads_nml, &
1164 file = trim(basename), &
1165 form =
'formatted', &
1169 if ( ierr /= 0 )
then 1170 log_error(
"ParentLandSetupGrADS",*)
'Input file is not found! ', trim(basename)
1174 read(io_fid_grads_nml,nml=nml_grads_grid,iostat=ierr)
1175 if( ierr /= 0 )
then 1176 log_error(
"ParentLandSetupGrADS",*)
'Not appropriate names in nml_grads_grid in ', trim(basename),
'. Check!' 1179 log_nml(nml_grads_grid)
1183 if(outer_nx_sfc > 0)
then 1184 ldims(2) = outer_nx_sfc
1187 outer_nx_sfc = outer_nx
1189 if(outer_ny_sfc > 0)
then 1190 ldims(3) = outer_ny_sfc
1193 outer_ny_sfc = outer_ny
1196 allocate( gland2d( ldims(2), ldims(3) ) )
1197 allocate( gland3d( ldims(2), ldims(3), ldims(1) ) )
1203 grads_swpoint(:,2), &
1206 grads_lvars(:,:,2), &
1207 grads_startrec(:,2), &
1208 grads_totalrec(:,2), &
1211 grads_fendian(:,2), &
1212 grads_missval(:,2), &
1213 data_available(:,2), &
1215 num_item_list_land, &
1219 close( io_fid_grads_nml )
1221 do ielem = 1, num_item_list_land
1222 item = item_list_land(ielem)
1224 select case(trim(item))
1225 case(
'TOPO',
'TOPO_sfc',
'lsmask')
1226 if ( .not. data_available(ielem,2) )
then 1227 log_warn(
"ParentLandSetupGrADS",*) trim(item),
' is not found & not used.' 1230 case(
'lon',
'lat',
'lon_sfc',
'lat_sfc')
1232 case(
'SMOISVC',
'SMOISDS')
1233 if ( use_file_landwater )
then 1234 if (.not. data_available(il_smoisvc,2) .and. .not. data_available(il_smoisds,2))
then 1235 log_error(
"ParentLandSetupGrADS",*)
'Not found in grads namelist! : ',trim(item_list_land(ielem))
1238 use_waterratio = data_available(il_smoisds,2)
1243 if ( .not. data_available(ielem,2) )
then 1244 log_error(
"ParentLandSetupGrADS",*)
'Not found in grads namelist! : ',trim(item_list_land(ielem))
1266 use_file_landwater, &
1275 real(RP),
intent(out) :: tg_org (:,:,:)
1276 real(RP),
intent(out) :: strg_org (:,:,:)
1277 real(RP),
intent(out) :: smds_org (:,:,:)
1278 real(RP),
intent(out) :: lst_org (:,:)
1279 real(RP),
intent(out) :: llon_org (:,:)
1280 real(RP),
intent(out) :: llat_org (:,:)
1281 real(RP),
intent(out) :: lz_org (:)
1282 real(RP),
intent(out) :: topo_org (:,:)
1283 real(RP),
intent(out) :: lmask_org(:,:)
1284 character(len=*),
intent(in) :: basename_num
1285 integer,
intent(in) :: ldims(3)
1286 logical,
intent(in) :: use_file_landwater
1287 integer,
intent(in) :: nt
1289 character(len=H_LONG) :: gfile
1291 integer :: i, j, k, ielem
1294 loop_inputlandgrads :
do ielem = 1, num_item_list_land
1296 item = item_list_land(ielem)
1298 dtype = grads_dtype(ielem,2)
1299 fname = grads_fname(ielem,2)
1300 lnum = grads_lnum(ielem,2)
1301 missval = grads_missval(ielem,2)
1303 if ( grads_knum(ielem,2) > 0 )
then 1304 knum = grads_knum(ielem,2)
1309 select case(trim(dtype))
1311 swpoint = grads_swpoint(ielem,2)
1312 dd = grads_dd(ielem,2)
1313 if( (abs(swpoint-large_number_one)<eps).or.(abs(dd-large_number_one)<eps) )
then 1314 log_error(
"ParentLandInputGrADS",*)
'"swpoint" is required in grads namelist! ',swpoint
1315 log_error_cont(*)
'"dd" is required in grads namelist! ',dd
1320 log_error(
"ParentLandInputGrADS",*)
'"lnum" in grads namelist is required for levels data! ' 1324 lvars(k)=grads_lvars(k,ielem,2)
1326 if(abs(lvars(1)-large_number_one)<eps)
then 1327 log_error(
"ParentLandInputGrADS",*)
'"lvars" must be specified in grads namelist for levels data!',(lvars(k),k=1,lnum)
1331 startrec = grads_startrec(ielem,2)
1332 totalrec = grads_totalrec(ielem,2)
1333 fendian = grads_fendian(ielem,2)
1334 yrev = grads_yrev(ielem,2)
1335 if( (startrec<0).or.(totalrec<0) )
then 1336 log_error(
"ParentLandInputGrADS",*)
'"startrec" is required in grads namelist! ',startrec
1337 log_error_cont(*)
'"totalrec" is required in grads namelist! ',totalrec
1341 if(io_fid_grads_data < 0)
then 1344 gfile=trim(fname)//trim(basename_num)//
'.grd' 1345 if( len_trim(fname)==0 )
then 1346 log_error(
"ParentLandInputGrADS",*)
'"fname" is required in grads namelist for map data! ',trim(fname)
1352 select case(trim(item))
1354 if ( data_available(il_lsmask,2) )
then 1355 if ( trim(dtype) ==
"map" )
then 1356 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1357 lmask_org(:,:) =
real(gland2D(:,:), kind=
rp)
1363 if ( .not. data_available(il_lon_sfc,2) )
then 1364 if ( ldims(2).ne.outer_nx .or. ldims(3).ne.outer_ny )
then 1365 log_error(
"ParentLandInputGrADS",*)
'namelist of "lon_sfc" is not found in grads namelist!' 1366 log_error_cont(*)
'dimension is different: outer_nx and outer_nx_sfc! ', outer_nx, ldims(2)
1367 log_error_cont(*)
' : outer_ny and outer_ny_sfc! ', outer_ny, ldims(3)
1370 if ( trim(dtype) ==
"linear" )
then 1373 llon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * D2R
1376 else if ( trim(dtype) ==
"map" )
then 1377 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1378 llon_org(:,:) =
real(gland2D(:,:), kind=RP) * D2R
1382 if ( .not. data_available(il_lon_sfc,2) ) cycle
1383 if ( trim(dtype) ==
"linear" )
then 1386 llon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * D2R
1389 else if ( trim(dtype) ==
"map" )
then 1390 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1391 llon_org(:,:) =
real(gland2D(:,:), kind=RP) * D2R
1394 if ( .not. data_available(il_lat_sfc,2) )
then 1395 if ( ldims(2).ne.outer_nx .or. ldims(3).ne.outer_ny )
then 1396 log_error(
"ParentLandInputGrADS",*)
'namelist of "lat_sfc" is not found in grads namelist!' 1397 log_error_cont(*)
'dimension is different: outer_nx and outer_nx_sfc! ', outer_nx, ldims(2)
1398 log_error_cont(*)
' : outer_ny and outer_ny_sfc! ', outer_nx, ldims(3)
1401 if ( trim(dtype) ==
"linear" )
then 1404 llat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * D2R
1407 else if ( trim(dtype) ==
"map" )
then 1408 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1409 llat_org(:,:) =
real(gland2D(:,:), kind=RP) * D2R
1413 if ( .not. data_available(il_lat_sfc,2) ) cycle
1414 if ( trim(dtype) ==
"linear" )
then 1417 llat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * D2R
1420 else if ( trim(dtype) ==
"map" )
then 1421 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1422 llat_org(:,:) =
real(gland2D(:,:), kind=RP) * D2R
1425 if(ldims(1)/=knum)
then 1426 log_error(
"ParentLandInputGrADS",*)
'"knum" must be equal to outer_nl for llev. knum:',knum,
'> outer_nl:',ldims(1)
1429 if ( trim(dtype) ==
"levels" )
then 1430 if(ldims(1)/=lnum)
then 1431 log_error(
"ParentLandInputGrADS",*)
'lnum must be same as the outer_nl for llev! ',ldims(1),lnum
1435 lz_org(k) =
real(lvars(k), kind=
rp)
1448 if(ldims(1)/=knum)
then 1449 log_error(
"ParentLandInputGrADS",*)
'The number of levels for STEMP must be same as llevs! ',ldims(1),knum
1452 if ( trim(dtype) ==
"map" )
then 1453 call read_grads_file_3d(io_fid_grads_data,gfile,ldims(2),ldims(3),ldims(1),nt,item,startrec,totalrec,yrev,gland3d)
1457 if ( abs(gland3d(i,j,k)-missval) < eps )
then 1458 tg_org(k,i,j) = undef
1460 tg_org(k,i,j) =
real(gland3D(i,j,k), kind=
rp)
1467 if ( use_file_landwater )
then 1468 if(ldims(1)/=knum)
then 1469 log_error(
"ParentLandInputGrADS",*)
'The number of levels for SMOISVC must be same as llevs! ',ldims(1),knum
1472 if ( trim(dtype) ==
"map" )
then 1473 call read_grads_file_3d(io_fid_grads_data,gfile,ldims(2),ldims(3),ldims(1),nt,item,startrec,totalrec,yrev,gland3d)
1477 if ( abs(gland3d(i,j,k)-missval) < eps )
then 1478 strg_org(k,i,j) = undef
1480 strg_org(k,i,j) =
real(gland3D(i,j,k), kind=
rp)
1488 if ( use_file_landwater )
then 1489 if(ldims(1)/=knum)
then 1490 log_error(
"ParentLandInputGrADS",*)
'The number of levels for SMOISDS must be same as llevs! ',ldims(1),knum
1493 if ( trim(dtype) ==
"map" )
then 1494 call read_grads_file_3d(io_fid_grads_data,gfile,ldims(2),ldims(3),ldims(1),nt,item,startrec,totalrec,yrev,gland3d)
1498 if ( abs(gland3d(i,j,k)-missval) < eps )
then 1499 smds_org(k,i,j) = undef
1501 smds_org(k,i,j) =
real(gland3D(i,j,k), kind=
rp)
1509 if ( trim(dtype) ==
"map" )
then 1510 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,nt,item,startrec,totalrec,yrev,gland2d)
1513 if ( abs(gland2d(i,j)-missval) < eps )
then 1514 lst_org(i,j) = undef
1516 lst_org(i,j) =
real(gland2D(i,j), kind=
rp)
1522 if ( .not. data_available(il_topo_sfc,2) )
then 1523 if ( ldims(2)==outer_nx .or. ldims(3)==outer_ny )
then 1524 if ( trim(dtype) ==
"map" )
then 1525 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,nt,item,startrec,totalrec,yrev,gland2d)
1528 if ( abs(gland2d(i,j)-missval) < eps )
then 1529 topo_org(i,j) = undef
1531 topo_org(i,j) =
real(gland2D(i,j), kind=
rp)
1541 if ( data_available(il_topo_sfc,2) )
then 1542 if ( trim(dtype) ==
"map" )
then 1543 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,nt,item,startrec,totalrec,yrev,gland2d)
1546 if ( abs(gland2d(i,j)-missval) < eps )
then 1547 topo_org(i,j) = undef
1549 topo_org(i,j) =
real(gland2D(i,j), kind=
rp)
1554 else if ( .not. data_available(il_topo,2) )
then 1558 enddo loop_inputlandgrads
1583 integer,
intent(out) :: odims(2)
1584 integer,
intent(out) :: timelen
1585 character(len=*),
intent(in) :: basename
1587 character(len=H_LONG) :: grads_ctl
1593 log_info(
"ParentOceanSetupGrADS",*)
'Real Case/Ocean Input File Type: GrADS format' 1597 if ( len_trim(basename) == 0 )
then 1598 grads_ctl =
"namelist.grads_boundary" 1600 grads_ctl = basename
1605 open( io_fid_grads_nml, &
1606 file = trim(grads_ctl), &
1607 form =
'formatted', &
1611 if ( ierr /= 0 )
then 1612 log_error(
"ParentOceanSetupGrADS",*)
'Input file is not found! ', trim(grads_ctl)
1616 read(io_fid_grads_nml,nml=nml_grads_grid,iostat=ierr)
1617 if( ierr /= 0 )
then 1618 log_error(
"ParentOceanSetupGrADS",*)
'Not appropriate names in nml_grads_grid in ', trim(grads_ctl),
'. Check!' 1621 log_nml(nml_grads_grid)
1626 if(outer_nx_sst > 0)
then 1627 odims(1) = outer_nx_sst
1628 else if (outer_nx_sfc > 0)
then 1629 odims(1) = outer_nx_sfc
1630 outer_nx_sst = outer_nx_sfc
1633 outer_nx_sst = outer_nx
1635 if(outer_ny_sst > 0)
then 1636 odims(2) = outer_ny_sst
1637 else if(outer_ny_sfc > 0)
then 1638 odims(2) = outer_ny_sfc
1639 outer_ny_sst = outer_ny_sfc
1642 outer_ny_sst = outer_ny
1645 allocate( gsst2d( odims(1), odims(2) ) )
1652 grads_swpoint(:,3), &
1655 grads_lvars(:,:,3), &
1656 grads_startrec(:,3), &
1657 grads_totalrec(:,3), &
1660 grads_fendian(:,3), &
1661 grads_missval(:,3), &
1662 data_available(:,3), &
1664 num_item_list_ocean, &
1668 close( io_fid_grads_nml )
1670 do ielem = 1, num_item_list_ocean
1671 item = item_list_ocean(ielem)
1673 select case(trim(item))
1674 case(
'lsmask',
'lsmask_sst')
1675 if ( .not. data_available(io_lsmask,3) .and. .not. data_available(io_lsmask_sst,3) )
then 1676 log_warn(
"ParentOceanSetupGrADS",*) trim(item),
' is not found & not used.' 1679 case(
'lon',
'lat',
'lon_sfc',
'lat_sfc',
'lon_sst',
'lat_sst')
1682 if (.not. data_available(io_sst,3) .and. .not. data_available(io_skint,3) )
then 1683 log_error(
"ParentOceanSetupGrADS",*)
'SST and SKINT are found in grads namelist!' 1686 if (.not. data_available(io_sst,3))
then 1687 log_warn(
"ParentOceanSetupGrADS",*)
'SST is found in grads namelist. SKINT is used in place of SST.' 1693 if ( .not. data_available(ielem,3) )
then 1694 log_error(
"ParentOceanSetupGrADS",*)
'Not found in grads namelist! : ', &
1695 trim(item_list_ocean(ielem))
1729 real(RP),
intent(out) :: tw_org (:,:)
1730 real(RP),
intent(out) :: sst_org (:,:)
1731 real(RP),
intent(out) :: omask_org(:,:)
1732 real(RP),
intent(out) :: olon_org (:,:)
1733 real(RP),
intent(out) :: olat_org (:,:)
1734 character(len=*),
intent(in) :: basename_num
1735 integer,
intent(in) :: odims(2)
1736 integer,
intent(in) :: nt
1738 character(len=H_LONG) :: gfile
1740 integer :: i, j, ielem
1743 loop_inputoceangrads :
do ielem = 1, num_item_list_ocean
1745 item = item_list_ocean(ielem)
1747 dtype = grads_dtype(ielem,3)
1748 fname = grads_fname(ielem,3)
1749 lnum = grads_lnum(ielem,3)
1750 missval = grads_missval(ielem,3)
1752 select case(trim(dtype))
1754 swpoint = grads_swpoint(ielem,3)
1755 dd = grads_dd(ielem,3)
1756 if( (abs(swpoint-large_number_one)<eps).or.(abs(dd-large_number_one)<eps) )
then 1757 log_error(
"ParentOceanInputGrADS",*)
'"swpoint" is required in grads namelist! ',swpoint
1758 log_error_cont(*)
'"dd" is required in grads namelist! ',dd
1762 log_error(
"ParentOceanInputGrADS",*)
'"lnum" in grads namelist is invalid for ocean data' 1765 startrec = grads_startrec(ielem,3)
1766 totalrec = grads_totalrec(ielem,3)
1767 fendian = grads_fendian(ielem,3)
1768 yrev = grads_yrev(ielem,3)
1769 if( (startrec<0).or.(totalrec<0) )
then 1770 log_error(
"ParentOceanInputGrADS",*)
'"startrec" is required in grads namelist! ',startrec
1771 log_error_cont(*)
'"totalrec" is required in grads namelist! ',totalrec
1775 if(io_fid_grads_data < 0)
then 1778 gfile=trim(fname)//trim(basename_num)//
'.grd' 1779 if( len_trim(fname)==0 )
then 1780 log_error(
"ParentOceanInputGrADS",*)
'"fname" is required in grads namelist for map data! ',trim(fname)
1786 select case(trim(item))
1788 if ( .not. data_available(io_lsmask_sst,3) .and. data_available(io_lsmask,3) )
then 1789 if ( odims(1)==outer_nx_sfc .and. odims(2)==outer_ny_sfc )
then 1790 if ( trim(dtype) ==
"map" )
then 1791 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1792 omask_org(:,:) =
real(gsst2D(:,:), kind=
rp)
1799 if ( data_available(io_lsmask_sst,3) )
then 1800 if ( trim(dtype) ==
"map" )
then 1801 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1802 omask_org(:,:) =
real(gsst2D(:,:), kind=
rp)
1804 else if ( .not. data_available(io_lsmask,3) )
then 1808 if ( .not. data_available(io_lon_sst,3) .and. .not. data_available(io_lon_sfc,3) )
then 1809 if ( odims(1).ne.outer_nx .or. odims(2).ne.outer_ny )
then 1810 log_error(
"ParentOceanInputGrADS",*)
'namelist of "lon_sst" is not found in grads namelist!' 1811 log_error_cont(*)
'dimension is different: outer_nx and outer_nx_sst! ', outer_nx, odims(1)
1812 log_error_cont(*)
' : outer_ny and outer_ny_sst! ', outer_ny, odims(2)
1815 if ( trim(dtype) ==
"linear" )
then 1818 olon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * D2R
1821 else if ( trim(dtype) ==
"map" )
then 1822 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1823 olon_org(:,:) =
real(gsst2D(:,:), kind=RP) * D2R
1827 if ( .not. data_available(io_lon_sst,3) .and. data_available(io_lon_sfc,3) )
then 1828 if ( odims(1).ne.outer_nx_sfc .or. odims(2).ne.outer_ny_sfc )
then 1829 log_error(
"ParentOceanInputGrADS",*)
'namelist of "lon_sst" is not found in grads namelist!' 1830 log_error_cont(*)
'dimension is different: outer_nx_sfc and outer_nx_sst! ', outer_nx_sfc, odims(1)
1831 log_error_cont(*)
' : outer_ny_sfc and outer_ny_sst! ', outer_ny_sfc, odims(2)
1834 if ( trim(dtype) ==
"linear" )
then 1837 olon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * D2R
1840 else if ( trim(dtype) ==
"map" )
then 1841 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1842 olon_org(:,:) =
real(gsst2D(:,:), kind=RP) * D2R
1846 if ( .not. data_available(io_lon_sst,3) ) cycle
1847 if ( trim(dtype) ==
"linear" )
then 1850 olon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * D2R
1853 else if ( trim(dtype) ==
"map" )
then 1854 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1855 olon_org(:,:) =
real(gsst2D(:,:), kind=RP) * D2R
1858 if ( .not. data_available(io_lat_sfc,3) .and. .not. data_available(io_lat_sst,3) )
then 1859 if ( odims(1).ne.outer_nx .or. odims(2).ne.outer_ny )
then 1860 log_error(
"ParentOceanInputGrADS",*)
'namelist of "lat_sst" is not found in grads namelist!' 1861 log_error_cont(*)
'dimension is different: outer_nx and outer_nx_sst! ', outer_nx, odims(1)
1862 log_error_cont(*)
' : outer_ny and outer_ny_sst! ', outer_ny, odims(2)
1865 if ( trim(dtype) ==
"linear" )
then 1868 olat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * D2R
1871 else if ( trim(dtype) ==
"map" )
then 1872 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1873 olat_org(:,:) =
real(gsst2D(:,:), kind=RP) * D2R
1877 if ( .not. data_available(io_lat_sst,3) .and. data_available(io_lat_sfc,3) )
then 1878 if ( odims(1).ne.outer_nx_sfc .or. odims(2).ne.outer_ny_sfc )
then 1879 log_error(
"ParentOceanInputGrADS",*)
'namelist of "lat_sst" is not found in grads namelist!' 1880 log_error_cont(*)
'dimension is different: outer_nx_sfc and outer_nx_sst! ', outer_nx_sfc, odims(1)
1881 log_error_cont(*)
' : outer_ny_sfc and outer_ny_sst! ', outer_ny_sfc, odims(2)
1884 if ( trim(dtype) ==
"linear" )
then 1887 olat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * D2R
1890 else if ( trim(dtype) ==
"map" )
then 1891 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1892 olat_org(:,:) =
real(gsst2D(:,:), kind=RP) * D2R
1896 if ( .not. data_available(io_lat_sst,3) ) cycle
1897 if ( trim(dtype) ==
"linear" )
then 1900 olat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * D2R
1903 else if ( trim(dtype) ==
"map" )
then 1904 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1905 olat_org(:,:) =
real(gsst2D(:,:), kind=RP) * D2R
1908 if ( .not. data_available(io_sst,3) )
then 1909 if ( odims(1).ne.outer_nx_sfc .or. odims(2).ne.outer_ny_sfc )
then 1910 log_error(
"ParentOceanInputGrADS",*)
'dimsntion is different: outer_nx_sst/outer_nx_sfc and outer_nx_sst! ', odims(1), outer_nx_sfc
1911 log_error_cont(*)
' : outer_ny_sst/outer_ny_sfc and outer_ny_sst! ', odims(2), outer_ny_sfc
1914 if ( trim(dtype) ==
"map" )
then 1915 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,nt,item,startrec,totalrec,yrev,gsst2d)
1918 if ( abs(gsst2d(i,j)-missval) < eps )
then 1919 sst_org(i,j) = undef
1921 sst_org(i,j) =
real(gsst2D(i,j), kind=
rp)
1928 if ( .not. data_available(io_sst,3) ) cycle
1929 if ( trim(dtype) ==
"map" )
then 1930 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,nt,item,startrec,totalrec,yrev,gsst2d)
1933 if ( abs(gsst2d(i,j)-missval) < eps )
then 1934 sst_org(i,j) = undef
1936 sst_org(i,j) =
real(gsst2D(i,j), kind=
rp)
1942 enddo loop_inputoceangrads
1983 character(len=H_SHORT),
intent(out) :: grads_item (:)
1984 character(len=H_LONG),
intent(out) :: grads_fname (:)
1985 character(len=H_LONG),
intent(out) :: grads_dtype (:)
1986 real(RP),
intent(out) :: grads_swpoint (:)
1987 real(RP),
intent(out) :: grads_dd (:)
1988 integer,
intent(out) :: grads_lnum (:)
1989 real(RP),
intent(out) :: grads_lvars (:,:)
1990 integer,
intent(out) :: grads_startrec(:)
1991 integer,
intent(out) :: grads_totalrec(:)
1992 integer,
intent(out) :: grads_knum (:)
1993 character(len=H_SHORT),
intent(out) :: grads_yrev (:)
1994 character(len=H_SHORT),
intent(out) :: grads_fendian (:)
1995 real(SP),
intent(out) :: grads_missval (:)
1996 logical,
intent(out) :: data_available(:)
1997 character(len=*),
intent(in) :: item_list (:)
1998 integer,
intent(in) :: num_item_list
1999 character(len=*),
intent(in) :: basename
2000 integer,
intent(in) :: io_fid_grads_nml
2002 integer :: grads_vars_nmax
2003 integer :: k, n, ielem, ierr
2005 namelist / grdvar / &
2021 if ( io_fid_grads_nml > 0 )
then 2022 rewind( io_fid_grads_nml )
2024 do n = 1, grads_vars_limit
2025 read(io_fid_grads_nml, nml=grdvar, iostat=ierr)
2027 log_error(
"REALINPUT_GRADS_read_namelist",*)
'Not appropriate names in grdvar in ', trim(basename),
'. Check!' 2029 else if( ierr < 0 )
then 2032 grads_vars_nmax = grads_vars_nmax + 1
2035 log_error(
"REALINPUT_GRADS_read_namelist",*)
'namelist file is not open! ', trim(basename)
2039 if ( grads_vars_nmax > grads_vars_limit )
then 2040 log_error(
"REALINPUT_GRADS_read_namelist",*)
'The number of grads vars exceeds grads_vars_limit! ', &
2041 grads_vars_nmax,
' > ', grads_vars_limit
2046 data_available(:) = .false.
2047 do ielem = 1, num_item_list
2048 if ( io_fid_grads_nml > 0 ) rewind( io_fid_grads_nml )
2049 do n = 1, grads_vars_nmax
2055 swpoint = large_number_one
2056 dd = large_number_one
2058 lvars = large_number_one
2064 missval = large_number_one
2067 if ( io_fid_grads_nml > 0 )
then 2068 read(io_fid_grads_nml, nml=grdvar, iostat=ierr)
2069 if( ierr /= 0 )
exit 2072 if(item == item_list(ielem))
then 2073 grads_item(ielem) = item
2074 grads_fname(ielem) = fname
2075 grads_dtype(ielem) = dtype
2076 grads_swpoint(ielem) = swpoint
2077 grads_dd(ielem) = dd
2078 grads_lnum(ielem) = lnum
2079 do k = 1, lvars_limit
2080 grads_lvars(k,ielem) = lvars(k)
2082 grads_startrec(ielem) = startrec
2083 grads_totalrec(ielem) = totalrec
2084 grads_knum(ielem) = knum
2085 grads_yrev(ielem) = yrev
2086 grads_fendian(ielem) = fendian
2087 grads_missval(ielem) = missval
2088 data_available(ielem) = .true.
2093 log_info(
"REALINPUT_GRADS_read_namelist",*)
'GrADS data availability ',trim(item_list(ielem)),data_available(ielem)
2099 subroutine open_grads_file(io_fid,filename,irecl)
2102 integer,
intent(in) :: io_fid
2103 character(len=*),
intent(in) :: filename
2104 integer,
intent(in) :: irecl
2109 file = trim(filename), &
2110 form =
'unformatted', &
2111 access =
'direct', &
2115 if ( ierr /= 0 )
then 2116 log_error(
"REALINPUT_GRADS_open_grads_file",*)
'grads file does not found! ', trim(filename)
2121 end subroutine open_grads_file
2124 subroutine read_grads_file_2d( &
2135 integer,
intent(in) :: io_fid
2136 character(len=*),
intent(in) :: gfile
2137 integer,
intent(in) :: nx,ny,nz,it
2138 character(len=*),
intent(in) :: item
2139 integer,
intent(in) :: startrec
2140 integer,
intent(in) :: totalrec
2141 character(len=*),
intent(in) :: yrev
2142 real(SP),
intent(out) :: gdata(nx,ny)
2144 real(SP) :: work(nx,ny)
2147 integer :: irec, irecl
2152 call open_grads_file(io_fid, gfile, irecl)
2153 irec = totalrec * (it-1) + startrec
2154 read(io_fid, rec=irec, iostat=ierr) gdata(:,:)
2155 if ( ierr /= 0 )
then 2156 log_error(
"REALINPUT_GRADS_read_grads_file_2d",*)
'grads data is not found! ',trim(item),it
2157 log_error_cont(*)
'namelist or grads data might be wrong.' 2161 if( trim(yrev) ==
"on" )
then 2162 work(:,:)=gdata(:,:)
2165 gdata(i,j)=work(i,ny-j+1)
2170 call close_grads_file(io_fid,gfile)
2173 end subroutine read_grads_file_2d
2176 subroutine read_grads_file_3d( &
2187 integer,
intent(in) :: io_fid
2188 character(len=*),
intent(in) :: gfile
2189 integer,
intent(in) :: nx,ny,nz,it
2190 character(len=*),
intent(in) :: item
2191 integer,
intent(in) :: startrec
2192 integer,
intent(in) :: totalrec
2193 character(len=*),
intent(in) :: yrev
2194 real(SP),
intent(out) :: gdata(nx,ny,nz)
2196 real(SP) :: work(nx,ny,nz)
2199 integer :: irec,irecl
2203 call open_grads_file(io_fid, gfile, irecl)
2205 irec = totalrec * (it-1) + startrec + (k-1)
2206 read(io_fid, rec=irec, iostat=ierr) gdata(:,:,k)
2207 if ( ierr /= 0 )
then 2208 log_error(
"REALINPUT_GRADS_read_grads_file_3d",*)
'grads data does not found! ',trim(item),
', k=',k,
', it=',it,
' in ', trim(gfile)
2213 if( trim(yrev) ==
"on" )
then 2214 work(:,:,:)=gdata(:,:,:)
2218 gdata(i,j,k)=work(i,ny-j+1,k)
2224 call close_grads_file(io_fid,gfile)
2227 end subroutine read_grads_file_3d
2230 subroutine close_grads_file(io_fid,filename)
2233 integer,
intent(in) :: io_fid
2234 character(len=*),
intent(in) :: filename
2237 close(io_fid, iostat=ierr)
2238 if ( ierr /= 0 )
then 2239 log_error(
"REALINPUT_GRADS_close_grads_file",*)
'grads file was not closed peacefully! ',trim(filename)
2244 end subroutine close_grads_file
real(rp), public const_cpdry
specific heat (dry air,constant pressure) [J/kg/K]
module atmosphere / saturation
integer, parameter, public i_hs
snow
integer, parameter, public i_hr
liquid water rain
integer, parameter, public i_hi
ice water cloud
real(rp), parameter, public const_tem00
temperature reference (0C) [K]
integer, public io_fid_conf
Config file ID.
real(rp), public const_d2r
degree to radian
real(rp), public const_laps
lapse rate of ISA [K/m]
real(rp), public const_rdry
specific gas constant (dry air) [J/kg/K]
real(rp), public const_undef
module atmosphere / hydrometeor
real(rp), public const_pre00
pressure reference [Pa]
integer function, public io_get_available_fid()
search & get available file ID
real(rp), public const_grav
standard acceleration of gravity [m/s2]
real(rp), public const_epsvap
Rdry / Rvap.
integer, public prc_myrank
process num in local communicator
real(rp), public const_epstvap
1 / epsilon - 1
subroutine, public prc_abort
Abort Process.
integer, parameter, public i_hc
liquid water cloud
real(rp), public const_eps
small number
integer, parameter, public n_hyd
integer, parameter, public rp
integer, parameter, public i_hg
graupel