The HDF_SD_ATTRFIND function locates the index of an HDF attribute given its name. The attribute can be global or from a specific dataset. If an attribute is located, its index is returned. Otherwise, -1 is returned. Once an attribute's index is known, the HDF_SD_ATTRINFO function can be used to read that attribute.
sd_id = HDF_SD_START('demo.hdf') ; Open an HDF file and start the SD interface.
gindex = HDF_SD_ATTRFIND(sd_id, 'TITLE')
;
Find "TITLE", a global attribute.
sds_id = HDF_SD_SELECT(sd_id, 1) ; Get the ID for the first dataset.
HDF_SD_ATTRINFO,sd_id,gindex, NAME=name, TYPE=type, COUNT=count
;
Read attribute info.
HELP, type, count, name ; Print info about the returned variables.
dindex = HDF_SD_ATTRFIND(sds_id, 'LOCATION')
;
Find the "LOCATION" dataset attribute.
HDF_SD_ATTRINFO,sds_id,dindex,NAME=name,TYPE=type,COUNT=count
;
Read attribute info.