
################################################################################
#
# Name : getsnow_nam.sh           Author : Eric Rogers
#
# Abstract: This script copies the imssnow.grb and snowdepth.grb files from 
#           from /com/nam/prod to the local directory for use in the NDAS/Nam.
#           If either file is missing from the nam or ndas /com directory,
#           the script searches back 12 cycles (3 days) until it finds both
#           files.
#
# Log:
#
# 1999-11-26 : Eric Rogers
#
# Usage:
#
# getsnow_nam.sh $SDATE
#
# SDATE  = 10 digit cycle time (e.g., 1998061900)
# IHFIN = Last forecast hour to be copied
#

set -x

SDATE=$1

echo $SDATE > SNOWDATE

ic=0

while [ $ic -le 12 ] ; do

snowdate=`cut -c 1-8 SNOWDATE`
snowhh=`cut -c 9-10 SNOWDATE`
cp /com/nam/prod/nam.${snowdate}/nam.t${snowhh}z.imssnow.grb imssnow.grb
err1=$?
cp /com/nam/prod/nam.${snowdate}/nam.t${snowhh}z.snowdepth.grb snowdepth.grb
err2=$?

tot=`expr $err1 + $err2 `

if test "$tot" -eq 0
then
 break
else
 cp /com/nam/prod/ndas.${snowdate}/ndas.t${snowhh}z.imssnow.grb imssnow.grb
 err3=$?
 cp /com/nam/prod/ndas.${snowdate}/ndas.t${snowhh}z.snowdepth.grb snowdepth.grb
 err4=$?
 tot2=`expr $err3 + $err4 `
 if test "$tot2" -eq 0 
 then
  break
 else
  SDATE=`/nwprod/util/exec/ndate -6 $SDATE`
  echo $SDATE > SNOWDATE 
  let "ic=ic+1"
  fi
fi

done 

if [[ -e imssnow.grb ]] 
then
  echo The snow files were successfully copied
  exit $?
else
  echo The snow files were not copied
  exit 8
fi
