From 915a2790b025580ee298eeade8dc30723ff36107 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 24 Aug 2022 16:10:17 +0200
Subject: [PATCH] Philippe 24/08/2022: change MNHVERSION to 5.6.0 and adapt
 conditions when reading older files

---
 src/MNH/ini_deep_convection.f90 |  9 ++++----
 src/MNH/ini_lb.f90              | 39 ++++++++++++++++++---------------
 src/MNH/ini_prog_var.f90        |  7 +++---
 src/MNH/read_field.f90          |  9 ++++----
 src/MNH/spawn_field2.f90        |  9 ++++----
 src/MNH/version.f90             | 10 ++++-----
 6 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/src/MNH/ini_deep_convection.f90 b/src/MNH/ini_deep_convection.f90
index cd57a04d4..187d2e820 100644
--- a/src/MNH/ini_deep_convection.f90
+++ b/src/MNH/ini_deep_convection.f90
@@ -188,10 +188,9 @@ TYPE(TFIELDMETADATA) :: TZFIELD
 !*       2. INITIALIZE CONVECTIVE TENDENCIES
 !	        --------------------------------
 !
-!If TPINIFILE file was written with a MesoNH version < 5.5.1, some variables had different names or were not available
-GOLDFILEFORMAT = (        TPINIFILE%NMNHVERSION(1) < 5                                                                            &
-                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) < 5 )                                      &
-                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) == 5  .AND. TPINIFILE%NMNHVERSION(3) < 1 ) )
+!If TPINIFILE file was written with a MesoNH version < 5.6, some variables had different names or were not available
+GOLDFILEFORMAT = (        TPINIFILE%NMNHVERSION(1) < 5                                       &
+                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) < 6 ) )
 
 PUMFCONV(:,:,:)  = 0.0
 PDMFCONV(:,:,:)  = 0.0
@@ -282,7 +281,7 @@ ELSE
                   ( JSV >= NSV_SLTDEPBEG .AND. JSV <= NSV_SLTDEPEND ) .OR. &
                   ( JSV >= NSV_SNWBEG    .AND. JSV <= NSV_SNWEND    )      ) THEN
           PDSVCONV(:,:,:,JSV) = 0.0
-          GREAD = .FALSE. !This variable was not written in pre-5.5.1 files
+          GREAD = .FALSE. !This variable was not written in pre-5.6 files
         ELSE
           TZFIELD%CMNHNAME   = 'DSVCONV_' // TRIM( TSVLIST(JSV)%CMNHNAME )
           TZFIELD%CLONGNAME  = 'DSVCONV_' // TRIM( TSVLIST(JSV)%CLONGNAME )
diff --git a/src/MNH/ini_lb.f90 b/src/MNH/ini_lb.f90
index c45c50666..a5da9cfcf 100644
--- a/src/MNH/ini_lb.f90
+++ b/src/MNH/ini_lb.f90
@@ -219,6 +219,7 @@ LOGICAL :: GHORELAX_UVWTH  ! switch for the horizontal relaxation for U,V,W,TH i
 LOGICAL :: GHORELAX_TKE    ! switch for the horizontal relaxation for tke in the FM file
 LOGICAL :: GHORELAX_R, GHORELAX_SV ! switch for the horizontal relaxation 
                                    ! for moist and scalar variables
+LOGICAL :: GIS551 ! True if file was written with MNH 5.5.1
 LOGICAL :: GOLDFILEFORMAT
 CHARACTER (LEN= LEN(HGETRVM)), DIMENSION (7) :: YGETRXM ! Arrays with  the get indicators 
                                                         !  for the moist variables
@@ -241,10 +242,10 @@ ENDIF
 !*       1.    SOME INITIALIZATIONS
 !              --------------------
 !
-!If TPINIFILE file was written with a MesoNH version < 5.5.1, some variables had different names or were not available
-GOLDFILEFORMAT = (        TPINIFILE%NMNHVERSION(1) < 5                                                                            &
-                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) < 5 )                                      &
-                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) == 5  .AND. TPINIFILE%NMNHVERSION(3) < 1 ) )
+!If TPINIFILE file was written with a MesoNH version < 5.6, some variables had different names or were not available
+GOLDFILEFORMAT = (        TPINIFILE%NMNHVERSION(1) < 5                                       &
+                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) < 6 ) )
+GIS551 = TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) == 5 .AND. TPINIFILE%NMNHVERSION(3) == 1
 !
 !
 !-------------------------------------------------------------------------------
