Skip to content

Commit 147ef71

Browse files
CHANGED: Report an error recommending -u def for a response whose input units
are not ground motion when displacement, velocity or acceleration is requested, instead of returning it in its own units.
1 parent 2a4b959 commit 147ef71

7 files changed

Lines changed: 79 additions & 46 deletions

File tree

‎ChangeLog‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Version 5.1.0
22

33
2026-11-07
44

5+
* CHANGED: Report an error recommending -u def for a response whose input units
6+
are not ground motion when displacement, velocity or acceleration is requested,
7+
instead of returning it in its own units.
8+
59
* IMPROVED: Blockette 55 (List) interpolation (-il, -ii) is now done
610
against log10(frequency), with amplitude interpolated as log10(amplitude).
711
Previously the cubic spline was applied in linear space and could
@@ -25,10 +29,6 @@ Version 5.1.0
2529

2630
* FIXED: Parse ResponseListElement entries in StationXML ResponseList stages.
2731

28-
* IMPROVED: Leave responses with non-ground-motion input units unconverted,
29-
regardless of the requested output units. The eases use with the default
30-
conversion to velocity and responses that cannot be converted.
31-
3232
* FIXED: Read StationXML from standard input with -stdio. Thanks to
3333
@peacocks for reporting.
3434

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ files.
9090
| Option | Meaning |
9191
| --- | --- |
9292
| `-f file` | Input file, or a directory of legacy `RESP.NET.STA.LOC.CHA` files |
93-
| `-u dis\|vel\|acc\|def` | Units of the response (default `vel`) |
93+
| `-u dis\|vel\|acc\|def` | Units of the response (default `vel`); `def` is required for responses that are not ground motion |
9494
| `-r ap\|fap\|cs` | Output: amplitude/phase, frequency/amplitude/phase, or complex spectra |
9595
| `-s log\|lin` | Frequency spacing (default `log`) |
9696
| `-t HH:MM:SS` | Time of day, to choose between responses effective on the same day |

‎doc/evalresp.1‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ Units of the response: \fBdis\fR (displacement), \fBvel\fR (velocity),
7171
\fBdef\fR the response is output units over input units, exactly as the first
7272
stage of the response takes them in and the last stage gives them out. This is
7373
the choice for sensors whose units cannot be converted to displacement,
74-
velocity or acceleration. Pressure (Pa), temperature (degrees C) and magnetic
75-
flux density (T) responses are always evaluated in their own units and this
76-
option has no effect on them.
74+
velocity or acceleration. A response whose input units are not ground motion
75+
(pressure, temperature, magnetic flux density, tilt, volts, counts or none) is
76+
an error unless \fBdef\fR is given.
7777
.TP
7878
.BR \-t " " \fIHH:MM:SS\fR " (" \-time )
7979
Time of day, used to choose between responses that are effective on the same

‎libsrc/evalresp/calc_fctns.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ convert_to_units (int inp, const evalresp_unit units, evalresp_complex *data, do
9191
return EVALRESP_ERR; /* BAD_OUT_UNITS */
9292
}
9393

