Index: BOL/script_install_amaury/install_lmdz.sh
===================================================================
--- BOL/script_install_amaury/install_lmdz.sh	(revision 4862)
+++ BOL/script_install_amaury/install_lmdz.sh	(revision 4871)
@@ -38,16 +38,12 @@
 ### Functions
 
-function myget {
-    # A function to fetch files either locally or on the internet
-
-    local file_name=$1
-    # Path on local computer where to look for the datafile
-    if [[ -f "/u/lmdz/WWW/LMDZ/pub/$file_name" ]]; then
-        \cp -f -p "/u/lmdz/WWW/LMDZ/pub/$file_name" .
-    elif [[ -f ~"/LMDZ/pub/$file_name" ]]; then
-        \cp -f -p ~"/LMDZ/pub/$file_name" .
-    else
-        wget --no-check-certificate -nv "http://lmdz.lmd.jussieu.fr/pub/$file_name"
-    fi
+function myget { # Get a file from LMDZ repository
+  local url=$1
+
+  local filename
+  filename=$(basename "$url")
+
+  wget --no-check-certificate -nv "http://lmdz.lmd.jussieu.fr/pub/$url"
+  if [[ $filename =~ .*\.(ba)?sh ]]; then chmod +x "$filename"; fi
 }
 
@@ -323,4 +319,29 @@
         \rm "modipsl.$version.tar"
     fi
+
+    if [[ $svn != "" ]]; then
+        mysvn=$svn
+    else
+        mysvn="$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null)"
+    fi
+    echo "SVN revision used: $mysvn"
+}
+
+function setup_local_arch {
+    # Setup local arch, and correspondance between arch names accross different programs
+
+    case $arch in
+        local)
+            arch_ioipsl="gfortran"
+            arch_xios="local"
+
+            cat <<EOF >"$MODEL/modipsl/modeles/IOIPSL/arch/arch-${arch_ioipsl}.path"  # fix bad IOIPSL arch files...
+NETCDF_INCDIR="\$(nf-config --fflags)"
+NETCDF_LIBDIR="\$(nf-config --flibs)"
+EOF
+        ;;
+      *) arch_ioipsl=$arch
+         arch_xios=$arch
+  esac
 }
 
@@ -405,5 +426,5 @@
     echo "Compiling IOIPSL, the interface library with Netcdf $(date) (log: $ioipsllog)"
 
-    if ! ./makeioipsl_fcm -job 8 > "$ioipsllog" 2>&1; then
+    if ! ./makeioipsl_fcm -arch "$arch_ioipsl" -job 8 > "$ioipsllog" 2>&1; then
       echo "IOIPSL compile failed, exiting"; exit 1
     fi
@@ -413,4 +434,21 @@
 }
 
+function install_XIOS {
+    if [[ $with_xios = "y"  && ! -f "$MODEL/modipsl/modeles/XIOS/lib/libxios.a" ]]; then
+        cd "$MODEL/modipsl/modeles"
+        xioslog="$(pwd)/xios.log"
+        echo "##########################################################"
+        echo "Compiling XIOS (log $xioslog) $(date)"
+        echo "##########################################################"
+        myget script_install/install_xios.bash
+
+        if ! ./install_xios.bash -prefix "$MODEL/modipsl/modeles" -arch "$arch_xios" > "$xioslog" 2>&1; then
+            echo "XIOS compilation failed, exiting"; exit 1
+        fi
+
+        echo "Compiled XIOS $(date)"
+    fi
+}
+
 echo "install_lmdz.sh DEBUT $(date)"
 
@@ -419,6 +457,10 @@
 check_available_software
 download_model
+setup_local_arch
 install_netcdf
 install_IOIPSL
