From d8a35a94a05e96323961c972ab5187bfe4627ba8 Mon Sep 17 00:00:00 2001
From: Quentin Rodier <quentin.rodier@meteo.fr>
Date: Fri, 22 Sep 2023 17:07:52 +0200
Subject: [PATCH] Quentin 22/09/2023: PHYEX v0.6.3 merge fix with POSNAM
 modernization and modd_param_ice_n renamed

---
 src/common/micro/modd_nebn.F90          |  9 +++++----
 src/common/micro/modd_param_icen.F90    |  9 +++++----
 src/common/micro/modd_param_lima.F90    |  9 +++++----
 src/common/turb/modd_param_mfshalln.F90 |  9 +++++----
 src/common/turb/modd_turbn.F90          | 10 ++++++----
 src/mesonh/aux/mode_posnam_phy.F90      |  8 ++++----
 6 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/src/common/micro/modd_nebn.F90 b/src/common/micro/modd_nebn.F90
index dce8f1d9a..fdc47f6a3 100644
--- a/src/common/micro/modd_nebn.F90
+++ b/src/common/micro/modd_nebn.F90
@@ -98,7 +98,7 @@ IF(.NOT. ASSOCIATED(NEBN, NEB_MODEL(KTO))) THEN
 ENDIF
 END SUBROUTINE NEB_GOTO_MODEL
 !
-SUBROUTINE NEBN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
+SUBROUTINE NEBN_INIT(HPROGRAM, TFILENAM, LDNEEDNAM, KLUOUT, &
                     &LDDEFAULTVAL, LDREADNAM, LDCHECK, KPRINT)
 !!*** *NEBN_INIT* - Code needed to initialize the MODD_NEB_n module
 !!
@@ -130,6 +130,7 @@ SUBROUTINE NEBN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
 !
 USE MODE_POSNAM_PHY, ONLY: POSNAM_PHY
 USE MODE_CHECK_NAM_VAL, ONLY: CHECK_NAM_VAL_CHAR
+USE MODD_IO,  ONLY: TFILEDATA
 !
 IMPLICIT NONE
 !
@@ -137,7 +138,7 @@ IMPLICIT NONE
 !       ------------------------
 !
 CHARACTER(LEN=6),  INTENT(IN) :: HPROGRAM     !< Name of the calling program
-INTEGER,           INTENT(IN) :: KUNITNML     !< Logical unit to access the namelist
+TYPE(TFILEDATA),   INTENT(IN) :: TFILENAM     !< Namelist file
 LOGICAL,           INTENT(IN) :: LDNEEDNAM    !< True to abort if namelist is absent
 INTEGER,           INTENT(IN) :: KLUOUT       !< Logical unit for outputs
 LOGICAL, OPTIONAL, INTENT(IN) :: LDDEFAULTVAL !< Must we initialize variables with default values (defaults to .TRUE.)
@@ -197,8 +198,8 @@ ENDIF
 !       -----------
 !
 IF(LLREADNAM) THEN
-  CALL POSNAM_PHY(KUNITNML, 'NAM_NEBN', LDNEEDNAM, LLFOUND, KLUOUT)
-  IF(LLFOUND) READ(UNIT=KUNITNML, NML=NAM_NEBn)
+  CALL POSNAM_PHY(TFILENAM, 'NAM_NEBN', LDNEEDNAM, LLFOUND)
+  IF(LLFOUND) READ(UNIT=TFILENAM%NLU, NML=NAM_NEBn)
 ENDIF
 !
 !*      3. CHECKS
diff --git a/src/common/micro/modd_param_icen.F90 b/src/common/micro/modd_param_icen.F90
index 9ea39306b..1113a1d47 100644
--- a/src/common/micro/modd_param_icen.F90
+++ b/src/common/micro/modd_param_icen.F90
@@ -229,7 +229,7 @@ IF(.NOT. ASSOCIATED(PARAM_ICEN, PARAM_ICE_MODEL(KTO))) THEN
 ENDIF
 END SUBROUTINE PARAM_ICE_GOTO_MODEL
 !
