#!/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

iyr=2009
eyr=1948	

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 giss.swup.T62.${i}_daymean.nc giss.swup.T62.$(($i - 1))_daymean.nc
# Split all the days of the year and modify the first one (which is wrong)
cdo setyear,$(($i - 1)) giss.swup.T62.$(($i - 1))_daymean.nc giss.swup.T62.$(($i - 1))_daymean_temp.nc
cdo settime,12:00:00 giss.swup.T62.$(($i - 1))_daymean_temp.nc giss.swup.T62.$(($i - 1))_daymean.nc
# NOT SURE THE PREVIOUS LINES WORK THE WAY I WANT TO, CHECK IT OUT

# Advancing to the next timestep (year)
i=`expr ${i} - 1`
done
rm   giss.swup.T62.1947_daymean.nc
rm   giss.swup.T62.**_temp.nc