@@ -488,21 +489,22 @@ DO JSV = 1, NSV
         TZFIELD%CMNHNAME  = 'LBX_' // TRIM( YMNHNAME_BASE  )
         TZFIELD%CLONGNAME = 'LBX_' // TRIM( YLONGNAME_BASE )
 
-        !Some variables were written with an other name in MesoNH < 5.5.1
+        !Some variables were written with an other name in MesoNH < 5.6
         IF ( GOLDFILEFORMAT ) THEN
           IF ( JSV >= 1 .AND. JSV <= NSV_USER ) THEN
             WRITE( TZFIELD%CMNHNAME, '( A6, I3.3 )' ) 'LBXSVM',JSV
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = TRIM( TZFIELD%CMNHNAME )
           ELSE IF ( JSV >= NSV_LIMA_BEG .AND. JSV <= NSV_LIMA_END ) THEN
-            CALL OLD_CMNHNAME_GENERATE_INTERN( TZFIELD%CMNHNAME, TZFIELD%CLONGNAME )
+            ! Name was corrected in MNH 5.5.1
+            IF ( .NOT. GIS551 ) CALL OLD_CMNHNAME_GENERATE_INTERN( TZFIELD%CMNHNAME, TZFIELD%CLONGNAME )
             TZFIELD%CSTDNAME  = ''
           ELSE IF ( JSV >= NSV_PPBEG .AND. JSV <= NSV_PPEND ) THEN
             TZFIELD%CMNHNAME  = 'LBX_PP'
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = 'LBX_PP'
             IF ( JSV == NSV_PPBEG .AND. NSV_PP > 1 ) THEN
-              CMNHMSG(1) = 'reading older file (<5.5.1) for LBX_PP scalar variables'
+              CMNHMSG(1) = 'reading older file (<5.6) for LBX_PP scalar variables'
               CMNHMSG(2) = 'they are bugged: there should be several LBX_PP variables'
               CMNHMSG(3) = 'but they were all written with the same name ''LBX_PP'''
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB' )
@@ -513,7 +515,7 @@ DO JSV = 1, NSV
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = 'LBX_FF'
             IF ( JSV == NSV_FFBEG .AND. NSV_FF > 1 ) THEN
-              CMNHMSG(1) = 'reading older file (<5.5.1) for LBX_FF scalar variables'
+              CMNHMSG(1) = 'reading older file (<5.6) for LBX_FF scalar variables'
               CMNHMSG(2) = 'they are bugged: there should be several LBX_FF variables'
               CMNHMSG(3) = 'but they were all written with the same name ''LBX_FF'''
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB' )
@@ -524,7 +526,7 @@ DO JSV = 1, NSV
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = 'LBX_CS'
             IF ( JSV == NSV_CSBEG .AND. NSV_CS > 1 ) THEN
-              CMNHMSG(1) = 'reading older file (<5.5.1) for LBX_CS scalar variables'
+              CMNHMSG(1) = 'reading older file (<5.6) for LBX_CS scalar variables'
               CMNHMSG(2) = 'they are bugged: there should be several LBX_CS variables'
               CMNHMSG(3) = 'but they were all written with the same name ''LBX_CS'''
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB' )
@@ -543,7 +545,7 @@ DO JSV = 1, NSV
             CALL PRINT_MSG( NVERB_INFO, 'IO', 'INI_LB', 'PLBXSVM is initialized to PLBXSVMM for ' // TRIM( YMNHNAME_BASE ) )
           ELSE
             IF ( GOLDFILEFORMAT .AND. JSV >= NSV_LIMA_BEG .AND. JSV <= NSV_LIMA_END ) THEN
-              !In pre 5.5.1 files, only CCN_FREE and IFN_FREE LIMA scalar variables were available (for LIMA scalar variables)
+              !In pre 5.6 files, only CCN_FREE and IFN_FREE LIMA scalar variables were available (for LIMA scalar variables)
               IF ( JSV >= NSV_LIMA_CCN_FREE .AND. JSV <= (NSV_LIMA_CCN_FREE+NMOD_CCN-1) ) THEN
                 CALL PRINT_MSG( NVERB_FATAL, 'IO', 'INI_LB', 'problem to initialize LIMA CCN_FREE PLBXSVM' )
               ELSE IF ( JSV >= NSV_LIMA_IFN_FREE .AND. JSV <= (NSV_LIMA_IFN_FREE+NMOD_IFN-1) ) THEN
@@ -557,7 +559,7 @@ DO JSV = 1, NSV
                       ( JSV >= NSV_FFBEG  .AND. JSV <= NSV_FFEND ) .OR. &
 #endif
                       ( JSV >= NSV_CSBEG  .AND. JSV <= NSV_CSEND ) .OR. &
-                      ( JSV >= NSV_SNWBEG .AND. JSV <= NSV_SNWEND .AND. GOLDFILEFORMAT ) ) THEN !Snow was not written in <5.5.1
+                      ( JSV >= NSV_SNWBEG .AND. JSV <= NSV_SNWEND .AND. GOLDFILEFORMAT ) ) THEN !Snow was not written in <5.6
               PLBXSVM(:,:,:,JSV) = 0.
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB', 'PLBXSVM is initialized to 0 for ' // TRIM( YMNHNAME_BASE ) )
             ELSE
