# download CMORPH 3hourly corrected
# author: longtt & Roderick van der Linden
year="2002"
#month="01 02 03 04 05 06 07 08 09 10 11 12"
month="08"
#date="01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31"
date="16"
#while [ $yyyy -le 2013 ]
#while [ $yyyy -le 1998 ] ; do
for yyyy in $year ; do
mkdir -p $yyyy
    for mm in ${month} ; do
#        da=28
        for da in $date  ; do
            dd=`printf "%02d" $da`
wget ftp://ftp.cpc.ncep.noaa.gov/precip/CMORPH_V1.0/CRT/0.25deg-3HLY/${yyyy}/${yyyy}${mm}/CMORPH_V1.0_ADJ_0.25deg-3HLY_${yyyy}${mm}${dd}.bz2
                for fil in CMORPH_V1.0_ADJ_0.25deg-3HLY_${yyyy}${mm}${dd}.bz2 CMORPH_V1.0_ADJ_0.25deg-DLY_00Z_${yyyy}${mm}${dd}.bz2 ; do
                   bunzip2 $fil
                    export y=${yyyy}
                    export m=${mm}
                    export d=${dd}
                    export h=00
                done
        done
    done
mv CMORPH_V1.0_ADJ_0.25deg-3HLY_${yyyy}* $yyyy
done
exit
