added the missing sample information when reading NeXus IDF V2.
This commit is contained in:
66
src/external/nexus/PNeXus.cpp
vendored
66
src/external/nexus/PNeXus.cpp
vendored
@@ -3306,6 +3306,10 @@ void nxH5::PNeXus::HandleIdfV2(H5::H5File &file)
|
|||||||
ReadFloatDataset(file, "/raw_data_1/instrument/detector_1/raw_time");
|
ReadFloatDataset(file, "/raw_data_1/instrument/detector_1/raw_time");
|
||||||
ReadIntDataset(file, "/raw_data_1/instrument/detector_1/spectrum_index");
|
ReadIntDataset(file, "/raw_data_1/instrument/detector_1/spectrum_index");
|
||||||
ReadFloatDataset(file, "/raw_data_1/detector_1/dead_time");
|
ReadFloatDataset(file, "/raw_data_1/detector_1/dead_time");
|
||||||
|
ReadStringDataset(file, "/raw_data_1/sample/name");
|
||||||
|
ReadFloatDataset(file, "/raw_data_1/sample/temperature");
|
||||||
|
ReadFloatDataset(file, "/raw_data_1/sample/magnetic_field");
|
||||||
|
ReadStringDataset(file, "/raw_data_1/sample/shape");
|
||||||
} catch (const H5::Exception& err) {
|
} catch (const H5::Exception& err) {
|
||||||
std::cerr << "Error in HandleIdfV2: " << err.getDetailMsg() << std::endl;
|
std::cerr << "Error in HandleIdfV2: " << err.getDetailMsg() << std::endl;
|
||||||
throw;
|
throw;
|
||||||
@@ -3908,6 +3912,68 @@ void nxH5::PNeXus::Dump()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << std::endl << "----";
|
std::cout << std::endl << "----";
|
||||||
|
std::cout << std::endl << " sample";
|
||||||
|
if (fDataMap.find("/raw_data_1/sample/name") != fDataMap.end()) {
|
||||||
|
try {
|
||||||
|
auto str = std::any_cast<PNXdata<std::string>>(fDataMap["/raw_data_1/sample/name"]);
|
||||||
|
std::cout << std::endl << " name : " << str.GetData()[0];
|
||||||
|
} catch (const std::bad_any_cast& e) {
|
||||||
|
std::cerr << std::endl << "Error: Failed to cast sample/name data" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << std::endl << " name : n/a";
|
||||||
|
}
|
||||||
|
if (fDataMap.find("/raw_data_1/sample/temperature") != fDataMap.end()) {
|
||||||
|
try {
|
||||||
|
auto temp_ds = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/sample/temperature"]);
|
||||||
|
float temp = temp_ds.GetData()[0];
|
||||||
|
if (temp_ds.HasAttribute("units")) {
|
||||||
|
try {
|
||||||
|
auto units = std::any_cast<std::string>(temp_ds.GetAttribute("units"));
|
||||||
|
if (units == "Celsius")
|
||||||
|
temp += 273.16;
|
||||||
|
} catch (const std::bad_any_cast& e) {
|
||||||
|
std::cerr << "Error: Failed to cast units attribute" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl << " temperature: " << temp << " K";
|
||||||
|
} catch (const std::bad_any_cast& e) {
|
||||||
|
std::cerr << std::endl << "Error: Failed to cast sample/temperature data" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << std::endl << " temperature: n/a";
|
||||||
|
}
|
||||||
|
if (fDataMap.find("/raw_data_1/sample/magnetic_field") != fDataMap.end()) {
|
||||||
|
try {
|
||||||
|
auto mag_field_ds = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/sample/magnetic_field"]);
|
||||||
|
float mag_field = mag_field_ds.GetData()[0];
|
||||||
|
if (mag_field_ds.HasAttribute("units")) {
|
||||||
|
try {
|
||||||
|
auto units = std::any_cast<std::string>(mag_field_ds.GetAttribute("units"));
|
||||||
|
if (units == "Tesla")
|
||||||
|
mag_field *= 1e4;
|
||||||
|
} catch (const std::bad_any_cast& e) {
|
||||||
|
std::cerr << "Error: Failed to cast units attribute" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl << " mag. field: " << mag_field << " G";
|
||||||
|
} catch (const std::bad_any_cast& e) {
|
||||||
|
std::cerr << std::endl << "Error: Failed to cast sample/magnetic_field data" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << std::endl << " temperature: n/a";
|
||||||
|
}
|
||||||
|
if (fDataMap.find("/raw_data_1/sample/shape") != fDataMap.end()) {
|
||||||
|
try {
|
||||||
|
auto str = std::any_cast<PNXdata<std::string>>(fDataMap["/raw_data_1/sample/shape"]);
|
||||||
|
std::cout << std::endl << " shape : " << str.GetData()[0];
|
||||||
|
} catch (const std::bad_any_cast& e) {
|
||||||
|
std::cerr << std::endl << "Error: Failed to cast sample/shape data" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << std::endl << " shape : n/a";
|
||||||
|
}
|
||||||
|
std::cout << std::endl << "----";
|
||||||
std::cout << std::endl << " detector_1";
|
std::cout << std::endl << " detector_1";
|
||||||
std::cout << std::endl << " counts:";
|
std::cout << std::endl << " counts:";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user