#!/bin/ksh
################################################################################
####  UNIX Script Documentation Block
#                      .                                             .
# Script name:         nam_smartinithi_off.sh
# Script description:  runs smartinit code over NDFD Hawaiian domain
#
# Author:        Geoff Manikin       Org: NP22         Date: 2007-08-06
#
# Script history log:
# 2007-08-06  Geoff Manikin
# 2011-05-10  Geoff Manikin - removed 1" SREF totals
#

set -x

let pcphr=ffhr+3
let pcphrl=ffhr+3
let pcphr12=pcphr-12
let pcphr6=pcphr-6
let pcphr3=pcphr-3

typeset -Z2 srefcyc 
typeset -Z2 gefscyc
typeset -Z2 pcphrl

cd $DATA 

if [ $ffhr -gt 0 ]; then
# get the sref precip fields that we need
cp $COMIN_SREF/sref.t${srefcyc}z.pgrb243.prob_3hrly SREFPROB

if [ ! -s SREFPROB ]; then
cp $COMIN_GEFS/${gefscyc}/sref.t${gefscyc}z.pgrb243.prob_3hrly SREFPROB
fi

$utilexec/grbindex SREFPROB SREFPROBI

# 3-hr prob of pcp > 0.01
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 64 64 0 0"| grep "0 1 $pcphr3 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp1

# 3-hr prob of pcp > 0.05
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 20 81 236"| grep "0 1 $pcphr3 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp2

# 3-hr prob of pcp > 0.10
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 40 163 215"| grep "0 1 $pcphr3 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp3

# 3-hr prob of pcp > 0.25
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 101 153 154"| grep "0 1 $pcphr3 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp4

# 3-hr prob of pcp > 0.50
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 203 51 51"| grep "0 1 $pcphr3 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp5

if [ $ffhr -gt 5 ]; then
# 6-hr prob of pcp > 0.01
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 64 64 0 0"| grep "0 1 $pcphr6 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp6

# 6-hr prob of pcp > 0.05
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 20 81 236"| grep "0 1 $pcphr6 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp7

# 6-hr prob of pcp > 0.10
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 40 163 215"| grep "0 1 $pcphr6 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp8

# 6-hr prob of pcp > 0.25
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 101 153 154"| grep "0 1 $pcphr6 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp9

# 6-hr prob of pcp > 0.50
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 203 51 51"| grep "0 1 $pcphr6 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp10
fi

if [ $ffhr -gt 11 ]; then
# 12-hr prob of pcp > 0.01
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 64 64 0 0"| grep "0 1 $pcphr12 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp11

# 12-hr prob of pcp > 0.05
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 20 81 236"| grep "0 1 $pcphr12 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp12

# 12-hr prob of pcp > 0.10
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 40 163 215"| grep "0 1 $pcphr12 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp13

# 12-hr prob of pcp > 0.25
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 101 153 154"| grep "0 1 $pcphr12 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp14

# 12-hr prob of pcp > 0.50
$utilexec/wgrib -PDS10 SREFPROB |grep "2 0 0 0 0 65 203 51 51"| grep "0 1 $pcphr12 $pcphr 4"|$utilexec/wgrib -i -grib -o dump SREFPROB
mv dump srefpcp15
fi

if [ $ffhr -gt 11 ]; then
cat srefpcp1 srefpcp2 srefpcp3 srefpcp4 srefpcp5 srefpcp6 srefpcp7 srefpcp8 srefpcp9 srefpcp10 srefpcp11 srefpcp12 srefpcp13 srefpcp14 srefpcp15 > srefallpcp
elif [ $ffhr -gt 5 ]; then
cat srefpcp1 srefpcp2 srefpcp3 srefpcp4 srefpcp5 srefpcp6 srefpcp7 srefpcp8 srefpcp9 srefpcp10 > srefallpcp
else
cat srefpcp1 srefpcp2 srefpcp3 srefpcp4 srefpcp5 > srefallpcp
fi

$utilexec/copygb -g "196" -x srefallpcp srefpcphi_${SREF_PDY}${srefcyc}f0${pcphrl}
$utilexec/grbindex srefpcphi_${SREF_PDY}${srefcyc}f0${pcphrl} srefpcphii_${SREF_PDY}${srefcyc}f0${pcphrl}
fi

