aboutsummaryrefslogblamecommitdiff
path: root/calctenna.py
blob: 23deff8b04b681ef3a78ee308cd73c29acda3107 (plain) (tree)













































































                                                                            
#!/usr/bin/env python

# calctenna
# antenna calculator
# 2020-12-19
# Oliver Meckmann

import argparse

def run_argparse():
    argparser = argparse.ArgumentParser()
    argparser.add_argument(
        '-f',
        '--frequency',
        metavar='frequency',
        help='Desired frequency in Hz',
        nargs='?',
        default='100e6'
    )
    argparser.add_argument(
        '-V',
        '--velocity-factor',
        metavar='velocity_factor',
        nargs='?',
        default='0.951'
    )
    argparser.add_argument(
        '-q',
        '--quiet',
        help='print only result',
        action='store_true'
    )
    args = argparser.parse_args()

    return args

def calc(args):
    c = 299792458 # speed of light

    try:
        f = float(args.frequency)
    except:
        print("Sorry, frequency input invalid")
        exit()

    if f <= 0.0:
        print("Sorry, frequency must be > 0")
        exit()

    try:
        V = float(args.velocity_factor)
    except:
        print("Sorry, velocity factor input invalid")
        exit()

    if V < 0.0 or V > 1.0:
        print("Sorry, velocity factor can only be between 0.0 and 1.0")
        exit()

    wavelength = float(c) / f
    wavelength_2 = wavelength/2
    wavelength_4 = wavelength/4
    dipole_leg_length = wavelength/4 * V

    return (wavelength, wavelength_2, wavelength_4, dipole_leg_length)

if __name__ == '__main__':
    args = run_argparse()
    (wavelength, wavelength_2, wavelength_4, dipole_leg_length) = calc(args)

    if not args.quiet:
        print("Desired Frequency: " + str(args.frequency) + " Hz")
        print("Wavelength: %.3f m" % wavelength)
        print("Wavelength / 2: %.3f m" % wavelength_2)
        print("Wavelength / 4: %.3f m" % wavelength_4)
        print("Velocity factor: " + str(args.velocity_factor))
        print("-> Dipole leg length (lambda/4): ", end='')
    print("%.3f m" % dipole_leg_length)
in each repos: see "about"-tab (if existing) for more details / README.
mailto contact at omeckman dot net
all timestamps in UTC (German winter time: UTC+01:00, summer time: UTC+02:00)
dark theme is a modded version of: https://gist.github.com/Yoplitein/f4b671a2ec70c9e743fa