idllib

Personal IDL library for M. Galloy

single page | use frames     summary     class     fields     routine details     file attributes

hdf5/

mg_h5_getdata.pro

file i/o, hdf5, sdf

includes main-level program

Routine for extracting datasets, slices of datasets, or attributes from an HDF 5 file with simple notation.

Examples

An example file is provided with the IDL distribution:

IDL> f = filepath('hdf5_test.h5', subdir=['examples', 'data'])
A full dataset can be easily extracted:
IDL> fullResult = mg_h5_getdata(f, '/arrays/3D int array')
Slices can also be pulled out:
IDL> bounds = [[3, 3, 1], [5, 49, 2], [0, 49, 3]] IDL> res1 = mg_h5_getdata(f, '/arrays/3D int array', bounds=bounds) IDL> help, res1 RESULT1 LONG = Array[1, 23, 17]
Verify that the slice is the same as the slice pulled out of the fullResult:
IDL> same = array_equal(fullResult[3, 5:*:2, 0:49:3], res1) IDL> print, same ? 'equal' : 'error' equal
Normal IDL array indexing notation can be used as well:
IDL> bounds = '3, 5:*:2, 0:49:3' IDL> res2 = mg_h5_getdata(f, '/arrays/3D int array', bounds=bounds) IDL> print, array_equal(res1, res2) ? 'equal' : 'error' equal
The variable location and bounds can be combined to slice a variable:
IDL> res3 = mg_h5_getdata(f, '/arrays/3D int array[3, 5:*:2, 0:49:3]') IDL> print, array_equal(res1, res3) ? 'equal' : 'error' equal
Attributes can be accessed as well:
IDL> print, mg_h5_getdata(f, '/images/Eskimo.CLASS') IMAGE
This example is available as a main-level program included in this file:
IDL> .run mg_h5_getdata

Author information

Author

Michael Galloy

Copyright

This library is released under a BSD-type license.

Copyright (c) 2007-2010, Michael Galloy <mgalloy@idldev.com>

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

a. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. b. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. c. Neither the name of Michael Galloy nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Other file information

Todo:

better error messages when items not found

top source mg_h5_getdata

result = mg_h5_getdata(filename, variable [, bounds=lonarr(3, ndims) or string] [, error=long])

Pulls out a section of a HDF5 variable.

Return value

data array

Parameters

filename in required type=string

filename of the HDF5 file

variable in required type=string

variable name (with path if inside a group)

Keywords

bounds in optional type=lonarr(3, ndims) or string

gives start value, end value, and stride for each dimension of the variable

error out optional type=long

error value

File attributes

Modification date: Fri Mar 9 14:19:50 2012
Lines: 490
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.