up
This commit is contained in:
@@ -58,6 +58,60 @@ func NameForDXCC(n int) string {
|
||||
return strings.Title(name) //nolint:staticcheck // ASCII entity names
|
||||
}
|
||||
|
||||
// ZoneByCallDistrict returns the CQ and ITU zone for a callsign in a country
|
||||
// that is split across zones by call district (USA, Australia…). cty.dat and
|
||||
// ClubLog's cty.xml only carry one zone per entity, so loggers apply this
|
||||
// district→zone convention to get e.g. W6 = CQ3/ITU6 instead of the entity
|
||||
// default CQ5/ITU8. ok=false means no district rule applies (use the entity
|
||||
// default). The district is the first digit of the callsign.
|
||||
func ZoneByCallDistrict(adif int, call string) (cqz, ituz int, ok bool) {
|
||||
d := districtDigit(call)
|
||||
if d < 0 {
|
||||
return 0, 0, false
|
||||
}
|
||||
switch adif {
|
||||
case 291: // United States — standard district defaults (state-level
|
||||
// exceptions exist, but this matches what Log4OM/DXKeeper default to).
|
||||
if z, o := usDistrictZones[d]; o {
|
||||
return z[0], z[1], true
|
||||
}
|
||||
case 150: // Australia — VK6/VK8 (west/north) are CQ29/ITU58, rest CQ30/ITU59.
|
||||
if d == 6 || d == 8 {
|
||||
return 29, 58, true
|
||||
}
|
||||
return 30, 59, true
|
||||
}
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
// usDistrictZones maps a US call district digit to its {CQ, ITU} zone.
|
||||
var usDistrictZones = map[int][2]int{
|
||||
0: {4, 7}, 1: {5, 8}, 2: {5, 8}, 3: {5, 8}, 4: {5, 8},
|
||||
5: {4, 7}, 6: {3, 6}, 7: {3, 6}, 8: {5, 8}, 9: {4, 8},
|
||||
}
|
||||
|
||||
// firstDigit returns the first 0-9 digit in a callsign, or -1 if none.
|
||||
func firstDigit(call string) int {
|
||||
for i := 0; i < len(call); i++ {
|
||||
if call[i] >= '0' && call[i] <= '9' {
|
||||
return int(call[i] - '0')
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// districtDigit returns the effective call-area digit: a trailing "/N" (single
|
||||
// digit) re-homes the call to area N (W6ABC/7 → area 7), otherwise the first
|
||||
// digit of the call.
|
||||
func districtDigit(call string) int {
|
||||
if i := strings.LastIndex(call, "/"); i >= 0 && i == len(call)-2 {
|
||||
if c := call[len(call)-1]; c >= '0' && c <= '9' {
|
||||
return int(c - '0')
|
||||
}
|
||||
}
|
||||
return firstDigit(call)
|
||||
}
|
||||
|
||||
// EntityNumberName pairs a DXCC entity number with its display name.
|
||||
type EntityNumberName struct {
|
||||
Num int
|
||||
|
||||
Reference in New Issue
Block a user