#!/bin/ksh
################################################################################
####  UNIX Script Documentation Block
#                      .                                             .
# Script name:         nam_smartinitaknest3_on.sh
# Script description:  runs smartinit code over NDFD 3 km Alaskan domain 
#
# Author:        Geoff Manikin       Org: NP22         Date: 2011-06-30
#
# Script history log:
# 2011-06-30  Geoff Manikin - adapted for AK nest 
#

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.pgrb216.prob_3hrly SREFPROB

if [ ! -s SREFPROB ]; then
cp $COMIN_GEFS/${gefscyc}/sref.t${gefscyc}z.pgrb216.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

grid="255 5 1649 1105 40530 181429 8 210000 2976 2976 0 64 0 25000 25000"
$utilexec/copygb -g "$grid" -x srefallpcp srefpcpak_${SREF_PDY}${srefcyc}f0${pcphrl}
$utilexec/grbindex srefpcpak_${SREF_PDY}${srefcyc}f0${pcphrl} srefpcpaki_${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 check=fhr%3
  let check6=fhr%6
  let fhr1=fhr-1
  let fhr2=fhr-2
  let fhr3=fhr-3
  let fhr6=fhr-6
  let fhr9=fhr-9 

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

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

# all nest files contain 3-hr precip accumulations
# if the forecast hour is valid at 06/18Z, we need to make 6-hr
#  accumulations.

if [ $check6 -eq 0 -a $fhr -ne 0 ] ; then
 echo 'need 6-hr buckets'

     cp $COMIN/nam.t${cyc}z.alaskanest.bsmart${fhr3}.tm00 WRFPRS${fhr3}.tm00
     $utilexec/grbindex WRFPRS${fhr3}.tm00 WRFPRS${fhr3}i.tm00

     export pgm=nam_smartaddprecip6_aknest;. 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_aknest <<EOF > makeprecip6.out
$fhr3 $fhr
EOF
export err=$?;err_chk

     $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

  # at 12-hr "on" times, we need 12-hour buckets as well

  if [ $fhr -eq 12 -o $fhr -eq 24 -o $fhr -eq 36 -o $fhr -eq 48 -o \
       $fhr -eq 60 ] ; then
  cp $COMIN/nam.t${cyc}z.alaskanest.bsmart${fhr6}.tm00 WRFPRS${fhr6}.tm00
  $utilexec/grbindex WRFPRS${fhr6}.tm00 WRFPRS${fhr6}i.tm00
  cp $COMIN/nam.t${cyc}z.alaskanest.bsmart${fhr9}.tm00 WRFPRS${fhr9}.tm00
  $utilexec/grbindex WRFPRS${fhr9}.tm00 WRFPRS${fhr9}i.tm00

    export pgm=nam_smartaddprecip12_aknest;. 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_aknest <<EOF >> makeprecip12.out
$fhr9 $fhr6 $fhr3 $fhr
EOF
export err=$?;err_chk

  $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

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_91_alaskanest    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 mesoak.NDFD mesoak.NDFDf${fhr}
  $utilexec/grbindex mesoak.NDFDf${fhr} mesoak.NDFDif${fhr}

 cp $FIXnam/nam_smarttopoak3.grb TOPONDFD
 cp $FIXnam/nam_smartmaskak3.grb LANDNDFD
 /nwprod/util/exec/grbindex TOPONDFD TOPONDFDi
 /nwprod/util/exec/grbindex LANDNDFD LANDNDFDi

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

  if [ $fhr -eq 12 -o $fhr -eq 24 -o $fhr -eq 36 -o $fhr -eq 48 -o \
       $fhr -eq 60 ] ; then
    cp srefpcpak_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCP
    cp srefpcpaki_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCPi

    cp MAXMIN${fhr2}.tm00 MAXMIN2
    cp MAXMIN${fhr1}.tm00 MAXMIN1
    cp $COMOUT/nam.t${cyc}z.smartak3${fhr3}.tm00 MAXMIN3
    cp $COMOUT/nam.t${cyc}z.smartak3${fhr6}.tm00 MAXMIN4
    cp $COMOUT/nam.t${cyc}z.smartak3${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_smartinitaknest3;. prep_step
    export XLFUNIT_11="mesoak.NDFDf${fhr}"
    export XLFUNIT_12="mesoak.NDFDif${fhr}"
    export XLFUNIT_13="SREFPCP"
    export XLFUNIT_14="SREFPCPi"
    export XLFUNIT_15="6precip"
    export XLFUNIT_16="6precipi"
    export XLFUNIT_17="12precip"
    export XLFUNIT_18="12precipi"
    export XLFUNIT_19="6snow"
    export XLFUNIT_20="6snowi"
    export XLFUNIT_21="12snow"
    export XLFUNIT_22="12snowi" 
    export XLFUNIT_23="MAXMIN1"
    export XLFUNIT_24="MAXMIN2"
    export XLFUNIT_25="MAXMIN3"
    export XLFUNIT_26="MAXMIN4"
    export XLFUNIT_27="MAXMIN5"
    export XLFUNIT_28="MAXMIN1i"
    export XLFUNIT_29="MAXMIN2i"
    export XLFUNIT_30="MAXMIN3i"
    export XLFUNIT_31="MAXMIN4i"
    export XLFUNIT_32="MAXMIN5i"
    export XLFUNIT_46="TOPONDFD"
    export XLFUNIT_47="TOPONDFDi"
    export XLFUNIT_48="LANDNDFD"
    export XLFUNIT_49="LANDNDFDi"
$EXECnam/nam_smartinitaknest3 <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
$utilexec/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak3${fhr}.tm00.grib2

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

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

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

mv MESOAK${fhr}.tm00 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00
mv nam.t${cyc}z.smartak3${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00.grib2
mv grib2.t${cyc}z.smartak3f${fhr} $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
if [ $SENDDBN = YES ] 
 then
  $DBNROOT/bin/dbn_alert NTC_LOW SMARTAK3 $job $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
fi

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

  # for all forecast hours divisible by 3 except for (3,15,27....), we need
  #    3-hr buckets and max/min temp data for the previous 2 hours

  elif [ $check -eq 0 -a $fhr -ne 00 -a $fhr -ne 03 -a $fhr -ne 15 -a $fhr -ne 27 -a \
       $fhr -ne 39 -a $fhr -ne 51 ] ; then

    cp srefpcpak_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCP
    cp srefpcpaki_${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_smartinitaknest3;. prep_step
    export XLFUNIT_11="mesoak.NDFDf${fhr}"
    export XLFUNIT_12="mesoak.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="TOPONDFD"
    export XLFUNIT_47="TOPONDFDi"
    export XLFUNIT_48="LANDNDFD"
    export XLFUNIT_49="LANDNDFDi"
$EXECnam/nam_smartinitaknest3 <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
$utilexec/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak3${fhr}.tm00.grib2

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

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

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

mv MESOAK${fhr}.tm00 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00
mv nam.t${cyc}z.smartak3${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00.grib2
mv grib2.t${cyc}z.smartak3f${fhr} $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
if [ $SENDDBN = YES ] 
then
  $DBNROOT/bin/dbn_alert NTC_LOW SMARTAK3 $job $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
fi

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

  #  for forecast hours 3,15,27,39.... the files already have 3-hr buckets,
  #   but we need max/min temp data for the previous 2 hours

  elif [ ${check} -eq 0 -a ${fhr} -ne 0 ]; then
    cp srefpcpak_${SREF_PDY}${srefcyc}f0${pcphrl} SREFPCP
    cp srefpcpaki_${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_smartinitaknest3;. prep_step 
    export XLFUNIT_11="mesoak.NDFDf${fhr}"
    export XLFUNIT_12="mesoak.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="TOPONDFD"
    export XLFUNIT_47="TOPONDFDi"
    export XLFUNIT_48="LANDNDFD"
    export XLFUNIT_49="LANDNDFDi"
$EXECnam/nam_smartinitaknest3 <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
  export err=$?;err_chk

  $utilexec/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak3${fhr}.tm00.grib2
  
# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

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

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

  mv MESOAK${fhr}.tm00 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00
  mv nam.t${cyc}z.smartak3${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00.grib2
  mv grib2.t${cyc}z.smartak3f${fhr} $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
  if [ $SENDDBN = YES ]
   then
    $DBNROOT/bin/dbn_alert NTC_LOW SMARTAK3 $job $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
  fi

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

  #  for all "in-between" forecast hours (13,14,16....), we don't need
  #    any special data
  else 
    export pgm=nam_smartinitaknest3;. prep_step
    export XLFUNIT_11="mesoak.NDFDf${fhr}"
    export XLFUNIT_12="mesoak.NDFDif${fhr}"
    export XLFUNIT_46="TOPONDFD"
    export XLFUNIT_47="TOPONDFDi"
    export XLFUNIT_48="LANDNDFD"
    export XLFUNIT_49="LANDNDFDi"
$EXECnam/nam_smartinitaknest3 <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
if [ $fhr -lt 9 ] ; then
 $utilexec/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak3${fhr}.tm00.grib2
 
# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

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

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

 mv MESOAK${fhr}.tm00 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00
 mv nam.t${cyc}z.smartak3${fhr}.tm00.grib2 $COMOUT/nam.t${cyc}z.smartak3${fhr}.tm00.grib2
 mv grib2.t${cyc}z.smartak3f${fhr} $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
 if [ $SENDDBN = YES ] 
  then
   $DBNROOT/bin/dbn_alert NTC_LOW SMARTAK3 $job $pcom/grib2.awpnamsmart3.ak${fhr}_awips_f${fhr}_${cyc}
 fi

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

fi
  fi
done
exit
