主题:[讨论]fortran 调用matlab的引擎函数,#include 出错
ailsa3484
[专家分:0] 发布于 2009-10-25 17:52:00
我运行 matlab 帮助中给出的例子fengdemo.f,出现错误
我用的是matlab R2007b 和CVF6.6 windows 2000
把文件名改为fengdemo.f90,并且把文件中的C 改为!
并且按照如下编译、连接设置:
#1.配置mex 在matlab下运行命令mex –setup,然后按提示选择CVF编译器
#2.配置编译环境:在CVF下编译
1.新建一个项目
2.在tools->directory 里设置 include 和 lib目录 包括以下目录
include ->D:\Program Files\Microsoft Visual Studio\DF98\Include
include->D:\Program Files\Microsoft Visual Studio\DF98\IMSL\Include
include->E:\MATLAB6p5\EXTERN\INCLUDE
lib->E:\MATLAB6p5\EXTERN\LIB\WIN32
lib->E:\MATLAB6p5\EXTERN\LIB\WIN32\DIGITAL\DF60
lib->D:\Program Files\Microsoft Visual Studio\DF98\IMSL\Lib
lib->D:\Program Files\Microsoft Visual Studio\DF98\Lib
3. 在project->setting->link->Object/library modules里添加
libmx.lib libmat.lib libeng.lib
问题 1 但是当设置lib时,有个matlab根目录下的文件DF60找不到
问题 2 文件当中的带有#if ,#include,#define......都不认并且编译时提醒
f90: Warning: Bad # preprocessor line
问题在哪??先感谢高手指点
最后更新于:2009-10-25 18:05:00
回复列表 (共6个回复)
沙发
trimtrim [专家分:1640] 发布于 2009-10-25 18:40:00
打开编译器fpp支持。
ivf 在preprocessor 下,cvf 不知道。
板凳
ailsa3484 [专家分:0] 发布于 2009-10-26 12:29:00
非常感谢,在project/setting/fortran tab/中有个Use FPP 打上勾就可以了
但是还存在问题,请高手帮忙,如下:
--------------------Configuration: fengdemo - Win32 Debug--------------------
Compiling Fortran...
fengdemo.i90
D:\Fortran Project\test pulseforce\test fengdemo\fengdemo.f90(23) : Error: Syntax error, found IDENTIFIER 'ENGOPEN' when expecting one of: ( : % . = =>
mwpointer engOpen, engGetVariable, mxCreateDoubleMatrix
----------------^
D:\Fortran Project\test pulseforce\test fengdemo\fengdemo.f90(24) : Error: Syntax error, found IDENTIFIER 'MXGETPR' when expecting one of: ( : % . = =>
mwpointer mxGetPr
----------------^
D:\Fortran Project\test pulseforce\test fengdemo\fengdemo.f90(25) : Error: Syntax error, found IDENTIFIER 'EP' when expecting one of: ( : % . = =>
mwpointer ep, T, D
----------------^
。。。。。。。。。。类似的----------------------------^
Error executing df.exe.
Creating browse info file...
fengdemo.exe - 14 error(s), 0 warning(s)
还是不认识mwpointer,
而且那个lib设置中的DF60还是没找到
3 楼
ailsa3484 [专家分:0] 发布于 2009-10-26 14:25:00
感谢高手trimtrim,打开了编译器中的FPP,似乎认识了include ,但是还是存在编译错误,不认识mwpointer
源程序如下:
#include "fintrf.h"
#ifndef mwpointer
#define mwpointer integer*4
#endif
#ifndef mwPointer
#define mwPointer mwpointer
#endif
program main
!-----------------------------------------------------------------------
! (pointer) Replace integer by integer*8 on 64-bit platforms
!
mwPointer engOpen, engGetVariable, mxCreateDoubleMatrix
mwPointer mxGetPr
mwpointer ep, T, D
!----------------------------------------------------------------------
!
! Other variable declarations here
double precision time(10), dist(10)
integer engPutVariable, engEvalString, engClose
integer temp, status
data time / 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 /
!
ep = engOpen('matlab ')
!
if (ep .eq. 0) then
write(6,*) 'Can''t start MATLAB engine'
stop
endif
!
T = mxCreateDoubleMatrix(1, 10, 0)
call mxCopyReal8ToPtr(time, mxGetPr(T), 10)
!
!
! Place the variable T into the MATLAB workspace
!
status = engPutVariable(ep, 'T', T)
!
if (status .ne. 0) then
write(6,*) 'engPutVariable failed'
stop
endif
!
!
! Evaluate a function of time, distance = (1/2)g.*t.^2
! (g is the acceleration due to gravity)
!
if (engEvalString(ep, 'D = .5.*(-9.8).*T.^2;') .ne. 0) then
write(6,*) 'engEvalString failed'
stop
endif
!
!
! Plot the result
!
if (engEvalString(ep, 'plot(T,D);') .ne. 0) then
write(6,*) 'engEvalString failed'
stop
endif
if (engEvalString(ep, 'title(''Position vs. Time'')') .ne. 0) then
write(6,*) 'engEvalString failed'
stop
endif
if (engEvalString(ep, 'xlabel(''Time (seconds)'')') .ne. 0) then
write(6,*) 'engEvalString failed'
stop
endif
if (engEvalString(ep, 'ylabel(''Position (meters)'')') .ne. 0)then
write(6,*) 'engEvalString failed'
stop
endif
!
!
! read from console to make sure that we pause long enough to be
! able to see the plot
!
print *, 'Type 0 <return> to Exit'
print *, 'Type 1 <return> to continue'
read(*,*) temp
!
if (temp.eq.0) then
print *, 'EXIT!'
status = engClose(ep)
if (status .ne. 0) then
write(6,*) 'engClose failed'
endif
stop
end if
!
if (engEvalString(ep, 'close;') .ne. 0) then
write(6,*) 'engEvalString failed'
stop
endif
!
D = engGetVariable(ep, 'D')
call mxCopyPtrToReal8(mxGetPr(D), dist, 10)
print *, 'MATLAB computed the following distances:'
print *, ' time(s) distance(m)'
do 10 i=1,10
print 20, time(i), dist(i)
20 format(' ', G10.3, G10.3)
10 continue
!
!
call mxDestroyArray(T)
call mxDestroyArray(D)
status = engClose(ep)
!
if (status .ne. 0) then
write(6,*) 'engClose failed'
stop
endif
!
stop
end
--------------------Configuration: fengdemo - Win32 Debug--------------------
Compiling Fortran...
fengdemo.i
D:\Fortran Project\test pulseforce\test engcall\fengdemo.for(23) : Error: Syntax error, found ',' when expecting one of: ( : % . = =>
mwPointer engOpen, engGetVariable, mxCreateDoubleMatrix
-----------------------^
D:\Fortran Project\test pulseforce\test engcall\fengdemo.for(24) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = =>
mwPointer mxGetPr
-----------------------^
D:\Fortran Project\test pulseforce\test engcall\fengdemo.for(25) : Error: Syntax error, found ',' when expecting one of: ( : % . = =>
mwpointer ep, T, D
------------------^
Error executing df.exe.
fengdemo.obj - 3 error(s), 0 warning(s)
不知道问题在哪?[em10]
4 楼
trimtrim [专家分:1640] 发布于 2009-10-26 18:01:00
删除:
#ifndef mwPointer
#define mwPointer mwpointer
#endif
看看
5 楼
doanything [专家分:0] 发布于 2010-03-29 20:25:00
“存在编译错误,不认识mwpointer”
怎样解决了?
6 楼
弯弓射大雕1 [专家分:0] 发布于 2012-10-31 21:09:00
同问!编译设置问题!visual fortran6.6调用matlab7!高手不吝赐教!
我来回复