fileio/
mg_h5_getdata.pro
file i/o, hdf5, sdf
includes main-level programRoutine 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
Routines
result = mg_h5_getdata_convertbounds(sbounds [, dimensions=lonarr(ndims)] [, /single])
Converts normal IDL indexing notation (represented as a string) into a lonarr(ndims, 3) where the first row is start values, the second row is the end values, and the last row is the stride value.
mg_h5_getdata_computeslab, bounds [, start=lonarr(ndims)] [, count=lonarr(ndims)] [, block=lonarr(ndims)] [, stride=lonarr(ndims)]
Compute the H5D_SELECT_HYPERSLAB arguments from the bounds.
result = mg_h5_getdata_getvariable(fileId, variable [, bounds=lonarr(3, ndims) or string] [, error=long])
Reads data in a dataset.
result = mg_h5_getdata_getattributedata(loc, attname)
Get the value of the attribute from its group, dataset, or type.
result = mg_h5_getdata_getattribute(fileId, variable [, error=long])
Get the value of an attribute in a file.
result = mg_h5_getdata(filename, variable [, bounds=lonarr(3, ndims) or string] [, error=long])
Pulls out a section of a HDF5 variable.
Routine details
top source mg_h5_getdata_convertboundsprivate
result = mg_h5_getdata_convertbounds(sbounds [, dimensions=lonarr(ndims)] [, /single])
Converts normal IDL indexing notation (represented as a string) into a
lonarr(ndims, 3)
where the first row is start values, the second row is
the end values, and the last row is the stride value.
Return value
lonarr(ndims, 3)
Parameters
- sbounds in required type=string
bounds specified as a string using IDL's normal indexing notation
Keywords
- dimensions in optional type=lonarr(ndims)
dimensions of the full array; required if a '*' is used in sbounds
- single out optional type=boolean
set to a named variable to determine if the bounds expression was specified in single-index dimensioning
top source mg_h5_getdata_computeslabprivate
mg_h5_getdata_computeslab, bounds [, start=lonarr(ndims)] [, count=lonarr(ndims)] [, block=lonarr(ndims)] [, stride=lonarr(ndims)]
Compute the H5D_SELECT_HYPERSLAB arguments from the bounds.
Parameters
- bounds in required type=lonarr(ndims, 3)
bounds
Keywords
- start out optional type=lonarr(ndims)
input for start argument to H5S_SELECT_HYPERSLAB
- count out optional type=lonarr(ndims)
input for count argument to H5S_SELECT_HYPERSLAB
- block out optional type=lonarr(ndims)
input for block keyword to H5S_SELECT_HYPERSLAB
- stride out optional type=lonarr(ndims)
input for stride keyword to H5S_SELECT_HYPERSLAB
top source mg_h5_getdata_getvariableprivate
result = mg_h5_getdata_getvariable(fileId, variable [, bounds=lonarr(3, ndims) or string] [, error=long])
Reads data in a dataset.
Return value
value of data read from dataset
Parameters
- fileId in required type=long
HDF 5 indentifier of the file
- variable in required type=string
string navigating the path to the dataset
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
top source mg_h5_getdata_getattributedataprivate
result = mg_h5_getdata_getattributedata(loc, attname)
Get the value of the attribute from its group, dataset, or type.
Return value
attribute data
Parameters
- loc in required type=long
identifier of group, dataset, or type that contains the attribute
- attname in required type=string
attribute name
top source mg_h5_getdata_getattributeprivate
result = mg_h5_getdata_getattribute(fileId, variable [, error=long])
Get the value of an attribute in a file.
Return value
attribute value
Parameters
- fileId in required type=long
HDF 5 file identifier of the file to read
- variable in required type=string
path to attribute using "/" to navigate groups/datasets and "." to indicate the attribute name
Keywords
- error out optional type=long
error value
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: | Mon Mar 21 13:25:40 2011 |
Lines: | 446 |
Docformat: | rst rst |