★ Scientific data file format routines
posted Tue 12 Aug 2014 by Michael Galloy under IDLI’ve been dealing with HDF 5 files for quite awhile, but IDL interface was as painful as the C interface. It did have H5_BROWSER
and H5_PARSE
to make things a bit easier, but these utilities are relevant for interactive browsing of a dataset and not for efficient, programmatic access. I created a set of routines for dealing with HDF 5 files that I have been extending as needed to other scientific data formats such as netCDF, HDF 4, and IDL Savefiles.
For example, MG_H5_GETDATA
can access variables stored in HDF 5 files:
f = filepath('hdf5_test.h5', subdir=['examples', 'data'])
arr = mg_h5_getdata(f, '/arrays/3D int array')
Or slices of variables:
slice = mg_h5_getdata(f, '/arrays/3D int array[3, 5:*:2, 0:49:3]')
Or attributes:
attr = mg_h5_getdata(f, '/images/Eskimo.CLASS')
Similarly, MG_H5_PUTDATA
can create and edit variables in HDF 5 files, while MG_H5_DUMP
prints a listing of the variables and attributes of a file.
I have adding corresponding routines for HDF 4, netCDF, and IDL Savefiles over the past few years. Since I have been dealing netCDF files more extensively recently, I have been adding to their routines, most notably I have created a LIST
routine which provides an array of variable/attribute names available in a file.
Here’s the routines available in mglib currently:
Action | HDF 4 | HDF 5 | netCDF | Savefile |
---|---|---|---|---|
get data | MG_HDF_GETDATA |
MG_H5_GETDATA |
MG_NC_GETDATA |
MG_SAVE_GETDATA |
put data | MG_HDF_PUTDATA |
MG_H5_PUTDATA |
MG_NC_PUTDATA |
|
dump | MG_HDF_DUMP |
MG_H5_DUMP |
MG_NC_DUMP |
MG_SAVE_DUMP |
list | MG_NC_LIST |