The following program copies an annotation file, changing all QRS annotations
to NORMAL and deleting all non-QRS annotations.
1 #include <stdio.h>
2 #include <ecg/db.h>
3 #include <ecg/ecgmap.h>
4
5 main()
6 {
7 DB_Anninfo an[2];
8 char record[8], iann[10], oann[10];
9 DB_Annotation annot;
10
11 printf("Type record name: ");
12 fgets(record, 8, stdin); record[strlen(record)-1] = '\0';
13 printf("Type input annotator name: ");
14 fgets(iann, 10, stdin); iann[strlen(iann)-1] = '\0';
15 printf("Type output annotator name: ");
16 fgets(oann, 10, stdin); oann[strlen(oann)-1] = '\0';
17 an[0].name = iann; an[0].stat = READ;
18 an[1].name = oann; an[1].stat = WRITE;
19 if (annopen(record, an, 2) < 0) exit(1);
20 while (getann(0, &annot) == 0)
21 if (isqrs(annot.anntyp)) {
22 annot.anntyp = NORMAL;
23 if (putann(0, &annot) < 0) break;
24 }
25 dbquit();
26 }
Notes:
#include statement makes available not only the mapping
macros, one of which will be used in line 21, but also the
annotation code symbols in `<ecg/ecgcodes.h>', one of which
will be needed in line 22.
DB_Anninfo objects has two members.
getann, modified, and passed
to putann for output.
fgets
copies into the string) with a null. String arguments to DB library
functions should not include newline characters.
name fields of the array of
DB_Anninfo objects. Note that the name fields are only
pointers and do not contain storage for the strings themselves. If this
is not clear to you, review the discussion of pointers and arrays in
K&R, pp. 97--100. The input annotator is to be read, the output
annotator is to be written. READ and WRITE are defined in
`<ecg/db.h>'.
annopen are
the names of the respective arrays; thus annopen receives pointers
rather than values in its argument list.
annot.
The `&' is necessary since getann requires a pointer to
the structure in order to be able to modify its contents. When
getann returns a negative value, no more annotations remain to be
read and the loop ends.
isqrs is defined in `<ecg/ecgmap.h>';
isqrs(x) is true if x is an annotation code that
denotes a QRS complex, false if x is not a QRS annotation
code.
NORMAL is defined in `<ecg/ecgcodes.h>'.
putann now writes the modified annotation in the
output annotator 0 file. As for getann, a pointer to
annot must be passed using the `&' operator.
putann.
Go to the first, previous, next, last section, table of contents.