#!/bin/env bash

set -ex

pool_dir=/project/s1032
gridreffile=/project/s1032/JSBACH_pool/input/r0010/T127/land_use_maps/cover_fract_T127_11tiles_1982.nc

cdo griddes -selvar,soil_layer_depth ${gridreffile} > grid1.dat
cdo griddes -selvar,cover_fract ${gridreffile} > grid2.dat

for year in $(seq 1369 2015); do 

   cdo selvar,soil_layer_depth ${pool_dir}/JSBACH_pool/input/r0010/T63/land_use_maps/cover_fract_T63_11tiles_${year}.nc tmp.1d.nc
   cdo selvar,cover_fract,cover_type ${pool_dir}/JSBACH_pool/input/r0010/T63/land_use_maps/cover_fract_T63_11tiles_${year}.nc tmp.2d.nc   

   cdo merge tmp.1d.nc tmp.2d.nc T127/cover_fract_T127_11tiles_${year}.nc

   rm tmp.?d.nc

done


exit 0
