73 g_log.
debug() <<
"Opening file " << filename <<
'\n';
75 Nexus::File nxFile(filename);
76 auto entries = nxFile.getEntries();
77 auto itend = entries.end();
80 for (
auto it = entries.begin(); it != itend; ++it) {
81 std::string entryName = it->first;
82 std::string type = it->second;
83 nxFile.openGroup(entryName, type);
84 auto dataEntries = nxFile.getEntries();
86 for (
auto &dataEntry : dataEntries) {
87 const std::string &dataName = dataEntry.first;
88 const std::string &dataType = dataEntry.second;
89 if (dataName ==
"content_nxs" || dataType !=
"NXdata")
91 g_log.
debug() <<
"Opening " << dataName <<
" " << dataType <<
'\n';
93 nxFile.openGroup(dataName, dataType);
96 auto nxdataEntries = nxFile.getEntries();
97 std::string axis1Name, axis2Name;
98 for (
const auto &nxdataEntry : nxdataEntries) {
99 if (nxdataEntry.second ==
"NXparameters")
101 nxFile.openData(nxdataEntry.first);
102 if (nxFile.hasAttr(
"axis")) {
104 nxFile.getAttr(
"axis", axisNo);
106 axis1Name = nxdataEntry.first;
107 else if (axisNo == 2)
108 axis2Name = nxdataEntry.first;
110 throw std::invalid_argument(
"Unknown axis number");
115 std::vector<double> axis1Values, axis2Values;
116 nxFile.readData<
double>(axis1Name, axis1Values);
117 nxFile.readData<
double>(axis2Name, axis2Values);
119 const auto axis1Length = axis1Values.size();
120 const auto axis2Length = axis2Values.size();
121 g_log.
debug() <<
"Axis lengths=" << axis1Length <<
" " << axis2Length <<
'\n';
124 std::vector<double> data;
125 nxFile.readData<
double>(
"data", data);
128 std::vector<double> errors;
130 nxFile.readData<
double>(
"errors", errors);
132 g_log.
information() <<
"Field " << dataName <<
" contains no error information.\n";
137 Axis *axis1 = ws->getAxis(0);
138 axis1->
title() = axis1Name;
140 auto lblUnit = std::make_shared<Units::Label>();
141 lblUnit->setLabel(axis1Name,
"");
142 axis1->
unit() = lblUnit;
144 auto axis2 = std::make_unique<NumericAxis>(axis2Length);
145 auto axis2Raw = axis2.get();
146 axis2->title() = axis2Name;
148 lblUnit = std::make_shared<Units::Label>();
149 lblUnit->setLabel(axis2Name,
"");
150 axis2->unit() = lblUnit;
152 ws->setYUnit(axis2Name);
153 ws->replaceAxis(1, std::move(axis2));
155 ws->mutableX(0) = axis1Values;
157 for (
size_t wsIndex = 0; wsIndex < axis2Length; ++wsIndex) {
158 auto &dataY = ws->mutableY(wsIndex);
159 auto &dataE = ws->mutableE(wsIndex);
160 ws->setSharedX(wsIndex, ws->sharedX(0));
162 for (
size_t j = 0; j < axis1Length; ++j) {
165 const size_t fileDataIndex = j * axis2Length + wsIndex;
167 dataY[j] = data[fileDataIndex];
169 dataE[j] = errors[fileDataIndex];
171 axis2Raw->setValue(wsIndex, axis2Values[wsIndex]);
174 outputGroup->addWorkspace(ws);