#!/bin/ksh
###############################################################################
#                              RUN EC_EARTH
###############################################################################
#
#
#@ job_name         = run_t159l62_uncoup
#@ wall_clock_limit = 00:30:00
#@ output           = run_t159l62_uncoup_%j.out
#@ error            = run_t159l62_uncoup_%j.err
#@ total_tasks      = 28
#@ initialdir       = .
#@ tasks_per_node   = 4

# General settings

set -xuv
date

ECEARTH=/gpfs/projects/ecm86/models/ecearth/v2.3.0
SCRIPTDIR=$ECEARTH/setup
PATH=${SCRIPTDIR}:${PATH}
TESTDATADIR=$ECEARTH/inidata/testdata
WRITINGDIR=/gpfs/scratch/ecm86/ecm86010/test
RUN_dir=$WRITINGDIR/run_t159l62_uncoup_$SLURM_JOBID

# Resolution dependent part

IFS_resolution=T159L62
RUN_length_prev=0
FCLENGTH=48
WAM=false
NPROCIFS=28
COUPFREQ=6
NPROMA=40
LLAST=.TRUE.
NPRTRVIFS=1
EXPID=b0if
LFASTRES=.FALSE.
ADVSCH=cen2
NFRP=6
LCMIP5=.TRUE.
NRCP=0

# Bin path

IFSEXE=$ECEARTH/bin/ifsMASTER

# Run setup

if [[ ${RUN_length_prev} = '0' ]]; then
  mkdir -p ${RUN_dir} || true
  rm -fr ${RUN_dir}/*
fi
cd ${RUN_dir}

export LOCAL_DEFINITION_TEMPLATES=$ECEARTH/sources/ifs/src/emos/local_definitions
export MBX_SIZE=512000000

EXPVER=$(setupifs.ksh -r ${IFS_resolution} -e $ECEARTH/sources -l $FCLENGTH -n $NPROCIFS -w $WAM -p $NPROMA -c $COUPFREQ -o $LLAST -0 $TESTDATADIR -1 $NPRTRVIFS -2 ${EXPID} -3 $LFASTRES -4 $NFRP -5 $LCMIP5 -6 $NRCP)

# Execution

export OASIS3=simulate
export OASIS3DEBUGLEVEL=3
export DR_HOOK_IGNORE_SIGNALS='-1'

ulimit -c 1000000

time srun -n $NPROCIFS -l ${IFSEXE} -v ecmwf -e ${EXPVER}
date