let ffhr1=ffhr-1
let ffhr2=ffhr-2

if [ $ffhr -gt 0 ]; then
hours="${ffhr2} ${ffhr1} ${ffhr}"
else
hours="00"
fi

for fhr in $hours; do

let fhr1=fhr-1
let fhr2=fhr-2
let fhr3=fhr-3
let fhr6=fhr-6
let fhr9=fhr-9
let check=fhr%3
let check6=fhr%6

typeset -Z2 fhr1
typeset -Z2 fhr2
typeset -Z2 fhr3
typeset -Z2 fhr6
typeset -Z2 fhr9
typeset -Z2 fhr

cp $COMIN/nam.t${cyc}z.bgrd3d${fhr}.tm00 WRFPRS${fhr}.tm00
$utilexec/grbindex WRFPRS${fhr}.tm00 WRFPRS${fhr}i.tm00
cp $PARMnam/nam_masterhi.ctl master${fhr}.ctl

# if the forecast hour is valid at 00/12Z, we need to make 12-hr
#  accumulations.

if [ $fhr -eq 18 -o $fhr -eq 30 -o $fhr -eq 42 -o $fhr -eq 54 -o \
       $fhr -eq 66 -o $fhr -eq 78 ] ; then
cp $COMIN/nam.t${cyc}z.bgrd3d${fhr3}.tm00 WRFPRS${fhr3}.tm00
$utilexec/grbindex WRFPRS${fhr3}.tm00 WRFPRS${fhr3}i.tm00
cp $COMIN/nam.t${cyc}z.bgrd3d${fhr6}.tm00 WRFPRS${fhr6}.tm00
$utilexec/grbindex WRFPRS${fhr6}.tm00 WRFPRS${fhr6}i.tm00
cp $COMIN/nam.t${cyc}z.bgrd3d${fhr9}.tm00 WRFPRS${fhr9}.tm00
$utilexec/grbindex WRFPRS${fhr9}.tm00 WRFPRS${fhr9}i.tm00

    export pgm=nam_smartaddprecip12;. prep_step
    export XLFUNIT_13="WRFPRS${fhr9}.tm00"
    export XLFUNIT_14="WRFPRS${fhr9}i.tm00"
    export XLFUNIT_15="WRFPRS${fhr6}.tm00"
    export XLFUNIT_16="WRFPRS${fhr6}i.tm00"
    export XLFUNIT_17="WRFPRS${fhr3}.tm00"
    export XLFUNIT_18="WRFPRS${fhr3}i.tm00"
    export XLFUNIT_19="WRFPRS${fhr}.tm00"
    export XLFUNIT_20="WRFPRS${fhr}i.tm00"
    export XLFUNIT_50="12precip.${fhr}"
    export XLFUNIT_51="12cprecip.${fhr}"
    export XLFUNIT_52="12snow.${fhr}"
    $EXECnam/nam_smartaddprecip12 <<EOF > addprecip12.out
$fhr9 $fhr6 $fhr3 $fhr
EOF
export err=$?;err_chk

grid="255 1 321 225 18067 -161626 128 23082 -153969 20000 0 64 2500 2500"
$utilexec/copygb -g "$grid" -i3 -x 12precip.${fhr} 12precip
$utilexec/grbindex 12precip 12precipi
$utilexec/copygb -g "$grid" -i3 -x 12snow.${fhr} 12snow
$utilexec/grbindex 12snow 12snowi
fi

# at all 6-hour intervals, we need 6 hour buckets as well
if [ $check6 -eq 0 -a $fhr -ne 0 ] ; then
 echo 'need 6-hr buckets'
