#! /bin/sh
#
#  Enter, in order, basin (e.g. AL), storm number (e.g. 07), year (e.g. 2010), month (e.g. 09),
#   day (e.g. 01), GMT (e.g. 00)
#
#  Note:  basin MUST BE IN UPPERCASE LETTERS
#
ntracks=100   # Total number of tracks to be generated
daystotrack=0 # Number of days until ECMWF track begins (this may not yet be functional)
vmcrit=40.0   # Critical maximum wind speed that storms must attain to be included in set
rerandom=1    # Set to zero to use same random seed each time or 1 to use a different one
#
basin="$1"
stormnum="$2"
year="$3"
month="$4"
day="$5"
hour="$6"
#
if [ $basin = AL ]; then
 basinlc=al
elif [ $basin = EP ]; then
 basinlc=ep
elif [ $basin = WP ]; then
 basinlc=wp
elif [ $basin = IO ]; then
 basinlc=io
elif [ $basin = SH ]; then
 basinlc=sh
fi
#
#   Go to NHC to get most recent best track and official forecast track and intensity
#
#
#   Go to NHC to get most recent best track and official forecast track and intensity
#
if [ $basin = AL -o $basin = EP ]; then
#
#  Use these for real-time forecasts
#
#wget -q -N ftp://ftp.tpc.ncep.noaa.gov/atcf/btk/b$basinlc$stormnum$year.dat -nd
#wget -q -N ftp://ftp.tpc.ncep.noaa.gov/atcf/afst/$basinlc$stormnum$year.fst -nd
#
#  Or use these if it is past season
#
wget -q -N ftp://ftp.tpc.ncep.noaa.gov/atcf/archive/$year/b$basinlc$stormnum$year.dat.gz -nd
wget -q -N ftp://ftp.tpc.ncep.noaa.gov/atcf/archive/$year/a$basinlc$stormnum$year.dat.gz -nd
gunzip -q -f b$basinlc$stormnum$year.dat.gz
gunzip -q -f a$basinlc$stormnum$year.dat.gz
fi
#
#  Get .fst and .dat files for regions outside NHC's purview from my directory
#
if [ $basin = WP -o $basin = IO -o $basin = SH ]; then
cp -f /disk13/emanuel/JTWC/b$basinlc$stormnum$year.dat b$basinlc$stormnum$year.dat
cp -f /disk13/emanuel/JTWC/$basinlc$stormnum$year.fst $basinlc$stormnum$year.fst
fi
#
modellist="ecmwf"
#
datelist=$year$month$day$hour
#
stormlist=$basin$stormnum
#
slash=/
for model in $modellist
do
for date in $datelist
do
for bas in $basin
do
for storm in $stormlist
do
rm -f wrt_pred.in
atime=`date +%N`
echo $bas $model $date $storm $month $day $hour $ntracks $vmcrit $daystotrack $rerandom $atime>wrt_pred.in
name=ascii/$date$slash$storm
named=$name$slash
mkdir -p $name
mkdir -p ascii
wrt_aer   
matfile=.mat
statsfile=stats.out
cp -f $named$statsfile $statsfile
matlab<matlab_scripts/wrt.m>rstemp
zipfile=.zip
mv -f temp.mat $date$storm$matfile
rm -f $statsfile 
statsfile=stats.txt
trackfile=data/ecmwf/${datelist}/${stormlist}/tracks.mat
cp -f $named$statsfile $statsfile
zip -q -j $date$storm$zipfile $date$storm$matfile $statsfile $trackfile b$basinlc$stormnum$year.dat $basinlc$stormnum$year.fst
mv -f $date$storm$zipfile matlab_binaries/
zfile=hurr
outfile=*.out
a1=10000
a2=20000
sleep 1
cp $statsfile ${named}
if [ $ntracks -lt $a1 ]; then
zip -jmq ${named}hurr.zip ${named}hurr*.out ${named}$statsfile 
elif [ $ntracks -ge $a1 -a $ntracks -lt $a2 ]; then
zip -jmq ${named}hurr1.zip ${named}hurr[1-9].out $statsfile 
zip -gjmq ${named}hurr1.zip ${named}hurr[1-9][0-9].out
zip -gjmq ${named}hurr1.zip ${named}hurr[1-9][0-9][0-9].out
sleep 2
zip -gjmq ${named}hurr1.zip ${named}hurr[1-9][0-9][0-9][0-9].out
zip -jmq ${named}hurr2.zip ${named}hurr[1][0-9][0-9][0-9][0-9].out
fi
sleep 1
rm -f result rstemp $date$storm$matfile $statsfile 
done 
done
done
done
