/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "derivative.p" */ #include /* derivative: take the derivative of x versus y in xyin Tom Schneider NCI/FCRDC Bldg 469. Room 144 P.O. Box B Frederick, MD 21702-1201 (301) 846-5581 (-5532 for messages) permanent email: toms@alum.mit.edu toms@ncifcrf.gov http://www.lecb.ncifcrf.gov/~toms/ National Cancer Institute Laboratory of Experimental and Computational Biology */ /* end of program */ /* begin module version */ #define version 1.03 /* of derivative.p 1999 September 24 origin 1999 Sep 24 */ #define updateversion 1.00 /* defines lowest acceptable current parameter file */ /* end module version */ /* begin module describe.derivative */ /* name derivative: take the derivative of x versus y in xyin synopsis derivative(xyin: in, derivativep: in, data: out, output: out) files xyin: a data file consisting of two columns, the first is called x and the second is y. Comment lines can begin with "*", and empty lines are allowed. output columns are: 1: slope 2: x 3: y 4: trigger value (see trigger parameter) data: output of this program, a single data file. The file may be passed to genhis for plotting. derivativep: 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. outwid, outdec: two integers that determine the width in characters of output numbers and their number of decimal places. scale: if the first character is 'l' then it is a log-log scale and log base 2 will be take of both x and y before computing the slope. trigger: when the slope is below the trigger, the trigger value in xyin will be 0, otherwise it will be 1. output: messages to the user description Two data columns in the xyin file are read as x and y. The difference between each x value and its previous one is deltax. The difference between each y value and its previous one is deltay. The computed slope is deltay/deltax. The program will halt if deltax is zero. examples documentation see also genhis.p, derivativep author Thomas Dana Schneider bugs technical notes */ /* end module describe.derivative */ Static _TEXT xyin; /* file used by this program */ Static _TEXT derivativep; /* file used by this program */ Static _TEXT data; /* 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); } /* end module halt version = 'delmod 6.16 84 mar 12 tds/gds'; */ /* begin module getxy */ Static Void getxy(xyin, x, y, gotten) _TEXT *xyin; double *x, *y; boolean *gotten; { /* get two numbers, x and y from the xyin file. If end of file was found, gotten is true, otherwise false. */ boolean done = false; /* done searching for the data? */ /*writeln(output,'in getxy');*/ *gotten = false; /* so pesimistic! */ while (!done) { if (BUFEOF(xyin->f)) { done = true; break; } if (P_eoln(xyin->f)) { fscanf(xyin->f, "%*[^\n]"); getc(xyin->f); continue; } if (P_peek(xyin->f) == '*') { fscanf(xyin->f, "%*[^\n]"); getc(xyin->f); } else { fscanf(xyin->f, "%lg%lg%*[^\n]", x, y); getc(xyin->f); *gotten = true; done = true; /* write (output,'x = ',x:1:1); write (output,' y = ',y:1:1); writeln(output); */ } } } /* Local variables for themain: */ struct LOC_themain { double ln2; /* ln(2) */ } ; Local double log2(x, LINK) double x; struct LOC_themain *LINK; { /* compute log base 2 of x */ return (log(x) / LINK->ln2); } /* log2 */ /* end module getxy */ /* begin module derivative.themain */ Static Void themain(xyin, derivativep, data) _TEXT *xyin, *derivativep, *data; { /* the main procedure of the program */ struct LOC_themain V; double deltax; /* change in x */ double deltay; /* change in y */ boolean gotten; /* have we gotten new data? */ double parameterversion; /* parameter version number */ long outwid; /* output width in places */ long outdec; /* output decimal places */ double previousx; /* previous value of x */ double previousy; /* previous value of y */ Char scale; /* l means log-log scale */ double slope; /* slope of curve */ double trigger; /* trigger value */ double x; /* current x */ double y; /* current y */ printf("derivative %4.2f\n", version); if (*derivativep->name != '\0') { if (derivativep->f != NULL) derivativep->f = freopen(derivativep->name, "r", derivativep->f); else derivativep->f = fopen(derivativep->name, "r"); } else rewind(derivativep->f); if (derivativep->f == NULL) _EscIO2(FileNotFound, derivativep->name); RESETBUF(derivativep->f, Char); fscanf(derivativep->f, "%lg%*[^\n]", ¶meterversion); getc(derivativep->f); if (parameterversion < updateversion) { printf("You have an old parameter file!\n"); halt(); } fscanf(derivativep->f, "%ld%ld%*[^\n]", &outwid, &outdec); getc(derivativep->f); fscanf(derivativep->f, "%c%*[^\n]", &scale); getc(derivativep->f); if (scale == '\n') scale = ' '; fscanf(derivativep->f, "%lg%*[^\n]", &trigger); getc(derivativep->f); if (*data->name != '\0') { if (data->f != NULL) data->f = freopen(data->name, "w", data->f); else data->f = fopen(data->name, "w"); } else { if (data->f != NULL) rewind(data->f); else data->f = tmpfile(); } if (data->f == NULL) _EscIO2(FileNotFound, data->name); SETUPBUF(data->f, Char); fprintf(data->f, "* derivative %4.2f\n", version); V.ln2 = log(2.0); if (*xyin->name != '\0') { if (xyin->f != NULL) xyin->f = freopen(xyin->name, "r", xyin->f); else xyin->f = fopen(xyin->name, "r"); } else rewind(xyin->f); if (xyin->f == NULL) _EscIO2(FileNotFound, xyin->name); RESETBUF(xyin->f, Char); getxy(xyin, &previousx, &previousy, &gotten); if (!gotten) { printf("NO DATA\n"); halt(); } while (!BUFEOF(xyin->f)) { getxy(xyin, &x, &y, &gotten); if (!gotten) continue; if (scale == 'l') { deltax = log2(x, &V) - log2(previousx, &V); deltay = log2(y, &V) - log2(previousy, &V); } else { deltax = x - previousx; deltay = y - previousy; } if (deltax == 0) { printf("DIVISION BY ZERO\n"); printf("DIVISION BY ZERO\n"); printf("x = %1.1f", x); printf("previousx = %1.1f\n", previousx); halt(); } slope = deltay / deltax; fprintf(data->f, "%*.*f", (int)outwid, (int)outdec, slope); fprintf(data->f, " %*.*f", (int)outwid, (int)outdec, x); fprintf(data->f, " %*.*f", (int)outwid, (int)outdec, y); if (slope < trigger) fprintf(data->f, " 0"); else fprintf(data->f, " 1"); putc('\n', data->f); previousx = x; previousy = y; } } /* end module derivative.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; data.f = NULL; strcpy(data.name, "data"); derivativep.f = NULL; strcpy(derivativep.name, "derivativep"); xyin.f = NULL; strcpy(xyin.name, "xyin"); themain(&xyin, &derivativep, &data); _L1: if (xyin.f != NULL) fclose(xyin.f); if (derivativep.f != NULL) fclose(derivativep.f); if (data.f != NULL) fclose(data.f); exit(EXIT_SUCCESS); } /* End. */