@@ -571,21 +573,22 @@ DO JSV = 1, NSV
         TZFIELD%CMNHNAME  = 'LBY_' // TRIM( YMNHNAME_BASE  )
         TZFIELD%CLONGNAME = 'LBY_' // TRIM( YLONGNAME_BASE )
 
-        !Some variables were written with an other name in MesoNH < 5.5.1
+        !Some variables were written with an other name in MesoNH < 5.6
         IF ( GOLDFILEFORMAT ) THEN
           IF ( JSV >= 1 .AND. JSV <= NSV_USER ) THEN
             WRITE( TZFIELD%CMNHNAME, '( A6, I3.3 )' ) 'LBYSVM',JSV
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = TRIM( TZFIELD%CMNHNAME )
           ELSE IF ( JSV >= NSV_LIMA_BEG .AND. JSV <= NSV_LIMA_END ) THEN
-            CALL OLD_CMNHNAME_GENERATE_INTERN( TZFIELD%CMNHNAME, TZFIELD%CLONGNAME )
+            ! Name was corrected in MNH 5.5.1
+            IF ( .NOT. GIS551 ) CALL OLD_CMNHNAME_GENERATE_INTERN( TZFIELD%CMNHNAME, TZFIELD%CLONGNAME )
             TZFIELD%CSTDNAME  = ''
           ELSE IF ( JSV >= NSV_PPBEG .AND. JSV <= NSV_PPEND ) THEN
             TZFIELD%CMNHNAME  = 'LBY_PP'
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = 'LBY_PP'
             IF ( JSV == NSV_PPBEG .AND. NSV_PP > 1 ) THEN
-              CMNHMSG(1) = 'reading older file (<5.5.1) for LBY_PP scalar variables'
+              CMNHMSG(1) = 'reading older file (<5.6) for LBY_PP scalar variables'
               CMNHMSG(2) = 'they are bugged: there should be several LBY_PP variables'
               CMNHMSG(3) = 'but they were all written with the same name ''LBY_PP'''
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB' )
@@ -596,7 +599,7 @@ DO JSV = 1, NSV
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = 'LBY_FF'
             IF ( JSV == NSV_FFBEG .AND. NSV_FF > 1 ) THEN
-              CMNHMSG(1) = 'reading older file (<5.5.1) for LBY_FF scalar variables'
+              CMNHMSG(1) = 'reading older file (<5.6) for LBY_FF scalar variables'
               CMNHMSG(2) = 'they are bugged: there should be several LBY_FF variables'
               CMNHMSG(3) = 'but they were all written with the same name ''LBY_FF'''
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB' )
@@ -607,7 +610,7 @@ DO JSV = 1, NSV
             TZFIELD%CSTDNAME  = ''
             TZFIELD%CLONGNAME = 'LBY_CS'
             IF ( JSV == NSV_CSBEG .AND. NSV_CS > 1 ) THEN
