FORTRAN Example - vg_att.f
PROGRAM vg_att
implicit none
integer file_id, vgroup_ref, vgroup_id, status
integer hopen, vfstart, vfind, vfatch, vfdtch, hclose
integer vfend, vfgcatt, vfainfo, vfscatt, vfnatts
integer v_type, v_count, v_size, nattr, i
character vgattrname*30, vgattr_buf*6
character* (*) vgattr_name, vg_attr
parameter (vgattr_name = 'Vgroup Attribute 1',
+ vg_attr = 'TEST1'
+ )
C The following parameters are defined in hdf.inc.
integer DFACC_WRITE, DFNT_CHAR, DFACC_READ
parameter (DFACC_WRITE = 2, DFNT_CHAR = 4,
+ DFACC_READ = 1)
C Open an HDF file with full access.
file_id = hopen('vg_sd1f.hdf', DFACC_WRITE, 0)
C Initialize the V interface.
status = vfstart(file_id)
C Get the reference number of the target vgroup.
vgroup_ref = vfind(file_id, 'MyVgroup')
C Attach to the target vdata.
vgroup_id = vfatch(file_id, vgroup_ref, 'w')
C Attach an attribute to the vgroup.
status = vfscatt(vgroup_id, vgattr_name, DFNT_CHAR, 5, vg_attr)
C Detach from the vgroup, close the V interface and the file.
status = vfdtch(vgroup_id)
status = vfend(file_id)
status = hclose(file_id)
C Open an HDF file and initialize the V interface.
file_id = hopen('vg_sd1f.hdf', DFACC_READ, 0)
status = vfstart(file_id)
C Get the reference number of the target vgroup.
vgroup_ref = vfind(file_id, 'MyVgroup')
C Attach to the target vdata.
vgroup_id = vfatch(file_id, vgroup_ref, 'r')
nattr = vfnatts (vgroup_id)
do 10 i=1,nattr
C Get information about the vgroup attribute.
status = vfainfo(vgroup_id, (i-1), vgattrname, v_type, v_count,
+ v_size)
print*,'Attribute name: ',vgattrname
C Get the vgroup attribute.
status = vfgcatt(vgroup_id, (i-1), vgattr_buf)
print*,'Attribute value: ',vgattr_buf
10 continue
C Detach from the vgroup, close the V interface and the file.
status = vfdtch(vgroup_id)
status = vfend(file_id)
status = hclose(file_id)
end