Writing Mixed Field Data Types


Contents:



How to Write Mixed Data Types

If the fields in your data are of mixed data types, then you will end up with "padding" or "alignment bytes" in your structure in memory. Before you write this data to a vdata, you must "pack" it, removing all alignment bytes.

To do this you can use the HDF function:

You can also do this yourself. For example, in C, you can use the memcpy function.


Sample Program to Write Mixed Data Types

The vd_ex4 program is an example of writing mixed data types. You can either download the C or FORTRAN program at the end, or you can take a look at the HTML version, with the HDF calls highlighted:

If you have downloaded this program, then compile and run it. It creates an HDF file called VD_Ex4.hdf (C) and VD_Ex4f.hdf (FORTRAN). To view the contents of the HDF file created, you can use the hdp command as shown in the next section.

Following is a detailed review of what vd_ex4 does:


Contents of HDF File created by vd_ex4

You can view the contents of the HDF file created, using the hdp command, as follows: Notice the order of the fields and their data types.


Download Sample Program (optional)

Programs used in this tutorial: [Compiling a program]