#!/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',
required=True,
metavar='frequency',
help='desired frequency in Hz (e.g. 144800000 or 433e6, ...',
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()
if not args.frequency:
argparser.print_usage()
exit()
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)