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

Example 3: An Annotation Printer

This program prints annotations in readable form. Its first argument is an annotator name, and its second argument is a record name.

 
 1  #include <stdio.h>
 2  #include <wfdb/wfdb.h>
 3
 4  main(argc, argv)
 5  int argc;
 6  char *argv[];
 7  {
 8      WFDB_Anninfo a;
 9      WFDB_Annotation annot;
10
11      if (argc < 3) {
12          fprintf(stderr, "usage: %s annotator record\n", argv[0]);
13          exit(1);
14      }
15      a.name = argv[1]; a.stat = WFDB_READ;
16      (void)sampfreq(argv[2]);
17      if (annopen(argv[2], &a, 1) < 0) exit(2);
18      while (getann(0, &annot) == 0)
19          printf("%s (%ld) %s %d %d %d %s\n",
20                 timstr(-(annot.time)),
21                 annot.time,
22                 annstr(annot.anntyp),
23                 annot.subtyp, annot.chan, annot.num,
24                 (annot.aux != NULL && *annot.aux > 0) ?
25                  annot.aux+1 : "");
26      exit(0);
27  }

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

Notes:

Line 16:

The invocation of sampfreq here sets the internal variables needed by timstr below.

Line 20:

This line gives the annotation time as a time of day. If the base time is omitted in the header file, or if we used timstr(annot.time) instead, we would obtain the elapsed time from the beginning of the record.

Lines 24–25:

This expression evaluates to an empty string unless the aux string is non-empty. It makes the assumption that aux is a printable ASCII string; the printable part follows the length byte.


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

PhysioNet (wfdb@physionet.org)