Skip to content

Commit

Permalink
Fix station bug for empty InstrumentSensitivity responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
junghao committed Sep 22, 2023
1 parent 3fea8b8 commit 3962473
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions cmd/fdsn-ws/fdsn_station.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,15 +539,21 @@ func (r *FDSNStationXML) trimLevel(level int) {
}
for c := 0; c < len(st.Channel); c++ {
ch := &st.Channel[c]
if level < STATION_LEVEL_RESPONSE {
if r := ch.Response; level < STATION_LEVEL_RESPONSE && r != nil {
// ch.Response is a pointer to source struct so we want to keep the source intact
res := &ResponseType{
ResourceId: ch.Response.ResourceId,
Items: ch.Response.Items,
InstrumentSensitivity: ch.Response.InstrumentSensitivity,
InstrumentPolynomial: ch.Response.InstrumentPolynomial,
Stage: nil,
ResourceId: r.ResourceId,
Items: r.Items,
Stage: nil,
}
if r.InstrumentSensitivity != nil {
res.InstrumentSensitivity = r.InstrumentSensitivity
}

if r.InstrumentPolynomial != nil {
res.InstrumentPolynomial = r.InstrumentPolynomial
}

ch.Response = res
continue
}
Expand Down Expand Up @@ -595,19 +601,30 @@ func (r *FDSNStationXML) marshalText(levelVal int) *bytes.Buffer {
}
for c := 0; c < len(sta.Channel); c++ {
cha := &sta.Channel[c]
var frequency float64
if cha.Response.InstrumentSensitivity.Frequency != nil {
frequency = *cha.Response.InstrumentSensitivity.Frequency
var frequency string
var value string
var unitsName string

if cha.Response != nil {
if s := cha.Response.InstrumentSensitivity; s != nil {
if s.Frequency != nil {
frequency = fmt.Sprintf("%f", *s.Frequency)
}
value = fmt.Sprintf("%f", s.Value)
if s.InputUnits != nil {
unitsName = s.InputUnits.Name
}
}
}

by.WriteString(fmt.Sprintf("%s|%s|%s|%s|%f|%f|%f|%f|%f|%f|%s|%f|%f|%s|%f|%s|%s\n",
by.WriteString(fmt.Sprintf("%s|%s|%s|%s|%f|%f|%f|%f|%f|%f|%s|%s|%s|%s|%f|%s|%s\n",
net.Code, sta.Code, cha.LocationCode, cha.Code,
cha.Latitude.Value, cha.Longitude.Value, cha.Elevation.Value,
cha.Depth.Value, cha.Azimuth.Value, cha.Dip.Value,
cha.Sensor.Type,
cha.Response.InstrumentSensitivity.Value,
value,
frequency,
cha.Response.InstrumentSensitivity.InputUnits.Name,
unitsName,
cha.SampleRate.Value,
cha.StartDate.MarshalFormatText(), cha.EndDate.MarshalFormatText()))

Expand Down

0 comments on commit 3962473

Please sign in to comment.