From 12539249b2ca6043b0c89acabe9536adbffc021f Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 17 Apr 2024 15:00:59 +0200
Subject: [PATCH] Philippe 17/04/2024: output: add attributes for when the main
 domain is written

---
 src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90 | 41 ++++++++++++++++++++-
 1 file changed, 40 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 64286bee2..baa8dc0ab 100644
--- a/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
+++ b/src/LIB/SURCOUCHE/src/mode_io_tools_nc4.f90
@@ -281,7 +281,8 @@ use modd_field,         only: NMNHDIM_NI, NMNHDIM_NJ, NMNHDIM_NI_U, NMNHDIM_NJ_U
 use modd_les,           only: lles_pdf, nles_k, npdf, nspectra_k, xles_temp_mean_start, xles_temp_mean_step, xles_temp_mean_end
 use modd_les_n,         only: nles_times, nspectra_ni, nspectra_nj
 use modd_nsv,           only: nsv
-use modd_out_n,         only: nout_nboxes, tout_boxes
+use modd_out_n,         only: lout_bigbox_write, lout_bal_remove, lout_tal_remove, lout_hor_border_remove, lout_ver_border_remove, &
+                              nout_nboxes, tout_boxes
 USE MODD_PARAMETERS_ll, ONLY: JPHEXT, JPVEXT
 use modd_param_n,       only: crad
 use modd_profiler_n,    only: lprofiler, tprofilers_time
@@ -387,6 +388,15 @@ end if
 
 !Write dimensions used in boxes (subdomains) for MNHOUTPUT files
 if ( tpfile%ctype == 'MNHOUTPUT' ) then
+  !Write attributes of main box (if written)
+  if ( lout_bigbox_write ) then
+    call IO_maindomain_attribute_write_nc4( tpfile, 'Bottom_Absorbing_Layer_removed',       lout_bal_remove )
+    call IO_maindomain_attribute_write_nc4( tpfile, 'Top_Absorbing_Layer_removed',          lout_tal_remove )
+    call IO_maindomain_attribute_write_nc4( tpfile, 'Unphysical_horizontal_layers_removed', lout_hor_border_remove )
+    call IO_maindomain_attribute_write_nc4( tpfile, 'Unphysical_vertical_layers_removed',   lout_ver_border_remove )
+    call IO_maindomain_attribute_write_nc4( tpfile, 'Simplified_physical_limits',           lout_physical_simplified )
+  end if
+
   !Allocate arrays
   Allocate( tpfile%nboxncid  (nout_nboxes) )
   Allocate( tpfile%tboxncdims(nout_nboxes) )
@@ -643,6 +653,35 @@ subroutine IO_box_attribute_write_nc4( tpfile, kbox, hattname, kdata )
 end subroutine IO_box_attribute_write_nc4
 
 
+subroutine IO_maindomain_attribute_write_nc4( tpfile, hattname, odata )
+  use NETCDF,            only: NF90_INQUIRE_ATTRIBUTE, NF90_PUT_ATT, NF90_GLOBAL, NF90_NOERR
+
+  use modd_precision,    only: CDFINT
+
+  type(tfiledata),  intent(in) :: tpfile
+  character(len=*), intent(in) :: hattname
+  logical,          intent(in) :: odata
+
+  character(len=Len(hattname)) :: yattname
+  integer(kind=CDFINT)         :: istatus
+
+  call IO_Mnhname_clean( hattname, yattname )
+
+  istatus = NF90_INQUIRE_ATTRIBUTE( tpfile%nncid, NF90_GLOBAL, yattname )
+  if (istatus == NF90_NOERR ) &
+    call Print_msg( NVERB_ERROR, 'IO', 'IO_maindomain_attribute_write_nc4', 'attribute ' // yattname // ' already exists' )
+
+  if ( odata ) then
+    istatus = NF90_PUT_ATT( tpfile%nncid, NF90_GLOBAL, yattname, 'yes' )
+  else
+    istatus = NF90_PUT_ATT( tpfile%nncid, NF90_GLOBAL, yattname, 'no' )
+  end if
+  if (istatus /= NF90_NOERR ) &
+   call IO_Err_handle_nc4( istatus, 'IO_box_attribute_write_nc4', 'NF90_PUT_ATT', Trim( yattname ) )
+
+end subroutine IO_maindomain_attribute_write_nc4
+
+
 SUBROUTINE IO_Iocdf_dealloc_nc4(tpdimsnc)
 TYPE(tdimsnc),  POINTER :: tpdimsnc
 
-- 
GitLab