Index: trunk/LMDZ.COMMON/libf/evolution/deftank/PCMrun.job
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/deftank/PCMrun.job	(revision 3460)
+++ trunk/LMDZ.COMMON/libf/evolution/deftank/PCMrun.job	(revision 3495)
@@ -23,4 +23,7 @@
 # Name of executable for the PCM:
 exePCM="gcm_64x48x32_phymars_para.e"
+
+# Execution command:
+exe_cmd="srun --cpu-bind=threads --label -c${OMP_NUM_THREADS:=1}"
 ########################################################################
 
@@ -32,6 +35,6 @@
 read i_myear n_myear convert_years iPCM iPEM nPCM nPCM_ini < info_PEM.txt
 cp run_PCM.def run.def
-srun --cpu-bind=threads --label -c${OMP_NUM_THREADS:=1} $exePCM > out_runPCM${iPCM} 2>&1
-if [ ! -f "restartfi.nc" ] || ! (tail -n 1 out_runPCM${iPCM} | grep -iq "everything is cool!"); then # Check if it ended abnormally
+eval "$exe_cmd $exePCM > out_runPCM${iPCM} 2>&1"
+if [ ! -f "restartfi.nc" ] || ! (tail -n 100 out_runPCM${iPCM} | grep -iq "everything is cool!"); then # Check if it ended abnormally
     echo "Error: the run PCM $iPCM crashed!"
     echo "Be careful: there may be dependent jobs remaining in the SLURM queue with status 'DependencyNeverSatisfied'! You can cancel them by executing the script \"kill_launchPEM.sh\"."
Index: trunk/LMDZ.COMMON/libf/evolution/deftank/PEMrun.job
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/deftank/PEMrun.job	(revision 3460)
+++ trunk/LMDZ.COMMON/libf/evolution/deftank/PEMrun.job	(revision 3495)
@@ -22,4 +22,7 @@
 # Name of executable for reshaping PCM data with XIOS:
 exeReshape="reshape_XIOS_output_64x48x32_phymars_seq.e"
+
+# Argument for the PEM execution (for SLURM: "$SLURM_JOB_ID" | for PBD/TORQUE: "$PBS_JOBID" | "" when the script is not run as a job):
+arg_pem="$SLURM_JOB_ID"
 ########################################################################
 
@@ -39,6 +42,6 @@
 echo "Run PEM $iPEM is starting."
 cp run_PEM.def run.def
-./$exePEM $SLURM_JOB_ID > out_runPEM${iPEM} 2>&1
-if [ ! -f "restartfi.nc" ] || ! (tail -n 1 out_runPEM${iPEM} | grep -iq "so far, so good!"); then # Check if it ended abnormally
+eval "./$exePEM $arg_pem > out_runPEM${iPEM} 2>&1"
+if [ ! -f "restartfi.nc" ] || ! (tail -n 100 out_runPEM${iPEM} | grep -iq "so far, so good!"); then # Check if it ended abnormally
     echo "Error: the run PEM $iPEM crashed!"
     exit 1
Index: trunk/LMDZ.COMMON/libf/evolution/deftank/README
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/deftank/README	(revision 3460)
+++ trunk/LMDZ.COMMON/libf/evolution/deftank/README	(revision 3495)
@@ -7,9 +7,9 @@
       (ii)  nPCM_ini -> the number of initial PCM runs (at least 2);
       (iii) nPCM -> the number of PCM runs between each PEM run (usually 2);
-      (iv)  dim -> the dimension of the model (1 for 1D, any other values stand for 3D).
+      (iv)  mode -> the launching mode (0 = "processing scripts"; any other values = "submitting jobs"). The former option is usually used to process the script on a local machine while the latter is used to submit jobs on supercomputer.
   The script can take an argument:
       - If there is no argument, then the script initiates a PEM simulation from scratch.
       - If the argument is 're', then the script relaunches an existing PEM simulation. It will ask for parameters to know the starting point that you want to. 
-  The script works only with the job scheduler SLURM to submit chained jobs.
+  To submit chained jobs, the script works with the job schedulers SLURM and PBS/TORQUE.
 
 # liblaunchPEM.sh:
@@ -17,13 +17,14 @@
 
 # PCMrun.job:
