Index: /bdm/estim/arx.h
===================================================================
--- /bdm/estim/arx.h (revision 271)
+++ /bdm/estim/arx.h (revision 283)
@@ -55,5 +55,5 @@
 	ARX ( const double frg0=1.0 ) : BMEF ( frg0 ),est (), V ( est._V() ), nu ( est._nu() ) {};
 	ARX ( const ARX &A0 ) : BMEF (),est ( A0.est ), V ( est._V() ), nu ( est._nu() ) {};
-	ARX* _copy_();
+	ARX* _copy_() const;
 	void set_parameters ( double frg0 ) {frg=frg0;}
 	void set_statistics ( int dimx0, const ldmat V0, double nu0=-1.0 ) {est.set_parameters ( dimx0,V0,nu0 );last_lognc=est.lognc();dimx=dimx0;}
Index: /bdm/estim/libPF.h
===================================================================
--- /bdm/estim/libPF.h (revision 281)
+++ /bdm/estim/libPF.h (revision 283)
@@ -40,11 +40,14 @@
 	mpdf *obs;
 
+	//! which resampling method will be used
+	RESAMPLING_METHOD resmethod;
+
 	//! \name Options
 	//!@{
 
-	//! Log resampling times
-	bool opt_L_res;
 	//! Log all samples
 	bool opt_L_smp;
+	//! Log all samples
+	bool opt_L_wei;
 	//!@}
 
@@ -52,17 +55,18 @@
 	//! \name Constructors
 	//!@{
-	PF ( ) :est(), _w ( est._w() ),_samples ( est._samples() ) {};
-	PF ( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) :
-			est ( ),_w ( est._w() ),_samples ( est._samples() )
-	{ set_parameters ( par0,obs0,n0 ); set_statistics ( ones ( n0 ),epdf0 ); };
-	void set_parameters ( mpdf *par0, mpdf *obs0, int n0 )
-	{ par = par0; obs=obs0; n=n0; est.set_n ( n );};
-	void set_statistics ( const vec w0, epdf *epdf0 ) {est.set_parameters ( w0,epdf0 );};
+	PF ( ) :est(), _w ( est._w() ),_samples ( est._samples() ), opt_L_smp ( false ), opt_L_wei ( false ) {LIDs.set_size ( 5 );};
+	/*	PF ( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) :
+				est ( ),_w ( est._w() ),_samples ( est._samples() ),opt_L_smp(false), opt_L_wei(false)
+		{ set_parameters ( par0,obs0,n0 ); set_statistics ( ones ( n0 ),epdf0 ); };*/
+	void set_parameters ( mpdf *par0, mpdf *obs0, int n0, RESAMPLING_METHOD rm=SYSTEMATIC )
+	{ par = par0; obs=obs0; n=n0; resmethod= rm;};
+	void set_statistics ( const vec w0, epdf *epdf0 ) {est.set_statistics ( w0,epdf0 );};
 	//!@}
 	//! Set posterior density by sampling from epdf0
-	void set_est ( const epdf &epdf0 );
-	void set_options(const string &opt){
-		opt_L_res= ( s.find ( "logres" ) !=string::npos );
-		opt_L_smp= ( s.find ( "logsmp" ) !=string::npos );		
+//	void set_est ( const epdf &epdf0 );
+	void set_options ( const string &opt ) {
+		BM::set_options(opt);
+		opt_L_wei= ( opt.find ( "logweights" ) !=string::npos );
+		opt_L_smp= ( opt.find ( "logsamples" ) !=string::npos );
 	}
 	void bayes ( const vec &dt );
@@ -78,7 +82,6 @@
 
 template<class BM_T>
-
 class MPF : public PF {
-	BM_T* Bms[10000];
+	Array<BM_T*> BMs;
 
 	//! internal class for MPDF providing composition of eEmp with external components
@@ -94,8 +97,17 @@
 				Coms ( _w.length() ) {
 		};
+		//! read statistics from MPF
+		void read_statistics ( Array<BM_T*> &A ) {
+			dim = E.dimension() +A ( 0 )->posterior().dimension();
+			for ( int i=0; i<_w.length() ;i++ ) {Coms ( i ) = A ( i )->_e();}
+		}
+		//! needed in resampling
 		void set_elements ( int &i, double wi, const epdf* ep )
 		{_w ( i ) =wi; Coms ( i ) =ep;};
 
-		void set_n ( int n ) {E.set_n ( n ); Coms.set_length ( n );}
+		void set_parameters ( int n ) {
+			E.set_parameters ( n, false );
+			Coms.set_length ( n );
+		}
 		vec mean() const {
 			// ugly
@@ -114,4 +126,33 @@
 			return concat ( E.variance(),pom2-pow ( pom,2 ) );
 		}
+		void qbounds ( vec &lb, vec &ub, double perc=0.95 ) const {
+			//bounds on particles
+			vec lbp;
+			vec ubp;
+			E.qbounds ( lbp,ubp );
+
+			//bounds on Components
+			int dimC=Coms ( 0 )->dimension();
+			int j;
+			// temporary
+			vec lbc(dimC);
+			vec ubc(dimC);
+			// minima and maxima
+			vec Lbc(dimC);
+			vec Ubc(dimC);
+			Lbc = std::numeric_limits<double>::infinity();
+			Ubc = -std::numeric_limits<double>::infinity();
+
+			for ( int i=0;i<_w.length();i++ ) {
+				// check Coms
+				Coms ( i )->qbounds ( lbc,ubc );
+				for ( j=0;j<dimC; j++ ) {
+					if ( lbc ( j ) <Lbc ( j ) ) {Lbc ( j ) =lbc ( j );}
+					if ( ubc ( j ) >Ubc ( j ) ) {Ubc ( j ) =ubc ( j );}
+				}
+			}
+			lb=concat(lbp,Lbc);
+			ub=concat(ubp,Ubc);
+		}
 
 		vec sample() const {it_error ( "Not implemented" );return 0;}
@@ -125,44 +166,40 @@
 	//! Log means of BMs
 	bool opt_L_mea;
-	
+
 public:
 	//! Default constructor.
-	MPF ( mpdf *par0, mpdf *obs0, int n, const BM_T &BMcond0 ) : PF (), jest ( est ) {
-		PF::set_parameters ( par0,obs0,n );
-		jest.set_n ( n );
-		//
-		//TODO test if rv and BMcond.rv are compatible.
-//		rv.add ( rvlin );
-		//
-
-		if ( n>10000 ) {it_error ( "increase 10000 here!" );}
-
-		for ( int i=0;i<n;i++ ) {
-			Bms[i] = new BM_T ( BMcond0 ); //copy constructor
-			const epdf& pom=Bms[i]->posterior();
-			jest.set_elements ( i,1.0/n,&pom );
-		}
+	MPF () : PF (), jest ( est ) {};
+	void set_parameters ( mpdf *par0, mpdf *obs0, int n0, RESAMPLING_METHOD rm=SYSTEMATIC ) {
+		PF::set_parameters ( par0, obs0, n0, rm );
+		jest.set_parameters ( n0 );//duplication of rm
+		BMs.set_length ( n0 );
+	}
+	void set_statistics ( epdf *epdf0, const BM_T* BMcond0 ) {
+
+		PF::set_statistics ( ones ( n ) /n, epdf0 );
+		// copy
+		for ( int i=0;i<n;i++ ) { BMs ( i ) = new BM_T ( *BMcond0 ); BMs ( i )->condition ( _samples ( i ) );}
+
+		jest.read_statistics ( BMs );
+		//options
 	};
-
-	~MPF() {
-	}
 
 	void bayes ( const vec &dt );
 	const epdf& posterior() const {return jest;}
 	const epdf* _e() const {return &jest;} //Fixme: is it useful?
-	//! Set postrior of \c rvc to samples from epdf0. Statistics of Bms are not re-computed! Use only for initialization!
-	void set_est ( const epdf& epdf0 ) {
-		PF::set_est ( epdf0 );  // sample params in condition
-		// copy conditions to BMs
-
-		for ( int i=0;i<n;i++ ) {Bms[i]->condition ( _samples ( i ) );}
-	}
-	void set_options(const string &opt){
-		PF:set_options(opt);
-		opt_L_mea = ( s.find ( "logmeans" ) !=string::npos );
-	}
-	
+	//! Set postrior of \c rvc to samples from epdf0. Statistics of BMs are not re-computed! Use only for initialization!
+	/*	void set_est ( const epdf& epdf0 ) {
+			PF::set_est ( epdf0 );  // sample params in condition
+			// copy conditions to BMs
+
+			for ( int i=0;i<n;i++ ) {BMs(i)->condition ( _samples ( i ) );}
+		}*/
+	void set_options ( const string &opt ) {
+		PF::set_options ( opt );
+		opt_L_mea = ( opt.find ( "logmeans" ) !=string::npos );
+	}
+
 	//!Access function
-	BM* _BM ( int i ) {return Bms[i];}
+	BM* _BM ( int i ) {return BMs ( i );}
 };
 
@@ -180,7 +217,7 @@
 		_samples ( i ) = par->samplecond ( _samples ( i ) );
 		llsP ( i ) = par->_e()->evallog ( _samples ( i ) );
-		Bms[i]->condition ( _samples ( i ) );
-		Bms[i]->bayes ( dt );
-		lls ( i ) = Bms[i]->_ll(); // lls above is also in proposal her must be lls(i) =, not +=!!
+		BMs ( i )->condition ( _samples ( i ) );
+		BMs ( i )->bayes ( dt );
+		lls ( i ) = BMs ( i )->_ll(); // lls above is also in proposal her must be lls(i) =, not +=!!
 		if ( lls ( i ) >mlls ) mlls=lls ( i ); //find maximum likelihood (for numerical stability)
 	}
@@ -204,5 +241,5 @@
 	double eff = 1.0/ ( _w*_w );
 	if ( eff < ( 0.3*n ) ) {
-		ind = est.resample();
+		ind = est.resample ( resmethod );
 		// Resample Bms!
 
@@ -215,7 +252,7 @@
 				// poor-man's solution: replicate constructor here
 				// copied from MPF::MPF
-				delete Bms[i];
-				Bms[i] = new BM_T ( *Bms[ind ( i ) ] ); //copy constructor
-				const epdf& pom=Bms[i]->posterior();
+				delete BMs ( i );
+				BMs ( i ) = new BM_T ( *BMs ( ind ( i ) ) ); //copy constructor
+				const epdf& pom=BMs ( i )->posterior();
 				jest.set_elements ( i,1.0/n,&pom );
 			}
Index: /bdm/estim/merger.cpp
===================================================================
--- /bdm/estim/merger.cpp (revision 278)
+++ /bdm/estim/merger.cpp (revision 283)
@@ -33,5 +33,5 @@
 	it_assert_debug ( rv.equal ( g0->_rv() ),"Incompatible g0" );
 	//Empirical density - samples
-	eSmp.set_parameters ( ones ( Ns ), g0 );
+	eSmp.set_statistics ( ones ( Ns ), g0 );
 	Array<vec> &Smp = eSmp._samples(); //aux
 	vec &w = eSmp._w(); //aux
Index: /bdm/estim/merger.h
===================================================================
--- /bdm/estim/merger.h (revision 278)
+++ /bdm/estim/merger.h (revision 283)
@@ -71,5 +71,5 @@
 	}
 //! Set internal parameters used in approximation
-	void set_parameters ( double beta0, int Ns0, int Nc0 ) {beta=beta0;Ns=Ns0;Nc=Nc0;eSmp.set_n(Ns0,false);}
+	void set_parameters ( double beta0, int Ns0, int Nc0 ) {beta=beta0;Ns=Ns0;Nc=Nc0;eSmp.set_parameters(Ns0,false);}
 //!Initialize the proposal density. This function must be called before merge()!
 	void init() { ////////////// NOT FINISHED
Index: /bdm/estim/libKF.cpp
===================================================================
--- /bdm/estim/libKF.cpp (revision 279)
+++ /bdm/estim/libKF.cpp (revision 283)
@@ -69,5 +69,5 @@
 
 	dimx = pfxu0->_dimx();
-	dimy = phxu0->_dimy();
+	dimy = phxu0->dimension();
 	dimu = pfxu0->_dimu();
 
@@ -169,6 +169,6 @@
 	phxu = phxu0;
 
-	dimx = pfxu0->_dimy();
-	dimy = phxu0->_dimy();
+	dimx = pfxu0->dimension();
+	dimy = phxu0->dimension();
 	dimu = pfxu0->_dimu();
 	// set size of mu - just for constant terms of A and C 
@@ -249,17 +249,3 @@
 }
 
-void KFcondQR::condition ( const vec &QR ) {
-	it_assert_debug ( QR.length() == ( dimx+dimy ),"KFcondRQ: conditioning by incompatible vector" );
-
-	Q.setD ( QR ( 0, dimx-1 ) );
-	R.setD ( QR ( dimx, -1 ) );
-};
-
-void KFcondR::condition ( const vec &R0 ) {
-	it_assert_debug ( R0.length() == ( dimy ),"KFcondR: conditioning by incompatible vector" );
-
-	R.setD ( R0 );
-};
-
-
-}
+}
Index: /bdm/estim/arx.cpp
===================================================================
--- /bdm/estim/arx.cpp (revision 270)
+++ /bdm/estim/arx.cpp (revision 283)
@@ -44,5 +44,5 @@
 }
 
