Index: library/bdm/design/ctrlbase.cpp
===================================================================
--- library/bdm/design/ctrlbase.cpp (revision 744)
+++ library/bdm/design/ctrlbase.cpp (revision 1064)
@@ -4,54 +4,54 @@
 
 void LQG::set_system ( shared_ptr<StateSpace<chmat> > S0 ) {
-	S = S0;
+    S = S0;
 }
 
 void LQG::update_system() {
-	pr.set_submatrix ( 0, 0, S->_B() );
-	pr.set_submatrix ( 0, dimu, S->_A() );
+    pr.set_submatrix ( 0, 0, S->_B() );
+    pr.set_submatrix ( 0, dimu, S->_A() );
 
-	//penalization
-	qux.set_submatrix ( 0, 0, Qu._Ch() );
-	qux.set_submatrix ( 0, dimx + dimu + dimy, -Qu._Ch() );
+    //penalization
+    qux.set_submatrix ( 0, 0, Qu._Ch() );
+    qux.set_submatrix ( 0, dimx + dimu + dimy, -Qu._Ch() );
 
-	qyx.set_submatrix ( 0, 0, S->_C() );
-	qyx.set_submatrix ( 0, dimx, -eye ( dimy ) );
+    qyx.set_submatrix ( 0, 0, S->_C() );
+    qyx.set_submatrix ( 0, dimx, -eye ( dimy ) );
 
-	// parts of QR
-	hqy = Qy.to_mat() * qyx * pr;
+    // parts of QR
+    hqy = Qy.to_mat() * qyx * pr;
 
-	// pre_qr
-	pre_qr = concat_vertical ( s * pr, concat_vertical ( hqy, qux ) );
+    // pre_qr
+    pre_qr = concat_vertical ( s * pr, concat_vertical ( hqy, qux ) );
 }
-	
+
 void LQG::set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 ) {
-	Qy = Qy0;
-	Qu = Qu0;
-	y_req = y_req0;
-	horizon = horizon0;
+    Qy = Qy0;
+    Qu = Qu0;
+    y_req = y_req0;
+    horizon = horizon0;
 }
 
 void LQG::validate() {
-	// set properties from S
-	dimx = S->_A().rows();
-	dimy = S->_C().rows();
-	dimu = S->_B().cols();
-	pr = zeros ( dimx + dimu + dimy,  dimu + dimx + dimu + dimy );
-	pr.set_submatrix ( dimx, dimu + dimx, eye ( dimu + dimy ) );
+    // set properties from S
+    dimx = S->_A().rows();
+    dimy = S->_C().rows();
+    dimu = S->_B().cols();
+    pr = zeros ( dimx + dimu + dimy,  dimu + dimx + dimu + dimy );
+    pr.set_submatrix ( dimx, dimu + dimx, eye ( dimu + dimy ) );
 
-	//penalization
-	bdm_assert ( Qy.cols() == dimy, "LQG: wrong dimensions of Qy " );
-	bdm_assert ( Qu.cols() == dimu, "LQG: wrong dimensions of Qu " );
-	bdm_assert ( y_req.length() == dimy, "LQG: wrong dimensions of y_req " );
+    //penalization
+    bdm_assert ( Qy.cols() == dimy, "LQG: wrong dimensions of Qy " );
+    bdm_assert ( Qu.cols() == dimu, "LQG: wrong dimensions of Qu " );
+    bdm_assert ( y_req.length() == dimy, "LQG: wrong dimensions of y_req " );
 
-	qux = zeros ( dimu, dimx + 2 * dimu + dimy );
-	qyx = zeros ( dimy, dimx + dimy + dimu );
+    qux = zeros ( dimu, dimx + 2 * dimu + dimy );
+    qyx = zeros ( dimy, dimx + dimy + dimu );
 
-	//
-	initial_belmann();
-	// parts of QR
-	post_qr = zeros ( pre_qr.rows(), pre_qr.cols() );
+    //
+    initial_belmann();
+    // parts of QR
+    post_qr = zeros ( pre_qr.rows(), pre_qr.cols() );
 
-	update_system();
+    update_system();
 }
 
@@ -59,21 +59,21 @@
 //	pre_qr.set_submatrix ( 0, 0, s*pr );
 //	pre_qr.set_submatrix ( dimx + dimu + dimy, dimu + dimx, -Qy.to_mat() *y_req );
