Index: BOL/LMDZ_Setup_amaury/README0_HowTo
===================================================================
--- BOL/LMDZ_Setup_amaury/README0_HowTo	(revision 4934)
+++ 	(revision )
@@ -1,144 +1,0 @@
-Last update : 2023-07-05
-===================================================================
-
-Complementary information and FAQ (in French) :
-https://docs.google.com/document/d/1OLZG6e-86NiXuv5-aALxKIh-QPkp4BdCwWtiBFot-6c
-
-===================================================================
-I. What this working environment does and does not
-===================================================================
-
-This tutorial can only be used on jean-zay computer at idris so far.
-    However, extension to ciclad or irene will be done soon.
-
-It proposes a light automatic setup of LMDZ long chained climate simulations
-   including installation of the model itself.
-
-It consists in running LMDZ coupled to Orchidee for land surface (optional)
-   but with imposed sea surface temperature.
-
-The basic default configuration makes use of the IPSL-CM6A grid configuration
-   and tuning, and runs a multi annual simulation on "climatological"
-   amip sea surface temperature (with a mean annual cycle) using
-   a calendar with 360 days.
-
-Optionally : the configuration includes the ability to use interannually
-   varying SST and to activate "nudgning" by reanalysis.
-   In both cases, the calendar is then a real one.
-   When nudging is activated, the simulation must be run on a monthly
-   basis, while otherwise, it can be either monthly or yearly.
-
-Since the tutorial automatically generates its own initial files, it
-   can be run with zoom configurations by only changing the number
-   of grid points ("resol" in main.sh) and the DEF/gcm.def file (see bellow).
-
-Aerosols can be read for the year 2000 (weighted average  over 1999-2001 cf Lurton et al 2020),
-  and instantaneous forcing with respect to 1850 can be computed as well.
-  NEW (end 2020) :
-	tutorial_prod can also run LMDZ coupled with the SPLA model
-	(SimPLe Aerosol, activated with option aerosols=spla in setup.sh). 
-	Emissions of dust and sea salt are then computed interactively.
-        2021-05 : tutorial_prod OK, code LMDZ-SPLA OK, 
-		regridding SPLA input files : work in progress
-
-A configuration with isotopes is also available since 2023-04.
-   
-===================================================================
-II. Files and scripts
-===================================================================
-----------------------------------------------------------------
-
-CAREFUL: these scripts MUST be run from $STORE !!!!!
-
-  untar the tutorial_prod.tar file in your $STORE 
-  rename the TEST_PROD directory if you want to;
-  then run everything from this newly created directory
-
-     EXPERT :
-     If the login groupe and computing allocation groupe are different :
-       choose on which STORE space you work (login vs computing allocation);
-       edit lmdz_env.sh, and set "groupe", "SCRATCHD" etc. accordingly.
-     If you want to install the package in a dedicated folder instead of the root of $STORE:
-       set STORED=$STORE/your_folder in lmdz_env.sh 
-----------------------------------------------------------------
-
-main.sh : a script written to pass options to the main script setup.sh
-
-setup.sh : sets up one (series of) simulation(s) by editing the "job" script_SIMU
-    When run with -init 1 options, creates INIT and LIMIT directories
-    Run ./setup.sh -h   for options
-    RECOMMENDATION: do not run it directly, but use main.sh to drive it
-    
-script_SIMU : script that is the basis for the job to run the simulations
-    Automatically edited by setup.sh
-
-reb.sh : to rebuild splitted outputfiles (parallelism with IOISPL)
-    automatically run by script_SIMU
-
-era2gcm_tuto.sh : to interpolate reanalysis onto the GCM grid, for nudging.
-   To be run manually after the first use of main.sh
-
-era2gcm_uv10m.nc : for option "aerosols=spla" only : 
-     to interpolate reanalysis 10m-winds onto the GCM grid, for sea-salt (and dust) emissions.
-        To be run manually after the first use of main.sh.
-
-season.sh : computing seasonal means and daily time series
-
-interp_aerosols.sh : interpolating aerosols on the GCM grid.
-    Automatically run by setup.sh
-
-post_season.sh : post processing a series of simulations with season.sh
-
-test_ERAfiles_JeanZay.sh : script to test the availability of ERA* files sur Jean-Zay
-    In case of nudging, one may use it before running era2gcm.sh		
-
-DEF: .def files for simulations
-   Some of them are changed by setup.sh or script_SIMU depending on chosen options
-   Some others need to be chosen and customized BEFORE RUNNING the scripts (main.sh or setup.sh):
-     DEF/config.def (versions *.def_* available): output files, frequencies, levels (see lines phys_out_file*)
-     DEF/gcm.def (versions *.def_* available): grid (and grid-related) parameters
-     DEF/guide.def : nudging parameters 
-
-============================================================
-III. Known problems
-============================================================
-
-Running zoomed or coarse grid simulations
-    May cause problems with routing and aerosols
-    Suggesting to put in DEF/config.def
-    ok_cdnc=n
-    ok_ade=n
-    ok_aie=n
-    flag_aerosol=0
-    and in DEF/orchidee*.def
-    RIVER_ROUTING=n : because of this, it is set to n by default
-    Be carefull, depending on the version of orchidee used, the job will
-       choose the corresponding version of DEF/orchidee_6.*.def
-
-============================================================
-IV. Updates (reverse chronological order)
-============================================================
-2023-07 (AS-FH-LF) : mise sous svn du repertoire TEST_PROD, renommé en "LMDZ_config"
-
-2023-06 (AS) : Ajout de l'option "veget=7994", pour ORCHIDEE trunk correspondant à la config libIGCM LMDZOR_6.4work 
-      	Le routage (méthode = simple) est désactivé par défaut ; 
-      	il peut être activé comme décrit dans la section "ORCHIDEE-routage". 
-	Le routage n’a pas été testé avec zoom.
-
-2023-05 (AS) : optimisation du functionnement de l'option isotopes : tout géré par phys=lmdiso
-
-2023-04 (S Nguyen) : introducing the option of running with isotopes)
-	
-2021-10 (AS): introducing the option of using the new snow scheme INLANDSIS (setup.sh)
-	Option not active yet, E Vignon will take care of that.
-
-2020 (AS): introducing the possibility to run with SPLA aerosol model 
-
-24/03/2020 (FH): corrections for use with AMIP SSTs and monthly freq
-
-============================================================
-V. TBD
-============================================================
-See documentation (link of the shared google doc in the beginning of this Readme)
-
-
Index: BOL/LMDZ_Setup_amaury/README0_HowTo.md
===================================================================
--- BOL/LMDZ_Setup_amaury/README0_HowTo.md	(revision 4935)
+++ BOL/LMDZ_Setup_amaury/README0_HowTo.md	(revision 4935)
@@ -0,0 +1,141 @@
+
+
+Last update : 2023-07-05
+
+Complementary information and FAQ (in French) :
+https://docs.google.com/document/d/1OLZG6e-86NiXuv5-aALxKIh-QPkp4BdCwWtiBFot-6c
+
+I. What this working environment does and does not
+==================================================
+
+This setup can only be used on jean-zay computer at idris so far.
+    However, extension to ciclad or irene will be done soon.
+
+It proposes a light automatic setup of LMDZ long chained climate simulations
+   including installation of the model itself.
+
+It consists in running LMDZ coupled to Orchidee for land surface (optional)
+   but with imposed sea surface temperature.
+
+The basic default configuration makes use of the IPSL-CM6A grid configuration
+   and tuning, and runs a multi annual simulation on "climatological"
+   amip sea surface temperature (with a mean annual cycle) using
+   a calendar with 360 days.
+
+Optionally: the configuration includes the ability to use interannually
+   varying SST and to activate "nudgning" by reanalysis.
+   In both cases, the calendar is then a real one.
+   When nudging is activated, the simulation must be run on a monthly
+   basis, while otherwise, it can be either monthly or yearly.
+
+Since the tutorial automatically generates its own initial files, it
+   can be run with zoom configurations by only changing the number
+   of grid points ("resol" in main.sh) and the DEF/gcm.def file (see bellow).
+
+Aerosols can be read for the year 2000 (weighted average  over 1999-2001 cf Lurton et al 2020),
+  and instantaneous forcing with respect to 1850 can be computed as well.
+  NEW (end 2020) :
+	tutorial_prod can also run LMDZ coupled with the SPLA model
+	(SimPLe Aerosol, activated with option aerosols=spla in setup.sh). 
+	Emissions of dust and sea salt are then computed interactively.
+        2021-05 : tutorial_prod OK, code LMDZ-SPLA OK, 
+		regridding SPLA input files : work in progress
+
+A configuration with isotopes is also available since 2023-04.
+   
+II. Files and scripts
+===================================================================
+----------------------------------------------------------------
+
+CAREFUL: these scripts MUST be run from $STORE !!!!!
+
+  untar the tutorial_prod.tar file in your $STORE;
+  rename the TEST_PROD directory if you want to;
+  then run everything from this newly created directory
+
+     EXPERT :
+     If the login groupe and computing allocation groupe are different :
+       choose on which STORE space you work (login vs computing allocation);
+       edit lmdz_env.sh, and set "groupe", "SCRATCHD" etc. accordingly.
+     If you want to install the package in a dedicated folder instead of the root of $STORE:
+       set STORED=$STORE/your_folder in lmdz_env.sh 
+----------------------------------------------------------------
+
+main.sh : a script written to pass options to the main script setup.sh
+
+setup.sh : sets up one (series of) simulation(s) by editing the "job" script_SIMU
+    When run with -init 1 options, creates INIT and LIMIT directories
+    Run ./setup.sh -h   for options
+    RECOMMENDATION: do not run it directly, but use main.sh to drive it
+    
+script_SIMU : script that is the basis for the job to run the simulations
+    Automatically edited by setup.sh
+
+reb.sh : to rebuild splitted outputfiles (parallelism with IOISPL)
+    automatically run by script_SIMU
+
+era2gcm_tuto.sh : to interpolate reanalysis onto the GCM grid, for nudging.
+   To be run manually after the first use of main.sh
+
+era2gcm_uv10m.nc : for option "aerosols=spla" only : 
+     to interpolate reanalysis 10m-winds onto the GCM grid, for sea-salt (and dust) emissions.
+        To be run manually after the first use of main.sh.
+
+season.sh : computing seasonal means and daily time series
+
+interp_aerosols.sh : interpolating aerosols on the GCM grid.
+    Automatically run by setup.sh
+
+post_season.sh : post processing a series of simulations with season.sh
+
+test_ERAfiles_JeanZay.sh : script to test the availability of ERA* files sur Jean-Zay
+    In case of nudging, one may use it before running era2gcm.sh		
+
+DEF: .def files for simulations
+   Some of them are changed by setup.sh or script_SIMU depending on chosen options
+   Some others need to be chosen and customized BEFORE RUNNING the scripts (main.sh or setup.sh):
+     DEF/config.def (versions *.def_* available): output files, frequencies, levels (see lines phys_out_file*)
+     DEF/gcm.def (versions *.def_* available): grid (and grid-related) parameters
+     DEF/guide.def : nudging parameters 
+
+III. Known problems
+===================
+
+Running zoomed or coarse grid simulations
+    May cause problems with routing and aerosols
+    Suggesting to put in DEF/config.def
+    ok_cdnc=n
+    ok_ade=n
+    ok_aie=n
+    flag_aerosol=0
+    and in DEF/orchidee*.def
+    RIVER_ROUTING=n : because of this, it is set to n by default
+    Be carefull, depending on the version of orchidee used, the job will
+       choose the corresponding version of DEF/orchidee_6.*.def
+
+IV. Updates (reverse chronological order)
+=========================================
+
+2023-07 (AS-FH-LF) : mise sous svn du repertoire TEST_PROD, renommé en "LMDZ_config"
+
+2023-06 (AS) : Ajout de l'option "veget=7994", pour ORCHIDEE trunk correspondant à la config libIGCM LMDZOR_6.4work 
+      	Le routage (méthode = simple) est désactivé par défaut ; 
+      	il peut être activé comme décrit dans la section "ORCHIDEE-routage". 
+	Le routage n’a pas été testé avec zoom.
+
+2023-05 (AS) : optimisation du functionnement de l'option isotopes : tout géré par phys=lmdiso
+
+2023-04 (S Nguyen) : introducing the option of running with isotopes)
+	
+2021-10 (AS): introducing the option of using the new snow scheme INLANDSIS (setup.sh)
+	Option not active yet, E Vignon will take care of that.
+
+2020 (AS): introducing the possibility to run with SPLA aerosol model 
+
+24/03/2020 (FH): corrections for use with AMIP SSTs and monthly freq
+
+V. TBD
+======
+See documentation (link of the shared google doc in the beginning of this Readme)
+
+
Index: BOL/LMDZ_Setup_amaury/README1_TestMode
===================================================================
--- BOL/LMDZ_Setup_amaury/README1_TestMode	(revision 4934)
+++ 	(revision )
@@ -1,31 +1,0 @@
-Last update : 2021-06-01
-
-For development/debug purposes :
-List of changes in tutorial_prod scripts, in order to obtain a light&fast version :  
-============================================= 
-
--> low horizontal resolution : 48x36x39, or 32x32x39
-   main.sh
-
--> # Run for 1 day only
-	main.sh :
-  mthend=200002 (=mthini + 1mois) 
-
--> use testmode=y (default =n) in setup.sh, which imposes the following changes :
-	script_SIMU : 
-  nday=1 
-
-	setup.sh : submitting job tmp_$SIM on "dev" queue
-   cput=00:30:00 (i.e. 30 min ; must be max 2h)
-    and 
-   #SBATCH --qos=qos_cpu-dev
- 	Attention au cput par defaut=10 min pour le job Init : si on est en climato, ça suffit, et on peut systematiquement envoyer sur queue test ; sinon (interannuel), un temps plus long peut être necessaire (?) 
-Mettre systematiquement 30 min et queue Test?
-
--> Compile & run without RRTM (NOT possible for aerosols=spla)
-	setup.sh : rrtm=false
-            # then the following changes are made automatically in DEF/physiq.def : iflag_rrtm=0 et NSW=2 
-
-(-> renoncer au rebuild ? plutôt mettre cputime à 10 min sur queue test pour rebuild aussi...)
-
-
Index: BOL/LMDZ_Setup_amaury/README1_TestMode.md
===================================================================
--- BOL/LMDZ_Setup_amaury/README1_TestMode.md	(revision 4935)
+++ BOL/LMDZ_Setup_amaury/README1_TestMode.md	(revision 4935)
@@ -0,0 +1,32 @@
+Last update : 2021-06-01
+
+For development/debug purposes :
+
+### List of changes in tutorial_prod scripts, in order to obtain a light&fast version :  
+
+
+-> low horizontal resolution : 48x36x39, or 32x32x39
+   main.sh
+
+-> # Run for 1 day only
+	main.sh :
+  mthend=200002 (=mthini + 1mois) 
+
+-> use testmode=y (default =n) in setup.sh, which imposes the following changes :
+	script_SIMU : 
+  nday=1 
+
+	setup.sh : submitting job tmp_$SIM on "dev" queue
+   cput=00:30:00 (i.e. 30 min ; must be max 2h)
+    and 
+   #SBATCH --qos=qos_cpu-dev
+ 	Attention au cput par defaut=10 min pour le job Init : si on est en climato, ça suffit, et on peut systematiquement envoyer sur queue test ; sinon (interannuel), un temps plus long peut être necessaire (?) 
+Mettre systematiquement 30 min et queue Test?
+
+-> Compile & run without RRTM (NOT possible for aerosols=spla)
+	setup.sh : rrtm=false
+            # then the following changes are made automatically in DEF/physiq.def : iflag_rrtm=0 et NSW=2 
+
+(-> renoncer au rebuild ? plutôt mettre cputime à 10 min sur queue test pour rebuild aussi...)
+
+
Index: BOL/LMDZ_Setup_amaury/main.sh
===================================================================
--- BOL/LMDZ_Setup_amaury/main.sh	(revision 4934)
+++ BOL/LMDZ_Setup_amaury/main.sh	(revision 4935)
@@ -1,3 +1,5 @@
 #!/bin/bash
