MEX-Quelldateien für Fortran
Über eine MEX-Datei können Sie eine Fortran-Subroutine aus MATLAB heraus aufrufen. Zur Erstellung einer MEX-Datei benötigen Sie:
Die Fähigkeit zum Schreiben von Fortran-Quellcode. Sie können diese Dateien mit dem MATLAB-Editor erstellen.
Einen von MATLAB unterstützten Compiler. Eine aktuelle Liste der unterstützten Compiler finden Sie unter Unterstützte und kompatible Compiler.
Die Funktionen Fortran Matrix API und Fortran MEX API.
Das Build-Script
mex
. Weitere Informationen finden Sie unter Ausführbare Fortran-MEX-Dateien.
Beispiele finden Sie unter Tables of MEX Function Source Code Examples.
Informationen zum Verfassen von S-Funktionen mit Fortran-Code finden Sie in Ihrer Dokumentation zu Simulink®.
MEX-Dateien eignen sich nicht für alle Anwendungsbereiche. MATLAB ist eine Hochproduktivitätsumgebung, die insbesondere zeitraubende Low-Level-Programmierarbeiten in kompilierten Sprachen wie Fortran überflüssig macht. Im Allgemeinen findet die Programmierung in MATLAB statt. Verwenden Sie MEX-Dateien nur, wenn dies für die Anwendung erforderlich ist.
Themen
- 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 Matrix 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 that your MEX file
myFunction
has two input arguments and one output argument. - Handling Large mxArrays
Binary MEX files built on 64-bit platforms can handle 64-bit
mxArray
s. - Upgrade Fortran MEX Files to use 64-bit API
Upgrade Fortran MEX files to use 64-bit API.