94-
/* only ground motion is converted */
95-
if (inp != DIS && inp != VEL && inp != ACC)
96-
return EVALRESP_OK;
97-
9894
if (inp == DIS)
9995
{
10096
if (out == DIS)
@@ -938,12 +934,19 @@ calculate_response (evalresp_logger *log, evalresp_options *options,
938934

939935
input_units = channel_input_units (chan);
940936

941-
if ((options->unit == evalresp_displacement_unit || options->unit == evalresp_acceleration_unit) &&
937+
/* only ground motion converts to displacement, velocity or acceleration */
938+
if (options->unit != evalresp_file_unit &&
942939
input_units != DIS && input_units != VEL && input_units != ACC)
943940
{
944-
evalresp_log (log, EV_WARN, EV_WARN,
945-
"input units ('%s') are not ground motion, response is not converted to %s",
946-
chan->first_units, evalresp_unit_string (options->unit));
941+
if (strlen (chan->first_units))
942+
evalresp_log (log, EV_ERROR, EV_ERROR,
943+
"input units ('%s') are not ground motion and cannot be converted to %s, request file units (-u def) to evaluate without conversion",
944+
chan->first_units, evalresp_unit_string (options->unit));
945+
else
946+
evalresp_log (log, EV_ERROR, EV_ERROR,
947+
"input units are undefined and cannot be converted to %s, request file units (-u def) to evaluate without conversion",
948+
evalresp_unit_string (options->unit));
949+
return EVALRESP_VAL;
947950
}
948951

949952
/* a list is read row by row, so it must be sampled at the output frequencies */

‎src/evalresp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ usage (char *program)
2626
printf (" MAXFREQ NFREQ [options]\n\n");
2727
printf (" OPTIONS:\n\n");
2828
printf (" -f file (directory-name|filename)\n");
29-
printf (" -u units ('dis'|'vel'|'acc'|'def')\n");
29+
printf (" -u units ('dis'|'vel'|'acc'|'def'), 'def' for non-ground-motion\n");
3030
printf (" -t time-of-day (HH:MM:SS)\n");
3131
printf (" -s type-of-spacing (log|lin)\n");
3232
printf (" -n netid ('II'|'IU'|'G'|'*'...)\n");

‎tests/cli/test_cli.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,17 @@ static const cli_case cases[] = {
180180
.expected = "args/polynomial_zero",
181181
.program = "evalresp",
182182
.input = "station-polynomial-zero.xml",
183-
.argv = {"MAJO", "LDO", "2022", "015", "0.01", "1.0", "5", "-f", "station-polynomial-zero.xml"},
183+
.argv = {"MAJO", "LDO", "2022", "015", "0.01", "1.0", "5", "-f", "station-polynomial-zero.xml", "-u", "def"},
184184
.stderr_to = "stderr"},
185+
{.name = "args_non_motion_units",
186+
.expected = "args/non_motion_units",
187+
.program = "evalresp",
188+
.input = "station-polynomial-zero.xml",
189+
.argv = {"MAJO", "LDO", "2022", "015", "0.01", "1.0", "5", "-f", "station-polynomial-zero.xml"},
190+
.stderr_to = "stderr",
191+
.only = "stderr",
192+
.ignore_extra = 1,
193+
.rc = 7},
185194
{.name = "args_xml_forced_on_resp",
186195
.expected = "args/xml_forced_on_resp",
187196
.program = "evalresp",

‎tests/unit/test_evaluation.c‎

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ check_gain_only (const char *file, int station_xml)
130130
ER_CHECK (!evalresp_filename_to_channels (NULL, er_data_path (file), options, NULL, &channels));
131131
ER_CHECK (channels && channels->nchannels == 1);
132132
ER_CHECK (!evalresp_set_frequency (NULL, options, "0.1", "10", "5"));
133+
/* gain-only channels have no units to convert */
134+
ER_CHECK (evalresp_channel_to_response (NULL, channels->channels[0], options, &response));
135+
evalresp_free_response (&response);
136+
ER_CHECK (!evalresp_set_unit (NULL, options, "def"));
133137
ER_CHECK (!evalresp_channel_to_response (NULL, channels->channels[0], options, &response));
134138
ER_CHECK_MSG (response->nfreqs == 5, "nfreqs: %d", response->nfreqs);
135139
for (i = 0; i < response->nfreqs; ++i)
@@ -311,6 +315,8 @@ test_zero_freq_pz (void)
311315
evalresp_options *options = NULL;
312316

313317
ER_CHECK (!evalresp_new_options (NULL, &options));
318+
319+
ER_CHECK (!evalresp_set_unit (NULL, options, "def"));
314320
options->station_xml = 1;
315321
ER_CHECK (!evalresp_filename_to_channels (NULL, er_data_path ("station-pz-zero-freq.xml"), options, NULL,
316322
&channels));
@@ -379,6 +385,7 @@ load_list_stages (int interpolate, int start, int stop, evalresp_options **optio
379385
evalresp_channels **channels)
380386
{
381387
ER_CHECK (!evalresp_new_options (NULL, options));
388+
ER_CHECK (!evalresp_set_unit (NULL, *options, "def"));
382389
(*options)->station_xml = 1;
383390
(*options)->b55_interpolate = interpolate;
384391
(*options)->start_stage = start;
@@ -606,6 +613,8 @@ test_polynomial_negative (void)
606613
evalresp_options *options = NULL;
607614

608615
ER_CHECK (!evalresp_new_options (NULL, &options));
616+
617+
ER_CHECK (!evalresp_set_unit (NULL, options, "def"));
609618
options->station_xml = 1;
610619
ER_CHECK (!evalresp_filename_to_channels (NULL, er_data_path ("station-polynomial-negative.xml"), options, NULL,
611620
&channels));
@@ -637,6 +646,7 @@ test_excess_pole_freq (void)
637646
ER_CHECK (NULL != (fd = fopen ("pole.log", "w+")));
638647
ER_CHECK (NULL != (log = evalresp_logger_alloc (evalresp_log_to_file, (void *)fd)));
639648
ER_CHECK (!evalresp_new_options (NULL, &options));
649+
ER_CHECK (!evalresp_set_unit (NULL, options, "def"));
640650
options->station_xml = 1;
641651
ER_CHECK (!evalresp_filename_to_channels (NULL, er_data_path ("station-pz-excess-pole.xml"), options, NULL,
642652
&channels));
@@ -664,20 +674,25 @@ test_excess_pole_freq (void)
664674
}
665675

666676
static void
667-
test_non_motion_units_not_converted (void)
677+
test_non_motion_units_rejected (void)
668678
{
669-
/* pressure input: displacement and acceleration requests leave the response as in file units */
679+
/* pressure input: dis, vel and acc requests fail and recommend file units, def evaluates */
670680
const double freqs[] = {0.1, 1.0, 10.0};
671681
const int nfreqs = sizeof (freqs) / sizeof (freqs[0]);
672-
const char *units[] = {"def", "dis", "acc"};
673-
evalresp_response *responses[3][2] = {{NULL}};
674-
int u, i, k;
682+
const char *units[] = {"def", "dis", "vel", "acc"};
683+
int u, i;
675684

676-
for (u = 0; u < 3; ++u)
685+
for (u = 0; u < 4; ++u)
677686
{
687+
char text[8192];
688+
size_t n;
689+
FILE *fd;
690+
evalresp_logger *log;
678691
evalresp_channels *channels = NULL;
679692
evalresp_options *options = NULL;
680693

694+
ER_CHECK (NULL != (fd = fopen ("units.log", "w+")));
695+
ER_CHECK (NULL != (log = evalresp_logger_alloc (evalresp_log_to_file, (void *)fd)));
681696
ER_CHECK (!evalresp_new_options (NULL, &options));
682697
ER_CHECK (!evalresp_set_unit (NULL, options, units[u]));
683698
options->station_xml = 1;
@@ -686,32 +701,38 @@ test_non_motion_units_not_converted (void)
686701
ER_CHECK (channels && channels->nchannels == 2);
687702
for (i = 0; i < channels->nchannels; ++i)
688703
{
689-
ER_CHECK (!evalresp_channel_to_response_freqs (NULL, channels->channels[i], options, freqs, nfreqs,
690-
&responses[u][i]));
691-
}
692-
evalresp_free_channels (&channels);
693-
evalresp_free_options (&options);
694-
}
704+
evalresp_response *response = NULL;
705+
int status = evalresp_channel_to_response_freqs (log, channels->channels[i], options, freqs, nfreqs,
706+
&response);
695707

696-
for (u = 1; u < 3; ++u)
697-
{
698-
for (i = 0; i < 2; ++i)
699-
{
700-
for (k = 0; k < nfreqs; ++k)
708+
if (u == 0)
701709
{
702-
const evalresp_complex *a = &responses[0][i]->rvec[k], *b = &responses[u][i]->rvec[k];
703-
const double tol = 1e-9 * (fabs (a->real) + fabs (a->imag));
704-
705-
ER_CHECK_MSG (fabs (a->real - b->real) <= tol && fabs (a->imag - b->imag) <= tol,
706-
"-u %s channel %d %g Hz: %g %g vs %g %g", units[u], i, freqs[k],
707-
b->real, b->imag, a->real, a->imag);
710+
ER_CHECK_MSG (!status, "-u def channel %d: status %d", i, status);
708711
}
712+
else
713+
{
714+
ER_CHECK_MSG (status, "-u %s channel %d evaluated", units[u], i);
715+
}
716+
evalresp_free_response (&response);
717+
}
718+
fflush (fd);
719+
rewind (fd);
720+
n = fread (text, 1, sizeof (text) - 1, fd);
721+
text[n] = '\0';
722+
if (u == 0)
723+
{
724+
ER_CHECK_MSG (!strstr (text, "-u def"), "-u def logged: %s", text);
709725
}
726+
else
727+
{
728+
ER_CHECK_MSG (strstr (text, "not ground motion") && strstr (text, "-u def"),
729+
"-u %s: missing recommendation in log: %s", units[u], text);
730+
}
731+
evalresp_free_channels (&channels);
732+
evalresp_free_options (&options);
733+
evalresp_logger_free (log);
734+
fclose (fd);
710735
}
711-
712-
for (u = 0; u < 3; ++u)
713-
for (i = 0; i < 2; ++i)
714-
evalresp_free_response (&responses[u][i]);
715736
}
716737

717738
static void
@@ -771,7 +792,7 @@ const er_test unit_evaluation_tests[] = {
771792
{"list_stage_not_evaluated", test_list_stage_not_evaluated, NULL},
772793
{"list_stage_note", test_list_stage_note, NULL},
773794
{"legacy_list_stage_freqs", test_legacy_list_stage_freqs, NULL},
774-
{"non_motion_units_not_converted", test_non_motion_units_not_converted, NULL},
795+
{"non_motion_units_rejected", test_non_motion_units_rejected, NULL},
775796
{"arbitrary_freqs", test_arbitrary_freqs, NULL},
776797
{"legacy_arbitrary_freqs", test_legacy_arbitrary_freqs, NULL},
777798
{"no_options", test_no_options, NULL},

0 commit comments

Comments
 (0)