Matlab.cpp

Go to the documentation of this file.
00001 #include "Matlab.h"
00002 
00003 Engine* gpMLEngine = NULL;
00004 FILE* gDebugLogFile = NULL;
00005 bool gEnableLineDebugger = false;
00006 
00007 
00008 
00009 bool InitMatlabEngine()
00010 {
00011 #ifdef NO_MATLAB
00012         assert(false);          // build without Matlab supports!
00013 
00014         return (false);
00015 #else
00016         if (gpMLEngine)
00017                 return (true);  // no need
00018 
00019         gpMLEngine = engOpen(NULL);     
00020         if (gpMLEngine == NULL)
00021         {
00022                 printf("Starting Engine Fails");
00023                 return(false);
00024         }
00025 
00026         return (true);
00027 #endif
00028 }
00029 
00030 void CloseMatlabEngine()
00031 {
00032 #ifdef NO_MATLAB
00033         assert(false);          // build without Matlab supports!
00034 
00035         return;
00036 #else
00037         if (gpMLEngine)
00038                 engClose(gpMLEngine);
00039 #endif
00040 }
00041 
00042 Engine* GetEngine()
00043 {
00044         return (gpMLEngine);
00045 }
00046 
00047 
00048 mxArray* _CreateDoubleMatrix(int nRow, int nCol, double* pData, char * szVarName)
00049 {
00050         if (!InitMatlabEngine())
00051                 return NULL;
00052 #ifndef NO_MATLAB
00053         Engine* ep = GetEngine();
00054 
00055         mxArray* pArr = mxCreateDoubleMatrix(nRow, nCol, mxREAL);
00056         double* xr = mxGetPr(pArr);
00057         memcpy(xr, pData, sizeof(double) * nRow * nCol);
00058         engPutVariable(ep, szVarName, pArr);
00059         return pArr;    
00060 #else
00061         return NULL;
00062 #endif
00063 }
00064 
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines