Skip Navigation Links.

HDF5DotNet wraps a subset of the HDF5 library API in a .NET assembly for consumption by .NET applications. The wrapper is written in C++/CLI and uses the .NET P/Invoke mechanism to call native code from managed code which facilitates multi-language development in other .NET languages such as C#, VB.NET, and IronPython (or Windows PowerShell). It is not a goal of this wrapper to provide an elaborate object-oriented interface to the HDF5 library.

What's new in release 1.8.9

HDF5DotNet was built and tested against HDF5 1.8.9. Check the mini-FAQ discussing several common issues in using the wrapper.

New Functions

No new functions have been wrapped in this release. The definition (and implementation) of H5F.flush has been updated to accept arbitrary IDs of entities that can be flushed (file, dataset, group, committed datatype, attribute).

New Releated Project

The HDF Group just released PSH5X, a Windows PowerShell module for HDF5. The PSH5X movie should give you a pretty good idea what this is about. Q: Can I use HDF5DotNet from PowerShell? A: Yes you can! Check question 2.02 in the PSH5X FAQ.


The two most common installation scenarios are:

  1. Obtain and install copies of pre-compiled binaries and assembly.

    The (native) binary distributions for Windows platforms include the header files, static and dynamic link libraries, and command line tools.

    Pre-built HDF5DotNet assemblies can be found here:

    To compile your .NET application, add a reference to HDF5DotNet.dll to your Visual Studio project. For running your application, in addition to HDF5DotNet.dll, only the following (native) DLLs are required: hdf5dll.dll, hdf5_hldll.dll, szip.dll, and zlib.dll. They can be found in the bin folder of the binary distribution (default installation directory C:\Program Files\HDF Group\HDF5\1.8.9\bin and must be present in a directory that is part of your PATH environment variable.

  2. Obtain copies of of the source code and build your own binaries.

    Follow the instructions provided with the source for building the HDF5 library. For building the HDF5DotNet assembly and examples use the Visual Studio project provided. Note: The assembly and examples can be built without Visual Studio. The compilers and tools for .NET development are part of the .NET Framework SDK or the Windows SDK. Use the WinSDKonly.BAT batch file to build the HDF5DotNet assembly and example programs. Follow these instructions to build the documentation.


The following example uses IronPython. A compressed, chunked dataset is being created and written.

import clr
import HDF5DotNet
from HDF5DotNet import *

import System
from System import Array, Double, Int64

print '\nInitializing HDF5 library\n'
status = H5.Open()
print 'HDF5 ', H5.Version.Major, '.', H5.Version.Minor, '.', H5.Version.Release

h5file = H5F.create('sample.h5', H5F.CreateMode.ACC_TRUNC)
dspace = H5S.create_simple(2, Array[Int64]((256,512)), Array[Int64]((-1,-1)))
dtype = H5T.copy(H5T.H5Type.IEEE_F64LE)

plist = H5P.create(H5P.PropertyListClass.DATASET_CREATE)
H5P.setChunk(plist, Array[Int64]((32, 64)))
H5P.setDeflate(plist, 7)
P_DEFAULT = H5PropertyListId(H5P.Template.DEFAULT)

dset = H5D.create(h5file, 'floats', dtype, dspace, P_DEFAULT, plist, P_DEFAULT);

data = Array.CreateInstance(Double, 256,512)
for i in range(256):
    data[i,i] = i
    data[i,256+i] = i

H5D.write(dset, dtype, H5Array[Double](data))

# H5.Close() takes care of all the open handles (dset, plist, dtype, dspace, h5file).
# It is good practice though to explicitly invoke the appropriate resource release
# routines, e.g., H5D.close(dset) etc.

print '\nShutting down HDF5 library\n'
status = H5.Close()

A nicer and much more Pythonic interface for the native HDF5 library is h5py. h5py comes with high- and low-level APIs. Using h5py's low-level API, the example shown above can be recast as follows:

import h5py
from h5py import *

import numpy
from numpy import zeros, float64

print '\nInitializing HDF5 library\n'
version = h5py.h5.get_libversion()
print 'HDF5 ', version[0], '.', version[1], '.', version[2]

h5file = h5f.create('sample1.h5', h5f.ACC_TRUNC)
dspace = h5s.create_simple((256,512), (h5s.UNLIMITED, h5s.UNLIMITED))
dtype = h5t.IEEE_F64LE.copy()

plist = h5p.create(h5p.DATASET_CREATE)

dset = h5d.create(h5file, 'floats', dtype, dspace, plist)

data = zeros((256,512), dtype=float64)
for i in range(256):
    data[i,i] = i
    data[i,256+i] = i

dset.write(dspace, dspace, data)

print '\nShutting down HDF5 library\n'


Please seek help through the HDF Group Helpdesk and HDF mailing lists. A searchable version of the HDF Forum can be found here.


The HDF Group
The HDF5 Standard Documentation Set
HDFView - a visual tool for browsing and editing HDF4 and HDF5 files


Copyright Notice and License Terms for HDF5 (Hierarchical Data Format 5) Software Library and Utilities