- 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                 dtsize=rowid.length();
    00047                 utsize=0;
    00048
    00049                 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional );
    00050                 RV ru = RV();
    00051                 if (r){
    00052                         set_drv ( *r, ru );
    00053                 } else {
    00054                         RV def((const char*)set["varname"],Data.rows());
    00055                         set_drv(def, ru);
    00056                 }
    00057         }
    00058
    00059
    00060         // TODO dodelat void to_setting( Setting &set ) const;
    00061 };
    00062
    00063 UIREGISTER ( mxArrayDS );
    00064 SHAREDPTR ( mxArrayDS );
    00065
    00074 class mexDS : public DS {
    00075         protected:
    00077                 string step_name;
    00079                 string input_name;
    00081                 vec dt;
    00083                 vec ut;
    00084         public:
    00086         mexDS ():DS() {};
    00087
    00103         void from_setting ( const Setting &set ) {
    00104                 UI::get(step_name, set, "step_name", UI::compulsory);
    00105                 UI::get(input_name, set, "input_name", UI::compulsory);
    00106
    00107                 shared_ptr<RV> ry = UI::build<RV> ( set, "rv_out", UI::compulsory );
    00108                 shared_ptr<RV> ru = UI::build<RV> ( set, "rv_in", UI::compulsory);
    00109
    00110                 dtsize=ry->_dsize();
    00111                 utsize=ru->_dsize();
    00112
    00113                 set_drv(*ry, *ru);
    00114         }
    00115
    00116         void step() {
    00117                 mxArray* tmp;
    00118                 mxArray* tmp2;
    00119                 // write inputs to variable input_name
    00120                 mxArray* mxinp= mexGetVariable ( "global", input_name.c_str()) ;
    00121                 vec2mxArray(ut, mxinp);
    00122                 // call function step_name
    00123                 mexCallMATLAB(1, &tmp, 0, (mxArray **) &tmp2, step_name.c_str());
    00124                 // save its results
    00125                 dt=mxArray2vec(tmp);
    00126         }
    00127         void write(const vec &ut0){ ut=ut0;}
    00128         void getdata(vec &dt_out){dt_out = dt;  }
    00129
    00130
    00131         // TODO dodelat void to_setting( Setting &set ) const;
    00132 };
    00133
    00134 UIREGISTER ( mexDS );
    00135 SHAREDPTR ( mexDS );
    00136
    00137 }
    00138 #endif //MXDS_H