void process(char *record, FILE *ifile) { char ofname[10], data[5]; WFDB_Time t = -1; static WFDB_Siginfo si[2]; static WFDB_Anninfo ai; static WFDB_Sample v[2]; static WFDB_Annotation a; setsampfreq(250.0); /* AHA DB is sampled at 250 Hz for each signal */ sprintf(ofname, "%s.dat", record); si[0].fname = ofname; si[0].desc = "ECG0"; si[0].units = "mV"; si[0].gain = 400; si[0].fmt = 212; si[0].adcres = 12; si[1] = si[0]; si[1].desc = "ECG1"; ai.name = "atr"; ai.stat = WFDB_WRITE; if (osigfopen(si, 2) != 2 || annopen(record, &ai, 1) < 0) { wfdbquit(); return; } while (fread(data, 1, 5, ifile) == 5) { v[0] = (data[0] & 0xff) | ((data[1] << 8) & 0xff00); v[1] = (data[2] & 0xff) | ((data[3] << 8) & 0xff00); (void)putvec(v); if (data[4] != '.') { a.anntyp = ammap(data[4]); a.subtyp = (data[4] == 'U' ? -1 : 0); a.time = t; (void)putann(0, &a); } t++; } (void)newheader(record); wfdbquit(); fprintf(stderr, "wrote %s.atr, $s.dat, and %s.hea\n", record,record,record); return; }
/* Read and interpret command-line arguments. */ void init(int argc, char *argv[]) { int i; void help(); pname = prog_name(argv[0]); for (i = 1; i < argc; i++) { if (*argv[i] == '-') switch (*(argv[i]+1)) { case 'a': /* annotator names follow */ if (++i >= argc-1) { (void)fprintf(stderr, "%s: reference and test annotator names must follow -a\n", pname); exit(0); } an[0].name = argv[i]; an[1].name = argv[++i]; break; case 'c': /* condensed output */ if (++i >= argc) { (void)fprintf(stderr, "%s: output file name must follow -c\n", pname); exit(0); } ofname = argv[i]; fflag = 1; break; case 'C': /* condensed output with SVEB statistics */ if (++i >= argc) { (void)fprintf(stderr, "%s: output file name must follow -C\n", pname); exit(0); } ofname = argv[i]; fflag = 4; break; case 'f': /* start time follows */ if (++i >= argc) { (void)fprintf(stderr,"%s: start time must follow -f\n", pname); exit(0); } start = i; /* save arg index, convert to samples later, when record has been opened and sampling frequency is known */ break; case 'h': /* print usage summary */ help(); exit(0); break; case 'l': /* line-format output */ if (++i >= argc-1) { (void)fprintf(stderr, "%s: two output file names must follow -l\n", pname); exit(0); } ofname = argv[i]; sfname = argv[++i]; fflag = 2; break; case 'L': /* line-format output, with SVEB statistics */ if (++i >= argc-1) { (void)fprintf(stderr, "%s: two output file names must follow -L\n", pname); exit(0); } ofname = argv[i]; sfname = argv[++i]; fflag = 5; break; case 'o': /* generate output annotation file */ oflag = 1; break; case 'O': /* generate expanded output annotation file */ oflag = 1; Oflag = 1; fflag = 0; break; case 'r': /* record name follows */ if (++i >= argc) { (void)fprintf(stderr, "%s: record name must follow -r\n", pname); exit(0); } // record = argv[i]; break; case 's': /* standard-format output */ if (++i >= argc) { (void)fprintf(stderr, "%s: output file name must follow -s\n", pname); exit(0); } ofname = argv[i]; fflag = 3; break; case 'S': /* standard-format output, with SVEB statistics */ if (++i >= argc) { (void)fprintf(stderr, "%s: output file name must follow -S\n", pname); exit(0); } ofname = argv[i]; fflag = 6; break; case 't': /* end time follows */ if (++i >= argc) { (void)fprintf(stderr, "%s: end time must follow -t\n", pname); exit(0); } end_time = i; break; case 'v': /* verbose mode */ verbose = 1; break; case 'w': /* match window follows */ if (++i >= argc) { (void)fprintf(stderr, "%s: match window must follow -w\n", pname); exit(0); } match_dt = i; break; default: (void)fprintf(stderr, "%s: unrecognized option %s\n", pname, argv[i]); exit(0); } else { (void)fprintf(stderr, "%s: unrecognized argument %s\n",pname,argv[i]); exit(0); } } if (!record || !an[0].name) { help(); exit(0); } if (start != 0L || end_time != 0L || match_dt != 0) (void)fprintf(stderr,"%s: (warning) nonstandard comparison selected\n", pname); if (sampfreq(record) <= 0) { (void)fprintf(stderr, "%s: (warning) %g Hz sampling frequency assumed\n", pname, WFDB_DEFFREQ); (void)setsampfreq(WFDB_DEFFREQ); } /* Set the match window and the times of the start and end of the test period. Initialize the shutdown tally to 1/2 second so that it will be properly rounded to the nearest second at the end. */ if (match_dt) match_dt = (int)strtim(argv[match_dt]); else match_dt = (int)strtim(".15"); /* 150 milliseconds */ if (start) start = strtim(argv[(int)start]); else start = strtim("5:0"); /* 5 minutes */ if (end_time) end_time = strtim(argv[(int)end_time]); else if ((end_time = strtim("e")) == 0L) end_time = -1L; /* record length unavailable -- go to end of reference annotation file */ if (end_time > 0L && end_time < start) { (void)fprintf(stderr, "%s: improper interval specified\n", pname); exit(0); } shut_down = strtim(".5"); /* 1/2 second */ an[0].stat = an[1].stat = WFDB_READ; if (oflag) { an[2].name = "bxb"; an[2].stat = WFDB_WRITE; } if (annopen(record, an, 2 + oflag) < 0) exit(0); }
INTEGER setsampfreq_(DOUBLE_PRECISION *frequency) { return (setsampfreq((WFDB_Frequency)(*frequency))); }
main(int argc, char **argv) { char *record = NULL, *prog_name(); int aindex = 0, alen = 0, framelen = 0; int i, nsig, s, vflag = 0; WFDB_Sample *frame; WFDB_Siginfo *si; void help(); pname = prog_name(argv[0]); for (i = 1; i < argc; i++) { if (*argv[i] == '-') switch (*(argv[i]+1)) { case 'F': if (++i >= argc) { (void)fprintf(stderr, "%s: sampling frequency must follow -F\n", pname); exit(1); } sscanf(argv[i], "%lf", &sfreq); if (sfreq <= 0.0) sfreq = 1.0; break; case 'h': /* help requested */ help(); exit(0); break; case 'r': /* record name */ if (++i >= argc) { (void)fprintf(stderr, "%s: record name must follow -r\n", pname); exit(1); } record = argv[i]; break; case 'v': /* verbose output -- include column headings */ vflag = 1; break; default: (void)fprintf(stderr, "%s: unrecognized option %s\n", pname, argv[i]); exit(1); } else { (void)fprintf(stderr, "%s: unrecognized argument %s\n", pname, argv[i]); exit(1); } } if (record == NULL) { help(); exit(1); } setgvmode(WFDB_HIGHRES); if ((nsig = isigopen(record, NULL, 0)) <= 0) exit(2); if ((si = malloc(nsig * sizeof(WFDB_Siginfo))) == NULL) { (void)fprintf(stderr, "%s: insufficient memory\n", pname); exit(2); } if ((nsig = isigopen(record, si, nsig)) <= 0) exit(2); for (i = framelen = 0; i < nsig; i++) { if (strcmp(si[i].desc, "EDF Annotations") == 0) { aindex = framelen; alen = si[i].spf; } framelen += si[i].spf; } if (alen == 0) { (void)fprintf(stderr, "%s: record %s has no EDF annotations\n", pname, record); (void)free(si); wfdbquit(); exit(3); } if ((frame = (int *)malloc((unsigned)framelen*sizeof(WFDB_Sample)))==NULL) { (void)fprintf(stderr, "%s: insufficient memory\n", pname); (void)free(si); exit(2); } if (sfreq > 0.0) { setgvmode(WFDB_LOWRES); setsampfreq(sfreq); } else sfreq = sampfreq(NULL); /* Print column headers if '-v' option selected. */ if (vflag) (void)printf(" Time Sample # Type Sub Chan Num\tAux\n"); while (getframe(frame) > 0) { WFDB_Sample *p; state = 0; for (i = 0, p = (frame + aindex); i < alen; i++, p++) { if (*p) { proc(*p); proc(*p >> 8); } else break; } }
main(int argc, char **argv) { char buf[80], *ifname, *record = NULL; double sps, wgain; int bitspersample, bytespersecond, framelen, i, nsig, tag, wres; long flen, len, wnsamp; static WFDB_Siginfo *s; /* Interpret the command line. */ pname = prog_name(argv[0]); for (i = 1; i < argc; i++) { if (*argv[i] == '-') switch (*(argv[i]+1)) { case 'h': /* help requested */ help(); exit(1); break; case 'i': /* input file name follows */ if (++i >= argc) { (void)fprintf(stderr, "%s: name of wav-format input file must follow -i\n", pname); exit(1); } ifname = argv[i]; if (strlen(ifname)<5 || strcmp(".wav", ifname+strlen(ifname)-4)) { (void)fprintf(stderr, "%s: name of input file must end in '.wav'\n", pname); exit(1); } break; case 'r': if (++i >= argc) { (void)fprintf(stderr, "%s: record name must follow -r\n", pname); exit(1); } record = argv[i]; break; default: (void)fprintf(stderr, "%s: unrecognized option %s\n", pname, argv[i]); exit(1); } else { (void)fprintf(stderr, "%s: unrecognized argument %s\n", pname, argv[i]); exit(1); } } /* Check that required arguments are present and valid. */ if (ifname == NULL) { help(); exit(1); } /* If the record name was not specified, generate it from ifname. */ if (record == NULL) { record = malloc(strlen(ifname)); strncpy(record, ifname, strlen(ifname)-4); record[strlen(ifname)-3] = '\0'; } /* Open the input file. */ if ((ifile = fopen(ifname, "rb")) == NULL) { fprintf(stderr, "%s: can't open %s\n", pname, ifname); exit(2); } /* Determine the size of the input file. */ fseek(ifile, 0L, SEEK_END); flen = ftell(ifile); fseek(ifile, 0L, SEEK_SET); /* Read and check the header chunk. */ if (fread(buf, 1, 4, ifile) != 4 || strncmp(buf, "RIFF", 4)) { fprintf(stderr, "%s: %s is not a .wav-format file\n", pname, ifname); exit(3); } len = in32() + 8; if (len != flen) { fprintf(stderr, "%s: header chunk of %s has incorrect length (%ld, should be %ld)\n", pname, ifname, len, flen); exit(3); } if (fread(buf, 1, 4, ifile) != 4 || strncmp(buf, "WAVE", 4)) { fprintf(stderr, "%s: %s is not a .wav-format file\n", pname, ifname); exit(3); } /* Read and check the format chunk. */ if (fread(buf, 1, 4, ifile) != 4 || strncmp(buf, "fmt ", 4)) { fprintf(stderr, "%s: format chunk missing or corrupt in %s\n", pname, ifname); exit(3); } len = in32(); tag = in16(); if (len != 16 || tag != 1) { fprintf(stderr, "%s: unsupported format %d in %s\n", pname, tag, ifname); exit(3); } nsig = in16(); sps = in32(); bytespersecond = in32(); framelen = in16(); bitspersample = in16(); if (bitspersample <= 8) { wres = 8; wgain = 12.5; } else if (bitspersample <= 16) { wres = 16; wgain = 6400; } else { fprintf(stderr, "%s: unsupported resolution (%d bits/sample) in %s\n", pname, bitspersample, ifname); exit(3); } if (framelen != nsig * wres / 8) { fprintf(stderr, "%s: format chunk of %s has incorrect frame length\n", pname, ifname); exit(3); } /* Read and check the beginning of the data chunk. */ if (fread(buf, 1, 4, ifile) != 4 || strncmp(buf, "data", 4)) { fprintf(stderr, "%s: data chunk missing or corrupt in %s\n", pname, ifname); exit(3); } len = in32(); wnsamp = len / framelen; if ((s = malloc(nsig * sizeof(WFDB_Siginfo))) == NULL) { (void)fprintf(stderr, "%s: insufficient memory\n", pname); exit(2); } for (i = 0; i < nsig; i++) { s[i].fname = ifname; s[i].desc = NULL; s[i].units = NULL; s[i].gain = wgain; s[i].initval = 0; s[i].group = 0; s[i].fmt = (wres == 16) ? 16 : 80; s[i].spf = 1; s[i].bsize = 0; s[i].adcres = wres; s[i].adczero = (wres == 16) ? 0 : 128; s[i].baseline = s[i].adczero; s[i].nsamp = wnsamp; s[i].cksum = 0; wfdbsetstart(i, 44L); } setsampfreq(sps); if (setheader(record, s, nsig)) exit(4); /* Clean up. */ wfdbquit(); exit(0); }