From fbd35b777276013cf5caf0f73ba6ac394ae83fd2 Mon Sep 17 00:00:00 2001
From: Quentin Rodier <quentin.rodier@meteo.fr>
Date: Sat, 26 Feb 2022 00:36:39 +0100
Subject: [PATCH] Quentin 26/02/2022: adapt use of modE instead of modI

---
 src/mesonh/ext/ice_adjust_bis.f90        | 155 +++++++++++++++++++++++
 src/mesonh/ext/lesn.f90                  |   2 +-
 src/mesonh/ext/prep_ideal_case.f90       |   2 +-
 src/mesonh/ext/set_rsou.f90              |   2 +-
 src/mesonh/turb/mode_prandtl.f90         |   4 +-
 src/mesonh/turb/turb_hor_sv_corr.f90     |   4 +-
 src/mesonh/turb/turb_hor_thermo_corr.f90 |   4 +-
 7 files changed, 164 insertions(+), 9 deletions(-)
 create mode 100644 src/mesonh/ext/ice_adjust_bis.f90

diff --git a/src/mesonh/ext/ice_adjust_bis.f90 b/src/mesonh/ext/ice_adjust_bis.f90
new file mode 100644
index 000000000..b5352ca07
--- /dev/null
+++ b/src/mesonh/ext/ice_adjust_bis.f90
@@ -0,0 +1,155 @@
+!MNH_LIC Copyright 2012-2019 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.
+!-----------------------------------------------------------------
+!     ######spl
+     MODULE MODI_ICE_ADJUST_BIS
+!    ###############################
+!
+INTERFACE
+!
+!     #################################################################
+      SUBROUTINE ICE_ADJUST_BIS(PP,PTH,PR)
+!     #################################################################
+!
+!!               
+!*               1.1  Declaration of Arguments
+!! 
+
+REAL, DIMENSION(:,:,:),  INTENT(IN)     :: PP     ! Pressure
+REAL, DIMENSION(:,:,:),  INTENT(INOUT)  :: PTH    ! thetal to transform into th
+REAL, DIMENSION(:,:,:,:),INTENT(INOUT)  :: PR     ! Total mixing ratios to transform into rv,rc and ri
+!
+END SUBROUTINE ICE_ADJUST_BIS
+
+END INTERFACE
+!
+END MODULE MODI_ICE_ADJUST_BIS
+!     ######spl
+      SUBROUTINE ICE_ADJUST_BIS(PP,PTH,PR)
+!     #################################################################
+!
+!
+!!****  *ICE_ADJUST_BIS* - computes an adjusted state of thermodynamical variables
+!!
+!!    PURPOSE
+!!    -------
+!!
+!!**  METHOD
+!!    ------
+!!
+!!
+!!    EXTERNAL
+!!    --------
+!!
+!!    IMPLICIT ARGUMENTS
+!!    ------------------
+!!
+!!
+!!    REFERENCE
+!!    ---------
+!!
+!!    AUTHOR
+!!    ------
+!!      Valery Masson & C. Lac * Meteo-France *
+!!
+!!    MODIFICATIONS
+!!    -------------
+!!      Original         09/2012
+!!      M.Moge           08/2015 UPDATE_HALO_ll on PTH, ZRV, ZRC, ZRI
+!  P. Wautelet 20/05/2019: add name argument to ADDnFIELD_ll + new ADD4DFIELD_ll subroutine
+!!
+!! --------------------------------------------------------------------------
+!
+!*      0. DECLARATIONS
+!          ------------
+!
+USE MODD_CST, ONLY : XCPD, XRD, XP00
+!
+USE MODI_COMPUTE_FUNCTION_THERMO
+USE MODE_TH_R_FROM_THL_RT_3D
+USE MODI_THLRT_FROM_THRVRCRI
+!
+USE MODE_ll
+!
+IMPLICIT NONE
+!
+!
+!*      0.1  declarations of arguments
+!
+REAL, DIMENSION(:,:,:),  INTENT(IN)     :: PP    ! Pressure
+REAL, DIMENSION(:,:,:),  INTENT(INOUT)  :: PTH   ! thetal to transform into th
+REAL, DIMENSION(:,:,:,:),INTENT(INOUT)  :: PR    ! Total mixing ratios to transform into rv,rc and ri
+!
+!-------------------------------------------------------------------------------
+!
+!       0.2  declaration of local variables
+REAL, DIMENSION(SIZE(PTH,1),SIZE(PTH,2),SIZE(PTH,3)) :: ZTHL, ZRW, ZRV, ZRC, &
+                                                        ZRI, ZWORK
+REAL, DIMENSION(SIZE(PTH,1),SIZE(PTH,2),SIZE(PTH,3)) :: ZFRAC_ICE, ZRSATW, ZRSATI
+REAL, DIMENSION(SIZE(PTH,1),SIZE(PTH,2),SIZE(PTH,3)) :: ZT, ZEXN, ZLVOCPEXN,ZLSOCPEXN
+INTEGER :: IRR
+CHARACTER(LEN=1) :: YFRAC_ICE
+!
+INTEGER :: IINFO_ll
+TYPE(LIST_ll), POINTER :: TZFIELDS_ll=>NULL()   ! list of fields to exchange
+!----------------------------------------------------------------------------
+!
+!*      1 Initialisation
+!         --------------
+!
+IRR = SIZE(PR,4)
+!
+ZRV(:,:,:)=0.
+IF (IRR>=1) &
+ZRV(:,:,:)=PR(:,:,:,1)
+ZRC(:,:,:)=0.
+IF (IRR>=2) &
+ZRC(:,:,:)=PR(:,:,:,2)
+ZRI(:,:,:)=0.
+IF (IRR>=4) &
+ZRI(:,:,:)=PR(:,:,:,4)
+!
+YFRAC_ICE='T'
+ZFRAC_ICE(:,:,:) = 0.
+!
+!*      2 Computation
+!         -----------
+!
+ZEXN(:,:,:)=(PP(:,:,:)/XP00)**(XRD/XCPD)
+!
+CALL COMPUTE_FUNCTION_THERMO( IRR,                                &
+                              PTH, PR, ZEXN, PP,                  &
+                              ZT,ZLVOCPEXN,ZLSOCPEXN              )
+
+!
+CALL THLRT_FROM_THRVRCRI( IRR, PTH, PR, ZLVOCPEXN, ZLSOCPEXN,&
+                          ZTHL, ZRW                          )
+!
+CALL TH_R_FROM_THL_RT_3D(YFRAC_ICE,ZFRAC_ICE(:,:,:),PP(:,:,:), &
+                         ZTHL(:,:,:), ZRW(:,:,:), PTH(:,:,:),  &
+                         ZRV(:,:,:), ZRC(:,:,:), ZRI(:,:,:),   &
+                         ZRSATW(:,:,:), ZRSATI(:,:,:)          )
+CALL ADD3DFIELD_ll( TZFIELDS_ll, PTH, 'ICE_ADJUST_BIS::PTH')
+IF (IRR>=1) THEN
+  CALL ADD3DFIELD_ll( TZFIELDS_ll, ZRV, 'ICE_ADJUST_BIS::ZRV' )
+ENDIF
+IF (IRR>=2) THEN
+  CALL ADD3DFIELD_ll( TZFIELDS_ll, ZRC, 'ICE_ADJUST_BIS::ZRC' )
+ENDIF
+IF (IRR>=4) THEN
+  CALL ADD3DFIELD_ll( TZFIELDS_ll, ZRI, 'ICE_ADJUST_BIS::ZRI' )
+ENDIF
+CALL UPDATE_HALO_ll(TZFIELDS_ll,IINFO_ll)
+CALL CLEANLIST_ll(TZFIELDS_ll)
+!
+
+IF (IRR>=1) &
+PR(:,:,:,1) = ZRV(:,:,:)
+IF (IRR>=2) &
+PR(:,:,:,2) = ZRC(:,:,:)
+IF (IRR>=4) &
+PR(:,:,:,4) = ZRI(:,:,:)
+!
+END SUBROUTINE ICE_ADJUST_BIS
diff --git a/src/mesonh/ext/lesn.f90 b/src/mesonh/ext/lesn.f90
index 129929246..acd15c8ed 100644
--- a/src/mesonh/ext/lesn.f90
+++ b/src/mesonh/ext/lesn.f90
@@ -83,7 +83,7 @@ USE MODI_THL_RT_FROM_TH_R
 USE MODI_LES_RES_TR
 USE MODI_BUDGET_FLAGS
 USE MODI_LES_BUDGET_TEND_n
