- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# mex_logger.h

    00001 #ifndef MXLOG_H
    00002 #define MXLOG_H
    00003
    00004 #include "base/loggers.h"
    00005
    00006 namespace bdm {
    00007 int mxReplaceFieldNM ( mxArray *X, const char * fname, mxArray *X1 ) {
    00008         mxArray *Old;
    00009         int i;
    00010
    00011         if ( ( i = mxGetFieldNumber ( X, fname ) ) == -1 ) {
    00012                 if ( ( i = mxAddField ( X, fname ) ) == -1 ) return i;
    00013
    00014         }
    00015
    00016         Old = mxGetFieldByNumber ( X, 0, i );
    00017         if ( Old ) mxDestroyArray ( Old );
    00018         mxSetFieldByNumber ( X, 0, i, X1 );
    00019         return i;
    00020
    00021 };
    00022
    00023 void Arrayvec2mxArray ( const Array<vec> &in, mxArray *out ) {
    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 }
    00043
    00045 class mexlog : public memlog {
    00046 public:
    00048         mexlog() : memlog ( 0, "" ) {};
    00050         mxArray* toCell() {
    00051                 mxArray* tmp = mxCreateStructMatrix ( 1, 1, 0, NULL );
    00052
    00053                 //copied from itsave
    00054                 int i;
    00055                 string vec_name = "";
    00056                 int istart, iend;
    00057
    00058                 mat M; //temporary matrix
    00059                 for ( i = 0; i < entries.length(); i++ ) {
    00060                         istart = 0;
    00061                         for ( int j = 0; j < entries ( i ).length(); j++ ) { // same for as in add!!!
    00062                                 vec_name = names ( i ) + entries ( i ).name ( j );
    00063                                 iend = istart + entries ( i ).size ( j ) - 1;
    00064                                 M = vectors ( i ).get_cols ( istart, iend );
    00065                                 istart = iend + 1;
    00066                                 // copy the selection to mx
    00067                                 mxArray* fld = mxCreateDoubleMatrix ( M.rows(), M.cols(), mxREAL );
    00068                                 mat2mxArray ( M, fld );
    00069                                 mxReplaceFieldNM ( tmp, vec_name.c_str(), fld );
    00070                         }
    00071                 }
    00072                 return tmp;
    00073         }
    00074         void from_setting ( const Setting &root ) {
    00075                 maxlen = root["maxlen"];
    00076         }
    00077 };
    00078 UIREGISTER ( mexlog );
    00079 SHAREDPTR ( mexlog );
    00080 }
    00081
    00082 #endif //MXLOG_H