program doudiff(input,output); (* double differences between integers. Dr. Thomas D. Schneider National Cancer Institute Laboratory of Experimental and Computational Biology Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.lecb.ncifcrf.gov/~toms/ *) const (* begin module version *) version = 1.00; (* of doudiff.p 2003 Aug 24 2003 Aug 24, 1.00, origin from difint *) (* end module version *) (* begin module describe.doudiff *) (* name doudiff: double differences between integers synopsis doudiff(input: in, output: out); files input: a set of integers, one per line. Lines that begin with "*" are ignored. output: Two integers are written per line: the difference between each integer and the previous one. the difference between each integer and the one before 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 along with the double distance difference is given to the output. author Thomas Dana Schneider technical notes The initial data points cannot be used. Data often comes separate into chunks. This is marked by the comments. So the program resets everytime there is a comment line. bugs none known *) (* end module describe.doudiff *) var current, previous: integer; (* two integers from the input file *) haveprevious: boolean; (* do we have the previous value? *) PREprevious: integer; (* three integers from the input file *) havePREprevious: boolean; (* do we have the PREprevious value? *) begin haveprevious := false; havePREprevious := 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; (* this resets at the '*' comments *) havePREprevious := false; (* this resets at the '*' comments *) readln(input); writeln(output) end else begin readln(input, current); { if haveprevious then writeln(output,current-previous:10); } if havePREprevious then begin writeln(output,current-previous:1, ' ',current-PREprevious:1); end; (* for the next data point: *) if haveprevious then begin havePREprevious := true; PREprevious := previous; end; haveprevious := true; previous := current; end; end end.