Reading Attributes
Contents:
To read and get information about attributes, you can use the following functions:
The following sample program shows how to read attributes in an HDF file
(You can either download the C or FORTRAN program at the end, or just take a
look at the HTML version with the HDF calls highlighted):
If you have downloaded this program, then you can
compile and run it. It reads the file attribute,
SDS attribute, and dimension attribute that were created in the tutorial
previous to this called "Adding Attributes".
Following is a detailed review of what this program does:
- Opens the file, sd.hdf, in READ ONLY mode.
- Gets the attribute index for the file attribute called "file_contents"
(SDfindattr/sffattr).
- Gets information about the file attribute
(SDattrinfo/sfgainfo).
- Reads the file attribute in to the buffer just allocated
(SDreadattr/sfrnatt/sfrcatt), and prints it out.
- Gets the index for the data array, "data1", which contains an attribute, and
uses this to find the attribute with the name "valid_range"
(SDfindattr/sffattr).
- Reads the data array attribute into a buffer
(SDreadattr/sfrnatt/sfrcatt), and then prints it out.
- Gets the index for the dimension that has an attribute
(SDgetdimid/sfdimid), and uses this to find the dimension attribute with the
name "dim_metric" (SDfindattr/sffattr).
- Reads the dimension attribute into a buffer
(SDreadattr/sfrnatt/sfrcatt), and then prints it out.
- Terminates access to the SDS array and SD interface and closes the file.
All that this program does is output the values of the file attribute,
SDS attribute, and dimension attribute added to sd.hdf in
the previous tutorial.
... sd.hdf opened for READ ONLY access
file_contents: storm_track_data
valid range: 2 10
dim_metric: millibars
... closing file
Programs used in this tutorial:
[Compiling a program]