FORTRAN Example - an_write.f
PROGRAM an_write
implicit none
integer hopen, afstart, affcreate, afendaccess, afend
integer afcreate, vfstart, vfatch, vfsnam, vfdtch
integer vfend, vfind
integer*4 vgroup_id
integer hclose, status, file_id, an_id, ann_id
integer afwriteann
integer obj_tag, obj_ref
integer*4 DFACC_CREATE, AN_FILE_LABEL, DFTAG_VG
integer*4 AN_FILE_DESC, AN_DATA_LABEL, AN_DATA_DESC
parameter (DFACC_CREATE = 4, AN_FILE_LABEL = 2)
parameter (AN_FILE_DESC = 3, AN_DATA_LABEL = 0)
parameter (AN_DATA_DESC = 1, DFTAG_VG = 1965)
character*27 file_label /'This is a file label.'/
character*27 file_desc /'This is a file description.'/
character*27 data_label /'This is a data label.'/
character*27 data_desc /'This is a data description.'/
C Open the HDF file.
file_id = hopen('an.hdf', DFACC_CREATE, 0)
C Initialize the AN interface and obtain an interface id.
an_id = afstart(file_id)
C Create the file label and obtain an annotation id
ann_id = affcreate(an_id, AN_FILE_LABEL)
C Write the file label to the file.
status = afwriteann(ann_id, file_label, 27)
C Terminate access to the annotation.
status = afendaccess(ann_id)
C Create the file description and obtain an annotation id
ann_id = affcreate(an_id, AN_FILE_DESC)
C Write the file description to the file.
status = afwriteann(ann_id, file_desc, 27)
C Terminate access to the annotation.
status = afendaccess(ann_id)
C Create a vgroup.
status = vfstart (file_id)
vgroup_id = vfatch (file_id, -1, 'w')
status = vfsnam (vgroup_id, 'Vgroup w/Annotations')
status = vfdtch (vgroup_id)
status = vfend (file_id)
C Get the reference number of vgroup just created
status = vfstart (file_id)
obj_ref = vfind (file_id, "Vgroup w/Annotations")
status = vfend (file_id)
obj_tag = DFTAG_VG
C Create the data label for the Vgroup just created.
ann_id = afcreate (an_id, obj_tag, obj_ref, AN_DATA_LABEL)
C Write the data label to the file.
status = afwriteann(ann_id, data_label, 27)
C Terminate access to the annotation.
status = afendaccess(ann_id)
C Create the data description for the Vgroup just created.
ann_id = afcreate (an_id, obj_tag, obj_ref, AN_DATA_DESC)
C Write the data description to the file.
status = afwriteann(ann_id, data_desc, 27)
C Terminate access to the annotation.
status = afendaccess(ann_id)
C Terminate access to the AN interface.
status = afend(an_id)
C Close the file.
status = hclose(file_id)
end