# HDF5 file managing for dummies

I am new to HDF5 format and I am also not hundred percent confident with Mathematica. I have googled to find out examples to deal with HDF5 files in Mathematica but couldn't find one that work out for me. What I would like to do is simply to import a .h5 file, print the dimension of all the subsets, choose one of them and plot it. After

In[1]:= Import["path/to/file.h5"]
Out[1]:= {"/AGB_CO", "/AGB_PY", "/AGE", "/AREA", "/AREA_SI", \
"/AVG_MONTHLY_WATERDEF", "/BALIVE", "/BALIVE_N_PY", "/BALIVE_PY", \
"/BLEAF", "/BROOT", "/BSAPWOODA", "/BSAPWOODA_N_PY", "/BSAPWOODA_PY", \
"/BSAPWOODB", "/BSAPWOODB_N_PY", "/BSAPWOODB_PY", "/BSEEDS_CO", \
...lots of other subsets...}


which shows all the subsets in the hdf5 file I am stuck. Thanks for any help.

• Without the actual file to work with, I can't give an answer. But when execute that code, it gives the elements in your file. Let's say the first one is elem. Then try test=Import["file.h5",elem1];Dimensions[test] – Jason B. Nov 18 '15 at 10:44
• I get elem1 is not a valid format or element specification. Expecting a \ string, list, or integer. Moreover I may not know which are the subsets in the file before Importing it. What I would need is a script that Import the file, shows all the imported data and plot it. – Manfredo Nov 18 '15 at 10:52
• Edit the question, and copy and paste the output that you get from Import["path/to/file.h5"] – Jason B. Nov 18 '15 at 10:57

Without having the data file myself, I can only give a general sort of answer here. But when you look at the documentation under Import and Export, it says

Import["file.h5"] returns a list of strings representing the names of all datasets contained in the file.

and

Import["file.h5",elem] imports the specified element from an HDF5 file.

So you can try

elemlist = Import["path/to/file.h5"];
importedelemets = Import["path/to/file.h5", # ] &/@ elemlist;
Dimensions /@ importedelemets
ListPlot[importedelemets[[1]]]


Of course, that assumes the first element of the file is a simple list. You may need to play around with it. There may be subelements apparently,

Import["file.h5",{elem,suba,subb,…}] imports a subelement.

• There is an error in what you have written. I have just played with hdf5 and mma and the doc is not easy to understand. The correct synthax is importedelemets = Import["path/to/file.h5", {"Datasets",#} ] &/@ elemlist; : The elements given by Import["...h5"] are not directly usable as 2nd argument of Import. (the hdf5 file is coming from a Agilent-Keysight oscilloscope). – andre314 Feb 3 '16 at 21:21

In M11.1 you can try one of these:

• Import["path/to/file.h5", "Dimensions"] to get dimensions of all datasets
• Import["path/to/file.h5", {"Dimensions", "/path/to/dataset"}] to get dimensions of a specific dataset
• Import["path/to/file.h5", {"Dimensions", n}] to get dimensions of the n-th dataset

This is a significant improvement over previous version of Import because it does not need to load the dataset into memory to get the dimensions.

You can see:

https://github.com/scotmartin1234/HDF5Mathematica

There are some screenshots about compound datatypes, and you could also download the package and use it.

This is version 2.00 (August 2016) of the package that was originally provided as version 1.00 in July 2011.