FORTRAN Example - vg_sd1.f
PROGRAM VG_SD1F
implicit none
C Create a Vgroup and an empty SDS
C Insert the SDS into the Vgroup
integer*4 file_id, vgroup_id
integer*4 fid, sds_id, dims(1), sref
integer istat
integer hopen, vfatch, vfadtr
integer vfdtch, hclose, vfsnam, vfscls
integer sfstart, sfend, sfcreate,sfendacc
integer sfid2ref, vfstart, vfend
integer*4 DFACC_CREATE, DFACC_WRITE, DFNT_INT32
integer*4 DFTAG_NDG
parameter (DFACC_CREATE = 4)
parameter (DFACC_WRITE = 2)
parameter (DFNT_INT32 = 24)
parameter (DFTAG_NDG = 720)
C Create an HDF file
file_id = hopen('vg_sd1f.hdf', DFACC_CREATE, 0)
C Initialize HDF for subsequent Vgroup/Vdata access.
istat = vfstart(file_id)
C Initiate SD interface
fid = sfstart('vg_sd1f.hdf',DFACC_WRITE)
C Create an empty SDS
dims(1) = 10
sds_id = sfcreate(fid,'sd1',DFNT_INT32,1,dims)
C Create a vgroup
vgroup_id = vfatch(file_id, -1, 'w')
istat = vfsnam(vgroup_id, 'MyVgroup')
istat = vfscls(vgroup_id, 'MyClass')
C Insert the SDS into the vgroup
sref = sfid2ref(sds_id)
istat = vfadtr(vgroup_id, DFTAG_NDG, sref)
C end access to the SDS
istat = sfendacc(sds_id)
istat = sfend(fid)
C Terminate access to the Vgroup.
istat = vfdtch(vgroup_id)
C Terminate access to the Vgroup interface and close the file.
istat = vfend(file_id)
istat = hclose(file_id)
end