89 character*256 :: fngrib
91 integer :: i, j, ij, jj
92 integer :: ii, iii, istart, iend, imid
95 integer,
parameter :: iunit = 14
96 integer,
parameter :: iunit2 = 34
99 integer :: jdisc, jgdtn, jpdtn, k
100 integer :: jids(200), jgdt(200), jpdt(200)
102 integer,
parameter :: lugi = 0
105 integer :: message_num
109 logical*1,
allocatable :: lbms(:)
112 real :: gridis, gridie, fraction, x1, r
113 real,
allocatable :: lats_mdl_temp (:,:)
114 real,
allocatable :: lons_mdl_temp (:,:)
116 type(gribfield) :: gfld
118 print*,
"- READ MODEL GRID INFORMATION" 129 print*,
'- FATAL ERROR: MODEL LAT FILE MUST BE GRIB1 OR GRIB2 FORMAT' 130 call w3tage(
'SNOW2MDL')
134 print*,
"- OPEN MODEL LAT FILE ", trim(fngrib)
135 call baopenr (iunit, fngrib, iret)
138 print*,
'- FATAL ERROR: BAD OPEN, IRET IS ', iret
139 call w3tage(
'SNOW2MDL')
156 print*,
"- GET GRIB HEADER" 157 call getgbh(iunit, lugi, lskip, jpds, jgds, numbytes, &
158 numpts, message_num, kpds, kgds, iret)
161 print*,
'- FATAL ERROR: BAD READ OF GRIB HEADER. IRET IS ', iret
162 call w3tage(
'SNOW2MDL')
180 if (kgds(1) == 4)
then 183 resol_mdl = float(kgds(9)) / 1000.0 * 111.0
184 else if (kgds(1) == 203)
then 187 resol_mdl = sqrt( (float(kgds(9)) / 1000.0)**2 + &
188 (float(kgds(10)) / 1000.0)**2 )
190 else if (kgds(1) == 205)
then 193 resol_mdl = ((float(kgds(9)) / 1000.0) + (float(kgds(10)) / 1000.0)) &
196 print*,
'- FATAL ERROR: UNRECOGNIZED MODEL GRID.' 197 call w3tage(
'SNOW2MDL')
204 print*,
"- DEGRIB DATA" 205 call getgb(iunit, lugi, (
imdl*
jmdl), lskip, jpds, jgds, &
206 numpts, message_num, kpds, kgds, lbms, lats_mdl_temp, iret)
209 print*,
'- FATAL ERROR: BAD DEGRIB OF FILE. IRET IS ',iret
210 call w3tage(
'SNOW2MDL')
216 lat11 = lats_mdl_temp(1,1)
219 elseif (isgrib==2)
then 234 print*,
"- DEGRIB DATA" 235 call getgb2(iunit, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
236 unpack, k, gfld, iret)
239 print*,
'- FATAL ERROR: BAD DEGRIB OF FILE, IRET IS ', iret
240 call w3tage(
'SNOW2MDL')
256 lats_mdl_temp = reshape(gfld%fld , (/
imdl,
jmdl/) )
258 lat11 = lats_mdl_temp(1,1)
265 call baclose(iunit,iret)
276 print*,
'- FATAL ERROR: MODEL LON FILE MUST BE GRIB1 OR GRIB2 FORMAT' 277 call w3tage(
'SNOW2MDL')
281 print*,
"- OPEN MODEL LON FILE ", trim(fngrib)
282 call baopenr (iunit, fngrib, iret)
285 print*,
"- FATAL ERROR: BAD OPEN. IRET IS ", iret
286 call w3tage(
'SNOW2MDL')
302 print*,
"- DEGRIB DATA" 303 call getgb(iunit, lugi, (
imdl*
jmdl), lskip, jpds, jgds, &
304 numpts, message_num, kpds, kgds, lbms, lons_mdl_temp, iret)
307 print*,
'- FATAL ERROR: BAD DEGRIB OF DATA. IRET IS ',iret
308 call w3tage(
'SNOW2MDL')
314 lon11 = lons_mdl_temp(1,1)
317 elseif (isgrib==2)
then 332 print*,
"- DEGRIB DATA" 333 call getgb2(iunit, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
334 unpack, k, gfld, iret)
337 print*,
'- FATAL ERROR: BAD DEGRIB OF FILE, IRET IS ', iret
338 call w3tage(
'SNOW2MDL')
343 lons_mdl_temp = reshape(gfld%fld , (/
imdl,
jmdl/) )
345 lon11 = lons_mdl_temp(1,1)
352 call baclose(iunit, iret)
363 print*,
'- FATAL ERROR: MODEL LANDMASK FILE MUST BE GRIB1 OR GRIB2 FORMAT' 364 call w3tage(
'SNOW2MDL')
368 print*,
"- OPEN MODEL LANDMASK FILE ", trim(fngrib)
369 call baopenr (iunit, fngrib, iret)
372 print*,
'- FATAL ERROR: BAD OPEN OF FILE. IRET IS ', iret
373 call w3tage(
'SNOW2MDL')
389 print*,
"- DEGRIB DATA" 390 call getgb(iunit, lugi, (
imdl*
jmdl), lskip, jpds, jgds, &
391 numpts, message_num, kpds, kgds, lbms,
lsmask_mdl, iret)
394 print*,
'- FATAL ERROR: BAD DEGRIB OF DATA. IRET IS ',iret
395 call w3tage(
'SNOW2MDL')
401 elseif (isgrib==2)
then 416 print*,
"- DEGRIB DATA" 417 call getgb2(iunit, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
418 unpack, k, gfld, iret)
421 print*,
'- FATAL ERROR: BAD DEGRIB OF FILE, IRET IS ', iret
422 call w3tage(
'SNOW2MDL')
433 call baclose(iunit,iret)
443 if (kgds(1) == 4 .and. (len_trim(
gfs_lpl_file) > 0))
then 447 print*,
"- RUNNING A THINNED GRID" 451 print*,
"- OPEN/READ GFS LONSPERLAT FILE: ",trim(
gfs_lpl_file)
454 print*,
'- FATAL ERROR: BAD OPEN OF LONSPERLAT FILE. ABORT. IRET: ', iret
455 call w3tage(
'SNOW2MDL')
462 print*,
'- FATAL ERROR: BAD READ OF LONSPERLAT FILE. ABORT. IRET: ', iret
463 call w3tage(
'SNOW2MDL')
467 if (numpts /= (
jmdl/2))
then 468 print*,
'- FATAL ERROR: WRONG DIMENSIION IN LONSPERLAT FILE. ABORT.' 469 call w3tage(
'SNOW2MDL')
498 istart = nint(gridis)
502 if (ii == istart)
then 503 fraction = 0.5 - (gridis - float(istart))
504 if (fraction < 0.0001) cycle
507 fraction = 0.5 + (gridie - float(iend))
508 if (fraction < 0.0001) cycle
511 if (iii < 1) iii =
imdl + iii
539 print*,
'- MODEL GRID ONLY HAS WATER POINTS, DONT CREATE SNOW FILE.' 540 print*,
'- NORMAL TERMINATION.' 541 call w3tage(
'SNOW2MDL')
563 deallocate (lats_mdl_temp, lons_mdl_temp)
This module reads in data from the program's configuration namelist.
real lonlast
Corner point longitude (imdl,jmdl) of model grid.
subroutine grib2_null(gfld)
Nullify the grib2 gribfield pointers.
integer jmdl
j-dimension of model grid
logical thinned
When true, global grids will run thinned (number of i points decrease toward pole) ...
integer, dimension(:), allocatable lonsperlat_mdl
Number of longitudes (i-points) for each latitude (row).
real, dimension(:), allocatable lats_mdl
Latitudes of model grid points.
Read in data defining the model grid.
real, dimension(:,:), allocatable lsmask_mdl
land mask of model grid (0 - non land, 1-land) for global grids run thinned, will contain a modified ...
subroutine read_mdl_grid_info
Read mdl grid.
real, dimension(:), allocatable lons_mdl
longitudes of model grid points
real resol_mdl
approximate model resolution in km.
subroutine gdt_to_gds(igdtnum, igdstmpl, igdtlen, kgds, ni, nj, res)
Convert from the grib2 grid description template array used by the ncep grib2 library, to the grib1 grid description section array used by ncep ipolates library.
integer imdl
i-dimension of model grid
subroutine grib2_free(gfld)
Deallocate the grib2 gribfield pointers.
subroutine model_grid_cleanup
Clean up allocatable arrays.
character *200, public model_lon_file
path/name lons on the model grid
real lon11
Corner point longitude (1,1) of model grid.
integer ijmdl
total number of model land points
integer, dimension(:), allocatable jpts_mdl
j index of point on full grid
character *200, public gfs_lpl_file
GFS gaussian thinned (reduced) grid definition file.
integer, dimension(200) kgds_mdl
holds grib gds info of model grid
real latlast
Corner point latitude (imdl,jmdl) of model grid.
integer, dimension(:), allocatable ipts_mdl
i index of point on full grid
character *200, public model_lsmask_file
path/name nesdis/ims land mask
subroutine grib_check(file_name, isgrib)
Determine whether file is grib or not.
integer grid_id_mdl
grib id of model grid, 4-gaussian, 203-egrid
real lat11
Corner point latitude (1,1) of model grid.
character *200, public model_lat_file
path/name lats on the model grid
real, dimension(:,:), allocatable lsmask_mdl_sav
saved copy of land mask of model grid (0 - non land, 1-land) only used for global thinned grids...