Why does Fortran write(6,...) not show in MATLAB window
1 view (last 30 days)
Show older comments
Hi all,
I'm having a bit of an issue with matlab displaying any write to screen commands from my fortran code. (write(6,...) print *)
Right now I have a Fortran Code with a write(6,*)"TOODLES" which will work fine in the compiler, but when I throw a C-Mex wrapper around the fortran code to call it from Simulink, Nothing shows up in the matlab window from the fortran code. printf works from the wrapper .c code, but I get nothing back from Fortran.
I've been looking it up and it seems to have been an issue in later versions of Matlab,
Does Matlab still have this issue? The threads above are out of date, and you would think there would be a fix for it by now.
The problem seems to be that matlab does not understand that the fortran unit=6 for the write function is the standard out
Changing the Fortran Code is not an option entirely. I can add an open statement, but I do not wish to change the write(6,..) to anything else as other programs use this fortran code too. (Thus no mex commands either)
I CAN change the .c-wrapper code. but I dont think that will help
I have Matlab version R2013b with compiler Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2010 linker)
Thanks in advance, Brian
0 Comments
Accepted Answer
James Tursa
on 16 Apr 2014
You can look near the end of this thread for a technique that might work for you if you do not need the output interactively within the mex routine itself:
Basically, the technique is to write to a file first, then rewind and print out the file just before exiting the mex routine:
Wrap your Fortran write(6,etc) stuff with this code:
integer*4 mexPrintf, k
character*200 ::str
:
open(unit=6,file='temp.txt',status='unknown')
Then call your write(6,__) statements as-is. Then just before mexFunction returns back to MATLAB, do this:
rewind 6
do
read(6,'(a)',end=500) str
k = mexPrintf(str//achar(10))
enddo
500 close(unit=6)
7 Comments
James Tursa
on 17 Apr 2014
You're welcome. You might also consider trimming the output to get rid of trailing spaces. E.g.
k = mexPrintf(trim(str)//achar(10))
More Answers (0)
See Also
Categories
Find more on MATLAB Compiler 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!