-USE MODI_BL_DEPTH_DIAG
+USE MODE_BL_DEPTH_DIAG
 !
 USE MODE_ll
 USE MODE_MODELN_HANDLER
diff --git a/src/mesonh/ext/prep_ideal_case.f90 b/src/mesonh/ext/prep_ideal_case.f90
index 370e21412..426f11cd1 100644
--- a/src/mesonh/ext/prep_ideal_case.f90
+++ b/src/mesonh/ext/prep_ideal_case.f90
@@ -416,7 +416,7 @@ USE MODD_SUB_MODEL_n
 USE MODE_MNH_TIMING
 USE MODN_CONFZ
 !JUAN
-USE MODI_TH_R_FROM_THL_RT_3D
+USE MODE_TH_R_FROM_THL_RT_3D
 !
 USE MODI_VERSION
 USE MODI_INIT_PGD_SURF_ATM
diff --git a/src/mesonh/ext/set_rsou.f90 b/src/mesonh/ext/set_rsou.f90
index c0aca1504..757640a6b 100644
--- a/src/mesonh/ext/set_rsou.f90
+++ b/src/mesonh/ext/set_rsou.f90
@@ -282,7 +282,7 @@ USE MODI_PRESS_HEIGHT
 USE MODI_SET_MASS
 USE MODI_SHUMAN
 USE MODI_THETAVPU_THETAVPM
