[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This program reads the signal specifications of the record named as its argument:
1 #include <stdio.h> 2 #include <wfdb/wfdb.h> 3 4 main(argc, argv) 5 int argc; 6 char *argv[]; 7 { 8 WFDB_Siginfo *s; 9 int i, nsig; 10 11 if (argc < 2) { 12 fprintf(stderr, "usage: %s record\n", argv[0]); 13 exit(1); 14 } 15 nsig = isigopen(argv[1], NULL, 0); 16 if (nsig < 1) exit(2); 17 s = (WFDB_Siginfo *)malloc(nsig * sizeof(WFDB_Siginfo)); 18 if (s == NULL) { 19 fprintf(stderr, "insufficient memory\n"); 20 exit(3); 21 } 22 if (isigopen(argv[1], s, nsig) != nsig) exit(2); 23 printf("Record %s\n", argv[1]); 24 printf("Starting time: %s\n", timstr(0L)); 25 printf("Sampling frequency: %g Hz\n", sampfreq(argv[1])); 26 printf("%d signals\n", nsig); 27 for (i = 0; i < nsig; i++) { 28 printf("Group %d, Signal %d:\n", s[i].group, i); 29 printf(" File: %s\n", s[i].fname); 30 printf(" Description: %s\n", s[i].desc); 31 printf(" Gain: "); 32 if (s[i].gain == 0.) 33 printf("uncalibrated; assume %g", WFDB_DEFGAIN); 34 else printf("%g", s[i].gain); 35 printf(" adu/%s\n", s[i].units ? s[i].units : "mV"); 36 printf(" Initial value: %d\n", s[i].initval); 37 printf(" Storage format: %d\n", s[i].fmt); 38 printf(" I/O: "); 39 if (s[i].bsize == 0) printf("can be unbuffered\n"); 40 else printf("%d-byte blocks\n", s[i].bsize); 41 printf(" ADC resolution: %d bits\n", s[i].adcres); 42 printf(" ADC zero: %d\n", s[i].adczero); 43 if (s[i].nsamp > 0L) { 44 printf(" Length: %s (%ld sample intervals)\n", 45 timstr(s[i].nsamp), s[i].nsamp); 46 printf(" Checksum: %d\n", s[i].cksum); 47 } 48 else printf(" Length undefined\n"); 49 } 50 exit(0); 51 } |
(See http://physionet.org/physiotools/wfdb/examples/example5.c for a copy of this program.)
Notes:
The command-line argument, argv[1]
, is the record name. The
number of signals listed in the header file for the record is returned by
isigopen
as nsig
. If nsig
< 1, isigopen
will
print an error message; in this case the program can’t do anything useful,
so it exits.
We allocate nsig
signal information (WFDB_Siginfo
) objects.
On the second invocation of isigopen
, we pass the pointer to the
signal information objects and the number of signals we expect to open.
isigopen
returns the number of signals it is able to open; if
any of those named in the header file are unreadable, the return value
will not match nsig
, and the program exits.
Invoking timstr
with an argument of zero (here written ‘0L’
to emphasize to the compiler that the argument is a long
integer)
will obtain the starting time of the record. If no starting time is
defined, timstr
will return “0:00:00
”.
Notice how a zero value for gain
is interpreted.
If the units
field is NULL, the physical units are assumed to be
millivolts (“mV”).
If bsize
is zero, I/O can be performed in blocks of any reasonable
size; otherwise it must be performed in blocks of exactly the specified
bsize
.
If the length of the record is defined, it is printed in both hours,
minutes, and seconds, and in sample intervals. Since the argument of
timstr
in line 39 is positive, it is interpreted as a time
interval. The checksum is defined only if the record length is
defined.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
PhysioNet (wfdb@physionet.org)