+
+set -eu
 
 #####################################################################
@@ -25,5 +27,5 @@
 #       modify STORED variable accordingly
 #    The model will be installed in $LMDZD directory defined in lmdz_env.sh
-#      Default : LMDZD=$WORK ; can be changed in LMDZD=$WORK/Your_directory
+#      Default : LMDZD=$WORK; can be changed in LMDZD=$WORK/Your_directory
 #    To use a model already installed (and compiled), by you or someone else (check the acces!):
 #       set LMDZD=path_to_model_to_use
@@ -37,4 +39,5 @@
 # Version of the tar file on https://lmdz.lmd.jussieu.fr/pub/src
 # Last "testing" version, thoroughly checked by the LMDZ team : contains LMDZ rev 4729 (2023-10-22)
+# TODO move to expert-level settings
 version="20240308.trunk" #!! DON'T CHANGE IT WITHOUT CHECKING WITH LMDZ TEAM !!
 svn="" 			 #!! DON'T CHANGE IT WITHOUT CHECKING WITH LMDZ TEAM !!	
@@ -43,33 +46,19 @@
 	# 	Mattermost: https://mattermost.lmd.ipsl.fr/lmdz/channels/installation-et-tutoriels
 
-#-----------------------------------------------------------
 # Grid number of points IMxJMxLM
-#-----------------------------------------------------------
-resol=144x142x79
+resol="144x142x79"
 
-#-----------------------------------------------------------
-# To install the model :  -install 
-#-----------------------------------------------------------
-install=""
-install=-install
+# Whether to install the model: "-install" to install the model, else ""
+install="-install"
 
-#-----------------------------------------------------------
-# Using XIOS for IOs
-#-----------------------------------------------------------
-xios="-xios"
+# Using XIOS for IOs: "-xios" for enabled, else ""
 xios=""
 
-#-----------------------------------------------------------
-# Using or not the Cosp simulator  
-#-----------------------------------------------------------
-#cosp="-cosp"
+# Using or not the Cosp simulator: "-cosp" for enabled, else ""
 cosp=""
-echo $xios $cosp
 
-#-----------------------------------------------------------
 # Choice of physics (default : "lmd" for "phylmd" )
 #   Examples : lmd_phys="new" to compile with phynew instead of phylmd,
 #              lmd_phys="lmdiso" to run with Isotopes 
-#-----------------------------------------------------------
 lmd_phys="lmd"
 
@@ -78,25 +67,17 @@
 #===========================================================
 
-#-----------------------------------------------------------
 # Initial state and Boundary conditions
-#-----------------------------------------------------------
+# init=   1: to create a new start in INIT
+#         0: to read start files in INIT
+#       SIM: to read start files from previous simulation SIM0, /!\ SIM0 must be in the same folder as the new SIM
+# (limit.nc and aerosols forcing are put in ./LIMIT)
+init=1
 
-# init=   1: to create a new start in INT
-#         0: to read start files in INIT
-#       SIM: to read start files from previous simulation SIM0
-# limit.nc and aerosols forcing are put in ./LIMIT
-init=1
-#init=SIM0 # SIM0 must be in the same folder as the new SIM
-
-#-----------------------------------------------------------
-# climato=1 : Climatological SSTs with 360-day calendar 
+# climato=1 : Climatological SSTs with 360-day calendar
 #        =0 : interannual SSTs with true (ie gregorian) calendar 
-#-----------------------------------------------------------
 climato=1
 
-#-----------------------------------------------------------
 # Nudging: Can only be activated with climato=0 and freq=mo
-#-----------------------------------------------------------
-nudging="-nudging"
+# ="-nudging" for enabled, else ""
 nudging=""
 #If using nudging, then check DEF/guide.def :
@@ -104,12 +85,8 @@
 #  - You may want to check/customize the nudging parameters
 
-#-----------------------------------------------------------
 # Length of elementary simulations yr (year) or mo (month)
-#-----------------------------------------------------------
-freq=yr
+freq="yr"
 
-#-----------------------------------------------------------
 # Initial/final month for simulation
-#-----------------------------------------------------------
 # If $init=1, the INIT file will be called start.200001.nc,
 # but the data correspond in fact to another day.
@@ -121,5 +98,5 @@
 # Output files, frequencies, levels 
 #   If you use IOIPSL (option xios=""), you may want to choose and customize DEF/config.def. 
-#     A few versions are available as DEF/config.def_* ; config.def is a copy of config.def_default 
+#     A few versions are available as DEF/config.def_*; config.def is a copy of config.def_default 
 #     See phys_out_filekeys, phys_out_filelevels, phys_out_filetimesteps, and supplementary variables
 #   If you use XIOS (option xios="-xios"), check/modify DEF/XMLfiles*/file*xml 
@@ -128,5 +105,5 @@
 # Grid characteristics (regular, zoomed)
 #   You may want to choose and customize DEF/gcm.def 
-#   A few versions are available as DEF/gcm.def_* ; 
+#   A few versions are available as DEF/gcm.def_*; 
 #      The default, for regular grid 144x142x79, corresponds to _iperiod7 
 #      (Expert : TEMPORARILY : setup.sh forces use of gcm.def_zNAfrica_BiJe for aerosols=spla)
@@ -140,26 +117,24 @@
 # NOTE : automatically choosing DEF/PHYS/physiq.def_NPiso for isotopes
 physics="NPv6.3"
-if [ $lmd_phys = "lmdiso" ] ; then physics="NPiso" ; fi
+if [[ $lmd_phys = "lmdiso" ]]; then physics="NPiso"; fi
 
-for phys in $physics ; do
-  deffile=DEF/PHYS/physiq.def_${phys}
-  if [ -f $deffile ] ; then 
+if [[ $(echo "$physics" |wc -w) -gt 1 && $init = 1 ]]; then echo "!=!=! TO LOOP OVER MULTIPLE physics [$physics], YOU NEED init =/= 1 AND start* + limit* files ALREADY AVAILABLE IN THIS FOLDER !=!=!"; exit 1; fi
+
+for phys in $physics; do
+  deffile="DEF/PHYS/physiq.def_$phys"
+  if [[ -f $deffile ]]; then
      cp -p $deffile DEF/physiq.def
 
     # name of simulation : can be changed to user's convenience
