From 52e87dc114388a67afde0797b17817e8d1f22c8d Mon Sep 17 00:00:00 2001
From: JorisP <pianezze.joris@gmail.com>
Date: Thu, 11 Jul 2024 15:23:51 +0200
Subject: [PATCH] Bugfix for sea salt emission in case of wave coupling

---
 src/SURFEX/coupling_seaflux_orogn.F90          | 2 +-
 src/SURFEX/coupling_seaflux_sbln.F90           | 2 +-
 src/SURFEX/coupling_seafluxn.F90               | 9 +++++----
 src/SURFEX/coupling_sean.F90                   | 2 +-
 src/SURFEX/coupling_surf_atm_multi_level_n.F90 | 2 +-
 src/SURFEX/coupling_surf_atmn.F90              | 2 +-
 6 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/SURFEX/coupling_seaflux_orogn.F90 b/src/SURFEX/coupling_seaflux_orogn.F90
index 062c04418..fc2325a88 100644
--- a/src/SURFEX/coupling_seaflux_orogn.F90
+++ b/src/SURFEX/coupling_seaflux_orogn.F90
@@ -108,7 +108,7 @@ REAL, DIMENSION(KI), INTENT(IN)  :: PLW       ! longwave radiation (on horizonta
 !                                             !                                       (W/m2)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPS       ! pressure at atmospheric model surface (Pa)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPA       ! pressure at forcing level             (Pa)
-REAL, DIMENSION(KI), INTENT(IN)  :: PZWS      ! significant sea wave                  (m)
+REAL, DIMENSION(KI), INTENT(INOUT)  :: PZWS   ! significant sea wave                  (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PZS       ! atmospheric model orography           (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PCO2      ! CO2 concentration in the air          (kg/m3)
 REAL, DIMENSION(KI), INTENT(IN)  :: PSNOW     ! snow precipitation                    (kg/m2/s)
diff --git a/src/SURFEX/coupling_seaflux_sbln.F90 b/src/SURFEX/coupling_seaflux_sbln.F90
index 2ec52035e..4d4419796 100644
--- a/src/SURFEX/coupling_seaflux_sbln.F90
+++ b/src/SURFEX/coupling_seaflux_sbln.F90
@@ -128,7 +128,7 @@ REAL, DIMENSION(KI), INTENT(IN)  :: PLW       ! longwave radiation (on horizonta
 !                                             !                                       (W/m2)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPS       ! pressure at atmospheric model surface (Pa)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPA       ! pressure at forcing level             (Pa)
-REAL, DIMENSION(KI), INTENT(IN)  :: PZWS      ! significant sea wave                  (m)
+REAL, DIMENSION(KI), INTENT(INOUT)  :: PZWS   ! significant sea wave                  (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PCO2      ! CO2 concentration in the air          (kg/m3)
 REAL, DIMENSION(KI), INTENT(IN)  :: PSNOW     ! snow precipitation                    (kg/m2/s)
 REAL, DIMENSION(KI), INTENT(IN)  :: PRAIN     ! liquid precipitation                  (kg/m2/s)
diff --git a/src/SURFEX/coupling_seafluxn.F90 b/src/SURFEX/coupling_seafluxn.F90
index f7884913a..8f4bb0f7e 100644
--- a/src/SURFEX/coupling_seafluxn.F90
+++ b/src/SURFEX/coupling_seafluxn.F90
@@ -172,7 +172,7 @@ REAL, DIMENSION(KI), INTENT(IN)  :: PLW       ! longwave radiation (on horizonta
 !                                             !                                       (W/m2)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPS       ! pressure at atmospheric model surface (Pa)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPA       ! pressure at forcing level             (Pa)
-REAL, DIMENSION(KI), INTENT(IN)  :: PZWS      ! significant sea wave                  (m)
+REAL, DIMENSION(KI), INTENT(INOUT)  :: PZWS   ! significant sea wave                  (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PCO2      ! CO2 concentration in the air          (kgCO2/m3)
 REAL, DIMENSION(KI), INTENT(IN)  :: PSNOW     ! snow precipitation                    (kg/m2/s)
 REAL, DIMENSION(KI), INTENT(IN)  :: PRAIN     ! liquid precipitation                  (kg/m2/s)
@@ -358,15 +358,16 @@ ZHS(:) = PZWS(:)
 #ifdef CPLOASIS
 ! HS value from WW3 if activated
 IF (LCPL_WAVE) THEN
-  ZHS(:)=S%XHS(:)
-  ZTP(:)=S%XTP(:)
+  ZHS(:) =S%XHS(:)
+  PZWS(:)=S%XHS(:)
+  ZTP(:) =S%XTP(:)
 ELSE
   ZHS(:)=PZWS(:)
   ZTP(:)=S%XTP(:)
 END IF
 #endif
 ! if HS value is undef : constant value and alert message
-IF (ALL(ZHS==XUNDEF)) THEN
+IF ( (KI/=0) .AND. ALL(ZHS==XUNDEF) ) THEN
 #ifdef SFX_MNH
  ZHS(:) = XZWS_DEFAULT
  WRITE (ILUOUT,*) 'WARNING : no HS values from ECMWF or WW3, then it is initialized to a constant value of XZWS_DEFAULT m'
diff --git a/src/SURFEX/coupling_sean.F90 b/src/SURFEX/coupling_sean.F90
index ca4ae2081..b9efe309f 100644
--- a/src/SURFEX/coupling_sean.F90
+++ b/src/SURFEX/coupling_sean.F90
@@ -105,7 +105,7 @@ REAL, DIMENSION(KI), INTENT(IN)  :: PLW       ! longwave radiation (on horizonta
 !                                             !                                       (W/m2)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPS       ! pressure at atmospheric model surface (Pa)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPA       ! pressure at forcing level             (Pa)
-REAL, DIMENSION(KI), INTENT(IN)  :: PZWS      ! significant sea wave                  (m)
+REAL, DIMENSION(KI), INTENT(INOUT)  :: PZWS   ! significant sea wave                  (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PZS       ! atmospheric model orography           (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PCO2      ! CO2 concentration in the air          (kg/m3)
 REAL, DIMENSION(KI), INTENT(IN)  :: PSNOW     ! snow precipitation                    (kg/m2/s)
diff --git a/src/SURFEX/coupling_surf_atm_multi_level_n.F90 b/src/SURFEX/coupling_surf_atm_multi_level_n.F90
index c820885d1..b8ad581c8 100644
--- a/src/SURFEX/coupling_surf_atm_multi_level_n.F90
+++ b/src/SURFEX/coupling_surf_atm_multi_level_n.F90
@@ -124,7 +124,7 @@ REAL,                INTENT(IN)    :: PTSTEP    ! atmospheric time-step
 REAL, DIMENSION(KI,KLEV), INTENT(IN) :: PZREF   ! height of T,q forcing                 (m)
 REAL, DIMENSION(KI,KLEV), INTENT(IN) :: PUREF   ! height of wind forcing                (m)
 REAL, DIMENSION(KI,KLEV), INTENT(IN) :: PPA     ! pressure at forcing level             (Pa)
-REAL, DIMENSION(KI,KLEV), INTENT(IN) :: PZWS    ! significant sea wave                  (m)
+REAL, DIMENSION(KI,KLEV), INTENT(INOUT) :: PZWS ! significant sea wave                  (m)
 REAL, DIMENSION(KI,KLEV), INTENT(IN) :: PTKE    ! Subgrid turbulent kinetic energy at forcing level (m2/s2)
 REAL, DIMENSION(KI,KLEV), INTENT(IN) :: PTA     ! air temperature forcing               (K)
 REAL, DIMENSION(KI,KLEV), INTENT(IN) :: PQA     ! air humidity forcing                  (kg/m3)
diff --git a/src/SURFEX/coupling_surf_atmn.F90 b/src/SURFEX/coupling_surf_atmn.F90
index a2b8e4d92..a2f7289ce 100644
--- a/src/SURFEX/coupling_surf_atmn.F90
+++ b/src/SURFEX/coupling_surf_atmn.F90
@@ -110,7 +110,7 @@ REAL, DIMENSION(KI), INTENT(IN)  :: PLW       ! longwave radiation (on horizonta
 !                                             !                                       (W/m2)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPS       ! pressure at atmospheric model surface (Pa)
 REAL, DIMENSION(KI), INTENT(IN)  :: PPA       ! pressure at forcing level             (Pa)
-REAL, DIMENSION(KI), INTENT(IN)  :: PZWS      ! significant sea wave                  (m)
+REAL, DIMENSION(KI), INTENT(INOUT)  :: PZWS   ! significant sea wave                  (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PZS       ! atmospheric model orography           (m)
 REAL, DIMENSION(KI), INTENT(IN)  :: PCO2      ! CO2 concentration in the air          (kg/m3)
 REAL, DIMENSION(KI,NIMPUR), INTENT(IN)  :: PIMPWET      ! 
-- 
GitLab