#!/bin/bash

case=noresm1-cmip6_historical_19500101
indir=/trd-project4/NS9039K/shared/norcpm/cases/NorESM1-CMIP6/$case
outfile=noresm1-cmip6_hist_sst_clm12_1981-2010.nc
## for ref.
gridfile=/trd-project4/NS9039K/shared/pgchiu/diag_norcpm/grid_norcpm1_ocn.nc

## mean of every jan, feb, ...
for m in {01..12}; do
    echo $m.nc
    time ncra -F -H -v sst $indir/${case}_mem??/ocn/hist/${case}_mem??.micom.hm.{1981..2010}-${m}.nc $m.nc |grep -v nco_inq_filter_avail
    ## need shift time if number of year is not single (time will be averaged too)
    cdo -shifttime,'-183day' ${m}.nc ${m}-time.nc && rm -f ${m}.nc
done

ncrcat ??-time.nc $outfile && rm ??-time.nc