-    # (Default : name=$phys to loop on different physics) 
-    name=${phys}      
+    # (Default: name=$phys to loop on different physics)
+    name="$phys"
 
     # launching setup.sh with the options defined in this main.sh. 
-    # Remember : some other options are only available in lmdz_env.sh and setup.sh.
-    ./setup.sh -v "$version" $svn -d $resol $install $cosp $xios -init $init -climato $climato $nudging -f $freq -mthini $mthini -mthend $mthend -p $lmd_phys -name $name
-
-    nphys=`echo "$physics" |wc -w` ; if [ $nphys -gt 1 -a $init = 1 ] ; then echo "!=!=! TO LOOP OVER MULTIPLE "physics", YOU NEED init /= 1 AND start* + limit* files ALREADY AVAILABLE IN THIS FOLDER !=!=!" ; exit ; fi
-
-else  # wrong "{phys}" name in "physics" list 
- echo File $deffile inexistent
- exit
-fi
-
+    # Remember: some other options are only available in lmdz_env.sh and setup.sh.
+    # TODO clarifier la diff entre $phys et $lmd_phys ?
+    ./setup.sh -v "$version" "$svn" -d "$resol" "$install" "$cosp" "$xios" -init "$init" -climato "$climato" "$nudging" -f "$freq" -mthini "$mthini" -mthend "$mthend" -p "$lmd_phys" -name "$name"
+  else
+    echo "File $deffile inexistent"; exit 1
+  fi
 done
 
Index: BOL/LMDZ_Setup_amaury/setup.sh
===================================================================
--- BOL/LMDZ_Setup_amaury/setup.sh	(revision 4934)
+++ BOL/LMDZ_Setup_amaury/setup.sh	(revision 4935)
@@ -1,259 +1,244 @@
 #!/bin/bash
-
-#set -vx
-
-#####################################################################
-# This script sets up and launches a (series of) simulation(s). 
-#
+# This script sets up and launches a (series of) simulation(s).
 # RECOMMENDATION: use main.sh to drive it (do not run it directly)
-#
-#####################################################################
-#
+
+set -eu
+
 # EXPERT-LEVEL CHOICES, only available in setup.sh, not in main.sh :
