/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "camplo.p" */ #include /* camplo: camspec plot Tom Schneider NCI/FCRDC Bldg 469. Room 144 P.O. Box B Frederick, MD 21702-1201 (301) 846-5581 (-5532 for messages) toms@ncifcrf.gov http://www-lmmb.ncifcrf.gov/~toms/ National Cancer Institute Laboratory of Mathematical Biology */ /* end of program */ /* begin module version */ #define version 1.02 /* of camplo.p 1996 March 19 origin 1996 March 18 */ /* end module version */ /* begin module describe.camplo */ /* name camplo: camspec plot synopsis camplo(baseline, sample: in, xyin: out, output: out) files baseline: baseline spectrum sample: sample spectrum xyin: difference between baseline and sample as input to xyplo output: messages to the user description Convert camspec output to plotting format. examples documentation see also xyplo.p author Thomas Dana Schneider bugs technical notes */ /* end module describe.camplo */ /* begin module camplo.const */ #define nmwid 5 /* width of nm data output */ #define nmdec 1 /* decimal places of nm data output */ #define odwid 7 /* width of od data output */ #define oddec 3 /* decimal places of od data output */ /* end module camplo.const */ Static _TEXT baseline, sample; /* file used by this program */ Static _TEXT xyin; /* 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 = 4.15; (@ of prgmod.p 1994 November 12 */ /* 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 = 4.15; (@ of prgmod.p 1994 November 12 */ /* begin module camplo.number */ Static boolean number(thefile) _TEXT *thefile; { /* does thefile contain a number next? */ return (P_peek(thefile->f) == '9' || P_peek(thefile->f) == '8' || P_peek(thefile->f) == '7' || P_peek(thefile->f) == '6' || P_peek(thefile->f) == '5' || P_peek(thefile->f) == '4' || P_peek(thefile->f) == '3' || P_peek(thefile->f) == '2' || P_peek(thefile->f) == '1' || P_peek(thefile->f) == '0'); } /* end module camplo.number */ /* begin module camplo.copyheader */ Static Void copyheader(infile, outfile) _TEXT *infile, *outfile; { /* does thefile contain a number next? */ while (!number(infile)) { fprintf(outfile->f, "* "); copyaline(infile, outfile); } } /* end module camplo.copyheader */ /* begin module camplo.checkcomma */ Static Void checkcomma(f) _TEXT *f; { /* check that the file f contained a comma next */ Char c; /* a character to read from the files */ c = getc(f->f); if (c == '\n') c = ' '; if (c != ',') { printf("\",\" missing, character was %c\"\n", c); halt(); } } /* end module camplo.checkcomma */ /* begin module camplo.themain */ Static Void themain(baseline, sample, xyin) _TEXT *baseline, *sample, *xyin; { /* the main procedure of the program */ double absorbance; /* od for sample vs baseline */ double nmbaseline; /* nm for baseline */ double nmsample; /* nm for sample */ double ln10 = log(10.0); /* natural log of 10 */ double Tbaseline; /* % Transmittance for baseline */ double Tsample; /* % Transmittance for sample */ printf("camplo %4.2f\n", version); if (*baseline->name != '\0') { if (baseline->f != NULL) baseline->f = freopen(baseline->name, "r", baseline->f); else baseline->f = fopen(baseline->name, "r"); } else rewind(baseline->f); if (baseline->f == NULL) _EscIO2(FileNotFound, baseline->name); RESETBUF(baseline->f, Char); if (*sample->name != '\0') { if (sample->f != NULL) sample->f = freopen(sample->name, "r", sample->f); else sample->f = fopen(sample->name, "r"); } else rewind(sample->f); if (sample->f == NULL) _EscIO2(FileNotFound, sample->name); RESETBUF(sample->f, Char); if (*xyin->name != '\0') { if (xyin->f != NULL) xyin->f = freopen(xyin->name, "w", xyin->f); else xyin->f = fopen(xyin->name, "w"); } else { if (xyin->f != NULL) rewind(xyin->f); else xyin->f = tmpfile(); } if (xyin->f == NULL) _EscIO2(FileNotFound, xyin->name); SETUPBUF(xyin->f, Char); fprintf(xyin->f, "* camplo %4.2f\n", version); /* copy headers */ fprintf(xyin->f, "*\n"); fprintf(xyin->f, "* baseline header:\n"); copyheader(baseline, xyin); fprintf(xyin->f, "*\n"); fprintf(xyin->f, "* sample header:\n"); copyheader(sample, xyin); fprintf(xyin->f, "*\n"); fprintf(xyin->f, "* columns:\n"); fprintf(xyin->f, "* 1: identifier (b=%%T for baseline, s=%%T for sample,\n"); fprintf(xyin->f, "* a=absorbance = -log10(sample/baseline)\n"); fprintf(xyin->f, "* 2: wavelength in nm\n"); fprintf(xyin->f, "* 3: od, optical density\n"); fprintf(xyin->f, "*\n"); while (!BUFEOF(baseline->f)) { if (!number(baseline)) { fscanf(baseline->f, "%*[^\n]"); getc(baseline->f); continue; } fscanf(baseline->f, "%lg", &nmbaseline); checkcomma(baseline); fscanf(baseline->f, "%lg%*[^\n]", &Tbaseline); getc(baseline->f); fscanf(sample->f, "%lg", &nmsample); checkcomma(sample); fscanf(sample->f, "%lg%*[^\n]", &Tsample); getc(sample->f); /* writeln(xyin,'b ', nmbaseline:nmwid:nmdec,' ',Tbaseline:odwid:oddec); writeln(xyin,'s ', nmsample:nmwid:nmdec ,' ', Tsample:odwid:oddec); */ if (nmbaseline != nmsample) { printf("nm of baseline (%*.*f)\n", nmwid, nmdec, nmbaseline); printf("does not equal\n"); printf("nm of sample (%*.*f)\n", nmwid, nmdec, nmsample); halt(); } absorbance = -(log(Tsample / Tbaseline) / ln10); fprintf(xyin->f, "d %*.*f %*.*f\n", nmwid, nmdec, nmbaseline, odwid, oddec, absorbance); } } /* end module camplo.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; xyin.f = NULL; strcpy(xyin.name, "xyin"); sample.f = NULL; strcpy(sample.name, "sample"); baseline.f = NULL; strcpy(baseline.name, "baseline"); themain(&baseline, &sample, &xyin); _L1: if (baseline.f != NULL) fclose(baseline.f); if (sample.f != NULL) fclose(sample.f); if (xyin.f != NULL) fclose(xyin.f); exit(EXIT_SUCCESS); } /* End. */