#!/bin/bash

## Just run code in recipes, use it carefully
## example: use cdo to make cache file. Since cdo is quicker than ncl.
#;DIAG_NORCPM; RUNTHESECODES: echo '    no codes run here.'

## make model and HadISST2 climatology
## ccipc2 env
module purge
module load cdo_gcc-7.5.0/1.9.8

## make model climatology
ofn=model_TS_cli.nc
if [ ! -f $ofn ];then
    filelist=$(ls /trd-project4/NS9039K/shared/pgchiu/archive/norcpm_ana_f09_tn14//*/atm/hist/*.h0.{1980..2020}-??.nc | sort )
    cdo -s -ymonmean -select,name=TS $filelist $ofn 
fi
## make HadISST mean climatology
ofn=obs_sst_cli.nc
if [ ! -f $ofn ];then
    ##filelist=$(ls ~/work/HadISST_2.1.0.0/*.nc)
    ##cdo -s -ymonmean -vertavg -select,name=sst $filelist $ofn 
    filelist=$(ls ~/NS9039K/shared/HadISST/HadISST_sst.nc)
    cdo -s -ymonmean -setattribute,sst@units="degC" -addc,273.15 -setmissval,-1000 -selyear,1980/2020 -select,name=sst $filelist $ofn 
fi
## diff
ofn=dif_sst.nc
if [ ! -f $ofn ];then
    cdo -sub -selvar,TS model_TS_cli.nc -remapbic,model_TS_cli.nc -selvar,sst obs_sst_cli.nc $ofn
fi


