本文整理汇总了C++中DataSpace::getSimpleExtentDims方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSpace::getSimpleExtentDims方法的具体用法?C++ DataSpace::getSimpleExtentDims怎么用?C++ DataSpace::getSimpleExtentDims使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSpace
的用法示例。
在下文中一共展示了DataSpace::getSimpleExtentDims方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例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:
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]);
}
示例4: 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;
}
示例5: 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;
}
示例6: strdatatype
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: 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());
}
}
示例8: file
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;
}
示例9:
index_system (DataSpace const & ds, bool is_complex) {
int rf = ds.getSimpleExtentNdims();
if ( rf != rank_full + (is_complex ? 1 : 0) ) TRIQS_RUNTIME_ERROR << "H5 : dimension error";
//int ndims = ds.getSimpleExtentDims( &lens_[0], NULL);
ds.getSimpleExtentDims( &lens_[0], NULL);
for (size_t i =0; i<rank; ++i) { dims[i] = lens_[i]; stri_[i] = 1; off_[i]= 0; }
total_lens_=dims;
mydomain = domain_type (dims);
}
示例10: h5ReadDoubleMat3
//'@title Legacy function to return a data frame chunk as a list
//'
//'@description Experimental function not intended for use at all
//'
//'@param chunkName the name of the chunk to be read
//'@param filePath the path to the h5 file
//'@return List of the data frame chunk
// [[Rcpp::export]]
SEXP h5ReadDoubleMat3(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
// Filling the matrix with data form the dataspace
//double (*buf)[dims[1]]*[dims[0]] = malloc(dims[1]]*[dims[0] * sizeof *buf);
//buf[dims[1]][dims[0]] = 0.0;
double **buf = (double**) calloc (dims[1]*dims[0], sizeof(double));
buf[dims[1]][dims[0]] = 0.0;
//double buf[dims[1]][dims[0]];
dataset.read(buf, PredType::NATIVE_DOUBLE, dataspace);
// Attempt tp append the contents to a list
List out;
NumericVector vec(dims[0]);
NumericMatrix M(dims[0], dims[1]);
CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath);
CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath);
string colName;
for(int i = 0; i < dims[1]; i++)
{
NumericVector vec(dims[0]);
for(int j = 0; j < dims[0]; j++)
{
M(j,i) = buf[i][j];
vec(j) = buf[i][j];
}
colName = colNames[i];
if(colClasses[i] == "factor")
{
CharacterVector levels;
levels = h5ReadFactor(colName, filePath);
IntegerVector fact(vec.size());
fact = cCreateFactor(vec, levels);
out[colName] = fact;
}else{
out[colName] = vec;
}
}
free(buf);
dataset.close(); //nn
file->close();
return wrap(out);
}
示例11: mSpace
int HDF5RecordingData::writeDataRow(int yPos, int xDataSize, HDF5FileBase::DataTypes type, void* data)
{
hsize_t dim[2],offset[2];
DataSpace fSpace;
DataType nativeType;
if (dimension > 2) return -4; //We're not going to write rows in datasets bigger than 2d.
// if (xDataSize != rowDataSize) return -2;
if ((yPos < 0) || (yPos >= size[1])) return -2;
try
{
if (rowXPos[yPos]+xDataSize > size[0])
{
dim[1] = size[1];
dim[0] = rowXPos[yPos] + xDataSize;
dSet->extend(dim);
fSpace = dSet->getSpace();
fSpace.getSimpleExtentDims(dim);
size[0]=dim[0];
}
if (rowXPos[yPos]+xDataSize > xPos)
{
xPos = rowXPos[yPos]+xDataSize;
}
dim[0] = xDataSize;
dim[1] = 1;
DataSpace mSpace(dimension,dim);
fSpace = dSet->getSpace();
offset[0] = rowXPos[yPos];
offset[1] = yPos;
fSpace.selectHyperslab(H5S_SELECT_SET, dim, offset);
nativeType = HDF5FileBase::getNativeType(type);
dSet->write(data,nativeType,mSpace,fSpace);
rowXPos.set(yPos,rowXPos[yPos] + xDataSize);
}
catch (DataSetIException error)
{
PROCESS_ERROR;
}
catch (DataSpaceIException error)
{
PROCESS_ERROR;
}
catch (FileIException error)
{
PROCESS_ERROR;
}
return 0;
}
示例12: read_feature_size
void read_feature_size(H5File h5f, Size &size_out, const char *name)
{
DataSet dataset = h5f.openDataSet(name);
DataSpace dspace = dataset.getSpace();
assert (dspace.getSimpleExtentNdims() == 2);
hsize_t dims[2];
dspace.getSimpleExtentDims(dims);
size_out.height = dims[0];
size_out.width = dims[1];
}
示例13: h5ReadDoubleMat2
//'@title Legacy function to return a data frame chunk as a list
//'
//'@description Experimental function not intended for use at all
//'
//'@param chunkName the name of the chunk to be read
//'@param filePath the path to the h5 file
//'@return List of the data frame chunk
// [[Rcpp::export]]
SEXP h5ReadDoubleMat2(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
// 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);
List out;
NumericVector vec(dims[0]);
CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath);
CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath);
string colName;
for(int i = 0; i < dims[1]; i++)
{
NumericVector vec(dims[0]);
for(int j = 0; j < dims[0]; j++)
{
vec(j) = M(j,i);
}
colName = colNames[i];
if(colClasses[i] == "factor")
{
CharacterVector levels;
levels = ch5ReadFactor(colName, filePath);
IntegerVector fact(vec.size());
fact = cCreateFactor(vec, levels);
out[colName] = fact;
}else{
out[colName] = vec;
}
}
dataset.close(); //nn
file->close();
// Returning the data
return wrap(out);
}
示例14: load
void Weather::load(const std::string& name)
{
std::cout << "Loading " << name << std::endl;
H5File file(name, H5F_ACC_RDONLY);
DataSet dataset = file.openDataSet("weather_data");
std::cout << "Number of attributes: " << dataset.getNumAttrs() << std::endl;
dataset.openAttribute("resolution").read(PredType::NATIVE_UINT, &resolution);
//float bounds[4];
dataset.openAttribute("bounds").read(PredType::NATIVE_DOUBLE, &bounds);
std::cout << "Resolution: " << resolution << std::endl;
std::cout << "Bounds: " << bounds.minx << "," << bounds.miny << "," << bounds.maxx << "," << bounds.maxy << std::endl;
DataSpace ds = dataset.getSpace();
int dim = ds.getSimpleExtentNdims();
std::cout << "Dimensions: " << dim << std::endl;
hsize_t dims_out[3];
ds.getSimpleExtentDims(dims_out, NULL);
std::cout << "Size: " << dims_out[0] << "," << dims_out[1] << "," << dims_out[2] << std::endl;
dimX = dims_out[1];
dimY = dims_out[2];
numScenarios = dims_out[0];
std::cout << "Size: " << dims_out[0] * dims_out[1] * dims_out[2] << std::endl;
std::cout << "Dataset typeclass: " << dataset.getTypeClass() << "," << H5T_COMPOUND << std::endl;
std::cout << "Dataset size: " << dataset.getInMemDataSize() << "," << H5T_COMPOUND << std::endl;
CompType mtype2(sizeof(WeatherData));
mtype2.insertMember("wind_xcomp", HOFFSET(WeatherData, wind_xcomp), PredType::NATIVE_FLOAT);
mtype2.insertMember("wind_ycomp", HOFFSET(WeatherData, wind_ycomp), PredType::NATIVE_FLOAT);
mtype2.insertMember("hs", HOFFSET(WeatherData, hs), PredType::NATIVE_FLOAT);
mtype2.insertMember("light", HOFFSET(WeatherData, light), PredType::NATIVE_CHAR);
//WeatherData wd[106938134];
try {
weatherData = (WeatherData *)malloc(ds.getSimpleExtentNpoints() * sizeof(WeatherData));
dataset.read(weatherData, mtype2);
std::cout << "Finished" << std::endl;
//size_t ix = i1*dims_out[1] * dims_out[2] + i2 * dims_out[2] + i3;
//printf("%f %f %f %d\n", wd[ix].wind_xcomp, wd[ix].wind_ycomp, wd[ix].hs, wd[ix].light);
}
catch (int e)
{
std::cout << "An exception occurred. Exception Nr. " << e << '\n';
}
}
示例15: file
std::uint64_t extract_data_range(std::string const& datafilename,
char const* name, double& minval, double& maxval, double& delta,
std::size_t start, std::size_t end)
{
try {
using namespace H5;
// Turn off auto-printing on failure.
Exception::dontPrint();
// Try to open the file.
H5File file(datafilename, H5F_ACC_RDONLY);
// Try to open the specified dataset.
DataSet dataset = file.openDataSet(name);
DataSpace dataspace = dataset.getSpace();
// Verify number of dimensions
HPX_ASSERT(dataspace.getSimpleExtentNdims() == 1);
// Get the size of each dimension in the dataspace.
hsize_t dims[1];
dataspace.getSimpleExtentDims(dims, nullptr);
if (end == std::size_t(-1))
end = dims[0];
// Read the minimum and maximum values.
detail::read_values(dataset, dataspace, start, 1, &minval);
detail::read_values(dataset, dataspace, end - 1, 1, &maxval);
// Read the delta value.
detail::read_values(dataset, dataspace, start + 1, 1, &delta);
delta -= minval;
// Return size of dataset.
return dims[0];
}
catch (H5::Exception e) {
std::string msg = e.getDetailMsg().c_str();
HPX_THROW_EXCEPTION(hpx::no_success,
"sheneos::extract_data_range", msg);
}
// This return statement keeps the compiler from whining.
return 0;
}