/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "diffintcut.p" */ #include /* differences between integers with cutoff. Dr. Thomas D. Schneider National Institutes of Health National Cancer Institute Center for Cancer Research Nanobiology Program Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu http://www.ccrnp.ncifcrf.gov/~toms/ */ /* end of program */ /* begin module version */ #define version 1.10 /* of diffintcut.p 2007 Nov 29 2007 Nov 29, 1.10: don't give program name to output 2007 Nov 29, 1.09: upgrade documentation 2007 Nov 29, 1.08: correct documentation 2007 Nov 29, 1.06: origin from diffint */ #define updateversion 1.00 /* defines lowest acceptable current parameter file */ /* end module version */ /* begin module describe.diffintcut */ /* name diffintcut: differences between integers with cutoff synopsis diffintcut(input: in, diffintcutp: in, output: out); files input: a set of integers, one per line. Lines that begin with "*" are ignored - a comment line. diffintcutp: parameters to control the program. The file must contain the following parameters, one per line: parameterversion: The version number of the program. This allows the user to be warned if an old parameter file is used. colummn: an integer that defines which column (space delimiter) of the input file to use. lower upper: Two integers on one line These define the range of differences to report width: an integer that defines the width of output numbers output: first column: the difference between each integer and the previous one within (inclusive) the lower and upper. second column: previous integer in the file third column: current integer in the file describe Lines that begin with an asterisk ('*') are first copied to the output. then the difference between each integer in input and the previous one is given to the output. Data often comes separated into chunks and the user may want to control the chunks, so the program resets everytime there is a comment line in the input file. That is, at the beginning of the data the program cannot give a difference because there is no previous value. So the program only starts reporting differences for the second and later data items. If there is a comment, the program starts over and does not report the difference with the value before the comment line. If you do not want this behavior, then use the Unix command: `grep -v '*' file|diffintcut`. The grep -v will remove all lines that have '* in them in the file. documentation see also {example parameter file:} diffintcutp {Simpler (and probably faster) differences of integer program:} diffint.p author Thomas Dana Schneider bugs technical notes bugs none known */ /* end module describe.diffintcut */ Static _TEXT diffintcutp; /* file used by this program */ Static jmp_buf _JL1; /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } #define tab 9 /* tab character */ /* end module halt version = 5.38; (@ of prgmod.p 2007 May 15 */ /* begin module skipblanks */ /* 2003 July 31: tab is considered a blank character */ Static boolean isblank(c) Char c; { /* is the character c blank or tab? */ return (c == ' ' || c == tab); } #undef tab Static Void skipblanks(thefile) _TEXT *thefile; { /* skip over blanks until a non-blank, or end of line, is found */ while (isblank(P_peek(thefile->f)) & (!P_eoln(thefile->f))) getc(thefile->f); } Static Void skipnonblanks(thefile) _TEXT *thefile; { /* skip over nonblanks until a blank, or end of line, is found */ while ((!isblank(P_peek(thefile->f))) & (!P_eoln(thefile->f))) getc(thefile->f); } Static Void skipcolumn(thefile) _TEXT *thefile; { /* skip over a data column */ skipblanks(thefile); skipnonblanks(thefile); } #define showparameters false /* show the parameters or not */ /* end module skipblanks version = 5.38; (@ of prgmod.p 2007 May 15 */ /* begin module diffintcut.themain */ Static Void themain(diffintcutp) _TEXT *diffintcutp; { /* the main procedure of the program */ long current, previous; /* two integers from the input file */ long c; /* the current column of the input we are on */ long column; /* column of input file to read */ long difference; /* difference between current and previous */ long width; /* width of numbers to report */ long lower, upper; /* range of differences to report */ boolean haveprevious = false; /* do we have the previous value? */ double parameterversion; /* parameter version number */ _TEXT TEMP; if (showparameters) printf("* diffintcut %4.2f\n", version); if (*diffintcutp->name != '\0') { if (diffintcutp->f != NULL) diffintcutp->f = freopen(diffintcutp->name, "r", diffintcutp->f); else diffintcutp->f = fopen(diffintcutp->name, "r"); } else rewind(diffintcutp->f); if (diffintcutp->f == NULL) _EscIO2(FileNotFound, diffintcutp->name); RESETBUF(diffintcutp->f, Char); fscanf(diffintcutp->f, "%lg%*[^\n]", ¶meterversion); getc(diffintcutp->f); if ((long)floor(100 * parameterversion + 0.5) < (long)floor(100.0 + 0.5)) { printf("You have an old parameter file!\n"); halt(); } fscanf(diffintcutp->f, "%ld%*[^\n]", &column); getc(diffintcutp->f); if (column < 1) { printf("column (%ld) < 1\n", column); halt(); } fscanf(diffintcutp->f, "%ld%ld%*[^\n]", &lower, &upper); getc(diffintcutp->f); if (lower > upper) { printf("lower (%ld) > upper (%ld) \n", lower, upper); halt(); } fscanf(diffintcutp->f, "%ld%*[^\n]", &width); getc(diffintcutp->f); if (width < 1) { printf("width (%ld) < 1\n", width); halt(); } if (showparameters) { printf("* parameterversion: %4.2f\n", parameterversion); printf("* column: %ld\n", column); printf("* lower: %ld\n", lower); printf("* upper: %ld\n", upper); printf("* width: %ld\n", width); } while (!P_eof(stdin)) { if (P_peek(stdin) == '*') { /* copy lines beginning with '*' to output */ while (!P_eoln(stdin)) { putchar(P_peek(stdin)); getc(stdin); } haveprevious = false; scanf("%*[^\n]"); getchar(); putchar('\n'); continue; } c = 1; while (c < column) { TEMP.f = stdin; *TEMP.name = '\0'; skipcolumn(&TEMP); c++; } scanf("%ld%*[^\n]", ¤t); getchar(); if (haveprevious) { difference = current - previous; if (difference >= lower) { if (difference <= upper) printf("%*ld %*ld %*ld\n", (int)width, current - previous, (int)width, previous, (int)width, current); } } haveprevious = true; previous = current; } } #undef showparameters /* end module diffintcut.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; diffintcutp.f = NULL; strcpy(diffintcutp.name, "diffintcutp"); themain(&diffintcutp); _L1: if (diffintcutp.f != NULL) fclose(diffintcutp.f); exit(EXIT_SUCCESS); } /* End. */