本文整理汇总了C++中nexus::File::putSlab方法的典型用法代码示例。如果您正苦于以下问题:C++ File::putSlab方法的具体用法?C++ File::putSlab怎么用?C++ File::putSlab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nexus::File
的用法示例。
在下文中一共展示了File::putSlab方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
void
SaveNXTomo::writeIntensityValue(const DataObjects::Workspace2D_sptr workspace,
::NeXus::File &nxFile, int thisFileInd) {
// Add Intensity to control if present, use 1 if not
try {
nxFile.openPath("/entry1/tomo_entry/control");
} catch (...) {
throw std::runtime_error("Unable to create a valid NXTomo file");
}
std::vector<double> intensityValue;
intensityValue.push_back(1);
if (workspace->run().hasProperty("Intensity")) {
std::string tmpVal = workspace->run().getLogData("Intensity")->value();
try {
intensityValue[0] = boost::lexical_cast<double>(tmpVal);
} catch (...) {
}
// Invalid Cast is handled below
}
nxFile.openData("data");
nxFile.putSlab(intensityValue, thisFileInd, 1);
nxFile.closeData();
}
示例2: writeLogValues
void SaveNXTomo::writeLogValues(const DataObjects::Workspace2D_sptr workspace,
::NeXus::File &nxFile, int thisFileInd) {
// Add Log information (minus special values - Rotation, ImageKey, Intensity)
// Unable to add multidimensional string data, storing strings as
// multidimensional data set of uint8 values
try {
nxFile.openPath("/entry1/log_info");
} catch (...) {
throw std::runtime_error("Unable to create a valid NXTomo file");
}
// Loop through all log values, create it if it doesn't exist. Then append
// value
std::vector<Property *> logVals = workspace->run().getLogData();
for (auto it = logVals.begin(); it != logVals.end(); ++it) {
auto prop = *it;
if (prop->name() != "ImageKey" && prop->name() != "Rotation" &&
prop->name() != "Intensity" && prop->name() != "Axis1" &&
prop->name() != "Axis2") {
try {
nxFile.openData(prop->name());
} catch (::NeXus::Exception &) {
// Create the data entry if it doesn't exist yet, and open.
std::vector<int64_t> infDim;
infDim.push_back(NX_UNLIMITED);
infDim.push_back(NX_UNLIMITED);
nxFile.makeData(prop->name(), ::NeXus::UINT8, infDim, true);
}
size_t strSize = prop->value().length();
char *val = new char[80]();
// If log value is from FITS file as it should be,
// it won't be greater than this. Otherwise Shorten it
if (strSize > 80)
strSize = 80;
strncpy(val, prop->value().c_str(), strSize);
std::vector<int64_t> start, size;
start.push_back(thisFileInd);
start.push_back(0);
size.push_back(1);
size.push_back(strSize);
// single item
nxFile.putSlab(val, start, size);
nxFile.closeData();
}
}
}
示例3: writeSingleWorkspace
/**
* Writes a single workspace into the file
* @param workspace the workspace to get data from
* @param nxFile the nexus file to save data into
*/
void SaveNXTomo::writeSingleWorkspace(const Workspace2D_sptr workspace,
::NeXus::File &nxFile) {
try {
nxFile.openPath("/entry1/tomo_entry/data");
} catch (...) {
throw std::runtime_error("Unable to create a valid NXTomo file");
}
int numFiles = 0;
nxFile.getAttr<int>("NumFiles", numFiles);
// Change slab start to after last data position
m_slabStart[0] = numFiles;
m_slabSize[0] = 1;
// Set the rotation value for this WS
std::vector<double> rotValue;
rotValue.push_back(0);
if (workspace->run().hasProperty("Rotation")) {
std::string tmpVal = workspace->run().getLogData("Rotation")->value();
try {
rotValue[0] = boost::lexical_cast<double>(tmpVal);
} catch (...) {
}
// Invalid Cast is handled below
}
nxFile.openData("rotation_angle");
nxFile.putSlab(rotValue, numFiles, 1);
nxFile.closeData();
// Copy data out, remake data with dimension of old size plus new elements.
// Insert previous data.
nxFile.openData("data");
double *dataArr = new double[m_spectraCount];
for (int64_t i = 0; i < m_dimensions[1]; ++i) {
for (int64_t j = 0; j < m_dimensions[2]; ++j) {
dataArr[i * m_dimensions[1] + j] =
workspace->dataY(i * m_dimensions[1] + j)[0];
}
}
nxFile.putSlab(dataArr, m_slabStart, m_slabSize);
nxFile.closeData();
nxFile.putAttr("NumFiles", numFiles + 1);
nxFile.closeGroup();
// Write additional log information, intensity and image key
writeLogValues(workspace, nxFile, numFiles);
writeIntensityValue(workspace, nxFile, numFiles);
writeImageKeyValue(workspace, nxFile, numFiles);
++numFiles;
delete[] dataArr;
}