本文整理汇总了C++中h5::DataSpace类的典型用法代码示例。如果您正苦于以下问题:C++ DataSpace类的具体用法?C++ DataSpace怎么用?C++ DataSpace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataSpace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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();
}
示例2:
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]);
}
}
示例3: addrow
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.
}
示例4:
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();
}
}
示例5: columnData
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");
}
}
示例6: GetDatasetNDim
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;
}
示例7:
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() ;
}
}
示例8: memspace
/**
* @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;
}
示例9: runtime_error
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;
}
示例10: dataspace_from_LS
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;
}
示例11: range_error
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;
}
示例12: getGroup
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");
}
}
示例13: mem_space
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);
}
示例14: clk
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 ;
}
示例15: GetDsDims
/** 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;
}