#!/bin/bash 

var=TMAX

exp1=ERA
exp2=GFS
exp3=BAN

datai=20200802
dataf=20210131


scr=`pwd`

ctl_exp1=/dados/ioper/tempo/CRNG/SAMeT/ERA5/$var/$var.ctl
ctl_exp2=/share/ioper/tempo/CRNG/users/ROZANTE/AVAL_GFS_WRF_ERA5/GFS_to_ERA5/GFS_to_ERA5_F24.ctl
ctl_exp3=/share/ioper/tempo/CRNG/users/ROZANTE/AVAL_GFS_WRF_ERA5/BAN_to_ERA5/BAN_to_ERA5_F24.ctl 


obs=/dados/ioper/tempo/CRNG/SAMeT/OBS/$var

out=$scr/${exp1}x${exp2}x${exp3}/F24/${var}
mkdir -p $out
cd $obs

while [ $datai -le $dataf ] ; do
   rm -f $out/tab_${datai}.txt
   DCTL=$(date -u -d "${datai} 00:00 00 hours " +"%H"Z"%d%b%Y")
   grads -blc "run $scr/gera_tabela.gs $datai $DCTL $ctl_exp1 $ctl_exp2  $ctl_exp3 $obs/${datai:0:6}/${var}_${datai}.txt $exp1 $exp2 $exp3 $out $var  "
   datai=`date -d "${datai:0:8} 00:00 24 hours" +"%Y%m%d"`
done
cd $out
cat tab_*.txt|sort -u |grep -v data > completo_${exp1}x${exp2}x${exp3}.txt
exit
