diff --git a/reader/HDF5MetadataSource.cpp b/reader/HDF5MetadataSource.cpp index f05b2596d..fa47c4232 100644 --- a/reader/HDF5MetadataSource.cpp +++ b/reader/HDF5MetadataSource.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include +#include #include #include "HDF5MetadataSource.h" @@ -1212,8 +1213,17 @@ std::optional HDF5MetadataSource::ReadAxis(HDF5Object *file, con return {}; } else if (!legacy_group) { return {}; - } else if (name.find("_end") != std::string::npos || name.find("_range") != std::string::npos) { - return {}; // the same companion datasets, by name, since there is no tag to go on + } else { + // The same companion datasets, recognised by name because there is no tag to go on. In the + // legacy layout each axis NAME carries five of them - AXIS_end, _start, _increment, + // _range_average, _range_total - and only the bare name is the axis itself. Matching the + // suffix rather than "contains an underscore" keeps a genuine two_theta axis readable. + static const char *const companions[] = {"_end", "_start", "_increment", + "_range_average", "_range_total"}; + for (const char *suffix: companions) + if (name.size() > strlen(suffix) + && name.compare(name.size() - strlen(suffix), strlen(suffix), suffix) == 0) + return {}; } std::vector end = file->ReadOptVector(dname + "_end");