From 5647790a5bfdfdd25baec65e18d964cc07407e05 Mon Sep 17 00:00:00 2001
From: Quentin Rodier <quentin.rodier@meteo.fr>
Date: Tue, 13 Dec 2022 19:37:30 +0100
Subject: [PATCH] Quentin 13/12/2022: bugfix les_mean_subgrid + adapt
 compare.py script for mesonh KTEST (better for testing LES diag)

---
 src/mesonh/turb/les_mean_subgrid_phy.f90 |  4 ++--
 tools/compare.py                         | 19 +++++--------------
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/src/mesonh/turb/les_mean_subgrid_phy.f90 b/src/mesonh/turb/les_mean_subgrid_phy.f90
index 4574a6385..88a7d2c72 100644
--- a/src/mesonh/turb/les_mean_subgrid_phy.f90
+++ b/src/mesonh/turb/les_mean_subgrid_phy.f90
@@ -66,7 +66,7 @@ REAL,    DIMENSION(D%NIJT,D%NKT), INTENT(IN)    :: PA
 REAL,    DIMENSION(D%NKLES,TLES%NLES_CURRENT_TCOUNT,D%NLESMASK), INTENT(INOUT) :: PA_MEAN
 LOGICAL, OPTIONAL,         INTENT(IN)    :: OSUM
 !
-CALL LES_MEAN_SUBGRID_unpack3D(D,PA, PA_MEAN, OSUM)
+CALL LES_MEAN_SUBGRID_unpack3D(D,TLES, PA, PA_MEAN, OSUM)
 !
 END SUBROUTINE LES_MEAN_SUBGRID_3D_PHY
 !
@@ -88,7 +88,7 @@ REAL,    DIMENSION(D%NIJT), INTENT(IN)    :: PA
 REAL,    DIMENSION(TLES%NLES_CURRENT_TCOUNT), INTENT(INOUT) :: PA_MEAN
 LOGICAL, OPTIONAL,         INTENT(IN)    :: OSUM
 !
-CALL LES_MEAN_SUBGRID_unpackSURF(D,PA, PA_MEAN, OSUM)
+CALL LES_MEAN_SUBGRID_unpackSURF(D, TLES, PA, PA_MEAN, OSUM)
 !
 END SUBROUTINE LES_MEAN_SUBGRID_SURF_PHY
 !
diff --git a/tools/compare.py b/tools/compare.py
index 816cac5f7..34f208405 100755
--- a/tools/compare.py
+++ b/tools/compare.py
@@ -4,28 +4,17 @@ import xarray as xr
 
 avail_groups=['Stations/sta1',
 'LES_budgets/Miscellaneous/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/Miscellaneous/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/Mean/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/Mean/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/Resolved/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/Resolved/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/Subgrid/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/Subgrid/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/Surface/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/Surface/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/BU_KE/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/BU_KE/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/BU_THL2/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/BU_THL2/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/BU_WTHL/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/BU_WTHL/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/BU_RT2/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/BU_RT2/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/BU_WRT/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/BU_WRT/Cartesian/Time_averaged/Not_normalized/cart/',
 'LES_budgets/BU_THLR/Cartesian/Not_time_averaged/Not_normalized/cart/',
-'LES_budgets/BU_THLR/Cartesian/Time_averaged/Not_normalized/cart/']
-
+]
 
 
 def compareBACKUPFiles(file_user, file_ref):
@@ -73,6 +62,10 @@ def compareTSERIESFiles(file_user, file_ref):
   da = xr.open_dataset(file_user)
   da2 = xr.open_dataset(file_ref)
   variables = list(da.keys())
+  try: 
+    nk=len(da['level_les'])
+  except:
+    pass
   for var in variables:
     try:
       ecart_min = float(da2[var].min())-float(da[var].min())
@@ -86,11 +79,9 @@ def compareTSERIESFiles(file_user, file_ref):
   # Groups comparison
   for grp in avail_groups:
     try:
-      nk=len(da['level_les'])
       da = xr.open_dataset(file_user, group=grp)
       da2 = xr.open_dataset(file_ref, group=grp)
       variables = list(da.keys())
-      print(grp)
       for var in variables:
         try:
           ecart_min = float(da2[var][:,:nk-JPVEXT].min())-float(da[var][:,:nk-JPVEXT].min())
-- 
GitLab