From ee2229e9900d4306db926829a73eab45c91eb390 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 26 May 2021 16:31:39 +0200
Subject: [PATCH] Philippe 26/05/2021: budgets: add comments to clarify
 usage/choice in metadata for diachronic entries

---
 src/MNH/mode_les_diachro.f90       | 25 +++++++++++++++++++++++++
 src/MNH/write_aircraft_balloon.f90 | 14 ++++++++++++++
 src/MNH/write_budget.f90           | 10 +++++++++-
 src/MNH/write_diachro.f90          | 10 ++--------
 src/MNH/write_profilern.f90        |  9 +++++++++
 src/MNH/write_seriesn.f90          |  6 ++++--
 src/MNH/write_stationn.f90         |  5 +++++
 7 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/src/MNH/mode_les_diachro.f90 b/src/MNH/mode_les_diachro.f90
index 489e35fff..ba8129e71 100644
--- a/src/MNH/mode_les_diachro.f90
+++ b/src/MNH/mode_les_diachro.f90
@@ -1077,6 +1077,7 @@ if ( iresp == 0 .and. any( zfield /= XUNDEF ) ) then
   tzbudiachro%lleveluse(NLVL_NORM)        = .true.
   if ( onorm ) then
     tzbudiachro%clevels  (NLVL_NORM)      = 'Normalized'
+    !Type of normalization is stored in the attribute "normalization" in Write_diachro
     tzbudiachro%ccomments(NLVL_NORM)      = 'Values are normalized'
   else
     tzbudiachro%clevels  (NLVL_NORM)      = 'Not normalized'
@@ -1104,6 +1105,10 @@ if ( iresp == 0 .and. any( zfield /= XUNDEF ) ) then
   tzbudiachro%nih        = iih
   tzbudiachro%njl        = ijl
   tzbudiachro%njh        = ijh
+  !nkl and nkh values have no real meaning here except if all levels from ikl to ikh are used (and are correctly ordered)
+  !and if xles_altitudes is not used
+  !These values are not written in the netCDF files
+  !These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
   tzbudiachro%nkl        = ikl
   tzbudiachro%nkh        = ikh
 
@@ -1122,6 +1127,8 @@ if ( iresp == 0 .and. any( zfield /= XUNDEF ) ) then
       call Write_diachro( tpdiafile, tzbudiachro, [ tzfields(jp) ], tzdates, zwork6(:,:,:,:,:,jp:jp) )
     end do
   else
+    !Set to the same value ('cart') than for the fields with no mask in Write_les_n
+    !to put the fields in the same position of the netCDF file
     tzbudiachro%clevels(NLVL_MASK) = 'cart'
 
     call Write_diachro( tpdiafile, tzbudiachro, tzfields, tzdates, zwork6 )
@@ -1320,6 +1327,9 @@ else
   tzbudiachro%cdirection = 'J'
 end if
 tzbudiachro%lmobile    = .false.
+!i/j/k compression has no meaning here as it is 2-point correlations
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility with these values
 tzbudiachro%licompress = .false.
 tzbudiachro%ljcompress = .false.
 tzbudiachro%lkcompress = .false.
@@ -1329,6 +1339,9 @@ tzbudiachro%nil        = iil
 tzbudiachro%nih        = iih
 tzbudiachro%njl        = ijl
 tzbudiachro%njh        = ijh
+!nkl and nkh values have no real meaning here
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
 tzbudiachro%nkl        = ikl
 tzbudiachro%nkh        = ikh
 
@@ -1500,6 +1513,9 @@ else
   tzbudiachro%cdirection = 'J'
 end if
 tzbudiachro%lmobile    = .false.
+!i/j/k compression has no meaning here as it is spectrum
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility with these values
 tzbudiachro%licompress = .false.
 tzbudiachro%ljcompress = .false.
 tzbudiachro%lkcompress = .false.
@@ -1509,6 +1525,9 @@ tzbudiachro%nil        = iil
 tzbudiachro%nih        = iih
 tzbudiachro%njl        = ijl
 tzbudiachro%njh        = ijh
+!nkl and nkh values have no real meaning here
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
 tzbudiachro%nkl        = ikl
 tzbudiachro%nkh        = ikh
 
