#include <iostream>
using std::cout;
using std::endl;
#include <string>
#include "H5Cpp.h"
const H5std_string FILE_NAME("SDS.h5");
const H5std_string DATASET_NAME("IntArray");
const int NX_SUB = 3;
const int NY_SUB = 4;
const int NX = 7;
const int NY = 7;
const int NZ = 3;
const int RANK_OUT = 3;
int
main(void)
{
int i, j, k;
int data_out[NX][NY][NZ];
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++) {
for (k = 0; k < NZ; k++)
data_out[j][i][k] = 0;
}
}
try {
H5File file(FILE_NAME, H5F_ACC_RDONLY);
DataSet dataset = file.openDataSet(DATASET_NAME);
H5T_class_t type_class = dataset.getTypeClass();
if (type_class == H5T_INTEGER) {
cout << "Data set has INTEGER type" << endl;
IntType intype = dataset.getIntType();
H5std_string order_string;
H5T_order_t order = intype.getOrder(order_string);
cout << order_string << endl;
size_t size = intype.getSize();
cout << "Data size is " << size << endl;
}
DataSpace dataspace = dataset.getSpace();
int rank = dataspace.getSimpleExtentNdims();
hsize_t dims_out[2];
int ndims = dataspace.getSimpleExtentDims(dims_out, NULL);
cout << "rank " << rank << ", dimensions " << (unsigned long)(dims_out[0]) << " x "
<< (unsigned long)(dims_out[1]) << endl;
hsize_t offset[2];
hsize_t count[2];
offset[0] = 1;
offset[1] = 2;
count[0] = NX_SUB;
count[1] = NY_SUB;
dataspace.selectHyperslab(H5S_SELECT_SET, count, offset);
hsize_t dimsm[3];
dimsm[0] = NX;
dimsm[1] = NY;
dimsm[2] = NZ;
DataSpace memspace(RANK_OUT, dimsm);
hsize_t offset_out[3];
hsize_t count_out[3];
offset_out[0] = 3;
offset_out[1] = 0;
offset_out[2] = 0;
count_out[0] = NX_SUB;
count_out[1] = NY_SUB;
count_out[2] = 1;
memspace.selectHyperslab(H5S_SELECT_SET, count_out, offset_out);
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++)
cout << data_out[j][i][0] << " ";
cout << endl;
}
}
catch (FileIException error) {
error.printErrorStack();
return -1;
}
catch (DataSetIException error) {
error.printErrorStack();
return -1;
}
catch (DataSpaceIException error) {
error.printErrorStack();
return -1;
}
catch (DataTypeIException error) {
error.printErrorStack();
return -1;
}
return 0;
}
static void dontPrint()
Turns off the automatic error printing from the C library.
Definition: H5Exception.cpp:161
static const PredType & NATIVE_INT
Definition: H5PredType.h:151
Definition: H5AbstractDs.cpp:34