-	if ( !qr ( pre_qr, post_qr ) ) {
-		bdm_warning ( "QR in LQG unstable" );
-	}
-	triu ( post_qr );
-	// hn(m+1:2*m+n+r,m+1:2*m+n+r);
-	s = post_qr.get ( dimu, 2 * dimu + dimx + dimy - 1, dimu, 2 * dimu + dimx + dimy - 1 );
+    if ( !qr ( pre_qr, post_qr ) ) {
+        bdm_warning ( "QR in LQG unstable" );
+    }
+    triu ( post_qr );
+    // hn(m+1:2*m+n+r,m+1:2*m+n+r);
+    s = post_qr.get ( dimu, 2 * dimu + dimx + dimy - 1, dimu, 2 * dimu + dimx + dimy - 1 );
 };
 
 void LQG::redesign() {
-	for ( td = horizon; td > 0; td-- ) {
-		update_system();
-		ricatti_step();
-	}
-	/*			ws=hn(1:m,m+1:2*m+n+r);
-				wsd=hn(1:m,1:m);
-				Lklq=-inv(wsd)*ws;*/
-	L = -inv ( post_qr.get ( 0, dimu - 1, 0, dimu - 1 ) ) * post_qr.get ( 0, dimu - 1, dimu, 2 * dimu + dimx + dimy - 1 );
+    for ( td = horizon; td > 0; td-- ) {
+        update_system();
+        ricatti_step();
+    }
+    /*			ws=hn(1:m,m+1:2*m+n+r);
+    			wsd=hn(1:m,1:m);
+    			Lklq=-inv(wsd)*ws;*/
+    L = -inv ( post_qr.get ( 0, dimu - 1, 0, dimu - 1 ) ) * post_qr.get ( 0, dimu - 1, dimu, 2 * dimu + dimx + dimy - 1 );
 }
 
