Linking Fortran to Matlab-generated MEX files

9 ビュー (過去 30 日間)
Marat Kulakhmetov
Marat Kulakhmetov 2014 年 5 月 1 日
回答済み: Ryan Livingston 2014 年 5 月 12 日
Hey!
I have written a trajectory code in Matlab and sped it up by compiling it into C using the codegen command. I run this code from matlab as a Trajectory_Mex function and got a 100x speed up compared to the original Matlab script, which is great given that even with the speed up my calculations take a few hours on a cluster.
The trajectory calculations need potential functions, which were provided to me in a Fortran format. After going through Matlab documentation I learned that I could also make Fortran-mex files, that work from the main Matlab workspace but when I try to compile a Matlab script that uses the Fortran-mex file I get the " ??? Only MATLAB files are supported for code generation. Unsupported file extension 'mexa64' for '/PotentialTests/O3PES/timestwo.mexa64'" error.
Is it possible to use a Fortran-mex within a codegen-compiled script? Do I have to rewrite the Fortran files to use codegen? What is the best way for me to implement my Fortran code within compiled scripts?
Thank you very much! MK.

採用された回答

Ryan Livingston
Ryan Livingston 2014 年 5 月 12 日
If your goal is to generate a MEX function, then I would recommend just declaring your Fortran MEX function as an extrinsic function:
function y = extrinsicTimesTwo(x)
coder.extrinsic('timestwo');
y = 0;
y = timestwo(x);
>> codegen extrinsicTimesTwo -args 1
This will allow the call to the Fortran MEX function to occur similar to how you call it in MATLAB.
See:
for the doc.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by