#!/bin/sh
# --- 08/05/96 -------- EXHRY SCRIPT ----------------------------
#
set +x

###################################################################################
#  Document the HISTORY of script modifications
#
#  REVISED: Aug  5,  1996  - standardize and add SMS hooks 
#           Aug  5,  1996  - added qsub to kick off MDL job 
#           Nov 18,  1999  - set up script to test hrlytbl job on the IBM SP.  RLA
#           Mar  8,  2002  - fixed if test associate with the llsubmit. RLC 
#           Apr 15,  2004  - Made changes to dumpjb setup.  Now use mneumonic for  
#                            tank instead of the 000 007, and use form=ibm so the  
#                            file name for unit 42 is different. RLC 
##################################################################################

set -x

cd $DATA

# ###############################################
#                                               #
#                 exhry.sh.sms                  #
#                                               #
# start accounting and MDL METAR BUFR processing#
#                                               #
# ###############################################
 
set +x
echo '------------------------------------------------------'
echo '      NMCOPS  FOB#4    ROOM 2330      457-5047 '
echo "              IBM $ENVIR PROCESSING                "
echo "      `date`      "
echo "     JOB WWMDL   HOUR(UTC) IS  ... $HOUR"
echo ' '
echo ' $VARIABLE info for this execution:'
echo " Processing executable environment is ............ $ENVIR"
echo " Temporary processing file directory is .......... $DATA"
echo " unique machine processing id is ................. $pid"
echo "________________________________________________"
set -x

cp /com/date/t${HOUR}z ncepdate
 
set +x
echo " "
echo "PDY=$PDY"
echo "HOUR=$HOUR"
echo " "
set -x
 
# Make sure com file variables are established
#
export DAT="$PDY$cyc"
export PDH="$PDY$HOUR"
export bufrsh=/nwprod/ush

# ###############################################
#
#   Begin processing hourly files
# 
#   DUMP SURFACE METAR DATA, TYPE 000 SUBTYPE 007
# 
# ###############################################

hour=$HOUR
msg="Processing hour ${HOUR}Z."
postmsg "$jlogfile" "$msg"

set -x
DUMP=${DUMP:-$bufrsh/dumpjb}

msg="The Dump for $PDH has started."
postmsg "$jlogfile" "$msg"

 time $DUMP $PDH 0.25 metar

cat metar.out >> $pgmout

msg="The Dump has ended."
postmsg "$jlogfile" "$msg"

msg="Creating the MDL Hourly Table." 
postmsg "$jlogfile" "$msg"

export pgm=mdl_hrlytbl
. prep_step

#     ASSIGN INPUT DATASETS SURFACE METAR REPORTS
export XLFUNIT_42="metar.ibm" 
export XLFUNIT_30="ncepdate" 

#     EXECUTE HRLYTBL 
export XLFUNIT_60="sfctbl.$PDH" 
export XLFUNIT_70="rawmetar.$PDH" 
export XLFUNIT_80="bufrmetar.$PDH" 

startmsg
$EXECmdl/mdl_hrlytbl >> $pgmout 2> errfile
export err=$?;err_chk

sort bufrmetar.$PDH >> sfctbl.$PDH
sort -o rawmetar.$PDH rawmetar.$PDH
 
echo "\nThe following files were created: \n"
ls -al *.$PDH
 
lines=`wc -l sfctbl.$PDH | cut -c1-8`
stations=`expr $lines - 3`

msg="$stations STATIONS WERE PROCESSED"
postmsg "$jlogfile" "$msg"

if test "$SENDDCOM" = 'YES'
then
   cp sfctbl.$PDH $dcom/sfctbl.$HOUR
   cp rawmetar.$PDH $dcom/rawmetar.$HOUR
fi

# ----------------- END OF EXHRY SCRIPT ----------------

