program logav(data, logavp, logavreport, output); (* logav: log average 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 schneidt@mail.nih.gov permanent email: toms@alum.mit.edu http://www.ccrnp.ncifcrf.gov/~toms/ *) label 1; (* end of program *) const (* begin module version *) version = 1.01; (* of logav.p 2009 Apr 15 2009 Apr 15, 1.01: parameter to adjust lengths 2009 Apr 08, 1.00: origin *) updateversion = 1.00; (* defines lowest acceptable current parameter file *) (* end module version *) (* begin module describe.logav *) (* name logav: log average synopsis logav(data: in, logavp: in, logavreport: out, output: out) files data: numbers, one per line logavreport: report logavp: 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. shift(integer): This number is subtracted from each input value before computing the log. output: messages to the user description Compute the average of the log of a set of numbers. examples documentation see also author Thomas Dana Schneider bugs technical notes *) (* end module describe.logav *) var data, (* file used by this program *) logavp, (* file used by this program *) logavreport: 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 = 'delmod 6.16 84 mar 12 tds/gds'; *) (* begin module logav.themain *) procedure themain(var data, logavp, logavreport: text); (* the main procedure of the program *) var parameterversion: real; (* parameter version number *) sumlogs: real; (* sum of logs *) n: real; (* a number from the data file *) m: real; (* n shifted *) count: integer; (* the number of numbers read from the data file *) shift: integer; (* Amount to subtract from each data number *) procedure report(var f: text); (* write a report to file f *) begin writeln(f, 'for ',count:1,' numbers,', ' the average of the log2 is ', sumlogs/count:10:5); end; begin writeln(output,'logav ',version:4:2); reset(logavp); readln(logavp, parameterversion); if round(100*parameterversion) < round(100*updateversion) then begin writeln(output, 'You have an old parameter file!'); halt end; read(logavp, shift); sumlogs := 0.0; count := 0; { shift := 20; shift := 0; } shift := 20; reset(data); while not eof(data) do begin if (data^ = '*') then begin readln(data) end else begin readln(data, n); m := n - shift; if m > 0 then begin sumlogs := sumlogs + ln(m)/ln(2); count := succ(count); end else begin writeln(output, 'The value n = ',n:1:1, ' cannot be shifted by ',shift:1, ' because that is not positive ', ' so the log cannot be taken.'); writeln(output, ' This value was dropped from the computation'); end end end; rewrite(logavreport); report(logavreport); report(output); end; (* end module logav.themain *) begin themain(data, logavp, logavreport); 1: end.