#!/bin/ksh

set +x
echo "********************************************************************"
echo "   Script Name: nesdis_interpgrib.sh                                "
echo "   Contacts   : Bruce Whistler (bwhistler@nesdis.noaa.gov)          " 
echo "                              (301-457-5254) Ext121                 "
echo "                Rich Kelley    (rkelley@nesdis.noaa.gov)            "
echo "                               (301-457-5195)                       "
echo "   Purpose    : Pull and Process 06,12 and 18 hour forecast data from"
echo "                NCEP's model data directories after data is available"
echo "       MODIFIED FOR BLUE AND WHITE.NCEP.NOAA.GOV  B. Whistler 12/03/04"
echo "********************************************************************"
set -x

##################################################################
#
# Script history log:
#
# 2006-09-12  P. O'Reilly	Modified script to remove processing
#	         of GDAS files, which are no longer being used upon
#                 transition from CEMSCS to DDS.
#
##################################################################
# Define Variables
#    Variables from Arguement List
#       cyc       - Current Model Cycle (Numeric: 00)
#       model     - Current Model
#    Variables Exported
#       COM       - NCEP Model Data Directory
#       PDY       - Current YYYYMMDD
#       cyc       - Current Model Cycle (Numeric: 00)
#       cycle     - Current Model Cycle (Alpha-Numeric: t00z)
#       model     - Current Model
#       fprefix   - NCEP Model Data file prefix
#       EXECdir   - Executables Directory
#       PARMdir   - Parameter Files Directory
#       SCRIPTdir - Script Directory
#    Local Variables
#       ftplog - Prefix for data/index/out files
##################################################################

if test $# -eq 2
then
   export model=`echo $1 | tr [A-Z] [a-z]`
   export cyc=$2
else
   echo ""
   echo "Usage: nesdis_interpgrib.sh model cyc"
   echo "  where model: gfs"
   echo "  where cyc: 00 or 12"
   echo ""
   exit
fi

cd $DATA

set +x
echo " "
echo "********************************************************************"
echo "        $model ${cyc}Z RUN has started at $(date)                   "
echo "********************************************************************"
echo " "
set -x

######################################
# Determine Forecast Hours to Process
######################################
case $model in
   gfs)hourlist="06 12 18"
       export fprefix="gfs"
   ;;
esac

###########################
# Run interpolation
###########################
for fhr in $hourlist
do

   $USHutil/interp.sh $fhr 2.5

done

if [ $SENDCOM = YES ] ; then
    cp ${model}${cyc}06.data $COMOUT/. 
    cp ${model}${cyc}06.index $COMOUT/. 
    cp ${model}${cyc}12.data $COMOUT/. 
    cp ${model}${cyc}12.index $COMOUT/. 
    cp ${model}${cyc}18.data $COMOUT/. 
    cp ${model}${cyc}18.index $COMOUT/. 
fi

##############################################################
# Alert DBNet to send the data to NESDIS DDS
##############################################################

  if [ $SENDDBN = "YES" ] ; then
     $DBNROOT/bin/dbn_alert MODEL DDS_GFS $job \
      $COMOUT/${model}${cyc}06.data
     $DBNROOT/bin/dbn_alert MODEL DDS_GFS $job \
      $COMOUT/${model}${cyc}06.index
     $DBNROOT/bin/dbn_alert MODEL DDS_GFS $job \
      $COMOUT/${model}${cyc}12.data
     $DBNROOT/bin/dbn_alert MODEL DDS_GFS $job \
      $COMOUT/${model}${cyc}12.index
     $DBNROOT/bin/dbn_alert MODEL DDS_GFS $job \
      $COMOUT/${model}${cyc}18.data
     $DBNROOT/bin/dbn_alert MODEL DDS_GFS $job \
      $COMOUT/${model}${cyc}18.index
  fi

set +x
echo " "
echo "********************************************************************"
echo "        $model ${cyc}Z RUN has ended at $(date)                     "
echo "********************************************************************"
echo " "
set -x