-#####################################################################
-
-#NOTE : $optim  is part of $LMDZname (see definition of LMDZname below),
-#   so that running with "-debug" needs to (re)install the model (install=-install in main.sh)
-#   If you have already installed the model, and only want to recompile the gcm in debug mode,
-#   add "-debug" to the compilation options in the compile.sh script created in the present folder, and run it (./compile.sh gcm)
-#   ALTERNATIVELY : you can remove $optim in the definition of "LMDZname" below
-optim=""
-#optim="-debug"
-
-#NOTE : "testmode=y" is for running in test mode : 
-# the simulation job "tmp_$SIM" (created on $SCRATCHDIR) is automatically changed for a short run,
-# and submitted to the Jean-Zay "test" queue :
-#  a/ time=00:10:00  (run time limit = 10 min ; for test queue, it must be 30 min maximum)
-#  b/ nday=1 (this line, forcing nday to 1 day, is "hidden" in script_SIMU, by default it is commented out)
-#  c/ #SBATCH --qos=qos_cpu-dev (this line is in script_SIMU, by default it is commented out)
-#If you want to change "time", or "nday", but still run in "test" mode, modify the "if [ $debug = 1 ]...; fi" further below.
-testmode=n
-
-# --->>> Radiative code : run with "oldrad" or "rrtm" or "ecrad" (default : rrtm)
-# NOTE : For LMDZ rev before 4185 included, if you change this choice and you want to recompile, 
-#        modify compile.sh and run it in the present folder ($local) : ./compile.sh gcm 
-#       with the appropriate compiling option (see $opt_rrtm below)
-rad=rrtm
-
-# --->>> AEROSOLS : n (=no) / clim (=average 1995-2014) / spla (interactive dust and sea salt)
-# (ATTENTION : if you first run the scripts with aerosols=n, then you want to change to =clim ,
-#   you'll need to remove the INIT and LIMIT folders that have been created, then run main.sh with init=1
-#   in order to re-run the initialisation job, which downloads the aerosol files and interpolates them)
-aerosols=clim
-
-# --->>> SURFACE/VEGETATION SCHEME (as in install_lmdz.sh ; LF)
-# It is 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 : only rev 7983 on branch _2_2, and 7994 on trunk, are available 
-	# !!! ATTENTION : both ORCHIDEE branch 2_2 and recent TRUNK REQUIRE XIOS !!!!
-veget=CMIP6
-#AS : If you have installed the model with a given "veget" option, and you want to change it :
-#   --> RECOMMENDED : re-install the model from scratch, using main.sh with "-install" option in it
-#    (even better : start in a new TEST_PROD folder)
-#   --> EXPERT : If you want to keep your previous installation, and not go through the install_lmdz.sh routine, 
-#    you will need to (a) install the proper version of ORCHIDEE in the modipsl/modeles directory, and 
-#                     (b) set the "veget" options (opt_veget, orchidee_rev, suforch) to their proper values 
-#                        in the file $LMDZD/modipsl/modeles/surface_env 
-# (NB : no need to initialise these vars here: 
-#     surface_env is either (re)created when (re)installing the model (run with install=-install), 
-#     or it already exists (install="").
-
-# --->>> New snow scheme INLANDSIS (y/n) 
-# (this flag activates INLANDSIS compilation ; 
-# not yet done : treatment of specific restart and def file)
-inlandsis=n
-
-## --->>> Isotopes : compile and run with/without (y/n) : is now dependent on phylmd (=lmd_phys from  main.sh), see below
-##isotopes=n
-
-# --->>> COMPILATION options : fcm, debug
-fcm=-nofcm
-fcm=""
-
-# --->>> ALSO PAY ATTENTION TO OUTPUT files, frequency, level ------------- 
-#   With IOIPSL : Choose your config.def among the versions available in DEF, 
-#     copy it as config.def (the copy is done automatically for "iso"), 
-#     edit it and set up output files, frequencies and levels.
-#     NB : For aerosols=spla, output level minimum 4 is required to output the specific variables.
-#          For aerosols=n, the corresponding flags will automatically be set to "n".
-#   With XIOS : adjust DEF/XMLfiles*/file*xml 
-#
-#### END EXPERT-LEVEL CHOICES #########################################
-
-# Set up the appropriate environment
-#------------------------------------
-sed -i -e 's/hostname=.*.$/hostname='`hostname`'/' lmdz_env.sh
-. lmdz_env.sh
-module list
-
-# Pour les post-traitements
-sed -i'' -e 's/groupe@cpu/'$groupe'@cpu/' seasonal.sh
-local=`pwd`
-
-##############################################################
-
-# A function to fetch files either locally or on the internet
-function myget { #1st and only argument should be file name
-   # Path on local computer where to look for the datafile
-   if [ -f /u/lmdz/WWW/LMDZ/pub/$1 ] ; then
-     \cp -f -p /u/lmdz/WWW/LMDZ/pub/$1 .
-   elif [ -f ~/LMDZ/pub/$1 ] ; then
-     \cp -f -p ~/LMDZ/pub/$1 .
-   else
-     wget -nv https://lmdz.lmd.jussieu.fr/pub/$1
-     #dir=~/LMDZ/pub/`dirname $1` ; mkdir -p $dir ; cp -r `basename $1` $dir
-   fi
+####################################################################
+function define_expert_options {
+  #NOTE : $optim  is part of $LMDZname (see definition of LMDZname below),
+  #   so that running with "-debug" needs to (re)install the model (install=-install in main.sh)
+  #   If you have already installed the model, and only want to recompile the gcm in debug mode,
+  #   add "-debug" to the compilation options in the compile.sh script created in the present folder, and run it (./compile.sh gcm)
+  #   ALTERNATIVELY : you can remove $optim in the definition of "LMDZname" below
+  optim=""
+  #optim="-debug"
+  # TODO Amaury: quelle diff avec l'option fcm="debug" ???
+
+  #NOTE : "testmode=y" is for running in test mode :
+  # the simulation job "tmp_$SIM" (created on $SCRATCHDIR) is automatically changed for a short run,
+  # and submitted to the Jean-Zay "test" queue :
+  #  a/ time=00:10:00  (run time limit = 10 min; for test queue, it must be 30 min maximum)
+  #  b/ nday=1 (this line, forcing nday to 1 day, is "hidden" in script_SIMU, by default it is commented out)
+  #  c/ #SBATCH --qos=qos_cpu-dev (this line is in script_SIMU, by default it is commented out)
+  #If you want to change "time", or "nday", but still run in "test" mode, modify the "if [ $debug = 1 ]...; fi" further below.
+  testmode=n
+
+  # Radiative code : "oldrad" or "rrtm" or "ecrad"
+  rad="rrtm"
+
+  # AEROSOLS : n (=no) / clim (=average 1995-2014) / spla (interactive dust and sea salt)
+  # (WARNING : if you first run the scripts with aerosols=n, then you want to change to =clim ,
+  #   you'll need to remove the INIT and LIMIT folders that have been created, then run main.sh with init=1
+  #   in order to re-run the initialisation job, which downloads the aerosol files and interpolates them)
+  aerosols="clim"
+
+  # SURFACE/VEGETATION SCHEME
+  # It is controlled by the single variable "veget" which can have the following values
+  # - "none": bucket scheme
+  # - "CMIP6" or "orch2.0": orchidee version used in CMIP exercise, rev 5661
+  # - "orch2.2": orchidee version used in IPSLCM7 configuration
+  # - number: orchidee version number : only rev 7983 on branch _2_2, and 7994 on trunk, are available
+  veget="CMIP6"
+  #AS : If you have installed the model with a given "veget" option, and you want to change it :
+  #   --> RECOMMENDED : re-install the model from scratch in a new TEST_PROD folder
+  #   TODO Amaury: check w/ Adriana what the use case is for lmdz_setup here
+  #   --> EXPERT : If you want to keep your previous installation, and not go through the install_lmdz.sh routine,
+  #    you will need to (a) install the proper version of ORCHIDEE in the modipsl/modeles directory, and
+  #                     (b) set the "veget" options (opt_veget, orchidee_rev, suforch) to their proper values
+  #                        in the file $LMDZD/modipsl/modeles/surface_env
+  # (NB : no need to initialise these vars here:
+  #     surface_env is either (re)created when (re)installing the model (run with install=-install),
+  #     or it already exists (install="").
+
+  # New snow scheme INLANDSIS (y/n)
+  # (this flag activates INLANDSIS compilation;
+  # not yet done : treatment of specific restart and def file)
+  inlandsis="n"
+
+  # COMPILATION options : "", "fcm", "debug"
+  fcm=""
+
+  # --->>> ALSO PAY ATTENTION TO OUTPUT files, frequency, level -------------
+  #   With IOIPSL : Choose your config.def among the versions available in DEF,
+  #     copy it as config.def (the copy is done automatically for "iso"),
+  #     edit it and set up output files, frequencies and levels.
+  #     NB : For aerosols=spla, output level minimum 4 is required to output the specific variables.
+  #          For aerosols=n, the corresponding flags will automatically be set to "n".
+  #   With XIOS : adjust DEF/XMLfiles*/file*xml
 }
 
-##############################################################
-# Choices : name, nudging, calendar ...
-##############################################################
-SIM=`basename \`pwd\``CTL
-phylmd=lmd #option -p $phylmd for makelmdz
-
-# COSP
-cosp=n
-
-#XIOS
-xios=n
-
-# Nudging :
-ok_guide=n
-# With nudging, use real calendar (climato=0) and monthly integrations
-climato=1
-freq=mo  # frequence mensuelle mo ou annuelle yr
-
-# NB : the run stops in the BEGINNING of mthend (test "next=stopsim")
-mthini=200001
-mthend=200501
-resol=144x142x79
-
-version=20230412.trunk
-svn=""
-
-install=0
-init=1
-
-LIMIT=LIMIT
-
-
-##############################################################
-# options
-##############################################################
-
-while (($# > 0))
-   do
-   case $1 in
-     "-h") cat <<........fin
-	   setup.sh can be launched/driven by main.sh; some options can only be specified in setup.sh (ex: veget, aerosols).
-           setup.sh [-v version] [-r svn_release] [-init INIT] [-d 96x95x79] [-f mo] [-nudging]
-           "version" like 20150828.trunk ; see https://lmdz.lmd.jussieu.fr/Distrib/LISMOI.trunk
-           "svn_release"      either the svn release number or "last"
-           -d IMxJMxLM        to run in resolution IM x JM x LM
-           -install           pour installer et compiler le modele
-           -f mo/yr           pour tourner en mensuel ou annuel
-           "INIT"             1: creates INIT and LIMIT
-                              0: reads from INIT and LIMIT
-                              SIMU: reads from preexisting simulation SIMU and LIMIT
-           -nudging           to run with nudging. Nudging files must be created independently
-           Other options available (see "options" section in the script)
+# /!\ DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING /!\
+
+function load_install_lib {
+  # Fetch and source install_lmdz.sh
+  if [[ ! -f "lib_install_lmdz.sh" ]]; then
+    wget "http://svn.lmd.jussieu.fr/LMDZ/BOL/script_install_amaury/install_lmdz.sh" # TODO change to normal branch once ready
+    mv install_lmdz.sh lib_install_lmdz.sh  # rename to avoid misleading users as to which script to run
+    sed -i'' "2i# This is a library used in the installation, DO NOT RUN IT YOURSELF unless you're an expert !" lib_install_lmdz.sh
+  fi
+  source lib_install_lmdz.sh
+}
+load_install_lib  # Do not move later, as it would overwrite some functions
+
+function set_default_params {
+  # Default value of script parameters
+  SIM=$(basename "$local")CTL  # name
+  phylmd="lmd" #option -p $phylmd for makelmdz
+
+  cosp="n"  # COSP
+  xios="n"  #XIOS
+
+  # Nudging :
+  ok_guide="n"
+  # With nudging, use real calendar (climato=0) and monthly integrations
+  climato=1
+  freq="mo"  # frequence mensuelle mo ou annuelle yr
+
+  # NB : the run stops in the BEGINNING of mthend (test "next=stopsim")
+  mthini=200001
+  mthend=200501
+  resol="144x142x79"
+
+  version="20230412.trunk"
+  svn=""
+
+  install=0
+  init=1
+
+  LIMIT="LIMIT"
+}
+
+function read_cmdline_args {
+  while (($# > 0)); do
+    case $1 in
+      "-h") cat <<........fin
+       setup.sh can be launched/driven by main.sh; some options can only be specified in setup.sh (ex: veget, aerosols).
+             setup.sh [-v version] [-r svn_release] [-init INIT] [-d 96x95x79] [-f mo] [-nudging]
+             "version" like 20150828.trunk; see https://lmdz.lmd.jussieu.fr/Distrib/LISMOI.trunk (default <$version>)
+             "svn_release"      either the svn release number or "last" (default <$svn>)
+             -d IMxJMxLM        to run in resolution IM x JM x LM (default <$resol>)
+             -install           pour installer et compiler le modele
+             -f mo/yr           pour tourner en mensuel ou annuel (default <$freq>)
+             "INIT"             1: creates INIT and LIMIT
+                                0: reads from INIT and LIMIT
+                                SIMU: reads from preexisting simulation SIMU and LIMIT (default <$init>)
+             -nudging           to run with nudging. Nudging files must be created independently
+             -p                 the physics to use (default <$phylmd>)
+             -name              install folder name (default <$SIM>)
+             Other options available (see "options" section in the script)
 ........fin
-     exit ;;
-     "-v") version="$2" ; shift ; shift ;;
-     "-r") svn=$2 ; shift ; shift ;;
-     "-d") resol=$2 ; shift ; shift ;;
-     "-f") freq=$2 ; shift ; shift ;;
-     "-p") phylmd=$2 ; shift ; shift ;;
-     "-install") install=1 ; shift ;;
-     "-name") SIM=$2 ; shift ; shift ;;
-     "-cosp") cosp=y ; shift ;;
-     "-xios") xios=y ; shift ;;
-     "-init") init=$2 ; shift ; shift ;;
-     "-nudging") ok_guide=y ; shift ;;
-     "-climato") climato=$2 ; shift ; shift ;;
-     "-mthini") mthini=$2 ; shift ; shift ;;
-     "-mthend") mthend=$2 ; shift ; shift ;;
-     *) $0 -h ; exit
-   esac
-done
-
-# --->>> Isotopes : ompile and run with isotopes if lmdz_phys="lmdiso" in main.sh
-if [ $phylmd = "lmdiso" ] ; then isotopes=y ; else isotopes=n ; fi
-
-# Three options for initialisation
-# 1: Create INIT
-# 0: Take from INIT
-# DIR : Take from DIR
-if [ $init = 1 -o $init = 0 ] ; then
-   INIT=INIT
-else
-   INIT=$init
-fi
-
-yearini=`echo $mthini | cut -c-4`
-if [ $freq = yr ] ; then stopsim=`echo $mthend | cut -c-4` ; else stopsim=$mthend ; fi
-
-if [ "$svn" = "" ] ; then svnopt="" ; else svnopt="-r $svn" ; fi
-
-if [ -d $SIM ] ; then
-   echo La simulation $SIM existe deja
-   echo Il est preferable d arreter et de verifier.
-   echo Si vous etes sur de vous, vous pouvez la prolonger
-   echo Voulez vous la prolonger '? (y/o)' 
-   read ans
-   if [ $ans != y -a $ans != o ] ; then
-      exit
-   fi
-fi
-
-# AVOID COMBINATIONS OF OPTIONS THAT DON'T WORK in user choices
-#-------------------------------------------------------
-
-if [ $ok_guide = y -a $climato = 1 ] ; then
-   echo "================================================================"
-   echo Running nudged simulations with climatological SSTs
-   echo is not planned. Change climato to 0 or modify the setup \(experts\)
-   echo "================================================================"
-   exit
-fi
-
-if [ $climato = 0 -a $freq = yr ] ; then
-   echo "================================================================"
-   echo running simulations with interannual SSTs is possible only
-   echo month by month and a true calendar.
-   echo Change climato to 1 or freq to mo or modify setup.sh \(experts\)
-   echo "================================================================"
-   exit
-fi
-
-# STOP if trying to use ORCHIDEE_2_2 or ORCHIDEE trunk post-CMIP6 without XIOS :
-if [ $veget != "NONE" -a $veget != "CMIP6" -a $xios = "n"  ] ; then echo "STOP : For this ORCHIDEE rev you need XIOS : change "xios" option in main.sh" ; exit ; fi
-
-# STOP if trying to use both ORCHIDEE and Isotopes :
-if [ $isotopes = "y" -a $veget != "NONE" ] ; then echo "STOP : You cannot run LMDZ with ORCHIDEE and ISOtopes at the same time ; either change "veget" option to NONE, or isotopes to "n" in setup.sh" ; exit ; fi
-
-# STOP if trying to use both SPLA and Isotopes :
-if [ $isotopes = "y" -a $aerosols = "spla" ] ; then echo "STOP : You cannot run LMDZ with Isotopes and aerosols=spla at the same time ; change "aerosols" option to "n" or "clim" in setup.sh " ; exit ; fi
-
-# (Temporary) STOP if trying to use Isotopes with XIOS :
-if [ $isotopes = "y" -a $xios = "y" ] ; then echo "STOP : Isotopes cannont yet be run with XIOS ; change xios option in main.sh" ; exit ; fi 
-
-# (Temporary) Constraints for aerosols=spla : 
-# --> resolution 128x88x79 and rad=rrtm
-if [ $aerosols = spla -a $resol != 128x88x79 ] ; then
-  echo 'For now, aerosols=spla requiers resol=128x88x79, and uses the zoomed grid from gcm.def_zNAfrica_BiJe, for which forcing & initial files are available'
-  echo Actual aerosols and resol is $aerosols, $resol
-  exit
-fi
-if [ ${aerosols} = "spla" -a ${rad} != "rrtm" ] ; then echo "STOP : For the time being, aerosols=spla requires rad=rrtm" ; exit ; fi
-
-
-# INSTALLATION OPTIONS depending on the user choices
-#-------------------------------------------------------
-
-if [ $cosp = y ] ; then  ins_cosp="-cosp v1" ; else ins_cosp="" ; fi
-
-if [ $xios = y ] ; then  ins_xios="-xios" ; else ins_xios="" ; fi
+        exit;;
+      "-v") version="$2"; shift; shift;;
+      "-r") svn=$2; shift; shift;;
+      "-d") resol=$2; shift; shift;;
+      "-f") freq=$2; shift; shift;;
+      "-p") phylmd=$2; shift; shift;;
+      "-install") install=1; shift;;
+      "-name") SIM=$2; shift; shift;;
+      "-cosp") cosp=y; shift;;
+      "-xios") xios=y; shift;;
+      "-init") init=$2; shift; shift;;
+      "-nudging") ok_guide=y; shift;;
+      "-climato") climato=$2; shift; shift;;
+      "-mthini") mthini=$2; shift; shift;;
+      "-mthend") mthend=$2; shift; shift;;
+      *) $0 -h; exit
+    esac
+  done
+
+  # Isotopes : Compile and run with isotopes if lmdz_phys="lmdiso" in main.sh
+  if [[ $phylmd = "lmdiso" ]]; then isotopes="y"; else isotopes="n"; fi
+
+  # Initialisation
+  if [[ $init = 1 || $init = 0 ]]; then
+    INIT="INIT"
+  else
+    INIT=$init
+  fi
+
+  yearini=$(echo "$mthini" | cut -c-4)
+  if [[ $freq = yr ]]; then stopsim=$(echo "$mthend" | cut -c-4); else stopsim=$mthend; fi
+
+  if [[ $svn = "" ]]; then svnopt=""; else svnopt="-r $svn"; fi
+
+  if [[ -d $SIM ]]; then
+     echo "La simulation $SIM existe deja. Il est conseillé d'arrêter et de vérifier."
+     echo "Si vous êtes sûr de vous, vous pouvez la prolonger. Voulez vous la prolonger ? (y/n)"
+     read -r ans
+     if [[ $ans != y ]]; then exit 1; fi
+  fi
+
+  if [[ $cosp = y ]]; then ins_cosp="-cosp v1"; else ins_cosp=""; fi
+
+  if [[ $xios = y ]]; then ins_xios="-xios"; else ins_xios=""; fi
+}
+
+function ensure_correct_option_combinations {
+  # AVOID COMBINATIONS OF OPTIONS THAT DON'T WORK in user choices
+
+  if [[ $ok_guide = y && $climato = 1 ]]; then
+     echo "Running nudged simulations with climatological SSTs is not planned. Change <climato> to <0> or modify the setup (experts)"; exit 1
+  fi
+
+  if [[ $climato = 0 && $freq = yr ]]; then
+     echo "Running simulations with interannual SSTs is possible only month by month and a true calendar."
+     echo "Change <climato> to <1> or <freq> to <mo> or modify setup.sh (experts)"; exit 1
+  fi
+
+  # STOP if trying to use both ORCHIDEE and Isotopes :
+  if [[ $isotopes = "y" && $veget != "NONE" ]]; then
+    echo "STOP: You cannot run LMDZ with ORCHIDEE and ISOtopes at the same time; either change <veget> option to NONE, or isotopes to <n> in setup.sh"; exit 1
+  fi
+
+  # STOP if trying to use both SPLA and Isotopes :
+  if [[ $isotopes = "y" && $aerosols = "spla" ]]; then
+    echo "STOP: You cannot run LMDZ with Isotopes and aerosols=spla at the same time; change <aerosols> option to <n> or <clim> in setup.sh"; exit 1
+  fi
+
+  # (Temporary) STOP if trying to use Isotopes with XIOS :
+  # TODO Amaury: check if still relevant
+  if [[ $isotopes = "y" && $xios = "y" ]]; then
+    echo "STOP: Isotopes cannont yet be run with XIOS; change <xios> option in main.sh"; exit 1
+  fi
+
+  # (Temporary) Constraints for aerosols=spla :
+  # --> resolution 128x88x79 and rad=rrtm
+  if [[ $aerosols = spla && $resol != 128x88x79 ]]; then
+    echo 'For now, <aerosols=spla> requires <resol=128x88x79>, and uses the zoomed grid from gcm.def_zNAfrica_BiJe, for which forcing & initial files are available'
+    echo "Right now aerosols=<$aerosols>, resol=<$resol>"
+    exit 1
+  fi
+
+  if [[ $aerosols = "spla" && $rad != "rrtm" ]]; then
+    echo "STOP: For the time being, <aerosols=spla> requires <rad=rrtm>"; exit 1
+  fi
+}
+
+# TODO Amaury: commented-out for now
+## Set up the appropriate environment
+##------------------------------------
+#sed -i -e "s/hostname=.*.$/hostname=$(hostname)/" lmdz_env.sh
+#. lmdz_env.sh
+#module list
+
+# TODO Amaury: commented-out for now
+## Pour les post-traitements
+#sed -i'' -e "s/groupe@cpu/$groupe@cpu/" seasonal.sh  # TODO Amaury: $groupe jamais défini, à virer ?
+local=$(pwd)
+
+define_expert_options
+set_default_params
+read_cmdline_args "$@"
+ensure_correct_option_combinations
+
+exit 1
+
+
+
+
+
+
 
 ########################################################################
