'reinit'
'set display color white'
'open GSMaP_NRT.hourly.rain_2014.ctl'

YEAR  = 2014
STMON = 4
ENMON = 4
STDAY = 29
ENDAY = 30


MONTH=STMON
while(MONTH <= ENMON)
DAY=STDAY
while(DAY <= ENDAY)
HOUR=1
while(HOUR<=24)
'reset'

'set string 1'
'set strsiz 0.23 0.25'
*'set parea 0.5 10.75 0.9 6.0'
*'draw string 0.6 6.4 GSMaP_NRT'
*'draw string 4.1 6.4 TIME='YEAR'/'


if(MONTH>=10)
*'draw string 6.3 6.4 'MONTH'/'
else
*'draw string 6.3 6.4 0'MONTH'/'
endif

if(DAY>=10)
*'draw string 7.0 6.4 'DAY'/'
else
*'draw string 7.0 6.4 0'DAY'/'
endif

if(HOUR>=10)
*'draw string 7.7 6.4 'HOUR-1'/'
else
*'draw string 7.7 6.4 0'HOUR-1'/'
endif

*'set mpdset hires'
*'set gxout grfill'
'set gxout kml'
'set grads off'

ttt=1

'set lat -60 60'
'set lon 0 360'
'set xlint 20'
'set ylint 20'

'define_colors.gs'
'set clevs 0.01 0.1 1 2 3 5 10'
*'set ccols 15 43 35 7 2 0'
'set ccols 1 21 22 23 24 25 26 27 28 29 79'

stime = 0
PREV = 1
while(PREV < MONTH)
if(PREV = 1) ; stime = stime + 744 ; endif
if(PREV = 2) ; stime = stime + 672 ; endif
if(PREV = 3) ; stime = stime + 744 ; endif
if(PREV = 4) ; stime = stime + 720 ; endif
if(PREV = 5) ; stime = stime + 744 ; endif
if(PREV = 6) ; stime = stime + 720 ; endif
if(PREV = 7) ; stime = stime + 744 ; endif
if(PREV = 8) ; stime = stime + 744 ; endif
if(PREV = 9) ; stime = stime + 720 ; endif
if(PREV =10) ; stime = stime + 744 ; endif
if(PREV =11) ; stime = stime + 720 ; endif
if(PREV =12) ; stime = stime + 744 ; endif
PREV=PREV+1
endwhile

ttt = stime + (DAY-1)*24 + HOUR
*'!echo 'ttt''
'set t 'ttt''

'd precip'
*'q pos'

*'cbar.gs'
'!convert -transparent white grads.tif grads.tif'

if(ttt<10);              '!convert -transparent white grads.tif TIFfile/gsmap_nrt0000'ttt'.tif' ; endif
if(ttt>9&ttt<100);       '!convert -transparent white grads.tif TIFfile/gsmap_nrt000'ttt'.tif' ; endif
if(ttt>99&ttt<1000);     '!convert -transparent white grads.tif TIFfile/gsmap_nrt00'ttt'.tif' ; endif
if(ttt>999&ttt<10000);   '!convert -transparent white grads.tif TIFfile/gsmap_nrt0'ttt'.tif' ; endif
if(ttt>9999&ttt<100000); '!convert -transparent white grads.tif TIFfile/gsmap_nrt'ttt'.tif' ; endif

*if(ttt<10);              '!convert -transparent white grads.tif -density 7200 PNGfile/gsmap_nrt0000'ttt'.PNG' ; endif
*if(ttt>9&ttt<100);       '!convert -transparent white grads.tif -density 7200 PNGfile/gsmap_nrt000'ttt'.PNG' ; endif
*if(ttt>99&ttt<1000);     '!convert -transparent white grads.tif -density 7200 PNGfile/gsmap_nrt00'ttt'.PNG' ; endif
*if(ttt>999&ttt<10000);   '!convert -transparent white grads.tif -density 7200 PNGfile/gsmap_nrt0'ttt'.PNG' ; endif
*if(ttt>9999&ttt<100000); '!convert -transparent white grads.tif -density 7200 PNGfile/gsmap_nrt'ttt'.PNG' ; endif

*if(ttt>999&ttt<10000);   '!convert grads.tif -density 7200 PNGfile/gsmap_nrt0'ttt'.JPG' ; endif

'!rm grads.kml'
'!rm grads.tif'

HOUR=HOUR+1
endwhile

DAY=DAY+1
endwhile

MONTH=MONTH+1
endwhile

return