162 integer :: i, j, ii, jj, ij
163 integer :: ijmdl2, istart, iend, imid, iii
164 integer,
allocatable :: idum(:,:)
165 integer :: int_opt, ipopt(20)
166 integer :: kgds_mdl_tmp(200)
167 integer :: no, ibo, iret, nret
169 logical*1,
allocatable :: bitmap_mdl(:)
173 real,
allocatable :: lsmask_1d(:)
174 real,
allocatable :: snow_cvr_mdl_1d(:)
175 real,
allocatable :: snow_dep_mdl_tmp(:)
176 real :: sumc, sumd, x1, r, fraction, gridis, gridie
177 real,
parameter :: undefined_value = -999.
187 print*,
"- FATAL ERROR: MUST SELECT EITHER AFWA OR AUTOSNOW DATA FOR MODEL GRID WITH SH POINTS." 188 call w3tage(
'SNOW2MDL')
209 print*,
"- FATAL ERROR: MUST SELECT EITHER NESDIS/IMS OR AFWA DATA FOR MODEL GRID WITH NH POINTS." 210 call w3tage(
'SNOW2MDL')
233 print*,
"- INTERPOLATE NH NESDIS/IMS DATA TO MODEL GRID USING BUDGET METHOD." 239 kgds_mdl_tmp(1) = kgds_mdl_tmp(1) - 255
243 print*,
"- INTERPOLATE NH NESDIS/IMS DATA TO MODEL GRID USING NEIGHBOR METHOD." 251 allocate (snow_cvr_mdl_1d(
ijmdl))
252 snow_cvr_mdl_1d = 0.0
254 allocate (bitmap_mdl(
ijmdl))
258 call ipolates(int_opt, ipopt,
kgds_nesdis, kgds_mdl_tmp, &
262 snow_cvr_mdl_1d, iret)
267 print*,
"- FATAL ERROR: IN INTERPOLATION ROUTINE. IRET IS: ", iret
268 call w3tage(
'SNOW2MDL')
282 if (.not. bitmap_mdl(ij))
then 284 snow_cvr_mdl_1d(ij) = 0.0
286 call gdswzd(
kgds_nesdis,-1,1,undefined_value,gridi,gridj, &
289 print*,
"- WARNING: MODEL POINT OUTSIDE NESDIS/IMS GRID: ",
ipts_mdl(ij),
jpts_mdl(ij)
290 snow_cvr_mdl_1d(ij) = 0.0
295 snow_cvr_mdl_1d(ij) = 100.0
297 snow_cvr_mdl_1d(ij) = 0.0
305 deallocate (bitmap_mdl)
322 print*,
"- INTERPOLATE GLOBAL AFWA DATA TO MODEL GRID USING BUDGET METHOD." 325 ipopt(20) = nint(100.0 /
afwa_res) + 1
327 kgds_mdl_tmp(1) = kgds_mdl_tmp(1) - 255
331 print*,
"- INTERPOLATE GLOBAL AFWA DATA TO MODEL GRID USING NEIGHBOR METHOD." 332 ipopt(1) = nint(100.0 /
afwa_res) + 1
339 allocate (snow_dep_mdl_tmp(
ijmdl))
340 snow_dep_mdl_tmp = 0.0
342 allocate (bitmap_mdl(
ijmdl))
349 snow_dep_mdl_tmp, iret)
354 print*,
"- FATAL ERROR IN INTERPOLATION ROUTINE. IRET IS: ", iret
355 call w3tage(
'SNOW2MDL')
367 if (.not. bitmap_mdl(ij))
then 371 snow_dep_mdl_tmp(ij) = 0.0
376 deallocate(bitmap_mdl)
393 print*,
"- INTERPOLATE NH AFWA DATA TO MODEL GRID USING BUDGET METHOD." 396 ipopt(20) = nint(100.0 /
afwa_res) + 1
398 kgds_mdl_tmp(1) = kgds_mdl_tmp(1) - 255
402 print*,
"- INTERPOLATE NH AFWA DATA TO MODEL GRID USING NEIGHBOR METHOD." 403 ipopt(1) = nint(100.0 /
afwa_res) + 1
410 allocate (snow_dep_mdl_tmp(
ijmdl))
411 snow_dep_mdl_tmp = 0.0
413 allocate (bitmap_mdl(
ijmdl))
416 call ipolates(int_opt, ipopt,
kgds_afwa_nh, kgds_mdl_tmp, &
420 snow_dep_mdl_tmp, iret)
425 print*,
"- FATAL ERROR IN INTERPOLATION ROUTINE. IRET IS: ", iret
426 call w3tage(
'SNOW2MDL')
439 if (.not. bitmap_mdl(ij))
then 443 snow_dep_mdl_tmp(ij) = 0.0
449 deallocate(bitmap_mdl)
464 print*,
"- BLEND NESDIS/IMS AND AFWA DATA IN NH." 474 deallocate (snow_cvr_mdl_1d)
476 print*,
"- BLEND NESDIS/IMS AND AFWA DATA IN NH." 486 deallocate (snow_cvr_mdl_1d)
487 deallocate (snow_dep_mdl_tmp)
489 print*,
"- SET DEPTH/COVER FROM AFWA DATA IN NH." 492 if (snow_dep_mdl_tmp(ij) > 0.0)
then 499 print*,
"- SET DEPTH/COVER FROM AFWA DATA IN NH." 502 if (snow_dep_mdl_tmp(ij) > 0.0)
then 508 deallocate (snow_dep_mdl_tmp)
510 print*,
"- SET DEPTH/COVER FROM NESDIS/IMS DATA IN NH." 519 deallocate (snow_cvr_mdl_1d)
530 print*,
"- INTERPOLATE AUTOSNOW DATA TO MODEL GRID USING BUDGET METHOD." 536 kgds_mdl_tmp(1) = kgds_mdl_tmp(1) - 255
540 print*,
"- INTERPOLATE AUTOSNOW DATA TO MODEL GRID USING NEIGHBOR METHOD." 548 allocate (snow_cvr_mdl_1d(
ijmdl))
549 snow_cvr_mdl_1d = 0.0
551 allocate (bitmap_mdl(
ijmdl))
559 snow_cvr_mdl_1d, iret)
564 print*,
"- FATAL ERROR IN INTERPOLATION ROUTINE. IRET IS: ", iret
565 call w3tage(
'SNOW2MDL')
576 if (.not. bitmap_mdl(ij))
then 578 snow_cvr_mdl_1d(ij) = 0.0
580 snow_cvr_mdl_1d(ij) = 100.0
586 deallocate (bitmap_mdl)
603 print*,
"- INTERPOLATE SH AFWA DATA TO MODEL GRID USING BUDGET METHOD." 606 ipopt(20) = nint(100.0 /
afwa_res) + 1
608 kgds_mdl_tmp(1) = kgds_mdl_tmp(1) - 255
612 print*,
"- INTERPOLATE SH AFWA DATA TO MODEL GRID USING NEIGHBOR METHOD." 613 ipopt(1) = nint(100.0 /
afwa_res) + 1
620 allocate (snow_dep_mdl_tmp(
ijmdl))
621 snow_dep_mdl_tmp = 0.0
623 allocate (bitmap_mdl(
ijmdl))
626 call ipolates(int_opt, ipopt,
kgds_afwa_sh, kgds_mdl_tmp, &
630 snow_dep_mdl_tmp, iret)
633 print*,
"- FATAL ERROR IN INTERPOLATION ROUTINE. IRET IS: ", iret
634 call w3tage(
'SNOW2MDL')
647 if (.not. bitmap_mdl(ij))
then 651 snow_dep_mdl_tmp(ij) = 0.0
657 deallocate(bitmap_mdl)
667 print*,
"- BLEND AUTOSNOW AND AFWA DATA IN SH." 677 deallocate (snow_cvr_mdl_1d)
678 deallocate (snow_dep_mdl_tmp)
680 print*,
"- SET DEPTH/COVER FROM AFWA DATA IN SH." 683 if (snow_dep_mdl_tmp(ij) > 0.0)
then 689 deallocate (snow_dep_mdl_tmp)
691 print*,
"- SET DEPTH/COVER FROM AUTOSNOW IN SH." 700 deallocate (snow_cvr_mdl_1d)
712 allocate (snow_cvr_mdl_1d(ijmdl2))
713 allocate (lsmask_1d(ijmdl2))
714 allocate (snow_dep_mdl_tmp(ijmdl2))
717 snow_cvr_mdl_1d = 0.0
718 snow_dep_mdl_tmp = 0.0
738 if (ii == istart)
then 739 fraction = 0.5 - (gridis - float(istart))
740 elseif (ii == iend)
then 741 fraction = 0.5 + (gridie - float(iend))
745 if (fraction < 0.0001) cycle
747 if (iii < 1) iii =
imdl + iii
751 snow_cvr_mdl_1d(ij) = sumc / r
752 snow_dep_mdl_tmp(ij) = 0.0
769 deallocate(snow_cvr_mdl_1d)
771 deallocate(snow_dep_mdl_tmp)
781 print*,
"- OUTPUT SNOW ANALYSIS DATA IN GRIB2 FORMAT" 784 print*,
"- OUTPUT SNOW ANALYSIS DATA IN GRIB1 FORMAT" 814 character(len=1),
allocatable :: cgrib(:)
816 integer,
parameter :: numcoord = 0
818 integer :: coordlist(numcoord)
819 integer :: lugb, lcgrib, iret
821 integer :: listsec0(2)
822 integer :: listsec1(13)
823 integer :: ideflist, idefnum, ipdsnum, idrsnum
824 integer :: igdstmplen, ipdstmplen, idrstmplen
825 integer :: ipdstmpl(15)
826 integer,
allocatable :: igdstmpl(:), idrstmpl(:)
827 integer :: ngrdpts, ibmap, lengrib
829 logical*1,
allocatable :: bmap(:), bmap2d(:,:)
831 real,
allocatable :: fld(:)
839 allocate(igdstmpl(igdstmplen))
843 listsec0, listsec1, igds, ipdstmpl, ipdsnum, igdstmpl, &
844 igdstmplen, idefnum, ideflist, ngrdpts)
847 allocate(cgrib(lcgrib))
855 print*,
"- CREATE SECTIONS 0 AND 1" 856 call gribcreate(cgrib,lcgrib,listsec0,listsec1,iret)
857 if (iret /= 0)
goto 900
863 print*,
"- CREATE SECTION 3" 864 call addgrid(cgrib,lcgrib,igds,igdstmpl,igdstmplen, &
865 ideflist,idefnum,iret)
866 if (iret /= 0)
goto 900
874 allocate (idrstmpl(idrstmplen))
878 allocate(fld(ngrdpts))
885 allocate(bmap(ngrdpts))
886 bmap = reshape(bmap2d, (/
imdl*
jmdl/) )
899 print*,
"- CREATE SECTIONS 4 AND 5 FOR SNOW COVER" 900 call addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, &
901 coordlist,numcoord,idrsnum,idrstmpl, &
902 idrstmplen,fld,ngrdpts,ibmap,bmap,iret)
903 if (iret /= 0)
goto 900
928 print*,
"- CREATE SECTIONS 4 AND 5 FOR SNOW DEPTH" 929 call addfield(cgrib,lcgrib,ipdsnum,ipdstmpl,ipdstmplen, &
930 coordlist,numcoord,idrsnum,idrstmpl, &
931 idrstmplen,fld,ngrdpts,ibmap,bmap,iret)
932 if (iret /= 0)
goto 900
940 call gribend(cgrib,lcgrib,lengrib,iret)
941 if (iret /= 0)
goto 900
952 print*,
'- FATAL ERROR: BAD OPEN OF OUTPUT GRIB FILE. IRET IS ', iret
953 call w3tage(
'SNOW2MDL')
957 print*,
'- WRITE OUTPUT GRIB FILE.' 958 call wryte(lugb, lengrib, cgrib)
960 call baclose (lugb, iret)
962 deallocate(fld, bmap, idrstmpl, igdstmpl, cgrib)
967 print*,
'- FATAL ERROR CREATING GRIB2 MESSAGE. IRET IS ', iret
968 call w3tage(
'SNOW2MDL')
993 integer,
parameter :: lugb = 64
996 logical*1 :: lbms(imdl,jmdl)
1043 print*,
'- FATAL ERROR OPENING OUTPUT GRIB FILE. IRET IS ', iret
1044 call w3tage(
'SNOW2MDL')
1049 call putgb (lugb, (imdl*jmdl), kpds,
kgds_mdl, lbms, &
1053 print*,
'- FATAL ERROR WRITING OUTPUT GRIB FILE. IRET IS ', iret
1054 call w3tage(
'SNOW2MDL')
1069 call putgb (lugb, (imdl*jmdl), kpds,
kgds_mdl, lbms, &
1073 print*,
'- FATAL ERROR WRITING OUTPUT GRIB FILE. IRET IS ', iret
1074 call w3tage(
'SNOW2MDL')
1078 88
call baclose(lugb, iret)
1100 subroutine uninterpred(iord,kmsk,fi,f,lonl,latd,len,lonsperlat)
1104 integer,
intent(in) :: len
1105 integer,
intent(in) :: iord
1106 integer,
intent(in) :: lonl
1107 integer,
intent(in) :: latd
1108 integer,
intent(in) :: lonsperlat(latd/2)
1109 integer,
intent(in) :: kmsk(lonl*latd)
1110 integer :: j,lons,jj,latd2,ii,i
1112 real,
intent(in) :: fi(len)
1113 real,
intent(out) :: f(lonl,latd)
1121 if (j .gt. latd2) jj = latd - j + 1
1124 if(lons.ne.lonl)
then 1125 call intlon(iord,1,1,lons,lonl,kmsk(ii),fi(ii),f(1,j))
1151 subroutine intlon(iord,imon,imsk,m1,m2,k1,f1,f2)
1155 integer,
intent(in) :: iord,imon,imsk,m1,m2
1156 integer,
intent(in) :: k1(m1)
1157 integer :: i2,in,il,ir
1159 real,
intent(in) :: f1(m1)
1160 real,
intent(out) :: f2(m2)
1168 if(iord.eq.2.and.(imsk.eq.0.or.k1(il).eq.k1(ir)))
then 1169 f2(i2)=f1(il)*(il-x1)+f1(ir)*(x1-il+1)
1171 in=mod(nint(x1),m1)+1
real, dimension(:,:), allocatable snow_dep_afwa_sh
Southern hemisphere afwa snow depth.
This module reads in data from the program's configuration namelist.
logical bad_afwa_sh
When true, the southern hemisphere afwa data failed its quality control check.
real, dimension(:,:), allocatable snow_cvr_mdl
snow cover on model grid in percent
integer, dimension(200) kgds_afwa_nh
grib1 grid description section for northern hemisphere 16th mesh afwa data.
integer mesh_nesdis
nesdis/ims data is 96th mesh (or bediant)
real, public snow_cvr_threshold
if percent coverage according to nesdis/ims or autosnow exceeds this value, then non-zero snow depth ...
real, public min_snow_depth
minimum snow depth in meters at model points with coverage exceeding threshold.
real lonlast
Corner point longitude (imdl,jmdl) of model grid.
subroutine init_grib2(century, year, month, day, hour, kgds, lat11, latlast, lon11, lonlast, listsec0, listsec1, igds, ipdstmpl, ipdsnum, igdstmpl, igdstmplen, idefnum, ideflist, ngrdpts)
Initialize grib2 arrays required by the ncep g2 library according to grib1 gds information.
subroutine grib2_check(kgds, igdstmplen)
Determine length of grib2 gds template array, which is a function of the map projection.
real, dimension(:,:), allocatable snow_cvr_autosnow
autosnow snow cover flag (0-no, 100-yes)
integer *1, dimension(:,:), allocatable sea_ice_nesdis
nesdis/ims sea ice flag (0-open water, 1-ice)
real, dimension(:,:), allocatable snow_dep_afwa_global
The global afwa snow depth.
integer, public grib_century
date of the final merged snow product that will be placed in grib header.
integer jmdl
j-dimension of model grid
integer, dimension(200) kgds_nesdis
nesdis/ims grid description section (grib section 2)
logical *1, dimension(:,:), allocatable bitmap_nesdis
nesdis data grib bitmap (false-non land, true-land).
integer, dimension(:), allocatable lonsperlat_mdl
Number of longitudes (i-points) for each latitude (row).
logical thinned
When true, global grids will run thinned (number of i points decrease toward pole) ...
real afwa_res
Resolution of afwa data in km.
real, dimension(:), allocatable lats_mdl
Latitudes of model grid points.
integer, dimension(200) kgds_afwa_global
grib1 grid description section for global afwa data.
Read in data defining the model grid.
integer, dimension(200) kgds_autosnow
autosnow grid description section (grib section 2)
integer jafwa
j-dimension of afwa grid
integer iautosnow
i-dimension of autosnow grid
Read and qc afwa, nesdis/ims and autosnow snow data.
integer iafwa
i-dimension of afwa 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 intlon(iord, imon, imsk, m1, m2, k1, f1, f2)
Convert data from the thinned (or reduced) to the full grid along a single row.
subroutine uninterpred(iord, kmsk, fi, f, lonl, latd, len, lonsperlat)
Fills out full grid using thinned grid data.
logical *1, dimension(:,:), allocatable bitmap_autosnow
autosnow data grib bitmap (false-non land, true-land).
real nesdis_res
Resolution of the nesdis data in km.
integer, public grib_month
date of the final merged snow product that will be placed in grib header.
logical *1, dimension(:,:), allocatable bitmap_afwa_sh
The southern hemisphere afwa data grib bitmap.
real, dimension(:), allocatable lons_mdl
longitudes of model grid points
real, dimension(:,:), allocatable snow_dep_afwa_nh
Northern hemisphere afwa snow depth.
real resol_mdl
approximate model resolution in km.
logical use_sh_afwa
True if southern hemisphere afwa data to be used.
Interpolate snow data to model grid and grib the result.
subroutine write_grib2
Write grib2 snow cover and depth on the model grid.
integer inesdis
i-dimension of nesdis grid
integer imdl
i-dimension of model grid
integer, public grib_day
date of the final merged snow product that will be placed in grib header.
integer jautosnow
j-dimension of autosnow grid
real, public lat_threshold
equatorward of this latitude, model points with undefined cover or depth (because the interpolation r...
logical use_nh_afwa
True if northern hemisphere afwa data to be used.
logical use_nesdis
True if nesdis/ims data to be used.
logical, public output_grib2
when true, output model snow analysis is grib 2.
subroutine write_grib1
Write grib1 snow cover and depth on the model grid.
real lon11
Corner point longitude (1,1) of model grid.
integer ijmdl
total number of model land points
logical use_autosnow
True if autosnow data to be used.
logical *1, dimension(:,:), allocatable bitmap_afwa_global
The global afwa data grib bitmap.
character *200, public model_snow_file
path/name nesdis/ims snow cover
integer, dimension(:), allocatable jpts_mdl
j index of point on full grid
integer, dimension(200) kgds_mdl
holds grib gds info of model grid
integer, public grib_year
date of the final merged snow product that will be placed in grib header.
integer jnesdis
j-dimension of nesdis grid
real latlast
Corner point latitude (imdl,jmdl) of model grid.
integer, dimension(:), allocatable ipts_mdl
i index of point on full grid
integer, public grib_hour
date of the final merged snow product that will be placed in grib header.
logical bad_afwa_nh
When true, the northern hemisphere afwa data failed its quality control check.
integer, dimension(200) kgds_afwa_sh
grib1 grid description section for southern hemisphere 16th mesh afwa data.
real autosnow_res
Resolution of autosnow in km.
logical *1, dimension(:,:), allocatable bitmap_afwa_nh
The northern hemisphere afwa data grib bitmap.
real, dimension(:,:), allocatable snow_dep_mdl
snow depth on model grid in meters
integer grid_id_mdl
grib id of model grid, 4-gaussian, 203-egrid
logical use_global_afwa
True if global hemisphere afwa data to be used.
real lat11
Corner point latitude (1,1) of 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...
real, dimension(:,:), allocatable snow_cvr_nesdis
nesdis/ims snow cover flag (0-no, 100-yes)
subroutine, public interp
Interpolate snow data to model grid.