#!/bin/bash

pwd=$PWD

ifort -O3 -zero make_PROMICE.f90 libUN.f -lnetcdf_ifort

#--------------------------------------------------------------------

function make_ave {

 Model=$1

 cd smb
 rm -f smb_${Model}.nc &>/dev/null
ferret <<EOF
use "../GRD-1km.nc"
define axis/t=1980:2012:1 time
define grid/x=lat/y=lat/t=time gg
set mem/size=5000
file/var=smb/col=1/grid=gg smb_${Model}.dat
save/clob/file=smb_${Model}.nc/NCFORMAT=4/DEFLATE=2/SHUFFLE smb
file/var=ru/col=1/grid=gg  ru__${Model}.dat
save/append/file=smb_${Model}.nc/NCFORMAT=4/DEFLATE=2/SHUFFLE ru
quit
EOF
[ -f smb_${Model}.nc ] && rm -f smb_${Model}.dat ru__${Model}.dat

} 

#--------------------------------------------------------------------

#for Model in "dESM_krebs" "MARv3.9.5" "CESM_kampenhout" "BESSI_zolles" "PDD1km_wilton" "PDD5km_hanna" "RACMO_noel" "SNOWMODEL_liston" "HIRHAM_mottram" "MPI-ESM_kapsch" ; do
for Model in "MARv3.9.5" ; do

 cd $pwd

                              mask=3
 [ ${Model:0:3} == "PDD" ] && mask=2
 

 for Mask in `seq 2 $mask` ; do
 echo "$Model" > make_PROMICE.dat
 echo "$Mask"     >> make_PROMICE.dat
 ./a.out &> log/log_${Model}_${Mask}
 done
 
 make_ave ${Model} &

done
