回 帖 发 新 帖 刷新版面

主题:急:MATLAB调用fortran的mex文件时生成的DLL文件时的遇到的几个问题!

我这里在用MATLAB调用fortran时存在几个问题无法解决,请高手帮帮忙!谢谢!
    我首先在fortran下生成一个mexCaclT90.f文件(fortran文件),然后使用MATLAB编译此文件生成mexCaclT90.dll,然后在MATLAB下调用此dll文件进行计算,但就算的过程中存在这样的几个问题,不是很理解,请大家帮忙看看。

我在MATLAB下输入如下语句编译fortran文件:
>> mex mexCaclT90.f
紧接着输入如下语句调用dll文件:
>> T90=mexCaclT90(70,10,10,5)
生成的结果如下:
T90 =
   47.5000

     问题在于:当我再一次调用该dll时,即输入>> T90=mexCaclT90(70,10,10,5)语句或>> T90=mexCaclT90(70,8,8,5)语句时为什么输出的结果就变为:
T90 =
     0

     但是当我把MATLAB关闭后再一次重新启动MATLAB,此时再输入>> T90=mexCaclT90(70,10,10,5)语句时又能生成正确的结果,但就是每次只能生成一次,不能重复进行2次计算,只要重复调用此dll,第二次生成的结果都为0,请问这是什么原因造成的?始终让我困惑!
     期待各位老师的帮忙,谢谢!

回复列表 (共3个回复)

沙发


楼主,你的问题解决了吗?
我最近也在做matlab和fortran的混合编程,可是我的mex ***.F总是不能成功,我觉得可能是两个编译器的问题,我想问问你当时是怎么设置的,以下是我在matlab中输入mex命令的结果
>> mex -setup
Please choose your compiler for building external interface (MEX) files: 
 
Would you like mex to locate installed compilers [y]/n? y
 
Select a compiler: 
[1] Digital Visual Fortran version 6.0 in C:\Program Files\Microsoft Visual Studio 
[2] Lcc C version 2.4.1 in E:\PROGRAM FILES\MATLAB71\sys\lcc 
[3] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio 
[4] Open WATCOM C/C++ version 1.3 in e:\watcom-1.3 
 
[0] None 
 
Compiler: 1
 
Please verify your choices: 
 
Compiler: Digital Visual Fortran 6.0 
Location: C:\Program Files\Microsoft Visual Studio 
 
Are these correct?([y]/n): y
 
Try to update options file: C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R14SP3\mexopts.bat 
From template:              E:\PROGRAM FILES\MATLAB71\BIN\win32\mexopts\df60opts.bat 
 
Done . . . 
 
Warning! The MathWorks has determined that Digital Fortran 6.0 has several 
serious bugs, and highly recommends that you upgrade to the latest version 
of Compaq Fortran. 
 
*************************************************************************** 
  Warning: The file extension of 32-bit Windows MEX-files was changed 
           from ".dll" to ".mexw32" in MATLAB 7.1 (R14SP3). The generated  
           MEX-file will not be found by MATLAB versions prior to 7.1. 
           Use the -output option with the ".dll" file extension to 
           generate a MEX-file that can be called in previous versions. 
           For more information see:  
           MATLAB 7.1 Release Notes, New File Extension for MEX-Files on Windows 
*************************************************************************** 
 
>> mex -v yprimef.F
 This is mex, Copyright 1984-2005 The MathWorks, Inc. 
 
-> Default options filename found in C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R14SP3 
---------------------------------------------------------------- 
->    Options file           = C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R14SP3\mexopts.bat 
      MATLAB                 = E:\Program Files\MATLAB71 
->    COMPILER               = fl32 
->    Compiler flags: 
         COMPFLAGS           = /fpp:"/m /SE:\Program Files\MATLAB71/extern/include" -c -G5 -nologo -DMATLAB_MEX_FILE 
         OPTIMFLAGS          = /MD -Ox -DNDEBUG 
         DEBUGFLAGS          = /MDd -Zi 
         arguments           =  
         Name switch         = /Fo 
->    Pre-linking commands   =  
->    LINKER                 = link 
->    Link directives: 
         LINKFLAGS           = /DLL /EXPORT:_MEXFUNCTION@16 /LIBPATH:"E:\Program Files\MATLAB71\extern\lib\win32\digital\df60" libmx.lib libmex.lib libmat.lib /implib:_lib6658.lib /NOLOGO 
     LINKDEBUGFLAGS      = /debug 
         LINKFLAGSPOST       =  
         Name directive      = "/out:yprimef.mexw32" 
         File link directive =  
         Lib. link directive =  
         Rsp file indicator  = @ 
->    Resource Compiler      = rc /fo "mexversion.res" 
->    Resource Linker        =  
---------------------------------------------------------------- 
 
 
--> "fl32  /fpp:"/m /SE:\Program Files\MATLAB71/extern/include" -c -G5 -nologo -DMATLAB_MEX_FILE /FoC:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\yprimef.obj /MD -Ox -DNDEBUG yprimef.F" 
 
 
  E:\PROGRAM FILES\MATLAB71\BIN\MEX.PL: Error: Compile of 'yprimef.F' failed. 
 
??? Error using ==> mex
Unable to complete successfully

板凳


楼主:
请问你问题已经解决了吧。我最近也在做这个,用intel fortran编译器编写DLL文件时,总是出现cannot debug because a debug target has not been specified ,想必楼主已经解决了这方面的问题,我上网找了很多材料,都不行,望楼主帮帮我。多谢了。

3 楼


你好,不知道你的问题解决了没有,我现在也做MATLAB与fortran的混合编程,用的是CVF6.5和MATLAB7.0,在windows Xp系统下,总是不成功,希望得到楼主的指点!

我来回复

您尚未登录,请登录后再回复。点此登录或注册