X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4246 Rate this article:
No rating

How to programmatically access HDF-4 SD dataset index values and names

ENVI can be used to open a variety of HDF-4 datasets such as ASTER, MODIS, Hyperion and others. ENVI's custom file readers are designed to open the most commonly used datasets that typically include only the spectral bands. However, HDF-4 files can contain many more datasets that users may wish to access or their particular dataset may not have a custom file reader in ENVI. In this case a user could open the file as Generic HDF and select the dataset they wish to open.

In order to perform this same task programmatically, you would use ENVI_OPEN_DATA_FILE with the HDFSD_DATASET and HDFSD_INTERLEAVE keywords. HDFSD_DATASET requires the dataset index of the HDF file which may not be known. One way to access this information programmatically from the HDF file is to use IDL's HDF_SD routines. The below function is an example of how to use these routines to access the SD index and dataset names from the file which can then be used to determine which datasets you wish to open using ENVI_OPEN_DATA_FILE.

The following function can be used access HDF-4 files (such as ASTER or MODIS) to find the dataset names contained in the HDF file and the associated index number.  The index number can be used to open select HDF datasets in ENVI using ENVI_OPEN_DATA_FILE with the HDFSD_DATASET keyword.
=================================

function hdf_sd_getnameandindex, hdf_file
compile_opt idl2

;check to see if the HDF-4 file is valid
if
hdf_file eq !null || ~hdf_ishdf(hdf_file) then begin
    message, 'Not an HDF4 file. Returning.', /info
    return, 0
endif

;initialize HDF SD interface
hdf_id = hdf_sd_start(hdf_file, /read)
    if ~hdf_id then return, 0

;retrieve HDF datasets and attributes
hdf_sd_fileinfo
, hdf_id, n_sds, n_attr
var_index = lonarr(n_sds)
var_name = strarr(n_sds)

;loop through datasets to get index values and names of datasets
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

hdf_sd_end, hdf_id
sd_info = {index:var_index, name:var_name}
return, sd_info

end
======================================

Call the routine at the command line using:

ENVI> result = hdf_sd_getnameandindex(hdf_file)

The 'result' will show the SD indicies and names of the datasets so that they can be searched and used to open the desired HDF-4 dataset using the ENVI routines.

Review on 12/31/2013 MM

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »