User`s manual

2 Creating C Language MEX-Files
2-42
B = mxGetPr(prhs[1]);
m = mxGetM(prhs[0]);
p = mxGetN(prhs[0]);
n = mxGetN(prhs[1]);
if(p != mxGetM( prhs[1])) {
mexErrMsgTxt("Inner dimensions of matrix multiply do not
match");
}
plhs[0] = mxCreateDoubleMatrix( m, n, mxREAL );
C = mxGetPr( plhs[0] );
/* Pass all arguments to Fortran by reference */
dgemm (chn, chn, &m, &n, &p, &one, A, &m, B, &p, &zero, C, &m);
}
Handling Complex Numbers
MATLAB stores complex numbers differently than Fortran. MATLAB stores
the real and imaginary parts of a complex number in separate, equal length
vectors,
pr and pi. Fortran stores the same number in one location with the
real and imaginary parts interleaved.
As a result, complex variables exchanged between MATLAB and the Fortran
functions in LAPACK and BLAS are incompatible. MATLAB provides
conversion routines that change the storage format of complex numbers to
address this incompatibility.
Input Arguments. For all complex variables passed as input arguments to a
Fortran function, you need to convert the storage of the MATLAB variable to
be compatible with the Fortran function. Use the
mat2fort function for this.
See the example that follows.
Output Arguments. For all complex variables passed as output arguments to a
Fortran function, you need to do the following:
1 When allocating storage for the complex variable, allocate a real variable
with twice as much space as you would for a MATLAB variable of the same
size. You need to do this because the returned variable uses the Fortran