/* file: makeid.c G. Moody 19 July 1983 Last revised: 27 September 1993 Make an AHA-format ID block for a database record Copyright (C) Massachusetts Institute of Technology 1993. All rights reserved. Note: the record name and copyright message generated by this program are appropriate for the MIT/BIH database but not for other databases. */ #include #ifndef __STDC__ extern void exit(); #endif #include main(argc, argv) int argc; char *argv[]; { long ftell(), nsamp, first, last; int blocks, len, nann; static char nulls[299]; struct DB_anninfo afarray[1]; struct DB_siginfo dfarray[2]; struct DB_ann annot; extern void db_p16(), db_p32(); if (argc < 3) { (void)fprintf(stderr, "usage: %s annotator record\n", argv[0]); exit(1); } if ((len = strlen(argv[2])) > 5) { (void)fprintf(stderr, "record name must be 5 characters or less\n"); exit(1); } afarray[0].name = argv[1]; afarray[0].stat = READ; if (dbinit(argv[2], afarray, 1, dfarray, 2) < 1) exit(2); nsamp = dfarray[0].nsamp; (void)getann(0, &annot); first = annot.time; nann = 1; while (getann(0, &annot) >= 0) { last = annot.time; nann++; } dbquit(); /* Bytes 1-8: record ID (null-padded) */ (void)printf("MIT%s", argv[2]); (void)fwrite(nulls, 1, 5-len, stdout); (void)fprintf(stderr, "MIT%s\n", argv[2]); /* Bytes 9-10: number of annotations */ db_p16((unsigned)nann, stdout); (void)fprintf(stderr, "%d annotations\n", nann); /* Bytes 11-16: unused */ (void)fwrite(nulls, 1, 6, stdout); /* Bytes 17-20: time of first sample in the annotated segment of the record, relative to the beginning of the record */ db_p32(0L, stdout); (void)fprintf(stderr, "Annotated segment begins at sample 0\n"); /* Bytes 21-24: time of last sample in the annotated segment of the record, relative to the beginning of the record */ db_p32(nsamp, stdout); (void)fprintf(stderr, "Annotated segment ends at sample %ld\n", nsamp); /* Bytes 25-26: number of 512-byte logical blocks of sample data (nsamp * 2 bytes per sample * 2 channels / 512, rounded upward) */ blocks = (nsamp + 127) >> 7; db_p16((unsigned)blocks, stdout); (void)fprintf(stderr, "%d blocks of sample data\n", blocks); /* Bytes 27-32: unused */ (void)fwrite(nulls, 1, 6, stdout); /* Bytes 33-36: TOC of first annotation, relative to the beginning of the annotated segment */ db_p32(first, stdout); (void)fprintf(stderr, "First annotation is at sample %ld\n", first); /* Bytes 37-40: TOC of last annotation, relative to the beginning of the annotated segment */ db_p32(last, stdout); (void)fprintf(stderr, "Last annotation is at sample %ld\n", last); /* Bytes 41-42: number of 512-byte logical blocks of annotations (nann * 16 bytes per annotation / 512, rounded upward) */ blocks = (nann + 31) >> 5; db_p16((unsigned)blocks, stdout); (void)fprintf(stderr, "%d blocks of annotations\n", blocks); /* Bytes 43-48: unused */ (void)fwrite(nulls, 1, 6, stdout); /* Bytes 49-213: copyright notice */ (void)printf("COPYRIGHT (C) MASSACHUSETTS INSTITUTE OF TECHNOLOGY AND\r\n"); (void)printf("HARVARD UNIVERSITY, BIOMEDICAL ENGINEERING CENTER FOR\r\n"); (void)printf("CLINICAL INSTRUMENTATION, 1993.\r\n"); (void)printf("ALL RIGHTS RESERVED."); /* Bytes 214-512: unused */ (void)fwrite(nulls, 1, 299, stdout); exit(0); /*NOTREACHED*/ }