Map HDF4 to MATLAB Syntax
Each HDF4 API includes many individual routines 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 routines 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 routines in the HDF4 library. These functions are
implemented in the matlab.io.hdf4.sd
, matlab.io.hdfeos.gd
,
and matlab.io.hdfeos.sw
packages. For example,
the SD API includes the C routine SDendaccess
to
close an HDF4 data set:
status = SDendaccess(sds_id); /* C code */
To call this routine 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 routines in
the particular HDF4 API. For example, the HDF Annotations (AN) API
includes the C routine ANend
to terminate access
to an AN interface:
status = ANend(an_id); /* C code */
To call this routine from MATLAB, use the MATLAB function
associated with the AN API, hdfan
. You must specify
the name of the routine, minus the API acronym, as the first argument
and pass any other required arguments to the routine in the order
they are expected. For example,
status = hdfan('end',an_id);
Some HDF4 API routines 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
routine 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 routine 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.