-ARX* ARX::_copy_ ( ) {
+ARX* ARX::_copy_ ( ) const {
 	ARX* Tmp=new ARX ( *this );
 	return Tmp;
Index: /bdm/estim/ekf_templ.h
===================================================================
--- /bdm/estim/ekf_templ.h (revision 279)
+++ /bdm/estim/ekf_templ.h (revision 283)
@@ -19,8 +19,6 @@
 
 //!Extended Kalman filter with unknown \c Q and \c R
-class EKFful_unQR : public EKFfull , public BMcond {
+class EKFful_unQR : public EKFfull  {
 public:
-	//! Default constructor
-	EKFful_unQR ( ) :EKFfull ( ),BMcond ( ) {};
 	void condition ( const vec &QR0 ) {
 		Q=diag(QR0(0,dimx-1));
@@ -30,8 +28,6 @@
 
 //!Extended Kalman filter in Choleski form with unknown \c Q
-class EKFCh_unQ : public EKFCh , public BMcond {
+class EKFCh_unQ : public EKFCh {
 public:
-	//! Default constructor
-	EKFCh_unQ (  ) :EKFCh ( ),BMcond ( ) {};
 	void condition ( const vec &Q0 ) {
 		Q.setD ( Q0,0 );
@@ -42,8 +38,6 @@
 
 //!Extended Kalman filter with unknown parameters in \c IM
-class EKFCh_cond : public EKFCh , public BMcond {
+class EKFCh_cond : public EKFCh  {
 	public:
-	//! Default constructor
-		EKFCh_cond ( ) :EKFCh ( ),BMcond ( ) {};
 		void condition ( const vec &val ) {
 			pfxu->condition ( val );
Index: /bdm/estim/libKF.h
===================================================================
--- /bdm/estim/libKF.h (revision 279)
+++ /bdm/estim/libKF.h (revision 283)
@@ -19,5 +19,5 @@
 #include "../math/chmat.h"
 
-namespace bdm{
+namespace bdm {
 
 /*!
@@ -49,5 +49,5 @@
 	friend std::ostream &operator<< ( std::ostream &os, const KalmanFull &kf );
 	//! For EKFfull;
-	KalmanFull(){};
+	KalmanFull() {};
 };
 
@@ -56,7 +56,7 @@
 * \brief Kalman filter with covariance matrices in square root form.
 
-Parameter evolution model:\f[ x_t = A x_{t-1} + B u_t + Q^{1/2} e_t \f] 
+Parameter evolution model:\f[ x_t = A x_{t-1} + B u_t + Q^{1/2} e_t \f]
 Observation model: \f[ y_t = C x_{t-1} + C u_t + Q^{1/2} w_t. \f]
-Where $e_t$ and $w_t$ are independent vectors Normal(0,1)-distributed disturbances. 
+Where $e_t$ and $w_t$ are independent vectors Normal(0,1)-distributed disturbances.
 */
 template<class sq_T>
@@ -77,5 +77,5 @@
 	mat A;
 	//! Matrix B
-	mat B; 
+	mat B;
 	//! Matrix C
 	mat C;
@@ -112,7 +112,7 @@
 	//! Set estimate values, used e.g. in initialization.
 	void set_est ( const vec &mu0, const sq_T &P0 ) {
-		sq_T pom(dimy);
+		sq_T pom ( dimy );
 		est.set_parameters ( mu0,P0 );
-		P0.mult_sym(C,pom);
+		P0.mult_sym ( C,pom );
 		fy.set_parameters ( C*mu0, pom );
 	};
@@ -133,16 +133,21 @@
 Trivial example:
 \include kalman_simple.cpp
- 
-*/
-class KalmanCh : public Kalman<chmat>{
+
+*/
+class KalmanCh : public Kalman<chmat> {
 protected:
 //! pre array (triangular matrix)
-mat preA;
+	mat preA;
 //! post array (triangular matrix)
-mat postA;
-
-public:
-	//! Default constructor
-	KalmanCh ():Kalman<chmat>(),preA(),postA(){};
+	mat postA;
+
+public:
+	//! copy constructor
+	BM* _copy_() const {
+		KalmanCh* K=new KalmanCh;
+		K->set_parameters ( A,B,C,D,Q,R );
+		K->set_statistics ( _mu,_P );
+		return K;
+	}
 	//! Set parameters with check of relevance
 	void set_parameters ( const mat &A0,const mat &B0,const mat &C0,const mat &D0,const chmat &Q0,const chmat &R0 );
@@ -150,18 +155,18 @@
 		est.set_parameters ( mu0,P0 );
 	};
-	
-	
+
+
 	/*!\brief  Here dt = [yt;ut] of appropriate dimensions
-	
+
 	The following equality hold::\f[
-\left[\begin{array}{cc}
-R^{0.5}\\
-P_{t|t-1}^{0.5}C' & P_{t|t-1}^{0.5}CA'\\
- & Q^{0.5}\end{array}\right]<\mathrm{orth.oper.}>=\left[\begin{array}{cc}
-R_{y}^{0.5} & KA'\\
- & P_{t+1|t}^{0.5}\\
-\\\end{array}\right]\f]
-
-Thus this object evaluates only predictors! Not filtering densities.
+	\left[\begin{array}{cc}
+	R^{0.5}\\
+	P_{t|t-1}^{0.5}C' & P_{t|t-1}^{0.5}CA'\\
+	& Q^{0.5}\end{array}\right]<\mathrm{orth.oper.}>=\left[\begin{array}{cc}
+	R_{y}^{0.5} & KA'\\
+	& P_{t+1|t}^{0.5}\\
+	\\\end{array}\right]\f]
+
+	Thus this object evaluates only predictors! Not filtering densities.
 	*/
 	void bayes ( const vec &dt );
@@ -179,6 +184,6 @@
 	//! Observation Model h(x,u)
 	diffbifn* phxu;
-	
-	enorm<fsqmat> E; 
+
+	enorm<fsqmat> E;
 public:
 	//! Default constructor
@@ -189,9 +194,9 @@
 	void bayes ( const vec &dt );
 	//! set estimates
-	void set_est (vec mu0, mat P0){mu=mu0;P=P0;};
+	void set_est ( vec mu0, mat P0 ) {mu=mu0;P=P0;};
 	//!dummy!
-	const epdf& posterior()const{return E;};
-	const enorm<fsqmat>* _e()const{return &E;};
-	const mat _R(){return P;}
+	const epdf& posterior() const{return E;};
+	const enorm<fsqmat>* _e() const{return &E;};
+	const mat _R() {return P;}
 };
 
@@ -210,4 +215,6 @@
 	//! Default constructor
 	EKF ( RV rvx, RV rvy, RV rvu );
+	//! copy constructor
+	EKF<sq_T>* _copy_() const { return new EKF<sq_T>(this); }
 	//! Set nonlinear functions for mean values and covariance matrices.
 	void set_parameters ( diffbifn* pfxu, diffbifn* phxu, const sq_T Q0, const sq_T R0 );
@@ -223,5 +230,5 @@
 
 class EKFCh : public KalmanCh {
-	protected:
+protected:
 	//! Internal Model f(x,u)
 	diffbifn* pfxu;
@@ -229,4 +236,11 @@
 	diffbifn* phxu;
 public:
+	//! copy constructor duplicated - calls different set_parameters
+	BM* _copy_() const {
+		EKFCh* E=new EKFCh;
+		E->set_parameters ( pfxu,phxu,Q,R );
+		E->set_statistics ( _mu,_P );
+		return E;
+	}
 	//! Set nonlinear functions for mean values and covariance matrices.
 	void set_parameters ( diffbifn* pfxu, diffbifn* phxu, const chmat Q0, const chmat R0 );
@@ -239,24 +253,31 @@
 */
 
-class KFcondQR : public Kalman<ldmat>, public BMcond {
+class KFcondQR : public Kalman<ldmat> {
 //protected:
 public:
+	void condition ( const vec &QR ) {
+		it_assert_debug ( QR.length() == ( dimx+dimy ),"KFcondRQ: conditioning by incompatible vector" );
+
+		Q.setD ( QR ( 0, dimx-1 ) );
+		R.setD ( QR ( dimx, -1 ) );
+	};
+};
+
+/*!
+\brief Kalman Filter with conditional diagonal matrices R and Q.
+*/
+
+class KFcondR : public Kalman<ldmat> {
+//protected:
+public:
 	//!Default constructor
-	KFcondQR ( ) : Kalman<ldmat> ( ),BMcond ( ) {};
-
-	void condition ( const vec &RQ );
-};
-
-/*!
-\brief Kalman Filter with conditional diagonal matrices R and Q.
-*/
-
-class KFcondR : public Kalman<ldmat>, public BMcond {
-//protected:
-public:
-	//!Default constructor
-	KFcondR ( ) : Kalman<ldmat> ( ),BMcond ( ) {};
-
-	void condition ( const vec &R );
+	KFcondR ( ) : Kalman<ldmat> ( ) {};
+
+	void condition ( const vec &R0 ) {
+		it_assert_debug ( R0.length() == ( dimy ),"KFcondR: conditioning by incompatible vector" );
+
+		R.setD ( R0 );
+	};
+
 };
 
@@ -267,6 +288,6 @@
 		dimx ( K0.dimx ), dimy ( K0.dimy ),dimu ( K0.dimu ),
 		A ( K0.A ), B ( K0.B ), C ( K0.C ), D ( K0.D ),
-		Q(K0.Q), R(K0.R),
-		est ( K0.est ), fy ( K0.fy ), _yp(fy._mu()),_Ry(fy._R()), _mu(est._mu()), _P(est._R()) {
+		Q ( K0.Q ), R ( K0.R ),
+		est ( K0.est ), fy ( K0.fy ), _yp ( fy._mu() ),_Ry ( fy._R() ), _mu ( est._mu() ), _P ( est._R() ) {
 
 // copy values in pointers
@@ -279,5 +300,5 @@
 
 template<class sq_T>
-Kalman<sq_T>::Kalman ( ) : BM (), est ( ), fy (),  _yp(fy._mu()), _Ry(fy._R()), _mu(est._mu()), _P(est._R()) {
+Kalman<sq_T>::Kalman ( ) : BM (), est ( ), fy (),  _yp ( fy._mu() ), _Ry ( fy._R() ), _mu ( est._mu() ), _P ( est._R() ) {
 };
 
@@ -287,5 +308,5 @@
 	dimy = C0.rows();
 	dimu = B0.cols();
-	
+
 	it_assert_debug ( A0.cols() ==dimx, "Kalman: A is not square" );
 	it_assert_debug ( B0.rows() ==dimx, "Kalman: B is not compatible" );
@@ -307,5 +328,5 @@
 	it_assert_debug ( dt.length() == ( dimy+dimu ),"KalmanFull::bayes wrong size of dt" );
 
-	sq_T iRy(dimy);
+	sq_T iRy ( dimy );
 	vec u = dt.get ( dimy,dimy+dimu-1 );
 	vec y = dt.get ( 0,dimy-1 );
@@ -328,7 +349,7 @@
 	sq_T pom ( ( int ) Pfull.rows() );
 	iRy.mult_sym_t ( C*Pfull,pom );
-	(_P ) -= pom; // P = P -PC'iRy*CP;
-	(_yp ) = C* _mu  +D*u; //y prediction
-	(_mu ) += _K* ( y- _yp  );
+	( _P ) -= pom; // P = P -PC'iRy*CP;
+	( _yp ) = C* _mu  +D*u; //y prediction
+	( _mu ) += _K* ( y- _yp );
 
 
@@ -340,5 +361,5 @@
 
 };
- 
+
 
 
@@ -369,5 +390,5 @@
 	it_assert_debug ( dt.length() == ( dimy+dimu ),"KalmanFull::bayes wrong size of dt" );
 
-	sq_T iRy(dimy,dimy);
+	sq_T iRy ( dimy,dimy );
 	vec u = dt.get ( dimy,dimy+dimu-1 );
 	vec y = dt.get ( 0,dimy-1 );
@@ -393,5 +414,5 @@
 	sq_T pom ( ( int ) Pfull.rows() );
 	iRy.mult_sym_t ( C*Pfull,pom );
-	(_P ) -= pom; // P = P -PC'iRy*CP;
+	( _P ) -= pom; // P = P -PC'iRy*CP;
 	_yp = phxu->eval ( _mu,u ); //y prediction
 	( _mu ) += _K* ( y-_yp );
Index: /bdm/estim/libPF.cpp
===================================================================
--- /bdm/estim/libPF.cpp (revision 278)
+++ /bdm/estim/libPF.cpp (revision 283)
@@ -1,5 +1,5 @@
 #include "libPF.h"
 
-namespace bdm{
+namespace bdm {
 
 using std::endl;
@@ -13,6 +13,6 @@
 	for ( i=0;i<n;i++ ) {
 		//generate new samples from paramater evolution model;
-		_samples ( i ) = par->samplecond ( _samples ( i ));
-		lls(i )= par->_e()->evallog(_samples(i));
+		_samples ( i ) = par->samplecond ( _samples ( i ) );
+		lls ( i ) = par->_e()->evallog ( _samples ( i ) );
 		lls ( i ) *= obs->evallogcond ( dt,_samples ( i ) );
 
@@ -30,15 +30,16 @@
 	_w ( i ) /=sum; //?
 
-	ind = est.resample();
+	ind = est.resample(resmethod);
 
 }
 
-void PF::set_est ( const epdf &epdf0 ) {
-	int i;
+// void PF::set_est ( const epdf &epdf0 ) {
+// 	int i;
+// 
+// 	for ( i=0;i<n;i++ ) {
+// 		_samples ( i ) = epdf0.sample();
+// 	}
+// }
 
-	for ( i=0;i<n;i++ ) {
-		_samples ( i ) = epdf0.sample();
-	}
-}
 
 }
Index: /bdm/stat/libEF.cpp
===================================================================
--- /bdm/stat/libEF.cpp (revision 281)
+++ /bdm/stat/libEF.cpp (revision 283)
@@ -183,5 +183,5 @@
 };
 
-ivec eEmp::resample ( RESAMPLING_METHOD method ) {
+ivec eEmp::resample (RESAMPLING_METHOD method) {
 	ivec ind=zeros_i ( n );
 	ivec N_babies = zeros_i ( n );
@@ -268,5 +268,5 @@
 }
 
-void eEmp::set_parameters ( const vec &w0, const epdf* epdf0 ) {
+void eEmp::set_statistics ( const vec &w0, const epdf* epdf0 ) {
 	//it_assert_debug(rv==epdf0->rv(),"Wrong epdf0");
 	dim = epdf0->dimension();
Index: /bdm/stat/libDS.h
===================================================================
--- /bdm/stat/libDS.h (revision 271)
+++ /bdm/stat/libDS.h (revision 283)
@@ -28,4 +28,5 @@
 */
 class MemDS : public DS {
+	protected:
 	//! internal matrix of data
 	mat Data;
@@ -45,5 +46,33 @@
 	void step();
 	//!Default constructor
+	MemDS () {};
 	MemDS ( mat &Dat, ivec &rowid, ivec &delays );
+};
+
+/*! Read Data Matrix from an IT file
+
+*/
+class FileDS: public MemDS {
+
+public:
+	FileDS ( const string &fname, const string &varname ) :MemDS() {
+		it_file it ( fname );
+		it << Name ( varname ); 
+		it >> Data;
+		time =0;
+		//rowid and delays are ignored
+	}
+	void getdata ( vec &dt ) {
+		it_assert_debug ( dt.length() ==Data.rows(),"" );
+		dt = Data.get_col(time);
+	};
+	void getdata ( vec &dt, const ivec &indeces ){
+		it_assert_debug ( dt.length() ==indeces.length(),"" );
+		vec tmp(indeces.length());
+		tmp = Data.get_col(time);
+		dt = tmp(indeces);
+	};
+	//! returns number of data in the file;
+	int ndat(){return Data.cols();}
 };
 
@@ -96,20 +125,20 @@
 	{ model.set_parameters ( Th0, mu0, sqR0 );};
 	//! Set
-	void set_drv(RV &yrv, RV &urv, RV &rrv){
+	void set_drv ( RV &yrv, RV &urv, RV &rrv ) {
 		Rrv = rrv;
 		Urv = urv;
-		dt_size = yrv._dsize()+urv._dsize();
-		
-		RV drv = concat(yrv,urv);
+		dt_size = yrv._dsize() +urv._dsize();
+
+		RV drv = concat ( yrv,urv );
 		Drv = drv;
 		int td = rrv.mint();
-		H.set_size(drv._dsize()*(-td+1));
-		U.set_size(Urv._dsize());
-		for (int i=-1;i>=td;i--){
-			drv.t(-1);
-			Drv.add(drv); //shift u1
+		H.set_size ( drv._dsize() * ( -td+1 ) );
+		U.set_size ( Urv._dsize() );
+		for ( int i=-1;i>=td;i-- ) {
+			drv.t ( -1 );
+			Drv.add ( drv ); //shift u1
 		}
-		rgrlnk.set_connection(rrv,Drv);
-		
+		rgrlnk.set_connection ( rrv,Drv );
+
 		dtsize = Drv._dsize();
 		utsize = Urv._dsize();
@@ -121,5 +150,5 @@
 	virtual void log_add ( logger &L ) {
 		//DS::log_add ( L ); too long!!
-		L_dt=L.add ( Drv(0,dt_size),"" );
+		L_dt=L.add ( Drv ( 0,dt_size ),"" );
 		L_ut=L.add ( Urv,"" );
 
@@ -131,7 +160,7 @@
 	virtual void logit ( logger &L ) {
 		//DS::logit ( L );
-		L.logit( L_dt, H.left(dt_size));
-		L.logit(L_ut, U);
-		
+		L.logit ( L_dt, H.left ( dt_size ) );
+		L.logit ( L_ut, U );
+
 		mat &A =model._A();
 		mat R =model._R();
Index: /bdm/stat/libEF.h
===================================================================
--- /bdm/stat/libEF.h (revision 281)
+++ /bdm/stat/libEF.h (revision 283)
@@ -94,5 +94,5 @@
 //	virtual void flatten ( double nu0 ) {it_error ( "Not implemented" );}
 
-	BMEF* _copy_ ( bool changerv=false ) {it_error ( "function _copy_ not implemented for this BM" ); return NULL;};
+	BMEF* _copy_ ( bool changerv=false ) const {it_error ( "function _copy_ not implemented for this BM" ); return NULL;};
 };
 
@@ -348,4 +348,6 @@
  \f]
 
+Vector \f$\beta\f$ has different meaning (in fact it is 1/beta as used in definition of iG)
+
  Inverse Gamma can be converted to Gamma using \f[
  x\sim iG(a,b) => 1/x\sim G(a,1/b)
@@ -354,30 +356,16 @@
  */
 
-class eigamma : public eEF {
-protected:
-	//!internal egamma
-	egamma eg;
-	//! Vector \f$\alpha\f$
-	vec &alpha;
-	//! Vector \f$\beta\f$ (in fact it is 1/beta as used in definition of iG)
-	vec &beta;
+class eigamma : public egamma {
+protected:
 public :
 	//! \name Constructors
-	//!@{
-	eigamma ( ) :eEF ( ), eg(),alpha ( eg._alpha() ), beta ( eg._beta() ) {};
-	eigamma ( const vec &a, const vec &b ) :eEF ( ), eg(),alpha ( eg._alpha() ), beta ( eg._beta() ) {eg.set_parameters ( a,b );};
-	void set_parameters ( const vec &a, const vec &b ) {eg.set_parameters ( a,b );};
-	//!@}
-
-	vec sample() const {return 1.0/eg.sample();};
-	//! TODO: is it used anywhere?
-//	mat sample ( int N ) const;
-	double evallog ( const vec &val ) const {return eg.evallog ( val );};
-	double lognc () const {return eg.lognc();};
+	//! All constructors are inherited
+	//!@{
+	//!@}
+
+	vec sample() const {return 1.0/egamma::sample();};
 	//! Returns poiter to alpha and beta. Potentially dangerous: use with care!
 	vec mean() const {return elem_div ( beta,alpha-1 );}
 	vec variance() const {vec mea=mean(); return elem_div ( elem_mult ( mea,mea ),alpha-2 );}
-	vec& _alpha() {return alpha;}
-	vec& _beta() {return beta;}
 };
 /*
@@ -490,5 +478,5 @@
 	mgnorm() :mu ( epdf._mu() ) {ep=&epdf;}
 	//!set mean function
-	void set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; epdf.set_parameters ( zeros ( g->_dimy() ), R0 );}
+	void set_parameters ( fnc* g0, const sq_T &R0 ) {g=g0; epdf.set_parameters ( zeros ( g->dimension() ), R0 );}
 	void condition ( const vec &cond ) {mu=g->eval ( cond );};
 };
@@ -686,9 +674,11 @@
 
 	//! Set samples and weights
-	void set_parameters ( const vec &w0, const epdf* pdf0 );
+	void set_statistics ( const vec &w0, const epdf* pdf0 );
+	//! Set samples and weights
+	void set_statistics ( const epdf* pdf0 , int n ) {set_statistics ( ones ( n ) /n,pdf0 );};
 	//! Set sample
 	void set_samples ( const epdf* pdf0 );
 	//! Set sample
-	void set_n ( int n0, bool copy=true ) {n=n0; w.set_size ( n0,copy );samples.set_size ( n0,copy );};
+	void set_parameters ( int n0, bool copy=true ) {n=n0; w.set_size ( n0,copy );samples.set_size ( n0,copy );};
 	//! Potentially dangerous, use with care.
 	vec& _w()  {return w;};
@@ -700,5 +690,5 @@
 	const Array<vec>& _samples() const {return samples;};
 	//! Function performs resampling, i.e. removal of low-weight samples and duplication of high-weight samples such that the new samples represent the same density.
-	ivec resample ( RESAMPLING_METHOD method = SYSTEMATIC );
+	ivec resample ( RESAMPLING_METHOD method=SYSTEMATIC );
 	//! inherited operation : NOT implemneted
 	vec sample() const {it_error ( "Not implemented" );return 0;}
@@ -714,4 +704,19 @@
 		for ( int i=0;i<n;i++ ) {pom+=pow ( samples ( i ),2 ) *w ( i );}
 		return pom-pow ( mean(),2 );
+	}
+	//! For this class, qbounds are minimum and maximum value of the population!
+	void qbounds ( vec &lb, vec &ub, double perc=0.95 ) const {
+		// lb in inf so than it will be pushed below;
+		lb.set_size(dim);
+		ub.set_size(dim);
+		lb = std::numeric_limits<double>::infinity();
+		ub = -std::numeric_limits<double>::infinity();
+		int j;
+		for ( int i=0;i<n;i++ ) {
+			for ( j=0;j<dim; j++ ) {
+				if ( samples ( i ) ( j ) <lb ( j ) ) {lb ( j ) =samples ( i ) ( j );}
+				if ( samples ( i ) ( j ) >ub ( j ) ) {ub ( j ) =samples ( i ) ( j );}
+			}
+		}
 	}
 };
Index: /bdm/stat/libBM.h
===================================================================
--- /bdm/stat/libBM.h (revision 281)
+++ /bdm/stat/libBM.h (revision 283)
@@ -126,7 +126,7 @@
 	int length() const {return len;} ;
 	int id ( int at ) const{return ids ( at );};
-	int size ( int at ) const {return RV_SIZES ( ids(at) );};
+	int size ( int at ) const {return RV_SIZES ( ids ( at ) );};
 	int time ( int at ) const{return times ( at );};
-	std::string name ( int at ) const {return RV_NAMES ( ids(at) );};
+	std::string name ( int at ) const {return RV_NAMES ( ids ( at ) );};
 	void set_time ( int at, int time0 ) {times ( at ) =time0;};
 	//!@}
@@ -204,5 +204,5 @@
 
 	//! access function
-	int _dimy() const{return dimy;}
+	int dimension() const{return dimy;}
 };
 
@@ -259,4 +259,9 @@
 	//! return expected variance (not covariance!)
 	virtual vec variance() const {it_error ( "not implemneted" );return vec ( 0 );};
+	//! Lower and upper bounds of \c percentage % quantile, returns mean-2*sigma as default
+	virtual void qbounds ( vec &lb, vec &ub, double percentage=0.95 ) const {
+		vec mea=mean(); vec std=sqrt(variance()); 
+		lb = mea-2*std; ub=mea+2*std;
+	};
 	//!@}
 
@@ -592,4 +597,21 @@
 /*! \brief Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.
 
+This object represents exact or approximate evaluation of the Bayes rule:
+\f[
+f(\theta_t | d_1,\ldots,d_t) = \frac{f(y_t|\theta_t,\cdot) f(\theta_t|d_1,\ldots,d_{t-1})}{f(y_t|d_1,\ldots,d_{t-1})}
+\f]
+
+Access to the resulting posterior density is via function \c posterior().
+
+As a "side-effect" it also evaluates log-likelihood of the data, which can be accessed via function _ll().
+It can also evaluate predictors of future values of \f$y_t\f$, see functions epredictor() and predictor().
+
+Alternatively, it can evaluate posterior density conditioned by a known constant, \f$ c_t \f$:
+\f[
+f(\theta_t | c_t, d_1,\ldots,d_t) \propto  f(y_t,\theta_t|c_t,\cdot, d_1,\ldots,d_{t-1})
+\f]
+
+The value of \f$ c_t \f$ is set by function condition().
+
 */
 
@@ -606,9 +628,9 @@
 	//! @{
 
-	BM () :ll ( 0 ),evalll ( true) {};
+	BM () :ll ( 0 ),evalll ( true ), LIDs ( 3 ), opt_L_bounds ( false ) {};
 	BM ( const BM &B ) :  drv ( B.drv ), ll ( B.ll ), evalll ( B.evalll ) {}
 	//! Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually!
-	//! Prototype: \code BM* _copy_(){return new BM(*this);} \endcode
-	virtual BM* _copy_ () {return NULL;};
+	//! Prototype: \code BM* _copy_() const {return new BM(*this);} \endcode
+	virtual BM* _copy_ () const {return NULL;};
 	//!@}
 
@@ -634,4 +656,20 @@
 	//!@}
 
+	//! \name Extension to conditional BM
+	//! This extension is useful e.g. in Marginalized Particle Filter (\ref bdm::MPF).
+	//! Alternatively, it can be used for automated connection to DS when the condition is observed
+	//!@{
+
+	//! Name of extension variable
+	RV rvc;
+	//! access function
+	const RV& _rvc() const {return rvc;}
+
+	//! Substitute \c val for \c rvc.
+	virtual void condition ( const vec &val ) {it_error ( "Not implemented!" );};
+
+	//!@}
+
+
 	//! \name Access to attributes
 	//!@{
@@ -646,30 +684,40 @@
 	//!@}
 
-};
-
-/*!
-\brief Conditional Bayesian Filter
-
-Evaluates conditional filtering density \f$f(rv|rvc,data)\f$ for a given \c rvc which is specified in each step by calling function \c condition.
-
-This is an interface class used to assure that certain BM has operation \c condition .
-
-*/
-
-class BMcond :public bdmroot {
-protected:
-	//!dimension of the conditioning variable
-	int dimc;
-	//! Identificator of the conditioning variable
-	RV rvc;
-public:
-	//! Substitute \c val for \c rvc.
-	virtual void condition ( const vec &val ) =0;
-	//! Default constructor
-	BMcond ( ) :rvc ( ) {};
-	//! Destructor for future use
-	virtual ~BMcond() {};
-	//! access function
-	const RV& _rvc() const {return rvc;}
+	//! \name Logging of results
+	//!@{
+
+	//! Set boolean options from a string
+	void set_options ( const string &opt ) {
+		opt_L_bounds= ( opt.find ( "logbounds" ) !=string::npos );
+	}
+	//! IDs of storages in loggers
+	ivec LIDs;
+
+	//! Option for logging bounds
+	bool opt_L_bounds;
+	//! Add all logged variables to a logger
+	void log_add ( logger *L, const string &name="" ) {
+		// internal
+		RV r;
+		if ( posterior().isnamed() ) {r=posterior()._rv();}
+		else{r=RV ( "est", posterior().dimension() );};
+
+		// Add mean value
+		LIDs ( 0 ) =L->add ( r,name );
+		if ( opt_L_bounds ) {
+			LIDs ( 1 ) =L->add ( r,name+"_lb" );
+			LIDs ( 2 ) =L->add ( r,name+"_ub" );
+		}
+	}
+	void logit ( logger *L ) {
+		L->logit ( LIDs ( 0 ), posterior().mean() );
+		if ( opt_L_bounds ) {
+			vec ub,lb;
+			posterior().qbounds(lb,ub);
+			L->logit ( LIDs ( 1 ), lb );
+			L->logit ( LIDs ( 2 ), ub );
+		}
+	}
+	//!@}
 };
 
Index: /tests/testKF_QR.cpp
===================================================================
--- /tests/testKF_QR.cpp (revision 278)
+++ /tests/testKF_QR.cpp (revision 283)
@@ -61,8 +61,8 @@
 	evolQR.set_parameters(10.0,"1 1 1"); //sigma = 1/10 mu
 	
-	MPF<KFcondQR > KF_QR(&evolQR,&evolQR,100,KF);
+	MPF<KFcondQR> KF_QR;
+	KF_QR.set_parameters(&evolQR,&evolQR,100);
 	evolQR.condition("1 1 1");
-	epdf& pfinit=evolQR._epdf();
-	KF_QR.set_est(pfinit);
+	KF_QR.set_statistics(evolQR._e(), &KF);
 	const epdf& mpost=KF_QR.posterior();
 	const epdf& mposttr=KFtr.posterior();
Index: /tests/testPF.cpp
===================================================================
--- /tests/testPF.cpp (revision 278)
+++ /tests/testPF.cpp (revision 283)
@@ -23,5 +23,5 @@
 	euni eun;
 	eun.set_parameters("0","1");
-	emp.set_parameters(ones(10),&eun);
+	emp.set_statistics(ones(10),&eun);
 	vec &v=emp._w();
 	Array<vec> &S=emp._samples();
Index: /tests/testResample.cpp
===================================================================
--- /tests/testResample.cpp (revision 278)
+++ /tests/testResample.cpp (revision 283)
@@ -23,5 +23,5 @@
 	euni eun;
 	eun.set_parameters("0","1");
-	emp.set_parameters(ones(10),&eun);
+	emp.set_statistics(ones(10),&eun);
 	vec &v=emp._w();
 	Array<vec> &S=emp._samples();
Index: /doprava/model.h
===================================================================
--- /doprava/model.h (revision 278)
+++ /doprava/model.h (revision 283)
@@ -5,10 +5,4 @@
 
 using namespace bdm;
-
-//Tady se naplni "popis" jednotlivych nahodnych velicin na kterych se pracuje
-// Moznosti je velmi mnoho (viz doc/html/index.html): napriklad
-RV RVstav ( "{stav }", "4");  // Vyrabim stav velikosti 4
-RV RVut ( "{ut }", "2");     // Vstup velikosti 2
-RV RVpozor ( "{I1 O1 }");     //Vystup je intenzita a obsazenost
 
 //! Model stredni hodnoty vyvoje stavu pro k1 
@@ -19,5 +13,5 @@
 public:
 	//! Constructor
-	IMk1() :diffbifn (RVstav.count(), RVstav, RVut ) {}; 
+	IMk1() :diffbifn () {dimy=4; dimx=3; dimu=1;}; 
 	//! set CONSTANT parameters
 	void set_parameters ( double alp10,  double alp20) {alp1=alp10; alp2=alp20;}
@@ -25,5 +19,5 @@
 	vec eval ( const vec &x0, const vec &u0 ) {
 		// napln stav nulami
-		vec xk=zeros ( RVstav.count() );
+		vec xk=zeros ( dimy );
 
 		xk ( 0 ) = 0.2* x0(1) - 0.1* x0(2)+ u0(0);  // vycucane z prstu
@@ -39,5 +33,5 @@
 
 		if (full) { // priznak full se nastavi na zacatku => je treba naplnit celou matici
-			A = eye(RVstav.count());
+			A = eye(dimy);
 			A(0,1) = 0.2;
 			A(0,2) = -0.1;
@@ -54,8 +48,8 @@
 public:
 	//! Constructor
-	OMk1() :diffbifn (RVpozor.count(), RVstav, RVut ) {}; 
+	OMk1() :diffbifn ( ) {dimy=2;dimx=3;dimu=2;}; //<======= TODO 
 	// Model pozorovani  je trivialni jen se zkopiruji stavy
 	vec eval(const vec &x0, const vec &u0 ){
-		vec dt(RVpozor.count());
+		vec dt(dimy);
 		// Pozoruji pouze prvni dva stavy
 		dt(0) = x0(0);
@@ -68,5 +62,5 @@
 
 		if (full) { // priznak full se nastavi na zacatku => je treba naplnit celou matici
-			A = zeros(RVpozor.count(),RVstav.count());
+			A = zeros(dimy,dimx);
 			A(0,0)=1.0;
 			A(1,1)=1.0;
Index: /doprava/k1.cpp
===================================================================
--- /doprava/k1.cpp (revision 278)
+++ /doprava/k1.cpp (revision 283)
@@ -12,7 +12,7 @@
 
 
-#include <stat/libFN.h>
 #include <estim/ekf_templ.h>
-#include <stat/loggers.h>
+#include <stat/loggers_ui.h>
+#include <stat/libDS_ui.h>
 
 //include dopravni model
@@ -21,11 +21,17 @@
 using namespace bdm;
 
-int main() {
-	// Pocet dat
-	int Ndat = 900;
-
-	// Objekt pro ukladani vysledku
-	memlog L(Ndat);
-
+int main( int argc, char* argv[] ) {
+/*	const char *fname;
+	if ( argc>1 ) {fname = argv[1];	}
+	else { fname = "k1.cfg"; }
+	UIFile F ( fname ); //protected by exceptions, should complain if not found*/
+	
+	FileDS DS("data.it","Data");		// Data Source
+	int ndat = DS.ndat();				// number of data
+	memlog L(ndat);						// Logger
+	string resfile="k1_results.it";		// name of output file
+	vec dQ="0.1 0.1";
+	vec dR="0.2 0.2";					// TODO: read from config file <== broken on windows
+	
 	//model vyvoje stavu
 	IMk1 fxu;
@@ -37,52 +43,26 @@
 
 	// ESTIMATOR --- EKF
-	vec mu0= "0.0 0.0 0.0 0.0";
 	// Priprava covariancnich matic pro EKF
-	vec Qdiag ( "1.0 10. 10 10" ); 
-	vec Rdiag ( "1 1" ); //var(diff(xth)) = "0.034 0.034"
-	mat Q =diag( Qdiag );
-	mat R =diag ( Rdiag );
-	EKFfull Efix ( RVstav,RVpozor,RVut );
-	// pocatecni podminky
-	Efix.set_est ( mu0, 1*eye ( 4 )  ); // nulova 
-	// nastaveni modelu pro EKF
-	Efix.set_parameters ( &fxu,&hxu,Q,R);
+	EKFCh Efix; 								//Extended KF s fix. variancemi
+	Efix.set_parameters ( &fxu,&hxu,diag(dQ),diag(dR));
+	Efix.set_statistics ( zeros(fxu.dimension()), 100*eye ( fxu.dimension() )  ); // nulova 
 
-	int L_xt = L.add(RVstav, "xt"); // Tady se rika jak velky vektor (pomoci obj. RV) se bude logovat 
-										// A jak se bude jsmenovat vysledek
-	int L_ut = L.add(RVut, "ut"); // Tady se rika jak velky vektor (pomoci obj. RV) se bude logovat 
-										// A jak se bude jsmenovat vysledek
-	int L_mean = L.add(RVstav, "odh_xt"); // Tady se rika jak velky vektor (pomoci obj. RV) se bude logovat 
-										// A jak se bude jsmenovat vysledek
-
+	// Definovat co se bude logovat
+	Efix.log_add(&L,"E");
 	L.init(); // <<==== allocate memory for results
-	// Priprava poli pro simulaci
-	vec ut(RVut.count()); 
-	vec xt(RVstav.count()); 
-	vec dt(RVpozor.count()); 
-	// minuly stav
-	vec xtm=zeros(RVstav.count()); // nulovy pocatecni stav
-	for ( int t=1;t<Ndat;t++ ) {
-		// Nastaveni vstupu
-		ut(0) = 1+sin((double)t/10); // V ut jsou same jednicky
-		ut(1) = 1+cos((double)t/10); // V ut jsou same jednicky
-		
-		// Generovani DAT modelem
-		xt = fxu.eval(xtm,ut);
-		dt = hxu.eval(xt,ut);
-		xtm = xt; //save xt for the next step
-
-		//ESTIMATE
-		Efix.bayes(concat(dt,ut));
+	
+	vec dt;
+	for ( int t=1;t<ndat;t++ ) {
+		DS.getdata(dt);			// dt is allocated
+		Efix.bayes(dt);			//ESTIMATE
 
 		//LOG results
-		L.logit(L_mean, Efix.posterior().mean() ); 
-		L.logit(L_xt, xt ); 
-		L.logit(L_ut, ut ); 
+		Efix.logit(&L); 
 		
 		L.step();
+		DS.step();
 	}
 	L.finalize();
-	L.itsave("k1.it");
+	L.itsave(resfile.c_str());
 	return 0;
 }
Index: /pmsm/simulator_zdenek/ekf_example/ekf_obj.h
===================================================================
--- /pmsm/simulator_zdenek/ekf_example/ekf_obj.h (revision 279)
+++ /pmsm/simulator_zdenek/ekf_example/ekf_obj.h (revision 283)
@@ -30,5 +30,5 @@
 An approximation of the exact Bayesian filter with Gaussian noices and non-linear evolutions of their mean.
 */
-class EKFfixed : public BM, public BMcond {
+class EKFfixed : public BM {
 public:
 void init_ekf(double Tv);
@@ -64,5 +64,5 @@
 public:
 	//! Default constructor
-	EKFfixed ():BM(),BMcond(),E(),Ry(2,2){
+	EKFfixed ():BM(),E(),Ry(2,2){
 	int i;
  for(i=0;i<16;i++){Q[i]=0;}
Index: /pmsm/TR2245/unitsteps.cpp
===================================================================
--- /pmsm/TR2245/unitsteps.cpp (revision 281)
+++ /pmsm/TR2245/unitsteps.cpp (revision 283)
@@ -61,4 +61,5 @@
 	KFE.set_parameters ( &fxu,&hxu,Q,R );
 	KFE.set_est ( mu0, chmat ( zeros ( 4 ) ) );
+	KFE.set_rv(rx);
 
 	RV rQ ( "{Q }","4" );
@@ -66,26 +67,26 @@
 	KFEp.set_parameters ( &fxu,&hxu,Q,R );
 	KFEp.set_est ( mu0, chmat ( zeros ( 4 ) ) );
-
-	//mgamma_fix evolQ ( rQ,rQ );
+	
 	migamma_fix evolQ ;
-	MPF<EKFCh_unQ> M ( &evolQ,&evolQ,Npart,KFEp );
+	MPF<EKFCh_unQ> M;
+	M.set_parameters( &evolQ,&evolQ,Npart);
 	// initialize
 	evolQ.set_parameters ( 0.1, 10*Qdiag, 1.0 ); //sigma = 1/10 mu
 	evolQ.condition ( 10*Qdiag ); //Zdenek default
-	M.set_est ( *evolQ._e() );
+	M.set_statistics ( evolQ._e() , &KFEp );
 	evolQ.set_parameters ( 0.10, 10*Qdiag,0.999 ); //sigma = 1/10 mu
 	//
 
-	const epdf& KFEep = KFE.posterior();
-	const epdf& Mep = M.posterior();
-
+	M.set_rv(concat(rQ,rx));
+	
 	dirfilelog *L; UIbuild(F.lookup("logger"), L);// ( "exp/mpf_test",100 );
 	int l_X = L->add ( rx, "xt" );
 	int l_D = L->add ( concat ( ry,ru ), "" );
-	int l_XE= L->add ( rx, "xtE" );
-	int l_XM= L->add ( concat ( rQ,rx ), "xtM" );
-	int l_VE= L->add ( rx, "VE" );
-	int l_VM= L->add ( concat ( rQ,rx ), "VM" );
 	int l_Q= L->add ( rQ, "" );
+	
+	KFE.set_options("logbounds");
+	KFE.log_add(L,"KF");
+	M.set_options("logbounds");
+	M.log_add(L,"M");
 	L->init();
 
@@ -126,15 +127,10 @@
 		M.bayes ( concat ( dt,ut ) );
 
-		vec mea=Mep.mean();
-		if (max(mea)>1e3){
-			cout << "here"<<endl;
-		}
 		L->logit ( l_X,xt );
 		L->logit ( l_D,concat ( dt,ut ) );
-		L->logit ( l_XE,KFEep.mean() );
-		L->logit ( l_XM, mea);
-		L->logit ( l_VE,KFEep.variance() );
-		L->logit ( l_VM,Mep.variance() );
 		L->logit ( l_Q,Qdiag );
+		
+		KFE.logit(L);
+		M.logit(L);
 		L->step();
 	}
Index: /pmsm/TR2245/exp/unitstep.kst
===================================================================
--- /pmsm/TR2245/exp/unitstep.kst (revision 281)
+++ /pmsm/TR2245/exp/unitstep.kst (revision 283)
@@ -8,5 +8,5 @@
   <graphicsautosave time="1" enabled="false" format="PNG" xsize="600" ysize="480" display="1" square="true" />
   <kstfile>
-    <tag>DS-mpf_test</tag>
+    <tag>DS-unitstep</tag>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <type>Directory of Binary Files</type>
@@ -15,324 +15,324 @@
     <tag>P1/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P1/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P1/YMin</tag>
     <orphan/>
-    <value>-4.5157036326817</value>
+    <value>-0.048334607484026</value>
   </scalar>
   <scalar>
     <tag>P1/YMax</tag>
     <orphan/>
-    <value>7.1059942008359</value>
+    <value>0.51400228173259</value>
   </scalar>
   <scalar>
     <tag>P2/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P2/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P2/YMin</tag>
     <orphan/>
-    <value>-8.7889029972173</value>
+    <value>-0.39028880388336</value>
   </scalar>
   <scalar>
     <tag>P2/YMax</tag>
     <orphan/>
-    <value>2.9406777090262</value>
+    <value>0.28756055295362</value>
   </scalar>
   <scalar>
     <tag>P3/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P3/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P3/YMin</tag>
     <orphan/>
-    <value>-9.9507440023583</value>
+    <value>2.9364401415802</value>
   </scalar>
   <scalar>
     <tag>P3/YMax</tag>
     <orphan/>
-    <value>10.112057855496</value>
+    <value>6.8935369383091</value>
   </scalar>
   <scalar>
     <tag>P4/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P4/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P4/YMin</tag>
     <orphan/>
-    <value>-3.2349482477224</value>
+    <value>1.3025848670891</value>
   </scalar>
   <scalar>
     <tag>P4/YMax</tag>
     <orphan/>
-    <value>1.950493542042</value>
+    <value>1.8398220026564</value>
   </scalar>
   <scalar>
     <tag>P5/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P5/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P5/YMin</tag>
     <orphan/>
-    <value>-4.5157024034826</value>
+    <value>-0.04833941248617</value>
   </scalar>
   <scalar>
     <tag>P5/YMax</tag>
     <orphan/>
-    <value>7.1060502918641</value>
+    <value>0.51402942484196</value>
   </scalar>
   <scalar>
     <tag>P6/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P6/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P6/YMin</tag>
     <orphan/>
-    <value>-8.7889142376003</value>
+    <value>-0.3902866183156</value>
   </scalar>
   <scalar>
     <tag>P6/YMax</tag>
     <orphan/>
-    <value>2.940623098786</value>
+    <value>0.2875552509328</value>
   </scalar>
   <scalar>
     <tag>P7/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P7/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P7/YMin</tag>
     <orphan/>
-    <value>-9.9423377081818</value>
+    <value>2.8955198144056</value>
   </scalar>
   <scalar>
     <tag>P7/YMax</tag>
     <orphan/>
-    <value>10.167729809906</value>
+    <value>6.8845837989307</value>
   </scalar>
   <scalar>
     <tag>P8/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P8/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P8/YMin</tag>
     <orphan/>
-    <value>-3.1990055876149</value>
+    <value>1.3045812312785</value>
   </scalar>
   <scalar>
     <tag>P8/YMax</tag>
     <orphan/>
-    <value>2.0317543342644</value>
+    <value>1.9219107533158</value>
   </scalar>
   <scalar>
     <tag>P9/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P9/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P9/YMin</tag>
     <orphan/>
-    <value>-4.5157373665507</value>
+    <value>-0.048337870582494</value>
   </scalar>
   <scalar>
     <tag>P9/YMax</tag>
     <orphan/>
-    <value>7.1060009663093</value>
+    <value>0.51406761152853</value>
   </scalar>
   <scalar>
     <tag>P10/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P10/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P10/YMin</tag>
     <orphan/>
-    <value>-8.7889175939615</value>
+    <value>-0.39028810807047</value>
   </scalar>
   <scalar>
     <tag>P10/YMax</tag>
     <orphan/>
-    <value>2.9407047630982</value>
+    <value>0.28761404165682</value>
   </scalar>
   <scalar>
     <tag>P11/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P11/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P11/YMin</tag>
     <orphan/>
-    <value>-9.9423985713648</value>
+    <value>2.9290394221155</value>
   </scalar>
   <scalar>
     <tag>P11/YMax</tag>
     <orphan/>
-    <value>10.156071405218</value>
+    <value>6.8868281881701</value>
   </scalar>
   <scalar>
     <tag>P12/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P12/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P12/YMin</tag>
     <orphan/>
-    <value>-3.2332263813866</value>
+    <value>1.3064345453176</value>
   </scalar>
   <scalar>
     <tag>P12/YMax</tag>
     <orphan/>
-    <value>1.9992572404254</value>
+    <value>1.8885338031887</value>
   </scalar>
   <scalar>
     <tag>P13/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P13/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P13/YMin</tag>
     <orphan/>
-    <value>-2.4976711470358e-07</value>
+    <value>-5.1884392049895e-08</value>
   </scalar>
   <scalar>
     <tag>P13/YMax</tag>
     <orphan/>
-    <value>2.093709004069e-05</value>
+    <value>7.396627640389e-06</value>
   </scalar>
   <scalar>
     <tag>P14/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P14/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P14/YMin</tag>
     <orphan/>
-    <value>-5.4365964898493e-07</value>
+    <value>-2.4282594344782e-06</value>
   </scalar>
   <scalar>
     <tag>P14/YMax</tag>
     <orphan/>
-    <value>3.2021199309101e-05</value>
+    <value>0.00010541853909026</value>
   </scalar>
   <scalar>
     <tag>P15/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P15/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P15/YMin</tag>
     <orphan/>
-    <value>-0.00037357938771325</value>
+    <value>-0.00017880685614156</value>
   </scalar>
   <scalar>
     <tag>P15/YMax</tag>
     <orphan/>
-    <value>0.01812882974232</value>
+    <value>0.0107775025083</value>
   </scalar>
   <scalar>
     <tag>P16/XMin</tag>
     <orphan/>
-    <value>0</value>
+    <value>2926.358392435</value>
   </scalar>
   <scalar>
     <tag>P16/XMax</tag>
     <orphan/>
-    <value>8996</value>
+    <value>3606.906855792</value>
   </scalar>
   <scalar>
     <tag>P16/YMin</tag>
     <orphan/>
-    <value>-0.00015311709117417</value>
+    <value>-2.8901098199394e-05</value>
   </scalar>
   <scalar>
     <tag>P16/YMax</tag>
     <orphan/>
-    <value>0.0066825740776078</value>
+    <value>0.0013375207853002</value>
   </scalar>
   <vector>
-    <tag>DS-mpf_test/INDEX</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/INDEX</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>INDEX</field>
@@ -341,6 +341,6 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/xt_ia</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/xt_ia</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>xt_ia</field>
@@ -349,6 +349,6 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/xt_ib</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/xt_ib</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>xt_ib</field>
@@ -357,6 +357,6 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/xt_om</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/xt_om</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>xt_om</field>
@@ -365,6 +365,6 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/xt_th</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/xt_th</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>xt_th</field>
@@ -373,102 +373,102 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtE_ia</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/KF_ia</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtE_ia</field>
+    <field>KF_ia</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtE_ib</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/KF_ib</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtE_ib</field>
+    <field>KF_ib</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtE_om</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/KF_om</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtE_om</field>
+    <field>KF_om</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtE_th</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/KF_th</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtE_th</field>
+    <field>KF_th</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_ia</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_ia</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_ia</field>
+    <field>M_ia</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_ib</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_ib</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_ib</field>
+    <field>M_ib</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_om</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_om</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_om</field>
+    <field>M_om</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_th</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_th</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_th</field>
+    <field>M_th</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_Q_0</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_Q_0</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_Q_0</field>
+    <field>M_Q_0</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_Q_1</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_Q_1</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_Q_1</field>
+    <field>M_Q_1</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_Q_2</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_Q_2</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_Q_2</field>
+    <field>M_Q_2</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/xtM_Q_3</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/M_Q_3</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
-    <field>xtM_Q_3</field>
+    <field>M_Q_3</field>
     <start>-1</start>
     <num>89996</num>
   </vector>
   <vector>
-    <tag>DS-mpf_test/Q_0</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/Q_0</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>Q_0</field>
@@ -477,6 +477,6 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/Q_1</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/Q_1</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>Q_1</field>
@@ -485,6 +485,6 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/Q_2</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/Q_2</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>Q_2</field>
@@ -493,6 +493,6 @@
   </vector>
   <vector>
-    <tag>DS-mpf_test/Q_3</tag>
-    <provider>DS-mpf_test</provider>
+    <tag>DS-unitstep/Q_3</tag>
+    <provider>DS-unitstep</provider>
     <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
     <field>Q_3</field>
@@ -500,8 +500,72 @@
     <num>89996</num>
   </vector>
+  <vector>
+    <tag>DS-unitstep/M_ub_Q_0</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_ub_Q_0</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
+  <vector>
+    <tag>DS-unitstep/M_ub_Q_1</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_ub_Q_1</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
+  <vector>
+    <tag>DS-unitstep/M_ub_Q_2</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_ub_Q_2</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
+  <vector>
+    <tag>DS-unitstep/M_ub_Q_3</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_ub_Q_3</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
+  <vector>
+    <tag>DS-unitstep/M_lb_Q_0</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_lb_Q_0</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
+  <vector>
+    <tag>DS-unitstep/M_lb_Q_1</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_lb_Q_1</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
+  <vector>
+    <tag>DS-unitstep/M_lb_Q_2</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_lb_Q_2</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
+  <vector>
+    <tag>DS-unitstep/M_lb_Q_3</tag>
+    <provider>DS-unitstep</provider>
+    <filename>/home/smidl/work/git/mixpp/pmsm/TR2245/exp/unitstep/</filename>
+    <field>M_lb_Q_3</field>
+    <start>-1</start>
+    <num>89996</num>
+  </vector>
   <curve>
     <tag>xt_ia</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xt_ia</yvectag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/xt_ia</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -517,6 +581,6 @@
   <curve>
     <tag>xt_ib</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xt_ib</yvectag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/xt_ib</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -532,6 +596,6 @@
   <curve>
     <tag>xt_om</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xt_om</yvectag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/xt_om</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -547,6 +611,6 @@
   <curve>
     <tag>xt_th</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xt_th</yvectag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/xt_th</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -561,7 +625,7 @@
   </curve>
   <curve>
-    <tag>xtE_ia</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtE_ia</yvectag>
+    <tag>KF_ia</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/KF_ia</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -576,7 +640,7 @@
   </curve>
   <curve>
-    <tag>xtE_ib</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtE_ib</yvectag>
+    <tag>KF_ib</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/KF_ib</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -591,7 +655,7 @@
   </curve>
   <curve>
-    <tag>xtE_om</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtE_om</yvectag>
+    <tag>KF_om</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/KF_om</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -606,7 +670,7 @@
   </curve>
   <curve>
-    <tag>xtE_th</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtE_th</yvectag>
+    <tag>KF_th</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/KF_th</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -621,7 +685,7 @@
   </curve>
   <curve>
-    <tag>xtM_ia</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_ia</yvectag>
+    <tag>M_ia</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_ia</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -636,7 +700,7 @@
   </curve>
   <curve>
-    <tag>xtM_ib</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_ib</yvectag>
+    <tag>M_ib</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_ib</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -651,7 +715,7 @@
   </curve>
   <curve>
-    <tag>xtM_om</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_om</yvectag>
+    <tag>M_om</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_om</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -666,7 +730,7 @@
   </curve>
   <curve>
-    <tag>xtM_th</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_th</yvectag>
+    <tag>M_th</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_th</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -681,67 +745,7 @@
   </curve>
   <curve>
-    <tag>xtM_Q_0</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_Q_0</yvectag>
-    <legend></legend>
-    <interp>0</interp>
-    <hasMinus/>
-    <color>#004040</color>
-    <hasLines/>
-    <lineWidth>0</lineWidth>
-    <lineStyle>0</lineStyle>
-    <pointType>0</pointType>
-    <pointDensity>0</pointDensity>
-    <barStyle>0</barStyle>
-  </curve>
-  <curve>
-    <tag>xtM_Q_1</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_Q_1</yvectag>
-    <legend></legend>
-    <interp>0</interp>
-    <hasMinus/>
-    <color>#008080</color>
-    <hasLines/>
-    <lineWidth>0</lineWidth>
-    <lineStyle>0</lineStyle>
-    <pointType>0</pointType>
-    <pointDensity>0</pointDensity>
-    <barStyle>0</barStyle>
-  </curve>
-  <curve>
-    <tag>xtM_Q_2</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_Q_2</yvectag>
-    <legend></legend>
-    <interp>0</interp>
-    <hasMinus/>
-    <color>#00c0c0</color>
-    <hasLines/>
-    <lineWidth>0</lineWidth>
-    <lineStyle>0</lineStyle>
-    <pointType>0</pointType>
-    <pointDensity>0</pointDensity>
-    <barStyle>0</barStyle>
-  </curve>
-  <curve>
-    <tag>xtM_Q_3</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/xtM_Q_3</yvectag>
-    <legend></legend>
-    <interp>0</interp>
-    <hasMinus/>
-    <color>#00ffff</color>
-    <hasLines/>
-    <lineWidth>0</lineWidth>
-    <lineStyle>0</lineStyle>
-    <pointType>0</pointType>
-    <pointDensity>0</pointDensity>
-    <barStyle>0</barStyle>
-  </curve>
-  <curve>
-    <tag>Q_0</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/Q_0</yvectag>
+    <tag>M_Q_0</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_Q_0</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -756,7 +760,7 @@
   </curve>
   <curve>
-    <tag>Q_1</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/Q_1</yvectag>
+    <tag>M_Q_1</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_Q_1</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -771,7 +775,7 @@
   </curve>
   <curve>
-    <tag>Q_2</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/Q_2</yvectag>
+    <tag>M_Q_2</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_Q_2</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -786,7 +790,7 @@
   </curve>
   <curve>
-    <tag>Q_3</tag>
-    <xvectag>DS-mpf_test/INDEX</xvectag>
-    <yvectag>DS-mpf_test/Q_3</yvectag>
+    <tag>M_Q_3</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_Q_3</yvectag>
     <legend></legend>
     <interp>0</interp>
@@ -796,4 +800,184 @@
     <lineWidth>0</lineWidth>
     <lineStyle>0</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>Q_0</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/Q_0</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#00ff00</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>0</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>Q_1</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/Q_1</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#000080</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>0</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>Q_2</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/Q_2</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#0000c0</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>0</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>Q_3</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/Q_3</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#0000ff</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>0</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_ub_Q_0</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_ub_Q_0</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#404000</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_ub_Q_1</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_ub_Q_1</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#808000</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_ub_Q_2</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_ub_Q_2</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#c0c000</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_ub_Q_3</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_ub_Q_3</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#ffff00</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_lb_Q_0</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_lb_Q_0</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#004040</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_lb_Q_1</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_lb_Q_1</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#008080</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_lb_Q_2</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_lb_Q_2</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#00c0c0</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
+    <pointType>0</pointType>
+    <pointDensity>0</pointDensity>
+    <barStyle>0</barStyle>
+  </curve>
+  <curve>
+    <tag>M_lb_Q_3</tag>
+    <xvectag>DS-unitstep/INDEX</xvectag>
+    <yvectag>DS-unitstep/M_lb_Q_3</yvectag>
+    <legend></legend>
+    <interp>0</interp>
+    <hasMinus/>
+    <color>#00ffff</color>
+    <hasLines/>
+    <lineWidth>0</lineWidth>
+    <lineStyle>2</lineStyle>
     <pointType>0</pointType>
     <pointDensity>0</pointDensity>
@@ -812,12 +996,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-4.5157036326817</ymin>
-    <ymax>7.1059942008359</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-0.048334607484026</ymin>
+    <ymax>0.51400228173259</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -845,5 +1029,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -852,5 +1036,5 @@
     </xticklabel>
     <yticklabel>
-      <text>6</text>
+      <text>0.5</text>
       <interpret/>
       <rotation>0</rotation>
@@ -923,12 +1107,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-8.7889029972173</ymin>
-    <ymax>2.9406777090262</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-0.39028880388336</ymin>
+    <ymax>0.28756055295362</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -956,5 +1140,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -963,5 +1147,5 @@
     </xticklabel>
     <yticklabel>
-      <text>2</text>
+      <text>0.2</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1034,12 +1218,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-9.9507440023583</ymin>
-    <ymax>10.112057855496</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>2.9364401415802</ymin>
+    <ymax>6.8935369383091</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1067,5 +1251,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1074,5 +1258,5 @@
     </xticklabel>
     <yticklabel>
-      <text>10</text>
+      <text>6</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1145,12 +1329,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-3.2349482477224</ymin>
-    <ymax>1.950493542042</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>1.3025848670891</ymin>
+    <ymax>1.8398220026564</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1178,5 +1362,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1185,5 +1369,5 @@
     </xticklabel>
     <yticklabel>
-      <text>1</text>
+      <text>1.8</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1256,12 +1440,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-4.5157024034826</ymin>
-    <ymax>7.1060502918641</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-0.04833941248617</ymin>
+    <ymax>0.51402942484196</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1282,5 +1466,5 @@
     </xlabel>
     <ylabel>
-      <text>xtE\_ia</text>
+      <text>KF\_ia</text>
       <interpret/>
       <rotation>270</rotation>
@@ -1289,5 +1473,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1296,5 +1480,5 @@
     </xticklabel>
     <yticklabel>
-      <text>6</text>
+      <text>0.5</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1311,5 +1495,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtE_ia</curvetag>
+    <curvetag>KF_ia</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -1367,12 +1551,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-8.7889142376003</ymin>
-    <ymax>2.940623098786</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-0.3902866183156</ymin>
+    <ymax>0.2875552509328</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1393,5 +1577,5 @@
     </xlabel>
     <ylabel>
-      <text>xtE\_ib</text>
+      <text>KF\_ib</text>
       <interpret/>
       <rotation>270</rotation>
@@ -1400,5 +1584,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1407,5 +1591,5 @@
     </xticklabel>
     <yticklabel>
-      <text>2</text>
+      <text>0.2</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1422,5 +1606,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtE_ib</curvetag>
+    <curvetag>KF_ib</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -1478,12 +1662,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-9.9423377081818</ymin>
-    <ymax>10.167729809906</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>2.8955198144056</ymin>
+    <ymax>6.8845837989307</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1504,5 +1688,5 @@
     </xlabel>
     <ylabel>
-      <text>xtE\_om</text>
+      <text>KF\_om</text>
       <interpret/>
       <rotation>270</rotation>
@@ -1511,5 +1695,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1518,5 +1702,5 @@
     </xticklabel>
     <yticklabel>
-      <text>10</text>
+      <text>6</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1533,5 +1717,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtE_om</curvetag>
+    <curvetag>KF_om</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -1589,12 +1773,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-3.1990055876149</ymin>
-    <ymax>2.0317543342644</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>1.3045812312785</ymin>
+    <ymax>1.9219107533158</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1615,5 +1799,5 @@
     </xlabel>
     <ylabel>
-      <text>xtE\_th</text>
+      <text>KF\_th</text>
       <interpret/>
       <rotation>270</rotation>
@@ -1622,5 +1806,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1629,5 +1813,5 @@
     </xticklabel>
     <yticklabel>
-      <text>2</text>
+      <text>1.9</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1644,5 +1828,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtE_th</curvetag>
+    <curvetag>KF_th</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -1700,12 +1884,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-4.5157373665507</ymin>
-    <ymax>7.1060009663093</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-0.048337870582494</ymin>
+    <ymax>0.51406761152853</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1726,5 +1910,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_ia</text>
+      <text>M\_ia</text>
       <interpret/>
       <rotation>270</rotation>
@@ -1733,5 +1917,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1740,5 +1924,5 @@
     </xticklabel>
     <yticklabel>
-      <text>6</text>
+      <text>0.5</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1755,5 +1939,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_ia</curvetag>
+    <curvetag>M_ia</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -1811,12 +1995,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-8.7889175939615</ymin>
-    <ymax>2.9407047630982</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-0.39028810807047</ymin>
+    <ymax>0.28761404165682</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1837,5 +2021,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_ib</text>
+      <text>M\_ib</text>
       <interpret/>
       <rotation>270</rotation>
@@ -1844,5 +2028,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1851,5 +2035,5 @@
     </xticklabel>
     <yticklabel>
-      <text>2</text>
+      <text>0.2</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1866,5 +2050,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_ib</curvetag>
+    <curvetag>M_ib</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -1922,12 +2106,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-9.9423985713648</ymin>
-    <ymax>10.156071405218</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>2.9290394221155</ymin>
+    <ymax>6.8868281881701</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -1948,5 +2132,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_om</text>
+      <text>M\_om</text>
       <interpret/>
       <rotation>270</rotation>
@@ -1955,5 +2139,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1962,5 +2146,5 @@
     </xticklabel>
     <yticklabel>
-      <text>10</text>
+      <text>6</text>
       <interpret/>
       <rotation>0</rotation>
@@ -1977,5 +2161,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_om</curvetag>
+    <curvetag>M_om</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -2033,12 +2217,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-3.2332263813866</ymin>
-    <ymax>1.9992572404254</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>1.3064345453176</ymin>
+    <ymax>1.8885338031887</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -2059,5 +2243,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_th</text>
+      <text>M\_th</text>
       <interpret/>
       <rotation>270</rotation>
@@ -2066,5 +2250,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2073,5 +2257,5 @@
     </xticklabel>
     <yticklabel>
-      <text>1</text>
+      <text>1.8</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2088,5 +2272,5 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_th</curvetag>
+    <curvetag>M_th</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -2144,12 +2328,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-2.4976711470358e-07</ymin>
-    <ymax>2.093709004069e-05</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-5.1884392049895e-08</ymin>
+    <ymax>7.396627640389e-06</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -2170,5 +2354,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_Q\_0 and Q\_0</text>
+      <text></text>
       <interpret/>
       <rotation>270</rotation>
@@ -2177,5 +2361,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2184,5 +2368,5 @@
     </xticklabel>
     <yticklabel>
-      <text>2e-05</text>
+      <text>7e-06</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2199,6 +2383,8 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_Q_0</curvetag>
+    <curvetag>M_Q_0</curvetag>
     <curvetag>Q_0</curvetag>
+    <curvetag>M_ub_Q_0</curvetag>
+    <curvetag>M_lb_Q_0</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -2256,12 +2442,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-5.4365964898493e-07</ymin>
-    <ymax>3.2021199309101e-05</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-2.4282594344782e-06</ymin>
+    <ymax>0.00010541853909026</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -2282,5 +2468,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_Q\_1 and Q\_1</text>
+      <text></text>
       <interpret/>
       <rotation>270</rotation>
@@ -2289,5 +2475,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2296,5 +2482,5 @@
     </xticklabel>
     <yticklabel>
-      <text>3e-05</text>
+      <text>0.0001</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2311,6 +2497,8 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_Q_1</curvetag>
+    <curvetag>M_Q_1</curvetag>
     <curvetag>Q_1</curvetag>
+    <curvetag>M_ub_Q_1</curvetag>
+    <curvetag>M_lb_Q_1</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -2368,12 +2556,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-0.00037357938771325</ymin>
-    <ymax>0.01812882974232</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-0.00017880685614156</ymin>
+    <ymax>0.0107775025083</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -2394,5 +2582,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_Q\_2 and Q\_2</text>
+      <text></text>
       <interpret/>
       <rotation>270</rotation>
@@ -2401,5 +2589,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2408,5 +2596,5 @@
     </xticklabel>
     <yticklabel>
-      <text>0.018</text>
+      <text>0.01</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2423,6 +2611,8 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_Q_2</curvetag>
+    <curvetag>M_Q_2</curvetag>
     <curvetag>Q_2</curvetag>
+    <curvetag>M_ub_Q_2</curvetag>
+    <curvetag>M_lb_Q_2</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -2480,12 +2670,12 @@
     <margin>0</margin>
     <padding>0</padding>
-    <xscalemode>0</xscalemode>
-    <yscalemode>5</yscalemode>
+    <xscalemode>2</xscalemode>
+    <yscalemode>2</yscalemode>
     <xscalemodedefault>0</xscalemodedefault>
     <yscalemodedefault>5</yscalemodedefault>
-    <xmin>0</xmin>
-    <xmax>8996</xmax>
-    <ymin>-0.00015311709117417</ymin>
-    <ymax>0.0066825740776078</ymax>
+    <xmin>2926.358392435</xmin>
+    <xmax>3606.906855792</xmax>
+    <ymin>-2.8901098199394e-05</ymin>
+    <ymax>0.0013375207853002</ymax>
     <xreversed>0</xreversed>
     <yreversed>0</yreversed>
@@ -2506,5 +2696,5 @@
     </xlabel>
     <ylabel>
-      <text>xtM\_Q\_3 and Q\_3</text>
+      <text></text>
       <interpret/>
       <rotation>270</rotation>
@@ -2513,5 +2703,5 @@
     </ylabel>
     <xticklabel>
-      <text>8000</text>
+      <text>3600</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2520,5 +2710,5 @@
     </xticklabel>
     <yticklabel>
-      <text>0.006</text>
+      <text>0.0012</text>
       <interpret/>
       <rotation>0</rotation>
@@ -2535,6 +2725,8 @@
     <xlogbase>10</xlogbase>
     <ylogbase>10</ylogbase>
-    <curvetag>xtM_Q_3</curvetag>
+    <curvetag>M_Q_3</curvetag>
     <curvetag>Q_3</curvetag>
+    <curvetag>M_ub_Q_3</curvetag>
+    <curvetag>M_lb_Q_3</curvetag>
     <xmajorgrid>0</xmajorgrid>
     <ymajorgrid>0</ymajorgrid>
@@ -2582,6 +2774,6 @@
   <window>
     <tag>W1</tag>
-    <restore x="4" y="4" w="1008" h="532" />
-    <internal x="4" y="4" w="1008" h="532" />
+    <restore x="4" y="4" w="1008" h="556" />
+    <internal x="4" y="4" w="1008" h="556" />
     <columns>4</columns>
     <name>W1</name>
@@ -2636,5 +2828,5 @@
         <border color="#000000" width="2" padding="0" margin="0" />
         <border color="#000000" width="2" padding="0" margin="0" />
-        <tag>Object 440</tag>
+        <tag>Object 561</tag>
         <aspect x="0.1" y="0.1" w="0.2" h="0.1" />
         <idealsize w="1" h="1" />
@@ -2653,6 +2845,8 @@
         <vertical>true</vertical>
         <title></title>
-        <curvetag>xtM_Q_0</curvetag>
+        <curvetag>M_Q_0</curvetag>
         <curvetag>Q_0</curvetag>
+        <curvetag>M_ub_Q_0</curvetag>
+        <curvetag>M_lb_Q_0</curvetag>
       </Legend>
     </Plot>
@@ -2662,5 +2856,5 @@
         <border color="#000000" width="2" padding="0" margin="0" />
         <border color="#000000" width="2" padding="0" margin="0" />
-        <tag>Object 441</tag>
+        <tag>Object 562</tag>
         <aspect x="0.1" y="0.1" w="0.2" h="0.1" />
         <idealsize w="1" h="1" />
@@ -2679,6 +2873,8 @@
         <vertical>true</vertical>
         <title></title>
-        <curvetag>xtM_Q_1</curvetag>
+        <curvetag>M_Q_1</curvetag>
         <curvetag>Q_1</curvetag>
+        <curvetag>M_ub_Q_1</curvetag>
+        <curvetag>M_lb_Q_1</curvetag>
       </Legend>
     </Plot>
@@ -2688,5 +2884,5 @@
         <border color="#000000" width="2" padding="0" margin="0" />
         <border color="#000000" width="2" padding="0" margin="0" />
-        <tag>Object 442</tag>
+        <tag>Object 563</tag>
         <aspect x="0.1" y="0.1" w="0.2" h="0.1" />
         <idealsize w="1" h="1" />
@@ -2705,6 +2901,8 @@
         <vertical>true</vertical>
         <title></title>
-        <curvetag>xtM_Q_2</curvetag>
+        <curvetag>M_Q_2</curvetag>
         <curvetag>Q_2</curvetag>
+        <curvetag>M_ub_Q_2</curvetag>
+        <curvetag>M_lb_Q_2</curvetag>
       </Legend>
     </Plot>
@@ -2714,5 +2912,5 @@
         <border color="#000000" width="2" padding="0" margin="0" />
         <border color="#000000" width="2" padding="0" margin="0" />
-        <tag>Object 443</tag>
+        <tag>Object 564</tag>
         <aspect x="0.1" y="0.1" w="0.2" h="0.1" />
         <idealsize w="1" h="1" />
@@ -2731,6 +2929,8 @@
         <vertical>true</vertical>
         <title></title>
-        <curvetag>xtM_Q_3</curvetag>
+        <curvetag>M_Q_3</curvetag>
         <curvetag>Q_3</curvetag>
+        <curvetag>M_ub_Q_3</curvetag>
+        <curvetag>M_lb_Q_3</curvetag>
       </Legend>
     </Plot>
Index: /pmsm/pmsm.h
===================================================================
--- /pmsm/pmsm.h (revision 280)
+++ /pmsm/pmsm.h (revision 283)
@@ -31,10 +31,10 @@
 	vec eval ( const vec &x0, const vec &u0 ) {
 		// last state
-		double iam = x0 ( 0 );
-		double ibm = x0 ( 1 );
-		double omm = x0 ( 2 );
-		double thm = x0 ( 3 );
-		double uam = u0 ( 0 );
-		double ubm = u0 ( 1 );
+		const double &iam = x0 ( 0 );
+		const double &ibm = x0 ( 1 );
+		const double &omm = x0 ( 2 );
+		const double &thm = x0 ( 3 );
+		const double &uam = u0 ( 0 );
+		const double &ubm = u0 ( 1 );
 
 		vec xk( 4 );
@@ -53,8 +53,8 @@
 
 	void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
-		double iam = x0 ( 0 );
-		double ibm = x0 ( 1 );
-		double omm = x0 ( 2 );
-		double thm = x0 ( 3 );
+		const double &iam = x0 ( 0 );
+		const double &ibm = x0 ( 1 );
+		const double &omm = x0 ( 2 );
+		const double &thm = x0 ( 3 );
 		// d ia
 		A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0;
Index: /CMakeLists.txt
===================================================================
--- /CMakeLists.txt (revision 280)
+++ /CMakeLists.txt (revision 283)
@@ -78,3 +78,3 @@
 #add_subdirectory (mpdm)
 add_subdirectory (library)
-#add_subdirectory (doprava)
+add_subdirectory (doprava)
