#!/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 /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

set -xuve
date

MPI=/share/mpi/openmpi/1.6/ics2012.0.032 # OpenMPI
#MPI=/share/compilers/ics/2012.0.032/impi/4.0.3.008/intel64 # Intel MPI
NetCDF=/scratch/cfu/opt/netcdf-3.6.3/intel12
UDUNITS=/scratch/cfu/opt/udunits-2.1.24/intel12

settings=settings.orca1.ithaca

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=ithaca
export PSMILE=\$ECEARTH/oasis3/prism_2-5/prism/\$OASIS3ARCH

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

# Settings for NEMO
export NEMOARCH=ithaca
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
