Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Capturing formatted output on UNIT 6

AndrewC
New Contributor III
633 Views
In my Windows MFC application I have a C++ main program that calls some FORTRAN libraries. Any ideas on how I could capture the output of a formatted FORTRAN unit ( specifically 6) ( if I can capture it I can redirect that to a log window).
0 Kudos
3 Replies
qolin
Novice
633 Views

You could use a console. The WinAPI function to create a console is AllocConsole(). Any windows task can create a console. Once created, the task can write to it as standard output (unit 6 or 0 or * in Fortran, usually). I do this from my Fortran DLLs called from Windows GUI programs written by other programmers (gets them somewhat spooked though...)

Qolin

0 Kudos
Jugoslav_Dujic
Valued Contributor II
633 Views
See
Creating a Child Process with Redirected Input and Output
Of course, it will work only if unit 6 refers to the standard output (i.e. if there's not explicit OPEN(6)). And you probably don't need to redirect the application's input.

The CreatePipe technique will still holds even if the Fortran libraries are statically linked in. In that case, you don't need CreateProcess, but just SetStdHandle(hPipe) for your own application. However, note that pipe communication is synchronous, i.e. reading from a pipe won't be done until writing a complete record to it (i.e. Fortran WRITE(6,...)) is completed. If you want the log window to display the library's output in the same time it is WRITEn, you will have to launch the Fortran calculation in a separate thread.
0 Kudos
AndrewC
New Contributor III
633 Views
Thanks for the great ideas. Very helpful.
Andrew
0 Kudos
Reply