#!/bin/ksh

# This script transmit the MIATCVAT(1-5) product to the world.
#
# M.Mainelli  04/2005 Initial creation
# M.Klein     06/2005 Modified for HPC
# A.Robson  09/29/11  Added test variables and tested on RH5.
#---------------------------------------

# SET TEST VARIABLES
if [[ -z "$NOSSH" && "$NOSSH" = '' ]]; then
    echo Test variable NOT set.
    ssh=ssh
    scp=scp
else
    echo Variable is set.
    echo No ssh allowed
    ssh=echo
    scp=echo
fi

if [[ -z "$NOLAUNCH" && "$NOLAUNCH" = '' ]]; then
    echo Test variable NOT set.
    launch_prod=launch_prod
else
    echo Do not launch to AWIPS 
    launch_prod=echo
fi
#-------------------------------
# Set up environmental variables
#-------------------------------
ADVS=$HOME/wgraph
cd $ADVS

year=`date -u +%Y`
hour=`date -u +%H`
date=`date -u +%Y%m%d`

#----------------
# GET USER INPUT
#----------------
print "ONLY SEND THIS PRODUCT IF "
print "WATCHES OR WARNINGS EXIST FOR THE"
print "GULF AND EAST COASTS...PUERTO RICO"
print "AND THE US VIRGIN ISLANDS!!!!!"
print " "
print "DO YOU WANT TO CONTINUE? "
print "y or n"
read answer
if [ $answer = "n" -o $answer = "no" ];
then
   exit
fi
print "What is the storm bin number?"
print "Enter: 1, 2, 3, 4, or 5"
print " "
read binno
id=`cat KNHCTCVAT${binno} | grep .10 | grep T0000Z | head -1 | cut -f6 -d"." | cut -c3-4 ` 
strmid=al${id}
echo $strmid

tcafile=`ls -alt tca_${strmid}${year}_*.vgf | tr -s " " | cut -f9 -d" " | head -1` 
advno=`echo $tcafile | cut -f3 -d"_" | cut -f1 -d"."`

echo $tcafile
echo $advno

#--------------------------------------------
# SEND THE TCV PRODUCT TO THE WORLD AND AWIPS
#--------------------------------------------

$launch_prod text KNHCTCVAT${binno}

chmod 666 KNHCTCVAT${binno}

print " "
print "TCV product sent"
print " "

#--------------------------------
# Copy files to archive directory 
#--------------------------------
mkdir $ADVS/tcvfiles
cp -f KNHCTCVAT${binno} $ADVS/tcvfiles/KNHCTCVAT${binno}_${strmid}.${advno}

exit