-USE MODI_TH_R_FROM_THL_RT_1D
+USE MODE_TH_R_FROM_THL_RT_1D
 USE MODI_VERT_COORD
 !
 USE NETCDF          ! for reading the NR files 
diff --git a/src/mesonh/turb/mode_prandtl.f90 b/src/mesonh/turb/mode_prandtl.f90
index 964d66938..31d126c08 100644
--- a/src/mesonh/turb/mode_prandtl.f90
+++ b/src/mesonh/turb/mode_prandtl.f90
@@ -150,8 +150,8 @@ USE MODD_IO,             ONLY: TFILEDATA
 USE MODD_PARAMETERS
 !
 USE MODI_GRADIENT_M
-USE MODI_EMOIST
-USE MODI_ETHETA
+USE MODE_EMOIST
+USE MODE_ETHETA
 USE MODI_SHUMAN, ONLY: MZM
 USE MODE_IO_FIELD_WRITE, ONLY: IO_FIELD_WRITE
 !
diff --git a/src/mesonh/turb/turb_hor_sv_corr.f90 b/src/mesonh/turb/turb_hor_sv_corr.f90
index f9e2c7b55..f9f4b2da7 100644
--- a/src/mesonh/turb/turb_hor_sv_corr.f90
+++ b/src/mesonh/turb/turb_hor_sv_corr.f90
@@ -98,8 +98,8 @@ USE MODI_GRADIENT_V
 USE MODI_GRADIENT_W
 USE MODI_SHUMAN 
 USE MODI_LES_MEAN_SUBGRID
-USE MODI_EMOIST
-USE MODI_ETHETA
+USE MODE_EMOIST
+USE MODE_ETHETA
 !
 USE MODI_SECOND_MNH
 !
diff --git a/src/mesonh/turb/turb_hor_thermo_corr.f90 b/src/mesonh/turb/turb_hor_thermo_corr.f90
index b61948676..cf29a349b 100644
--- a/src/mesonh/turb/turb_hor_thermo_corr.f90
+++ b/src/mesonh/turb/turb_hor_thermo_corr.f90
@@ -135,8 +135,8 @@ USE MODI_GRADIENT_W
 USE MODI_SHUMAN 
 USE MODI_LES_MEAN_SUBGRID
 !
-USE MODI_EMOIST
-USE MODI_ETHETA
+USE MODE_EMOIST
+USE MODE_ETHETA
 !
 USE MODI_SECOND_MNH
 !
-- 
GitLab