Index: library/bdm/design/arx_ctrl.h
===================================================================
--- library/bdm/design/arx_ctrl.h (revision 896)
+++ library/bdm/design/arx_ctrl.h (revision 1064)
@@ -22,127 +22,131 @@
 class LQG_ARX : public Controller {
 protected:
-	//! Internal ARX estimator
-	shared_ptr<ARX> ar;
-	//! Internal LQG designer
-	LQG lq;
-	//! Intermediate StateSpace model
-	shared_ptr<StateFromARX> Stsp;
-	//! AR predictor
-	shared_ptr<mlnorm<chmat> > pred;
-	//! datalink from rvc to ar.bayes
-	datalink rvc2ar_y;
-	//! datalink from rvc to ar.bayes
-	datalink_buffered rvc2ar_cond;
+    //! Internal ARX estimator
+    shared_ptr<ARX> ar;
+    //! Internal LQG designer
+    LQG lq;
+    //! Intermediate StateSpace model
+    shared_ptr<StateFromARX> Stsp;
+    //! AR predictor
+    shared_ptr<mlnorm<chmat> > pred;
+    //! datalink from rvc to ar.bayes
+    datalink rvc2ar_y;
+    //! datalink from rvc to ar.bayes
+    datalink_buffered rvc2ar_cond;
 
-	//! flag to use iterations spread in time (ist)
-	bool ist;
-	//! flag to use windsurfer approach
-	bool windsurfer;
+    //! flag to use iterations spread in time (ist)
+    bool ist;
+    //! flag to use windsurfer approach
+    bool windsurfer;
 public:
-	//! Default constructor
-	LQG_ARX() : ar(), lq() { }
+    //! Default constructor
+    LQG_ARX() : ar(), lq() { }
 
-	//! adaptation is to store arx estimates in stsp
-	void adapt ( const vec &data ) {
-		ar->bayes ( rvc2ar_y.pushdown ( data ), rvc2ar_cond.pushdown ( data ) );
-		rvc2ar_cond.store_data ( data );
-		ar->ml_predictor_update ( *pred );
-	}
-	void redesign() {
-		Stsp->update_from ( *pred );
-		if ( windsurfer ) {
-			mat Ry = pred->_R();
-			lq.set_control_Qy ( inv ( Ry ) );
-		}
-		if ( !ist ) {
-			lq.initial_belmann();
-		}
-		lq.redesign();
-	}
-	vec ctrlaction ( const vec &cond ) const {
-		//cond is xt + ut
-		vec state = cond.left ( Stsp->_A().rows() );
-		if ( Stsp->_have_constant() ) {
-			state ( state.length() - 1 ) = 1;
-		}
-		vec tmp=lq.ctrlaction ( state, cond.right ( Stsp->_B().cols() ) );
-		if (!std::isfinite(sum(tmp))) {
-			cout << "infinite ctrl action";
-		}
-		return tmp;
-	}
-	//!
-	//! LQG is defined by quadratic loss function
-	/*! \f[ L(y,u) = (y-y_{req})'Q_y (y-y_{req}) + (u-u_{req})' Q_u (u-u_{req}) \f]
-			expected input
-			\code
-		{ class="LQG";
-			arx = {class="ARX", ...} // internal arx model, see
-			Qy = ("matrix", ...);
-			Qu = ("matrix", ...);
-			yreq = [];               // requested output
-			ureq = [];               // requested input value
-		}
-			\endcode
-	 */
-	void from_setting ( const Setting &set ) {
-		ar = UI::build<ARX> ( set, "ARX", UI::compulsory );
+    //! adaptation is to store arx estimates in stsp
+    void adapt ( const vec &data ) {
+        ar->bayes ( rvc2ar_y.pushdown ( data ), rvc2ar_cond.pushdown ( data ) );
+        rvc2ar_cond.store_data ( data );
+        ar->ml_predictor_update ( *pred );
+    }
+    void redesign() {
+        Stsp->update_from ( *pred );
+        if ( windsurfer ) {
+            mat Ry = pred->_R();
+            lq.set_control_Qy ( inv ( Ry ) );
+        }
+        if ( !ist ) {
+            lq.initial_belmann();
+        }
+        lq.redesign();
+    }
+    vec ctrlaction ( const vec &cond ) const {
+        //cond is xt + ut
+        vec state = cond.left ( Stsp->_A().rows() );
+        if ( Stsp->_have_constant() ) {
+            state ( state.length() - 1 ) = 1;
+        }
+        vec tmp=lq.ctrlaction ( state, cond.right ( Stsp->_B().cols() ) );
+        if (!std::isfinite(sum(tmp))) {
+            cout << "infinite ctrl action";
+        }
+        return tmp;
+    }
+    //!
+    //! LQG is defined by quadratic loss function
+    /*! \f[ L(y,u) = (y-y_{req})'Q_y (y-y_{req}) + (u-u_{req})' Q_u (u-u_{req}) \f]
+    		expected input
+    		\code
+    	{ class="LQG";
+    		arx = {class="ARX", ...} // internal arx model, see
+    		Qy = ("matrix", ...);
+    		Qu = ("matrix", ...);
+    		yreq = [];               // requested output
+    		ureq = [];               // requested input value
+    	}
+    		\endcode
+     */
+    void from_setting ( const Setting &set ) {
+        ar = UI::build<ARX> ( set, "ARX", UI::compulsory );
 
-		mat Qu;
-		mat Qy;
+        mat Qu;
+        mat Qy;
 
-		UI::get ( Qu, set, "Qu", UI::compulsory );
-		UI::get ( Qy, set, "Qy", UI::compulsory );
+        UI::get ( Qu, set, "Qu", UI::compulsory );
+        UI::get ( Qy, set, "Qy", UI::compulsory );
 
-		vec y_req;
-		if ( !UI::get ( y_req, set, "yreq", UI::optional ) )
-			y_req = zeros ( ar->_yrv()._dsize() );
+        vec y_req;
+        if ( !UI::get ( y_req, set, "yreq", UI::optional ) )
+            y_req = zeros ( ar->_yrv()._dsize() );
 
-		int horizon;
-		UI::get ( horizon, set, "horizon", UI::compulsory );
-		lq.set_control_parameters ( Qy, Qu, y_req, horizon );
+        int horizon;
+        UI::get ( horizon, set, "horizon", UI::compulsory );
+        lq.set_control_parameters ( Qy, Qu, y_req, horizon );
 
-		int wind;
-		if ( UI::get ( wind, set, "windsurfer", UI::optional ) ) {
-			windsurfer = wind > 0;
-		} else {
-			windsurfer = false;
-		};
-		int ist_;
-		if ( UI::get ( ist_, set, "ist", UI::optional ) ) {
-			ist = ist_ > 0;
-		} else {
-			ist = false;
-		};
-		validate();
-	}
+        int wind;
+        if ( UI::get ( wind, set, "windsurfer", UI::optional ) ) {
+            windsurfer = wind > 0;
+        } else {
+            windsurfer = false;
+        };
+        int ist_;
+        if ( UI::get ( ist_, set, "ist", UI::optional ) ) {
+            ist = ist_ > 0;
+        } else {
+            ist = false;
+        };
+        validate();
+    }
 
-	void validate() {
-		// ar is valid
-		pred = ar->ml_predictor<chmat>();
-		Stsp = new StateFromARX;
-		RV xrv;
-		RV urvm; //old ut
-		Stsp->connect_mlnorm ( *pred, xrv, urvm );
-		lq.set_system ( Stsp );
-		lq.validate();
+    void validate() {
+        // ar is valid
+        pred = ar->ml_predictor<chmat>();
+        Stsp = new StateFromARX;
+        RV xrv;
+        RV urvm; //old ut
+        Stsp->connect_mlnorm ( *pred, xrv, urvm );
+        lq.set_system ( Stsp );
+        lq.validate();
 
-		rv = urvm; // rv is not shifted to t+1!!
-		rvc = concat ( xrv, urvm );
-		rvc2ar_y.set_connection ( ar->_yrv(), rvc );
-		rvc2ar_cond.set_connection ( ar->_rvc(), rvc );
-		//datalink from ARX to rvc
-	}
-	void log_register ( logger &L, const string &prefix ) {
-		ar->log_register ( L, prefix );
-	}
-	void log_write ( ) const {
-		ar->log_write();
-	}
-	//! access function
-	const ARX& _ar() {return *ar.get();}
-	//! access function
-	mlnorm<chmat>* _pred() {return pred.get();}
-	
+        rv = urvm; // rv is not shifted to t+1!!
+        rvc = concat ( xrv, urvm );
+        rvc2ar_y.set_connection ( ar->_yrv(), rvc );
+        rvc2ar_cond.set_connection ( ar->_rvc(), rvc );
+        //datalink from ARX to rvc
+    }
+    void log_register ( logger &L, const string &prefix ) {
+        ar->log_register ( L, prefix );
+    }
+    void log_write ( ) const {
+        ar->log_write();
+    }
+    //! access function
+    const ARX& _ar() {
+        return *ar.get();
+    }
+    //! access function
+    mlnorm<chmat>* _pred() {
+        return pred.get();
+    }
+
 
 };
