X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 22 Nov 2011 03:56 PM by  anon
Query HDF file for list of datat sets and indices
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
22 Nov 2011 03:56 PM
    ENVI_OPEN_DATA_FILE allows a programmer to open a HDF dataset by specifying the HDF dataset index with the HDFSD_DATASET parameter. But this assumes the programmer knows the index of the HDF DATASET desired. I don't know the index of the dataset in the HDF file until the user specifies the dataset name that is desired. I need to query the HDF file to get the list of dataset names and associated index values and then search the list to see if it matches with the dataset name provided by the user. Once I have the index associated with the desired dataset name I can open the data set using the command: ENVI_OPEN_DATA_FILE, image_filename, /HDF_SD, HDFSD_DATASET="index found by search", r_fid=fid Does anyone know how to query the HDF file for its list of data set names and associated indices? Thank you, Gaucho

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    23 Nov 2011 11:45 AM
    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
    You are not authorized to post a reply.