Contact: zeng  @      Last update: 20 January 2010

HDF-5 Library

This library includes only part of the functions of Hierarchical Data Format library. Supported dataset types include simple array of native char, uchar, short, ushort, int, uint, float, and double types. Supported attribute types include native string, integer, double, and simple array of native integer and double.

Function Parameter Type Remark
hdf(filename[,mode]) string[, string] Returns a HDF object. Using "w" for The optional mode parameter will open the file for writing or "c" for creating a new HDF file. The root "/" is set as the target group. Returns null if failed.
.version()   Returns HDF version as string.
.group(name) string Sets the named group as the target group. The function first tries to open the group if it exists and creates the group if not.
.dataset(name) string Sets the named dataset in the target group as the target dataset. The dataset name must include group name. It returns false if failed or true otherwise.
.dataset(name, type, dim1[, dim2...]) string, string, integers Defines a dataset in the target group and set it as the target dataset. The dataset name must include group name. The dataset type name must be "char", "uchar", "short", "ushort", "int", "uint", "float", or "double". The number of integers after the type argument determines the number of dimensions and integer values define dimension sizes.
.dims()   Returns dimension sizes of the current dataset as an array.
.size()   Returns an array containing the number of data, datum size, and type name of the target dataset.
.cmm()   Returns the comment of the target group or dataset.
.cmm(comment) string Writes comment to the target group or dataset.
.list()   List contents in the target group and dataset.
.scan(callback, groupname) strings Scans groups and datasets in the specified group. The callback will be called with three parameters with the first being "GROUP", "DATASET", or "DEFAULT" and the rest being names of the parent group and the current item.
.__get(name) string To be called by such an expression as to get the named attribute in the target group or dataset. It may return a string, a number, or an array of numbers.
.__get(index...) null or integer or array To be called by such an expression as hdf[*, 1] to read data from the target dataset. A null index (may be represented by *) specifies reading all data in that dimension; an integer index (must be positive) specifies reading at that position in that dimension; and an array index (e.g., [1,2]) specifies reading range for that dimension. If the number of indices is smaller than the number of dimensions of the dataset, unspecified dimension indices are defaulted to null. The function returns an integer or real if indices are fully specified by integers; otherwise, it returns a pointer to data.
.__set(name, value) string, string or number or array of numbers To be called by such an expression as = value to set the named attribute of the target group or dataset.
.__set(index.., data.) null or integers or array, user or number To be called by such an expression as hdf[*, 1] = data to write data to the target dataset. If the data is a user type, you are responsible to ensure that its pointer points to correct number of data.

HDF Example


h = hdf("test.hdf", "c");

h.dataset("/data1", "int", 10, 10);


h.cmm("test group comment");

h.att1 = "attribute of data1";

h.att2 = 1.5;

h.att3 = [1, 2.1, 3];
h.att1 = "attribute of group1";

h.att2 = 15;

h.att3 = [1, 2, 3];

h.cmm("test group comment");


load("matrix.dll", "hdf.dll");

h = hdf("test.hdf", "w");

a = matrix("int", 10, 10);
a.fill(0, 1);
[ptr, n, e] = a.ptr();

h[*] = ptr;
h[1,*] = 100;
h[*,2] = 200;
h[[1,5],[2,5]] = 0;

h[9,[2,5]] = 0;