--------------------------------------------------------------------------------
-- Company: 
-- Engineer:
--
-- Create Date:   17:16:42 10/02/2005
-- Design Name:   cordic_top
-- Module Name:   tb_cordic_top.vhd
-- Project Name:  cordic
-- Target Device:  
-- Tool versions:  
-- Description:   
-- 
-- VHDL Test Bench Created by ISE for module: cordic_top
--
-- Dependencies:
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
-- Notes: 
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test.  Xilinx recommends 
-- that these types always be used for the top-level I/O of a design in order 
-- to guarantee that the testbench will bind correctly to the post-implementation 
-- simulation model.
--------------------------------------------------------------------------------
-- Results:In 16i2 and Out 16i0
------------------------------
-- xmean = -3.051757808671257e-7
-- ymean = 1.525878906192144e-6
-- zmean = 0.0
-- xvar  = 7.723598281502283e-10
-- yvar  = 8.539443970667266e-10
-- zvar  = 0.0
-- xstd  = 2.779136247380161e-5
-- ystd  = 2.922232703031582e-5
-- zstd  = 0.0
--
------------------------------
-- Results:In 16i2 and Out 16i1
------------------------------
-- xmean = 6.103515628828741e-7
-- ymean = -1.220703125057855e-6
-- zmean = 0.0
-- xvar  = 9.76293486677989e-10
-- yvar  = 7.934037490259732e-10
-- zvar  = 0.0
-- xstd  = 3.124569549038697e-5
-- ystd  = 2.816742354256017e-5
-- zstd  = 0.0
--
------------------------------
-- Results:In 16i2 and Out 16i2
------------------------------
-- xmean = 2.441406250382875e-6
-- ymean = -1.220703125057855e-6
-- zmean = 0.0
-- xvar  = 2.126680036682826e-9
-- yvar  = 2.117107754473399e-9
-- zvar  = 0.0
-- xstd  = 4.611594124251206e-5
-- ystd  = 4.601203923402438e-5
-- zstd  = 0.0
--
------------------------------
-- Results:In 32i2 and Out 32i0
------------------------------
-- xmean = -9.312842871812748e-12 
-- ymean = -5.78558739545293e-17 
-- zmean = 0.0 
-- xvar  = 1.671709854744817e-19 
-- yvar  = 1.790442305004033e-19 
-- zvar  = 0.0 
-- xstd  = 4.088654857951228e-10 
-- ystd  = 4.231361843430591e-10 
-- zstd  = 0.0 
--
------------------------------
-- Results:In 32i2 and Out 32i1
------------------------------
-- xmean = 9.313608620496825e-12
-- ymean = 9.31316789028083e-12
-- zmean = 0.0
-- xvar  = 1.876480788588237e-19
-- yvar  = 2.238344116260579e-19
-- zvar  = 0.0
-- xstd  = 4.331836548841885e-10
-- ystd  = 4.731114156581492e-10
-- zstd  = 0.0
--
------------------------------
-- Results:In 32i2 and Out 32i2
------------------------------
-- xmean = -3.72525201102771e-11
-- ymean = -5.78558739545293e-17
-- zmean = 0.0
-- xvar  = 5.458335981037092e-19
-- yvar  = 5.704280631341228e-19
-- zvar  = 0.0
-- xstd  = 7.388055211648797e-10
-- ystd  = 7.552668820583376e-10
-- zstd  = 0.0
--
------------------------------
-- Results:In 64i2 and Out 64i0
------------------------------
-- xmean = 3.45418680637588e-17
-- ymean = 3.859475130978118e-17
-- zmean = 2.205267218835516e-16
-- xvar  = 5.54111959258452e-28
-- yvar  = 5.549496221074054e-28
-- zvar  = 7.916891206490056e-29
-- xstd  = 2.353958281827551e-14
-- ystd  = 2.355736874329146e-14
-- zstd  = 8.897691389619023e-15
--
------------------------------
-- Results:In 64i2 and Out 64i1
------------------------------
-- xmean = 3.45418680637588e-17
-- ymean = 3.859475130978118e-17
-- zmean = 2.205267218835516e-16
-- xvar  = 5.541120861185077e-28
-- yvar  = 5.549497432144743e-28
-- zvar  = 7.916856202525234e-29
-- xstd  = 2.353958551288674e-14
-- ystd  = 2.355737131376237e-14
-- zstd  = 8.897671719346156e-15
--
------------------------------
-- Results:In 64i2 and Out 64i2
------------------------------
-- xmean = 3.343164503913365e-17
-- ymean = 3.859475130978118e-17
-- zmean = 2.205223850748616e-16
-- xvar  = 5.540559656182732e-28
-- yvar  = 5.549495010008071e-28
-- zvar  = 7.916821581863743e-29
-- xstd  = 2.353839343749427e-14
-- ystd  = 2.355736617283025e-14
-- zstd  = 8.897652264425568e-15
--
--------------------------------------------------------------------------------
LIBRARY ieee;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.MATH_REAL.ALL;
USE ieee.numeric_std.ALL;
use std.textio.all; --  Imports the standard textio package.