@@ -261,11 +246,11 @@
 ########################################################################
 
-if [ ! -d $LMDZD ] ; then mkdir -p $LMDZD ; fi
+if [ ! -d $LMDZD ]; then mkdir -p $LMDZD; fi
 version_name=LMDZ`echo $version | sed -e 's/-v//g' -e 's/-unstable//' -e 's/-r/r/' -e 's/ //g'`
 LMDZname=${version_name}${svn}${optim}OR${veget}${ins_xios}
 MODEL=$LMDZD/$LMDZname/modipsl/modeles/LMDZ
 
-if [ $install = 1 ] ; then
-   if [ -d $MODEL ] ; then
+if [ $install = 1 ]; then
+   if [ -d $MODEL ]; then
 	   echo $MODEL
       echo "Vous essayez d installer une version deja presente"
@@ -283,9 +268,9 @@
       ./install_lmdz.sh $fcm $optim -v $version $svnopt -d $resol -rad $rad -bench 0 -parallel mpi_omp $ins_cosp $ins_xios -name $LMDZname -env_file $local/lmdz_env.sh -veget $veget
       mv install_lmdz.sh install_lmdz.$$
-      if grep "Not Found" $LMDZname/get.log >/dev/null ; then echo "version=$version is NOT A TESTING VERSION, Ask LMDZ Team" ; exit ; fi
+      if grep "Not Found" $LMDZname/get.log >/dev/null; then echo "version=$version is NOT A TESTING VERSION, Ask LMDZ Team"; exit; fi
       cd $local
    fi
 else
-   if [ ! -d $MODEL ] ; then
+   if [ ! -d $MODEL ]; then
       echo Le model $MODEL n est pas installe
       echo relancer avec install=1 si vous voulez l installer automatiquement
@@ -299,6 +284,6 @@
 # for which the test was introduced
 mysvn=`svnversion $MODEL | egrep -o "[0-9]+" 2>/dev/null`  
-if [ "$mysvn" = "" ] ; then mysvn=`grep 'Revision: [0-9]' $LMDZD/$LMDZname/Read*.md | awk ' { print $2 } ' 2>/dev/null` ; fi
-if [ "$mysvn" = "" ] ; then mysvn=4190 ; fi
+if [ "$mysvn" = "" ]; then mysvn=`grep 'Revision: [0-9]' $LMDZD/$LMDZname/Read*.md | awk ' { print $2 } ' 2>/dev/null`; fi
+if [ "$mysvn" = "" ]; then mysvn=4190; fi
 echo mysvn $mysvn
 
@@ -306,5 +291,5 @@
 # lmdz_env.sh must be sourced again, and copied again as $MODEL/arch/arch-X64_JEANZAY.env
 # (first copy is done by install_lmdz.sh launched with option "-env lmdz_env.sh" )
-if [ ${hostname:0:5} = "jean-" -a $mysvn -ge 4532 -a ! "`grep netcdf95 lmdz_env.sh`" ] ; then
+if [ ${hostname:0:5} = "jean-" -a $mysvn -ge 4532 -a ! "`grep netcdf95 lmdz_env.sh`" ]; then
    cp -p lmdz_env.sh lmdz_env.orig
    sed -i'' -e 's/module load nco/module load netcdf95\n                module load nco/' lmdz_env.sh
@@ -315,33 +300,33 @@
 # COMPILATION OPTIONS depending on the user choices and LMDZ revision number $mysvn
 #-------------------------------------------------------
-if [ "$ARCH" = "" ] ; then arch= ; else arch="-arch $ARCH" ; fi
-
-if [ $cosp = y ] ; then opt_cosp="-cosp true" ; else opt_cosp="" ; fi
+if [ "$ARCH" = "" ]; then arch=; else arch="-arch $ARCH"; fi
+
+if [ $cosp = y ]; then opt_cosp="-cosp true"; else opt_cosp=""; fi
    # makelmdz* uses "opt_cosp", and for v1 (default) needs "-cosp true/false"  
    # When cosp v2 will be validated, we'll have opt_cosp=ins_cosp="-cosp v2" 
-   # (option cosp2 in makelmdz* to be ignored ; it is a transitory version from v1 to v2)
-
-if [ $xios = y ] ; then opt_xios="-io xios" ; else opt_xios="" ; fi
+   # (option cosp2 in makelmdz* to be ignored; it is a transitory version from v1 to v2)
+
+if [ $xios = y ]; then opt_xios="-io xios"; else opt_xios=""; fi
 
 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 
+    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 
 esac
-if [ "$rad" = "ecrad" -a ! -d ecrad_data ] ; then
-    cd $local ; wget https://lmdz.lmd.jussieu.fr/pub/3DInputData/ecrad/ecrad_data.tar ; tar xvf ecrad_data.tar ; cd -
-fi
-if [ "$rad" = "ecrad" -a "$aerosols" != "n" -a "$mysvn" -lt 4489 ]  ; then echo Les aerosols tropospheriques ne sont pas pris en charge par ecrad avant LMDZ rev 4489, ici rev est $mysvn ; exit ; fi
+if [ "$rad" = "ecrad" -a ! -d ecrad_data ]; then
+    cd $local; wget https://lmdz.lmd.jussieu.fr/pub/3DInputData/ecrad/ecrad_data.tar; tar xvf ecrad_data.tar; cd -
+fi
+if [ "$rad" = "ecrad" -a "$aerosols" != "n" -a "$mysvn" -lt 4489 ] ; then echo Les aerosols tropospheriques ne sont pas pris en charge par ecrad avant LMDZ rev 4489, ici rev est $mysvn; exit; fi
 
 
 # Aerosols : also define the associated suffix in gcm name
-if [ $aerosols = spla ] ; then
-  opt_aer=' -dust true ' ;  sufaer='_spla'
+if [ $aerosols = spla ]; then
+  opt_aer=' -dust true ';  sufaer='_spla'
 else
-  opt_aer=""             ;  sufaer=''
-fi
-
-if [ $inlandsis = y ] ; then
+  opt_aer=""            ;  sufaer=''
+fi
+
+if [ $inlandsis = y ]; then
    opt_inlandsis="-inlandsis true"
 else
@@ -350,8 +335,8 @@
 
 # Isotopes : also define the associated suffix in gcm name
-if [ $isotopes = y ] ; then
-  opt_isotopes="-isotopes true" ; sufiso="_iso"
+if [ $isotopes = y ]; then
+  opt_isotopes="-isotopes true"; sufiso="_iso"
 else
-  opt_isotopes=""               ; sufiso=""
+  opt_isotopes=""              ; sufiso=""
 fi
 
@@ -381,8 +366,8 @@
 #   You'll need to modify and run the compile.sh script created in the present folder, and run it (./compile.sh gcm) 
 
-# compile_opt_iso is used for gcm only ; ce0l cannot be compiled with isotopes yet (phylmd instead of phylmdiso is required)
-if [ $isotopes = y ] ; then
+# compile_opt_iso is used for gcm only; ce0l cannot be compiled with isotopes yet (phylmd instead of phylmdiso is required)
+if [ $isotopes = y ]; then
     compile_opt_iso="$optim -p $phylmd $opt_cosp $opt_xios $opt_rad $arch -d $resol $opt_veget $opt_aer $opt_inlandsis $opt_isotopes -mem -parallel mpi_omp"  
-    if [ $mysvn -le 4185 ] ; then 
+    if [ $mysvn -le 4185 ]; then 
       suffix_iso=_${resol}_phy${phylmd}_para_mem${suforch}${sufaer}${sufiso}
     else
@@ -395,6 +380,6 @@
 compile_opt="$optim -p $phylmd $opt_cosp $opt_xios $opt_rad $arch -d $resol $opt_veget $opt_aer $opt_inlandsis -mem -parallel mpi_omp"
 
