#!/bin/sh

# This is a template of script for calculation of dynamical trends
# Assumes that  the programs zanalogsphi.f90 has been compiled into zanalogsphi.e

m=ACCESS-CM2_r1i1p1f1.hssp585
iread=0

# mkdir -p $SCRATCHDIR/HEATTRENDS/ancors.$m
# ln -sf $SCRATCHDIR/HEATTRENDS/ancors.$m ancors.$m
mkdir -p ancors.$m
mkdir -p TRENDS

# echo $iread "'"$m"'" "'"tmp/phi500_dom.ano.$m.nc"'" "'"tmp/phi500_dom.ano.$m.nc"'" "'"models/tasmax.$m.eur.jja.nc"'" "'"models/tasmax.$m.eur.jja.nc"'" "'"covariates/SGSAT1950-2022.$m.dat"'" "'"covariates/SGSAT1950-2022.$m.dat"'" | zanaloguesphi.e
echo $iread "'"$m"'" "'"tmp/phi500_dom.ano.$m.nc"'" "'"tmp/phi500_dom.ano.$m.nc"'" "'"models/tasmax.$m.eur.jja.nc"'" "'"models/tasmax.$m.eur.jja.nc"'" "'"covariates/SGSAT.$m.dat"'" "'"covariates/SGSAT.$m.dat"'" | zanaloguesphi.e

gawk '{print $3}' TRENDS/txm.$m.trends.dat | cdo -s -f nc input,GRID_TAS tmp/t$m.nc ; cdo -s setvrange,-100,100 tmp/t$m.nc TRENDS/txm.trend.$m.trends.nc
gawk '{print $4}' TRENDS/txm.$m.trends.dat | cdo -s -f nc input,GRID_TAS tmp/t$m.nc ; cdo -s setvrange,-100,100 tmp/t$m.nc TRENDS/txm.trdyn.$m.trends.nc

gawk '{print $3}' TRENDS/txx.$m.trends.dat | cdo -s -f nc input,GRID_TAS tmp/t$m.nc ; cdo -s setvrange,-100,100 tmp/t$m.nc TRENDS/txx.trend.$m.trends.nc
gawk '{print $4}' TRENDS/txx.$m.trends.dat | cdo -s -f nc input,GRID_TAS tmp/t$m.nc ; cdo -s setvrange,-100,100 tmp/t$m.nc TRENDS/txx.trdyn.$m.trends.nc
