#!/bin/bash
#
IN=/data/pub/CWRF/hindcast/daily 
OUT=/data/pub/CWRF/hindcast/monthly
#
var=' RH ASWDNS axsmtg '
#


# years="$@"
# years=2016
# years=' 2012 2013 '
years=`seq 2012 2017`
#
md=' 0101 0106 0111 0116 0121 0126 0131 0205 0210 0215 0220 0225 0302 0307 0312 0317 0322 0327 0401 0406 0411 0416 0421
 0426 0501 0506 0511 0516 0521 0526 0531 0605 0610 0615 0620 0625 0630 0705 0710 0715 0720 0725 0730 0804 0809 0814 0819
 0824 0829 0903 0908 0913 0918 0923 0928 1003 1008 1013 1018 1023 1028 1102 1107 1112 1117 1122 1127 1202 1207 1212 1217
 1222 1227  '

for y in $years; do
  for mn in ${md}; do
    # for s in 00 06; do
    for s in 06; do
      if [ "$s" == "06" ]; then
        exps="00 02"
      else
        exps="00"
      fi

      for exp in $exps; do
        for V in ${var}; do
	echo "Processing year=$y, month=$mn, s=$s, exp=$exp, var=$V ..."
        cdo  -P 4 -f nc monmean ${IN}/${y}/${y}${mn}/${y}${mn}${s}_icbc01_exp${exp}_${V}_daily.nc ${OUT}/${y}${mn}_${s}Z_icbc01_exp${exp}_${V}_monthly.nc


        done
      done
    done
  done
done
