How to call a .exe filed compiled in Fortran having multiple text input files through a MATLAB gui ?
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 30 Oct 2017
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 Comments
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!