# QSUB -r GETON84                       # request name
# QSUB -q reg                           # job queue class
# QSUB -eo                              # stdout and stderr together
# QSUB -lM 2Mw                          # maximum memory
# QSUB -lT 600                          # time limit
# QSUB -lt 600                          # time limit
# QSUB -mb                              # mail me when it starts
# QSUB -me                              # mail me when it ends
# QSUB                                  # no more qsub commands

ja
set echo

# The necessary arguments:

set startdate = 1994-12-12+00     # YYYY-MM-DD+HH
set ndates = 3
set itimint = 12

set Host = username@host.domain:/local_directory

###############################################################################
######################                         ################################
######################  END USER MODIFICATION  ################################
######################                         ################################
###############################################################################

cd $TMPDIR

cat >! ftp.cmd << EOF0
open ftp.ucar.edu
user anonymous ${user}@ucar.edu
cd mesouser/MM5V3
get REGRID.TAR.gz regrid.tar.gz
EOF0

ftp -n < ftp.cmd
rm ftp.cmd

gzip -cd regrid.tar.gz | tar xf -

cd REGRID/pregrid/on84

# Set up the list "mdate".  "mdate" will hold all the times we 
# need to get.

set num = 0
set idth = -$itimint
set mdate = ( )
while ( $num < $ndates )
   @ idth = $idth + $itimint
   @ num ++
   set ndate = `../util/geth_newdate ${startdate} ${idth}`
   set mdate = ( ${mdate} ${ndate} )
end

echo "mdate = $mdate"

# Set up the ftp command-script to get the archive lists.  First, set 
# up to login anonymously to ncardata.ucar.edu

cat >! ftp.cmd << EOF1
open ncardata.ucar.edu
user anonymous ${user}@ucar.edu
get datasets/ds082.0/MSS-file-list on84.master
quit
EOF1

# Now invoke ftp to get the archive lists.

if ( ! -e on84.master ) then
   ftp -n < ftp.cmd
   rm ftp.cmd
endif

set MNAM = ( JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC )

cat >! gnc.awpr <= IDATE) )
       {
	 {print substr(hold,1,9), \$1}
       }
    } 
EOF
endif

# Construct the dates as they appear in the archive titles.  Use awk
# (nawk) to get the actual MSS filenames from the archive lists.  We
# change the text-string month in the archive list to a two-digit 
# number, to make comparisons among dates easier.

foreach ndate ( $mdate ) 

   set YYYY = `echo $ndate | cut -b 1-4`
   set Mm = `echo $ndate | cut -b 6-7`
   set Dd = `echo $ndate | cut -b 9-10`


# Get the upper-air analysis files.


   set MssFile = `nawk -v IDATE=${YYYY}${Mm}${Dd} -f gnc.awpr on84.master`
   if ($MssFile[2] == ) then
cat <