From 27dce8731842cc7feab7271974b915e9a75d8b05 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Tue, 24 Oct 2017 14:06:29 +0200
Subject: [PATCH] Philippe: 24/10/2017: workaround in PREP_PGD due to NPROC set
 earlier than before (commit 86f22a35d4fb9)

---
 src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90 | 4 ++++
 src/SURFEX/mode_gridtype_conf_proj.F90       | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90 b/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90
index c09b6fd31..9e8fcd46b 100644
--- a/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90
+++ b/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90
@@ -49,6 +49,8 @@ MODULE MODE_SPLITTINGZ_ll
   !
   USE MODE_SPLITTING_ll
   !
+  LOGICAL,SAVE :: LINI_PARAZ = .FALSE. !Useful to know if a call to INI_PARAZ_ll or INI_PARAZ_CHILD_ll has already be done
+  !
 CONTAINS
   !       ################################
   SUBROUTINE INI_PARAZ_ll(KINFO_ll)
@@ -471,6 +473,7 @@ CONTAINS
     !
     DEALLOCATE(TZDZP)
     !
+    LINI_PARAZ = .TRUE.
     !-------------------------------------------------------------------------------
     !
   END SUBROUTINE INI_PARAZ_ll
@@ -860,6 +863,7 @@ CONTAINS
     !
     DEALLOCATE(TZDZP)
     !
+    LINI_PARAZ = .TRUE.
     !-------------------------------------------------------------------------------
     !
     CONTAINS
diff --git a/src/SURFEX/mode_gridtype_conf_proj.F90 b/src/SURFEX/mode_gridtype_conf_proj.F90
index 2e78c77c1..d083f5575 100644
--- a/src/SURFEX/mode_gridtype_conf_proj.F90
+++ b/src/SURFEX/mode_gridtype_conf_proj.F90
@@ -42,6 +42,7 @@ USE MODD_SURF_PAR, ONLY : XUNDEF, NUNDEF
 #ifdef MNH_PARALLEL
 USE MODD_VAR_ll, ONLY : NPROC, IP, MPI_PRECISION, NMNH_COMM_WORLD, YSPLITTING
 USE MODD_MPIF
+USE MODE_SPLITTINGZ_ll, ONLY : LINI_PARAZ
 USE MODE_TOOLS_ll, ONLY : GET_OR_ll
 #endif
 !
@@ -114,7 +115,8 @@ END IF
 #ifdef MNH_PARALLEL
 !get the index of the process with IL>0 that own the southmost and the westmost point
 !then broadcast the value of PDX and PDY at these points
-IF ( NPROC > 1 ) THEN
+!Call this only if INI_PARAZ_ll has already been called (to prevent problemns in GET_OR_ll)
+IF ( NPROC > 1 .AND. LINI_PARAZ) THEN
 ! we need to determine wich processes own the southmost and the westmost point
   CALL GET_OR_ll( YSPLITTING, IXOR, IYOR )
   IF ( IL==0 ) THEN ! we don't consider processes with IL==0
-- 
GitLab