Index: library/bdm/mex/mex_function.h
===================================================================
--- library/bdm/mex/mex_function.h (revision 885)
+++ library/bdm/mex/mex_function.h (revision 1064)
@@ -8,36 +8,36 @@
 namespace bdm {
 
-	/*! class mapping fnc.eval to call of matlab function via mexCallMatlab
-	*/
-	class mexFnc: public fnc{
-		protected:
-		string fname;
-		public:
-			vec eval(const vec &cond){
-				mxArray *mxinp = mxCreateDoubleMatrix ( cond.length(), 1, mxREAL );
-				mxArray *mxout;
-				
-				vec2mxArray(cond,mxinp);
-				mexCallMATLAB ( 1, &mxout, 1, &mxinp, fname.c_str() );
-				
-				bdm_assert(int(mxGetN(mxout))==(dimension()) || int(mxGetM(mxout))==(dimension()), "vector length mismatch");
-				vec tmp=mxArray2vec(mxout);
-				return tmp;
-			}
-			/*! 
-			\code
-			function = 'matlab_function_name';
-			\endcode
-			*/
-			void from_setting(const Setting &set){
-				fnc::from_setting(set);
-				UI::get(fname, set, "function", UI::compulsory);
-			}
-			void to_setting(Setting &set) const {
-				fnc::to_setting(set);
-				UI::save(fname, set, "function");
-			}
-	};
-	UIREGISTER(mexFnc);
+/*! class mapping fnc.eval to call of matlab function via mexCallMatlab
+*/
+class mexFnc: public fnc {
+protected:
+    string fname;
+public:
+    vec eval(const vec &cond) {
+        mxArray *mxinp = mxCreateDoubleMatrix ( cond.length(), 1, mxREAL );
+        mxArray *mxout;
+
+        vec2mxArray(cond,mxinp);
+        mexCallMATLAB ( 1, &mxout, 1, &mxinp, fname.c_str() );
+
+        bdm_assert(int(mxGetN(mxout))==(dimension()) || int(mxGetM(mxout))==(dimension()), "vector length mismatch");
+        vec tmp=mxArray2vec(mxout);
+        return tmp;
+    }
+    /*!
+    \code
+    function = 'matlab_function_name';
+    \endcode
+    */
+    void from_setting(const Setting &set) {
+        fnc::from_setting(set);
+        UI::get(fname, set, "function", UI::compulsory);
+    }
+    void to_setting(Setting &set) const {
+        fnc::to_setting(set);
+        UI::save(fname, set, "function");
+    }
+};
+UIREGISTER(mexFnc);
 }
 #endif //MXFNC_H
Index: library/bdm/mex/mex_pdf.h
===================================================================
--- library/bdm/mex/mex_pdf.h (revision 955)
+++ library/bdm/mex/mex_pdf.h (revision 1064)
@@ -1,50 +1,50 @@
-class mexEpdf: public epdf{
-	protected:
-		mxArray *data;
-	public:
-		mexEpdf() {};
-		void from_setting(const Setting &S)  {
-			Setting &So=S["object"];
-			data = (mxArray*)long(So);
-		} 
-		void set_data(mxArray * tmp){
-			data=tmp;
-		}
-		void validate() {
-			mexCallMATLAB(0, 0, 1, &data,  "validate");
-			mxArray *tmp;
-			mexCallMATLAB(1, &tmp, 1, &data, "dimension");
-			dim = mxArray2double(tmp);
-			mexCallMATLAB(1, &tmp, 1, &data, "get_rv");
-			UImxArray rvtmp(tmp);
-			shared_ptr<RV> r=UI::build<RV>(rvtmp);
-			if (r){
-				set_rv(*r);
-			}
-		}
-		vec mean() const {
-			mxArray *tmp;
-			mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, "mean");
-			return mxArray2vec(tmp);
-		}
-		vec sample() const {
-			mxArray *tmp;
-			mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, "sample");
-			return mxArray2vec(tmp);
-		}
-		double evallog(const vec &dt) const {
-			mxArray *tmp;
-			mxArray *in[2];
-			in[0]=data;
-			in[1]=mxCreateDoubleMatrix(dimension(),1,mxREAL);
-			vec2mxArray(dt,in[1]);
-			mexCallMATLAB(1, &tmp, 2, in, "evallog");
-			return mxArray2double(tmp);
-		}
-		vec variance() const {
-			mxArray *tmp;
-			mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, "variance");
-			return mxArray2vec(tmp);
-		}
+class mexEpdf: public epdf {
+protected:
+    mxArray *data;
+public:
+    mexEpdf() {};
+    void from_setting(const Setting &S)  {
+        Setting &So=S["object"];
+        data = (mxArray*)long(So);
+    }
+    void set_data(mxArray * tmp) {
+        data=tmp;
+    }
+    void validate() {
+        mexCallMATLAB(0, 0, 1, &data,  "validate");
+        mxArray *tmp;
+        mexCallMATLAB(1, &tmp, 1, &data, "dimension");
+        dim = mxArray2double(tmp);
+        mexCallMATLAB(1, &tmp, 1, &data, "get_rv");
+        UImxArray rvtmp(tmp);
+        shared_ptr<RV> r=UI::build<RV>(rvtmp);
+        if (r) {
+            set_rv(*r);
+        }
+    }
+    vec mean() const {
+        mxArray *tmp;
+        mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, "mean");
+        return mxArray2vec(tmp);
+    }
+    vec sample() const {
+        mxArray *tmp;
+        mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, "sample");
+        return mxArray2vec(tmp);
+    }
+    double evallog(const vec &dt) const {
+        mxArray *tmp;
+        mxArray *in[2];
+        in[0]=data;
+        in[1]=mxCreateDoubleMatrix(dimension(),1,mxREAL);
+        vec2mxArray(dt,in[1]);
+        mexCallMATLAB(1, &tmp, 2, in, "evallog");
+        return mxArray2double(tmp);
+    }
+    vec variance() const {
+        mxArray *tmp;
+        mexCallMATLAB(1, &tmp, 1, (mxArray **) &data, "variance");
+        return mxArray2vec(tmp);
+    }
 };
 UIREGISTER(mexEpdf);
