#!/bin/csh
source $NAWIPS/Gemenviron
echo Script Name: "$0"
echo Total Number of Arguments Passed: "$#"
if ( $# != 2 ) then
echo not two arguments, leaving
exit 1
endif
## initializing variables
set res="$1"
set hhh="$2"
set grib2_in="gfs.t00z.pgrb2.$res.f$hhh"
set grid_in="gfs.t00z.pgrob2.$res.f$hhh.grd"
set grid_2p50_out="gfs.t00z.pgrb2.2p50.f$hhh.grd"
set grid_2p50_template="gfs_25deg_12hr.grd"
## make sure files exist
if ( ! -f $grib2_in ) then
echo "file($grib2_in) does not exist, exiting"
exit 1
endif
if ( ! -f $grid_2p50_template ) then
echo "file($grid_2p50_template) does not exist, exiting"
exit 1
endif
## cleanup files to be created if they exist
if ( -f $grid_in ) then
echo "removing residual grid file($grid_in)"
rm "$grid_in"
endif
if ( -f $grid_2p50_out ) then
echo "removing residual grid_file($grid_2p50_out)"
rm "$grid_2p50_out"
endif
echo "using nagrib2 to convert $grib2_in to $grid_in"
nagrib2 << NAGRIB2_EOF
GBFILE=$grib2_in
GDOUTF=$grid_in
PROJ=
GRDAREA=
KXKY=
MAXGRD=1500
CPYFIL=gds
GAREA=grid
OUTPUT=n
G2TBLS=
G2DIAG=
r
e
NAGRIB2_EOF
gpend
rm *nts
echo "using gdcfil to create $grid_2p50_out"
gdcfil << GDCFIL_EOF
PROJ=
GRDAREA=
KXKY=
MAXGRD=1500
ANLYSS=
GDOUTF=$grid_2p50_out
CPYFIL=$grid_2p50_template
r
e
GDCFIL_EOF
gpend
rm *.nts
echo "using gdbiint to convert $grid_in to $grid_2p50_out"
gdbiint << GDBIINT_EOF
GDFILE=$grid_in
GDOUTF=$grid_2p50_out
GFUNC=
GLEVEL=
GVCORD=
GDATTIM=
GDNUM=ALL
r
e
GDBIINT_EOF
gpend
#rm *.nts