+install_XIOS
+
+exit 0
 
 
@@ -562,48 +604,10 @@
 
 
-if [[ "$with_xios" = "y" ]]; then
-    echo '##########################################################'
-    echo 'Compiling XIOS'
-    echo '##########################################################'
-    cd "$MODEL/modipsl/modeles"
-    xioslog="$(pwd)/xios.log"
-    #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/install_xios.bash
-    myget script_install/install_xios.bash
-    chmod u=rwx install_xios.bash
-# following will be recalculated later on once LMDZ is updated
-#    mysvn=`svnversion LMDZ | egrep || "[0-9]+" 2>/dev/null`
-    mysvn=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null)
-    if [[ $svn != "" ]]; then mysvn=$svn; fi
-    echo "mysvn $mysvn"
-
-    if [[ ${hostname:0:5} = jean- ]]; then
-        if [[ $mysvn -ge 4619 ]]; then
-            svn co http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6 XIOS
-        else
-            svn co http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.5 XIOS
-        fi
-        cd XIOS/arch
-        svn update
-        cd ..
-        echo "Compiling XIOS, start $(date) (it takes about 20 min on Jean-Zay)"
-        echo "log file: $xioslog"
-        ./make_xios --prod --arch $arch --job 4 > xios.log 2>&1
-    else
-        ./install_xios.bash -prefix "$MODEL/modipsl/modeles" \
-                            -netcdf "$ncdfdir" -hdf5 "$ncdfdir" \
-                            -MPI "$root_mpi" -arch $arch > xios.log 2>&1
-    fi # of case Jean-Zay
-    if [[ -f XIOS/lib/libxios.a ]]; then
-        echo "XIOS library successfully generated"
-        echo install_lmdz.sh XIOS_OK "$(date)"
-    fi
-fi
-
 #============================================================================
 veget_version=false
-if [[ "$veget" != 'NONE' ]]; then
+if [[ $veget != 'NONE' ]]; then
     cd "$MODEL/modipsl/modeles/ORCHIDEE"
     set +e; svn upgrade; set -e
-    if [[ "$veget" = "CMIP6" ]]; then
+    if [[ $veget = "CMIP6" ]]; then
         veget_version=orchidee2.0
         orchidee_rev=6592
@@ -652,9 +656,4 @@
         # Pour les experts qui voudraient changer de version d'orchidee.
         # Attention : necessite d'avoir le password pour orchidee
-
-        # Correctif suite debug Jean-Zay
-        if [[ -f src_global/time.f90 ]]; then
-            sed -i -e 's/CALL tlen2itau/\!CALL tlen2itau/' src_global/time.f90
-        fi
         ###################################################################
         if [[ "$veget_version" == "false" ]]; then
Index: BOL/script_install_amaury/install_xios.bash
===================================================================
--- BOL/script_install_amaury/install_xios.bash	(revision 4862)
+++ BOL/script_install_amaury/install_xios.bash	(revision 4871)
@@ -1,129 +1,115 @@
-#!/bin/bash 
-#########################################################################
-# Defaults
-#########################################################################
-hostname=`hostname`
-install_dir=$(pwd)
-netcdf_home="/usr/local/netcdf"
-hdf5_home="/usr/local/hdf5"
-if [ -d /usr/lib64/openmpi ] ; then
-  mpi_home="/usr/lib64/openmpi"
-else
-  mpi_home="/usr"
-fi
-arch="local"
-#xios_branch="trunk"
-xios_branch="2.6"
-#xios_rev="HEAD"
-xios_rev="2568"
+#!/bin/bash
+set -e -u  # exit on most (not all!) error codes, and error on unset variables
 
-#########################################################################
-#  Options 
-#########################################################################
-while (($# > 0))
-   do
-   case $1 in
-     "-h") cat <<........fin
-    $0 [ -prefix path ]       where (path) to install
-                              (default: $install_dir)
-       [ -netcdf path ]       top directory of the netcdf library
-                              (default: $netcdf_home)
-       [ -hdf5 path ]         top directory of the hdf5 library
-                              (default: $hdf5_home)
-       [ -MPI path ]          top directory of the MPI library
-                              (default: $mpi_home)
-       [ -branch branch]      XIOS branch trunk|2.5|2.6
-                              (default: $xios_branch)
-       [ -rev number ]        XIOS revision
-                              (default: $xios_rev)
-       [ -arch ARCH ]         Use ARCH file (provided by XIOS)
-                              (default: make/use a local arch file)
-........fin
-     exit ;;
-     "-prefix") install_dir=$2 ; shift ; shift ;;
-     "-netcdf") netcdf_home=$2 ; shift ; shift ;;
-     "-hdf5" ) hdf5_home=$2 ; shift ; shift ;;
-     "-MPI") mpi_home=$2 ; shift ; shift ;;
-     "-branch") xios_branch=$2 ; shift ; shift ;;
-     "-rev") xios_rev=$2 ; shift ; shift ;;
-     "-arch") arch=$2 ; shift ; shift ;;
-     *) echo "Error, bad argument $1" ; $0 -h ; exit
-   esac
-done
+# Installs xios
+# Rewritten 02/2024 A. Barral
 
