'reinit'

**'open /stornext/online3/eta/CLIMATOLOGIA_ERA5/TESTE/MEDIA_DIARIA/Media_diaria_ERA5_U_1990-2021_HS.ctl'
***************'open /stornext/online3/eta/CLIMATOLOGIA_ERA5/ERA5_U_1990-2021_HS/ERA5_hourly_UVEL_HS_template.ctl'
**'sdfopen /stornext/online3/eta/CLIMATOLOGIA_ERA5/SCRIPTS_FIGURAS/ERA5_U_1990_HS.nc'
'open /stornext/online16/etamc/JOAO_FIGUEIREDO/ERA5_U_ANUAL_1990-2021_HS/ERA5_U_ANUAL_UVEL_HS_template_TESTE.ctl'


'!rm -rf VP_ERA5.bin'

'set lat -60'

*****'set gxout fwrite'
*****'set fwrite VP_ERA5.bin'


dias = "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"
meses = "JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
diasmes = "31 28 31 30 31 30 31 31 30 31 30 31"


mes=1
while(mes<=12)
diaf=subwrd(diasmes,mes)
mesm=subwrd(meses,mes)

say diaf' 'mesm

dia=1
while(dia<=diaf)
diam=subwrd(dias,dia)

***TROCAR OS NÍVEIS 1 -37 ERA5 E 31 - 1 GEF***
nivel=1
while (nivel<=37)
'set z 'nivel

'define valor=0'
'define soma=0'

ano=1990
while(ano<=2021)

say '00z'diam%mesm%ano' 'nivel

say '00z'diam%mesm%ano' 'nivel
'set gxout shaded'
'define valor=(ave(u(time=00z'diam%mesm%ano'),lon=-180,lon=179.75)+ave(u(time=06z'diam%mesm%ano'),lon=-180,lon=179.75)+ave(u(time=12z'diam%mesm%ano'),lon=-180,lon=179.75)+ave(u(time=18z'diam%mesm%ano'),lon=-180,lon=179.75))/4'
say 'valor=(ave(u(time=00z'diam%mesm%ano'),lon=-180,lon=179.75)+ave(u(time=06z'diam%mesm%ano'),lon=-180,lon=179.75)+ave(u(time=12z'diam%mesm%ano'),lon=-180,lon=179.75)+ave(u(time=18z'diam%mesm%ano'),lon=-180,lon=179.75))/4'
*'d valor'
*say result
'define soma=soma+valor'
*'d soma'
*say result
ano=ano+1
endwhile

'set gxout fwrite'
'set fwrite -ap VP_ERA5.bin'

***TROCAR soma/NUMERO DE ANOS***
'define media=soma/32'
'd media'
'disable fwrite'
***TROCAR niviel+1 (ERA5) nivel-1 (GEF)***
nivel=nivel+1
endwhile

dia=dia+1
endwhile

mes=mes+1
endwhile

'quit'




