Skip to content
Snippets Groups Projects
Commit def18db2 authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Move away from deprecated nxs functions

Rather than `NXgetnextattr` use `NXgetnextattra` and error
out if an array is encountered.
parent 60bdc07a
No related merge requests found
...@@ -418,11 +418,22 @@ void LoadHelper::dumpNexusAttributes(NXhandle nxfileID, ...@@ -418,11 +418,22 @@ void LoadHelper::dumpNexusAttributes(NXhandle nxfileID,
// Attributes // Attributes
NXname pName; NXname pName;
int iLength, iType; int iLength, iType;
int rank;
int dims[4];
int nbuff = 127; int nbuff = 127;
boost::shared_array<char> buff(new char[nbuff + 1]); 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 << " = "; 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) { switch (iType) {
case NX_CHAR: { case NX_CHAR: {
if (iLength > nbuff + 1) { if (iLength > nbuff + 1) {
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <Poco/File.h> #include <Poco/File.h>
//#include <hdf5.h> //This is troublesome on multiple platforms.
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
...@@ -649,15 +648,20 @@ int SaveToSNSHistogramNexus::WriteAttributes(int is_definition) { ...@@ -649,15 +648,20 @@ int SaveToSNSHistogramNexus::WriteAttributes(int is_definition) {
(void)is_definition; (void)is_definition;
int status, i, attrLen, attrType; int status, i, attrLen, attrType;
int rank;
int dims[4];
NXname attrName; NXname attrName;
void *attrBuffer; void *attrBuffer;
i = 0; i = 0;
do { do {
status = NXgetnextattr(inId, attrName, &attrLen, &attrType); status = NXgetnextattra(inId, attrName, &rank, dims, &attrType);
if (status == NX_ERROR) if (status == NX_ERROR)
return NX_ERROR; return NX_ERROR;
if (status == NX_OK) { if (status == NX_OK) {
if (rank != 1)
return NX_ERROR;
attrLen = dims[0];
if (strcmp(attrName, "NeXus_version") && if (strcmp(attrName, "NeXus_version") &&
strcmp(attrName, "XML_version") && strcmp(attrName, "HDF_version") && strcmp(attrName, "XML_version") && strcmp(attrName, "HDF_version") &&
strcmp(attrName, "HDF5_Version") && strcmp(attrName, "file_name") && strcmp(attrName, "HDF5_Version") && strcmp(attrName, "file_name") &&
......
...@@ -83,12 +83,24 @@ std::string NXObject::name() const { ...@@ -83,12 +83,24 @@ std::string NXObject::name() const {
void NXObject::getAttributes() { void NXObject::getAttributes() {
NXname pName; NXname pName;
int iLength, iType; int iLength, iType;
int rank;
int dims[4];
int nbuff = 127; int nbuff = 127;
boost::shared_array<char> buff(new char[nbuff + 1]); 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<<"--------------------------\n";
// std::cerr<<"name="<<path()<<'\n'; // std::cerr<<"name="<<path()<<'\n';
// std::cerr<<pName<<' ' <<iLength<<' '<<iType<<'\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) { switch (iType) {
case NX_CHAR: { case NX_CHAR: {
if (iLength > nbuff + 1) { if (iLength > nbuff + 1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment