File MEX con sorgente in Fortran
Un file MEX consente di chiamare una subroutine in Fortran da MATLAB. Per creare un file MEX, sono necessari:
La capacità di scrivere il codice sorgente in Fortran. È possibile creare questi file con l’Editor di MATLAB.
Un compilatore supportato da MATLAB. Per un elenco aggiornato dei compilatori supportati, vedere Supported and Compatible Compilers (Compilatori supportati e compatibili).
Il API Matrix Fortran e le funzioni API MEX Fortran.
Lo script di costruzione
mex
. Per maggiori informazioni, vedere File MEX in Fortran eseguibili.
Per degli esempi, vedere Tables of MEX Function Source Code Examples.
Per informazioni sulla scrittura di funzioni S utilizzando il codice in Fortran, vedere la documentazione di Simulink®.
I file MEX non sono adatti a tutte le applicazioni. MATLAB è un ambiente ad alta produttività la cui specialità è eliminare la programmazione di basso livello nei linguaggi compilati, che richiede molto tempo, come nel caso di Fortran. In generale, eseguire la programmazione in MATLAB. Non utilizzare i file MEX a meno che l'applicazione non lo richieda.
Argomenti
- 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 API Matrix Fortran and the API MEX Fortran 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.