Index: BOL/script_install_amaury/install_lmdz.sh
===================================================================
--- BOL/script_install_amaury/install_lmdz.sh	(revision 5030)
+++ BOL/script_install_amaury/install_lmdz.sh	(revision 5031)
@@ -247,5 +247,9 @@
     if [[ $MODEL = "" ]]; then MODEL="./LMDZ$version${svn_lmdz}OR$veget$xios_name"; fi
 
-    if [[ $arch_dir = "" ]]; then arch_dir="$MODEL/modipsl/config/IPSLCM7/ARCH/"; fi
+    if [[ $arch_dir = "" ]]; then
+      arch_dir="$MODEL/modipsl/config/IPSLCM7/ARCH/";
+    elif ! readlink -fe "$arch_dir"; then
+      echo "STOP: no arch dir <$arch_dir>"; exit 1
+    fi
 }
 
@@ -317,7 +321,7 @@
     mkdir -p "$MODEL"
     MODEL=$(readlink -e -f "$MODEL"); echo "$MODEL"  # absolute path
-    if [[ ! -f "$MODEL/modipsl" ]]; then
+    if [[ ! -d "$MODEL/modipsl" ]]; then
         echo "##########################################################"
-        echo "Download a slightly modified version of  LMDZ"
+        echo "Download a slightly modified version of LMDZ"
         echo "##########################################################"
         cd "$MODEL"
@@ -334,35 +338,29 @@
 
 function init_arch {
-    arch_dir=$(readlink -e -f "$arch_dir")  # full path. readlink must be called *after* the path is created
-    if [[ ! -d $arch_dir ]]; then
-        echo "STOP: no arch dir $arch_dir"; exit 1
-    fi
-
-    local fcm_path
-    if [[ -f $arch_dir/arch-$arch.fcm ]]; then
-        fcm_path="$arch_dir/arch-$arch.fcm"
-    else
-        fcm_path="$MODEL/modipsl/modeles/LMDZ/arch/arch-$arch.fcm"
-        if [[ ! -f $fcm_path ]]; then
-            echo "STOP: no $fcm_path"; exit 1
-        fi
-    fi
-
-    local env_path
-    if [[ -f $arch_dir/arch-$arch.env ]]; then
-        env_path="$arch_dir/arch-$arch.env"
-    else
-        env_path="$MODEL/modipsl/modeles/LMDZ/arch/arch-$arch.env"
-        if [[ ! -f $env_path ]]; then
-            echo "STOP: no $env_path"; exit 1
-        fi
-    fi
+    set +e; arch_dir=$(readlink -f "$arch_dir"); set -e  # full path. readlink must be called *after* the path is created
+
+    # Check where default fcm, path, env are located - by default in $arch_path, instead in $MODEL/modipsl/modeles/LMDZ/arch/
+    local i fcm_path path_path env_path
+    for i in "path" "fcm" "env"; do
+      local varname=${i}_path
+      if [[ -f $arch_dir/arch-$arch.$i ]]; then
+          declare $varname="$arch_dir/arch-$arch.$i"
+      else
+          declare $varname="$MODEL/modipsl/modeles/LMDZ/arch/arch-$arch.$i"
+          if [[ ! -f ${!varname} ]]; then
+              echo "STOP: no ${!varname}"; exit 1
+          fi
+      fi
+    done
+    default_fcm_path=$fcm_path
+    default_path_path=$path_path
+    default_env_path=$env_path
 
     # check compiler
-    compiler=$(< "$fcm_path" grep "%COMPILER" | sed -e "s/%COMPILER\s*//")
+    compiler=$(< "$default_fcm_path" grep "%COMPILER" | sed -e "s/%COMPILER\s*//")
 
     # load env
     # shellcheck disable=SC1090
-    if [[ -f $env_path ]]; then source "$env_path"; fi
+    if [[ -f $default_env_path ]]; then source "$default_env_path"; fi
 }
 
@@ -370,14 +368,23 @@
     local component=$1
 
-    if [[ -f "$arch_dir/arch-$arch.env" ]]; then
-        cp -f "$arch_dir/arch-$arch."{fcm,path,env} "$MODEL/modipsl/modeles/$component/arch" &> /dev/null || true  # allow failure if doesn't exist
+    # Use same .env for all components (for module compatibility)
+    cp -f "$default_env_path" "$MODEL/modipsl/modeles/$component/arch" &> /dev/null || true  # allow failure if we're copying the file to itself
+
+    # Use local .path and .fcm is available, otherwise default
+    if [[ ! -f "$MODEL/modipsl/modeles/$component/arch/arch-$arch.path" ]]; then
+        cp -f "$default_path_path" "$MODEL/modipsl/modeles/$component/arch"
+
+        if [[ $component = "ORCHIDEE" ]]; then
+            if [[ $orcbranch = "/tags/ORCHIDEE_2_0/ORCHIDEE" ]]; then  # 2.0 and before have a different fcm convention
+                sed -i'' -e "s/-I//" -e "s/-L//" "$MODEL/modipsl/modeles/ORCHIDEE/arch/arch-$arch.path"  # /!\ we only replace first occurence on purpose
+            fi
+        fi
+    fi
+    if [[ ! -f "$MODEL/modipsl/modeles/$component/arch/arch-$arch.fcm" ]]; then
+        cp -f "$default_fcm_path"  "$MODEL/modipsl/modeles/$component/arch"
 
         if [[ $component = "XIOS" ]]; then
             # Adapt for XIOS, which uses different naming conventions
             sed -i'' -e "s/%COMPILER/%FCOMPILER/" -e "s/%LINK/%LINKER/" -e "s/-fdefault-real-8//" "$MODEL/modipsl/modeles/XIOS/arch/arch-$arch.fcm"
-        elif [[ $component = "ORCHIDEE" ]]; then
-            if [[ $orcbranch = "/tags/ORCHIDEE_2_0/ORCHIDEE" ]]; then  # 2.0 and before have a different fcm convention
-                sed -i'' -e "s/-I//" -e "s/-L//" "$MODEL/modipsl/modeles/ORCHIDEE/arch/arch-$arch.path"  # /!\ we only replace first occurence on purpose
-            fi
         fi
     fi
@@ -469,5 +476,5 @@
         myget src_archives/netcdf/NetCDF95-0.3.tar.gz
         tar -xf NetCDF95-0.3.tar.gz
-        \rm NetCDF95-0.3.tar.gz
+        rm NetCDF95-0.3.tar.gz
         cd NetCDF95-0.3
         mkdir -p build && cd build
@@ -533,4 +540,8 @@
         "orch2.2") fcm_veget_version=orchidee2.1; orcbranch="/branches/ORCHIDEE_2_2/ORCHIDEE" ;; # the bundled version
         *) fetch_rev=$veget; fcm_veget_version=orchidee2.1;;  # /!\ arbitary rev only works for orch>=2.1
+          # /!\ Note: for orch>=4, we should be using fcm_vegt_version="orchideetrunk". Below copied comment by Adriana in LMDZ_Setup docs:
+#          Avec orchidee2.1, on va compiler LMDZ avec le cle cpp ORCHIDEE_NOLIC. On ne va donc pas prendre en compte les avancements fait dans le trunk qui permet que les fractions lic soitent traité par ORCHIDEE. Ca marche très bien sans cela puisque dans tout façon c'est en cours de développement et ce n'est pas activé par default. En fait on devrait compiler le trunk avec -v orchideetrunk mais avec landice_opt>2, ce qui ne change rien par rapport à orchidee2.1
+#Si on voudrait activer landice_opt=2 , il faut compiler avec -v orchideetrunk.
+
     esac
 
