HDF (.hdf)

Background & Context

    • MIME type: application/x-hdf
    • HDF data format Version 4.
    • General-purpose format for representing multidimensional datasets.
    • Used for storage, management, and exchange of scientific data.
    • HDF is an acronym for Hierarchical Data Format.
    • Developed by the US National Center for Supercomputing Applications (NCSA).
    • Binary file format.
    • Incompatible with HDF Version 5.

Import & Export

  • Import["file.hdf"] imports an HDF file, returning the names of the datasets stored in the file.
  • Export["file.hdf",expr] exports a multidimensional array to an HDF file.
  • Import["file.hdf"] returns a list of strings representing the names of all datasets contained in the file.
  • Export["file.hdf",{expr1,},{"Datasets",{"/dataset1",}}] creates an HDF file, storing the arrays {expr1,} as separate datasets.
  • Import["file.hdf",elem] imports the specified element from an HDF file.
  • Import["file.hdf",{elem,suba,subb,}] imports a subelement.
  • Import["file.hdf",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","HDF"] or Import["file",{"HDF",elem,}].
  • Export["file.hdf",expr,elem] creates an HDF file by treating expr as specifying element elem.
  • Export["file.hdf",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.hdf",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.hdf",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Data representation elements:
  • "Data"all datasets imported as a list of arrays
    "Datasets"names of all datasets
  • Import by default uses the "Datasets" element for the HDF format.
  • Specifying and selecting datasets:
  • "Datasets",nn^(th) dataset
    "Datasets",datasetnamed dataset
  • Meta-information elements:
  • "DataFormat"type used to represent each dataset
    "Dimensions"data dimensions of each dataset
  • The following values can be given for "DataFormat":
  • "Integer8"8-bit integers
    "Integer16"16-bit integers
    "Integer32"32-bit integers
    "UnsignedInteger8"8-bit unsigned integers
    "UnsignedInteger16"16-bit unsigned integers
    "UnsignedInteger32"32-bit unsigned integers
    "Real32"IEEE single-precision numbers
    "Real64"IEEE double-precision numbers


  • Export option:
  • "Append"Falsewhether to append to an existing file


Basic Examples  (2)

Show the names of datasets in a file:

Import a dataset and render it as a raster image:

Render as ArrayPlot, specifying a color scheme:

Rasterize the color image and export the data to HDF:

Create a random matrix and export it to HDF:

Show the datasets contained in the generated file:

Import the data: