Hello All,
I am considering HDF5 as the file format for a grid type data format we use
in our software. As such, the format and API are fairly new to me. Each
cell contains about 8-10 pieces of data so I am using a compound type. I am
also using the C++ API.
Here is where I am having trouble. When I initially setup the dataset, I
don't know how big the grid will be. So it gets setup like this:
···
***********************
db = new H5File( file_name, H5F_ACC_TRUNC );
CompType mtx_data( sizeof( mtx_cell_t ));
mtx_data.insertMember( "UpdateTime", offsetof( mtx_cell_t, update_time
), PredType::NATIVE_DOUBLE );
mtx_data.insertMember( "CenterX", offsetof( mtx_cell_t, center_x ),
PredType::NATIVE_FLOAT );
mtx_data.insertMember( "CenterY", offsetof( mtx_cell_t, center_y ),
PredType::NATIVE_FLOAT );
mtx_data.insertMember( "CenterZ", offsetof( mtx_cell_t, center_z ),
PredType::NATIVE_FLOAT );
mtx_data.insertMember( "Minimum", offsetof( mtx_cell_t, min ),
PredType::NATIVE_FLOAT );
mtx_data.insertMember( "Maximum", offsetof( mtx_cell_t, max ),
PredType::NATIVE_FLOAT );
mtx_data.insertMember( "Sum", offsetof( mtx_cell_t, sum ),
PredType::NATIVE_DOUBLE );
mtx_data.insertMember( "Squares", offsetof( mtx_cell_t, sum_squares ),
PredType::NATIVE_LONG );
mtx_data.insertMember( "Samples", offsetof( mtx_cell_t, samples ),
PredType::NATIVE_UINT );
mtx_data.insertMember( "Entries", offsetof( mtx_cell_t, entries ),
PredType::NATIVE_UINT );
hsize_t dim_data[2] = { 1, 1 };
hsize_t max_dims[2] = { H5S_UNLIMITED, H5S_UNLIMITED };
DataSpace data_space( 2, dim_data, max_dims );
mtx_cell_t blank;
setmem( &blank, sizeof( mtx_cell_t ), 0 );
DSetCreatPropList cparms;
hsize_t chunk_dims[2] ={1, 1};
cparms.setChunk( 2, chunk_dims );
cparms.setFillValue( mtx_data, &blank );
cell_data = new DataSet(db->createDataSet( "Matrix", mtx_data,
data_space, cparms));
hsize_t dim_attr[] = {1};
DataSpace data_attr( 1, dim_attr );
CompType mtx_params( sizeof( mtx_params_t ));
mtx_params.insertMember( "AnchorX", offsetof( mtx_params_t, anchor.x
), PredType::NATIVE_FLOAT );
mtx_params.insertMember( "AnchorY", offsetof( mtx_params_t, anchor.y
), PredType::NATIVE_FLOAT );
mtx_params.insertMember( "Width", offsetof( mtx_params_t, width ),
PredType::NATIVE_FLOAT );
mtx_params.insertMember( "Height", offsetof( mtx_params_t, height ),
PredType::NATIVE_FLOAT );
mtx_params.insertMember( "CellWidth", offsetof( mtx_params_t,
cell_width ), PredType::NATIVE_FLOAT );
mtx_params.insertMember( "CellHeight", offsetof( mtx_params_t,
cell_height ), PredType::NATIVE_FLOAT );
mtx_params.insertMember( "Rotation", offsetof( mtx_params_t, rotation
), PredType::NATIVE_FLOAT );
cell_data->createAttribute( "Information", mtx_params, data_attr );
***********************
When the grid size is determined, the dataset gets expanded like:
***********************
mtx_info = mtx_params;
cos_rot = cos( mtx_info.rotation );
sin_rot = sin( mtx_info.rotation );
i_num_height = ( mtx_info.height / mtx_info.cell_height ) +
1;
i_num_width = ( mtx_info.width / mtx_info.cell_width ) + 1;
i_num_cells = i_num_height * i_num_width;
hsize_t dim_data[2] = { i_num_height, i_num_width };
cell_data->extend( dim_data );
Attribute attr = cell_data->openAttribute( "Information" );
CompType datatype = attr.getCompType();
attr.write( datatype, &mtx_info );
***********************
Later, my attempts to read and write to the dataset are met with an
exception.
Here is the test code:
***********************
mtx_cell_t mtx_cell;
CompType type = cell_data->getCompType();
hsize_t dim_data[] = { 1, 1 };
DataSpace ds( 2, dim_data );
hsize_t start[2]; // Start of hyperslab
hsize_t stride[2]; // Stride of hyperslab
hsize_t count[2]; // Block count
hsize_t block[2]; // Block sizes
start[0] = h; start[1] = w;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 1; count[1] = 1;
ds.selectHyperslab( H5S_SELECT_SET, count, start, stride, block );
cell_data->read( &mtx_cell, type, ds );
***********************
Know that the code is in very early rough testing phase, just trying to get
a feel about how to work with this. I know for sure it is something that I
am not understanding and I am leaving out a important step, I just haven't
been able to grasp what that is. Any suggestions?
Thanks,
John