From 439b215a9e3687065757cedb6f102c2de5d92f0a Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Thu, 31 Aug 2023 11:11:48 +0200
Subject: [PATCH] Philippe 31/08/2023: IO: bugfix for diachronic LFI files with
 flyers

---
 src/MNH/menu_diachro.f90 | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/MNH/menu_diachro.f90 b/src/MNH/menu_diachro.f90
index f6d0ff1c9..dd2430743 100644
--- a/src/MNH/menu_diachro.f90
+++ b/src/MNH/menu_diachro.f90
@@ -103,11 +103,15 @@ LPACK=.FALSE.
 !
 IF(HGROUP == 'END')THEN
 
-  IF(IGROUP == 0)THEN
-!   print *,' No record for the diachronic file' mettre les prints dans le fichier LISTING
-    LPACK=GPACK
-    RETURN
-  ENDIF
+! The following block is commented because in some special cases (ie if flyers are present), the IGROUP value may be different
+! between the master process and the other ones (and may be 0)
+! In all cases, the master process has the correct values and is the only one to do the real writing (CDRIR='--')
+! Therefore, MENU_BUDGET.DIM is now always written in the LFI file. MENU_BUDGET is not written if empty (IO_Field_write does
+! not write a zero-size object)
+!   IF(IGROUP == 0)THEN
+!     LPACK=GPACK
+!     RETURN
+!   ENDIF
 
   !Write only in LFI files
   tzfile = tpdiafile
@@ -156,6 +160,7 @@ ELSE IF(HGROUP == 'READ')THEN
   tzfile = tpdiafile
   tzfile%cformat = 'LFI'
 
+  ILENG = 0
   TZFIELD = TFIELDMETADATA(         &
     CMNHNAME   = 'MENU_BUDGET.DIM', &
     CSTDNAME   = '',                &
@@ -168,7 +173,9 @@ ELSE IF(HGROUP == 'READ')THEN
     NDIMS      = 0,                 &
     LTIMEDEP   = .FALSE.            )
   CALL IO_Field_read(tzfile,TZFIELD,ILENG,IRESPDIA)
-  IF(IRESPDIA == -47)THEN
+  ! Note: keep check on IRESPDIA to ensure backward compatibility with older LFI files
+  !       MENU_BUDGET.DIM was not written if IGROUP=0 before MNH 5.6.1
+  IF( IRESPDIA == -47 .OR. ILENG == 0 ) THEN
 !   print *,' No record MENU_BUDGET '
     LPACK=GPACK
     RETURN
-- 
GitLab