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 mexlog ( long maxlen0 ) : memlog ( maxlen0, "" ) {}; 00052 mxArray* toCell() { 00053 mxArray* tmp = mxCreateStructMatrix ( 1, 1, 0, NULL ); 00054 00055 //copied from itsave 00056 int i; 00057 string vec_name = ""; 00058 int istart, iend; 00059 00060 mat M; //temporary matrix 00061 for ( i = 0; i < entries.length(); i++ ) { 00062 istart = 0; 00063 for ( int j = 0; j < entries ( i ).length(); j++ ) { // same for as in add!!! 00064 vec_name = names ( i ) + separator + entries ( i ).name ( j ); 00065 iend = istart + entries ( i ).size ( j ) - 1; 00066 M = vectors ( i ).get_cols ( istart, iend ); 00067 istart = iend + 1; 00068 // copy the selection to mx 00069 mxArray* fld = mxCreateDoubleMatrix ( M.rows(), M.cols(), mxREAL ); 00070 mat2mxArray ( M, fld ); 00071 mxReplaceFieldNM ( tmp, vec_name.c_str(), fld ); 00072 } 00073 } 00074 return tmp; 00075 } 00076 00084 void from_setting ( const Setting &set ) { 00085 UI::get ( maxlen, set, "maxlen", UI::compulsory ); 00086 } 00087 00088 Config& _setting_conf() { 00089 return setting_conf; 00090 } 00091 }; 00092 UIREGISTER ( mexlog ); 00093 SHAREDPTR ( mexlog ); 00094 } 00095 00096 #endif //MXLOG_H
Generated on 2 Dec 2013 for mixpp by 1.4.7