Index: mttroot/mtt/bin/mtt ================================================================== --- mttroot/mtt/bin/mtt +++ mttroot/mtt/bin/mtt @@ -15,10 +15,15 @@ ############################################################### ## Version control history ############################################################### ## $Header$ ## $Log$ +## Revision 1.336 2002/05/07 23:50:34 geraint +## Preliminary support for Matlab dynamically linked shared objects: +## invoke with: mtt -cc sys rep mexglx +## ode2odes support is not yet included. +## ## Revision 1.335 2002/05/01 17:30:55 geraint ## Improved pre-processor directives to better accommodate future alternatives (matlab) ## if necessary. ## ## Revision 1.334 2002/05/01 14:10:22 gawthrop @@ -2112,11 +2117,11 @@ ## .mex files $1_%.mexglx: $1_%.cc $1_def.h $1_sympar.h $1_cr.h echo Creating $1_\$*.mexglx ${MTT_CXX} -shared -o $1_\$*.mexglx $1_\$*.cc \ ${MTT_MATLAB_FLAGS} -DCODEGENTARGET=MATLABMEX \ - ${MTT_CXXINCS} ${MTT_CXXLIBS} ${MTT_CXXFLAGS} ${MTT_LIB}/cc/mtt_kpathsea.cc + ${MTT_CXXINCS} ${MTT_CXXLIBS} ${MTT_CXXFLAGS} ${MTT_LIB}/cc/mtt_kpathsea.cc ${MTT_LIB}/cc/mtt_matlab_octave.cc ## .cc files .PRECIOUS: %.cc # Don't let mtt delete them $1_%.cc: $1_%.m mtt_m2cc.sh $1 \$* cat Index: mttroot/mtt/bin/mttrc ================================================================== --- mttroot/mtt/bin/mttrc +++ mttroot/mtt/bin/mttrc @@ -13,10 +13,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.33 2002/05/08 11:39:36 gawthrop +## Added MTT_REP to PATH +## ## Revision 1.32 2002/05/07 23:50:34 geraint ## Preliminary support for Matlab dynamically linked shared objects: ## invoke with: mtt -cc sys rep mexglx ## ode2odes support is not yet included. ## @@ -240,9 +243,9 @@ # exported variables export MTT_CXX="g++" export MTT_CXXFLAGS="${DEBUG} ${OPTIM} ${FLAGS}" export MTT_CXXLIBS="${LOCTAVE} ${LSYSTEM}" - export MTT_CXXINCS="-I. ${IOCTAVE}" + export MTT_CXXINCS="-I. -I${MTT_LIB}/cc ${IOCTAVE}" export MTT_LDFLAGS=" " export MTT_MATLAB_FLAGS="${MATLAB_FLAGS} ${MATLAB_INCS} ${MATLAB_LIBS}" fi Index: mttroot/mtt/bin/trans/mtt_header ================================================================== --- mttroot/mtt/bin/trans/mtt_header +++ mttroot/mtt/bin/trans/mtt_header @@ -10,10 +10,15 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.47 2002/05/07 23:50:34 geraint +## Preliminary support for Matlab dynamically linked shared objects: +## invoke with: mtt -cc sys rep mexglx +## ode2odes support is not yet included. +## ## Revision 1.46 2002/05/07 13:48:43 geraint ## Improved clarity of code generated for -cc and -oct (except ode2odes). ## Octave DEFUN_DLDs now call (rather than replace) their .cc equivalents. ## ## Revision 1.45 2002/05/02 09:30:22 gawthrop @@ -882,73 +887,16 @@ { func=${1:-""} args=${2:-""} cat < extern "C" { - void mexFunction (int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) + void mexFunction (int nlhs, mxArray *plhs[], + int nrhs, const mxArray *prhs[]) { EOF map_mex_inputs ${args} cat < +#include + + +// conversions from Matlab mxArray* to Octave data types + +Matrix +mtt_Matrix (const mxArray *m) +{ + const unsigned long int nrows = mxGetM (m); + const unsigned long int ncols = mxGetN (m); + Matrix o (nrows, ncols); + const double *p = mxGetPr (m); + for (unsigned long int row = 0; row < nrows; row++) + for (unsigned long int col = 0; col < ncols; col++) + o (row, col) = p[row + nrows*col]; + return (o); +} + +ColumnVector +mtt_ColumnVector (const mxArray *m) +{ + const unsigned long int nrows = mxGetM (m); + ColumnVector o (nrows); + const double *p = mxGetPr (m); + for (unsigned long int row = 0; row < nrows; row++) + o (row) = p[row]; + return (o); +} + +const double +mtt_double (const mxArray *m) +{ + const double *p = mxGetPr (m); + return (*p); +} + + +// conversions from Octave data types to Matlab mxArray* + +mxArray * +mtt_mxArray (const Matrix &o) +{ + const unsigned long int nrows = o.rows (); + const unsigned long int ncols = o.columns (); + mxArray *m; + m = mxCreateDoubleMatrix (nrows, ncols, mxREAL); + double *p = mxGetPr (m); + for (unsigned long int row = 0; row < nrows; row++) + for (unsigned long int col = 0; col < ncols; col++) + p [row + nrows*col] = o (row, col); + return (m); +} + +mxArray * +mtt_mxArray (const ColumnVector &o) +{ + const unsigned long int nrows = o.length (); + mxArray *m; + m = mxCreateDoubleMatrix (nrows, 1, mxREAL); + double *p = mxGetPr (m); + for (unsigned long int row = 0; row < nrows; row++) + p [row] = o (row); + return (m); +} ADDED mttroot/mtt/lib/cc/mtt_matlab_octave.hh Index: mttroot/mtt/lib/cc/mtt_matlab_octave.hh ================================================================== --- /dev/null +++ mttroot/mtt/lib/cc/mtt_matlab_octave.hh @@ -0,0 +1,28 @@ + +#ifndef MTT_MATLAB_OCTAVE_HH +#define MTT_MATLAB_OCTAVE_HH + +#include +#include + +// conversions from Matlab mxArray* to Octave data types + +extern Matrix +mtt_Matrix (const mxArray *m); + +extern ColumnVector +mtt_ColumnVector (const mxArray *m); + +extern const double +mtt_double (const mxArray *m); + + +// conversions from Octave data types to Matlab mxArray* + +extern mxArray * +mtt_mxArray (const Matrix &o); + +extern mxArray * +mtt_mxArray (const ColumnVector &o); + +#endif // MTT_MATLAB_OCTAVE_HH