-SUBROUTINE PARAM_ICEN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
+SUBROUTINE PARAM_ICEN_INIT(HPROGRAM, TFILENAM, LDNEEDNAM, KLUOUT, &
                           &LDDEFAULTVAL, LDREADNAM, LDCHECK, KPRINT)
 !!*** *PARAM_ICEN_INIT* - Code needed to initialize the MODD_PARAM_ICE_n module
 !!
@@ -262,6 +262,7 @@ SUBROUTINE PARAM_ICEN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
 USE MODE_POSNAM_PHY, ONLY: POSNAM_PHY
 USE MODE_MSG, ONLY: PRINT_MSG, NVERB_FATAL
 USE MODE_CHECK_NAM_VAL, ONLY: CHECK_NAM_VAL_CHAR, CHECK_NAM_VAL_REAL, CHECK_NAM_VAL_INT
+USE MODD_IO,  ONLY: TFILEDATA
 !
 IMPLICIT NONE
 !
@@ -269,7 +270,7 @@ IMPLICIT NONE
 !       ------------------------
 !
 CHARACTER(LEN=6),  INTENT(IN) :: HPROGRAM     !< Name of the calling program
-INTEGER,           INTENT(IN) :: KUNITNML     !< Logical unit to access the namelist
+TYPE(TFILEDATA),   INTENT(IN) :: TFILENAM     !< Namelist file
 LOGICAL,           INTENT(IN) :: LDNEEDNAM    !< True to abort if namelist is absent
 INTEGER,           INTENT(IN) :: KLUOUT       !< Logical unit for outputs
 LOGICAL, OPTIONAL, INTENT(IN) :: LDDEFAULTVAL !< Must we initialize variables with default values (defaults to .TRUE.)
@@ -392,8 +393,8 @@ ENDIF
 !       -----------
 !
 IF(LLREADNAM) THEN
-  CALL POSNAM_PHY(KUNITNML, 'NAM_PARAM_ICEN', LDNEEDNAM, LLFOUND, KLUOUT)
-  IF(LLFOUND) READ(UNIT=KUNITNML, NML=NAM_PARAM_ICEn)
+  CALL POSNAM_PHY(TFILENAM, 'NAM_PARAM_ICEN', LDNEEDNAM, LLFOUND)
+  IF(LLFOUND) READ(UNIT=TFILENAM%NLU, NML=NAM_PARAM_ICEn)
 ENDIF
 !
 !*      3. CHECKS
diff --git a/src/common/micro/modd_param_lima.F90 b/src/common/micro/modd_param_lima.F90
index 3565e1d9a..1ba738383 100644
--- a/src/common/micro/modd_param_lima.F90
+++ b/src/common/micro/modd_param_lima.F90
@@ -557,7 +557,7 @@ SUBROUTINE PARAM_LIMA_ALLOCATE(HNAME, KDIM1, KDIM2, KDIM3)
   END SELECT
 END SUBROUTINE PARAM_LIMA_ALLOCATE
 !
-SUBROUTINE PARAM_LIMA_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
+SUBROUTINE PARAM_LIMA_INIT(HPROGRAM, TFILENAM, LDNEEDNAM, KLUOUT, &
                           &LDDEFAULTVAL, LDREADNAM, LDCHECK, KPRINT)
 !!*** *PARAM_ICEN_INIT* - Code needed to initialize the MODD_PARAM_LIMA module
 !!
@@ -590,6 +590,7 @@ SUBROUTINE PARAM_LIMA_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
 USE MODE_POSNAM_PHY, ONLY: POSNAM_PHY
 USE MODE_MSG, ONLY: PRINT_MSG, NVERB_FATAL
 USE MODE_CHECK_NAM_VAL, ONLY: CHECK_NAM_VAL_CHAR
+USE MODD_IO,  ONLY: TFILEDATA
 !
 IMPLICIT NONE
 !
@@ -597,7 +598,7 @@ IMPLICIT NONE
 !       ------------------------
 !
 CHARACTER(LEN=6),  INTENT(IN) :: HPROGRAM     !< Name of the calling program
-INTEGER,           INTENT(IN) :: KUNITNML     !< Logical unit to access the namelist
+TYPE(TFILEDATA),   INTENT(IN) :: TFILENAM     !< Namelist file
 LOGICAL,           INTENT(IN) :: LDNEEDNAM    !< True to abort if namelist is absent
 INTEGER,           INTENT(IN) :: KLUOUT       !< Logical unit for outputs
 LOGICAL, OPTIONAL, INTENT(IN) :: LDDEFAULTVAL !< Must we initialize variables with default values (defaults to .TRUE.)
