The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Segmentation violation in fortran source MEX file
Replies: 1   Last Post: Mar 26, 2013 10:21 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Segmentation violation in fortran source MEX file
Posted: Mar 26, 2013 10:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Sudarshan " <> wrote in message
>> Are you running 32-bit or 64-bit?
>> What version of MATLAB are you using?
>> I see potential problems with your use of "integer" as a pointer (will
>> need to be integer*8 on 64-bit systems ... i.e. should use mwPointer
>> instead).
>> Also the mxCreateFull function is deprecated, and has been for quite some
>> time, so this must be very old code.
>> Is it your intent to simply call the pr_equil function with MATLAB inputs
>> & outputs? If so, this can probably be done much simpler.
>> James Tursa

> Hi James,
> Thanks a lot for such a quick turnaround :) I am using Windows 7 32 bit,
> MATLAB R2011b 32 bit, Visual Studio 2010 Professional and Intel Visual
> Fortran Composer XE 2011. Yes the code is pretty old, written in 2001 and
> modified in 2006.
> I have replaced mxCreateFull function with mxCreateDoubleMatrix. Also i
> used mwPointer wherever appropriate. However, MATLAB still crashes.
> I guess i should learn about MEX files properly to get out of this.
> Anyway, if you think minor corrections could make the code work, would you
> please let me know?


It might be a "minor correction" but that's a good chunk of code to dig
through to locate it. This reminds me of an old joke:

I recommend that you follow the suggestions in the Debugging MEX-files
section of the documentation:

If you don't have access to this online documentation, search the
documentation in your installation of MATLAB for "debug Fortran MEX" and it
should be one of the first few hits.

Alternately you could always go for the quick & dirty debugging method,
which involves doing divide and conquer in your file with mexPrintf
statements to isolate the line that's causing the crash. Write a mexPrintf
statement roughly in the middle of your file, run. If it crashes before the
message is printed, the line on which the crash occurs is in the first half
of your code; repeat by putting a mexPrintf in the middle of that first
half. Otherwise put a mexPrintf in the middle of the second half of your
code. Repeat this process until you know where the crash happens. Then you
get to work your way backwards and figure out why the crash occurs on that

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.