For Programmers: Free Programming Magazines  


Home > Archive > Fortran > January 2006 > Calling Matlab from G95 code









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Calling Matlab from G95 code
Mohammad

2006-01-12, 7:58 am

Calling Matlab from G95 code
Matlab lets third party programs call its routines through Matlab
External Interface.
I try to use Matlab engine in a G95 (Fortran 95 compiler) code. I use
G95-MinGW32 under Windows XP SP2.
To call Matlab engine from a G95 code, the basic three Matlab dlls
(libeng.dll, libmx.dll, libut.dll) should be linked to the G95 code. It
seems there is a problem with decoration and case sensitivity. Matlab
routines reside in dll have a special char cases like "engOpen" or
"engClose". This while G95 can be instructed only to generate the codes
with lowercase or uppercase. Linking a G95 code with Matlab dlls
generates the following error:

feng.f90:(.text+0x18): undefined reference to 'engopen'

To clear the subject I introduce here a step by step example:

1. Fortran program to Call Matlab
--------------------------------
program feng
integer engOpen
integer ep

ep = engOpen('matlab ')
if (ep .eq. 0) then
write(6,*) 'Can''t start MATLAB engine'
stop
else
write(6,*) 'MATLAB engine started'
endif
end program main

2. All matlab dlls are in the Path, now we compile the above code
under Windows XP using G95 - MinGW compiler as follows:
------------------------------------------

g95 -c -mrtd -fno-underscoring feng.f90 -o feng.o
g95 -o %1.exe -shared -L. libeng.dll %1.o

::::OUTPUTS
feng.f90:(.text+0x18): undefined reference to 'engopen'


How we can resolve this problem. Your kind help is appreciated


Aria


P.s:
- I know about GNUmex and some other methods, but they are very
complicated.
- I generated a lib interface as "lib /def:libeng.def" using the
Matlab provided "def" files but the problem was not resolved.

Helge Avlesen

2006-01-12, 7:58 am

"Mohammad" <mohammad.rahmani@gmail.com> writes:

> Calling Matlab from G95 code


there is something about this on the following page that may help;

http://g95.sourceforge.net/howto.html#matlabwin

Helge
Mohammad

2006-01-13, 7:01 pm

Thanks Helge.
There are two method on that page.
ne of them needs GNUmex to do that. The other method proposed by Aaron
Schmidt seems promising but I failed to implement it on a windows
machine.

Any comment?

Mohammad

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com