create or replace
PROCEDURE showb57resp(
	in_network   IN decimation.net%TYPE,
        in_station   IN decimation.sta%TYPE,
        in_location  IN decimation.location%TYPE,
        in_channel   IN decimation.seedchan%TYPE,
        starttime    IN varchar2,
        endtime      IN varchar2,
        in_stage     IN decimation.stage_seq%TYPE
 )
IS
	samprate   dm.samprate%TYPE;
	factor     dm.factor%TYPE;
	offset     dm.offset%TYPE;
	delay      dm.delay%TYPE;
        correction dm.correction%TYPE;

	CURSOR cr_decimation IS
		SELECT samprate, factor, offset, delay, correction
		FROM   DM
		WHERE  key =
		(SELECT dm_key
			FROM   Decimation
			WHERE
			net = in_network AND 
			sta = in_station AND 
			location = in_location AND
			seedchan = in_channel AND
			to_date(starttime,'MM/DD/YYYY HH24:MI:SS') >= ondate AND
			to_date(starttime,'MM/DD/YYYY HH24:MI:SS') < offdate AND
			stage_seq = in_stage);

BEGIN
	DBMS_OUTPUT.enable(1000000);

	IF NOT cr_decimation%ISOPEN THEN
		OPEN cr_decimation;
	END IF;

	FETCH cr_decimation into samprate, factor, offset, delay, correction;

	DBMS_OUTPUT.PUT_LINE('#');
	DBMS_OUTPUT.PUT_LINE('#                  +-----------------------------------+');
	DBMS_OUTPUT.PUT_LINE('#                  |            Decimation             |' );
	DBMS_OUTPUT.PUT_LINE('#                  |        ' || rpad(in_network,2,' ')
				|| '  ' || rpad(in_station,5,' ')
				|| '  ' || rpad(in_location,2,' ')
				|| '  ' || in_channel || '         |' );
	DBMS_OUTPUT.PUT_LINE('#                  |     ' || to_char(to_date(starttime,'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY') || ' to '
								|| to_char(to_date(endtime,'MM/DD/YYYY HH24:MI:SS'),'MM/DD/YYYY') || '      |' );
	DBMS_OUTPUT.PUT_LINE('#                  +-----------------------------------+');
	DBMS_OUTPUT.PUT_LINE('#');
	DBMS_OUTPUT.PUT_LINE( 'B057F03     Stage sequence number:                  ' || in_stage );
	DBMS_OUTPUT.PUT_LINE( 'B057F04     Input sample rate (HZ):               ' || to_char(samprate, '0.9999EEEE') );
	DBMS_OUTPUT.PUT_LINE( 'B057F05     Decimation factor:                     ' || to_char(factor,'09999') );
	DBMS_OUTPUT.PUT_LINE( 'B057F06     Decimation offset:                     ' || to_char(offset,'09999') );
	DBMS_OUTPUT.PUT_LINE( 'B057F07     Estimated delay (seconds):            ' || to_char(delay,'S0.9999EEEE') );
	DBMS_OUTPUT.PUT_LINE( 'B057F08     Correction applied (seconds):         ' || to_char(correction,'S0.9999EEEE') );

	close cr_decimation;
END;
