-
Notifications
You must be signed in to change notification settings - Fork 36
/
root.go
169 lines (138 loc) · 3.37 KB
/
root.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package stationxml
import (
"time"
)
// Equipment describes a StationXML Equipment element
type Equipment struct {
Type string
Description string
Manufacturer string
Model string
SerialNumber string
InstallationDate time.Time
RemovalDate time.Time
Response string
}
// Stream forms the main part of an individual StationXML Channel element
type Stream struct {
Code string
SamplingRate float64
Triggered bool
Types string
Vertical float64
Azimuth float64
Dip float64
Datalogger Equipment
Sensor Equipment
StartDate time.Time
EndDate time.Time
Response *ResponseType
}
// Channel forms the main part of a set of StationXML Channel elements
type Channel struct {
LocationCode string
Latitude float64
Longitude float64
Elevation float64
Survey string
Datum string
Streams []Stream
}
// Station forms the main part of a StationXML Station element.
type Station struct {
Code string
Name string
Description string
Latitude float64
Longitude float64
Elevation float64
Survey string
Datum string
StartDate time.Time
EndDate time.Time
CreationDate time.Time
TerminationDate time.Time
Channels []Channel
}
// Network forms the main part of a StationXML Network element.
type Network struct {
Code string
Description string
Restricted bool
Stations []Station
}
// External maps between an External Network and individal Networks.
type External struct {
Code string
Description string
Restricted bool
StartDate time.Time
EndDate time.Time
Networks []Network
}
// Root describes the standard StationXML layout which can be used as the barebones for building version specific encoders.
type Root struct {
Source string
Sender string
Module string
Create bool
Externals []External
}
// ExternalCode returns the network code of the first External entry in the Root structure, this is aimed at building single entry file names.
func (r Root) ExternalCode() string {
for _, e := range r.Externals {
return e.Code
}
return ""
}
// NetworkCode returns the network code of the first Network entry in the Root structure, this is aimed at building single entry file names.
func (r Root) NetworkCode() string {
for _, e := range r.Externals {
for _, n := range e.Networks {
return n.Code
}
}
return ""
}
// StationCode returns the station code of the first Station entry in the Root structure, this is aimed at building single entry file names.
func (r Root) StationCode() string {
for _, e := range r.Externals {
for _, n := range e.Networks {
for _, s := range n.Stations {
return s.Code
}
}
}
return ""
}
// Single builds a Root structure for the given station code.
func (r Root) Single(code string) (Root, bool) {
for _, e := range r.Externals {
for _, n := range e.Networks {
for _, s := range n.Stations {
if s.Code != code {
continue
}
root := Root{
Source: r.Source,
Sender: r.Sender,
Module: r.Module,
Create: r.Create,
Externals: []External{{
Code: e.Code,
Description: e.Description,
StartDate: e.StartDate,
EndDate: e.EndDate,
Networks: []Network{{
Code: n.Code,
Description: n.Description,
Stations: []Station{s},
}},
}},
}
return root, true
}
}
}
return Root{}, false
}