- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have the problem calling Matlab function from the main program written in Fortran. Thereis no problem in compiling and building the program, but during execution, the following error was shown:
forrt1: severe(157): Program Exception -access violation
Image PC Routine Line Source
Stack trace terminated abnormally.
I am using Compaq Visual Fortran 6 and Matlab R13 for my programming. I have tried all the programs provided from Matlab extern example folder they are work perfectly. However, when I wrote my own Matlab function called by the main fortran program, error occurred as mentioned above.
Can anyone help me to solve my problem. Thank you!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A wild guess of mine is that you tried to pass a literal constant or a PARAMETER to a routine argument which is modifiable by Matlab. But there might be a thousands other causes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have solved that problem as mentioned earlier but encounter another problem. That is I have written the following simple fortran code for testing but the result is not what I expected:
program main
integer engOpen, engGetVariable, mxCreateDoubleMatrix
integer mxGetPr
integer A, B, teststatus, Z
integer engPutVariable, engEvalString, engClose
A = mxCreateDoubleMatrix(1, 1, 0)
call mxCopyReal8ToPtr(2, mxGetPr(A), 1)
teststatus = engPutVariable(ep, 'A', A)
if (teststatus .ne. 0) then
write(6,*) 'engPutVariable A failed'
stop
endif
if (engEvalString(ep, 'B = A*5;') .ne. 0) then
write(6,*) 'engEvalString failed'
stop
endif
B = engGetVariable(ep, 'B')
call mxCopyPtrToReal8(mxGetPr(B), Z, 1)
write (*,*) "Z=", Z
call mxDestroyArray(A)
call mxDestroyArray(B)
status = engClose(ep)
if (status .ne. 0) then
write(6,*) 'engClose failed'
stop
endif
stop
end
The final result is Z which should be equal to 10 but the result is 0. I am not sure where go wrong with the program. Could any one help me?
Furthermore, if I would like to write a maltab function to be call by my fortran main program, what command should I used. I have came accross the command "mexCallMATLAB", but it seem to be used when the fortran is a subrountine of a main Matlab function, which the fortran subrountine named as "mexFunction" will then calla matlab function. However, my main function is in Fortran, not inmatlab. Hence, anyone know what command to use and which directory should the written matlab function saved so that when calling of the funciton will not result in linking error?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now, I am able to obtain the multiplication of Z*5=10 when calling Matlab engine from Fortran. However, I couldn't get the desire result when I perform the following:
B=sin(A), B=cos(A), B=A*A, B=A.^2, B=2+A ... and so on as long as the expression is not simply multiplication of integer value. Anyone know the why is this so?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It my own fault. Never properly declare the variable. Now all the expression can be executed by Matlab function. However, still on the way to determine how to call user defined Matlab function from Fortran.
I thinking of upgrading my fortran compilier to Intel Fortran Compilier V 10.0. Does anyone know whether v10.0 can edit/compilier/run the program without MVS 2005? That is, is it operate independently, or does it need to depend of the MSV2005 to form all tasks?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What form is the MatLab function? Is it in C or C++ code? Is it compiled into a linkableobject module? Is it in a DLL? Is it in a static Library? What calling convention does Matlab use?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page