-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrl-csv-to-chirp-csv
executable file
·95 lines (87 loc) · 2.11 KB
/
arrl-csv-to-chirp-csv
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
from csv import DictReader, DictWriter
from decimal import Decimal
from sys import argv, stdout
fieldnames = (
"Location",
"Name",
"Frequency",
"Duplex",
"Offset",
"Tone",
"rToneFreq",
"cToneFreq",
"DtcsCode",
"DtcsPolarity",
"Mode",
"Comment",
)
# 'TStep', 'Skip', 'Comment', 'URCALL', 'RPT1CALL', 'RPT2CALL')
def drop_decimals(d):
# Decimal.normalize gives 2E+1 for 20...
d = str(d)
if "." in d:
d = d.rstrip("0").rstrip(".")
return d
c = open(argv[1], "r")
# Discard the ARRL DATA_SPEC_VERSION line
c.readline()
d = DictReader(c)
w = DictWriter(stdout, fieldnames)
# w.writeheader()
w.writerow(dict(zip(fieldnames, fieldnames)))
i = 0
for row in d:
in_freq = Decimal(row["INPUT_FREQ"])
out_freq = Decimal(row["OUTPUT_FREQ"])
duplex = "off"
offset = Decimal(0)
if out_freq < in_freq:
duplex = "+"
offset = in_freq - out_freq
elif out_freq > in_freq:
duplex = "-"
offset = out_freq - in_freq
tone = None
if row["CTCSS_IN"]:
tone = "Tone"
elif row["DCS_CDCSS"]:
tone = "DTCS"
mode = None
if row["FM_WIDE"] == "Y":
mode = "FM"
elif row["FM_NARROW"] == "Y":
mode = "NFM"
else:
continue
if "Y" in (
row["DSTAR_DV"],
row["DSTAR_DD"],
row["DMR"],
row["FUSION"],
row["P25_PHASE_1"],
row["P25_PHASE_2"],
row["NXDN_DIGITAL"],
row["ATV"],
row["DATV"],
):
# These are not Analog modes
continue
w.writerow(
{
"Location": i,
"Name": row["CALL"],
"Frequency": row["OUTPUT_FREQ"],
"Duplex": duplex,
"Offset": drop_decimals(offset),
"Tone": tone,
"rToneFreq": row["CTCSS_IN"] or "88.5",
"cToneFreq": row["CTCSS_OUT"] or "88.5",
"DtcsCode": row["DCS_CDCSS"] or "23",
"DtcsPolarity": "NN",
"Mode": mode,
"Comment": " ".join((row["CALL"], row["CITY"])),
}
)
i += 1
c.close()