Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to export attributes and annotations to an HDF5 file. But the documentation here is horrible and there are no examples of this.

I spent some time playing, but I can't get it to work. Here is the simplest example that should have helped me to get started:

Export["test.h5", {{{1, 2}, {2, 3}}, {{10, 11}, {12, 13}}}, {"Datasets", {"m1", "m2"}}]
r = Import["test.h5", "Rules"]
Export["test1.h5", r, "Rules"]

but it fails with:

Export::errelem: The Export element Dataset1 contains a malformed data structure and could not be exported to HDF5 format. >>
Export::noopen: Cannot open C:\Users\ajasja\Documents\test1.h5. >>

So my question is: How can one export attributes with datasets? (preferably using built in Mathematica functionality)

EDIT For reference here are some external MMA HDF5 packages that might provide the required functionality, but I have not yet managed to write any attributes:

share|improve this question
Just wondering, is this resolved in version 10? – Oleksandr R. Apr 26 '15 at 2:40

AFAIK, this isn't possible yet with Mathematica straight from the oven, but there is a package created by Scot Martin here.

As far as I can see, it implements a lot of the HDF5 functionality, including Compound Types.

For attribute creation take a look at the following functions : H5Acreate, H5Awrite, H5Aclose (the A comes from "Attribute")

BTW, I think that Annotations are deprecated in V5.

share|improve this answer
Yup, I've seen the package. There is also this which goes through intermidiate dump files and another one (I have the link at home) with C extensions. – Ajasja Apr 8 '13 at 19:18
Yes, you're right about the annotations, they are now attributes of the root group. – Ajasja Apr 8 '13 at 19:22
Also, Python makes this kind of stuff real sweet :) – Ajasja Apr 8 '13 at 19:23
@Ajasja as with other formats, Mma does a better job importing than exporting. I haven't an official confirmation, but my experiments show that writing attributes is not available – Dr. belisarius Apr 8 '13 at 19:23
Regarding the extra package I get: System.IO.FileLoadException: Mixed mode assembly is built against \ version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 \ runtime without additional configuration information. out of the box (using MMA9). So if you provide a short example of writing attributes the (admittedly nominal) bounty is yours :) Aaa, for mma9 you probably have to download the 4.0 net assemblies from – Ajasja Apr 8 '13 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.