[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 A Trivial Example Program in C

Suppose we wish to print the first ten samples of record ‘100s’. (Record ‘100s’ is the first minute of MIT-BIH Arrhythmia Database record ‘100’, supplied as a sample in the data directory of all source distributions of the WFDB Software Package.) We might begin by creating a source file called ‘psamples.c’ that contains:

 
#include <stdio.h>
#include <wfdb/wfdb.h>

main()
{
    int i;
    WFDB_Sample v[2];
    WFDB_Siginfo s[2];

    if (isigopen("100s", s, 2) < 2)
        exit(1);
    for (i = 0; i < 10; i++) {
        if (getvec(v) < 0)
            break;
        printf("%d\t%d\n", v[0], v[1]);
    }
    exit(0);
}

(See http://physionet.org/physiotools/wfdb/examples/psamples.c for a copy of this program.)

All programs that use the WFDB library must include the statement

 
#include <wfdb/wfdb.h>

which defines function interfaces, data types (such as the WFDB_Sample and WFDB_Siginfo types used in this example), and a few useful constants. (Most MS-DOS C compilers accept ‘/’ as a directory separator. If you prefer to use the non-portable ‘\’ under MS-DOS, remember to quote it: ‘#include <wfdb\\wfdb.h>’.)

The functions used in the example are described in detail in the next chapter, and the data types are described in the following chapter (see section Data Types). For now, note that isigopen prepares a record to be read by getvec, which reads a sample from each of the two signals each time it is called.

Note that in some cases it may be important to insure that all memory allocated by the WFDB library is freed before the program exits; in the example program, this can be done by adding the line

 
wfdbquit();

just above exit(0); (see section wfdbquit).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

PhysioNet (wfdb@physionet.org)