Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-03 - decus/20-0078/libsim/histp.sim
There is 1 other file named histp.sim in the archive. Click here to see a list.
OPTIONS(/E/C/-A/-D/-I);
PROCEDURE histp(a,lowerbound,upperbound,yscale,
max,min,brick,xlabels,title,pf);
NAME title,xlabels;   VALUE brick;
INTEGER ARRAY a;
INTEGER lowerbound,upperbound,yscale,max,min;
TEXT brick,xlabels,title;   REF (Outfile) pf;
!
Procedure HISTP prints a histogram of the
INTEGER ARRAY   A [LOWERBOUND:UPPERBOUND] on file PF.
YSCALE is the increment for the y axis (Integer > 0).
MAX is the maximum y value displayed (INTEGER).
MIN is the minimum y value displayed (INTEGER).
BRICK is a text which will be used when printing histogram "piles"
(TEXT by VALUE).
XLABELS is a text that will be printed under the histogram.
If XLABELS == NOTEXT the indicies LOWERBOUND and UPPERBOUND will
be printed. The start of the text will be at the first "brick"
character of the first "pile".
TITLE is a text that will be printed on top of the histogram.
PF is the output file. If PF is a PRINTFILE, HISTP will start calling
EJECT(1).
   Please note the following HISTP properties:
1. If MAX < MIN, the MAX and MIN values will be adjusted if
necessary (individually!). Thus, if MAX = -1 and MIN = 0
an array A with only positive elements will be presented in
a histogram with y axis range [0:max of A].

2. If (resulting) MIN is zero, this level will be indicated by
the x axis (----).

3. If BRICK starts with a blank, a single space between "piles"
will be printed.

4. IF PF == NONE, SYSOUT will be used.

5. IF the range [LOWERBOUND:UPPERBOUND] in combination with actual
BRICK.LENGTH cannot be printed on one page due to current
PF.Length, then the rest (the rightmost part) of the histogram
will be printed on a subsequent page.

An example:
Input:
A[0:6]:=  5 -3 -1 0 3 4 2
YSCALE:=  1
MAX:=     -10
MIN:=      10
BRICK:=   " ***"
XLABELS:=  "  A   B   C   D   E   F   G"
TITLE:=    "Test example - histogram print"
PF:-       NONE
   will produce the following output on SYSOUT:
             Test example - histogram print

           5 ! ***
             ! ***                 ***
             ! ***             *** ***
             ! ***             *** *** ***
           1 ! ***             *** *** ***
             !----------------------------
             !     *** ***
             !     ***
          -3 !     ***
              --+---+---+---+---+---+---+-
                A   B   C   D   E   F   G
;
IF lowerbound > upperbound THEN
BEGIN   Outtext("?HISTP Illegal Array Bounds");   Outimage  END
ELSE IF yscale <= 0 THEN
BEGIN   Outtext("?HISTP Non-positive Y-scale element");   Outimage   END
ELSE
BEGIN   INTEGER i,up,newupperbound,h2,tempmax,tempmin,width,negscale;
    TEXT axis;
    width:= brick.Length;
    axis:- Blanks(width);   WHILE axis.More DO axis.Putchar('-');
    IF pf == NONE THEN pf:- Sysout;
    IF max < min THEN
    BEGIN   tempmin:= tempmax:= a[lowerbound];
	FOR i:= lowerbound+1 STEP 1 UNTIL upperbound DO
	IF a[i] > tempmax THEN tempmax:= a[i] ELSE
	IF a[i] < tempmin THEN tempmin:= a[i];
	IF max < tempmax THEN max:= tempmax;
	IF min > tempmin THEN min:= tempmin;
    END loop setting max and min;
    h2:= (max+min)//2;
    IF (upperbound - lowerbound + 1)*width + 15 > pf.Length THEN
    BEGIN   newupperbound:= upperbound;
	upperbound:= (pf.Length-15)//width + lowerbound - 1
    END
    ELSE newupperbound:= lowerbound - 1;
    ! That was checking histogram width;
    INSPECT pf WHEN Printfile DO
    BEGIN   Eject(1);   Setpos(14);   Outtext(title);
	Outimage;   Eject(Line+2)
    END
    WHEN Outfile DO
    BEGIN   Setpos(14);   Outtext(title);
	Outimage;   Outimage
    END;
    up:= ((h2-min)//yscale)*yscale + min;
    IF up < h2 THEN up:= up + yscale;   h2:= up;
    up:= ((max-min)//yscale)*yscale + min;
    IF up < max THEN up:= up + yscale;
    pf.Outint(up,12);   pf.Outtext(" !");
    negscale:= - yscale;
    FOR up:= up STEP negscale UNTIL min DO
    IF NOT (up = min AND min = 0) THEN
    BEGIN
	IF up = h2 OR up = min THEN
	BEGIN   pf.Setpos(1);   pf.Outint(up,12);   pf.Outtext(" !")   END
	ELSE
	BEGIN   pf.Setpos(14);   pf.Outchar('!')   END;
	IF up NE 0 THEN
	BEGIN
	    FOR i:= lowerbound STEP 1 UNTIL upperbound DO
	    IF a[i] = up THEN pf.Outtext(brick) ELSE
	    IF a[i] > up EQV up >= 0 THEN pf.Outtext(brick) ELSE
	    pf.Setpos(pf.Pos+width);
	END ne 0 ELSE
	IF min < 0 THEN
	BEGIN   pf.Setpos(14);   pf.Outchar('!');
	    FOR i:= lowerbound STEP 1 UNTIL upperbound DO
	    pf.Outtext(axis);
	END zero axis;
	pf.Outimage
    END print loop;
    pf.Setpos(15);
    FOR i:= lowerbound STEP 1 UNTIL upperbound DO
    pf.Outtext(axis);
    i:= (upperbound-lowerbound)*width+15+width//2;
    IF width > 1 THEN
    BEGIN
	FOR h2:= 15+width//2 STEP width UNTIL i DO
	BEGIN   pf.Setpos(h2);   pf.Outchar('+')   END;
    END;
    pf.Outimage;
    IF xlabels == NOTEXT THEN
    BEGIN
	pf.Outint(lowerbound,15+width//2);
	IF i > pf.Length THEN i:= pf.Length - 4;
	pf.Setpos(i-4);   pf.Outint(upperbound,5);
    END ELSE
    BEGIN   pf.Setpos(15);   pf.Outtext(xlabels)   END;
    pf.Outimage;
    IF newupperbound >= upperbound THEN
    histp(a,upperbound+1,newupperbound,yscale,max,min,
    brick,xlabels,title,pf);
END of histp;