#!/bin/ksh
###############################################################################
#                              RUN EC_EARTH
###############################################################################
#PBS -N run_t159l62_uncoup
#PBS -l mppwidth=32
#PBS -l mppnppn=24
#PBS -o /cfs/klemming/nobackup/a/asifsami/models/ecearth/v2.3.0/scripts/
#PBS -e /cfs/klemming/nobackup/a/asifsami/models/ecearth/v2.3.0/scripts/
#PBS -l walltime=00:30:00
#

# General settings

set -xuv
date

ECEARTH=/cfs/klemming/nobackup/a/asifsami/models/ecearth/v2.3.0
SCRIPTDIR=$ECEARTH/setup
BINDIR=$ECEARTH/bin
PATH=${SCRIPTDIR}:${PATH}
TESTDATADIR=$ECEARTH/inidata/testdata
WRITINGDIR=/cfs/klemming/scratch/a/asifsami/test
RUN_dir=$WRITINGDIR/run_t159l62_uncoup_${PBS_JOBID}

# Resolution dependent part

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

# Bin path

IFSEXE=$BINDIR/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 -s unlimited

t1=$(date +%s)

aprun -n $NPROCIFS ${IFSEXE} -v ecmwf -e $EXPVER

t2=$(date +%s)

tr=$(date -d "0 -$t1 sec + $t2 sec" +%T)

date
