MATLAB - Fortran interface

The C++ API is newer and offers the benefits like better type-safety and automatic memory management (due to use of C++ containers). It is also part of a general trend that more and more software is C++ (as are the developers).

For interfacing to Fortran I was surprised by how much easier it was to write the C MEX function. You just need to follow the steps

  • unpack contents of prhs into corresponding C types
  • prepare any output buffers to pass to Fortran
  • call your Fortran routine

If you avoid doing any other operations in the C MEX function you should remain pretty safe.

3 Likes