// filename: get_ecg_annotation.c // copyright Massachusetts Institute of Technology // author: Matt Oefinger #include #include #include char DB_PATH[] = "http://physionet.org/physiobank/database"; char ABSOLUTE_PATH[150]; char RECORD_ID[50]; WFDB_Time string2int(char* digit); int string2int_2(char *digit); WFDB_Time string2int(char* digit) { WFDB_Time result = 0; //--- Convert each digit char and add into result. while (*digit >= '0' && *digit <='9') { result = (result * 10) + (*digit - '0'); digit++; } //--- Check that there were no non-digits at end. if (*digit != 0) { return 0; } return result; } int string2int_2(char* digit) { int result = 0; //--- Convert each digit char and add into result. while (*digit >= '0' && *digit <='9') { result = (result * 10) + (*digit - '0'); digit++; } //--- Check that there were no non-digits at end. if (*digit != 0) { return 0; } return result; } main(int argc, char* argv[]) { int i, j, nsig, nsamples, screenwidth, CMDcode, found, start_time_offset; WFDB_Siginfo *siarray; WFDB_Sample *v; WFDB_Time start_t_index, abstime, tmptime; WFDB_Anninfo a; WFDB_Annotation annot; char annotator[50]; char desiredannot[2]; char annotvalue[2]; char first; char second; found = 0; start_t_index = string2int(argv[3]); screenwidth = string2int_2(argv[4]); start_time_offset = (start_t_index + screenwidth); CMDcode = string2int_2(argv[5]); sprintf(annotator,argv[6]); sprintf(desiredannot,argv[7]); sprintf(ABSOLUTE_PATH,"%s/%s",DB_PATH,argv[1]); setwfdb(ABSOLUTE_PATH); switch(CMDcode) { //This case is a carry over from get_ecg_waveform.c, not used here case 0: nsig = isigopen(argv[2], NULL, 0); if (nsig < 1) exit(1); siarray = (WFDB_Siginfo *)malloc(nsig * sizeof(WFDB_Siginfo)); nsig = isigopen(argv[2], siarray, nsig); v = (WFDB_Sample *)malloc(nsig * sizeof(WFDB_Sample)); if(isigsettime(start_t_index) != 0) exit(1); for(j=0; j < screenwidth; j++) { if(getvec(v) <= 0) exit(1); else { for(i=0; i start_t_index)) if((first == second) && (annot.time > start_time_offset)) { //abstime = annot.time; abstime = (annot.time - (screenwidth/2)); printf("%d\n", abstime); found = 1; break; } } if(found == 0){ printf("none"); } break; case 2: first = desiredannot[0]; a.name = annotator; a.stat = WFDB_READ; if (annopen(argv[2], &a, 1) < 0) exit(1); if(iannsettime(0) != 0) exit(1); tmptime = 0; while(getann(0, &annot) == 0 ) { sprintf(annotvalue, annstr(annot.anntyp)); second = annotvalue[0]; if((first == second) && (annot.time < start_t_index)) { tmptime = annot.time; found = 1; } } if(found == 0){ printf("none"); } else if (found == 1){ if((tmptime-(screenwidth/2)) < 0) tmptime = 0; else tmptime = (tmptime - (screenwidth/2)); printf("%d\n", tmptime); } break; //get the number of samples in the file case 3: nsig = isigopen(argv[2], NULL, 0); if (nsig < 1) exit(1); siarray = (WFDB_Siginfo *)malloc(nsig * sizeof(WFDB_Siginfo)); nsig = isigopen(argv[2], siarray, nsig); v = (WFDB_Sample *)malloc(nsig * sizeof(WFDB_Sample)); if(isigsettime(start_t_index) != 0) exit(1); //for(;;) // { // if(getvec(v) <= 0){ // abstime = start_t_index; // break; // } // else { // start_t_index++; // isigsettime(start_t_index); // } // } //abstime = 0; nsamples = 0; for( i = 0; i < nsig; i++){ if(nsamples < siarray[i].nsamp){ nsamples = siarray[i].nsamp; } } //printf("%d\n", abstime-screenwidth/2); printf("%d\n", nsamples-screenwidth/2); break; //first = desiredannot[0]; //a.name = annotator; a.stat = WFDB_READ; //if (annopen(argv[2], &a, 1) < 0) // exit(1); //if(iannsettime(0) != 0) // exit(1); //while (getann(0, &annot) == 0) // { //sprintf(annotvalue, annstr(annot.anntyp)); //second = annotvalue[0]; //printf("%c\n", first); // printf("%c\n", second); // break; // if((first == second) && (annot.time > start_t_index)) //if((first == second) && (annot.time > start_time_offset)) // { //abstime = annot.time; //abstime = (annot.time - (screenwidth/2)); // printf("%d\n", abstime); //found = 1; // break; // } // abstime = annot.time; // } //abstime = start_t_index; //while(isigsettime(abstime)==0) // { // abstime += 127231; // } //printf("%d\n", abstime); //break; default: exit(1); break; } wfdbquit(); exit(0); }