#!/bin/sh

#########################################################################
echo "------------------------------------------------------------------"
echo "extpc_psurge_nhctrk.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

ScriptDir=$USHpsurge
stormAdvDir=$DATA
workDir=$DATA/run
ansDir=$DATA/ans

rm -rf $workDir
rm -rf $ansDir
mkdir $workDir
mkdir $ansDir
cd $workDir

$USHpsurge/tpc_psurge_nhctrk.sh $ScriptDir $stormAdvDir $stormid $AdvTime
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
