Skip to content

Commit 439511f

Browse files
committed
goadifstat: add query type cqz
1 parent 9d64849 commit 439511f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

goadifstat/goadifstat.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// goadifstat: check statistics of ADIF ADI files
22
// by Kenji Rikitake, JJ1BDX
33
// Usage: goadifstat [-f infile] [-o outfile] -q query type
4-
// Valid query types: bands, country, dxcc, gridsquare, modes, nqso, submodes
4+
// Valid query types: bands, country, cqz, dxcc, gridsquare, modes, nqso, submodes
55

66
package main
77

@@ -29,6 +29,7 @@ var bandList = []string{
2929

3030
var mapBand map[string]int
3131
var mapCountry map[string]int
32+
var mapCqz map[int]bool
3233
var mapDxcc map[int]bool
3334
var mapGrid map[string]bool
3435
var mapMode map[string]int
@@ -37,6 +38,7 @@ var mapSubmode map[string]int
3738
func initStatMaps() {
3839
mapBand = make(map[string]int)
3940
mapCountry = make(map[string]int)
41+
mapCqz = make(map[int]bool)
4042
mapDxcc = make(map[int]bool)
4143
mapGrid = make(map[string]bool)
4244
mapMode = make(map[string]int)
@@ -83,6 +85,23 @@ func updateStatMaps(record adifparser.ADIFRecord) {
8385
}
8486
}
8587

88+
// cqz
89+
key, err = record.GetValue("cqz")
90+
if err != nil && err != ErrNoSuchField {
91+
fmt.Fprint(os.Stderr, err)
92+
} else if key != "" {
93+
// Cqz values are integers
94+
keynum, err = strconv.Atoi(key)
95+
if err != nil && err != ErrNoSuchField {
96+
fmt.Fprint(os.Stderr, err)
97+
} else {
98+
_, exists = mapCqz[keynum]
99+
if !exists {
100+
mapCqz[keynum] = true
101+
}
102+
}
103+
}
104+
86105
// dxcc
87106
key, err = record.GetValue("dxcc")
88107
if err != nil && err != ErrNoSuchField {
@@ -166,6 +185,16 @@ func statOutput(query *string, writer *bufio.Writer,
166185
fmt.Fprintf(writer, "%s: %d\n", k, mapCountry[k])
167186
}
168187
fmt.Fprintln(writer, "(TOTAL):", reader.RecordCount())
188+
case *query == "cqz":
189+
keys := make([]int, 0, len(mapCqz))
190+
for k := range mapCqz {
191+
keys = append(keys, k)
192+
}
193+
sort.Ints(keys)
194+
for _, n := range keys {
195+
fmt.Fprintf(writer, "%d ", n)
196+
}
197+
fmt.Fprintf(writer, "\n")
169198
case *query == "dxcc":
170199
keys := make([]int, 0, len(mapDxcc))
171200
for k := range mapDxcc {
@@ -227,7 +256,7 @@ func main() {
227256
fmt.Fprintf(flag.CommandLine.Output(),
228257
"Usage: %s [-f infile] [-o outfile] -q query type\n", execname)
229258
fmt.Fprintln(flag.CommandLine.Output(),
230-
"Valid query types: bands, country, dxcc, gridsquare, modes, nqso, submodes")
259+
"Valid query types: bands, country, cqz, dxcc, gridsquare, modes, nqso, submodes")
231260
flag.PrintDefaults()
232261
}
233262

0 commit comments

Comments
 (0)