diff --git a/build/with_fcm/make_fcm.sh b/build/with_fcm/make_fcm.sh
index 20d1f0c29132627c95751e229619fa32cb548d4e..f89e38d49f93b0db76668d29df202392c605639e 100755
--- a/build/with_fcm/make_fcm.sh
+++ b/build/with_fcm/make_fcm.sh
@@ -14,6 +14,8 @@ function parse_args() {
   MESONHPROFILE=
   useexpand=1
   commit=""
+  packcreation=0
+  compilation=0
   # pass unrecognized arguments to fcm
   FCM_ARGS=""
   
@@ -30,6 +32,8 @@ $0 [options]
 --mesonhprofile FILE  build using Méso-NH profile and rules (--arch must be used to give a name to the build dir)
 --noexpand            do not use mnh_expand (code will be in array-syntax)"
 --commit              commit hash (or a directory) to test; do not use this option from within a repository
+-p                    creates 'pack' (compilation directory)
+-c                    performs compilation
 
 Unrecognized options are passed to the fcm build command. Useful options include :
 --new                   clean build tree before building
@@ -39,6 +43,8 @@ Unrecognized options are passed to the fcm build command. Useful options include
 For details on FCM, see 
     http://metomi.github.io/fcm/doc/user_guide/build.html
     http://metomi.github.io/fcm/doc/user_guide/command_ref.html#fcm-build
+
+If neither creation nor execution is requested, both steps are performed.
 EOF
         exit;;
       "--arch")
@@ -51,6 +57,8 @@ EOF
         MESONHPROFILE=$1 ; shift ;;
       '--noexpand') useexpand=0;;
       '--commit') commit=$1; shift;;
+      '-p') packcreation=1;;
+      '-c') compilation=1;;
       *)
         FCM_ARGS="$FCM_ARGS $OPTION" ;;
     esac
@@ -64,6 +72,11 @@ EOF
     echo "--arch option is mandatory if --mesonhprofile option is used"
     exit 3
   fi
+  if [ $packcreation -eq 0 -a \
+       $compilation -eq 0 ]; then
+    packcreation=1
+    compilation=1
+  fi
 }
 
 function check_install_fcm() {
@@ -248,85 +261,89 @@ chmod +x compilation.sh
 # Parse command line arguments
 parse_args $*
 
-# Change current working dir
-cd -P $(dirname $0)
-
-# Check the fcm installation
-check_install_fcm
-
-# Check the fiat installation
-check_install_fiat
-
-# Create the build directory and set up the build system
-builddir=arch_$ARCH
-if [ -d $builddir ]; then
-  echo "$builddir already exists. To rerun compilation, please enter this directory and use the compilation.sh script."
-  echo "Otherwise, you can remove the $builddir directory and execute again this script."
-  exit 1
-fi
-mkdir $builddir
-if [ "$GMKFILE" != "" ]; then
-  touch $builddir/arch.env
-  gmkfile2arch $GMKFILE $builddir/arch.fcm
-elif [ "$MESONHPROFILE" != "" ]; then
-  touch $builddir/arch.env
-  mesonhprofile2archenv $MESONHPROFILE $builddir/arch.fcm $builddir/arch.env
-else
-  cp ${ARCH_PATH}/arch-${ARCH}.env $builddir/arch.env
-  cp ${ARCH_PATH}/arch-${ARCH}.fcm $builddir/arch.fcm 
-fi
-cp fcm-make.cfg $builddir
-cd $builddir
-
-# Populate the source directory with (modified) PHYEX source code
-[ "$commit" == "" ] && commit=$PWD/../../.. #Current script run from within a PHYEX repository
-if echo $commit | grep '/' | grep -v '^tags/' > /dev/null; then
-  # We get the source code directly from a directory
-  fromdir=$commit
-else
-  # We use a commit to checkout
-  fromdir=''
-fi
-#Expand options
-if [ $useexpand == 1 ]; then
-  expand_options="-D MNH_EXPAND -D MNH_EXPAND_LOOP"
-else
-  expand_options=""
-fi
-PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/../../../tools #if run from within a PHYEX repository
-UPDATEDPATH=$PATH
-which prep_code.sh > /dev/null || export UPDATEDPATH=$PHYEXTOOLSDIR:$PATH
-subs="$subs -s turb -s shallow -s turb_mnh -s micro -s aux -s ice_adjust -s rain_ice -s rain_ice_old -s support"
-if [ "$fromdir" == '' ]; then
-  echo "Clone repository, and checkout commit $commit (using prep_code.sh)"
-  if [[ $commit == testprogs${separator}* ]]; then
-    PATH=$UPDATEDPATH prep_code.sh -c $commit src #This commit is ready for inclusion
+if [ $packcreation -eq 1 ]; then
+  # Change current working dir
+  cd -P $(dirname $0)
+  
+  # Check the fcm installation
+  check_install_fcm
+  
+  # Check the fiat installation
+  check_install_fiat
+  
+  # Create the build directory and set up the build system
+  builddir=arch_$ARCH
+  if [ -d $builddir ]; then
+    echo "$builddir already exists. To rerun compilation, please enter this directory and use the compilation.sh script."
+    echo "Otherwise, you can remove the $builddir directory and execute again this script."
+    exit 1
+  fi
+  mkdir $builddir
+  if [ "$GMKFILE" != "" ]; then
+    touch $builddir/arch.env
+    gmkfile2arch $GMKFILE $builddir/arch.fcm
+  elif [ "$MESONHPROFILE" != "" ]; then
+    touch $builddir/arch.env
+    mesonhprofile2archenv $MESONHPROFILE $builddir/arch.fcm $builddir/arch.env
+  else
+    cp ${ARCH_PATH}/arch-${ARCH}.env $builddir/arch.env
+    cp ${ARCH_PATH}/arch-${ARCH}.fcm $builddir/arch.fcm 
+  fi
+  cp fcm-make.cfg $builddir
+  cd $builddir
+  
+  # Populate the source directory with (modified) PHYEX source code
+  [ "$commit" == "" ] && commit=$PWD/../../.. #Current script run from within a PHYEX repository
+  if echo $commit | grep '/' | grep -v '^tags/' > /dev/null; then
+    # We get the source code directly from a directory
+    fromdir=$commit
+  else
+    # We use a commit to checkout
+    fromdir=''
+  fi
+  #Expand options
+  if [ $useexpand == 1 ]; then
+    expand_options="-D MNH_EXPAND -D MNH_EXPAND_LOOP"
   else
-    PATH=$UPDATEDPATH prep_code.sh -c $commit $expand_options $subs -m testprogs src
+    expand_options=""
   fi
-else
-  echo "Copy $fromdir"
-  mkdir src
-  scp -q -r $fromdir/src src/
-  PATH=$UPDATEDPATH prep_code.sh $expand_options $subs -m testprogs src
+  PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/../../../tools #if run from within a PHYEX repository
+  UPDATEDPATH=$PATH
+  which prep_code.sh > /dev/null || export UPDATEDPATH=$PHYEXTOOLSDIR:$PATH
+  subs="$subs -s turb -s shallow -s turb_mnh -s micro -s aux -s ice_adjust -s rain_ice -s rain_ice_old -s support"
+  if [ "$fromdir" == '' ]; then
+    echo "Clone repository, and checkout commit $commit (using prep_code.sh)"
+    if [[ $commit == testprogs${separator}* ]]; then
+      PATH=$UPDATEDPATH prep_code.sh -c $commit src #This commit is ready for inclusion
+    else
+      PATH=$UPDATEDPATH prep_code.sh -c $commit $expand_options $subs -m testprogs src
+    fi
+  else
+    echo "Copy $fromdir"
+    mkdir src
+    scp -q -r $fromdir/src src/
+    PATH=$UPDATEDPATH prep_code.sh $expand_options $subs -m testprogs src
+  fi
+  
+  # Add some code
+  cd src
+  ln -s ../../fiat/src fiat
+  cat <<..EOF > dummyprog.F90
+  PROGRAM DUMMYPROG
+    PRINT*, "CREATED TO FORCE FCM TO LINK SOMETHING"
+  END PROGRAM DUMMYPROG
+..EOF
 fi
 
-# Add some code
-cd src
-ln -s ../../fiat/src fiat
-cat <<EOF > dummyprog.F90
-PROGRAM DUMMYPROG
-  PRINT*, "CREATED TO FORCE FCM TO LINK SOMETHING"
-END PROGRAM DUMMYPROG
-EOF
-
 # Build the compilation script and run it
-cd ..
-build_compilation_script src
-./compilation.sh
-ln -s build/bin/libphyex.so .
-
-# Check if python can open the resulting shared lib
-python3 -c "from ctypes import cdll; cdll.LoadLibrary('./libphyex.so')"
-
-# ldd -r ./libphyex.so should also give interesting results
+if [ $compilation -eq 1 ]; then
+  cd -P $(dirname $0)/arch_$ARCH
+  build_compilation_script src
+  ./compilation.sh
+  ln -s build/bin/libphyex.so .
+  
+  # Check if python can open the resulting shared lib
+  python3 -c "from ctypes import cdll; cdll.LoadLibrary('./libphyex.so')"
+  
+  # ldd -r ./libphyex.so should also give interesting results
+fi
diff --git a/src/testprogs/testprogs_version.json b/src/testprogs/testprogs_version.json
index 528914ce657e44610fe13f3e2a9eb15a9837ba2b..95dc1e732e72ca45ac96d382e7e7d398a2721141 100644
--- a/src/testprogs/testprogs_version.json
+++ b/src/testprogs/testprogs_version.json
@@ -1,5 +1,9 @@
 {
 "testing": {
-            "ALL":"41c6be7"
+            "ice_adjust":"41c6be7",
+            "rain_ice":"41c6be7",
+            "rain_ice_old":"41c6be7",
+            "turb":"41c6be7",
+            "shallow":"41c6be7"
            }
 }
diff --git a/tools/INSTALL.sh b/tools/INSTALL.sh
new file mode 100755
index 0000000000000000000000000000000000000000..862b33b4e9dbf651452c31913d63f21a7d6c0a84
--- /dev/null
+++ b/tools/INSTALL.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+#set -x
+set -e
+set -o pipefail #abort if left command on a pipe fails
+
+PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+function usage {
+  echo "Usage: $0 [-h] [--install-dataset]"
+  echo "--install-dataset          Install a reduced dataset for the test programs"
+}
+
+install_dataset=0
+
+while [ -n "$1" ]; do
+  case "$1" in
+    '--install-dataset') install_dataset=1;;
+  esac
+  shift
+done
+
+if [ $install_dataset -eq 1 ]; then
+  cd $PHYEXTOOLSDIR/testprogs_data/
+  for file in https://github.com/UMR-CNRM/PHYEX/files/12783926/ice_adjust.tar.gz \
+              https://github.com/UMR-CNRM/PHYEX/files/12783935/rain_ice.tar.gz \
+              https://github.com/UMR-CNRM/PHYEX/files/12783942/rain_ice_old.tar.gz \
+              https://github.com/UMR-CNRM/PHYEX/files/12783945/shallow.tar.gz \
+              https://github.com/UMR-CNRM/PHYEX/files/12783952/turb.tar.gz; do
+    basefile=$(basename $file)
+    wget --no-check-certificate $file -O $basefile
+    tar xf $basefile
+    rm -f $basefile
+  done
+fi
diff --git a/tools/INSTALL_testprogs.md b/tools/INSTALL_testprogs.md
index 6429882e255ff00c15ec28bbea218a81824692cf..8a3e9241799876ee1abdc151db6f577623ab0284 100644
--- a/tools/INSTALL_testprogs.md
+++ b/tools/INSTALL_testprogs.md
@@ -7,11 +7,10 @@ These programs need data. This document describes how to generate the data, the
 
 This document is written using the markdown language. With pandoc, it can be converted to HTML (pandoc -s \<filename\>.md -o \<filename\>.html) or PDF (pandoc -s \<filename\>.md -o \<filename\>.pdf). 
 