@@ -700,8 +701,8 @@ ENDIF
 !       -----------
 !
 IF(LLREADNAM) THEN
-  CALL POSNAM_PHY(KUNITNML, 'NAM_PARAM_LIMA', LDNEEDNAM, LLFOUND, KLUOUT)
-  IF(LLFOUND) READ(UNIT=KUNITNML, NML=NAM_PARAM_LIMA)
+  CALL POSNAM_PHY(TFILENAM, 'NAM_PARAM_LIMA', LDNEEDNAM, LLFOUND)
+  IF(LLFOUND) READ(UNIT=TFILENAM%NLU, NML=NAM_PARAM_LIMA)
 ENDIF
 !
 !*      3. CHECKS
diff --git a/src/common/turb/modd_param_mfshalln.F90 b/src/common/turb/modd_param_mfshalln.F90
index 664812c58..6c50a6fe6 100644
--- a/src/common/turb/modd_param_mfshalln.F90
+++ b/src/common/turb/modd_param_mfshalln.F90
@@ -181,7 +181,7 @@ ENDIF
 !
 END SUBROUTINE PARAM_MFSHALL_GOTO_MODEL
 
-SUBROUTINE PARAM_MFSHALLN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
+SUBROUTINE PARAM_MFSHALLN_INIT(HPROGRAM, TFILENAM, LDNEEDNAM, KLUOUT, &
                          &LDDEFAULTVAL, LDREADNAM, LDCHECK, KPRINT)
 !!*** *PARAM_MFSHALLN* - Code needed to initialize the MODD_PARAM_MFSHALL_n module
 !!
@@ -213,6 +213,7 @@ SUBROUTINE PARAM_MFSHALLN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
 !
 USE MODE_POSNAM_PHY, ONLY: POSNAM_PHY
 USE MODE_CHECK_NAM_VAL, ONLY: CHECK_NAM_VAL_CHAR
+USE MODD_IO,  ONLY: TFILEDATA
 !
 IMPLICIT NONE
 !
@@ -220,7 +221,7 @@ IMPLICIT NONE
 !       ------------------------
 !
 CHARACTER(LEN=6),  INTENT(IN) :: HPROGRAM     !< Name of the calling program
-INTEGER,           INTENT(IN) :: KUNITNML     !< Logical unit to access the namelist
+TYPE(TFILEDATA),   INTENT(IN) :: TFILENAM     !< Namelist file
 LOGICAL,           INTENT(IN) :: LDNEEDNAM    !< True to abort if namelist is absent
 INTEGER,           INTENT(IN) :: KLUOUT       !< Logical unit for outputs
 LOGICAL, OPTIONAL, INTENT(IN) :: LDDEFAULTVAL !< Must we initialize variables with default values (defaults to .TRUE.)
@@ -290,8 +291,8 @@ ENDIF
 !       -----------
 !
 IF(LLREADNAM) THEN
-  CALL POSNAM_PHY(KUNITNML, 'NAM_PARAM_MFSHALLN', LDNEEDNAM, LLFOUND, KLUOUT)
-  IF(LLFOUND) READ(UNIT=KUNITNML, NML=NAM_PARAM_MFSHALLn)
+  CALL POSNAM_PHY(TFILENAM, 'NAM_PARAM_MFSHALLN', LDNEEDNAM, LLFOUND)
+  IF(LLFOUND) READ(UNIT=TFILENAM%NLU, NML=NAM_PARAM_MFSHALLn)
 ENDIF
 !
 !*      3. CHECKS
diff --git a/src/common/turb/modd_turbn.F90 b/src/common/turb/modd_turbn.F90
index b4c173c55..9c485f2c5 100644
--- a/src/common/turb/modd_turbn.F90
+++ b/src/common/turb/modd_turbn.F90
@@ -281,7 +281,7 @@ ENDIF
 !
 END SUBROUTINE TURB_GOTO_MODEL
 
-SUBROUTINE TURBN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
+SUBROUTINE TURBN_INIT(HPROGRAM, TFILENAM, LDNEEDNAM, KLUOUT, &
                      &LDDEFAULTVAL, LDREADNAM, LDCHECK, KPRINT)
 !!*** *TURBN_INIT* - Code needed to initialize the MODD_TURB_n module
 !!
