#include <iostream>
using std::cout;
using std::endl;
#include <string>
#include "H5Cpp.h"
const H5std_string FILE_NAME("Select.h5");
const H5std_string DATASET_NAME("Matrix in file");
const int MSPACE1_RANK = 1;
const int MSPACE1_DIM = 50;
const int MSPACE2_RANK = 1;
const int MSPACE2_DIM = 4;
const int FSPACE_RANK = 2;
const int FSPACE_DIM1 = 8;
const int FSPACE_DIM2 = 12;
const int MSPACE_RANK = 2;
const int MSPACE_DIM1 = 8;
const int MSPACE_DIM2 = 9;
const int NPOINTS = 4;
int
main(void)
{
int i, j;
try {
Exception::dontPrint();
int fillvalue = 0;
hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2};
hsize_t start[2];
hsize_t stride[2];
hsize_t count[2];
hsize_t block[2];
start[0] = 0;
start[1] = 1;
stride[0] = 4;
stride[1] = 3;
count[0] = 2;
count[1] = 4;
block[0] = 3;
block[1] = 2;
fspace.selectHyperslab(H5S_SELECT_SET, count, start, stride, block);
hsize_t dim1[] = {MSPACE1_DIM};
start[0] = 1;
stride[0] = 1;
count[0] = 48;
block[0] = 1;
mspace1.selectHyperslab(H5S_SELECT_SET, count, start, stride, block);
int vector[MSPACE1_DIM];
vector[0] = vector[MSPACE1_DIM - 1] = -1;
for (i = 1; i < MSPACE1_DIM - 1; i++)
vector[i] = i;
dataset->
write(vector, PredType::NATIVE_INT, mspace1, fspace);
fspace.selectNone();
hsize_t dim2[] = {MSPACE2_DIM};
hsize_t coord[NPOINTS][FSPACE_RANK];
coord[0][0] = 0;
coord[0][1] = 0;
coord[1][0] = 3;
coord[1][1] = 3;
coord[2][0] = 3;
coord[2][1] = 5;
coord[3][0] = 5;
coord[3][1] = 6;
fspace.selectElements(H5S_SELECT_SET, NPOINTS, (const hsize_t *)coord);
int values[] = {53, 59, 61, 67};
dataset->
write(values, PredType::NATIVE_INT, mspace2, fspace);
delete dataset;
delete file;
file =
new H5File(FILE_NAME, H5F_ACC_RDONLY);
start[0] = 1;
start[1] = 2;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 3;
count[1] = 4;
start[0] = 2;
start[1] = 4;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 6;
count[1] = 5;
fspace.selectHyperslab(H5S_SELECT_OR, count, start, stride, block);
hsize_t mdim[] = {MSPACE_DIM1, MSPACE_DIM2};
start[0] = 0;
start[1] = 0;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 3;
count[1] = 4;
mspace.selectHyperslab(H5S_SELECT_SET, count, start, stride, block);
start[0] = 1;
start[1] = 2;
block[0] = 1;
block[1] = 1;
stride[0] = 1;
stride[1] = 1;
count[0] = 6;
count[1] = 5;
mspace.selectHyperslab(H5S_SELECT_OR, count, start, stride, block);
int matrix_out[MSPACE_DIM1][MSPACE_DIM2];
for (i = 0; i < MSPACE_DIM1; i++)
for (j = 0; j < MSPACE_DIM2; j++)
matrix_out[i][j] = 0;
dataset->
read(matrix_out, PredType::NATIVE_INT, mspace, fspace);
for (i = 0; i < MSPACE_DIM1; i++) {
for (j = 0; j < MSPACE_DIM2; j++)
cout << matrix_out[i][j] << " ";
cout << endl;
}
delete dataset;
delete file;
}
return -1;
}
return -1;
}
return -1;
}
return 0;
}
Class DSetCreatPropList inherits from ObjCreatPropList and provides wrappers for the HDF5 dataset cre...
Definition: H5DcreatProp.h:29
void setFillValue(const DataType &fvalue_type, const void *value) const
Sets a dataset fill value.
Definition: H5DcreatProp.cpp:294
Class DataSet operates on HDF5 datasets.
Definition: H5DataSet.h:28
void write(const void *buf, const DataType &mem_type, const DataSpace &mem_space=DataSpace::ALL, const DataSpace &file_space=DataSpace::ALL, const DSetMemXferPropList &xfer_plist=DSetMemXferPropList::DEFAULT) const
Writes raw data from an application buffer to a dataset.
Definition: H5DataSet.cpp:492
virtual DataSpace getSpace() const
Gets a copy of the dataspace of this dataset.
Definition: H5DataSet.cpp:133
void read(void *buf, const DataType &mem_type, const DataSpace &mem_space=DataSpace::ALL, const DataSpace &file_space=DataSpace::ALL, const DSetMemXferPropList &xfer_plist=DSetMemXferPropList::DEFAULT) const
Reads raw data from the specified dataset.
Definition: H5DataSet.cpp:417
Definition: H5Exception.h:131
Class DataSpace inherits from IdComponent and provides wrappers for the HDF5's dataspaces.
Definition: H5DataSpace.h:25
void selectHyperslab(H5S_seloper_t op, const hsize_t *count, const hsize_t *start, const hsize_t *stride=NULL, const hsize_t *block=NULL) const
Selects a hyperslab region to add to the current selected region.
Definition: H5DataSpace.cpp:598
Definition: H5Exception.h:103
static void printErrorStack(FILE *stream=stderr, hid_t err_stack=H5E_DEFAULT)
Prints the error stack in a default manner.
Definition: H5Exception.cpp:315
Definition: H5Exception.h:89
Class H5File represents an HDF5 file and inherits from class Group as file is a root group.
Definition: H5File.h:25
DataSet openDataSet(const char *name, const DSetAccPropList &dapl=DSetAccPropList::DEFAULT) const
Opens an existing dataset at this location.
Definition: H5Location.cpp:1006
DataSet createDataSet(const char *name, const DataType &data_type, const DataSpace &data_space, const DSetCreatPropList &create_plist=DSetCreatPropList::DEFAULT, const DSetAccPropList &dapl=DSetAccPropList::DEFAULT, const LinkCreatPropList &lcpl=LinkCreatPropList::DEFAULT) const
Creates a new dataset at this location.
Definition: H5Location.cpp:950
Definition: H5AbstractDs.cpp:34