User`s manual

iii
3
Creating Fortran MEX-Files
Fortran MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
The Components of a Fortran MEX-File . . . . . . . . . . . . . . . . . . 3-3
The %val Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
Examples of Fortran MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . 3-9
A First Example — Passing a Scalar . . . . . . . . . . . . . . . . . . . . 3-10
Passing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12
Passing Arrays of Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
Passing Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
Passing Two or More Inputs or Outputs . . . . . . . . . . . . . . . . . . 3-19
Handling Complex Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22
Dynamically Allocating Memory . . . . . . . . . . . . . . . . . . . . . . . . 3-25
Handling Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
Calling Functions from Fortran MEX-Files . . . . . . . . . . . . . . . 3-32
Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
Help Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
Linking Multiple Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
Workspace for MEX-File Functions . . . . . . . . . . . . . . . . . . . . . 3-36
Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37
Debugging Fortran Language MEX-Files . . . . . . . . . . . . . . . 3-38
Debugging on UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-38
Debugging on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-39
4
Calling MATLAB from C and Fortran Programs
Using the MATLAB Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
The Engine Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
GUI-Intensive Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Examples of Calling Engine Functions . . . . . . . . . . . . . . . . . . 4-6
Calling MATLAB From a C Application . . . . . . . . . . . . . . . . . . . 4-6