67 | | <a name="l00003"></a>00003 <span class="keywordtype">int</span> mxReplaceFieldNM(mxArray *X,<span class="keyword">const</span> <span class="keywordtype">char</span> * fname,mxArray *X1) |
68 | | <a name="l00004"></a>00004 { |
69 | | <a name="l00005"></a>00005 mxArray *Old; |
70 | | <a name="l00006"></a>00006 <span class="keywordtype">int</span> i; |
71 | | <a name="l00007"></a>00007 |
72 | | <a name="l00008"></a>00008 <span class="keywordflow">if</span>((i=mxGetFieldNumber(X,fname))==-1) |
73 | | <a name="l00009"></a>00009 { |
74 | | <a name="l00010"></a>00010 <span class="keywordflow">if</span>((i=mxAddField(X,fname))==-1) <span class="keywordflow">return</span> i; |
75 | | <a name="l00011"></a>00011 |
76 | | <a name="l00012"></a>00012 } |
77 | | <a name="l00013"></a>00013 |
78 | | <a name="l00014"></a>00014 Old=mxGetFieldByNumber(X,0,i); |
79 | | <a name="l00015"></a>00015 <span class="keywordflow">if</span>(Old)mxDestroyArray(Old); |
80 | | <a name="l00016"></a>00016 mxSetFieldByNumber(X,0,i,X1); |
81 | | <a name="l00017"></a>00017 <span class="keywordflow">return</span> i; |
82 | | <a name="l00018"></a>00018 |
83 | | <a name="l00019"></a>00019 }; |
84 | | <a name="l00020"></a>00020 |
85 | | <a name="l00021"></a>00021 <span class="keyword">class </span>mexlog : <span class="keyword">public</span> memlog{ |
86 | | <a name="l00022"></a>00022 <span class="keyword">public</span>: |
87 | | <a name="l00024"></a>00024 mexlog(<span class="keywordtype">int</span> maxlen): memlog(maxlen,<span class="stringliteral">"mx"</span>){}; |
88 | | <a name="l00026"></a>00026 mxArray* toCell(){ |
89 | | <a name="l00027"></a>00027 mxArray* tmp = mxCreateStructMatrix(1,1,0,NULL); |
90 | | <a name="l00028"></a>00028 |
91 | | <a name="l00029"></a>00029 <span class="comment">//copied from itsave</span> |
92 | | <a name="l00030"></a>00030 <span class="keywordtype">int</span> i; |
93 | | <a name="l00031"></a>00031 <span class="keywordtype">string</span> vec_name=<span class="stringliteral">""</span>; |
94 | | <a name="l00032"></a>00032 <span class="keywordtype">int</span> istart, iend; |
95 | | <a name="l00033"></a>00033 |
96 | | <a name="l00034"></a>00034 mat M; <span class="comment">//temporary matrix</span> |
97 | | <a name="l00035"></a>00035 <span class="keywordflow">for</span> ( i=0; i<entries.length();i++ ) { |
98 | | <a name="l00036"></a>00036 istart=0; |
99 | | <a name="l00037"></a>00037 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=0; j<entries(i).length(); j++){ <span class="comment">// same for as in add!!!</span> |
100 | | <a name="l00038"></a>00038 vec_name = names(i) + entries(i).name(j); |
101 | | <a name="l00039"></a>00039 iend=istart+entries(i).size(j)-1; |
102 | | <a name="l00040"></a>00040 M=vectors(i).get_cols(istart,iend); |
103 | | <a name="l00041"></a>00041 istart=iend+1; |
104 | | <a name="l00042"></a>00042 <span class="comment">// copy the selection to mx</span> |
105 | | <a name="l00043"></a>00043 mxArray* fld=mxCreateDoubleMatrix(M.rows(), M.cols(), mxREAL); |
106 | | <a name="l00044"></a>00044 mat2mxArray(M,fld); |
107 | | <a name="l00045"></a>00045 mxReplaceFieldNM(tmp, vec_name.c_str(), fld); |
108 | | <a name="l00046"></a>00046 } |
109 | | <a name="l00047"></a>00047 } |
110 | | <a name="l00048"></a>00048 <span class="keywordflow">return</span> tmp; |
111 | | <a name="l00049"></a>00049 } |
112 | | <a name="l00050"></a>00050 }; |
113 | | <a name="l00051"></a>00051 |
114 | | <a name="l00052"></a>00052 <span class="keyword">class </span>UImexlog: <span class="keyword">public</span> UIbuilder{ |
115 | | <a name="l00053"></a>00053 <span class="keyword">public</span>: |
116 | | <a name="l00054"></a>00054 UImexlog():UIbuilder(<span class="stringliteral">"mexlog"</span>){}; |
117 | | <a name="l00055"></a>00055 bdmroot* build(Setting &S)<span class="keyword"> const</span>{ |
118 | | <a name="l00056"></a>00056 <span class="keywordflow">return</span> <span class="keyword">new</span> mexlog(S[<span class="stringliteral">"maxlen"</span>]); |
119 | | <a name="l00057"></a>00057 }; |
120 | | <a name="l00058"></a>00058 }; |
121 | | <a name="l00059"></a>00059 UIREGISTER(UImexlog); |
| 67 | <a name="l00003"></a>00003 <span class="keyword">namespace </span>bdm{ |
| 68 | <a name="l00004"></a>00004 <span class="keywordtype">int</span> mxReplaceFieldNM(mxArray *X,<span class="keyword">const</span> <span class="keywordtype">char</span> * fname,mxArray *X1) |
| 69 | <a name="l00005"></a>00005 { |
| 70 | <a name="l00006"></a>00006 mxArray *Old; |
| 71 | <a name="l00007"></a>00007 <span class="keywordtype">int</span> i; |
| 72 | <a name="l00008"></a>00008 |
| 73 | <a name="l00009"></a>00009 <span class="keywordflow">if</span>((i=mxGetFieldNumber(X,fname))==-1) |
| 74 | <a name="l00010"></a>00010 { |
| 75 | <a name="l00011"></a>00011 <span class="keywordflow">if</span>((i=mxAddField(X,fname))==-1) <span class="keywordflow">return</span> i; |
| 76 | <a name="l00012"></a>00012 |
| 77 | <a name="l00013"></a>00013 } |
| 78 | <a name="l00014"></a>00014 |
| 79 | <a name="l00015"></a>00015 Old=mxGetFieldByNumber(X,0,i); |
| 80 | <a name="l00016"></a>00016 <span class="keywordflow">if</span>(Old)mxDestroyArray(Old); |
| 81 | <a name="l00017"></a>00017 mxSetFieldByNumber(X,0,i,X1); |
| 82 | <a name="l00018"></a>00018 <span class="keywordflow">return</span> i; |
| 83 | <a name="l00019"></a>00019 |
| 84 | <a name="l00020"></a>00020 }; |
| 85 | <a name="l00021"></a>00021 |
| 86 | <a name="l00022"></a>00022 <span class="keyword">class </span>mexlog : <span class="keyword">public</span> memlog { |
| 87 | <a name="l00023"></a>00023 <span class="keyword">public</span>: |
| 88 | <a name="l00025"></a>00025 mexlog(): <a class="code" href="classbdm_1_1memlog.html#611dda03b3050de2eaa448a59cee9c27" title="Default constructor.">memlog</a>(0,<span class="stringliteral">"mx"</span>){}; |
| 89 | <a name="l00027"></a>00027 mxArray* toCell(){ |
| 90 | <a name="l00028"></a>00028 mxArray* tmp = mxCreateStructMatrix(1,1,0,NULL); |
| 91 | <a name="l00029"></a>00029 |
| 92 | <a name="l00030"></a>00030 <span class="comment">//copied from itsave</span> |
| 93 | <a name="l00031"></a>00031 <span class="keywordtype">int</span> i; |
| 94 | <a name="l00032"></a>00032 <span class="keywordtype">string</span> vec_name=<span class="stringliteral">""</span>; |
| 95 | <a name="l00033"></a>00033 <span class="keywordtype">int</span> istart, iend; |
| 96 | <a name="l00034"></a>00034 |
| 97 | <a name="l00035"></a>00035 mat M; <span class="comment">//temporary matrix</span> |
| 98 | <a name="l00036"></a>00036 <span class="keywordflow">for</span> ( i=0; i<<a class="code" href="classbdm_1_1logger.html#c54566a4554089443a20b2a49ed1a61f" title="RVs of all logged variables.">entries</a>.length();i++ ) { |
| 99 | <a name="l00037"></a>00037 istart=0; |
| 100 | <a name="l00038"></a>00038 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=0; j<<a class="code" href="classbdm_1_1logger.html#c54566a4554089443a20b2a49ed1a61f" title="RVs of all logged variables.">entries</a>(i).length(); j++){ <span class="comment">// same for as in add!!!</span> |
| 101 | <a name="l00039"></a>00039 vec_name = <a class="code" href="classbdm_1_1logger.html#68ca1f05cf3d414ba0f39211977b8d02" title="Names of logged quantities, e.g. names of algorithm variants.">names</a>(i) + <a class="code" href="classbdm_1_1logger.html#c54566a4554089443a20b2a49ed1a61f" title="RVs of all logged variables.">entries</a>(i).name(j); |
| 102 | <a name="l00040"></a>00040 iend=istart+<a class="code" href="classbdm_1_1logger.html#c54566a4554089443a20b2a49ed1a61f" title="RVs of all logged variables.">entries</a>(i).size(j)-1; |
| 103 | <a name="l00041"></a>00041 M=<a class="code" href="classbdm_1_1memlog.html#1fed143162f2de6ef1c1b6557964f24e" title="Storage.">vectors</a>(i).get_cols(istart,iend); |
| 104 | <a name="l00042"></a>00042 istart=iend+1; |
| 105 | <a name="l00043"></a>00043 <span class="comment">// copy the selection to mx</span> |
| 106 | <a name="l00044"></a>00044 mxArray* fld=mxCreateDoubleMatrix(M.rows(), M.cols(), mxREAL); |
| 107 | <a name="l00045"></a>00045 mat2mxArray(M,fld); |
| 108 | <a name="l00046"></a>00046 mxReplaceFieldNM(tmp, vec_name.c_str(), fld); |
| 109 | <a name="l00047"></a>00047 } |
| 110 | <a name="l00048"></a>00048 } |
| 111 | <a name="l00049"></a>00049 <span class="keywordflow">return</span> tmp; |
| 112 | <a name="l00050"></a>00050 } |
| 113 | <a name="l00051"></a>00051 <span class="keywordtype">void</span> from_setting (<span class="keyword">const</span> Setting &root){ |
| 114 | <a name="l00052"></a>00052 <a class="code" href="classbdm_1_1memlog.html#a690ebd91430b5973855c9b4c9cf1b1d" title="Maximum length of vectors stored in memory.">maxlen</a>=root[<span class="stringliteral">"maxlen"</span>]; |
| 115 | <a name="l00053"></a>00053 } |
| 116 | <a name="l00054"></a>00054 }; |
| 117 | <a name="l00055"></a>00055 UIREGISTER(mexlog); |
| 118 | <a name="l00056"></a>00056 } |