home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HAM Radio 1
/
HamRadio.cdr
/
tech
/
eepub15
/
smith4.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-07-06
|
14KB
|
627 lines
PROGRAM Smith3;
(*$I GRAPH.P*)
(*$Iploader.inc*)
LABEL
ReDo, start;
CONST
CenterX:integer = 219;
CenterY:integer = 100;
IncX :real = 2E-2;
IncB :real = 2E-2;
IncRho :real = 3.4906556E-2;
VAR
Done:boolean;
Z0,R,X,B,G,Xn,Rn,Gn,Bn,RhoRealReal,RhoImagReal,Rho,RhoW :Real;
Psi,Theta,DeltaX,DeltaB,DeltaZRho,DeltaYRho,XW,RW,BW,GW :Real;
RhoMagReal,RhoAngReal,PsiW,VSWR,XincReal,BincReal,RhoIncReal :Real;
Xplot,Yplot,RhoReal,RhoImag,M,N,Index :Integer;
Ch :Char;
RhoStr,PsiStr,XStr,RStr,BStr,Z0Str,GStr,VSWRStr,XincStr,BincStr :String[10];
RhoIncStr,MStr :String[10];
DataLabel : Array [1..10] Of String[10];
DataValue : Array [1..10] Of String[10];
PROCEDURE CalcZfromRho;forward;
PROCEDURE CalcYfromRho;forward;
PROCEDURE CalcPolarRho;forward;
PROCEDURE CalcVSWR; forward;
PROCEDURE Background; forward;
PROCEDURE Title;
BEGIN
ClrScr;
Ploader('TITLE');
TextColor(7); TextBackground(0);
Read(Kbd,Ch);
END;
PROCEDURE Help;
BEGIN
GotoXY(1,1);ClrEol;
write(chr(255),chr(255),'HELP/');
TextColor(7); TextBackground(0);
Read(Kbd,Ch);
END;
PROCEDURE NewWrite;
BEGIN
CalcZfromRho;
CalcYfromRho;
CalcPolarRho;
XW := Z0 * Xn; RW := Z0 * Rn; BW := Bn / Z0; GW := Gn / Z0;
GoToXY(4,2); Write('X Ohm ');
TextColor(1);
GoToXY(4,4); Write('R Ohm ');
TextColor(3);
Str(XW:5:3,XStr);
GoToXY(4,3); Write(XStr,' ');
Str(RW:5:3,RStr);
TextColor(1);
GoToXY(4,5); Write(RStr,' ');
TextColor(2);
GoToXY(4,6); Write('B mhO ');
TextColor(3);
GoToXY(4,8); Write('G mhO ');
Str(BW:5:3,BStr);
TextColor(2);
GoToXY(4,7); Write(BStr,' ');
Str(GW:5:3,GStr);
TextColor(3);
GoToXY(4,9); Write(GStr,' ');
GoToXY(4,10); Write('Rho (Mag) ');
Str(RhoMagReal:5:3,RhoStr);
GoToXY(4,11); Write(RhoStr,' ');
GoToXY(4,12); Write('Rho (Ang) ');
RhoAngReal := -180*RhoAngReal/Pi;
Str(RhoAngReal:5:3,PsiStr);
RhoAngReal := -Pi*RhoAngReal/180;
GoToXY(4,13); Write(PsiStr,' ');
GoToXY(4,14); Write('VSWR ');
CalcVSWR;
Str(VSWR:5:3,VSWRStr);
GoToXY(4,15); Write(VSWRStr,' ');
END;
PROCEDURE InputVariables;
BEGIN
GotoXY(2,25);
Str(Z0:5:3,Z0Str);
Write(' Type in Z0 ',Z0Str,' ');
GotoXY(14,25);
Read(Z0);
Str(R:5:3,RStr);
GotoXY(2,25);
Write(' Type in R ',RStr,' ');
GotoXY(14,25);
Read(R);
Str(X:5:3,XStr);
GotoXY(2,25);
Write(' Type in X ',XStr,' ');
GotoXY(14,25);
Read(X);
If X=0 then X:=1E-6;
If R=0 then R:=1E-6;
END;
PROCEDURE NormalizeX;
BEGIN
Rn := R/Z0;
Xn := X/Z0;
{ Bn := B*Z0;
Gn := G*Z0;
}END;
PROCEDURE background;
BEGIN
GraphColorMode;
Palette(2);
Circle(CenterX,CenterY,100,1);
Circle(CenterX+50,CenterY,50,1);
Circle(CenterX+75,CenterY,25,1);
Circle(CenterX+25,CenterY,75,1);
Circle(CenterX-50,CenterY,50,2);
Circle(CenterX-75,CenterY,25,2);
Circle(CenterX-25,CenterY,75,2);
END;
PROCEDURE PlotRho;
BEGIN
RhoReal := round(100*RhoRealReal);
RhoImag := round(100*RhoImagReal);
Xplot := CenterX + RhoReal;
Yplot := CenterY + RhoImag;
Circle(Xplot,Yplot,3,3);
END;
PROCEDURE CalcRhoFromZ;
BEGIN
DeltaX := Sqr(Rn+1)+Sqr(Xn);
RhoRealReal:= (Sqr(Rn)-1+Sqr(Xn))/DeltaX;
RhoImagReal:= 2*Xn/DeltaX;
END;
PROCEDURE CalcZfromRho;
BEGIN
DeltaZRho := Sqr(1-RhoRealReal)+Sqr(RhoImagReal);
Rn:= (1-Sqr(RhoRealReal)-Sqr(RhoImagReal))/DeltaZRho;
Xn:= 2*RhoImagReal/DeltaZRho;
END;
PROCEDURE CalcRhoFromY;
BEGIN
DeltaB := Sqr(Gn+1)+Sqr(Bn);
RhoRealReal:= (1-Sqr(Gn)-Sqr(Bn))/DeltaB;
RhoImagReal:=-2*Bn/DeltaB;
END;
PROCEDURE CalcYfromRho;
BEGIN
DeltaYRho := Sqr(1+RhoRealReal)+Sqr(RhoImagReal);
Gn:= (1-Sqr(RhoRealReal)-Sqr(RhoImagReal))/DeltaYRho;
Bn:=-2*RhoImagReal/DeltaYRho;
END;
PROCEDURE CalcPolarRho;
BEGIN
RhoMagReal := Sqrt(Sqr(RhoRealReal)+Sqr(RhoImagReal));
RhoAngReal := ArcTan(RhoImagReal/RhoRealReal);
IF (RhoRealReal<0) THEN RhoAngReal := RhoAngReal - Pi;
END;
PROCEDURE CalcRectRho;
BEGIN
RhoRealReal := RhoMagReal*Cos(RhoAngReal);
RhoImagReal := RhoMagReal*Sin(RhoAngReal);
END;
PROCEDURE CalcVSWR;
BEGIN
VSWR :=(1+RhoMagReal)/(1-RhoMagReal);
END;
PROCEDURE IncrementX;
BEGIN
CalcZfromRho;
Xn := Xn + IncX;
N := N+1;
CalcRhoFromZ;
PlotRho;
NewWrite;
XincReal := N*IncX*Z0;
GoToXY(4,22);
Write('X',M );
Str(XincReal:5:3,XincStr);
GoToXY(4,23);
Write(XincStr);
Str(M,MStr);
MStr := Concat('X',MStr);
DataLabel[M] := MStr;
DataValue[M] := XincStr;
END;
PROCEDURE DecrementX;
BEGIN
CalcZfromRho;
Xn := Xn - IncX;
N := N-1;
CalcRhoFromZ;
PlotRho;
NewWrite;
XincReal := N*IncX*Z0;
GoToXY(4,22);
Write('X',M );
Str(XincReal:5:3,XincStr);
GoToXY(4,23);
Write(XincStr);
Str(M,MStr);
MStr := Concat('X',MStr);
DataLabel[M] := MStr;
DataValue[M] := XincStr;
END;
PROCEDURE Decrement10X;
BEGIN
CalcZfromRho;
Xn := Xn - 10*IncX;
N := N-10;
CalcRhoFromZ;
PlotRho;
NewWrite;
XincReal := N*IncX*Z0;
GoToXY(4,22);
Write('X',M );
Str(XincReal:5:3,XincStr);
GoToXY(4,23);
Write(XincStr);
Str(M,MStr);
MStr := Concat('X',MStr);
DataLabel[M] := MStr;
DataValue[M] := XincStr;
END;
PROCEDURE Increment10X;
BEGIN
CalcZfromRho;
Xn := Xn + 10*IncX;
N := N + 10;
CalcRhoFromZ;
PlotRho;
NewWrite;
XincReal := N*IncX*Z0;
GoToXY(4,22);
Write('X',M );
Str(XincReal:5:3,XincStr);
GoToXY(4,23);
Write(XincStr);
Str(M,MStr);
MStr := Concat('X',MStr);
DataLabel[M] := MStr;
DataValue[M] := XincStr;
END;
PROCEDURE IncrementB;
BEGIN
CalcYfromRho;
Bn := Bn + IncB;
N := N + 1;
CalcRhoFromY;
PlotRho;
NewWrite;
BincReal := N*IncB/Z0;
GoToXY(4,22);
Write('B',M );
Str(BincReal:5:3,BincStr);
GoToXY(4,23);
Write(BincStr);
Str(M,MStr);
MStr := Concat('B',MStr);
DataLabel[M] := MStr;
DataValue[M] := BincStr;
END;
PROCEDURE DecrementB;
BEGIN
CalcYfromRho;
Bn := Bn - IncB;
N := N - 1;
CalcRhoFromY;
PlotRho;
NewWrite;
BincReal := N*IncB/Z0;
GoToXY(4,22);
Write('B',M );
Str(BincReal:5:3,BincStr);
GoToXY(4,23);
Write(BincStr);
Str(M,MStr);
MStr := Concat('B',MStr);
DataLabel[M] := MStr;
DataValue[M] := BincStr;
END;
PROCEDURE Increment10B;
BEGIN
CalcYfromRho;
Bn := Bn + 10*IncB;
N := N + 10;
CalcRhoFromY;
PlotRho;
NewWrite;
BincReal := N*IncB/Z0;
GoToXY(4,22);
Write('B',M );
Str(BincReal:5:3,BincStr);
GoToXY(4,23);
Write(BincStr);
Str(M,MStr);
MStr := Concat('B',MStr);
DataLabel[M] := MStr;
DataValue[M] := BincStr;
END;
PROCEDURE Decrement10B;
BEGIN
CalcYfromRho;
Bn := Bn - 10*IncB;
N := N - 10;
CalcRhoFromY;
PlotRho;
NewWrite;
BincReal := N*IncB/Z0;
GoToXY(4,22);
Write('B',M );
Str(BincReal:5:3,BincStr);
GoToXY(4,23);
Write(BincStr);
Str(M,MStr);
MStr := Concat('B',MStr);
DataLabel[M] := MStr;
DataValue[M] := BincStr;
END;
PROCEDURE DecrementRho;
BEGIN
CalcPolarRho;
RhoAngReal := RhoAngReal + IncRho;
CalcRectRho;
N := N + 1;
PlotRho;
NewWrite;
RhoIncReal := -90*N*IncRho/Pi;
GoToXY(4,22);
Write('A',M );
Str(RhoIncReal:5:3,RhoIncStr);
GoToXY(4,23);
Write(RhoIncStr);
Str(M,MStr);
MStr := Concat('A',MStr);
DataLabel[M] := MStr;
DataValue[M] := RhoincStr;
END;
PROCEDURE IncrementRho;
BEGIN
CalcPolarRho;
RhoAngReal := RhoAngReal - IncRho;
CalcRectRho;
N := N - 1;
PlotRho;
NewWrite;
RhoIncReal := -90*N*IncRho/Pi;
GoToXY(4,22);
Write('A',M );
Str(RhoIncReal:5:3,RhoIncStr);
GoToXY(4,23);
Write(RhoIncStr);
Str(M,MStr);
MStr := Concat('A',MStr);
DataLabel[M] := MStr;
DataValue[M] := RhoincStr;
END;
PROCEDURE Decrement10Rho;
BEGIN
CalcPolarRho;
RhoAngReal := RhoAngReal + 10*IncRho;
CalcRectRho;
N := N + 10;
PlotRho;
NewWrite;
RhoIncReal := -90*N*IncRho/Pi;
GoToXY(4,22);
Write('A',M );
Str(RhoIncReal:5:3,RhoIncStr);
GoToXY(4,23);
Write(RhoIncStr);
Str(M,MStr);
MStr := Concat('A',MStr);
DataLabel[M] := MStr;
DataValue[M] := RhoincStr;
END;
PROCEDURE Increment10Rho;
BEGIN
CalcPolarRho;
RhoAngReal := RhoAngReal - 10*IncRho;
CalcRectRho;
N := N - 10;
PlotRho;
NewWrite;
RhoIncReal := -90*N*IncRho/Pi;
GoToXY(4,22);
Write('A',M );
Str(RhoIncReal:5:3,RhoIncStr);
GoToXY(4,23);
Write(RhoIncStr);
Str(M,MStr);
MStr := Concat('A',MStr);
DataLabel[M] := MStr;
DataValue[M] := RhoincStr;
END;
PROCEDURE ChangeX;
BEGIN
GoToXY(2,19);
Write('MOVE MODE ');
GoToXY(2,20);
Write('F10 to COMMAND ');
GoToXY(2,21);
TextColor(1);
Write('Changing X ');
TextColor(3);
GoToXY(2,22);
Write(' ');
GoToXY(2,23);
Write(' ');
GoToXY(2,24);
Write(' ');
GoToXY(2,25);
Write(' ');
N := 0; M := M + 1; done := false;
WHILE Done = false do
BEGIN
Read (Kbd,Ch);
IF (Ch = #27) AND KeyPressed THEN
Read (Kbd,Ch);
IF Ch in [#59..#68] THEN
Case Ch of
#59 : IncrementX;
#60 : DecrementX;
#61 : Increment10X;
#62 : Decrement10X;
#68 : Done := True;
END;
END;
done := false;
GoToXY(2,20);
Write(' ');
GoToXY(2,21);
Write(' ');
END;
PROCEDURE ChangeB;
BEGIN
GoToXY(2,19);
Write('MOVE MODE ');
GoToXY(2,20);
Write('F10 to COMMAND ');
GoToXY(2,21);
TextColor(2);
Write('Changing B ');
TextColor(3);
GoToXY(2,22);
Write(' ');
GoToXY(2,23);
Write(' ');
GoToXY(2,24);
Write(' ');
GoToXY(2,25);
Write(' ');
N := 0; M := M + 1; done := false;
WHILE Done = false do
BEGIN
Read (Kbd,Ch);
IF (Ch = #27) AND KeyPressed THEN
Read (Kbd,Ch);
IF Ch in [#59..#68] THEN
Case Ch of
#59 : IncrementB;
#60 : DecrementB;
#61 : Increment10B;
#62 : Decrement10B;
#68 : Done := True;
END;
END;
done := false;
GoToXY(2,20);
Write(' ');
GoToXY(2,21);
Write(' ');
END;
PROCEDURE ChangeRho;
BEGIN
GoToXY(2,19);
Write('MOVE MODE ');
GoToXY(2,20);
Write('F10 to COMMAND ');
GoToXY(2,21);
Write('Changing A ');
GoToXY(2,22);
Write(' ');
GoToXY(2,23);
Write(' ');
GoToXY(2,24);
Write(' ');
GoToXY(2,25);
Write(' ');
N := 0; M := M + 1; done := false;
WHILE Done = false do
BEGIN
Read (Kbd,Ch);
IF (Ch = #27) AND KeyPressed THEN
Read (Kbd,Ch);
IF Ch in [#59..#62,#68] THEN
Case Ch of
#59 : IncrementRho; (* F1 *)
#60 : DecrementRho; (* F2 *)
#61 : Increment10Rho; (* F3 *)
#62 : Decrement10Rho; (* F4 *)
#68 : Done := True; (* F10 *)
END;
END;
done := false;
GoToXY(2,20);
Write(' ');
GoToXY(2,21);
Write(' ');
END;
PROCEDURE DataTable;
BEGIN
GoToXY(4,2); Write('DATA TABLE');
For index := 1 to M do
BEGIN
GoToXY(4,(2+index));
Write(DataLabel[index],' = ',DataValue[index]);
END;
GoToXY(4,(3+index)); Write(' ');
END;
BEGIN
Done := false;
R := 1; X := 1; Z0 :=1;
Title;
Help;
Start:
InputVariables;
ReDo:
M := 0;
NormalizeX;
CalcRhoFromZ;
Background;
NewWrite;
PlotRho;
While Done = false do
BEGIN
GoToXY(2,19);
Write('COMMAND MODE');
GoToXY(2,21);
TextColor(1);
Write('Change X = F5 ');
GoToXY(2,22);
TextColor(2);
Write('Change B = F6 ');
GoToXY(2,23);
TextColor(3);
Write('Change Angl = F7');
GoToXY(2,24);
Write('Redo=F8 New=F9 Quit');
GoToXY(2,25);
TextColor(2);
Write('DATA TABLE = ALT F9');
GoToXY(15,25);
TextColor(3);
Read(Kbd,Ch);
IF (Ch = Chr(27)) AND KeyPressed THEN
Read(Kbd,Ch);
IF Ch in [#71,#63..#68,#112,'q','Q'] THEN
Case Ch of
#63 : ChangeX; (* F5 *)
#64 : ChangeB; (* F6 *)
#65 : ChangeRho; (* F7 *)
#66 : GoTo ReDo; (* F8 *)
#67 : GoTo start; (* F9 *)
'Q' : Done := True; (* Quit *)
'q' : Done := True; (* Quit *)
#112 : DataTable; (* Alt F9 *)
#71 : Help;
END;
END;
TextMode;
GoToXY(0,5);
WriteLn('DATA TABLE');
For index := 1 to M do
BEGIN
WriteLn(DataLabel[index],' = ',DataValue[index]);
END;
END.