-              CMNHMSG(1) = 'reading older file (<5.5.1) for LBY_CS scalar variables'
+              CMNHMSG(1) = 'reading older file (<5.6) for LBY_CS scalar variables'
               CMNHMSG(2) = 'they are bugged: there should be several LBY_CS variables'
               CMNHMSG(3) = 'but they were all written with the same name ''LBY_CS'''
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB' )
@@ -625,7 +628,7 @@ DO JSV = 1, NSV
             CALL PRINT_MSG( NVERB_INFO, 'IO', 'INI_LB', 'PLBYSVM is initialized to PLBYSVMM for ' // TRIM( YMNHNAME_BASE ) )
           ELSE
             IF ( GOLDFILEFORMAT .AND. JSV >= NSV_LIMA_BEG .AND. JSV <= NSV_LIMA_END ) THEN
-              !In pre 5.5.1 files, only CCN_FREE and IFN_FREE LIMA scalar variables were available (for LIMA scalar variables)
+              !In pre 5.6 files, only CCN_FREE and IFN_FREE LIMA scalar variables were available (for LIMA scalar variables)
               IF ( JSV >= NSV_LIMA_CCN_FREE .AND. JSV <= (NSV_LIMA_CCN_FREE+NMOD_CCN-1) ) THEN
                 CALL PRINT_MSG( NVERB_FATAL, 'IO', 'INI_LB', 'problem to initialize LIMA CCN_FREE PLBYSVM' )
               ELSE IF ( JSV >= NSV_LIMA_IFN_FREE .AND. JSV <= (NSV_LIMA_IFN_FREE+NMOD_IFN-1) ) THEN
@@ -639,7 +642,7 @@ DO JSV = 1, NSV
                       ( JSV >= NSV_FFBEG  .AND. JSV <= NSV_FFEND ) .OR. &
 #endif
                       ( JSV >= NSV_CSBEG  .AND. JSV <= NSV_CSEND ) .OR. &
-                      ( JSV >= NSV_SNWBEG .AND. JSV <= NSV_SNWEND .AND. GOLDFILEFORMAT ) ) THEN !Snow was not written in <5.5.1
+                      ( JSV >= NSV_SNWBEG .AND. JSV <= NSV_SNWEND .AND. GOLDFILEFORMAT ) ) THEN !Snow was not written in <5.6
               PLBYSVM(:,:,:,JSV) = 0.
               CALL PRINT_MSG( NVERB_WARNING, 'IO', 'INI_LB', 'PLBYSVM is initialized to 0 for ' // TRIM( YMNHNAME_BASE ) )
             ELSE
diff --git a/src/MNH/ini_prog_var.f90 b/src/MNH/ini_prog_var.f90
index 3a60efc9a..d21746e6d 100644
--- a/src/MNH/ini_prog_var.f90
+++ b/src/MNH/ini_prog_var.f90
@@ -215,10 +215,9 @@ IF(PRESENT(HCHEMFILE)) THEN
   CALL IO_File_add2list(TZCHEMFILE,TRIM(HCHEMFILE),'MNH','READ',KLFITYPE=2,KLFIVERB=NVERB)
   CALL IO_File_open(TZCHEMFILE)
 
-  !If TZCHEMFILE file was written with a MesoNH version < 5.5.1, some variables had different names (or were not available)
-  GOLDFILEFORMAT = ( TZCHEMFILE%NMNHVERSION(1) < 5                                                                              &
-              .OR. ( TZCHEMFILE%NMNHVERSION(1) == 5 .AND. TZCHEMFILE%NMNHVERSION(2) < 5 )                                       &
-              .OR. ( TZCHEMFILE%NMNHVERSION(1) == 5 .AND. TZCHEMFILE%NMNHVERSION(2) == 5  .AND. TZCHEMFILE%NMNHVERSION(3) < 1 ) )
+  !If TZCHEMFILE file was written with a MesoNH version < 5.6, some variables had different names (or were not available)
+  GOLDFILEFORMAT = ( TZCHEMFILE%NMNHVERSION(1) < 5                                        &
+              .OR. ( TZCHEMFILE%NMNHVERSION(1) == 5 .AND. TZCHEMFILE%NMNHVERSION(2) < 6 ) )
 
   ILUDES = TZCHEMFILE%TDESFILE%NLU
   !
diff --git a/src/MNH/read_field.f90 b/src/MNH/read_field.f90
index 8b72ffd03..1a40d1797 100644
--- a/src/MNH/read_field.f90
+++ b/src/MNH/read_field.f90
@@ -425,10 +425,9 @@ TYPE(TFIELDMETADATA)         :: TZFIELD
 GLSOURCE=.FALSE.
 ZWORK = 0.0
 !
-!If TPINIFILE file was written with a MesoNH version < 5.5.1, some variables had different names or were not available
-GOLDFILEFORMAT = (        TPINIFILE%NMNHVERSION(1) < 5                                                                            &
-                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) < 5 )                                      &
-                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) == 5  .AND. TPINIFILE%NMNHVERSION(3) < 1 ) )
+!If TPINIFILE file was written with a MesoNH version < 5.6, some variables had different names or were not available
+GOLDFILEFORMAT = (        TPINIFILE%NMNHVERSION(1) < 5                                       &
+                   .OR. ( TPINIFILE%NMNHVERSION(1) == 5 .AND. TPINIFILE%NMNHVERSION(2) < 6 ) )
 !-------------------------------------------------------------------------------
 !
 !*       2.    READ PROGNOSTIC VARIABLES
