Index: library/bdm/base/datasources.cpp
===================================================================
--- library/bdm/base/datasources.cpp (revision 895)
+++ library/bdm/base/datasources.cpp (revision 896)
@@ -1,55 +1,104 @@
-
 #include "datasources.h"
 
 using namespace bdm;
 
-void MemDS::getdata ( vec &dt ) const {
-	int i;
-
-	bdm_assert_debug ( dt.length() == rowid.length(), "MemDS:getdata incompatible dt" );
-	for ( i = 0; i < rowid.length(); i++ ) {
-		dt ( i ) = Data ( rowid ( i ), time );
-	}
+MemDS::MemDS ( mat &Dat ) : Data( Dat ) {
 }
 
-void MemDS::getdata ( vec &dt, const ivec &indeces ) {
-	int j, i;
-	bdm_assert_debug ( dt.length() == indeces.length(), "MemDS:getdata incompatible dt" );
-	for ( i = 0; i < indeces.length(); i++ ) {
-		j = indeces ( i );
-		dt ( i ) = Data ( rowid ( j ), time );
-	}
-}
-
-void MemDS::step() {
-	if ( time < Data.cols() ) {
+void MemDS::step( ) {
+	if ( time < max_length() ) {
 		time++;
 	}
 }
 
-void MemDS::set_drv ( const RV &drv, const RV &urv ) {
-	bdm_assert_debug ( drv._dsize() == rowid.length(), "MemDS::set_rvs incompatible drv" );
-	bdm_assert_debug ( urv._dsize() == 0, "MemDS does not support urv." );
-
-	DS::set_drv ( drv, urv );
+void MemDS::getdata ( vec &dt ) const {
+	bdm_assert_debug ( dt.length() == Data.rows(), "MemDS:getdata incompatible dt" );
+	dt = Data.get_col ( time );
 }
 
-MemDS::MemDS ( mat &Dat, ivec &rowid0 ) : rowid ( rowid0 ) {
-	bdm_assert_debug ( max ( rowid ) <= Dat.rows(), "MemDS rowid is too high for given Dat." );
+void MemDS::getdata ( vec &dt, const ivec &indices ) {
+	bdm_assert_debug ( dt.length() == indices.length(), "MemDS:getdata incompatible dt" );
+	vec tmp = Data.get_col ( time );
+	dt = tmp ( indices );
+}
+
+void MemDS::set_drv ( const RV &drv ) {
+	bdm_assert_debug ( drv._dsize() == Data.rows(), "MemDS::set_rvs incompatible drv" );
+	DS::set_drv ( drv, RV() );
+}
+
+void MemDS::from_setting ( const Setting &set ) {
+	DS::from_setting ( set );
+
+	UI::get ( Data, set, "Data", UI::compulsory );
+	
+	if ( !UI::get ( time, set, "time", UI::optional ) ) {
+		time = 0;
+	}
+	
+	shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional );
+	if ( !r ) {
+		r = new RV();
+		for ( int i = 0; i < Data.rows(); i++ ) {
+			r->add ( RV ( "ch" + num2str ( i ), 1, 0 ) );
+		}
+	}
+	
+	set_drv ( *r );
+	dtsize = r->_dsize();
+	utsize = 0;
+}
+
+void FileDS::from_setting ( const Setting & set ) {
+	// here we do not call MemDS::from_setting intentionally as we can not load any Data matrix directly
+	DS::from_setting ( set );
+
+	string filename;
+	UI::get ( filename, set, "filename", UI::compulsory );
 
 	time = 0;
-	Data = Dat;
+
+	shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional );
+	if ( !r ) {
+		r = new RV();
+		for ( int i = 0; i < Data.rows(); i++ ) {
+			r->add ( RV ( "ch" + num2str ( i ), 1, 0 ) );
+		}
+	}
+	
+	set_drv ( *r );
+	dtsize = r->_dsize();
+	utsize = 0;
 }
 
-void ITppFileDS::from_setting ( const Setting &set ) {
-	shared_ptr<RV> rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory );
+void CsvFileDS::from_setting ( const Setting & set ) {
+	FileDS::from_setting ( set );
 
-	it_file it ( set["filename"] );
-	it << Name ( set["varname"] );
+	vec data_line;
+	string line;
+
+	ifstream fs;
+	fs.open ( filename.c_str() );
+	if ( fs.is_open() ) {
+		while ( getline ( fs, line ) ) {
+			data_line.set ( line );
+			Data.append_row ( data_line );
+		}
+	}
+
+	string orientation;
+	if( UI::get ( orientation, set, "orientation", UI::optional ) & orientation == "BY_ROW" ) 
+		transpose ( Data, Data );
+}
+
+void ITppFileDS::from_setting ( const Setting & set ) {
+	FileDS::from_setting ( set );
+
+	string varname;
+	UI::get ( varname, set, "varname", UI::compulsory );
+
+	it_file it ( filename );
+	it << Name ( varname );
 	it >> Data;
-	time = 0;
-	//rowid and delays are ignored
-	rowid = linspace ( 0, Data.rows() - 1 );
-	set_drv ( *rvtmp, RV() );
 }
 
@@ -62,5 +111,5 @@
 }
 
-void PdfDS::getdata ( vec &dt_out ) const {
+void PdfDS::getdata ( vec & dt_out ) const {
 	bdm_assert_debug ( dt_out.length() >= dtsize, "Short output vector" );
 	dt_out.set_subvector ( 0, yt );
@@ -85,5 +134,5 @@
 }
 
-void StateDS::from_setting ( const Setting &set ) {
+void StateDS::from_setting ( const Setting & set ) {
 	IM = UI::build<pdf> ( set, "IM", UI::compulsory );
 	OM = UI::build<pdf> ( set, "OM", UI::compulsory );
