Index: BOL/LMDZ_Setup_amaury/lmdz_env.sh
===================================================================
--- BOL/LMDZ_Setup_amaury/lmdz_env.sh	(revision 4940)
+++ BOL/LMDZ_Setup_amaury/lmdz_env.sh	(revision 4953)
@@ -4,52 +4,53 @@
 ##############################################################
 
-hostname=jean-zay-pp2
-echo lmdz_env $hostname 0:3 ${hostname:0:3}
+hostname=$(hostname)
+echo "Setting up lmdz_env on $hostname"
 
 case ${hostname:0:5} in
-
-        jean-) ARCH=X64_JEANZAY
-		module purge
-		compilo=19.0.4 # available 2013.0, 2017.2
-		module load intel-compilers/$compilo
-		#module load intel-mpi/$compilo
-		module load intel-mkl/$compilo
-		module load hdf5/1.10.5-mpi
-		module load netcdf/4.7.2-mpi
-		module load netcdf-fortran/4.5.2-mpi
-		module load subversion/1.9.7
-		#Pour module gcc, voir : https://trac.lmd.jussieu.fr/LMDZ/wiki/PortageJeanZay
-		#module load gcc/6.5.0
-                module load nco
-                module load cdo
-		# Imputation de la consommation sur le groupe (projet) actif par defaut,
-		#   idrproj indique le groupe (projet) actif par defaut
-		#   idrproj -d newproj   redefinit "newproj" en tant que  projet actif, 
-		#        alors $STORE, $WORK etc vont designer les espaces de "newproj")
-		groupe=`idrproj | grep active | awk '{ print $1}'`
-		submit="sbatch -A ${groupe}@cpu "
-		run="srun --label -n "
-		# Espaces suivants definis par defaut en fonction du groupe actif,
-		#  par exemple : SCRATCHD=$SCRATCH is /gpfsstore/rech/$groupe/$login
-                #    * On peut aussi ne pas installer les scripts a la racine de STORE, 
+  jean-)
+    ARCH="X64_JEANZAY"
+    module purge
+    compilo=19.0.4 # available 2013.0, 2017.2
+    module load intel-compilers/$compilo
+    #module load intel-mpi/$compilo
+    module load intel-mkl/$compilo
+    module load hdf5/1.10.5-mpi
+    module load netcdf/4.7.2-mpi
+    module load netcdf-fortran/4.5.2-mpi
+    module load subversion/1.9.7
+    #Pour module gcc, voir : https://trac.lmd.jussieu.fr/LMDZ/wiki/PortageJeanZay
+    #module load gcc/6.5.0
+    module load nco
+    module load cdo
+    # Imputation de la consommation sur le groupe (projet) actif par defaut,
+    #   idrproj indique le groupe (projet) actif par defaut
+    #   idrproj -d newproj   redefinit "newproj" en tant que  projet actif,
+    #        alors $STORE, $WORK etc vont designer les espaces de "newproj")
+    groupe=$(idrproj | grep active | awk '{ print $1}')
+    submit="sbatch -A ${groupe}@cpu "
+    run="srun --label -n "
+    # Espaces suivants definis par defaut en fonction du groupe actif,
+    #  par exemple : SCRATCHD=$SCRATCH is /gpfsstore/rech/$groupe/$login
+                #    * On peut aussi ne pas installer les scripts a la racine de STORE,
                 #        mais dans STORED=$STORE/your_folder
