From fa732088d521367e73e96da1497707a1743ab6d5 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 6 Jan 2021 11:13:50 +0100
Subject: [PATCH] Philippe 06/01/2021: bugfix in IO_Select_split_file

---
 src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90 | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90 b/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90
index 27e53e864..f19e20238 100644
--- a/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90
@@ -590,6 +590,8 @@ call IO_Field_create_nc4( tzfile, tzfield, kshape = Shape( pfield ), oiscoord =
 istatus = NF90_PUT_VAR(TZFILE%NNCID, IVARID, PFIELD)
 IF (istatus /= NF90_NOERR) CALL IO_Err_handle_nc4(istatus,'IO_Field_write_nc4_X2','NF90_PUT_VAR',trim(TZFIELD%CMNHNAME),KRESP)
 
+if ( Present( kvertlevel ) ) deallocate( tzfield )
+
 END SUBROUTINE IO_Field_write_nc4_X2
 
 
@@ -1133,6 +1135,8 @@ if ( Size( pfield ) > 0 ) then
     call IO_Err_handle_nc4( istatus, 'IO_Field_partial_write_nc4_X2', 'NF90_PUT_VAR', Trim( tzfield%cmnhname ), kresp )
 end if
 
+if ( Present( kvertlevel ) ) deallocate( tzfield )
+
 end subroutine IO_Field_partial_write_nc4_X2
 
 
@@ -1920,6 +1924,7 @@ if ( Present( kvertlevel ) ) then
   Write( ysuffix, '( i4.4 )' ) kvertlevel
   tpfileout => tpfile%tfiles_ioz(kzfile)%tfile
   !Copy the values of tpfield to the pointer tpfieldout (new tfielddata)
+  Allocate( tpfieldout )
   tpfieldout = tpfield
   tpfieldout%cmnhname  = Trim( tpfieldout%cmnhname ) // ysuffix
   if ( Len_trim( tpfieldout%cstdname  ) > 0 )  tpfieldout%cstdname  = Trim( tpfieldout%cstdname  ) // '_at_level_' // ysuffix
-- 
GitLab