home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hacker Chronicles 2
/
HACKER2.BIN
/
149.GRAPHWAV.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-06-30
|
14KB
|
360 lines
(****************************************************************************)
(*** ***)
(*** GraphResults plots either the time domain data or the frequency ***)
(*** domain data, as determined by the value of parameter PlotType. The ***)
(*** data is either plotted over the whole interval, or over a user ***)
(*** defined subinterval. Additionally, a hard copy may be made of the ***)
(*** current screen, a zoom factor may be given, or the type of plot may ***)
(*** be changed. Initially the plot is drawn as a log-log plot. Four ***)
(*** types of plots are defined: ***)
(*** 1. Linear x, linear y. ***)
(*** 2. Log x, log y. ***)
(*** 3. Log x, linear y. ***)
(*** 4. Linear x, log y. ***)
(*** ***)
(*** ***)
(****************************************************************************)
UNIT GraphWaveform;
INTERFACE
USES
{$IFDEF DOSCrt}
DOSCrt,
{$ELSE}
Crt,
{$ENDIF}
Extended_Reals,
Graph,
DrawGraf,
Global,
TextOps,
GraphText,
Application_Specifics;
PROCEDURE GraphResults (PlotType : CHAR);
PROCEDURE Graph_Wave;
(****************************************************************************)
IMPLEMENTATION
CONST
NormSize = 1;
LineX = 60;
LineY = 16;
VAR
i : INTEGER; (* Loop counter *)
MinFirst : INTEGER; (* Smallest index that can be graphed. *)
MaxLast : INTEGER; (* Largest index that can be graphed. *)
first : INTEGER; (* Subinterval setup: graph from *)
last : INTEGER; (* first to last points of Temp. *)
RightEnd : REAL; (* Subinterval setup: user *)
LeftEnd : REAL; (* inputted endpoints. *)
tempx : REAL; (* Temp var for swapping values. *)
temp : REAL; (* Variable for swapping values. *)
Title : string; (* Title of graph. *)
XTitle : INTEGER; (* X coordinate to print title. *)
YTitle : INTEGER; (* Y coordinate to print title. *)
TitlePos : INTEGER; (* Position of 'Title:' in title. *)
j : BYTE; (* Temp counter variable. *)
Plot : BYTE; (* Plot type. *)
PlotMAG : boolean; (* Magnitude of frequency data? *)
PlotPHASE : boolean; (* Phase of frequency data? *)
X_Units : string;
Y_Units : string;
leftx : INTEGER; (* Left edge of window boundary *)
rightx : INTEGER; (* Right edge of window boundary *)
topy : INTEGER; (* Top edge of window boundary *)
bottomy : INTEGER; (* Bottom edge of window boundary *)
{----------------------------------------------------------------------------}
PROCEDURE ClearWindow (x_1,y_1,x_2,y_2 : INTEGER);
VAR
v : ViewPortType;
BEGIN {ClearWindow}
GetViewSettings (v);
SetViewPort (x_1,y_1,x_2,y_2,ClipOff);
ClearViewPort;
WITH v DO
SetViewPort (x1,y1,x2,y2,Clip);
END; {ClearWindow}
PROCEDURE ClearTextWindow (x_1,y_1,x_2,y_2 : INTEGER);
BEGIN {ClearTextWindow}
Text_To_Cart (x_1,y_1,x_1,y_1);
Text_To_Cart (x_2,y_2,x_2,y_2);
ClearWindow (x_1,y_1,x_2,y_2);
END; {ClearTextWindow}
PROCEDURE PrintMenu;
VAR
x, y : INTEGER;
BEGIN {PrintMenu}
Text_To_Cart (LineX,LineY,x,y);
Line (x,0,x,GetMaxY);
Line (x,y,GetMaxX,y);
ClearTextWindow (LineX+1,LineY+1,80,25);
WriteText ('Select Option: ',LineX+2,LineY+1);
WriteText (' 1. Print Screen ',LineX+2,LineY+3);
WriteText (' 2. Plot Type ',LineX+2,LineY+4);
WriteText (' 3. Interval ',LineX+2,LineY+5);
WriteText (' 9. Main Menu ',LineX+2,LineY+6);
WriteText ('Your Choice? ',LineX+2,LineY+8);
END; {PrintMenu}
{----------------------------------------------------------------------------}
{- -}
{- GraphData graphs the data. Initially, time data is graphed on a -}
{- linear (type 1) graph, magnitudes are graphed on log-log (type 2) -}
{- graphs, and phase is plotted on a semi-log (type 3) graph. -}
{- -}
{----------------------------------------------------------------------------}
PROCEDURE GraphData;
CONST
shift : REAL = 0; (* y offset for graphing data *)
NumDigits = 4; (* number of digits of delay to display *)
VAR
Delay : REAL; (* X offset of data to be graphed. *)
dummy : string [20];
error : BYTE; (* Error code returned by DrawGraph *)
ErrStr : string[3];
i : INTEGER;
BEGIN {GraphData}
SetViewPort (0,0,GetMaxX,GetMaxY,ClipOn);
ClearWindow (0,0,GetMaxX,GetMaxY);
FOR i:=first TO last DO BEGIN
TempXPtr^[i-first]:=OutArrayX^[i];
TempYPtr^[i-first]:=OutArrayY^[i];
END; {FOR}
leftx:=0;
rightx:=5*((GetMaxX+1) div 8);
topy:=5*(char_height div 2);
bottomy:=GetMaxY-2*char_height;
DrawGraph (TempXPtr,TempYPtr,last-first+1,Plot,leftx,topy,
rightx,bottomy,delay,shift,X_Units,Y_Units,error);
Value_To_String (Delay,NumDigits,dummy);
dummy:='X Delay: '+dummy+'s';
WriteText (dummy,LineX+2,LineY-2);
IF error <> 0 THEN BEGIN
GotoXY (11,13);
Write ('[Error ',error,' in drawing routine]');
END; {IF error}
Display_Test_Point_Info;
END; {GraphData}
{----------------------------------------------------------------------------}
{- -}
{- ChangeIntervals divides the array to be graphed into subintervals -}
{- as input by the user. -}
{- -}
{----------------------------------------------------------------------------}
PROCEDURE ChangeIntervals;
VAR
i : INTEGER;
EndString : string; (* Right endpoint + multiplier *)
old_last : INTEGER; (* store old right endpoint *)
x1,x2,y1,y2 : INTEGER; (* Window coordinates of menu *)
BEGIN {ChangeIntervals}
old_last:=last;
ClearLine (LineX+1,LineY+8,18);
WriteText ('Maximum: ',LineX+2,LineY+8);
ReadText (EndString,LineX+11,LineY+8);
IF length (EndString) > 0
THEN String_to_Value (EndString,RightEnd,EndString)
ELSE RightEnd:=OutArrayX^[MaxLast];
i:=MaxLast;
WHILE ((OutArrayX^[i] >= RightEnd) AND (i > MinFirst)) DO DEC (i,1);
last:=i;
IF (last-first) < 5 THEN BEGIN
WriteText ('Too few points! ',LineX+2,LineY+8);
Buzzer;
last:=old_last;
END {then}
ELSE IF last <> old_last THEN BEGIN
GraphData;
END; {ELSE IF}
END; {ChangeIntervals}
{----------------------------------------------------------------------------}
{- -}
{- OutputScreen sets up the screen for a hard copy, then calls the -}
{- PrintScreen routine to produce the hard copy. -}
{- -}
{----------------------------------------------------------------------------}
PROCEDURE OutputScreen;
VAR
Title : string [80];
SubTitle : string [80];
x : INTEGER;
y : INTEGER;
BEGIN {OutputScreen}
Text_to_Cart (LineX+1,LineY+1,x,y);
ClearWindow (x,y,GetMaxX,GetMaxY);
WriteText ('Horiz units: ',LineX+2,LineY+2);
ReadText (X_Units,LineX+15,LineY+2);
WriteText ('Vert units: ',LineX+2,LineY+4);
ReadText (Y_Units,LineX+15,LineY+4);
WriteText ('Title of graph: ',1,1);
ReadText (Title,17,1);
WriteText ('Sub-Title: ',1,2);
ReadText (SubTitle,17,2);
GraphData;
XTitle:=(LineX-length(Title)) div 2 +2;
WriteText (Title,XTitle,1);
XTitle:=(LineX-length(SubTitle)) div 2 +2;
WriteText (SubTitle,XTitle,2);
IF NOT NoPrinter THEN Print_Screen;
END; {OutputScreen}
{----------------------------------------------------------------------------}
{- -}
{- ChangePlotType changes the plot number or the interval endpoints. -}
{- It is assumed that the window boundaries are already drawn. -}
{- -}
{----------------------------------------------------------------------------}
PROCEDURE ChangePlotType;
VAR
ch : CHAR;
NewPlotNum : BYTE;
BEGIN {ChangePlotType}
SetViewPort (0,0,GetMaxX,GetMaxY,ClipOn);
ClearTextWindow (LineX+1,LineY+1,80,25);
WriteText ('Select Plot: ',LineX+2,LineY+1);
WriteText (' 1. Linear ',LineX+2,LineY+3);
WriteText (' 2. Log ',LineX+2,LineY+4);
WriteText (' 3. Log-Linear ',LineX+2,LineY+5);
WriteText (' 4. Linear-Log ',LineX+2,LineY+6);
WriteText ('Your Choice? ',LineX+2,LineY+8);
REPEAT
ch:=ReadKey;
UNTIL ch in ['1'..'4',ENTER];
IF ch <> ENTER
THEN NewPlotNum:=ord(ch)-ord('0')
ELSE IF PlotMAG
THEN NewPlotNum:=Logarithmic
ELSE IF PlotPHASE
THEN NewPlotNum:=LogLin
ELSE NewPlotNum:=Linear;
IF PlotPHASE THEN
IF NewPlotNum = Logarithmic
THEN NewPlotNum:= LogLin
ELSE IF NewPlotNum = LinLog
THEN NewPlotNum:= Linear;
IF NewPlotNum <> Plot THEN BEGIN
Plot:=NewPlotNum;
GraphData;
END; {THEN}
END; {ChangePlotType}
{----------------------------------------------------------------------------}
PROCEDURE GraphResults (PlotType : CHAR);
VAR
choice : CHAR;
BEGIN {GraphResults}
X_Units:='';
Y_Units:='';
PlotMAG :=(UpCase(PlotType) = 'M');
PlotPHASE:=(UpCase(PlotType) = 'P');
MinFirst:=0;
IF (PlotMAG OR PlotPHASE)
THEN BEGIN
MaxLast :=pred(NumFreqs);
FOR i:=MinFirst TO MaxLast DO BEGIN
OutArrayX^[i]:=freq^[i];
IF PlotMAG
THEN OutArrayY^[i]:=mag^[i]
ELSE OutArrayY^[i]:=phase^[i]*180/PI;
END; {FOR}
IF PlotMAG
THEN Plot:=Logarithmic
ELSE Plot:=LogLin;
END {then}
ELSE BEGIN
MaxLast :=pred(NumPoints);
FOR i:=MinFirst TO MaxLast DO BEGIN
OutArrayX^[i]:=time^[i];
OutArrayY^[i]:=ampl^[i];
END; {FOR}
Plot:=Linear;
END; {else}
first:=MinFirst;
last :=MaxLast;
InitGraph (GraphDriver,GraphMode,'');
SetViewPort (0,0,GetMaxX,GetMaxY,ClipOn);
IF GraphDriver <> HercMono THEN SetColor (White);
GraphData;
REPEAT
PrintMenu;
REPEAT
choice:=ReadKey;
UNTIL choice IN ['1'..'3','9'];
CASE choice OF
'1': OutputScreen;
'2': ChangePlotType;
'3': ChangeIntervals;
'9': BEGIN
CloseGraph;
TextColor (ForeColor);
TextBackGround (BackColor);
ClrScr;
Exit;
END;
END; {CASE}
UNTIL FALSE;
END; {GraphResults}
{----------------------------------------------------------------------------}
PROCEDURE Graph_Wave;
VAR
ch : CHAR;
BEGIN {Graph_Wave}
IF TRANS
THEN BEGIN
GotoXY (StartColumn,23);
Write ('Time, Magnitude or Phase (T/M/P)?');
REPEAT
ch:=UpCase(ReadKey);
UNTIL (ch IN ['T','M','P',ENTER]);
IF (ch = ENTER)
THEN IF ORIG
THEN GraphResults ('T')
ELSE GraphResults ('M')
ELSE GraphResults (ch);
END {THEN}
ELSE GraphResults ('T');
END; {Graph_Wave}
(****************************************************************************)
BEGIN {INITIALIZATION}
END. {UNIT GraphWaveform}