52 integer,
parameter :: grads_vars_limit = 1000
53 integer,
parameter :: num_item_list = 24
54 integer,
parameter :: num_item_list_atom = 24
55 integer,
parameter :: num_item_list_land = 12
56 integer,
parameter :: num_item_list_ocean = 10
57 logical :: data_available(num_item_list_atom,3)
58 character(len=H_SHORT) :: item_list_atom (num_item_list_atom)
59 character(len=H_SHORT) :: item_list_land (num_item_list_land)
60 character(len=H_SHORT) :: item_list_ocean(num_item_list_ocean)
61 data item_list_atom /
'lon',
'lat',
'plev',
'DENS',
'U',
'V',
'W',
'T',
'HGT',
'QV',
'QC',
'QR',
'QI',
'QS',
'QG',
'RH', &
62 'MSLP',
'PSFC',
'U10',
'V10',
'T2',
'Q2',
'RH2',
'TOPO' /
63 data item_list_land /
'lsmask',
'lon',
'lat',
'lon_sfc',
'lat_sfc',
'llev', &
64 'STEMP',
'SMOISVC',
'SMOISDS',
'SKINT',
'TOPO',
'TOPO_sfc' /
65 data item_list_ocean /
'lsmask',
'lsmask_sst',
'lon',
'lat',
'lon_sfc',
'lat_sfc',
'lon_sst',
'lat_sst',
'SKINT',
'SST'/
67 integer,
parameter :: Ia_lon = 1
68 integer,
parameter :: Ia_lat = 2
69 integer,
parameter :: Ia_p = 3
70 integer,
parameter :: Ia_dens = 4
71 integer,
parameter :: Ia_u = 5
72 integer,
parameter :: Ia_v = 6
73 integer,
parameter :: Ia_w = 7
74 integer,
parameter :: Ia_t = 8
75 integer,
parameter :: Ia_hgt = 9
76 integer,
parameter :: Ia_qv = 10
77 integer,
parameter :: Ia_qc = 11
78 integer,
parameter :: Ia_qr = 12
79 integer,
parameter :: Ia_qi = 13
80 integer,
parameter :: Ia_qs = 14
81 integer,
parameter :: Ia_qg = 15
82 integer,
parameter :: Ia_rh = 16
83 integer,
parameter :: Ia_slp = 17
84 integer,
parameter :: Ia_ps = 18
85 integer,
parameter :: Ia_u10 = 19
86 integer,
parameter :: Ia_v10 = 20
87 integer,
parameter :: Ia_t2 = 21
88 integer,
parameter :: Ia_q2 = 22
89 integer,
parameter :: Ia_rh2 = 23
90 integer,
parameter :: Ia_topo = 24
92 integer,
parameter :: Il_lsmask = 1
93 integer,
parameter :: Il_lon = 2
94 integer,
parameter :: Il_lat = 3
95 integer,
parameter :: Il_lon_sfc = 4
96 integer,
parameter :: Il_lat_sfc = 5
97 integer,
parameter :: Il_lz = 6
98 integer,
parameter :: Il_stemp = 7
99 integer,
parameter :: Il_smoisvc = 8
100 integer,
parameter :: Il_smoisds = 9
101 integer,
parameter :: Il_skint = 10
102 integer,
parameter :: Il_topo = 11
103 integer,
parameter :: Il_topo_sfc= 12
105 integer,
parameter :: Io_lsmask = 1
106 integer,
parameter :: Io_lsmask_sst = 2
107 integer,
parameter :: Io_lon = 3
108 integer,
parameter :: Io_lat = 4
109 integer,
parameter :: Io_lon_sfc = 5
110 integer,
parameter :: Io_lat_sfc = 6
111 integer,
parameter :: Io_lon_sst = 7
112 integer,
parameter :: Io_lat_sst = 8
113 integer,
parameter :: Io_skint = 9
114 integer,
parameter :: Io_sst = 10
117 integer,
parameter :: lvars_limit = 1000
118 real(RP),
parameter :: large_number_one = 9.999e+15_rp
121 character(len=H_SHORT) :: upper_qv_type =
"ZERO" 125 character(len=H_SHORT) :: grads_item (num_item_list,3)
126 character(len=H_LONG) :: grads_dtype (num_item_list,3)
127 character(len=H_LONG) :: grads_fname (num_item_list,3)
128 character(len=H_SHORT) :: grads_fendian (num_item_list,3)
129 character(len=H_SHORT) :: grads_yrev (num_item_list,3)
130 real(RP) :: grads_swpoint (num_item_list,3)
131 real(RP) :: grads_dd (num_item_list,3)
132 integer :: grads_lnum (num_item_list,3)
133 real(RP) :: grads_lvars (lvars_limit,num_item_list,3)
134 integer :: grads_startrec(num_item_list,3)
135 integer :: grads_totalrec(num_item_list,3)
136 integer :: grads_knum (num_item_list,3)
137 real(SP) :: grads_missval (num_item_list,3)
139 real(SP),
allocatable :: gdata2D(:,:)
140 real(SP),
allocatable :: gdata3D(:,:,:)
141 real(SP),
allocatable :: gland2D(:,:)
142 real(SP),
allocatable :: gland3D(:,:,:)
143 real(SP),
allocatable :: gsst2D (:,:)
145 integer :: io_fid_grads_nml = -1
146 integer :: io_fid_grads_data = -1
150 integer :: outer_nx = -1
151 integer :: outer_ny = -1
152 integer :: outer_nz = -1
153 integer :: outer_nl = -1
155 integer :: outer_nx_sfc = -1
156 integer :: outer_ny_sfc = -1
158 integer :: outer_nx_sst = -1
159 integer :: outer_ny_sst = -1
161 namelist / nml_grads_grid / &
171 character(len=H_SHORT) :: item
173 character(len=H_SHORT) :: dtype
174 character(len=H_LONG) :: fname
178 real(RP) :: lvars(lvars_limit) = large_number_one
182 character(len=H_SHORT) :: fendian=
'big' 183 character(len=H_SHORT) :: yrev=
'off' 195 integer,
intent(out) :: dims(6)
196 character(len=*),
intent(in) :: basename
199 namelist / param_mkinit_real_grads / &
208 if(
io_l )
write(
io_fid_log,*)
'+++ Real Case/Atom Input File Type: GrADS format' 212 read(
io_fid_conf,nml=param_mkinit_real_grads,iostat=ierr)
215 write(*,*)
'xxx [realinput_grads] Not appropriate names in namelist PARAM_MKINIT_REAL_GrADS. Check!' 221 if ( len_trim(basename) == 0 )
then 222 write(*,*)
'xxx [realinput_grads] "BASENAME_ORG" is not specified in "PARAM_MKINIT_REAL_ATMOS"!', trim(basename)
228 open( io_fid_grads_nml, &
229 file = trim(basename), &
230 form =
'formatted', &
234 if ( ierr /= 0 )
then 235 write(*,*)
'xxx [realinput_grads] Input file is not found! ', trim(basename)
239 read(io_fid_grads_nml,nml=nml_grads_grid,iostat=ierr)
241 write(*,*)
'xxx [realinput_grads] Not appropriate names in nml_grads_grid in ', trim(basename),
'. Check!' 255 allocate( gdata2d( dims(2), dims(3) ) )
256 allocate( gdata3d( dims(2), dims(3), dims(1) ) )
262 grads_swpoint(:,1), &
265 grads_lvars(:,:,1), &
266 grads_startrec(:,1), &
267 grads_totalrec(:,1), &
270 grads_fendian(:,1), &
271 grads_missval(:,1), &
272 data_available(:,1), &
274 num_item_list_atom, &
278 close( io_fid_grads_nml )
280 do ielem = 1, num_item_list_atom
281 item = item_list_atom(ielem)
283 select case(trim(item))
284 case(
'DENS',
'W',
'QC',
'QR',
'QI',
'QS',
'QG',
'MSLP',
'PSFC',
'U10',
'V10',
'T2',
'Q2',
'TOPO')
285 if (.not. data_available(ielem,1))
then 286 if(
io_l )
write(
io_fid_log,*)
'warning: ',trim(item),
' is not found & will be estimated.' 290 if (.not. data_available(ia_qv,1))
then 291 if (.not.data_available(ia_rh,1))
then 292 write(*,*)
'xxx [realinput_grads] Not found in grads namelist! : QV and RH' 299 if (.not. data_available(ia_qv,1))
then 300 if(data_available(ia_rh,1))
then 301 if ((.not. data_available(ia_t,1)).or.(.not. data_available(ia_p,1)))
then 302 write(*,*)
'xxx [realinput_grads] Temperature and pressure are required to convert from RH to QV ! ' 308 write(*,*)
'xxx [realinput_grads] Not found in grads namelist! : QV and RH' 313 if ( data_available(ia_q2,1) )
then 316 if ( data_available(ia_rh2,1) )
then 317 if ((.not. data_available(ia_t2,1)).or.(.not. data_available(ia_ps,1)))
then 318 if(
io_l )
write(
io_fid_log,*)
'warning: T2 and PSFC are required to convert from RH2 to Q2 !' 319 if(
io_l )
write(
io_fid_log,*)
' Q2 will be copied from data at above level.' 320 data_available(ia_rh2,1) = .false.
324 if(
io_l )
write(
io_fid_log,*)
'warning: Q2 and RH2 are not found, Q2 will be estimated.' 329 if ( .not. data_available(ielem,1) )
then 330 write(*,*)
'xxx [realinput_grads] Not found in grads namelist! : ',trim(item_list_atom(ielem))
344 if(
io_l )
write(
io_fid_log,*)
'+++ ScaleLib/IO[realinput]/Categ[AtomOpenGrADS]' 382 psat => atmos_saturation_psat_liq
386 real(RP),
intent(out) :: velz_org(:,:,:)
387 real(RP),
intent(out) :: velx_org(:,:,:)
388 real(RP),
intent(out) :: vely_org(:,:,:)
389 real(RP),
intent(out) :: pres_org(:,:,:)
390 real(RP),
intent(out) :: dens_org(:,:,:)
391 real(RP),
intent(out) :: temp_org(:,:,:)
392 real(RP),
intent(out) :: qtrc_org(:,:,:,:)
393 real(RP),
intent(out) :: lon_org(:,:)
394 real(RP),
intent(out) :: lat_org(:,:)
395 real(RP),
intent(out) :: cz_org(:,:,:)
396 character(len=*),
intent(in) :: basename_num
397 integer,
intent(in) :: dims(6)
398 integer,
intent(in) :: nt
400 real(RP) :: rhprs_org(dims(1)+2,dims(2),dims(3))
406 integer :: lm_layer(dims(2),dims(3))
409 character(len=H_LONG) :: gfile
411 real(RP) :: p_sat, qm, rhsfc, dz
414 integer :: i, j, k, iq, ielem
416 logical :: pressure_coordinates
419 if(
io_l )
write(
io_fid_log,*)
'+++ ScaleLib/IO[realinput]/Categ[AtomInputGrADS]' 421 dens_org(:,:,:) = undef
422 velz_org(:,:,:) = 0.0_rp
423 qtrc_org(:,:,:,:) = 0.0_rp
426 loop_inputatomgrads :
do ielem = 1, num_item_list_atom
428 if ( .not. data_available(ielem,1) ) cycle
430 item = grads_item(ielem,1)
431 dtype = grads_dtype(ielem,1)
432 fname = grads_fname(ielem,1)
433 lnum = grads_lnum(ielem,1)
434 missval = grads_missval(ielem,1)
436 if ( dims(1) < grads_knum(ielem,1) )
then 437 write(*,*)
'xxx "knum" must be less than or equal to outer_nz. knum:',knum,
'> outer_nz:',dims(1),trim(item)
439 else if ( grads_knum(ielem,1) > 0 )
then 440 knum = grads_knum(ielem,1)
445 select case(trim(dtype))
447 swpoint = grads_swpoint(ielem,1)
448 dd = grads_dd(ielem,1)
449 if( (abs(swpoint-large_number_one)<eps).or.(abs(dd-large_number_one)<eps) )
then 450 write(*,*)
'xxx "swpoint" is required in grads namelist! ',swpoint
451 write(*,*)
'xxx "dd" is required in grads namelist! ',dd
456 write(*,*)
'xxx "lnum" is required in grads namelist for levels data! ' 460 lvars(k)=grads_lvars(k,ielem,1)
462 if(abs(lvars(1)-large_number_one)<eps)
then 463 write(*,*)
'xxx "lvars" must be specified in grads namelist for levels data! ' 467 startrec = grads_startrec(ielem,1)
468 totalrec = grads_totalrec(ielem,1)
469 fendian = grads_fendian(ielem,1)
470 yrev = grads_yrev(ielem,1)
471 if( (startrec<0).or.(totalrec<0) )
then 472 write(*,*)
'xxx "startrec" is required in grads namelist! ',startrec
473 write(*,*)
'xxx "totalrec" is required in grads namelist! ',totalrec
477 if(io_fid_grads_data < 0)
then 480 gfile=trim(fname)//trim(basename_num)//
'.grd' 481 if( len_trim(fname)==0 )
then 482 write(*,*)
'xxx "fname" is required in grads namelist for map data! ',trim(fname)
488 select case(trim(item))
490 if ( trim(dtype) ==
"linear" )
then 493 lon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * d2r
496 else if ( trim(dtype) ==
"map" )
then 497 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,1,item,startrec,totalrec,yrev,gdata2d)
498 lon_org(:,:) =
real(gdata2D(:,:), kind=RP) * d2r
501 if ( trim(dtype) ==
"linear" )
then 504 lat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * d2r
507 else if ( trim(dtype) ==
"map" )
then 508 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,1,item,startrec,totalrec,yrev,gdata2d)
509 lat_org(:,:) =
real(gdata2D(:,:), kind=RP) * d2r
512 if(dims(1)/=knum)
then 513 write(*,*)
'xxx "knum" must be equal to outer_nz for plev. knum:',knum,
'> outer_nz:',dims(1)
516 if ( trim(dtype) ==
"levels" )
then 517 pressure_coordinates = .true.
518 if(dims(1)/=lnum)
then 519 write(*,*)
'xxx lnum must be same as the outer_nz for plev! ',dims(1),lnum
525 pres_org(k+2,i,j) =
real(lvars(k), kind=
rp)
529 else if ( trim(dtype) ==
"map" )
then 530 pressure_coordinates = .false.
531 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),dims(1),nt,item,startrec,totalrec,yrev,gdata3d)
535 pres_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
537 if( abs( pres_org(k+2,i,j) - missval ) < eps )
then 538 pres_org(k+2,i,j) = undef
545 if ( trim(dtype) ==
"map" )
then 546 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
550 dens_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
552 if( abs( dens_org(k+2,i,j) - missval ) < eps )
then 553 dens_org(k+2,i,j) = undef
560 if ( trim(dtype) ==
"map" )
then 561 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
564 velx_org(1:2,i,j) = 0.0_rp
566 velx_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
568 if( abs( velx_org(k+2,i,j) - missval ) < eps )
then 569 velx_org(k+2,i,j) = undef
573 do k = knum+1, dims(1)
574 velx_org(k+2,i,j) = velx_org(knum+2,i,j)
581 if ( trim(dtype) ==
"map" )
then 582 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
585 vely_org(1:2,i,j) = 0.0_rp
587 vely_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
589 if( abs( vely_org(k+2,i,j) - missval ) < eps )
then 590 vely_org(k+2,i,j) = undef
594 do k = knum+1, dims(1)
595 vely_org(k+2,i,j) = vely_org(knum+2,i,j)
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 ( trim(dtype) ==
"map" )
then 619 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
623 temp_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
625 if( abs( temp_org(k+2,i,j) - missval ) < eps )
then 626 temp_org(k+2,i,j) = undef
630 do k = knum+1, dims(1)
631 temp_org(k+2,i,j) = temp_org(knum+2,i,j)
638 if(dims(1)/=knum)
then 639 write(*,*)
'xxx The number of levels for HGT must be same as plevs! knum:',knum,
'> outer_nz:',dims(1)
642 if ( trim(dtype) ==
"levels" )
then 643 if(dims(1)/=lnum)
then 644 write(*,*)
'xxx lnum must be same as the outer_nz for HGT! ',dims(1),lnum
650 cz_org(k+2,i,j) =
real(lvars(k), kind=
rp)
652 cz_org(1,i,j) = 0.0_rp
655 else if ( trim(dtype) ==
"map" )
then 656 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),dims(1),nt,item,startrec,totalrec,yrev,gdata3d)
660 cz_org(k+2,i,j) =
real(gdata3D(i,j,k), kind=
rp)
662 if( abs( cz_org(k+2,i,j) - missval ) < eps )
then 663 cz_org(k+2,i,j) = undef
666 cz_org(1,i,j) = 0.0_rp
671 if ( trim(dtype) ==
"map" )
then 672 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
676 qtrc_org(k+2,i,j,
i_qv) =
real(gdata3D(i,j,k), kind=
rp)
678 if( abs( qtrc_org(k+2,i,j,
i_qv) - missval ) < eps )
then 679 qtrc_org(k+2,i,j,
i_qv) = undef
682 qtrc_org(1:2,i,j,
i_qv) = qtrc_org(3,i,j,
i_qv)
685 if( dims(1)>knum )
then 686 select case( upper_qv_type )
690 do k = knum+1, dims(1)
691 qtrc_org(k+2,i,j,
i_qv) = qtrc_org(knum+2,i,j,
i_qv)
698 write(*,*)
'xxx upper_qv_type in PARAM_MKINIT_REAL_GrADS is invalid! ', upper_qv_type
704 if ( trim(dtype) ==
"map" )
then 705 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
709 qtrc_org(k+2,i,j,
i_qc) =
real(gdata3D(i,j,k), kind=
rp)
711 if( abs( qtrc_org(k+2,i,j,
i_qc) - missval ) < eps )
then 712 qtrc_org(k+2,i,j,
i_qc) = undef
715 qtrc_org(1:2,i,j,
i_qc) = qtrc_org(3,i,j,
i_qc)
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 qtrc_org(k+2,i,j,
i_qr) =
real(gdata3D(i,j,k), kind=
rp)
727 if( abs( qtrc_org(k+2,i,j,
i_qr) - missval ) < eps )
then 728 qtrc_org(k+2,i,j,
i_qr) = undef
731 qtrc_org(1:2,i,j,
i_qr) = qtrc_org(3,i,j,
i_qr)
736 if ( trim(dtype) ==
"map" )
then 737 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
741 qtrc_org(k+2,i,j,
i_qi) =
real(gdata3D(i,j,k), kind=
rp)
743 if( abs( qtrc_org(k+2,i,j,
i_qi) - missval ) < eps )
then 744 qtrc_org(k+2,i,j,
i_qi) = undef
747 qtrc_org(1:2,i,j,
i_qi) = qtrc_org(3,i,j,
i_qi)
752 if ( trim(dtype) ==
"map" )
then 753 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
757 qtrc_org(k+2,i,j,
i_qs) =
real(gdata3D(i,j,k), kind=
rp)
759 if( abs( qtrc_org(k+2,i,j,
i_qs) - missval ) < eps )
then 760 qtrc_org(k+2,i,j,
i_qs) = undef
763 qtrc_org(1:2,i,j,
i_qs) = qtrc_org(3,i,j,
i_qs)
768 if ( trim(dtype) ==
"map" )
then 769 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
773 qtrc_org(k+2,i,j,
i_qg) =
real(gdata3D(i,j,k), kind=
rp)
775 if( abs( qtrc_org(k+2,i,j,
i_qg) - missval ) < eps )
then 776 qtrc_org(k+2,i,j,
i_qg) = undef
779 qtrc_org(1:2,i,j,
i_qg) = qtrc_org(3,i,j,
i_qg)
784 if (data_available(ia_qv,1)) cycle
785 if ( trim(dtype) ==
"map" )
then 786 call read_grads_file_3d(io_fid_grads_data,gfile,dims(2),dims(3),knum,nt,item,startrec,totalrec,yrev,gdata3d)
790 qtrc_org(k+2,i,j,
i_qv) =
real(gdata3D(i,j,k), kind=
rp)
792 if( abs( qtrc_org(k+2,i,j,
i_qv) - missval ) < eps )
then 793 qtrc_org(k+2,i,j,
i_qv) = undef
795 rhprs_org(k+2,i,j) = qtrc_org(k+2,i,j,
i_qv) / 100.0_rp
796 call psat( p_sat, temp_org(k+2,i,j) )
797 qm = epsvap * rhprs_org(k+2,i,j) * p_sat &
798 / ( pres_org(k+2,i,j) - rhprs_org(k+2,i,j) * p_sat )
799 qtrc_org(k+2,i,j,
i_qv) = qm / ( 1.0_rp + qm )
802 qtrc_org(1:2,i,j,
i_qv) = qtrc_org(3,i,j,
i_qv)
805 if( dims(3)>knum )
then 806 select case( upper_qv_type )
810 do k = knum+1, dims(1)
811 rhprs_org(k+2,i,j) = rhprs_org(knum+2,i,j)
812 call psat( p_sat, temp_org(k+2,i,j) )
813 qm = epsvap * rhprs_org(k+2,i,j) * p_sat &
814 / ( pres_org(k+2,i,j) - rhprs_org(k+2,i,j) * p_sat )
815 qtrc_org(k+2,i,j,
i_qv) = qm / ( 1.0_rp + qm )
816 qtrc_org(k+2,i,j,
i_qv) = min(qtrc_org(k+2,i,j,
i_qv),qtrc_org(k+1,i,j,
i_qv))
823 write(*,*)
'xxx upper_qv_type in PARAM_MKINIT_REAL_GrADS is invalid! ', upper_qv_type
829 if ( trim(dtype) ==
"map" )
then 830 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
833 pres_org(1,i,j) =
real(gdata2D(i,j), kind=
rp)
835 if( abs( pres_org(1,i,j) - missval ) < eps )
then 836 pres_org(1,i,j) = undef
842 if ( trim(dtype) ==
"map" )
then 843 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
846 pres_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
848 if( abs( pres_org(2,i,j) - missval ) < eps )
then 849 pres_org(2,i,j) = undef
855 if ( trim(dtype) ==
"map" )
then 856 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
859 velx_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
861 if( abs( velx_org(2,i,j) - missval ) < eps )
then 862 velx_org(2,i,j) = undef
868 if ( trim(dtype) ==
"map" )
then 869 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
872 vely_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
874 if( abs( vely_org(2,i,j) - missval ) < eps )
then 875 vely_org(2,i,j) = undef
881 if ( trim(dtype) ==
"map" )
then 882 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
885 temp_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
887 if( abs( temp_org(2,i,j) - missval ) < eps )
then 888 temp_org(2,i,j) = undef
894 if ( trim(dtype) ==
"map" )
then 895 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
898 qtrc_org(2,i,j,
i_qv) =
real(gdata2D(i,j), kind=
rp)
900 if( abs( qtrc_org(2,i,j,
i_qv) - missval ) < eps )
then 901 qtrc_org(2,i,j,
i_qv) = undef
907 if (data_available(ia_q2,1)) cycle
908 if ( trim(dtype) ==
"map" )
then 909 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
912 qtrc_org(2,i,j,
i_qv) =
real(gdata2D(i,j), kind=
rp)
914 if( abs( qtrc_org(2,i,j,
i_qv) - missval ) < eps )
then 915 qtrc_org(2,i,j,
i_qv) = undef
917 rhsfc = qtrc_org(2,i,j,
i_qv) / 100.0_rp
918 call psat( p_sat, temp_org(2,i,j) )
919 qm = epsvap * rhsfc * p_sat &
920 / ( pres_org(2,i,j) - rhsfc * p_sat )
921 qtrc_org(2,i,j,
i_qv) = qm / ( 1.0_rp + qm )
927 if ( trim(dtype) ==
"map" )
then 928 call read_grads_file_2d(io_fid_grads_data,gfile,dims(2),dims(3),1,nt,item,startrec,totalrec,yrev,gdata2d)
931 cz_org(2,i,j) =
real(gdata2D(i,j), kind=
rp)
933 if( abs( cz_org(2,i,j) - missval ) < eps )
then 934 cz_org(2,i,j) = undef
940 enddo loop_inputatomgrads
948 if( abs( pres_org(k,i,j) - undef ) < eps )
then 949 lm_layer(i,j) = k + 1
960 if ( data_available(ia_t2,1) .and. data_available(ia_ps,1) )
then 963 dens_org(2,i,j) = pres_org(2,i,j) / ( rdry * temp_org(2,i,j) )
966 else if ( data_available(ia_ps,1) )
then 967 if ( data_available(ia_topo,1) )
then 971 dz = cz_org(k,i,j) - cz_org(2,i,j)
972 dens_org(2,i,j) = ( pres_org(k,i,j) - pres_org(2,i,j) ) * 2.0_rp / ( grav * dz ) &
974 temp_org(2,i,j) = pres_org(2,i,j) / ( rdry * dens_org(2,i,j) )
981 dz = cz_org(k,i,j) - cz_org(2,i,j)
982 temp_org(2,i,j) = temp_org(k,i,j)
983 dens_org(2,i,j) = pres_org(2,i,j) / ( rdry * temp_org(2,i,j) )
987 else if ( data_available(ia_topo,1) )
then 988 if ( .not. data_available(ia_t2,1) )
then 992 dz = cz_org(k,i,j) - cz_org(2,i,j)
993 temp_org(2,i,j) = temp_org(k,i,j) + laps * dz
1000 dz = cz_org(k,i,j) - cz_org(2,i,j)
1002 dens_org(2,i,j) = ( pres_org(k,i,j) + grav * dens_org(k,i,j) * dz * 0.5_rp ) &
1003 / ( rdry * temp_org(2,i,j) - grav * dz * 0.5_rp )
1004 pres_org(2,i,j) = dens_org(2,i,j) * rdry * temp_org(2,i,j)
1011 temp_org(2,i,j) = temp_org(k,i,j)
1012 dens_org(2,i,j) = dens_org(k,i,j)
1013 pres_org(2,i,j) = pres_org(k,i,j)
1019 if ( .not. data_available(ia_topo,1) )
then 1024 if ( pres_org(2,i,j) < pres_org(1,i,j) )
then 1025 lp2 = log( pres_org(2,i,j) / pres_org(1,i,j) )
1029 if ( pres_org(k,i,j) < pres_org(1,i,j) )
then 1030 lp3 = log( pres_org(k,i,j) / pres_org(1,i,j) )
1034 cz_org(2,i,j) = max( 0.0_rp, cz_org(k,i,j) * lp2 / lp3 )
1042 temp_org(1,i,j) = temp_org(2,i,j) + laps * cz_org(2,i,j)
1045 if ( data_available(ia_slp,1) )
then 1048 dens_org(1,i,j) = pres_org(1,i,j) / ( rdry * temp_org(1,i,j) )
1054 dens_org(1,i,j) = ( pres_org(2,i,j) + grav * dens_org(2,i,j) * cz_org(2,i,j) * 0.5_rp ) &
1055 / ( rdry * temp_org(1,i,j) - grav * cz_org(2,i,j) * 0.5_rp )
1056 pres_org(1,i,j) = dens_org(1,i,j) * rdry * temp_org(1,i,j)
1062 if( pressure_coordinates )
then 1066 if( pres_org(k,i,j) > pres_org(2,i,j) )
then 1067 velz_org(k,i,j) = velz_org(2,i,j)
1068 velx_org(k,i,j) = velx_org(2,i,j)
1069 vely_org(k,i,j) = vely_org(2,i,j)
1070 dens_org(k,i,j) = dens_org(2,i,j)
1071 temp_org(k,i,j) = temp_org(2,i,j)
1072 qtrc_org(k,i,j,:) = qtrc_org(2,i,j,:)
1073 cz_org(k,i,j) = cz_org(2,i,j)
1082 if( abs( velz_org(k,i,j) - undef ) < eps ) velz_org(k,i,j) = velz_org(2,i,j)
1083 if( abs( velx_org(k,i,j) - undef ) < eps ) velx_org(k,i,j) = velx_org(2,i,j)
1084 if( abs( vely_org(k,i,j) - undef ) < eps ) vely_org(k,i,j) = vely_org(2,i,j)
1085 if( abs( pres_org(k,i,j) - undef ) < eps ) pres_org(k,i,j) = pres_org(2,i,j)
1086 if( abs( dens_org(k,i,j) - undef ) < eps ) dens_org(k,i,j) = dens_org(2,i,j)
1087 if( abs( temp_org(k,i,j) - undef ) < eps ) temp_org(k,i,j) = temp_org(2,i,j)
1089 if( abs( qtrc_org(k,i,j,iq) - undef ) < eps ) qtrc_org(k,i,j,iq) = 0.0_rp
1104 use_file_landwater, &
1108 integer,
intent(out) :: ldims(3)
1109 logical,
intent(out) :: use_waterratio
1110 logical,
intent(in) :: use_file_landwater
1111 character(len=*),
intent(in) :: basename
1119 if(
io_l )
write(
io_fid_log,*)
'+++ Real Case/Land Input File Type: GrADS format' 1122 use_waterratio = .false.
1124 if ( len_trim(basename) == 0 )
then 1125 write(*,*)
'xxx [realinput_grads] "BASEMAAME" is not specified in "PARAM_MKINIT_REAL_ATOMS"!', trim(basename)
1131 open( io_fid_grads_nml, &
1132 file = trim(basename), &
1133 form =
'formatted', &
1137 if ( ierr /= 0 )
then 1138 write(*,*)
'xxx [realinput_grads] Input file is not found! ', trim(basename)
1142 read(io_fid_grads_nml,nml=nml_grads_grid,iostat=ierr)
1143 if( ierr /= 0 )
then 1144 write(*,*)
'xxx [realinput_grads] Not appropriate names in nml_grads_grid in ', trim(basename),
'. Check!' 1151 if(outer_nx_sfc > 0)
then 1152 ldims(2) = outer_nx_sfc
1155 outer_nx_sfc = outer_nx
1157 if(outer_ny_sfc > 0)
then 1158 ldims(3) = outer_ny_sfc
1161 outer_ny_sfc = outer_ny
1164 allocate( gland2d( ldims(2), ldims(3) ) )
1165 allocate( gland3d( ldims(2), ldims(3), ldims(1) ) )
1171 grads_swpoint(:,2), &
1174 grads_lvars(:,:,2), &
1175 grads_startrec(:,2), &
1176 grads_totalrec(:,2), &
1179 grads_fendian(:,2), &
1180 grads_missval(:,2), &
1181 data_available(:,2), &
1183 num_item_list_land, &
1187 close( io_fid_grads_nml )
1189 do ielem = 1, num_item_list_land
1190 item = item_list_land(ielem)
1192 select case(trim(item))
1193 case(
'TOPO',
'TOPO_sfc',
'lsmask')
1194 if ( .not. data_available(ielem,2) )
then 1195 if(
io_l )
write(
io_fid_log,*)
'warning: ',trim(item),
' is not found & not used.' 1198 case(
'lon',
'lat',
'lon_sfc',
'lat_sfc')
1200 case(
'SMOISVC',
'SMOISDS')
1201 if ( use_file_landwater )
then 1202 if (.not. data_available(il_smoisvc,2) .and. .not. data_available(il_smoisds,2))
then 1203 write(*,*)
'xxx [realinput_grads] Not found in grads namelist! : ',trim(item_list_land(ielem))
1206 use_waterratio = data_available(il_smoisds,2)
1211 if ( .not. data_available(ielem,2) )
then 1212 write(*,*)
'xxx [realinput_grads] Not found in grads namelist! : ',trim(item_list_land(ielem))
1234 use_file_landwater, &
1243 real(RP),
intent(out) :: tg_org (:,:,:)
1244 real(RP),
intent(out) :: strg_org (:,:,:)
1245 real(RP),
intent(out) :: smds_org (:,:,:)
1246 real(RP),
intent(out) :: lst_org (:,:)
1247 real(RP),
intent(out) :: llon_org (:,:)
1248 real(RP),
intent(out) :: llat_org (:,:)
1249 real(RP),
intent(out) :: lz_org (:)
1250 real(RP),
intent(out) :: topo_org(:,:)
1251 real(RP),
intent(out) :: lmask_org(:,:)
1253 character(len=*),
intent(in) :: basename_num
1254 integer,
intent(in) :: ldims(3)
1255 logical,
intent(in) :: use_file_landwater
1256 integer,
intent(in) :: nt
1260 character(len=H_LONG) :: gfile
1262 real(RP) :: qvsat, qm
1264 integer :: i, j, k, ielem, n
1269 if(
io_l )
write(
io_fid_log,*)
'+++ ScaleLib/IO[realinput]/Categ[LandInputGrADS]' 1272 loop_inputlandgrads :
do ielem = 1, num_item_list_land
1274 item = item_list_land(ielem)
1276 dtype = grads_dtype(ielem,2)
1277 fname = grads_fname(ielem,2)
1278 lnum = grads_lnum(ielem,2)
1279 missval = grads_missval(ielem,2)
1281 if ( grads_knum(ielem,2) > 0 )
then 1282 knum = grads_knum(ielem,2)
1287 select case(trim(dtype))
1289 swpoint = grads_swpoint(ielem,2)
1290 dd = grads_dd(ielem,2)
1291 if( (abs(swpoint-large_number_one)<eps).or.(abs(dd-large_number_one)<eps) )
then 1292 write(*,*)
'xxx "swpoint" is required in grads namelist! ',swpoint
1293 write(*,*)
'xxx "dd" is required in grads namelist! ',dd
1298 write(*,*)
'xxx "lnum" in grads namelist is required for levels data! ' 1302 lvars(k)=grads_lvars(k,ielem,2)
1304 if(abs(lvars(1)-large_number_one)<eps)
then 1305 write(*,*)
'xxx "lvars" must be specified in grads namelist for levels data!',(lvars(k),k=1,lnum)
1309 startrec = grads_startrec(ielem,2)
1310 totalrec = grads_totalrec(ielem,2)
1311 fendian = grads_fendian(ielem,2)
1312 yrev = grads_yrev(ielem,2)
1313 if( (startrec<0).or.(totalrec<0) )
then 1314 write(*,*)
'xxx "startrec" is required in grads namelist! ',startrec
1315 write(*,*)
'xxx "totalrec" is required in grads namelist! ',totalrec
1319 if(io_fid_grads_data < 0)
then 1322 gfile=trim(fname)//trim(basename_num)//
'.grd' 1323 if( len_trim(fname)==0 )
then 1324 write(*,*)
'xxx "fname" is required in grads namelist for map data! ',trim(fname)
1330 select case(trim(item))
1332 if ( data_available(il_lsmask,2) )
then 1333 if ( trim(dtype) ==
"map" )
then 1334 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1335 lmask_org(:,:) =
real(gland2D(:,:), kind=
rp)
1341 if ( .not. data_available(il_lon_sfc,2) )
then 1342 if ( ldims(2).ne.outer_nx .or. ldims(3).ne.outer_ny )
then 1343 write(*,*)
'xxx namelist of "lon_sfc" is not found in grads namelist!' 1344 write(*,*)
'xxx dimension is different: outer_nx and outer_nx_sfc! ', outer_nx, ldims(2)
1345 write(*,*)
' : outer_ny and outer_ny_sfc! ', outer_ny, ldims(3)
1348 if ( trim(dtype) ==
"linear" )
then 1351 llon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * d2r
1354 else if ( trim(dtype) ==
"map" )
then 1355 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1356 llon_org(:,:) =
real(gland2D(:,:), kind=RP) * d2r
1360 if ( .not. data_available(il_lon_sfc,2) ) cycle
1361 if ( trim(dtype) ==
"linear" )
then 1364 llon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * d2r
1367 else if ( trim(dtype) ==
"map" )
then 1368 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1369 llon_org(:,:) =
real(gland2D(:,:), kind=RP) * d2r
1372 if ( .not. data_available(il_lat_sfc,2) )
then 1373 if ( ldims(2).ne.outer_nx .or. ldims(3).ne.outer_ny )
then 1374 write(*,*)
'xxx namelist of "lat_sfc" is not found in grads namelist!' 1375 write(*,*)
'xxx dimension is different: outer_nx and outer_nx_sfc! ', outer_nx, ldims(2)
1376 write(*,*)
' : outer_ny and outer_ny_sfc! ', outer_nx, ldims(3)
1379 if ( trim(dtype) ==
"linear" )
then 1382 llat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * d2r
1385 else if ( trim(dtype) ==
"map" )
then 1386 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1387 llat_org(:,:) =
real(gland2D(:,:), kind=RP) * d2r
1391 if ( .not. data_available(il_lat_sfc,2) ) cycle
1392 if ( trim(dtype) ==
"linear" )
then 1395 llat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * d2r
1398 else if ( trim(dtype) ==
"map" )
then 1399 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,1,item,startrec,totalrec,yrev,gland2d)
1400 llat_org(:,:) =
real(gland2D(:,:), kind=RP) * d2r
1403 if(ldims(1)/=knum)
then 1404 write(*,*)
'xxx "knum" must be equal to outer_nl for llev. knum:',knum,
'> outer_nl:',ldims(1)
1407 if ( trim(dtype) ==
"levels" )
then 1408 if(ldims(1)/=lnum)
then 1409 write(*,*)
'xxx lnum must be same as the outer_nl for llev! ',ldims(1),lnum
1413 lz_org(k) =
real(lvars(k), kind=
rp)
1426 if(ldims(1)/=knum)
then 1427 write(*,*)
'xxx The number of levels for STEMP must be same as llevs! ',ldims(1),knum
1430 if ( trim(dtype) ==
"map" )
then 1431 call read_grads_file_3d(io_fid_grads_data,gfile,ldims(2),ldims(3),ldims(1),nt,item,startrec,totalrec,yrev,gland3d)
1435 if ( abs(gland3d(i,j,k)-missval) < eps )
then 1436 tg_org(k,i,j) = undef
1438 tg_org(k,i,j) =
real(gland3D(i,j,k), kind=
rp)
1445 if ( use_file_landwater )
then 1446 if(ldims(1)/=knum)
then 1447 write(*,*)
'xxx The number of levels for SMOISVC must be same as llevs! ',ldims(1),knum
1450 if ( trim(dtype) ==
"map" )
then 1451 call read_grads_file_3d(io_fid_grads_data,gfile,ldims(2),ldims(3),ldims(1),nt,item,startrec,totalrec,yrev,gland3d)
1455 if ( abs(gland3d(i,j,k)-missval) < eps )
then 1456 strg_org(k,i,j) = undef
1458 strg_org(k,i,j) =
real(gland3D(i,j,k), kind=
rp)
1466 if ( use_file_landwater )
then 1467 if(ldims(1)/=knum)
then 1468 write(*,*)
'xxx The number of levels for SMOISDS must be same as llevs! ',ldims(1),knum
1471 if ( trim(dtype) ==
"map" )
then 1472 call read_grads_file_3d(io_fid_grads_data,gfile,ldims(2),ldims(3),ldims(1),nt,item,startrec,totalrec,yrev,gland3d)
1476 if ( abs(gland3d(i,j,k)-missval) < eps )
then 1477 smds_org(k,i,j) = undef
1479 smds_org(k,i,j) =
real(gland3D(i,j,k), kind=
rp)
1487 if ( trim(dtype) ==
"map" )
then 1488 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,nt,item,startrec,totalrec,yrev,gland2d)
1491 if ( abs(gland2d(i,j)-missval) < eps )
then 1492 lst_org(i,j) = undef
1494 lst_org(i,j) =
real(gland2D(i,j), kind=
rp)
1500 if ( .not. data_available(il_topo_sfc,2) )
then 1501 if ( ldims(2)==outer_nx .or. ldims(3)==outer_ny )
then 1502 if ( trim(dtype) ==
"map" )
then 1503 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,nt,item,startrec,totalrec,yrev,gland2d)
1506 if ( abs(gland2d(i,j)-missval) < eps )
then 1507 topo_org(i,j) = undef
1509 topo_org(i,j) =
real(gland2D(i,j), kind=
rp)
1519 if ( data_available(il_topo_sfc,2) )
then 1520 if ( trim(dtype) ==
"map" )
then 1521 call read_grads_file_2d(io_fid_grads_data,gfile,ldims(2),ldims(3),1,nt,item,startrec,totalrec,yrev,gland2d)
1524 if ( abs(gland2d(i,j)-missval) < eps )
then 1525 topo_org(i,j) = undef
1527 topo_org(i,j) =
real(gland2D(i,j), kind=
rp)
1532 else if ( .not. data_available(il_topo,2) )
then 1536 enddo loop_inputlandgrads
1561 integer,
intent(out) :: odims(2)
1562 integer,
intent(out) :: timelen
1563 character(len=*),
intent(in) :: basename
1565 character(len=H_LONG) :: grads_ctl
1572 if(
io_l )
write(
io_fid_log,*)
'+++ Real Case/Ocean Input File Type: GrADS format' 1576 if ( len_trim(basename) == 0 )
then 1577 grads_ctl =
"namelist.grads_boundary" 1579 grads_ctl = basename
1584 open( io_fid_grads_nml, &
1585 file = trim(grads_ctl), &
1586 form =
'formatted', &
1590 if ( ierr /= 0 )
then 1591 write(*,*)
'xxx [realinput_grads] Input file is not found! ', trim(grads_ctl)
1595 read(io_fid_grads_nml,nml=nml_grads_grid,iostat=ierr)
1596 if( ierr /= 0 )
then 1597 write(*,*)
'xxx [realinput_grads] Not appropriate names in nml_grads_grid in ', trim(grads_ctl),
'. Check!' 1605 if(outer_nx_sst > 0)
then 1606 odims(1) = outer_nx_sst
1607 else if (outer_nx_sfc > 0)
then 1608 odims(1) = outer_nx_sfc
1609 outer_nx_sst = outer_nx_sfc
1612 outer_nx_sst = outer_nx
1614 if(outer_ny_sst > 0)
then 1615 odims(2) = outer_ny_sst
1616 else if(outer_ny_sfc > 0)
then 1617 odims(2) = outer_ny_sfc
1618 outer_ny_sst = outer_ny_sfc
1621 outer_ny_sst = outer_ny
1624 allocate( gsst2d( odims(1), odims(2) ) )
1631 grads_swpoint(:,3), &
1634 grads_lvars(:,:,3), &
1635 grads_startrec(:,3), &
1636 grads_totalrec(:,3), &
1639 grads_fendian(:,3), &
1640 grads_missval(:,3), &
1641 data_available(:,3), &
1643 num_item_list_ocean, &
1647 close( io_fid_grads_nml )
1649 do ielem = 1, num_item_list_ocean
1650 item = item_list_ocean(ielem)
1652 select case(trim(item))
1653 case(
'lsmask',
'lsmask_sst')
1654 if ( .not. data_available(io_lsmask,3) .and. .not. data_available(io_lsmask_sst,3) )
then 1655 if(
io_l )
write(
io_fid_log,*)
'warning: ',trim(item),
' is not found & not used.' 1658 case(
'lon',
'lat',
'lon_sfc',
'lat_sfc',
'lon_sst',
'lat_sst')
1661 if (.not. data_available(io_sst,3) .and. .not. data_available(io_skint,3) )
then 1662 write(*,*)
'xxx [realinput_grads] SST and SKINT are found in grads namelist!' 1665 if (.not. data_available(io_sst,3))
then 1666 if(
io_l )
write(
io_fid_log,*)
'warning: SST is found in grads namelist. SKINT is used in place of SST.' 1672 if ( .not. data_available(ielem,3) )
then 1673 write(*,*)
'xxx [realinput_grads/ParentOceanSetupGrADS] Not found in grads namelist! : ', &
1674 trim(item_list_ocean(ielem))
1688 if(
io_l )
write(
io_fid_log,*)
'+++ ScaleLib/IO[realinput]/Categ[OceanOpenGrADS]' 1710 real(RP),
intent(out) :: tw_org (:,:)
1711 real(RP),
intent(out) :: sst_org (:,:)
1712 real(RP),
intent(out) :: omask_org(:,:)
1713 real(RP),
intent(out) :: olon_org (:,:)
1714 real(RP),
intent(out) :: olat_org (:,:)
1716 character(len=*),
intent(in) :: basename_num
1717 integer,
intent(in) :: odims(2)
1718 integer,
intent(in) :: nt
1722 character(len=H_LONG) :: gfile
1724 real(RP) :: qvsat, qm
1726 integer :: i, j, ielem, n
1731 if(
io_l )
write(
io_fid_log,*)
'+++ ScaleLib/IO[realinput]/Categ[OceanInputGrADS]' 1734 loop_inputoceangrads :
do ielem = 1, num_item_list_ocean
1736 item = item_list_ocean(ielem)
1738 dtype = grads_dtype(ielem,3)
1739 fname = grads_fname(ielem,3)
1740 lnum = grads_lnum(ielem,3)
1741 missval = grads_missval(ielem,3)
1743 select case(trim(dtype))
1745 swpoint = grads_swpoint(ielem,3)
1746 dd = grads_dd(ielem,3)
1747 if( (abs(swpoint-large_number_one)<eps).or.(abs(dd-large_number_one)<eps) )
then 1748 write(*,*)
'xxx "swpoint" is required in grads namelist! ',swpoint
1749 write(*,*)
'xxx "dd" is required in grads namelist! ',dd
1753 write(*,*)
'xxx "lnum" in grads namelist is invalid for ocean data' 1756 startrec = grads_startrec(ielem,3)
1757 totalrec = grads_totalrec(ielem,3)
1758 fendian = grads_fendian(ielem,3)
1759 yrev = grads_yrev(ielem,3)
1760 if( (startrec<0).or.(totalrec<0) )
then 1761 write(*,*)
'xxx "startrec" is required in grads namelist! ',startrec
1762 write(*,*)
'xxx "totalrec" is required in grads namelist! ',totalrec
1766 if(io_fid_grads_data < 0)
then 1769 gfile=trim(fname)//trim(basename_num)//
'.grd' 1770 if( len_trim(fname)==0 )
then 1771 write(*,*)
'xxx "fname" is required in grads namelist for map data! ',trim(fname)
1777 select case(trim(item))
1779 if ( .not. data_available(io_lsmask_sst,3) .and. data_available(io_lsmask,3) )
then 1780 if ( odims(1)==outer_nx_sfc .and. odims(2)==outer_ny_sfc )
then 1781 if ( trim(dtype) ==
"map" )
then 1782 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1783 omask_org(:,:) =
real(gsst2D(:,:), kind=
rp)
1790 if ( data_available(io_lsmask_sst,3) )
then 1791 if ( trim(dtype) ==
"map" )
then 1792 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1793 omask_org(:,:) =
real(gsst2D(:,:), kind=
rp)
1795 else if ( .not. data_available(io_lsmask,3) )
then 1799 if ( .not. data_available(io_lon_sst,3) .and. .not. data_available(io_lon_sfc,3) )
then 1800 if ( odims(1).ne.outer_nx .or. odims(2).ne.outer_ny )
then 1801 write(*,*)
'xxx namelist of "lon_sst" is not found in grads namelist!' 1802 write(*,*)
'xxx dimension is different: outer_nx and outer_nx_sst! ', outer_nx, odims(1)
1803 write(*,*)
' : outer_ny and outer_ny_sst! ', outer_ny, odims(2)
1806 if ( trim(dtype) ==
"linear" )
then 1809 olon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * d2r
1812 else if ( trim(dtype) ==
"map" )
then 1813 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1814 olon_org(:,:) =
real(gsst2D(:,:), kind=RP) * d2r
1818 if ( .not. data_available(io_lon_sst,3) .and. data_available(io_lon_sfc,3) )
then 1819 if ( odims(1).ne.outer_nx_sfc .or. odims(2).ne.outer_ny_sfc )
then 1820 write(*,*)
'xxx namelist of "lon_sst" is not found in grads namelist!' 1821 write(*,*)
'xxx dimension is different: outer_nx_sfc and outer_nx_sst! ', outer_nx_sfc, odims(1)
1822 write(*,*)
' : outer_ny_sfc and outer_ny_sst! ', outer_ny_sfc, odims(2)
1825 if ( trim(dtype) ==
"linear" )
then 1828 olon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * d2r
1831 else if ( trim(dtype) ==
"map" )
then 1832 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1833 olon_org(:,:) =
real(gsst2D(:,:), kind=RP) * d2r
1837 if ( .not. data_available(io_lon_sst,3) ) cycle
1838 if ( trim(dtype) ==
"linear" )
then 1841 olon_org(i,j) =
real(swpoint+real(i-1)*dd, kind=RP) * d2r
1844 else if ( trim(dtype) ==
"map" )
then 1845 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1846 olon_org(:,:) =
real(gsst2D(:,:), kind=RP) * d2r
1849 if ( .not. data_available(io_lat_sfc,3) .and. .not. data_available(io_lat_sst,3) )
then 1850 if ( odims(1).ne.outer_nx .or. odims(2).ne.outer_ny )
then 1851 write(*,*)
'xxx namelist of "lat_sst" is not found in grads namelist!' 1852 write(*,*)
'xxx dimension is different: outer_nx and outer_nx_sst! ', outer_nx, odims(1)
1853 write(*,*)
' : outer_ny and outer_ny_sst! ', outer_ny, odims(2)
1856 if ( trim(dtype) ==
"linear" )
then 1859 olat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * d2r
1862 else if ( trim(dtype) ==
"map" )
then 1863 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1864 olat_org(:,:) =
real(gsst2D(:,:), kind=RP) * d2r
1868 if ( .not. data_available(io_lat_sst,3) .and. data_available(io_lat_sfc,3) )
then 1869 if ( odims(1).ne.outer_nx_sfc .or. odims(2).ne.outer_ny_sfc )
then 1870 write(*,*)
'xxx namelist of "lat_sst" is not found in grads namelist!' 1871 write(*,*)
'xxx dimension is different: outer_nx_sfc and outer_nx_sst! ', outer_nx_sfc, odims(1)
1872 write(*,*)
' : outer_ny_sfc and outer_ny_sst! ', outer_ny_sfc, odims(2)
1875 if ( trim(dtype) ==
"linear" )
then 1878 olat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * d2r
1881 else if ( trim(dtype) ==
"map" )
then 1882 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1883 olat_org(:,:) =
real(gsst2D(:,:), kind=RP) * d2r
1887 if ( .not. data_available(io_lat_sst,3) ) cycle
1888 if ( trim(dtype) ==
"linear" )
then 1891 olat_org(i,j) =
real(swpoint+real(j-1)*dd, kind=RP) * d2r
1894 else if ( trim(dtype) ==
"map" )
then 1895 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,1,item,startrec,totalrec,yrev,gsst2d)
1896 olat_org(:,:) =
real(gsst2D(:,:), kind=RP) * d2r
1899 if ( .not. data_available(io_sst,3) )
then 1900 if ( odims(1).ne.outer_nx_sfc .or. odims(2).ne.outer_ny_sfc )
then 1901 write(*,*)
'xxx dimsntion is different: outer_nx_sst/outer_nx_sfc and outer_nx_sst! ', odims(1), outer_nx_sfc
1902 write(*,*)
' : outer_ny_sst/outer_ny_sfc and outer_ny_sst! ', odims(2), outer_ny_sfc
1905 if ( trim(dtype) ==
"map" )
then 1906 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,nt,item,startrec,totalrec,yrev,gsst2d)
1909 if ( abs(gsst2d(i,j)-missval) < eps )
then 1910 sst_org(i,j) = undef
1912 sst_org(i,j) =
real(gsst2D(i,j), kind=
rp)
1919 if ( .not. data_available(io_sst,3) ) cycle
1920 if ( trim(dtype) ==
"map" )
then 1921 call read_grads_file_2d(io_fid_grads_data,gfile,odims(1),odims(2),1,nt,item,startrec,totalrec,yrev,gsst2d)
1924 if ( abs(gsst2d(i,j)-missval) < eps )
then 1925 sst_org(i,j) = undef
1927 sst_org(i,j) =
real(gsst2D(i,j), kind=
rp)
1933 enddo loop_inputoceangrads
1973 character(len=H_SHORT),
intent(out) :: grads_item (:)
1974 character(len=H_LONG),
intent(out) :: grads_fname (:)
1975 character(len=H_LONG),
intent(out) :: grads_dtype (:)
1976 real(RP),
intent(out) :: grads_swpoint (:)
1977 real(RP),
intent(out) :: grads_dd (:)
1978 integer,
intent(out) :: grads_lnum (:)
1979 real(RP),
intent(out) :: grads_lvars (:,:)
1980 integer,
intent(out) :: grads_startrec(:)
1981 integer,
intent(out) :: grads_totalrec(:)
1982 integer,
intent(out) :: grads_knum (:)
1983 character(len=H_SHORT),
intent(out) :: grads_yrev (:)
1984 character(len=H_SHORT),
intent(out) :: grads_fendian (:)
1985 real(SP),
intent(out) :: grads_missval (:)
1986 logical,
intent(out) :: data_available(:)
1987 character(len=*),
intent(in) :: item_list (:)
1988 integer,
intent(in) :: num_item_list
1989 character(len=*),
intent(in) :: basename
1990 integer,
intent(in) :: io_fid_grads_nml
1992 integer :: grads_vars_nmax
1993 integer :: k, n, ielem, ierr
2011 if ( io_fid_grads_nml > 0 )
then 2012 rewind( io_fid_grads_nml )
2014 do n = 1, grads_vars_limit
2015 read(io_fid_grads_nml, nml=grdvar, iostat=ierr)
2017 write(*,*)
'xxx [realinput_grads/read_namelist] Not appropriate names in grdvar in ', &
2018 trim(basename),
'. Check!' 2020 else if( ierr < 0 )
then 2023 grads_vars_nmax = grads_vars_nmax + 1
2026 write(*,*)
'xxx [realinput_grads/read_namelist] namelist file is not open! ', trim(basename)
2030 if ( grads_vars_nmax > grads_vars_limit )
then 2031 write(*,*)
'xxx [realinput_grads/read_namelist] The number of grads vars exceeds grads_vars_limit! ', &
2032 grads_vars_nmax,
' > ', grads_vars_limit
2037 data_available(:) = .false.
2038 do ielem = 1, num_item_list
2039 if ( io_fid_grads_nml > 0 ) rewind( io_fid_grads_nml )
2040 do n = 1, grads_vars_nmax
2046 swpoint = large_number_one
2047 dd = large_number_one
2049 lvars = large_number_one
2055 missval = large_number_one
2058 if ( io_fid_grads_nml > 0 )
then 2059 read(io_fid_grads_nml, nml=grdvar, iostat=ierr)
2060 if( ierr /= 0 )
exit 2063 if(item == item_list(ielem))
then 2064 grads_item(ielem) = item
2065 grads_fname(ielem) = fname
2066 grads_dtype(ielem) = dtype
2067 grads_swpoint(ielem) = swpoint
2068 grads_dd(ielem) = dd
2069 grads_lnum(ielem) = lnum
2070 do k = 1, lvars_limit
2071 grads_lvars(k,ielem) = lvars(k)
2073 grads_startrec(ielem) = startrec
2074 grads_totalrec(ielem) = totalrec
2075 grads_knum(ielem) = knum
2076 grads_yrev(ielem) = yrev
2077 grads_fendian(ielem) = fendian
2078 grads_missval(ielem) = missval
2079 data_available(ielem) = .true.
2084 if(
io_l )
write(
io_fid_log,*)
'GrADS data availability ',trim(item_list(ielem)),data_available(ielem)
2090 subroutine open_grads_file(io_fid,filename,irecl)
2093 integer,
intent(in) :: io_fid
2094 character(len=*),
intent(in) :: filename
2095 integer,
intent(in) :: irecl
2100 file = trim(filename), &
2101 form =
'unformatted', &
2102 access =
'direct', &
2106 if ( ierr /= 0 )
then 2107 write(*,*)
'xxx grads file does not found! ', trim(filename)
2112 end subroutine open_grads_file
2115 subroutine read_grads_file_2d( &
2126 integer,
intent(in) :: io_fid
2127 character(len=*),
intent(in) :: gfile
2128 integer,
intent(in) :: nx,ny,nz,it
2129 character(len=*),
intent(in) :: item
2130 integer,
intent(in) :: startrec
2131 integer,
intent(in) :: totalrec
2132 character(len=*),
intent(in) :: yrev
2133 real(SP),
intent(out) :: gdata(nx,ny)
2135 real(SP) :: work(nx,ny)
2138 integer :: irec, irecl
2142 call open_grads_file(io_fid, gfile, irecl)
2143 irec = totalrec * (it-1) + startrec
2144 read(io_fid, rec=irec, iostat=ierr) gdata(:,:)
2145 if ( ierr /= 0 )
then 2146 write(*,*)
'xxx grads data is not found! ',trim(item),it
2147 write(*,*)
'xxx namelist or grads data might be wrong.' 2151 if( trim(yrev) ==
"on" )
then 2152 work(:,:)=gdata(:,:)
2155 gdata(i,j)=work(i,ny-j+1)
2160 call close_grads_file(io_fid,gfile)
2163 end subroutine read_grads_file_2d
2166 subroutine read_grads_file_3d( &
2177 integer,
intent(in) :: io_fid
2178 character(len=*),
intent(in) :: gfile
2179 integer,
intent(in) :: nx,ny,nz,it
2180 character(len=*),
intent(in) :: item
2181 integer,
intent(in) :: startrec
2182 integer,
intent(in) :: totalrec
2183 character(len=*),
intent(in) :: yrev
2184 real(SP),
intent(out) :: gdata(nx,ny,nz)
2186 real(SP) :: work(nx,ny,nz)
2189 integer :: irec,irecl
2193 call open_grads_file(io_fid, gfile, irecl)
2195 irec = totalrec * (it-1) + startrec + (k-1)
2196 read(io_fid, rec=irec, iostat=ierr) gdata(:,:,k)
2197 if ( ierr /= 0 )
then 2198 write(*,*)
'xxx grads data does not found! ',trim(item),
', k=',k,
', it=',it,
' in ', trim(gfile)
2203 if( trim(yrev) ==
"on" )
then 2204 work(:,:,:)=gdata(:,:,:)
2208 gdata(i,j,k)=work(i,ny-j+1,k)
2214 call close_grads_file(io_fid,gfile)
2217 end subroutine read_grads_file_3d
2220 subroutine close_grads_file(io_fid,filename)
2223 integer,
intent(in) :: io_fid
2224 character(len=*),
intent(in) :: filename
2227 close(io_fid, iostat=ierr)
2228 if ( ierr /= 0 )
then 2229 write(*,*)
'xxx grads file was not closed peacefully! ',trim(filename)
2234 end subroutine close_grads_file
real(rp), public const_cpdry
specific heat (dry air,constant pressure) [J/kg/K]
module ATMOSPHERE / Saturation adjustment
subroutine, public prc_mpistop
Abort MPI.
logical, public io_l
output log or not? (this process)
real(rp), parameter, public const_tem00
temperature reference (0C) [K]
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
logical, public io_nml
output log or not? (for namelist, this process)
integer function, public io_get_available_fid()
search & get available file ID
real(rp), public const_pre00
pressure reference [Pa]
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_eps
small number
integer, public io_fid_conf
Config file ID.
integer, public io_fid_log
Log file ID.
integer, parameter, public rp
integer, public io_fid_nml
Log file ID (only for output namelist)