Changeset 685 for library/bdm/mex/mex_datasource.h
- Timestamp:
- 10/29/09 23:23:56 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/mex/mex_datasource.h
r676 r685 91 91 \code 92 92 system={ 93 type="mexDS";93 class="mexDS"; 94 94 step_name=""; // name of function to call 95 95 input_name=""; // name of workspace variable where inputs are written 96 rv_out= {class='RV',...} // identification of outputs97 rv_in= {class='RV',...} // identification of inputs96 yrv = {class='RV',...} // identification of outputs 97 urv = {class='RV',...} // identification of inputs 98 98 }; 99 99 \endcode … … 106 106 UI::get(input_name, set, "input_name", UI::compulsory); 107 107 108 shared_ptr<RV> ry = UI::build<RV> ( set, " rv_out", UI::compulsory );109 shared_ptr<RV> ru = UI::build<RV> ( set, " rv_in", UI::compulsory);108 shared_ptr<RV> ry = UI::build<RV> ( set, "yrv", UI::compulsory ); 109 shared_ptr<RV> ru = UI::build<RV> ( set, "urv", UI::compulsory); 110 110 111 dtsize=ry->_dsize();111 ytsize=ry->_dsize(); 112 112 utsize=ru->_dsize(); 113 113 dtsize = ytsize+utsize; 114 114 115 set_drv(*ry, *ru); 116 validate(); 115 117 } 116 118 117 119 void step() { 118 120 mxArray* tmp; 119 mxArray* tmp2;121 mxArray* dummy=NULL; 120 122 // write inputs to variable input_name 121 123 mxArray* mxinp= mexGetVariable ( "global", input_name.c_str()) ; 124 if (mxinp){ 125 if((int)mxGetM(mxinp)!=utsize || (int)mxGetN(mxinp)!=utsize) { 126 // mxinp is invalid - create new one 127 mxDestroyArray(mxinp); 128 mxinp=mxCreateDoubleMatrix(utsize,1,mxREAL); 129 } 130 131 } else { 132 mxinp=mxCreateDoubleMatrix(utsize,1,mxREAL); 133 } 122 134 vec2mxArray(ut, mxinp); 135 mexPutVariable("global",input_name.c_str(),mxinp); 123 136 // call function step_name 124 mexCallMATLAB(1, &tmp, 0, (mxArray **) & tmp2, step_name.c_str());137 mexCallMATLAB(1, &tmp, 0, (mxArray **) &dummy, step_name.c_str()); 125 138 // save its results 126 dt=mxArray2vec(tmp); 139 bdm_assert_debug((int)mxGetM(tmp)==ytsize || (int)mxGetN(tmp)==ytsize,"mexDS.step() expected return vector of length " + num2str(dtsize) + 140 "got vector " + num2str((int)mxGetM(tmp)) + "x" + num2str((int)mxGetN(tmp))); 141 //write y 142 dt.set_subvector(0,mxArray2vec(tmp)); 143 //write u 144 dt.set_subvector(ytsize,ut); 127 145 } 128 void write(const vec &ut0){ ut=ut0;} 129 void getdata(vec &dt_out) const {dt_out = dt; } 146 void write(const vec &ut0){ 147 bdm_assert_debug(ut0.length()==ut.length(),"mexDS: Incompatible input vector"); 148 ut=ut0; 149 } 150 void getdata(vec &dt_out) const { 151 bdm_assert_debug(dt_out.length()==dt.length(),"mexDS: Incompatible output vector"); 152 dt_out = dt; 153 } 130 154 155 void validate() { 156 dt=zeros(dtsize); 157 ut=zeros(utsize); 158 } 131 159 132 160 // TODO dodelat void to_setting( Setting &set ) const;