From b66db5da7050eb1eced29cf773ee823a22e398b2 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Thu, 23 May 2024 16:12:01 +0200
Subject: [PATCH] Philippe 23/05/2024: outputs: do not write box metadata in
 Z-split files (box data is not written in them)

---
 .../SURCOUCHE/src/mode_io_manage_struct.f90   |  5 ++
 src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90   | 57 ++++++++++---------
 2 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90 b/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90
index b3af57c57..020cb37a8 100644
--- a/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io_manage_struct.f90
@@ -1169,6 +1169,7 @@ USE MODD_CONFZ,          ONLY: NB_PROCIO_R, NB_PROCIO_W
 USE MODD_DYN_n,          ONLY: DYN_MODEL
 USE MODD_IO,             ONLY: LDIAG_REDUCE_FLOAT_PRECISION, LIO_COMPRESS, NIO_COMPRESS_LEVEL
 USE MODD_NESTING,        ONLY: NDAD
+USE MODD_OUT_n,          ONLY: OUT_MODEL
 !
 USE MODE_MODELN_HANDLER, ONLY: GET_CURRENT_MODEL_INDEX
 USE MODE_TOOLS,          ONLY: UPCASE
@@ -1345,6 +1346,10 @@ else
       ! MNH/MNHBACKUP/MNHOUTPUT
       !Remark: 'MNH' is more general than MNHBACKUP and could be in fact a MNHBACKUP file
       gsplit_ioz = .true.
+
+      ! Disable Z-split files for output files with no write of the main domain
+      ! Boxes/subdomains are assumed to be too small to be usefully split vertically
+      if ( htype == 'MNHOUTPUT' .and. .not. out_model(imi)%lout_bigbox_write ) gsplit_ioz = .false.
     end if
   end if
 end if
diff --git a/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90 b/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
index 904c8651e..59289e953 100644
--- a/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
@@ -407,33 +407,36 @@ if ( tpfile%ctype == 'MNHOUTPUT' ) then
   Allocate( tpfile%nboxncid  (nout_nboxes) )
   Allocate( tpfile%tboxncdims(nout_nboxes) )
 
-  !Loop on the boxes
-  do jbox = 1, nout_nboxes
-    !Create the HDF group for each box
-    tpfile%nboxncid(jbox) = IO_Box_group_create_nc4( tpfile, tout_boxes(jbox) )
-
-    !Allocate dimension list
-    tpfile%tboxncdims(jbox)%nmaxdims = NMNHDIM_BOX_LAST_ENTRY - NMNHDIM_BOX_FIRST_ENTRY + 1
-    Allocate( tpfile%tboxncdims(jbox)%tdims(NMNHDIM_BOX_FIRST_ENTRY:NMNHDIM_BOX_LAST_ENTRY) )
-
-    !Write the box dimensions
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NI,      'ni',      tout_boxes(jbox)%nisup-tout_boxes(jbox)%niinf+1 )
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NI_U,    'ni_u',    tout_boxes(jbox)%nisup-tout_boxes(jbox)%niinf+1 )
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NI_V,    'ni_v',    tout_boxes(jbox)%nisup-tout_boxes(jbox)%niinf+1 )
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NJ,      'nj',      tout_boxes(jbox)%njsup-tout_boxes(jbox)%njinf+1 )
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NJ_U,    'nj_u',    tout_boxes(jbox)%njsup-tout_boxes(jbox)%njinf+1 )
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NJ_V,    'nj_v',    tout_boxes(jbox)%njsup-tout_boxes(jbox)%njinf+1 )
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_LEVEL,   'level',   tout_boxes(jbox)%nksup-tout_boxes(jbox)%nkinf+1 )
-    call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_LEVEL_W, 'level_w', tout_boxes(jbox)%nksup-tout_boxes(jbox)%nkinf+1 )
-
-    !Write the box attributes
-    call IO_box_attribute_write_nc4( tpfile, jbox, 'min_I_index_in_physical_domain', tout_boxes(jbox)%niinf )
-    call IO_box_attribute_write_nc4( tpfile, jbox, 'max_I_index_in_physical_domain', tout_boxes(jbox)%nisup )
-    call IO_box_attribute_write_nc4( tpfile, jbox, 'min_J_index_in_physical_domain', tout_boxes(jbox)%njinf )
-    call IO_box_attribute_write_nc4( tpfile, jbox, 'max_J_index_in_physical_domain', tout_boxes(jbox)%njsup )
-    call IO_box_attribute_write_nc4( tpfile, jbox, 'min_K_index_in_physical_domain', tout_boxes(jbox)%nkinf )
-    call IO_box_attribute_write_nc4( tpfile, jbox, 'max_K_index_in_physical_domain', tout_boxes(jbox)%nksup )
-  end do
+  ! Write box informations only in main file (subdomains are not written in the Z-split files)
+  if ( .not. associated( tpfile%tmainfile ) ) then
+    !Loop on the boxes
+    do jbox = 1, nout_nboxes
+      !Create the HDF group for each box
+      tpfile%nboxncid(jbox) = IO_Box_group_create_nc4( tpfile, tout_boxes(jbox) )
+
+      !Allocate dimension list
+      tpfile%tboxncdims(jbox)%nmaxdims = NMNHDIM_BOX_LAST_ENTRY - NMNHDIM_BOX_FIRST_ENTRY + 1
+      Allocate( tpfile%tboxncdims(jbox)%tdims(NMNHDIM_BOX_FIRST_ENTRY:NMNHDIM_BOX_LAST_ENTRY) )
+
+      !Write the box dimensions
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NI,      'ni',      tout_boxes(jbox)%nisup-tout_boxes(jbox)%niinf+1 )
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NI_U,    'ni_u',    tout_boxes(jbox)%nisup-tout_boxes(jbox)%niinf+1 )
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NI_V,    'ni_v',    tout_boxes(jbox)%nisup-tout_boxes(jbox)%niinf+1 )
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NJ,      'nj',      tout_boxes(jbox)%njsup-tout_boxes(jbox)%njinf+1 )
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NJ_U,    'nj_u',    tout_boxes(jbox)%njsup-tout_boxes(jbox)%njinf+1 )
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_NJ_V,    'nj_v',    tout_boxes(jbox)%njsup-tout_boxes(jbox)%njinf+1 )
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_LEVEL,   'level',   tout_boxes(jbox)%nksup-tout_boxes(jbox)%nkinf+1 )
+      call IO_Add_dim_box_nc4( tpfile, jbox, NMNHDIM_BOX_LEVEL_W, 'level_w', tout_boxes(jbox)%nksup-tout_boxes(jbox)%nkinf+1 )
+
+      !Write the box attributes
+      call IO_box_attribute_write_nc4( tpfile, jbox, 'min_I_index_in_physical_domain', tout_boxes(jbox)%niinf )
+      call IO_box_attribute_write_nc4( tpfile, jbox, 'max_I_index_in_physical_domain', tout_boxes(jbox)%nisup )
+      call IO_box_attribute_write_nc4( tpfile, jbox, 'min_J_index_in_physical_domain', tout_boxes(jbox)%njinf )
+      call IO_box_attribute_write_nc4( tpfile, jbox, 'max_J_index_in_physical_domain', tout_boxes(jbox)%njsup )
+      call IO_box_attribute_write_nc4( tpfile, jbox, 'min_K_index_in_physical_domain', tout_boxes(jbox)%nkinf )
+      call IO_box_attribute_write_nc4( tpfile, jbox, 'max_K_index_in_physical_domain', tout_boxes(jbox)%nksup )
+    end do
+  end if
 end if
 
 !Write dimensions used in diachronic files
-- 
GitLab