Creating/Reading Attributes
Contents:
Following are functions used in creating/reading attributes:
(Functions in bold are included in the example program for this tutorial.)
The following program adds an attribute to a Vgroup, and then reads it
back in and prints it (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.
Following is a detailed review of what this program does:
- Opens the HDF file vg_sd1.hdf (vg_sd1f.hdf, for Fortran)
in Read/Write mode, and
initializes the V interface.
- Gets the reference number for the Vgroup called "MyVgroup", and
attaches to it.
- Attaches a character attribute called "Vgroup Attribute 1" to
this Vgroup (Vsetattr/vfsnatt/vsfcatt).
- Detaches from the Vgroup, and closes the V interface and file.
- Re-opens the file in READ-ONLY mode, gets the reference number
of the Vgroup called "MyVgroup", and attaches to it.
- Gets the total number of attributes attached to the Vgroup.
In this case it will be 1 (Vnattrs/vfnatts).
- Gets the Attribute information for the attribute (Vattrinfo/vfainfo) and
prints the name.
- Gets the value of the attribute and prints it (Vgetattr/vfgnatt/vfgcatt).
- Detaches from the vgroup, and closes the V interface and the file.
This program prints out the following:
Attribute name: Vgroup Attribute 1
Attribute value: TEST1
NOTE: Vfindattr/vffdatt was not used in this program. If you know
the name of the attribute, you can use this function instead of
using Vnattrs/vfnatts.
You can view the contents of the HDF file with the attribute, by
using the vshow or the hdp command.
With hdp, the resulting HDF file looks as follows:
Notice that under "Vgroup:0" at the top, one attribute is listed called
"Vgroup Attribute 1", with a value of "TEST1" and size of 5.
Programs used in this tutorial:
[Compiling a program]