#!/bin/ksh
######################################################
echo "-----------------------------------------------" 
echo "     exhwrf_tpcpost.sh.sms                     "
echo "   Hurricane model control script              "
echo "-----------------------------------------------" 
######################################################
set -x

PS4=' + exhwrf_tpcpost.sh.sms line $LINENO: ' 

#-----------------------------------------------------
# This script will run the HWRF post-processing of TPC text
# and wind and rainfall swath files 
#
# Be sure that there is a holdvars.txt file, and source 
# it because it contains needed enviromental variables 
# from the JHWRF_PRE_MASTER job that need to be passed
# into this script. 
#----------------------------------------------------- 
sh ${utilscript}/setup.sh
export pgm=exhwrf_tpcpost.sh.sms
. prep_step
startmsg
if test -f ${COMOUT}/${stormlabel}.holdvars.txt
then
   . ${COMOUT}/${stormlabel}.holdvars.txt
else
   set +x
   echo " "
   echo "!!! ERROR: holdvars.txt file missing"
   echo " "
   set -x
   msg="Hurricane to Run But No ${stormlabel}.holdvars.txt file found."
   postmsg "$jlogfile" "$msg"
   export err=911;err_chk
   err_exit "Hurricane to Run But No ${stormlabel}.holdvars.txt file found."
fi
#-------------------------------------------------------
# check the ocean_status file to see if the model ran coupled 
# to the ocean or the atmosphere alone. 
 
if [ -s ${COMOUT}/ocean_status.${STORM}${STORMID}.${YYYYMMDDHH} ]  
then
   echo "Will source file ${COMOUT}/ocean_status.${STORM}${STORMID}.${YYYYMMDDHH}"
   . ${COMOUT}/ocean_status.${STORM}${STORMID}.${YYYYMMDDHH}    
   echo 'RUN_COUPLED = ' ${RUN_COUPLED} 
else
   echo 'No ocean_status file present; set RUN_COUPLED=NO'  
   RUN_COUPLED=NO
fi     

# determine parameter passed to hwr_tpcpost for postprocessing  
# of MODEL = ATMOS or COUPLED output. This overides (only for postprocessing)
# the value of MODEL specified in the holdvars.txt file at start of run.  

if [ ${RUN_COUPLED} = YES ] 
then
   MODEL=COUPLED
else
   MODEL=ATMOS
fi
echo 'MODEL = ' ${MODEL}

# set shell variables to be passed into script
DOMAIN=COMBINE
CASE=FCST

echo "Script exhwrf_post.sh.sms running CASE=${CASE}"  

${USHhwrf}/hwrf_tpcpost.sh  ${STORM} ${PDY} ${CYC} ${STORMID}  ${CASE} \
                           ${MODEL} ${DOMAIN}  

# end of script 
