This page contains some basic examples to demonstrate how the h5labview interface works. The VIs can be found in the "h5labview" directory
of the LabVIEW examples folder (LabVIEW\examples\h5labview).
Got an example you'd like to submit or suggest? Please get in contact!
The simplest example demonstrates creating a new HDF file and writing a homogeneous dataset (U16s) with a string attribute. Note that
it is not necessary to close the group reference, as all associated references are closed when the file is. This greatly simplifies
both reference managing and error tracking.
The converse of this example is to read the dataset and attribute back out. Note that a "default" must be provided to the read node.
This tells HDF what kind of data to read and also provides a fall-back value in case the read fails.
h5labview now fully supports compound datatypes, including nested structures and selective read-out. Here an array of clusters
are written to the file (as shown in HDFView, bottom right), and then one "column" (cluster element) of the data is read out afterwards,
demonstrating selective read-out capabilities.
As discussed in this FAQ
, h5labview uses the label associated with a string to determine whether it should
be written as a variable string or fixed string. Provided you do not store binary data containing \0 in strings (which is not recommended
anyway), there is no operational difference in LabVIEW. The example below demonstrates writing different types of string, as defined by the
string label. Here we specify the fixed length strings to be 32-characters using the string labels. In this example, we include the NULL (\00)
character to demonstrate difference in behaviour.
In the first instance, the string is truncated at \0 during writing, so "some" is stored in the file. In the second instance, the string
is written to the file correctly "some\00test\00\00\00..." but truncated upon readout. In the third instance, the string is read out including
all the NULL values. Note other HDF applications may inconsistently handle NULL values in strings and as such it is recommended to store
binary data in a U8 array instead of a string.
Since v2.6, h5labview supports direct reading and writing of variants. This should greatly simplify middleware I/O wrappers to make using
H5 more convenient in the LabVIEW environment. All types supported by the XNode are permitted, unexpected types will result in an error at
runtime, propagated through the Error Out terminal..
Here we take an array of strings, bundle it into a variant (implicitly) and add two attributes. The string array is written as a dataset
of variable-length strings, and the attributes are added. This is then read out with attributes attached.
You can create an extensible dataset by using H5Dcreate_simple and specifying max dims
(a max dim of -1 means infinite). This creates
dataset when can be resized/appended to using the H5Dprepare_append VI, enabling data to be appended to a dataset as it
comes in. This is demonstrated in the example below,
is a array of clusters, which we write one-by-one by appending them to the dataset. Note the H5Sclose call after H5Dwrite,
which closes the dataspace pointer that keeps track of resizing, and is necessary to prevent memory leaks.
MATLAB uses the MAT file format to store data for import/export. Version 7.3 of this file format uses HDF5 internally to store its data.
You can therefore use h5labview
to read, create and modify such MAT files to exchange data with MATLAB!
The code required to create a valid MAT file is distributed with h5labview in LabVIEW\examples\h5labview\matlab, making exporting
data as easy as wiring up the write function!
More detailed documentation about how the format works internally is provided in the source code. Data can also be read out of MAT files using
simple H5Dread calls like a regular dataset.