#!/bin/ksh
  
edatei=20040101
edatef=20041231

#dir_in=/pesq/share/oceanwave/dist/MONAN/MERRA2
dir_in=/pesq/share/monan/ocean_model/dados/merra2
dir_out=/pesq/share/monan/ocean_model/merra2_3-hour

edate=$edatei

while [ $edate -le $edatef ]; do

mkdir -p ${dir_out}/${edate:0:4}
echo ${edate:0:4}-${edate:4:2}-${edate:6:2}

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/PCIP_${edate}.nc ${dir_out}/${edate:0:4}/PCIP_3-hour_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/LWNT_${edate}.nc ${dir_out}/${edate:0:4}/LWNT_3-hour_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/QV10M_${edate}.nc ${dir_out}/${edate:0:4}/QV10M_3-hour_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/SWNT_${edate}.nc ${dir_out}/${edate:0:4}/SWNT_3-hour_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/T10M_${edate}.nc ${dir_out}/${edate:0:4}/T10M_3-hour_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/TS_${edate}.nc ${dir_out}/${edate:0:4}/TS_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/U10M_${edate}.nc ${dir_out}/${edate:0:4}/U10M_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/V10M_${edate}.nc ${dir_out}/${edate:0:4}/V10M_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/LWGAB_${edate}.nc ${dir_out}/${edate:0:4}/LWGAB_${edate}.nc

#cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/PRECCUCORR_${edate}.nc ${dir_out}/${edate:0:4}/PRECCUCORR_${edate}.nc

cdo selhour,0,3,6,9,12,15,18,21 -settaxis,${edate:0:4}-${edate:4:2}-${edate:6:2},00:00:00,1hour ${dir_in}/${edate:0:4}/SLP_${edate}.nc ${dir_out}/${edate:0:4}/SLP_${edate}.nc

edate=$(date -u "+%Y%m%d" -d "${edate:0:8} 00:00 24 hour")
done
