set +x
#####################################################################
echo "---------------------------------------------------------"
echo "JINAMSST - FTPs Great Lakes Lab (NOAA - GLERL) Water Temp"
echo "---------------------------------------------------------"
echo "History: Aug 1998 - First implementation of this new script."
#####################################################################
set -x

cd $DATA

if [ -s /dcom/us007003/$PDY/wtxtbul/ncepnamgl.dat ] ; then
  cp /dcom/us007003/$PDY/wtxtbul/ncepnamgl.dat ncepnamgl.dat
else
  if [ -s /dcom/us007003/$PDYm1/wtxtbul/ncepnamgl.dat ] ; then
  cp /dcom/us007003/$PDYm1/wtxtbul/ncepnamgl.dat /dcom/us007003/$PDY/wtxtbul/ncepnamgl.dat
  cp /dcom/us007003/$PDYm1/wtxtbul/ncepnamgl.dat ncepnamgl.dat
  else
    err_exit "Great Lakes SST NOT Found - Fatal Error!"
  fi
fi

cp $TANKDIR_IN/$PDY/wgrdbul/PRD.SST.FIELD.KM50 sst50.grid

# generate a high resolution SST analysis for use by the
# Mesoscale NAM forecast model.  A satellite generated 50km
# ocean SST field is blended with a high resolution SST
# field over the Great Lakes area.

export pgm=sstoi_namsst
. prep_step

export XLFUNIT_23="sst50.grid"
export XLFUNIT_24="ncepnamgl.dat"
export XLFUNIT_31="$FIXsstoi/sstoi_lst.grid"
export XLFUNIT_51="namsst.grid"

startmsg
$EXECsstoi/sstoi_namsst >> $pgmout 2> errfile
export err=$?
if (( $err == 10 )) 
then
   msg="Error reading 50-km Global SST file"
   postmsg "$jlogfile" "$msg"
elif (( $err == 20 ))
then
   msg="50-km Global SST file > 7 days older than Great Lakes file"
   postmsg "$jlogfile" "$msg"
elif (( $err == 30 ))
then
   msg="Great Lakes file > 7 days older than 50-km Global SST file"
   postmsg "$jlogfile" "$msg"
fi
#err_chk

if test "$SENDCOM" = 'YES'
then
   cp namsst.grid $COMOUT/${RUN}.${cycle}.nam_grid

   if test "$SENDDBN" = 'YES'
   then
      if test "$DBNROOT" = 'DBNROOT_OFF'
      then
         echo "DBNROOT is not set, no DBNet alerts will be issued."
      else
      $DBNROOT/bin/dbn_alert MODEL SST_NAM_GRID namsst $COMOUT/${RUN}.${cycle}.nam_grid
      fi
   fi
fi

