Differences From Artifact [aeb001e855]:

To Artifact [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}));
  }
}

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