How to call a .exe filed compiled in Fortran having multiple text input files through a MATLAB gui ?
3 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to create a MATLAB gui which call a .exe file compiled in Fortran (CFD code), submit text input files to it, get the text output file and after modifying the input files, again submit it to the .exe file for solving. (Like a loop) How can I can execute this is MATLAB?....will the system or ! bang operator work?
0 个评论
回答(1 个)
Walter Roberson
2017-10-30
program_exe = 'C:\Programs and Executables\HyperCFD\hypercfd.exe';
tname = tempname();
inname1 = [tname '-in1.txt'];
inname2 = [tname '-in2.txt'];
outname1 = [tname '-out1.txt'];
iteration = 0;
while true
iteration = iteration + 1;
fid = fopen(inname1, 'wt');
fprintf(fid, 'first file\nsome appropriate content\n');
fclose(fid);
fid = fopen(inname2, 'wt');
fprintf(fid, 'second file\nsomething appropriate here\n');
fclose(fid);
cmd = sprintf('"%s" -geometry "%s" -materials "%s" -out "%s"', inname1, inname2, outname1);
if exist(outname1, 'file'); delete(outname1); end
[status, msg] = system(cmd);
if status ~= 0
fprintf('Failed to run executable on iteration #%d, giving up iterating\n', iteration);
break;
end
if ~exist(outname1, 'file')
fprintf('Iteration %d: Executable ran but did not create expected output file "%s", giving up iterating\n', iteration, outname1);
break;
end
[fid, msg] = fopen(outname1, 'rt');
if fid < 0
fprintf('Iteration %d: Output file exists but cannot be opened. Giving up iterations. File "%s", reason "s"\n', iteration, outname1, msg );
break;
end
.... read in the output at this point ...
fclose(fid);
... figure out how to change variables ...
end
if exist(inname1, 'file'); delete(inname1); end
if exist(inname2, 'file'); delete(inname2); end
if exist(outname1, 'file'); delete(outname1); end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Software Development Tools 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!