#!/bin/csh
#
# NAME:  get_ncep_data.csh
#
# PURPOSE:  To use ftp to retrieve NCEP reanalysis data from the CDC ftp site.
#
# CALLING SEQUENCE:  ftp_ncep_data <4 digit year>
#
# RESTRICTIONS: Places ncep netcdf files into directory where script is run.
#
# CREATION HISTORY:  Darren Jackson ETL/CIRES March 2002
#
#----------------------------------------------------------------------------------
#
#### Command line inputs  #########
set year = $1

######### Adjustable parameters ##############
set parm = (air shum air.sig995 pres.sfc)

####### Establish subdirectory type by year
#if($year >= 1974 && $year <= 1986) set archive = archive2
#if($year >= 1987 && $year <= 1999) set archive = archive3
#if($year >= 2000) set archive = archive4

######## Loop for each parameter ############
foreach field ( $parm )

####### Establish directory path
  if($field == air || $field == shum) then
     set dpath = /Datasets/ncep.reanalysis/pressure
  endif
  if($field == air.sig995 || $field == pres.sfc) then
     set dpath = /Datasets/ncep.reanalysis/surface
  endif

###### Establish file name #################
  set fname = ${field}.${year}.nc

  echo "start file transfer of file "$fname
##### Embark on FTP session #################
  ftp -n ftp.cdc.noaa.gov <<EOF
  user anonymous Darren.L.Jackson@noaa.gov
  cd $dpath
  binary
  get $fname
  quit
EOF

  sleep 15
  echo "Completed transfer of file "$fname
end
