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

SWIG wrappers for Java, Perl, Python, and other languages

Isaac Henry has contributed WFDB wrappers for Java, Perl, and Python, as well as for .NET languages such as C#, created using the Simplified Wrapper Interface Generator (SWIG, http://www.swig.org/). Using these wrappers, the example program can be written in any of these languages:

Java:

 
import wfdb.*;

public class rdsamp {
    static {
        System.loadLibrary("wfdbjava");
    }

    public static void main(String argv[]) {
        WFDB_SiginfoArray siarray = new WFDB_SiginfoArray(2);
        if (wfdb.isigopen ("100s", siarray.cast(), 2) < 2)
            System.exit(1);
        WFDB_SampleArray v = new WFDB_SampleArray(2);
        for (int i = 0; i < 10; i++) {
            if (wfdb.getvec(v.cast()) < 0)
                break;
            System.out.print("\t" + v.getitem(0));
            System.out.print("\t" + v.getitem(1));
            System.out.println();
        }
    }
}

Perl:

 
package wfdb;
use wfdb;

$siarray = new wfdb::WFDB_SiginfoArray(2);
if ($nsig = isigopen("100s", $siarray->cast(), 2) < 2) {
    exit(1);
}
$v = new wfdb::WFDB_SampleArray(2);
for ($i=0; $i < 10; $i++) {
    if (getvec($v->cast()) < 0) {
        exit(2);
    }
    print "\t", $v->getitem(0), "\t", $v->getitem(1), "\n";
}

Python:

 
import wfdb, sys

def main(argv):
    siarray = wfdb.WFDB_SiginfoArray(2)
    if wfdb.isigopen("100s", siarray.cast(), 2) < 2: sys.exit(1)
    v = wfdb.WFDB_SampleArray(2)
    for i in range(0,10):
        if wfdb.getvec(v.cast()) > 0: sys.exit(2)
        print v[0],
        print v[1],
        print

if __name__ == "__main__":
    main(sys.argv[1:])

C#:

 
using System;
using Wfdb;

public class psamples {
    static void Main(string[] argv) {
        WFDB_SiginfoArray siarray = new WFDB_SiginfoArray(2);
        if (wfdb.isigopen("100s", siarray.cast(), 2) < 2)
            Environment.Exit(1);
        WFDB_SampleArray v = new WFDB_SampleArray(2);
        for (int i = 0; i < 10; i++) {
            if (wfdb.getvec(v.cast()) < 0)
                break;
            Console.Write(v.getitem(0));
            Console.Write(v.getitem(1));
            Console.WriteLine();
        }
    }
}

All SWIG wrappers for the WFDB library are generated using a single interface file, `wfdb.i'. In principle, this file might be used to generate wrappers for other programming languages supported by SWIG, including several versions of LISP, Modula-3, PHP, Ruby, and Tcl.


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

George B. Moody (george@mit.edu)