From 5c068483ffe7895b000ff7c9a75908767a01ade8 Mon Sep 17 00:00:00 2001
From: Quentin Rodier <quentin.rodier@meteo.fr>
Date: Tue, 29 Jun 2021 17:14:30 +0200
Subject: [PATCH] P.Tulet 29/06/2021: SURFEX bugfix, PK%NSIZE_P can be zero
 leading to missing initialization of dust variables + missing logical
 LCH_SURF_EMIS for chemical emission activation

---
 src/SURFEX/compute_isba_parameters.F90 | 4 ++--
 src/SURFEX/init_surf_atmn.F90          | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/SURFEX/compute_isba_parameters.F90 b/src/SURFEX/compute_isba_parameters.F90
index 39fb20dde..9effc18ad 100644
--- a/src/SURFEX/compute_isba_parameters.F90
+++ b/src/SURFEX/compute_isba_parameters.F90
@@ -521,8 +521,8 @@ IF (KSV /= 0) THEN
     !
     IF (CHI%SVI%NDSTEQ >=1) THEN
       !
-      ALLOCATE (DSTK%XSFDST (PK%NSIZE_P, CHI%SVI%NDSTEQ))  !Output array
-      ALLOCATE (DSTK%XSFDSTM(PK%NSIZE_P, CHI%SVI%NDSTEQ))  !Output array
+      ALLOCATE (DSTK%XSFDST (KI, CHI%SVI%NDSTEQ))  !Output array
+      ALLOCATE (DSTK%XSFDSTM(KI, CHI%SVI%NDSTEQ))  !Output array
       DSTK%XSFDST (:,:)  = 0.
       DSTK%XSFDSTM(:,:) = 0.     
       CALL INIT_DST(DSTK, U, HPROGRAM, PK%NSIZE_P, PK%NR_P, PK%XVEGTYPE_PATCH)    
diff --git a/src/SURFEX/init_surf_atmn.F90 b/src/SURFEX/init_surf_atmn.F90
index 2c6c776dc..3c4f61cce 100644
--- a/src/SURFEX/init_surf_atmn.F90
+++ b/src/SURFEX/init_surf_atmn.F90
@@ -404,7 +404,7 @@ ENDIF
 !
  CALL READ_SURF(HPROGRAM,'CH_EMIS',YSC%CHU%LCH_EMIS,IRESP)
 !
-IF (YSC%CHU%LCH_EMIS) THEN
+IF ((YSC%CHU%LCH_EMIS) .AND. (YSC%CHU%LCH_SURF_EMIS)) THEN
   !
   IF ( IVERSION<7 .OR. IVERSION==7 .AND. IBUGFIX<3 ) THEN
     YSC%CHU%CCH_EMIS='AGGR'
-- 
GitLab