本文整理汇总了C++中DataSpace::getSimpleExtentNdims方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSpace::getSimpleExtentNdims方法的具体用法?C++ DataSpace::getSimpleExtentNdims怎么用?C++ DataSpace::getSimpleExtentNdims使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSpace
的用法示例。
在下文中一共展示了DataSpace::getSimpleExtentNdims方法的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: 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());
}
}
示例3: 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());
}
}
示例4: 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;
}
示例5:
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);
}
示例6: 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);
}
示例7: 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];
}
示例8: 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);
}
示例9: DataSpace
h5_read (h5::group_or_file f, std::string const & name, S & A) {
if (!f.exists(name)) TRIQS_RUNTIME_ERROR << "no such dataset : "<<name <<" in file ";
try {
DataSet ds = f->openDataSet( name.c_str() );
DataSpace dataspace = ds.getSpace();
int rank = dataspace.getSimpleExtentNdims();
if (rank != 0) TRIQS_RUNTIME_ERROR << "triqs::array::h5::read. Rank mismatch : expecting a scalar (rank =0)"
<<" while the array stored in the hdf5 file has rank = "<<rank;
ds.read( (void *)(&A), data_type_mem_scalar(A), DataSpace() , DataSpace() );
}
TRIQS_ARRAYS_H5_CATCH_EXCEPTION;
}
示例10: strdatatype
/**
* \brief Read a string from an hdf5 file
* \param f The h5 file or group of type H5::H5File or H5::Group
* \param name The name of the hdf5 array in the file/group where the stack will be stored
* \param value The string to fill
* \exception The HDF5 exceptions will be caught and rethrown as TRIQS_RUNTIME_ERROR (with a full stackstrace, cf triqs doc).
*/
inline void h5_read (h5::group_or_file f, std::string const & name, std::string & value) {
if (!f.exists(name)) TRIQS_RUNTIME_ERROR << "no such dataset : "<<name <<" in file ";
try {
DataSet ds = f->openDataSet( name.c_str() );
DataSpace dataspace = ds.getSpace();
int rank = dataspace.getSimpleExtentNdims();
if (rank != 0) TRIQS_RUNTIME_ERROR << "Reading a string and got rank !=0";
size_t size = ds.getStorageSize();
StrType strdatatype(PredType::C_S1, size);
std::vector<char> buf(size+1, 0x00);
ds.read( (void *)(&buf[0]), strdatatype, DataSpace(), DataSpace() );
value = ""; value.append( &(buf.front()) );
}
TRIQS_ARRAYS_H5_CATCH_EXCEPTION;
}
示例11: 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';
}
}
示例12: 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;
}
示例13: DataSpace
void HDF5HandlerBase::save(const std::vector<int> &dataPoints) {
// Return if no data to add
if (dataPoints.size() < 1)
return;
// dataset.write needs not const value of data
int *data = const_cast<int*>(&dataPoints[0]);
// Determine value of
hsize_t dimsext[1];
dimsext[0] = dataPoints.size();
hsize_t size[1];
hsize_t offset[1];
try {
DataSpace filespace = dataset.getSpace();
int ndims = filespace.getSimpleExtentNdims();
hsize_t dims[ndims];
filespace.getSimpleExtentDims(dims);
size[0] = dims[0] + dimsext[0];
dataset.extend(size);
offset[0] = dims[0];
filespace = dataset.getSpace();
filespace.selectHyperslab(H5S_SELECT_SET, dimsext, offset);
DataSpace memspace = DataSpace(1, dimsext, NULL);
dataset.write(data, PredType::NATIVE_INT, memspace, filespace);
filespace.close();
memspace.close();
} catch (Exception &error) {
throw;
}
}
示例14: file
boost::uint64_t extract_data_range (std::string const& datafilename,
double& minval, double& maxval, double& delta,
std::size_t start, std::size_t end)
{
try {
using namespace H5;
// Turn off the auto-printing when failure occurs
Exception::dontPrint();
H5File file(datafilename, H5F_ACC_RDONLY);
DataSet dataset = file.openDataSet("x"); // 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_range",
"number of dimensions was not 1");
}
// Get the dimension 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_values(dataset, dataspace, start, 1, &minval);
read_values(dataset, dataspace, end-1, 1, &maxval);
read_values(dataset, dataspace, start+1, 1, &delta);
delta -= minval;
return dims[0]; // return size of dataset
}
catch (H5::Exception const& e) {
HPX_THROW_EXCEPTION(hpx::no_success, "extract_data_range",
e.getDetailMsg());
}
return 0; // keep compiler happy
}
示例15: GetAttributeDimensions
// [[Rcpp::export]]
NumericVector GetAttributeDimensions(XPtr<Attribute> attribute) {
try {
DataSpace dataspace = attribute->getSpace();
int ndim = dataspace.getSimpleExtentNdims();
NumericVector out;
if(ndim > 0) {
vector<hsize_t> dims_out(ndim);
dataspace.getSimpleExtentDims(&dims_out[0], NULL);
out = NumericVector(dims_out.begin(), dims_out.end());
} else { // Assume scalar Attribute
out = NumericVector(1);
out[0] = 1;
}
return out;
} catch (Exception& error) {
string msg = error.getDetailMsg() + " in " + error.getFuncName();
throw Rcpp::exception(msg.c_str());
}
}