# HDF User’s Guide

Version 4.2r4

[Top] [Prev][Next]

> create_vgroups.c

>     #include "hdf.h"
>     #define  FILE_NAME    "Two_Vgroups.hdf"
>     main()
>     {
>        /************************* Variable declaration **************************/
>        intn  status_n;      /* returned status for functions returning an intn  */
>        int32 status_32,     /* returned status for functions returning an int32 */
>              vgroup_ref = -1,
>              vgroup1_id, vgroup2_id, file_id;
>        /********************** End of variable declaration **********************/
>        /*
>        * Create the HDF file.
>        */
>        file_id = Hopen (FILE_NAME, DFACC_CREATE, 0);
>        /*
>        * Initialize the V interface.
>        */
>        status_n = Vstart (file_id);
>        /*
>        * Create the first vgroup.  Note that the vgroup reference number is set
>        * to -1 for creating and the access mode is "w" for writing.
>        */
>        vgroup1_id = Vattach (file_id, vgroup_ref, "w");
>        /*
>        * Create the second vgroup.
>        */
>        vgroup2_id = Vattach (file_id, vgroup_ref, "w");
>        /*
>        * Any operations on the vgroups.
>        */
>        /*
>        * Terminate access to the first vgroup.
>        */
>        status_32 = Vdetach (vgroup1_id);
>        /*
>        * Terminate access to the second vgroup.
>        */
>        status_32 = Vdetach (vgroup2_id);
>        /*
>        * Terminate access to the V interface and close the HDF file.
>        */
>        status_n = Vend (file_id);
>        status_n = Hclose (file_id);
>     }

> create_vgroups.f

