Reputation: 41
I've a long (about 1000 lines) and complicated Matlab function (say mat_test.m), which works perfectly fine. On the other hand, I've a complicated set of Fortran codes. I am trying to insert my Matlab function in one of the Fortran code. I don't have much competency in Fortran, so I don't want to rewrite the whole Matlab function in Fortran. Is there a way to define variables in Fortran and remotely call this Matlab function and use the output generated by it?
Upvotes: 1
Views: 196
Reputation: 111
you can execute, or better launch a program in Fortran using
call SYSTEM("script.m")
now, you edit your Matlab script in a such way to save data in a .txt file; then you can code in Fortran to read that file;
my idea looks like this:
! ...do something in Fortran
call SYSTEM("modified_script.m")
! read data.txt
! continue your works with data from Matlab...
PS: you do not need to include any library
Upvotes: 0
Reputation: 4230
It is indeed possible to call a matlab function from within fortran code. Matlab includes a verbose example of how to properly implement this within the matlabroot/extern/examples/eng_mat folder, in the fengdemo.F
file.
Here is the file showing how it's done.
Here is the example output of this file, from the mathworks website.
Upvotes: 2