#!/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
## env for cdo
source /projects/NS9039K/shared/python3env/etc/p3env.sh


## make model climatology
ofn=model_TS_cli.nc
if [ ! -f $ofn ];then
    filelist=$(ls /trd-project4/NS9039K/shared/norcpm/cases/NorCPM/norcpm-cmip6_analysis_19500115/*/atm/hist/*.h0.{1982..2000}-??.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 /trd-project4/NS9039K/shared/HadISST/HadISST_sst.nc)
    cdo -s -ymonmean -setattribute,sst@units="degC" -addc,273.15 -setmissval,-1000 -selyear,1982/2000 -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


