#!/bin/sh

#########################################################################
echo "------------------------------------------------------------------"
echo "extpc_psurge_slosh.sh.sms - Generate the Probability Storm Surge for TPC"
echo "------------------------------------------------------------------"
echo "History: April 25 2007 - Original script from Arthur Taylor in MDL"
#########################################################################

############################################################################
# START FLOW OF CONTROL
#   1) Create the directories for the specific storm-id in zsurge
#   2) Generate the hypothetical tracks for the specific storm by 
#      running mdl_psurge_nhctrk.sh
############################################################################

set -x
export PS4='$SECONDS + ' 
cd $DATA

msg="TPC psurge has begun on `hostname` at `date`"
postmsg "$jlogfile" "$msg"
startmsg

# Step 1: Create storm-id directories in zsurge
cp $COM_ZSURGE/queue/${stormlabel}.txt .
export stormid=`cat ${stormlabel}.txt |awk '{print $1}`
export AdvTime=`cat ${stormlabel}.txt |awk '{print $2}`

cp $TPC_ZSURGE/${stormid}/b${stormid}.dat $DATA/.
if [ -s $TPC_ZSURGE/${stormid}/${stormid}.fst.new ]
then
  cp $TPC_ZSURGE/${stormid}/${stormid}.fst.new  $DATA/${stormid}.fst
else
  cp $TPC_ZSURGE/${stormid}/${stormid}.fst  $DATA/${stormid}.fst
fi
cp $TPC_ZSURGE/${stormid}/${stormid}_${AdvTime}_wlevel.dat $DATA/.

if [ ! -d $COM_ZSURGE/${stormid} ]
then
   mkdir -p $COM_ZSURGE/${stormid}
fi

# Step 2: Generate the hypothetical tracks and run the SLOSH model 
# for each track.
#         
ScriptDir=$USHpsurge
stormAdvDir=$DATA

mkdir -p $DATA
$USHpsurge/tpc_psurge_slosh.sh $ScriptDir $stormAdvDir
export err=$?; err_chk

#####################################################################
# GOOD RUN
set +x
echo "**************JOB $job COMPLETED NORMALLY on `hostname` at `date`"
echo "**************JOB $job COMPLETED NORMALLY on `hostname` at `date`"
echo "**************JOB $job COMPLETED NORMALLY on `hostname` at `date`"
set -x
#####################################################################

echo EXITING $0
exit
