void Bundle2::storeParameters(H5::H5File& file) const { H5::Group root = file.openGroup("/"); H5::DataSpace scalar; H5::Attribute attr = root.createAttribute("version", H5::PredType::STD_U32LE, scalar); attr.write(H5::PredType::NATIVE_UINT, &version_); attr.close(); unsigned char r2 = parameters_.reduce2?1:0; attr = root.createAttribute("reduce2", H5::PredType::STD_U8LE, scalar); attr.write(H5::PredType::NATIVE_UCHAR, &r2); attr.close(); attr = root.createAttribute("xROI", H5::PredType::STD_U32LE, scalar); attr.write(H5::PredType::NATIVE_UINT, ¶meters_.xROI); attr.close(); attr = root.createAttribute("yROI", H5::PredType::STD_U32LE, scalar); attr.write(H5::PredType::NATIVE_UINT, ¶meters_.yROI); attr.close(); scalar.close(); root.close(); }
void HDFAtom<std::vector<std::string> >::Read(std::vector<std::string> &values) { std::string value; /* * This attribute is an array of std::strings. They are read in by * storing pointers to std::strings in memory controlled by HDF. To read * the std::strings, read the pointers into a temporary array, then copy * those std::strings to the values array. This way when the values array * is destroyed, it will not try and get rid of space that is under * HDF control. */ H5::DataSpace attributeSpace = attribute.getSpace(); hsize_t nPoints; nPoints = attributeSpace.getSelectNpoints(); H5::DataType attrType = attribute.getDataType(); // necessary for attr.read() // Declare and initialize std::vector of pointers to std::string attribute list. std::vector<char*> ptrsToHDFControlledMemory; ptrsToHDFControlledMemory.resize(nPoints); // Copy the pointers. attribute.read(attrType, &ptrsToHDFControlledMemory[0]); // Copy the std::strings into memory the main program has control over. unsigned int i; for (i = 0; i < ptrsToHDFControlledMemory.size(); i++ ){ values.push_back(ptrsToHDFControlledMemory[i]); free(ptrsToHDFControlledMemory[i]); } }
void addrow( H5::DataSet& ds, const std::vector<double>& rowtowrite ) { //Get the space (since it may have grown in length since last time of course ) H5::DataSpace origspace = ds.getSpace(); //get the rank, even though I know it is 2 int rank = origspace.getSimpleExtentNdims(); //Get the actual dimensions of the ranks. hsize_t dims[rank]; int ndims = origspace.getSimpleExtentDims( dims, NULL); //Want to ADD a row, so need to offset at row = nrows, and col = 0; hsize_t offset[rank] = { dims[0], 0 }; hsize_t dims_toadd[rank] = { 1, rowtowrite.size() }; //will write 1 row, ncols columns. //Compute "new" size (extended by 1 row). hsize_t size[rank] = { dims[0]+dims_toadd[0], rowtowrite.size() }; //Do the extension. ds.extend( size ); //Get the new (extended) space, and select the hyperslab to write the row to. origspace = ds.getSpace(); origspace.selectHyperslab( H5S_SELECT_SET, dims_toadd, offset ); //Make the "memory" data space? H5::DataSpace toaddspace(rank, dims_toadd); ds.write( rowtowrite.data(), H5::PredType::NATIVE_DOUBLE, toaddspace, origspace ); //Can close toaddspace/origspace with no effect. //Can also close/open data set at the beginning of each time with no effect. }
void ossim_hdf5::getExtents( const H5::DataSet* dataset, std::vector<ossim_uint32>& extents ) { extents.clear(); if ( dataset ) { // Get dataspace of the dataset. H5::DataSpace dataspace = dataset->getSpace(); // Number of dimensions: int ndims = dataspace.getSimpleExtentNdims(); if ( ndims ) { //hsize_t dims_out[ndims]; std::vector<hsize_t> dims_out(ndims); dataspace.getSimpleExtentDims( &dims_out.front(), 0 ); for ( ossim_int32 i = 0; i < ndims; ++i ) { extents.push_back(static_cast<ossim_uint32>(dims_out[i])); } } dataspace.close(); } }
void Hdf5Handler::getColumnEntries( void* data, const std::string& dataSetName, const hsize_t numEntries, const hsize_t offset) const { try { const ColumnData& columnData(getColumnData(dataSetName)); columnData.dataSpace.selectHyperslab( H5S_SELECT_SET, &numEntries, &offset); const hsize_t outOffset = 0; const H5::DataSpace outSpace(1, &numEntries); outSpace.selectHyperslab(H5S_SELECT_SET, &numEntries, &outOffset); columnData.dataSet.read( data, columnData.predType, outSpace, columnData.dataSpace); } catch (const H5::Exception&) { throw hdf5_error("Could not read from dataset"); } }
UInt GetDatasetNDim(H5::CommonFG &parentGroup, std::string datasetName) { HDFData tmpDataset; tmpDataset.InitializeDataset(parentGroup, datasetName); H5::DataSpace dataspace = tmpDataset.dataset.getSpace(); UInt nDims = dataspace.getSimpleExtentNdims(); dataspace.close(); tmpDataset.dataset.close(); return nDims; }
int H5Signal::signal_count(void) /*----------------------------*/ { H5::DataSpace uspace = dataset.openAttribute("uri").getSpace() ; int udims = uspace.getSimpleExtentNdims() ; if (udims == 0) return 1 ; // SCALAR else { if (udims != 1) throw H5Exception("Dataset's 'uri' attribute has wrong shape: " + uri) ; return uspace.getSimpleExtentNpoints() ; } }
/** * @brief Returns a pointer to a std::vector<float> containing the values of the selected variable * * This allocates a new std::vector<float> pointer. Make sure you * delete the contents when you done using it, or you will have a memory leak. * * @param variable * @return std::vector<float> containing the values of the selected variable. */ std::vector<float>* HDF5FileReader::getVariable(const std::string& variable) { std::vector<float>* variableData = new std::vector<float>(); if (this->doesVariableExist(variable)) { //std::cout << "reading " << variable << std::endl; //get variable number // long variableNum = this->getVariableID(variable); //std::cout << "variableNum for " << variable << ": " << variableNum << std::endl; //get dim sizes H5::Group group = this->current_file->openGroup("Variables"); //cout << "variable: " << variable << ": " << counts[0] << endl; H5::DataSet * dataset = new H5::DataSet(group.openDataSet(variable)); H5::DataSpace dataspace = dataset->getSpace(); int rank = dataspace.getSimpleExtentNdims(); //should be 1 hsize_t count[1]; hsize_t offset[1] = {0}; // int ndims = dataspace.getSimpleExtentDims(count, NULL); //std::cout << "count[0]: " << count[0] << std::endl; float * buffer = new float[count[0]]; dataspace.selectHyperslab(H5S_SELECT_SET, count, offset); H5::DataSpace memspace( rank, count); memspace.selectHyperslab(H5S_SELECT_SET, count, offset); dataset->read(buffer, H5::PredType::NATIVE_FLOAT, memspace, dataspace); //std::cout << "after read" << std::endl; //add data to vector type, and delete original array variableData->reserve(count[0]); for (int i = 0; i < count[0]; i++) { variableData->push_back(buffer[i]); } //std::cout << "after adding to variableData vector" << std::endl; delete[] buffer; delete dataset; //std::cout << "finished reading " << variable << std::endl; //std::cout << "size of variable: " << variableData.size() << std::endl; //std::cout << "dimSizes[0]: " << dimSizes[0] << std::endl; } return variableData; }
const std::vector<hsize_t> TableDims(){ if(flags_ != hdf5::READ) throw std::runtime_error("TableDims() is only valid in READ mode"); H5::DataSet dSet = file_->openDataSet("T00000000"); H5::DataSpace dSpace = dSet.getSpace(); std::vector<hsize_t> dims(dSpace.getSimpleExtentNdims()); dSpace.getSimpleExtentDims(&dims[0]); return dims; }
H5::DataSpace dataspace_from_LS ( mini_vector<hsize_t, R> const & Ltot, mini_vector<hsize_t, R> const & L, mini_vector<hsize_t, R> const & S, mini_vector<hsize_t, R> const & offset = mini_vector<hsize_t,R>() ) { static const unsigned int rank = R + (IsComplex ? 1 : 0); hsize_t totdimsf[rank], dimsf [rank], stridesf[rank], offsetf[rank]; // dataset dimensions for (size_t u=0; u<R ; ++u) { offsetf[u] = offset[u]; dimsf[u] = L[u]; totdimsf[u] = Ltot[u]; stridesf[u] = S[u]; } if (IsComplex) { offsetf[rank-1]=0; dimsf[rank-1]=2; totdimsf[rank-1] = 2; stridesf[rank-1]=1; } H5::DataSpace ds ( rank, totdimsf ); ds.selectHyperslab (H5S_SELECT_SET , dimsf, offsetf, stridesf); return ds; }
NDArray<T, Nd> NDArray<T,Nd>::ReadFromH5(const H5::DataSet& h5Dset) { H5::DataSpace dspace = h5Dset.getSpace(); int ndim = dspace.getSimpleExtentNdims(); if (ndim>Nd) throw std::range_error("Too many dimensions in H5 dataset for NDArray"); hsize_t dimSize[ndim]; dspace.getSimpleExtentDims(dimSize); std::array<std::size_t, Nd> dimSizeArr; for (int i=0; i<Nd; ++i) dimSizeArr[i] = dimSize[i]; NDArray<T, Nd> arr(dimSizeArr); // Read in data here H5::DataType h5DType = GetH5DataType<T>(); h5Dset.read(arr.mData, h5DType); return arr; }
void HDF5IO::loadStdVector(const std::string& GroupName, const std::string& Name, std::vector<RealType>& V) { try{ H5::Group FG = getGroup( GroupName ); H5::DataSet DataSet = FG.openDataSet(Name.c_str()); H5::DataSpace DataSpace = DataSet.getSpace(); if(DataSpace.getSimpleExtentNdims() != 1) throw(H5::DataSpaceIException("HDF5IO::loadRealVector()","Unexpected multidimentional dataspace.")); V.resize(DataSpace.getSimpleExtentNpoints()); DataSet.read(V.data(),H5::PredType::NATIVE_DOUBLE); FG.close(); } catch( const H5::Exception err ){ RUNTIME_ERROR("HDF5IO::loadRealStdVector"); } }
inline void read_values(H5::DataSet& dataset, H5::DataSpace& data_space, dimension const& dimx, dimension const& dimy, dimension const& dimz, double* values) { using namespace H5; // Define the hyperslab for file based data. hsize_t data_offset[dimension::dim] = { dimx.offset_, dimy.offset_, dimz.offset_ }; hsize_t data_count[dimension::dim] = { dimx.count_, dimy.count_, dimz.count_ }; data_space.selectHyperslab(H5S_SELECT_SET, data_count, data_offset); // Memory dataspace. DataSpace mem_space (dimension::dim, data_count); // Define the hyperslab for data in memory. hsize_t mem_offset[dimension::dim] = { 0, 0, 0 }; mem_space.selectHyperslab(H5S_SELECT_SET, data_count, mem_offset); // Read data to memory. dataset.read(values, PredType::NATIVE_DOUBLE, mem_space, data_space); }
void HDF5IO::loadStdVector(const std::string& GroupName, const std::string& Name, std::vector<ComplexType>& V) { try{ H5::CompType ComplexDataType = this->openCompType("complex"); H5::Group FG = getGroup( GroupName ); H5::DataSet DataSet = FG.openDataSet(Name.c_str()); H5::DataSpace DataSpace = DataSet.getSpace(); if(DataSpace.getSimpleExtentNdims() != 1) throw(H5::DataSpaceIException("HDF5IO::loadComplexVector()","Unexpected multidimentional dataspace.")); V.resize(DataSpace.getSimpleExtentNpoints()); DataSet.read(V.data(),ComplexDataType); FG.close(); } catch( const H5::Exception err ){ RUNTIME_ERROR("HDF5IO::loadComplexStdVector"); } }
void Bundle2::closeSaveStream() { H5::DataSpace scalar; // Saving remaining POI information H5::Group poiGroup = streamFile_->openGroup("/POI"); H5::Attribute attr = poiGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar); hsize_t count = poiFirstFrame_; attr.write(H5::PredType::NATIVE_HSIZE, &count); attr.close(); poiGroup.close(); scalar.close(); // Closing HDF5 file streamFile_->close(); delete streamFile_; streamFile_ = NULL; }
void HDF5IO::loadVector(const std::string& GroupName, const std::string& Name, RealVectorType& V) { H5::Group FG = getGroup( GroupName ); H5::DataSet DataSet = FG.openDataSet(Name.c_str()); H5::DataSpace DataSpace = DataSet.getSpace(); if(DataSpace.getSimpleExtentNdims() != 1) throw(H5::DataSpaceIException("HDF5IO::loadRealVector()", "Unexpected multidimentional dataspace.")); V.resize(DataSpace.getSimpleExtentNpoints()); try{ DataSet.read(V.data(),H5::PredType::NATIVE_DOUBLE); }catch( H5::GroupIException not_found_error ){ RUNTIME_ERROR("No dataset found in loadRealVector. "); } FG.close(); }
/** * @brief Returns a value in the flat array of the variable and index requested. * * Use this method on variables that have a type of int * * @param variable The variable in the file * @param index The index in the variable's array in the file * * @return int of the value in the array. */ int HDF5FileReader::getVariableIntAtIndex(const std::string& variable, long index) { // long counts[1]; int value = std::numeric_limits<int>::min(); if (this->doesVariableExist(variable)) { //std::cout << "reading " << variable << std::endl; //get variable number // long variableNum = this->getVariableID(variable); //get dim sizes H5::Group group = this->current_file->openGroup("Variables"); //cout << "variable: " << variable << ": " << counts[0] << endl; H5::DataSet * dataset = new H5::DataSet(group.openDataSet(variable)); H5::DataSpace dataspace = dataset->getSpace(); int rank = dataspace.getSimpleExtentNdims(); //should be 1 hsize_t count[1] = {1}; hsize_t offset[1] = {0}; //int ndims = dataspace.getSimpleExtentDims(count, NULL); float * buffer = new float[count[0]]; dataspace.selectHyperslab(H5S_SELECT_SET, count, offset); hsize_t dim[] = {count[0]}; H5::DataSpace memspace( rank, dim); memspace.selectHyperslab(H5S_SELECT_SET, dim, offset); dataset->read(buffer, H5::PredType::NATIVE_INT, memspace, dataspace); //add data to vector type, and delete original array value = buffer[0]; delete[] buffer; delete dataset; } return value; //std::cout << "finished reading " << variable << std::endl; //std::cout << "size of variable: " << variableData.size() << std::endl; //std::cout << "dimSizes[0]: " << dimSizes[0] << std::endl; }
size_t H5Signal::clock_size(void) /*-----------------------------*/ { try { H5::Attribute attr = dataset.openAttribute("clock") ; hobj_ref_t ref ; attr.read(H5::PredType::STD_REF_OBJ, &ref) ; attr.close() ; H5::DataSet clk(H5Rdereference(H5Iget_file_id(dataset.getId()), H5R_OBJECT, &ref)) ; H5::DataSpace cspace = clk.getSpace() ; int cdims = cspace.getSimpleExtentNdims() ; hsize_t cshape[cdims] ; cspace.getSimpleExtentDims(cshape) ; return cshape[0] ; } catch (H5::AttributeIException e) { } return -1 ; }
/** Retrieves the dimensions of the dataset */ int hdfutil::GetDsDims (const H5::DataSet & dataset, int dims[3]) { H5::DataSpace dataspace = dataset.getSpace(); bool simple = dataspace.isSimple(); if (!simple) throw std::runtime_error("complex HDF5 dataspace"); int rank = (int)dataspace.getSimpleExtentNdims(); if (rank > 3) throw std::runtime_error("unsupported dimensionality"); hsize_t h5_dims[3]; dataspace.getSimpleExtentDims(h5_dims, NULL); for (int i = 0; i < rank; i++) dims[i] = (int)h5_dims[i]; for (int i = rank; i < 3; i++) dims[i] = -1; return rank; }
bool readDataset1D(const H5::H5File &file, const std::string &name, std::vector<_Tp> &data) { H5::DataSet dataset = file.openDataSet(name); H5::DataSpace dataspace = dataset.getSpace(); hsize_t dims_out[1]; int rank = dataspace.getSimpleExtentDims( dims_out, NULL); int _type; bool read = getNodeType(dataset, _type); read &= (_type == StorageNode::SEQ); read &= (rank == 1); if (!read) return read; data.resize(dims_out[0]); dataset.read(data.data(), dataset.getDataType()); return true; }
void HDF5IO::loadMatrix(const std::string& GroupName, const std::string& Name, ComplexMatrixType& M) { try{ H5::CompType ComplexDataType = this->openCompType("complex"); H5::Group FG = getGroup( GroupName ); H5::DataSet DataSet = FG.openDataSet(Name.c_str()); H5::DataSpace DataSpace = DataSet.getSpace(); if(DataSpace.getSimpleExtentNdims() != 2) throw(H5::DataSpaceIException("HDF5IO::loadMatrix()","A dataspace must be precisely two-dimensional.")); hsize_t Dims[2]; DataSpace.getSimpleExtentDims(Dims); M.resize(Dims[0],Dims[1]); DataSet.read(M.data(), ComplexDataType); FG.close(); } catch( const H5::Exception err ){ RUNTIME_ERROR("HDF5IO::loadComplexMatrix at "); } }
/** * Returns a pointer to a std::vector<float> containing the values of the selected variable * in the range specified by the startIndex and count (the number of records to read) stored * in the selected file. This allocates a new std::vector<float> pointer. Make sure you * delete the contents when you done using it, or you will have a memory leak. * @param variableID * @param startIndex * @param count * @return std::vector<float> containing the values of the selected variable. */ std::vector<float>* HDF5FileReader::getVariable(long variable, long indexOffset, long count) { std::vector<float>* variableData = new std::vector<float>(); //get dim sizes H5::Group group = this->current_file->openGroup("Variables"); //cout << "variable: " << variable << ": " << counts[0] << endl; H5::DataSet * dataset = new H5::DataSet(group.openDataSet(group.getObjnameByIdx(variable))); H5::DataSpace dataspace = dataset->getSpace(); int rank = dataspace.getSimpleExtentNdims(); //should be 1 hsize_t length[1] = {count}; hsize_t offset[1] = {indexOffset}; //int ndims = dataspace.getSimpleExtentDims(count, NULL); float * buffer = new float[length[0]]; dataspace.selectHyperslab(H5S_SELECT_SET, length, offset); hsize_t dim[] = {length[0]}; H5::DataSpace memspace( rank, dim); memspace.selectHyperslab(H5S_SELECT_SET, dim, offset); dataset->read(buffer, H5::PredType::NATIVE_FLOAT, memspace, dataspace); //add data to vector type, and delete original array variableData->reserve(length[0]); for (int i = 0; i < length[0]; i++) { variableData->push_back(buffer[i]); } delete[] buffer; delete dataset; //std::cout << "finished reading " << variable << std::endl; //std::cout << "size of variable: " << variableData.size() << std::endl; //std::cout << "dimSizes[0]: " << dimSizes[0] << std::endl; return variableData; }
arma::Mat<uint16_t> readLUT(const std::string& path) { H5::H5File file (path.c_str(), H5F_ACC_RDONLY); H5::DataSet ds = file.openDataSet("LUT"); H5::DataSpace filespace = ds.getSpace(); int ndims = filespace.getSimpleExtentNdims(); assert(ndims == 2); hsize_t dims[2] = {1, 1}; filespace.getSimpleExtentDims(dims); H5::DataSpace memspace (ndims, dims); arma::Mat<uint16_t> res (dims[0], dims[1]); ds.read(res.memptr(), H5::PredType::NATIVE_UINT16, memspace, filespace); filespace.close(); memspace.close(); ds.close(); file.close(); // NOTE: Armadillo stores data in column-major order, while HDF5 uses // row-major ordering. Above, we read the data directly from HDF5 into // the arma matrix, so it was implicitly transposed. The next function // fixes this problem. arma::inplace_trans(res); return res; }
/// Return the attribute name of obj, and "" if the attribute does not exist. inline std::string read_string_attribute (H5::H5Object const * obj, std::string name ) { std::string value =""; H5::Attribute attr; if (H5LTfind_attribute(obj -> getId(), name.c_str() )==0) return value;// not present // can not find how to get the size with hl. Using full interface //herr_t err2 = H5LTget_attribute_string(gr.getId(), x.c_str(), name.c_str() , &(buf.front()) ) ; //value.append( &(buf.front()) ); try { attr= obj->openAttribute(name.c_str());} catch (H5::AttributeIException) { return value;} try { H5::DataSpace dataspace = attr.getSpace(); int rank = dataspace.getSimpleExtentNdims(); if (rank != 0) TRIQS_RUNTIME_ERROR << "Reading a string attribute and got rank !=0"; size_t size = attr.getStorageSize(); H5::StrType strdatatype(H5::PredType::C_S1, size+1); std::vector<char> buf(size+1, 0x00); attr.read(strdatatype, (void *)(&buf[0])); value.append( &(buf.front()) ); } TRIQS_ARRAYS_H5_CATCH_EXCEPTION; return value; }
static void read_attr(Attribute *attr, H5::Group g, cpath basename, cpath group_path, cpath name, BaseType &type) { int total = 1; H5::Attribute h5attr = g.openAttribute(name.generic_string().c_str()); type = toBaseType(H5Aget_type(h5attr.getId())); H5::DataSpace space = h5attr.getSpace(); int dimcount = space.getSimpleExtentNdims(); hsize_t *dims = new hsize_t[dimcount]; hsize_t *maxdims = new hsize_t[dimcount]; space.getSimpleExtentDims(dims, maxdims); for(int i=0;i<dimcount;i++) total *= dims[i]; group_path = remove_prefix(group_path, basename); name = group_path / name; //legacy attribute reading if (dimcount == 1) { void *buf = malloc(baseType_size(type)*total); h5attr.read(toH5NativeDataType(type), buf); attr->set<hsize_t>(name, dimcount, dims, type, buf); } else { Mat m; Mat_H5AttrRead(m, h5attr); attr->setName(name); attr->set(m); } delete[] dims; delete[] maxdims; }
void Datafile::write_time_step_history(size_t index, double eps) { // pack values of index and eps into a struct in memory time_step_history_pair pair; pair.step = static_cast<int>(index); pair.time_step = eps; try { ensure_time_step_history_data(); // calculate current size, extend if needed, and write data. You know the drill. H5::DataSpace tempspace = time_step_history_data.getSpace(); tempspace.selectAll(); hsize_t cur_size = tempspace.getSelectNpoints(); hsize_t new_size = cur_size + 1; space_1d.setExtentSimple(1, &new_size); time_step_history_data.extend(&new_size); space_1d.selectElements(H5S_SELECT_SET, 1, &cur_size); validate_selection(space_1d); time_step_history_data.write(&pair, time_step_history_type, scalar_space, space_1d); } catch(H5::Exception& e) { e.printError(); throw; } }
void Bundle2::streamPOI(size_t frame) { H5::DataSpace scalar; H5::Group poiGroup = streamFile_->openGroup("/POI"); for(size_t i = poiFirstFrame_; i <= frame; ++i) { const std::string frameGroupName = boost::str(boost::format("Frame %1$04d") % i); H5::Group frameGroup = poiGroup.createGroup(frameGroupName); hsize_t count = poi_[(ptrdiff_t)i - (ptrdiff_t)poiFirstFrame_].size(); H5::Attribute attr = frameGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar); attr.write(H5::PredType::NATIVE_HSIZE, &count); attr.close(); for(size_t camera = 0; camera < poi_[(ptrdiff_t)i - (ptrdiff_t)poiFirstFrame_].size(); ++camera) poi_[(ptrdiff_t)i - (ptrdiff_t)poiFirstFrame_][camera].save(frameGroup, camera); frameGroup.close(); } poiGroup.close(); scalar.close(); poi_.erase(poi_.begin(), poi_.begin() + (ptrdiff_t)frame - (ptrdiff_t)poiFirstFrame_ + 1); poiFirstFrame_ = frame + 1; }
std::vector<double> readlastrow( H5::DataSet& ds ) { H5::DataSpace origspace = ds.getSpace(); int rank = origspace.getSimpleExtentNdims(); hsize_t dims[rank]; int ndims = origspace.getSimpleExtentDims( dims, NULL); hsize_t nrows=dims[0]; hsize_t ncols=dims[1]; std::vector<double> returnvect( ncols ); hsize_t targrowoffset = nrows-1; hsize_t targcoloffset = 0; hsize_t dimsmem[rank] = {1, ncols}; H5::DataSpace memspace(rank, dimsmem); hsize_t offset[rank] = { targrowoffset, targcoloffset }; origspace.selectHyperslab( H5S_SELECT_SET, dimsmem, offset ); ds.read( returnvect.data(), H5::PredType::NATIVE_DOUBLE, memspace, origspace ); return returnvect; }
inline void read_values(H5::DataSet& dataset, H5::DataSpace& data_space, hsize_t offset, hsize_t count, double* values) { using namespace H5; // Define hyperslab for file based data hsize_t data_offset[1] = { offset }; hsize_t data_count[1] = { count }; data_space.selectHyperslab(H5S_SELECT_SET, data_count, data_offset); // memory dataspace hsize_t mem_dims[1] = { count }; DataSpace mem_space (1, mem_dims); // Define hyperslab for data in memory hsize_t mem_offset[1] = { 0 }; hsize_t mem_count[1] = { count }; mem_space.selectHyperslab(H5S_SELECT_SET, mem_count, mem_offset); // read data to memory dataset.read(values, PredType::NATIVE_DOUBLE, mem_space, data_space); }
std::vector<double> readEloss(const std::string& path) { H5::H5File file (path.c_str(), H5F_ACC_RDONLY); H5::DataSet ds = file.openDataSet("eloss"); H5::DataSpace filespace = ds.getSpace(); int ndims = filespace.getSimpleExtentNdims(); assert(ndims == 1); hsize_t dim; filespace.getSimpleExtentDims(&dim); H5::DataSpace memspace (ndims, &dim); std::vector<double> res (dim); ds.read(res.data(), H5::PredType::NATIVE_DOUBLE, memspace, filespace); filespace.close(); memspace.close(); ds.close(); file.close(); return res; }