23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Hierarchical Data Format (HDF4) Files<br />

their names and data types. For example, the HDF4 SD API defines an<br />

attribute, named cordsys, in which you can specify the coordinate system<br />

used by the data set. Possible values of this attribute include the text strings<br />

'cartesian', 'polar', and'spherical'.<br />

Predefined attributes can be useful because they establish conventions that<br />

applications can depend on. The HDF4 SD API supports predefined attributes<br />

for data sets and dimensions only; there arenopredefinedattributesforfiles.<br />

For a complete list of the predefined attributes, see the NCSA documentation.<br />

In the HDF4 SD API, you create predefined attributes the same way you<br />

create user-defined attributes, using the SDsetattr routine. In <strong>MATLAB</strong>, use<br />

the hdfsd function, specifying setattr as the first argument:<br />

attr_name = 'cordsys';<br />

attr_value = 'polar';<br />

status = hdfsd('setattr',sds_id,attr_name,attr_value);<br />

The HDF4 SD API also includes specialized functions for writing and<br />

reading the predefined attributes. These specialized functions, such as<br />

SDsetdatastrs, are sometimes easier to use, especially when you are reading<br />

or writing multiple related predefined attributes. You must use specialized<br />

functions to read or write the predefined dimension attributes.<br />

You can associate multiple attributes with a single HDF4 object. HDF4<br />

maintains an attribute index for each object. The attribute index is<br />

zero-based. The first attribute has index value 0, the second has index value<br />

1, and so on. You access an attribute by its index value.<br />

Each attribute has the format name=value, wherename (called label in<br />

HDF4 terminology) is a text string up to 256 characters in length and value<br />

contains one or more entries of the same data type. A single attribute can<br />

have multiple values.<br />

Step 5: Closing HDF4 Data Sets. After writing data to a data set in an<br />

HDF4 file, you must close access to the data set. In the HDF4 SD API, you<br />

use the SDendaccess routine to close a data set. In <strong>MATLAB</strong>, use the hdfsd<br />

function, specifying endaccess as the first argument. As the only other<br />

argument, specify a valid HDF4 SD data set identifier, sds_id in this example:<br />

7-69

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!