aboutsummaryrefslogtreecommitdiff
path: root/calctenna.py
blob: 23deff8b04b681ef3a78ee308cd73c29acda3107 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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)
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