int getvec(DB_Sample *vector)
Return:
This function reads a sample from each input signal. The caller should
allocate storage for an array of DB_Samples (integers) and pass a
pointer to this array to getvec
. (The length of the array must
be no less than the number of input signals, as obtained from
isigopen
or dbinit
; this number will never exceed
DB_MAXSIG
, defined in `<ecg/db.h>'.) On return,
vector[i] contains the next sample from signal i. For
example, this modified version of the example from chapter 1 reads and
prints the first ten samples of each available input signal:
#include <ecg/db.h> main() { int i, j, nsig; DB_Sample v[DB_MAXSIG]; static DB_Siginfo s[DB_MAXSIG]; nsig = isigopen("100s", s, DB_MAXSIG); if (nsig < 1) exit(1); for (i = 0; i < 10; i++) { if (getvec(v) < 0) break; for (j = 0; j < nsig; j++) printf("%8d", v[j]); printf("\n"); } exit(0); }
Notice how the value returned by isigopen
is used to determine
how many input signals there are. The array of DB_Siginfo
structures is declared static
, a practice that is recommended
for all arrays and data structures of any substantial size, to avoid
run-time stack overflow. Several of the example programs in chapter 6
illustrate the use of getvec
; for example, see section Example 6: A Differentiator.
Go to the first, previous, next, last section, table of contents.