From 76dbd757e32f06a0a335bfe7effa9b1c798047ca Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Mon, 2 Feb 2026 19:08:12 +0100 Subject: [PATCH] dump_header can now handle HDF4/HDF5 NeXus files, without the NeXus library. --- src/dump_header.cpp | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/dump_header.cpp b/src/dump_header.cpp index 4ed86769..c1a49934 100644 --- a/src/dump_header.cpp +++ b/src/dump_header.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -365,19 +366,40 @@ int dump_header_root(const std::string fileName, const bool summary, const bool int dump_header_nexus(const std::string fileName, const bool counts) { #ifdef PNEXUS_ENABLED - std::cout << std::endl << "new NeXus handling not yet implemented ..." << std::endl << std::endl; -/* //as35 - std::unique_ptr nxs_file = std::make_unique(fileName.c_str()); + nxs::HDFType type = nxs::checkHDFType(fileName); - if (nxs_file->IsValid(false)) { - nxs_file->Dump(counts); - } else { - std::cerr << std::endl; - std::cerr << "**ERROR** found invalid NeXus file." << std::endl; - std::cerr << std::endl; - return 1; + // check for type errors, missing enabled HDF4 + switch (type) { + case nxs::HDFType::HDF4: + std::cout << std::endl << ">> PRunDataHandler::ReadNexusFile(): HDF4 file." << std::endl; +#ifndef HAVE_HDF4 + std::cerr << std::endl << ">> PRunDataHandler::ReadNexusFile(): **ERROR**, HDF4 is not enabled." << std::endl; + return 1; +#endif + break; + case nxs::HDFType::HDF5: + std::cout << std::endl << ">> PRunDataHandler::ReadNexusFile(): HDF5 file." << std::endl; + break; + case nxs::HDFType::Unknown: + std::cerr << std::endl << ">> PRunDataHandler::ReadNexusFile(): Not a valid NeXus file." << std::endl; + return 1; + } + + if (type == nxs::HDFType::HDF4) { +#ifdef HAVE_HDF4 + std::unique_ptr nxs_file = std::make_unique(fileName); + if (nxs_file == nullptr) { + std::cerr << std::endl << "**ERROR** allocation of nxH4::PNeXus object faild." << std::endl; + } + nxs_file->Dump(); +#endif + } else { // HDF5 + std::unique_ptr nxs_file = std::make_unique(fileName); + if (nxs_file == nullptr) { + std::cerr << std::endl << "**ERROR** allocation of nxH5::PNeXus object faild." << std::endl; + } + nxs_file->Dump(); } -*/ //as35 #else std::cout << std::endl << "NeXus not enabled, hence the header information cannot be dumped." << std::endl << std::endl; #endif