From 1bfac7c1e9e2540b6655f11e6e0174a8fe8e8bc5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Riette?= <sebastien.riette@meteo.fr>
Date: Wed, 15 Nov 2023 14:06:56 +0100
Subject: [PATCH] S. Riette 15 Nov 2023: change filepp for pyft_tool

---
 build/with_fcm/make_fcm.sh                    |   9 +-
 docs/Tools.md                                 |   3 -
 src/common/micro/mode_ice4_compute_pdf.F90    |  58 ++--
 src/common/turb/mode_compute_updraft_raha.F90 |   2 +-
 src/common/turb/mode_emoist.F90               |  36 +--
 src/common/turb/mode_etheta.F90               |  26 +-
 src/common/turb/mode_rmc01.F90                |  34 +--
 src/common/turb/mode_turb_ver_thermo_flux.F90 |  26 +-
 src/common/turb/turb.F90                      | 278 +++++++++---------
 tools/.gitignore                              |   6 +-
 tools/INSTALL.md                              |  12 +-
 tools/INSTALL.sh                              |  48 ++-
 tools/INSTALL_mnh_expand.md                   |  34 ---
 tools/PHYEX2IAL.sh                            |   2 +-
 tools/check_commit_ial.sh                     |   7 +-
 tools/check_commit_lmdz.sh                    |   6 +-
 tools/check_commit_mesonh.sh                  |   7 +-
 tools/check_commit_testprogs.sh               |   5 +-
 tools/correct_indent.py                       | 179 -----------
 tools/env.sh                                  |   6 +-
 tools/prep_code.sh                            |  47 ++-
 tools/{mnh_expand => site}/.gitkeep           |   0
 tools/testing.sh                              |  14 +-
 tools/verify_mnh_expand.py                    | 153 ----------
 24 files changed, 316 insertions(+), 682 deletions(-)
 delete mode 100644 tools/INSTALL_mnh_expand.md
 delete mode 100755 tools/correct_indent.py
 rename tools/{mnh_expand => site}/.gitkeep (100%)
 delete mode 100755 tools/verify_mnh_expand.py

diff --git a/build/with_fcm/make_fcm.sh b/build/with_fcm/make_fcm.sh
index f89e38d49..94cb82b33 100755
--- a/build/with_fcm/make_fcm.sh
+++ b/build/with_fcm/make_fcm.sh
@@ -258,12 +258,15 @@ chmod +x compilation.sh
 
 ####################################
 
+# Where we are
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
 # Parse command line arguments
 parse_args $*
 
 if [ $packcreation -eq 1 ]; then
   # Change current working dir
-  cd -P $(dirname $0)
+  cd -P $DIR
   
   # Check the fcm installation
   check_install_fcm
@@ -303,7 +306,7 @@ if [ $packcreation -eq 1 ]; then
   fi
   #Expand options
   if [ $useexpand == 1 ]; then
-    expand_options="-D MNH_EXPAND -D MNH_EXPAND_LOOP"
+    expand_options="--mnhExpand"
   else
     expand_options=""
   fi
@@ -337,7 +340,7 @@ fi
 
 # Build the compilation script and run it
 if [ $compilation -eq 1 ]; then
-  cd -P $(dirname $0)/arch_$ARCH
+  cd -P $DIR/arch_$ARCH
   build_compilation_script src
   ./compilation.sh
   ln -s build/bin/libphyex.so .
