mathhdf

A MathLink-based external package for reading and writing HDF Scientific Data Sets

Version 1.0 - Pekka Janhunen, Finnish Meterological Institute
Version 1.1, 1.2, 1.3 - Doug Stein, Wolfram Research, Inc.

Installing mathhdf

Before you can use the functions in mathhdf, you need to Install the external package. If you want mathhdf to run on another machine, simply launch it there directly. It will ask you for a portname on which to listen. You may then use this portname along with the LinkMode -> Connect option of Install. MathLink will handle all of the communication for you! The following command assumes that mathhdf is on the kernel's search path (see $Path) and can be launched by name. If it is somewhere else, simply use the full pathname.

hdfLink = Install["mathhdf"]

Functions Provided

Names["HDF`*"]

?AppendSDS

?ReadSDS

?WriteSDS

Examples

Reading an SDS

Note the semicolon at the end of the next input. These data sets can be quite large! Also, the directory space searched is with respect to the location of the mathhdf executable (which after all may be on a different machine than Mathematica).

data = ReadSDS["test3.hdf"];

Let's see how big this is.

Dimensions[data]

Following are three visualizations using the unadulterated data. Of course, one can use the full capabilities of Mathematica.

ListDensityPlot[data, Mesh->False, PlotRange->All]

ListPlot3D[data, Mesh->False, PlotRange->All]

ListContourPlot[data, PlotRange->All]

Writing an SDS

Let's create a 2D array of floating-point numbers.

dataToWrite = 
	Table[N[Sin[x y]],{x,-2,2,0.1},{y,-2,2,0.1}];

Dimensions[dataToWrite]

Writing the data to an HDF file simply requires a call to WriteSDS or AppendSDS. The first function erases any SDSs in the file before writing whereas the second simply appends to an existing file.

WriteSDS["SinXY.hdf", dataToWrite]

The file SinXY.hdf can be read with ReadSDS (of course); you may also use any other HDF-based programs such as NCSA's DataScope or Spyglass Transform.

Handling of errors

Any errors in the HDF library are transformed into Mathematica error messages. The offending function will then return $Failed.

Here's the case of reading a nonexistent file:

nonData = ReadSDS["foo"]

Uninstalling mathhdf

If you are finished using mathhdf and wish to shut it down you may execute the following command.You don't have to do this since mathhdf will automatically shut down when the Mathematica Kernel does.

Uninstall[hdfLink]