- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# mex_datasource.h

    00001 #ifndef MXDS_H
    00002 #define MXDS_H
    00003
    00004
    00005 #include "../bdm/bdmerror.h"
    00006 #include "../bdm/base/datasources.h"
    00007 #include "mex_parser.h"
    00008
    00009 namespace bdm {
    00017 class mxArrayDS : public MemDS {
    00018         public:
    00020         mxArrayDS ():MemDS() {};
    00021
    00035         void from_setting ( const Setting &set ) {
    00036                 Data = mxArray2mat ( mexGetVariable ( "base", set["varname"] ) );
    00037 /*              UI::get ( rowid, set, "rids" , UI::compulsory );
    00038                 bdm_assert_debug ( max ( rowid ) <= Data.rows(), "MemDS rowid is too high for given Dat." );
    00039
    00040                 UI::get ( delays, set, "tds", UI::compulsory );
    00041                 time = max ( delays );
    00042                 bdm_assert_debug ( time < Data.cols(), "MemDS delays are too high." );
    00043 */
    00044                 //set MemDS
    00045                 rowid = linspace(0,Data.rows()-1);
    00046                 delays = zeros_i(Data.rows());
    00047                 dtsize=rowid.length();
    00048                 utsize=0;
    00049
    00050                 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional );
    00051                 RV ru = RV();
    00052                 if (r){
    00053                         set_rvs ( *r, ru );
    00054                 } else {
    00055                         RV def((const char*)set["varname"],Data.rows());
    00056                         set_rvs(def, ru);
    00057                 }
    00058         }
    00059
    00060
    00061         // TODO dodelat void to_setting( Setting &set ) const;
    00062 };
    00063
    00064 UIREGISTER ( mxArrayDS );
    00065 SHAREDPTR ( mxArrayDS );
    00066
    00075 class mexDS : public DS {
    00076         protected:
    00078                 string step_name;
    00080                 string input_name;
    00082                 vec dt;
    00084                 vec ut;
    00085         public:
    00087         mexDS ():DS() {};
    00088
    00104         void from_setting ( const Setting &set ) {
    00105                 UI::get(step_name, set, "step_name", UI::compulsory);
    00106                 UI::get(input_name, set, "input_name", UI::compulsory);
    00107
    00108                 shared_ptr<RV> ry = UI::build<RV> ( set, "rv_out", UI::compulsory );
    00109                 shared_ptr<RV> ru = UI::build<RV> ( set, "rv_in", UI::compulsory);
    00110
    00111                 dtsize=ry->_dsize();
    00112                 utsize=ru->_dsize();
    00113
    00114                 set_drv(*ry, *ru);
    00115         }
    00116
    00117         void step() {
    00118                 mxArray* tmp;
    00119                 mxArray* tmp2;
    00120                 // write inputs to variable input_name
    00121                 mxArray* mxinp= mexGetVariable ( "global", input_name.c_str()) ;
    00122                 vec2mxArray(ut, mxinp);
    00123                 // call function step_name
    00124                 mexCallMATLAB(1, &tmp, 0, (mxArray **) &tmp2, step_name.c_str());
    00125                 // save its results
    00126                 dt=mxArray2vec(tmp);
    00127         }
    00128         void write(vec &ut0){ ut=ut0;}
    00129         void getdata(vec &dt_out){dt_out = dt;  }
    00130
    00131
    00132         // TODO dodelat void to_setting( Setting &set ) const;
    00133 };
    00134
    00135 UIREGISTER ( mexDS );
    00136 SHAREDPTR ( mexDS );
    00137
    00138 }
    00139 #endif //MXDS_H