-
Notifications
You must be signed in to change notification settings - Fork 3
/
remarks.go
71 lines (64 loc) · 1.65 KB
/
remarks.go
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
package metar
import (
"regexp"
"strconv"
"strings"
"github.com/urkk/metar/wind"
)
// Remark - Additional information not included in the main message
type Remark struct {
WindOnRWY []WindOnRWY
QBB int // Cloud base in meters
МТOBSC bool // Mountains obscured
MASTOBSC bool // Mast obscured
OBSTOBSC bool // Obstacle obscured
QFE int // Q-code Field Elevation (mmHg)
}
// WindOnRWY - surface wind observations on the runways
type WindOnRWY struct {
Runway string
wind.Wind
}
func parseRemarks(tokens []string) *Remark {
if len(tokens) == 0 {
return nil
}
RMK := &Remark{}
for count := 0; count < len(tokens); {
// Wind value on runway. Not documented, but used in URSS and UHMA
regex := regexp.MustCompile(`^(R\d{2}[LCR]?)/((\d{3})?(VRB)?(\d{2})?(G\d\d)?(MPS|KT))`)
matches := regex.FindStringSubmatch(tokens[count])
if len(matches) != 0 && matches[0] != "" {
wnd := &WindOnRWY{}
wnd.Runway = matches[1][1:]
input := matches[2]
if count < len(tokens)-1 {
input += tokens[count+1]
}
count += wnd.ParseWind(input)
RMK.WindOnRWY = append(RMK.WindOnRWY, *wnd)
}
if count < len(tokens) && strings.HasPrefix(tokens[count], "QBB") {
RMK.QBB, _ = strconv.Atoi(tokens[count][3:])
count++
}
for count < len(tokens)-1 && tokens[count+1] == "OBSC" {
switch tokens[count] {
case "MT":
RMK.МТOBSC = true
case "MAST":
RMK.MASTOBSC = true
case "OBST":
RMK.OBSTOBSC = true
}
count += 2
}
// may be QFE767/1022 (mmHg/hPa)
if count < len(tokens) && strings.HasPrefix(tokens[count], "QFE") {
RMK.QFE, _ = strconv.Atoi(tokens[count][3:6])
count++
}
count++
}
return RMK
}