#!/bin/bash

#
# Andrés Sepúlveda 12/2020 (DGEO-UDEC)
#

#
# Se asume que estamos grabando el archivo cada 3 días
#
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

yi=1
yf=2

while [ "$yi" -le "$yf" ]
do
	ncks -F -d time,1,10      "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M1.nc
	ncks -F -d time,11,20     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M2.nc
	ncks -F -d time,21,30     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M3.nc
	ncks -F -d time,31,40     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M4.nc
	ncks -F -d time,41,50     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M5.nc
	ncks -F -d time,51,60     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M6.nc
	ncks -F -d time,61,70     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M7.nc
	ncks -F -d time,71,80     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M8.nc
	ncks -F -d time,81,90     "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M9.nc
	ncks -F -d time,91,100    "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M10.nc
	ncks -F -d time,101,110   "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M11.nc
	ncks -F -d time,111,120   "$model"_"$type"_Y"$yi".nc "$model"_"$type"_Y"$yi"M12.nc
	yi=`expr $yi + 1`
done
exit
