#!/bin/ksh
#
#---------------------------------------
# ksh job run in Hexagon
#---------------------------------------
#
#PBS -A nn9039k
#PBS -W group_list=noresm
#PBS -N timeseries
#PBS -l select=1:ncpus=32
#PBS -l walltime=20:00:00
#PBS -j oe
#PBS -S /bin/ksh
#
set -xe
#
typeset -Z2 monat    
# what does this typeset?
# loading modules in NorStore for ksh
#. /opt/modules/default/init/ksh
#module load cdo

cdo setyear,2007 u_10_CAM4eqmeanSSTmean.nc ncep.u_10.T62.2007.nc
cdo setyear,2007 v_10_CAM4eqmeanSSTmean.nc ncep.v_10.T62.2007.nc

# -----------
#
# Use the shiftime loop here for creating files for every year
#
# ----------

iyr=2007
eyr=1977

i=$iyr
while [ ${i} -ge $eyr ] ; do
echo $i
#
# Select the variables one by one and creating one file per variable and year
cdo shifttime,-365day ncep.u_10.T62.${i}.nc ncep.u_10.T62.$(($i - 1)).nc
cdo shifttime,-365day ncep.v_10.T62.${i}.nc ncep.v_10.T62.$(($i - 1)).nc

# Advancing to the next timestep (year)
i=`expr ${i} - 1`
done

