# author: Roderick van der Linden & Trinh Tuan Long 
#!/bin/bash
### Job name
#PBS -N Extract_PERSIANN
#PBS -q serial_q 
#PBS -l nodes=1:ppn=1
#PBS -o z.out
#PBS -e z.err
#PBS -V
# 
year="2001"
month="01"
#year="2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015"
#month="01 02 03 04 05 06 07 08 09 10 11 12"
for y in $year ; do
  for mo in $month ; do
        multiget -l ftp://data.ncdc.noaa.gov/cdr/persiann/files/${y}/PERSIANN-CDR_v01r01_${y}${mo}*.nc
        cdo -r mergetime PERSIANN-CDR_v01r01_${y}${mo}??_?????????.nc PERSIANN-CDR_v01r01_${y}${mo}.nc
        rm PERSIANN-CDR_v01r01_${y}${mo}??_?????????.nc
        cdo sellonlatbox,70,140,-15,40 PERSIANN-CDR_v01r01_${y}${mo}.nc temp.nc
        mv temp.nc PERSIANN-CDR_v01r01_${y}${mo}.nc
  done
done