@@ -1556,6 +1575,9 @@ else
   tzbudiachro%cdirection = 'J'
 end if
 tzbudiachro%lmobile    = .false.
+!i/j/k compression has no meaning here as it is spectrum
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility with these values
 tzbudiachro%licompress = .false.
 tzbudiachro%ljcompress = .false.
 tzbudiachro%lkcompress = .false.
@@ -1565,6 +1587,9 @@ tzbudiachro%nil        = iil
 tzbudiachro%nih        = iih
 tzbudiachro%njl        = ijl
 tzbudiachro%njh        = ijh
+!nkl and nkh values have no real meaning here
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
 tzbudiachro%nkl        = ikl
 tzbudiachro%nkh        = ikh
 
diff --git a/src/MNH/write_aircraft_balloon.f90 b/src/MNH/write_aircraft_balloon.f90
index 62df99c8d..e103f1b5b 100644
--- a/src/MNH/write_aircraft_balloon.f90
+++ b/src/MNH/write_aircraft_balloon.f90
@@ -882,12 +882,17 @@ tzbudiachro%ccomments(NLVL_NORM)        = ''
 tzbudiachro%lleveluse(NLVL_MASK)        = .false.
 tzbudiachro%clevels  (NLVL_MASK)        = ''
 tzbudiachro%ccomments(NLVL_MASK)        = ''
+
 tzbudiachro%lmobile    = .true.
+!Compression does not make sense here
 ! tzbudiachro%licompress = NOT SET (default values)
 ! tzbudiachro%ljcompress = NOT SET (default values)
 ! tzbudiachro%lkcompress = NOT SET (default values)
 tzbudiachro%ltcompress = .false.
 tzbudiachro%lnorm      = .false.
+!Boundaries in physical domain does not make sense here (but flyer position does)
+!These values are not written in the netCDF files
+!These values are written in the LFI files
 ! tzbudiachro%nil        = NOT SET (default values)
 ! tzbudiachro%nih        = NOT SET (default values)
 ! tzbudiachro%njl        = NOT SET (default values)
@@ -946,15 +951,24 @@ tzbudiachro%clevels  (NLVL_MASK)        = ''
 tzbudiachro%ccomments(NLVL_MASK)        = ''
 
 tzbudiachro%lmobile    = .true.
+!Compression does not make sense here
+!Keep these values for backward compatibility of LFI files
 tzbudiachro%licompress = .true.
 tzbudiachro%ljcompress = .true.
 tzbudiachro%lkcompress = .false.
 tzbudiachro%ltcompress = .false.
 tzbudiachro%lnorm      = .false.
+!Horizontal boundaries in physical domain does not make sense here (but flyer position does)
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
 tzbudiachro%nil        = 1
 tzbudiachro%nih        = 1
 tzbudiachro%njl        = 1
 tzbudiachro%njh        = 1
+!1->iku includes non-physical levels (IKU=NKMAX+2*JPVEXT)
+!This does not conform to documentation (limits are in the physical domain)
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
 tzbudiachro%nkl        = 1
 tzbudiachro%nkh        = iku
 