+## DATA
 
-## DATA GENERATION
+There are two options.
 
-Please, refer to the [Offline](../docs/Offline.md) documentation.
+On one hand, the data can be generated (please, refer to the [Offline](../docs/Offline.md) documentation) and, once produced, be put in the corresponding directories under tools/testprogs\_data.
 
-## DATA INSTALLATION
-
-Once produced, the data must be put in the corresponding directories under tools/testprogs\_data.
+On the other hand, a reduced dataset can be automatically dowloaded and installed using the INSTALL.sh script.
diff --git a/tools/check_commit_ial.sh b/tools/check_commit_ial.sh
index da9ef89114d2de2e42316792a169eb932a0cf260..3f5e489cef849a195878fe952613953b50412e08 100755
--- a/tools/check_commit_ial.sh
+++ b/tools/check_commit_ial.sh
@@ -115,7 +115,7 @@ mainPackVersion=${mainPackVersion:-${defaultMainPackVersion}}
 ################################
 
 function usage {
-  echo "Usage: $0 [-h] [-p] [-c] [-r] [-C] [-s] [-f] [--noexpand] [-t test] [--cycle CYCLE] [--scripttag TAG] [--repo-user USER] [--repo-protocol PROTOCOL] [--remove] [--onlyIfNeeded] [--computeRefIfNeeded] commit [reference]"
+  echo "Usage: $0 [-h] [-p] [-c] [-r] [-C] [-s] [-f] [--noexpand] [-t TEST] [--cycle CYCLE] [--scripttag TAG] [--repo-user USER] [--repo-protocol PROTOCOL] [--remove] [--onlyIfNeeded] [--computeRefIfNeeded] commit [reference]"
   echo "commit          commit hash (or a directory, or among $specialPack) to test"
   echo "reference       commit hash (or a directory, or among $specialPack) REF to use as a reference"
   echo "-s              suppress compilation pack"
@@ -123,7 +123,7 @@ function usage {
   echo "-c              performs compilation"
   echo "-r              runs the tests"
   echo "-C              checks the result against the reference"
-  echo "-t              comma separated list of tests to execute"
+  echo "-t TEST         comma separated list of tests to execute"
   echo "                or ALL to execute all tests"
   echo "--noexpand      do not use mnh_expand (code will be in array-syntax)"
   echo "-f              full compilation (do not use pre-compiled pack)"
@@ -631,6 +631,10 @@ if [ $compilation -eq 1 ]; then
   fi
 fi
 
+###################
+#### EXECUTION ####
+###################
+
 if [ $run -ge 1 ]; then
   #Cleaning to suppress old results that may be confusing in case of a crash during the run
   if [ $onlyIfNeeded -eq 0 ]; then
diff --git a/tools/check_commit_mesonh.sh b/tools/check_commit_mesonh.sh
index b3d2835f5b4f05baa97d2207ef2110feadf57daa..f1950e3cac2afd425458b4b81123e6557513175a 100755
--- a/tools/check_commit_mesonh.sh
+++ b/tools/check_commit_mesonh.sh
@@ -4,41 +4,68 @@
 set -e
 set -o pipefail #abort if left command on a pipe fails
 
+#Notes for v5.5.0
+#For the OCEAN_LES/004_run2 case, results obtained are different from those obtained with the original version
+#of Meso-NH because of new developments and bug correction. The reference version is given by commit e053c59.
+#In this commit two modifications must be done in turb/mode_tke_eps_sources.f90 to change twice LOCEAN into OOCEAN.
+
+#######################
+#### CONFIGURATION ####
+#######################
+
 #The folowing environment variables can be defined:
-# REFDIR: directory in which the reference compilation directory can be found
 # TARGZDIR: directory where tar.gz files are searched for
 # MNHPACK: directory where tests are build
 
-availTests="007_16janvier/008_run2, 007_16janvier/008_run2_turb3D, 007_16janvier/008_run2_lredf, COLD_BUBBLE/002_mesonh, 
-            ARMLES/RUN, COLD_BUBBLE_3D/002_mesonh,OCEAN_LES/004_run2,014_LIMA/002_mesonh"
+#About the tests:
+# - ALLTests is a list of tests to be done when '-t ALL' is used. This list is filled here
+#   in case there is no mesonh_version.json file containig a 'testing' section. If this 'testing'
+#   section exists, this list is overridden.
+# - allowedTests is the list of allowed tests which can depend on platform, if we ask to perform an action
+#   with a test not in the allowedTests list, the action is ignored
+# - defaultTest is the list of tests to perform when no '-t' option is provided on the command line.
+ALLTests="007_16janvier/008_run2, 007_16janvier/008_run2_turb3D, 007_16janvier/008_run2_lredf, 
+          COLD_BUBBLE/002_mesonh, ARMLES/RUN, COLD_BUBBLE_3D/002_mesonh,OCEAN_LES/004_run2,014_LIMA/002_mesonh"
 defaultTest="007_16janvier/008_run2"
+allowedTests=$ALLTests
+
 separator='_' #- be carrefull, gmkpack (at least on belenos) has multiple allergies (':', '.', '@')
               #- seprator must be in sync with prep_code.sh separator
 
-#Notes for v5.5.0
-#For the OCEAN_LES/004_run2 case, results obtained are different from those obtained with the original version
-#of Meso-NH because of new developments and bug correction. The reference version is given by commit e053c59.
-#In this commit two modifications must be done in turb/mode_tke_eps_sources.f90 to change twice LOCEAN into OOCEAN.
-
 PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+MNHPACK=${MNHPACK:=$HOME/MesoNH/PHYEX}
+TARGZDIR=${TARGZDIR:=$PHYEXTOOLSDIR/pack/}
+
+################################
+#### COMMAND LINE ARGUMENTS ####
+################################
+
 function usage {
-  echo "Usage: $0 [-h] [-c] [-r] [-C] [-s] [--expand] [-t test] [--remove] commit [reference]"
-  echo "commit          commit hash (or a directory)"
+  echo "Usage: $0 [-h] [-p] [-c] [-r] [-C] [-s] [--expand] [-t TEST] [--repo-user USER] [--repo-protocol PROTOCOL] [--remove] [--onlyIfNeeded] [--computeRefIfNeeded] commit [reference]"
+  echo "commit          commit hash (or a directory) to test"
   echo "reference       commit hash or a directory or nothing for ref"
   echo "-s              suppress compilation pack"
+  echo "-p              creates pack"
   echo "-c              performs compilation"
   echo "-r              runs the tests"
   echo "-C              checks the result against the reference"
-  echo "-t              comma separated list of tests to execute"
+  echo "-t TEST         comma separated list of tests to execute"
   echo "                or ALL to execute all tests"
   echo "--expand        use mnh_expand (code will use do loops)"
-  echo "--repo-user     user hosting the PHYEX repository on github,"
+  echo "--repo-user USER"
+  echo "                user hosting the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
-  echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github,"
+  echo "--repo-protocol PROTOCOL"
+  echo "                protocol (https or ssh) to reach the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)"
   echo "--remove        removes the pack"
+  echo "--onlyIfNeeded  performs the pack creation and/or the compilation and/or the execution"
+  echo "                only if the step has not already been done"
+  echo "--computeRefIfNeeded"
+  echo "                computes the missing references"
   echo ""
-  echo "If nothing is asked (compilation, running, check, removing) everything"
+  echo "If nothing is asked (pack creation, compilation, running, check, removing) everything"
   echo "except the removing is done"
   echo
   echo "If no test is aked for, the default one ($defaultTest) is executed"
@@ -51,6 +78,7 @@ function usage {
   echo "The commit can be a tag, written with syntagx tags/<TAG>"
 }
 
+packcreation=0
 compilation=0
 run=0
 check=0
@@ -60,11 +88,14 @@ tests=""
 suppress=0
 useexpand=0
 remove=0
+onlyIfNeeded=0
+computeRefIfNeeded=0
 
 while [ -n "$1" ]; do
   case "$1" in
     '-h') usage;;
     '-s') suppress=1;;
+    '-p') packcreation=1;;
     '-c') compilation=1;;
     '-r') run=$(($run+1));;
     '-C') check=1;;
