HDF

There are two HDF formats, HDF4, and HDF5 which each have their own libraries and drivers. HDF4 is more common, but HDF5 is the next generation format.

Building with HDF4

NCSA HDF library can be downloaded from the The NCSA HDF Home Page at the the National Center for Supercomputing Applications. HDF 4.2r1 is generally the preferred version if working from source. The szip option is not widely used, and may be omitted for simplicity.

If your OS distribution already contains prebuilt HDF library you can use one from the distribution.

Open File Limits

Please note, that NCSA HDF library compiled with several defaults which is defined in hlimits.h file. For example, hlimits.h defines the maximum number of opened files:

#   define MAX_FILE   32

If you need open more HDF4 files simultaneously you should change this value and rebuild HDF4 library (there is no need to rebuild GDAL if it is already compiled with HDF4 support).

Incompatibility with NetCDF Libraries

The HDF4 libraries include an implementation of the netcdf api which can access hdf files. If building with HDF4 and NetCDF it is necessary to build the HDF library with this disable. This can be accomplished by defining the macro HAVE_NETCDF when building the HDF libraries. I normally accomplish this by configuring the HDF4 libraries as follows:

export CFLAGS="-fPIC -DHAVE_NETCDF"
export CXXFLAGS="-fPIC -DHAVE_NETCDF"
export LIBS="-lm"
./configure --disable-fortran

The -fPIC and LIBS may not be necessary on all platforms. Without this fix either GDAL will crash intermittently when accessing netcdf files, or the build of GDAL will fail. On more recent HDF4 releases it has been added a new configuration flag, so that you have to use

./configure --disable-netcdf --disable-fortran

and HDF4 will move its embedded NetCDF functions in a different private namespace to avoid name clashes.

Potential conflicts with internal libz

The HDF4 libraries depend on libz library. If you build HDF4 from sources, you most likely use libz library already installed in your system. Then, when you run GDAL ./configure script using option --with-libz=internal requesting GDAL to use its internal version of libz, you may notice that HDF4 support is not enabled as you expected. This might signal a conflict between internal libz and the version installed in you system against which HDF libraries were linked. More detailed description of the problem and its symptoms can be found in summary of Ticket #1955.

Building with HDF5

Building on Windows with MSVC

If your HDF5 source directory does not have an /include directory in its root, then you must do the following:

  • in nmake.opt add a pointer to the directory containing the headers, such as
              HDF5_INCLUDE =  $(HDF5_DIR)\src
    
  • modify the EXTRAFLAGS parameter in gdal\frmts\hdf\makefile.vc to include this new definition, such as:
              EXTRAFLAGS 	= 	-I$(HDF5_INCLUDE) -DWIN32 -D_HDF5USEDLL_ 
    
  • You can test this by executing the following in gdal\frmts\hdf:
              nmake /f makefile.vc
    

Open Tickets

#430
ASTER HDF Georeferencing Off by 1KM?
#671
GDAL does not georef "Aster relative DEM" HDF
#672
gdal_merge.py failes on ~20 "Aster relative DEM" HDF files
#772
HDF - Georeferencing for ASTER HDF_EOS products
#995
reading hdf5 in gdal 1.3.1
#1239
MODIS HDF LAI product: ERROR 1: latitude or longitude exceeded limits in gdalwarp
#1424
subset in an hdf5 file let gdal_info and gdal_translate bail
#1900
Get hdf band, inverse data set dimensions
#2079
HDF4 driver can't read geolocation fields if the dimension map does not exist
#2282
gdalinfo/ gdalwarp (build from source on Ubuntu 7.10, 64-bit) fail to work with HDF5 on a MOD09 product acquired on 2007
#2539
patch for frmts/HDF4 (HDF_GLOBAL#{spatial_ref/GeoTransform})
#2718
hdf4_read.py and hdf4_write.py tests failed on 64-bit Debian Lenny
#3184
unable to compile 1.6.2 w/ netcdf, hdf
#3316
Crash and geolocation array extraction problems with HDF4 LISOTD_HRAC dataset