File: README

package info (click to toggle)
matwrap 0.57-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 464 kB
  • ctags: 238
  • sloc: perl: 2,774; cpp: 622; makefile: 170; sh: 32
file content (88 lines) | stat: -rw-r--r-- 3,177 bytes parent folder | download | duplicates (5)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Have you ever wanted to call subroutines from a C library from a
scripting language like MATLAB or octave or tela?  Have you ever wanted
to write your own simulation in C and have its functions be directly
callable from MATLAB, instead of going through output files?  It is very
tedious and error-prone to write the wrapper functions which convert
from MATLAB's types to the float or double or int types that your
functions actually want.

matwrap is a perl script that generates the wrapper functions for you
automatically from your .h files.  Suppose, for example, that you've
defined a C++ class like this:

class Simulator {
public:
  Simulator(int a, float b);
  int do_something();
  ~Simulator();
  double param;

private:
	// ...
};

matwrap defines the MATLAB/octave/whatever functions

	sim_ptr = Simulator_new(a, b)
	result = Simulator_do_something(sim_ptr)
	Simulator_delete(sim_ptr)
	param_value = Simulator_get_param(sim_ptr)
	Simulator_set_param(sim_ptr, param_value)

which call the member functions or set the data member.  All you have to
do is to provide the C++ definition of your class to the program.  You
don't have to learn anything about MATLAB or octave internals.

matwrap also automatically vectorizes your functions.
Suppose, for example, you have a function like this:

  double my_special_func(double arg1, double arg2, double arg3);

You can supply a vector or matrix argument for either arg1 or arg2, like
this in MATLAB:

>> A = [1, 2; 3, 4]; B = [5, 6; 7, 8]; C = 9;
>> res = my_special_func(A, B, C);

The C function my_special_func is called 4 times, once for each element
of A and B, and the result is returned as a matrix.  This happens
automatically, without any special declarations in your code at all.

You can also supply a vector argument, like this:

  void plot_vector(int n_elements, float *vec); //%input vec[n_elements]

In this case, by adding the comment "//%input...", you tell
matwrap that the calling sequence from MATLAB should be

  plot_vector(xyz)

and that n_elements should be computed from the number of rows of the
vector xyz.

I have used matwrap to wrap my C++ simulations, which have
dozens of members and member functions, as well as the entire pgplot
plotting library.

matwrap currently supports the languages Matlab (version
5.0), octave, and tela.  Other languages can be added with a little bit
of work.

The idea for matwrap came from Dave Beazley's SWIG, a wrapper generator
for non-matrix languages like perl, python, and TCL.  Wrapper generation
for matrix languages requires a number of additional features not
present in SWIG, so this wrapper generator was written.  Hopefully the
features found in matwrap will eventually be incorporated into SWIG, but
for the moment it is entirely separate.

matwrap requires a relatively recent version of perl (it was tested with
5.004 and 5.005) and a C++ compiler such as gcc (even if you are
wrapping C code).  It has only been developed on unix; the wrapper
generation should work fine on other platforms but some modifications

You can pick up the latest distribution from
http://LNC.usc.edu/~holt/matwrap/.

Gary Holt (holt@klab.caltech.edu)
13 Dec 1999