#!/bin/bash

# Modify jpni, jpnj and jpnij in the following code
# according to no. of proc to be used.
# vi ../../modeles/NEMO/OPA_SRC/par_oce.F90

# Modify compiler options in the following configuration
# file.
# vi ../../util/AA_make.gdef

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/bash

set -xuve
date

sed -e "s/ABC/$nemo_i/" \
    -e "s/DEF/$nemo_j/" \
    -e "s/GHI/$((nemo_i*nemo_j))/" \
../../modeles/NEMO/OPA_SRC/par_oce.F90.orig > ../../modeles/NEMO/OPA_SRC/tmp
mv ../../modeles/NEMO/OPA_SRC/tmp ../../modeles/NEMO/OPA_SRC/par_oce.F90

compile=platine

# MODEL Compilation
# =================
rm -rf ../../lib/*
gmake clean
cp scripts/BB_make.ldef_1st scripts/BB_make.ldef
../../util/ins_make -t $compile
cat Makefile
gmake
cp scripts/BB_make.ldef_2nd scripts/BB_make.ldef
../../util/ins_make -t $compile
cat Makefile
gmake

# TOOLS Compilation
# ================
cd ../../modeles/IOIPSL/tools
gmake clean
gmake

date