-# Install directory (get full path)
-mkdir -p $install_dir
-install_dir=$(cd $install_dir ; pwd -P )
+function read_args {
+  ## Defaults
+  install_dir=$(pwd)
 
-# Download XIOS
-case $xios_branch in
-  "trunk")
-  xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/trunk" ;;
-  "2.5")
-  xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-2.5" ;;
-  "2.6")
-  xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6" ;;
-*)
-echo "Error, bad argument for -branch ! Did not expect $xios_branch" ; exit ;;
-esac
+  xios_branch="2.6"
+  xios_rev="2568"
+  arch="local"
+  make_j="8"
+  # Not inputs
+  hdf5_home=$(dirname "$(dirname "$(readlink -f "$(which h5pcc)")")")
+  mpi_home=$(dirname "$(dirname "$(readlink -f "$(which mpif90)")")")
 
-cd $install_dir
-svn co --revision $xios_rev $xios_http XIOS
+  while (($# > 0)); do
+    case $1 in
+      "-h") cat <<eof
+      $0 [ -prefix path ]       where (path) to install (default: $install_dir)
+      [ -branch branch]         XIOS branch trunk|2.5|2.6 (default: $xios_branch)
+      [ -rev number ]           XIOS revision (default: $xios_rev)
+      [ -arch ARCH ]            Use ARCH file (provided by XIOS) (default: make/use a local arch file)
+      [ -make_j N ]             Number of procs for compilation
+eof
+      exit;;
+      "-prefix") install_dir=$2; shift; shift;;
+      "-branch") xios_branch=$2; shift; shift;;
+      "-rev") xios_rev=$2; shift; shift;;
+      "-arch") arch=$2; shift; shift;;
+      "-make_j") make_j=$2; shift; shift;;
+      *) echo "Error, bad argument $1"; $0 -h; exit
+    esac
+  done
+}
 
-# Make arch files, if necesary:
-if [ "$arch" = "local" ] ; then
-cd $install_dir/XIOS/arch
-# arch-local.env
-echo 'export MPI_LIB="-L'${mpi_home}'/lib -lmpi"'     > arch-local.env
-echo ''                                              >> arch-local.env
-echo 'export NETCDFC='${netcdf_home}                 >> arch-local.env
-echo 'export NETCDFC_LIB=$NETCDFC/lib'               >> arch-local.env
-echo 'export NETCDFC_INC=$NETCDFC/include'           >> arch-local.env
-echo ''                                              >> arch-local.env
-echo 'export NETCDFF='${netcdf_home}                 >> arch-local.env
-echo 'export NETCDFF_LIB=$NETCDFF/lib'               >> arch-local.env
-echo 'export NETCDFF_INC=$NETCDFF/include'           >> arch-local.env
-echo ''                                              >> arch-local.env
-echo 'export NETCDFCXX='${netcdf_home}               >> arch-local.env
-echo 'export NETCDFCXX_LIB=$NETCDFCXX/lib'           >> arch-local.env
-echo 'export NETCDFCXX_INC=$NETCDFCXX/include'       >> arch-local.env
+function download_xios {
+  # Install directory (get full path)
+  mkdir -p "$install_dir"
+  install_dir=$(cd "$install_dir" || exit 1; pwd -P)
 
-# arch-local.fcm
-echo '%CCOMPILER      '${mpi_home}'/bin/mpicc'             > arch-local.fcm
-echo '%FCOMPILER      '${mpi_home}'/bin/mpif90'           >> arch-local.fcm
-echo '%LINKER         '${mpi_home}'/bin/mpif90'           >> arch-local.fcm
-echo ''                                                   >> arch-local.fcm
-if [ ${hostname:0:5} = cicla ] ; then
-echo '%BASE_CFLAGS    -w -ansi'                >> arch-local.fcm
-else
-echo '%BASE_CFLAGS    -w -std=c++11 -D__XIOS_EXCEPTION'   >> arch-local.fcm
-fi
-echo '%PROD_CFLAGS    -O3 -D BOOST_DISABLE_ASSERTS'       >> arch-local.fcm
-echo '%DEV_CFLAGS     -g -O2'                             >> arch-local.fcm
-echo '%DEBUG_CFLAGS   -g -DBZ_DEBUG'                      >> arch-local.fcm
-echo ''                                                   >> arch-local.fcm
-echo '%BASE_FFLAGS    -D__NONE__ -ffree-line-length-none' >> arch-local.fcm
-echo '%PROD_FFLAGS    -O3'                                >> arch-local.fcm
-echo '%DEV_FFLAGS     -g -O2'                             >> arch-local.fcm
-echo '%DEBUG_FFLAGS   -g'                                 >> arch-local.fcm
-echo ''                                                   >> arch-local.fcm
-echo '%BASE_INC       -D__NONE__'                         >> arch-local.fcm
-echo '%BASE_LD        -lstdc++ -Wl,-rpath='${mpi_home}'/lib' >> arch-local.fcm
-echo ''                                                   >> arch-local.fcm
-echo '%CPP            '${mpi_home}'/bin/mpicc -EP'        >> arch-local.fcm
-echo '%FPP            cpp -P'                             >> arch-local.fcm
-echo '%MAKE           make'                               >> arch-local.fcm
+  local xios_http
+  case $xios_branch in
+    "trunk") xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/trunk";;
+    "2.5") xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-2.5";;
+    "2.6") xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6";;
+    *) echo "Error, bad argument for -branch ! Did not expect $xios_branch"; exit 1;;
+  esac
 
