I created a 3 dimension dataset and viewed it in HDFView 3.2.0. I expected to see 3 arrays of dimension 32x32. Instead, I see 32 3x32 arrays. Here is my code. :
// Create the dataset
hsize_t dims[3];
dims[0] = 3;
dims[1] = 32;
dims[2] = 32;
// Data initialization.
int data[3][32][32]; // buffer for data to write
const int RANK = dims[0]; // This is a three dimensional array
for (int i = 0; i < blk.Components.size(); i++) {
int blk_rows = blk.Components[i].Info.Height();
int blk_cols = blk.Components[i].Info.Width();
for (int row = 0; row < blk_rows; row++) {
for (int col = 0; col < blk_cols; col++) {
if (int(row * blk_cols + col) < blk.Components[i].Data.size()) {
data[i][row][col] = blk.Components[i].GetValue(row, col);
}
}
}
}
// Try block to detect exceptions raised by any of the calls inside it
try {
// Turn off the auto-printing when failure occurs so that we can
// handle the errors appropriately
Exception::dontPrint();
DataSpace dataspace = DataSpace(RANK, dims); // create new dataspace
// Create the dataset.
DataSet dataset = DataSet(blocks_group->createDataSet(dsname, PredType::STD_I32BE, dataspace));
// Write the data to the dataset using default memory space, file
// space, and transfer properties.
dataset.write(data, PredType::NATIVE_INT);
} // end of try block
// catch failure caused by the H5File operations
catch (FileIException error) {
error.printErrorStack();
throw std::runtime_error("HDF5 FileIException");
}
// catch failure caused by the DataSet operations
catch (DataSetIException error) {
error.printErrorStack();
throw std::runtime_error("HDF5 DataSetIException");
}
// catch failure caused by the DataSpace operations
catch (DataSpaceIException error) {
error.printErrorStack();
throw std::runtime_error("HDF5 DataSpaceException");
}