From 931e696f6ee854da092965975cbd2d3e222c4b85 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Fri, 21 May 2021 14:56:26 +0200
Subject: [PATCH] Philippe 21/05/2021: budgets: merge LES terms with time
 averaging or not and normalization or not in the same group levels

---
 src/MNH/mode_les_diachro.f90 | 27 ++++-----------------------
 src/MNH/write_diachro.f90    | 28 ++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/src/MNH/mode_les_diachro.f90 b/src/MNH/mode_les_diachro.f90
index 88258d0e6..f2509c9e7 100644
--- a/src/MNH/mode_les_diachro.f90
+++ b/src/MNH/mode_les_diachro.f90
@@ -978,7 +978,6 @@ use mode_write_diachro, only: Write_diachro
 logical, intent(in) :: oavg
 logical, intent(in) :: onorm
 
-character(len=10)                                    :: ygroup  ! Group title
 integer                                              :: iresp   ! Return code
 integer                                              :: ji
 integer                                              :: jk      ! Vertical loop counter
@@ -1018,24 +1017,10 @@ end if
 iresp = 0
 if ( oavg ) call Les_time_avg_4d( zfield, tzdates, iresp )
 
-if ( oavg ) then
-  if ( onorm ) then
-    ygroup = 'H_' // tpfield%cmnhname
-  else
-    ygroup = 'A_' // tpfield%cmnhname
-  end if
-else
-  if ( onorm ) then
-    ygroup = 'E_' // tpfield%cmnhname
-  else
-    ygroup = tpfield%cmnhname
-  end if
-endif
-
 if ( Present( hsuffixes ) ) then
-  ytitle(:) = ygroup // hsuffixes(:)
+  ytitle(:) = tpfield%cmnhname // hsuffixes(:)
 else
-  ytitle(:) = ygroup
+  ytitle(:) = tpfield%cmnhname
 endif
 
 ! Write the profile
@@ -1073,12 +1058,12 @@ if ( iresp == 0 .and. any( zfield /= XUNDEF ) ) then
   tzbudiachro%ccomments(NLVL_SUBCATEGORY) = ''
 
   tzbudiachro%lleveluse(NLVL_GROUP)       = .true.
-  tzbudiachro%clevels  (NLVL_GROUP)       = Trim( ygroup )
+  tzbudiachro%clevels  (NLVL_GROUP)       = Trim( tpfield%cmnhname )
   tzbudiachro%ccomments(NLVL_GROUP)       = ''
 
   tzbudiachro%lleveluse(NLVL_SHAPE)       = .true.
   tzbudiachro%clevels  (NLVL_SHAPE)       = 'Cartesian'
-  tzbudiachro%ccomments(NLVL_SHAPE)       = 'cartesian domain'
+  tzbudiachro%ccomments(NLVL_SHAPE)       = 'Cartesian domain'
 
   tzbudiachro%lleveluse(NLVL_TIMEAVG)     = .true.
   if ( oavg ) then
@@ -1532,14 +1517,10 @@ call Write_diachro( tpdiafile, tzbudiachro, [ tzfield ], tzdates, zwork6 )
 !
 iresp = 0
 call Les_time_avg( zwork6, tzdates, iresp )
-ygroup = 'T_' // ygroup
 do ji = 1, NMNHMAXDIMS
   if ( tzfield%ndimlist(ji) == NMNHDIM_BUDGET_LES_TIME ) tzfield%ndimlist(ji) = NMNHDIM_BUDGET_LES_AVG_TIME
 end do
 
-tzfield%cmnhname  = ygroup
-tzfield%clongname = ygroup
-
 tzbudiachro%lleveluse(NLVL_CATEGORY)    = .true.
 tzbudiachro%clevels  (NLVL_CATEGORY)    = 'LES budgets'
 tzbudiachro%ccomments(NLVL_CATEGORY)    = 'Level for the different LES budgets'
diff --git a/src/MNH/write_diachro.f90 b/src/MNH/write_diachro.f90
index f8ddd23e1..1bb06996d 100644
--- a/src/MNH/write_diachro.f90
+++ b/src/MNH/write_diachro.f90
@@ -265,6 +265,34 @@ if (       Trim( tpbudiachro%clevels(NLVL_CATEGORY) ) == 'Flyers'           &
   ygroup = Trim( ygroup ) // 'Z'
 end if
 
+if (       Trim( tpbudiachro%clevels(NLVL_CATEGORY) ) == 'LES budgets' &
+     .and. Trim( tpbudiachro%clevels(NLVL_SHAPE) )    == 'Cartesian'   ) then
+  if ( tpbudiachro%ltcompress ) then
+    if ( tpbudiachro%lnorm ) then
+      ygroup = 'H_' // Trim( ygroup )
+    else
+      ygroup = 'A_' // Trim( ygroup )
+    end if
+  else
+    if ( tpbudiachro%lnorm ) then
+      ygroup = 'E_' // Trim( ygroup )
+    else
+      !Nothing to do
+    end if
+  end if
+  !Limit to 10 characters (backward compatibility again...)
+  if ( Len_trim( ygroup )  > 10 ) ygroup = ygroup(1:10)
+end if
+
+if (       Trim( tpbudiachro%clevels(NLVL_CATEGORY) ) == 'LES budgets' &
+     .and. Trim( tpbudiachro%clevels(NLVL_SHAPE) )    == 'Spectrum'    ) then
+  if ( tpbudiachro%ltcompress ) then
+    ygroup = 'T_' // Trim( ygroup )
+    !Limit to 10 characters (backward compatibility again...)
+    if ( Len_trim( ygroup )  > 10 ) ygroup = ygroup(1:10)
+  end if
+end if
+
 !Recompute old TYPE for backward compatibility
 if ( ycategory == 'Budgets' ) then
   if ( yshape == 'Cartesian' ) then
-- 
GitLab