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

Fortran Mex Problem...

infinity77
Beginner
212 Views
Hello NG,

I've build a simple fortran mex function that creates a modal
dialog. This dialog just asks for an input (a number, a string, whatever) and then the user has again the control when he clicks on OK/Cancel button. I managed to compile it (in Matlab, with MEX)without errors/warnings with the command:

mex -v miomes.f90

(At the end of the message I will put my f90 mex subroutine).

Everything goes fine (I have Matlab 6.0 + Digital Visual Fortran 6.0, Win2000). But when I tried to run it, I get a segmentation violation.

I debugged the mex dll, and I found that Matlab crashes when I call the function:

results = DLGMODAL (dlg)

This is probably because I declare in the subroutine header that I will use dflogm, as

USE DFLOGM

Or because there is an INCLUDE statement, as:

INCLUDE 'RESOURCE.FD'

Does anyone know if I have to modify the mexopts.bat file in order to use an external library (as DFLOGM) or to have an include file? Am I missing anything else? I'm not really an expert and I don't know how to proceed...
I will attach also the mexopts.bat file (options for the fortran compiler)

Thanks for every suggestion.

Andrea.

! FORTRAN Function

subroutine mexfunction(nlhs, plhs, nrhs, prhs)

USE DFLOGM

IMPLICIT NONE
INCLUDE 'RESOURCE.FD'

TYPE (dialog) dlg
LOGICAL returno, retlog, value
INTEGER results
CHARACTER(200) text, retval, title, firstname

integer plhs(*), prhs(*)
integer nlhs, nrhs
integer status
integer mxCreateString, mxGetString

if(nrhs .ne. 2) then
call mexErrMsgTxt('Two inputs required.')
elseif(nlhs .ne. 1) then
call mexErrMsgTxt('One output required.')
endif

status = mxGetString(prhs(1), title, 200)
status = mxGetString(prhs(2), firstname, 200)

returno = DLGINIT( IDD_DIALOG1, dlg )

retlog = DLGSET (dlg, IDC_EDIT1, '')

!!! HERE IT CRASHES !!!!!
results = DLGMODAL (dlg)

value = DLGGET (dlg, IDC_EDIT1, text)

if (results.ne.1) then
retval = 'No'
else
if (.not.value) then
retval = 'No'
else
retval = text
endif
endif

CALL DlgUninit( dlg )

plhs(1) = mxCreateString(retval)

return

end subroutine mexfunction
!! FORTRAN MEXOPTS.BAT
@echo off
rem DF60OPTS.BAT
rem
rem Compile and link options used for building MEX-files
rem using the DEC Visual Fortran compiler version 6.0
rem
rem $Revision: 1.5 $ $Date: 2000/04/04 17:07:32 $
rem
rem ********************************************************************
rem General parameters
rem ********************************************************************
set MATLAB=%MATLAB%
set DF_ROOT=C:Program FilesMicrosoft Visual Studio
set VCDir=%DF_ROOT%VC98
set MSDevDir=%DF_ROOT%Commonmsdev98
set DFDir=%DF_ROOT%DF98
set PATH=%MSDevDir%in;%DFDir%BIN;%VCDir%BIN;%PATH%
set INCLUDE=%DFDir%INCLUDE;%INCLUDE%
set LIB=%DFDir%LIB;%VCDir%LIB;%LIB%
rem ********************************************************************
rem Compiler parameters
rem ********************************************************************
set COMPILER=fl32
set COMPFLAGS=-c -G5 -no logo -DMATLAB_MEX_FILE
set OPTIMFLAGS=-Ox -DNDEBUG
set DEBUGFLAGS=-Zi
set NAME_OBJECT=/Fo
rem ********************************************************************
rem Linker parameters
rem ********************************************************************
set LIBLOC=%MATLAB%externlibwin32digitaldf60
set LIB=%LIB%;C:Program FilesMicrosoft Visual StudioDF98LIB
set LINKER=link
set LINKFLAGS=/DLL /EXPORT:_MEXFUNCTION@16 /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /implib:%LIB_NAME%.lib /NOLOGO
set LINKFLAGS=DFLOGM.LIB DFWIN.LIB %LINKFLAGS%
set LINKOPTIMFLAGS=
set LINKDEBUGFLAGS=/debug
set LINK_FILE=DFLOGM.LIB DFWIN.LIB
set LINK_LIB=DFLOGM.LIB DFWIN.LIB
set NAME_OUTPUT="/out:%OUTDIR%%MEX_NAME%.dll"
set RSP_FILE_INDICATOR=@
rem ********************************************************************
rem Resource compiler parameters
rem ********************************************************************
set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"
set RC_LINKER=
0 Kudos
0 Replies
Reply