diff options
-rwxr-xr-x | calctenna.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/calctenna.py b/calctenna.py new file mode 100755 index 0000000..23deff8 --- /dev/null +++ b/calctenna.py @@ -0,0 +1,78 @@ +#!/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) |