PROGRAM analysedata (input,output); {This program accepts a sequence of numbers, stores them, finds their maximum and sets up a horizontal scale for them it then goes on to do a bincount.} CONST max = 5000; TYPE onefive = (i,ii,iiv,v); {1, 2, 2.5, 5} tentwenty = 10..20; datarray = array[1..max]of real; datax = 0..max; {an index into the data array} countarray = array[1..20] of integer; {holds initial counts} VAR data :datarray; ndata :0..max; binsize :onefive; binexp :integer; binnumber :tentwenty; count :countarray; { This procedure is designed to divide a set of numbers into a number of ranges which are suitable for use in producing a histogram. It makes the assumption that:- 1. The collection of numbers are in the range 0 to +ve. 2. That the maximum value is available. In deciding the range to use it adopts the follwoing constraints:- 1. The range covered by each bin for a histogram bar will be one of:- (1 or 2 or 2.5 or 5) * 10En where n is an integer. 2. The number of bins spanning the data shall be in the range 10..20 Computing the binsize and number of bins is done by considering the logarithms of the various numbers. A binsize and bin number is needed which conforma to :- log(binsize) + n + log(binnumber) > log(maxvalue) where log is to thhe base 10. The maximum binnumber is required concistent with this constraint. Consider the decade (10En .. 10E(n+1) which contains the maxvalue. The choices of bin number available span this decade as in ndicated by the diagram:-?? n n+1 |++++++++++|++++++++++|----|++++++++++| log i .301 ii .602 .699 v |++++++++| .398 iiv |+++++| represents the (almost linear) log of 10,11,12 . .20 (-1) The bisize exponent will be n-1. Use the 2.5 (iiv) scale only in the gap not covered between 2 (ii) & 5 (v). } PROCEDURE sethorizscale ( max :real; {max value in number set} var binsize :onefive; {horiz scale size} var binexp :integer; { scale factor for binsize} var binnumber :tentwenty {self-explan?} ); VAR lxtoxx :array [tentwenty] of real; {:= log (10..20)} litov :array [onefive] of real; {:= log (1,2,2.5, 5} lm, {:= log(max)} fm :real; { frac pt of lm} im :integer;{:=trunc(lm)} ivx :onefive; {array index} xxxx :tentwenty; {arrayindex lxtoxx} base, z :real; {used in computing binnumber} FUNCTION log(z :real) :real; BEGIN log:= ln(z)/ln(10) END; BEGIN if max <= 0 then begin writeln('Illegal max -', max:9); lm:=1/max; {!!!!!! diagnose????} halt('**from sethscale**'); {eventually have to get rports out in more sanitary way?} end; for xxxx:=10 to 20 do lxtoxx[ xxxx ]:= log(xxxx)-1; litov[i] := log (1); litov[ii] := log(2); litov[iiv] := log(2.5); litov[v] := log(5); lm := log(max); im := trunc(lm); fm := lm-im; if fm<0 then fm:=0; binexp := im-1; {the easy bit} {try to discover the particular binsize involved} if fm max then max:=A[p]; p:=p+1; end; maximum:=max END; {maximum} FUNCTION bstoreal (bs :onefive) :real; BEGIN case bs of i : bstoreal:=1.0; ii: bstoreal:=2.0; iiv: bstoreal:=2.5; v: bstoreal:=5.0; end; END; {bstoreal} FUNCTION tentopower(n :integer) :real; VAR result :real; exp :integer; BEGIN result:=1; exp:=0; while exp