You would need to use the IDL routines to query the HDF file. This would require that you get the hdf_id, query for the number of datasets in the HDF file, and extract the SD names and SD ids associated with the names. Then with the names and associated IDs you would know which ID to pass to HDFSD_DATASET. An example might be:
=======================
function hdf_sd_getnameandindex, hdf_file
compile_opt idl2
;obtain the HDF SD id
hdf_id = hdf_sd_start(hdf_file, /read)
if ~hdf_id then return, 0
; retrieve the number of datasets and attributes
hdf_sd_fileinfo, hdf_id, n_sds, n_attr
;set up arrays to hold the names and attributes
var_index = lonarr(n_sds)
var_name = strarr(n_sds)
;loop through the datasets to get the name and SD dataset ID
for i = 0, n_sds-1 do begin
var_id = hdf_sd_select(hdf_id, i)
hdf_sd_getinfo, var_id, name=vn
var_index[i] = hdf_sd_nametoindex(hdf_id, vn)
var_name[i] = vn
endfor
;close the SD interface
hdf_sd_end, hdf_id
;return file info
sd_info = {index:var_index, name:var_name}
return, sd_info
end
|