-                STORED=$STORE
-		SCRATCHD=$SCRATCH
-		LMDZD=$WORK
-		nb_mpi_max=2000
-		nb_omp_max=20
-		#LMDZ_Init sur le $STORE du $groupe
-		LMDZ_Init=$STORE/LMDZ_Init ;;
-	*) ARCH=
-		submit=". "
-		run="mpirun -np "
-		SCRATCHD=~/TMP/SCRATCH
-		STORED=~/TMP/
-		LMDZD=~/TMP
-		nb_mpi_max=2
-		nb_omp_max=2
-		LMDZ_Init=~/LMDZ/LMDZ_Init
+    STORED=$STORE
+    SCRATCHD=$SCRATCH
+    LMDZD=$WORK
+    NB_MPI_MAX=2000
+    NB_OMP_MAX=20
+    #LMDZ_Init sur le $STORE du $groupe
+    LMDZ_Init=$STORE/LMDZ_Init ;;
+  *)  # TODO mettre clairement dans ce paragraphe une doc de chaque param
+    ARCH="local-gfortran-parallel"
+#    submit=". "
+#    run="mpirun -np "
+#    SCRATCHD="/tmp/SCRATCH"
+#    STORED=~"/TMP/"
+    LMDZD="./LMDZD"
+    NB_MPI_MAX=999999
+    NB_OMP_MAX=999999
+#    LMDZ_Init=~"/LMDZ/LMDZ_Init"
 esac
 
 
-echo LMDZ_Init dans lmdz_env $LMDZ_Init
+#echo LMDZ_Init dans lmdz_env $LMDZ_Init
Index: BOL/LMDZ_Setup_amaury/setup.sh
===================================================================
--- BOL/LMDZ_Setup_amaury/setup.sh	(revision 4940)
+++ BOL/LMDZ_Setup_amaury/setup.sh	(revision 4953)
@@ -15,5 +15,4 @@
   optim=""
   #optim="-debug"
-  # TODO Amaury: quelle diff avec l'option fcm="debug" ???
 
   #NOTE : "testmode=y" is for running in test mode :
@@ -58,7 +57,4 @@
   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,
@@ -104,5 +100,4 @@
   svn=""
 
-  install=0
   init=1
 
@@ -135,5 +130,4 @@
       "-f") freq=$2; shift; shift;;
       "-p") phylmd=$2; shift; shift;;
-      "-install") install=1; shift;;
       "-name") SIM=$2; shift; shift;;
       "-cosp") cosp=y; shift;;
@@ -169,15 +163,31 @@
   # 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
+     echo "STOP: 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 "STOP: 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
+
+
+  # (Temporary) Constraints for aerosols=spla :
+  # --> resolution 128x88x79 and rad=rrtm
+  if [[ $aerosols = 1 && $resol != "128x88x79" ]]; then
+    echo 'STOP: 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 resol=<$resol>"
+    exit 1
+  fi
 }
 
 function install_model {
   mkdir -p "$LMDZD"
+
+  local ins_xios ins_cosp ins_aero ins_inlandsis
+  if [[ $xios = "y" ]]; then ins_xios="-xios"; else ins_xios=""; fi
+  if [[ $cosp = "y" ]]; then ins_cosp="-cosp v1"; else ins_cosp=""; fi
+  if [[ $aerosols = "spla" ]]; then ins_aero="-spla"; else ins_aero=""; fi
+  if [[ $inlandsis = "y" ]]; then ins_inlandsis="-inlandsis"; else ins_inlandsis=""; fi
+  if [[ -n $svn ]]; then svnopt="-r $svn"; else svnopt=""; fi
 
   version_name=LMDZ$(echo "$version" | sed -e 's/-v//g' -e 's/-unstable//' -e 's/-r/r/' -e 's/ //g')
@@ -185,26 +195,16 @@
   MODEL="$LMDZD/$LMDZname/modipsl/modeles/LMDZ"
 
-  if [[ $install = 1 ]]; then  # run install_lmdz to pull the required files and compile once
-    if [[ -d $MODEL ]]; then
-      echo "MODEL=$MODEL"
-      echo "STOP: Vous essayez d'installer une version déja présente (option <-install>)"; exit 1
-    else
-      echo "Installing model"
-      cd "$LMDZD"
-      cp "$local/install_lmdz.sh" .
-      chmod +x install_lmdz.sh
-      # TODO handle arch/env here (used to be -env-file)
-      echo "./install_lmdz.sh $fcm $optim -v $version $svnopt -d $resol -rad $rad -bench 0 -parallel mpi_omp $ins_cosp $ins_xios -name $LMDZname -veget $veget -netcdf 0 -arch $ARCH" >> install_lmdz_options.$$.sh
-      chmod +x install_lmdz_options.$$.sh
-      echo "Running install_lmdz_options.$$.sh"
-      ./install_lmdz_options.$$.sh
-      mv install_lmdz.sh install_lmdz.$$.sh
-      cd -
-     fi
-  else
-     if [[ ! -d $MODEL ]]; then
-        echo "Le model $MODEL n'est pas installé. Vous pouvez relancez avec <-install>."; exit 1
-     fi
-  fi
+  if [[ -d $MODEL ]]; then echo "Found existing install at MODEL=$MODEL"; fi
+  echo "Installing model"
+  cd "$LMDZD"
+  cp "$local/install_lmdz.sh" .
+  chmod +x install_lmdz.sh
+  # TODO handle arch/env here (used to be -env-file)
+  echo "./install_lmdz.sh -noclean $optim -v $version $svnopt -d $resol -rad $rad -bench 0 -parallel mpi_omp $ins_cosp $ins_xios $ins_aero $ins_inlandsis -name $LMDZname -veget $veget -netcdf 0 -arch $ARCH" >> install_lmdz_options.$$.sh
+  chmod +x install_lmdz_options.$$.sh
+  echo "Running install_lmdz_options.$$.sh"
+  ./install_lmdz_options.$$.sh
+  mv install_lmdz.sh install_lmdz.$$.sh
+  cd -
 }
 