@@ -314,6 +314,8 @@ SUBROUTINE TURBN_INIT(HPROGRAM, KUNITNML, LDNEEDNAM, KLUOUT, &
 USE MODE_POSNAM_PHY, ONLY: POSNAM_PHY
 USE MODE_CHECK_NAM_VAL, ONLY: CHECK_NAM_VAL_CHAR
 USE MODD_PARAMETERS, ONLY: XUNDEF
+USE MODD_IO,  ONLY: TFILEDATA
+
 !
 IMPLICIT NONE
 !
@@ -321,7 +323,7 @@ IMPLICIT NONE
 !       ------------------------
 !
 CHARACTER(LEN=6),  INTENT(IN) :: HPROGRAM     !< Name of the calling program
-INTEGER,           INTENT(IN) :: KUNITNML     !< Logical unit to access the namelist
+TYPE(TFILEDATA),   INTENT(IN) :: TFILENAM     !< Namelist file
 LOGICAL,           INTENT(IN) :: LDNEEDNAM    !< True to abort if namelist is absent
 INTEGER,           INTENT(IN) :: KLUOUT       !< Logical unit for outputs
 LOGICAL, OPTIONAL, INTENT(IN) :: LDDEFAULTVAL !< Must we initialize variables with default values (defaults to .TRUE.)
@@ -404,8 +406,8 @@ ENDIF
 !       -----------
 !
 IF(LLREADNAM) THEN
-  CALL POSNAM_PHY(KUNITNML, 'NAM_TURBN', LDNEEDNAM, LLFOUND, KLUOUT) 
-  IF(LLFOUND) READ(UNIT=KUNITNML, NML=NAM_TURBn) 
+  CALL POSNAM_PHY(TFILENAM, 'NAM_TURBN', LDNEEDNAM, LLFOUND) 
+  IF(LLFOUND) READ(UNIT=TFILENAM%NLU, NML=NAM_TURBn) 
 ENDIF
 !
 !*      3. CHECKS
diff --git a/src/mesonh/aux/mode_posnam_phy.F90 b/src/mesonh/aux/mode_posnam_phy.F90
index 692ade326..5f5f47b58 100644
--- a/src/mesonh/aux/mode_posnam_phy.F90
+++ b/src/mesonh/aux/mode_posnam_phy.F90
@@ -3,22 +3,22 @@ IMPLICIT NONE
 PRIVATE
 PUBLIC :: POSNAM_PHY
 CONTAINS
-SUBROUTINE POSNAM_PHY(KULNAM, CDNAML, LDNEEDNAM, LDFOUND, KLUOUT)
+SUBROUTINE POSNAM_PHY(TFILENAM, CDNAML, LDNEEDNAM, LDFOUND)
 
 !Wrapper to call the Meso-NH version of posnam
 
 USE MODE_MSG, ONLY: NVERB_FATAL, PRINT_MSG
 USE MODE_POS, ONLY: POSNAM
+USE MODD_IO,  ONLY: TFILEDATA
 
 IMPLICIT NONE
 
-INTEGER,          INTENT(IN)    :: KULNAM    !< Logical unit to access the namelist
+TYPE(TFILEDATA),  INTENT(IN)    :: TFILENAM    !< Namelist file
 CHARACTER(LEN=*), INTENT(IN)    :: CDNAML    !< Namelist name
 LOGICAL,          INTENT(IN)    :: LDNEEDNAM !< True to abort if namelist is absent
 LOGICAL,          INTENT(OUT)   :: LDFOUND   !< True if namelist has been found
-INTEGER,          INTENT(IN)    :: KLUOUT    !< Logical unit for output
 
-CALL POSNAM(KULNAM, CDNAML, LDFOUND, KLUOUT)
+CALL POSNAM(TFILENAM, CDNAML, LDFOUND)
 IF(LDNEEDNAM .AND. .NOT. LDFOUND) CALL PRINT_MSG(NVERB_FATAL, 'GEN', 'POSNAM_PHY', 'CANNOT LOCATE '//CDNAML)
 
 END SUBROUTINE POSNAM_PHY
-- 
GitLab