回 帖 发 新 帖 刷新版面

主题:通过matlab调用Fortran可执行文件读外部文本

问题描述:通过matlab调用visual Fortran 9.0生成的.exe文件读取外部文本
其中MATLAB中的.m文件的内容为
----------------------------------------
name = {'t1.dat','t2.dat','t3.dat'};
batch = 'test.exe';
for i = 1:length(name)
    batch = strcat(batch,{' '},name{i});
end
batch{1}
dos(batch{1});
----------------------------------------
其中t1.dat,t2.dat,t3.dat中分别只有一个整数1,2,3,test.exe文件为Fortran可执行文件,其中代码为
test.f90
-------------------------------------
implicit none
integer i
open(1,file = ' ',status = 'old')
read(1,*) i
close(1)
print*,i

open(1,file = ' ',status = 'old')
read(1,*) i
close(1)
print*,i

open(1,file = ' ',status = 'old')
read(1,*) i
close(1)
print*,i

pause 
end
---------------------------------------
将上面的.m文件,三个文本文件,test.exe文件放在同一文件夹中
在matlab界面下进入该文件夹并运行.m文件,出线如下错误:
----------------------------------------------------------------------
forrtl: severe (29): file not found, unit 1, file   
Image              PC        Routine            Line        Source              
test.exe           00497692  Unknown               Unknown  Unknown 
test.exe           0049492C  Unknown               Unknown  Unknown 
test.exe           0040BF02  Unknown               Unknown  Unknown 
test.exe           0040BB1F  Unknown               Unknown  Unknown 
test.exe           00401FE9  Unknown               Unknown  Unknown 
test.exe           0040106A  _MAIN__                     3  test.F90 
test.exe           0049DDEC  Unknown               Unknown  Unknown 
test.exe           0043DFA3  Unknown               Unknown  Unknown 
test.exe           0043DD6D  Unknown               Unknown  Unknown 
kernel32.dll       7C817067  Unknown               Unknown  Unknown 
-----------------------------------------------------------------------
不知道是什么原因导致这样的问题,请各位大侠指点迷津!

回复列表 (共1个回复)

沙发

问题已经解决了,问题属于“Use Filenames from Command Line ”,需要通过修改编译器的参数来实现。在IVF中点击project> test properties,弹出窗口“test property pages”点击左端“configuration on properties>Fortran>compatibility,将右端窗口中的“use filenames from conmmand line”后的‘no’改为‘yes’,重新编译生成.exe文件即可实现上面的功能。

我来回复

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