Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Using Intel Fortran to call Matlab

a_r_lamb
Beginner
344 Views
Dear All,
I am trying to run fortran codethat contains some of the eng * commands(e.g. engOpen, engClose)to open the Matlab engine but it just does not seem to work. I am not sure how to set the environment to call the Matlab functionsand would appreciate any assistance that can be offered. I am running the Intel Fortran compiler from the Microsoft Visual Studio 2003.net environment.
Many thanks,
Tony
0 Kudos
4 Replies
ferrisma
Beginner
344 Views
Hi Tony,

I've had problems starting the Matlab engine directly from Fortran, so I had to write a C wrapper to do the job. I'm using CVF 6.6 with Matlab 6.5.1. I've attached some code that may be of some help to you. Make sure you link with the following Matlab libraries: libeng.lib, libmat.lib, and libmx.lib.

Hope this helps,

Mike
0 Kudos
larsm
Beginner
344 Views
Hello Tony!

Heres the way that I do it (without any C code). This is also in CVF 6.6, Im afraid but...

I write my Fortran code and compile it (not link) declaring the MATLAB engOpen, engClose e.t.c. as INTEGER, EXTERNAL.

Then I open MATLAB and cd myself (not necessary, but practical) to where my object code is, in this case h:TM253A (see below).

I then issue a link command in MATLAB. It executes link.m, which can look like this

mex -f h:TM253Adf60engmatopts.bat TM253A.obj ...
c:mat_dvfsmat_dvfs.lib ...
c:mat_matlabsmat_matlab.lib ...
h:f90libf2kclif2kcli.lib
! Editbin TM253A.EXE /Stack:500000000

In this case, for example, TM253A.obj and mat_matlab.lib both contain (pure Fortran) MATLAB stuff.

I am not sure that I need the df60engmatopts.bat file anymore but its a good place to put your linker options, see line:

LINKFLAGS=/LIBPATH:"%LIBLOC%" libmx.lib libmat.lib libeng.lib /nodefaultlib:"libc.lib"

for example, where the linker ignores libc.lib.

I attach the df60engmatopts.bat file.

Lars
0 Kudos
larsm
Beginner
344 Views
Trying to attach it as a ZIP file to see if it works.

Lars
0 Kudos
g_f_thomas
Beginner
344 Views
I've attached an IVF 8 .vfproj (.txt) that runs fengdemo.f from MATLAB R12.

Ciao,
Gerry T.
0 Kudos
Reply