@@ -821,7 +820,7 @@ DO JSV = 1, NSV              ! initialize according to the get indicators
              ( JSV >= NSV_FFBEG .AND. JSV <= NSV_FFEND ) .OR. &
 #endif
              ( JSV >= NSV_CSBEG .AND. JSV <= NSV_CSEND )      ) THEN
-          !Some variables were written with an other name in MesoNH < 5.5.1
+          !Some variables were written with an other name in MesoNH < 5.6
           WRITE(TZFIELD%CMNHNAME,'(A3,I3.3)')'SVT',JSV
           TZFIELD%CLONGNAME  = TRIM(TZFIELD%CMNHNAME)
           TZFIELD%CSTDNAME   = ''
diff --git a/src/MNH/spawn_field2.f90 b/src/MNH/spawn_field2.f90
index ccd4ceaea..50047fb02 100644
--- a/src/MNH/spawn_field2.f90
+++ b/src/MNH/spawn_field2.f90
@@ -279,10 +279,9 @@ CALL GOTO_MODEL(2)
 CALL GO_TOMODEL_ll(2, IINFO_ll)
 
 IF (PRESENT(TPSONFILE)) THEN
-  !If TPSONFILE file was written with a MesoNH version < 5.5.1, some variables had different names or were not available
-  GOLDFILEFORMAT = (      TPSONFILE%NMNHVERSION(1) < 5                                                                            &
-                   .OR. ( TPSONFILE%NMNHVERSION(1) == 5 .AND. TPSONFILE%NMNHVERSION(2) < 5 )                                      &
-                   .OR. ( TPSONFILE%NMNHVERSION(1) == 5 .AND. TPSONFILE%NMNHVERSION(2) == 5  .AND. TPSONFILE%NMNHVERSION(3) < 1 ) )
+  !If TPSONFILE file was written with a MesoNH version < 5.6, some variables had different names or were not available
+  GOLDFILEFORMAT = (      TPSONFILE%NMNHVERSION(1) < 5                                      &
+                   .OR. ( TPSONFILE%NMNHVERSION(1) == 5 .AND. TPSONFILE%NMNHVERSION(2) <6 ) )
 END IF
 !
 !*       1.0  recovers logical unit number of output listing
@@ -843,7 +842,7 @@ IF (PRESENT(TPSONFILE)) THEN
            ( JSV >= NSV_FFBEG .AND. JSV <= NSV_FFEND ) .OR. &
 #endif
            ( JSV >= NSV_CSBEG .AND. JSV <= NSV_CSEND )      ) THEN
-        !Some variables were written with an other name in MesoNH < 5.5.1
+        !Some variables were written with an other name in MesoNH < 5.6
         WRITE(TZFIELD%CMNHNAME,'(A3,I3.3)')'SVT',JSV
         TZFIELD%CLONGNAME  = TRIM(TZFIELD%CMNHNAME)
         TZFIELD%CSTDNAME   = ''
diff --git a/src/MNH/version.f90 b/src/MNH/version.f90
index 5c98f1946..c8283e723 100644
--- a/src/MNH/version.f90
+++ b/src/MNH/version.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 2002-2021 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 2002-2022 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -43,10 +43,10 @@ USE MODD_CONF, ONLY : NMNHVERSION,NMASDEV,NBUGFIX,CBIBUSER
 IMPLICIT NONE
 !
 NMNHVERSION(1)=5
-NMNHVERSION(2)=5
-NMNHVERSION(3)=1
-NMASDEV=55
-NBUGFIX=1
+NMNHVERSION(2)=6
+NMNHVERSION(3)=0
+NMASDEV=56
+NBUGFIX=0
 CBIBUSER=''
 !
 END SUBROUTINE VERSION
-- 
GitLab