/*
 *  Copyright 2002 by Soos, Antal 
 *  All rights reserved. Property of Soos, Antal.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.  
 */
/***************************************************************************/
/*                                                                         */
/*     sysControl . cpp	                                                   */
/*                                                                         */
/*     System Control - Common Procedures.       			   */
/*                                                                         */
/*                                                                         */
/***************************************************************************/

// Include files definition:

#include "sysContr.hpp"

//-----------------------------------------------------------------------------
// Declaration of the sysCR object
//-----------------------------------------------------------------------------


syscr::syscr(int is, int ia, int ib, int ic)
{
  int i;
 // Initialisation of the model dimensions:
	m_s = is;
	m_a = ia;  // <-- The system dimension "sys_n"
	m_b = ib;
	m_c = ic;


 // Memory alocation for the matrices:
	matrix_alloc(&state, m_a, 1);	// state
 



#if STATISTIC_IS_IMPLEMENTED //------------------------------------------------
	// Alocate memory for the neccessery matrices in statistic calculation:

	// Initialise paramethers:

#endif //STATISTIC_IS_IMPLEMENTED ---------------------------------------------

}

//-----------------------------------------------------------------------------
syscr::~syscr()
{

 // Remouve the alocation from the heep
	matrix_delete(&state);
       

#if STATISTIC_IS_IMPLEMENTED //------------------------------------------------



#endif //STATISTIC_IS_IMPLEMENTED ---------------------------------------------
	    
}


//-----------------------------------------------------------------------------
void syscr::get_state(Matrix *gstate)
{ // Copy the theta matrix from private space to public space
  int i ;
 
   
   gstate->row = state.row;
   gstate->col = 1; // It is a vector
	  
   if(gstate->row > gstate->al_row)  sg_error(SMALL_MATRIX_ALOCATION);

   for (i=1;i<=state.row;i++)  gstate->mtx[i][1] = state.mtx[i][1];


}

//-----------------------------------------------------------------------------



#if CSTATISTIC_IS_IMPLEMENTED //------------------------------------------------

int syscr::update_stat(void)
{

	if (count_n == NxT) // if new sesion initialixe:
	{
		// Zero initialization: v statistics
	

		// Zero initialization: theta statistics
	
	}

	if( count_n > 1)
	{
		count_n--;
		
		// Statistic for the residuals: v
	
		
		return 0;
	}
	else if( count_n == 1)	// the NxT lengt is achived meke the data redy:
	{
		count_n = 0; //calculate for the last sample in this period:

		// Statistic for the residuals: v
			

	 	//Calculate the final statistics:
	

		// Statistic for the estimated partemethers:
	
		//performance_index= theta_frob * v_mami * v_qume * v_moav*v_moav * v_vari;
		performance_index = 1234;


		
		return 1;
	}
	else	return -1;
	
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

float syscr::get_performance_index(void) // generalized performance index
{
	return performance_index;
}
//-----------------------------------------------------------------------------

#endif //CSTATISTIC_IS_IMPLEMENTED ---------------------------------------------
//-----------------------------------------------------------------------------
