@@ -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
666676static 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
717738static 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