-if [ $mysvn -le 4185 ] ; then suffix=_${resol}_phy${phylmd}_para_mem${suforch}${sufaer} ;
-                         else suffix=_${resol}_phy${phylmd}_${rad}_para_mem${suforch}${sufaer} ; fi
+if [ $mysvn -le 4185 ]; then suffix=_${resol}_phy${phylmd}_para_mem${suforch}${sufaer};
+                         else suffix=_${resol}_phy${phylmd}_${rad}_para_mem${suforch}${sufaer}; fi
 
 # use an intermediate variable to use either suffix or suffix_iso
@@ -405,12 +390,12 @@
 echo $gcm
 
-if [ ! -f $gcm ] ; then
+if [ ! -f $gcm ]; then
    echo Le model $gcm n existe pas
    echo il va se compiler automatiquement sur $MODEL
    sleep 10
 
-   if [ "$fcm" = "-nofcm" ] ; then
-       compile="./makelmdz $compile_opt \$1 ; mkdir -p bin ; \mv -f \${prog}.e $gcm"
-       compile_iso="./makelmdz $compile_opt_iso \$1 ; mkdir -p bin ; \mv -f \${prog}.e $gcm"
+   if [ "$fcm" = "-nofcm" ]; then
+       compile="./makelmdz $compile_opt \$1; mkdir -p bin; \mv -f \${prog}.e $gcm"
+       compile_iso="./makelmdz $compile_opt_iso \$1; mkdir -p bin; \mv -f \${prog}.e $gcm"
    else
       # makelmdz_fcm directly produces executable named $gcm, depending on the compilation options
@@ -422,7 +407,7 @@
    echo $compile${sufiso}
 
-   #create compile.sh ; 
+   #create compile.sh; 
    # if isotopes = y , it will still be used for compiling ce0l
-   cat <<...eod>| compile.sh
+   cat << ...eod >| compile.sh
    cd $MODEL
    prog=\$1
@@ -434,6 +419,6 @@
 
    #create compile_iso.sh for compiling gcm_ _iso.e
-   if [ $isotopes = y ] ; then
-   cat <<...eod>| compile_iso.sh
+   if [ $isotopes = y ]; then
+   cat << ...eod >| compile_iso.sh
    cd $MODEL
    prog=\$1
@@ -448,5 +433,5 @@
    ./compile${sufiso}.sh gcm > lmdz.log 2>&1
 
-   if [ ! -f $gcm ] ; then echo la compilation a echoue ; exit ; fi
+   if [ ! -f $gcm ]; then echo la compilation a echoue; exit; fi
    cd $local
 fi
@@ -463,13 +448,13 @@
 (( mpi = ( $jm + 1 ) / 2 ))
 omp=8
-if [ $aerosols = spla ] ; then omp=1 ; fi
-if [ $veget = CMIP6 -a $xios = y ] ; then omp=2 ; fi
-if [ $mpi -gt $nb_mpi_max ] ; then mpi=$nb_mpi_max ; fi
-if [ $omp -gt $nb_omp_max ] ; then omp=$nb_omp_max ; fi
+if [ $aerosols = spla ]; then omp=1; fi
+if [ $veget = CMIP6 -a $xios = y ]; then omp=2; fi
+if [ $mpi -gt $nb_mpi_max ]; then mpi=$nb_mpi_max; fi
+if [ $omp -gt $nb_omp_max ]; then omp=$nb_omp_max; fi
 
 ######################################################################
 # Utilisation des .def_iso pour LMDZ-ISOtopes
 ######################################################################
-if [ $isotopes = y ] ; then
+if [ $isotopes = y ]; then
   for file_iso in $( ls DEF | grep _iso)
   do
@@ -481,7 +466,7 @@
 # Choix de la grille verticale
 ######################################################################
-if [ ! -d DEF ] ; then echo Recuperer un repertoire DEF ; exit ; fi
+if [ ! -d DEF ]; then echo Recuperer un repertoire DEF; exit; fi
 lm=`echo $resol | cut -dx -f3`
-if [ ! -f DEF/L$lm.def ] ; then echo resolution verticale non prevue
+if [ ! -f DEF/L$lm.def ]; then echo resolution verticale non prevue
                                  echo creer un fichier DEF/L$lm.def
    exit
@@ -496,13 +481,13 @@
 
 # Choix du fichier traceur.def coherent avec l'option "aerosols"
-#  NOTE : Le nouveau tracer.def_nospla par defaut n'inclut pas Rn-Pb ; 
+#  NOTE : Le nouveau tracer.def_nospla par defaut n'inclut pas Rn-Pb; 
 #		si on les veut, il faut utiliser ci-dessous; a la place, tracer_RN_PB.def
 #---------------------------------------------------------------------
 # NB: Si on change de traceur.def (entre spla et nospla), il faut refaire l'etape "initialisation" (ce0l)? 
-# Normalement les traceurs absents de start* files sont initialises=0 dans le code ; verifier pour spla !  
-if [ $aerosols = spla ] ; then 
+# Normalement les traceurs absents de start* files sont initialises=0 dans le code; verifier pour spla !  
+if [ $aerosols = spla ]; then 
    # ancien traceur pour l instant
    cp DEF/traceur.def_spla   DEF/traceur.def  
-elif [ $isotopes = n ] ; then
+elif [ $isotopes = n ]; then
    # nouveau traceur 
    # déjà copié si 'y'
@@ -512,5 +497,5 @@
 # TEMPORAIREMENT pour spla on force l'utilisation de gcm.def_zNAfrica_BiJe (avec resolution 128x88x79)
 #----------------------------------------------------------------------
-if [ $aerosols = spla ] ; then cp DEF/gcm.def_zNAfrica_BiJe DEF/gcm.def ; fi
+if [ $aerosols = spla ]; then cp DEF/gcm.def_zNAfrica_BiJe DEF/gcm.def; fi
 
 # Inscription du choix ok_guide dans DEF/guide.def
@@ -522,5 +507,5 @@
 # NB Contrairement a ce qui est ecrit dans les fichiers run.def standard, 
 # dans ce tutorial le choix earth_365d n'est pas disponible, et earth_366d s'appelle gregorian
-if [ $climato = 0 ] ; then calend=gregorian ; else calend=earth_360d ; fi
+if [ $climato = 0 ]; then calend=gregorian; else calend=earth_360d; fi
 sed -i -e 's/calend=.*.$/calend='$calend'/' DEF/run.def
 
@@ -528,8 +513,8 @@
 #   cf options veget, aerosols, cosp, xios
 #---------------------------------------------------------------------
-if [ $veget = NONE ] ; then  VEGET=n ; else VEGET=y ; fi
+if [ $veget = NONE ]; then  VEGET=n; else VEGET=y; fi
 sed -i -e 's/VEGET=.*.$/VEGET='$VEGET'/' DEF/config.def
 
-if [ $aerosols = n ] ; then
+if [ $aerosols = n ]; then
   # set flag_aerosols=0 and flags ok_ade&co=n
   sed -i'' -e 's/^ok_cdnc=.*.$/ok_cdnc=n/' -e 's/^ok_ade=.*.$/ok_ade=n/' -e 's/^ok_aie=.*.$/ok_aie=n/' -e 's/^ok_alw=.*.$/ok_alw=n/' -e 's/^flag_aerosol=.*.$/flag_aerosol=0/' DEF/config.def
@@ -538,5 +523,5 @@
 # COSP : ok_cosp desactive COSP si on a compile avec; il ne l'active pas si on a compile sans 
 sed -i -e 's/ok_cosp.*.$/ok_cosp='$cosp'/' DEF/config.def
-if [ $cosp = y ] ; then \cp -f $MODEL/DefLists/cosp*.txt $local/DEF/ ; fi
+if [ $cosp = y ]; then \cp -f $MODEL/DefLists/cosp*.txt $local/DEF/; fi
 
 # Sorties LMDZ en fonction de l'option "xios"
@@ -550,24 +535,24 @@
 sed -i'' -e 's:directory_name.*$:directory_name="'$local'/ecrad_data",:' DEF/namelist_ecrad
 
-if [ $isotopes = y ] ; then iflag_ice_thermo=0 ; else iflag_ice_thermo=1 ; fi
+if [ $isotopes = y ]; then iflag_ice_thermo=0; else iflag_ice_thermo=1; fi
 sed -i -e 's/iflag_ice_thermo=.*.$/iflag_ice_thermo='$iflag_ice_thermo'/' DEF/physiq.def
 
-# Choix de orchidee.def en fonction de orchidee_rev ; modification pour xios
+# Choix de orchidee.def en fonction de orchidee_rev; modification pour xios
 #  NOTE separate orchidee_pft.def file for ORCHIDEE trunk post-CMIP6  
 #---------------------------------------------------------------------
 orchidee_def=orchidee.def_6.1
 orchidee_pft_def=""
-if [ $veget = "7983" ] ; then 
+if [ $veget = "7983" ]; then 
   orchidee_def=orchidee.def_6.2work 
-elif [ $veget = "7994" ] ; then 
+elif [ $veget = "7994" ]; then 
   orchidee_def=orchidee.def_6.4work
   orchidee_pft_def=orchidee_pft.def_6.4work
-  if [ ! grep "INCLUDEDEF=orchidee_pft.def" DEF/run.def ] ; then
-    sed -i'' -e 's/INCLUDEDEF=orchidee.def/INCLUDEDEF=orchidee.def\nINCLUDEDEF=orchidee_pft.def/' DEF/run.def ; fi
+  if ! grep "INCLUDEDEF=orchidee_pft.def" DEF/run.def; then
+    sed -i'' -e 's/INCLUDEDEF=orchidee.def/INCLUDEDEF=orchidee.def\nINCLUDEDEF=orchidee_pft.def/' DEF/run.def; fi
 fi
 \cp -f DEF/$orchidee_def DEF/orchidee.def
-if [ "$orchidee_pft_def" != "" ] ; then \cp -f DEF/$orchidee_pft_def DEF/orchidee_pft.def ; fi
-
-# Only for veget=CMIP6 it is still possible to use IOIPSL ; newer versions of orchidee.def have XIOS_ORCHIDEE_OK = y
+if [ "$orchidee_pft_def" != "" ]; then \cp -f DEF/$orchidee_pft_def DEF/orchidee_pft.def; fi
+
+# Only for veget=CMIP6 it is still possible to use IOIPSL; newer versions of orchidee.def have XIOS_ORCHIDEE_OK = y
 sed -i'' -e 's/XIOS_ORCHIDEE_OK =.*.$/XIOS_ORCHIDEE_OK = '$xios'/' DEF/orchidee.def
 
@@ -577,8 +562,8 @@
 # (ils vont se repercuter dans les repertoires de simulation $local/$SIM et de run $WRK)
 ######################################################################
-if [ $xios = y ] ; then
+if [ $xios = y ]; then
   \cp -f $MODEL/DefLists/context_lmdz.xml $local/DEF/XMLfilesLMDZ/.
   \cp -f $MODEL/DefLists/field_def_lmdz.xml $local/DEF/XMLfilesLMDZ/.
-  if [ $cosp = y ] ; then \cp -f $MODEL/DefLists/field_def_cosp1.xml $local/DEF/XMLfilesLMDZ/. ; fi
+  if [ $cosp = y ]; then \cp -f $MODEL/DefLists/field_def_cosp1.xml $local/DEF/XMLfilesLMDZ/.; fi
 fi
 
