#!/bin/csh

# This sets up the environment for creating the necessary graphics 
# to back up NHC.  These are:
#
# 3 and 5-day Tropical cyclone graphics (with watch/warning)
# Wind Swath
# Intensity
# Probability Swath
# Probability Table 
# Wind table graphic (changed for 2008)
#
# In addition, the experimental TCV text product will be generated.
#
# Log:
# M. Klein	06/17/2005	Creation.
# M. Klein      06/13/2006      Add copy of /pub directory from CCS for
#                               graphic production of intermediate advisories.
# M. Klein      01/31/2007      Change PRODCCS determination and directory where TPC data located. Tested.
# A. Robson     05/10/2007      Commented out line to copy files from .../atcf-noaa/prb-tbl dir on CCS.
# A. Robson     07/24/2007      Changed to use rsync instead of scp to clean up directory (use pullsync)
# M. Klein      06/16/2008      Copy over the ../atcf-noaa/wndprb directory from the CCS to produce new
#                               wind table graphic.
# A. Robson     06/17/2009      Added alaska@halaska to allowable accounts/workstations.
# M. Klein      05/15/2012      Modify to include systems in NCWCP.
# A. Robson     06/13/2013      Modified to get advisories from NETAPP (after moved from WCOS)
  

# FIRST RYSNC THE ADVISORIES FROM WCOSS TO $GRPHGD/ATCF
ssh hpcops@vm-lnx-hpccf "nhcwcos2cf"

# NOW COPY (USING PULLSYNC) THE LATEST ADVISORIES FROM NETAPP TO LOCAL WORKSTATION
setenv WORKDIR    ${HOME}/wgraph
setenv ADVS       ${WORKDIR}/mar
set machine = `hostname -s`
set user = `whoami`

# THERE ARE NOW NO RESTRICTIONS ON WHERE THIS CAN BE RUN FROM AS ALL SYSTEMS SHOULD BE ABLE TO SSH INTO NCOSRV TO GET THE FILES.

#if ( ${machine} != "hwwe" && ${machine} != "heff1" && ${machine} != "hback1"  && ${machine} != "halaska" && ${machine} != "hpc-lw-wwd" && ${machine} != "hpc-lw-back2" && ${machine} != "hpc-lw-medr3" ) then
#    echo "   "
#    echo " This script currently can only be run on heff1, hback1, halaska and hwwe at WWB."
#    echo " This script currently can only be run on hpc-lw-wwd, hpc-lw-back2 and hpc-lw-medr3 at NCWCP."
#    echo " For hwwe or hpc-lw-wwd, use the mdldiag account."
#    echo " For heff1 or hpc-lw-back2, use the eff1 account."
#    echo " For hback1, use the eff2 account."
#    echo " For halaska or hpc-lw-medr3, use the alaska account."
#    echo "   "
#    exit
#else if ( (${machine} == "hwwe" || ${machine} == "hpc-lw-wwd") && ${user} != "mdldiag" ) then
#    echo "   "
#    echo " This script currently can only be run on the mdldiag account on this machine."
#    echo " Please log off and log in as mdldiag."
#    echo "   "
#    exit
#else if ( (${machine} == "heff1" || ${machine} == "hpc-lw-back2") && ${user} != "eff1" ) then
#    echo "   "
#    echo " This script currently can only be run on the eff1 account on this machine."
#    echo " Please log off and log in as eff1."
#    echo "   "
#    exit
#else if ( ${machine} == "hback1" && ${user} != "eff2" ) then
#    echo "   "
#    echo " This script currently can only be run on the eff2 account on this machine."
#    echo " Please log off and log in as eff1."
#    echo "   "
#    exit
#else if ( (${machine} == "halaska" || ${machine} == "hpc-lw-medr3") && ${user} != "alaska" ) then
#    echo "   "
#    echo " This script currently can only be run on the alaska account on this machine."
#    echo " Please log off and log in as alaska."
#    echo "   "
#    exit
#endif

# MAKE AND CHANGE TO A WORKING DIRECTORY
mkdir ${WORKDIR}
cd ${WORKDIR}

# NOW COPIES FROM $GRPHGD/atcf
set proddir = "/pub/share/hpcops/grids/atcf"

cp ${opsdir}/tables/tpc/stns/*.tbl .

# CREATE THE WORKDIRS IN CASE THEY DON'T EXIST...
mkdir -p ~/wgraph/wndprb
mkdir -p ~/wgraph/dis
mkdir -p ~/wgraph/mar
mkdir -p ~/wgraph/pub

pullsync hpcops ${NCOSRV} ${proddir}/dis ~/wgraph/dis/. D
pullsync hpcops ${NCOSRV} ${proddir}/pub ~/wgraph/pub/. D
pullsync hpcops ${NCOSRV} ${proddir}/mar ~/wgraph/mar/. D
pullsync hpcops ${NCOSRV} ${proddir}/wndprb ~/wgraph/wndprb/. D

if ( ! -e ${ADVS} ) then
    echo "     "
    echo "There is a problem getting the previous advisories from the IBM.  Contact SDM or DTB"
    echo "     "
    exit
endif

setenv NCDESK     ${opsdir}/tables/tpc

nmap2

exit