cp $COMIN/nam.t${cyc}z.bgrd3d${fhr3}.tm00 WRFPRS${fhr3}.tm00
$utilexec/grbindex WRFPRS${fhr}.tm00 WRFPRS${fhr}i.tm00
$utilexec/grbindex WRFPRS${fhr3}.tm00 WRFPRS${fhr3}i.tm00

    export pgm=nam_smartaddprecip6;. prep_step 
    export XLFUNIT_13="WRFPRS${fhr3}.tm00"
    export XLFUNIT_14="WRFPRS${fhr3}i.tm00"
    export XLFUNIT_15="WRFPRS${fhr}.tm00"
    export XLFUNIT_16="WRFPRS${fhr}i.tm00"
    export XLFUNIT_50="6precip.${fhr}"
    export XLFUNIT_51="6cprecip.${fhr}"
    export XLFUNIT_52="6snow.${fhr}"
    $EXECnam/nam_smartaddprecip6 <<EOF > addprecip6.out
$fhr3 $fhr
EOF
export err=$?;err_chk

grid="255 1 321 225 18067 -161626 128 23082 -153969 20000 0 64 2500 2500"
$utilexec/copygb -g "$grid" -i3 -x 6precip.${fhr} 6precip
$utilexec/grbindex 6precip 6precipi
$utilexec/copygb -g "$grid" -i3 -x 6snow.${fhr} 6snow
$utilexec/grbindex 6snow 6snowi
fi

cat >input${fhr}.prd <<EOF5
WRFPRS${fhr}.tm00
EOF5

export pgm=nam_prdgen;. prep_step 
ln -sf master${fhr}.ctl                 fort.10
ln -sf $FIXnam/nam_wgt_196         fort.21
ln -sf $PARMnam/nam_kwbx.tbl       fort.41
ln -sf $PARMnam/nam_time.tbl       fort.42
ln -sf $PARMnam/nam_parm.tbl       fort.43
ln -sf $PARMnam/nam_grid.tbl       fort.44
ln -sf $PARMnam/nam_levl.tbl       fort.45

$EXECnam/nam_prdgen < input${fhr}.prd > prdgen.out${fhr}
export err=$?;err_chk

cp /com/date/t${cyc}z DATE

    mv mesohi.NDFD mesohi.NDFDf${fhr}
    $utilexec/grbindex mesohi.NDFDf${fhr} mesohi.NDFDif${fhr}

# at 12-hr times, we need to make 12-hr max/min temps
#   we also need 3 and 6-hr buckets

if [ $fhr -eq 18 -o $fhr -eq 30 -o $fhr -eq 42 -o $fhr -eq 54 -o \
       $fhr -eq 66 -o $fhr -eq 78 ] ; then
    cp srefpcphi_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCP
    cp srefpcphii_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCPi

    cp MAXMIN${fhr2}.tm00 MAXMIN2
    cp MAXMIN${fhr1}.tm00 MAXMIN1
    cp $COMOUT/nam.t${cyc}z.smarthi${fhr3}.tm00 MAXMIN3
    cp $COMOUT/nam.t${cyc}z.smarthi${fhr6}.tm00 MAXMIN4
    cp $COMOUT/nam.t${cyc}z.smarthi${fhr9}.tm00 MAXMIN5

    $utilexec/grbindex MAXMIN1 MAXMIN1i
    $utilexec/grbindex MAXMIN2 MAXMIN2i
    $utilexec/grbindex MAXMIN3 MAXMIN3i
    $utilexec/grbindex MAXMIN4 MAXMIN4i
    $utilexec/grbindex MAXMIN5 MAXMIN5i

    export pgm=nam_smartinithi;. prep_step
    export XLFUNIT_11="mesohi.NDFDf${fhr}"
    export XLFUNIT_12="mesohi.NDFDif${fhr}"
    export XLFUNIT_13="SREFPCP"
    export XLFUNIT_14="SREFPCPi"
    export XLFUNIT_15="6precip"
    export XLFUNIT_16="6precipi"
    export XLFUNIT_17="6snow"
    export XLFUNIT_18="6snowi"
    export XLFUNIT_19="12precip"
    export XLFUNIT_20="12precipi"
    export XLFUNIT_21="MAXMIN1"
    export XLFUNIT_22="MAXMIN2"
    export XLFUNIT_23="MAXMIN3"
    export XLFUNIT_24="MAXMIN4"
    export XLFUNIT_25="MAXMIN5"
    export XLFUNIT_26="MAXMIN1i"
    export XLFUNIT_27="MAXMIN2i"
    export XLFUNIT_28="MAXMIN3i"
    export XLFUNIT_29="MAXMIN4i"
    export XLFUNIT_30="MAXMIN5i"
    export XLFUNIT_46="$FIXnam/nam_smartmaskhi.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskhi.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopohi.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopohi.grbi"
    $EXECnam/nam_smartinithi <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