@@ -73,6 +104,9 @@ while [ -n "$1" ]; do
     '--repo-user') export PHYEXREPOuser=$2; shift;;
     '--repo-protocol') export PHYEXREPOprotocol=$2; shift;;
     '--remove') remove=1;;
+    '--onlyIfNeeded') onlyIfNeeded=1;;
+    '--computeRefIfNeeded') computeRefIfNeeded=1;;
+
     #--) shift; break ;;
      *) if [ -z "${commit-}" ]; then
           commit=$1
@@ -88,21 +122,12 @@ while [ -n "$1" ]; do
   shift
 done
 
-[ "$reference" == 'REF' ] && reference="" #Compatibility with check_commit_arome.sh
-
-MNHPACK=${MNHPACK:=$HOME/MesoNH/PHYEX}
-REFDIR=${REFDIR:=$PHYEXTOOLSDIR/pack/}
-TARGZDIR=${TARGZDIR:=$PHYEXTOOLSDIR/pack/}
-if [ -z "${tests-}" ]; then
-  tests=$defaultTest
-elif [ $tests == 'ALL' ]; then
-  tests=$availTests
-fi
-
-if [ $compilation -eq 0 -a \
+if [ $packcreation -eq 0 -a \
+     $compilation -eq 0 -a \
      $run -eq 0 -a \
      $check -eq 0 -a \
      $remove -eq 0 ]; then
+  packcreation=1
   compilation=1
   run=1
   check=1
@@ -113,7 +138,23 @@ if [ -z "${commit-}" ]; then
   exit 2
 fi
 
-#Name, directory and reference for compiling and executing user pack
+##############################
+#### FUNCTION DEFINITIONS ####
+##############################
+
+function json_dictkey2value {
+  # $1 must contain the json string
+  # $2 must be the key name
+  # $3 is the default value
+  json_content="$1" python3 -c "import json; import os; result=json.loads(os.environ['json_content']).get('$2', '$3'); print(json.dumps(result) if isinstance(result, dict) else result)"
+}
+
+###################################
+#### VERSION/COMMIT ADAPTATION ####
+###################################
+
+#Name and directory for compiling and executing user pack
+declare -A refByTest
 if echo $commit | grep '/' | grep -v '^tags/' > /dev/null; then
   fromdir=$commit
   content_mesonh_version=$(scp $commit/src/mesonh/mesonh_version.json /dev/stdout 2>/dev/null || echo "")
@@ -131,7 +172,22 @@ else
   fi
   content_mesonh_version=$(wget --no-check-certificate https://raw.githubusercontent.com/$PHYEXREPOuser/PHYEX/${urlcommit}/$mesonh_version_file -O - 2>/dev/null || echo "")
 fi
-refversion=$(content_mesonh_version=$content_mesonh_version python3 -c "import json, os; v=os.environ['content_mesonh_version']; print(json.loads(v if len(v)!=0 else '{}').get('refversion', 'MNH-V5-5-0'))")
+if [ ! "${content_mesonh_version}" == "" ]; then
+  testing=$(json_dictkey2value "$content_mesonh_version" 'testing' '')
+  if [ ! "$testing" == "" ]; then
+    ALLTests='' #We reset the list of tests
+    for t in $(echo $allowedTests | sed 's/,/ /g'); do
+      ref=$(json_dictkey2value "$testing" "$t" '')
+      if [ ! "$ref" == "" ]; then
+        ALLTests="${ALLTests},$t"
+        refByTest[$t]=$ref
+      fi
+    done
+    ALLTests="${ALLTests:1}" #Remove first character (',')
+  fi
+fi
+[ "${content_mesonh_version}" == "" ] && content_mesonh_version='{}'
+refversion=$(json_dictkey2value "$content_mesonh_version" 'refversion' 'MNH-V5-5-0')
 if [ $refversion == "MNH-V5-5-0" ]; then
   targzsuffix="_PHYEX"
 else
@@ -141,403 +197,346 @@ tag=$(echo $commit | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' |
 name=${refversion}-$tag
 [ $suppress -eq 1 -a -d $MNHPACK/$name ] && rm -rf $MNHPACK/$name
 
-#Two possibilities are supported for the simulations
-# - they can be done in the the pack we are currently checking
-# - they can be done in the reference pack
-#They are done in the current pack except if the reference pack
-#already contains a tested simulation
-#To check this, we use the case 007_16janvier/008_run2_turb3D
-if [ $(ls -d $REFDIR/${refversion}/MY_RUN/KTEST/007_16janvier/008_run2_turb3D_* 2> /dev/null | wc -l) -gt 0 ]; then
-  run_in_ref=1
-else
-  run_in_ref=0
-fi
-if [ $run_in_ref -eq 1 ]; then
-  path_user_beg=$REFDIR/${refversion} #pack directory containing the simulation
-  path_user_end=_$tag #to be appended to the 'run' simulation directory
-else
-  path_user_beg=$MNHPACK/$name #pack directory containing the simulation
-  path_user_end= #to be appended to the 'run' simulation directory
-fi
-
-#Name and directory for the reference
-reffromdir=''
-if echo $reference | grep '/' > /dev/null; then
-  reffromdir=$reference
-  reftag=$(echo $reference | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')
-else
-  reftag=$reference
-fi
-refname=${refversion}-$reftag
-if [ $run_in_ref -eq 1 ]; then
-  path_ref_beg=$REFDIR/${refversion}
-  if [ "$reference" == "" ]; then
-    path_ref_end=
+#Name and directory for the reference version
+declare -A refnameByTest
+#Reference to use for each test
+for t in $(echo $ALLTests | sed 's/,/ /g'); do
+  #Name of the reference
+  if [ "$reference" == "" -o "$reference" == "REF" ]; then
+    if [[ ! -z "${refByTest[$t]+unset}" ]]; then #the -v test is valid only with bash > 4.3
+      #The json file contained the references to use on a per test case basis
+      reftag=${refByTest[$t]}
+    else
+      reftag=""
+    fi
+    refByTest[$t]=$reftag
   else
-    path_ref_end=_$reftag
+    if echo $reference | grep '/' > /dev/null; then
+      reftag=$(echo $reference | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')
+    else
+      reftag=$reference
+    fi
+    refByTest[$t]=$reference
   fi
-else
-  path_ref_end=
-  if [ "$reference" == "" ]; then
-    path_ref_beg=$REFDIR/${refversion}
+  #Conversion into directory name
+  if [ "$reftag" == "" ]; then
+    refname=${refversion}
   else
-    path_ref_beg=$MNHPACK/${refversion}-$reftag
+    refname=${refversion}-$reftag
   fi
+  refnameByTest[$t]=$refname
+done
+
+if [ -z "${tests-}" ]; then
+  tests=$defaultTest
+elif echo "$tests" | grep -w 'ALL' > /dev/null; then
+  tests=$(echo "$tests" | sed "s:\bALL\b:$ALLTests:g")
 fi
 
-if [ $compilation -eq 1 ]; then
-  echo "### Compilation of commit $commit"
+#######################
+#### PACK CREATION ####
+#######################
 
+if [ $packcreation -eq 1 ]; then
   if [ -d $MNHPACK/$name ]; then
-    echo "Pack already exists ($MNHPACK/$name), suppress it to be able to compile it again (or use the -s option to automatically suppress it)"
-    exit 5
-  fi
-
-  # Prepare the pack
-  cd $MNHPACK
-  cp $TARGZDIR/${refversion}${targzsuffix}.tar.gz .
-  tar xfz ${refversion}${targzsuffix}.tar.gz 
-  rm ${refversion}${targzsuffix}.tar.gz
-  mv ${refversion} $name
-  cd $name/src
-  # Routine that changed names
-  
-  [ -f PHYEX/turb/modd_diag_in_run.f90 ] && mv -f PHYEX/turb/modd_diag_in_run.f90 MNH/. #To be removed once, this is done in MNH-git-lfs repo before inclusion of last version of PHYEX
-
-  rm -rf PHYEX
-
-  MNH_EXPAND_DIR=$PHYEXTOOLSDIR/mnh_expand
-  export PATH=$MNH_EXPAND_DIR/filepp:$MNH_EXPAND_DIR/MNH_Expand_Array:$PATH
-
-  if [ $useexpand == 1 ]; then
-    expand_options="-D MNH_EXPAND -D MNH_EXPAND_LOOP"
+    if [ $onlyIfNeeded -eq 0 ]; then
+      echo "Pack already exists ($MNHPACK/$name), suppress it to be able to compile it again (or use the -s option to automatically suppress it)"
+      exit 5
+    fi
   else
-    expand_options=""
-  fi
-  subs="-s turb -s micro -s aux -s ext -s conv"
-  prep_code=$PHYEXTOOLSDIR/prep_code.sh
-  if [ "$fromdir" == '' ]; then
-    echo "Clone repository, and checkout commit $commit (using prep_code.sh)"
-    if [[ $commit == mesonh${separator}* ]]; then
-      $prep_code --renameFf --ilooprm -c $commit PHYEX #This commit is ready for inclusion
+    echo "### Pack creation for commit $commit"
+
+    # Prepare the pack
+    cd $MNHPACK
+    mkdir ${name}_$$
+    cd ${name}_$$
+    cp $TARGZDIR/${refversion}${targzsuffix}.tar.gz .
+    tar xfz ${refversion}${targzsuffix}.tar.gz 
+    rm ${refversion}${targzsuffix}.tar.gz
+    mv ${refversion} ../$name
+    cd ..
+    rmdir ${name}_$$
+    cd $name/src
+
+    # Routine that changed names
+    [ -f PHYEX/turb/modd_diag_in_run.f90 ] && mv -f PHYEX/turb/modd_diag_in_run.f90 MNH/. #To be removed once, this is done in MNH-git-lfs repo before inclusion of last version of PHYEX
+
+    rm -rf PHYEX
+
+    MNH_EXPAND_DIR=$PHYEXTOOLSDIR/mnh_expand
+    export PATH=$MNH_EXPAND_DIR/filepp:$MNH_EXPAND_DIR/MNH_Expand_Array:$PATH
+
+    if [ $useexpand == 1 ]; then
+      expand_options="-D MNH_EXPAND -D MNH_EXPAND_LOOP"
     else
-      $prep_code --renameFf --ilooprm -c $commit $expand_options $subs -m mesonh PHYEX
+      expand_options=""
+    fi
+    subs="-s turb -s micro -s aux -s ext -s conv"
+    prep_code=$PHYEXTOOLSDIR/prep_code.sh
+    if [ "$fromdir" == '' ]; then
+      echo "Clone repository, and checkout commit $commit (using prep_code.sh)"
+      if [[ $commit == mesonh${separator}* ]]; then
+        $prep_code --renameFf --ilooprm -c $commit PHYEX #This commit is ready for inclusion
+      else
+        $prep_code --renameFf --ilooprm -c $commit $expand_options $subs -m mesonh PHYEX
+      fi
+    else
+      echo "Copy $fromdir"
+      mkdir PHYEX
+      scp -q -r $fromdir/src PHYEX/
+      $prep_code --renameFf --ilooprm $expand_options $subs -m mesonh PHYEX
+    fi
+    rm -rf PHYEX/.git
+    find PHYEX -type f -exec touch {} \; #to be sure a recompilation occurs
+
+    # Move manually ext/ files in src/MNH
+    [ -f PHYEX/ext/yomhook.f90 ] && mv PHYEX/ext/yomhook.f90 PHYEX/ext/yomhook.F90
+    if [ -d PHYEX/ext ]; then
+      mv -f PHYEX/ext/* MNH/
+      rmdir PHYEX/ext
     fi
-  else
-    echo "Copy $fromdir"
-    mkdir PHYEX
-    scp -q -r $fromdir/src PHYEX/
-    $prep_code --renameFf --ilooprm $expand_options $subs -m mesonh PHYEX
-  fi
-  rm -rf PHYEX/.git
-  find PHYEX -type f -exec touch {} \; #to be sure a recompilation occurs
-
-  # Move manually ext/ files in src/MNH
-  [ -f PHYEX/ext/yomhook.f90 ] && mv PHYEX/ext/yomhook.f90 PHYEX/ext/yomhook.F90
-  if [ -d PHYEX/ext ]; then
-    mv -f PHYEX/ext/* MNH/
-    rmdir PHYEX/ext
-  fi
 
-  cd $MNHPACK/$name/src/PHYEX/turb
-  # Delete files of ${refversion}/src/MNH and MNH/src/LIB/SURCOUCHE/src with same name
-  for rep in turb micro conv aux ; do
-    cd ../$rep
-    for f in *.f90; do
-      echo $f
-      rm -f ../../MNH/$f
-      rm -f ../../LIB/SURCOUCHE/src/$f
+    cd $MNHPACK/$name/src/PHYEX/turb
+    # Delete files of ${refversion}/src/MNH and MNH/src/LIB/SURCOUCHE/src with same name
+    for rep in turb micro conv aux ; do
+      cd ../$rep
+      for f in *.f90; do
+        echo $f
+        rm -f ../../MNH/$f
+        rm -f ../../LIB/SURCOUCHE/src/$f
+      done
     done
-  done
-  cd ..
-  
-  # Delete old files of ${refversion}/src/MNH that is now called by mode_... NO /aux NEEDED!
-  find turb micro conv -name 'mode_*' > remove_non_mode.sh
-  sed -i 's/turb\/mode_/rm -f MNH\//g' remove_non_mode.sh
-  sed -i 's/micro\/mode_/rm -f MNH\//g' remove_non_mode.sh
-  sed -i 's/conv\/mode_/rm -f MNH\//g' remove_non_mode.sh
-  chmod +x remove_non_mode.sh
-  mv remove_non_mode.sh ../.
-  cd ../
-  ./remove_non_mode.sh
-  # Supress some files if they are not used anymore
-  ! grep -i MODI_COMPUTE_ENTR_DETR $(ls MNH/*compute_updraft* PHYEX/turb/*compute_updraft* 2>/dev/null) && rm -f MNH/compute_entr_detr.f90
-  ! grep -i MODI_TH_R_FROM_THL_RT_ $(ls MNH/compute_entr_detr.f90 MNH/compute_entr_detr.f90 PHYEX/turb/mode_compute_updraft*.f90 MNH/ice_adjust_bis.f90 MNH/prep_ideal_case.f90 MNH/set_rsou.f90 2>/dev/null)  > /dev/null && rm -f MNH/th_r_from_thl_rt_1d.f90 MNH/th_r_from_thl_rt_2d.f90 MNH/th_r_from_thl_rt_3d.f90
+    cd ..
+    
+    # Delete old files of ${refversion}/src/MNH that is now called by mode_... NO /aux NEEDED!
+    find turb micro conv -name 'mode_*' > remove_non_mode.sh
+    sed -i 's/turb\/mode_/rm -f MNH\//g' remove_non_mode.sh
+    sed -i 's/micro\/mode_/rm -f MNH\//g' remove_non_mode.sh
+    sed -i 's/conv\/mode_/rm -f MNH\//g' remove_non_mode.sh
+    chmod +x remove_non_mode.sh
+    mv remove_non_mode.sh ../.
+    cd ../
+    ./remove_non_mode.sh
+    # Supress some files if they are not used anymore
+    ! grep -i MODI_COMPUTE_ENTR_DETR $(ls MNH/*compute_updraft* PHYEX/turb/*compute_updraft* 2>/dev/null) && rm -f MNH/compute_entr_detr.f90
+    ! grep -i MODI_TH_R_FROM_THL_RT_ $(ls MNH/compute_entr_detr.f90 MNH/compute_entr_detr.f90 PHYEX/turb/mode_compute_updraft*.f90 MNH/ice_adjust_bis.f90 MNH/prep_ideal_case.f90 MNH/set_rsou.f90 2>/dev/null)  > /dev/null && rm -f MNH/th_r_from_thl_rt_1d.f90 MNH/th_r_from_thl_rt_2d.f90 MNH/th_r_from_thl_rt_3d.f90
  
-  # Routine that changed names
-  #To be removed once, this is done in MNH-git-lfs repo before inclusion of last version of PHYEX
-  rm -f PHYEX/micro/ini_rain_ice.f90
-  rm -f PHYEX/micro/lima_nucleation_procs.f90
-  
- 
-  #Configure and compilation
-  command -v module && modulelist=$(module -t list 2>&1 | tail -n +2) #save loaded modules
-  ./configure
-  set +e #file ends with a test that can return false
-  . ../conf/profile_mesonh-* #This lines modifies the list of loaded modules
-  set -e
-  rm -f ../exe/* #Suppress old executables, if any
-  make -j 8 2>&1 | tee ../Output_compilation
-  make installmaster 2>&1 | tee -a ../Output_compilation
-  command -v module && module load $modulelist #restore loaded modules
+    # Routine that changed names
+    #To be removed once, this is done in MNH-git-lfs repo before inclusion of last version of PHYEX
+    rm -f PHYEX/micro/ini_rain_ice.f90
+    rm -f PHYEX/micro/lima_nucleation_procs.f90
+
+    # Remove binaries
+    rm -f $MNHPACK/$name/exe/*
+
+    # Remove execution results
+    for t in $(echo $ALLTests | sed 's/,/ /g'); do
+      case1=$(echo $t | cut -d / -f 1)
+      case2=$(echo $t | cut -d / -f 2)
+      casedir=$MNHPACK/$name/MY_RUN/KTEST/$case1
+      [ -d $casedir/$case2 ] && rm -rf $casedir/$case2
+    done
+  fi
 fi
 
-if [ $run -ge 1 ]; then
-  echo "### Running of commit $commit"
+#####################
+#### COMPILATION ####
+#####################
+
+profile_sourced=0
+if [ $compilation -eq 1 ]; then
+  if [ $onlyIfNeeded -eq 0 -o ! -f $MNHPACK/$name/exe/MESONH* ]; then
+    echo "### Compilation of commit $commit"
+    cd $MNHPACK/$name/src
+    #Configure and compilation
+    command -v module && modulelist=$(module -t list 2>&1 | tail -n +2) #save loaded modules
+    ./configure
+    set +e #file ends with a test that can return false
+    . ../conf/profile_mesonh-* #This lines modifies the list of loaded modules
+    set -e
+    profile_sourced=1
+    rm -f ../exe/* #Suppress old executables, if any
+    make -j 8 2>&1 | tee ../Output_compilation
+    make installmaster 2>&1 | tee -a ../Output_compilation
+    command -v module && module load $modulelist #restore loaded modules
+  fi
+fi
+
+###################
+#### EXECUTION ####
+###################
 
-  if [ ! -f $MNHPACK/$name/exe/MESONH* ]; then
-    echo "Pack does not exist ($MNHPACK/$name) or compilation has failed, please check"
-    exit 6
+if [ $run -ge 1 ]; then
+  #Cleaning to suppress old results that may be confusing in case of a crash during the run
+  if [ $onlyIfNeeded -eq 0 ]; then
+    for t in $(echo $tests | sed 's/,/ /g'); do
+      case1=$(echo $t | cut -d / -f 1)
+      case2=$(echo $t | cut -d / -f 2)
+      casedir=$MNHPACK/$name/MY_RUN/KTEST/$case1
+      [ -d $casedir/$case2 ] && rm -rf $casedir/$case2
+    done
   fi
 
+  #Run the tests one after the other
+  firstrun=1
   for t in $(echo $tests | sed 's/,/ /g'); do
-    case=$(echo $t | cut -d / -f 1)
-    exedir=$(echo $t | cut -d / -f 2)
-    if [ $run_in_ref -eq 1 ]; then
-      cd $REFDIR/${refversion}/MY_RUN/KTEST/$case/
-      [ ! -d ${exedir}_$commit ] && cp -R ${exedir} ${exedir}_$commit
-      cd $REFDIR/${refversion}/MY_RUN/KTEST/$case/${exedir}_$commit
-    else
-      #If the test case didn't exist in the tar.gz, we copy it from from the reference version
-      rep=$MNHPACK/$name/MY_RUN/KTEST/$case
-      [ ! -d $rep ] && cp -r $REFDIR/${refversion}/MY_RUN/KTEST/$case $rep
-      cd $rep
-
-      #Loop on the directories
-      for rep in *; do
-        if [[ -d "$rep" || ( -L "$rep" && ! -e "$rep" ) ]]; then #directory (or a link to a directory) or a broken link
-          if echo $availTests | grep ${case}/$rep > /dev/null; then
-            #This directory is a test case
-            if [ $rep == ${exedir} ]; then
-              #this is the case we want to run
-              rm -rf $rep
-              cp -r $REFDIR/${refversion}/MY_RUN/KTEST/$case/$rep .
+    if echo $allowedTests | grep -w $t > /dev/null; then #test is allowed on this plateform
+      case1=$(echo $t | cut -d / -f 1)
+      case2=$(echo $t | cut -d / -f 2)
+      casedir=$MNHPACK/$name/MY_RUN/KTEST/$case1
+      if [ ! -d $casedir/$case2 ]; then #We do not enter systematically this part if onlyIfNeeded=1
+        if [ $firstrun -eq 1 ]; then
+          echo "### Running of commit $commit"
+          firstrun=0
+        fi
+
+        if [ ! -f $MNHPACK/$name/exe/MESONH* ]; then
+          echo "Pack does not exist ($MNHPACK/$name) or compilation has failed, please check"
+          exit 6
+        fi
+
+        #If the test case didn't exist in the tar.gz, we copy it from from the reference version
+        #and we suppress all the test directories for this case
+        if [ ! -d $casedir ]; then
+          cp -r $MNHPACK/${refversion}/MY_RUN/KTEST/$case1 $casedir/
+          for newt in $(echo $ALLTests | sed 's/,/ /g'); do
+            newcase1=$(echo $newt | cut -d / -f 1)
+            newcase2=$(echo $newt | cut -d / -f 2)
+            if [ $case1 == $newcase1 ]; then
+              [ -d $casedir/$newcase2 ] rm -rf $casedir/$newcase2
             fi
-          else
-            #This directory might be neede to run the test case, we take the reference version
-            rm -rf $rep
-            ln -s $REFDIR/${refversion}/MY_RUN/KTEST/$case/$rep 
-          fi
+          done
         fi
-      done
 
-      #In case subcase does not exist we create it
-      [ ! -d ${exedir} ] && cp -r $REFDIR/${refversion}/MY_RUN/KTEST/$case/${exedir} .
-      cd ${exedir}
-    fi
+        #Loop on the subdirectories to replace them by links to their reference version
+        cd $casedir
+        for d in *; do
+          if [[ -d "$d" || ( -L "$d" && ! -e "$d" ) ]]; then #directory (or a link to a directory) or a broken link
+            if ! echo $ALLTests | grep ${case1}/$d > /dev/null; then
+              #This directory is not a test case but might be needed to run the test case,
+              #we take the reference version
+              rm -rf $d
+              ln -s $MNHPACK/${refversion}/MY_RUN/KTEST/$case1/$d 
+            fi
+          fi
+        done
 
-    set +e #file ends with a test that can return false
-    [ $compilation -eq 0 ] && . $MNHPACK/$name/conf/profile_mesonh-*
-    set -e
-    ./clean_mesonh_xyz
-    set +o pipefail #We want to go through all tests
-    ./run_mesonh_xyz | tee Output_run
-    set -o pipefail
+        #We create the test case directory
+        cp -r $MNHPACK/${refversion}/MY_RUN/KTEST/$case1/${case2} .
+
+        #execution
+        cd ${case2}
+        if [ $profile_sourced -eq 0 ]; then
+          set +e #file ends with a test that can return false
+          . $MNHPACK/$name/conf/profile_mesonh-*
+          set -e
+          profile_sourced=1
+        fi
+        ./clean_mesonh_xyz
+        set +o pipefail #We want to go through all tests
+        ./run_mesonh_xyz | tee Output_run
+        set -o pipefail
+      fi
+    fi
   done
 fi
 
+####################
+#### COMPARISON ####
+####################
+
 if [ $check -eq 1 ]; then
   echo "### Check commit $commit against commit $reference"
 
   allt=0
   for t in $(echo $tests | sed 's/,/ /g'); do
-    case=$(echo $t | cut -d / -f 1)
-    exedir=$(echo $t | cut -d / -f 2)
-    if [ $t == 007_16janvier/008_run2 ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/007_16janvier/008_run2$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/007_16janvier/008_run2$path_ref_end
-    elif  [ $t == 007_16janvier/008_run2_turb3D ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/007_16janvier/008_run2_turb3D$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/007_16janvier/008_run2_turb3D$path_ref_end
-    elif  [ $t == 007_16janvier/008_run2_lredf ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/007_16janvier/008_run2_lredf$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/007_16janvier/008_run2_lredf$path_ref_end
-    elif   [ $t == COLD_BUBBLE/002_mesonh ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/COLD_BUBBLE/002_mesonh$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/COLD_BUBBLE/002_mesonh$path_ref_end
-    elif   [ $t == COLD_BUBBLE_3D/002_mesonh ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/COLD_BUBBLE_3D/002_mesonh$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/COLD_BUBBLE_3D/002_mesonh$path_ref_end
-    elif   [ $t == ARMLES/RUN ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/ARMLES/RUN$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/ARMLES/RUN$path_ref_end
-    elif   [ $t == OCEAN_LES/004_run2 ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/OCEAN_LES/004_run2$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/OCEAN_LES/004_run2$path_ref_end
-    elif   [ $t == 014_LIMA/002_mesonh ]; then
-      path_user=$path_user_beg/MY_RUN/KTEST/014_LIMA/002_mesonh$path_user_end
-      path_ref=$path_ref_beg/MY_RUN/KTEST/014_LIMA/002_mesonh$path_ref_end
-    else
-      echo "cas $t non reconnu"
-    fi
-
-    if [ ! -d $path_user ]; then
-      echo "$path_user is missing, please run the simulation"
-      exit 7
-    fi
-    if [ ! -d $path_ref ]; then
-      echo "$path_ref is missing, please run the reference simulation"
-      exit 8
-    fi
-
-    if [ $case == 007_16janvier ]; then
-      # Compare variable of both Synchronous and Diachronic files with printing difference
-      file1=$path_user/16JAN.1.12B18.001.nc 
-      file2=$path_ref/16JAN.1.12B18.001.nc
-      file3=$path_user/16JAN.1.12B18.000.nc 
-      file4=$path_ref/16JAN.1.12B18.000.nc
-      if [ -f $file1 -a -f $file2 ]; then
-        echo "Compare with python..."
-        set +e
-        $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2 --f3 $file3 --f4 $file4
-        t=$?
-        set -e
-        allt=$(($allt+$t))
-        
-        #Check bit-repro before date of creation of Synchronous file from ncdump of all values (pb with direct .nc file checks)
-        echo "Compare with ncdump..."
-        set +e
-        bit_diff=57100
-        diff <(ncdump $file1 | head -c $bit_diff) <(ncdump $file2 | head -c $bit_diff)
-        t=$?
-        set -e
-        allt=$(($allt+$t))
-      else
-        [ ! -f $file1 ] && echo "  $file1 is missing"
-        [ ! -f $file2 ] && echo "  $file2 is missing"
-        allt=$(($allt+1))
+    if echo $allowedTests | grep -w $t > /dev/null; then
+      #Run the reference if needed
+      if [ $computeRefIfNeeded -eq 1 ]; then
+        if [ "${refByTest[$t]}" == "" ]; then
+          echo "Don't know how to compile/run $refversion"
+          exit 3
+        else
+          #We must call it in another shell because of the potentially loaded MesoNH profile
+          #because we cannot load two MesoNH profiles in the same shell
+          env -i $SHELL -l -c "MNHPACK=${MNHPACK} TARGZDIR=${TARGZDIR} \
+                               PHYEXREPOuser=${PHYEXREPOuser} PHYEXREPOprotocol=${PHYEXREPOprotocol} \
+                               $0 -p -c -r -t $t --onlyIfNeeded ${refByTest[$t]}"
+        fi
       fi
-    fi
 
-    if [ $case == COLD_BUBBLE ]; then
-      # Compare variable of both Synchronous files with printing difference
-      file1=$path_user/BUBBL.1.CEN4T.001.nc
-      file2=$path_ref/BUBBL.1.CEN4T.001.nc
-      if [ -f $file1 -a -f $file2 ]; then
-        echo "Compare with python..."
-        set +e
-        $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2
-        t=$?
-        set -e
-        allt=$(($allt+$t))
-        
-        #Check bit-repro before date of creation of Synchronous file from ncdump of all values (pb with direct .nc file checks)
-        echo "Compare with ncdump..."
-        set +e
+      #Files to compare
+      refname=${refnameByTest[$t]}
+      case1=$(echo $t | cut -d / -f 1)
+      case2=$(echo $t | cut -d / -f 2)
+      path_user=$MNHPACK/$name/MY_RUN/KTEST/$case1/$case2
+      path_ref=$MNHPACK/$refname/MY_RUN/KTEST/$case1/$case2
+      file3=""
+      file4=""
+      if [ $case1 == 007_16janvier ]; then
+        file1=$path_user/16JAN.1.12B18.001.nc 
+        file2=$path_ref/16JAN.1.12B18.001.nc
+        file3=$path_user/16JAN.1.12B18.000.nc 
+        file4=$path_ref/16JAN.1.12B18.000.nc
+        bit_diff=57100
+      elif [ $case1 == COLD_BUBBLE ]; then
+        file1=$path_user/BUBBL.1.CEN4T.001.nc
+        file2=$path_ref/BUBBL.1.CEN4T.001.nc
         bit_diff=27300
-        diff <(ncdump $file1 | head -c $bit_diff) <(ncdump $file2 | head -c $bit_diff)
-        t=$?
-        set -e
-        allt=$(($allt+$t))
-      else
-        [ ! -f $file1 ] && echo "  $file1 is missing"
-        [ ! -f $file2 ] && echo "  $file2 is missing"
-        allt=$(($allt+1))
-      fi
-    fi
-
-   if [ $case == OCEAN_LES ]; then
-        # Compare variable of both Synchronous files with printing difference
+      elif [ $case1 == OCEAN_LES ]; then
         file1=$path_user/SPWAN.2.25m00.001.nc
         file2=$path_ref/SPWAN.2.25m00.001.nc
-        if [ -f $file1 -a -f $file2 ]; then
-          echo "Compare with python..."
-          set +e
-          $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2
-          t=$?
-          set -e
-          allt=$(($allt+$t))
-  
-          #Check bit-repro before date of creation of Synchronous file from ncdump of all values (pb with direct .nc file checks)
-          echo "Compare with ncdump..."
-          set +e
-          bit_diff=18400
-          diff <(ncdump $file1 | head -c $bit_diff) <(ncdump $file2 | head -c $bit_diff)
-          t=$?
-          set -e
-          allt=$(($allt+$t))
-        else
-          [ ! -f $file1 ] && echo "  $file1 is missing"
-          [ ! -f $file2 ] && echo "  $file2 is missing"
-          allt=$(($allt+1))
-        fi
-      fi
-
-    if [ $case == COLD_BUBBLE_3D ]; then
-      # Compare variable of both Synchronous and Diachronic files with printing difference
-      file1=$path_user/BUBBL.1.CEN4T.001.nc
-      file2=$path_ref/BUBBL.1.CEN4T.001.nc
-      file3=$path_user/BUBBL.1.CEN4T.000.nc
-      file4=$path_ref/BUBBL.1.CEN4T.000.nc
-      if [ -f $file1 -a -f $file2 ]; then
-        echo "Compare with python..."
-        set +e
-        $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2 --f3 $file3 --f4 $file4
-        t=$?
-        set -e
-        allt=$(($allt+$t))
-
-        #Check bit-repro before date of creation of Synchronous file from ncdump of all values (pb with direct .nc file checks)
-        echo "Compare with ncdump..."
-        set +e
-        diff <(ncdump $file1 | head -c 27300) <(ncdump $file2 | head -c 27300)
-        t=$?
-        set -e
-        allt=$(($allt+$t))
+        bit_diff=18400
+      elif [ $case1 == COLD_BUBBLE_3D ]; then
+        file1=$path_user/BUBBL.1.CEN4T.001.nc
+        file2=$path_ref/BUBBL.1.CEN4T.001.nc
+        file3=$path_user/BUBBL.1.CEN4T.000.nc
+        file4=$path_ref/BUBBL.1.CEN4T.000.nc
+        bit_diff=27300
+      elif [ $case1 == ARMLES ]; then
+        file1=$path_user/ARM__.1.CEN4T.001.nc
+        file2=$path_ref/ARM__.1.CEN4T.001.nc
+        file3=$path_user/ARM__.1.CEN4T.000.nc
+        file4=$path_ref/ARM__.1.CEN4T.000.nc
+        bit_diff=76300
+      elif [ $case1 == 014_LIMA ]; then
+        file1=$path_user/XPREF.1.SEG01.002.nc
+        file2=$path_ref/XPREF.1.SEG01.002.nc
+        file3=$path_user/XPREF.1.SEG01.000.nc
+        file4=$path_ref/XPREF.1.SEG01.000.nc
+        bit_diff=32200
       else
-        [ ! -f $file1 ] && echo "  $file1 is missing"
-        [ ! -f $file2 ] && echo "  $file2 is missing"
-        allt=$(($allt+1))
+        echo "cas $t non reconnu"
       fi
-    fi
-
-    if [ $case == ARMLES ]; then
-      # Compare variable of both Synchronous and Diachronic files with printing difference
-      file1=$path_user/ARM__.1.CEN4T.001.nc
-      file2=$path_ref/ARM__.1.CEN4T.001.nc
-      file3=$path_user/ARM__.1.CEN4T.000.nc
-      file4=$path_ref/ARM__.1.CEN4T.000.nc
-      if [ -f $file1 -a -f $file2 ]; then
-        echo "Compare with python..."
-        set +e
-        $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2 --f3 $file3 --f4 $file4
-        t=$?
-        set -e
-        allt=$(($allt+$t))
 
-        #Check bit-repro before date of creation of Synchronous file from ncdump of all values (pb with direct .nc file checks)
-        echo "Compare with ncdump..."
-        set +e
-        bit_diff=76300
-        diff <(ncdump $file1 | head -c $bit_diff) <(ncdump $file2 | head -c $bit_diff)
-        t=$?
-        set -e
-        allt=$(($allt+$t))
-      else
-        [ ! -f $file1 ] && echo "  $file1 is missing"
-        [ ! -f $file2 ] && echo "  $file2 is missing"
-        allt=$(($allt+1))
+      if [ ! -d $path_user ]; then
+        echo "$path_user is missing, please run the simulation"
+        exit 7
+      fi
+      if [ ! -d $path_ref ]; then
+        echo "$path_ref is missing, please run the reference simulation"
+        exit 8
       fi
-    fi
 
-    if [ $case == 014_LIMA ]; then
-      # Compare variable of both Synchronous and Diachronic files with printing difference
-      file1=$path_user/XPREF.1.SEG01.002.nc
-      file2=$path_ref/XPREF.1.SEG01.002.nc
-      file3=$path_user/XPREF.1.SEG01.000.nc
-      file4=$path_ref/XPREF.1.SEG01.000.nc
+      #Comparison
       if [ -f $file1 -a -f $file2 ]; then
+        # Compare variable of both Synchronous and Diachronic files with printing difference
         echo "Compare with python..."
         set +e
-        $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2 --f3 $file3 --f4 $file4
-        t=$?
+        if [ "$file3" == "" ]; then
+          $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2
+          t=$?
+        else
+          $PHYEXTOOLSDIR/compare.py --f1 $file1 --f2 $file2 --f3 $file3 --f4 $file4
+          t=$?
+        fi
         set -e
         allt=$(($allt+$t))
 
-        #Check bit-repro before date of creation of Synchronous file from ncdump of all values (pb with direct .nc file checks)
+        #Check bit-repro before date of creation of Synchronous file from ncdump of all values
+        #(pb with direct .nc file checks)
         echo "Compare with ncdump..."
         set +e
-        bit_diff=32200
         diff <(ncdump $file1 | head -c $bit_diff) <(ncdump $file2 | head -c $bit_diff)
         t=$?
         set -e
@@ -559,6 +558,10 @@ if [ $check -eq 1 ]; then
   echo "...comparison done: $status"
 fi
 
+##################
+#### CLEANING ####
+##################
+
 if [ $remove -eq 1 ]; then
   echo "### Remove model directory for commit $commit"
   [ -d $MNHPACK/$name ] && rm -rf $MNHPACK/$name
diff --git a/tools/check_commit_testprogs.sh b/tools/check_commit_testprogs.sh
index 3314f89eccc4b2f75912b8982cd102c364ca19bb..67e71fa0888df29dc7823250d750673b73856e9d 100755
--- a/tools/check_commit_testprogs.sh
+++ b/tools/check_commit_testprogs.sh
@@ -28,13 +28,32 @@ set -o pipefail #abort if left command on a pipe fails
 # - The last commit of the testprogs_data2 branch (based on 48t3) is able to produce the data
 #   for the rain_ice_old testprog.
 
+#######################
+#### CONFIGURATION ####
+#######################
+
+#Special pack names:
+# - ref: symbolic name to the commit to use as a reference
+#        useless for the commits containing a json file
 specialName="ref"
-availTests="ice_adjust,rain_ice,rain_ice_old,turb,shallow"
-defaultTest='ALL'
+
+#About the tests:
+# - ALLTests is a list of tests to be done when '-t ALL' is used. This list is filled here
+#   in case there is no ial_version.json file containig a 'testing' section. If this 'testing'
+#   section exists, this list is overridden.
+# - allowedTests is the list of allowed tests which can depend on platform, if we ask to perform an action
+#   with a test not in the allowedTests list, the action is ignored
+# - defaultTest is the list of tests to perform when no '-t' option is provided on the command line.
+ALLTests="ice_adjust,rain_ice,rain_ice_old,turb,shallow"
+defaultTest=${ALLTests}
+allowedTests=${ALLTests}
+
 separator='_' #- seprator must be in sync with prep_code.sh separator
 
 PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
+TESTDIR=${TESTPROGSDIR:=$HOME/TESTPROGS}
+
 dirdata=$PHYEXTOOLSDIR/testprogs_data
 if [ $(hostname | cut -c 1-7) == 'belenos' -o $(hostname | cut -c 1-7) == 'taranis' ]; then
   HPC=1
@@ -45,26 +64,33 @@ else
 fi
 defaultRef=ref
 
+################################
+#### COMMAND LINE ARGUMENTS ####
+################################
+
 function usage {
-  echo "Usage: $0 [-h] [-c] [-r] [-C] [-s] [-f] [--noexpand] [-t test] [--repo-user user] [--repo-protocol protocol] [-a arch] [-A arch] [--remove] commit [reference]"
+  echo "Usage: $0 [-h] [-p] [-c] [-r] [-C] [-s] [--noexpand] [-t TEST] [--repo-user USER] [--repo-protocol PROTOCOL] [-a ARCH] [-A ARCH] [--remove] [--onlyIfNeeded] [--computeRefIfNeeded] commit [reference]"
   echo "commit          commit hash (or a directory, or among $specialName) to test"
   echo "reference       commit hash (or a directory, or among $specialName) REF to use as a reference"
   echo "-s              suppress compilation directory"
+  echo "-p              creates pack"
   echo "-c              performs compilation"
   echo "-r              runs the tests"
   echo "-C              checks the result against the reference"
-  echo "-t              comma separated list of tests to execute"
+  echo "-t TEST         comma separated list of tests to execute"
   echo "                or ALL to execute all tests"
   echo "--noexpand      do not use mnh_expand (code will be in array-syntax)"
-  echo "--repo-user     user hosting the PHYEX repository on github,"
+  echo "--repo-user USER"
+  echo "                user hosting the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
-  echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github,"
+  echo "--repo-protocol PROTOCOL"
+  echo "                protocol (https or ssh) to reach the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)"
   echo "--remove        removes the pack"
-  echo "-a arch         architecture name to use to build and run the commit (=$defaultarchfile)"
-  echo "-A arch         architecture name to use for the reference simulation (=$defaultarchfile)"
+  echo "-a arch ARCH    architecture name to use to build and run the commit (=$defaultarchfile)"
+  echo "-A arch ARCH    architecture name to use for the reference simulation (=$defaultarchfile)"
   echo ""
-  echo "If nothing is asked (compilation, running, check, removing) everything"
+  echo "If nothing is asked (pack creation compilation, running, check, removing) everything"
   echo "except the removing is done"
   echo
   echo "If no test is aked for, the default one ($defaultTest) is executed"
@@ -77,6 +103,7 @@ function usage {
   echo "The commit can be a tag, written with syntagx tags/<TAG>"
 }
 
+packcreation=0
 compilation=0
 run=0
 check=0
@@ -88,11 +115,14 @@ useexpand=""
 archfile=$defaultarchfile
 refarchfile=$defaultarchfile
 remove=0
+onlyIfNeeded=0
+computeRefIfNeeded=0
 
 while [ -n "$1" ]; do
   case "$1" in
     '-h') usage;;
     '-s') suppress=1;;
+    '-p') packcreation=1;;
     '-c') compilation=1;;
     '-r') run=$(($run+1));;
     '-C') check=1;;
@@ -103,6 +133,9 @@ while [ -n "$1" ]; do
     '--remove') remove=1;;
     '-a') archfile="$2"; shift;;
     '-A') refarchfile="$2"; shift;;
+    '--onlyIfNeeded') onlyIfNeeded=1;;
+    '--computeRefIfNeeded') computeRefIfNeeded=1;;
+
     #--) shift; break ;;
      *) if [ -z "${commit-}" ]; then
           commit=$1
@@ -118,31 +151,12 @@ while [ -n "$1" ]; do
   shift
 done
 
-TESTDIR=${TESTPROGSDIR:=$HOME/TESTPROGS}
-
-function exescript () {
-  #usage: exescript <output file> <script> [arg [arg ...]]
-  output=$1
-  shift
-  if [ $HPC -eq 1 ]; then
-    sbatch --wait -o $output $@
-    cat $output
-  else
-    $@ 2>&1 | tee $output
-  fi
-}
-
-if [ -z "${tests-}" ]; then
-  tests=$defaultTest
-fi
-if [ $tests == 'ALL' ]; then
-  tests=$availTests
-fi
-
-if [ $compilation -eq 0 -a \
+if [ $packcreation -eq 0 -a \
+     $compilation -eq 0 -a \
      $run -eq 0 -a \
      $check -eq 0 -a \
      $remove -eq 0 ]; then
+  packcreation=1
   compilation=1
   run=1
   check=1
@@ -158,115 +172,233 @@ if [ $check -eq 1 -a -z "${reference-}" ]; then
   exit 3
 fi
 
+##############################
+#### FUNCTION DEFINITIONS ####
+##############################
+
+function json_dictkey2value {
+  # $1 must contain the json string
+  # $2 must be the key name
+  # $3 is the default value
+  json_content="$1" python3 -c "import json; import os; result=json.loads(os.environ['json_content']).get('$2', '$3'); print(json.dumps(result) if isinstance(result, dict) else result)"
+}
+
+###########################
+#### COMMIT ADAPTATION ####
+###########################
+
+#Name and directory for compiling and executing user pack
+declare -A refByTest
 if echo $commit | grep '/' | grep -v '^tags/' > /dev/null; then
+  #The git repository is a directory
   name=$(echo $commit | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')
+  content_testprogs_version=$(scp $commit/src/testprogs/testprogs_version.json /dev/stdout 2>/dev/null || echo "")
   [ $suppress -eq 1 -a -d $TESTDIR/$name ] && rm -rf $TESTDIR/$name
 elif echo $specialName | grep -w $commit > /dev/null; then
   name="$commit"
 else
+  #The git repository is on github
+  if [[ $commit == testprogs${separator}* ]]; then
+    testprogs_version_file="testprogs_version.json"
+  else
+    testprogs_version_file="src/testprogs/testprogs_version.json"
+  fi
+  if echo $commit | grep '^tags/' > /dev/null; then
+    urlcommit=$(echo $commit | cut -d / -f 2-)
+  else
+    urlcommit=$commit
+  fi
+  content_testprogs_version=$(wget --no-check-certificate https://raw.githubusercontent.com/$PHYEXREPOuser/PHYEX/${urlcommit}/$testprogs_version_file -O - 2>/dev/null || echo "")
   name="COMMIT$(echo $commit | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')"
   [ $suppress -eq 1 -a -d $TESTDIR/$name ] && rm -rf $TESTDIR/$name
 fi
-if [ ! -z "${reference-}" ]; then
-  [ $reference == 'REF' ] && reference=$defaultRef
-  reffromdir=''
-  if echo $reference | grep '/' > /dev/null; then
-    reffromdir=$reference
-    refname=$(echo $reference | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')
-  elif echo $specialName | grep -w $reference > /dev/null; then
-    refname="$reference"
-  else
-    refname="COMMIT${reference}"
+if [ ! "${content_testprogs_version}" == "" ]; then
+  testing=$(json_dictkey2value "$content_testprogs_version" 'testing' '')
+  refALL=$(json_dictkey2value "$testing" "ALL" '')
+  if [ ! "$testing" == "" ]; then
+    ALLTests='' #We reset the list of tests
+    for t in $(echo $allowedTests | sed 's/,/ /g'); do
+      ref=$(json_dictkey2value "$testing" "$t" "$refALL")
+      if [ ! "$ref" == "" ]; then
+        ALLTests="${ALLTests},$t"
+        refByTest[$t]=$ref
+      fi
+    done
+    ALLTests="${ALLTests:1}" #Remove first character (',')
   fi
 fi
 
-if [ $compilation -eq 1 ]; then
-  echo "### Compilation of commit $commit"
+#Name and directory for the reference version
+if [ ! -z "${reference-}" ]; then
+  declare -A refnameByTest
+  #Reference to use for each test
+  for t in $(echo $ALLTests | sed 's/,/ /g'); do
+    #Name of the reference
+    if [ "$reference" == "REF" ]; then
+      if [[ ! -z "${refByTest[$t]+unset}" ]]; then #the -v test is valid only with bash > 4.3
+        #The json file contained the references to use on a per test case basis
+        caseref=${refByTest[$t]}
+      else
+        caseref=$defaultRef
+      fi
+      refByTest[$t]=$caseref
+    else
+      #The exact reference to use was given on the command line
+      caseref=$reference
+    fi
+    refByTest[$t]=$caseref
+  
+    #Conversion into directory name
+    if echo $caseref | grep '/' > /dev/null; then
+      refname=$(echo $reference | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')
+    elif echo $specialName | grep -w $caseref > /dev/null; then
+      refname="$caseref"
+    else
+      refname="COMMIT${caseref}"
+    fi
+    refnameByTest[$t]=$refname
+  done
+fi
 
-  if echo $specialName | grep -w $commit > /dev/null; then
-    echo "Special commit '$commit' cannot be compiled with this script"
-    exit 4
-  fi
+if [ -z "${tests-}" ]; then
+  tests=$defaultTest
+elif echo "$tests" | grep -w 'ALL' > /dev/null; then
+  tests=$(echo "$tests" | sed "s/\bALL\b/$ALLTests/g")
+fi
+
+#######################
+#### PACK CREATION ####
+#######################
 
+if [ $packcreation -eq 1 ]; then
   if [ -d $TESTDIR/$name ]; then
-    echo "Directory already exists ($TESTDIR/$name), suppress it to be able to compile it again (or use the -s option to automatically suppress it)"
-    exit 5
+    if [ $onlyIfNeeded -eq 0 ]; then
+      echo "Directory already exists ($TESTDIR/$name), suppress it to be able to compile it again (or use the -s option to automatically suppress it)"
+      exit 5
+    fi
+  else
+    echo "### Pack creation for commit $commit"
+
+    if echo $specialName | grep -w $commit > /dev/null; then
+      echo "Special commit '$commit' cannot be compiled with this script"
+      exit 4
+    fi
+
+    mkdir $TESTDIR/$name
+    cd $TESTDIR/$name/
+    cp -r $PHYEXTOOLSDIR/../build . #We use the compilation system from the same commit as the current script
+
+    MNH_EXPAND_DIR=$PHYEXTOOLSDIR/mnh_expand
+    export PATH=$PHYEXTOOLSDIR:$MNH_EXPAND_DIR/filepp:$MNH_EXPAND_DIR/MNH_Expand_Array:$PATH
+
+    cd $TESTDIR/$name/build/with_fcm/
+    rm -rf arch_*
+    ./make_fcm.sh -p $useexpand --commit $commit --arch $archfile 2>&1 | tee Output_compilation_step1
   fi
-  mkdir $TESTDIR/$name
-  cd $TESTDIR/$name/
-  cp -r $PHYEXTOOLSDIR/../build . #We use the compilation system from the same commit as the current script
+fi
 
-  MNH_EXPAND_DIR=$PHYEXTOOLSDIR/mnh_expand
-  export PATH=$PHYEXTOOLSDIR:$MNH_EXPAND_DIR/filepp:$MNH_EXPAND_DIR/MNH_Expand_Array:$PATH
+#####################
+#### COMPILATION ####
+#####################
+
+if [ $compilation -eq 1 ]; then
+  if [ $onlyIfNeeded -eq 0 -o ! -f $TESTDIR/$name/build/with_fcm/arch_${archfile}/build/bin/libphyex.so ]; then
+    echo "### Compilation of commit $commit"
 
-  cd $TESTDIR/$name/build/with_fcm/
-  rm -rf arch_*
-  ./make_fcm.sh $useexpand --commit $commit --arch $archfile 2>&1 | tee Output_compilation
+    cd $TESTDIR/$name/build/with_fcm/
+    ./make_fcm.sh -c $useexpand --commit $commit --arch $archfile 2>&1 | tee Output_compilation_step2
+  fi
 fi
 
-if [ $run -ge 1 ]; then
-  echo "### Running of commit $commit"
+###################
+#### EXECUTION ####
+###################
 
-  for t in $(echo $tests | sed 's/,/ /g'); do
-    if [ ! -f $TESTDIR/$name/build/with_fcm/arch_${archfile}/build/bin/main_${t}.exe ]; then
-      echo "Directory does not exist ($TESTDIR/$name) or compilation has failed, please check"
-      exit 6
-    fi
-  done
+if [ $run -ge 1 ]; then
+  cd $TESTDIR/$name
 
   #Cleaning to suppress old results that may be confusing in case of a crash during the run
-  for t in $(echo $tests | sed 's/,/ /g'); do
-    cd $TESTDIR/$name
-    if [ -d tests/with_fcm/arch_${archfile}/$t ]; then
-      rm -rf tests/with_fcm/arch_${archfile}/$t
-    fi
-  done
+  if [ $onlyIfNeeded -eq 0 ]; then
+    for t in $(echo $tests | sed 's/,/ /g'); do
+      if [ -d tests/with_fcm/arch_${archfile}/$t ]; then
+        rm -rf tests/with_fcm/arch_${archfile}/$t
+      fi
+    done
+  fi
 
   #Run the tests one after the other
+  firstrun=1
   for t in $(echo $tests | sed 's/,/ /g'); do
-    cd $TESTDIR/$name
-    mkdir -p tests/with_fcm/arch_${archfile}/$t
-    cd tests/with_fcm/arch_${archfile}/$t
-    ln -s $dirdata/$t data
-    $TESTDIR/$name/build/with_fcm/arch_${archfile}/build/bin/main_${t}.exe --check 2>&1 > Output_run
+    if echo $allowedTests | grep -w $t > /dev/null; then #test is allowed on this plateform
+      if  [ ! -d tests/with_fcm/arch_${archfile}/$t ]; then #We do not enter systematically this part if onlyIfNeeded=1
+        if [ $firstrun -eq 1 ]; then
+          echo "### Running of commit $commit"
+          firstrun=0
+        fi
+
+        if [ ! -f $TESTDIR/$name/build/with_fcm/arch_${archfile}/build/bin/main_${t}.exe ]; then
+          echo "Directory does not exist ($TESTDIR/$name) or compilation has failed, please check"
+          exit 6
+        fi
+
+        #execution
+        cd $TESTDIR/$name
+        mkdir -p tests/with_fcm/arch_${archfile}/$t
+        cd tests/with_fcm/arch_${archfile}/$t
+        ln -s $dirdata/$t data
+        $TESTDIR/$name/build/with_fcm/arch_${archfile}/build/bin/main_${t}.exe --check 2>&1 > Output_run
+      fi
+    fi
   done
 fi
 
+####################
+#### COMPARISON ####
+####################
+
 if [ $check -eq 1 ]; then
   echo "### Check commit $commit against commit $reference"
 
   alltests=0
   message=""
   for t in $(echo $tests | sed 's/,/ /g'); do
-    file1=$TESTDIR/$name/tests/with_fcm/arch_${archfile}/$t/Output_run
-    file2=$TESTDIR/$refname/tests/with_fcm/arch_${refarchfile}/$t/Output_run
-    mess=""
-    te=0
-    if [ ! -f "$file1" ]; then
-      mess="Result ($file1) for commit $commit does not exist, please run the simulation"
-      te=1
-    fi
-    if [ ! -f "$file2" ]; then
-      mess2="Result ($file2) for commit $reference does not exist, please run the simulation"
-      te=1
-      if [ "$mess" = "" ]; then
-        mess=$mess2
-      else
-        mess="$mess and $mess2"
+    if echo $allowedTests | grep -w $t > /dev/null; then
+      #Run the reference if needed
+      if [ $computeRefIfNeeded -eq 1 ]; then
+        $0 -p -c -r -t $t -a ${archfile} --onlyIfNeeded ${refByTest[$t]}
       fi
+
+      #File comparison
+      file1=$TESTDIR/$name/tests/with_fcm/arch_${archfile}/$t/Output_run
+      file2=$TESTDIR/${refnameByTest[$t]}/tests/with_fcm/arch_${refarchfile}/$t/Output_run
+      mess=""
+      te=0
+      if [ ! -f "$file1" ]; then
+        mess="Result ($file1) for commit $commit does not exist, please run the simulation"
+        te=1
+      fi
+      if [ ! -f "$file2" ]; then
+        mess2="Result ($file2) for commit ${refByTest[$t]} does not exist, please run the simulation"
+        te=1
+        if [ "$mess" = "" ]; then
+          mess=$mess2
+        else
+          mess="$mess and $mess2"
+        fi
+      fi
+      if [ $te -eq 0 ]; then
+        set +e
+        mess=$(cmp <(cat $file1 | sed 's/\.\.//g' | sed 's/~=//g' | sed 's/!=//g' | grep -v 'Total time: ' | sed 's/-0.00000E+00|/ 0.00000E+00|/g' | sed 's/-0.00000E+00 / 0.00000E+00 /g' | sed 's/-0.00000E+00-/ 0.00000E+00-/g') \
+                   <(cat $file2 | sed 's/\.\.//g' | sed 's/~=//g' | sed 's/!=//g' | grep -v 'Total time: ' | sed 's/-0.00000E+00|/ 0.00000E+00|/g' | sed 's/-0.00000E+00 / 0.00000E+00 /g' | sed 's/-0.00000E+00-/ 0.00000E+00-/g') 246 246 2>&1)
+        te=$?
+        set -e
+        #The use of "<()" bash syntax replaces the actual file name seen by cmp
+        #We modify the cmp output to display the actual file names
+        mess=$(echo $mess | sed "s#^.*differ# $file1 $file2 differ#")
+      fi
+      [ $te -ne 0 ] && message="$message $mess \n"
+      alltests=$(($alltests+$te))
     fi
-    if [ $te -eq 0 ]; then
-      set +e
-      mess=$(cmp <(cat $file1 | sed 's/\.\.//g' | sed 's/~=//g' | sed 's/!=//g' | grep -v 'Total time: ' | sed 's/-0.00000E+00|/ 0.00000E+00|/g' | sed 's/-0.00000E+00 / 0.00000E+00 /g' | sed 's/-0.00000E+00-/ 0.00000E+00-/g') \
-                 <(cat $file2 | sed 's/\.\.//g' | sed 's/~=//g' | sed 's/!=//g' | grep -v 'Total time: ' | sed 's/-0.00000E+00|/ 0.00000E+00|/g' | sed 's/-0.00000E+00 / 0.00000E+00 /g' | sed 's/-0.00000E+00-/ 0.00000E+00-/g') 246 246 2>&1)
-      te=$?
-      set -e
-      #The use of "<()" bash syntax replaces the actual file name seen by cmp
-      #We modify the cmp output to display the actual file names
-      mess=$(echo $mess | sed "s#^.*differ# $file1 $file2 differ#")
-    fi
-    [ $te -ne 0 ] && message="$message $mess \n"
-    alltests=$(($alltests+$te))
   done
   if [ $alltests -eq 0 ]; then
     echo "SUCCESS, files are identical"
@@ -277,6 +409,10 @@ if [ $check -eq 1 ]; then
   fi
 fi
 
+##################
+#### CLEANING ####
+##################
+
 if [ $remove -eq 1 ]; then
   echo "### Remove model directory for commit $commit"
   [ -d $TESTDIR/$name ] && rm -rf $TESTDIR/$name
diff --git a/tools/testing.sh b/tools/testing.sh
index a413671d62cd507f127df9e078b8e92477a2c816..aec67ad892c6da243ea3ffe4599c721c99b0beb6 100755
--- a/tools/testing.sh
+++ b/tools/testing.sh
@@ -299,9 +299,9 @@ if [ ${force} -eq 1 -o $(get_statuses "${SHA}" | grep "${context}" | wc -l) -eq
       jsonfile="src/${model}/${model}_version.json"
       docmp=0
     else
-      compilation='-c'
+      compilation='-p -c'
       execution='-r'
-      comparison='-C'
+      comparison='-C --computeRefIfNeeded'
       jsonfile="src/${model}/${model}_version.json"
       docmp=1
     fi