Index: /bdm/uibuilder.cpp
===================================================================
--- /bdm/uibuilder.cpp (revision 257)
+++ /bdm/uibuilder.cpp (revision 260)
@@ -37,4 +37,41 @@
 UIREGISTER(UIinternal);
 
+	void UI_DBG ( Setting &S, const string &spc ) {
+		const char *Name=S.getName();
+		if ( Name!=NULL ) {cout << spc << std::string ( Name );};
+		Setting::Type T=S.getType();
+		switch ( T ) {
+			case Setting::TypeArray:
+				cout << endl;
+				for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );};
+				break;
+			case Setting::TypeList:
+				cout << endl;
+				for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );};
+				break;
+			case Setting::TypeGroup:
+				cout << endl;
+				for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );}
+				break;
+			case Setting::TypeInt:
+				cout << " = ";
+				cout << int ( S ) <<endl;
+				break;
+			case Setting::TypeFloat:
+				cout << " = ";
+				cout << double ( S ) <<endl;
+				break;
+			case Setting::TypeString:
+				cout << " = ";
+				cout << ( const char* ) ( S ) <<endl;
+				break;
+			case Setting::TypeBoolean:
+				cout << " = ";
+				cout << bool ( S ) <<endl;
+				break;
+				default: {cout << "?";};
+		}
+	}
+
 }
 //UIexternal* UIexternal_instance =new UIexternal();
Index: /bdm/uibuilder.h
===================================================================
--- /bdm/uibuilder.h (revision 257)
+++ /bdm/uibuilder.h (revision 260)
@@ -6,8 +6,8 @@
 #include "libconfig/libconfig.h++"
 
