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

H5TB: HDF5 Table
Tables

Write and read fields by name

Individual fields can be written, either be specifying its names or indexes. To overwrite fields of a table by name we use the H5TBwrite_fields_name function. This function overwrites one or several fields by specifying their names and a start record and the number of records to write. In the example, we overwrite the field Pressure, writing 3 records starting at record 2 by calling

H5TBwrite_fields_name( file_id, "Table1", "Pressure", 2, 3, dst_size, dst_offset, pressure_in );

To overwrite the latitude and longitude fields, again writing 3 records starting at record 2 by calling, we use the call

H5TBwrite_fields_name( file_id, "Table1", "Latitude,Longitude", 2, 3, dst_size, dst_offset, position_in );

The data buffer of this call is of a subset type of Particle that holds information of the wanted fields, that is, two integers, and its type is defined as

typedef struct Position 
{
int lati;
int longi;
} Position;

To read individual fields from disk we use the function H5TBread_fields_name. In the example we call

H5TBread_fields_name( file_id, "Table1", "Name,Latitude,Longitude,Pressure,Temperature", 
dst_size, dst_offset, 0, NRECORDS-1, p_data_out );

to read back the all table. Note that since the start and end records to read from are zero based index values, the last element to read from is equal to the number of records minus one. To read a subset of all the fields we use

H5TBread_fields_name( file_id, "Table2", "Latitude,Longitude", 0, NRECORDS-1, dst_size, field_offset_pos, , position_out );

Note that for the the offsets of the fields we use an array initialized as

size_t field_offset_pos[2] = { HOFFSET( Position, lati ),
                               HOFFSET( Position, longi )};

 

Programming Example

The following C program provide an example of how to overwrite fields of a table, by specifying the field names. 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