
Program DemoPlot;  { Test program to demonstrate plotter }

Const
  DemoVers = '1.01';
  DemoDate = '19 Sept 86';

Label
  Exit;


Var                                         { These are only for demo }
  i,IXvalue,IYvalue          : Integer;
  x,y,xc,yc                  : Real;
  Answer,Answer2             : Char;
  v1,v2,v3,v4,v5,v6          : Real;
  SelectAxis                 : Boolean;

{$I HiResPlt.pas }


{ ***** Main test program to demonstrate operation of plotter ****** }

begin

{ This tests for installation of HIPLOT2 which is required for plotting.    }
{  User types HIPLOT2 (i.e. runs the program) to install the plotter before }
{ running any programs with this plotter software.  It needs to be run      }
{ only once.  Running it several times simply makes useless copies.         }

  ClrScr;
  WriteLn('PPLOT.PAS ... Plotter Demonstration Program');
  WriteLn;
  WriteLn('For a quick preview, simply press ''Enter'' at each pause...');
  WriteLn;
  WriteLn('  This demonstration will draw lines and plot a full graph with');
  WriteLn('an opportunity to get a hardcopy.  First, do a preview of the');
  WriteLn('demo by pressing ''Enter'' at each pause.  You can use the keypad');
  WriteLn('to position the crosshair and read off values.  You can try to');
  WriteLn('get a hardcopy later when you know the screen plotting works.');
  WriteLn('First, a box and a diagonal is drawn.  Then part of the box is');
  WriteLn('erased and the box is converted to a backwards ''L''.  The latter');
  WriteLn('was done to demonstrate selective erasing and the ability to write');
  WriteLn('to only the screen.  A hardcopy will show only the box and');
  WriteLn('diagonal.  A crosshair is then drawn which allows you to read off');
  WriteLn('values into your program.  When ready, press ''Enter'' to continue.');
  WriteLn;
  WriteLn;

  Writeln('But first, do you have a color graphics card? <y>/n: ');
  Read(Answer);
  If UpCase(Answer) = 'N' then
  Begin
    ClrScr;
    ScreenOff;
    WriteLn;
    WriteLn('Plotting into internal buffer but not CRT...');
  End
  Else ScreenOn;    { Either ScreenOn or ScreenOff is required }

  SetTypeComputer;  { This adjusts speed of crosshair movement } { Required }

                 { ****** Plot example #1 ****** }
{ The following simply draws a box and a diagonal.  It does not draw an axis }
{ You may use the keypad cursor controls to move the crosshair }

{ The following aborts program if HIPLOT2 is not loaded }
  If (Vcheck = 0) Then GoTo EXIT;                                { Required }

{ This draws a box and a diagonal through it }
  SetPlot;                    { First, must initialize plotting }
  Box(160,100,479,299);       { Now draw box }
  Hplot(0.0,0.0); Hplot(639.0,399.0);  { Now draw diagonal line }

{ The box and diagonal is drawn, now part of the box will be erased, but }
{ only the CRT part.  A hardcopy will show the original box only. }
  Option(5,True);     { Inhibit write to buffer }
  Option(7,True);     { XOR mode }
  Box(160,100,485,305);  { This draws a second box, also not to buffer }

{ Now, the user can use the crosshairs to pick off values and get hardcopy. }
  Crosshair(IXvalue,IYvalue);
  Hcopy('Eject','Pause'); Cls;
  WriteLn('The crosshair was position at...  X:',IXvalue:4,' Y:',IYvalue:4);
  WriteLn;
  WriteLn('This demonstrates graphics where an axis is required for');
  WriteLn('plotting data.  Axis generation with heading, tic marks and');
  WriteLn('time and date marking is done with a single procedure.  As above,');
  WriteLn('a crosshair can be used to read values back into the program.');
  WriteLn;
  WriteLn('Press ''Enter'' when ready...');
  ReadLn(Answer);



                 { ****** Plot example #2 ****** }

{ The following is for more complex plotting where an axis is drawn
  and labeled.  It is in a loop to allow testing different axis values. }

{ The following aborts program if HIPLOT2 is not loaded }
  If (Vcheck = 0) Then GoTo EXIT;                                { Required }
  SelectAxis := False;
{ This defines the heading, 62 characters, max except as shown. }
  Alpha99[1] := 'Time, Sec  (  X-Axis )';  { 59 characters, max }  { Required }
  Alpha99[2] := 'Amplitude  Y-Axis';       { 17 characters, max }  { Required }
  Alpha99[3] := '* * * Demonstration of Axis Graphics  * * *';     { Required }
  Alpha99[4] := 'This is the Second Line of the heading';          { Required }
  Alpha99[5] := ' ';                                               { Required }
  Alpha99[6] :=  '                 Demo: '+DemoVers+'   '+DemoDate;{ Required }
  Alpha99[7] :=  '                 Plot: '+HiResVers99+
                                   '   '+HiResDate99;              { Required }
  Alpha99[8] :=  '                 Uses: HIPLOT2';                 { Required }
  Alpha99[9] :=  'This is the Last Line of the Heading';           { Required }
  v1:=0; v2:=10; v3:=1; v4:=-1; v5:=1; v6:=0.1;                    { Required }


  Repeat
    If SelectAxis then
    Begin
      Writeln;
      Writeln('Change axis values x1, x2, x3 and y1, y2, y3 where:');
      Writeln('Linear scale:      1: start,    2: stop,    3: increment');
      Writeln('Log scale   :      1: start decade,   2: number of decades, 3=0');
      Writeln;
      Writeln('Enter values to be changed or press "Enter" if no change');
      Writeln;
      Writeln('Old value=',v1:8:2,', enter new x1: ');
      Read(v1);
      Writeln;
      Writeln('Old value=',v2:8:2,', enter new x2: ');
      Read(v2);
      Writeln;
      Writeln('Old value=',v3:8:2,', enter new x3: ');
      Read(v3);
      Writeln;
      Writeln('Old value=',v4:8:2,', enter new y1: ');
      Read(v4);
      Writeln;
      Writeln('Old value=',v5:8:2,', enter new y2: ');
      Read(v5);
      Writeln;
      Writeln('Old value=',v6:8:2,', enter new y3: ');
      Read(v6);
    End
    Else
    Begin
      v1:=0; v2:=10; v3:=1; v4:=-1; v5:=1; v6:=0.1;
    End;


{ This defines X and Y limits and draws axis with heading (Alpha99) }
{ SEE AXIS PROCEDURE FOR DEFINITION OF VARIABLES }
    Axis(v1,v2,v3,v4,v5,v6,Alpha99);                               { Required }

{ This calculates X,Y values and plots them }
    x := 0.01;
    For i := 1 to 200 do
    Begin
      y := Abs(Sin(x*2.0*Pi/2.5))+0.01;
      Hplot(x,y);                                                 { Required }
      If i=23 Then Insert(x+0.1,y,1);           { Useful for multiple curves}
      x := x+0.05;
    End;

    ReOrg;             { Declair next point to be the origin }
    Pattern($cccc);    { Set pattern to dotted line          }
    Hplot(1.0,0.05);    { Plot single line                    }
    Hplot(9.5,0.05);
    Insert(9.5,0.05,2);  { Place the number 2 at the end     }

{ DaTime(1);  If used, this would place date and time at top(1). }
    Crosshair(IXvalue,IYvalue);

    Hcopy('Eject','Pause');                        { Required for hard copy }
    Cls;                                           { Clean screen }

    WriteLn('The crosshair was position at...  X:',IXvalue:4,' Y:',IYvalue:4);
    FindReal(IXvalue,IYvalue,xc,yc);
    WriteLn('The crosshair was positioned at:  X= ',xc:4:2,' and Y= ',yc:4:2);
    WriteLn;

{ Repeat loop for test program }
    Writeln('Repeat demo program? y/<n>: ');
    ReadLn(Answer);
    If Not (UpCase(Answer) <> 'Y') then
    begin
      Writeln('Do you wish to try different axis values? y/<n>: ');
      Read(Answer2);
      SelectAxis := (UpCase(Answer2) = 'Y');
    end;

  Until UpCase(Answer) <> 'Y';

EXIT:   { This is an excape for case where HIPLOT2 was not run}  { Required }

End. { PPLOT }