-  Bash script file to submit a PCM job (with SLURM or PBS/TORQUE). The name of the PCM executable file should be adapted. The headers correspond to the ADASTRA supercomputer and should be changed for other machines and job schedulers. In case of 1D, the headers are naturally omitted.
+  Bash script file to submit a PCM job (with SLURM or PBS/TORQUE). The headers correspond to the ADASTRA supercomputer and should be changed for other machines and job schedulers. In case of "processiong scripts" launching mode, the headers are naturally omitted.
   The path to source the arch file should be adapted to the machine.
-  The execution line should also be adapted according to the set-up.
+  The name of the PCM executable file should be adapted.
+  The execution command should also be adapted according to the set-up.
 
 # PEMrun.job:
-  Bash script file to submit PEM job (with SLURM or PBS/TORQUE). The name of the PEM executable file and Reshaping executable file should be adapted. The headers correspond to the ADASTRA supercomputer and should be changed for other machines and job schedulers. In case of 1D, the headers are naturally omitted.
+  Bash script file to submit PEM job (with SLURM or PBS/TORQUE).The headers correspond to the ADASTRA supercomputer and should be changed for other machines and job schedulers. In case of "processiong scripts" launching mode, the headers are naturally omitted.
   The path to source the arch file should be adapted to the machine.
-  The execution line should also be adapted according to the set-up.
-  The PEM executable can have an optional argument to specify the SLURM job ID in order to detect the job time limit and deal with it.
+  The name of the PEM executable file and Reshaping executable file should be adapted.
+  The PEM executable can have an optional argument which should be specified according to the set-up. This the job ID to make the PEM detect the job time limit.
 
 # run_PEM.def
Index: trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh	(revision 3460)
+++ trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh	(revision 3495)
@@ -17,12 +17,12 @@
 #n_earth_years=300
 
-# Set the number of initial PCM runs:
+# Set the number of initial PCM runs (>= 2):
 nPCM_ini=3
 
-# Set the number of PCM runs between each PEM run:
+# Set the number of PCM runs between each PEM run (>= 2):
 nPCM=2
 
-# Set the dimension of the model (1 = "1D"; other values = "3D"):
-dim=3
+# Set the launching mode (0 = "processing scripts"; any other values = "submitting jobs"). The former option is usually used to process the script on a local machine while the latter is used to submit jobs on supercomputer:
+mode=1
 ########################################################################
 
@@ -48,5 +48,5 @@
     checklaunch
     initlaunch
-    cyclelaunch $dim $nPCM_ini
+    cyclelaunch $mode $nPCM_ini
 
 else
@@ -57,9 +57,9 @@
         echo "This is a new cycle for the PEM simulation."
         date
-        if [ $dim -ne 1 ]; then
+        if [ $mode -ne 0 ]; then
             job_scheduler
         fi
         read i_myear n_myear convert_years iPCM iPEM nPCM nPCM_ini < info_PEM.txt
-        cyclelaunch $dim $nPCM
+        cyclelaunch $mode $nPCM
 
     # Starting a relaunch
@@ -122,7 +122,7 @@
         fi
         if [ $relaunch = "PCM" ]; then
-            relaunchPCM $dim
+            relaunchPCM $mode
         else
-            relaunchPEM $dim
+            relaunchPEM $mode
         fi
 
@@ -133,5 +133,5 @@
         echo "This is a continuation of the previous PEM run."
         date
-        submitPEM $dim
+        submitPEM $mode
 
     # Default case: error
Index: trunk/LMDZ.COMMON/libf/evolution/deftank/lib_launchPEM.sh
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/deftank/lib_launchPEM.sh	(revision 3460)
+++ trunk/LMDZ.COMMON/libf/evolution/deftank/lib_launchPEM.sh	(revision 3495)
@@ -32,5 +32,4 @@
         submit_job="sbatch --parsable"
         submit_dependjob="sbatch --parsable --dependency"
-        sed -i 's/\$PBS_JOBID/\$SLURM_JOB_ID/g' PEMrun.job
     elif command -v qstat &> /dev/null; then
         echo "PBS/TORQUE is installed on $machine."
@@ -39,5 +38,4 @@
         submit_job="qsub"
         submit_dependjob="qsub -W depend"
-        sed -i 's/\$SLURM_JOB_ID/\$PBS_JOBID/g' PEMrun.job
     else
         echo "Error: neither SLURM nor TORQUE/PBS is installed on $machine!"
