Changeset 896 for library/bdm/base/datasources.h
- Timestamp:
- 04/09/10 09:31:37 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/datasources.h
r895 r896 32 32 //! active column in the Data matrix 33 33 int time; 34 //! vector of rows that are presented in Dt 35 ivec rowid; 36 37 public: 34 35 public: 36 //!Default constructor 37 MemDS () {}; 38 39 //! Convenience constructor 40 MemDS ( mat &Dat ); 41 42 //! returns number of data in the file; 38 43 int max_length() { 39 44 return Data.cols(); 40 45 } 46 41 47 void getdata ( vec &dt ) const; 42 void getdata ( vec &dt, const ivec &indeces ); 43 void set_drv ( const RV &drv, const RV &urv ); 48 49 void getdata ( vec &dt, const ivec &indices ); 50 51 void set_drv ( const RV &drv ); 52 53 void set_drv ( const RV &drv, const RV &urv ) 54 { 55 bdm_error ( "MemDS::urv is not supported" ); 56 } 44 57 45 58 void write ( const vec &ut ) { … … 52 65 53 66 void step(); 54 //!Default constructor 55 MemDS () {}; 56 //! Convenience constructor 57 MemDS ( mat &Dat, ivec &rowid0 ); 67 58 68 /*! Create object from the following structure 59 69 \code … … 63 73 drv = {class="RV"; ...} // Identification how rows of the matrix Data will be known to others 64 74 time = 0; // Index of the first column to user_info, 65 rowid = [1,2,3...]; // ids of rows to be used66 75 } 67 76 \endcode … … 69 78 If the optional fields are not given, they will be filled as follows: 70 79 \code 71 rowid= [0, 1, 2, ...number_of_rows_of_Data];72 80 drv = {names=("ch0", "ch1", "ch2", ..."number_of_rows_of_Data"); 73 81 sizes=( 1 1 1 ...); … … 76 84 time = 0; 77 85 \endcode 78 If \c rowid is given, \c drv will be named after ind eces in rowids.86 If \c rowid is given, \c drv will be named after indices in rowids. 79 87 80 88 Hence the data provided by method \c getdata() will be full column of matrix Data starting from the first record. 81 89 */ 82 void from_setting ( const Setting &set ) { 83 UI::get ( Data, set, "Data", UI::compulsory ); 84 if ( !UI::get ( time, set, "time", UI::optional ) ) { 85 time = 0; 86 } 87 if ( !UI::get ( rowid, set, "rowid", UI::optional ) ) { 88 rowid = linspace ( 0, Data.rows() - 1 ); 89 } 90 shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional ); 91 if ( !r ) { 92 r = new RV(); 93 for ( int i = 0; i < rowid.length(); i++ ) { 94 r->add ( RV ( "ch" + num2str ( rowid ( i ) ), 1, 0 ) ); 95 } 96 } 97 set_drv ( *r, RV() ); //empty urv 98 dtsize = r->_dsize(); 99 utsize = 0; 100 } 90 void from_setting ( const Setting &set ); 101 91 }; 102 92 UIREGISTER ( MemDS ); … … 106 96 */ 107 97 class FileDS: public MemDS { 108 109 public: 110 void getdata ( vec &dt ) { 111 dt = Data.get_col ( time ); 112 } 113 114 void getdata ( vec &dt, const ivec &indices ) { 115 vec tmp = Data.get_col ( time ); 116 dt = tmp ( indices ); 117 } 118 119 //! returns number of data in the file; 120 int ndat() { 121 return Data.cols(); 122 } 123 //! no sense to log this type 124 void log_register ( logger &L, const string &prefix ) {}; 125 //! no sense to log this type 126 void log_write ( ) const {}; 98 protected: 99 string filename; 100 public: 101 void from_setting ( const Setting & set ); 127 102 }; 128 103 … … 142 117 it >> Data; 143 118 time = 0; 144 // rowid anddelays are ignored119 //delays are ignored 145 120 }; 146 121 … … 165 140 */ 166 141 class CsvFileDS: public FileDS { 167 168 public: 169 //! Constructor - create DS from a CSV file. 170 CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 142 public: 143 void from_setting ( const Setting & set ); 171 144 }; 172 145 … … 203 176 virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 204 177 205 //! Accepts action variables at specific ind eces206 virtual void write ( const vec &ut, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;178 //! Accepts action variables at specific indices 179 virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 207 180 208 181 /*! … … 261 234 262 235 263 //! Returns data records at ind eces.264 virtual void getdata ( vec &dt, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;236 //! Returns data records at indices. 237 virtual void getdata ( vec &dt, const ivec &indices ) NOT_IMPLEMENTED_VOID; 265 238 266 239 … … 364 337 } 365 338 366 virtual void write ( const vec &ut, const ivec &ind eces ) NOT_IMPLEMENTED_VOID;339 virtual void write ( const vec &ut, const ivec &indices ) NOT_IMPLEMENTED_VOID; 367 340 368 341 /*! UI for stateDS