-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
152 lines (126 loc) · 5.06 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"flag"
"fmt"
"log"
"os"
"regexp"
"strings"
"github.com/GeoNet/delta"
)
type Settings struct {
base string // options delta base file directory
networks string // overall installed sensor network code
dart string // DART network code
lentic string // coastal network code
coastal string // coastal network code
enviro string // envirosensor network code
manual string // manualcollect network code
volcano string // volcano camera network code
building string // building camera network code
doas string // doas network code
combined regexp.Regexp // installed location codes
water regexp.Regexp // water location codes
geomag regexp.Regexp // geomag location codes
output string // optional output file
json bool // use json for output format
}
func main() {
var settings Settings
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Build a sensor description file\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Usage:\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, " %s [options]\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Options:\n")
fmt.Fprintf(os.Stderr, "\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n")
}
flag.StringVar(&settings.base, "base", "", "delta base files")
flag.StringVar(&settings.networks, "networks", "AK,CB,CH,EC,FI,HB,KI,NM,NZ,OT,RA,RT,SC,SI,SM,SP,TP,TR,WL", "installed network codes")
flag.StringVar(&settings.coastal, "coastal", "TG", "coastal tsunami gauge network code")
flag.StringVar(&settings.lentic, "lentic", "LG", "lentic tsunami gauge network code")
flag.StringVar(&settings.dart, "dart", "TD", "dart buoy network code")
flag.StringVar(&settings.enviro, "enviro", "EN", "envirosensor network code")
flag.StringVar(&settings.manual, "manual", "MC", "manualcollect network code")
flag.StringVar(&settings.volcano, "volcano", "VC", "volcano camera network code")
flag.StringVar(&settings.building, "building", "BC", "building camera network code")
flag.StringVar(&settings.doas, "doas", "EN", "doas network code")
flag.TextVar(&settings.combined, "combined", regexp.MustCompile("^[123]"), "combined sensor location codes")
flag.TextVar(&settings.water, "water", regexp.MustCompile("^4"), "water pressue sensor codes")
flag.TextVar(&settings.geomag, "geomag", regexp.MustCompile("^5"), "geomag sensor codes")
flag.StringVar(&settings.output, "output", "", "output sensor description file")
flag.BoolVar(&settings.json, "json", false, "use JSON for output format")
flag.Parse()
set, err := delta.NewBase(settings.base)
if err != nil {
log.Fatalf("unable to load delta base files: %v", err)
}
var network Network
for _, n := range strings.Split(settings.networks, ",") {
if err := network.InstalledSensors(set, &settings.combined, strings.TrimSpace(n), ""); err != nil {
log.Fatalf("unable to build seismic details (%s): %v", n, err)
}
}
if err := network.InstalledSensors(set, &settings.water, settings.coastal, "Coastal"); err != nil {
log.Fatalf("unable to build water details: %v", err)
}
if err := network.InstalledSensors(set, &settings.water, settings.lentic, "Lake"); err != nil {
log.Fatalf("unable to build water details: %v", err)
}
if err := network.EnviroSensor(set, settings.enviro, "Environmental Sensor"); err != nil {
log.Fatalf("unable to build envirosensor configuration: %v", err)
}
if err := network.Dart(set, settings.dart, "DART Bottom Pressure Recorder"); err != nil {
log.Fatalf("unable to build dart configuration: %v", err)
}
if err := network.Gnss(set, "GNSS Antenna", "GNSS Receiver"); err != nil {
log.Fatalf("unable to build gnss configuration: %v", err)
}
if err := network.Camera(set, settings.volcano, "Camera"); err != nil {
log.Fatalf("unable to build camera configuration: %v", err)
}
if err := network.Camera(set, settings.building, "Camera"); err != nil {
log.Fatalf("unable to build camera configuration: %v", err)
}
if err := network.Doas(set, settings.doas, "DOAS"); err != nil {
log.Fatalf("unable to build camera configuration: %v", err)
}
if err := network.ManualCollection(set, settings.manual, "Manual Collection"); err != nil {
log.Fatalf("unable to build camera configuration: %v", err)
}
switch {
case settings.output != "":
// output file has been given
file, err := os.Create(settings.output)
if err != nil {
log.Fatalf("unable to create output file %q: %v", settings.output, err)
}
defer file.Close()
switch {
case settings.json:
if err := network.EncodeJSON(file); err != nil {
log.Fatalf("unable to marshal output file %q: %v", settings.output, err)
}
default:
if err := network.EncodeXML(file, "", " "); err != nil {
log.Fatalf("unable to marshal output file %q: %v", settings.output, err)
}
}
default:
switch {
case settings.json:
if err := network.EncodeJSON(os.Stdout); err != nil {
log.Fatalf("unable to marshal output: %v", err)
}
default:
if err := network.EncodeXML(os.Stdout, "", " "); err != nil {
log.Fatalf("unable to marshal output: %v", err)
}
}
}
}