Skip to content
Snippets Groups Projects
Commit 7a70f9ee authored by Hahn, Steven's avatar Hahn, Steven Committed by GitHub
Browse files

Merge pull request #17739 from mantidproject/nexus_warnings

Move away from deprecated nxs functions
parents e5d13b3e 31866ff0
No related branches found
No related tags found
No related merge requests found
...@@ -419,11 +419,28 @@ void LoadHelper::dumpNexusAttributes(NXhandle nxfileID, ...@@ -419,11 +419,28 @@ void LoadHelper::dumpNexusAttributes(NXhandle nxfileID,
// Attributes // Attributes
NXname pName; NXname pName;
int iLength, iType; int iLength, iType;
#ifndef NEXUS43
int rank;
int dims[4];
#endif
int nbuff = 127; int nbuff = 127;
boost::shared_array<char> buff(new char[nbuff + 1]); boost::shared_array<char> buff(new char[nbuff + 1]);
#ifdef NEXUS43
while (NXgetnextattr(nxfileID, pName, &iLength, &iType) != NX_EOD) { while (NXgetnextattr(nxfileID, pName, &iLength, &iType) != NX_EOD) {
#else
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");
}
#endif
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,28 @@ int SaveToSNSHistogramNexus::WriteAttributes(int is_definition) { ...@@ -649,15 +648,28 @@ int SaveToSNSHistogramNexus::WriteAttributes(int is_definition) {
(void)is_definition; (void)is_definition;
int status, i, attrLen, attrType; int status, i, attrLen, attrType;
#ifndef NEXUS43
int rank;
int dims[4];
#endif
NXname attrName; NXname attrName;
void *attrBuffer; void *attrBuffer;
i = 0; i = 0;
do { do {
#ifdef NEXUS43
status = NXgetnextattr(inId, attrName, &attrLen, &attrType); status = NXgetnextattr(inId, attrName, &attrLen, &attrType);
#else
status = NXgetnextattra(inId, attrName, &rank, dims, &attrType);
#endif
if (status == NX_ERROR) if (status == NX_ERROR)
return NX_ERROR; return NX_ERROR;
if (status == NX_OK) { if (status == NX_OK) {
#ifndef NEXUS43
if (rank != 1)
return NX_ERROR;
attrLen = dims[0];
#endif
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,32 @@ std::string NXObject::name() const { ...@@ -83,12 +83,32 @@ std::string NXObject::name() const {
void NXObject::getAttributes() { void NXObject::getAttributes() {
NXname pName; NXname pName;
int iLength, iType; int iLength, iType;
#ifndef NEXUS43
int rank;
int dims[4];
#endif
int nbuff = 127; int nbuff = 127;
boost::shared_array<char> buff(new char[nbuff + 1]); boost::shared_array<char> buff(new char[nbuff + 1]);
#ifdef NEXUS43
while (NXgetnextattr(m_fileID, pName, &iLength, &iType) != NX_EOD) { while (NXgetnextattr(m_fileID, pName, &iLength, &iType) != NX_EOD) {
// std::cerr<<"--------------------------\n"; #else
// std::cerr<<"name="<<path()<<'\n'; while (NXgetnextattra(m_fileID, pName, &rank, dims, &iType) != NX_EOD) {
// std::cerr<<pName<<' ' <<iLength<<' '<<iType<<'\n'; #endif
// std::cerr<<"--------------------------\n";
// std::cerr<<"name="<<path()<<'\n';
// std::cerr<<pName<<' ' <<iLength<<' '<<iType<<'\n';
#ifndef NEXUS43
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");
}
#endif
switch (iType) { switch (iType) {
case NX_CHAR: { case NX_CHAR: {
if (iLength > nbuff + 1) { if (iLength > nbuff + 1) {
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
# NEXUS_C_LIBRARIES C libraries to link against # NEXUS_C_LIBRARIES C libraries to link against
# NEXUS_CPP_LIBRARIES C++ libraries to link against # NEXUS_CPP_LIBRARIES C++ libraries to link against
# NEXUS_LIBRARIES All libraries that have been found # NEXUS_LIBRARIES All libraries that have been found
# NEXUS_VERSION The NeXus version # NEXUS_VERSION The NeXus version
# NEXUS_FOUND If false, do not try to use NeXus # NEXUS_FOUND If false, do not try to use NeXus
############################################################################### ###############################################################################
# Search for the include files. Newer versions of Nexus have a nexus sub directory # Search for the include files. Newer versions of Nexus have a nexus sub directory
# containing the headers but older versions just have napi.h in the root include path # containing the headers but older versions just have napi.h in the root include path
# Try for nexus/napi.h first # Try for nexus/napi.h first
find_path ( NEXUS_INCLUDE_DIR napi.h find_path ( NEXUS_INCLUDE_DIR napi.h
...@@ -26,32 +26,37 @@ find_library ( NEXUS_C_LIBRARIES_DEBUG NAMES NeXus libNeXus-0D ) ...@@ -26,32 +26,37 @@ find_library ( NEXUS_C_LIBRARIES_DEBUG NAMES NeXus libNeXus-0D )
find_library ( NEXUS_CPP_LIBRARIES_DEBUG NAMES NeXusCPP libNeXusCPP-0D) find_library ( NEXUS_CPP_LIBRARIES_DEBUG NAMES NeXusCPP libNeXusCPP-0D)
if ( NEXUS_C_LIBRARIES_DEBUG AND NEXUS_CPP_LIBRARIES_DEBUG ) if ( NEXUS_C_LIBRARIES_DEBUG AND NEXUS_CPP_LIBRARIES_DEBUG )
set ( NEXUS_LIBRARIES optimized ${NEXUS_C_LIBRARIES} set ( NEXUS_LIBRARIES optimized ${NEXUS_C_LIBRARIES}
optimized ${NEXUS_CPP_LIBRARIES} optimized ${NEXUS_CPP_LIBRARIES}
debug ${NEXUS_C_LIBRARIES_DEBUG} debug ${NEXUS_C_LIBRARIES_DEBUG}
debug ${NEXUS_CPP_LIBRARIES_DEBUG} ) debug ${NEXUS_CPP_LIBRARIES_DEBUG} )
else() else()
set ( NEXUS_LIBRARIES ${NEXUS_C_LIBRARIES} ${NEXUS_CPP_LIBRARIES} ) set ( NEXUS_LIBRARIES ${NEXUS_C_LIBRARIES} ${NEXUS_CPP_LIBRARIES} )
endif() endif()
# Set a version string by examining the napi.h header # Set a version string by examining the napi.h header
if( NEXUS_INCLUDE_DIR ) if( NEXUS_INCLUDE_DIR )
# Extract the line containing the version string which will look like this "#define NEXUS_VERSION "X.X.X" /* major.minor.patch */" # Extract the line containing the version string which will look like this "#define NEXUS_VERSION "X.X.X" /* major.minor.patch */"
file ( STRINGS ${NEXUS_INCLUDE_DIR}/napi.h NEXUS_VERSION_TMP REGEX "^#define[ \t]+NEXUS_VERSION[ \t]+\"[0-9]+.[0-9]+.[0-9]+\"[ \t]+/\\* major\\.minor\\.patch \\*/$" ) file ( STRINGS ${NEXUS_INCLUDE_DIR}/napi.h NEXUS_VERSION_TMP REGEX "^#define[ \t]+NEXUS_VERSION[ \t]+\"[0-9]+.[0-9]+.[0-9]+\"[ \t]+/\\* major\\.minor\\.patch \\*/$" )
# Hack off the portion up to and including the first double quote # Hack off the portion up to and including the first double quote
string( REGEX REPLACE "^#define[ \t]+NEXUS_VERSION[ \t]+\"" "" NEXUS_VERSION_TMP ${NEXUS_VERSION_TMP} ) string( REGEX REPLACE "^#define[ \t]+NEXUS_VERSION[ \t]+\"" "" NEXUS_VERSION_TMP ${NEXUS_VERSION_TMP} )
# Hack off the portion from the second double quote to the end of the line # Hack off the portion from the second double quote to the end of the line
string( REGEX REPLACE "\"[ \t]+/\\* major\\.minor\\.patch \\*/$" "" NEXUS_VERSION_TMP ${NEXUS_VERSION_TMP} ) string( REGEX REPLACE "\"[ \t]+/\\* major\\.minor\\.patch \\*/$" "" NEXUS_VERSION_TMP ${NEXUS_VERSION_TMP} )
set( NEXUS_VERSION ${NEXUS_VERSION_TMP} CACHE STRING "" FORCE ) set( NEXUS_VERSION ${NEXUS_VERSION_TMP} CACHE STRING "" FORCE )
endif() endif()
# Handle the QUIETLY and REQUIRED arguments and set NEXUS_FOUND to TRUE if # Handle the QUIETLY and REQUIRED arguments and set NEXUS_FOUND to TRUE if
# all listed variables are TRUE # all listed variables are TRUE
include ( FindPackageHandleStandardArgs ) include ( FindPackageHandleStandardArgs )
if (NEXUS_VERSION) if (NEXUS_VERSION)
message (STATUS "NeXus version ${NEXUS_VERSION}")
find_package_handle_standard_args( Nexus REQUIRED_VARS NEXUS_LIBRARIES NEXUS_INCLUDE_DIR find_package_handle_standard_args( Nexus REQUIRED_VARS NEXUS_LIBRARIES NEXUS_INCLUDE_DIR
VERSION_VAR NEXUS_VERSION ) VERSION_VAR NEXUS_VERSION )
# this and related code should go away when libraries are upgraded
if (NEXUS_VERSION VERSION_LESS 4.4)
add_definitions(-DNEXUS43)
endif ()
else (NEXUS_VERSION) else (NEXUS_VERSION)
message (status "Failed to determine version: Ignoring version requirement") message (WARNING "Failed to determine version: Ignoring version requirement")
find_package_handle_standard_args( Nexus DEFAULT_MSG NEXUS_LIBRARIES NEXUS_INCLUDE_DIR ) find_package_handle_standard_args( Nexus DEFAULT_MSG NEXUS_LIBRARIES NEXUS_INCLUDE_DIR )
endif (NEXUS_VERSION) endif (NEXUS_VERSION)
\ No newline at end of file
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