program diffintcut(input, diffintcutp, output); (* differences between integers with cutoff. 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 http://www.ccrnp.ncifcrf.gov/~toms/ *) label 1; (* end of program *) const (* begin module version *) version = 1.10; (* of diffintcut.p 2007 Nov 29 2007 Nov 29, 1.10: don't give program name to output 2007 Nov 29, 1.09: upgrade documentation 2007 Nov 29, 1.08: correct documentation 2007 Nov 29, 1.06: origin from diffint *) updateversion = 1.00; (* defines lowest acceptable current parameter file *) (* end module version *) (* begin module describe.diffintcut *) (* name diffintcut: differences between integers with cutoff synopsis diffintcut(input: in, diffintcutp: in, output: out); files input: a set of integers, one per line. Lines that begin with "*" are ignored - a comment line. diffintcutp: 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. colummn: an integer that defines which column (space delimiter) of the input file to use. lower upper: Two integers on one line These define the range of differences to report width: an integer that defines the width of output numbers output: first column: the difference between each integer and the previous one within (inclusive) the lower and upper. second column: previous integer in the file third column: current integer in the file describe Lines that begin with an asterisk ('*') are first copied to the output. then the difference between each integer in input and the previous one is given to the output. Data often comes separated into chunks and the user may want to control the chunks, so the program resets everytime there is a comment line in the input file. That is, at the beginning of the data the program cannot give a difference because there is no previous value. So the program only starts reporting differences for the second and later data items. If there is a comment, the program starts over and does not report the difference with the value before the comment line. If you do not want this behavior, then use the Unix command: `grep -v '*' file|diffintcut`. The grep -v will remove all lines that have '* in them in the file. documentation see also {example parameter file:} diffintcutp {Simpler (and probably faster) differences of integer program:} diffint.p author Thomas Dana Schneider bugs technical notes bugs none known *) (* end module describe.diffintcut *) var diffintcutp: text; (* file used by this program *) (* begin module halt *) procedure 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. *) begin writeln(output,' program halt.'); goto 1 end; (* end module halt version = 5.38; (@ of prgmod.p 2007 May 15 *) (* begin module skipblanks *) (* 2003 July 31: tab is considered a blank character *) function isblank(c: char): boolean; (* is the character c blank or tab? *) const tab = 9; (* tab character *) begin isblank := (c = ' ') or (ord(c) = tab) end; procedure skipblanks(var thefile: text); (* skip over blanks until a non-blank, or end of line, is found *) begin while isblank(thefile^) and not eoln(thefile) do get(thefile); end; procedure skipnonblanks(var thefile: text); (* skip over nonblanks until a blank, or end of line, is found *) begin while (not isblank(thefile^)) and not eoln(thefile) do get(thefile); end; procedure skipcolumn(var thefile: text); (* skip over a data column *) begin skipblanks(thefile); skipnonblanks(thefile) end; (* end module skipblanks version = 5.38; (@ of prgmod.p 2007 May 15 *) (* begin module diffintcut.themain *) procedure themain(var diffintcutp: text); (* the main procedure of the program *) const showparameters = false; (* show the parameters or not *) var current, previous: integer; (* two integers from the input file *) c: integer; (* the current column of the input we are on *) column: integer; (* column of input file to read *) difference: integer; (* difference between current and previous *) width: integer; (* width of numbers to report *) lower, upper: integer; (* range of differences to report *) haveprevious: boolean; (* do we have the previous value? *) parameterversion: real; (* parameter version number *) begin if showparameters then writeln(output,'* diffintcut ',version:4:2); reset(diffintcutp); readln(diffintcutp, parameterversion); if round(100*parameterversion) < round(100*updateversion) then begin writeln(output, 'You have an old parameter file!'); halt end; readln(diffintcutp, column); if column < 1 then begin writeln(output,'column (',column:1,') < 1'); halt; end; readln(diffintcutp, lower, upper); if lower > upper then begin writeln(output,'lower (',lower:1,') > upper (',upper:1,') '); halt; end; readln(diffintcutp, width); if width < 1 then begin writeln(output,'width (',width:1,') < 1'); halt; end; if showparameters then begin writeln(output,'* parameterversion: ', parameterversion:4:2); writeln(output,'* column: ', column:1); writeln(output,'* lower: ', lower:1); writeln(output,'* upper: ', upper:1); writeln(output,'* width: ', width:1); end; haveprevious := false; while not eof(input) do begin if input^='*' then begin (* copy lines beginning with '*' to output *) while not eoln(input) do begin write(output,input^); get(input); end; haveprevious := false; readln(input); writeln(output) end else begin c := 1; while c < column do begin skipcolumn(input); c := succ(c); end; readln(input, current); if haveprevious then begin difference := current-previous; if difference >= lower then begin if difference <= upper then begin writeln(output,current-previous:width, ' ',previous:width, ' ',current:width); end; end; end; haveprevious := true; previous := current; end; end; end; (* end module diffintcut.themain *) begin themain(diffintcutp); 1: end.