#!/bin/sh
set -x

#
# Adaptado del código de Vincent Echevin (IRD)
#
# Correcion typo Cristian Rojas (12/01/2022)
#
ml purge
ml icc/2018.5.274-GCC-8.2.0-2.31.1 impi/2018.4.274 NCO/4.7.6

export model=croco
export type=avg


mi=1
mf=12
while test "$mi" -le "$mf"
do
y0=1
yi=1
yf=2


while test "$yi" -le "$yf"
do
ncra  "$model"_"$type"_Y"$yi"M"$mi".nc "$model"_y"$yi".nc
yi=`expr $yi + 1`
done
if test "$yf" -ge 10
then
ncrcat  "$model"_y?.nc "$model"_y??.nc "$model"_yall.M"$mi".a.nc
else
ncrcat  "$model"_y?.nc  "$model"_yall.M"$mi".a.nc
fi
ncra    "$model"_yall.M"$mi".a.nc   "$model"_M"$mi".nc
\rm  "$model"_y*.nc
mi=`expr $mi + 1`
done
ncrcat "$model"_M?.nc "$model"_M1?.nc "$model"_"$type".mean.nc
\rm  "$model"_M*nc
exit




