- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# mex_logger.h

    00001 #include "base/loggers.h"
    00002
    00003 namespace bdm{
    00004 int mxReplaceFieldNM(mxArray *X,const char * fname,mxArray *X1)
    00005 {
    00006         mxArray *Old;
    00007         int i;
    00008
    00009         if((i=mxGetFieldNumber(X,fname))==-1)
    00010         {
    00011                 if((i=mxAddField(X,fname))==-1) return i;
    00012
    00013         }
    00014
    00015         Old=mxGetFieldByNumber(X,0,i);
    00016         if(Old)mxDestroyArray(Old);
    00017         mxSetFieldByNumber(X,0,i,X1);
    00018         return i;
    00019
    00020 };
    00021
    00022 void Arrayvec2mxArray(const Array<vec> &in, mxArray *out)
    00023 {
    00024   int rows, cols, r, c;
    00025
    00026   double* temp = (double *) mxGetPr(out);
    00027   if (temp == 0) mexErrMsgTxt("mat2mxArray: Pointer to data is NULL");
    00028
    00029   cols = in.size();
    00030   if (cols == 0) mexErrMsgTxt("mat2mxArray: Data has zero columns");
    00031
    00032   rows = in(0).length(); //length of the first vec
    00033   if (rows == 0) mexErrMsgTxt("mat2mxArray: Data has zero rows");
    00034
    00035   for (c = 0; c < cols; c++) {
    00036     for (r = 0; r < rows; r++) {
    00037       *temp++ = in(c)(r);
    00038     }
    00039   }
    00040
    00041 }
    00042 class mexlog : public memlog {
    00043         public:
    00045         mexlog(): memlog(0,""){};
    00047         mxArray* toCell(){
    00048                 mxArray* tmp = mxCreateStructMatrix(1,1,0,NULL);
    00049
    00050                 //copied from itsave
    00051                 int i;
    00052                 string vec_name="";
    00053                 int istart, iend;
    00054
    00055                 mat M; //temporary matrix
    00056                 for ( i=0; i<entries.length();i++ ) {
    00057                         istart=0;
    00058                         for (int j=0; j<entries(i).length(); j++){ // same for as in add!!!
    00059                                 vec_name = names(i) + entries(i).name(j);
    00060                                 iend=istart+entries(i).size(j)-1;
    00061                                 M=vectors(i).get_cols(istart,iend);
    00062                                 istart=iend+1;
    00063                                 // copy the selection to mx
    00064                                 mxArray* fld=mxCreateDoubleMatrix(M.rows(), M.cols(), mxREAL);
    00065                                 mat2mxArray(M,fld);
    00066                                 mxReplaceFieldNM(tmp, vec_name.c_str(), fld);
    00067                         }
    00068                 }
    00069                 return tmp;
    00070         }
    00071         void from_setting (const Setting &root){
    00072           maxlen=root["maxlen"];
    00073         }
    00074 };
    00075 UIREGISTER(mexlog);
    00076 }