C   From the feeble mind of N3GO - Gary O'Neil - March 17, 1995
C               End-fed Zepp/J-pole design calculations
C
C   Converted to Fortran 77 by SM5SXL Mats Peterson 2002-12-19

      PROGRAM JPOLE
      PRINT *, 'J-pole design calculations by N3GO Gary O''Neil'
      PRINT *, '-----------------------------------------------'
   10 PRINT *, ' '
      PRINT *, '1  Antenna design calculations'
      PRINT *, '2  Antenna adjustment calculations'
      PRINT *, '3  Velocity factor calculations'
      PRINT *, '0  Quit'
      CALL GETINT(N)
      IF (N .EQ. 1) THEN
         CALL DESIGN
      ELSE IF (N .EQ. 2) THEN
         CALL TUNING
      ELSE IF (N .EQ. 3) THEN
         CALL VELOC
      ELSE IF (N .EQ. 0) THEN
         STOP
      END IF
      GO TO 10
      END

C **********************************************************************

      SUBROUTINE DESIGN()
      IMPLICIT DOUBLE PRECISION (A-H, O-Z)
      PARAMETER (PI = 3.14159265358979323846D0)

C  ZA = antenna feedpoint impedance, ZF = feedline impedance, and
C  Z0 = the impedance of the matching transmission line.
C  ZA = 3500 TO 5000 Ohms for end fed dipole.
C  ZF = 50 Ohms in my analysis
C  Z0 = 300 Ohms nominal ** Note:  maximum = SQRT(ZA*ZF)

      ZA = 5000.D0
      ZF = 50.D0
      Z0 = 300.D0

      ZMAX = SQRT(ZA * ZF)
      IF (Z0 .GT. ZMAX) THEN
         PRINT 110,
     $   'Use matching transmission line impedance less than ',
     $   ZMAX, ' Ohms'
         PRINT *, 'Change term in data statement to reflect a lower ',
     $   'impedance'
         RETURN
      END IF

      PRINT 100, 'Feedline impedance (Ohms):            ', ZF
      PRINT 100, 'Matching transmission line impedance: ', Z0
      PRINT *, 'Frequency (MHz):'
      CALL GETFLT(F)

C  V = velocity factor of transmission line used for matching network

      PRINT *, 'Velocity factor:' 
      CALL GETFLT(V)

C  ZP = the antenna impedance ZA normalized to the stub impedance Z0

C     Equation A1
   10 ZP = ZA / Z0

C  RHO = the antenna reflection coefficient with respect to the
C  matching stub impedance

C     Equation A2
      RHO = (ZP - 1) / (ZP + 1)

C  YF = the feedline admittance 1/ZF normalized to the stub admittance
C  1/Z0

C     Equation A3
      YF = Z0 / ZF

C  B =  the normalized susceptance of the shorted stub section

C     Equation A4
      B = SQRT((RHO**5 * (YF+1.D0)**2 - (YF-1.D0)**2) / (1-RHO**2))

C  X2 = the normalized reactance of the shorted stub section

C     Equation A5
      X2 = 1 / B
C     Equation A6
      XL2 = ATAN(X2) * (180.D0 / PI)
C     Equation A7 (real)
      R = YF / (YF**2 + B**2)
C     Equation A7 (imaginary)
      X1 = B / (YF**2 + B**2)
      XL1 = 90.D0 - (ATAN(X1) * (180.D0 / PI))

C  The constant 5606 is 95 per cent of the speed of light in inches
C  for a half wavelength at 1 MHz

C     Equation A9 - A
      DIPOLE = 5606.D0 / F
C  The constant 32.78 is the speed of light in inches/degree/MHz
C     Equation A9 - B
      SERIES = 32.78D0 * V * (XL1 / F)
