From b72c4d1abd465792ec3676f2f13c0fffe139d190 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 8 Feb 2023 14:57:15 +0100
Subject: [PATCH] Juan (+Philippe) 08/02/2023: workaround for gfortran and Cray
 compilers on Adastra

---
 src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90 | 22 ++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90 b/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
index cca90579e..7d98869b4 100644
--- a/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 1994-2022 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 1994-2023 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.
@@ -672,6 +672,7 @@ character(len=16)             :: ysuffix
 integer :: inewsize
 integer :: ji
 integer(kind=CDFINT)  :: istatus
+type(tdimsnc),              pointer     :: tz_tncdims
 type(tdimnc), dimension(:), allocatable :: tzncdims
 
 
@@ -725,9 +726,18 @@ if ( kidx == - 1 ) then
   call Move_alloc( from = tzncdims, to = tpfile%tncdims%tdims )
 #else
   !Do the Move_alloc by hand...
+#if 0
   if ( Allocated( tpfile%tncdims%tdims ) ) Deallocate( tpfile%tncdims%tdims )
   Allocate( tpfile%tncdims%tdims(Size( tzncdims )) )
   tpfile%tncdims%tdims(:) = tzncdims
+#else
+  !Use intermediate pointer to work around problem with gfortran/10.3.0 and Cray/cce/15.0 compilers (on Adastra)
+  !(does not like to modify pointed data if intent(in))
+  tz_tncdims => tpfile%tncdims
+  if ( Allocated( tz_tncdims%tdims ) ) Deallocate( tz_tncdims%tdims )
+  Allocate( tz_tncdims%tdims(Size( tzncdims )) )
+  tz_tncdims%tdims(:) = tzncdims
+#endif
   Deallocate( tzncdims )
 #endif
 
@@ -752,6 +762,7 @@ integer                                 :: idx
 integer                                 :: inewsize
 integer                                 :: ji
 integer(kind=CDFINT)                    :: istatus
+type(tdimsnc),              pointer     :: tz_tncdims
 type(tdimnc), dimension(:), allocatable :: tzncdims
 
 CALL PRINT_MSG(NVERB_DEBUG,'IO','IO_Strdimid_get_nc4','called')
@@ -791,9 +802,18 @@ if ( idx == -1 ) then
   call Move_alloc( from = tzncdims, to = tpfile%tncdims%tdims_str )
 #else
   !Do the Move_alloc by hand...
+#if 0
   if ( Allocated( tpfile%tncdims%tdims_str ) ) Deallocate( tpfile%tncdims%tdims_str )
   Allocate( tpfile%tncdims%tdims_str(Size( tzncdims )) )
   tpfile%tncdims%tdims_str(:) = tzncdims(:)
+#else
+  !Use intermediate pointer to work around problem with gfortran/10.3.0 and Cray/cce/15.0 compilers (on Adastra)
+  !(does not like to modify pointed data if intent(in))
+  tz_tncdims => tpfile%tncdims
+  if ( Allocated( tz_tncdims%tdims_str ) ) Deallocate( tz_tncdims%tdims_str )
+  Allocate( tz_tncdims%tdims_str(Size( tzncdims )) )
+  tz_tncdims%tdims_str(:) = tzncdims
+#endif
   Deallocate( tzncdims )
 #endif
   tpfile%tncdims%nmaxdims_str = inewsize
-- 
GitLab