#!/bin/bash

#SBATCH -n 1
#SBATCH -t 120:00:00
#SBATCH -J glosea5_O25L75
#SBATCH --mail-user <eleftheria.exarchou@ic3.cat>
#SBATCH --mail-type FAIL
#SBATCH -o glosea5_O25L75-%j.out
#SBATCH -e glosea5_O25L75-%j.err

set -evx
TMPDIR=/scratch/$(whoami)/$$
mkdir $TMPDIR
cd $TMPDIR

year=1994
mon=05

((mon1=$mon -1 ))


cp /home/Earth/$(whoami)/git-stuff/cfutools/prep_restarts/generate_restarts_gs5_HR/19940501/script_interp_vert_ocean_restart_GS5_ORCA025L75.bash  . 
ln -sf /cfunas/exp/MetOffice/GS5/restarts/${year}/${year}${mon}01__restart00.tar  ${year}${mon}01__restart00.tar  
ln -sf /cfu/autosubmit/con_files/mesh_mask_nemo.Ec3.0_O25L75_ClosedSeas.nc mesh_mask_nemo.Ec3.0_O25L75_ClosedSeas.nc 
ln -sf /cfu/autosubmit/con_files/new_mask.GloSea5_O25L75.nc mask_GS5.nc
ln -sf /cfu/pub/scripts/prep_restarts/auxfiles/masks/Tofill_ecearth.v3.0.ORCA025L75.extrap.glosea5.nc Tofill_extrap.nc 
ln -sf /cfu/pub/scripts/prep_restarts/auxfiles/masks/Tofill_ecearth.v3.0.ORCA025L75.clim.glosea5.nc   Tofill_clim.nc  

tar xvf  ${year}${mon}01__restart00.tar  
gunzip restart.nc.gz

./script_interp_vert_ocean_restart_GS5_ORCA025L75.bash  restart  restart_out  11 

ncecat -O -h restart_out.nc    tmp1.nc
ncrename -d record,t  tmp1.nc  tmp2.nc
cdo setmisstoc,0  tmp2.nc      GLOSEA5_fc0_${year}0${mon1}30_restart.nc

gzip -c GLOSEA5_fc0_${year}0${mon1}30_restart.nc > GLOSEA5_fc0_${year}0${mon1}30_restart.nc.gz  
mv  GLOSEA5_fc0_${year}0${mon1}30_restart.nc.gz  /cfu/releases/ic/ocean/ORCA025L75/GLOSEA5/





