26 integer :: grid_id_mdl
30 integer,
allocatable :: ipts_mdl(:)
31 integer,
allocatable :: jpts_mdl(:)
33 integer :: kgds_mdl(200)
34 integer,
allocatable :: lonsperlat_mdl (:)
41 real,
allocatable :: lats_mdl(:)
46 real,
allocatable :: lons_mdl(:)
47 real,
allocatable :: lsmask_mdl(:,:)
50 real,
allocatable :: lsmask_mdl_sav(:,:)
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"
124 fngrib = model_lat_file
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')
178 grid_id_mdl = kpds(3)
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 )
189 resol_mdl = resol_mdl * 111.0
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')
201 allocate(lats_mdl_temp(imdl,jmdl))
202 allocate(lbms(imdl*jmdl))
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)
217 latlast = lats_mdl_temp(imdl,jmdl)
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')
249 call
gdt_to_gds(gfld%igdtnum, gfld%igdtmpl, gfld%igdtlen, kgds_mdl, &
250 imdl, jmdl, resol_mdl)
255 allocate(lats_mdl_temp(imdl,jmdl))
256 lats_mdl_temp = reshape(gfld%fld , (/imdl,jmdl/) )
258 lat11 = lats_mdl_temp(1,1)
259 latlast = lats_mdl_temp(imdl,jmdl)
265 call baclose(iunit,iret)
271 fngrib = model_lon_file
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')
299 allocate(lons_mdl_temp(imdl,jmdl))
300 allocate(lbms(imdl*jmdl))
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)
315 lonlast = lons_mdl_temp(imdl,jmdl)
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')
342 allocate(lons_mdl_temp(imdl,jmdl))
343 lons_mdl_temp = reshape(gfld%fld , (/imdl,jmdl/) )
345 lon11 = lons_mdl_temp(1,1)
346 lonlast = lons_mdl_temp(imdl,jmdl)
352 call baclose(iunit, iret)
358 fngrib = model_lsmask_file
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')
386 allocate(lsmask_mdl(imdl,jmdl))
387 allocate(lbms(imdl*jmdl))
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')
426 allocate(lsmask_mdl(imdl,jmdl))
427 lsmask_mdl = reshape(gfld%fld , (/imdl,jmdl/) )
433 call baclose(iunit,iret)
443 if (kgds(1) == 4 .and. (len_trim(gfs_lpl_file) > 0))
then
447 print*,
"- RUNNING A THINNED GRID"
449 allocate (lonsperlat_mdl(jmdl/2))
451 print*,
"- OPEN/READ GFS LONSPERLAT FILE: ",trim(gfs_lpl_file)
452 open (iunit2, file=trim(gfs_lpl_file), iostat=iret)
454 print*,
'- FATAL ERROR: BAD OPEN OF LONSPERLAT FILE. ABORT. IRET: ', iret
455 call w3tage(
'SNOW2MDL')
459 read (iunit2,*,iostat=iret) numpts, lonsperlat_mdl
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')
473 allocate (lsmask_mdl_sav(imdl,jmdl))
474 lsmask_mdl_sav = lsmask_mdl
490 if (j > jmdl/2) jj = jmdl - j + 1
491 r = float(imdl)/ float(lonsperlat_mdl(jj))
492 do i = 1, lonsperlat_mdl(jj)
496 if (lsmask_mdl_sav(imid,j) > 0.0)
then
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
512 lsmask_mdl(iii,j) = lsmask_mdl_sav(imid,j)
529 if (lsmask_mdl(i,j) > 0.0)
then
539 print*,
'- MODEL GRID ONLY HAS WATER POINTS, DONT CREATE SNOW FILE.'
540 print*,
'- NORMAL TERMINATION.'
541 call w3tage(
'SNOW2MDL')
545 allocate (lats_mdl(ijmdl))
546 allocate (lons_mdl(ijmdl))
547 allocate (ipts_mdl(ijmdl))
548 allocate (jpts_mdl(ijmdl))
553 if (lsmask_mdl(i,j) > 0.0)
then
555 lats_mdl(ij) = lats_mdl_temp(i,j)
556 lons_mdl(ij) = lons_mdl_temp(i,j)
563 deallocate (lats_mdl_temp, lons_mdl_temp)
581 if (
allocated(lsmask_mdl))
deallocate(lsmask_mdl)
582 if (
allocated(lats_mdl))
deallocate(lats_mdl)
583 if (
allocated(lons_mdl))
deallocate(lons_mdl)
584 if (
allocated(lonsperlat_mdl))
deallocate(lonsperlat_mdl)
585 if (
allocated(ipts_mdl))
deallocate(ipts_mdl)
586 if (
allocated(jpts_mdl))
deallocate(jpts_mdl)
subroutine grib2_null(gfld)
Nullify the grib2 gribfield pointers.
Read in data defining the model grid.
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.
subroutine grib2_free(gfld)
Deallocate the grib2 gribfield pointers.
subroutine model_grid_cleanup
Clean up allocatable arrays.
subroutine read_mdl_grid_info
Read mdl grid.
This module reads in data from the program's configuration namelist.
subroutine grib_check(file_name, isgrib)
Determine whether file is grib or not.