diff --git a/docs/Tools.md b/docs/Tools.md
index aef6814ae..a0c4312dd 100644
--- a/docs/Tools.md
+++ b/docs/Tools.md
@@ -59,7 +59,6 @@ script with the 'REF' argument), the reference simulation directory (under $TEST
 ### prep\_code.sh
 
 This script is used by the different check\_commit\_\* scripts and can be used directly to pre-process the source code.
- The installation is described in the [tools/INSTALL\_mnh\_expand.md file](../tools/INSTALL_mnh_expand.md)
 
 ### testing.sh
 
@@ -73,7 +72,5 @@ Other scripts are:
 
   - comp\_DDH.py: compare DDH outputs (used by check\_commit\_ial.sh)
   - compare.py: compare MESO-NH outputs (used by check\_commit\_mesonh.sh)
-  - correct\_indent.py: correct source code indentation in mnh\_expand blocs
   - diffNODE.001\_01: compare NODE.0001\_01 output files
-  - verify\_mnh\_expand.py: check syntax in mnh\_expand blocs
   - generate\_standalone\_doc.sh: to generate a standalone doc from the different md files
diff --git a/src/common/micro/mode_ice4_compute_pdf.F90 b/src/common/micro/mode_ice4_compute_pdf.F90
index b284ced68..fce6431f5 100644
--- a/src/common/micro/mode_ice4_compute_pdf.F90
+++ b/src/common/micro/mode_ice4_compute_pdf.F90
@@ -93,7 +93,7 @@ END WHERE
 !$mnh_end_expand_where(JL=1:KSIZE)
 IF(HSUBG_AUCV_RC=='NONE') THEN
   !Cloud water is entirely in low or high part
- !$mnh_expand_where(JL=1:KSIZE)
+  !$mnh_expand_where(JL=1:KSIZE)
   WHERE(PRCT(:)>ZRCRAUTC(:) .AND. LDMICRO(:))
     PHLC_HCF(:)=1.
     PHLC_LCF(:)=0.
@@ -110,11 +110,11 @@ IF(HSUBG_AUCV_RC=='NONE') THEN
     PHLC_HRC(:)=0.
     PHLC_LRC(:)=0.
   END WHERE
- !$mnh_end_expand_where(JL=1:KSIZE)
+  !$mnh_end_expand_where(JL=1:KSIZE)
 
 ELSEIF(HSUBG_AUCV_RC=='CLFR') THEN
   !Cloud water is only in the cloudy part and entirely in low or high part
- !$mnh_expand_where(JL=1:KSIZE)
+  !$mnh_expand_where(JL=1:KSIZE)
   WHERE(PCF(:)>0. .AND. PRCT(:)>ZRCRAUTC(:)*PCF(:) .AND. LDMICRO(:))
     PHLC_HCF(:)=PCF(:)
     PHLC_LCF(:)=0.
@@ -131,16 +131,16 @@ ELSEIF(HSUBG_AUCV_RC=='CLFR') THEN
     PHLC_HRC(:)=0.
     PHLC_LRC(:)=0.
   END WHERE
- !$mnh_end_expand_where(JL=1:KSIZE)
+  !$mnh_end_expand_where(JL=1:KSIZE)
 ELSEIF(HSUBG_AUCV_RC=='ADJU') THEN
- !$mnh_expand_where(JL=1:KSIZE)
+  !$mnh_expand_where(JL=1:KSIZE)
   WHERE(LDMICRO(:))
     ZSUMRC(:)=PHLC_LRC(:)+PHLC_HRC(:)
   ELSEWHERE
     ZSUMRC(:)=0.
   ENDWHERE
- !$mnh_end_expand_where(JL=1:KSIZE)
- !$mnh_expand_where(JL=1:KSIZE)
+  !$mnh_end_expand_where(JL=1:KSIZE)
+  !$mnh_expand_where(JL=1:KSIZE)
   WHERE(ZSUMRC(:) .GT. 0. .AND. LDMICRO(:))
     PHLC_LRC(:)=PHLC_LRC(:)*PRCT(:)/ZSUMRC(:)
     PHLC_HRC(:)=PHLC_HRC(:)*PRCT(:)/ZSUMRC(:)
@@ -148,7 +148,7 @@ ELSEIF(HSUBG_AUCV_RC=='ADJU') THEN
     PHLC_LRC(:)=0.
     PHLC_HRC(:)=0.
   ENDWHERE
- !$mnh_end_expand_where(JL=1:KSIZE)
+  !$mnh_end_expand_where(JL=1:KSIZE)
 ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
   !Cloud water is split between high and low part according to a PDF
   !    'HLCRECTPDF'    : rectangular PDF form
@@ -158,7 +158,7 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
   !    'SIGM'          : Redelsperger and Sommeria (1986)
   IF(HSUBG_PR_PDF=='SIGM') THEN
     ! Redelsperger and Sommeria (1986) but organised according to Turner (2011, 2012)
-   !$mnh_expand_where(JL=1:KSIZE)
+    !$mnh_expand_where(JL=1:KSIZE)
     WHERE (PRCT(:)>ZRCRAUTC(:)+PSIGMA_RC(:) .AND. LDMICRO(:))
       PHLC_HCF(:)=1.
       PHLC_LCF(:)=0.
@@ -183,7 +183,7 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
       PHLC_HRC(:)=0.
       PHLC_LRC(:)=0.
     END WHERE
-   !$mnh_end_expand_where(JL=1:KSIZE)
+    !$mnh_end_expand_where(JL=1:KSIZE)
   ELSEIF(HSUBG_PR_PDF=='HLCRECTPDF' .OR. HSUBG_PR_PDF=='HLCISOTRIPDF' .OR. &
          &HSUBG_PR_PDF=='HLCTRIANGPDF' .OR. HSUBG_PR_PDF=='HLCQUADRAPDF') THEN
     ! Turner (2011, 2012)
@@ -195,18 +195,18 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
     ELSE IF(HSUBG_PR_PDF=='HLCQUADRAPDF') THEN
       ZCOEFFRCM=4.
     END IF
-   !$mnh_expand_where(JL=1:KSIZE)
+    !$mnh_expand_where(JL=1:KSIZE)
     WHERE(PRCT(:).GT.0. .AND. PCF(:).GT.0. .AND. LDMICRO(:))
       ZHLC_RCMAX(:)=ZCOEFFRCM*PRCT(:)/PCF(:)
     ELSEWHERE
       ZHLC_RCMAX(:)=0.
     END WHERE
-   !$mnh_end_expand_where(JL=1:KSIZE)
+    !$mnh_end_expand_where(JL=1:KSIZE)
 
     ! Split available water and cloud fraction in two parts
     ! Calculate local mean values int he low and high parts for the 3 PDF forms:
     IF(HSUBG_PR_PDF=='HLCRECTPDF') THEN
-   !$mnh_expand_where(JL=1:KSIZE)
+      !$mnh_expand_where(JL=1:KSIZE)
       WHERE(PRCT(:).GT.0. .AND. PCF(:).GT.0. .AND. ZHLC_RCMAX(:).GT.ZRCRAUTC(:) .AND. LDMICRO(:))
         ZHLC_LRCLOCAL(:)=0.5*ZRCRAUTC(:)
         ZHLC_HRCLOCAL(:)=( ZHLC_RCMAX(:) + ZRCRAUTC(:))/2.0
@@ -214,9 +214,9 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
         ZHLC_LRCLOCAL(:)=0.
         ZHLC_HRCLOCAL(:)=0.
       END WHERE
-   !$mnh_end_expand_where(JL=1:KSIZE)
+      !$mnh_end_expand_where(JL=1:KSIZE)
     ELSE IF(HSUBG_PR_PDF=='HLCTRIANGPDF') THEN
-   !$mnh_expand_where(JL=1:KSIZE)
+      !$mnh_expand_where(JL=1:KSIZE)
       WHERE(PRCT(:).GT.0. .AND. PCF(:).GT.0. .AND. ZHLC_RCMAX(:).GT.ZRCRAUTC(:) .AND. LDMICRO(:))
         ZHLC_LRCLOCAL(:)=( ZRCRAUTC(:) *(3.0 * ZHLC_RCMAX(:) - 2.0 * ZRCRAUTC(:) ) ) &
                         / (3.0 * (2.0 * ZHLC_RCMAX(:) - ZRCRAUTC(:)  ) )
@@ -225,9 +225,9 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
         ZHLC_LRCLOCAL(:)=0.
         ZHLC_HRCLOCAL(:)=0.
       END WHERE
-   !$mnh_end_expand_where(JL=1:KSIZE)
+      !$mnh_end_expand_where(JL=1:KSIZE)
     ELSE IF(HSUBG_PR_PDF=='HLCQUADRAPDF') THEN
-   !$mnh_expand_where(JL=1:KSIZE)
+      !$mnh_expand_where(JL=1:KSIZE)
       WHERE(PRCT(:).GT.0. .AND. PCF(:).GT.0. .AND. ZHLC_RCMAX(:).GT.ZRCRAUTC(:) .AND. LDMICRO(:))
         ZHLC_LRCLOCAL(:)=(3.0 *ZRCRAUTC(:)**3 - 8.0 *ZRCRAUTC(:)**2 * ZHLC_RCMAX(:) &
                         + 6.0*ZRCRAUTC(:) *ZHLC_RCMAX(:)**2 ) &
@@ -239,10 +239,10 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
         ZHLC_LRCLOCAL(:)=0.
         ZHLC_HRCLOCAL(:)=0.
       END WHERE
-   !$mnh_end_expand_where(JL=1:KSIZE)
+      !$mnh_end_expand_where(JL=1:KSIZE)
     ELSE IF(HSUBG_PR_PDF=='HLCISOTRIPDF') THEN
-   !$mnh_expand_where(JL=1:KSIZE)
-    WHERE (PRCT(:).LE.ZRCRAUTC(:)*PCF(:) .AND. &
+      !$mnh_expand_where(JL=1:KSIZE)
+      WHERE (PRCT(:).LE.ZRCRAUTC(:)*PCF(:) .AND. &
             &PRCT(:).GT.0. .AND. PCF(:).GT.0. .AND. &
             &ZHLC_RCMAX(:).GT.ZRCRAUTC(:) .AND. LDMICRO(:))
         ZHLC_LRCLOCAL(:)=( (ZHLC_RCMAX(:))**3 &
@@ -260,10 +260,10 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
         ZHLC_LRCLOCAL(:)=0.
         ZHLC_HRCLOCAL(:)=0.
       END WHERE
-    !$mnh_end_expand_where(JL=1:KSIZE)
+      !$mnh_end_expand_where(JL=1:KSIZE)
     END IF
     ! Compare r_cM  to r_cR to know if cloud water content is high enough to split in two parts or not
-   !$mnh_expand_where(JL=1:KSIZE)
+    !$mnh_expand_where(JL=1:KSIZE)
     WHERE (PRCT(:).GT.0. .AND. PCF(:).GT.0. .AND. ZHLC_RCMAX(:).GT.ZRCRAUTC(:) .AND. LDMICRO(:))
       ! Calculate final values for LCF and HCF:
       PHLC_LCF(:)=PCF(:) &
@@ -287,7 +287,7 @@ ELSEIF(HSUBG_AUCV_RC=='PDF ') THEN
       PHLC_LRC(:)=0.
       PHLC_HRC(:)=0.
     END WHERE
-   !$mnh_end_expand_where(JL=1:KSIZE)
+    !$mnh_end_expand_where(JL=1:KSIZE)
   ELSE
     CALL PRINT_MSG(NVERB_FATAL,'GEN','ICE4_COMPUTE_PDF','wrong HSUBG_PR_PDF case')
   ENDIF
@@ -305,7 +305,7 @@ ENDWHERE
 !$mnh_end_expand_where(JL=1:KSIZE)
 IF(HSUBG_AUCV_RI=='NONE') THEN
   !Cloud water is entirely in low or high part
-!$mnh_expand_where(JL=1:KSIZE)
+  !$mnh_expand_where(JL=1:KSIZE)
   WHERE(PRIT(:)>ZCRIAUTI(:) .AND. LDMICRO(:))
     PHLI_HCF(:)=1.
     PHLI_LCF(:)=0.
@@ -322,10 +322,10 @@ IF(HSUBG_AUCV_RI=='NONE') THEN
     PHLI_HRI(:)=0.
     PHLI_LRI(:)=0.
   END WHERE
- !$mnh_end_expand_where(JL=1:KSIZE)
+  !$mnh_end_expand_where(JL=1:KSIZE)
 ELSEIF(HSUBG_AUCV_RI=='CLFR') THEN
   !Cloud water is only in the cloudy part and entirely in low or high part
- !$mnh_expand_where(JL=1:KSIZE)
+  !$mnh_expand_where(JL=1:KSIZE)
   WHERE(PCF(:)>0. .AND. PRIT(:)>ZCRIAUTI(:)*PCF(:) .AND. LDMICRO(:))
     PHLI_HCF(:)=PCF(:)
     PHLI_LCF(:)=0.
@@ -342,9 +342,9 @@ ELSEIF(HSUBG_AUCV_RI=='CLFR') THEN
     PHLI_HRI(:)=0.
     PHLI_LRI(:)=0.
   END WHERE
- !$mnh_end_expand_where(JL=1:KSIZE)
+  !$mnh_end_expand_where(JL=1:KSIZE)
 ELSEIF(HSUBG_AUCV_RI=='ADJU') THEN
- !$mnh_expand_where(JL=1:KSIZE)
+  !$mnh_expand_where(JL=1:KSIZE)
   WHERE(LDMICRO(:))
     ZSUMRI(:)=PHLI_LRI(:)+PHLI_HRI(:)
   ELSEWHERE
@@ -357,7 +357,7 @@ ELSEIF(HSUBG_AUCV_RI=='ADJU') THEN
     PHLI_LRI(:)=0.
     PHLI_HRI(:)=0.
   ENDWHERE
- !$mnh_end_expand_where(JL=1:KSIZE)
+  !$mnh_end_expand_where(JL=1:KSIZE)
 ELSE
   !wrong HSUBG_AUCV_RI case
   CALL PRINT_MSG( NVERB_FATAL, 'GEN', 'ICE4_COMPUTE_PDF', 'wrong HSUBG_AUCV_RI case' )
diff --git a/src/common/turb/mode_compute_updraft_raha.F90 b/src/common/turb/mode_compute_updraft_raha.F90
index a92c40616..3cb1077c4 100644
--- a/src/common/turb/mode_compute_updraft_raha.F90
+++ b/src/common/turb/mode_compute_updraft_raha.F90
@@ -592,7 +592,7 @@ DO JK=IKB+IKL,IKE-IKL,IKL !  Vertical loop
       PEMF(JIJ,JK+IKL)=PEMF(JIJ,JK)*EXP(ZMIX1(JIJ))
     END IF
 
-! Updraft fraction must be smaller than XFRAC_UP_MAX
+    ! Updraft fraction must be smaller than XFRAC_UP_MAX
     PFRAC_UP(JIJ,JK+IKL)=PEMF(JIJ,JK+IKL)/&
                                     &(SQRT(ZW_UP2(JIJ,JK+IKL))*ZRHO_F(JIJ,JK+IKL))
     PFRAC_UP(JIJ,JK+IKL)=MIN(PARAMMF%XFRAC_UP_MAX,PFRAC_UP(JIJ,JK+IKL))
diff --git a/src/common/turb/mode_emoist.F90 b/src/common/turb/mode_emoist.F90
index ec88edc65..6b0881f43 100644
--- a/src/common/turb/mode_emoist.F90
+++ b/src/common/turb/mode_emoist.F90
@@ -106,17 +106,17 @@ IKT=D%NKT
 !
 IF (OOCEAN) THEN
  IF ( KRR == 0 ) THEN                                ! Unsalted
-  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
    PEMOIST(IIJB:IIJE,:) = 0.
-  !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
  ELSE
    !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
    PEMOIST(IIJB:IIJE,:) = 1.                              ! Salted case
    !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
  END IF
-!
+ !
 ELSE
-!
+ !
  IF ( KRR == 0 ) THEN                                ! dry case
    PEMOIST(IIJB:IIJE,:) = 0.
  ELSE IF ( KRR == 1 ) THEN                           ! only vapor
@@ -127,7 +127,7 @@ ELSE
  ELSE                                                ! liquid water & ice present
   ZDELTA = (CST%XRV/CST%XRD) - 1.
   ZRW(IIJB:IIJE,:) = PRM(IIJB:IIJE,:,1)
-!
+  !
   IF ( KRRI>0) THEN  ! rc and ri case
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZRW(IIJB:IIJE,:) = ZRW(IIJB:IIJE,:) + PRM(IIJB:IIJE,:,3)
@@ -142,12 +142,12 @@ ELSE
               (1.+ZDELTA) * (PRM(IIJB:IIJE,:,1) - PRM(IIJB:IIJE,:,2) - PRM(IIJB:IIJE,:,4)) &
               -ZRW(IIJB:IIJE,:)                                                &
                      )  /  (1. + ZRW(IIJB:IIJE,:)) 
-  !
-  !   Emoist = ZB + ZC * Amoist
-  !   ZB is computed from line 1 to line 2
-  !   ZC is computed from line 3 to line 5
-  !   Amoist* 2 * SRC is computed at line 6
-  !
+    !
+    !   Emoist = ZB + ZC * Amoist
+    !   ZB is computed from line 1 to line 2
+    !   ZC is computed from line 3 to line 5
+    !   Amoist* 2 * SRC is computed at line 6
+    !
     PEMOIST(IIJB:IIJE,:) = ZDELTA * (PTHLM(IIJB:IIJE,:) + PLOCPEXNM(IIJB:IIJE,:)*(           &
                                                     PRM(IIJB:IIJE,:,2)+PRM(IIJB:IIJE,:,4)))&
                             / (1. + ZRW(IIJB:IIJE,:))                                &
@@ -168,12 +168,12 @@ ELSE
               (1.+ZDELTA) * (PRM(IIJB:IIJE,:,1) - PRM(IIJB:IIJE,:,2)) &
               -ZRW(IIJB:IIJE,:)                                 &
                      )  /  (1. + ZRW(IIJB:IIJE,:)) 
-  !
-  !   Emoist = ZB + ZC * Amoist
-  !   ZB is computed from line 1 to line 2
-  !   ZC is computed from line 3 to line 5
-  !   Amoist* 2 * SRC is computed at line 6
-  !
+    !
+    !   Emoist = ZB + ZC * Amoist
+    !   ZB is computed from line 1 to line 2
+    !   ZC is computed from line 3 to line 5
+    !   Amoist* 2 * SRC is computed at line 6
+    !
     PEMOIST(IIJB:IIJE,:) = ZDELTA * (PTHLM(IIJB:IIJE,:) + PLOCPEXNM(IIJB:IIJE,:)* &
                                        PRM(IIJB:IIJE,:,2)) / (1. + ZRW(IIJB:IIJE,:))          &
         +( PLOCPEXNM(IIJB:IIJE,:) * ZA(IIJB:IIJE,:)                                        &
@@ -183,7 +183,7 @@ ELSE
     !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   END IF
  END IF
-!
+ !
 END IF
 !---------------------------------------------------------------------------
 !
diff --git a/src/common/turb/mode_etheta.F90 b/src/common/turb/mode_etheta.F90
index fd8e1b69f..d50da8b78 100644
--- a/src/common/turb/mode_etheta.F90
+++ b/src/common/turb/mode_etheta.F90
@@ -114,9 +114,9 @@ IF (OOCEAN) THEN                                    ! ocean case
   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 ELSE   
  IF ( KRR == 0) THEN                                ! dry case
- !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   PETHETA(IIJB:IIJE,:) = 1.
- !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
  ELSE IF ( KRR == 1 ) THEN                           ! only vapor
   ZDELTA = (CST%XRV/CST%XRD) - 1.
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
@@ -127,7 +127,7 @@ ELSE
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZRW(IIJB:IIJE,:) = PRM(IIJB:IIJE,:,1)
   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
-!
+  !
   IF ( KRRI>0 ) THEN  ! rc and ri case
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZRW(IIJB:IIJE,:) = ZRW(IIJB:IIJE,:) + PRM(IIJB:IIJE,:,3)
@@ -142,11 +142,11 @@ ELSE
               (1.+ZDELTA) * (PRM(IIJB:IIJE,:,1) - PRM(IIJB:IIJE,:,2) - PRM(IIJB:IIJE,:,4)) &
               -ZRW(IIJB:IIJE,:)                                                &
                      )  /  (1. + ZRW(IIJB:IIJE,:))
-  !
-  !   Etheta = ZA + ZC * Atheta  
-  !   ZC is computed from line 2 to line 5
-  !   - Atheta * 2. * SRC is computed at line 6 
-  !
+    !
+    !   Etheta = ZA + ZC * Atheta  
+    !   ZC is computed from line 2 to line 5
+    !   - Atheta * 2. * SRC is computed at line 6 
+    !
     PETHETA(IIJB:IIJE,:) = ZA(IIJB:IIJE,:)                                                 &
         +( PLOCPEXNM(IIJB:IIJE,:) * ZA(IIJB:IIJE,:)                                        &
                -(1.+ZDELTA) * (PTHLM(IIJB:IIJE,:) + PLOCPEXNM(IIJB:IIJE,:)*(               &
@@ -165,11 +165,11 @@ ELSE
               (1.+ZDELTA) * (PRM(IIJB:IIJE,:,1) - PRM(IIJB:IIJE,:,2)) &
               -ZRW(IIJB:IIJE,:)                                 &
                      )  /  (1. + ZRW(IIJB:IIJE,:))
-  !
-  !   Etheta = ZA + ZC * Atheta  
-  !   ZC is computed from line 2 to line 5
-  !   - Atheta * 2. * SRC is computed at line 6 
-  !
+    !
+    !   Etheta = ZA + ZC * Atheta  
+    !   ZC is computed from line 2 to line 5
+    !   - Atheta * 2. * SRC is computed at line 6 
+    !
     PETHETA(IIJB:IIJE,:) = ZA(IIJB:IIJE,:)                                                 &
         +( PLOCPEXNM(IIJB:IIJE,:) * ZA(IIJB:IIJE,:) -(1.+ZDELTA) * (PTHLM(IIJB:IIJE,:) &
         + PLOCPEXNM(IIJB:IIJE,:)*PRM(IIJB:IIJE,:,2))   &
diff --git a/src/common/turb/mode_rmc01.F90 b/src/common/turb/mode_rmc01.F90
index 73922adce..f28382352 100644
--- a/src/common/turb/mode_rmc01.F90
+++ b/src/common/turb/mode_rmc01.F90
@@ -185,9 +185,9 @@ SELECT CASE (TURBN%CTURBLEN)
       !$mnh_end_expand_array(JIJ=IIJB:IIJE)
     END DO
     !
-!*     4. factor controling the transition between SBL and free isotropic turb. (3D case)
-!         --------------------------------------------------------------------
-!
+    !*     4. factor controling the transition between SBL and free isotropic turb. (3D case)
+    !         --------------------------------------------------------------------
+    !
     ZGAM(IIJB:IIJE,IKA) = 0.
     DO JK=IKTB,IKTE
       !$mnh_expand_array(JIJ=IIJB:IIJE)
@@ -208,15 +208,15 @@ SELECT CASE (TURBN%CTURBLEN)
       ZGAM(IIJB:IIJE,IKU) = 1.
     END WHERE
     !$mnh_end_expand_where(JIJ=IIJB:IIJE)
-!   
-!
-!-------------------------------------------------------------------------------
-!
-!*     5. factor controling the transition between SBL and free isotropic turb.(1D case)
-!         --------------------------------------------------------------------
-!
+  !   
+  !
+  !-------------------------------------------------------------------------------
+  !
+  !*     5. factor controling the transition between SBL and free isotropic turb.(1D case)
+  !         --------------------------------------------------------------------
+  !
   CASE DEFAULT
-!* SBL depth is used
+    !* SBL depth is used
     ZGAM(IIJB:IIJE,1:IKT) = 1.
     ZGAM(IIJB:IIJE,IKA) = 0.
     DO JK=IKTB,IKTE
@@ -235,14 +235,14 @@ SELECT CASE (TURBN%CTURBLEN)
     WHERE(PSBL_DEPTH(IIJB:IIJE)>0.)
       ZGAM(IIJB:IIJE,IKU) = TANH( (ZZZ(IIJB:IIJE,IKU)-ZZZ(IIJB:IIJE,IKB))/PSBL_DEPTH(IIJB:IIJE) )
     END WHERE
-   !$mnh_end_expand_where(JIJ=IIJB:IIJE)
-   !$mnh_expand_where(JIJ=IIJB:IIJE)
+    !$mnh_end_expand_where(JIJ=IIJB:IIJE)
+    !$mnh_expand_where(JIJ=IIJB:IIJE)
     WHERE (ZGAM(IIJB:IIJE,IKU-IKL)>0.99 ) 
       ZGAM(IIJB:IIJE,JK) = 1.
     END WHERE
     !$mnh_end_expand_where(JIJ=IIJB:IIJE)
-!
-!-------------------------------------------------------------------------------
+  !
+  !-------------------------------------------------------------------------------
 END SELECT
 !-------------------------------------------------------------------------------
 !
@@ -250,10 +250,10 @@ END SELECT
 !         ---------------------------------
 !
 DO JK=1,IKT
-!$mnh_expand_array(JIJ=IIJB:IIJE)
+  !$mnh_expand_array(JIJ=IIJB:IIJE)
   ZL(IIJB:IIJE,JK) =  CST%XKARMAN/SQRT(CSTURB%XALPSBL)/CSTURB%XCMFS                                      &
               * ZZZ(IIJB:IIJE,JK)*PDIRCOSZW(IIJB:IIJE)/(ZPHIM(IIJB:IIJE,JK)**2*SQRT(ZPHIE(IIJB:IIJE,JK)))
-!$mnh_end_expand_array(JIJ=IIJB:IIJE)
+  !$mnh_end_expand_array(JIJ=IIJB:IIJE)
 END DO
 !
 !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
diff --git a/src/common/turb/mode_turb_ver_thermo_flux.F90 b/src/common/turb/mode_turb_ver_thermo_flux.F90
index 767e8826a..8c26f8c5c 100644
--- a/src/common/turb/mode_turb_ver_thermo_flux.F90
+++ b/src/common/turb/mode_turb_ver_thermo_flux.F90
@@ -495,7 +495,7 @@ IF (GFWTH) THEN
   CALL M3_WTH_W2TH(D,CSTURB,TURBN,PREDTH1,PREDR1,PD,ZKEFF,PTKEM,Z3RDMOMENT)
   CALL D_M3_WTH_W2TH_O_DDTDZ(D,CSTURB,TURBN,PREDTH1,PREDR1,&
    & PD,PBLL_O_E,PETHETA,ZKEFF,PTKEM,ZWORK1)
-!
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZF(IIJB:IIJE,1:IKT)= ZF(IIJB:IIJE,1:IKT) + Z3RDMOMENT(IIJB:IIJE,1:IKT) * PFWTH(IIJB:IIJE,1:IKT)
   ZDFDDTDZ(IIJB:IIJE,1:IKT) = ZDFDDTDZ(IIJB:IIJE,1:IKT) + ZWORK1(IIJB:IIJE,1:IKT) &
@@ -509,7 +509,7 @@ IF (GFTH2) THEN
   CALL D_M3_WTH_WTH2_O_DDTDZ(D,CSTURB,TURBN,Z3RDMOMENT,PREDTH1,PREDR1,&
     & PD,PBLL_O_E,PETHETA,ZWORK1)
   CALL MZM_PHY(D,PFTH2,ZWORK2)
-!
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZF(IIJB:IIJE,1:IKT) = ZF(IIJB:IIJE,1:IKT) + Z3RDMOMENT(IIJB:IIJE,1:IKT) &
                                 * ZWORK2(IIJB:IIJE,1:IKT)
@@ -522,7 +522,7 @@ END IF
 IF (GFWR) THEN
   CALL M3_WTH_W2R(D,CSTURB,TURBN,PD,ZKEFF,PTKEM,PBLL_O_E,PEMOIST,PDTH_DZ,ZWORK1)
   CALL D_M3_WTH_W2R_O_DDTDZ(D,CSTURB,TURBN,PREDTH1,PREDR1,PD,ZKEFF,PTKEM,PBLL_O_E,PEMOIST,ZWORK2)
-!
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZF(IIJB:IIJE,1:IKT) = ZF(IIJB:IIJE,1:IKT) + ZWORK1(IIJB:IIJE,1:IKT) * PFWR(IIJB:IIJE,1:IKT)
   ZDFDDTDZ(IIJB:IIJE,1:IKT) = ZDFDDTDZ(IIJB:IIJE,1:IKT) + ZWORK2(IIJB:IIJE,1:IKT) &
@@ -536,7 +536,7 @@ IF (GFR2) THEN
   CALL MZM_PHY(D,PFR2,ZWORK2)
   CALL D_M3_WTH_WR2_O_DDTDZ(D,CSTURB,TURBN,PREDTH1,PREDR1,PD,&
     & ZKEFF,PTKEM,PSQRT_TKE,PBLL_O_E,PBETA,PLEPS,PEMOIST,ZWORK3)
-!
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)    
   ZF(IIJB:IIJE,1:IKT) = ZF(IIJB:IIJE,1:IKT) + ZWORK1(IIJB:IIJE,1:IKT) * ZWORK2(IIJB:IIJE,1:IKT)
   ZDFDDTDZ(IIJB:IIJE,1:IKT) = ZDFDDTDZ(IIJB:IIJE,1:IKT) + ZWORK3(IIJB:IIJE,1:IKT) &
@@ -550,7 +550,7 @@ IF (GFTHR) THEN
     & PLEPS,PEMOIST,Z3RDMOMENT)
   CALL D_M3_WTH_WTHR_O_DDTDZ(D,CSTURB,TURBN,Z3RDMOMENT,PREDTH1,PREDR1,PD,PBLL_O_E,PETHETA,ZWORK1)
   CALL MZM_PHY(D,PFTHR, ZWORK2)
-!
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZF(IIJB:IIJE,1:IKT) = ZF(IIJB:IIJE,1:IKT) + Z3RDMOMENT(IIJB:IIJE,1:IKT) &
                                 * ZWORK2(IIJB:IIJE,1:IKT)
@@ -581,9 +581,9 @@ ELSE ! atmosp bottom
                        * 0.5 * (1. + PRHODJ(IIJB:IIJE,IKA) / PRHODJ(IIJB:IIJE,IKB))
     !$mnh_end_expand_array(JIJ=IIJB:IIJE) 
   END IF
-!
-    ! atmos top
-      ZF(IIJB:IIJE,IKE+1)=0.
+  !
+  ! atmos top
+  ZF(IIJB:IIJE,IKE+1)=0.
 END IF
 !
 ! Compute the split conservative potential temperature at t+deltat
@@ -601,7 +601,7 @@ IF (TURBN%LLEONARD) THEN
  DO JK=1,IKT
    !$mnh_expand_array(JIJ=IIJB:IIJE)
    ZALT(IIJB:IIJE,JK) = PZZ(IIJB:IIJE,JK)-PZS(IIJB:IIJE) 
-   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+   !$mnh_end_expand_array(JIJ=IIJB:IIJE)
  END DO
  CALL MZM_PHY(D,PRHODJ,ZWORK1)
  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
@@ -890,7 +890,7 @@ IF (KRR /= 0) THEN
     CALL M3_WR_W2R(D,CSTURB,TURBN,PREDR1,PREDTH1,PD,ZKEFF,PTKEM,Z3RDMOMENT)
     CALL D_M3_WR_W2R_O_DDRDZ(D,CSTURB,TURBN,PREDR1,PREDTH1,PD,&
      & PBLL_O_E,PEMOIST,ZKEFF,PTKEM,ZWORK1)
-  !
+    !
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZF(IIJB:IIJE,1:IKT)= ZF(IIJB:IIJE,1:IKT) + Z3RDMOMENT(IIJB:IIJE,1:IKT) * PFWR(IIJB:IIJE,1:IKT)
     ZDFDDRDZ(IIJB:IIJE,1:IKT) = ZDFDDRDZ(IIJB:IIJE,1:IKT) + ZWORK1(IIJB:IIJE,1:IKT) &
@@ -904,7 +904,7 @@ IF (KRR /= 0) THEN
     CALL MZM_PHY(D,PFR2,ZWORK1)
     CALL D_M3_WR_WR2_O_DDRDZ(D,CSTURB,TURBN,Z3RDMOMENT,PREDR1,&
      & PREDTH1,PD,PBLL_O_E,PEMOIST,ZWORK2)
-  !
+    !
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZF(IIJB:IIJE,1:IKT) = ZF(IIJB:IIJE,1:IKT) + Z3RDMOMENT(IIJB:IIJE,1:IKT) &
                                   * ZWORK1(IIJB:IIJE,1:IKT)
@@ -919,7 +919,7 @@ IF (KRR /= 0) THEN
      & PTKEM,PBLL_O_E,PETHETA,PDR_DZ,ZWORK1)
     CALL D_M3_WR_W2TH_O_DDRDZ(D,CSTURB,TURBN,PREDR1,PREDTH1,&
      & PD,ZKEFF,PTKEM,PBLL_O_E,PETHETA,ZWORK2)
-  !
+    !
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZF(IIJB:IIJE,1:IKT) = ZF(IIJB:IIJE,1:IKT) + ZWORK1(IIJB:IIJE,1:IKT) * PFWTH(IIJB:IIJE,1:IKT)
     ZDFDDRDZ(IIJB:IIJE,1:IKT) = ZDFDDRDZ(IIJB:IIJE,1:IKT) + ZWORK2(IIJB:IIJE,1:IKT) &
@@ -949,7 +949,7 @@ IF (KRR /= 0) THEN
     CALL MZM_PHY(D,PFTHR,ZWORK1)
     CALL D_M3_WR_WTHR_O_DDRDZ(D,CSTURB,TURBN,Z3RDMOMENT,PREDR1, &
      & PREDTH1,PD,PBLL_O_E,PEMOIST,ZWORK2)
-  !
+    !
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZF(IIJB:IIJE,1:IKT) = ZF(IIJB:IIJE,1:IKT) + Z3RDMOMENT(IIJB:IIJE,1:IKT) &
                                   * ZWORK1(IIJB:IIJE,1:IKT)
diff --git a/src/common/turb/turb.F90 b/src/common/turb/turb.F90
index eb97ee0ef..c1ba44f85 100644
--- a/src/common/turb/turb.F90
+++ b/src/common/turb/turb.F90
@@ -552,27 +552,27 @@ ZCP(IIJB:IIJE,1:IKT)=CST%XCPD
 IF (KRR > 0) ZCP(IIJB:IIJE,1:IKT) = ZCP(IIJB:IIJE,1:IKT) + CST%XCPV * PRT(IIJB:IIJE,1:IKT,1)
 !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 DO JRR = 2,1+KRRL                          ! loop on the liquid components
-!$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)  
+  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)  
   ZCP(IIJB:IIJE,1:IKT)  = ZCP(IIJB:IIJE,1:IKT) + CST%XCL * PRT(IIJB:IIJE,1:IKT,JRR)
