From def18db234df6bbfcd692e76c5d89bc75e6b3471 Mon Sep 17 00:00:00 2001 From: Pete Peterson <petersonpf@ornl.gov> Date: Thu, 6 Oct 2016 16:57:04 -0400 Subject: [PATCH] Move away from deprecated nxs functions Rather than `NXgetnextattr` use `NXgetnextattra` and error out if an array is encountered. --- Framework/DataHandling/src/LoadHelper.cpp | 13 ++++++++++++- .../DataHandling/src/SaveToSNSHistogramNexus.cpp | 8 ++++++-- Framework/Nexus/src/NexusClasses.cpp | 14 +++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Framework/DataHandling/src/LoadHelper.cpp b/Framework/DataHandling/src/LoadHelper.cpp index f53b40e5ef4..64e202bbe70 100644 --- a/Framework/DataHandling/src/LoadHelper.cpp +++ b/Framework/DataHandling/src/LoadHelper.cpp @@ -418,11 +418,22 @@ void LoadHelper::dumpNexusAttributes(NXhandle nxfileID, // Attributes NXname pName; int iLength, iType; + int rank; + int dims[4]; int nbuff = 127; boost::shared_array<char> buff(new char[nbuff + 1]); - while (NXgetnextattr(nxfileID, pName, &iLength, &iType) != NX_EOD) { + while (NXgetnextattra(nxfileID, pName, &rank, dims, &iType) != NX_EOD) { g_log.debug() << indentStr << '@' << pName << " = "; + if (rank > 1) { // mantid only supports single value attributes + throw std::runtime_error( + "Encountered attribute with multi-dimensional array value"); + } + iLength = dims[0]; // to clarify things + if (iType != NX_CHAR && iLength != 1) { + throw std::runtime_error("Encountered attribute with array value"); + } + switch (iType) { case NX_CHAR: { if (iLength > nbuff + 1) { diff --git a/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp b/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp index a7861c6ee6e..4c00a74f532 100644 --- a/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp +++ b/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp @@ -18,7 +18,6 @@ #include <boost/shared_ptr.hpp> #include <boost/scoped_array.hpp> #include <Poco/File.h> -//#include <hdf5.h> //This is troublesome on multiple platforms. #include <cstdlib> #include <cstring> @@ -649,15 +648,20 @@ int SaveToSNSHistogramNexus::WriteAttributes(int is_definition) { (void)is_definition; int status, i, attrLen, attrType; + int rank; + int dims[4]; NXname attrName; void *attrBuffer; i = 0; do { - status = NXgetnextattr(inId, attrName, &attrLen, &attrType); + status = NXgetnextattra(inId, attrName, &rank, dims, &attrType); if (status == NX_ERROR) return NX_ERROR; if (status == NX_OK) { + if (rank != 1) + return NX_ERROR; + attrLen = dims[0]; if (strcmp(attrName, "NeXus_version") && strcmp(attrName, "XML_version") && strcmp(attrName, "HDF_version") && strcmp(attrName, "HDF5_Version") && strcmp(attrName, "file_name") && diff --git a/Framework/Nexus/src/NexusClasses.cpp b/Framework/Nexus/src/NexusClasses.cpp index 16d5b88e5c2..62ca8725159 100644 --- a/Framework/Nexus/src/NexusClasses.cpp +++ b/Framework/Nexus/src/NexusClasses.cpp @@ -83,12 +83,24 @@ std::string NXObject::name() const { void NXObject::getAttributes() { NXname pName; int iLength, iType; + int rank; + int dims[4]; int nbuff = 127; boost::shared_array<char> buff(new char[nbuff + 1]); - while (NXgetnextattr(m_fileID, pName, &iLength, &iType) != NX_EOD) { + + while (NXgetnextattra(m_fileID, pName, &rank, dims, &iType) != NX_EOD) { // std::cerr<<"--------------------------\n"; // std::cerr<<"name="<<path()<<'\n'; // std::cerr<<pName<<' ' <<iLength<<' '<<iType<<'\n'; + if (rank > 1) { // mantid only supports single value attributes + throw std::runtime_error( + "Encountered attribute with multi-dimensional array value"); + } + iLength = dims[0]; // to clarify things + if (iType != NX_CHAR && iLength != 1) { + throw std::runtime_error("Encountered attribute with array value"); + } + switch (iType) { case NX_CHAR: { if (iLength > nbuff + 1) { -- GitLab