-namespace bdm{
+namespace bdm {
 
-using namespace libconfig;
-using namespace std;
+	using namespace libconfig;
+	using namespace std;
 
 #define CHECK_UITYPE(S,Type) it_assert_debug(S.getType()==Setting::Type, string("Wrong input path \"")+string(S.getPath())+string("\""));
@@ -16,135 +16,146 @@
 ////////// GLOBAL VAriables
 
-class UIbuilder;
+	class UIbuilder;
 //! Internal structure mapping strings to UIBuilder objects
-typedef map<const string, const UIbuilder*> UImap;
-extern UImap __uimap__;
+	typedef map<const string, const UIbuilder*> UImap;
+	extern UImap __uimap__;
 
-class UIFile : public Config{
+	class UIFile : public Config {
 	public:
-	UIFile(const char * fname):Config(){
-		try{Config::readFile(fname);} 
-		catch (ParseException& P) {
-			char msg[200];
-			sprintf(msg,"Error in file %s  on line %d.", fname, P.getLine());
-			it_error(msg);
-		} 
-		catch (FileIOException f) {it_error("File " + string(fname) + " not found");} 
-	}
-};
+		UIFile ( const char * fname ) :Config() {
+			try{Config::readFile ( fname );}
+			catch ( ParseException& P ) {
+				char msg[200];
+				sprintf ( msg,"Error in file %s  on line %d.", fname, P.getLine() );
+				it_error ( msg );
+			}
+			catch ( FileIOException f ) {it_error ( "File " + string ( fname ) + " not found" );}
+		}
+	};
 
-/*!\brief Builds computational object from a UserInfo structure
+	/*!\brief Builds computational object from a UserInfo structure
 
-Return value is a pointer to the created object (memory management issue?)
-*/
-class UIbuilder {
+	Return value is a pointer to the created object (memory management issue?)
+	*/
+	class UIbuilder {
 	protected:
-		static const UIbuilder* theinstance;
-	vec getvec ( Setting& S ) {
-		CHECK_UITYPE(S,TypeArray);
-		vec tmp;
-		tmp.set_size ( S.getLength() );
-		for ( int i=0;i<S.getLength();i++ ) {
-			switch (S[i].getType()) {
-				case Setting::TypeFloat :
-					tmp[i]=double(S[i]);break;
-				case Setting::TypeInt :
-					tmp[i]=int(S[i]);break;
-				case Setting::TypeBoolean :
-					tmp[i]=bool(S[i]);break;
-				default: it_error("libconfig error?");
-			} 
-		}
-		return tmp;
-	};
-	vec getivec ( Setting& S ) {
-		CHECK_UITYPE(S,TypeArray);
-		vec tmp;
-		tmp.set_size ( S.getLength() );
-		for ( int i=0;i<S.getLength();i++ ) {
-			switch (S[i].getType()) {
-				case Setting::TypeFloat :
-					tmp[i]=double(S[i]);break;
-				case Setting::TypeInt :
-					tmp[i]=int(S[i]);break;
-				case Setting::TypeBoolean :
-					tmp[i]=bool(S[i]);break;
-					default: it_error("libconfig error?");
-			} 
-		}
-		return tmp;
-	};
+		const vec getvec ( Setting& S ) const {
+			CHECK_UITYPE ( S,TypeArray );
+			vec tmp;
+			tmp.set_size ( S.getLength() );
+			for ( int i=0;i<S.getLength();i++ ) {
+				switch ( S[i].getType() ) {
+					case Setting::TypeFloat :
+						tmp[i]=double ( S[i] );break;
+					case Setting::TypeInt :
+						tmp[i]=int ( S[i] );break;
+					case Setting::TypeBoolean :
+						tmp[i]=bool ( S[i] );break;
+					default: it_error ( "libconfig error?" );
+				}
+			}
+			return tmp;
+		};
+		const vec getivec ( Setting& S ) const {
+			CHECK_UITYPE ( S,TypeArray );
+			vec tmp;
+			tmp.set_size ( S.getLength() );
+			for ( int i=0;i<S.getLength();i++ ) {
+				switch ( S[i].getType() ) {
+					case Setting::TypeFloat :
+						tmp[i]=double ( S[i] );break;
+					case Setting::TypeInt :
+						tmp[i]=int ( S[i] );break;
+					case Setting::TypeBoolean :
+						tmp[i]=bool ( S[i] );break;
+					default: it_error ( "libconfig error?" );
+				}
+			}
+			return tmp;
+		};
 	public:
 		//!Constructor needs to be run only once macro UIREGISTER
-		UIbuilder(const string &typ){__uimap__.insert(make_pair(typ,this));}
+		UIbuilder ( const string &typ ) {__uimap__.insert ( make_pair ( typ,this ) );}
 		//! Function building the computational object
-		virtual bdmroot* build(Setting &S) const =0;
-};
+		virtual bdmroot* build ( Setting &S ) const =0;
+	};
 
-class UIexternal:public UIbuilder{
+	class UIexternal:public UIbuilder {
 	public:
-		UIexternal():UIbuilder("external"){}
-		bdmroot* build(Setting &S) const;
-};
+		UIexternal() :UIbuilder ( "external" ) {}
+		bdmroot* build ( Setting &S ) const;
+	};
 
-class UIinternal:public UIbuilder{
+	class UIinternal:public UIbuilder {
 	public:
-		UIinternal():UIbuilder("internal"){}
-		bdmroot* build(Setting &S) const;
-};
+		UIinternal() :UIbuilder ( "internal" ) {}
+		bdmroot* build ( Setting &S ) const;
+	};
+
+	//! [Debugging] Print values in current S to cout
+	void UI_DBG ( Setting &S, const string &spc );
 
 //! Prototype of a UI builder. Return value is by the second argument since it type checking via \c dynamic_cast.
-template<class T>
-void UIbuild(Setting &S, T* &ret){
-	CHECK_UITYPE(S,TypeGroup);
-	// Check if field "type" is present, if not it is not a valid UI
-	it_assert_debug(S.exists("type"), string(S.getPath())+" is not a valid UI!");
-		
-	const string typ=S["type"];	
-	// Find "type" in list of registred UI builders
-	UImap::const_iterator iter = __uimap__.find( typ );
-	if( iter == __uimap__.end()) {
-		it_error("UI of type \"" + typ + "\" is not registered!");
-	}
-	
-	//BUILD the result
-	ret = dynamic_cast<T*>(iter->second->build(S));
-};
+	template<class T>
+	void UIbuild ( Setting &S, T* &ret ) {
+		CHECK_UITYPE ( S,TypeGroup );
+		// Check if field "type" is present, if not it is not a valid UI
+		it_assert_debug ( S.exists ( "type" ), string ( S.getPath() ) +" is not a valid UI!" );
 
-//! Auxiliary function allowing recursivity in S
-template<class T>
-void UIcall(Setting &S, void (*func)(Setting&, T), T Tmp ){
-	CHECK_UITYPE(S,TypeGroup);
-	// Check if field "type" is present, if not it is not a valid UI
-	it_assert_debug(S.exists("type"), string(S.getPath())+" is not a valid UI!");
-		
-	const string typ=S["type"];	
-	if(typ=="internal"){
-		try {	
-			Setting* Stmp = &S;
-			do {Stmp=&(Stmp->getParent());} while (!Stmp->isRoot());
-			Setting& intS=Stmp->lookup((const char*)S["path"]);
-			func(intS, Tmp); // <======== calling UIset
+		const string typ=S["type"];
+		// Find "type" in list of registred UI builders
+		UImap::const_iterator iter = __uimap__.find ( typ );
+		if ( iter == __uimap__.end() ) {
+			it_error ( "UI of type \"" + typ + "\" is not registered!" );
+		}
+
+		//BUILD the result
+		try {
+			ret = dynamic_cast<T*> ( iter->second->build ( S ) );
+		}
+		catch ( SettingTypeException e ) {
+			UI_DBG(S,""); 
+			it_error ( "Setting " +string ( e.getPath() ) +" is of incorrect Type" );}
+		catch ( SettingNotFoundException e ) {
+			UI_DBG(S,"");
+			it_error ( "Setting " + string ( e.getPath() ) +" was not found" );}
+	};
+
+//! Auxiliary function allowing recursivity in S (too complex, remove?)
+	template<class T>
+	void UIcall ( Setting &S, void ( *func ) ( Setting&, T ), T Tmp ) {
+		CHECK_UITYPE ( S,TypeGroup );
+		// Check if field "type" is present, if not it is not a valid UI
+		it_assert_debug ( S.exists ( "type" ), string ( S.getPath() ) +" is not a valid UI!" );
+
+		const string typ=S["type"];
+		if ( typ=="internal" ) {
+			try {
+				Setting* Stmp = &S;
+				do {Stmp=& ( Stmp->getParent() );}
+				while ( !Stmp->isRoot() );
+				Setting& intS=Stmp->lookup ( ( const char* ) S["path"] );
+				func ( intS, Tmp ); // <======== calling func
+				return;
+			}
+			catch ( ... ) {
+				it_error ( "Internal field " + string ( S.getPath() ) + " not valid" );
+			}
+		}
+		if ( typ=="external" ) {
+			UIFile C(S["filename"]);
+			try {
+				func ( C.lookup ( ( const char* ) S["path"] ), Tmp );
+			}
+			catch ( ... ) {
+				it_error ( "External field " + string ( S.getPath() ) + " not valid" );
+			}
 			return;
 		}
-		catch (...) { it_error("Internal field " + string(S.getPath()) + " not valid");
-		}
-	}
-	if(typ=="extern"){
-		Config C;
-		bdmroot* tmp;
-		try{C.readFile((const char*)S["filename"]);} catch (...){
-			it_error("File " + string((const char*)S["filename"]) + " not found or broken");
-		}
-		try {func(C.lookup((const char*)S["path"]), Tmp);} catch (...) { //<=========== calling UIset
-			it_error("External field " + string(S.getPath()) + " not valid");
-		}
-		return;
-	}
-	
-	// v======================= calling final set
-	func(S, Tmp);
-};
+
+		// v======================= calling final func
+		func ( S, Tmp );
+	};
 
 }
-#endif UIBUILD
+#endif //UIBUILD
Index: /bdm/stat/loggers.h
===================================================================
--- /bdm/stat/loggers.h (revision 257)
+++ /bdm/stat/loggers.h (revision 260)
@@ -14,7 +14,5 @@
 #define LGR_H
 
-#include <itpp/itbase.h>
 #include "libBM.h"
-#include "../itpp_ext.h"
 
 namespace bdm{
Index: /tests/UI/UIbuilder_test.cpp
===================================================================
--- /tests/UI/UIbuilder_test.cpp (revision 257)
+++ /tests/UI/UIbuilder_test.cpp (revision 260)
@@ -22,5 +22,4 @@
 	UItest():UIbuilder("test"){}
 	bdmroot* build(Setting &S) const{
-		try{
 			int a=S["a"];
 			string St;
@@ -28,8 +27,4 @@
 			cls* tmp = new cls(a,St);
 			return tmp;
-		}
-		catch (...){
-			it_error(string(S.getPath()) + " is not a valid test UI");
-		}
 	}	
 };
@@ -39,13 +34,8 @@
 	UItest2():UIbuilder("test2"){}
 	bdmroot* build(Setting &S) const{
-		try{
 			int a=S["a"];
 			string St;
 			S.lookupValue("S",St);
 			return  new cls2(a,St);
-		}
-		catch (...){
-			it_error(string(S.getPath()) + " is not a valid test UI");
-		}
 	}	
 	int no(){return 2;}
Index: /pmsm/pmsmDS.h
===================================================================
--- /pmsm/pmsmDS.h (revision 258)
+++ /pmsm/pmsmDS.h (revision 260)
@@ -12,8 +12,6 @@
 
 #include <stat/loggers.h>
-
+#include "simulator.h"
 #include "pmsm.h"
-#include "simulator.h"
-#include <uibuilder.h>
 
 //! Simulator of PMSM machine with predefined profile on omega
@@ -22,5 +20,5 @@
 protected:
 	//! indeces of logged variables
-	int L_x, L_ou, L_oy, L_iu;
+	int L_x, L_ou, L_oy, L_iu, L_optu;
 	//! Setpoints of omega in timespans given by dt_prof
 	vec profileWw;
@@ -29,6 +27,10 @@
 	//! Number of miliseconds per discrete time step
 	int Dt;
+	//! options for logging, string in which each character has a meaning:
+	//! \c u - log predictions of 'true' voltage
+	string opt;
 public:
-	pmsmDS ( int Dt0 ) : Dt ( Dt0 ) {}
+	//! Constructor with fixed sampling period
+	pmsmDS (string opt0="" ) : Dt ( 125 ), opt(opt0) {}
 	void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) {
 		pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 );
@@ -42,8 +44,13 @@
 		static double Ww; // W
 		if ( t>=dt_prof*ind ) {
+			ind++;
 			if ( ind<profileWw.length() ) {
-				ind++;
 				//linear increase
-				dW = profileWw ( ind )-profileWw ( ind-1 );
+				if ( profileWw.length() ==1 ) {
+					Ww=profileWw ( 0 ); dW=0.0;}
+				else {
+					dW = profileWw ( ind )-profileWw ( ind-1 );
+					dW *=125e-6/dt_prof;
+				}
 			}
 			else {
@@ -58,7 +65,11 @@
 	void log_add ( logger &L ) {
 		L_x = L.add ( rx, "x" );
-		L_oy = L.add ( ry, "oi" );
-		L_ou = L.add ( ru, "ou" );
-		L_iu = L.add ( ru, "iu" );
+		L_oy = L.add ( ry, "obs" );
+		L_ou = L.add ( ru, "obs" );
+		L_iu = L.add ( ru, "true" );
+		// log differences
+		if (opt.find("u")==string::npos){
+			L_optu = L.add(ru, "model");
+		}
 	}
 
@@ -68,31 +79,23 @@
 		L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) );
 		L.logit ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) );
