From 4eb1b6829fbca117df09f926c3a8d00b908ba004 Mon Sep 17 00:00:00 2001 From: Howard Wu Date: Fri, 22 Sep 2023 15:40:22 +1200 Subject: [PATCH] Fix station bug for empty InstrumentSensitivity responses. --- cmd/fdsn-ws/fdsn_station.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/cmd/fdsn-ws/fdsn_station.go b/cmd/fdsn-ws/fdsn_station.go index c38c791c..eee76ce4 100644 --- a/cmd/fdsn-ws/fdsn_station.go +++ b/cmd/fdsn-ws/fdsn_station.go @@ -539,15 +539,16 @@ 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, + ResourceId: r.ResourceId, + Items: r.Items, + InstrumentSensitivity: r.InstrumentSensitivity, + InstrumentPolynomial: r.InstrumentPolynomial, Stage: nil, } + ch.Response = res continue } @@ -595,19 +596,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()))