#!/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.'

cases='TBI_NUG_Ano TBI_NUG_FF TBI_N2_Ano_w2 TBI_N2_FF_w2'
for s in '_' '_MAM_' '_JJA_'; do
for p in 1980-2000 2000-2020 1980-2020; do
for i in $cases ;do
    ii=$(echo $i | sed 's/TBI_//')
    fig="21_prec/cor_ens_${ii}_PRECT-GPCP${s}${p}.png"
    src="../../${i}/${fig}"
    dst="cor_ens_${i}_PRECT-GPCP${s}${p}.png"
    tsrc=$(echo $src | sed -e's/.png/_thumb.png/')  
    tdst=$(echo $dst | sed -e's/.png/_thumb.png/')  
    cp -v "$src" "./$dst"
    cp "$tsrc" "./$tdst"
done
done
done
ln -sf ../../TBI_NUG_FF/21_prec/gpcp_prec_atm_grid_1980-2020.nc ./  ## for lower resolution
cdo -O -selyear,1980/2000  "gpcp_prec_atm_grid_1980-2020.nc" "gpcp_prec_atm_grid_1980-2000.nc"
cdo -O -selyear,2000/2020  "gpcp_prec_atm_grid_1980-2020.nc" "gpcp_prec_atm_grid_2000-2020.nc"

## for sst of each member
for i in $cases ;do
for j in ../../${i}/01_sst_regional-cor/sst_??.nc; do
  jj="$(basename $j)"
  ln -sf ${j} ./${i}_${jj}
done
done


