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

invoking matlab from FORTRAN code

prashantsondkar
Beginner
918 Views
I want to call MATLAB from my FORTRAN code. MATLAB provides option of MEX- filename
But for this I need to make sure that MATLAB support the FORTRAN compiler. When I run MEX -setup in MATLAB it shows me INTEL compiler

"[5] Intel Visual Fortran 10.1 (with Microsoft Visual C++ 2005 SP1 linker"

but when I select this it gives me error
"Error: Microsoft Visual Studio 2005 was not found by mex -setup.
The Microsoft Visual Studio 2005 linker is required
to build Intel Fortran MEX-files. Please make sure that
Microsoft Visual Studio 2005 is installed properly. "
0 Kudos
5 Replies
mecej4
Honored Contributor III
918 Views
Typically, one uses Matlab's mex Perl scripts to build a DLL from Fortran or C sources, to called from Matlab, which is the opposite of what you stated.

The failure to complete the MEX setup is probably caused by Matlab being run from the Windows Explorer without the proper environmental variables (PATH, LIB, INCLUDE) being set up. In particular, Matlab was able to run the compiler but not the linker.

Two possible solutions:

1. Make sure that the environment contains the parts pertaining to the IFort directories.

2. First open an IFort command window, run Matlab from the command line and try the MEX setup again.

0 Kudos
prashantsondkar
Beginner
918 Views
I am getting same error even after using second option

I do not understand option 1

Also do you suggest some better and easier way to use some fucntions of MATLAB like "polyeig" in FORTRAN code,

Is it possible to write function in matlab and share libraries between fortran and matlab and use that function

0 Kudos
mecej4
Honored Contributor III
918 Views
I am getting same error even after using second option

Lets' run a test. From the IFort command window, compile a complete Fortran program -- even a 'Hello World' program will do. If you do not succeed in building an EXE file, you need to take care of the Fortran installation first before trying "mex -setup".

I do not understand option 1

Many software packages use so-called environmental variables to modify/control their operation, in Windows and in Linux/Unix. Some variables are set for all users, some for the current user only, and others are set using a batch file or other means when a Start Menu item is launched.

Also do you suggest some better and easier way to use some fucntions of MATLAB like "polyeig" in FORTRAN code,

Fortran is a compiled language, as is C. Matlab is an interpreted language. Whether you can make Matlab and Fortran/C interoperate depends on the specific versions of Matlab and the compilers you have, and the depth of your knowledge. If you depend on Matlab's "mex -setup", your choices are reduced further.

In my opinion, asking for an easy way to do all this, before doing adequate preparatory reading of documentation, amounts to wishful thinking.

Is it possible to write function in matlab and share libraries between fortran and matlab and use that function

Share what libraries? Fortran source libraries? Matlab m-file libraries? DLLs built from Fortran or C? And what do you mean by 'share' ?

All these things may well be possible, but how much effort are you willing to devote to that end? Or would you be better off using pure Fortran for some things, and using Matlab exclusively for other tasks?
0 Kudos
prashantsondkar
Beginner
918 Views
I do not think there is problem with my fortran compiler as I ran many program so far though not by using compiler alone but using integrated enviorment of visual studio 2005.

When it comes to sharing the libraries
there is command mcc in matlab where you can create stand alone exe of .m code at a same tilme it creats the dynamic link library file of the the executable MEX-file but for C

I am not sure if I can use same dll for FORTRAN as well


Well my goal is to use some functions in matlab directly in fortran without me developing those like polyeig.
0 Kudos
psantos
Beginner
918 Views
Hello prashantsondkar. Perhaps you should consider using alternatives libraries to compute eigenvalues, such has the Intel Math Kernel Library. Using this package will certainly increase the performance of your program and you will certainly avoid a couple of headaches when trying to mix Fortran and Matlab. Take a look at the MKL documentation and see the function(s) that most fit your needs. I also have to say that when comes to performance Matlab is a bit weak. However, I don't know if you are concerned about performance...

Pedro
0 Kudos
Reply