@@ -227,107 +227,11 @@
 
 
-# TODO check w/ Adriana the exact reasons why we recompile the model (or even compile it using install_lmdz in the first place)
-
 # COMPILATION OPTIONS depending on the user choices and LMDZ revision number $mysvn
 #-------------------------------------------------------
-arch="-arch $ARCH"
-if [ "$rad" = "ecrad" -a ! -d ecrad_data ]; then
+if [[ $rad = "ecrad" && ! -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 1; fi
-
-# Source the surface_env file created by install_lmdz.sh, to get the "veget"-related variables
-#--------------------------------------------------------------------------------------
-# surface_env is produced by install_lmdz in $MODEL=$LMDZD/$LMDZname/modipsl/modeles
-# Every model installation will have an unique orchidee_rev, 
-#   to be changed by hand if a new Orchidee rev is installed by hand in modipsl/models
-. $LMDZD/$LMDZname/modipsl/modeles/surface_env
-echo LMDZname $LMDZD/$LMDZname/modipsl/modeles/surface_env
-echo veget=$veget
-echo opt_veget=$opt_veget
-echo orchidee_rev=$orchidee_rev
-echo suforch=$suforch
-
-
-#######################################################################
-# Compilation du modele
-#######################################################################
-# The gcm name defined below is used to check if the executable exists
-# It is also used when compiling without fcm : the output of makelmdz is gcm.e, and is renamed as $gcm
-#
-# NOTE : Some compilation options do not appear in the gcm name (xios, cosp, ...).
-#   (Also : LMDZ rev before 4185 included, did not contain radiative-code suffix; starting r4186, it includes oldrad/rrtm/ecrad )
-#   So if you change those options and you want to recompile,
-#   setup.sh will not detect the change when testing if [ ! -f $gcm ], 
-#   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="$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 
-      suffix_iso=_${resol}_phy${phylmd}_para_mem${suforch}${sufaer}${sufiso}
-    else
-      suffix_iso=_${resol}_phy${phylmd}_${rad}_para_mem${suforch}${sufaer}${sufiso}
-    fi
-    phylmd="lmd"
-fi
-
-# compile_opt is used for gcm if isotopes=n, and for ce0l always
-compile_opt="$optim -p $phylmd $opt_cosp $opt_xios $opt_rad $arch -d $resol $opt_veget $opt_aer $opt_inlandsis -mem -parallel mpi_omp"
-
-
-# use an intermediate variable to use either suffix or suffix_iso
-strsuffix=suffix${sufiso}
-gcm=$MODEL/bin/gcm${!strsuffix}.e
-
-echo $mysvn
-echo $gcm
-
-if [ ! -f $gcm ]; then
-   echo Le model $gcm n existe pas
-   echo il va se compiler automatiquement sur $MODEL
-   sleep 10
-
-   compile="./makelmdz_fcm $compile_opt -j 2 \$1"
-   compile_iso="./makelmdz_fcm $compile_opt_iso -j 2 \$1"
-
-   #NB on est dans $local, qui est $STORE/$MAINDIR
-   echo $compile${sufiso}
-
-   #create compile.sh; 
-   # if isotopes = y , it will still be used for compiling ce0l
-   cat << ...eod >| compile.sh
-   cd $MODEL
-   prog=\$1
-   ${compile}
-...eod
-   pwd
-   ls -l compile.sh
-   chmod +x compile.sh
-
-   #create compile_iso.sh for compiling gcm_ _iso.e
-   if [ $isotopes = y ]; then
-   cat << ...eod >| compile_iso.sh
-   cd $MODEL
-   prog=\$1
-   ${compile_iso}
-...eod
-   pwd
-   ls -l compile_iso.sh
-   chmod +x compile_iso.sh
-   fi
-
-   echo Compilation de LMDZ, suivre avancement dans lmdz.log
-   ./compile${sufiso}.sh gcm > lmdz.log 2>&1
-
-   if [ ! -f $gcm ]; then echo la compilation a echoue; exit; fi
-   cd $local
-fi
-
-# TODO ^ qu'est-ce qui nous empêche de mettre tout ça directement dans install_lmdz ????
-# TODO Ce qu'il faudrait faire:
-# TODO 1) bien expliquer ce que fait l'option install (lancer install_lmdz une unique fois pour lancer tout sauf la compil LMDZ => maintenant ça ne fonctionne plus car on installe tjrs lmdz, mais en fait c'est pas grave car derrière on vérifie si le gcm.e existe ou non)
-# TODO 2) importer les fonctions de install_lmdz nécessaires pour "recompiler" lmdz "à la carte" (ou bien juste modifier compile.sh ??)
 
 
@@ -339,19 +243,19 @@
 #   omp=2 for veget=CMIP6 beacause of a bug in ORCHIDEE/src_xml/xios_orchidee.f90
 ######################################################################
-jm=`echo $resol | cut -dx -f2`
-(( mpi = ( $jm + 1 ) / 2 ))
+
+cd "$local"
+
+jm=$(echo "$resol" | cut -dx -f2)
+(( 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" && $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
-  for file_iso in $( ls DEF | grep _iso)
-  do
-    cp DEF/$file_iso DEF/${file_iso%%_iso}
+if [[ $phylmd = "lmdiso" ]]; then
+  for file_iso in $(ls DEF | grep _iso); do
+    cp DEF/"$file_iso" DEF/"${file_iso%%_iso}"
   done
 fi
@@ -360,11 +264,9 @@
 # Choix de la grille verticale
 ######################################################################
-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
-                                 echo creer un fichier DEF/L$lm.def
-   exit
+lm=$(echo "$resol" | cut -dx -f3)
+if [ ! -f "DEF/L$lm.def" ]; then
+  echo "STOP: Résolution verticale non prévue - créer un fichier DEF/L$lm.def"; exit 1
 else
-   sed -i -e 's/INCLUDEDEF=L.*.def/INCLUDEDEF=L'$lm'.def/' DEF/run.def
+  sed -i'' -e "s/INCLUDEDEF=L.*.def/INCLUDEDEF=L$lm.def/" DEF/run.def
 fi
 
@@ -380,10 +282,9 @@
 # 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 
+if [[ $aerosols = "spla" ]]; then
    # ancien traceur pour l instant
-   cp DEF/traceur.def_spla   DEF/traceur.def  
-elif [ $isotopes = n ]; then
-   # nouveau traceur 
-   # déjà copié si 'y'
+   cp DEF/traceur.def_spla DEF/traceur.def
+elif [[ $phylmd = "lmdiso" ]]; then
+   # nouveau traceur , déjà copié si 'y'
    cp DEF/tracer.def_nospla DEF/tracer.def  
 fi
@@ -391,5 +292,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
