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