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.

7 Working with Scientific Data Formats<br />

Note The following sections, when referring to specific routines in the HDF4<br />

SD API, use the C library name rather than the <strong>MATLAB</strong> function name. The<br />

<strong>MATLAB</strong> syntax is used in all examples.<br />

Step 1: Opening the HDF4 File. To import an HDF4 SD data set, you must<br />

first open the file using the SD API routine SDstart. (InHDF4terminology,<br />

the numeric arrays stored in HDF4 files are called data sets.) In <strong>MATLAB</strong>,<br />

you use the hdfsd function, specifying as arguments:<br />

• Name of the SD API routine, start in this case.<br />

• Name of the file you want to open.<br />

• Mode in which you want to open it. The following table lists the file access<br />

modes supported by the SDstart routine. In <strong>MATLAB</strong>, you specify these<br />

modesastextstrings.YoucanspecifythefullHDF4modenameoroneof<br />

the abbreviated forms listed in the table.<br />

HDF4 File Creation<br />

Mode HDF4 Mode Name <strong>MATLAB</strong> String<br />

Create a new file 'DFACC_CREATE' 'create'<br />

Read access 'DFACC_RDONLY' 'read' or 'rdonly'<br />

Read and write access 'DFACC_RDWR' 'rdwr' or 'write'<br />

For example, this code opens the file mydata.hdf for read access:<br />

sd_id = hdfsd('start','mydata.hdf','read');<br />

If SDstart can find and open the file specified, it returns an HDF4 SD file<br />

identifier, named sd_id in the example. Otherwise, it returns -1.<br />

Step 2: Retrieving Information About the HDF4 File. To get information<br />

about an HDF4 file, you must use the SD API routine SDfileinfo. This<br />

function returns the number of data sets in the file and the number of global<br />

attributes in the file, if any. (For more information about global attributes, see<br />

“Example: Exporting Data Using the HDF4 SD API Functions” on page 7-63.)<br />

In <strong>MATLAB</strong>, you use the hdfsd function, specifying the following arguments:<br />

7-58

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

Saved successfully!

Ooh no, something went wrong!