>           program  create_vgroup
>           implicit none
>     C
>     C     Parameter declaration
>     C
>           character*15 FILE_NAME
>     C
>           parameter (FILE_NAME = `Two_Vgroups.hdf')
>           integer DFACC_CREATE
>           parameter (DFACC_CREATE = 4)
>     C
>     C     Function declaration
>     C
>           integer hopen, hclose
>           integer vfstart, vfatch, vfdtch, vfend
>     C
>     C**** Variable declaration *******************************************
>     C
>           integer status
>           integer file_id
>           integer vgroup1_id, vgroup2_id, vgroup_ref
>     C
>     C**** End of variable declaration ************************************
>     C
>     C
>     C     Create the HDF file.
>     C
>           file_id = hopen(FILE_NAME, DFACC_CREATE, 0)
>     C
>     C     Initialize the V interface.
>     C
>           status = vfstart(file_id)
>     C
>     C     Create the first vgroup. Note that the vgroup reference number is set
>     C     to -1 for creating and the access mode is `w' for writing.
>     C
>           vgroup_ref = -1
>           vgroup1_id = vfatch(file_id, vgroup_ref, `w')
>     C
>     C     Create the second vgroup.
>     C
>           vgroup2_id = vfatch(file_id, vgroup_ref, `w')
>     C
>     C     Any operations on the vgroups.
>     C
>     C     ..............................
>     C
>     C     Terminate access to the first vgroup.
>     C
>           status = vfdtch(vgroup1_id)
>     C
>     C     Terminate access to the second vgroup.
>     C
>           status = vfdtch(vgroup2_id)
>     C
>     C     Terminate access to the V interface and close the HDF file.
>     C
>           status = vfend(file_id)
>           status = hclose(file_id)
>           end

> add_sds_to_vgroup.c

>     #include   "hdf.h"      /* Note: in this example, hdf.h can be omitted...*/
>     #include   "mfhdf.h"    /* ...since mfhdf.h already includes hdf.h */
>     #define  FILE_NAME    "General_Vgroups.hdf"
>     #define  SDS_NAME     "Test SD"
>     #define  VG_NAME      "SD Vgroup"
>     #define  VG_CLASS     "Common Vgroups"
>     main()
>     {
>        /************************* Variable declaration **************************/
>        intn   status_n;     /* returned status for functions returning an intn  */
>        int32  status_32,    /* returned status for functions returning an int32 */
>               sd_id,        /* SD interface identifier */
>               sds_id,       /* data set identifier */
>               sds_ref,      /* reference number of the data set */
>               dim_sizes[1], /* dimension of the data set - only one */
>               rank = 1,     /* rank of the data set array */
>               vgroup_id,    /* vgroup identifier */
>               file_id;      /* HDF file identifier, same for V interface */
>        /********************** End of variable declaration **********************/
>        /*
>        * Create the HDF file.
>        */
>        file_id = Hopen (FILE_NAME, DFACC_CREATE, 0);
>        /*
>        * Initialize the V interface.
>        */
>        status_n = Vstart (file_id);
>        /*
>        * Initialize the SD interface.
>        */
>        sd_id = SDstart (FILE_NAME, DFACC_WRITE);
>        /*
>        * Set the size of the SDS's dimension.
>        */
>        dim_sizes[0] = 10;
>        /*
>        * Create the SDS.
>        */
>        sds_id = SDcreate (sd_id, SDS_NAME, DFNT_INT32, rank, dim_sizes);
>        /*
>        * Create a vgroup and set its name and class.
>        */
>        vgroup_id = Vattach (file_id, -1, "w");
>        status_32 = Vsetname (vgroup_id, VG_NAME);
>        status_32 = Vsetclass (vgroup_id, VG_CLASS);
>        /*
>        * Obtain the reference number of the SDS using its identifier.
>        */
>        sds_ref = SDidtoref (sds_id);
>        /*
>        * Add the SDS to the vgroup.  Note: the tag DFTAG_NDG is used
>        * when adding an SDS.  Refer to Appendix A for the entire list of tags.
>        */
>        status_32 = Vaddtagref (vgroup_id, DFTAG_NDG, sds_ref);
>        /*
>        * Terminate access to the SDS and to the SD interface.
>        */
>        status_n = SDendaccess (sds_id);
>        status_n = SDend (sd_id);
>        /*
>        * Terminate access to the vgroup and to the V interface, and
>        * close the HDF file.
>        */
>        status_32 = Vdetach (vgroup_id);
>        status_n = Vend (file_id);
>        status_n = Hclose (file_id);
>     }

> add_sds_to_vgroup.f

>           program  add_SDS_to_a_vgroup
>           implicit none
>     C
>     C     Parameter declaration
>     C
>           character*19 FILE_NAME
>           character*7  SDS_NAME
>           character*9  VG_NAME
>           character*13 VG_CLASS
>     C
>           parameter (FILE_NAME = `General_Vgroups.hdf',
>          +           SDS_NAME  = `Test SD',
>          +           VG_NAME   = `SD Vgroup',
>          +           VG_CLASS  = `Common Vgroups')
>           integer DFACC_CREATE, DFACC_WRITE
>           parameter (DFACC_CREATE = 4, DFACC_WRITE = 2)
>           integer DFNT_INT32
>           parameter (DFNT_INT32 = 24)
>           integer DFTAG_NDG
>           parameter (DFTAG_NDG = 720)
>     C
>     C     Function declaration
>     C
>           integer hopen, hclose
>           integer vfstart, vfatch, vfsnam, vfscls, vfadtr, vfdtch, vfend
>           integer sfstart, sfcreate, sfid2ref, sfendacc, sfend
>     C
>     C**** Variable declaration *******************************************
>     C
>           integer status
>           integer file_id
>           integer vgroup_id
>           integer sd_id, sds_id, sds_ref
>           integer dim_sizes(1), rank
>     C
>     C**** End of variable declaration ************************************
>     C
>     C
>     C     Create the HDF file.
>     C
>           file_id = hopen(FILE_NAME, DFACC_CREATE, 0)
>     C
>     C     Initialize the V interface.
>     C
>           status = vfstart(file_id)

>     C
>     C     Initialize SD interface.
>     C
>           sd_id = sfstart(FILE_NAME, DFACC_WRITE)
>     C
>     C     Set the rank and the size of SDS's dimension.
>     C
>           rank = 1
>           dim_sizes(1) = 10
>     C
>     C     Create the SDS.
>     C
>           sds_id = sfcreate(sd_id, SDS_NAME, DFNT_INT32, rank, dim_sizes)
>     C
>     C     Create a vgroup and set its name and class.
>     C
>           vgroup_id = vfatch(file_id, -1 , `w')
>           status    = vfsnam(vgroup_id, VG_NAME)
>           status    = vfscls(vgroup_id, VG_CLASS)
>     C
>     C     Obtain the reference number of the SDS using its identifier.
>     C
>           sds_ref = sfid2ref(sds_id)
>     C
>     C     Add the SDS to the vgroup. Note: the tag DFTAG_NDG is used
>     C     when adding an SDS.  Refer to HDF Reference Manual, Section III, Table 3K,
>     C     for the entire list of tags.
>     C
>           status = vfadtr(vgroup_id, DFTAG_NDG, sds_ref)
>     C
>     C     Terminate access to the SDS and to the SD interface.
>     C
>           status = sfendacc(sds_id)
>           status = sfend(sd_id)
>     C
>     C     Terminate access to the vgroup.
>     C
>           status = vfdtch(vgroup_id)
>     C
>     C     Terminate access to the V interface and close the HDF file.
>     C
>           status = vfend(file_id)
>           status = hclose(file_id)
>           end

> insert_vdatas_to_vgroup.c

>     #include "hdf.h"
>     #define  FILE_NAME         "General_Vgroups.hdf"
>     #define  N_RECORDS         30       /* number of records in the vdatas */
>     #define  ORDER             3        /* order of field FIELD_VD2 */
>     #define  VG_NAME           "Vertices"
>     #define  VG_CLASS          "Vertex Set"
>     #define  VD1_NAME          "X,Y Coordinates"   /* first vdata to hold X,Y...*/
>     #define  VD1_CLASS         "Position"          /*...values of the vertices */
>     #define  VD2_NAME          "Temperature"       /* second vdata to hold the...*/
>     #define  VD2_CLASS         "Property List"     /*...temperature field */
>     #define  VD3_NAME          "Node List"         /* third vdata to hold...*/
>     #define  VD3_CLASS         "Mesh"              /*...the list of nodes */
>     #define  FIELD1_VD1        "PX"    /* first field of first vdata - X values */
>     #define  FIELD2_VD1        "PY"/* second field of first vdata - Y values */
>     #define  FIELD_VD2         "TMP"/* field of third vdata */
>     #define  FIELD_VD3         "PLIST"/* field of second vdata */
>     #define  FIELDNAME_LIST    "PX,PY" /* field name list for first vdata */
>     /* Note that the second and third vdatas can use the field names as
>        the field name lists unless more fields are added to a vdata.
>        Then a field name list is needed for that vdata */
>     main( )
>     {
>        /************************* Variable declaration **************************/
>        intn     status_n;   /* returned status for functions returning an intn  */
>        int32    status_32,  /* returned status for functions returning an int32 */
>                 file_id, vgroup_id,
>                 vdata1_id, vdata2_id, vdata3_id;
>        int32    num_of_records,           /* number of records actually written */
>                 vd_index;                 /* position of a vdata in the vgroup  */
>        int8     i, j, k = 0;
>        float32  pxy[N_RECORDS][2] =       /* buffer for data of the first vdata */
>     		  	{-1.5, 2.3, -1.5, 1.98, -2.4, .67,
>        			-3.4, 1.46, -.65, 3.1, -.62, 1.23,
>        			-.4, 3.8, -3.55, 2.3, -1.43, 2.44,
>        			.23, 1.13, -1.4, 5.43, -1.4, 5.8,
>        			-3.4, 3.85, -.55, .3, -.21, 1.22,
>        			-1.44, 1.9, -1.4, 2.8, .94, 1.78,
>        			-.4, 2.32, -.87, 1.99, -.54, 4.11,
>        			-1.5, 1.35, -1.4, 2.21, -.22, 1.8,
>        			-1.1, 4.55, -.44, .54, -1.11, 3.93,
>        			-.76, 1.9, -2.34, 1.7, -2.2, 1.21};
>        float32  tmp[N_RECORDS];          /* buffer for data of the second vdata */
>        int16    plist[N_RECORDS][3];     /* buffer for data of the third vdata */
>        /********************** End of variable declaration ***********************/
>        /*
>        * Open the HDF file for writing.
>        */
>        file_id = Hopen (FILE_NAME, DFACC_WRITE, 0);
>        /*
>        * Initialize the V interface.
>        */
>        status_n = Vstart (file_id);
>        /*
>        * Buffer the data for the second and third vdatas.
>        */
>        for (i = 0; i < N_RECORDS; i++)
>           for (j = 0; j < ORDER; j++)
>              plist[i][j] = ++k;
>        for (i = 0; i < N_RECORDS; i++)
>           tmp[i] = i * 10.0;
>        /*
>        * Create the vgroup then set its name and class.  Note that the vgroup's
>        * reference number is set to -1 for creating and the access mode is "w" for
>        * writing.
>        */
>        vgroup_id = Vattach (file_id, -1, "w");
>        status_32 = Vsetname (vgroup_id, VG_NAME);
>        status_32 = Vsetclass (vgroup_id, VG_CLASS);
>        /*
>        * Create the first vdata then set its name and class. Note that the vdata's
>        * reference number is set to -1 for creating and the access mode is "w" for
>        * writing.
>        */
>        vdata1_id = VSattach (file_id, -1, "w");
>        status_32 = VSsetname (vdata1_id, VD1_NAME);
>        status_32 = VSsetclass (vdata1_id, VD1_CLASS);
>        /*
>        * Introduce and define the fields of the first vdata.
>        */
>        status_n = VSfdefine (vdata1_id, FIELD1_VD1, DFNT_FLOAT32, 1);
>        status_n = VSfdefine (vdata1_id, FIELD2_VD1, DFNT_FLOAT32, 1);
>        status_n = VSsetfields (vdata1_id, FIELDNAME_LIST);
>        /*
>        * Write the buffered data into the first vdata with full interlace mode.
>        */
>        num_of_records = VSwrite (vdata1_id, (uint8 *)pxy, N_RECORDS,
>                                  FULL_INTERLACE);
>        /*
>        * Insert the vdata into the vgroup using its identifier.
>        */
>        vd_index = Vinsert (vgroup_id, vdata1_id);
>        /*
>        * Detach from the first vdata.
>        */
>        status_32 = VSdetach (vdata1_id);
>        /*
>        * Create, write, and insert the second vdata to the vgroup using
>        * steps similar to those used for the first vdata.
>        */
>        vdata2_id = VSattach (file_id, -1, "w");
>        status_32 = VSsetname (vdata2_id, VD2_NAME);
>        status_32 = VSsetclass (vdata2_id, VD2_CLASS);
>        status_n = VSfdefine (vdata2_id, FIELD_VD2, DFNT_FLOAT32, 1);
>        status_n = VSsetfields (vdata2_id, FIELD_VD2);
>        num_of_records = VSwrite (vdata2_id, (uint8 *)tmp, N_RECORDS,
>                                  FULL_INTERLACE);
>        vd_index = Vinsert (vgroup_id, vdata2_id);
>        status_32 = VSdetach (vdata2_id);
>        /*
>        * Create, write, and insert the third vdata to the vgroup using
>        * steps similar to those used for the first and second vdatas.
>        */
>        vdata3_id = VSattach (file_id, -1, "w");
>        status_32 = VSsetname (vdata3_id, VD3_NAME);
>        status_32 = VSsetclass (vdata3_id, VD3_CLASS);
>        status_n = VSfdefine (vdata3_id, FIELD_VD3, DFNT_INT16, 3);
>        status_n = VSsetfields (vdata3_id, FIELD_VD3);
>        num_of_records = VSwrite (vdata3_id, (uint8 *)plist, N_RECORDS,
>                                  FULL_INTERLACE);
>        vd_index = Vinsert (vgroup_id, vdata3_id);
>        status_32 = VSdetach (vdata3_id);
>        /*
>        * Terminate access to the vgroup "Vertices".
>        */
>        status_32 = Vdetach (vgroup_id);
>        /*
>        * Terminate access to the V interface and close the HDF file.
>        */
>        status_n = Vend (file_id);
>        status_n = Hclose (file_id);
>     }

> insert_vdatas_to_vgroup.f

>           program  add_vdatas_to_a_vgroup
>           implicit none
>     C
>     C     Parameter declaration
>     C
>           character*19 FILE_NAME
>           character*8  VG_NAME
>           character*10 VG_CLASS
>           character*15 VD1_NAME
>           character*8  VD1_CLASS
>           character*11 VD2_NAME
>           character*13 VD2_CLASS
>           character*9  VD3_NAME
>           character*4  VD3_CLASS
>     C
>           parameter (FILE_NAME = `General_Vgroups.hdf',
>          +           VG_NAME   = `Vertices',
>          +           VG_CLASS  = `Vertex Set')
>           parameter (VD1_NAME  = `X,Y Coordinates',
>          +           VD2_NAME  = `Temperature',
>          +           VD3_NAME  = `Node List')
>           parameter (VD1_CLASS = `Position',
>          +           VD2_CLASS = `Property List',
>          +           VD3_CLASS = `Mesh')
>           character*2 FIELD1_VD1
>           character*2 FIELD2_VD1
>           character*3 FIELD_VD2
>           character*4 FIELD_VD3
>           character*5 FIELDNAME_LIST
>           parameter (FIELD1_VD1 = `PX',
>          +           FIELD2_VD1 = `PY',
>          +           FIELD_VD2  = `TMP',
>          +           FIELD_VD3  = `PLIST',
>          +           FIELDNAME_LIST = `PX,PY')
>           integer N_RECORDS
>           parameter (N_RECORDS = 30)

>           integer  DFACC_WRITE
>           parameter (DFACC_WRITE = 2)
>           integer DFNT_FLOAT32, DFNT_INT16
>           parameter (DFNT_FLOAT32 = 5, DFNT_INT16 = 22)
>           integer FULL_INTERLACE
>           parameter (FULL_INTERLACE = 0)
>     C
>     C     Function declaration
>     C
>           integer hopen, hclose
>           integer vfstart, vfatch, vfsnam, vfscls, vfinsrt, vfdtch, vfend
>           integer vsfatch, vsfsnam, vsfscls, vsffdef, vsfsfld,
>          +        vsfwrt, vsfwrtc, vsfdtch
>     C
>     C**** Variable declaration *******************************************
>     C
>           integer status
>           integer file_id
>           integer vgroup_id
>           integer vdata1_id, vdata2_id, vdata3_id, vd_index
>           integer num_of_records
>           integer i, j, k
>           real    pxy(2,N_RECORDS), tmp(N_RECORDS)
>           integer plist(3,N_RECORDS)
>           data pxy /-1.5, 2.3, -1.5, 1.98, -2.4, .67,
>          +          -3.4, 1.46, -.65, 3.1, -.62, 1.23,
>          +          -.4, 3.8, -3.55, 2.3, -1.43, 2.44,
>          +          .23, 1.13, -1.4, 5.43, -1.4, 5.8,
>          +          -3.4, 3.85, -.55, .3, -.21, 1.22,
>          +          -1.44, 1.9, -1.4, 2.8, .94, 1.78,
>          +          -.4, 2.32, -.87, 1.99, -.54, 4.11,
>          +          -1.5, 1.35, -1.4, 2.21, -.22, 1.8,
>          +          -1.1, 4.55, -.44, .54, -1.11, 3.93,
>          +          -.76, 1.9, -2.34, 1.7, -2.2, 1.21/
>     C
>     C**** End of variable declaration ************************************
>     C
>     C
>     C     Open the HDF file for writing.
>     C
>           file_id = hopen(FILE_NAME, DFACC_WRITE, 0)
>     C
>     C     Initialize the V interface.
>     C
>           status = vfstart(file_id)
>     C
>     C     Buffer the data for the third and second vdatas.
>     C
>           do 20 i = 1, N_RECORDS
>              do 10 j = 1, 3
>                 plist(j,i) = k
>                 k = k+1
>     10       continue
>     20    continue
>           do 30 i = 1, N_RECORDS
>              tmp(i) = (i-1) * 10.0
>     30    continue
>     C
>     C     Create a vgroup and set its name and class.
>     C     Note that the vgroup's reference number is set to -1 for creating
>     C     and the access mode is `w' for writing.
>     C
>           vgroup_id = vfatch(file_id, -1 , `w')
>           status    = vfsnam(vgroup_id, VG_NAME)
>           status    = vfscls(vgroup_id, VG_CLASS)
>     C
>     C     Create the first vdata then set its name and class. Note that the vdata's
>     C     reference number is set to -1 for creating and the access mode is `w' for
>     C     writing.
>     C
>           vdata1_id = vsfatch(file_id, -1, `w')
>           status = vsfsnam(vdata1_id, VD1_NAME)
>           status = vsfscls(vdata1_id, VD1_CLASS)
>     C
>     C     Introduce and define the fields of the first vdata.
>     C
>           status = vsffdef(vdata1_id, FIELD1_VD1, DFNT_FLOAT32, 1)
>           status = vsffdef(vdata1_id, FIELD2_VD1, DFNT_FLOAT32, 1)
>           status = vsfsfld(vdata1_id, FIELDNAME_LIST)
>     C
>     C     Write the buffered data into the first vdata.
>     C
>           num_of_records = vsfwrt(vdata1_id, pxy, N_RECORDS,
>          +                        FULL_INTERLACE)
>     C
>     C     Insert the vdata into the vgroup using its identifier.
>     C
>           vd_index = vfinsrt(vgroup_id, vdata1_id)
>     C
>     C     Detach from the first vdata.
>     C
>           status = vsfdtch(vdata1_id)
>     C
>     C     Create, write, and insert the second vdata to the vgroup using
>     C     steps similar to those used for the first vdata.
>     C
>           vdata2_id = vsfatch(file_id, -1, `w')
>           status = vsfsnam(vdata2_id, VD2_NAME)
>           status = vsfscls(vdata2_id, VD2_CLASS)
>           status = vsffdef(vdata2_id, FIELD_VD2, DFNT_FLOAT32, 1)
>           status = vsfsfld(vdata2_id, FIELD_VD2)
>           num_of_records = vsfwrt(vdata2_id, tmp, N_RECORDS,
>          +                        FULL_INTERLACE)
>           vd_index = vfinsrt(vgroup_id, vdata2_id)
>           status = vsfdtch(vdata2_id)
>     C
>     C     Create, write, and insert the third vdata to the vgroup using
>     C     steps similar to those used for the first and second vdatas.
>     C
>           vdata3_id = vsfatch(file_id, -1, `w')
>           status = vsfsnam(vdata3_id, VD3_NAME)
>           status = vsfscls(vdata3_id, VD3_CLASS)
>           status = vsffdef(vdata3_id, FIELD_VD3, DFNT_INT16, 3)
>           status = vsfsfld(vdata3_id, FIELD_VD3)
>           num_of_records = vsfwrtc(vdata3_id, plist, N_RECORDS,
>          +                        FULL_INTERLACE)
>           vd_index = vfinsrt(vgroup_id, vdata3_id)
>           status = vsfdtch(vdata3_id)

>     C
>     C     Terminate access to the vgroup `Vertices'.
>     C
>           status = vfdtch(vgroup_id)
>     C
>     C     Terminate access to the V interface and close the HDF file.
>     C
>           status = vfend(file_id)
>           status = hclose(file_id)
>           end

> get_vgroup_info.c

>     #include "hdf.h"
>     #define  FILE_NAME   "General_Vgroups.hdf"
>     main( )
>     {
>        /************************* Variable declaration **************************/
>        intn   status_n;     /* returned status for functions returning an intn  */
>        int32  status_32,    /* returned status for functions returning an int32 */
>               file_id, vgroup_id;
>        int32  lone_vg_number,      /* current lone vgroup number */
>               num_of_lones = 0;    /* number of lone vgroups */
>        int32 *ref_array;    /* buffer to hold the ref numbers of lone vgroups   */
>        char   vgroup_name[VGNAMELENMAX], vgroup_class[VGNAMELENMAX];
>        /********************** End of variable declaration **********************/

>        /*
>        * Open the HDF file for reading.
>        */
>        file_id = Hopen (FILE_NAME, DFACC_READ, 0);
>        /*
>        * Initialize the V interface.
>        */
>        status_n = Vstart (file_id);
>        /*
>        * Get and print the names and class names of all the lone vgroups.
>        * First, call Vlone with num_of_lones set to 0 to get the number of
>        * lone vgroups in the file, but not to get their reference numbers.
>        */
>        num_of_lones = Vlone (file_id, NULL, num_of_lones );
>        /*
>        * Then, if there are any lone vgroups,
>        */
>        if (num_of_lones > 0)
>        {
>           /*
>           * use the num_of_lones returned to allocate sufficient space for the
>           * buffer ref_array to hold the reference numbers of all lone vgroups,
>           */
>           ref_array = (int32 *) malloc(sizeof(int32) * num_of_lones);
>           /*
>           * and call Vlone again to retrieve the reference numbers into
>           * the buffer ref_array.
>           */
>           num_of_lones = Vlone (file_id, ref_array, num_of_lones);
>           /*
>           * Display the name and class of each lone vgroup.
>           */
>           printf ("Lone vgroups in this file are:\n");
>           for (lone_vg_number = 0; lone_vg_number < num_of_lones;
>                                                                 lone_vg_number++)
>           {
>              /*
>              * Attach to the current vgroup then get and display its
>              * name and class. Note: the current vgroup must be detached before
>              * moving to the next.
>              */
>              vgroup_id = Vattach (file_id, ref_array[lone_vg_number], "r");
>              status_32 = Vgetname (vgroup_id, vgroup_name);
>              status_32 = Vgetclass (vgroup_id, vgroup_class);
>              printf ("   Vgroup name %s and class %s\n", vgroup_name,
>                          vgroup_class);
>              status_32 = Vdetach (vgroup_id);
>           } /* for */
>        } /* if */
>        /*
>        * Terminate access to the V interface and close the file.
>        */
>        status_n = Vend (file_id);
>        status_n = Hclose (file_id);
>        /*
>        * Free the space allocated by this program.
>        */
>        free (ref_array);
>     }

> get_vgroup_info.f

>           program  getinfo_about_vgroup
>           implicit none
>     C
>     C     Parameter declaration
>     C
>           character*19 FILE_NAME
>     C
>           parameter (FILE_NAME = `General_Vgroups.hdf')
>           integer DFACC_READ
>           parameter (DFACC_READ = 1)
>           integer SIZE
>           parameter(SIZE = 10)
>     C
>     C     Function declaration
>     C
>           integer hopen, hclose
>           integer vfstart, vfatch, vfgnam, vfgcls, vflone, vfdtch, vfend
>     C
>     C**** Variable declaration *******************************************
>     C
>           integer status
>           integer file_id
>           integer vgroup_id
>           integer lone_vg_number, num_of_lones
>           character*64 vgroup_name, vgroup_class
>           integer ref_array(SIZE)
>           integer i
>     C
>     C**** End of variable declaration ************************************
>     C
>     C
>     C     Initialize ref_array.
>     C
>           do 10 i = 1, SIZE
>              ref_array(i) = 0
>     10    continue
>     C
>     C     Open the HDF file for reading.
>     C
>           file_id = hopen(FILE_NAME, DFACC_READ, 0)
>     C
>     C     Initialize the V interface.
>     C
>           status = vfstart(file_id)
>     C
>     C     Get and print the name and class name of all lone vgroups.
>     C     First, call vflone with num_of_lones set to 0 to get the number of
>     C     lone vgroups in the file and check whether size of ref_array is
>     C     big enough to hold reference numbers of ALL lone groups.
>     C     If ref_array is not big enough, exit the program after displaying an
>     C     informative message.
>     C
>           num_of_lones = 0
>           num_of_lones = vflone(file_id, ref_array, num_of_lones)
>           if (num_of_lones .gt. SIZE) then
>           write(*,*) num_of_lones, `lone vgroups is found'
>           write(*,*) `increase the size of ref_array to hold reference `
>           write(*,*) `numbers of all lone vgroups in the file'
>           stop
>           endif
>     C
>     C     If there are any lone groups in the file,
>     C
>           if (num_of_lones .gt. 0) then
>     C
>     C     call vflone again to retrieve the reference numbers into ref_array.
>     C
>           num_of_lones = vflone(file_id, ref_array, num_of_lones)
>     C
>     C     Display the name and class of each vgroup.
>     C
>           write(*,*) `Lone vgroups in the file are:'
>           do 20 lone_vg_number = 1, num_of_lones
>     C
>     C     Attach to the current vgroup, then get and display its name and class.
>     C     Note: the current vgroup must be detached before moving to the next.
>     C
>           vgroup_name = ` `
>           vgroup_class = ` `
>           vgroup_id = vfatch(file_id, ref_array(lone_vg_number), `r')
>           status    = vfgnam(vgroup_id, vgroup_name)
>           status    = vfgcls(vgroup_id, vgroup_class)
>           write(*,*) `Vgroup name ` ,  vgroup_name
>           write(*,*) `Vgroup class ` , vgroup_class
>           write(*,*)
>           status = vfdtch(vgroup_id)
>     20    continue
>           endif
>     C
>     C     Terminate access to the V interface and close the HDF file.
>     C
>           status = vfend(file_id)
>           status = hclose(file_id)
>           end

> set_get_vgroup_attr.c

>     #include "hdf.h"
>     #define  FILE_NAME      "General_Vgroups.hdf"
>     #define  VGROUP_NAME    "SD Vgroup"
>     #define  VGATTR_NAME    "First Attribute"
>     #define  N_ATT_VALUES   7              /* number of values in the attribute */
>     main( )
>     {
>        /************************* Variable declaration **************************/
>        intn   status_n,     /* returned status for functions returning an intn  */
>               n_attrs;      /* number of attributes of the vgroup */
>        int32  status_32,    /* returned status for functions returning an int32 */
>               file_id, vgroup_ref, vgroup_id,
>               attr_index, i, vg_version,
>               data_type, n_values, size;
>        char   vg_attr[N_ATT_VALUES] = {`v','g','r','o','u','p','\0'};
>        char   vgattr_buf[N_ATT_VALUES], attr_name[30];
>        /********************** End of variable declaration **********************/
>        /*
>        * Open the HDF file for writing.
>        */
>        file_id = Hopen (FILE_NAME, DFACC_WRITE, 0);
>        /*
>        * Initialize the V interface.
>        */
>        status_n = Vstart (file_id);
>        /*
>        * Get the reference number of the vgroup named VGROUP_NAME.
>        */
>        vgroup_ref = Vfind (file_id, VGROUP_NAME);
>        /*
>        * Attach to the vgroup found.
>        */
>        vgroup_id = Vattach (file_id, vgroup_ref, "w");
>        /*
>        * Get and display the version of the attached vgroup.
>        */
>        vg_version = Vgetversion (vgroup_id);
>        switch (vg_version) {
>             case VSET_NEW_VERSION:
>                   printf ("\nVgroup %s is of the newest version, version 4\n",
>                        VGROUP_NAME);
>                break;
>             case VSET_VERSION:
>                   printf ("Vgroup %s is of a version between 3.2 and 4.0r2\n",
>                        VGROUP_NAME);
>                break;
>             case VSET_OLD_VERSION:
>                   printf ("Vgroup %s is of version before 3.2\n", VGROUP_NAME);
>                break;
>             default:
>                printf ("Unknown version = %d\n", vg_version);
>             } /* switch */
>        /*
>        * Add the attribute named VGATTR_NAME to the vgroup.
>        */
>        status_n = Vsetattr (vgroup_id, VGATTR_NAME, DFNT_CHAR, N_ATT_VALUES,
>                             vg_attr);
>        /*
>        * Get and display the number of attributes attached to this vgroup.
>        */
>        n_attrs = Vnattrs (vgroup_id);
>        printf ("\nThis vgroup has %d attribute(s)\n", n_attrs);
>        /*
>        * Get and display the name and the number of values of each attribute.
>        * Note that the fourth and last parameters are set to NULL because the type
>        * and the size of the attribute are not desired.
>        */
>        for (attr_index = 0; attr_index < n_attrs; attr_index++)
>        {
>           status_n = Vattrinfo (vgroup_id, attr_index, attr_name, NULL,
>                                 &n_values, NULL);
>           printf ("\nAttribute #%d is named %s and has %d values: ",
>                                 attr_index+1, attr_name, n_values);
>           /*
>           * Get and display the attribute values.
>           */
>           status_n = Vgetattr (vgroup_id, attr_index, vgattr_buf);
>           for (i = 0; i < n_values; i++)
>              printf ("%c ", vgattr_buf[i]);
>           printf ("\n");
>        }
>        /*
>        * Terminate access to the vgroup and to the V interface, and close
>        * the HDF file.
>        */
>        status_32 = Vdetach (vgroup_id);
>        status_n = Vend (file_id);
>        status_n = Hclose (file_id);
>     }

> set_get_vgroup_attr.f

>           program  vgroup_attribute
>           implicit none
>     C
>     C     Parameter declaration
>     C
>           character*19 FILE_NAME
>           character*9  VGROUP_NAME
>           character*15 VGATTR_NAME
>     C
>           parameter (FILE_NAME    = `General_Vgroups.hdf',
>          +           VGROUP_NAME  = `SD Vgroup',
>          +           VGATTR_NAME  = `First Attribute')
>           integer VSET_NEW_VERSION, VSET_VERSION, VSET_OLD_VERSION
>           parameter (VSET_NEW_VERSION = 4,
>          +           VSET_VERSION     = 3,
>          +           VSET_OLD_VERSION = 2)
>           integer DFACC_WRITE
>           parameter (DFACC_WRITE = 2)
>           integer DFNT_CHAR
>           parameter (DFNT_CHAR = 4)
>           integer N_ATT_VALUES
>           parameter (N_ATT_VALUES = 6)
>     C
>     C     Function declaration
>     C
>           integer hopen, hclose
>           integer vfstart, vfatch, vfgver, vfscatt, vfnatts, vfainfo,
>          +        vfind, vfgcatt, vfdtch, vfend
>     C
>     C**** Variable declaration *******************************************
>     C
>           integer status, n_attrs
>           integer file_id
>           integer vgroup_id, vgroup_ref, vg_version
>           integer attr_index, i
>           integer data_type, n_values, size
>           character vg_attr(N_ATT_VALUES)
>           character vgattr_buf(N_ATT_VALUES), attr_name(30)
>           data vg_attr /'v','g','r','o','u','p'/
>     C
>     C**** End of variable declaration ************************************
>     C
>     C
>     C     Open the HDF file for reading/writing.
>     C
>           file_id = hopen(FILE_NAME, DFACC_WRITE, 0)
>     C
>     C     Initialize the V interface.
>     C
>           status = vfstart(file_id)
>     C
>     C     Get the reference number of the vgroup named VGROUP_NAME.
>     C
>           vgroup_ref = vfind(file_id, VGROUP_NAME)
>     C
>     C     Attach to the vgroup found.
>     C
>           vgroup_id = vfatch(file_id, vgroup_ref , `w')
>     C
>     C     Get and display the version of the attached vgroup.
>     C
>           vg_version = vfgver(vgroup_id)
>           if (vg_version .eq. VSET_NEW_VERSION) write(*,*)
>          +   VGROUP_NAME, ` is of the newest version, version 4'
>           if (vg_version .eq. VSET_VERSION) write(*,*)
>          +   VGROUP_NAME, ` is of a version between 3.2 and 4.0r2'
>           if(vg_version .eq. VSET_OLD_VERSION) write(*,*)
>          +   VGROUP_NAME, ` is of version before 3.2'
>           if ((vg_version .ne. VSET_NEW_VERSION) .and.
>          +    (vg_version .ne. VSET_VERSION)     .and.
>          +    (vg_version .ne. VSET_OLD_VERSION)) write(*,*)
>          +    `Unknown version'
>     C
>     C     Add the attribute named VGATTR_NAME to the vgroup.
>     C
>           status = vfscatt(vgroup_id, VGATTR_NAME, DFNT_CHAR, N_ATT_VALUES,
>          +                 vg_attr)
>     C
>     C     Get and display the number of attributes attached to this group.
>     C
>           n_attrs = vfnatts(vgroup_id)
>           write(*,*) `This group has', n_attrs, ` attributes'
>     C
>     C     Get and display the name and the number of values of each attribute.
>     C
>           do 10 attr_index=1, n_attrs
>              status = vfainfo(vgroup_id, attr_index-1, attr_name, data_type,
>          +                    n_values, size)
>           write(*,*) `Attribute #', attr_index-1, ` is named `, attr_name
>           write(*,*) `and has', n_values, ` values: `
>     C
>     C     Get and display the attribute values.
>     C
>           status = vfgcatt(vgroup_id, attr_index-1, vgattr_buf)
>           write(*,*) (vgattr_buf(i), i=1,n_values)
>     10    continue
>     C
>     C     Terminate access to the vgroup.
>     C
>           status = vfdtch(vgroup_id)
>     C
>     C     Terminate accessto the V interface and close the HDF file.
>     C
>           status = vfend(file_id)
>           status = hclose(file_id)
>           end

> vgroup_contents.c

>     #include "hdf.h"
>     #define   FILE_NAME        "General_Vgroups.hdf"
>     main( )
>     {
>        /************************* Variable declaration **************************/
>        intn   status_n;     /* returned status for functions returning an intn  */
>        int32  status_32,    /* returned status for functions returning an int32 */
>               file_id, vgroup_id, vgroup_ref,
>               obj_index,    /* index of an object within a vgroup */
>               num_of_pairs, /* number of tag/ref number pairs, i.e., objects */
>               obj_tag, obj_ref,     /* tag/ref number of an HDF object */
>               vgroup_pos = 0;       /* position of a vgroup in the file */
>        /********************** End of variable declaration ***********************/
>        /*
>        * Open the HDF file for reading.
>        */
>        file_id = Hopen (FILE_NAME, DFACC_READ, 0);
>        /*
>        * Initialize the V interface.
>        */
>        status_n = Vstart (file_id);
>        /*
>        * Obtain each vgroup in the file by its reference number, get the
>        * number of objects in the vgroup, and display the information about
>        * that vgroup.
>        */
>        vgroup_ref = -1;        /* set to -1 to search from the beginning of file */
>        while (TRUE)
>        {
>           /*
>           * Get the reference number of the next vgroup in the file.
>           */
>           vgroup_ref = Vgetid (file_id, vgroup_ref);
>           /*
>           * Attach to the vgroup for reading or exit the loop if no more vgroups
>           * are found.
>           */
>           if (vgroup_ref == -1) break;
>           vgroup_id = Vattach (file_id, vgroup_ref, "r");
>           /*
>           * Get the total number of objects in the vgroup.
>           */
>           num_of_pairs = Vntagrefs (vgroup_id);
>           /*
>           * If the vgroup contains any object, print the tag/ref number
>           * pair of each object in the vgroup, in the order they appear in the
>           * file, and indicate whether the object is a vdata, vgroup, or neither.
>           */
>           if (num_of_pairs > 0)
>           {
>              printf ("\nVgroup #%d contains:\n", vgroup_pos);
>              for (obj_index = 0; obj_index < num_of_pairs; obj_index++)
>              {
>                 /*
>                 * Get the tag/ref number pair of the object specified
>                 * by its index, obj_index, and display them.
>                 */
>                 status_n = Vgettagref (vgroup_id, obj_index, &obj_tag, &obj_ref);
>                 printf ("tag = %d, ref = %d", obj_tag, obj_ref);
>                 /*
>                 * State whether the HDF object referred to by obj_ref is a vdata,
>                 * a vgroup, or neither.
>                 */
>                 if (Visvg (vgroup_id, obj_ref))
>                    printf ("  <-- is a vgroup\n");
>                 else if (Visvs (vgroup_id, obj_ref))
>                    printf ("  <-- is a vdata\n");
>                 else
>                    printf ("  <-- neither vdata nor vgroup\n");
>              } /* for */
>           } /* if */
>           else
>              printf ("Vgroup #%d contains no HDF objects\n", vgroup_pos);
>           /*
>           * Terminate access to the current vgroup.
>           */
>           status_32 = Vdetach (vgroup_id);
>           /*
>           * Move to the next vgroup position.
>           */
>           vgroup_pos++;
>        } /* while */
>        /*
>        * Terminate access to the V interface and close the file.
>        */
>        status_n = Vend (file_id);
>        status_n = Hclose (file_id);
>     }

> vgroup_contents.f

>           program  vgroup_contents
>           implicit none
>     C
>     C     Parameter declaration
>     C
>           character*19 FILE_NAME
>     C
>           parameter (FILE_NAME = `General_Vgroups.hdf')
>           integer DFACC_ READ
>           parameter (DFACC_READ = 1)
>     C
>     C     Function declaration
>     C
>           integer hopen, hclose
>           integer vfstart, vfatch, vfgid, vntrc, vfgttr, vfisvg,
>          +        vfisvs, vfdtch, vfend
>     C
>     C**** Variable declaration *******************************************
>     C
>           integer status
>           integer file_id
>           integer vgroup_id, vgroup_ref,  vgroup_pos
>           integer obj_index, num_of_pairs
>           integer obj_tag, obj_ref
>     C
>     C**** End of variable declaration ************************************
>     C
>     C
>     C     Open the HDF file for reading.
>     C
>           file_id = hopen(FILE_NAME, DFACC_READ, 0)
>     C
>     C     Initialize the V interface.
>     C
>           status = vfstart(file_id)
>     C
>     C     Obtain each vgroup in the file by its reference number, get the
>     C     number of objects in the vgroup, and display the information
>     C     about that vgroup.
>     C
>           vgroup_ref = -1
>           vgroup_pos = 0
>     10    continue
>     C
>     C     Get the reference number of the next vgroup in the file.
>     C
>           vgroup_ref = vfgid(file_id, vgroup_ref)
>     C
>     C     Attach to the vgroup or go to the end if no additional vgroup is found.
>     C
>           if(vgroup_ref. eq. -1) goto 100
>           vgroup_id = vfatch(file_id, vgroup_ref , `r')
>     C
>     C     Get the total number of objects in the vgroup.
>     C
>           num_of_pairs = vntrc(vgroup_id)
>     C
>     C     If the vgroup contains any object, print the tag/ref number
>     C     pair of each object in vgroup, in the order they appear in the
>     C     file, and indicate whether the object is a vdata, vgroup, or neither.
>     C
>           if (num_of_pairs .gt. 0) then
>              write(*,*) `Vgroup # `, vgroup_pos, ` contains:'
>              do 20 obj_index = 1, num_of_pairs
>     C
>     C     Get the tag/ref number pair of the object specified by its index
>     C     and display them.
>     C
>              status = vfgttr(vgroup_id, obj_index-1, obj_tag, obj_ref)
>     C
>     C     State whether the HDF object referred to by obj_ref is a vdata,
>     C     a vgroup, or neither.
>     C
>              if( vfisvg(vgroup_id, obj_ref) .eq. 1) then
>                  write(*,*) `tag = `, obj_tag, ` ref = `, obj_ref,
>          +       `  <--- is a vgroup `
>              else if ( vfisvs(vgroup_id, obj_ref) .eq. 1) then
>                  write(*,*) `tag = `, obj_tag, ` ref = `, obj_ref,
>          +       `  <--- is a vdata `
>              else
>                  write(*,*) `tag = `, obj_tag, ` ref = `, obj_ref,
>          +       `  <--- neither vdata nor vgroup `
>              endif
>     20       continue
>           else
>              write (*,*) `Vgroup #', vgroup_pos, ` contains no HDF objects'
>           endif
>           write(*,*)
>           vgroup_pos = vgroup_pos + 1
>           goto 10
>     100   continue
>     C
>     C     Terminate access to the vgroup.
>     C
>           status = vfdtch(vgroup_id)
>     C
>     C     Terminate access to the V interface and close the HDF file.
>     C
>           status = vfend(file_id)
>           status = hclose(file_id)
>           end

HDF4.2r4 - February 2009 Copyright | The HDF Group www.hdfgroup.org