C Example - vg_sd2.c




/* vg_sd2.c 
 * Extract members of a Vgroup from the file created 
 * by vg_sd1.c
 */

#include "hdf.h"

main( )
{
    int32    file_id;
    int32    vgroup_id, vgroup_ref;
    int32    vdata_tag, vdata_ref;
    int32    status, i, npairs;
    char     vgroup_name[VGNAMELENMAX], vgroup_class[VGNAMELENMAX];
    

    /* Open the "vg_sd1.hdf" file. */
    file_id = Hopen("vg_sd1.hdf", DFACC_READ, 0);

    /* Initialize HDF for subsequent Vgroup/Vdata access. */
    status = Vstart(file_id);

    /* Attach to every Vgroup in the file. */
    vgroup_ref = -1;
    while (TRUE) {
       vgroup_ref = Vgetid(file_id, vgroup_ref);

       if (vgroup_ref == -1) break;
       vgroup_id = Vattach(file_id, vgroup_ref, "r"); 

       /* Get the name of the Vgroup and print it */
       status = Vgetname (vgroup_id, vgroup_name);
       printf ("Vgroup name: %s\n", vgroup_name);

       /* Get the class of the Vgroup and print it */
       status = Vgetclass (vgroup_id, vgroup_class);
       printf ("Vgroup class: %s\n", vgroup_class);

       /* Get the total number of tag/reference id pairs. */
       npairs = Vntagrefs(vgroup_id);

       /* Print every tag and reference id with their 
          corresponding file position. */
       for (i = 0; i < npairs; i++) {
          status = Vgettagref(vgroup_id, i, &vdata_tag, &vdata_ref);
          printf("Found tag = %d, ref = %d at position %d.\n", \
                  vdata_tag, vdata_ref, i+1);
       }
       printf ("\n");

       /* Terminate access to the Vgroup. */
       status = Vdetach(vgroup_id);
    }

    /* Terminate access to the Vgroup interface and close the file. */
    status = Vend(file_id);
    status = Hclose(file_id);

}