#! /bin/ksh -
#set -x

# This script connects at 
# ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis/ and
# ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis.dailyavgs/
# dowload the specified data files in the specified timeint
#
# NB: Make sure your .netrc file contains the line:
# machine ftp.cdc.noaa.gov login anonymous password 'mailadress'
# 
# The script getNCEPdata.sh must be in the same directory.
# getNCEPdata FIELD FIELDS GETDIR POS STARTYEAR ENDYEAR
# FIELD = Field name in uppercase letters #NLWRS
# FIELDS = Field name in lowercase letters #nlwrs
# GETDIR = Directory at CDC #/Datasets/ncep.reanalysis.dailyavgs/surface_gauss/
# POS = specify the 'last'name of the files like sfc, eatm or clm.
# LOCALDIR = Local directory for downloaded files. Subdirs for each var are created.
# STARTYEAR = first year of the downloaded files.
# ENDYEAR = last year of the dowloaded files.
#
# NB:If you would like to download a single year, 
# use same year for STARTYEAR and ENDYEAR.


LOCALDIR=/work/shared/noresm/inputdata/atm/datm7/IAF_NCEP/NCEP_data_orig/
STARTYEAR=2012
ENDYEAR=2012


# 6-hourly data

# PRES
getNCEPdata.sh PRES pres /Datasets/ncep.reanalysis/surface_gauss/ sfc ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}

# SKT
getNCEPdata.sh SKT skt   /Datasets/ncep.reanalysis/surface_gauss/ sfc ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}

# AIR
getNCEPdata.sh AIR air   /Datasets/ncep.reanalysis/surface_gauss/  2m ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}

# SHUM
getNCEPdata.sh SHUM shum /Datasets/ncep.reanalysis/surface_gauss/  2m ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}

# UWND
getNCEPdata.sh UWND uwnd /Datasets/ncep.reanalysis/surface_gauss/ 10m ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}

# VWND
getNCEPdata.sh VWND vwnd /Datasets/ncep.reanalysis/surface_gauss/ 10m ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}




# Daily average radiation and precipitation data

# DSWRF
getNCEPdata.sh DSWRF dswrf /Datasets/ncep.reanalysis.dailyavgs/surface_gauss/ sfc ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}

# DLWRF
getNCEPdata.sh DLWRF dlwrf /Datasets/ncep.reanalysis.dailyavgs/surface_gauss/ sfc ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}

# PRATE
getNCEPdata.sh PRATE prate /Datasets/ncep.reanalysis.dailyavgs/surface_gauss/ sfc ${LOCALDIR} ${STARTYEAR} ${ENDYEAR}
