start:
CLS
PRINT " This program by W0IVJ calculates the values for a high-pass T-network"
PRINT " tuner assuming lossless capacitors:"
PRINT
PRINT "   ------| |---------| |--------"
PRINT "   |     Ci     |      Co       |"
PRINT "   |            |               @"
PRINT "   \            $               @ Xload"
PRINT "   /            $               @"
PRINT "   \ Ri         $ L             |"
PRINT "   /            $               /"
PRINT "   \            $               \ Rload"
PRINT "   |            |               /"
PRINT "   |            |               |"
PRINT "   ------------------------------"
PRINT
PRINT " Frequency in Mhz ";
INPUT F$
F = VAL(F$)
IF F = 0 THEN
  PRINT
  PRINT " Impedance cannot be matched."
  GOTO done
END IF
PRINT " Input Resistance in ohms ";
INPUT Ri$
Ri = VAL(Ri$)
IF Ri = 0 THEN
  PRINT
  PRINT " Impedance cannot be matched."
  GOTO done
END IF
PRINT " Output Load Resistance in ohms ";
INPUT Rload$
Rload = VAL(Rload$)
IF Rload = 0 THEN
  PRINT
  PRINT " Impedance cannot be matched."
  GOTO done
END IF
PRINT " Output Load Reactance in ohms (use a - for capacitive reactance) ";
INPUT Xload$
Xload = VAL(Xload$)
PRINT " Maximum value for the series capacitors in pf ";
INPUT Cmax1$
Cmax1 = VAL(Cmax1$)
IF Cmax1 = 0 THEN
  PRINT
  PRINT " Impedance cannot be matched."
  GOTO done
END IF
PRINT " Unloaded Coil Q (250 is not unreasonable for a good coil) ";
INPUT Ql$
Ql = VAL(Ql$)
Cmax2 = Cmax1
F = F * 1000000!
pi = 3.14159
Xcimin = 1 / (2 * pi * F * Cmax2 * 1E-12)
Qmin = Xcimin / Ri
DO
  NoMatch = 0
  Cmax = Cmax1 * 1E-12
  Xmax = -1 / (2 * pi * F * Cmax)
  Xco = Xmax
  Xs = Xmax + Xload
  Rp = (Rload ^ 2 + Xs ^ 2) / Rload
  Xp = (Rload ^ 2 + Xs ^ 2) / Xs
  IF Ri >= Rp THEN
    NoMatch = 1
    GOTO NxtLoop
  END IF
  Q = SQR((Rp / Ri) - 1)
  IF Q < Qmin THEN
    NoMatch = 1
    GOTO NxtLoop
  END IF
  Xa = Rp / Q
  Xci = Q * Ri
  IF Xp < 0 THEN
    Xb = -Xp
    Xl = 1 / ((1 / Xa) + (1 / Xb))
  ELSE
    Xb = Xp
    Xden = (1 / Xa) - (1 / Xb)
    IF Xden <= 0 THEN
      NoMatch = 1
      GOTO NxtLoop
    END IF
    Xl = 1 / Xden
  END IF
NxtLoop:
  Cmax1 = Cmax1 - .1
LOOP UNTIL (Cmax1 <= 5) OR NoMatch = 0
IF NoMatch = 1 THEN
  PRINT
  PRINT " Impedance cannot be matched."
  GOTO done
END IF
Ci = 1 / (2 * pi * F * Xci)
L = Xl / (2 * pi * F)
Co = -1 / (2 * pi * F * Xco)
Vi = SQR(Ri * 1000)
Ii = Vi / Ri
Vci = Xci * Ii
Vl = SQR(Vi ^ 2 + Vci ^ 2)
Rl = Xl / Ql
Zl = SQR(Xl ^ 2 + Rl ^ 2)
Il = Vl / Zl
Pl = Il ^ 2 * Rl
IF Pl >= 1000 THEN
  PRINT
  PRINT " Impedance cannot be matched."
  GOTO done
END IF
PercentLoss = (Pl / 1000) * 100
Loss = (1000 - Pl) / 1000
DbLoss = -10 * (LOG(Loss) / LOG(10))
L = L * 1000000!
Ci = Ci * 1E+12
Co = Co * 1E+12
PRINT
PRINT " Ci =  ";
PRINT USING "###.##"; Ci;
PRINT " pf"
PRINT " L  =  ";
PRINT USING "###.##"; L;
PRINT " uh"
PRINT " Co =  ";
PRINT USING "###.##"; Co;
PRINT " pf"
PRINT " Circuit Q  =  ";
PRINT USING "##.#"; Q
PRINT " Tuner Loss  =  ";
PRINT USING "##.#"; PercentLoss;
PRINT " %  ;";
PRINT USING "##.##"; DbLoss;
PRINT " db"
done:
PRINT
PRINT " Another Calculation (Y/N)  ";
INPUT Ans$
IF (Ans$ = "N") OR (Ans$ = "n") THEN
  GOTO ReallyDone
ELSE
  GOTO start
END IF
ReallyDone:
END