#!/bin/ksh

nemo_i=6
nemo_j=6

while getopts i:j: option
do
 case $option in
  i) nemo_i=$OPTARG;;
  j) nemo_j=$OPTARG;;
  \?) exit 1;;
 esac
done

source /usr/share/modules/init/ksh
module switch openmpi impi

set -xuve
date

#MPI=/gpfs/apps/MN3/OPENMPI/1.5.4 # OpenMPI
MPI=/gpfs/apps/MN3/INTEL/impi/4.1.0.024/intel64 # Intel MPI
NetCDF=/gpfs/projects/ecm86/opt/netcdf-3.6.3/intel-13
UDUNITS=

settings=settings.orca1.marenostrum3

cd ..
ECEARTH=`pwd`
cd -

cat > $settings <<EOF
# General settings
export MPIDIR=$MPI
#export MPILIBS="-lmpi -lmpi_f77" # OpenMPI
export MPILIBS="-lmpi -lmpiif" # Intel MPI
export NETCDFDIR=$NetCDF
export NETCDFLIBS="-lnetcdf"
export UDUNITSDIR=$UDUNITS
which ifort

# settings for EC-Earth
export ECEARTH=$ECEARTH

# Settings for OASIS3
export OASIS3ARCH=marenostrum3
export PSMILE=\$ECEARTH/oasis3/prism_2-5/prism/\$OASIS3ARCH

# Settings of IFS
export ARCH=marenostrum3
export IFSROOT=\$ECEARTH/ifs
PATH=\$IFSROOT/scripts:\$PATH

# Settings for NEMO
export NEMOARCH=marenostrum3
export NEMOPROCX=$nemo_i
export NEMOPROCY=$nemo_j
export NEMOGRID=ORCA1
export NEMOCLEAN=no

# Settings for FOcean and SlabOcean models
export FORTRANCOMPILER=ifort
export FORTRANFLAGS=''
export FORTRANLINK=''
export FOCEANARCH=ithaca
export FOCEANCLEAN=yes
export SLABOCEANARCH=ithaca
export SLABOCEANCLEAN=yes
EOF
cat $settings

ln -sf $ECEARTH/build/$settings settings

#./cleannemo.ksh
./makenemo.ksh

date
