program roundfile(input, output); (* roundfile: rounds off a file by droping incomplete last lines 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/ *) label 1; (* end of program *) const (* begin module version *) version = 1.03; (* of roundfile 2006 Dec 30 2006 Dec 30, 1.03: rename from 'round' to 'roundfile' 1988 Oct 12, 1.03: origin *) (* end module version *) (* begin module describe.roundfile *) (* name roundfile: rounds off a file by droping incomplete last lines synopsis roundfile(input: in, output: out) files input: a text file, possibly ending without a carriage return. output: the text file from input copied, but without the last line if that has no carriage return description Remove partial lines at the end of a file. For example, if a program is creating a xyin file, the file may be incomplete because of a partially written output buffer. But one may still want to graph it even thouth only part of a xyin line has been written. Since the xyplo program would object to a partial line, the roundfile program removes the incomplete line, allowing the graph to be created. see also xyplo.p author Thomas Dana Schneider bugs none known *) (* end module describe.roundfile *) (* begin module roundfile.const *) maxline = 500; (* maximum number of characters the program can handle *) (* end module roundfile.const *) (* begin module roundfile.themain *) procedure themain(var fin, fout: text); (* the main procedure of the program *) var line: array[1..maxline] of char; (* line of characters *) i: integer; (* index to the line *) characters: integer; (* position in the line, number of characters read *) begin characters := 0; repeat if eoln(fin) then begin readln(fin); if not eof(fin) then begin for i := 1 to characters do write(fout,line[i]); writeln(fout); end; characters := 0; end else begin characters := characters + 1; read(fin,line[characters]); end; until eof(fin) end; (* end module roundfile.themain *) begin themain(input, output); 1: end.