Personal IDL library for M. Galloy

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


file i/o, netcdf, sdf

includes main-level program

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


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_nc_getdata

Author information


Michael Galloy

Other file information


better error messages when items not found access for global attributes

top source mg_nc_getdata

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

Pulls out a section of a netCDF variable.

Return value

data array


filename in required type=string

filename of the netCDF file

variable in required type=string

variable name (with path if inside a group)


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: Wed Sep 28 16:19:14 2011
Lines: 417
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.