From cc9ba99c12f7f9e56cf0a8fe54e8330f54c879ff Mon Sep 17 00:00:00 2001 From: Hugo Farajallah Date: Thu, 13 Aug 2026 11:32:00 +0200 Subject: [PATCH] Fall back to the MNH_VERSION attribute when MASDEV is absent read_TIMESfiles indexed theFile['MASDEV'] unconditionally to decide whether a file is new enough to read. netCDF4 raises when the variable is missing, so any diagnostic file written without MASDEV aborts the read before the version test can be applied. Meso-NH writes an MNH_VERSION global attribute alongside MASDEV (src/MNH/io/mode_io_write_nc4.f90), and reads it back the same way in IO_Mnhversion_get, so use it as the fallback. The version test is also reworked to compare major and minor separately rather than treating the packed MASDEV integer as a single number. Ported from Meso-NH's in-tree copy of the module (src/LIB/Python/read_MNHfile.py), which has carried this since the 6.x IO changes; the two copies now match byte for byte again. --- src/MNHPy/read_MNHfile.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/MNHPy/read_MNHfile.py b/src/MNHPy/read_MNHfile.py index 7e240f6..ea5d50f 100644 --- a/src/MNHPy/read_MNHfile.py +++ b/src/MNHPy/read_MNHfile.py @@ -137,7 +137,19 @@ def read_netcdf(LnameFiles, Dvar_input, path='.', get_data_only=True, del_empty_ theFile = nc.Dataset(ipath + LnameFiles[i], 'r') Dvar[keyFiles] = {} if '000' in LnameFiles[i][-6:-3]: - if theFile['MASDEV'][0] <= 54: + # Check version: try MASDEV field first, fall back to MNH_VERSION attribute + try: + masdev = int(theFile['MASDEV'][0]) + masdev_str = str(masdev) + version = int(masdev_str[0]) # First digit + subversion = int(masdev_str[1:]) if len(masdev_str) > 1 else 0 # Remaining digits + except (KeyError, IndexError): + # MASDEV not found, use MNH_VERSION attribute (3 integers) + mnh_version = theFile.getncattr('MNH_VERSION') + version = mnh_version[0] + subversion = mnh_version[1] + + if version < 5 or (version == 5 and subversion < 5): raise TypeError('The python lib is available for MNH >= 5.5') else: Dvar[keyFiles] = read_TIMESfiles_55(theFile, Dvar_input[keyFiles], Dvar[keyFiles], get_data_only, del_empty_dim, removeHALO)