#!/bin/bash

set -ex

cdo=/usr/bin/cdo
tmpdir_base="/scratch3/ralf/spielwiese"

setlist="HIPPO_set_1850_1 HIPPO_set_1850_2 HIPPO_set_1850_3 HIPPO_set_1850_4"
# setlist="HIPPO_set_1850_2 HIPPO_set_1850_3 HIPPO_set_1850_4"
setlist="HIPPO_set_1420_1"
# setlist="HIPPO_set_1850_all_HadISST"
varlist="temp2 totprec slp"
varlist="tsurf"

olddir=$(pwd)

for set in ${setlist}; do

   cd ${set}

   for exp in $(ls -d HIPPO_r*i*p*f*); do
      for var in ${varlist}; do

         # tmp=$(mktemp -d ${tmpdir_base}/tmp.compute_timmeans_timeseries.XXX)

         if [ ! -d ${exp}/timeseries/year ]; then mkdir -p ${exp}/timeseries/year; fi
         cdo yearmean ${exp}/timeseries/mon/${exp}_${var}_mon.nc ${exp}/timeseries/year/${exp}_${var}_year.nc
 
         if [ ! -d ${exp}/timeseries/seas ]; then mkdir -p ${exp}/timeseries/seas; fi
         cdo seasmean ${exp}/timeseries/mon/${exp}_${var}_mon.nc ${exp}/timeseries/seas/${exp}_${var}_seas.nc

      done # var
   done # exp

   cd ..  # leave ${set}

done # set in setlist

exit 0
