#!/bin/ksh
################################################################################
####  UNIX Script Documentation Block
#                      .                                             .
# Script name:         nam_smartinitak_on.sh
# Script description:  runs smartinit code over NDFD Alaskan 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.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 825 553 40530 181429 8 210000 5953 5953 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 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.bgrd3d${fhr}.tm00 WRFPRS${fhr}.tm00
  $utilexec/grbindex WRFPRS${fhr}.tm00 WRFPRS${fhr}i.tm00
  cp $PARMnam/nam_masterak.ctl master${fhr}.ctl

  # if the forecast hour is a 3-hr time (3,15,27,39....) it already
  #   contains 3-hr accumulations;  otherwise, we need to make 3-hr
  #   accumulations.   We don't need them for in-between hours (22,23,25...),
  #   since we only gather max/min data at those hours

  if [ $fhr -ne 00 -a $fhr -ne 03 -a $fhr -ne 15 -a $fhr -ne 27 -a \
       $fhr -ne 39 -a $fhr -ne 51 -a $fhr -ne 63 -a $fhr -ne 75 ] ; then
    if [ ${check} -eq 0 ]; then
     cp $COMIN/nam.t${cyc}z.bgrd3d${fhr3}.tm00 WRFPRS${fhr3}.tm00
     $utilexec/grbindex WRFPRS${fhr3}.tm00 WRFPRS${fhr3}i.tm00

     export pgm=nam_smartmakeprecip;. 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="3precip.${fhr}"
     export XLFUNIT_51="3cprecip.${fhr}"
     export XLFUNIT_52="3snow.${fhr}"
$EXECnam/nam_smartmakeprecip <<EOF > makeprecip3.out
$fhr $fhr3
EOF
export err=$?;err_chk

     grid="255 5 825 553 40530 181429 8 210000 5953 5953 0 64 0 25000 25000"
     $utilexec/copygb -g "$grid" -i3 -x 3precip.${fhr} 3precip
     $utilexec/grbindex 3precip 3precipi
     $utilexec/copygb -g "$grid" -i3 -x 3snow.${fhr} 3snow
     $utilexec/grbindex 3snow 3snowi
    fi
  fi

  # at 12-hr "on" times, we need 6 hour buckets as well
  #  we don't need them at 6-hr times (18,30,42...) because
  #  those files already have 6-hr buckets

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

    export pgm=nam_smartmakeprecip;. prep_step
    export XLFUNIT_13="WRFPRS${fhr6}.tm00"
    export XLFUNIT_14="WRFPRS${fhr6}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_smartmakeprecip <<EOF > makeprecip6.out
$fhr $fhr6
EOF
export err=$?;err_chk
 
  grid="255 5 825 553 40530 181429 8 210000 5953 5953 0 64 0 25000 25000"
  $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_198         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}

  # 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 -o $fhr -eq 72 -o $fhr -eq 84 ] ; 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.smartak${fhr3}.tm00 MAXMIN3
    cp $COMOUT/nam.t${cyc}z.smartak${fhr6}.tm00 MAXMIN4
    cp $COMOUT/nam.t${cyc}z.smartak${fhr9}.tm00 MAXMIN5

    /nwprod/util/exec/grbindex MAXMIN1 MAXMIN1i
    /nwprod/util/exec/grbindex MAXMIN2 MAXMIN2i
    /nwprod/util/exec/grbindex MAXMIN3 MAXMIN3i
    /nwprod/util/exec/grbindex MAXMIN4 MAXMIN4i
    /nwprod/util/exec/grbindex MAXMIN5 MAXMIN5i

    export pgm=nam_smartinitak;. 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="3precip"
    export XLFUNIT_16="3precipi"
    export XLFUNIT_17="6precip"
    export XLFUNIT_18="6precipi"
    export XLFUNIT_19="3snow"
    export XLFUNIT_20="3snowi"
    export XLFUNIT_21="6snow"
    export XLFUNIT_22="6snowi" 
    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="$FIXnam/nam_smartmaskak.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskak.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopoak.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopoak.grbi"
$EXECnam/nam_smartinitak <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
#bsm - add processing for conversion to grib2
 $utilexec/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2
#bsm /u/wx11bm/cnvgrib/new_cnvgrib/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2

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

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

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

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

if [ $SENDDBN_GB2 = YES ]
 then
  $DBNROOT/bin/dbn_alert MODEL NAM_SMARTAK_GB2 $job $COMOUT/nam.t${cyc}z.smartak${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 -a $fhr -ne 63 -a $fhr -ne 75 ] ; 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_smartinitak;. 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="3precip"
    export XLFUNIT_16="3precipi"
    export XLFUNIT_17="3snow"
    export XLFUNIT_18="3snowi"
    export XLFUNIT_19="MAXMIN2"
    export XLFUNIT_20="MAXMIN1"
    export XLFUNIT_21="MAXMIN2i"
    export XLFUNIT_22="MAXMIN1i"
    export XLFUNIT_46="$FIXnam/nam_smartmaskak.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskak.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopoak.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopoak.grbi"
$EXECnam/nam_smartinitak <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
export err=$?;err_chk
#bsm - add processing for conversion to grib2
$utilexec/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2
#bsm /u/wx11bm/cnvgrib/new_cnvgrib/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2

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

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

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

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

if [ $SENDDBN_GB2 = YES ]
 then
  $DBNROOT/bin/dbn_alert MODEL NAM_SMARTAK_GB2 $job $COMOUT/nam.t${cyc}z.smartak${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_smartinitak;. 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="$FIXnam/nam_smartmaskak.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskak.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopoak.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopoak.grbi"
$EXECnam/nam_smartinitak <<EOF >> smartinit.out${fhr}
$fhr
$cyc
EOF
  export err=$?;err_chk

  #bsm - add processing for conversion to grib2
  $utilexec/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2
  #bsm /u/wx11bm/cnvgrib/new_cnvgrib/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2
  
# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

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

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

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

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

  #  for all "in-between" forecast hours (13,14,16....), we don't need
  #    any special data
  else 
    export pgm=nam_smartinitak;. prep_step
    export XLFUNIT_11="mesoak.NDFDf${fhr}"
    export XLFUNIT_12="mesoak.NDFDif${fhr}"
    export XLFUNIT_46="$FIXnam/nam_smartmaskak.grb"
    export XLFUNIT_47="$FIXnam/nam_smartmaskak.grbi"
    export XLFUNIT_48="$FIXnam/nam_smarttopoak.grb"
    export XLFUNIT_49="$FIXnam/nam_smarttopoak.grbi"
$EXECnam/nam_smartinitak <<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 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2
 #bsm /u/wx11bm/cnvgrib/new_cnvgrib/cnvgrib -g12 -p40 MESOAK${fhr}.tm00 nam.t${cyc}z.smartak${fhr}.tm00.grib2
 
# Processing grids for AWIPS
 pgm=tocgrib2
 export pgm;. prep_step
 startmsg

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

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

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

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

fi
  fi
done
exit