library work;
use work.fixed_ja.all;
use work.cordic_pkg.all;
use work.PCK_FIO.all;

ENTITY tb_cordic_top IS
	Generic (
	        nbits			: integer := 32;
	        nbits_int		: integer := 2;
	        nbits_out		: integer := 32;
	        nbits_out_int	: integer := 1
	        );
END tb_cordic_top;

ARCHITECTURE behavior OF tb_cordic_top IS 

	-- Component Declaration for the Unit Under Test (UUT)
	COMPONENT cordic_top
	GENERIC (
		nbits			: integer;
		nbits_int		: integer;
		nbits_out		: integer;
		nbits_out_int	: integer
		);
	PORT(
		rst : IN std_logic;
		clk : IN std_logic;
		ce : in std_logic;
		xin : IN sfixed_t;
		yin : IN sfixed_t;
		zin : IN sfixed_t;
		xout : OUT sfixed_t;
		yout : OUT sfixed_t;
		zout : OUT sfixed_t;
		ready : OUT std_logic;
		valid : out std_logic;
		cordic_mode	: in cordic_mode_t
	);
	END COMPONENT;

	--Constants
	constant num_cycles : integer := 5;
	constant num_steps_per_cycle : integer := 100;
	constant PERIOD : time := 10 ns;

	constant one_sfix  : sfixed_t := to_sfixed(1.0, nbits, nbits_int);
	constant zero_sfix : sfixed_t := to_sfixed(0.0, nbits, nbits_int);
	
	--Inputs
	SIGNAL clk :  std_logic := '0';
	SIGNAL rst :  std_logic := '1';
	SIGNAL ce  :  std_logic := '0';
	SIGNAL xin, yin, zin : sfixed_t(sproto(nbits, nbits_int)'high downto sproto(nbits, nbits_int)'low) := zero_sfix;

	--Outputs
	SIGNAL xout, yout, zout :  sfixed_t(sproto(nbits_out, nbits_out_int)'high downto sproto(nbits_out, nbits_out_int)'low);
	SIGNAL valid, ready :  std_logic;
	SIGNAL cordic_mode : cordic_mode_t := cordic_mode_vector;
	

	--------------------------------------------------------------------
	--Functions
	--------------------------------------------------------------------
	type real_vector_t is array (natural range <>) of real;
	function mean(x : real_vector_t; len : integer) return real is
	variable xm : real := 0.0;
	begin
		for i in 0 to len-1 loop
			xm := xm + x(i);
		end loop;
		
		return xm / real(len);
	end mean;	
	
	--------------------------------------------------------------------
	function var(x : real_vector_t; len : integer) return real is
	variable xv, xm, xp : real := 0.0;
	begin
		xm := mean(x, len);
		
		for i in 0 to len-1 loop
			xp := x(i) - xm;
			xv := xv + xp*xp;
		end loop;
	
		return xv / real(len);
	end var;
	
	--------------------------------------------------------------------
	function stddev(x : real_vector_t; len : integer) return real is
	variable xv, xs : real := 0.0;
	begin
		xv := var(x, len);
		if xv > 0.0 then
			xs := sqrt(xv);
		end if;
		
		return xs;
	end stddev;
		
