#set -x

# User defined
diret='/stornext/online13/ocean/simulations/forced/cmip6a/mom6/exp006/Artigo/history'
outpath='.'
year_ini=2000
year_end=2009
nome_exp='exp006'
# end: User defined

source $MODULESHOME/init/sh
module load cdo/1.8.2_cmor2

for iarq in `seq 6 7`
do
  if [ "$iarq" == "1" ]; then
    nomearq='ocean_month_ts_z'
  fi
  if [ "$iarq" == "2" ]; then
    nomearq='ocean_month_tsa_z'
  fi
  if [ "$iarq" == "3" ]; then
    nomearq='ocean_month_u_z'
  fi
  if [ "$iarq" == "4" ]; then
    nomearq='ocean_month_v_z'
  fi
  if [ "$iarq" == "5" ]; then
    nomearq='ocean_month_ua_z'
  fi
  if [ "$iarq" == "6" ]; then
    nomearq='ocean_month_va_z'
  fi
  if [ "$iarq" == "7" ]; then
    nomearq='ocean_month'
  fi

for i in `seq $year_ini $year_end`
do
 cp ${diret}/${nomearq}_${i}_*.nc .
echo cdo -O --no_warnings mergetime ./${nomearq}_${i}_??.nc ${outpath}/tmp.nc
     cdo -O --no_warnings mergetime ./${nomearq}_${i}_??.nc ${outpath}/tmp.nc
echo cdo -O yearmean ${outpath}/tmp.nc ${outpath}/${nome_exp}_${nomearq}_${i}.nc
     cdo -O yearmean ${outpath}/tmp.nc ${outpath}/${nome_exp}_${nomearq}_${i}.nc
 rm ./${nomearq}_${i}_??.nc ${outpath}/tmp.nc
echo
echo
done
echo
echo
done
