C Example - vg_att.c
#include "hdf.h"
#define VGATTR_NAME "Vgroup Attribute 1"
main( )
{
int32 file_id, vgroup_ref, vgroup_id, status;
int32 v_type, v_count, v_size;
intn nattr, i, j;
char vgattr_buf[5], vattrname[30];
/* Open the HDF file. */
file_id = Hopen("vg_sd1.hdf", DFACC_WRITE, 0);
/* Initialize the V interface. */
status = Vstart(file_id);
/* Get the reference number of the target vgroup. */
vgroup_ref = Vfind(file_id, "MyVgroup");
/* Attach to the target vgroup. */
vgroup_id = Vattach(file_id, vgroup_ref, "w");
/* Attach an attribute to the vgroup. */
status = Vsetattr(vgroup_id, VGATTR_NAME, DFNT_CHAR, 5, "TEST1");
/* Detach from the vgroup, close the V interface and the file. */
status = Vdetach(vgroup_id);
status = Vend(file_id);
status = Hclose(file_id);
/* Open the HDF file, start V interface */
file_id = Hopen("vg_sd1.hdf", DFACC_READ, 0);
status = Vstart(file_id);
/* Get the reference number of the target vgroup. */
vgroup_ref = Vfind(file_id, "MyVgroup");
/* Attach to the target vgroup. */
vgroup_id = Vattach(file_id, vgroup_ref, "r");
/* Get total number of attributes assigned to this vgroup. */
nattr = Vnattrs (vgroup_id);
for (i=0; < nattr; i++)
{
/* Get information about the vgroup attribute. */
status = Vattrinfo(vgroup_id, i, vattrname, &v_type, &v_count, &v_size);
printf ("Attribute name: %s\n", vattrname);
/* Get the vgroup attribute value. */
status = Vgetattr(vgroup_id, i, vgattr_buf);
printf ("Attribute value: ");
for (j=0; j < v_count; j++)
printf ("%c", vgattr_buf[j]);
printf ("\n");
}
/* Detach from the vgroup, close the V interface and the file. */
status = Vdetach(vgroup_id);
status = Vend(file_id);
status = Hclose(file_id);
}