@@ -119,5 +117,5 @@
         mkdir diags
     fi
-    if [ $dim -ne 1 ]; then
+    if [ $mode -ne 0 ]; then
         job_scheduler
     fi
@@ -161,5 +159,5 @@
 
 # To submit the PCM runs
-# arg1: model dimension
+# arg1: launching mode
 # arg2: number of PCM runs to launch
 # arg3: local number of the PCM run from which to start (optional)
@@ -172,5 +170,5 @@
     if [ $i_myear -lt $n_myear ]; then
         echo "Run PCM $iPCM: call $ii/$2..."
-        if [ $1 -eq 1 ]; then # 1D model
+        if [ $1 -eq 0 ]; then # Mode: processing scripts
             sed -i "s/^k=[0-9]\+$/k=$(echo "3 - $nPCM_ini" | bc)/" PCMrun.job
             ./PCMrun.job
@@ -178,5 +176,5 @@
                 errlaunch
             fi
-        else # 3D model
+        else # Mode: launching jobs
             cp PCMrun.job PCMrun${iPCM}.job
             sed -i -E "s/($name_job[^0-9]*[0-9]*[^0-9]*)[0-9]+$/\1${iPCM}/" PCMrun${iPCM}.job
@@ -197,5 +195,5 @@
         if [ $i_myear -lt $n_myear ]; then
             echo "Run PCM $iPCM: call $i/$2..."
-            if [ $1 -eq 1 ]; then # 1D model
+            if [ $1 -eq 0 ]; then # Mode: processing scripts
                 sed -i "s/^k=[0-9]\+$/k=$(echo "$i + 2 - $nPCM_ini" | bc)/" PCMrun.job
                 ./PCMrun.job
@@ -203,5 +201,5 @@
                     errlaunch
                 fi
-            else # 3D model
+            else # Mode: launching jobs
                 cp PCMrun.job PCMrun${iPCM}.job
                 sed -i -E "s/($name_job[^0-9]*[0-9]*[^0-9]*)[0-9]+$/\1${iPCM}/" PCMrun${iPCM}.job
@@ -219,14 +217,14 @@
 
 # To submit the PEM run
-# arg1: model dimension
+# arg1: launching mode
 submitPEM() {
     if [ $i_myear -lt $n_myear ]; then
         echo "Run PEM $iPEM"
-        if [ $1 -eq 1 ]; then # 1D model
+        if [ $1 -eq 0 ]; then # Mode: processing scripts
             ./PEMrun.job
             if [ $? -ne 0 ]; then
                 errlaunch
             fi
-        else # 3D model
+        else # Mode: launching jobs
             sed -i -E "s/($name_job[^0-9]*[0-9]*[^0-9]*)[0-9]+$/\1${iPEM}/" PEMrun.job
             jobID=$(eval "$submit_job PEMrun.job")
@@ -242,5 +240,5 @@
 
 # To make one cycle of PCM and PEM runs
-# arg1: model dimension
+# arg1: launching mode
 # arg2: number of PCM runs to launch
 # arg3: local number of the PCM run from which to start (optional)
@@ -252,10 +250,10 @@
     if [ $i_myear -lt $n_myear ]; then
         echo "Run PEM $iPEM"
-        if [ $1 -eq 1 ]; then # 1D model
+        if [ $1 -eq 0 ]; then # Mode: processing scripts
             ./PEMrun.job
             if [ $? -ne 0 ]; then
                 errlaunch
             fi
-        else # 3D model
+        else # Mode: launching jobs
             sed -i -E "s/($name_job[^0-9]*[0-9]*[^0-9]*)[0-9]+$/\1${iPEM}/" PEMrun.job
             jobID=$(eval "$submit_dependjob=afterok:${jobID} PEMrun.job")
@@ -293,5 +291,5 @@
 
 # To relaunch from PCM run
-# arg1: model dimension
+# arg1: launching mode
 relaunchPCM() {
     iPCM=$(($irelaunch + 1))
@@ -361,5 +359,5 @@
 
 # To relaunch from PEM run
-# arg1: model dimension
+# arg1: launching mode
 relaunchPEM() {
     iPEM=$(echo "$irelaunch + 1" | bc)
