#!/bin/ksh 
# 
set -xv

#-----------------------------------------------------------------------------------
# retrieve IPCC simulations from CMIP3/WCRP database
#----------------------------------------------------------------------------------- 

# Pathout to store the datas, to modify...
Pathout=/home/caminade

# Type of experiments: 20c3m, sresa1b...
expid=sresa1b

# Name of the variables to be retrieved (here rainfall and temperature), you can add here other variables

for varin in tas pr

do

# Type of output mo=monthly datas / da=daily datas
type=mo

# model selected (all), you can subset if desired....

for model in bcc_cm1 bccr_bcm2_0 cccma_cgcm3_1 cccma_cgcm3_1_t63 cnrm_cm3 csiro_mk3_0 csiro_mk3_5 gfdl_cm2_0 gfdl_cm2_1 giss_aom giss_model_e_h giss_model_e_r iap_fgoals1_0_g ingv_echam4 inmcm3_0 ipsl_cm4 miroc3_2_hires miroc3_2_medres miub_echo_g mpi_echam5 mri_cgcm2_3_2a ncar_ccsm3_0 ncar_pcm1 ukmo_hadcm3 ukmo_hadgem1

do

#Define the path to retrieve the IPCC datas
indir=$expid/atm/$type/$varin/$model/run1

# if the outdir does not exist then create it
outdir=$Pathout/$expid/$varin/$model/

if [ ! -d $outdir ]; then
mkdir -p $outdir
fi

# Change to output dir and launch the ftp
cd $outdir
getIPCCfile $indir

# Coming back to current directory
cd -

done

done

