#  UTILITY SCRIPT NAME :  mkfnmoc
#               AUTHOR :  Joe Johnson 
#         DATE WRITTEN :  01/29/98
#
#  Abstract:  This utility script produces the 1x1 stratospheric
#             heights and temperature fields for FNMOC (Monterrey).
#             Program FNMOCTOV reads the 65x65 nh and sh polar 
#             stereographic fields of heights and temps and
#             interpolates to 1-degree global grids.
#
echo "History: Feb 1998 - First implementation of this utility script"
echo "History: DEC 1999 - Created for implementation on IBM SP"
echo "                  - Allows users to run interactively"
#

set -x
export EXECutil=${EXECutil:-/nwprod/util/exec}
export envir=${envir:-prod}
export jlogfile=${jlogfile:-jlogfile}
export NET=${NET:-gfs}
export RUN=${RUN:-gdas}
export cyc=${cyc:-00}
export cycle=${cycle:-t${cyc}z}
export SENDCOM=${SENDCOM:-NO}
export SENDDBN=${SENDDBN:-NO}
if [ -z "$DATA" ]
then
   export DATA=`pwd`
   cd $DATA
   /nwprod/util/ush/setup.sh
   /nwprod/util/ush/setpdy.sh
   . PDY
fi
export COMIN=${COMIN:-/com/$NET/$envir/$NET.$PDY}
export COMINm1=${COMINm1:-/com/$NET/$envir/$NET.$PDYm1}
export job=${job:-interactive}
export pgmout=${pgmout:-OUTPUT.$$}
export comrun=${comrun:-/com/$NET/$envir/$NET.$PDYm1}

##############################
# Copy Input Field to $DATA
##############################

if test ! -f tovshgt
then
   cp $COMINm1/tovs_height.grb tovshgt
fi
if test ! -f tovstmp
then
   cp $COMINm1/tovs_temperature.grb tovstmp
fi

/nwprod/util/exec/grbindex tovshgt tovshgt.index
/nwprod/util/exec/grbindex tovstmp tovstmp.index

export pgm=fnmoctov
. prep_step

export XLFUNIT_11="tovshgt"
export XLFUNIT_12="tovstmp"
export XLFUNIT_31="tovshgt.index"
export XLFUNIT_32="tovstmp.index"
export XLFUNIT_50="tovs65"
export XLFUNIT_51="fnmoc_tovs"

startmsg
$EXECutil/fnmoctov >> $pgmout 2> errfile
export err=$?;err_chk

###################################################################
if test "$SENDCOM" = 'YES'
then
  cp fnmoc_tovs $comrun
  if test "$SENDDBN" = 'YES'
  then
    $DBNROOT/bin/dbn_alert MODEL GDAS_STRAT_GRIB $job $comrun/fnmoc_tovs
  else
    echo "SENDDBN='NO', fnmoc files not posted to db_net."
  fi
fi
###################################################################

msg="FNMOC Stratospheric GRIB Processing completed normally"
echo $msg
postmsg "$jlogfile" "$msg"

exit
