Main Content

Map HDF4 to MATLAB Syntax

Each HDF4 API includes many individual functions that you use to read data from files, write data to files, and perform other related functions. For example, the HDF4 Scientific Data (SD) API includes separate C functions to open (SDopen), close (SDend), and read data (SDreaddata). For the SD API and the HDF-EOS GD and SW APIs, MATLAB® provides functions that map to individual C functions in the HDF4 library. These functions are implemented in the matlab.io.hdf4.sd, matlab.io.hdfeos.gd, and matlab.io.hdfeos.sw namespaces. For example, the SD API includes the C function SDendaccess to close an HDF4 dataset:

status = SDendaccess(sds_id); /* C code */

To call this function from MATLAB, use the MATLAB function, matlab.io.hdf4.sd.endAccess. The syntax is similar:

sd.endAccess(sdsID)

For the remaining supported HDF4 APIs, MATLAB provides a single function that serves as a gateway to all the functions in the particular HDF4 API. For example, the HDF Annotations (AN) API includes the C function ANend to terminate access to an AN interface:

status = ANend(an_id); /* C code */

To call this function from MATLAB, use the MATLAB function associated with the AN API, hdfan. You must specify the name of the function, minus the API acronym, as the first argument and pass any other required arguments to the function in the order they are expected. For example,

status = hdfan('end',an_id);

Some HDF4 API functions use output arguments to return data. Because MATLAB does not support output arguments, you must specify these arguments as return values.

For example, the ANget_tagref function returns the tag and reference number of an annotation in two output arguments, ann_tag and ann_ref. Here is the C code:

status = ANget_tagref(an_id,index,annot_type,ann_tag,ann_ref);

To call this function from MATLAB, change the output arguments into return values:

[tag,ref,status] = hdfan('get_tagref',AN_id,index,annot_type);

Specify the return values in the same order as they appear as output arguments. The function status return value is always specified as the last return value.