-!$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 END DO
 !
 DO JRR = 2+KRRL,1+KRRL+KRRI                ! loop on the solid components   
-!$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZCP(IIJB:IIJE,1:IKT)  = ZCP(IIJB:IIJE,1:IKT)  + CST%XCI * PRT(IIJB:IIJE,1:IKT,JRR)
-!$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 END DO
 !
 !*      2.2 Exner function at t
 !
 IF (OOCEAN) THEN
-!$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZEXN(IIJB:IIJE,1:IKT) = 1.
-!$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 ELSE
-!$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZEXN(IIJB:IIJE,1:IKT) = (PPABST(IIJB:IIJE,1:IKT)/CST%XP00) ** (CST%XRD/CST%XCPD)
-!$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 END IF
 !
 !*      2.3 dissipative heating coeff a t
@@ -587,18 +587,18 @@ ZATHETA(IIJB:IIJE,1:IKT) = 0.0
 ZAMOIST(IIJB:IIJE,1:IKT) = 0.0
 !
 IF (KRRL >=1) THEN
-!
-!*      2.4 Temperature at t
-!
+  !
+  !*      2.4 Temperature at t
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   ZT(IIJB:IIJE,1:IKT) =  PTHLT(IIJB:IIJE,1:IKT) * ZEXN(IIJB:IIJE,1:IKT)
   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
