#!/usr/bin/expect -f
#
#########################################################################
# Script to get daily NOAA_20CR data from anonymous ftp
# ftp://ftp.cdc.noaa.gov/Datasets/20thC_ReanV2/Dailies
#########################################################################
#
# usage:   [user] [variable] [year]
#
set user "[lindex $argv 0]"
set variable "[lindex $argv 1]"
set year "[lindex $argv 2]"
set pass $user@cerfacs.fr
set path "/pub/Datasets/20thC_ReanV2/Dailies/pressure"

spawn ftp ftp.cdc.noaa.gov
expect "Name* "
send "anonymous\r"
expect "Password*" {send $pass\r}
expect "*ftp>*"

send "cd $path\r"
expect "*ftp>*"

send "get $variable.$year.nc\r"
set timeout 3600
expect "*ftp>*"
close
