
'reinit'
'set display color white'
'clear'

dirindice="/dados/grpeta/Team/Priscila/PCNPq/correcao/data/eta_cmip5/Eta_HadGEM2-ES_cor/RCP8.5/2071-2099/PREC"
dirout="/dados/grpeta/Team/DiegoChagas/IndicesExtremos/Eta_HadGEM2-ES_cor_mensal/RCP8.5"

nmes = 'JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC'
fmes = '30 30 30 30 30 30 30 30 30 30 30 30'

'open 'dirindice'/Eta_HadGEM2-ES_20km_RCP8.5_Diario_PREC_corr_template.ctl'

'set x 1 355'
'set y 1 390'

ano=2071
while(ano<=2099)
mes=1
while(mes<=12)

fm=subwrd(fmes,mes)

nm=subwrd(nmes,mes)

if(mes < 10); mes = '0'%mes; endif

dt='01'% nm % ano

'set time 'dt
'q dims'
aux=sublin(result,5)
dia=subwrd(aux,9)

'set gxout fwrite'
'set fwrite 'dirout'/Eta_HadGEM2-ES_prec3_'%mes''%ano'.bin' 

i=1
while(i<=fm)
'define acumP=prec(t='dia')'
'd acumP' 
i=i+1
dia=dia+1
endwhile

'disable fwrite'
mes=mes+1

   
endwhile
ano=ano+1

endwhile
'quit'

 