-!
-!*       2.5 Lv/Cph/Exn
-!
+  !
+  !*       2.5 Lv/Cph/Exn
+  !
   IF ( KRRI >= 1 ) THEN
     IF (NEBN%LSTATNW) THEN
-    !wc call new functions depending on statnew
+       !wc call new functions depending on statnew
        CALL COMPUTE_FUNCTION_THERMO_NEW_STAT(CST%XALPW,CST%XBETAW,CST%XGAMW,CST%XLVTT,CST%XCL,ZT,ZEXN,ZCP, &
                                  ZLVOCPEXNM,ZAMOIST,ZATHETA)
        CALL COMPUTE_FUNCTION_THERMO_NEW_STAT(CST%XALPI,CST%XBETAI,CST%XGAMI,CST%XLSTT,CST%XCI,ZT,ZEXN,ZCP, &
@@ -609,14 +609,14 @@ IF (KRRL >=1) THEN
       CALL COMPUTE_FUNCTION_THERMO(CST%XALPI,CST%XBETAI,CST%XGAMI,CST%XLSTT,CST%XCI,ZT,ZEXN,ZCP, &
                                  ZLSOCPEXNM,ZAMOIST_ICE,ZATHETA_ICE)
     ENDIF
-!
+    !
     !$mnh_expand_where(JIJ=IIJB:IIJE,JK=1:IKT)
     WHERE(PRT(IIJB:IIJE,1:IKT,2)+PRT(IIJB:IIJE,1:IKT,4)>0.0)
       ZFRAC_ICE(IIJB:IIJE,1:IKT) = PRT(IIJB:IIJE,1:IKT,4) / ( PRT(IIJB:IIJE,1:IKT,2) &
                                           +PRT(IIJB:IIJE,1:IKT,4) )
     END WHERE
     !$mnh_end_expand_where(JIJ=IIJB:IIJE,JK=1:IKT)
-!
+    !
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZLOCPEXNM(IIJB:IIJE,1:IKT) = (1.0-ZFRAC_ICE(IIJB:IIJE,1:IKT))*ZLVOCPEXNM(IIJB:IIJE,1:IKT) &
                            +ZFRAC_ICE(IIJB:IIJE,1:IKT) *ZLSOCPEXNM(IIJB:IIJE,1:IKT)
@@ -635,8 +635,8 @@ IF (KRRL >=1) THEN
                                    ZLOCPEXNM,ZAMOIST,ZATHETA)
     ENDIF
   END IF
-!
-!
+  !
+  !
   IF ( TPFILE%LOPENED .AND. TURBN%LTURB_DIAG ) THEN
     TZFIELD = TFIELDMETADATA(      &
       CMNHNAME   = 'ATHETA',       &
@@ -650,7 +650,7 @@ IF (KRRL >=1) THEN
       NDIMS      = 3,              &
       LTIMEDEP   = .TRUE.          )
     CALL IO_FIELD_WRITE_PHY(D,TPFILE,TZFIELD,ZATHETA)
-!
+    !
     TZFIELD = TFIELDMETADATA(      &
       CMNHNAME   = 'AMOIST',       &
       CSTDNAME   = '',             &
@@ -664,7 +664,7 @@ IF (KRRL >=1) THEN
       LTIMEDEP   = .TRUE.          )
     CALL IO_FIELD_WRITE_PHY(D,TPFILE,TZFIELD,ZAMOIST)
   END IF
-!
+  !
 ELSE
   ZLOCPEXNM(IIJB:IIJE,1:IKT)=0.
 END IF              ! loop end on KRRL >= 1
@@ -718,16 +718,16 @@ END IF
 IF (.NOT. TURBN%LHARAT) THEN
 
 SELECT CASE (TURBN%CTURBLEN)
-!
-!*      3.1 BL89 mixing length
-!           ------------------
+  !
+  !*      3.1 BL89 mixing length
+  !           ------------------
 
   CASE ('BL89')
     ZSHEAR(:,:)=0.
     CALL BL89(D,CST,CSTURB,TURBN,PZZ,PDZZ,PTHVREF,ZTHLM,KRR,ZRM,PTKET,ZSHEAR,ZLM,OOCEAN)
-!
-!*      3.2 RM17 mixing length
-!           ------------------
+  !
+  !*      3.2 RM17 mixing length
+  !           ------------------
 
   CASE ('RM17')
     CALL GZ_U_UW_PHY(D,PUT,PDZZ,ZWORK1)
@@ -743,9 +743,9 @@ SELECT CASE (TURBN%CTURBLEN)
                                     + ZDVDZ(IIJB:IIJE,1:IKT)*ZDVDZ(IIJB:IIJE,1:IKT))
     !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     CALL BL89(D,CST,CSTURB,TURBN,PZZ,PDZZ,PTHVREF,ZTHLM,KRR,ZRM,PTKET,ZSHEAR,ZLM,OOCEAN)
-!
-!*      3.3 Grey-zone combined RM17 & Deardorff mixing lengths
-!           --------------------------------------------------
+  !
+  !*      3.3 Grey-zone combined RM17 & Deardorff mixing lengths
+  !           --------------------------------------------------
 
   CASE ('HM21')
     CALL GZ_U_UW_PHY(D,PUT,PDZZ,ZWORK1)
@@ -772,22 +772,22 @@ SELECT CASE (TURBN%CTURBLEN)
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     ZLM(IIJB:IIJE,1:IKT) = MIN(ZLM(IIJB:IIJE,1:IKT),TURBN%XCADAP*ZLMW(IIJB:IIJE,1:IKT))
     !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
-!
-!*      3.4 Delta mixing length
-!           -------------------
-!
+  !
+  !*      3.4 Delta mixing length
+  !           -------------------
+  !
   CASE ('DELT')
     CALL DELT(ZLM,ODZ=.TRUE.)
-!
-!*      3.5 Deardorff mixing length
-!           -----------------------
-!
+  !
+  !*      3.5 Deardorff mixing length
+  !           -----------------------
+  !
   CASE ('DEAR')
     CALL DEAR(ZLM)
-!
-!*      3.6 Blackadar mixing length
-!           -----------------------
-!
+  !
+  !*      3.6 Blackadar mixing length
+  !           -----------------------
+  !
   CASE ('BLKR')
    ZL0 = 100.
    !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
@@ -803,14 +803,14 @@ SELECT CASE (TURBN%CTURBLEN)
      ZLM(IIJB:IIJE,JK) = ZALPHA  * ZLM(IIJB:IIJE,JK) * ZL0 / ( ZL0 + ZALPHA*ZLM(IIJB:IIJE,JK) )
      !$mnh_end_expand_array(JIJ=IIJB:IIJE)
    END DO
-!
+   !
    !$mnh_expand_array(JIJ=IIJB:IIJE)
    ZLM(IIJB:IIJE,IKTB-1) = ZLM(IIJB:IIJE,IKTB)
    ZLM(IIJB:IIJE,IKTE+1) = ZLM(IIJB:IIJE,IKTE)
    !$mnh_end_expand_array(JIJ=IIJB:IIJE)
-!
-!
-!
+   !
+   !
+   !
 END SELECT
 !
 !*      3.5 Mixing length modification for cloud
@@ -886,7 +886,7 @@ IF (TURBN%LROTATE_WIND) THEN
                      PCOSSLOPE,PSINSLOPE,               &
                      PDXX,PDYY,PDZZ,                    &
                      ZUSLOPE,ZVSLOPE                    )
