WFDB-x

A fast, lightweight implementation of the WFDB library and command-line tools, with identical behavior across seven programming languages

View the Project on GitHub alphanumericslab/wfdb-x

Porting guide

This document describes how every WFDB-x implementation is organized, and the details of the C implementation that an implementation must reproduce to pass the conformance suite. The Python implementation (python/src/wfdbx/) is the template for the others.

Structure

Each implementation mirrors the C sources, file by file:

C source (third_party/wfdb-main.zip) Python module Contents
lib/wfdbio.c _wfdbio.py input and output directories, network access, the WFDB path of legacy mode, wfdb_open, error reporting, binary I/O helpers
lib/signal.c _signal.py headers, signal I/O in all formats, time/date conversion, units
lib/annot.c _annot.py annotation I/O (MIT and AHA formats), mnemonics
lib/calib.c _calib.py calibration list
lib/wfdbinit.c _wfdbinit.py wfdbinit, wfdbquit, wfdbflush
lib/ecgcodes.h, lib/ecgmap.h, the mapping functions of lib/annot.c _ecgcodes.py annotation codes and mapping tables
FLAC support in lib/signal.c (libFLAC) _flac.py the FLAC support of the signal functions, a translation of libFLAC 1.4.3’s stream decoder, and WFDB-x’s own FLAC encoder
app/*.c, convert/*.c apps/*.py command-line tools
(C standard library) _cstd.py strtol, strtod, strtok, sscanf, fgets, glibc rand, printf details

Ports of the library keep the C library’s global state and its function names, so that ports of the applications can follow the C sources line by line. A high-level API in the idiom of the language is built on top.

C semantics to reproduce

Reference platform: x86-64 Linux, glibc, -DWFDB_LARGETIME.

Library details that are easy to get wrong

Applications

Each tool is a line-by-line port of its C source. Several C programs rely on stale buffer contents, modify their arguments in place, or have undefined behavior; KNOWN_C_BEHAVIORS.md lists them, with the behavior chosen by WFDB-x where C’s is undefined.

Messages that include the program name use the name the program was invoked by (argv[0] or its last path component, as the C source does). Ports must arrange for this to be the tool’s name (e.g. rdsamp), as the conformance suite expects.