/* file: m2a.c G. Moody 9 June 1983 Last revised: 27 September 1993 Convert MIT format annotation files to AHA DB distribution tape format Copyright (C) Massachusetts Institute of Technology 1993. All rights reserved. The files generated by this program are in the format formerly used for distribution of the AHA and MIT-BIH databases on half-inch 9-track digital tape. This program is provided as a convenience for those who may have software that requires files in AHA tape format as input. It does *not* generate files in the format currently used for distribution of the AHA database on floppy disk; program `a2m.c' can perform the reverse conversion, however. */ #include #ifndef __STDC__ #ifndef MSDOS extern void exit(); #endif #endif #include char *pname; main(argc, argv) int argc; char *argv[]; { char *ianame = NULL, *oaname = NULL, *record = NULL, *shift = NULL; char *prog_name(); int i; struct DB_anninfo afarray[2]; struct DB_ann annot; 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: input and output annotator names must follow -a\n", pname); exit(1); } ianame = argv[i++]; oaname = argv[i]; break; case 'h': /* help requested */ help(); exit(1); break; case 'r': /* record name follows */ if (++i >= argc) { (void)fprintf(stderr, "%s: record name must follow -r\n", pname); exit(1); } record = argv[i]; break; case 's': /* shift follows */ if (++i >= argc) { (void)fprintf(stderr, "%s: time shift must follow -s\n", pname); exit(1); } shift = 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); } } if (ianame == NULL || oaname == NULL || record == NULL) { help(); exit(1); } afarray[0].name = ianame; afarray[0].stat = READ; afarray[1].name = oaname; afarray[1].stat = AHA_WRITE; if (annopen(argv[1], afarray, 2) < 0) /* open files */ exit(2); if (shift == NULL) while (getann(0, &annot) >= 0) /* copy annotations to end of data */ (void)putann(0, &annot); else { long dt; double mssi; /* milliseconds per sample interval */ if (sampfreq(record) <= 0.) (void)setsampfreq(DEFFREQ); mssi = 1000./strtim("1"); dt = strtim(shift); while (getann(0, &annot) >= 0) if (annot.time >= dt) { annot.time = (annot.time - dt)*mssi; (void)putann(0, &annot); } } dbquit(); exit(0); /*NOTREACHED*/ } char *prog_name(s) char *s; { char *p = s + strlen(s); #ifdef MSDOS while (p >= s && *p != '\\' && *p != ':') { if (*p == '.') *p = '\0'; /* strip off extension */ if ('A' <= *p && *p <= 'Z') *p += 'a' - 'A'; /* convert to lower case */ p--; } #else while (p >= s && *p != '/') p--; #endif return (p+1); } static char *help_strings[] = { "usage: %s -r RECORD -a MIT-ANNOTATOR AHA-ANNOTATOR [ OPTIONS ... ]\n", "where RECORD is the record name, MIT-ANNOTATOR is the annotator name", "for the input annotation file, AHA-ANNOTATOR is the annotator name", "for the output (AHA format) annotation file, and OPTIONS may include:", " -h print this usage summary", " -s TIME shift annotation times backwards by the specified TIME,", " and convert them to milliseconds", NULL }; void help() { int i; (void)fprintf(stderr, help_strings[0], pname); for (i = 1; help_strings[i] != NULL; i++) (void)fprintf(stderr, "%s\n", help_strings[i]); }