H2MEX

ABC_set_x(ABC_ptr, 3.4); % Set the data member.

ABC_delete(ABC_ptr); % Discard the structure.

the same thing will work for C structs–the only difference is that they have only data members and no member functions.

  • Only public members are accessible from matlab.
  • Operator overloading and function overloading are not supported.
  • Function pointers are not supported.


Arrays

You can also call functions that take arrays of data, provided that they accept the arrays in a standard format. For example, suppose you want to use the pgplot distribution to make graphs. The following function generates a histogram of data:

void cpgbin(int nbin, const float *x, const float *data, Logical center);

Here x[] are the abscissae values and data[] are the data values. If you add to your .h file a simple statement indicating the dimensions of the matrices, like this:

//%input x(nbin), data(nbin)

then from MATLAB, you can call this function like this:

cpgbin(X, Data, 1)

where X and Data are vectors. The nbin argument is determined from the length of the X and Data vectors automatically (and the wrapper generator makes sure they are of the same length!).

This will also work with multidimensional arrays, provided that the function expects the array to be a single one-dimensional array which is really the concatenation of the columns of the two-dimensional array.(This is normal for Fortran programs.).

The first array dimension varies the fastest, the second the next fastest, etc. (This is column major order, as in Fortran, not row-major order, as in C. Most matlab-like languages use the Fortran convention. Tela is an exception.)

You may only use variable name or a constant for the array dimension. You can also use expressions like 2*nbin or 2*nbin+1. If the expression is sufficiently simple, the wrapper generator will determine the values of any integer values (like nbin in this example) from the dimension of the input arrays, so they do not have to be specified as an argument.


INPUT FILES

Input files are designed to be your ordinary .h files, so your wrapper and your C++ sources are never out of date. In general, the wrapper generator does the obvious thing with each different kind of type. For example, consider the function declaration:

double abcize(float a, int b, char *c, SomeClass *d);

This will pass a single-precision floating point number as argument a. An integer is passed as argument b (probably converted from a double precision value). A null-terminated string is passed as argument c. The argument d must be a pointer value which was returned by another function.

Page 2 of 4 | Previous page | Next page