#!/bin/ksh
###############################################################################
#                              RUN EC_EARTH
###############################################################################
#
#$ -N run_t159l62_uncoup
#$ -cwd
#$ -S /bin/ksh
#$ -V
#$ -pe orte 32
#

# modules setup
source /opt/modules/init/ksh
module load intel/13.0.1
module load openmpi/1.6-intel # OpenMPI
#module load intel/4.0.3.008 # Intel MPI
# tell OpenMPI to only use infiniband
export OMPI_MCA_btl=sm,self,openib

# General settings

set -xuv
date

ECEARTH=/scratch/cfu/models/ecearth/v2.3.0
SCRIPTDIR=$ECEARTH/setup
BINDIR=$ECEARTH/bin
PATH=${SCRIPTDIR}:${PATH}
TESTDATADIR=$ECEARTH/inidata/testdata
WRITINGDIR=/scratch/cfu/$USER/test
RUN_dir=$WRITINGDIR/run_t159l62_uncoup_$JOB_ID

# 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)

mpirun -np ${NPROCIFS} ${IFSEXE} -v ecmwf -e ${EXPID}

t2=$(date +%s)

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

date
