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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by