1 | #include "../bdm/stat/datasources.h" |
---|
2 | #include "mex_parser.h" |
---|
3 | |
---|
4 | namespace bdm { |
---|
5 | /*! |
---|
6 | * \brief Memory storage of off-line data column-wise |
---|
7 | |
---|
8 | The data are stored in an internal matrix \c Data . Each column of Data corresponds to one discrete time observation \f$t\f$. Access to this matrix is via indices \c rowid and \c delays. |
---|
9 | |
---|
10 | The data can be loaded from a file. |
---|
11 | */ |
---|
12 | class MexDS : public MemDS { |
---|
13 | //!Default constructor |
---|
14 | MexDS () {}; |
---|
15 | |
---|
16 | /*! \brief Create memory data source from mxArray |
---|
17 | |
---|
18 | \code |
---|
19 | system={ |
---|
20 | type="mexDS"; |
---|
21 | varname=""; // name of workspace variable |
---|
22 | rids=[1 1 1]; // numbers of data rows |
---|
23 | tds =[0 1 2]; // time delays |
---|
24 | }; |
---|
25 | \endcode |
---|
26 | |
---|
27 | MemDS with the above fields will be created; |
---|
28 | |
---|
29 | \todo Very memory inefficient implementation. The data file is copied 2 times! |
---|
30 | For better implementatin we would need MemDS with pointer to the raw data. Then it could operate directly inside mxArray. |
---|
31 | |
---|
32 | */ |
---|
33 | void from_setting ( const Setting &set ) { |
---|
34 | Data = mxArray2mat ( mexGetVariable ( "base", set["varname"] ) ); |
---|
35 | UI::get ( rowid, set, "rids" , UI::compulsory ); |
---|
36 | it_assert_debug ( max ( rowid ) <= Data.rows(), "MemDS rowid is too high for given Dat." ); |
---|
37 | |
---|
38 | UI::get ( delays, set, "tds", UI::compulsory ); |
---|
39 | time = max ( delays ); |
---|
40 | it_assert_debug ( time < Data.cols(), "MemDS delays are too high." ); |
---|
41 | |
---|
42 | shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::compulsory ); |
---|
43 | RV ru = RV(); |
---|
44 | set_rvs ( *r, ru ); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | // TODO dodelat void to_setting( Setting &set ) const; |
---|
49 | }; |
---|
50 | |
---|
51 | UIREGISTER ( MexDS ); |
---|
52 | SHAREDPTR ( MexDS ); |
---|
53 | |
---|
54 | } |
---|