program diffint(input,output); (* differences between integers. 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/ *) const (* begin module version *) version = 1.07; (* of diffint.p 2007 Nov 29 2007 Nov 29, 1.07: rename difint as diffint 2007 Nov 28, 1.06: rename difint as diffint 1996 Oct 24, 1.05: functional 1986 dec 2, 1.00: origin *) (* end module version *) (* begin module describe.diffint *) (* name diffint: differences between integers synopsis diffint(input: in, output: out); files input: a set of integers, one per line. Lines that begin with "*" are ignored. output: the difference between each integer and the previous one. 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. documentation see also {Program that allows selection of columns and ranges of differences to be selected:} diffintcut.p author Thomas Dana Schneider bugs technical notes The program originally acted as if the integer before the first one is zero, but this creates artifacts. The initial data point is now dropped. However, data often comes separate into chunks. This is marked by the comments. So the program resets everytime there is a comment line. The name was changed to diffint (from difint) because that's closer to the Unix diff command. bugs none known *) (* end module describe.diffint *) var current, previous: integer; (* two integers from the input file *) haveprevious: boolean; (* do we have the previous value? *) begin 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 readln(input, current); if haveprevious then writeln(output,current-previous:10); haveprevious := true; previous := current; end; end end.