HDF5: Difference between revisions
From charlesreid1
No edit summary |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Installing = | = Installing = | ||
==Mac OS X Lion: Use Brew== | |||
If you're on Mac OS X Lion (10.7), you may run into issues. If you're less inclined to get elbow-deep in computer problems, you can just use Homebrew (http://mxcl.github.io/homebrew/), a really nice package manager for Mac OS X. MacPorts and Fink can both be nightmares, but Homebrew manages to do everything hassle-free. | |||
You can install HDF5 using Homebrew by running: | |||
<pre> | |||
$ brew install hdf5 | |||
</pre> | |||
UPDATE: HDF5 has since moved to Homebrew-Science (https://github.com/Homebrew/homebrew-science). You can "tap" into Homebrew Science to get to the HDF5 recipe. | |||
== Configuring == | == Configuring == | ||
| Line 11: | Line 23: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
You can optionally use the configure arguments <code>--enable-static-exe --enable-static</code>, though in my experience these aren't necessary to build (and link to) HDF5. | |||
==Errors== | |||
You may run into problems during make check, something looking like this: | |||
<pre> | |||
Testing hard normalized long double -> signed char conversions Command terminated by signal 11 | |||
0.31user 0.04system 0:01.64elapsed 21%CPU (0avgtext+0avgdata 19936maxresident)k | |||
824inputs+360outputs (6major+14996minor)pagefaults 0swaps | |||
make[4]: *** [dt_arith.chkexe_] Error 1 | |||
</pre> | |||
The solution, as mentioned here http://kartadikaria.wordpress.com/2011/10/06/how-to-install-hdf5-macintosh-lion/, is to modify the configure flags for GNU compilers (the one used on Mac, if you're using gcc). Change the <code>PROD_CFLAG</code> for gcc compilers version 4 and up to use <code>-O0</code> instead of the default <code>-O3</code>. | |||
=Using= | |||
==Python and HDF5== | |||
Link to docs: http://docs.h5py.org/en/latest/ | |||
Link to quickstart: http://docs.h5py.org/en/latest/quick.html | |||
Start by creating an HDF5 file object: | |||
<pre> | |||
>>> import h5py | |||
>>> import numpy as np | |||
>>> | |||
>>> f = h5py.File("mytestfile.hdf5", "w") | |||
</pre> | |||
Now that you have a file object, create data sets: | |||
<pre> | |||
>>> dset = f.create_dataset("mydataset", (100,), dtype='i') | |||
</pre> | |||
(This is not a file, but a dataset object - this is similar to a Numpy array.) | |||
HDF5 files are stored in a hierarchical way, with a "directory"-like structure. | |||
<pre> | |||
>>> dset.name | |||
u'/mydataset' | |||
</pre> | |||
The file object is the root group, equivalent to <code>/</code> on a Unix system: | |||
<pre> | |||
>>> f.name | |||
u'/' | |||
</pre> | |||
=Flags= | |||
{{Programs}} | {{Programs}} | ||
Latest revision as of 05:42, 10 October 2017
Installing
Mac OS X Lion: Use Brew
If you're on Mac OS X Lion (10.7), you may run into issues. If you're less inclined to get elbow-deep in computer problems, you can just use Homebrew (http://mxcl.github.io/homebrew/), a really nice package manager for Mac OS X. MacPorts and Fink can both be nightmares, but Homebrew manages to do everything hassle-free.
You can install HDF5 using Homebrew by running:
$ brew install hdf5
UPDATE: HDF5 has since moved to Homebrew-Science (https://github.com/Homebrew/homebrew-science). You can "tap" into Homebrew Science to get to the HDF5 recipe.
Configuring
I am using the HDF5 libraries for various software tools available through the CRSim Software repository http://software.crsim.utah.edu/ - specifically, C++ programs using the C++ interface to HDF5 - necessitating the --enable-cxx configure argument:
./configure \
--prefix=/path/to/hdf5 \
--enable-cxx
You can optionally use the configure arguments --enable-static-exe --enable-static, though in my experience these aren't necessary to build (and link to) HDF5.
Errors
You may run into problems during make check, something looking like this:
Testing hard normalized long double -> signed char conversions Command terminated by signal 11 0.31user 0.04system 0:01.64elapsed 21%CPU (0avgtext+0avgdata 19936maxresident)k 824inputs+360outputs (6major+14996minor)pagefaults 0swaps make[4]: *** [dt_arith.chkexe_] Error 1
The solution, as mentioned here http://kartadikaria.wordpress.com/2011/10/06/how-to-install-hdf5-macintosh-lion/, is to modify the configure flags for GNU compilers (the one used on Mac, if you're using gcc). Change the PROD_CFLAG for gcc compilers version 4 and up to use -O0 instead of the default -O3.
Using
Python and HDF5
Link to docs: http://docs.h5py.org/en/latest/
Link to quickstart: http://docs.h5py.org/en/latest/quick.html
Start by creating an HDF5 file object:
>>> import h5py
>>> import numpy as np
>>>
>>> f = h5py.File("mytestfile.hdf5", "w")
Now that you have a file object, create data sets:
>>> dset = f.create_dataset("mydataset", (100,), dtype='i')
(This is not a file, but a dataset object - this is similar to a Numpy array.)
HDF5 files are stored in a hierarchical way, with a "directory"-like structure.
>>> dset.name u'/mydataset'
The file object is the root group, equivalent to / on a Unix system:
>>> f.name u'/'
Flags