Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/MNHPy/read_MNHfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down