void HDF5IO::saveMatrix(const std::string& GroupName, const std::string& Name, const ComplexMatrixType& M) { try{ H5::CompType ComplexDataType = this->openCompType("complex"); hsize_t Dims[2] = {hsize_t(M.rows()),hsize_t(M.cols())}; H5::DataSpace dataspace(2,Dims); H5::Group FG = getGroup( GroupName ); try{ H5::Exception::dontPrint(); H5::DataSet dset = FG.openDataSet(Name.c_str()); // dset.extend( Dims );not working dset.write(M.data(), ComplexDataType); } catch ( const H5::GroupIException not_found_error ){ H5::DataSet dset = FG.createDataSet(Name.c_str(), ComplexDataType, dataspace); dset.write(M.data(), ComplexDataType); } catch ( const H5::DataSetIException error ){ error.printError(); RUNTIME_ERROR("HDF5IO::saveComplexMatrix at "); } FG.close(); } catch( const H5::Exception error ){ error.printError(); RUNTIME_ERROR("HDF5IO::saveComplexMatrix at "); } }
void HDF5IO::saveStdVector(const std::string& GroupName, const std::string& Name, const std::vector<std::complex<double> >& V) { try{ H5::CompType ComplexDataType = openCompType("complex"); hsize_t Dim[1] = {hsize_t(V.size())}; H5::DataSpace dataspace(1,Dim); H5::Group FG = getGroup( GroupName.c_str() ); try{ H5::Exception::dontPrint(); H5::DataSet dataset = FG.openDataSet(Name.c_str()); dataset.write(V.data(), ComplexDataType, dataspace); } catch( const H5::GroupIException not_found_error ){ H5::DataSet dataset = FG.createDataSet(Name.c_str(), ComplexDataType, dataspace); dataset.write(V.data(), ComplexDataType); } catch( const H5::FileIException error){ error.printError(); } catch( const H5::DataSetIException error){ error.printError(); } FG.close(); } catch( const H5::Exception err ){ err.printError(); RUNTIME_ERROR("HDF5IO::saveComplexStdVector. "); } }
void BufferedHDF2DArray<T>::Create(H5::CommonFG *_container, string _datasetName, unsigned int _rowLength) { container = _container; datasetName = _datasetName; rowLength = (unsigned int)_rowLength; // // Make life easy if the buffer is too small to fit a row -- // resize it so that rows may be copied and written out in an // atomic unit. // if (this->bufferSize < rowLength) { // When the buffer size is greater than 0, the write buffer // should exist. if (this->bufferSize > 0) { assert(this->writeBuffer != NULL); delete[] this->writeBuffer; } this->writeBuffer = new T[rowLength]; this->bufferSize = rowLength; } hsize_t dataSize[2] = {0, hsize_t(rowLength)}; hsize_t maxDataSize[2] = {H5S_UNLIMITED, hsize_t(rowLength)}; H5::DataSpace fileSpace(2, dataSize, maxDataSize); H5::DSetCreatPropList cparms; /* * For some reason, chunking must be enabled when creating a dataset * that has an unlimited dimension. Of course, this is not * mentioned in the hdf5 c++ documentation, because that * docuemntation was written for people who enjoy learning how to * use an API by reading comments in source code. */ hsize_t chunkDims[2] = {16384, hsize_t(rowLength)}; cparms.setChunk( 2, chunkDims ); TypedCreate(fileSpace, cparms); fileSpace.close(); // // Set some flags that indicate this dataset is ready for writing. // fileDataSpaceInitialized = true; isInitialized = true; }
void HDF5IO::saveMatrix(const std::string& GroupName, const std::string& Name, const RealMatrixType& M) { try{ hsize_t Dims[2] = {hsize_t(M.rows()),hsize_t(M.cols())}; H5::DataSpace dataspace(2,Dims); H5::Group FG = getGroup( GroupName ); try{ H5::Exception::dontPrint(); H5::DataSet DataSet = FG.openDataSet(Name.c_str()); DataSet.write(M.data(),H5::PredType::NATIVE_DOUBLE,dataspace); } catch ( const H5::GroupIException not_found_error ){ H5::DataSet DataSet = FG.createDataSet(Name.c_str(),H5::PredType::NATIVE_DOUBLE,dataspace); DataSet.write(M.data(),H5::PredType::NATIVE_DOUBLE); } FG.close(); } catch( const H5::Exception err ){ RUNTIME_ERROR("HDF5IO::saveRealMatrix"); } }
/* only for Eigen3 matrix/vector */ void HDF5IO::saveVector(const std::string& GroupName, const std::string& Name, const RealVectorType& V) { hsize_t Dim[1] = {hsize_t(V.size())}; H5::DataSpace dspace(1,Dim); H5::Group FG = getGroup( GroupName ); try{ H5::Exception::dontPrint(); H5::DataSet DataSet = FG.openDataSet(Name.c_str()); DataSet.write(V.data(),H5::PredType::NATIVE_DOUBLE, dspace); } catch ( const H5::GroupIException not_found_error ){ H5::DataSet DataSet = FG.createDataSet(Name.c_str(), H5::PredType::NATIVE_DOUBLE,dspace); DataSet.write(V.data(),H5::PredType::NATIVE_DOUBLE); } FG.close(); }
void HDF5IO::saveStdVector(const std::string& GroupName, const std::string& Name, const std::vector<double>& V) { try{ hsize_t Dim[1] = {hsize_t(V.size())}; H5::DataSpace dataspace(1,Dim); H5::Group FG = getGroup( GroupName ); try{ H5::Exception::dontPrint(); H5::DataSet dataset = FG.openDataSet(Name.c_str()); dataset.write(V.data(),H5::PredType::NATIVE_DOUBLE, dataspace); } catch ( const H5::GroupIException not_found_error ){ H5::DataSet dataset = FG.createDataSet(Name.c_str(), H5::PredType::NATIVE_DOUBLE,dataspace); dataset.write(V.data(),H5::PredType::NATIVE_DOUBLE); } FG.close(); } catch( const H5::Exception err ){ RUNTIME_ERROR("HDF5IO::saveRealStdVector"); } }
void HDF5IO::saveVector(const std::string& GroupName, const std::string& Name, const ComplexVectorType& V) { try{ H5::CompType ComplexDataType = this->openCompType("complex"); hsize_t Dim[1] = {hsize_t(V.size())}; H5::DataSpace dspace(1,Dim); H5::Group FG = getGroup( GroupName ); try{ H5::Exception::dontPrint(); H5::DataSet DataSet = FG.openDataSet(Name.c_str()); DataSet.write(V.data(), ComplexDataType, dspace); } catch ( const H5::GroupIException not_found_error ){ H5::DataSet DataSet = FG.createDataSet(Name.c_str(), ComplexDataType, dspace); DataSet.write(V.data(), ComplexDataType); } FG.close(); } catch ( const H5::DataSetIException error ){ error.printError(); RUNTIME_ERROR("HDF5IO::saveComplexVector at "); } }
inline DataSpace::DataSpace(const size_t dim1){ const hsize_t dims = hsize_t(dim1); if( (_hid = H5Screate_simple(1, &dims, NULL) ) < 0){ throw DataSpaceException("Unable to create dataspace"); } }