#  UTILITY SCRIPT NAME :  mkfossst
#               AUTHOR :  Joe Johnson 
#         DATE WRITTEN :  06/13/97
#             Modified :  07/16/97 added step SSTGRIDS which changes
#                         the PDS octet 9 from 11 (TMP) to 80 (WTMP)
#                         for FOS distribution.
#             Modified :  09/10/97 added steps to output SST 1-deg GRIB
#                         GRID 360x180 with WMO header HTXA99 for ECMWF.
#             Modified :  06/24/98 - Added copy of PGrbF00 and PGrbiF00
#                         files to current working directory.  Used by
#                         MKFOSSPC to create a bitmap for the 2x2 SST
#                         fields.
#
#  Abstract:  This utility script produces the SST 2.5x5, and
#             1.25x1.25 degree GRIB bulletins.  Also appends WMO
#             bulletin header on 360x180 1-deg SST grid.              
#
#             NOTE:  MKFOSSPC makes 2.5x5 deg bulletins
#                             makes 2x2 deg bulletins
#                    MAKEWAFS makes 1.25x1.25 deg bulletins
#
#     Input:  2 arguments are passed to this script.   
#             1st argument - Model - format of 3X in lower case (sst)
#             2nd argument - Forecast Hour - format of 2I (12)
#
echo "History: June 17,1997 - First implementation of this utility script"
#

set -xa
NET="$1"
hour="$2"
num=$#

if test "$num" -eq 2
then
   echo " Appropriate number of arguments were passed"
else
   echo " Two arguments are needed in order to execute"
   echo " this script.  You passed $num."
   exit 16
fi

if [ ! -f sst2dvgrb_awips ]
then
   cp $COMOUT/sst2dvar_grb_0.5_awips sst2dvgrb_awips
fi
if [ ! -f sst2dvgrb_awips.index ]
then
   cp $COMOUT/sst2dvar_grb_0.5_awips.index sst2dvgrb_awips.index
fi

set +x
echo " ---------------------------------------------------"
echo "  Make SST 0.5 degree GRIB Product for the ECMWF "
echo " ---------------------------------------------------"
set -x

# Add WMO Bulletin Header to 0.5 deg SST field to send to ECMWF.

export pgm=tocgrib
. prep_step

export XLFUNIT_11="sst2dvgrb_awips"
export XLFUNIT_31="sst2dvgrb_awips.index"
export XLFUNIT_51="xtrn.rtgsst_ecmwf"

startmsg
$EXECutil/tocgrib < $PARMutil/grib_rtgsstecmwf parm='KWBI' >> $pgmout 2>errfile
export err=$?;err_chk

#################################################################
if test "$SENDCOM" = 'YES'
then
  cp xtrn.rtgsst_ecmwf $pcom/grib.rtgsst.$job

  if test "$SENDDBN" = 'YES'
  then
    $DBNROOT/bin/dbn_alert GRIB_LOW $NET $job $pcom/grib.rtgsst.$job
  else
    echo "SENDDBN=$SENDDBN, files not alerted to DBNet."
  fi
fi
###################################################################


msg="AWIPS GRIB Processing ${hour} hour completed normally"
postmsg "$jlogfile" "$msg"

exit