@@ -588,7 +573,7 @@
 # pour sa creation
 ######################################################################
-if [ ! -d $INIT ] ; then 
-   if [ $init = 0 ] ; then
-      echo  Recuperer les repertoires $INIT ou lancer avec option -init ; exit
+if [ ! -d $INIT ]; then 
+   if [ $init = 0 ]; then
+      echo  Recuperer les repertoires $INIT ou lancer avec option -init; exit
    else
       ce0l=$MODEL/bin/ce0l${suffix}.e
@@ -596,5 +581,5 @@
 
       # Test if $ce0l exists (it may be the case if you use a model configuration already installed and compiled)
-      if [ ! -f $ce0l ] ; then
+      if [ ! -f $ce0l ]; then
        echo L executable $ce0l n existe pas
        echo il va se compiler automatiquement sur $MODEL
@@ -604,9 +589,9 @@
      fi
 
-     if [ ! -f $ce0l ] ; then echo la compilation de $ce0l a echoue ; exit ; fi
+     if [ ! -f $ce0l ]; then echo la compilation de $ce0l a echoue; exit; fi
 
       cd $local
    fi
-elif [ $init = 1 ] ; then
+elif [ $init = 1 ]; then
    echo Vous essayez d initialiser le modele mais $INIT existe deja
    exit
@@ -617,5 +602,5 @@
 # EXIT after (install and) compilation if we are on jean-zay-pp instead of jean-zay !
 hostname=`hostname`
-if [ ${hostname:0:11} = "jean-zay-pp" ] ; then
+if [ ${hostname:0:11} = "jean-zay-pp" ]; then
  echo "You are on jean-zay-pp, here you only can install and compile the model, not run it" 
  echo "If you want to run a simulation, log in to jean-zay and launch main.sh again, without install"
@@ -638,15 +623,15 @@
 #####################################################################
 
-if [ ! -d $local/$SIM ] ; then
+if [ ! -d $local/$SIM ]; then
 mkdir $local/$SIM
 cd $local
-sed -e 's:^rebuild=.*.$:rebuild='$LMDZD/$LMDZname/modipsl/bin/rebuild':' -e 's/groupe@cpu/'$groupe'@cpu/' reb.sh  >| $local/$SIM/reb.sh ; chmod +x $local/$SIM/reb.sh
+sed -e 's:^rebuild=.*.$:rebuild='$LMDZD/$LMDZname/modipsl/bin/rebuild':' -e 's/groupe@cpu/'$groupe'@cpu/' reb.sh  >| $local/$SIM/reb.sh; chmod +x $local/$SIM/reb.sh
 cp lmdz_env.sh $local/$SIM/