-!
+  !
   CALL UPDATE_ROTATE_WIND(D,ZUSLOPE,ZVSLOPE,HLBCX,HLBCY)
 ELSE
   ZUSLOPE(IIJB:IIJE)=PUT(IIJB:IIJE,IKA)
@@ -934,14 +934,14 @@ ZMTHR(:,:) = 0.     ! w'th'r'
 !
 IF (TURBN%CTOM=='TM06') THEN
   CALL TM06(D,CST,PTHVREF,PBL_DEPTH,PZZ,PSFTH,ZMWTH,ZMTH2)
-!
-   CALL GZ_M_W_PHY(D,ZMWTH,PDZZ,ZWORK1)    ! -d(w'2th' )/dz
-   CALL GZ_W_M_PHY(D,ZMTH2,PDZZ,ZWORK2)    ! -d(w'th'2 )/dz
-   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
-   ZFWTH(IIJB:IIJE,1:IKT) = -ZWORK1(IIJB:IIJE,1:IKT)
-   ZFTH2(IIJB:IIJE,1:IKT) = -ZWORK2(IIJB:IIJE,1:IKT)
-   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
-!
+  !
+  CALL GZ_M_W_PHY(D,ZMWTH,PDZZ,ZWORK1)    ! -d(w'2th' )/dz
+  CALL GZ_W_M_PHY(D,ZMTH2,PDZZ,ZWORK2)    ! -d(w'th'2 )/dz
+  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  ZFWTH(IIJB:IIJE,1:IKT) = -ZWORK1(IIJB:IIJE,1:IKT)
+  ZFTH2(IIJB:IIJE,1:IKT) = -ZWORK2(IIJB:IIJE,1:IKT)
+  !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !
   ZFWTH(:,IKTE:) = 0.
   ZFWTH(:,:IKTB) = 0.
   ZFWR(:,:)  = 0.
@@ -1219,9 +1219,9 @@ ENDIF
 !          ---------------------------------------------------------
 !
 IF ( TURBN%LTURB_DIAG .AND. TPFILE%LOPENED ) THEN
-!
-! stores the mixing length
-!
+  !
+  ! stores the mixing length
+  !
   TZFIELD = TFIELDMETADATA(       &
     CMNHNAME   = 'LM',            &
     CSTDNAME   = '',              &
@@ -1234,11 +1234,11 @@ IF ( TURBN%LTURB_DIAG .AND. TPFILE%LOPENED ) THEN
     NDIMS      = 3,               &
     LTIMEDEP   = .TRUE.           )
   CALL IO_FIELD_WRITE_PHY(D,TPFILE,TZFIELD,ZLM)
-!
+  !
   IF (KRR /= 0) THEN
-!
-! stores the conservative potential temperature
-!
+    !
+    ! stores the conservative potential temperature
+    !
     TZFIELD = TFIELDMETADATA(                          &
     CMNHNAME   = 'THLM',                               &
     CSTDNAME   = '',                                   &
@@ -1251,9 +1251,9 @@ IF ( TURBN%LTURB_DIAG .AND. TPFILE%LOPENED ) THEN
     NDIMS      = 3,                                    &
     LTIMEDEP   = .TRUE.                                )
     CALL IO_FIELD_WRITE_PHY(D,TPFILE,TZFIELD,PTHLT)
-!
-! stores the conservative mixing ratio
-!
+    !
+    ! stores the conservative mixing ratio
+    !
     TZFIELD = TFIELDMETADATA(                &
     CMNHNAME   = 'RNPM',                     &
     CSTDNAME   = '',                         &
@@ -1271,7 +1271,7 @@ END IF
 !
 !* stores value of conservative variables & wind before turbulence tendency (AROME only)
 IF(PRESENT(PDRUS_TURB)) THEN
-!$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
+  !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   PDRUS_TURB(IIJB:IIJE,1:IKT)   = PRUS(IIJB:IIJE,1:IKT) - PDRUS_TURB(IIJB:IIJE,1:IKT)
   PDRVS_TURB(IIJB:IIJE,1:IKT)   = PRVS(IIJB:IIJE,1:IKT) - PDRVS_TURB(IIJB:IIJE,1:IKT)
   PDRTHLS_TURB(IIJB:IIJE,1:IKT) = PRTHLS(IIJB:IIJE,1:IKT) - PDRTHLS_TURB(IIJB:IIJE,1:IKT)
@@ -1300,7 +1300,7 @@ IF ( KRRL >= 1 ) THEN
                                     * PRRS(IIJB:IIJE,1:IKT,2) &
                                     + ZLSOCPEXNM(IIJB:IIJE,1:IKT) * PRRS(IIJB:IIJE,1:IKT,4)
     !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
-!
+    !
   ELSE
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
     PRT(IIJB:IIJE,1:IKT,1)  = PRT(IIJB:IIJE,1:IKT,1)  - PRT(IIJB:IIJE,1:IKT,2)
@@ -1334,11 +1334,11 @@ IF (TLES%LLES_CALL) THEN
   ZWORK2D(IIJB:IIJE) = (PSFU(IIJB:IIJE)*PSFU(IIJB:IIJE)+PSFV(IIJB:IIJE)*PSFV(IIJB:IIJE))**0.25
   !$mnh_end_expand_array(JIJ=IIJB:IIJE)
   CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZWORK2D,TLES%X_LES_USTAR)
-!----------------------------------------------------------------------------
-!
-!*     10. LES for 3rd order moments
-!          -------------------------
-!
+  !----------------------------------------------------------------------------
+  !
+  !*     10. LES for 3rd order moments
+  !          -------------------------
+  !
   CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZMWTH,TLES%X_LES_SUBGRID_W2Thl)
   CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZMTH2,TLES%X_LES_SUBGRID_WThl2)
   IF (KRR>0) THEN
@@ -1346,12 +1346,12 @@ IF (TLES%LLES_CALL) THEN
     CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZMTHR,TLES%X_LES_SUBGRID_WThlRt)
     CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZMR2,TLES%X_LES_SUBGRID_WRt2)
   END IF
-!
-!----------------------------------------------------------------------------
-!
-!*     11. LES quantities depending on <w'2> in "1DIM" mode
-!          ------------------------------------------------
-!
+  !
+  !----------------------------------------------------------------------------
+  !
+  !*     11. LES quantities depending on <w'2> in "1DIM" mode
+  !          ------------------------------------------------
+  !
   IF (TURBN%CTURBDIM=="1DIM") THEN
     !
     !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
@@ -1386,19 +1386,19 @@ IF (TLES%LLES_CALL) THEN
     END DO
   END IF
 
-!----------------------------------------------------------------------------
-!
-!*     12. LES mixing end dissipative lengths, presso-correlations
-!          -------------------------------------------------------
-!
+  !----------------------------------------------------------------------------
+  !
+  !*     12. LES mixing end dissipative lengths, presso-correlations
+  !          -------------------------------------------------------
+  !
   CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZLM,TLES%X_LES_SUBGRID_LMix)
   CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZLEPS,TLES%X_LES_SUBGRID_LDiss)
-!
-!* presso-correlations for subgrid Tke are equal to zero.
-!
+  !
+  !* presso-correlations for subgrid Tke are equal to zero.
+  !
   ZLEPS(:,:) = 0. !ZLEPS is used as a work array (not used anymore)
   CALL LES_MEAN_SUBGRID_PHY(D,TLES,ZLEPS,TLES%X_LES_SUBGRID_WP)
-!
+  !
   CALL SECOND_MNH(ZTIME2)
   TLES%XTIME_LES = TLES%XTIME_LES + ZTIME2 - ZTIME1
 END IF
@@ -1444,33 +1444,33 @@ REAL, DIMENSION(D%NIJT,D%NKT), INTENT(OUT)   :: PAMOIST,PATHETA
 !
   IF (LHOOK) CALL DR_HOOK('TURB:COMPUTE_FUNCTION_THERMO',0,ZHOOK_HANDLE2)
   ZEPS = CST%XMV / CST%XMD
-!
-!*       1.1 Lv/Cph at  t
-!
+  !
+  !*       1.1 Lv/Cph at  t
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   PLOCPEXN(IIJB:IIJE,1:IKT) = ( PLTT + (CST%XCPV-PC) *  (PT(IIJB:IIJE,1:IKT)-CST%XTT) ) &
                                      / PCP(IIJB:IIJE,1:IKT)
-!
-!*      1.2 Saturation vapor pressure at t
-!
+  !
+  !*      1.2 Saturation vapor pressure at t
+  !
   ZRVSAT(IIJB:IIJE,1:IKT) =  EXP( PALP - PBETA/PT(IIJB:IIJE,1:IKT) - PGAM*ALOG( PT(IIJB:IIJE,1:IKT) ) )
-!
-!*      1.3 saturation  mixing ratio at t
-!
+  !
+  !*      1.3 saturation  mixing ratio at t
+  !
   ZRVSAT(IIJB:IIJE,1:IKT) =  ZRVSAT(IIJB:IIJE,1:IKT) &
                                     * ZEPS / ( PPABST(IIJB:IIJE,1:IKT) - ZRVSAT(IIJB:IIJE,1:IKT) )
