This library includes only part of the functions of Hierarchical Data Format library. Datasets and attributes are stored as simple array of native char, uchar, short, ushort, int, uint, float, and double types. But an attribute of char array appears to user like a string.
| Function | Parameter Type | Remark |
| hdf(filename[,mode]) | string[, string] | Returns a HDF object. The optional mode parameter determines writing ("w"), creation ("c"), or reading ("r" or none). 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 and returns the group ID or null if failed. The function first tries to open the group if it exists and creates the group if not. The functions also close any group ID obtained previously from the file handle. |
| :dataset(name) | string | Sets the named dataset as the target dataset for the target group and returns the dataset ID or null if failed. The functions also close any dataset ID obtained previously. |
| :dataset(name, type, dim1[, dim2...]) | string, string, number[, number...] | Defines a dataset and returns the dataset ID. 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 arguments after the type argument determines the dimensions and each argument defines dimension size . |
| :size() | Returns the dimensions and element size of the currently opened dataset as an array: [0]--number of data, [1]--datum size, [2]--size of the first dimension, [2]--size of the second dimension, and so on. | |
| :getdat(ptr, n, esize[, start, count...]) | user, number, number[, number, number...] | Reads all data from the dataset if no start-count arguments are used; other wise reads a block of data. The number of start-count pairs must be the same as the dimensions of the dataset. The memory (n*esize) pointed to by the pointer of ptr must equal the total number of bytes to be read. |
| :putdat(ptr[, start, count...]) | user[, number, number...] | Writes data to the dataset. Refer to getdat() for explanations of the start and count arguments. |
| :getatt(id, name) | integer (dataset or group ID), string | Returns the named attribute of the target group or dataset as string for text attribute, as array for other types of attributes, or as null if the attribute does not exist. |
| :putatt(id, name, att1[, att2...]) | integer (dataset or group ID), string, string or numbers | Deletes, creates, and then writes contents to the named attribute for the target. If attr1 is a string, the rest of att will be ignore. If att1 is an integer or real, the rest of att will be treated as the same type and all are treated as values of a data array. |
| :getcmm(id, name) | integer (dataset or group ID), string | Returns the comment of the group or dataset. |
| :putcmm( id, name, comment) | integer (dataset or group ID), string, string | Writes comment to the group or dataset. |
| :list(id) | integer (dataset or group ID) | List contents in the group or dataset. |
load("matrix.dll", "hdf.dll");
h = hdf("test.hdf", "c");
id = h:dataset("/data1", "int", 10, 10);
h:putatt(id, "att1", "dataset attribute");
csv(h:getatt(id, "att1"));
h:putatt(id, "att2", 1, 2, 3);
a = h:getatt(id, "att2");
csv(a[0], a[1], a[2]);
id = h:group("/group1");
h:putatt(id, "att1", "group attribute");
csv(h:getatt(id, "att1"));
h:putatt(id, "att2", 1.1, 2.2, 3.3);
a = h:getatt(id, "att2");
csv(a[0], a[1], a[2]);
id = h:group("/");
h:putcmm(id, "data1", "test dataset comment");
csv(h:getcmm(id, "data1"));
h:putcmm(id, "group1", "test group comment");
csv(h:getcmm(id, "group1"));
/////////////////////////////////////////////////////////////////////
h = hdf("test.hdf", "w");
h:dataset("/data1");
a = matrix("int", 10, 10);
a:fill(0, 1);
p = a:ptr();
h:putdat(p[0]);
a:fill(10, 10);
h:putdat(p[0], 3, 2, 3, 3);
h:getdat(p[0], p[1], p[2]);
a:print();
a:resize(2, 3);
p = a:ptr();
h:getdat(p[0], p[1], p[2], 3, 2, 3, 3);
a:print();
/////////////////////////////////////////////////////////////////////
h = hdf("test.hdf");
id1 = h:group("/group1");
id2 = h:dataset("/data1");
h:list(id1);
h:list(id2);