-# arch-local.path
-echo 'NETCDF_INCDIR="-I${NETCDFC_INC} -I${NETCDFF_INC} -I${NETCDFCXX_INC} "'  > arch-local.path
-echo 'NETCDF_LIBDIR="-L${NETCDFC_LIB} -L${NETCDFF_LIB} -L${NETCDFCXX_LIB} "' >> arch-local.path
-echo 'NETCDF_LIB="-lnetcdf -lnetcdff -lnetcdf_c++4"'                         >> arch-local.path
-echo 'HDF5_INCDIR="-I'${hdf5_home}'/include"'                                >> arch-local.path
-echo 'HDF5_LIBDIR="-L'${hdf5_home}'/lib"'                                    >> arch-local.path
-echo 'HDF5_LIB="-lhdf5_hl -lhdf5 -lhdf5 -lz -lcurl"'                         >> arch-local.path
-fi
+  cd "$install_dir" || exit 1
+  svn co --revision "$xios_rev" "$xios_http" XIOS
+}
 
-# make XIOS
-cd $install_dir/XIOS
-./make_xios --arch $arch --job 8 2>&1 | tee make_xios.out
+function create_local_arch {
+  cd "$install_dir/XIOS/arch" || exit 1
 
+  cat <<eof > arch-local.env
+export MPI_LIB="-L${mpi_home}/lib -lmpi"
+
+export NETCDFC_INC="\$(nc-config --includedir)"
+export NETCDFC_LIB="\$(nc-config --libdir)"
+
+export NETCDFF_INC="\$(nf-config --includedir)"
+export NETCDFF_LIB="\$(nf-config --prefix)/lib"
+
+export NETCDFCXX_INC="\$(ncxx4-config --includedir)"
+export NETCDFCXX_LIB="\$(ncxx4-config --libdir)"
+eof
+
+  cat <<eof > arch-local.fcm
+%CCOMPILER      "$(which mpicc)"
+%FCOMPILER      "$(which mpif90)"
+%LINKER         "$(which mpif90)"
+
+%BASE_CFLAGS    -w -std=c++11 -D__XIOS_EXCEPTION
+%PROD_CFLAGS    -O3 -D BOOST_DISABLE_ASSERTS
+%DEV_CFLAGS     -g -O2
+%DEBUG_CFLAGS   -g -DBZ_DEBUG
+
+%BASE_FFLAGS    -D__NONE__ -ffree-line-length-none
+%PROD_FFLAGS    -O3
+%DEV_FFLAGS     -g -O2
+%DEBUG_FFLAGS   -g
+
+%BASE_INC       -D__NONE__
+%BASE_LD        -lstdc++ -Wl,-rpath=${mpi_home}/lib
+
+%CPP            $(which mpicc) -EP
+%FPP            cpp -P
+%MAKE           make
+eof
+  cat <<eof > arch-local.path
+NETCDF_INCDIR="-I\${NETCDFC_INC} -I\${NETCDFF_INC} -I\${NETCDFCXX_INC}"
+NETCDF_LIBDIR="-L\${NETCDFC_LIB} -L\${NETCDFF_LIB} -L\${NETCDFCXX_LIB}"
+NETCDF_LIB="-lnetcdf -lnetcdff -lnetcdf_c++4"
+
+HDF5_INCDIR="-I${hdf5_home}/include"
+HDF5_LIBDIR="-L${hdf5_home}/lib"
+HDF5_LIB="-lhdf5_hl -lhdf5 -lz -lcurl"
+eof
+}
+
+function make_xios {
+  cd "$install_dir/XIOS"
+  echo "Compiling xios, see $(pwd)/make_xios.out"
+  ./make_xios --arch "$arch" --job "$make_j" >make_xios.out 2>&1
+}
+
+read_args "$@"
+download_xios
+if [[ $arch = "local" ]]; then create_local_arch; fi
+make_xios
+