Index: library/bdm/design/ctrlbase.h
===================================================================
--- library/bdm/design/ctrlbase.h (revision 907)
+++ library/bdm/design/ctrlbase.h (revision 1064)
@@ -21,36 +21,36 @@
 class Controller : public root {
 protected:
-	//! identifier of the designed action;
-	RV rv;
-	//! identifier of the conditioning variables - data needed ;
-	RV rvc;
+    //! identifier of the designed action;
+    RV rv;
+    //! identifier of the conditioning variables - data needed ;
+    RV rvc;
 public:
-	//! function processing new observations and adapting control strategy accordingly
-	virtual void adapt ( const vec &data ) {};
-	//! function redesigning the control strategy
-	virtual void redesign() {};
-	//! returns designed control action
-	virtual vec ctrlaction ( const vec &cond ) const {
-		return vec ( 0 );
-	}
+    //! function processing new observations and adapting control strategy accordingly
+    virtual void adapt ( const vec &data ) {};
+    //! function redesigning the control strategy
+    virtual void redesign() {};
+    //! returns designed control action
+    virtual vec ctrlaction ( const vec &cond ) const {
+        return vec ( 0 );
+    }
 
-	void from_setting ( const Setting &set ) {
-		shared_ptr<RV> rv_ptr = UI::build<RV>( set, "rv", UI::optional );
-		if( rv_ptr ) rv = *rv_ptr;
-		shared_ptr<RV> rvc_ptr = UI::build<RV>( set, "rvc", UI::optional );
-		if( rvc_ptr ) rvc = *rvc_ptr;
-	}
-	//! access function
-	const RV& _rv() {
-		return rv;
-	}
-	//! access function
-	const RV& _rvc() {
-		return rvc;
-	}
-	//! register this controller with given datasource under name "name"
-	virtual void log_register ( logger &L, const string &prefix ) { }
-	//! write requested values into the logger
-	virtual void log_write ( ) const { }
+    void from_setting ( const Setting &set ) {
+        shared_ptr<RV> rv_ptr = UI::build<RV>( set, "rv", UI::optional );
+        if( rv_ptr ) rv = *rv_ptr;
+        shared_ptr<RV> rvc_ptr = UI::build<RV>( set, "rvc", UI::optional );
+        if( rvc_ptr ) rvc = *rvc_ptr;
+    }
+    //! access function
+    const RV& _rv() {
+        return rv;
+    }
+    //! access function
+    const RV& _rvc() {
+        return rvc;
+    }
+    //! register this controller with given datasource under name "name"
+    virtual void log_register ( logger &L, const string &prefix ) { }
+    //! write requested values into the logger
+    virtual void log_write ( ) const { }
 
 };