-!
-!*      1.4 compute the saturation mixing ratio derivative (rvs')
-!
+  !
+  !*      1.4 compute the saturation mixing ratio derivative (rvs')
+  !
   ZDRVSATDT(IIJB:IIJE,1:IKT) = ( PBETA / PT(IIJB:IIJE,1:IKT)  - PGAM ) / PT(IIJB:IIJE,1:IKT)   &
                  * ZRVSAT(IIJB:IIJE,1:IKT) * ( 1. + ZRVSAT(IIJB:IIJE,1:IKT) / ZEPS )
-!
-!*      1.5 compute Amoist
-!
+  !
+  !*      1.5 compute Amoist
+  !
   PAMOIST(IIJB:IIJE,1:IKT)=  0.5 / ( 1.0 + ZDRVSATDT(IIJB:IIJE,1:IKT) * PLOCPEXN(IIJB:IIJE,1:IKT) )
-!
-!*      1.6 compute Atheta
-!
+  !
+  !*      1.6 compute Atheta
+  !
   PATHETA(IIJB:IIJE,1:IKT)= PAMOIST(IIJB:IIJE,1:IKT) * PEXN(IIJB:IIJE,1:IKT) *               &
         ( ( ZRVSAT(IIJB:IIJE,1:IKT) - PRT(IIJB:IIJE,1:IKT,1) ) * PLOCPEXN(IIJB:IIJE,1:IKT) / &
           ( 1. + ZDRVSATDT(IIJB:IIJE,1:IKT) * PLOCPEXN(IIJB:IIJE,1:IKT) )        *               &
@@ -1482,9 +1482,9 @@ REAL, DIMENSION(D%NIJT,D%NKT), INTENT(OUT)   :: PAMOIST,PATHETA
           )                                                                  &
          - ZDRVSATDT(IIJB:IIJE,1:IKT)                                                  &
         )
-!
-!*      1.7 Lv/Cph/Exner at t-1
-!
+  !
+  !*      1.7 Lv/Cph/Exner at t-1
+  !
   PLOCPEXN(IIJB:IIJE,1:IKT) = PLOCPEXN(IIJB:IIJE,1:IKT) / PEXN(IIJB:IIJE,1:IKT)
   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 !
@@ -1528,35 +1528,35 @@ REAL, DIMENSION(D%NIJT,D%NKT), INTENT(OUT)   :: PAMOIST,PATHETA
 !
   IF (LHOOK) CALL DR_HOOK('TURB:COMPUTE_FUNCTION_THERMO_NEW_STAT',0,ZHOOK_HANDLE2)
   ZEPS = CST%XMV / CST%XMD
-!
-!*       1.1 Lv/Cph at  t
-!
+  !
+  !*       1.1 Lv/Cph at  t
+  !
   !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
   PLOCPEXN(IIJB:IIJE,1:IKT) = ( PLTT + (CST%XCPV-PC) *  (PT(IIJB:IIJE,1:IKT)-CST%XTT) ) / PCP(IIJB:IIJE,1:IKT)
-!
-!*      1.2 Saturation vapor pressure at t
-!
+  !
+  !*      1.2 Saturation vapor pressure at t
+  !
   ZRVSAT(IIJB:IIJE,1:IKT) =  EXP( PALP - PBETA/PT(IIJB:IIJE,1:IKT) - PGAM*ALOG( PT(IIJB:IIJE,1:IKT) ) )
-!
-!*      1.3 saturation  mixing ratio at t
-!
+  !
+  !*      1.3 saturation  mixing ratio at t
+  !
   ZRVSAT(IIJB:IIJE,1:IKT) =  ZRVSAT(IIJB:IIJE,1:IKT) * ZEPS / ( PPABST(IIJB:IIJE,1:IKT) - ZRVSAT(IIJB:IIJE,1:IKT) )
-!
-!*      1.4 compute the saturation mixing ratio derivative (rvs')
-!
+  !
+  !*      1.4 compute the saturation mixing ratio derivative (rvs')
+  !
   ZDRVSATDT(IIJB:IIJE,1:IKT) = ( PBETA / PT(IIJB:IIJE,1:IKT)  - PGAM ) / PT(IIJB:IIJE,1:IKT)   &
                  * ZRVSAT(IIJB:IIJE,1:IKT) * ( 1. + ZRVSAT(IIJB:IIJE,1:IKT) / ZEPS )
-!
-!*      1.5 compute Amoist
-!
+  !
+  !*      1.5 compute Amoist
+  !
   PAMOIST(IIJB:IIJE,1:IKT)=  1.0 / ( 1.0 + ZDRVSATDT(IIJB:IIJE,1:IKT) * PLOCPEXN(IIJB:IIJE,1:IKT) )
-!
-!*      1.6 compute Atheta
-!
+  !
+  !*      1.6 compute Atheta
+  !
   PATHETA(IIJB:IIJE,1:IKT)= PAMOIST(IIJB:IIJE,1:IKT) * PEXN(IIJB:IIJE,1:IKT) * ZDRVSATDT(IIJB:IIJE,1:IKT)
-!
-!*      1.7 Lv/Cph/Exner at t-1
-!
+  !
+  !*      1.7 Lv/Cph/Exner at t-1
+  !
   PLOCPEXN(IIJB:IIJE,1:IKT) = PLOCPEXN(IIJB:IIJE,1:IKT) / PEXN(IIJB:IIJE,1:IKT)
   !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
 !
@@ -1934,23 +1934,23 @@ IF (HTURBLEN_CL == TURBN%CTURBLEN) THEN
   ZLM_CLOUD(:,:) = ZLM(:,:)
 ELSE
   SELECT CASE (HTURBLEN_CL)
-!
-!*         3.1 BL89 mixing length
-!           ------------------
+  !
+  !*         3.1 BL89 mixing length
+  !           ------------------
   CASE ('BL89','RM17','HM21')
     ZSHEAR(:,:)=0.
     CALL BL89(D,CST,CSTURB,TURBN,PZZ,PDZZ,PTHVREF,ZTHLM,KRR,ZRM,PTKET,ZSHEAR,ZLM_CLOUD,OOCEAN)
-!
-!*         3.2 Delta mixing length
-!           -------------------
+  !
+  !*         3.2 Delta mixing length
+  !           -------------------
   CASE ('DELT')
     CALL DELT(ZLM_CLOUD,ODZ=.TRUE.)
-!
-!*         3.3 Deardorff mixing length
-!           -----------------------
+  !
+  !*         3.3 Deardorff mixing length
+  !           -----------------------
   CASE ('DEAR')
     CALL DEAR(ZLM_CLOUD)
-!
+  !
   END SELECT
 ENDIF
 !
diff --git a/tools/.gitignore b/tools/.gitignore
index 4ea657ac4..567bda1f4 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -2,9 +2,9 @@
 pack/**
 !pack/.gitkeep
 
-# Ignore the content of mnh_expand directory but not the directory itself
-mnh_expand/**
-!mnh_expand/.gitkeep
+# Ignore the content of the site directory but not the directory itself
+site/**
+!site/.gitkeep
 
 # Ignore the content of testprogs_data but not the directory itself
 testprogs_data/ice_adjust/**
diff --git a/tools/INSTALL.md b/tools/INSTALL.md
index d72e545e0..5c93e7440 100644
--- a/tools/INSTALL.md
+++ b/tools/INSTALL.md
@@ -17,11 +17,9 @@ This document is written using the markdown language. With pandoc, it can be con
    The reference pack for Meso-NH must be installed. Instructions can be found in
    [INSTALL\_pack\_mesonh](./INSTALL_pack_mesonh.md)
 
-3. MNH\_EXPAND
-   This tool is composed of two parts: the filepp software, and the MNH\_Expand\_Array package.
-   It is needed by the different check\_commit\_\*.sh scripts, depending on options used at execution.
-   Installation is described in [INSTALL\_mnh\_expand](./INSTALL_mnh_expand.md)
+3. AUTOMATIC INSTALLATION
+   The script INSTALL.sh (INSTALL.sh -h for help) handles the installation of:
 
-4. TESTPROGS REFERENCE DATA
-   The script check\_commit\_testprogs.sh needs reference data.
-   The data generation is explained in [INSTALL\_testprogs](./INSTALL_testprogs.md)
+     - the pyft tool needed by the different check\_commit\_\*.sh scripts, depending on options used at execution.
+     - the testprogs reference data which are needed by the script check\_commit\_testprogs.sh. The manual
+       generation of these data is explained in [INSTALL\_testprogs](./INSTALL_testprogs.md)
diff --git a/tools/INSTALL.sh b/tools/INSTALL.sh
index 862b33b4e..f7b7155f7 100755
--- a/tools/INSTALL.sh
+++ b/tools/INSTALL.sh
@@ -7,20 +7,35 @@ 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"
+  echo "Usage: $0 [-h] [--ALL] [--dataset] [--pyft] [--clean]"
+  echo "  --ALL              Install or clean everything"
+  echo "  --dataset          Install or clean a reduced dataset for the test programs"
+  echo "  --pyft             Install or clean the pyft tool"
+  echo "  --clean            Clean instead of installing"
 }
 
-install_dataset=0
+ALL=0
+dataset=0
+pyft=0
+clean=0
 
 while [ -n "$1" ]; do
   case "$1" in
-    '--install-dataset') install_dataset=1;;
+    '--ALL') ALL=1;;
+    '--dataset') dataset=1;;
+    '--pyft') pyft=1;;
+    '--clean') clean=1;;
+    '-h') usage;;
   esac
   shift
 done
 
-if [ $install_dataset -eq 1 ]; then
+if [ $ALL == 1 ]; then
+  dataset=1
+  pyft=1
+fi
+
+if [ $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 \
@@ -28,8 +43,25 @@ if [ $install_dataset -eq 1 ]; then
               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
+    if [ $clean -eq 1 ]; then
+      find $(basename $basefile .gz) -name \*.dat -type f -delete
+    else
+      wget --no-check-certificate $file -O $basefile
+      tar xf $basefile
+      rm -f $basefile
+    fi
   done
 fi
+
+if [ $pyft -eq 1 ]; then
+  cd $PHYEXTOOLSDIR/site
+  if [ $clean -eq 1 ]; then
+    rm -rf pyft
+  else
+    git clone git@github.com:UMR-CNRM/pyft.git
+    pyft/bin/INSTALL.sh
+    echo "Instead of sourcing the previous file, you can source $PHYEXTOOLSDIR/env.sh"
+    echo "This file, among other things, source the previous displayed file."
+  fi
+fi
+    
diff --git a/tools/INSTALL_mnh_expand.md b/tools/INSTALL_mnh_expand.md
deleted file mode 100644
index 406b1f53e..000000000
--- a/tools/INSTALL_mnh_expand.md
+++ /dev/null
@@ -1,34 +0,0 @@
-# INSTALLATION NEEDED THE prep\_code.sh script
-
-## ABOUT THIS DOCUMENT 
-
-This document is intended for persons who want to use the prep\_code.sh script (directly or through a check\_commit\_\*.sh script).
-
-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).
-
-Two packages must be installed:
-
-  - [filepp](#filepp)
-  - [MNH\_Expand\_Array](#mnh\_expand\_array)
-
-## filepp
-In the \<git repository\>/tools/mnh\_expand directory:
-
-```
-wget https://www-users.york.ac.uk/~dm26/filepp/filepp-1.8.0.tar.gz
-tar xvf filepp-1.8.0.tar.gz
-cd filepp-1.8.0
-./configure --prefix=$PWD
-make install
-cd ..
-ln -s filepp-1.8.0 filepp
-```
-
-## MNH\_Expand\_Array
-In the \<git repository\>/tools/mnh\_expand directory, clone the MNH\_Expand\_Array repository:
-
-```
-git clone https://github.com/JuanEscobarMunoz/MNH_Expand_Array.git
-```
-
-
diff --git a/tools/PHYEX2IAL.sh b/tools/PHYEX2IAL.sh
index 7bce8d759..3e391fe65 100755
--- a/tools/PHYEX2IAL.sh
+++ b/tools/PHYEX2IAL.sh
@@ -17,7 +17,7 @@ function usage {
   echo "                                        defaults to the env variable PHYEXREOuser (=$PHYEXREPOuser)"
   echo "--phyex-repo-protocol PHYEXREPOprotocol protocol (https or ssh) to reach the PHYEX repository on github,"
   echo "                                        defaults to the env variable PHYEXREOprotocol (=$PHYEXREPOprotocol)"
-  echo "--noexpand                              do not use mnh_expand (code will be in array-syntax)"
+  echo "--noexpand                              do not expand mnh_expand blocks (code will be in array-syntax)"
   echo "IALDIRECTORY                            local directory containing the IAL repository"
   echo "IALVERSION                              version to checkout in the IAL repository"
   echo "PHYEXVERSION                            commit, tag (as tags/<tag>) of PHYEX to use"
diff --git a/tools/check_commit_ial.sh b/tools/check_commit_ial.sh
index 3f5e489ce..2bc421e6d 100755
--- a/tools/check_commit_ial.sh
+++ b/tools/check_commit_ial.sh
@@ -125,7 +125,7 @@ function usage {
   echo "-C              checks the result against the reference"
   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 "--noexpand      do not expand mnh_expand blocks (code will be in array-syntax)"
   echo "-f              full compilation (do not use pre-compiled pack)"
   echo "--cycle CYCLE   to force using CYCLE"
   echo "--scripttag TAG script tag to use in case --cycle is provided"
@@ -492,11 +492,8 @@ if [ $packcreation -eq 1 ]; then
     fi
     cd $HOMEPACK/$name/src/local/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"
+      expand_options="--mnhExpand"
     else
       expand_options=""
     fi
diff --git a/tools/check_commit_lmdz.sh b/tools/check_commit_lmdz.sh
index b8b1d0af7..391caa667 100755
--- a/tools/check_commit_lmdz.sh
+++ b/tools/check_commit_lmdz.sh
@@ -28,7 +28,7 @@ function usage {
   echo "-t              comma separated list of tests to execute"
   echo "                or ALL to execute all tests"
   echo "--nofcm         don't use fcm (be carreful, with fcm compilation exits with a (false) error"
-  echo "--expand        use mnh_expand (code will be in do loops)"
+  echo "--expand        expand mnh_expand blocks (code will be in do loops)"
   echo "--version VERSION   to force using lmdz VERSION"
   echo "--repo-user     user hosting the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
@@ -215,11 +215,9 @@ if [ $packcreation -eq 1 ]; then
   else
     #Checkout PHYEX
     cd $LMDZPACK/$name
-    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"
+      expand_options="--mnhExpand"
     else
       expand_options=""
     fi
diff --git a/tools/check_commit_mesonh.sh b/tools/check_commit_mesonh.sh
index f1950e3ca..e310d9694 100755
--- a/tools/check_commit_mesonh.sh
+++ b/tools/check_commit_mesonh.sh
@@ -52,7 +52,7 @@ function usage {
   echo "-C              checks the result against the reference"
   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 "--expand        expand mnh_expand blocks (code will use do loops)"
   echo "--repo-user USER"
   echo "                user hosting the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
@@ -263,11 +263,8 @@ if [ $packcreation -eq 1 ]; then
 
     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"
+      expand_options="--mnhExpand"
     else
       expand_options=""
     fi
diff --git a/tools/check_commit_testprogs.sh b/tools/check_commit_testprogs.sh
index 67e71fa08..6a0ba9aa4 100755
--- a/tools/check_commit_testprogs.sh
+++ b/tools/check_commit_testprogs.sh
@@ -79,7 +79,7 @@ function usage {
   echo "-C              checks the result against the reference"
   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 "--noexpand      do not expand mnh_expand blocks (code will be in array-syntax)"
   echo "--repo-user USER"
   echo "                user hosting the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)"
@@ -288,9 +288,6 @@ if [ $packcreation -eq 1 ]; then
     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
diff --git a/tools/correct_indent.py b/tools/correct_indent.py
deleted file mode 100755
index f3f560585..000000000
--- a/tools/correct_indent.py
+++ /dev/null
@@ -1,179 +0,0 @@
-#!/usr/bin/env python3
-
-def detectMNH_expand(f):
-    # Adds MNH EXPAND comment before and after $mnh_expand$
-    fin = open(f, 'r')
-    fout = open(f+'_EXPAND', 'w')
-    contentbyline = fin.readlines()
-
-    for i in contentbyline:
-        if "!$mnh_expand" in i:
-            fout.writelines("! $MNH EXPAND$ !\n")
-            fout.writelines(i)
-        elif "!$mnh_end_expand" in i:
-            fout.writelines(i)
-            fout.writelines("! $MNH END EXPAND$ !\n")
-        else:
-            fout.writelines(i)
-
-    fout.close()
-    fin.close()
-
-
-def count_blank(text):
-    # Count number of space blank before a first character of a line
-    count = 0
-    for t in text:
-        if t == " ":
-            count = count+1
-        else:
-            break
-    return count
-
-
-def check_indent(n, indent_score, worktext):
-    # Correct the indentation with respect to the indent_score
-    nblank = count_blank(worktext)
-    rawtext = worktext[nblank:]
-    correcttext = ' '*((indent_score)*2) + rawtext
-    return correcttext
-
-
-def firstchar(string):
-    # Return the first non-blank character of a string
-    for i in string:
-        if i == " ":
-            pass
-        else:
-            return i
-
-
-def first7char(string):
-    # Return the 7 first non-blank character of a string
-    nb_blank = 0
-    for i in string:
-        if i == " ":
-            nb_blank = nb_blank+1
-        else:
-            return string[nb_blank:nb_blank+7]
-
-
-def correct_indent(f):
-    import sys
-# Correct the indentation between MNH EXPAND comment
-# Does not change the indentation outside MNH EXPAND > ... < MNH END EXPAND
-# Does not indent comment lines
-# Handles IF in two lines (e.g IF(... &
-#                                 ......) THEN
-# TODO : handles more than two lines of & with IF
-# TODO : do not correct indentation for & within an regular line
-# To improve : the indentation correction is weird (strict) if the indentation before
-# the MNH EXPAND comments is not respected (over-indentation)
-    fin = open(f, 'r')
-    fout = open(f+'_CORRECT_INDENT', 'w')
-    contentbyline = fin.readlines()
-
-    ncurrline = 0
-    indent_score = 0
-    expand_score = 0
-    passNextLine = {'Pass': False, 'Reason': ""}
-    for i in contentbyline:
-        i7 = first7char(i)
-        if passNextLine['Pass']:  # Second line with & for if or #if(n)def
-            textwrite = i
-            passNextLine['Pass'] = False
-            if passNextLine['Reason'] == "IF":
-                indent_score = indent_score+1
-            elif passNextLine['Reason'] == "#ifdef":
-                textwrite = check_indent(ncurrline, indent_score, i)
-            elif passNextLine['Reason'] == "#else":
-                textwrite = check_indent(ncurrline, indent_score, i)
-                # ONLY IF present in between #ifdef is handled
-                # If more test is needed (present in the fortran code), duplicate test here
-                if "IF" in i7 and "THEN" in i:
-                    indent_score = indent_score+1
-            else:
-                sys.exit("Reason for passing the line not defined")
-        elif "! $MNH EXPAND$ !" in i:
-            expand_score = expand_score + 1
-            textwrite = ""
-        elif "! $MNH END EXPAND$ !" in i:
-            expand_score = expand_score - 1
-            textwrite = ""
-        # Ignore comment lines
-        elif firstchar(i) == "!":
-            textwrite = i
-        # Correct indentation only in between $MNH EXPAND$ and $MNH END EXPAND$
-        elif expand_score >= 1:
-            if indent_score > 0 and ("DO J" not in i and "ENDDO" not in i and "END DO" not in i and "END IF" not in i and "ENDIF" not in i and "THEN" not in i and "ELSE" not in i and "#if" not in i and "#else" not in i and "#endif" not in i):
-                textwrite = check_indent(ncurrline, indent_score, i)
-            # #ifdef handling = pass to next lines with no indent
-            elif "#if" in i7:  # ifdef or ifndef
-                textwrite = i
-                passNextLine['Pass'], passNextLine['Reason'] = (True, "#ifdef")
-            elif "#else" in i7:
-                textwrite = i
-                passNextLine['Pass'], passNextLine['Reason'] = (True, "#else")
-            elif '#endif' in i7:
-                textwrite = i
-            elif "ELSE" in i7:  # ELSE or ELSEIF
-                indent_score = indent_score-1
-                textwrite = check_indent(ncurrline, indent_score, i)
-                indent_score = indent_score+1
-            elif "IF" in i7 and "&" in i:  # IF on two lines #TODO on > 2 lines
-                textwrite = i
-                passNextLine['Pass'], passNextLine['Reason'] = (True, "IF")
-            # exclude IF in one line (without THEN)
-            elif "IF" in i7 and "THEN" in i:
-                textwrite = check_indent(ncurrline, indent_score, i)
-                indent_score = indent_score+1
-            elif "DO J" in i7:
-                textwrite = check_indent(ncurrline, indent_score, i)
-                indent_score = indent_score+1
-            elif ("ENDDO" in i7) or ("END DO" in i7):
-                indent_score = indent_score-1
-                textwrite = check_indent(ncurrline, indent_score, i)
-            elif ("END IF" in i7) or ("ENDIF" in i7):
-                indent_score = indent_score-1
-                textwrite = check_indent(ncurrline, indent_score, i)
-            else:
-                textwrite = i
-        else:  # not EXPAND lines nor within mnh_expand
-            if "ELSE" in i7:  # ELSE or ELSEIF
-                pass  # no increase in indent
-            elif "IF" in i7 and "&" in i:  # IF on two lines #TODO on > 2 lines
-                passNextLine['Pass'], passNextLine['Reason'] = (True, "IF")
-            # exclude IF in one line (without THEN)
-            elif "IF" in i7 and "THEN" in i:
-                indent_score = indent_score+1
-            elif "DO J" in i7:
-                indent_score = indent_score+1
-            elif ("ENDDO" in i7) or ("END DO" in i7):
-                indent_score = indent_score-1
-            elif ("END IF" in i7) or ("ENDIF" in i7):
-                indent_score = indent_score-1
-            textwrite = i
-        ncurrline = ncurrline+1
-        fout.writelines(textwrite)
-
-    fout.close()
-    fin.close()
-
-
-if __name__ == "__main__":
-    import argparse
-    import sys
-    parser = argparse.ArgumentParser(
-        description='Detecte les balises !$mnh_expand et !$mnh_end_expand et ajoute un commentaire avant et après pour corriger l\'indentation par la suite avec correct_indentation.py')
-    value = argparse.ArgumentParser()
-    parser.add_argument('file1', metavar='file1',
-                        type=str, help="file to check")
-    parser.add_argument('action', metavar='action', type=str,
-                        help="action (indent or detect")
-    args = parser.parse_args()
-    if "indent" in args.action:
-        sys.exit(correct_indent(args.file1))
-    elif "detect" in args.action:
-        sys.exit(detectMNH_expand(args.file1))
-    else:
-        sys.exit("Error : action should be indent or detect. Nothing has been done")
diff --git a/tools/env.sh b/tools/env.sh
index 1bec04b6d..1a93af493 100644
--- a/tools/env.sh
+++ b/tools/env.sh
@@ -1,4 +1,6 @@
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
-MNH_EXPAND_DIR=$DIR/mnh_expand
-export PATH=$DIR:$MNH_EXPAND_DIR/filepp:$MNH_EXPAND_DIR/MNH_Expand_Array:$PATH
+export PATH=$DIR:$PATH
+
+PYFT_DIR=$DIR/site/pyft
+. $PYFT_DIR/bin/env.sh
diff --git a/tools/prep_code.sh b/tools/prep_code.sh
index 5fc20c5db..a1d0f2103 100755
--- a/tools/prep_code.sh
+++ b/tools/prep_code.sh
@@ -6,7 +6,7 @@ set -e
 #This script can:
 # - extract a tag or a commit from the PHYEX repository
 # - merge code from common and model specific directories
-# - apply mnh_expand tool
+# - apply the pyft tool
 # - push the result in a new branch of the repository
 
 
@@ -21,10 +21,9 @@ function usage {
   echo "-c CHECKOUT_POINT     git object to checkout, can be a specific commit"
   echo "                      or a tag with the following syntax: tags/TAG where TAG is the tag name"
   echo "-m MODEL              merge the code under the common directory with the code specific to MODEL model"
-  echo "-D OPTION             option to use with mnh_expand"
-  echo "                      BE CARREFULL, a space between -D and the option is required here"
+  echo "--mnhExpand           option passed to the pyft tool"
   echo "-p                    push the result as a new branch"
-  echo "-s SUB                subdiretory or file (under src) to consider when merging and applying mnh_expand"
+  echo "-s SUB                subdiretory or file (under src) to consider when merging and applying pyft"
   echo "--renameFf            rename .F90 into .f90"
   echo "--ilooprm             replace indexes in do loop (and mnh_expand) by :"
   echo "--repo                use this repository instead of the one derived (if any) from the env variables"
@@ -34,11 +33,11 @@ function usage {
   echo "* If the -c option is not provided, DIRECTORY must already contain files and directory as if"
   echo "  it was the result of a git checkout"
   echo "* If the -m option is used, directory tree is modified, only relevant code is kept"
-  echo "* If no -D options are used, mnh_expand is not called at all"
+  echo "* If --mnhExpand is not used, pyft is not called at all"
   echo "* -s options are mandatory for -m, -D and -p options"
   echo "* -p option is allowed only if -c and -m options are provided"
   echo ""
-  echo "To use mnh_expand... it must be installed (alongside the filepp tool)"
+  echo "To use the pyft tool... it must be installed"
 }
 
 full_command="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}") $@"
@@ -47,7 +46,7 @@ separator='_' #- be carrefull, gmkpack (at least on belenos) has multiple allerg
 
 directory=""
 checkout_point=""
-mnh_expand_options=""
+pyft_options=""
 model=""
 push=0
 subs=""
@@ -72,7 +71,7 @@ while [ -n "$1" ]; do
     '-h') usage;;
     '-c') checkout_point="$2"; shift;;
     '-m') model="$2"; shift;;
-    '-D') mnh_expand_options="$mnh_expand_options -D$2"; shift;;
+    '--mnhExpand') pyft_options="$pyft_options $1";;
     '-s') subs="$subs $2"; shift;;
     '-p') push=1;;
     '--renameFf') renameFf=1;;
@@ -135,6 +134,7 @@ else
 fi
 
 ###### RENAME .F90 into .f90
+#This step could also be achieved by pyft_tool.py but it must be done *before* the call to pyft_tool
 if [ $renameFf -eq 1 ]; then
   #we use find/while/read in case the number of files is too big to be hold on a single shell line
   find . -type f  -name \*.F90 -print0 | \
@@ -243,27 +243,13 @@ if [ $ilooprm -eq 1 ]; then
   done
 fi
 
-###### MNH_EXPAND
-if [ -n "${mnh_expand_options-}" ]; then
-  [ $verbose -gt 0 ] && echo "Applying mnh_expand"
+###### PYFT
+if [ -n "${pyft_options-}" ]; then
+  [ $verbose -gt 0 ] && echo "Applying pyft_tool"
 
-  #Update PATH if needed
-  UPDATEDPATH=$PATH
-  which correct_indent.py > /dev/null || UPDATEDPATH=$PHYEXTOOLSDIR:$UPDATEDPATH
-  which mnh_expand  > /dev/null || UPDATEDPATH=$PHYEXTOOLSDIR/mnh_expand/MNH_Expand_Array:$UPDATEDPATH
-  which filepp > /dev/null || UPDATEDPATH=$PHYEXTOOLSDIR/mnh_expand/filepp:$UPDATEDPATH
+  #Update PATH and PYTHONPATH if needed
+  which pyft_tool.py > /dev/null || . $PHYEXTOOLSDIR/site/pyft/bin/env.sh
 
-  function apply_mnh_expand () {
-    if grep mnh_expand $1 > /dev/null 2>&1 ; then
-      [ $verbose -gt 1 ] && echo "Applying mnh_expand on $1"
-      PATH=$UPDATEDPATH correct_indent.py $1 "detect"
-      PATH=$UPDATEDPATH mnh_expand -DMNH_EXPAND_NOCPP $mnh_expand_options $1_EXPAND > tempo_mnh_expand
-      rm -f $1_EXPAND
-      PATH=$UPDATEDPATH correct_indent.py tempo_mnh_expand "indent"
-      mv tempo_mnh_expand_CORRECT_INDENT $1
-      rm -f tempo_mnh_expand
-    fi
-  }
   if [ -n "${model-}" ]; then
     reps=$subs
   else
@@ -274,9 +260,12 @@ if [ -n "${mnh_expand_options-}" ]; then
   fi
   for rep in $reps; do
     if [ -d $rep ]; then
-      #find $rep -type f | while read file; do
       find $rep -type f -not -name '.*.swp'  -not -name '.*.swo' | while read file; do
-        apply_mnh_expand "$file"
+        if [ "$(echo $file | grep '\.')" != '' -a $(echo $file | rev | cut -d. -f1 | rev) != 'fypp' ]; then
+          #Files without extension are certainly not source code files
+          #.fypp files cannot be read by pyft_tool.py
+          pyft_tool.py --wrapH $pyft_options "$file" #--wrapH allows to deal with h files
+        fi
       done
     fi
   done
diff --git a/tools/mnh_expand/.gitkeep b/tools/site/.gitkeep
similarity index 100%
rename from tools/mnh_expand/.gitkeep
rename to tools/site/.gitkeep
diff --git a/tools/testing.sh b/tools/testing.sh
index aec67ad89..71cef6ff9 100755
--- a/tools/testing.sh
+++ b/tools/testing.sh
@@ -238,18 +238,8 @@ if [ ${force} -eq 1 -o $(get_statuses "${SHA}" | grep "${context}" | wc -l) -eq
       log 1 "Clonig PHYEX in ${WORKDIR}/PHYEX"
       git clone "${PHYEXREPOgiturl}" "${WORKDIR}/PHYEX"
   
-      log 1 "Installing filepp"
-      cd tools/mnh_expand
-      wget https://www-users.york.ac.uk/~dm26/filepp/filepp-1.8.0.tar.gz
-      tar xvf filepp-1.8.0.tar.gz
-      cd filepp-1.8.0
-      ./configure --prefix="${PWD}"
-      make install
-      cd ..
-      ln -s filepp-1.8.0 filepp
-  
-      log 1 "Installing MNH_Expand_Array"
-      git clone https://github.com/JuanEscobarMunoz/MNH_Expand_Array.git
+      log 1 "Installing PHYEX"
+      ./tools/INSTALL.sh --ALL
     fi
     log 1 "Checkout commit ${SHA}"
     cd "${WORKDIR}/PHYEX"
diff --git a/tools/verify_mnh_expand.py b/tools/verify_mnh_expand.py
deleted file mode 100755
index c6e3d934e..000000000
--- a/tools/verify_mnh_expand.py
+++ /dev/null
@@ -1,153 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import glob
-import logging
-
-def verify_mnh_expand(path):
-    """
-    Verifies if source files are ready for expansion through mnh_expand
-    :param path: directory to recursively check or file name
-
-    Presently the folowing tests are performed:
-      - starting and closing directives are conform
-      - each instruction in the bloc is an effectation to an array with the right number of dimensions
-
-    Limitation:
-      - if the '=' sign is not on same line than the left hand side of the affectation instruction,
-        the instruction will no be checked. And an error can be thrown for the folowing line.
-      - one-line version of IF or WHERE statement must be really on one line (no continuation line)
-      - conditional part of IF and WHERE statements should be written on a signle line to be parsed
-        correctly.
-      - brackets in comments or in strings can mislead the script
-    """
-    lhschar = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_(:)%, \t'
-
-    if os.path.isdir(path):
-        logging.info("Enters directory: " + path)
-        for filename in glob.glob(os.path.join(path, '*')):
-            verify_mnh_expand(filename)
-    else:
-        logging.debug("Checks filename: " + path)
-        with open(path, 'rb') as f: #read as byte because some files contain non UTF-8 characters
-            lines = f.readlines()
-        inside = False
-        for iline, line in enumerate(lines):
-            line = line.strip()
-            if line[:13] == b'!$mnh_expand_':
-                #New mnh_expand bloc
-                logging.debug('Opening directive found. Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                if inside:
-                    logging.error('New mnh_expand bloc detected whereas we are already in a bloc. ' +
-                                  'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                inside = True
-                open_directive = line[13:].split(b'(')[0]
-                open_args = line[13:].split(b'(')[1].split(b')')[0].replace(b' ', b'')
-                dim = len(line.split(b'(')[1].split(b','))
-                if line[-1:] != b')':
-                    logging.error('Open directive must end with a closing bracket. ' +
-                                  'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-            elif line[:17] == b'!$mnh_end_expand_':
-                #End of a mnh_expand bloc
-                logging.debug('Closing directive found. Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                if not inside:
-                    logging.error('End of a mnh_expand bloc detected whereas we are not in a bloc. ' +
-                                  'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                else:
-                    inside = False
-                    end_directive = line[17:].split(b'(')[0]
-                    end_args = line[17:].split(b'(')[1].split(b')')[0].replace(b' ', b'')
-                    if end_directive != open_directive:
-                        logging.error('The end directive ({enddirect}) is not consistent with the opening directive ({opendirect}). '
-                                      'Line {line} of file {filename}'.format(enddirect=end_directive.decode('UTF-8'),
-                                                                              opendirect=open_directive.decode('UTF-8'),
-                                                                              line=iline + 1, filename=path))
-                    if end_args.upper() != open_args.upper():
-                        logging.error('The end args ({endargs}) are not consistent with the opening args ({openargs}). '
-                                      'Line {line} of file {filename}'.format(endargs=end_args.decode('UTF-8'),
-                                                                              openargs=open_args.decode('UTF-8'),
-                                                                              line=iline + 1, filename=path))
-                    if line[-1:] != b')':
-                        logging.error('Closing directive must end with a closing bracket. ' +
-                                      'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-            elif inside:
-                #We do not want to implement a full fortran parser, we are only interested in the left hand side of
-                #affectation instructions. If left hand side is correct (an array element) the right hand side
-                #will be necessarily correct (otherwise a compilation error will be thrown).
-
-                #Suppresion of conditional statement in 'IF' and 'WHERE' one-line instructions
-                #For simplicity, all conditional statements are suppressed
-                if any([line.startswith(s) for s in (b'IF ', b'IF(',
-                                                     b'ELSEIF ', b'ELSEIF(', b'ELSE IF ', b'ELSE IF(')]):
-                    try:
-                        line = line[line.index(b'(') + 1:]
-                        nb = 1
-                        while nb >= 1 and(len(line) > 0):
-                            if line[:1] == b'(': nb += 1
-                            elif line[:1] == b')': nb -= 1
-                            line = line[1:].strip()
-                        if nb >= 1 and len(line) == 0:
-                            logging.warning('Parsing error during treatment of an IF statement. ' +
-                                            'The closing bracket should be on the same line as the IF keyword. ' +
-                                            'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                        if line.upper()[:5] in (b'THEN ', b'THEN!'): line = line[5:]
-                    except ValueError:
-                        logging.error('Parsing error during treatment of an IF statement. ' +
-                                      'The opening bracket must be on the same line as the IF keyword. ' +
-                                      'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                elif any([line.startswith(s) for s in (b'WHERE ', b'WHERE(',
-                                                     b'ELSEWHERE ', b'ELSEWHERE(', b'ELSE WHERE ', b'ELSE WHERE(')]):
-                    if open_directive != b'where':
-                        logging.error('There is a WHERE statement in a mnh_expand array bloc. '
-                                      'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                    try:
-                        line = line[line.index(b'(') + 1:]
-                        nb = 1
-                        while nb >= 1 and(len(line)>0):
-                            if line[:1] == b'(': nb += 1
-                            elif line[:1] == b')': nb -= 1
-                            line = line[1:].strip()
-                        if nb >= 1 and len(line) == 0:
-                            logging.warning('Parsing error during treatment of a WHERE statement. ' +
-                                            'The closing bracket should be on the same line as the WHERE keyword. ' +
-                                            'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                    except ValueError:
-                        logging.error('Parsing error during treatment of a WHERE statement. ' +
-                                      'The opening bracket must be on the same line as the WHERE keyword. ' +
-                                      'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-
-                #Check if it is the left hand side of an affectation
-                if line[:3].upper() == b'DO ':
-                    logging.warning('A DO loop is inside a mnh_expand bloc, is order correct?. ' +
-                                    'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                elif line[:5].upper() == b'CALL ':
-                    logging.warning('A CALL statement is inside a mnh_expand bloc, is it correct? ' +
-                                    'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                elif b'=' in line and all([c in lhschar for c in line.split(b'=')[0]]):
-                    lhs = line.split(b'=')[0]
-                    if not b'(' in lhs:
-                        logging.error('Array on the left hand side of an effectation instruction must be written ' +
-                                      'with opening and closing brackets. ' + 
-                                      'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                    if lhs.count(b':') != dim:
-                        logging.error('Array on the left hand side of an effectation instruction must have the same ' +
-                                      'number of :-dimensions as the number defined in the directive. ' +
-                                      'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-                    if line[line.index(b'(')-1] in b' \t':
-                        logging.error('There must be no space wetween the array name and the opening bracket in ' +
-                                      'the affectation instruction. ' +
-                                      'Line {line} of file {filename}'.format(line=iline + 1, filename=path))
-
-if __name__ == '__main__':
-    import argparse
-    parser = argparse.ArgumentParser(description='mnh_expand checker')
-    parser.add_argument("-v", "--verbose", dest="verbose", action="count", default=0,
-                        help="Show warning (-v), info (-v -v) or debug (-v -v -v) messages")
-    parser.add_argument('PATH', help="directory to recursively check, or filename")
-    args = parser.parse_args()
-    level = {0:'ERROR',
-             1:'WARNING',
-             2:'INFO',
-             3:'DEBUG'}[args.verbose]
-    logging.basicConfig(level=getattr(logging, level, None))
-    verify_mnh_expand(args.PATH)
-- 
GitLab