#!/bin/bash

# slurm specific options for Marenostrum4
#SBATCH --qos=debug
#SBATCH -N 1
#SBATCH -n 3
#SBATCH -c 1
#SBATCH -t 1:00:00
#SBATCH --exclusive

#load python and netcdf modules
export PYTHONPATH=""
module load python/3.6.1
module load netcdf/4.2

set -xuve

# setup pyOasis environment
export PYOASIS_ROOT=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/sources/oasis3-mct/generated
export LD_LIBRARY_PATH=${PYOASIS_ROOT}/lib:${LD_LIBRARY_PATH}
export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH}
export MPIRUN4PY="mpirun"

# prepare rundir
rundir=run/
srcdir=`pwd`
datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model

rm -rf $rundir
mkdir -p $rundir

for f in masks.nc grids.nc areas.nc rstas.nc rstos.nc; do
    cp -f $datadir/$f $rundir
done
cp -f $datadir/rmp* $rundir
cp -f $srcdir/*.py $rundir
cp -f $srcdir/namcouple $rundir

cd $rundir

# run IFS+NEMO+runoff toy model
mpirun -np 1 python3 $srcdir/IFS_toy.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py
