Index: /BOL/script_install_amaury/install_lmdz.sh
===================================================================
--- /BOL/script_install_amaury/install_lmdz.sh	(revision 4890)
+++ /BOL/script_install_amaury/install_lmdz.sh	(revision 4891)
@@ -37,4 +37,5 @@
 
 ### Functions
+# TODO add make_j parallel argument -> check what is used for libigcm
 
 function myget { # Get a file from LMDZ repository
@@ -50,30 +51,13 @@
 function set_default_params {
     # Valeur par défaut des parametres
-
-    # 04_2021 : tester si r4 marche encore !
-    real="r8"  # ou "r4"
-
     svn=""
     version="20231022.trunk"
 
-    netcdf=1   #  1: for automatic installation;
-    #          or 0: do not install NetCDF and look for it in standard locations;
-    #          or absolute path: look for NetCDF there
+    netcdf=1
     bench=1
-    pclinux=1
     pcmac=0 # default: not on a Mac
     SCM=0
-    # surface/vegetation scheme treatment
-    # controlled by the single variable veget which can have the following values
-    # - none: bucket scheme (default)
-    # - CMIP6: orchidee version used in CMIP exercise, rev 5661
-    # - number: orchidee version number
     veget="none"
-    # choose the resolution for the bench runs
-    # grid_resolution= 32x24x11 or 48x36x19 for tests (test without ORCHIDEE)
-    #                  96x71x19  standard configuration
-    grid_resolution="32x32x39"  # "48x36x19", "96x95x39", "144x142x79"
-    # choose the physiq version you want to test
-    #physiq=NPv6.0.14splith
+    grid_resolution="32x32x39"
     physiq=""
 
@@ -81,21 +65,15 @@
     xios_rev="2568"
 
-    ## parallel can take the values none/mpi/omp/mpi_omp
-    parallel="none"  # "mpi_omp"
-    idris_acct="lmd"
+    parallel="none"
     trusting="testing"
     MODEL=""
 
-    ## also compile XIOS? (and more recent NetCDF/HDF5 libraries) Default=no
-    with_xios="n"
+    with_xios=0
     opt_makelmdz_xios=""
 
-    ## compile with oldrad/rrtm/ecrad radiatif code (Default=rrtm)
     rad="rrtm"
 
-    ## compile_with_fcm=1 : use makelmdz_fcm (1) or makelmdz (0)
     compile_with_fcm=1
 
-    #Compilation with Cosp (cosp=none/v1/v2; default=none)
     cosp="none"
     opt_cosp=""
@@ -107,5 +85,4 @@
     fi
 
-    env_file=""
     optim_debug=""
     arch="local"
@@ -192,5 +169,5 @@
             "-netcdf") netcdf=$2; shift; shift;;
             "-physiq") physiq=$2; shift; shift;;
-            "-xios") with_xios="y"; shift;;
+            "-xios") with_xios=1; shift;;
             "-arch") arch=$2; shift; shift;;
             "-arch_dir") arch_dir=$2; shift; shift;;
@@ -227,7 +204,7 @@
 
     if [[ $parallel = "none" ]]; then
-        sequential=1; suff_exe='_seq'
-    else
-        sequential=0; suff_exe='_para_mem'
+        suff_exe='_seq'
+    else
+        suff_exe='_para_mem'
     fi
 
@@ -236,13 +213,13 @@
 
     ## if also compiling XIOS, parallel must be mpi_omp
-    if [[ $with_xios = "y" && $parallel != "mpi_omp" ]]; then
+    if [[ $with_xios = 1 && $parallel != "mpi_omp" ]]; then
         echo "Error, you must set -parallel mpi_omp if you want XIOS"; exit 1
     fi
 
-    if [[ $with_xios = "y" ]]; then
+    if [[ $with_xios = 1 ]]; then
         opt_makelmdz_xios="-io xios"
     fi
 
-    if [[ $cosp = "v2" && $with_xios = "n" ]]; then
+    if [[ $cosp = "v2" && $with_xios = 0 ]]; then
         echo "Error, Cospv2 cannot run without Xios"; exit 1
     fi
@@ -314,6 +291,4 @@
 
 function install_arch {
-    # TODO     if [[ $(gfortran -dumpversion | cut -d. -f1) -ge 10 ]]; then allow_arg_mismatch="-fallow-argument-mismatch"; fi
-
     if [[ ! -d $arch_dir ]]; then
         echo "Error: no arch dir $arch_dir"; exit 1
@@ -337,8 +312,8 @@
     # Copy arch to different components
     # TODO check that this doesn't error if the source and destination are the same
-    \cp -f "$arch_dir/arch-$arch.fcm" "$MODEL/modipsl/modeles/IOIPSL/arch"
-    \cp -f "$arch_dir/arch-$arch.path" "$MODEL/modipsl/modeles/IOIPSL/arch"
-    \cp -f "$arch_dir/arch-$arch.fcm" "$MODEL/modipsl/modeles/ORCHIDEE/arch"
-    \cp -f "$arch_dir/arch-$arch.path" "$MODEL/modipsl/modeles/ORCHIDEE/arch"
+    for dir in "IOIPSL" "ORCHIDEE" "LMDZ"; do
+        \cp -f "$arch_dir/arch-$arch.fcm" "$MODEL/modipsl/modeles/$dir/arch"
+        \cp -f "$arch_dir/arch-$arch.path" "$MODEL/modipsl/modeles/$dir/arch"
+    done
 
     # TODO TEMP compat w/ old orch version - make a proper case later
@@ -362,11 +337,11 @@
 
         case $with_xios in
-            n) script_install_netcdf="install_netcdf4_hdf5_seq.bash"
+            0) script_install_netcdf="install_netcdf4_hdf5_seq.bash"
                ncdfdir="netcdf4_hdf5_seq"
                opt_="$opt1";;
-            y) script_install_netcdf="install_netcdf4_hdf5.bash"
+            1) script_install_netcdf="install_netcdf4_hdf5.bash"
                ncdfdir="netcdf4_hdf5"
                opt_="$opt2 -MPI $root_mpi";;
-            *) echo "with_xios=$with_xios, should be n or y"; exit 1
+            *) echo "with_xios=$with_xios, should be 0 or 1"; exit 1
         esac
         if [[ $netcdf = 1 ]]; then
@@ -418,4 +393,16 @@
         exit 1
     fi
+
+    # Compile NetCDF95
+    cd "$MODEL/modipsl/modeles/LMD"*
+    echo "Installing NetCDF95"
+    cd "$MODEL"
+    myget src_archives/netcdf/NetCDF95-0.3.tar.gz
+    tar -xf NetCDF95-0.3.tar.gz
+    \rm NetCDF95-0.3.tar.gz
+    cd NetCDF95-0.3
+    mkdir -p build && cd build
+    netCDF_INCLUDE_DIR=$(nc-config --includedir) netCDF_LIBRARY=$(nc-config --libdir) cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$ncdfdir" -DCMAKE_INSTALL_PREFIX="$MODEL/modipsl"
+    make install
 }
 
@@ -431,10 +418,10 @@
     echo "IOIPSL compiled $(date)"
 
