FORTRAN Example - an_read.f



      PROGRAM an_read  

      implicit none

      integer*4 afstart, affileinfo, afselect, afendaccess, afend
      integer*4 afannlen, afendaccess, afend, hopen, hclose
      integer*4 afreadann
      integer*4 n_file_label, n_file_desc, n_data_label
      integer*4 n_data_desc, ann_length
      integer*4 status, file_id, an_id, ann_id, i
      character ann_buf(28), ann_bufl(22)
   
      integer*4 DFACC_WRITE, AN_FILE_LABEL, AN_FILE_DESC
      integer*4 AN_DATA_LABEL, AN_DATA_DESC
      parameter (AN_DATA_LABEL = 0, AN_DATA_DESC = 1)
      parameter (DFACC_WRITE = 2, AN_FILE_LABEL = 2,
     +            AN_FILE_DESC=3)
     

C     Open the HDF file.
      file_id = hopen('an.hdf', DFACC_WRITE, 0)

C     Initialize the AN interface and obtain an interface id.
      an_id = afstart(file_id)

C     Get the annotation information.
      status = affileinfo(an_id, n_file_label, n_file_desc,
     +                    n_data_label, n_data_desc)
      write (*,*)
      write (*,*) 'Number of file labels:       ',n_file_label
      write (*,*) 'Number of file descriptions: ',n_file_desc
      write (*,*) 'Number of data labels:       ',n_data_label
      write (*,*) 'Number of data descriptions: ',n_data_desc
      write (*,*)

C     Get file labels.
      do 10 i = 0, (n_file_label -1)

C       Get the identifier for the current index.
        ann_id = afselect(an_id, i, AN_FILE_LABEL)

C       Get the length of the annotation for the current id.
        ann_length = afannlen(ann_id)

C       Read the file label.
        status = afreadann(ann_id, ann_bufl, ann_length+1)
        write(*,*) 'File Label:       ',ann_bufl

C       Terminate access to the annotation.
        status = afendaccess(ann_id)
10    continue

C     Get the file descriptions
      do 20 i = 0, (n_file_desc -1)
        ann_id = afselect (an_id, i, AN_FILE_DESC)

C       Get the length of the annotation for the current id.
        ann_length = afannlen(ann_id)

C       Read the file desc.
        status = afreadann(ann_id, ann_buf, ann_length)
        write(*,*) 'File Description: ',ann_buf

C       Terminate access to the annotation.
        status = afendaccess(ann_id)
20    continue

C     Get the data labels
      do 30 i = 0, (n_data_label -1)
        ann_id = afselect (an_id, i, AN_DATA_LABEL)

C       Get the length of the annotation for the current id.
        ann_length = afannlen(ann_id)

C       Read the file desc.
        status = afreadann(ann_id, ann_bufl, ann_length+1)
        write(*,*) 'Data Label:       ',ann_bufl

C       Terminate access to the annotation.
        status = afendaccess(ann_id)
30    continue

C     Get the data descriptions
      do 40 i = 0, (n_data_desc -1)
        ann_id = afselect (an_id, i, AN_DATA_DESC)

C       Get the length of the annotation for the current id.
        ann_length = afannlen(ann_id)

C       Read the file desc.
        status = afreadann(ann_id, ann_buf, ann_length)
        write(*,*) 'Data Description: ',ann_buf

C       Terminate access to the annotation.
        status = afendaccess(ann_id)
40    continue

      write(*,*)

C     Terminate access to the AN interface.
      status = afend(an_id)

C     Close the file.
      status =  hclose(file_id)

      end