Overview
hdf5 wraps libHDF5 — the standard storage format for scientific and engineering data used by NASA, CERN, financial institutions, and ML research. HDF5 files are self-describing hierarchical containers: each file is a filesystem of typed N-dimensional arrays with metadata attributes.
CLib package
Ubuntu/Debian: sudo apt install libhdf5-dev
Quick Start
uses hdf5;
var f := OpenFile('/data/experiment.h5', 'w');
// Write datasets
WriteFloat64(f, '/signals/temperature', [22.1, 22.5, 23.0, 22.8]);
WriteInt32(f, '/counts/events', [10, 14, 9, 17, 12]);
// Metadata attributes
SetAttrString(f, '/signals/temperature', 'units', 'Celsius');
SetAttrFloat(f, '/signals/temperature', 'sample_rate', 1.0);
CloseFile(f);
WriteLn('Version: ', HDF5Version);
Read Data
var f := OpenFile('/data/experiment.h5', 'r');
var temps := ReadFloat64(f, '/signals/temperature');
for I := 0 to Length(temps) - 1 do
WriteLn('T[', I, '] = ', temps[I]:0:2);
var units := GetAttrString(f, '/signals/temperature', 'units');
WriteLn('Units: ', units);
CloseFile(f);
2-D Matrices
// Store a 100×256 matrix (e.g. 100 feature vectors of dim 256)
var matrix: array of Double;
SetLength(matrix, 100 * 256);
// ... fill matrix ...
var f := OpenFile('/data/embeddings.h5', 'w');
WriteMatrix(f, '/embeddings', matrix, 100, 256);
// Read back
var rows, cols: Integer;
var data := ReadMatrix(f, '/embeddings', rows, cols);
WriteLn(rows, 'x', cols, ' matrix loaded');
CloseFile(f);
Groups and Navigation
var f := OpenFile('/data/runs.h5', 'w');
CreateGroup(f, '/run1');
CreateGroup(f, '/run2');
WriteFloat64(f, '/run1/voltage', voltageData);
WriteFloat64(f, '/run2/voltage', voltageData2);
SetAttrString(f, '/run1', 'date', '2026-03-13');
// List contents
var items := ListGroup(f, '/');
for I := 0 to Length(items) - 1 do
WriteLn(items[I]); // "run1", "run2"
// Check existence
if Exists(f, '/run1/voltage') then
WriteLn('Dataset found');
CloseFile(f);
Compressed Storage
// Store large dataset with GZIP compression (level 6) and chunking
var f := OpenFile('/data/large.h5', 'w');
WriteCompressed(f, '/data/signals', bigArray,
Rows := 10000,
Cols := 1024,
CompressLevel := 6,
ChunkSize := 1024);
CloseFile(f);
var info := DatasetInfo(OpenFile('/data/large.h5','r'), '/data/signals');
WriteLn('Compressed: ', info.Compressed);
WriteLn('Elements: ', info.Size);
Package Info
Version1.0.0
Typeclib
C Librarylibhdf5
Authorgustavo
Functions
- OpenFile / CloseFile
- IsHDF5
- CreateGroup / OpenGroup
- ListGroup
- WriteFloat64 / ReadFloat64
- WriteInt32 / ReadInt32
- WriteMatrix / ReadMatrix
- WriteStrings / ReadStrings
- WriteBytes / ReadBytes
- WriteCompressed
- DatasetInfo
- Exists / Delete
- SetAttrString / GetAttrString
- SetAttrFloat / GetAttrFloat
- ListAttrs
- HDF5Version