@@ -60,80 +60,80 @@
 class LQG : public Controller {
 protected:
-	//! StateSpace model from which we read data
-	shared_ptr<StateSpace<chmat> > S;
-	//! required value of the output y at time t (assumed constant)
-	vec y_req;
-	//! required value of the output y at time t (assumed constant)
-	vec u_req;
+    //! StateSpace model from which we read data
+    shared_ptr<StateSpace<chmat> > S;
+    //! required value of the output y at time t (assumed constant)
+    vec y_req;
+    //! required value of the output y at time t (assumed constant)
+    vec u_req;
 
-	//! Control horizon, set to maxint for infinite horizons
-	int horizon;
-	//! penalization matrix Qy
-	chmat Qy;
-	//! penalization matrix Qu
-	chmat Qu;
-	//! time of the design step - from horizon->0
-	int td;
-	//! controller parameters
-	mat L;
+    //! Control horizon, set to maxint for infinite horizons
+    int horizon;
+    //! penalization matrix Qy
+    chmat Qy;
+    //! penalization matrix Qu
+    chmat Qu;
+    //! time of the design step - from horizon->0
+    int td;
+    //! controller parameters
+    mat L;
 
-	//!@{ \name temporary storage for ricatti - use initialize
-	//! convenience parameters
-	int dimx;
-	//! convenience parameters
-	int dimy;
-	//! convenience parameters
-	int dimu;
+    //!@{ \name temporary storage for ricatti - use initialize
+    //! convenience parameters
+    int dimx;
+    //! convenience parameters
+    int dimy;
+    //! convenience parameters
+    int dimu;
 
-	//!  parameters
-	mat pr;
-	//! penalization
-	mat qux;
-	//! penalization
-	mat qyx;
-	//! internal quadratic form
-	mat s;
-	//! penalization
-	mat qy;
-	//! pre_qr part
-	mat hqy;
-	//! pre qr matrix
-	mat pre_qr;
-	//! post qr matrix
-	mat post_qr;
-	//!@}
+    //!  parameters
+    mat pr;
+    //! penalization
+    mat qux;
+    //! penalization
+    mat qyx;
+    //! internal quadratic form
+    mat s;
+    //! penalization
+    mat qy;
+    //! pre_qr part
+    mat hqy;
+    //! pre qr matrix
+    mat pre_qr;
+    //! post qr matrix
+    mat post_qr;
+    //!@}
 
 public:
-	//! set system parameters from given matrices
-	void set_system ( shared_ptr<StateSpace<chmat> > S0 );
-	//! update internal whan system has changed
-	void update_system();
-	//! set penalization matrices and control horizon
-	void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 );
-	//! set penalization matrices and control horizon
-	void set_control_Qy ( const mat &Qy0 ) {
-		Qy = Qy0;
-	}
-	//! refresh temporary storage - inefficient can be improved
-	void initial_belmann() {
-		s = 1e-5 * eye ( dimx + dimu + dimy );
-	};
-	//! validation procedure
-	void validate();
-	//! function for future use which is called at each time td; Should call initialize()!
-	//! redesign one step of the
-	void ricatti_step();
-	
-	void redesign();
+    //! set system parameters from given matrices
+    void set_system ( shared_ptr<StateSpace<chmat> > S0 );
+    //! update internal whan system has changed
+    void update_system();
+    //! set penalization matrices and control horizon
+    void set_control_parameters ( const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0 );
+    //! set penalization matrices and control horizon
+    void set_control_Qy ( const mat &Qy0 ) {
+        Qy = Qy0;
+    }
+    //! refresh temporary storage - inefficient can be improved
+    void initial_belmann() {
+        s = 1e-5 * eye ( dimx + dimu + dimy );
+    };
+    //! validation procedure
+    void validate();
+    //! function for future use which is called at each time td; Should call initialize()!
+    //! redesign one step of the
+    void ricatti_step();
 
-	//! compute control action
-	vec ctrlaction ( const vec &state, const vec &ukm ) const {
-		vec pom = concat ( state, ones ( dimy ), ukm );
-		return L*pom;
-	}
-	//! access function
-	mat _L() const {
-		return L;
-	}
+    void redesign();
+
+    //! compute control action
+    vec ctrlaction ( const vec &state, const vec &ukm ) const {
+        vec pom = concat ( state, ones ( dimy ), ukm );
+        return L*pom;
+    }
+    //! access function
+    mat _L() const {
+        return L;
+    }
 } ;
 
