PROGRAM LinPltTest (OUTPUT); { Test PROCEDURE LinPlt. } CONST NCols = 51; NPts = 50; Scale = 10.0; { Scale factor for test plot } TYPE YArrTyp = ARRAY[1..512] OF REAL; VAR Y : YArrTyp; J,KFlag : INTEGER; PROCEDURE LinPlt (VAR Y:YArrTyp; NPts,NCols:INTEGER; VAR KFlag:INTEGER); { LinPlt Standard Pascal January 1995 PROCEDURE LinPlt prints a line plot on the line printer. Plots Y[J] versus J, one point per line. J. P. Chandler, Computer Science Department, Oklahoma State University Input quantities .... Y[*], NPts, NCols Output quantity ..... KFlag Y[*] -- The ordinates Y[1], Y[2], ..., Y[Npts] to be plotted NPts -- The number of Y[J] values NCols -- The number of columns (print positions) in the graph (Suggestion... Use NCols = 21 or 51 or 101) KFlag -- A flag that returns a condition code as follows... = 0 if LinPlt executed normally, = -1 if Npts<1, = -2 if NCols<3 or NCols>NCMax (see below) = -3 if DY=0.0 (see below) = -4 if JYZero<1 or JYZero>NCols (see below) } CONST NCMax = 101; { Maximum number of print positions } KBlank = ' '; KMinus = '-'; { Symbol used for the Y axis } KhPlus = '+'; { Symbol used for the ends of the Y axis } KhI = 'I'; { Symbol used for the X axis } KhZero = '0'; { Symbol used at Y=0 } KhSym = '*'; { The plotting symbol } TYPE LineType = PACKED ARRAY[1..101] OF CHAR; VAR KhAxis, KhLine : LineType; J,K,JYZero,L,NCmu : INTEGER; YMin,YMax,DY : REAL; BEGIN IF NPts < 1 THEN KFlag := -1 ELSE IF (NCols < 3) OR (NCols > NCMax) THEN KFlag := -2 ELSE BEGIN YMin := Y[1]; YMax := Y[1]; FOR J := 1 TO NPts DO BEGIN IF Y[J] < YMin THEN YMin := Y[J]; IF Y[J] > YMax THEN YMax := Y[J]; END; IF YMin > 0.0 THEN YMin := 0.0; IF YMax < 0.0 THEN YMax := 0.0; IF YMin >= YMax THEN BEGIN YMin := -1.0; YMax := +1.0; END; { At this point, either YMin <= 0.0 < YMax or YMin < 0.0 <= YMax . Therefore, KFlag=-3 or KFlag=-4 should be impossible. } NCmu := NCols - 1; DY := (YMax - YMin)/NCmu; IF DY = 0.0 THEN KFlag := -3 ELSE BEGIN JYZero := Trunc(-YMin/DY + 1.5); IF (JYZero < 1) OR (JYZero > NCols) THEN KFlag := -4 ELSE BEGIN Writeln; Writeln(' J Y[J] YMin = ',YMin:15, ' YMax =',YMax:15); Writeln(' ---- -----------'); { Print the Y axis. } FOR J := 2 TO NCmu DO KhAxis[J] := KMinus; KhAxis[1] := KhPlus; KhAxis[NCols] := KhPlus; KhAxis[JYZero] := KhZero; Write(' ':18); FOR J := 1 TO NCols DO Write(KhAxis[J]); Writeln; { Loop over the lines in the graph. } FOR J := 1 TO NPts DO BEGIN { Set up the line of characters and then print it. } FOR K := 1 TO NCols DO KhLine[K] := KBlank; KhLine[JYZero] := KhI; K := Trunc((Y[J] - YMin) / DY + 1.5); IF (K >= 1) AND (K <= NCols) THEN KhLine[K] := KhSym; Write(J:5,' ',Y[J]:11,' '); FOR K := 1 TO NCols DO Write(KhLine[K]); Writeln; END; { End loop over the points in the graph } { Print another Y axis at the bottom of the graph. } Write(' ':18); FOR J := 1 TO NCols DO Write(KhAxis[J]); Writeln; Writeln(' ':21,'YMin = ',YMin:15, ' YMax =',YMax:15); KFlag := 0; END; { End ELSE (KFlag <> -4) } END; { End ELSE (KFlag <> -3) } END; { End ELSE (KFlag <> -1) and (KFlag <> -2) } END; { End PROCEDURE LinPlt } BEGIN { Begin main } FOR J := 1 TO NPts DO Y[J] := Sin(J/Scale) + 0.5; LinPlt(Y,NPts,NCols,KFlag); END. { End main }