echo "------------------------------------------------"
echo "Executing exhrly_realtime.sh.sms XXXX "
echo "This script reads the model dump counts"
echo "and compares to the monthly averages makes"
echo "summary text for later WEB applications "
echo "Authors: Bradley Ballish & Krishna Kumar"
echo "NCO/Data Management & Quality Assessment Branch SEP 2004"
echo "V. Krishna Kumar NCO/System Integration Branch July 2008"
echo "Modified to automate plotting data types from bufr dumplist"
echo "Modified to extend the time series to 30 days for all models May 2010"
echo "------------------------------------------------"

cd $DATA

########################################
set -x
msg="HAS BEGUN!"
$DATAO/postmsg "$jlogfile" "$msg"
########################################

cp $FIXPREP/bufr_dumplist bufr_dumplist_temp
grep "#>" bufr_dumplist_temp > realtime_bufr_dumplist.txt
STATFILE=/com/$NET/prod/$RUNM.$PDY/$BASERUN.$cycle.updated.status.tm00.bufr_d

### Check file exists or else exit

if test -s $STATFILE
then
   cat $STATFILE > update
else
   msg="current hourly updated status file not available"
   echo $msg
   exit
fi

### Create model_name as input for fortran

echo $NETMOD > model_name

msg="Begin program REALTIME_MODELMON."
$DATAO/postmsg "$jlogfile" "$msg"

export pgm=realtime_modelmon
. prep_step
startmsg

export XLFRTEOPTS="unit_vars=yes"     # Allow overriding default names.
export XLFUNIT_24="update"
export XLFUNIT_26="realtime_bufr_dumplist.txt"
export XLFUNIT_50="output"
export XLFUNIT_55="gemout"
export XLFUNIT_56="sumtable"
export XLFUNIT_57="datatypes_plotnumbs"

$EXECPREP/realtime_modelmonx <model_name 1>modelmon.out 2>modelmon.err

errmodelmon=$?

cat output > hourtest_$PDY_$cycle
cat sumtable | sort +0 -1 > ${NETMOD}_sumtable
cat datatypes_plotnumbs | sort +0 -1 > ${NETMOD}_dataplotlist_${cycle}

if test "$SENDCOM" = 'YES'
then
   echo $PDY$cyc > $COMOUTRT/${NETMOD}_$cycle
   echo $PDY$cyc > ${NETMOD}_latest
   cp ${NETMOD}_latest $COM1OUT/.
   cp ${NETMOD}_sumtable $COM1OUT/.
   cp ${NETMOD}_dataplotlist_${cycle} $COM1OUT/.
fi

chmod og+r $COMOUT/*html*

#####################################################################
# GOOD RUN
set +x
echo "************** exmodels_realtime_summary.sh COMPLETED NORMALLY ON THE IBM"
echo "************** exmodels_realtime_summary.sh COMPLETED NORMALLY ON THE IBM"
echo "************** exmodels_realtime_summary.sh COMPLETED NORMALLY ON THE IBM"
set -x
#####################################################################

msg="HAS COMPLETED NORMALLY!"
echo $msg
$DATAO/postmsg "$jlogfile" "$msg"

############## END OF SCRIPT #######################
