[ HDF5 High Level Tutorial Top ] [ Next ] [ Prev ]

H5TB: HDF5 Table
Tables

Making and reading a table

To create and write a table we use the function H5TBmake_table. In this example we call the function as 

H5TBmake_table( "Table Title", file_id, "Table1", NFIELDS, NRECORDS, dst_size, field_names, dst_offset, field_type, chunk_size, fill_data, compress, p_data );

This call creates a dataset named "Table1". The dst_size parameter contains size in bytes of the structure associated with the table. This value is obtained with sizeof. In this example

size_t dst_size = sizeof( Particle );

The parameter dst_offset is an array containing the offsets of the fields. These values are obtained with the HOFFSET macro, that retrieves the offset of a member from the beginning of its parent structure.

size_t dst_offset[NFIELDS] = { HOFFSET( Particle, name ),
HOFFSET( Particle, lati ),
HOFFSET( Particle, longi ),
HOFFSET( Particle, pressure ),
HOFFSET( Particle, temperature )};

The parameter field_type is an array containing the type of each field. These values are initialized as

string_type = H5Tcopy( H5T_C_S1 );
H5Tset_size( string_type, 16 );
field_type[0] = string_type;
field_type[1] = H5T_NATIVE_INT;
field_type[2] = H5T_NATIVE_INT;
field_type[3] = H5T_NATIVE_FLOAT;
field_type[4] = H5T_NATIVE_DOUBLE;

To read back the table we use the function H5TBread_table

H5TBread_table( file_id, "Table1", dst_size, dst_offset, dst_sizes, dst_buf );

The destination buffer, dst_buf, that was previously packed by H5TBmake_table, is unpacked by the H5LTrepack function .

Programming Example

The following example demonstrates how to create and write a table with the function H5TBmake_table. The corresponding HDF5 file that is generated is also referenced here. You can use an HDF5 file browser to access this file by clicking on the link below.

NOTE: To download a tar file of all of the examples, including a Makefile, please go to the Index page.


HDF Help Desk
Last modified: November 18, 2002