Overview
Comment:Moved matlab/octave data type conversion functions to a separate file.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: cdb81663cf6fedc5a44ab1a98ec7c1278306f2050110a1d1386c2d0555bcff28
User & Date: geraint@users.sourceforge.net on 2002-05-08 14:51:04
Other Links: branch diff | manifest | tags
Context
2002-05-08
16:03:32
Added mex support for ode2odes: mtt sys ode2odes mexglx.
This mex stuff seems to require octave2.1-headers.
check-in: 20ae5bf7e0 user: geraint@users.sourceforge.net tags: origin/master, trunk
14:51:04
Moved matlab/octave data type conversion functions to a separate file. check-in: cdb81663cf user: geraint@users.sourceforge.net tags: origin/master, trunk
14:14:55
Tidied up ode2odes code - reduced interweaving of STANDALONE/OCTAVEDLD sections check-in: 80539fd341 user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/mtt from [c87980939a] to [570aa6b93c].

13
14
15
16
17
18
19





20
21
22
23
24
25
26
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$





## 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
## Added -dr foo (reads from dir foo) option
##







>
>
>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## 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
## Added -dr foo (reads from dir foo) option
##
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
	${MKOCTFILE} -DCODEGENTARGET=OCTAVEDLD $define_octave_dev \$<

## .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

## .cc files
.PRECIOUS: %.cc # Don't let mtt delete them
$1_%.cc:  $1_%.m
	mtt_m2cc.sh  $1 \$* cat 

mtt_%.cc: ${MTT_LIB}/cc/mtt_%.cc







|







2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
	${MKOCTFILE} -DCODEGENTARGET=OCTAVEDLD $define_octave_dev \$<

## .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_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 

mtt_%.cc: ${MTT_LIB}/cc/mtt_%.cc

Modified mttroot/mtt/bin/mttrc from [d1cbabffc3] to [7e41f569d0].

11
12
13
14
15
16
17



18
19
20
21
22
23
24


###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## 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.
##
## Revision 1.31  2002/05/02 20:12:45  geraint
## Added -Wl,--rpath to MTT_CXXLIBS. Sets the runtime linker path so that the







>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


###############################################################
## 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.
##
## Revision 1.31  2002/05/02 20:12:45  geraint
## Added -Wl,--rpath to MTT_CXXLIBS. Sets the runtime linker path so that the
238
239
240
241
242
243
244
245
246
247
248
    MATLAB_LIBS="-Wl,--rpath-link,${MATLAB_ROOT}/extern/lib/${MATLAB_ARCH},--rpath-link,${MATLAB_ROOT}/bin/${MATLAB_ARCH} -L${MATLAB_ROOT}/bin/${MATLAB_ARCH} -lmx -lmex -lm"

    # exported variables

    export MTT_CXX="g++"
    export MTT_CXXFLAGS="${DEBUG} ${OPTIM} ${FLAGS}"
    export MTT_CXXLIBS="${LOCTAVE} ${LSYSTEM}"
    export MTT_CXXINCS="-I. ${IOCTAVE}"
    export MTT_LDFLAGS=" "
    export MTT_MATLAB_FLAGS="${MATLAB_FLAGS} ${MATLAB_INCS} ${MATLAB_LIBS}"
fi







|



241
242
243
244
245
246
247
248
249
250
251
    MATLAB_LIBS="-Wl,--rpath-link,${MATLAB_ROOT}/extern/lib/${MATLAB_ARCH},--rpath-link,${MATLAB_ROOT}/bin/${MATLAB_ARCH} -L${MATLAB_ROOT}/bin/${MATLAB_ARCH} -lmx -lmex -lm"

    # exported variables

    export MTT_CXX="g++"
    export MTT_CXXFLAGS="${DEBUG} ${OPTIM} ${FLAGS}"
    export MTT_CXXLIBS="${LOCTAVE} ${LSYSTEM}"
    export MTT_CXXINCS="-I. -I${MTT_LIB}/cc ${IOCTAVE}"
    export MTT_LDFLAGS=" "
    export MTT_MATLAB_FLAGS="${MATLAB_FLAGS} ${MATLAB_INCS} ${MATLAB_LIBS}"
fi

Modified mttroot/mtt/bin/trans/mtt_header from [aeb001e855] to [630b2a9dfd].

8
9
10
11
12
13
14





15
16
17
18
19
20
21
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$





## 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
## _ssim.m now returns t as 4th arg
##







>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## 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
## _ssim.m now returns t as 4th arg
##
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956

write_mex ()
{
    func=${1:-"<insert function name>"}
    args=${2:-""}
    cat <<EOF
#if (CODEGENTARGET == MATLABMEX)
#include "mex.h"

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);
}

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);
}

extern "C"
{
  void mexFunction (int nlhs,       mxArray *plhs[],
		  int nrhs, const mxArray *prhs[])
  {
EOF
  map_mex_inputs ${args}
cat <<EOF
  plhs[0] = mtt_mxArray (${func} (${args}));
  }
}







|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


|
|







885
886
887
888
889
890
891
892
893

























































894
895
896
897
898
899
900
901
902
903
904

write_mex ()
{
    func=${1:-"<insert function name>"}
    args=${2:-""}
    cat <<EOF
#if (CODEGENTARGET == MATLABMEX)
#include <mtt_matlab_octave.hh>


























































extern "C"
{
  void mexFunction (int nlhs, mxArray *plhs[],
		    int nrhs, const mxArray *prhs[])
  {
EOF
  map_mex_inputs ${args}
cat <<EOF
  plhs[0] = mtt_mxArray (${func} (${args}));
  }
}

Added mttroot/mtt/lib/cc/mtt_matlab_octave.cc version [b74de52abf].





































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

#include <octave/oct.h>
#include <mex.h>


// 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 version [7d4f1bcd2c].

























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#ifndef MTT_MATLAB_OCTAVE_HH
#define MTT_MATLAB_OCTAVE_HH

#include <octave/oct.h>
#include <mex.h>

// 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


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]