-    export IOIPSL_LIBDIR="$MODEL/modipsl/modeles/IOIPSL/lib"
-    export IOIPSL_INCDIR="$MODEL/modipsl/modeles/IOIPSL/inc"
+    IOIPSL_LIBDIR_="$MODEL/modipsl/modeles/IOIPSL/lib"
+    IOIPSL_INCDIR_="$MODEL/modipsl/modeles/IOIPSL/inc"
 }
 
 function install_XIOS {
-    if [[ $with_xios = "y" ]]; then
+    if [[ $with_xios = 1 ]]; then
         cd "$MODEL/modipsl/modeles"
         xioslog="$(pwd)/xios.log"
@@ -467,63 +454,348 @@
 
 function get_orchidee_version {  # Set / Check ORCHIDEE version
-  if [[ $veget = "none" ]]; then
-    veget_version="false"
-  elif [[ $veget = "CMIP6" ]]; then
-    veget_version=orchidee2.0
-    orchidee_rev=6592
-  else # specific orchidee revision newer than CMIP6, on 2_1 or 2_2 branches
-    veget_version=orchidee2.1
-    orchidee_rev="$veget"
-    if [[ $veget -lt 4465 ]]; then
-      echo 'ORCHIDEE version must be >=4465, exiting'
-      exit 1
-    fi
+    if [[ $veget = "none" ]]; then
+        veget_version="false"
+    elif [[ $veget = "CMIP6" ]]; then
+        veget_version=orchidee2.0
+        orchidee_rev=6592
+    else # specific orchidee revision newer than CMIP6, on 2_1 or 2_2 branches
+        veget_version=orchidee2.1
+        orchidee_rev="$veget"
+        if [[ $veget -lt 4465 ]]; then
+            echo 'ORCHIDEE version must be >=4465, exiting'
+            exit 1
+        fi
+
+        set +e
+        svn upgrade
+        local orcbranch
+        orcbranch=$(svn log -v -q svn://forge.ipsl.jussieu.fr/orchidee/ -r "$veget" |grep ORCHIDEE |head -1| sed -e 's:ORCHIDEE/.*$:ORCHIDEE:' | awk '{print $2}')
+        echo "IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at orchidee-help@listes.ipsl.fr"
+        svn switch -r "$veget" --accept theirs-full "svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch"
+        svn log -r "$veget" | grep "$veget"
+        if ! svn log -r "$veget" | grep "$veget"; then
+            echo 'Cannot update ORCHIDEE as not on the right branch for ORCHIDEE'
+            exit 1
+        fi
+        svn update -r "$veget"
+        set -e
+    fi
+}
+
+function compile_orchidee {
+    get_orchidee_version
+    ORCHPATH=""
+
+
+    if [[ $veget != "none" ]]; then
+        cd "$MODEL/modipsl/modeles/ORCHIDEE"
+        ORCHPATH=$(pwd)
+
+        orchideelog="$(pwd)/orchidee.log"
+        echo "Compiling ORCHIDEE, the continental surface model (log $orchideelog) $(date)"
+
+        local xios_orchid opt_orc
+        if [[ $with_xios = 1 ]]; then
+            xios_orchid="-xios";
+        else
+            xios_orchid="-noxios"
+        fi
+        if [[ $optim_debug = "-debug" ]]; then
+            opt_orc="-debug";
+        else
+            opt_orc="-prod"
+        fi
+
+        # TODO check that this works with old orchidee versions (cf. -d tools)
+        local varenv="IOIPSL_LIBDIR_=$IOIPSL_LIBDIR_ IOIPSL_INCDIR_=$IOIPSL_INCDIR_ ORCHPATH=$ORCHPATH"
+        if [[ $parallel = "none" ]]; then
+            echo "$varenv ./makeorchidee_fcm $xios_orchid $opt_orc -parallel none -arch $arch -j 8" > compile.sh
+        else
+            if [[ ! -d src_parallel ]]; then
+               echo "Orchidee version too old for parallel support"; exit 1
+            fi
+            {
+                echo "$varenv ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc -parallel $parallel -arch $arch"
+                echo "$varenv ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel $parallel -arch $arch"
+            } > compile.sh
+        fi
+        chmod +x compile.sh
+        echo "Compiling ORCHIDEE using $(\cat compile.sh)"
+        if ! ./compile.sh > "$orchideelog" 2>&1; then
+            echo "ORCHIDEE compilation failed, exiting"; exit 1
+        fi
+        echo "Compiled ORCHIDEE $(date)"
+    fi
+
+    ORCH_LIBDIR_="$MODEL/modipsl/modeles/ORCHIDEE/lib"
+}
+
+function get_lmdz_version {
+    LMDZPATH=$(readlink -f "$MODEL/modipsl/modeles/LMD"*)
+    cd "$LMDZPATH"
+    lmdzlog="$(pwd)/lmdz.log"
 
     set +e
     svn upgrade
-    local orcbranch
-    orcbranch=$(svn log -v -q svn://forge.ipsl.jussieu.fr/orchidee/ -r "$veget" |grep ORCHIDEE |head -1| sed -e 's:ORCHIDEE/.*$:ORCHIDEE:' | awk '{print $2}')
-    echo "IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at orchidee-help@listes.ipsl.fr"
-    svn switch -r "$veget" --accept theirs-full "svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch"
-    svn log -r "$veget" | grep "$veget"
-    if ! svn log -r "$veget" | grep "$veget"; then
-      echo 'Cannot update ORCHIDEE as not on the right branch for ORCHIDEE'
-      exit 1
-    fi
-    svn update -r "$veget"
+    if [[ $svn = "last" ]]; then
+        svnopt=""
+    else
+        svnopt="-r $svn"
+    fi
+    if [[ $svn != "" ]]; then
+        if svn info | grep -q 'https:'; then svn switch --relocate https://svn.lmd.jussieu.fr/LMDZ http://svn.lmd.jussieu.fr/LMDZ; fi
+        svn update "$svnopt"
+    fi
+    mysvn=$(svnversion . | grep -E -o "[0-9]+" 2>/dev/null)
     set -e
-  fi
-}
-
-function compile_orchidee_seq {
-  get_orchidee_version
-
-  if [[ $veget != "none" ]]; then
-    cd "$MODEL/modipsl/modeles/ORCHIDEE"
-
-    orchideelog="$(pwd)/orchidee.log"
-    echo "Compiling ORCHIDEE, the continental surface model (log $orchideelog)"
-    echo "Start of the first compilation of orchidee, in sequential mode: $(date)"
-
-    ORCHPATH=$(pwd)
-    export ORCHPATH=$ORCHPATH
-
-    local xios_orchid opt_orc
-    if [[ $with_xios = "y" ]]; then
-      xios_orchid="-xios";
-    else
-      xios_orchid="-noxios"
-    fi
-    if [[ $optim_debug = "-debug" ]]; then
-      opt_orc="-debug";
-    else
-      opt_orc="-prod"
-    fi
-
-    if ! ./makeorchidee_fcm "$xios_orchid" "$opt_orc" -parallel none -arch "$arch" > "$orchideelog" 2>&1; then
-      echo "ORCHIDEE seq compilation failed, exiting"; exit 1
-    fi
-    echo "Compiled ORCHIDEE seq $(date)"
-  fi
+
+    if [[ $mysvn = "" ]]; then mysvn=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null); fi
+    if [[ $mysvn = "" ]]; then mysvn=4190; fi
+}
+
+function compile_lmdz {
+    get_lmdz_version
+
+    exe_name="bin/gcm_${grid_resolution}_phylmd_${rad}${suff_exe}${suff_orc}.e"
+
+    local opt_rad
+    case $rad in
+        oldrad) iflag_rrtm=0; NSW=2; opt_rad="";;
+        rrtm)   iflag_rrtm=1; NSW=6
+            if [[ $mysvn -le 4185 ]]; then
+                opt_rad="-rrtm true"
+            else
+                opt_rad="-rad rrtm"
+            fi;;
+        ecrad)  iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";;
+        *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
+    esac
+    if [[ $mysvn -le 4185 && $rad = "ecrad" ]]; then
+        echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1
+    fi
+
+    # Compile
+    local varenv="IOIPSL_LIBDIR_=$IOIPSL_LIBDIR_ IOIPSL_INCDIR_=$IOIPSL_INCDIR_ ORCH_LIBDIR_=$ORCH_LIBDIR_ ORCHPATH=$ORCHPATH"
+    makelmdz="makelmdz_fcm $optim_debug -arch $arch -j 8"
+    if [[ $parallel = "none" ]]; then
+        echo "$varenv ./$makelmdz $opt_rad $opt_cosp -d ${grid_resolution} -v $veget_version gcm " > compile.sh
+    else
+        echo "$varenv ./$makelmdz $opt_rad $opt_cosp $opt_makelmdz_xios -d ${grid_resolution} -v $veget_version -mem -parallel $parallel gcm" > compile.sh
+    fi
+    echo "Compiling lmdz using $(\cat compile.sh) (log: $lmdzlog) $(date)"
+    chmod +x ./compile.sh
+    if ! ./compile.sh > "$lmdzlog" 2>&1; then
+        echo "LMDZ compilation failed, exiting"; exit 1
+    fi
+    echo "Finished LMDZ compilation $(date)"
+
+    # Check executable
+    # TODO $mysev -ge 4186 => other name convention ! check original install
+    if [[ ! -f $exe_name ]]; then
+        echo "Compilation failed, can't find the executable"; exit 1
+    else
+        echo "Compilation successfull, the executable is $exe_name $(date)"
+    fi
+}
+
+function run_bench {
+    cd "$MODEL/modipsl/modeles/LMDZ"*
+
+    if [[ $bench = "tuto" ]]; then
+        myget Training/tutorial.tar; tar xf tutorial.tar; cd TUTORIAL
+        ./init.sh
+    elif [[ $bench = 1 ]]; then
+        \rm -rf "BENCH${grid_resolution}"
+        local bench=bench_lmdz_${grid_resolution}
+        myget "3DBenchs/$bench.tar.gz"
+        tar xf "$bench.tar.gz"
+
+        if [[ $cosp = "v1" || $cosp = "v2" ]]; then
+            cd "BENCH${grid_resolution}"
+            # copier les fichiers namelist input et output our COSP
+            cp ../DefLists/cosp*_input_nl.txt .
+            cp ../DefLists/cosp*_output_nl.txt .
+            # Activer la cles ok_cosp pour tourner avec COSP
+            sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp
+            \mv -f tmp config.def
+            cd ..
+        fi
+
+        if [[ -n "$physiq" ]]; then
+            cd "BENCH${grid_resolution}"
+            if [[ -f "physiq.def_${physiq}" ]]; then
+                cp "physiq.def_${physiq}" physiq.def
+                echo "using physiq.def_${physiq}"
+            else
+                echo "using standard physiq.def"
+            fi
+            cd ..
+        else
+            echo "using standard physiq.def"
+        fi
+
+        if [[ $with_xios = 1 ]]; then
+            cd "BENCH${grid_resolution}"
+            cp ../DefLists/iodef.xml .
+            cp ../DefLists/context_lmdz.xml .
+            cp ../DefLists/field_def_lmdz.xml .
+            # A raffiner par la suite
+            echo "A FAIRE : Copier les *xml en fonction de l option cosp"
+            cp ../DefLists/field_def_cosp*.xml .
+            cp ../DefLists/file_def_hist*xml .
+            # adapt iodef.xml to use attached mode
+            sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \
+                iodef.xml > tmp
+            \mv -f tmp iodef.xml
+
+            # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
+            # except for histday
+            for histfile in file_def_hist*xml
+            do
+                if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then
+                    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \
+                        "$histfile" > tmp
+                    \mv -f tmp "$histfile"
+                    sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \
+                        > tmp
+                    \mv -f tmp "$histfile"
+                    sed -e 's@compression_level="2"@compression_level="0"@' \
+                        "$histfile" > tmp
+                    \mv -f tmp "$histfile"
+                else
+                    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
+                        "$histfile" > tmp
+                    \mv -f tmp "$histfile"
+                fi
+            done
+            # and add option "ok_all_xml=y" in config.def
+            echo "### XIOS outputs" >> config.def
+            echo 'ok_all_xml=.true.' >> config.def
+
+            #activer les sorties pour Cosp
+            if [[ "$cosp" = "v1" ]]; then
+                sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \
+                         -e 's@output_level="_AUTO_"@output_level="5"@' \
+                         -e 's@compression_level="2"@compression_level="0"@' \
+                         file_def_histdayCOSP_lmdz.xml
+            fi
+            if [[ "$cosp" = "v2" ]]; then
+                sed -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml
+                for type_ in hf day mth; do
+                    file=file_def_hist${type_}COSP
+                    sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml
+                done
+                sed -i '' -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' field_def_lmdz.xml
+            fi
+
+            cd ..
+        fi
+
+        # Cas Bench avec ecrad
+        if [[ $rad = "ecrad" ]]; then
+            cd "BENCH${grid_resolution}"
+            cp  ../DefLists/namelist_ecrad .
+            cp -r ../libf/phylmd/ecrad/data .
+            cd ..
+        fi
+
+        # Adjusting bench physiq.def to radiative code chosen
+        cd "BENCH${grid_resolution}"
+        sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \
+            -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
+        \mv tmpdef physiq.def
+        cd ..
+
+        cp "$exe_name" "BENCH${grid_resolution}/gcm.e"
+        cd "BENCH${grid_resolution}"
+
+        if [[ ${parallel:0:3} = "mpi" ]]; then
+            # Lancement avec deux procs mpi et 2 openMP
+            echo "export OMP_STACKSIZE=800M" > bench.sh
+            if [[ "${parallel:4:3}" = "omp" ]]; then
+                echo "export OMP_NUM_THREADS=2" >> bench.sh
+            fi
+            if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
+                echo "ulimit -s 200000" >> bench.sh
+            else
+                echo "ulimit -s unlimited" >> bench.sh
+            fi
+            echo "mpirun -np 2 gcm.e > listing  2>&1" >> bench.sh
+            # Add rebuild, using reb.sh if it is there
+            cat <<EOF >> bench.sh
+    if [[ -f reb.sh ]]; then
+      ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf;
+      ./reb.sh histins; ./reb.sh stomate_history;
+      ./reb.sh sechiba_history; ./reb.sh sechiba_out_2
+    fi
+EOF
+        else
+            echo "./gcm.e > listing  2>&1" > bench.sh
+        fi
+        # Getting orchidee stuff
+        if [[ $veget = 'CMIP6' ]]; then
+            echo 'myget 3DBenchs/BENCHCMIP6.tar.gz'
+            myget 3DBenchs/BENCHCMIP6.tar.gz
+            tar xvzf BENCHCMIP6.tar.gz
+            sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
+            mv -f tmp config.def
+            if [[ $with_xios = 1 ]]; then
+                cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
+                echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp
+                cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml .
+                cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
+                cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
+                if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then
+                       cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
+                       echo '<context id="orchidee" src="./context_input_orchidee.xml"/>' >> add.tmp
+                fi
+                sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp
+                mv tmp iodef.xml
+                sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \
+                    file_def_orchidee.xml > tmp
+                \mv -f tmp file_def_orchidee.xml
+                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
+                    file_def_orchidee.xml > tmp
+                \mv -f tmp file_def_orchidee.xml
+                sed -e 's@output_level="_AUTO_"@output_level="1"@' \
+                    file_def_orchidee.xml > tmp
+                \mv -f tmp file_def_orchidee.xml
+                sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \
+                    file_def_orchidee.xml > tmp
+                \mv -f tmp file_def_orchidee.xml
+                sed -e 's@compression_level="4"@compression_level="0"@' \
+                    file_def_orchidee.xml > tmp
+                \mv -f tmp file_def_orchidee.xml
+                sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \
+                    orchidee.def > tmp
+                \mv -f tmp orchidee.def
+            fi
+        fi
+
+        if [[ -f ../arch.env ]]; then source ../arch.env; fi
+
+        echo "EXECUTION DU BENCH"
+        date
+        if (! ./bench.sh > out.bench 2>&1) || ! (tail -n 1 listing | grep "Everything is cool"); then
+            tail listing
+            echo "Bench FAILED, exiting"; exit 1
+        fi
+        date
+        tail listing
+    fi
+
+    # 1D case
+    if [[ $SCM = 1 ]]; then
+        cd "$MODEL"
+        myget 1D/1D.tar.gz
+        tar xf 1D.tar.gz
+        cd 1D
+        if [[ $rad = "oldrad" ]]; then
+            sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh
+            sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile
+        fi
+        echo "Running 1D/run.sh, log in $(pwd)/run1d.log"
+        ./run.sh > "$(pwd)/run1d.log" 2>&1
+    fi
 }
 
@@ -539,808 +811,5 @@
 install_IOIPSL
 #install_XIOS  # TODO disabled for now, did not decide which flags/arch to use for compile
-compile_orchidee_seq
-
-exit 0
-
-
-
-
-################################################################
-# Specificite des machines
-################################################################
-
-hostname=$(hostname)
-#case ${hostname:0:5} in
-#    *)       if [[ $parallel = none || -f /usr/bin/mpif90 ]]; then
-#                 path_mpi=$(which mpif90 | sed -e s:/mpif90::);
-#                 if [[ -d /usr/lib64/openmpi ]]; then
-#                     root_mpi="/usr/lib64/openmpi"
-#                 else
-#                     root_mpi="/usr"
-#                 fi
-#             else
-#                 echo "Cannot find mpif90";
-#                 if [[ $parallel = none ]]; then exit 1; fi;
-#             fi;
-#             if [[ $parallel != none ]]; then
-#                 root_mpi=$(which mpif90 | sed -e s:/bin/mpif90::)
-#                 path_mpi=$(which mpif90 | sed -e s:/mpif90::)
-#                 export LD_LIBRARY_PATH=${root_mpi}/lib:$LD_LIBRARY_PATH
-#             fi
-#             par_comp=${path_mpi}/mpif90;
-#             mpirun=${path_mpi}/mpirun;
-#             arch="local";
-#             make="make";
-#             o_ins_make="-t g95"
-#esac
-
-## Flags for parallelism:
-#if [[ $parallel != none ]]; then
-#    # MPI_LD are the flags needed for linking with MPI
-#    MPI_LD="-L${root_mpi}/lib -lmpi"
-#    if [[ $compiler = "gfortran" ]]; then
-#        # MPI_FLAGS are the flags needed for compilation with MPI
-#        MPI_FLAGS="-fcray-pointer"
-#        # OMP_FLAGS are the flags needed for compilation with OpenMP
-#        OMP_FLAGS="-fopenmp -fcray-pointer"
-#        # OMP_LD are the flags needed for linking with OpenMP
-#        OMP_LD="-fopenmp"
-#    elif [[ $compiler = "ifort" ]]; then
-#        MPI_FLAGS=""
-#        OMP_FLAGS="-openmp"
-#        OMP_LD="-openmp"
-#    else # pgf90
-#        MPI_FLAGS=""
-#        OMP_FLAGS="-mp"
-#        OMP_LD="-mp"
-#    fi
-#fi
-#
-#
-#echo "################################################################"
-#echo  "Choix des options de compilation"
-#echo "################################################################"
-#
-#export FC=$compiler
-#export F90=$compiler
-#export F77=$compiler
-#export CPPFLAGS=
-#OPTIMNC=""
-#BASE_LD="$OPT_GPROF"
-#OPTPREC="$OPT_GPROF"
-#ARFLAGS="rs"
-#if [[ $(lsb_release -i -s) = "Ubuntu" ]]; then
-#    if [[ $(lsb_release -r -s | cut -d. -f1) -ge 16 ]]; then
-#        ARFLAGS="rU"
-#    fi
-#fi
-#
-#if [[ $compiler = "gfortran" ]]; then
-#   OPTIM="-O3 $allow_arg_mismatch"
-#   OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all -fbacktrace -finit-real=snan  $allow_arg_mismatch"
-#   OPTDEV="-Wall -fbounds-check  $allow_arg_mismatch"
-#   fmod="I "
-#   OPTPREC="$OPTPREC -cpp -ffree-line-length-0"
-#   if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE"; fi
-#   export F90FLAGS=" -ffree-form $OPTIMNC"
-#   export FFLAGS=" $OPTIMNC"
-#   export CC=gcc
-#   export CXX=g++
-#   export fpp_flags="-P -C -traditional -ffreestanding"
-#
-#elif [[ $compiler = mpif90 ]]; then
-#    OPTIM="-O3"
-#    OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all"
-#    OPTDEV="-Wall -fbounds-check"
-#    BASE_LD="$BASE_LD -lblas"
-#    fmod="I "
-#    if [[ $real = r8 ]]; then
-#        OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE -fcray-pointer"
-#    fi
-#    export F90FLAGS=" -ffree-form $OPTIMNC"
-#    export FFLAGS=" $OPTIMNC"
-#    export CC=gcc
-#    export CXX=g++
-#
-#elif [[ $compiler = pgf90 ]]; then
-#    OPTIM="-O2 -Mipa -Munroll -Mnoframe -Mautoinline -Mcache_align"
-#    OPTDEB="-g -Mdclchk -Mbounds -Mchkfpstk -Mchkptr -Minform=inform -Mstandard -Ktrap=fp -traceback"
-#    OPTDEV="-g -Mbounds -Ktrap=fp -traceback"
-#    fmod="module "
-#    if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -r8 -DNC_DOUBLE"; fi
-#    export CPPFLAGS="-DpgiFortran"
-#    export CC=pgcc
-#    export CFLAGS="-O2 -Msignextend"
-#    export CXX=pgCC
-#    export CXXFLAGS="-O2 -Msignextend"
-#    export FFLAGS="-O2 $OPTIMNC"
-#    export F90FLAGS="-O2 $OPTIMNC"
-#    compile_with_fcm=1
-#
-#elif [[ $compiler = ifort || $compiler = mpiifort ]]; then
-#    OPTIM="-O2 -fp-model strict -ip -align all "
-#    OPTDEV="-p -g -O2 -traceback -fp-stack-check -ftrapuv -check"
-#    OPTDEB="-g -no-ftz -traceback -ftrapuv -fp-stack-check -check"
-#    fmod='module '
-#    if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -real-size 64 -DNC_DOUBLE"; fi
-#    export CPP="icc -E"
-#    export FFLAGS="-O2 -ip -fpic -mcmodel=large"
-#    export FCFLAGS="-O2 -ip -fpic -mcmodel=large"
-#    export CC=icc
-#    export CFLAGS="-O2 -ip -fpic -mcmodel=large"
-#    export CXX=icpc
-#    export CXXFLAGS="-O2 -ip -fpic -mcmodel=large"
-#    export fpp_flags="-P -traditional"
-#    # Pourquoi forcer la compilation fcm. Marche mieux sans
-#    #compile_with_fcm=1
-#else
-#    echo "unexpected compiler $compiler"; exit 1
-#fi
-#
-#OPTIMGCM="$OPTIM $OPTPREC"
-
-
-veget_version=false
-if [[ $veget != 'none' ]]; then
-    cd "$MODEL/modipsl/modeles/ORCHIDEE"
-
-    opt_orc="-prod"; if [[ "$optim_debug" = "-debug" ]]; then opt_orc="-debug"; fi
-
-    orchideelog=$(pwd)/orchidee.log
-    echo '########################################################'
-    echo 'Compiling ORCHIDEE, the continental surface model '
-    echo '########################################################'
-    echo "Start of the first compilation of orchidee, in sequential mode: $(date)"
-    echo "log file : $orchideelog"
-
-    ORCHPATH=$(pwd)
-    export ORCHPATH=$ORCHPATH
-    xios_orchid="-noxios"
-    if [[ "$with_xios" = "y" ]]; then
-        xios_orchid="-xios"
-    fi
-    if [[ -d tools ]]; then
-        ###################################################################
-        # Pour les experts qui voudraient changer de version d'orchidee.
-        # Attention : necessite d'avoir le password pour orchidee
-        ###################################################################
-        if [[ "$veget_version" == "false" ]]; then
-            veget_version=orchidee2.0
-        fi
-        cd arch
-        sed -e s:"%COMPILER        .*.$:%COMPILER            $compiler":1 \
-            -e s:"%LINK            .*.$:%LINK                $compiler":1 \
-            -e s:"%FPP_FLAGS       .*.$:%FPP_FLAGS           $fpp_flags":1 \
-            -e s:"%PROD_FFLAGS     .*.$:%PROD_FFLAGS         $OPTIM":1 \
-            -e s:"%DEV_FFLAGS      .*.$:%DEV_FFLAGS          $OPTDEV":1 \
-            -e s:"%DEBUG_FFLAGS    .*.$:%DEBUG_FFLAGS        $OPTDEB":1 \
-            -e s:"%BASE_FFLAGS     .*.$:%BASE_FFLAGS         $OPTPREC":1 \
-            -e s:"%BASE_LD         .*.$:%BASE_LD             $BASE_LD":1 \
-            -e s:"%ARFLAGS         .*.$:%ARFLAGS             $ARFLAGS":1 \
-            arch-gfortran.fcm > arch-local.fcm
-        cat <<EOF > arch-local.path
-NETCDF_LIBDIR="-L$ncdfdir/lib -lnetcdff -lnetcdf"
-NETCDF_INCDIR="$ncdfdir/include"
-IOIPSL_INCDIR="$ORCHPATH/../../lib"
-IOIPSL_LIBDIR="$ORCHPATH/../../lib"
-XIOS_INCDIR="\$ORCHDIR/../XIOS/inc"
-XIOS_LIBDIR="\$ORCHDIR/../XIOS/lib -lxios"
-EOF
-        cd ../
-
-        echo ./makeorchidee_fcm -j $xios_orchid $opt_orc -parallel none \
-             -arch $arch
-        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel none \
-                           -arch $arch > "$orchideelog" 2>&1
-        pwd
-    else # of "if [[ -d tools ]]"
-        if [[ -d src_parallel ]]; then
-            liste_src="parallel parameters global stomate sechiba driver"
-            if [[ "$veget_version" == "false" ]]; then
-                veget_version=orchidee2.0
-            fi
-        fi
-        for d in $liste_src; do
-            src_d=src_$d
-            echo src_d "$src_d"
-            echo ls; ls
-            if [[ ! -d $src_d ]]; then
-                echo "Problem orchidee : no $src_d"; exit 1
-            fi
-            cd "$src_d"; \rm -f -- *.mod make; $make clean
-            $make > "$orchideelog" 2>&1
-            if [[ "$compiler" = "gfortran" || "$compiler" = "mpif90" ]]; then
-                cp -f -- *.mod ../../../lib
-            fi
-            cd ..
-        done
-    fi # of "if [[ -d tools ]]"
-    echo "install_lmdz.sh orchidee_compil_seq_OK $(date)"
-fi # of if [[ "$veget" != 'none' ]]
-
-
-#============================================================================
-# Ehouarn: the directory name LMDZ* depends on version/tar file...
-if find . -name "$MODEL/modipsl/modeles/LMD*"; then
-    echo '###############################################################'
-    echo 'Preparing LMDZ compilation : arch file, svn switch if needed...'
-    echo '###############################################################'
-    cd "$MODEL/modipsl/modeles/"LMD*
-    LMDZPATH=$(pwd)
-else
-    echo "ERROR: No LMD* directory !!!"
-    exit 1
-fi
-
-
-###########################################################
-# For those who want to use fcm to compile via :
-#  makelmdz_fcm -arch local .....
-############################################################
-
-
-
-cd "$MODEL/modipsl/modeles"/LMDZ*
-lmdzlog=$(pwd)/lmdz.log
-
-##################################################################
-# Possibly update LMDZ if a specific svn release is requested
-##################################################################
-
-set +e; svn upgrade; set -e
-
-if [[ $svn = "last" ]]; then svnopt=""; else svnopt="-r $svn"; fi
-if [[ $svn != "" ]]; then
-    if set +e; svn info | grep -q 'https:'; then
-        svn switch --relocate https://svn.lmd.jussieu.fr/LMDZ \
-            http://svn.lmd.jussieu.fr/LMDZ
-    fi
-    svn update "$svnopt"
-    set -e
-fi
-
-#---------------------------------------------------------------------
-# Retrieve the final svn release number, and adjust compilation
-# options accordingly
-# If svn not available, will use the svn writen in $MODEL/Readm*md
-# For old version it assumes that it is before 4185 (the version
-# for which the test was introduced
-#---------------------------------------------------------------------
-
-set +e; mysvn=$(svnversion . | grep -E || "[0-9]+" 2>/dev/null); set -e
-if [[ "$mysvn" = "" ]]; then mysvn=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null); fi
-if [[ "$mysvn" = "" ]]; then mysvn=4190; fi
-
-if [[ "$pclinux" = "1" && ! -f arch/arch-local.path ]]; then
-
-    # create local 'arch' files (if on Linux PC):
-    cd arch
-    # arch-local.path file
-    # test for version as arch.pth file changed format with rev 4426
-    if [[ "$mysvn" -gt 4425 ]]; then
-      cat <<EOF > arch-local.path
-NETCDF_LIBDIR="-L$ncdfdir/lib"
-NETCDF_LIB="-lnetcdff -lnetcdf"
-NETCDF_INCDIR=-I$ncdfdir/include
-NETCDF95_INCDIR=-I\$LMDGCM/../../include
-NETCDF95_LIBDIR=-L\$LMDGCM/../../lib
-NETCDF95_LIB=-lnetcdf95
-IOIPSL_INCDIR=-I\$LMDGCM/../../lib
-IOIPSL_LIBDIR=-L\$LMDGCM/../../lib
-IOIPSL_LIB=-lioipsl
-XIOS_INCDIR=-I\$LMDGCM/../XIOS/inc
-XIOS_LIBDIR=-L\$LMDGCM/../XIOS/lib
-XIOS_LIB="-lxios -lstdc++"
-ORCH_INCDIR=-I\$LMDGCM/../../lib
-ORCH_LIBDIR=-L\$LMDGCM/../../lib
-EOF
-    else
-      cat <<EOF > arch-local.path
-NETCDF_LIBDIR="-L$ncdfdir/lib -lnetcdff -lnetcdf"
-NETCDF_INCDIR=-I$ncdfdir/include
-NETCDF95_INCDIR=\$LMDGCM/../../include
-NETCDF95_LIBDIR=\$LMDGCM/../../lib
-IOIPSL_INCDIR=\$LMDGCM/../../lib
-IOIPSL_LIBDIR=\$LMDGCM/../../lib
-XIOS_INCDIR=\$LMDGCM/../XIOS/inc
-XIOS_LIBDIR=\$LMDGCM/../XIOS/lib
-ORCH_INCDIR=\$LMDGCM/../../lib
-ORCH_LIBDIR=\$LMDGCM/../../lib
-EOF
-    fi 
-
-    if [[ $pcmac == 1 ]]; then
-        BASE_LD="$BASE_LD -Wl,-rpath,${ncdfdir}/lib"
-    else
-        BASE_LD="$BASE_LD -Wl,-rpath=${ncdfdir}/lib"
-    fi
-    # Arch-local.fcm file (adapted from arch-linux-32bit.fcm)
-
-    if [[ $real = r8 ]]; then FPP_DEF=NC_DOUBLE; else FPP_DEF=""; fi
-    sed -e s:"%COMPILER        .*.$:%COMPILER            $compiler":1 \
-        -e s:"%LINK            .*.$:%LINK                $compiler":1 \
-        -e s:"%PROD_FFLAGS     .*.$:%PROD_FFLAGS         $OPTIM":1 \
-        -e s:"%DEV_FFLAGS      .*.$:%DEV_FFLAGS          $OPTDEV":1 \
-        -e s:"%DEBUG_FFLAGS    .*.$:%DEBUG_FFLAGS        $OPTDEB":1 \
-        -e s:"%BASE_FFLAGS     .*.$:%BASE_FFLAGS         $OPTPREC":1 \
-        -e s:"%FPP_DEF         .*.$:%FPP_DEF             $FPP_DEF":1 \
-        -e s:"%BASE_LD         .*.$:%BASE_LD             $BASE_LD":1 \
-        -e s:"%ARFLAGS         .*.$:%ARFLAGS             $ARFLAGS":1 \
-        arch-linux-32bit.fcm > arch-local.fcm
-
-    cd ..
-    ### Adapt "bld.cfg" (add the shell):
-    #whereisthatshell=$(which ${use_shell})
-    #echo "bld::tool::SHELL   $whereisthatshell" >> bld.cfg
-
-fi # of if [[ "$pclinux" = 1 ]]
-#---------------------------------------------------------------------
-# Option de compilation du rayonnement : depend de $mysvn ><= r4185
-#---------------------------------------------------------------------
-opt_rad=""
-
-case $rad in
-    oldrad) iflag_rrtm=0; NSW=2; opt_rad="";;
-    rrtm)   iflag_rrtm=1; NSW=6
-            if [[ $mysvn -le 4185 ]]; then
-                opt_rad="-rrtm true"
-            else
-                opt_rad="-rad rrtm"
-            fi;;
-    ecrad)  iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";;
-    *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
-esac
-
-if [[ $mysvn -le 4185 && $rad = "ecrad" ]]; then
-    echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1
-fi
-
-##################################################################
-
-
-if [[ ! -f libf/misc/netcdf95.F90 &&  ! -d $MODEL/NetCDF95-0.3 ]]; then
-    cd "$MODEL"
-    myget src_archives/netcdf/NetCDF95-0.3.tar.gz
-    tar -xf NetCDF95-0.3.tar.gz
-    rm NetCDF95-0.3.tar.gz
-    cd NetCDF95-0.3
-    mkdir build
-    cd build
-    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$ncdfdir" \
-          -DCMAKE_INSTALL_PREFIX="$MODEL/modipsl"
-    make install
-    cd "$MODEL/modipsl/modeles/"LMDZ*
-fi
-
-echo '##################################################################'
-echo "Preparing script compile.sh for LMDZ compilation"
-echo "It will only be run automatically if bench=1/tuto"
-echo "Here bench=$bench"
-echo '##################################################################'
-
-if [[ $env_file != "" ]]; then
-    mv arch/arch-${arch}.env arch/arch-${arch}.orig
-    \cp -f "$env_file" arch/arch-${arch}.env
-fi
-
-if [[ $compile_with_fcm = 1 ]]; then
-    makelmdz="makelmdz_fcm $optim_debug -arch $arch -j 8 "
-else
-    makelmdz="makelmdz $optim_debug -arch $arch"
-fi
-
-# sequential compilation
-if [[ "$sequential" = 1 ]]; then
-    echo Sequential compilation command, saved in compile.sh:
-    echo "./$makelmdz $optim_debug $OPT_MAKELMDZ $optim_debug $opt_rad $opt_cosp " \
-         "-d ${grid_resolution} -v $veget_version gcm "
-    echo "./$makelmdz $optim_debug $OPT_MAKELMDZ $optim_debug $opt_rad $opt_cosp " \
-         "-d ${grid_resolution} -v $veget_version gcm " > compile.sh
-    chmod +x ./compile.sh
-    if [[ $bench = 1 ]]; then
-        echo "install_lmdz.sh start_lmdz_seq_compilation $(date)"
-        echo "log file: $lmdzlog"
-        ./compile.sh > "$lmdzlog" 2>&1
-        echo "install_lmdz.sh end_lmdz_seq_compilation $(date)"
-    fi
-fi # fin sequential
-
-# compiling in parallel mode
-if [[ $parallel != "none" ]]; then
-    echo '##########################################################'
-    echo ' Parallel compile '
-    echo '##########################################################'
-    echo "(after saving the sequential libs and binaries)"
-    cd "$MODEL/modipsl"
-    tar cf sequential.tar bin/ lib/
-    #
-    # Orchidee
-    #
-    cd "$ORCHPATH"
-    if [[ -d src_parallel && $veget != 'none' ]]; then
-        cd arch
-        sed  \
-            -e s:"%COMPILER.*.$:%COMPILER            $par_comp":1 \
-            -e s:"%LINK.*.$:%LINK                $par_comp":1 \
-            -e s:"%MPI_FFLAG.*.$:%MPI_FFLAGS          $MPI_FLAGS":1 \
-            -e s:"%OMP_FFLAG.*.$:%OMP_FFLAGS          $OMP_FLAGS":1 \
-            -e s:"%MPI_LD.*.$:%MPI_LD              $MPI_LD":1 \
-            -e s:"%OMP_LD.*.$:%OMP_LD              $OMP_LD":1 \
-            arch-local.fcm > tmp.fcm
-
-        mv tmp.fcm arch-local.fcm
-        cd ../
-        echo "Compiling ORCHIDEE in parallel mode $(date)"
-        echo "logfile $orchideelog"
-        echo "NOTE : to recompile it when necessary, use ./compile_orc.sh " \
-             "in modipsl/modeles/ORCHIDEE"
-        echo ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
-             -parallel "$parallel" -arch $arch > compile_orc.sh
-        echo ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc \
-             -parallel "$parallel" -arch $arch >> compile_orc.sh
-        echo echo Now you must also recompile LMDZ, by running ./compile.sh \
-             in modeles/LMDZ >> compile_orc.sh
-        chmod u+x compile_orc.sh
-        ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
-                           -parallel "$parallel" -arch $arch > "$orchideelog" 2>&1
-        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel "$parallel" \
-                           -arch $arch >> "$orchideelog" 2>&1
-        echo "End of ORCHIDEE compilation in parallel mode $(date)"
-    elif [[ $veget != 'none' ]]; then
-        echo '##########################################################'
-        echo ' Orchidee version too old                                 '
-        echo ' Please update to new version                             '
-        echo '##########################################################'
-        exit 1
-    fi #�of [ -d src_parallel && $veget != 'none' ]
-
-    # LMDZ
-    cd "$LMDZPATH"
-    if [[ $arch = local ]]; then
-        cd arch
-        sed -e s:"%COMPILER.*.$:%COMPILER            $par_comp":1 \
-            -e s:"%LINK.*.$:%LINK                $par_comp":1 \
-            -e s:"%MPI_FFLAG.*.$:%MPI_FFLAGS          $MPI_FLAGS":1 \
-            -e s:"%OMP_FFLAG.*.$:%OMP_FFLAGS          $OMP_FLAGS":1 \
-            -e s:"%ARFLAGS.*.$:%ARFLAGS          $ARFLAGS":1 \
-            -e "s§%BASE_LD.*.$§%BASE_LD             -Wl,-rpath=${root_mpi}/lib:${ncdfdir}/lib§1" \
-            -e s:"%MPI_LD.*.$:%MPI_LD              $MPI_LD":1 \
-            -e s:"%OMP_LD.*.$:%OMP_LD              $OMP_LD":1 \
-            arch-local.fcm > tmp.fcm
-        mv tmp.fcm arch-local.fcm
-        cd ../
-    fi
-    rm -f compile.sh
-    echo resol="$grid_resolution" >> compile.sh
-    if [[ ${hostname:0:5} = jean- && "$cosp" = "v2" ]]; then
-
-        echo "LMDZ compilation command in parallel mode, saved in compile.sh, is :"
-        echo "(ATTENTION le probleme de cospv2 sur jean-zay en mode prod " \
-             "n est pas corrige ! )"
-        # ATTENTION le probleme de cospv2 sur jean-zay en mode prod n
-        # est pas corrige
-        echo ./"$makelmdz" -dev $optim_debug "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
-             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
-             -parallel "$parallel" gcm >> compile.sh
-        echo ./"$makelmdz" -dev $optim_debug "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
-             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
-             -parallel "$parallel" gcm
-    else
-        echo ./"$makelmdz" $optim_debug "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
-             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
-             -parallel "$parallel" gcm >> compile.sh
-        echo ./"$makelmdz" $optim_debug "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
-             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
-             -parallel "$parallel" gcm
-    fi
-    chmod +x ./compile.sh
-
-    if [[ $bench = 1 ]]; then
-        echo "Compiling LMDZ in parallel mode $(date),  LMDZ log file: $lmdzlog"
-        ./compile.sh > "$lmdzlog" 2>&1
-    fi
-
-fi # of if [[ $parallel != "none" ]]
-
-
-##################################################################
-# Verification du succes de la compilation
-##################################################################
-
-# Recherche de l'executable dont le nom a change au fil du temps ...
-# suffix contains radiative option starting with revision 4186
-if [[ $mysvn -ge 4186 ]]; then suff_exe=_${rad}${suff_exe}; fi
-gcm=""
-
-for exe in gcm.e bin/gcm_${grid_resolution}_phylmd${suff_exe}${suff_orc}.e
-do
-    if [[ -f $exe ]]; then gcm=$exe; fi
-done
-
-if [[ "$gcm" = "" ]]; then
-    if [[ $bench = 1 ]]; then
-        echo 'Compilation failed !! Cannot run the benchmark;'
-        exit 1
-    else
-        echo 'Compilation not done (only done when bench=1)'
-    fi
-else
-    echo '##########################################################'
-    echo "Compilation successfull !!  $(date)"
-    echo '##########################################################'
-    echo "The executable is $gcm"
-fi
-
-##################################################################
-# Below, we run a benchmark if bench=1 or tuto
-##################################################################
-
-if [[ $bench = tuto ]]; then
-    myget Training/tutorial.tar; tar xf tutorial.tar; cd TUTORIAL
-    ./init.sh
-
-elif [[ $bench = 1 && ! -d BENCH${grid_resolution} ]]; then
-    # TOUTE CETTE SECTION DEVRAIT DISPARAITRE POUR UNE COMMANDE
-    # OU DES BENCHS PAR MOTS CLES COMME tuto
-
-    echo '##########################################################'
-    echo ' Running a test run '
-    echo '##########################################################'
-
-    \rm -rf "BENCH${grid_resolution}"
-    bench=bench_lmdz_${grid_resolution}
-    echo "install_lmdz.sh before bench download  $(date)"
-    #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/$bench.tar.gz
-    myget "3DBenchs/$bench.tar.gz"
-    echo "install_lmdz.sh after bench download  $(date)"
-    tar xf "$bench.tar.gz"
-
-    if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
-        cd "BENCH${grid_resolution}"
-        # copier les fichiers namelist input et output our COSP
-        cp ../DefLists/cosp*_input_nl.txt .
-        cp ../DefLists/cosp*_output_nl.txt .
-        # Activer la cles ok_cosp pour tourner avec COSP
-        sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp
-        \mv -f tmp config.def
-        cd ..
-    fi
-
-    if [[ -n "$physiq" ]]; then
-        cd "BENCH${grid_resolution}"
-        if [[ -f "physiq.def_${physiq}" ]]; then
-            cp "physiq.def_${physiq}" physiq.def
-            echo using "physiq.def_${physiq}"
-        else
-            echo using standard physiq.def
-        fi
-        cd ..
-    else
-        echo using standard physiq.def
-    fi
-
-    if [[ "$with_xios" = "y" ]]; then
-        cd "BENCH${grid_resolution}"
-        cp ../DefLists/iodef.xml .
-        cp ../DefLists/context_lmdz.xml .
-        cp ../DefLists/field_def_lmdz.xml .
-        # A raffiner par la suite
-        echo "A FAIRE : Copier les *xml en fonction de l option cosp"
-        cp ../DefLists/field_def_cosp*.xml .
-        cp ../DefLists/file_def_hist*xml .
-        # adapt iodef.xml to use attached mode
-        sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' \
-            iodef.xml > tmp
-        \mv -f tmp iodef.xml
-
-        # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
-        # except for histday
-        for histfile in file_def_hist*xml
-        do
-            if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then
-                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \
-                    "$histfile" > tmp
-                \mv -f tmp "$histfile"
-                sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \
-                    > tmp
-                \mv -f tmp "$histfile"
-                sed -e 's@compression_level="2"@compression_level="0"@' \
-                    "$histfile" > tmp
-                \mv -f tmp "$histfile"
-            else
-                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
-                    "$histfile" > tmp
-                \mv -f tmp "$histfile"
-            fi
-        done
-        # and add option "ok_all_xml=y" in config.def
-        echo "### XIOS outputs" >> config.def
-        echo 'ok_all_xml=.true.' >> config.def
-
-        #activer les sorties pour Cosp
-        if [[ "$cosp" = "v1" ]]; then
-            sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \
-                     -e 's@output_level="_AUTO_"@output_level="5"@' \
-                     -e 's@compression_level="2"@compression_level="0"@' \
-                     file_def_histdayCOSP_lmdz.xml
-        fi
-        if [[ "$cosp" = "v2" ]]; then
-            sed -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml
-            for type_ in hf day mth; do
-                file=file_def_hist${type_}COSP
-                sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml
-            done
-            sed -i '' -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' field_def_lmdz.xml
-        fi
-
-        cd ..
-    fi
-
-    # Cas Bensh avec ecrad
-    if [[ "$rad" = "ecrad" ]]; then
-        cd "BENCH${grid_resolution}"
-        cp  ../DefLists/namelist_ecrad .
-        cp -r ../libf/phylmd/ecrad/data .
-        cd ..
-    fi
-
-    # Adjusting bench physiq.def to radiative code chosen
-    cd "BENCH${grid_resolution}"
-    sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \
-        -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
-    \mv tmpdef physiq.def
-    cd ..
-
-    cp "$gcm" "BENCH${grid_resolution}/gcm.e"
-
-    cd "BENCH${grid_resolution}"
-    # On cree le fichier bench.sh au besoin
-    # Dans le cas 48x36x39 le bench.sh existe deja en parallele
-
-    if [[ "$grid_resolution" = "48x36x39" ]]; then
-        echo On ne touche pas au bench.sh
-        # But we have to adapt "run_local.sh" for $mpirun
-        sed -e "s@mpirun@$mpirun@g" run_local.sh > tmp
-        mv -f tmp run_local.sh
-        chmod u=rwx run_local.sh
-    elif [[ "${parallel:0:3}" = "mpi" ]]; then
-        # Lancement avec deux procs mpi et 2 openMP
-        echo "export OMP_STACKSIZE=800M" > bench.sh
-        if [[ "${parallel:4:3}" = "omp" ]]; then
-            echo "export OMP_NUM_THREADS=2" >> bench.sh
-        fi
-        if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
-            if [[ ${hostname:0:5} = jean- ]]; then
-                   chmod +x ../arch.env
-                ../arch.env        
-                echo "ulimit -s 2000000" >> bench.sh
-            else
-                echo "ulimit -s 200000" >> bench.sh
-            fi        
-        else
-            echo "ulimit -s unlimited" >> bench.sh
-        fi
-        if [[ ${hostname:0:5} = jean- ]]; then
-            . ../arch/arch-${arch}.env
-            echo "srun -n 2 && $idris_acct@cpu gcm.e > listing  2>&1" \
-                 >> bench.sh
-        else
-            echo "$mpirun -np 2 gcm.e > listing  2>&1" >> bench.sh
-        fi
-        # Add rebuild, using reb.sh if it is there
-        cat <<EOF >> bench.sh
-if [[ -f reb.sh ]]; then
-  ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf;
-  ./reb.sh histins; ./reb.sh stomate_history;
-  ./reb.sh sechiba_history; ./reb.sh sechiba_out_2
-fi
-EOF
-    else
-        echo "./gcm.e > listing  2>&1" > bench.sh
-    fi
-    # Getting orchidee stuff
-    if [[ $veget == 'CMIP6' ]]; then
-        #echo 'myget 3DBenchs/BENCHorch11.tar.gz'
-        #myget 3DBenchs/BENCHorch11.tar.gz
-        #tar xvzf BENCHorch11.tar.gz
-        echo 'myget 3DBenchs/BENCHCMIP6.tar.gz'
-        myget 3DBenchs/BENCHCMIP6.tar.gz
-        tar xvzf BENCHCMIP6.tar.gz
-        sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
-        mv -f tmp config.def
-        if [[ "$with_xios" = "y" ]]; then
-            cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
-            echo '<context id="orchidee" src="./context_orchidee.xml"/>' \
-                 > add.tmp
-            cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml .
-            cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
-            cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
-            if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then
-                   cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
-                   echo '<context id="orchidee" ' \
-                     'src="./context_input_orchidee.xml"/>' >> add.tmp
-            fi
-            sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp
-            mv tmp iodef.xml
-            sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' \
-                file_def_orchidee.xml > tmp
-            \mv -f tmp file_def_orchidee.xml
-            sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
-                file_def_orchidee.xml > tmp
-            \mv -f tmp file_def_orchidee.xml
-            sed -e 's@output_level="_AUTO_"@output_level="1"@' \
-                file_def_orchidee.xml > tmp
-            \mv -f tmp file_def_orchidee.xml
-            sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' \
-                file_def_orchidee.xml > tmp
-            \mv -f tmp file_def_orchidee.xml
-            sed -e 's@compression_level="4"@compression_level="0"@' \
-                file_def_orchidee.xml > tmp
-            \mv -f tmp file_def_orchidee.xml
-            sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' \
-                orchidee.def > tmp
-            \mv -f tmp orchidee.def
-        fi
-    fi
-
-    if [[ -f ../arch.env ]]
-    then
-        source ../arch.env
-    fi
-
-    echo EXECUTION DU BENCH
-    set +e
-    date; ./bench.sh > out.bench 2>&1; date
-    set -e
-    tail listing
-
-
-    echo "##########################################################"
-    echo "Simulation finished in $(pwd)"
-    echo "You have compiled with:"
-    cat ../compile.sh
-    if [[ $parallel = "none" ]]; then
-        echo "You may re-run it with : cd  $(pwd); gcm.e"
-        echo "or ./bench.sh"
-    else
-        echo "You may re-run it with : "
-        echo "cd  $(pwd); ./bench.sh"
-        #  echo 'ulimit -s unlimited'
-        #  echo 'export OMP_NUM_THREADS=2'
-        #  echo 'export OMP_STACKSIZE=800M'
-        #  echo "$mpirun -np 2 gcm.e "
-    fi
-    echo '##########################################################'
-
-fi # bench
-
-
-#################################################################
-# Installation eventuelle du 1D
-#################################################################
-
-if [[ $SCM = 1 ]]; then
-    cd "$MODEL"
-    myget 1D/1D.tar.gz
-    tar xf 1D.tar.gz
-    cd 1D
-    if [[ $rad = oldrad ]]; then
-        sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh
-        sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile
-    fi
-    echo "Running 1D/run.sh, log in $(pwd)/run1d.log"
-    ./run.sh > "$(pwd)/run1d.log" 2>&1
-fi
-
-
-#################################################################
-# sauvegarde des options veget pour utilisation eventuelle tutorial_prod
-#################################################################
-cd "$MODEL/modipsl/modeles"
-#echo surface_env file created in $MODEL
-cat <<EOF >surface_env
-veget=$veget
-opt_veget="-v $veget_version"
-orchidee_rev=$orchidee_rev
-suforch=$suff_orc
-EOF
+compile_orchidee
+compile_lmdz
+run_bench
