/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "cumulative.p" */ #include /* cumulative: cumulative probability distribution Tom Schneider NCI/FCRDC Bldg 469. Room 144 P.O. Box B Frederick, MD 21702-1201 (301) 846-5581 (-5532 for messages) network address: toms@ncifcrf.gov National Cancer Institute Laboratory of Mathematical Biology 1991 */ /* end of program */ /* begin module version */ #define version 1.08 Static jmp_buf _JL1; /* of cumulative.p 1991 September 16 origin 1991 Sep 16 */ /* end module version */ /* begin module describe.cumulative */ /* name cumulative: cumulative probability distribution synopsis cumulative(input: in, output: out) files input: input file output: input file with line numbers and cumulative probability at the start description Add line numbers to the input file along with cumulative probability. The input file should be sorted numerically first, for example with: cat myfile | sort -n -r | cumulative examples documentation see also number.p author Thomas Dana Schneider bugs technical notes The technical problem of number.p was solved here by first copying to an internal file. */ /* end module describe.cumulative */ /* 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.11; (@ of prgmod.p 1991 Apr 22 */ /* 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 */ #define decimals 5 /* that should be sufficient for most files! */ #define width 10 /* width of number for probabilities */ /* end module copyaline version = 4.11; (@ of prgmod.p 1991 Apr 22 */ /* begin module cumulative.themain */ Static Void themain(fin, fout) _TEXT *fin, *fout; { /* the main procedure of the program */ long count = 0; /* count of the lines processed so far */ _TEXT hold; /* internal holding file */ long lines = 0; /* total count of the lines */ /* decimals: integer; (* decimal places to express the value of lines in *) */ /* this is crazy. the extra reset prevents this from being used in pipes. (* determine number of lines in the file *) lines := -1; (* don't count the line that has the eof on it! *) reset(fin); while not eof(fin) do begin lines := lines + 1; readln(fin) end; if lines > 0 then begin (* determine how many decimal places to put out for line numbers *) decimals := trunc(ln(lines)/ln(10))+1; (* copy the file *) reset(fin); for count := 1 to lines do begin write(fout,count:decimals,' '); copyaline(fin,fout) end; end; reset(fin); */ hold.f = NULL; *hold.name = '\0'; if (*hold.name != '\0') { if (hold.f != NULL) hold.f = freopen(hold.name, "w", hold.f); else hold.f = fopen(hold.name, "w"); } else { if (hold.f != NULL) { /* the strategy is that it would be nice to use this program in a pipe, which means that it cannot reset the input file. The (possible) solution is to copy the file to an internal file while counting the lines and then to spit that to the output. */ /* First copy to the internal file while counting */ rewind(hold.f); } else hold.f = tmpfile(); } if (hold.f == NULL) _EscIO2(FileNotFound, hold.name); SETUPBUF(hold.f, Char); while (!BUFEOF(fin->f)) { lines++; copyaline(fin, &hold); } if (*hold.name != '\0') { if (hold.f != NULL) hold.f = freopen(hold.name, "r", hold.f); else hold.f = fopen(hold.name, "r"); } else rewind(hold.f); if (hold.f == NULL) _EscIO2(FileNotFound, hold.name); RESETBUF(hold.f, Char); /* that's allowed because it is not in the pipe! */ while (!BUFEOF(hold.f)) { count++; /* ie the probability */ fprintf(fout->f, "%*ld %*.*f ", width, count, width, decimals, (double)count / lines); copyaline(&hold, fout); } if (hold.f != NULL) fclose(hold.f); } #undef decimals #undef width /* end module cumulative.themain */ main(argc, argv) int argc; Char *argv[]; { _TEXT TEMP, TEMP1; PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; TEMP.f = stdin; *TEMP.name = '\0'; TEMP1.f = stdout; *TEMP1.name = '\0'; themain(&TEMP, &TEMP1); _L1: exit(EXIT_SUCCESS); } /* End. */