-	}
+		if (opt.find("u")==string::npos){
+			double sq3=sqrt(3.0);
+			double ua,ub;
+			double i1=x[0];
+			double i2=0.5*(-i1+sq3*x[1]);
+			double i3=0.5*(-i1-sq3*x[1]);
+			double u1=KalmanObs[0];
+			double u2=0.5*(-u1+sq3*KalmanObs[1]);
+			double u3=0.5*(-u1-sq3*KalmanObs[1]);
+			
+			double du1=0.7*(double(i1>0.1) - double(i1<-0.1))+0.05*i1;
+			double du2=0.7*(double(i2>0.1) - double(i2<-0.1))+0.05*i2;
+			double du3=0.7*(double(i3>0.1) - double(i3<-0.1))+0.05*i3;
+			ua = (2.0*(u1-du1)-(u2-du2)-(u3-du3))/3.0;
+			ub = ((u2-du2)-(u3-du3))/sq3;
+			L.logit( L_optu , vec_2 (ua,ub));
+		}
+		}
 
 	void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;}
 };
-
-class UIpmsm: public UIbuilder {
-public:
-	UIpmsm() :UIbuilder ( "pmsm" ) {}
-	//Non-standard BUILD!! Does not create
-	void build ( Setting &S, void** result ) const {
-
-	};
-};
-
-class UIpmsmDS: public UIbuilder {
-	static void tmp_set ( Setting &S, pmsmDS* tmp ) {
-		tmp->set_parameters ( S["Rs"], S["Ls"], S["Fmag"], S["Bf"], S["p"], S["kp"], \
-		                      S["J"], S["Uc"], S["DT"], 1.0e-6 );
-	};
-public:
-	UIpmsmDS() :UIbuilder ( "pmsmDS" ) {};
-	bdmroot* build ( Setting &S ) const {
-		pmsmDS* tmp = new pmsmDS ( S["DT"] );
-		//allowing recursive Settings
-		UIcall<pmsmDS*> ( S["params"], &tmp_set , tmp );
-	};
-
-};
-UIREGISTER(UIpmsmDS);
Index: /pmsm/sim.cpp
===================================================================
--- /pmsm/sim.cpp (revision 257)
+++ /pmsm/sim.cpp (revision 260)
@@ -11,8 +11,5 @@
 */
 
-#include <uibuilder.h>
-#include <stat/libDS.h>
-#include "pmsmDS.h"
-
+#include "pmsm_ui.h"
 #include <stat/loggers_ui.h>
 
@@ -35,4 +32,5 @@
 		DS->step();
 		DS->logit(*L);
+		L->step();
 	}
 	
Index: /CMakeLists.txt
===================================================================
--- /CMakeLists.txt (revision 256)
+++ /CMakeLists.txt (revision 260)
@@ -29,6 +29,6 @@
 	SET(CMAKE_CXX_FLAGS "-Wall -pipe  -Wno-unknown-pragmas")
 	SET(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG -O2")
-	SET(CMAKE_CXX_FLAGS_DEBUG "-g")
-	SET(CMAKE_CXX_FLAGS "-O2 -Wall -Wno-unknown-pragmas")
+	SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
+	SET(CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas")
 	ADD_DEFINITIONS(-DNDEBUG)
 	INCLUDE(CMakeLocal.txt OPTIONAL)	