Index: library/bdm/mex/mex_datasource.h
===================================================================
--- library/bdm/mex/mex_datasource.h (revision 1060)
+++ library/bdm/mex/mex_datasource.h (revision 1064)
@@ -9,69 +9,71 @@
 namespace bdm {
 /*!
-* \brief DataSource reading data columns from a Matlab matrix 
+* \brief DataSource reading data columns from a Matlab matrix
 
-The data are stored in a arbitrary Matlab matrix. Each column of the matrix corresponds to one discrete time observation \f$t\f$. 
+The data are stored in a arbitrary Matlab matrix. Each column of the matrix corresponds to one discrete time observation \f$t\f$.
 The DataSource needs to know the name of the matrix and possibly decription of its contents (via RV)_
 
 */
 class mxArrayDS : public DS {
-	protected:
-		//! raw pointer to data
-		double *data;
-		//! maximum length of data
-		int max_len;
-		//! active column 
-		int column;
+protected:
+    //! raw pointer to data
+    double *data;
+    //! maximum length of data
+    int max_len;
+    //! active column
+    int column;
 public:
-	
-	//!Default constructor
-	mxArrayDS () : DS() {};
 
-	/*! Create object from the following structure
+    //!Default constructor
+    mxArrayDS () : DS() {};
 
-	\code
-	class   = 'mxArrayDS';
-	varname = 'data_matrix';                   % name of a Matlab workspace variable
-	-- inherited fields ---
-	bdm::DS::from_setting
-	drv     = RV({'names',...},[sizes,...]);   % names of data redords in columns
-	\endcode
-	
-	*/
-	void from_setting ( const Setting &set ) {
-		string name;
-		UI::get(name, set, "varname", UI::compulsory);
-		mxArray *mxAr = mexGetVariable ( "base", name.c_str() );
-		
-		bdm_assert(mxIsNumeric(mxAr),"Matlab variable: "+name +" is not a matrix");
-		
-		dtsize = mxGetM(mxAr);
-		max_len= mxGetN(mxAr);
-		data = (double*)mxGetPr(mxAr);
-		utsize = 0;
+    /*! Create object from the following structure
 
-		DS::from_setting(set); //read drv
-		
-		if (Drv._dsize()!=dtsize){
-			Drv=RV( ( const char* ) set["varname"], dtsize );
-		}
-		column = 0;
-	
-		if (max_length()>0){
-			dt = vec(&data[column*dtsize],dtsize);
-		}
-	}
+    \code
+    class   = 'mxArrayDS';
+    varname = 'data_matrix';                   % name of a Matlab workspace variable
+    -- inherited fields ---
+    bdm::DS::from_setting
+    drv     = RV({'names',...},[sizes,...]);   % names of data redords in columns
+    \endcode
 
-	int max_length() {return max_len;}
-	
-	void step(){
-		if (column<max_length()){
-			column++;
-		
-			dt = vec(&data[column*dtsize],dtsize);
-		} else {
-			bdm_error("DS: trying to read after max_length()");
-		}
-	}
+    */
+    void from_setting ( const Setting &set ) {
+        string name;
+        UI::get(name, set, "varname", UI::compulsory);
+        mxArray *mxAr = mexGetVariable ( "base", name.c_str() );
+
+        bdm_assert(mxIsNumeric(mxAr),"Matlab variable: "+name +" is not a matrix");
+
+        dtsize = mxGetM(mxAr);
+        max_len= mxGetN(mxAr);
+        data = (double*)mxGetPr(mxAr);
+        utsize = 0;
+
+        DS::from_setting(set); //read drv
+
+        if (Drv._dsize()!=dtsize) {
+            Drv=RV( ( const char* ) set["varname"], dtsize );
+        }
+        column = 0;
+
+        if (max_length()>0) {
+            dt = vec(&data[column*dtsize],dtsize);
+        }
+    }
+
+    int max_length() {
+        return max_len;
+    }
+
+    void step() {
+        if (column<max_length()) {
+            column++;
+
+            dt = vec(&data[column*dtsize],dtsize);
+        } else {
+            bdm_error("DS: trying to read after max_length()");
+        }
+    }
 };
 
Index: library/bdm/mex/mex_parser.h
===================================================================
--- library/bdm/mex/mex_parser.h (revision 969)
+++ library/bdm/mex/mex_parser.h (revision 1064)
@@ -16,278 +16,278 @@
 class UImxArray : public Config {
 public:
-	//! Build an instance of Config with fields filled from the given \a mxarray
-	UImxArray ( const mxArray *mxarray ) : Config() {
-		Setting & setting = this->getRoot(); //setting is a group
-		if ( !mxIsStruct ( mxarray ) ) {
-			mexErrMsgTxt ( "Given mxArray is not a struct." );
-		};
-
-		//mexCallMATLAB(0, NULL, 1, (mxArray **) &mxarray, "dump");
-		fillGroup ( setting, mxarray );
-		setAutoConvert ( true );
-	}
-	UImxArray() : Config() {
-		setAutoConvert ( true );
-	}
-	//! Add libconfig's \c list to the structure
-	void addList ( const mxArray *mxarray, const char* name ) {
-		Setting & setting = this->getRoot(); //setting is a group
-		Setting & child = setting.add ( name, Setting::TypeList );
-		fillList ( child, mxarray );
-	}
-	//! Add libconfig's \c group to the structure
-	void addGroup ( const mxArray *mxarray, const char* name ) {
-		Setting & setting = this->getRoot(); //setting is a group
-		Setting & child = setting.add ( name, Setting::TypeGroup );
-		fillGroup ( child, mxarray );
-	}
-	//! Operator for more convenient access to this Config
-	operator Setting&() {
-		return getRoot();
-	}
+    //! Build an instance of Config with fields filled from the given \a mxarray
+    UImxArray ( const mxArray *mxarray ) : Config() {
+        Setting & setting = this->getRoot(); //setting is a group
+        if ( !mxIsStruct ( mxarray ) ) {
+            mexErrMsgTxt ( "Given mxArray is not a struct." );
+        };
+
+        //mexCallMATLAB(0, NULL, 1, (mxArray **) &mxarray, "dump");
+        fillGroup ( setting, mxarray );
+        setAutoConvert ( true );
+    }
+    UImxArray() : Config() {
+        setAutoConvert ( true );
+    }
+    //! Add libconfig's \c list to the structure
+    void addList ( const mxArray *mxarray, const char* name ) {
+        Setting & setting = this->getRoot(); //setting is a group
+        Setting & child = setting.add ( name, Setting::TypeList );
+        fillList ( child, mxarray );
+    }
+    //! Add libconfig's \c group to the structure
+    void addGroup ( const mxArray *mxarray, const char* name ) {
+        Setting & setting = this->getRoot(); //setting is a group
+        Setting & child = setting.add ( name, Setting::TypeGroup );
+        fillGroup ( child, mxarray );
+    }
+    //! Operator for more convenient access to this Config
+    operator Setting&() {
+        return getRoot();
+    }
 
 private:
-	void storeNumeric ( Setting &setting, const mxArray *value, string key = "" ) {
-		//TODO: integer matrices
-		if ( !mxIsNumeric ( value ) ) {
-			mexErrMsgTxt ( "Given mxArray is not numeric." );
-		};
-		//treat empty matrices independently
-		mat val;
-		if ( mxGetM ( value ) > 0 && mxGetN(value)>0) {
-			val = mxArray2mat ( value );
-		}
-		if ( ( val.rows() == 1 ) && ( val.cols() == 1 ) ) {
-			Setting &child = ( key == "" ) ? setting.add ( Setting::TypeFloat )
-			                 : setting.add ( key, Setting::TypeFloat );
-			child = val ( 0, 0 );
-		} else {
-			Setting &child = ( key == "" ) ? setting.add ( Setting::TypeList )
-			                 : setting.add ( key, Setting::TypeList );
-			Setting &label = child.add ( Setting::TypeString );
-			label = "matrix";
-			Setting &rows = child.add ( Setting::TypeInt );
-			Setting &cols = child.add ( Setting::TypeInt );
-			Setting &elements = child.add ( Setting::TypeArray );
-			cols = val.cols();
-			rows = val.rows();
-			for ( int i = 0; i < val.rows(); i++ ) {
-				for ( int j = 0; j < val.cols(); j++ ) {
-					Setting &el = elements.add ( Setting::TypeFloat );
-					el = val ( i, j );
-				}
-			}
-		}
-	}
-
-	void fillGroup ( Setting &setting, const mxArray *mxarray ) {
-		if ( !mxIsStruct ( mxarray ) ) {
-			mexErrMsgTxt ( "Given mxArray is not a struct." );
-		};
-		for ( int i = 0; i < mxGetNumberOfFields ( mxarray ); i++ ) {
-			const char *key = mxGetFieldNameByNumber ( mxarray, i );
-			mxArray *value = mxGetField ( mxarray, 0, key );
-			if ( mxIsChar ( value ) ) {
-				Setting &child = setting.add ( key, Setting::TypeString );
-				child = mxArray2string ( value );
-				} else {
-			if ( mxIsLogical ( value ) ) {
-				Setting &child = setting.add ( key, Setting::TypeBoolean );
-				child = ( bool ) mxArray2bin ( value );
-			} else {
-			if ( mxIsStruct ( value ) ) {
-				Setting &child = setting.add ( key, Setting::TypeGroup );
-				fillGroup ( child, value );
-			} else {
-			if ( mxIsCell ( value ) ) {
-				Setting &child = setting.add ( key, Setting::TypeList );
-				fillList ( child, value );
-			} else {
-			if ( mxIsNumeric ( value ) ) {
-				storeNumeric ( setting, value, ( string ) key );
-			} else {
-			// it is neither of above - treat it as an address
-			// if (mxIsObject(value)){ <== should be tested but it is broken in matlab...
-			
-				Setting &child = setting.add(key, Setting::TypeInt64);
-				child = (long long)value;
-			}
-			}
-			}
-			}
-				}
-		}
-	}
-
-	void fillList ( Setting &setting, const mxArray *mxarray ) {
-		if ( !mxIsCell ( mxarray ) ) {
-			mexErrMsgTxt ( "Given mxArray is not a cell." );
-		};
-		for ( unsigned int i = 0; i < ( unsigned int ) mxGetNumberOfElements ( mxarray ); i++ ) {
-			mxArray *value = mxGetCell ( mxarray, i );
-			if ( mxIsChar ( value ) ) {
-				Setting &child = setting.add ( Setting::TypeString );
-				child = mxArray2string ( value );
-			}
-			if ( mxIsLogical ( value ) ) {
-				Setting &child = setting.add ( Setting::TypeBoolean );
-				child = ( bool ) mxArray2bin ( value );
-			}
-			if ( mxIsStruct ( value ) ) {
-				Setting &child = setting.add ( Setting::TypeGroup );
-				fillGroup ( child, value );
-			}
-			if ( mxIsCell ( value ) ) {
-				Setting &child = setting.add ( Setting::TypeList );
-				fillList ( child, value );
-			}
-			if ( mxIsNumeric ( value ) ) {
-				storeNumeric ( setting, value );
-			}
-		}
-	}
+    void storeNumeric ( Setting &setting, const mxArray *value, string key = "" ) {
+        //TODO: integer matrices
+        if ( !mxIsNumeric ( value ) ) {
+            mexErrMsgTxt ( "Given mxArray is not numeric." );
+        };
+        //treat empty matrices independently
+        mat val;
+        if ( mxGetM ( value ) > 0 && mxGetN(value)>0) {
+            val = mxArray2mat ( value );
+        }
+        if ( ( val.rows() == 1 ) && ( val.cols() == 1 ) ) {
+            Setting &child = ( key == "" ) ? setting.add ( Setting::TypeFloat )
+                             : setting.add ( key, Setting::TypeFloat );
+            child = val ( 0, 0 );
+        } else {
+            Setting &child = ( key == "" ) ? setting.add ( Setting::TypeList )
+                             : setting.add ( key, Setting::TypeList );
+            Setting &label = child.add ( Setting::TypeString );
+            label = "matrix";
+            Setting &rows = child.add ( Setting::TypeInt );
+            Setting &cols = child.add ( Setting::TypeInt );
+            Setting &elements = child.add ( Setting::TypeArray );
+            cols = val.cols();
+            rows = val.rows();
+            for ( int i = 0; i < val.rows(); i++ ) {
+                for ( int j = 0; j < val.cols(); j++ ) {
+                    Setting &el = elements.add ( Setting::TypeFloat );
+                    el = val ( i, j );
+                }
+            }
+        }
+    }
+
+    void fillGroup ( Setting &setting, const mxArray *mxarray ) {
+        if ( !mxIsStruct ( mxarray ) ) {
+            mexErrMsgTxt ( "Given mxArray is not a struct." );
+        };
+        for ( int i = 0; i < mxGetNumberOfFields ( mxarray ); i++ ) {
+            const char *key = mxGetFieldNameByNumber ( mxarray, i );
+            mxArray *value = mxGetField ( mxarray, 0, key );
+            if ( mxIsChar ( value ) ) {
+                Setting &child = setting.add ( key, Setting::TypeString );
+                child = mxArray2string ( value );
+            } else {
+                if ( mxIsLogical ( value ) ) {
+                    Setting &child = setting.add ( key, Setting::TypeBoolean );
+                    child = ( bool ) mxArray2bin ( value );
+                } else {
+                    if ( mxIsStruct ( value ) ) {
+                        Setting &child = setting.add ( key, Setting::TypeGroup );
+                        fillGroup ( child, value );
+                    } else {
+                        if ( mxIsCell ( value ) ) {
+                            Setting &child = setting.add ( key, Setting::TypeList );
+                            fillList ( child, value );
+                        } else {
+                            if ( mxIsNumeric ( value ) ) {
+                                storeNumeric ( setting, value, ( string ) key );
+                            } else {
+                                // it is neither of above - treat it as an address
+                                // if (mxIsObject(value)){ <== should be tested but it is broken in matlab...
+
+                                Setting &child = setting.add(key, Setting::TypeInt64);
+                                child = (long long)value;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    void fillList ( Setting &setting, const mxArray *mxarray ) {
+        if ( !mxIsCell ( mxarray ) ) {
+            mexErrMsgTxt ( "Given mxArray is not a cell." );
+        };
+        for ( unsigned int i = 0; i < ( unsigned int ) mxGetNumberOfElements ( mxarray ); i++ ) {
+            mxArray *value = mxGetCell ( mxarray, i );
+            if ( mxIsChar ( value ) ) {
+                Setting &child = setting.add ( Setting::TypeString );
+                child = mxArray2string ( value );
+            }
+            if ( mxIsLogical ( value ) ) {
+                Setting &child = setting.add ( Setting::TypeBoolean );
+                child = ( bool ) mxArray2bin ( value );
+            }
+            if ( mxIsStruct ( value ) ) {
+                Setting &child = setting.add ( Setting::TypeGroup );
+                fillGroup ( child, value );
+            }
+            if ( mxIsCell ( value ) ) {
+                Setting &child = setting.add ( Setting::TypeList );
+                fillList ( child, value );
+            }
+            if ( mxIsNumeric ( value ) ) {
+                storeNumeric ( setting, value );
+            }
+        }
+    }
 
 public:
-	//! Convert existing Setting to Matlab arrays
-	static mxArray * create_mxArray( const Setting &setting )
-	{
-		return group2mxstruct ( setting );
-	}
-
-	//! Convert existing Setting to Matlab arrays
-	mxArray * create_mxArray(  )
-	{
-		return group2mxstruct ( *this );
-	}
+    //! Convert existing Setting to Matlab arrays
+    static mxArray * create_mxArray( const Setting &setting )
+    {
+        return group2mxstruct ( setting );
+    }
+
+    //! Convert existing Setting to Matlab arrays
+    mxArray * create_mxArray(  )
+    {
+        return group2mxstruct ( *this );
+    }
 
 private:
-	//! Convert libconfig's array to Matlab vector
-	static mxArray* array2mxvector ( const Setting &setting )  {
-		if ( !setting.isArray() ) mexErrMsgTxt ( "Given setting is not an array" );
-		mxArray *result = mxCreateDoubleMatrix ( 1, setting.getLength(), mxREAL );
-		double *elements = mxGetPr ( result );
-		for ( int i = 0; i < setting.getLength(); i++ ) {
-			if ( setting.getType() == Setting::TypeInt ) { //TODO: tady je chyba -- zaporna cisla nejsou TypeInt
-				elements[i] = ( int ) setting[i];
-			} else {
-				elements[i] =  setting[i];
-			}
-		}
-		return result;
-	}
-
-	//! Convert libconfig's array to Matlab matrix
-	static mxArray* list2mxmatrix ( const Setting &setting )  {
-		if ( !setting.isList() || ( strcmp ( "matrix", setting[0] ) != 0 ) )
-			mexErrMsgTxt ( "Given setting is not a matrix" );
-		int rows = setting[1];
-		int cols = setting[2];
-		if ( setting[3].getLength() != rows*cols )
-			mexErrMsgTxt ( "Matrix elements do not fit to rows*cols" );
-		double *elements = new double[rows*cols];
-		for ( int i = 0; i < rows*cols; i++ ) {
-			elements[i] = setting[3][i];
-		}
-		mat &m = * ( new mat ( elements, rows, cols ) );
-		mxArray *result = mxCreateDoubleMatrix ( rows, cols, mxREAL );
-		mat2mxArray ( m, result );
-		delete &m;
-		delete [] elements;
-		return result;
-	}
-
-	//! Convert libconfig's gourp to Matlab structure
-	static mxArray* group2mxstruct ( const Setting &setting ) {
-		if ( !setting.isGroup() ) mexErrMsgTxt ( "Given setting is not a group." );
-		const char ** keys = new const char*[setting.getLength() ];
-		for ( int i = 0; i < setting.getLength(); i++ ) {
-			keys[i] = setting[i].getName();
-		}
-		mxArray *result = mxCreateStructMatrix ( 1, 1, setting.getLength(), keys );
-		delete keys;
-		for ( int i = 0; i < setting.getLength(); i++ ) {
-			Setting &value = setting[i];
-			mxArray *old = mxGetFieldByNumber ( result, 0, i );
-			if ( old ) mxDestroyArray ( old );
-			switch ( value.getType() ) {
-			case Setting::TypeString:
-				mxSetFieldByNumber ( result, 0, i, mxCreateString ( value ) );
-				break;
-			case Setting::TypeBoolean:
-				mxSetFieldByNumber ( result, 0, i, mxCreateLogicalScalar ( value ) );
-				break;
-			case Setting::TypeGroup:
-				mxSetFieldByNumber ( result, 0, i, group2mxstruct ( value ) );
-				break;
-			case Setting::TypeList:
-				mxSetFieldByNumber ( result, 0, i, list2mxcell ( value ) );
-				break;
-			case Setting::TypeArray:
-				mxSetFieldByNumber ( result, 0, i, array2mxvector ( value ) );
-				break;
-			case Setting::TypeInt:
-			case Setting::TypeInt64:
-				mxSetFieldByNumber ( result, 0, i, mxCreateDoubleScalar ( ( int ) value ) );
-				break;
-			case Setting::TypeFloat:
-				mxSetFieldByNumber ( result, 0, i, mxCreateDoubleScalar ( value ) );
-				break;
-			default:
-				//this should never happen
-				mexErrMsgTxt ( "Unknown type of a setting." );
-			}
-		}
-		return result;
-
-	}
-	//! Convert libconfig's list  to Matlab cell
-	static mxArray* list2mxcell ( const Setting &setting )  {
-		if ( !setting.isList() ) mexErrMsgTxt ( "Given setting is not a list." );
-		if ( setting.getLength() == 0 ) {
-			mxArray *result = mxCreateCellMatrix ( 1, 0 );
-			return result;
-		}
-
-		if ( ( setting[0].getType() == Setting::TypeString ) ) {
-			string s = ( setting[0] );
-			if ( s == "matrix" ) {
-				return list2mxmatrix ( setting );
-			}
-		}
-		mxArray *result = mxCreateCellMatrix ( 1, setting.getLength() );
-		for ( int i = 0; i < setting.getLength(); i++ ) {
-			Setting &value = setting[i];
-			mxArray *old = mxGetCell ( result, i );
-			if ( old ) mxDestroyArray ( old );
-			switch ( value.getType() ) {
-			case Setting::TypeString:
-				mxSetCell ( result, i, mxCreateString ( value ) );
-				break;
-			case Setting::TypeBoolean:
-				mxSetCell ( result, i, mxCreateLogicalScalar ( value ) );
-				break;
-			case Setting::TypeGroup:
-				mxSetCell ( result, i, group2mxstruct ( value ) );
-				break;
-			case Setting::TypeList:
-				mxSetCell ( result, i, list2mxcell ( value ) );
-				break;
-			case Setting::TypeArray:
-				mxSetCell ( result, i, array2mxvector ( value ) );
-				break;
-			case Setting::TypeInt:
-			case Setting::TypeInt64:
-				mxSetCell ( result, i, mxCreateDoubleScalar ( ( int ) value ) );
-				break;
-			case Setting::TypeFloat:
-				mxSetCell ( result, i, mxCreateDoubleScalar ( value ) );
-				break;
-			default:
-				//this should never happen
-				mexErrMsgTxt ( "Unknown type of a setting." );
-			}
-		}
-		return result;
-	}
+    //! Convert libconfig's array to Matlab vector
+    static mxArray* array2mxvector ( const Setting &setting )  {
+        if ( !setting.isArray() ) mexErrMsgTxt ( "Given setting is not an array" );
+        mxArray *result = mxCreateDoubleMatrix ( 1, setting.getLength(), mxREAL );
+        double *elements = mxGetPr ( result );
+        for ( int i = 0; i < setting.getLength(); i++ ) {
+            if ( setting.getType() == Setting::TypeInt ) { //TODO: tady je chyba -- zaporna cisla nejsou TypeInt
+                elements[i] = ( int ) setting[i];
+            } else {
+                elements[i] =  setting[i];
+            }
+        }
+        return result;
+    }
+
+    //! Convert libconfig's array to Matlab matrix
+    static mxArray* list2mxmatrix ( const Setting &setting )  {
+        if ( !setting.isList() || ( strcmp ( "matrix", setting[0] ) != 0 ) )
+            mexErrMsgTxt ( "Given setting is not a matrix" );
+        int rows = setting[1];
+        int cols = setting[2];
+        if ( setting[3].getLength() != rows*cols )
+            mexErrMsgTxt ( "Matrix elements do not fit to rows*cols" );
+        double *elements = new double[rows*cols];
+        for ( int i = 0; i < rows*cols; i++ ) {
+            elements[i] = setting[3][i];
+        }
+        mat &m = * ( new mat ( elements, rows, cols ) );
+        mxArray *result = mxCreateDoubleMatrix ( rows, cols, mxREAL );
+        mat2mxArray ( m, result );
+        delete &m;
+        delete [] elements;
+        return result;
+    }
+
+    //! Convert libconfig's gourp to Matlab structure
+    static mxArray* group2mxstruct ( const Setting &setting ) {
+        if ( !setting.isGroup() ) mexErrMsgTxt ( "Given setting is not a group." );
+        const char ** keys = new const char*[setting.getLength() ];
+        for ( int i = 0; i < setting.getLength(); i++ ) {
+            keys[i] = setting[i].getName();
+        }
+        mxArray *result = mxCreateStructMatrix ( 1, 1, setting.getLength(), keys );
+        delete keys;
+        for ( int i = 0; i < setting.getLength(); i++ ) {
+            Setting &value = setting[i];
+            mxArray *old = mxGetFieldByNumber ( result, 0, i );
+            if ( old ) mxDestroyArray ( old );
+            switch ( value.getType() ) {
+            case Setting::TypeString:
+                mxSetFieldByNumber ( result, 0, i, mxCreateString ( value ) );
+                break;
+            case Setting::TypeBoolean:
+                mxSetFieldByNumber ( result, 0, i, mxCreateLogicalScalar ( value ) );
+                break;
+            case Setting::TypeGroup:
+                mxSetFieldByNumber ( result, 0, i, group2mxstruct ( value ) );
+                break;
+            case Setting::TypeList:
+                mxSetFieldByNumber ( result, 0, i, list2mxcell ( value ) );
+                break;
+            case Setting::TypeArray:
+                mxSetFieldByNumber ( result, 0, i, array2mxvector ( value ) );
+                break;
+            case Setting::TypeInt:
+            case Setting::TypeInt64:
+                mxSetFieldByNumber ( result, 0, i, mxCreateDoubleScalar ( ( int ) value ) );
+                break;
+            case Setting::TypeFloat:
+                mxSetFieldByNumber ( result, 0, i, mxCreateDoubleScalar ( value ) );
+                break;
+            default:
+                //this should never happen
+                mexErrMsgTxt ( "Unknown type of a setting." );
+            }
+        }
+        return result;
+
+    }
+    //! Convert libconfig's list  to Matlab cell
+    static mxArray* list2mxcell ( const Setting &setting )  {
+        if ( !setting.isList() ) mexErrMsgTxt ( "Given setting is not a list." );
+        if ( setting.getLength() == 0 ) {
+            mxArray *result = mxCreateCellMatrix ( 1, 0 );
+            return result;
+        }
+
+        if ( ( setting[0].getType() == Setting::TypeString ) ) {
+            string s = ( setting[0] );
+            if ( s == "matrix" ) {
+                return list2mxmatrix ( setting );
+            }
+        }
+        mxArray *result = mxCreateCellMatrix ( 1, setting.getLength() );
+        for ( int i = 0; i < setting.getLength(); i++ ) {
+            Setting &value = setting[i];
+            mxArray *old = mxGetCell ( result, i );
+            if ( old ) mxDestroyArray ( old );
+            switch ( value.getType() ) {
+            case Setting::TypeString:
+                mxSetCell ( result, i, mxCreateString ( value ) );
+                break;
+            case Setting::TypeBoolean:
+                mxSetCell ( result, i, mxCreateLogicalScalar ( value ) );
+                break;
+            case Setting::TypeGroup:
+                mxSetCell ( result, i, group2mxstruct ( value ) );
+                break;
+            case Setting::TypeList:
+                mxSetCell ( result, i, list2mxcell ( value ) );
+                break;
+            case Setting::TypeArray:
+                mxSetCell ( result, i, array2mxvector ( value ) );
+                break;
+            case Setting::TypeInt:
+            case Setting::TypeInt64:
+                mxSetCell ( result, i, mxCreateDoubleScalar ( ( int ) value ) );
+                break;
+            case Setting::TypeFloat:
+                mxSetCell ( result, i, mxCreateDoubleScalar ( value ) );
+                break;
+            default:
+                //this should never happen
+                mexErrMsgTxt ( "Unknown type of a setting." );
+            }
+        }
+        return result;
+    }
 };
 
Index: library/bdm/mex/mex_BM.h
===================================================================
--- library/bdm/mex/mex_BM.h (revision 944)
+++ library/bdm/mex/mex_BM.h (revision 1064)
@@ -1,77 +1,79 @@
 #include <mex/mex_parser.h>
 #include <mex/mex_pdf.h>
-class mexBM: public BM{
-	protected:
-		mxArray *data;
-		mexEpdf est;
-	public:
-		mexBM() {};
-		void from_setting(const Setting &S)  {
-			Setting &So=S["object"];
-			data = (mxArray*)long(So);
-		} 
-		void validate() {
-			mxArray *tmp;
-			mexCallMATLAB(1, &tmp, 1, &data,  "validate");
-			// new object is in tmp
-			data = tmp;
-			
-			mexCallMATLAB(1, &tmp, 1, &data, "dimensions");
-			vec v=mxArray2vec(tmp);
-			if (v.length()<3) {bdm_error("Three dimensions are expected in mexBM.dimensions");}
-			set_dim(v(0));
-			dimy = v(1);
-			dimc = v(2);
-			
-			mexCallMATLAB(1, &tmp, 1, &data, "get_rv");
-			UImxArray rvtmp(tmp);
-			shared_ptr<RV> r = UI::build<RV>(rvtmp);
-			set_rv(*r);
-			
-			mexCallMATLAB(1, &tmp, 1, &data, "get_rvc");
-			UImxArray rvtmpc(tmp);
-			shared_ptr<RV> rc = UI::build<RV>(rvtmpc);
-			rvtmpc.writeFile("tmpc.cfg");
-			rvc=*rc;
-			
-			mexCallMATLAB(1, &tmp, 1, &data, "get_rvy");
-			UImxArray rvtmpy(tmp);
-			rvtmpy.writeFile("tmpy.cfg");
-			shared_ptr<RV> ry = UI::build<RV>(rvtmpy);
-			yrv = *ry;
-			
-		}
-		void bayes(const vec &dt, const vec &cond) {
-			mxArray *tmp;
-			mxArray *in[3];
-			in[0]=data;
-			in[1]=mxCreateDoubleMatrix(dt.length(),1,mxREAL);
-			vec2mxArray(dt,in[1]);
-			in[2]=mxCreateDoubleMatrix(cond.length(),1,mxREAL);
-			vec2mxArray(cond,in[2]);
-			
-			mexCallMATLAB(1, &tmp, 3, in, "bayes");
-			data = tmp;
-		}
-		epdf* predictor(const vec &cond) const {
-			mxArray *tmp;
-			mxArray *in[3];
-			in[0]=data;
-			in[1]=mxCreateDoubleMatrix(cond.length(),1,mxREAL);
-			vec2mxArray(cond,in[1]);
-			
-			mexCallMATLAB(1, &tmp, 3, in, "predictor");
-			
-			UImxArray uitmp(tmp);
-			shared_ptr<epdf> pred = UI::build<epdf>(uitmp);
-			return pred.get();
-			//
-		}
-		const epdf& posterior() const {
-			mxArray *tmp;
-			mexCallMATLAB(1, &tmp, 1,(mxArray **) &data,  "posterior");
-			const_cast<mexEpdf*>(&est)->set_data(tmp);
-			return est;
-		}
+class mexBM: public BM {
+protected:
+    mxArray *data;
+    mexEpdf est;
+public:
+    mexBM() {};
+    void from_setting(const Setting &S)  {
+        Setting &So=S["object"];
+        data = (mxArray*)long(So);
+    }
+    void validate() {
+        mxArray *tmp;
+        mexCallMATLAB(1, &tmp, 1, &data,  "validate");
+        // new object is in tmp
+        data = tmp;
+
+        mexCallMATLAB(1, &tmp, 1, &data, "dimensions");
+        vec v=mxArray2vec(tmp);
+        if (v.length()<3) {
+            bdm_error("Three dimensions are expected in mexBM.dimensions");
+        }
+        set_dim(v(0));
+        dimy = v(1);
+        dimc = v(2);
+
+        mexCallMATLAB(1, &tmp, 1, &data, "get_rv");
+        UImxArray rvtmp(tmp);
+        shared_ptr<RV> r = UI::build<RV>(rvtmp);
+        set_rv(*r);
+
+        mexCallMATLAB(1, &tmp, 1, &data, "get_rvc");
+        UImxArray rvtmpc(tmp);
+        shared_ptr<RV> rc = UI::build<RV>(rvtmpc);
+        rvtmpc.writeFile("tmpc.cfg");
+        rvc=*rc;
+
+        mexCallMATLAB(1, &tmp, 1, &data, "get_rvy");
+        UImxArray rvtmpy(tmp);
+        rvtmpy.writeFile("tmpy.cfg");
+        shared_ptr<RV> ry = UI::build<RV>(rvtmpy);
+        yrv = *ry;
+
+    }
+    void bayes(const vec &dt, const vec &cond) {
+        mxArray *tmp;
+        mxArray *in[3];
+        in[0]=data;
+        in[1]=mxCreateDoubleMatrix(dt.length(),1,mxREAL);
+        vec2mxArray(dt,in[1]);
+        in[2]=mxCreateDoubleMatrix(cond.length(),1,mxREAL);
+        vec2mxArray(cond,in[2]);
+
+        mexCallMATLAB(1, &tmp, 3, in, "bayes");
+        data = tmp;
+    }
+    epdf* predictor(const vec &cond) const {
+        mxArray *tmp;
+        mxArray *in[3];
+        in[0]=data;
+        in[1]=mxCreateDoubleMatrix(cond.length(),1,mxREAL);
+        vec2mxArray(cond,in[1]);
+
+        mexCallMATLAB(1, &tmp, 3, in, "predictor");
+
+        UImxArray uitmp(tmp);
+        shared_ptr<epdf> pred = UI::build<epdf>(uitmp);
+        return pred.get();
+        //
+    }
+    const epdf& posterior() const {
+        mxArray *tmp;
+        mexCallMATLAB(1, &tmp, 1,(mxArray **) &data,  "posterior");
+        const_cast<mexEpdf*>(&est)->set_data(tmp);
+        return est;
+    }
 };
 UIREGISTER(mexBM);
Index: library/bdm/mex/mex_logger.h
===================================================================
--- library/bdm/mex/mex_logger.h (revision 900)
+++ library/bdm/mex/mex_logger.h (revision 1064)
@@ -6,37 +6,37 @@
 namespace bdm {
 int mxReplaceFieldNM ( mxArray *X, const char * fname, mxArray *X1 ) {
-	mxArray *Old;
-	int i;
+    mxArray *Old;
+    int i;
 
-	if ( ( i = mxGetFieldNumber ( X, fname ) ) == -1 ) {
-		if ( ( i = mxAddField ( X, fname ) ) == -1 ) return i;
+    if ( ( i = mxGetFieldNumber ( X, fname ) ) == -1 ) {
+        if ( ( i = mxAddField ( X, fname ) ) == -1 ) return i;
 
-	}
+    }
 
-	Old = mxGetFieldByNumber ( X, 0, i );
-	if ( Old ) mxDestroyArray ( Old );
-	mxSetFieldByNumber ( X, 0, i, X1 );
-	return i;
+    Old = mxGetFieldByNumber ( X, 0, i );
+    if ( Old ) mxDestroyArray ( Old );
+    mxSetFieldByNumber ( X, 0, i, X1 );
+    return i;
 
 };
 
 void Arrayvec2mxArray ( const Array<vec> &in, mxArray *out ) {
-	int rows, cols, r, c;
+    int rows, cols, r, c;
 
-	double* temp = ( double * ) mxGetPr ( out );
-	if ( temp == 0 ) mexErrMsgTxt ( "mat2mxArray: Pointer to data is NULL" );
+    double* temp = ( double * ) mxGetPr ( out );
+    if ( temp == 0 ) mexErrMsgTxt ( "mat2mxArray: Pointer to data is NULL" );
 
-	cols = in.size();
-	if ( cols == 0 ) mexErrMsgTxt ( "mat2mxArray: Data has zero columns" );
+    cols = in.size();
+    if ( cols == 0 ) mexErrMsgTxt ( "mat2mxArray: Data has zero columns" );
 
-	rows = in ( 0 ).length(); //length of the first vec
-	if ( rows == 0 ) mexErrMsgTxt ( "mat2mxArray: Data has zero rows" );
+    rows = in ( 0 ).length(); //length of the first vec
+    if ( rows == 0 ) mexErrMsgTxt ( "mat2mxArray: Data has zero rows" );
 
-	for ( c = 0; c < cols; c++ ) {
-		for ( r = 0; r < rows; r++ ) {
-			*temp++ = in ( c ) ( r );
+    for ( c = 0; c < cols; c++ ) {
+        for ( r = 0; r < rows; r++ ) {
+            *temp++ = in ( c ) ( r );
 
-		}
-	}
+        }
+    }
 
 }
@@ -45,39 +45,39 @@
 class mexlog : public memlog {
 public:
-	//! constructor
-	mexlog() : memlog ( 0, "" ) {};
-	//! constructor
-	mexlog ( long maxlen0 ) : memlog ( maxlen0, "" ) {};
-	//! copy internal data to output mxArray
-	mxArray* toCell() {
-		mxArray* tmp = mxCreateStructMatrix ( 1, 1, 0, NULL );
+    //! constructor
+    mexlog() : memlog ( 0, "" ) {};
+    //! constructor
+    mexlog ( long maxlen0 ) : memlog ( maxlen0, "" ) {};
+    //! copy internal data to output mxArray
+    mxArray* toCell() {
+        mxArray* tmp = mxCreateStructMatrix ( 1, 1, 0, NULL );
 
-		//copied from itsave
-		int i;
-		string vec_name = "";
-		int istart, iend;
+        //copied from itsave
+        int i;
+        string vec_name = "";
+        int istart, iend;
 
-		mat M; //temporary matrix
-		for ( i = 0; i < entries.length(); i++ ) {
-			istart = 0;
-			for ( int j = 0; j < entries ( i ).length(); j++ ) { // same for as in add!!!
-				vec_name = names ( i ) + separator + entries ( i ).name ( j );
-				iend = istart + entries ( i ).size ( j ) - 1;
-				M = vectors ( i ).get_cols ( istart, iend );
-				istart = iend + 1;
-				// copy the selection to mx
-				mxArray* fld = mxCreateDoubleMatrix ( M.rows(), M.cols(), mxREAL );
-				mat2mxArray ( M, fld );
-				mxReplaceFieldNM ( tmp, vec_name.c_str(), fld );
-			}
-		}
-		return tmp;
-	}
-	void from_setting ( const Setting &root ) {
-		maxlen = root["maxlen"];
-	}
-	Config& _setting_conf() {
-		return setting_conf;
-	}
+        mat M; //temporary matrix
+        for ( i = 0; i < entries.length(); i++ ) {
+            istart = 0;
+            for ( int j = 0; j < entries ( i ).length(); j++ ) { // same for as in add!!!
+                vec_name = names ( i ) + separator + entries ( i ).name ( j );
+                iend = istart + entries ( i ).size ( j ) - 1;
+                M = vectors ( i ).get_cols ( istart, iend );
+                istart = iend + 1;
+                // copy the selection to mx
+                mxArray* fld = mxCreateDoubleMatrix ( M.rows(), M.cols(), mxREAL );
+                mat2mxArray ( M, fld );
+                mxReplaceFieldNM ( tmp, vec_name.c_str(), fld );
+            }
+        }
+        return tmp;
+    }
+    void from_setting ( const Setting &root ) {
+        maxlen = root["maxlen"];
+    }
+    Config& _setting_conf() {
+        return setting_conf;
+    }
 };
 UIREGISTER ( mexlog );
