FORTRAN Example - vg_sd2f.f
PROGRAM VG_SD2F
implicit none
C Extract members of the Vgroup from vg_sd1f.hdf
integer*4 file_id, vgroup_id, vgroup_ref, vdata_tag
integer*4 vdata_ref, npairs
integer i, istat
integer hopen, vfatch, vfgttr, vntrc
integer vfgid, vfdtch, hclose, vfstart
integer vfend, vfgnam, vfgcls
integer*4 DFACC_READ
parameter (DFACC_READ = 1)
character vgroup_name(64), vgroup_class(64)
C Open an HDF file with read-only access.
C DFACC_READ is defined in hdf.inc.
file_id = hopen('vg_sd1f.hdf', DFACC_READ, 0)
C Initialize HDF for subsequent Vgroup/Vdata access.
istat = vfstart(file_id)
C Attach to every Vgroup in the file.
vgroup_ref = -1
30 vgroup_ref = vfgid(file_id, vgroup_ref)
if (vgroup_ref .eq. -1) then
go to 20
else
vgroup_id = vfatch(file_id, vgroup_ref, 'r')
C Get the name of the Vgroup
istat = vfgnam (vgroup_id, vgroup_name)
print *, 'Vgroup Name: ', vgroup_name
C Get the class of the Vgroup
istat = vfgcls (vgroup_id, vgroup_class)
print *, 'Vgroup Class: ', vgroup_class
C Get the total number of tag/reference id pairs.
npairs = vntrc(vgroup_id)
C Print every tag and reference id with their
C corresponding file position.
do 10 i = 1, npairs
istat = vfgttr(vgroup_id, i-1, vdata_tag, vdata_ref)
if (istat .eq. -1) then
go to 40
end if
print *, 'Found tag = ', vdata_tag, ' ref = ', vdata_ref,
+ ' at position ', i
10 continue
print *
C Terminate access to the Vgroup.
40 istat = vfdtch(vgroup_id)
end if
go to 30
C Terminate access to the Vgroup interface and close the file.
20 istat = vfend(file_id)
istat = hclose(file_id)
end