From e8190b357a260cb6897ff8c60a60b136dd2ad9b3 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Mon, 5 Feb 2018 16:51:05 +0100
Subject: [PATCH] Philippe 05/02/2018: remove some small problems detected with
 valgrind

---
 src/LIB/SURCOUCHE/src/mode_field.f90  | 2 ++
 src/LIB/SURCOUCHE/src/mode_fm.f90     | 4 ++++
 src/LIB/SURCOUCHE/src/mode_netcdf.f90 | 7 ++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/LIB/SURCOUCHE/src/mode_field.f90 b/src/LIB/SURCOUCHE/src/mode_field.f90
index 2ba86e49f..3e62ade65 100644
--- a/src/LIB/SURCOUCHE/src/mode_field.f90
+++ b/src/LIB/SURCOUCHE/src/mode_field.f90
@@ -3338,6 +3338,7 @@ END IF
 IF (.NOT.ASSOCIATED(CSURF)) THEN
   CALL PRINT_MSG(NVERB_DEBUG,'GEN','ALLOC_FIELD_SCALARS',' CSURF was not associated')
   ALLOCATE(CHARACTER(LEN=4) :: CSURF)
+  CSURF = ''
 END IF
 !
 END SUBROUTINE ALLOC_FIELD_SCALARS
@@ -3426,6 +3427,7 @@ END IF
 IF (.NOT.ASSOCIATED(CSURF)) THEN
   CALL PRINT_MSG(NVERB_DEBUG,'GEN','INI_FIELD_SCALARS',' CSURF was not associated')
   ALLOCATE(CHARACTER(LEN=4) :: CSURF)
+  CSURF = ''
 END IF
 CALL FIND_FIELD_ID_FROM_MNHNAME('SURF',IID,IRESP)
 TFIELDLIST(IID)%TFIELD_C0D(1)%DATA=>CSURF
diff --git a/src/LIB/SURCOUCHE/src/mode_fm.f90 b/src/LIB/SURCOUCHE/src/mode_fm.f90
index 18fd44e58..8134fb55b 100644
--- a/src/LIB/SURCOUCHE/src/mode_fm.f90
+++ b/src/LIB/SURCOUCHE/src/mode_fm.f90
@@ -79,6 +79,9 @@ CALL PRINT_MSG(NVERB_DEBUG,'IO','IO_FILE_OPEN_ll','opening '//TRIM(TPFILE%CNAME)
 !
 IF (.NOT.ASSOCIATED(TPFILE)) CALL PRINT_MSG(NVERB_FATAL,'IO','IO_FILE_OPEN_ll','TPFILE is not associated')
 !
+TZFILE_DES   => NULL()
+TZFILE_DUMMY => NULL()
+!
 TPFILE%NOPEN         = TPFILE%NOPEN + 1
 TPFILE%NOPEN_CURRENT = TPFILE%NOPEN_CURRENT + 1
 !
@@ -275,6 +278,7 @@ IF (.NOT. GCONFIO) THEN
    STOP
 END IF
 
+ININAR = 0
 INPRAR = TPFILE%NLFINPRAR
 IROWF  = 0
 IRESP  = 0
diff --git a/src/LIB/SURCOUCHE/src/mode_netcdf.f90 b/src/LIB/SURCOUCHE/src/mode_netcdf.f90
index 29cd0f9b2..8ed0d895b 100644
--- a/src/LIB/SURCOUCHE/src/mode_netcdf.f90
+++ b/src/LIB/SURCOUCHE/src/mode_netcdf.f90
@@ -322,8 +322,11 @@ SUBROUTINE WRITE_HOR_COORD(TDIM,HLONGNAME,HSTDNAME,HAXIS,PSHIFT,KBOUNDLOW,KBOUND
   END IF
 
   IF (.NOT.TPFILE%LMASTER) THEN
-    IF (PRESENT(PCOORDS)) &
+    IF (PRESENT(PCOORDS)) THEN
+      ALLOCATE(ZTAB(0)) !To prevent false positive with valgrind
+      GALLOC = .TRUE.
       CALL GATHER_XXFIELD(YDIR,PCOORDS,ZTAB,TPFILE%NMASTER_RANK,TPFILE%NMPICOMM)
+    END IF
   ELSE !TPFILE%LMASTER
     ISIZE = TDIM%LEN
     YVARNAME = TRIM(TDIM%NAME)
@@ -401,6 +404,8 @@ SUBROUTINE WRITE_HOR_2DCOORD(PX,PY,HLAT,HLON)
                  ZLAT,ZLON)
 
   IF (.NOT.TPFILE%LMASTER) THEN
+    ALLOCATE(ZTAB1(0,0),ZTAB2(0,0)) !To prevent false positive with valgrind
+    GALLOC1 = .TRUE. ; GALLOC2 = .TRUE.
     CALL GATHER_XYFIELD(ZLAT,ZTAB1,TPFILE%NMASTER_RANK,TPFILE%NMPICOMM)
     CALL GATHER_XYFIELD(ZLON,ZTAB2,TPFILE%NMASTER_RANK,TPFILE%NMPICOMM)
   ELSE !TPFILE%LMASTER
-- 
GitLab