本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。

Fortran 源 MEX 文件

使用 MATLAB® API 库编写 Fortran 子例程

MEX 文件允许您通过 MATLAB 调用 Fortran 子例程。要创建 MEX 文件,您需要:

有关示例,请参阅MEX 函数源代码示例表

有关使用 Fortran 代码编写 S 函数的信息,请参阅您的 Simulink® 文档。

MEX 文件并不适用于所有应用程序。MATLAB 是一种高生产率环境,尤其适用于消除像 Fortran 等编译语言中需要花费大量时间的低级编程。一般情况下,请在 MATLAB 中进行编程。除非您的应用程序需要,否则请不要使用 MEX 文件。

主题

Create Fortran Source MEX File

This example shows how to write a MEX file to call a Fortran subroutine, timestwo, in MATLAB using a MATLAB matrix.

Handle Complex Fortran Data

This example shows how to pass complex data to a MEX file using the interleaved complex Fortran Matrix API.

Pass Separate Complex Numbers to Fortran Functions

Write MEX functions in MATLAB R2017b and earlier to call LAPACK or BLAS functions.

User Messages

To print text in the MATLAB Command Window, use the mexPrintf function.

Error Handling

The mexErrMsgIdAndTxt function prints error information and terminates your binary MEX file.

Components of Fortran MEX File

The gateway routine is the entry point to the MEX file.

MATLAB Fortran API Libraries

The Fortran 矩阵 API and the Fortran MEX API describe functions you can use in your gateway and computational routines that interact with MATLAB programs and the data in the MATLAB workspace.

Data Flow in Fortran MEX Files

Suppose your MEX-file myFunction has two input arguments and one output argument.

Memory Management

When a MEX function returns control to MATLAB, it returns the results of its computations in the output arguments—the mxArrays contained in the left-side arguments plhs[].

Handling Large mxArrays

Binary MEX-files built on 64-bit platforms can handle 64-bit mxArrays.

Upgrade Fortran MEX Files to use 64-bit API

Upgrade Fortran MEX files to use 64-bit API.