#!/bin/bash
#===============================================================================
#
#          FILE:  create_experiment.sh
# 
#         USAGE:  ./create_experiment.sh 
# 
#   DESCRIPTION:  
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:   (), 
#       COMPANY:  
#       VERSION:  1.0
#       CREATED:  15/01/24 16:54:10 EET
#      REVISION:  ---
#===============================================================================

ROOTDIR="$(git rev-parse --show-toplevel)"

ICDIR="$ROOTDIR/nemo/V40/eORCA12_Z75/2020012000"
COMMONDIR="$ROOTDIR/nemo/V40/eORCA12_Z75/common"
XIOSDIR="$ROOTDIR/nemo/V40/eORCA12_Z75/xios"
SCRIPTDIR="$ROOTDIR/scripts"

EXPID=${EXPID:-"`date +%F-%s`"}

EXPDIR="exp-${EXPID}"

FORCINGDIR="$ROOTDIR/nemo_forcing"

cp -Rs $ICDIR $EXPDIR
cp -Rs $COMMONDIR/* $EXPDIR
cp -Rs $XIOSDIR/* $EXPDIR
rm $EXPDIR/namelist*
cp $ICDIR/namelist* $EXPDIR
cp $SCRIPTDIR/rebuild.slurm $EXPDIR
cp $SCRIPTDIR/nam_grid_U $EXPDIR 
cp $SCRIPTDIR/nam_grid_V $EXPDIR 
cp $SCRIPTDIR/nam_grid_T $EXPDIR 
cp $SCRIPTDIR/nam_icemod $EXPDIR 

for var in precip q10 qlw qsw slp snow t10 u10 v10; do for year in 2015 2016 2017 2018 2019; do ln -s ${FORCINGDIR}/${var}_fc00_ERA5_HRES_eORCA12_Z75_${year}.smooth.nc ${EXPDIR}/${var}_y${year}.nc; done; done

sed -i 's/sn_cfctl%l_runstat.*/sn_cfctl%l_runstat = .TRUE./'  $EXPDIR/namelist_cfg
sed -i 's/ln_timing_detail.*/ln_timing_detail = .TRUE./'  $EXPDIR/namelist_cfg
sed -i 's/nn_stock .*=.*/nn_stock = -1/'  $EXPDIR/namelist_cfg
sed -i 's/nn_stocklist.*=.*/nn_stocklist = -9999/'  $EXPDIR/namelist_cfg
sed -i 's!\(<variable id="info_level".*>\).*</variable>!\1-2</variable>!' $EXPDIR/iodef.xml


echo $EXPDIR



