161 const std::string& name)
const {
163 hsize_t dims[1] = {1};
164 H5::DataSpace dp(1, dims);
168 attr = loc.createAttribute(name, *dataType, dp);
169 }
catch (H5::AttributeIException&) {
170 attr = loc.openAttribute(name);
172 attr.write(*dataType, &value);
176 const std::string& name)
const {
177 hsize_t dims[1] = {1};
178 H5::DataSpace dp(1, dims);
184 attr = loc.createAttribute(name, *strType, dp);
185 }
catch (H5::AttributeIException&) {
186 attr = loc.openAttribute(name);
189 const char* c_str_copy = value.c_str();
190 attr.write(*strType, &c_str_copy);
195 const std::string& name)
const {
197 hsize_t matRows = hsize_t(matrix.rows());
198 hsize_t matCols = hsize_t(matrix.cols());
200 hsize_t dims[2] = {matRows, matCols};
206 H5::DataSpace dp(2, dims);
210 dataset = loc.createDataSet(name.c_str(), *dataType, dp);
211 }
catch (H5::GroupIException&) {
212 dataset = loc.openDataSet(name.c_str());
215 hsize_t matColSize = matrix.derived().outerStride();
217 hsize_t fileRows = matCols;
219 hsize_t fStride[2] = {1, fileRows};
220 hsize_t fCount[2] = {1, 1};
221 hsize_t fBlock[2] = {1, fileRows};
223 hsize_t mStride[2] = {matColSize, 1};
224 hsize_t mCount[2] = {1, 1};
225 hsize_t mBlock[2] = {matCols, 1};
227 hsize_t mDim[2] = {matCols, matColSize};
228 H5::DataSpace mspace(2, mDim);
230 for (hsize_t i = 0; i < matRows; i++) {
231 hsize_t fStart[2] = {i, 0};
232 hsize_t mStart[2] = {0, i};
233 dp.selectHyperslab(H5S_SELECT_SET, fCount, fStart, fStride, fBlock);
234 mspace.selectHyperslab(H5S_SELECT_SET, mCount, mStart, mStride, mBlock);
235 dataset.write(matrix.derived().data(), *dataType, mspace, dp);
240 typename std::enable_if<std::is_fundamental<T>::value>::type
WriteData(
241 const CptLoc& loc,
const std::vector<T> v,
242 const std::string& name)
const {
243 hsize_t dims[2] = {(hsize_t)v.size(), 1};
247 H5::DataSpace dp(2, dims);
249 dataset = loc.createDataSet(name.c_str(), *dataType, dp);
250 }
catch (H5::GroupIException&) {
251 dataset = loc.openDataSet(name.c_str());
253 dataset.write(v.data(), *dataType);
257 const std::string& name)
const {
259 hsize_t dims[1] = {(hsize_t)v.size()};
261 std::vector<const char*> c_str_copy;
262 c_str_copy.reserve(v.size());
263 for (
const std::string& s : v) {
264 c_str_copy.push_back(s.c_str());
268 H5::DataSpace dp(1, dims);
270 dataset = loc.createDataSet(name.c_str(), *dataType, dp);
271 }
catch (H5::GroupIException&) {
272 dataset = loc.openDataSet(name.c_str());
274 dataset.write(c_str_copy.data(), *dataType);