#!/bin/ksh
# DSG
# this scripts get ORCHIDEE-CN-P and does all the adjustments for you
# which are needed and 
# documented here: https://forge.ipsl.jussieu.fr/orchidee/wiki/DevelopmentActivities/ORCHIDEE-CNP/howtoUse

# check which machine:
host=$(hostname)

# the Makefile for IOIPSL needs to ab adjusted to the machine
# first check if we  have the information for this machine
if [[ $host == 'curie90' ]]; then
 echo $host
 f0='F_O = -DCPP_PARA -O3 -xAVX -align all -align array32byte $(F_D) $(F_P) -I$(MODDIR) -module $(MODDIR) -fp-model precise'
elif [[ $host == 'obelix5' ]]; then
 echo $host
 f0='F_O = -DCPP_PARA -O3 -align all $(F_D) $(F_P) -I$(MODDIR) -module $(MODDIR) -fp-model precise'
else
 echo 'configuration for ' $host ' not known'
 echo 'find it here https://forge.ipsl.jussieu.fr/orchidee/wiki/DevelopmentActivities/Branches/ORCHIDEE-MICT-IMBALANCE-P/Compile#After8.4.0rev4057'
 exit
fi
# now get to wrok
# check out modipsl
svn -r2728 co http://forge.ipsl.jussieu.fr/igcmg/svn/modipsl/trunk modipsl
cd modipsl/util
./model ORCHIDEE_trunk
cd ../modeles
# remove ORCHIDEE(trunk), IOIPSL and XIOS...
rm -fr ORCHIDEE IOIPSL XIOS
# .. and replace with ORCHIDEE-CN-P and another IOIPSL
svn co svn://forge.ipsl.jussieu.fr/orchidee/branches/ORCHIDEE-CN-P/ORCHIDEE ORCHIDEE
svn co svn://forge.ipsl.jussieu.fr/orchidee/branches/ORCHIDEE-MICT/IOIPSL IOIPSL
svn co https://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/trunk XIOS
# ajust IOIPSL
cd IOIPSL/src
../../../util/ins_make
sed -i "s/F_O =.*/$f0/g" Makefile
#then
gmake 
# get the CNP adjusted libIGCM configurations
cd ../../../config/
rm -fr ORCHIDEE_OL
svn co svn://forge.ipsl.jussieu.fr/orchidee/branches/ORCHIDEE-CN-P/ORCHIDEE_OL ORCHIDEE_OL
cd ../util ; ./ins_make






