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