#!/bin/csh
#################################################################
# Csh Script to retrieve online Data from the UCAR server.
# This script uses 'wget' to download data.
#
# You need pass in your password as a parameter to execute
# this script; or you can set an environment variable RDAPSWD
# if your Operating System supports it.
#
# Contact grace@ucar.edu (Grace Peng) for further assistance.
#################################################################
 
set pswd = $1
if(x$pswd == x && `env | grep RDAPSWD` != '') then
set pswd = $RDAPSWD
endif
if(x$pswd == x) then
echo
echo Usage: $0 YourPassword
echo
exit 1
endif
set v = `wget -V |grep 'GNU Wget ' | cut -d ' ' -f 3`
set a = `echo $v | cut -d '.' -f 1`
set b = `echo $v | cut -d '.' -f 2`
if(100 * $a + $b > 109) then
set opt = 'wget --no-check-certificate'
else
set opt = 'wget'
endif
set opt1 = '-O /dev/null --save-cookies auth.rda_ucar_edu --post-data'
set opt2 = "email=rlt@nilu.no&passwd=$pswd&action=login"
$opt $opt1="$opt2" https://rda.ucar.edu/cgi-bin/login
set opt1 = "-N --load-cookies auth.rda_ucar_edu"
set opt2 = "$opt $opt1 http://rda.ucar.edu/data/ds083.2/"
set filelist = ( \
  grib2/2012/2012.12/fnl_20121201_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121201_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121201_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121201_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121202_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121202_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121202_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121202_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121203_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121203_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121203_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121203_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121204_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121204_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121204_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121204_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121205_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121205_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121205_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121205_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121206_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121206_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121206_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121206_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121207_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121207_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121207_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121207_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121208_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121208_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121208_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121208_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121209_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121209_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121209_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121209_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121210_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121210_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121210_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121210_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121211_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121211_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121211_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121211_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121212_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121212_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121212_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121212_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121213_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121213_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121213_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121213_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121214_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121214_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121214_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121214_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121215_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121215_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121215_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121215_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121216_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121216_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121216_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121216_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121217_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121217_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121217_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121217_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121218_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121218_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121218_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121218_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121219_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121219_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121219_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121219_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121220_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121220_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121220_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121220_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121221_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121221_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121221_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121221_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121222_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121222_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121222_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121222_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121223_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121223_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121223_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121223_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121224_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121224_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121224_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121224_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121225_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121225_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121225_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121225_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121226_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121226_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121226_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121226_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121227_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121227_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121227_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121227_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121228_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121228_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121228_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121228_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121229_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121229_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121229_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121229_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121230_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121230_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121230_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121230_18_00.grib2 \
  grib2/2012/2012.12/fnl_20121231_00_00.grib2 \
  grib2/2012/2012.12/fnl_20121231_06_00.grib2 \
  grib2/2012/2012.12/fnl_20121231_12_00.grib2 \
  grib2/2012/2012.12/fnl_20121231_18_00.grib2 \
)
while($#filelist > 0)
  set syscmd = "$opt2$filelist[1]"
  echo "$syscmd ..."
  $syscmd
  shift filelist
end
 
rm -f auth.rda_ucar_edu
exit 0
