create or replace
PROCEDURE showb54rep(
	id_in IN coefficients.dc_key%TYPE
 )
IS
	rtype      dc_data.type%TYPE;
	value1     string(15);
	value2     string(15);
	rep1       integer;
	rep2       integer;
	linestr    string(20);
	lineno     integer;
	symmetry   dc.symmetry%TYPE;

	CURSOR cr_repeat_dc IS
		SELECT type,
		to_char(coefficient,'S0.99999EEEE'),
		to_char(error,'S0.99999EEEE')
		FROM DC_Data
		WHERE key = id_in
		ORDER BY row_key;

	CURSOR cr_repeat_dcs IS
                SELECT type,
                to_char(coefficient,'S0.99999EEEE'),
                to_char(error,'S0.99999EEEE')
                FROM DC_Data
                WHERE key = id_in
                ORDER BY row_key DESC;

BEGIN
	DBMS_OUTPUT.enable(1000000);
	rep1 := 1;
	rep2 := 1;

	SELECT symmetry
	INTO symmetry
	FROM DC
	WHERE key = id_in;

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

	FETCH cr_repeat_dc into rtype, value1, value2;

	WHILE cr_repeat_dc%FOUND
	LOOP
		IF( (rep1 = 1 ) and (rtype = 'N') ) THEN
			linestr := 'B054F08-09 ';
			DBMS_OUTPUT.PUT_LINE('#              Numerator coefficients:');
			DBMS_OUTPUT.PUT_LINE('#              i  coefficient   error' );
			rep1 := 0;
			lineno := 0;
		END IF;
		IF( (rep2 = 1 ) and (rtype = 'D') ) THEN
			linestr := 'B054F11-12 ';
			DBMS_OUTPUT.PUT_LINE('#              Denominator coefficients:');
			DBMS_OUTPUT.PUT_LINE('#              i  coefficient   error' );
			rep2 := 0;
			lineno := 0;
		END IF;
		DBMS_OUTPUT.PUT_LINE( linestr || to_char(lineno,'9999')
								|| ' ' || value1 || ' ' || value2 );
		lineno := lineno + 1;
		FETCH cr_repeat_dc into rtype, value1, value2;
	END LOOP;

	if (symmetry = 'E' or symmetry = 'O') then
		IF NOT cr_repeat_dcs%ISOPEN THEN
			OPEN cr_repeat_dcs;
		END IF;

		FETCH cr_repeat_dcs into rtype, value1, value2;

		if (symmetry = 'O') then
			FETCH cr_repeat_dcs into rtype, value1, value2;
		end if;

        	WHILE cr_repeat_dcs%FOUND
        	LOOP	
			linestr := 'B054F08-09 ';	
			DBMS_OUTPUT.PUT_LINE( linestr || to_char(lineno,'9999') || ' ' || value1 || ' ' || value2 );
			lineno := lineno + 1;
			FETCH cr_repeat_dcs into rtype, value1, value2;
		END LOOP;

		CLOSE cr_repeat_dcs;
	end if;

	CLOSE cr_repeat_dc;
END;

