1 | #ifndef MXDS_H |
---|
2 | #define MXDS_H |
---|
3 | |
---|
4 | |
---|
5 | #include "../bdm/bdmerror.h" |
---|
6 | #include "../bdm/base/datasources.h" |
---|
7 | #include "mex_parser.h" |
---|
8 | |
---|
9 | namespace bdm { |
---|
10 | /*! |
---|
11 | * \brief Memory storage of off-line data column-wise |
---|
12 | |
---|
13 | 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. |
---|
14 | |
---|
15 | The data can be loaded from a file. |
---|
16 | */ |
---|
17 | class mxArrayDS : public MemDS { |
---|
18 | public: |
---|
19 | //!Default constructor |
---|
20 | mxArrayDS ():MemDS() {}; |
---|
21 | |
---|
22 | /*! \brief Create memory data source from mxArray |
---|
23 | |
---|
24 | \code |
---|
25 | system={ |
---|
26 | type="mexDS"; |
---|
27 | varname=""; // name of workspace variable |
---|
28 | row_rv = {class='RV',...} // definition of |
---|
29 | }; |
---|
30 | \endcode |
---|
31 | |
---|
32 | MemDS with the above fields will be created; |
---|
33 | |
---|
34 | */ |
---|
35 | void from_setting ( const Setting &set ) { |
---|
36 | Data = mxArray2mat ( mexGetVariable ( "base", set["varname"] ) ); |
---|
37 | /* UI::get ( rowid, set, "rids" , UI::compulsory ); |
---|
38 | bdm_assert_debug ( max ( rowid ) <= Data.rows(), "MemDS rowid is too high for given Dat." ); |
---|
39 | |
---|
40 | UI::get ( delays, set, "tds", UI::compulsory ); |
---|
41 | time = max ( delays ); |
---|
42 | bdm_assert_debug ( time < Data.cols(), "MemDS delays are too high." ); |
---|
43 | */ |
---|
44 | //set MemDS |
---|
45 | rowid = linspace(0,Data.rows()-1); |
---|
46 | delays = zeros_i(Data.rows()); |
---|
47 | dtsize=rowid.length(); |
---|
48 | utsize=0; |
---|
49 | |
---|
50 | shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); |
---|
51 | RV ru = RV(); |
---|
52 | if (r){ |
---|
53 | set_rvs ( *r, ru ); |
---|
54 | } else { |
---|
55 | RV def((const char*)set["varname"],Data.rows()); |
---|
56 | set_rvs(def, ru); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | // TODO dodelat void to_setting( Setting &set ) const; |
---|
62 | }; |
---|
63 | |
---|
64 | UIREGISTER ( mxArrayDS ); |
---|
65 | SHAREDPTR ( mxArrayDS ); |
---|
66 | |
---|
67 | } |
---|
68 | #endif //MXDS_H |
---|