/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "derive.p" */ #include /* derive: compute the derivative curve for a xyin 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 (use only if first address fails) http://www.ccrnp.ncifcrf.gov/~toms/ */ /* end of program */ /* begin module version */ #define version 1.02 /* of derive.p 2007 Mar 13 2007 Mar 13, 1.02: upgrade documentation 2007 Jan 20, 1.01: mostly ready 2007 Jan 20, 1.00: origin */ #define updateversion 1.00 /* defines lowest acceptable current parameter file */ /* end module version */ /* begin module describe.derive */ /* name derive: compute the derivative curve for a xyin synopsis derive(xyin: in, derivep: in, dxyin: out, output: out) files xyin: input file for the xyplo program dxyin: derivative of log of values from the xyin derivep: 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. (Missing parameters to determine columns, defaults to 1 and 2 for x and y.) output: messages to the user description Compute the derivative of the curve by finding the differences of the y values divided by the differences of the x values. examples documentation see also {program for plotting xyin} xyplo.p author Thomas Dana Schneider bugs Only columns 1 and 2 can be used for now. The code for chosing arbitrary columns has not been written. technical notes */ /* end module describe.derive */ Static _TEXT xyin; /* file used by this program */ Static _TEXT derivep; /* file used by this program */ Static _TEXT dxyin; /* 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 = 5.31; (@ of prgmod.p 2006 Oct 10 */ /* begin module copyaline */ Static Void copyaline(fin, fout) _TEXT *fin, *fout; { /* copy a line from file fin to file fout */ while (!P_eoln(fin->f)) { putc(P_peek(fin->f), fout->f); getc(fin->f); } fscanf(fin->f, "%*[^\n]"); getc(fin->f); putc('\n', fout->f); } /* copyaline */ /* end module copyaline version = 5.31; (@ of prgmod.p 2006 Oct 10 */ /* begin module getcolumns */ Static Void getcolumns(xyin, column1, column2, x, y) _TEXT *xyin; long column1, column2; double *x, *y; { /* get the x and y values from the two designated columns. */ if (column1 != 1 && column2 != 2) { printf("COLUMNS NOT BEING READ PROPERLY YET\n"); halt(); } fscanf(xyin->f, "%lg%lg%*[^\n]", x, y); getc(xyin->f); } /* end module getcolumns */ /* begin module derive.themain */ Static Void themain(xyin, derivep, dxyin) _TEXT *xyin, *derivep, *dxyin; { /* the main procedure of the program */ double parameterversion; /* parameter version number */ long columnx = 1, columny = 2; /* columns to be read */ double x0, y0; /* previous values of the computation */ double x1, y1; /* current values of the computation */ double slope; /* computed slope */ boolean initializing = true; /* when to start computing */ long xwidth = 15, xdecimal = 13; /* characters for output */ long ywidth = 15, ydecimal = 13; /* characters for output */ long swidth = 15, sdecimal = 13; /* characters for output */ printf("derive %4.2f\n", version); if (*derivep->name != '\0') { if (derivep->f != NULL) derivep->f = freopen(derivep->name, "r", derivep->f); else derivep->f = fopen(derivep->name, "r"); } else rewind(derivep->f); if (derivep->f == NULL) { _EscIO2(FileNotFound, derivep->name); } RESETBUF(derivep->f, Char); fscanf(derivep->f, "%lg%*[^\n]", ¶meterversion); getc(derivep->f); if ((long)floor(100 * parameterversion + 0.5) < (long)floor(100.0 + 0.5)) { printf("You have an old parameter file!\n"); halt(); } 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); if (*dxyin->name != '\0') { if (dxyin->f != NULL) dxyin->f = freopen(dxyin->name, "w", dxyin->f); else dxyin->f = fopen(dxyin->name, "w"); } else { if (dxyin->f != NULL) rewind(dxyin->f); else dxyin->f = tmpfile(); } if (dxyin->f == NULL) _EscIO2(FileNotFound, dxyin->name); SETUPBUF(dxyin->f, Char); fprintf(dxyin->f, "* derive %4.2f\n", version); while (!BUFEOF(xyin->f)) { if (P_eoln(xyin->f)) { fscanf(xyin->f, "%*[^\n]"); getc(xyin->f); putc('\n', dxyin->f); continue; } if (P_peek(xyin->f) == '*') { copyaline(xyin, dxyin); continue; } if (initializing) { getcolumns(xyin, columnx, columny, &x0, &y0); /*writeln(output,'INITIALIZING');*/ /* writeln(output, x0:xwidth:xdecimal, ' ', y0:ywidth:ydecimal ); */ initializing = false; fprintf(dxyin->f, "\n* dxyin columns: x, y, slope\n"); continue; } /*writeln(output,'STEPPING');*/ getcolumns(xyin, columnx, columny, &x1, &y1); if (x1 - x0 == 0) { printf("x1 = x0 = %5.2f\n", x1); halt(); } /* slope := (y1 - y0)/(x1 - x0); */ slope = (log(y1) - log(y0)) / (log(x1) - log(x0)); fprintf(dxyin->f, "%*.*f %*.*f %*.*f\n", (int)xwidth, (int)xdecimal, x0, (int)ywidth, (int)ydecimal, y0, (int)swidth, (int)sdecimal, slope); /* step the variables forward for next time */ x0 = x1; y0 = y1; } } /* end module derive.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; dxyin.f = NULL; strcpy(dxyin.name, "dxyin"); derivep.f = NULL; strcpy(derivep.name, "derivep"); xyin.f = NULL; strcpy(xyin.name, "xyin"); themain(&xyin, &derivep, &dxyin); _L1: if (xyin.f != NULL) fclose(xyin.f); if (derivep.f != NULL) fclose(derivep.f); if (dxyin.f != NULL) fclose(dxyin.f); exit(EXIT_SUCCESS); } /* End. */