#!/bin/sh
#  UTILITY SCRIPT NAME :  mknavyb.sh
#               AUTHOR :  Lauren Morone and Hua-Lu Pan
#         DATE WRITTEN :  04/24/97
#
#  Abstract:  This utility script produces the navybull
#             bulletins, from the GFS and GDAS datadumps.
#
#     Input:  none
#
echo "History: April 1997 - First implementation of this utility script"
echo "         Jan 2000   - Converted to IBM-SP."
echo "         Oct 2005   - Send products to TOC via the NTC."
echo "         Jan 2008   - Changed the input file to non-restricted."
#

set -xa

cd $DATA

# Copy in updated files containing dates and times

cp /nwges/${envir}/ship.cntl .

# Copy in appropriate parm field

echo $cyc > parm.job1

# Copy in SFCSHP file for use as input data set

cp ${COMIN}/${RUN}.${cycle}.sfcshp.tm00.bufr_d.nr SFCSHP

export pgm=navybull;. prep_step

export XLFUNIT_11="SFCSHP"
export XLFUNIT_12="parm.job1"
export XLFUNIT_15="ship.cntl"
export XLFUNIT_51="navybull.part1"

$EXECbulls/navybull
export err=$?; err_chk

#
#  Do Part II of the datadump. For GFS, the precious six hour data is used
#     for GDAS, the next six hour dump is used
#

case $cyc in
 00) echo 18 > parm.job1
     cp $COMINm1/${RUN}.t18z.sfcshp.tm00.bufr_d.nr SFCSHP ;;
 12) echo 06 > parm.job1
     cp $COMIN/${RUN}.t06z.sfcshp.tm00.bufr_d.nr SFCSHP ;;
esac

export pgm=navybull;. prep_step

export XLFUNIT_11="SFCSHP"
export XLFUNIT_12="parm.job1"
export XLFUNIT_15="ship.cntl"
export XLFUNIT_51="navybull.part2"

$EXECbulls/navybull
export err=$?; err_chk

#
#  Now cat the two parts together to make the final bulletin
#

cp navybull.part1 navybull.tran.${cyc}
err1=$?

cat navybull.part2 >> navybull.tran.${cyc}
err2=$?

# In case no bulletin was made, send a message and get out

if test $err1 -eq 0 -o $err2 -eq 0; then

  echo 'navybull finished'

  cp ship.cntl /nwges/${envir}
  chmod 775 /nwges/${envir}/ship.cntl

  if test $SENDCOM = 'YES'
    then
    cp ship.cntl $COMOUT/ship.cntl.$cyc
    cp navybull.tran.${cyc} $COMOUT
  fi

  msg=" navybull bulletin successfully made"
  postmsg "$jlogfile" "$msg"

######################################################

  if test $SENDDBN = 'YES'
  then
    cp navybull.tran.${cyc} $pcom/navybull.tran.${cyc}.$job
    $USHutil/make_ntc_bull.pl  WMONV NONE KWBC NONE  \
       navybull.tran.${cyc} $pcom/navybull.tran.${cyc}.$job
  fi

###################################################################

else

  msg=" navybull bulletin was not created "
  postmsg "$jlogfile" "$msg"

fi