C     Equation A9 - C
      SHUNT = 32.78D0 * V * (XL2 / F)

      PRINT 100, 'Frequency in MHz =   ', F
      PRINT 110, 'Wavelength in air =  ',
     $ (299.7D0 * 39.37D0 / F) * 2.54D0, ' cm'
      PRINT 110, 'Length of stub =     ',
     $ (XL1 + XL2) / 360.D0, ' wavelengths'
      PRINT 110, 'Height of ''tap'' =    ',
     $ XL2 / 360.D0, ' wavelengths'
      PRINT 110, 'Dipole length =      ',
     $ DIPOLE * 2.54D0, ' cm'
      PRINT 110, 'Series trans. line = ',
     $ SERIES * 2.54D0, ' cm'
      PRINT 110, 'Shunt trans. line =  ',
     $ SHUNT * 2.54D0, ' cm'
      PRINT 110, 'Stub length =        ',
     $SERIES * 2.54D0 + SHUNT * 2.54D0, ' cm'
      PRINT 110, 'Overall length =     ',
     $ SERIES * 2.54D0 + SHUNT * 2.54D0 + DIPOLE * 2.54D0, ' cm'
      PRINT *, ' '
      PRINT *, 'Impedances used for this calculation are as follows:'
      PRINT *, ' '
      PRINT 110, 'Impedance of end-fed dipole:                  ',
     $ ZA, ' Ohms'
      PRINT 110, 'Antenna system feedline impedance:            ',
     $ ZF, ' Ohms'
      PRINT 110, 'Matching section transmission line impedance: ',
     $ Z0, ' Ohms'
      PRINT 110, 'Maximum usable matching line impedance:       ',
     $ ZMAX, ' Ohms'
      PRINT 100, 'Velocity factor of matching section:          ',
     $ V
      PRINT *, 'New velocity factor (enter zero to quit):'
      CALL GETFLT(V)
      IF (V .EQ. 0.D0) RETURN
      GO TO 10
  100 FORMAT (1X, A, F8.3)
  110 FORMAT (1X, A, F8.3, A)
      END

C **********************************************************************

      SUBROUTINE TUNING()
      IMPLICIT DOUBLE PRECISION (A-H, O-Z)

C  Antenna adjustment calculations by N3GO  03/24/95

      PRINT *, 'Frequency (MHz) where minimum VSWR is desired:'
      CALL GETFLT(F2)

   10 PRINT *, 'Measured minimum VSWR frequency (MHz):'
      CALL GETFLT(F1)
      IF (F1 .EQ. 0.D0) RETURN

C     Equation B1
      DL = (491.78D0 * (F2 - F1)) / (F1 * F2)
      IF (DL .EQ. 0.D0) THEN
         PRINT *, 'Good job!'
         RETURN
      END IF
      IF (DL .GT. 0.D0) THEN
         PRINT 110, 'Reduce the length of the halfwave element by: ',
     $   DL * 12.D0 * 2.54D0, ' cm'
      ELSE
         PRINT 110, 'Increase the length of the halfwave element by: ',
     $   ABS(DL) * 12.D0 * 2.54D0, ' cm'
      END IF
      GO TO 10
  100 FORMAT (1X, A, F8.3)
  110 FORMAT (1X, A, F8.3, A)
      END

C **********************************************************************

      SUBROUTINE VELOC()
      IMPLICIT DOUBLE PRECISION (A-H, O-Z)
      CHARACTER ANS

      PRINT *, 'Desired operating frequency (MHz):'
      CALL GETFLT(F1)
      PRINT *, 'Estimate the velocity factor of the transmission line:'
      CALL GETFLT(V)
      PRINT *, 'Cut an electrical half wavelength sample.'

C     Equation C1
      XL1 = (V * 491.78D0) / F1

      PRINT 110, 'Cut sample length to: ', XL1 * 12 * 2.54D0, ' cm'

   10 PRINT *, 'Frequency (MHz) where VSWR is lowest:'
      CALL GETFLT(F2)

C  Compute new velocity factor estimate based on vswr measurement result

      V = XL1 * F2 / 491.78D0

      PRINT 100, 'Current velocity factor estimate: ', V

C  Compute new sample length based on new velocity factor estimate

      XL2 = 491.78D0 * V / F1

C  Compute length change required for desired frequency sample

      DL = XL2 - XL1

      PRINT 120, 'Adjusted length of ', F1, ' MHz sample: ',
     $ XL2 * 12.D0 * 2.54D0
      PRINT 110, 'Does the VSWR at ', F2,
     $ ' MHz equal that of the dummy load?'
      CALL GETSTR(ANS)
      IF (ANS .EQ. 'y') GO TO 20

      IF (DL .LE. 0.D0) THEN
         PRINT 110, 'Reduce the stub length by ', 
     $   ABS(DL) * 12.D0 * 2.54D0, ' cm'
      ELSE
         PRINT 110, 'Increase the stub length by ', 
     $   DL * 12.D0 * 2.54D0, ' cm'
      END IF
      XL1 = XL2
      GO TO 10

   20 PRINT *, 'Measured physical length (cm):'
      CALL GETFLT(XL)
      XL = XL / 2.54D0 / 12.D0

C     Equation C3 in appendix C
      PRINT 100, 'The velocity factor is: ', XL * F2 / 491.78D0
      RETURN
  100 FORMAT (1X, A, F8.3)
  110 FORMAT (1X, A, F8.3, A)
  120 FORMAT (1X, A, F8.3, A, F8.3)
      END
.