-mkdir $local/$SIM/DEF ; cp DEF/*def DEF/namelis* $local/$SIM/DEF/
+mkdir $local/$SIM/DEF; cp DEF/*def DEF/namelis* $local/$SIM/DEF/
 #Pour XIOS, respectivement COSP, copier aussi les fichiers *xml / *txt
-if [ $cosp = y ] ; then cp DEF/cosp*txt $local/$SIM/DEF/ ; fi
-if [ $xios = y ] ; then
+if [ $cosp = y ]; then cp DEF/cosp*txt $local/$SIM/DEF/; fi
+if [ $xios = y ]; then
    cp DEF/XMLfilesLMDZ/*xml $local/$SIM/DEF/
-   if [ $veget != 'NONE' ] ; then cp DEF/XMLfilesOR$veget/*xml $local/$SIM/DEF/ ; fi
+   if [ $veget != 'NONE' ]; then cp DEF/XMLfilesOR$veget/*xml $local/$SIM/DEF/; fi
 fi
 chmod u+w $local/$SIM/DEF/*
@@ -657,5 +642,5 @@
     DEF/run.def >| $local/$SIM/DEF/run.def
 cd $SIM
-if [ "$freq" = "yr" ] ; then date=$yearini ; else date=$mthini ; fi
+if [ "$freq" = "yr" ]; then date=$yearini; else date=$mthini; fi
 echo $date a faire >| etat
 
@@ -663,6 +648,6 @@
 #############################################################
 echo $date 
-for f in start startphy ; do inf=../$INIT/$f.$date.nc ; if [ -f $inf -o $init = 1 ] ; then ln -s $inf ./ ; else echo $inf inexistant ; exit ; fi ; done
-for f in sechiba stomate ; do if [ -f ../$INIT/start_$f.$date.nc ] ; then ln -sf  ../$INIT/start_$f.$date.nc . ; fi ; done
+for f in start startphy; do inf=../$INIT/$f.$date.nc; if [ -f $inf -o $init = 1 ]; then ln -s $inf ./; else echo $inf inexistant; exit; fi; done
+for f in sechiba stomate; do if [ -f ../$INIT/start_$f.$date.nc ]; then ln -sf  ../$INIT/start_$f.$date.nc .; fi; done
 cp $gcm gcm.e
 fi  # fin de " if [ ! -d $local/$SIM ]"
@@ -671,5 +656,5 @@
 # Choix du "time limit" pour le job
 ###################################
-if [ "$freq" = "yr" ] ; then cput=04:00:00 ; else cput=01:00:00 ; fi
+if [ "$freq" = "yr" ]; then cput=04:00:00; else cput=01:00:00; fi
 
 #####################################################################
@@ -678,13 +663,13 @@
 sed -e 's/stopsim=.*.$/stopsim='$stopsim'/' -e 's/^veget=.*.$/veget='$veget'/' -e 's/orchidee_rev=.*.$/orchidee_rev='$orchidee_rev'/' -e 's/^aerosols=.*.$/aerosols='$aerosols'/' -e 's/^isotopes=.*.$/isotopes='$isotopes'/' -e 's/NOM_SIMU/'$SIM'/' -e 's/time=.*.$/time='$cput'/' -e 's/MAINDIR=.*.$/MAINDIR='$MAINDIR'/' -e 's:STORED=.*.*:STORED='$STORED':'  -e 's:SCRATCHD=.*.*:SCRATCHD='$SCRATCHD':' -e 's/ntasks=.*.$/ntasks='$mpi'/' -e 's/cpus-per-task=.*.$/cpus-per-task='$omp'/' -e 's/nthreads=.*./nthreads='$omp'/' -e 's/^climato=.*.$/climato='$climato'/' -e 's/^ok_guide=.*.$/ok_guide='$ok_guide'/' -e 's/groupe@cpu/'$groupe'@cpu/' $local/script_SIMU >| $WRK/tmp_$SIM
 
-if [ "$testmode" = "y" ] ; then
+if [ "$testmode" = "y" ]; then
   sed -i -e 's/time=.*.$/time=00:30:00/' -e 's/#nday=1/nday=1/' -e 's/#[[:space:]]#SBATCH[[:space:]]--qos=qos_cpu-dev/#SBATCH --qos=qos_cpu-dev/' $WRK/tmp_$SIM
 fi
 
-if [ $climato = 0 ] ; then
+if [ $climato = 0 ]; then
 # calend est choisi plus haut dans "Changements dans les fichiers DEF/*def" et ecrit dans $MAINDIR/DEF/run.def
 yrini=`echo $mthini | cut -c-4`
 yrend=`echo $mthend | cut -c-4`
-yrs="" ; yr=$yrini ; while [ $yr -le $yrend ] ; do yrs="$yrs $yr" ; (( yr = $yr + 1 )) ; done
+yrs=""; yr=$yrini; while [ $yr -le $yrend ]; do yrs="$yrs $yr"; (( yr = $yr + 1 )); done
 suf=360x180_
 else
@@ -698,5 +683,5 @@
 #####################################################################
 
-if [ ! -d $LMDZ_Init ] ; then mkdir $LMDZ_Init ; fi
+if [ ! -d $LMDZ_Init ]; then mkdir $LMDZ_Init; fi
 
 #------------------------------------------------------------------- 
@@ -707,23 +692,23 @@
 liste_get+="routing.nc routing_simple.nc lai2D.nc soils_param.nc "
 liste_get+="woodharvest_2000.nc PFTmap_15PFT.v1_2000.nc"
-for file in $liste_get ; do 
-  if [ ! -f $LMDZ_Init/$file ] ; then cd $LMDZ_Init ; ${get}$file ; cd - ; fi 
+for file in $liste_get; do 
+  if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi 
 done
 # Additionnal files needed for ORCHIDEE trunk post-CMIP6
-if [ $veget = 7994 -a ! -f $LMDZ_Init/soil_bulk_and_ph.nc ] ; then
+if [ $veget = 7994 -a ! -f $LMDZ_Init/soil_bulk_and_ph.nc ]; then
   cd $LMDZ_Init 
-  ${get}soil_bulk_and_ph.nc ; ${get}NITROGEN_for_ORtrunk.tar
-  tar -xvf NITROGEN_for_ORtrunk.tar ; cd - 
+  ${get}soil_bulk_and_ph.nc; ${get}NITROGEN_for_ORtrunk.tar
+  tar -xvf NITROGEN_for_ORtrunk.tar; cd - 
 fi
 #------------------------------------------------------------------- 
 # Fichiers aerosols/chimie
 #------------------------------------------------------------------- 
-if [ $aerosols = clim ] ; then
+if [ $aerosols = clim ]; then
   get="myget 3DInputData/AerChem/"
   #liste_get="aerosols1850_from_inca.nc aerosols2000_from_inca.nc" 
   #aerosols9999_from_inca.nc est un lien vers aerosols1995_2014_ensavg_from_inca.nc
   liste_get="aerosols1850_from_inca.nc aerosols9999_from_inca.nc"
-  for file in $liste_get ; do 
-    if [ ! -f $LMDZ_Init/$file ] ; then cd $LMDZ_Init ; ${get}$file ; cd - ; fi
+  for file in $liste_get; do 
+    if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi
   done
 fi
@@ -736,6 +721,6 @@
 # a regrider ensuite par un script interp_fichiers_spla.sh (comme pour aerosols="clim") 
 # Les fichiers (regrides, sauf SOILSPEC.data utilise tel quel) seront mis dans $MAINDIR/INPUT_SPLA (equivalent de INPUT_DUST)
-if [ $aerosols = spla ] ; then
-  if [ ! -d ${LMDZ_Init}/SPLA_Init ] ; then mkdir ${LMDZ_Init}/SPLA_Init ; mkdir $LMDZ_Init/SPLA_Init/INITIAL ; fi
+if [ $aerosols = spla ]; then
+  if [ ! -d ${LMDZ_Init}/SPLA_Init ]; then mkdir ${LMDZ_Init}/SPLA_Init; mkdir $LMDZ_Init/SPLA_Init/INITIAL; fi
   get="cp -p /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/INITIAL/"
   liste_get="wth.dat cly.dat donnees_lisa.nc SOILSPEC.data \
@@ -743,6 +728,6 @@
                sulphur_emissions_nat.nc  sulphur_emissions_volc.nc" 
 
-  for file in $liste_get ; do
-    if [ ! -f $LMDZ_Init/SPLA_Init/INITIAL/$file ] ; then cd $LMDZ_Init/SPLA_Init/INITIAL ; ${get}$file . ; cd - ; fi
+  for file in $liste_get; do
+    if [ ! -f $LMDZ_Init/SPLA_Init/INITIAL/$file ]; then cd $LMDZ_Init/SPLA_Init/INITIAL; ${get}$file .; cd -; fi
   done
 ###
@@ -754,5 +739,5 @@
   #ICI pour l'instant je copie les fichiers de chez Binta (repositoire==http...) dans LMDZ_Init/SPLA_Init, avec test sur mois 01
 
-  if [ ! -d ${LMDZ_Init}/SPLA_Init/PERIOD0001 ] ; then cp -pr /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/PERIOD* $LMDZ_Init/SPLA_Init/. ; fi
+  if [ ! -d ${LMDZ_Init}/SPLA_Init/PERIOD0001 ]; then cp -pr /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/PERIOD* $LMDZ_Init/SPLA_Init/.; fi
 
  #A la fin on doit avoir dans SPLA_Init les fichiers initiaux dans INITIAL plus les repertoires PERIOD00MM contenant dust.nc 
@@ -767,6 +752,6 @@
 get="myget 3DInputData/Init/"
 liste_get="alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc"
-for file in $liste_get ; do 
-  if [ ! -f $LMDZ_Init/$file ] ; then cd $LMDZ_Init ; ${get}$file ; cd - ; fi
+for file in $liste_get; do 
+  if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi
 done
 
@@ -775,5 +760,5 @@
 
 
-if [ $init = 1 ] ; then
+if [ $init = 1 ]; then
    #####################################################################
       echo Creation de l etat initial
@@ -782,14 +767,14 @@
    # Creation du repertoire INIT et mise en place de liens logiques vers les starts
    # en anticipation de leur création :
-   mkdir $local/$INIT ; cd $local/$INIT
-   for an in $mthini $yearini ; do for f in start startphy ; do ln -s $f.nc $f.$an.nc ; done ; done
+   mkdir $local/$INIT; cd $local/$INIT
+   for an in $mthini $yearini; do for f in start startphy; do ln -s $f.nc $f.$an.nc; done; done
 
    # Creation du repertoire INIT temporaire et rapatriement des fichiers necessaires
-   if [ -d $WRK/$INIT ] ; then mv $WRK/$INIT $WRK/$INIT$$ ; fi
-   mkdir $WRK/$INIT ;  cp -r $local/DEF $WRK/$INIT/
-   cd $WRK/$INIT ; cp DEF/*.def . ; cp $local/lmdz_env.sh .
-   if [ $xios = y ] ; then 
+   if [ -d $WRK/$INIT ]; then mv $WRK/$INIT $WRK/$INIT$$; fi
+   mkdir $WRK/$INIT;  cp -r $local/DEF $WRK/$INIT/
+   cd $WRK/$INIT; cp DEF/*.def .; cp $local/lmdz_env.sh .
+   if [ $xios = y ]; then 
        cp DEF/XMLfilesLMDZ/*xml .  
-       if [ $veget != 'NONE' ] ; then cp DEF/XMLfilesOR$veget/*xml . ; fi 
+       if [ $veget != 'NONE' ]; then cp DEF/XMLfilesOR$veget/*xml .; fi 
    fi 
    sed -e 's/anneeref=.*.$/anneeref='$yearini'/' DEF/run.def >| run.def
@@ -800,11 +785,11 @@
    get="myget 3DInputData/Limit/"
    liste_get="Albedo.nc Relief.nc Rugos.nc landiceref.nc"
-   for yr in $yrs ; do
-       if [ $climato = 0 ] ; then sufyr=$suf$yr ; else sufyr=$suf ; fi
+   for yr in $yrs; do
+       if [ $climato = 0 ]; then sufyr=$suf$yr; else sufyr=$suf; fi
        liste_get="$liste_get  amipbc_sic_$sufyr.nc amipbc_sst_$sufyr.nc"
    done
    echo LISTEGET $liste_get
-   for file in $liste_get ; do
-     if [ ! -f $LMDZ_Init/$file ] ; then cd $LMDZ_Init ; ${get}$file ; cd - ; fi
+   for file in $liste_get; do
+     if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi
      ln -s $LMDZ_Init/$file
    done
@@ -813,5 +798,5 @@
 #------------------------------------------------------------------- 
    get="myget 3DInputData/Init/"
-   if [ ! -f $LMDZ_Init/ECDYN.nc ] ; then cd $LMDZ_Init ; ${get}ECDYN.nc ; cd - ; fi
+   if [ ! -f $LMDZ_Init/ECDYN.nc ]; then cd $LMDZ_Init; ${get}ECDYN.nc; cd -; fi
    ln -s $LMDZ_Init/ECDYN.nc
    ln -sf ECDYN.nc ECPHY.nc
@@ -819,5 +804,5 @@
 
    # Creation du script d'initialisation
-   cat <<...eod>| tmp
+   cat << ...eod >| tmp
 #!/bin/bash
 
@@ -832,5 +817,5 @@
 #SBATCH --output=Init%j.out     # Nom du fichier de sortie
 #SBATCH --error=Init%j.out      # Nom du fichier d'erreur (ici commun avec la sortie)
-# To submit to dev queue ; "time" (above) must be max 2h
+# To submit to dev queue; "time" (above) must be max 2h
 # #SBATCH --qos=qos_cpu-dev
 
@@ -839,5 +824,5 @@
 # ANCIEN MULTI STEP   init )
 
-   if [ ! -f lmdz_env.sh ] ; then echo manque fichier lmdz_env.sh ; ls ; exit ; fi
+   if [ ! -f lmdz_env.sh ]; then echo manque fichier lmdz_env.sh; ls; exit; fi
    . lmdz_env.sh
    ulimit -s unlimited
@@ -846,6 +831,6 @@
    cd $WRK/$INIT
    echo Executable : $ce0l
-   for yr in $yrs ; do 
-      if [ $climato = 0 ] ; then sufyr=$suf\$yr ; else sufyr=$suf ; fi
+   for yr in $yrs; do 
+      if [ $climato = 0 ]; then sufyr=$suf\$yr; else sufyr=$suf; fi
       ln -sf amipbc_sic_\$sufyr.nc amipbc_sic_1x1.nc
       ln -sf amipbc_sst_\$sufyr.nc amipbc_sst_1x1.nc
@@ -853,44 +838,44 @@
       echo Starting initialisation
       $run 1 $ce0l
-      if [ $climato = 0 ] ; then mv limit.nc limit.\$yr.nc ; fi
+      if [ $climato = 0 ]; then mv limit.nc limit.\$yr.nc; fi
    done
-# ANCIEN MULTI STEP    ;;
+# ANCIEN MULTI STEP   ;;
 
 # ANCIEN MULTI STEP   interp )
-   if [ $aerosols = clim ] ; then
-    cp $local/interp_aerosols.sh . ; chmod +x interp_aerosols.sh
+   if [ $aerosols = clim ]; then
+    cp $local/interp_aerosols.sh .; chmod +x interp_aerosols.sh
     # Les aerosols de l'annee 2000 ont ete remplaces par "9999" qui pointe vers un fichier moyen sur 1995-2014
-    #for year in 2000 1850 ; do  ./interp_aerosols.sh \$year ; done
-    #mv aerosols.2000.nc aerosols.clim.nc ; mv aerosols.1850.nc aerosols.nat.nc
-    for year in 9999 1850 ; do ./interp_aerosols.sh \$year ; done
-    mv aerosols.9999.nc aerosols.clim.nc ; mv aerosols.1850.nc aerosols.nat.nc
+    #for year in 2000 1850; do  ./interp_aerosols.sh \$year; done
+    #mv aerosols.2000.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
+    for year in 9999 1850; do ./interp_aerosols.sh \$year; done
+    mv aerosols.9999.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
    fi
 
    # AS : S'il etait possible d'automatiser l'interpolation de l'input SPLA, ce serait a lancer ici
    #en attendant, on passe au paragraphe suivant où on copie les fichiers à la res ZoomNaf depuis $LMDZ_Init/SPLA_Init
-   #if [ $aerosols = spla ] ; then
-    #cp $local/futur script interp_aerosols_SPLA.sh . ; chmod +x interp_aerosols_SPLA.sh
-    #for file in... ; do  ./interp_aerosols_SPLA.sh \$year ; done
+   #if [ $aerosols = spla ]; then
+    #cp $local/futur script interp_aerosols_SPLA.sh .; chmod +x interp_aerosols_SPLA.sh
+    #for file in...; do  ./interp_aerosols_SPLA.sh \$year; done
     #etc etc etc ...
    #fi
 
 # Copy initial and forcing files in $local/$INIT and $local/$LIMIT; also in $local/INPUT_SPLA if $aerosols=spla
-   for f in sta* limit.nc gri*nc ; do cp \$f $local/$INIT/\$f ; done
+   for f in sta* limit.nc gri*nc; do cp \$f $local/$INIT/\$f; done
    mkdir -p $local/$LIMIT
-   for f in limit*.nc  ; do cp \$f $local/$LIMIT/\$f ; done
-   if [ $aerosols = clim ] ; then  for f in aerosols[.0-9]*nc ; do cp \$f $local/$LIMIT/\$f ; done ; fi
+   for f in limit*.nc ; do cp \$f $local/$LIMIT/\$f; done
+   if [ $aerosols = clim ]; then  for f in aerosols[.0-9]*nc; do cp \$f $local/$LIMIT/\$f; done; fi
    # 
-   if [ $aerosols = spla ] ; then 
-     #mkdir -p $local/INPUT_SPLA ; pour l'instant on copie $LMDZ_Init/SPLA_Init en block
-     if [ ! -d $local/INPUT_SPLA ] ; then cp -pr $LMDZ_Init/SPLA_Init $local/INPUT_SPLA ; fi
+   if [ $aerosols = spla ]; then 
+     #mkdir -p $local/INPUT_SPLA; pour l'instant on copie $LMDZ_Init/SPLA_Init en block
+     if [ ! -d $local/INPUT_SPLA ]; then cp -pr $LMDZ_Init/SPLA_Init $local/INPUT_SPLA; fi
    fi
    cd $WRK
 ...eod
-   if [ $ok_guide != y ] ; then # Running first simulation automatically except for nudging
-      cat <<...eod>> tmp
+   if [ $ok_guide != y ]; then # Running first simulation automatically except for nudging
+      cat << ...eod >> tmp
          $submit tmp_$SIM
 ...eod
    fi
-   cat <<...eod>> tmp
+   cat << ...eod >> tmp
 # ANCIEN MULTI STEP   esac
 ...eod
@@ -914,10 +899,10 @@
 
 
-if [ $ok_guide = y -a $init = 1 ] ; then
+if [ $ok_guide = y -a $init = 1 ]; then
    echo Once initialisation is finished, you have to create nudging files
    echo Edit era2gcm.sh and set the desired parameters in section "User choices"
    echo Make sure you have acces to the chosen ERA files, and the required modules are load
    echo Then run : ./era2gcm.sh
-   if [ "$aerosols" = "spla" ] ; then
+   if [ "$aerosols" = "spla" ]; then
      echo Your aerosol choice is "spla", so you need ERA 10m-winds interpolated on LMDZ grid
      echo Use script era2gcm_uv10m.sh  
