      PROGRAM SEARCH INDEX

      integer*4 sd_id, sds_index, sds_id, status
      integer*4 start(3), edges(3), stride(3) 
      integer sfstart, sfn2index, sfrdata, sfendacc, sfselect

C     DFACC_RDONLY is defined in hdf.h.
      integer*4 DFACC_RDONLY
      integer*4 X_LENGTH, Y_LENGTH, Z_LENGTH
      parameter (DFACC_RDONLY = 1, X_LENGTH = 4, Y_LENGTH = 5,
     +           Z_LENGTH = 6)
      integer*2 array_data(X_LENGTH, Y_LENGTH, Z_LENGTH)

C     Open the file. 
      sd_id = sfstart('Example4.hdf', DFACC_RDONLY)

C     Search for the index of a non-existent array data set. 
      sds_index = sfn2index(sd_id, 'Invalid_Data_Set_Name')

C     Error condition: sds_index contains the value -1. 

C     Search for the index of a 'Ex_array_4' array data set. 
      sds_index = sfn2index(sd_id, 'Ex_array_4')

C     Select the data set corresponding to the returned index.
      sds_id = sfselect(sd_id, sds_index)

C     Read the data set data into the rd_data array. 
      start(1) = 0
      start(2) = 0
      start(3) = 0
      edges(1) = X_LENGTH
      edges(2) = Y_LENGTH
      edges(3) = Z_LENGTH
      stride(1) = 1
      stride(2) = 1
      stride(3) = 1
      status = sfrdata(sds_id, start, stride, edges, array_data)

C     Terminate access to the array 
      status = sfendacc(sds_id)

      end