BEGIN

	-- Instantiate the Unit Under Test (UUT)
	uut: cordic_top 
	GENERIC MAP (
		nbits			=> nbits,
		nbits_int		=> nbits_int,
		nbits_out		=> nbits_out,
		nbits_out_int	=> nbits_out_int
		)
	PORT MAP(
		rst => rst,
		clk => clk,
		ce => ce,
		xin => xin,
		yin => yin,
		zin => zin,
		xout => xout,
		yout => yout,
		zout => zout,
		ready => ready,
		valid => valid,
		cordic_mode => cordic_mode
	);

 	tb_clk : PROCESS
	BEGIN
		clk <= not clk;
		wait for PERIOD/2;
	END PROCESS;

	tb : PROCESS
	variable xerr, yerr, zerr : real_vector_t (0 to num_steps_per_cycle*num_cycles-1);
	variable xvar, xstd, xmean, yvar, ystd, ymean, zvar, zstd, zmean : real;
	variable argx, argy, argz : real := 0.0;
	variable phi, dphi : real := 0.0;
	file RESULT:        text open write_mode is "STD_OUTPUT"; 
	file RESULT_X:      text open write_mode is "x.txt"; 
	file RESULT_Y:      text open write_mode is "y.txt"; 
	file RESULT_Z:      text open write_mode is "z.txt"; 
	variable L:         line;
	variable j : integer := 0;
	BEGIN

		-- Wait 100 ns for global reset to finish
		wait for 4*PERIOD;
		rst <= '0';

		wait for 2*PERIOD;

		for i in 0 to arctan_tbl'length-1 loop
			fprint(RESULT, L,"coeff arctan (%d) = %s\n", fo(i), REAL'image(arctan_tbl(i)));
		end loop;	
		for i in 0 to gain_tbl'length-1 loop
			fprint(RESULT, L,"coeff gain (%d) = %s\n", fo(i), REAL'image(gain_tbl(i)));
		end loop;	
		fprint(RESULT, L,"Pi = %s\n", REAL'image(MATH_PI));
		fprint(RESULT, L,"sqrt(2) = %s\n", REAL'image(SQRT(2.0)));
		fprint(RESULT, L,"1/sqrt(2) = %s\n", REAL'image(1.0/SQRT(2.0)));
			
		-------------------------------------------
		-- 1
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_rotate;
		argx		:= 1.0;
		argy		:= 0.0;
		argz		:= -pi/4.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*[X0*cos(Z0) - Y0*sin(Z0)]\n");
		fprint(RESULT, L,"Yn = An*[Y0*cos(Z0) + X0*sin(Z0)]\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- 2
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_rotate;
		argx		:= 1.0;
		argy		:= 0.0;
		argz		:= pi/2.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*[X0*cos(Z0) - Y0*sin(Z0)]\n");
		fprint(RESULT, L,"Yn = An*[Y0*cos(Z0) + X0*sin(Z0)]\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- 3
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_rotate;
		argx		:= sqrt2_inv;
		argy		:= -sqrt2_inv;
		argz		:= pi/2.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*[X0*cos(Z0) - Y0*sin(Z0)]\n");
		fprint(RESULT, L,"Yn = An*[Y0*cos(Z0) + X0*sin(Z0)]\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- 4
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_rotate;
		argx		:= sqrt2_inv;
		argy		:= -sqrt2_inv;
		argz		:= -pi/4.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*[X0*cos(Z0) - Y0*sin(Z0)]\n");
		fprint(RESULT, L,"Yn = An*[Y0*cos(Z0) + X0*sin(Z0)]\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- 5
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_vector;
		argx		:= 1.0;
		argy		:= 1.0;
		argz		:= 0.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*sqrt(X0^2 + Y0^2)\n");
		fprint(RESULT, L,"Zn = Z0 + arctan(Y0/X0)\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- 6
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_vector;
		argx		:= sqrt2_inv;
		argy		:= -sqrt2_inv;
		argz		:= 0.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*sqrt(X0^2 + Y0^2)\n");
		fprint(RESULT, L,"Zn = Z0 + arctan(Y0/X0)\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- 7
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_vector;
		argx		:= -sqrt2_inv;
		argy		:= sqrt2_inv;
		argz		:= 0.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*sqrt(X0^2 + Y0^2)\n");
		fprint(RESULT, L,"Zn = Z0 + arctan(Y0/X0)\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- 8
		wait until rising_edge(clk) and ready = '1';

		cordic_mode	<= cordic_mode_vector;
		argx		:= -sqrt2_inv;
		argy		:= -sqrt2_inv;
		argz		:= 0.0;

		xin <= to_sfixed(argx, xin);
		yin <= to_sfixed(argy, yin);
		zin <= to_sfixed(argz, zin);

		ce <= '1';
		wait until rising_edge(clk);
		ce <= '0';

		wait until rising_edge(clk) and ready = '0';
		wait until rising_edge(clk) and valid = '1';

		fprint(RESULT, L,"--------------------------------\n");
		fprint(RESULT, L,"%s\n", cordic_mode_t'image(cordic_mode));
		fprint(RESULT, L,"Xn = An*sqrt(X0^2 + Y0^2)\n");
		fprint(RESULT, L,"Zn = Z0 + arctan(Y0/X0)\n");
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"X0 = %s\n", REAL'image(to_real(xin)));
		fprint(RESULT, L,"Y0 = %s\n", REAL'image(to_real(yin)));
		fprint(RESULT, L,"Z0 = %s\n", REAL'image(to_real(zin)));
		fprint(RESULT, L,"\n");
		fprint(RESULT, L,"Xn = %s\n", REAL'image(to_real(xout)));
		fprint(RESULT, L,"Yn = %s\n", REAL'image(to_real(yout)));
		fprint(RESULT, L,"Zn = %s\n", REAL'image(to_real(zout)));
		fprint(RESULT, L,"\n");

		-------------------------------------------
		-- Place stimulus here
		wait for 10*PERIOD;
		j := 0;
		cordic_mode	<= cordic_mode_rotate;
		dphi := 2.0*pi/real(num_steps_per_cycle);
		for k in 0 to num_cycles-1 loop
			phi := -pi;
			for i in 0 to num_steps_per_cycle-1 loop
				xin <= one_sfix;
				yin <= zero_sfix;
				zin <= to_sfixed(phi, zin, round_nearest);

				wait until rising_edge(clk) and ready = '1';
				ce <= '1';
				wait until rising_edge(clk);
				ce <= '0';

				wait until rising_edge(clk) and ready = '0';
				wait until rising_edge(clk) and valid = '1';

				fprint(RESULT_X, L,"%s\n", REAL'image(to_real(xout)));
				fprint(RESULT_Y, L,"%s\n", REAL'image(to_real(yout)));
				fprint(RESULT_Z, L,"%s\n", REAL'image(to_real(zout)));

--				fprint(RESULT_X, L,"%s\n", REAL'image(cos(phi)));
--				fprint(RESULT_Y, L,"%s\n", REAL'image(sin(phi)));
--				fprint(RESULT_Z, L,"%s\n", REAL'image(0.0));

				xerr(j) := to_real(xout) - cos(phi);
				yerr(j) := to_real(yout) - sin(phi);
				zerr(j) := to_real(zout);
				j := j + 1;
				phi := (phi + dphi);
			end loop;	
		end loop;
		xmean := mean(xerr, j);
		ymean := mean(yerr, j);
		zmean := mean(zerr, j);
		xvar := var(xerr, j);
		yvar := var(yerr, j);
		zvar := var(zerr, j);
		xstd := stddev(xerr, j);
		ystd := stddev(yerr, j);
		zstd := stddev(zerr, j);
		fprint(RESULT, L,"------------------------------------------\n");
		fprint(RESULT, L,"Results: \n");
		fprint(RESULT, L,"xmean = %s\n", REAL'image(xmean));
		fprint(RESULT, L,"ymean = %s\n", REAL'image(ymean));
		fprint(RESULT, L,"zmean = %s\n", REAL'image(zmean));
		fprint(RESULT, L,"xvar  = %s\n", REAL'image(xvar));
		fprint(RESULT, L,"yvar  = %s\n", REAL'image(yvar));
		fprint(RESULT, L,"zvar  = %s\n", REAL'image(zvar));
		fprint(RESULT, L,"xstd  = %s\n", REAL'image(xstd));
		fprint(RESULT, L,"ystd  = %s\n", REAL'image(ystd));
		fprint(RESULT, L,"zstd  = %s\n", REAL'image(zstd));
		fprint(RESULT, L,"------------------------------------------\n");
		
		assert false report "Test finished" severity error;
		wait; 
	END PROCESS;

END;