diff --git a/src/MNH/write_budget.f90 b/src/MNH/write_budget.f90
index e87e4b0c6..e761b21c9 100644
--- a/src/MNH/write_budget.f90
+++ b/src/MNH/write_budget.f90
@@ -548,7 +548,7 @@ subroutine Store_one_budget_rho( tpdiafile, tpdates, tprhodj, knocompress, prhod
 
   tzbudiachro%lleveluse(NLVL_GROUP)       = .true.
   tzbudiachro%clevels  (NLVL_GROUP)       = 'RhodJ'
-  tzbudiachro%ccomments(NLVL_GROUP)       = ''
+  tzbudiachro%ccomments(NLVL_GROUP)       = 'mass of dry air contained in the mesh cells'
 
   tzbudiachro%lleveluse(NLVL_SHAPE)       = .false.
   if ( ybutype == 'CART' ) then
@@ -587,6 +587,9 @@ subroutine Store_one_budget_rho( tpdiafile, tpdates, tprhodj, knocompress, prhod
   tzbudiachro%lkcompress = lbu_kcp
   tzbudiachro%ltcompress = .true. !Data is temporally averaged
   tzbudiachro%lnorm      = .false.
+  !Boundaries in physical domain does not make sense here if 'MASK'
+  !In that case, these values are not written in the netCDF files
+  !But they are always written in the LFI files. They are kept (in the MASK case) for backward compatibility.
   tzbudiachro%nil        = nbuil
   tzbudiachro%nih        = nbuih
   tzbudiachro%njl        = nbujl
@@ -874,8 +877,13 @@ subroutine Store_one_budget( tpdiafile, tpdates, tpbudget, prhodjn, knocompress,
   tzbudiachro%licompress = lbu_icp
   tzbudiachro%ljcompress = lbu_jcp
   tzbudiachro%lkcompress = lbu_kcp
+  !Remark: ltcompress should be false for INIF and ENDF fields
+  !        but if set to false these fields should be separated and stored somewhere else
   tzbudiachro%ltcompress = .true. !Data is temporally averaged
   tzbudiachro%lnorm      = .false.
+  !Boundaries in physical domain does not make sense here if 'MASK'
+  !In that case, these values are not written in the netCDF files
+  !But they are always written in the LFI files. They are kept (in the MASK case) for backward compatibility.
   tzbudiachro%nil        = nbuil
   tzbudiachro%nih        = nbuih
   tzbudiachro%njl        = nbujl
diff --git a/src/MNH/write_diachro.f90 b/src/MNH/write_diachro.f90
index d0dce9879..0c3eca9ce 100644
--- a/src/MNH/write_diachro.f90
+++ b/src/MNH/write_diachro.f90
@@ -916,6 +916,7 @@ MASTER: if ( isp == tzfile%nmaster_rank) then
          .or. tpbudiachro%clevels(NLVL_GROUP)      == 'TSERIES'                &
          .or. tpbudiachro%clevels(NLVL_GROUP)      == 'ZTSERIES'               &
          .or. tpbudiachro%clevels(NLVL_GROUP)(1:8) == 'XTSERIES'               ) then
+      !Disabled for LES budgets because no real meaning on that case (vertical levels are stored in the level_les variable)
       call Att_write( ylevelname, ilevelid, 'min K index in physical domain', ikl )
       call Att_write( ylevelname, ilevelid, 'max K index in physical domain', ikh )
     end if
@@ -991,10 +992,8 @@ MASTER: if ( isp == tzfile%nmaster_rank) then
     call Att_write( ylevelname, ilevelid, 'masks are stored in variable', tpbudiachro%clevels(NLVL_MASK) )
   end if
 
-
 end if MASTER
 
-
 !Determine the number of dimensions and do some verifications
 do jp = 1, Size( tpfields )
   if ( Any( tpfields(jp)%ndimlist(:) == NMNHDIM_UNKNOWN ) ) &
@@ -1475,14 +1474,9 @@ if ( Present( tpflyer ) ) then
   call IO_Field_write( tzfile, tzfield, tpflyer%y )
 end if
 
-
-
-
-
-
-
 end  subroutine Write_diachro_nc4
 
+
 subroutine Diachro_one_field_write_nc4( tpfile, tpbudiachro, tpfield, pvar, kdims, osplit, odistributed, &
                                         kil, kih, kjl, kjh, kkl, kkh )
 use modd_budget,      only: NLVL_CATEGORY, NLVL_GROUP, NLVL_SHAPE, nbutshift, nbusubwrite, tbudiachrometadata
diff --git a/src/MNH/write_profilern.f90 b/src/MNH/write_profilern.f90
index 4393ffa9e..cb341f90c 100644
--- a/src/MNH/write_profilern.f90
+++ b/src/MNH/write_profilern.f90
@@ -680,15 +680,24 @@ tzbudiachro%clevels  (NLVL_MASK)        = ''
 tzbudiachro%ccomments(NLVL_MASK)        = ''
 
 tzbudiachro%lmobile    = .false.
+!Compression does not make sense here
+!Keep these values for backward compatibility of LFI files
 tzbudiachro%licompress = .true.
 tzbudiachro%ljcompress = .true.
 tzbudiachro%lkcompress = .false.
 tzbudiachro%ltcompress = .false.
 tzbudiachro%lnorm      = .false.
+!Horizontal boundaries in physical domain does not make sense here (but flyer position does)
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
 tzbudiachro%nil        = 1
 tzbudiachro%nih        = 1
 tzbudiachro%njl        = 1
 tzbudiachro%njh        = 1
+!1->iku includes non-physical levels (IKU=NKMAX+2*JPVEXT)
+!This does not conform to documentation (limits are in the physical domain)
+!These values are not written in the netCDF files
+!These values are written in the LFI files. They are kept for backward compatibility (and not set to default values)
 tzbudiachro%nkl        = 1
 tzbudiachro%nkh        = iku
 
diff --git a/src/MNH/write_seriesn.f90 b/src/MNH/write_seriesn.f90
index c8424aba1..153b7a4e0 100644
--- a/src/MNH/write_seriesn.f90
+++ b/src/MNH/write_seriesn.f90
@@ -288,7 +288,7 @@ tzbudiachro%ccomments(NLVL_NORM)        = 'Values are not normalized'
 
 tzbudiachro%lleveluse(NLVL_MASK)        = .true.
 ! tzbudiachro%clevels  (NLVL_MASK)        = DONE LATER
-tzbudiachro%ccomments(NLVL_MASK)        = ''
+! tzbudiachro%ccomments(NLVL_MASK)        = DONE LATER
 
 tzbudiachro%lmobile    = .false.
 tzbudiachro%licompress = .true.
@@ -307,6 +307,7 @@ tzbudiachro%nkh        = ikmax
 ! Do not provide all tzfields once because they can be stored in different HDF groups (based on masks)
 do jp = 1 , nstemp_serie1
   tzbudiachro%clevels(NLVL_MASK) = Trim( csmask1(jp) )
+  tzbudiachro%ccomments(NLVL_MASK) = ''
 
   call Write_diachro( tpdiafile, tzbudiachro, [ tzfields(jp) ], tpsdates(1:nsnbstept), &
                       xsseries1(1:1,1:1,1:1,1:nsnbstept,1:1,jp:jp)                 )
@@ -415,7 +416,7 @@ tzbudiachro%ccomments(NLVL_NORM)        = 'Values are not normalized'
 
 tzbudiachro%lleveluse(NLVL_MASK)        = .true.
 ! tzbudiachro%clevels  (NLVL_MASK)        = DONE LATER
-tzbudiachro%ccomments(NLVL_MASK)        = ''
+! tzbudiachro%ccomments(NLVL_MASK)        = DONE LATER
 
 tzbudiachro%lmobile    = .false.
 tzbudiachro%licompress = .true.
@@ -434,6 +435,7 @@ tzbudiachro%nkh        = ikmax
 ! Do not provide all tzfields once because they can be stored in different HDF groups (based on masks)
 do jp = 1 , nstemp_serie2
   tzbudiachro%clevels(NLVL_MASK) = csmask2(jp)
+  tzbudiachro%ccomments(NLVL_MASK) = ''
 
   call Write_diachro( tpdiafile, tzbudiachro, [ tzfields(jp) ], tpsdates(1:nsnbstept), &
                       xsseries2(1:1,1:1,1:ikmax,1:nsnbstept,1:1,jp:jp)                 )
diff --git a/src/MNH/write_stationn.f90 b/src/MNH/write_stationn.f90
index 364b4ed11..b89b12c21 100644
--- a/src/MNH/write_stationn.f90
+++ b/src/MNH/write_stationn.f90
@@ -765,11 +765,16 @@ tzbudiachro%clevels  (NLVL_MASK)        = ''
 tzbudiachro%ccomments(NLVL_MASK)        = ''
 
 tzbudiachro%lmobile    = .false.
+!Compression does not make sense here
+!Keep these values for backward compatibility of LFI files
 tzbudiachro%licompress = .true.
 tzbudiachro%ljcompress = .true.
 tzbudiachro%lkcompress = .false.
 tzbudiachro%ltcompress = .false.
 tzbudiachro%lnorm      = .false.
+!Boundaries in physical domain does not make sense here
+!These values are not written in the netCDF files
+!These values are written in the LFI files. Kept for backward compatibility of LFI files
 tzbudiachro%nil        = 1
 tzbudiachro%nih        = 1
 tzbudiachro%njl        = 1
-- 
GitLab