/* interval.c Compile with: gcc -g interval.c -lm -o interval Example run: interval hs2_DEVIATION.l6 13 Given a "DEVIATION" file (infocon false positives & false negatives data) and the number of characters in the denomination of the runs preceding the length indicator, it outputs the intervals [start,end] of invariance for the anchor, with the following format: start end #fp #fn #fn+#fp Example: The denomination 'infocon.hs2.l4.a0.266.list' in the DEVIATION file specifies an infocon run for the hs2 region with the parameter values 4 for minimum length of reported region, and 0.226 for the fixed anchor, respectively. The distance for the file is then 13 (strlen("infocon.hs2.l")). */ #include #include #include #include #include #include #define EPSILON 0.001 #define Usage "%s " void fatal(char *message); void fatalf(char *msg, char *val); FILE *ckopen(char *name, char *mode); double get_anchor(char *, int); int main(int argc, char *argv[]) { char buffer[200], key[50], *s; double anchor, panchor; int i, min, fp, fn, pfp, pfn, count; double From[1000], To[1000]; int FP[1000], FN[1000]; FILE *file; if (argc!=3) fatalf(Usage, argv[0]); file = ckopen(argv[1],"r"); min = 100000; pfp = pfn = -1; count = -1; panchor = -1; while (fgets(buffer,200,file)!=NULL) { if (buffer[0]=='#') continue; s = buffer; i = 0; while (!isspace(*s)) { key[i] = *s; s++; i++; } key[i] = '\0'; anchor = get_anchor(key,atoi(argv[2])); while (isspace(*s)) s++; /* go past blanks */ while (!isspace(*s)) s++; /* go past fp: label */ while (isspace(*s)) s++; /* go past blanks */ fp = 0; while (isdigit(*s)) { /* go past fp values */ fp = fp*10 + *s-'0'; s++; } while (isspace(*s)) s++; /* go past blanks */ while (!isspace(*s)) s++; /* go past fn: label */ while (isspace(*s)) s++; /* go past blanks */ fn = 0; while (isdigit(*s)) { /* go past fn values */ fn = fn*10 + *s-'0'; s++; } if ((fn!=pfn) || (fp!=pfp)) { /* new interval */ if (count>=0) To[count] = anchor-EPSILON; From[++count] = anchor; To[count] = anchor; FP[count] = fp; FN[count] = fn; pfp = fp; pfn = fn; } else { /* same interval */ To[count] = anchor; } } fclose(file); /* print out the values */ for (i= count; i>=0; i--) printf("%-3.3f %-3.3f %-3d %-3d %3d\n", From[count-i], To[count-i], FP[count-i], FN[count-i], FP[count-i]+FN[count-i]); return 0; } void fatal(char *msg) { (void)fprintf(stderr, "%s\n", msg); exit(1); } void fatalf(char *msg, char *val) { (void)fprintf(stderr, msg, val); (void)putc('\n', stderr); exit(1); } FILE *ckopen(char *name, char *mode) { FILE *fp; if ((fp = fopen(name, mode)) == NULL) fatalf("Cannot open %s.", name); return fp; } /* prune key */ double get_anchor(char *key, int chars_to_len) { int anchor = 0, value, decs, sign = 1; double rval; char *s; s = key; s = s+chars_to_len; /* strlen("infocon.beta.l"); */ while (isdigit(*s)) s++; /* go past length */ *s++ = '\0'; /* go past '.'; prune here */ s++; /* go past 'a' */ if (*s=='-') { sign = -1; s++; } value = 0; while (isdigit(*s)) { value = value*10+*s-'0'; s++; } s++; /* replace '.' and skip it */ decs = 0; while (isdigit(*s)) { value = value*10+*s-'0'; s++; decs++; } rval = value; while (--decs>=0) rval = rval/10; return sign*rval; }