#bsm - add processing for conversion to grib2
$utilexec/cnvgrib -g12 -p40 MESOHI${fhr}.tm00 nam.t${cyc}z.smarthi${fhr}.tm00.grib2
# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

 export XLFUNIT_11=nam.t${cyc}z.smarthi${fhr}.tm00.grib2
 export XLFUNIT_31=" "
 export XLFUNIT_51=grib2.t${cyc}z.smarthif${fhr}

 $utilexec/tocgrib2 <$UTILparm/grib2_awpnamsmarthiofff${fhr}.196 >> $pgmout 2> errfile
 echo " error from tocgrib=",$err

mv MESOHI${fhr}.tm00 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00
mv nam.t${cyc}z.smarthi${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
mv grib2.t${cyc}z.smarthif${fhr} $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
if [ $SENDDBN = YES ] #bsm 25 feb 2008 - added code for awips alerts
 then
  $DBNROOT/bin/dbn_alert NTC_LOW SMARTHI $job $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
fi

if [ $SENDDBN_GB2 = YES ]
 then
  $DBNROOT/bin/dbn_alert MODEL NAM_SMARTHI_GB2 $job $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
fi

elif [ $check6 -eq 0 -a $fhr -ne 0 ]; then

    cp srefpcphi_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCP
    cp srefpcphii_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCPi
    cp MAXMIN${fhr2}.tm00 MAXMIN2
    cp MAXMIN${fhr1}.tm00 MAXMIN1

    $utilexec/grbindex MAXMIN2 MAXMIN2i
    $utilexec/grbindex MAXMIN1 MAXMIN1i

    export pgm=nam_smartinithi;. prep_step
    export XLFUNIT_11="mesohi.NDFDf${fhr}"
    export XLFUNIT_12="mesohi.NDFDif${fhr}"
    export XLFUNIT_13="SREFPCP"
    export XLFUNIT_14="SREFPCPi"
    export XLFUNIT_15="6precip"
    export XLFUNIT_16="6precipi"
    export XLFUNIT_17="6snow"
    export XLFUNIT_18="6snowi"
    export XLFUNIT_19="MAXMIN2"
    export XLFUNIT_20="MAXMIN1"
    export XLFUNIT_21="MAXMIN2i"
    export XLFUNIT_22="MAXMIN1i"
    export XLFUNIT_46="$FIXnam/nam_smartmaskhi.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskhi.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopohi.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopohi.grbi"
    $EXECnam/nam_smartinithi <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
#bsm - add processing for conversion to grib2
$utilexec/cnvgrib -g12 -p40 MESOHI${fhr}.tm00 nam.t${cyc}z.smarthi${fhr}.tm00.grib2
# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

 export XLFUNIT_11=nam.t${cyc}z.smarthi${fhr}.tm00.grib2
 export XLFUNIT_31=" "
 export XLFUNIT_51=grib2.t${cyc}z.smarthif${fhr}

 $utilexec/tocgrib2 <$UTILparm/grib2_awpnamsmarthiofff${fhr}.196 >> $pgmout 2> errfile
 echo " error from tocgrib=",$err

mv MESOHI${fhr}.tm00 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00
mv nam.t${cyc}z.smarthi${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
mv grib2.t${cyc}z.smarthif${fhr} $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
if [ $SENDDBN = YES ] #bsm 25 feb 2008 - added code for awips alerts
 then
  $DBNROOT/bin/dbn_alert NTC_LOW SMARTHI $job $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
fi

if [ $SENDDBN_GB2 = YES ]
 then
  $DBNROOT/bin/dbn_alert MODEL NAM_SMARTHI_GB2 $job $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
fi

# for all forecast hours divisible by 3,  we need
#    3-hr buckets and max/min temp data for the previous 2 hours

elif [ $check -eq 0 -a $fhr -ne 0 ]; then

    cp srefpcphi_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCP
    cp srefpcphii_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCPi
    cp MAXMIN${fhr2}.tm00 MAXMIN2
    cp MAXMIN${fhr1}.tm00 MAXMIN1

   $utilexec/grbindex MAXMIN2 MAXMIN2i
    $utilexec/grbindex MAXMIN1 MAXMIN1i

    export pgm=nam_smartinithi;. prep_step
    export XLFUNIT_11="mesohi.NDFDf${fhr}"
    export XLFUNIT_12="mesohi.NDFDif${fhr}"
    export XLFUNIT_13="SREFPCP"
    export XLFUNIT_14="SREFPCPi"
    export XLFUNIT_15="MAXMIN2"
    export XLFUNIT_16="MAXMIN1"
    export XLFUNIT_17="MAXMIN2i"
    export XLFUNIT_18="MAXMIN1i"
    export XLFUNIT_46="$FIXnam/nam_smartmaskhi.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskhi.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopohi.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopohi.grbi"
    $EXECnam/nam_smartinithi <<EOF > smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
#bsm - add processing for conversion to grib2 and awips files
$utilexec/cnvgrib -g12 -p40 MESOHI${fhr}.tm00 nam.t${cyc}z.smarthi${fhr}.tm00.grib2

# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

 export XLFUNIT_11=nam.t${cyc}z.smarthi${fhr}.tm00.grib2
 export XLFUNIT_31=" "
 export XLFUNIT_51=grib2.t${cyc}z.smarthif${fhr}

 $utilexec/tocgrib2 <$UTILparm/grib2_awpnamsmarthiofff${fhr}.196 >> $pgmout 2> errfile
 echo " error from tocgrib=",$err

mv MESOHI${fhr}.tm00 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00
mv nam.t${cyc}z.smarthi${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
mv grib2.t${cyc}z.smarthif${fhr} $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
if [ $SENDDBN = YES ] #bsm 25 feb 2008 - added code for awips alerts
 then
  $DBNROOT/bin/dbn_alert NTC_LOW SMARTHI $job $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
fi

if [ $SENDDBN_GB2 = YES ]
 then
  $DBNROOT/bin/dbn_alert MODEL NAM_SMARTHI_GB2 $job $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
fi

#  for all "in-between" forecast hours (13,14,16....), we don't need
#    any special data, but we do need to write out a grib file
# for hours 1,2,4,5,7,8 for Hawaiian RTMA first guess
else 
    export pgm=nam_smartinithi;. prep_step
    export XLFUNIT_11="mesohi.NDFDf${fhr}"
    export XLFUNIT_12="mesohi.NDFDif${fhr}"
    export XLFUNIT_46="$FIXnam/nam_smartmaskhi.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskhi.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopohi.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopohi.grbi"
    $EXECnam/nam_smartinithi <<EOF > smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
if [ $fhr -lt 9 ] ; then 
 #bsm - add processing for conversion to grib2
 $utilexec/cnvgrib -g12 -p40 MESOHI${fhr}.tm00 nam.t${cyc}z.smarthi${fhr}.tm00.grib2
# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

 export XLFUNIT_11=nam.t${cyc}z.smarthi${fhr}.tm00.grib2
 export XLFUNIT_31=" "
 export XLFUNIT_51=grib2.t${cyc}z.smarthif${fhr}

 $utilexec/tocgrib2 <$UTILparm/grib2_awpnamsmarthiofff${fhr}.196 >> $pgmout 2> errfile
 echo " error from tocgrib=",$err

mv MESOHI${fhr}.tm00 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00
mv nam.t${cyc}z.smarthi${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
mv grib2.t${cyc}z.smarthif${fhr} $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
if [ $SENDDBN = YES ] #bsm 25 feb 2008 - added code for awips alerts
 then
  $DBNROOT/bin/dbn_alert NTC_LOW SMARTHI $job $pcom/grib2.awpnamsmart.hi${fhr}_awips_f${fhr}_${cyc}
fi

if [ $SENDDBN_GB2 = YES ]
 then
  $DBNROOT/bin/dbn_alert MODEL NAM_SMARTHI_GB2 $job $COMOUT/nam.t${cyc}z.smarthi${fhr}.tm00.grib2
fi

fi

fi
done
exit
