本文整理汇总了C++中DataSpace类的典型用法代码示例。如果您正苦于以下问题:C++ DataSpace类的具体用法?C++ DataSpace怎么用?C++ DataSpace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataSpace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pluginLoad
void pluginLoad()
{
if (notifyFrequency > 0)
{
// number of cells on the current CPU for each direction
const DataSpace<simDim> nrOfGpuCells = Environment<simDim>::get().SubGrid().getLocalDomain().size;
// create as much storage as cells in the direction we are interested in:
// on gpu und host
sliceDataField = new GridBuffer<float3_X, DIM1 >
(DataSpace<DIM1 > (nrOfGpuCells.y()));
Environment<>::get().PluginConnector().setNotificationPeriod(this, notifyFrequency);
const int rank = Environment<simDim>::get().GridController().getGlobalRank();
// open output file
std::stringstream oFileName;
oFileName << "lineSliceFields_" << rank << ".txt";
outfile.open(oFileName.str().c_str(), std::ofstream::out | std::ostream::trunc);
outfile.precision(8);
outfile.setf(std::ios::scientific);
}
}
示例2: ch5ChunkSel
// Function to return a selected part of a data frame as a list
List ch5ChunkSel(string chunkName, CharacterVector selCols, string filePath)
{
// Open the file in Read/Write Mode, H5F_ACC_RDONLY
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Opening the data set
DataSet dataset = file->openDataSet((H5std_string)chunkName);
// Opening the data space
DataSpace dataspace = dataset.getSpace();
// Get the number of dimensions
int ndim = dataspace.getSimpleExtentNdims();
// Create a dimension object to be filled with the dimensions of the data set
hsize_t dims[ndim];
// Fill the dimension of the dataset
dataspace.getSimpleExtentDims(dims, NULL);
// Create the return data
// Filling the matrix with data form the dataspace
SEXP data;
// Allocating a matrix of the right size and dimension
data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1]));
// Filling the matrix with data form the dataspace
dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace);
UNPROTECT(1);
// converting the R object to a numeric matrix
NumericMatrix M = as<NumericMatrix>(data);
CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath);
CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath);
// Create the output
List DF;
string colName;
string colClass;
NumericVector vec;
CharacterVector levels;
int n = selCols.size();
IntegerVector sel(n);
int selN;
// First we need to find which of the columns has been selected
sel = match(selCols, colNames);
for(int i = 0; i < n; i++)
{
colName = selCols[i];
selN = sel[i] - 1;
colClass = colClasses[selN];
if(colClass != "factor")
{
DF[colName] = M(_, selN);
}else{
vec = M(_, selN);
levels = (CharacterVector)ch5ReadFactor(colName, filePath);
DF[colName] = cCreateFactor(vec, levels);
}
}
dataset.close();
file->close();
return DF;
}
示例3: extract_data
void extract_data(std::string const& datafilename, char const* name,
double* values, dimension const& dimx, dimension const& dimy,
dimension const& dimz)
{
try {
using namespace H5;
// Turn off the auto-printing when failure occurs
Exception::dontPrint();
H5File file(datafilename, H5F_ACC_RDONLY);
DataSet dataset = file.openDataSet(name);
DataSpace dataspace = dataset.getSpace();
// Verify number of dimensions.
HPX_ASSERT(dataspace.getSimpleExtentNdims() == dimension::dim);
// Read the data subset.
detail::read_values(dataset, dataspace, dimx, dimy, dimz, values);
}
catch (H5::Exception const& e) {
HPX_THROW_EXCEPTION(hpx::no_success, "sheneos::extract_data",
e.getDetailMsg());
}
}
示例4: file
int H5PlanckDataManager::getData(string channel, long iStart, int nElements, double* data){
H5File file( DataPath+"_"+channel+".h5", H5F_ACC_RDONLY );
if (iStart < LengthPerChannel) {
if (iStart + nElements >= LengthPerChannel) {
nElements = LengthPerChannel - iStart;
}
DataSet dataset = file.openDataSet( channel );
//DATASPACE
DataSpace dataspace = dataset.getSpace();
hsize_t offset[1]; // hyperslab offset in memory
hsize_t count[1]; // size of the hyperslab in memory
offset[0] = GlobalOffset + iStart;
count[0] = nElements;
dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );
//MEMSPACE
hsize_t dimsm[1];
dimsm[0] = nElements;
hsize_t offset_out[1]; // hyperslab offset in memory
offset_out[0] = 0;
hsize_t count_out[1]; // size of the hyperslab in memory
count_out[0] = nElements;
DataSpace memspace( 1, dimsm );
memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );
dataset.read( data, PredType::NATIVE_DOUBLE, memspace, dataspace );
}
return 0;
}
示例5: h5DummyRead
//'@title Function for dummy read
//'
//'@param chunkName the name of the chunk to be read back
//'@param filePath the path to the h5 file
//'@return int 0
// [[Rcpp::export]]
int h5DummyRead(std::string chunkName, std::string filePath)
{
// Open the file in Read/Write Mode, H5F_ACC_RDONLY
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Opening the data set
DataSet dataset = file->openDataSet((H5std_string)chunkName);
// Opening the data space
DataSpace dataspace = dataset.getSpace();
// Get the number of dimensions
int ndim = dataspace.getSimpleExtentNdims();
// Create a dimension object to be filled with the dimensions of the data set
hsize_t dims[ndim];
// Fill the dimension of the dataset
dataspace.getSimpleExtentDims(dims, NULL);
// Create the return data
SEXP data;
// Allocating a matrix of the right size and dimension
data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1]));
// Filling the matrix with data form the dataspace
dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace);
UNPROTECT(1);
dataset.close();
file->close();
return 0;
}
示例6: read_1darray_vector_of_string_impl
void read_1darray_vector_of_string_impl (group_or_file f, std::string const & name, ArrayVectorOfStringType & V) {
if (!h5::exists(f, name)) TRIQS_RUNTIME_ERROR << "no such dataset : "<<name <<" in file ";
try {
DataSet ds = f->openDataSet( name.c_str() );
DataSpace dataspace = ds.getSpace();
mini_vector<hsize_t,1> dims_out;
int ndims = dataspace.getSimpleExtentDims( &dims_out[0], NULL);
if (ndims !=1) TRIQS_RUNTIME_ERROR << "triqs::h5 : Trying to read 1d array/vector . Rank mismatch : the array stored in the hdf5 file has rank = "<<ndims;
size_t Len = dims_out[0];
V.resize(Len);
size_t size = ds.getStorageSize();
StrType strdatatype(PredType::C_S1, size);
std::vector<char> buf(Len*(size+1), 0x00);
mini_vector<hsize_t,1> L; L[0]=V.size();
mini_vector<hsize_t,1> S; S[0]=1;
auto d_space = dataspace_from_LS<1,false > (L,L,S);
ds.read( (void *)(&buf[0]),strdatatype, d_space );
size_t i=0; for (auto & x : V) { x = ""; x.append(&buf[i*(size)]); ++i;}
}
TRIQS_ARRAYS_H5_CATCH_EXCEPTION;
}
示例7: FILE_NAME
DataSet *load_fMRI3D_DS(std::string filename) {
std::cout << "Opening file " << filename << std::endl;
typedef DataSet DBN_DS;
using namespace H5;
using H5::DataSet;
const H5std_string FILE_NAME(filename);
H5File file(FILE_NAME, H5F_ACC_RDONLY);
int dims[4];
DataSet datadims = file.openDataSet("dims");
datadims.read(dims, PredType::NATIVE_INT);
datadims.close();
DataSet data = file.openDataSet("data");
DataSpace dsp = data.getSpace();
hsize_t dims_out[2];
dsp.getSimpleExtentDims(dims_out, NULL);
int volumes = (int)dims_out[0];
int voxels = (int)dims_out[1];
std::cout << "Dataset images are of size " << dims[0] << "x" << dims[1] << "x" << dims[2] << "x" << dims[3] << std::endl;
std::cout << "Training set is of size " << volumes << "x" << voxels << std::endl;
DBN_DS *dataset = new DBN_DS(AOD, volumes, dims[0], dims[1], dims[2], voxels);
dataset->data_path = filename;
std::cout << "Reading dataset" << std::endl;
float *out_buffer = new float[voxels*volumes];
data.read(out_buffer, PredType::NATIVE_FLOAT);
for (int volume = 0; volume < volumes; ++volume) {
for (int voxel = 0; voxel < voxels; ++voxel) {
float val = out_buffer[volumes*voxel + volume];
dataset->data(volume,voxel) = val;
}
}
data.close();
dsp.close();
#if 0
Vector col = transpose(dataset->data)(9);
col.save("/Users/devon/Research/matlab/tocmat2");
exit(1);
#endif
std::cout << "Reading mask" << std::endl;
DataSet mask_data = file.openDataSet("mask");
dsp = mask_data.getSpace();
mask_data.read(dataset->mask.m->data, PredType::NATIVE_FLOAT);
mask_data.close();
std::cout << "Done reading mask" << std::endl;
dataset->applymask = true;
std::cout << "Done loading dataset" << std::endl;
return dataset;
}
示例8: getPointsNumber
int HdfProcessor::getPointsNumber(const Group& group) const {
DataSet dataSet = group.openDataSet(COORDINATES_DATASET_NAMES[Step::X]);
DataSpace dataSpace = dataSet.getSpace();
int pointsNumber = dataSpace.getSimpleExtentNpoints();
dataSet.close();
return pointsNumber;
}
示例9: extract_data
void extract_data(std::string const& datafilename, double* values,
std::size_t offset, std::size_t count)
{
try {
using namespace H5;
// Turn off the auto-printing when failure occurs
Exception::dontPrint();
H5File file(datafilename, H5F_ACC_RDONLY);
DataSet dataset = file.openDataSet("sine"); // name of data to read
DataSpace dataspace = dataset.getSpace();
// number of dimensions
int numdims = dataspace.getSimpleExtentNdims();
if (numdims != 1)
{
HPX_THROW_EXCEPTION(hpx::no_success, "extract_data",
"number of dimensions was not 1");
}
// Get the dimension size of each dimension in the dataspace.
hsize_t dims[1];
dataspace.getSimpleExtentDims(dims, nullptr);
read_values(dataset, dataspace, offset, count, values);
}
catch (H5::Exception const& e) {
HPX_THROW_EXCEPTION(hpx::no_success, "extract_data",
e.getDetailMsg());
}
}
示例10: catch
int HDF5RecordingData::prepareDataBlock(int xDataSize)
{
hsize_t dim[3];
DataSpace fSpace;
if (dimension > 2) return -4; //We're not going to write rows in datasets bigger than 2d.
dim[2] = size[2];
dim[1] = size[1];
dim[0] = xPos + xDataSize;
try
{
dSet->extend(dim);
fSpace = dSet->getSpace();
fSpace.getSimpleExtentDims(dim);
size[0]=dim[0];
}
catch (DataSetIException error)
{
PROCESS_ERROR;
}
rowXPos = xPos;
rowDataSize = xDataSize;
xPos += xDataSize;
return 0;
}
示例11: getGridDim
HINLINE static DataSpace<DIM2> getGridDim(const Base &base, const DataSpace<DIM2> &gBlocks)
{
return DataSpace<DIM2 > (
gBlocks.x() +
gBlocks.y() - 2 * base.getGuardingSuperCells(),
2 * base.getGuardingSuperCells());
}
示例12: read
//--------------------------------------------------------------------------
// Function: DataSet::read
///\brief This is an overloaded member function, provided for convenience.
/// It takes a reference to a \c H5std_string for the buffer.
///\param buf - IN: Buffer for read data
///\param mem_type - IN: Memory datatype
///\param mem_space - IN: Memory dataspace
///\param file_space - IN: Dataset's dataspace in the file
///\param xfer_plist - IN: Transfer property list for this I/O operation
///\exception H5::DataSetIException
// Programmer Binh-Minh Ribler - 2000
// Modification
// Jul 2009
// Follow the change to Attribute::read and use the following
// private functions to read datasets with fixed- and
// variable-length string:
// DataSet::p_read_fixed_len and
// DataSet::p_read_variable_len
//--------------------------------------------------------------------------
void DataSet::read(H5std_string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist) const
{
// Check if this dataset has variable-len string or fixed-len string and
// proceed appropriately.
htri_t is_variable_len = H5Tis_variable_str(mem_type.getId());
if (is_variable_len < 0)
{
throw DataSetIException("DataSet::read", "H5Tis_variable_str failed");
}
// Obtain identifiers for C API
hid_t mem_type_id = mem_type.getId();
hid_t mem_space_id = mem_space.getId();
hid_t file_space_id = file_space.getId();
hid_t xfer_plist_id = xfer_plist.getId();
if (!is_variable_len) // only allocate for fixed-len string
{
p_read_fixed_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg);
}
else
{
p_read_variable_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg);
}
}
示例13: FILE_NAME
HDF5HandlerBase::HDF5HandlerBase(const std::string &fileName, const std::string &datasetName)
: FILE_NAME(H5std_string(fileName))
, DATASETNAME(H5std_string(datasetName))
{
try
{
Exception::dontPrint();
file = H5File(FILE_NAME, H5F_ACC_TRUNC);
hsize_t dims[1] = {0};
hsize_t maxdims[1] = {H5S_UNLIMITED};
hsize_t chunk_dims[1] = {10000};
DataSpace dataspace = DataSpace(1,dims,maxdims);
DSetCreatPropList prop;
prop.setChunk(1, chunk_dims);
dataset = file.createDataSet( DATASETNAME,
PredType::STD_I32BE, dataspace, prop);
prop.close();
dataspace.close();
} catch (Exception &error) {
// Throw FileIException, DataSetIException, DataSpaceIException
throw;
}
}
示例14:
HDF5RecordingData::HDF5RecordingData(DataSet* data)
{
DataSpace dSpace;
DSetCreatPropList prop;
ScopedPointer<DataSet> dataSet = data;
hsize_t dims[3], chunk[3];
dSpace = dataSet->getSpace();
prop = dataSet->getCreatePlist();
dimension = dSpace.getSimpleExtentDims(dims);
prop.getChunk(dimension,chunk);
this->size[0] = dims[0];
if (dimension > 1)
this->size[1] = dims[1];
else
this->size[1] = 1;
if (dimension > 1)
this->size[2] = dims[2];
else
this->size[2] = 1;
this->xChunkSize = chunk[0];
this->xPos = dims[0];
this->dSet = dataSet;
this->rowXPos.clear();
this->rowXPos.insertMultiple(0,0,this->size[1]);
}
示例15: ch5ReadFactor
CharacterVector ch5ReadFactor(string charName, string filePath)
{
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Group Meta Group
Group* metaGroup = new Group(file->openGroup("/MetaData/Factor"));
// Getting the data set from the file
DataSet dataset = metaGroup->openDataSet((H5std_string)charName);
// Getting the data space from the dataset
DataSpace dataspace = dataset.getSpace();
// We know that it is a char vector array so ndim = 1
hsize_t dims[1];
// Getting the length of strings
dataspace.getSimpleExtentDims(dims, NULL);
// for convenience
int dim = dims[0];
// String Type
StrType vlst(0, H5T_VARIABLE);
// Returning the data
char *strRet[dim];
dataset.read(strRet, vlst);
CharacterVector out(dim);
for(int i = 0; i < dim; i++)
{
out[i] = strRet[i];
}
dataset.close(); //nn
metaGroup->close();
file->close();
return out;
}