#!/bin/ksh
YYYY=2024
MM=SEP
df=04
gribmap -i /share/ioper/tempo/MERGE/GPM/DAILY/MERGE_CPTEC_2024.ctl

cat << Eof >gera_fig_reuniao_climatica.gs
'set display grey white'
'set display color'
'c'
'open /share/ioper/tempo/MERGE/GPM/DAILY/MERGE_CPTEC_2024.ctl'
'open /share/ioper/tempo/MERGE/GPM/CLIMATOLOGY/DAILY_AVERAGE/MERGE_CPTEC_mean_daily.ctl'
'open mask_brasil.ctl'
'br=lterp(mk.3(t=1),lat.1(t=1))'
'set lat -35 6' 
'set lon -75 -33'
'set mpdset brmap_hires'
'acum=sum(prec,time=12z01${MM}${YYYY},time=12Z${df}${MM}${YYYY})'
'clim=sum(pmed.2,time=12z01${MM}2023,time=12Z${df}${MM}2023)'

'color  -80 80 10 -kind saddlebrown->white->darkgreen -xcbar 0.5 8.0 0.6 0.8 -fw 0.14 -fh 0.14 -edge rectangle -line off -fs 2'
'set gxout shaded'
'anomalia=lterp(acum-clim,mk.3(t=1))'
'set grads off'
'set grid off'
'd maskout(anomalia,mk.3(t=1))'
'draw title MERGE \ Anomalia de Precipitacao \ 01 ate $df - ${MM}'
'printim Prec_Anomalia_${MM}.png'

'c'
color='(255,255,255)->(2,1,129)->(51,102,255)->(1,204,255)->(30,156,129)->(1,108,2)->(93,187,2)->(170,255,151)->(254,255,127)->(254,205,6)->(255,142,12)->(255,1,1)->(187,2,1)->(255,1,255)->(255,152,205)->(165,145,170)->(130,130,130)'
'color 10 200 10 -kind 'color' -xcbar 0.5 8.0 0.6 0.8 -fw 0.14 -fh 0.14 -edge rectangle -line off -fs 2'
'set gxout shaded'
'set grads off'
'set grid off'
'd maskout(lterp(acum,mk.3(t=1)),mk.3(t=1))'
'draw title MERGE \ Precipitacao Acumulada \ 01 ate $df - ${MM}'
'printim Prec_Acumulada_${MM}.png'



'quit'
Eof

grads -pc "run gera_fig_reuniao_climatica.gs"
rm -f gera_fig_reuniao_climatica.gs
exit
