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

writing on stdout with write(6,*)

Bruno_Arbter
Beginner
2,118 Views
Hi,

I am using a staticfortran lib in c++ applications. The routines of the fortran lib write status messages via write(6,*). When linking the fortran lib to a console application everything works fine and the messages are passed to stdout of the c++ application. But linking the lib to a window gui application based on qt (trolltech) the following run-time error occured when calling the fortran routine:

"forrtl severe (38): error during write, unit 6, file CONOUT$"

Any suggestions?

Bruno
0 Kudos
12 Replies
Steven_L_Intel1
Employee
2,118 Views

There is no stdout defined in a windows gui application. You can create one by calling AllocConsole() (a Win32 API routine.)

Previous versions of Intel Fortran would silently ignore writes to a non-existent console - this changed in 11.1.
0 Kudos
GVautier
New Contributor II
2,118 Views
Quoting - Bruno Arbter
Hi,

I am using a staticfortran lib in c++ applications. The routines of the fortran lib write status messages via write(6,*). When linking the fortran lib to a console application everything works fine and the messages are passed to stdout of the c++ application. But linking the lib to a window gui application based on qt (trolltech) the following run-time error occured when calling the fortran routine:

"forrtl severe (38): error during write, unit 6, file CONOUT$"

Any suggestions?

Bruno

Hello

I think that the syntax :

write(6,IOSTAT=ioerr,*)

may solve the problem.

0 Kudos
Bruno_Arbter
Beginner
2,118 Views

Thanks, both, write(6,IOSTAT=ioerr) and AllocConsole() prevents the run-time error.

But how can I catch the messages in C++?
In the moment, within my GUI application, I redirect all my status (printf)-messages of the C functions from stdout to a log-file via freopen( "./test.log", "w", stdout ). (By the way, that worked without creating a console...) But (write)-messages from the fortran-lib are not catched, when using write(6,IOSTAT=ioerr), and are catched only to the created console using AllocConsole(). I want to have all messages in the log-file.

Any Idea?

Bruno
0 Kudos
Les_Neilson
Valued Contributor II
2,118 Views
Quoting - Bruno Arbter

Thanks, both, write(6,IOSTAT=ioerr) and AllocConsole() prevents the run-time error.

But how can I catch the messages in C++?
In the moment, within my GUI application, I redirect all my status (printf)-messages of the C functions from stdout to a log-file via freopen( "./test.log", "w", stdout ). (By the way, that worked without creating a console...) But (write)-messages from the fortran-lib are not catched, when using write(6,IOSTAT=ioerr), and are catched only to the created console using AllocConsole(). I want to have all messages in the log-file.

Any Idea?

Bruno

Mixing Fortran and C/C++ I/O to the same file - the simplest way is for the Fortran code to call a C/C++ function (instead of the write statement) with the string to be printed and let the C/C++ printf handle it (as you already have that).

Les
0 Kudos
ludovicnorsar_no
Beginner
2,118 Views
Hei,
I have the same problem, but only in release configuration.
My main application is in C++ compiled by MSVC .NET 2003 and it links to fortran libraries compiled by Intel Fortran 8.1
By using freopen("myfile.txt", "w", stdout) in C++, all printouts from fortran go to my file in debug configuration, but not in release configuration. I guess that because the application has a console in debug, but not in release. Besides I understand that this behavior has changed in Intel fortran 11.1 and that the program may crash if there are no console!
As I have thousands of fortran prints, I can not change the fortran code.
Please advise how to fix this problem?
Ludovic
0 Kudos
mecej4
Honored Contributor III
2,118 Views
As Les Neilson has already pointed out, mixing C and Fortran output to the same channel has many chances of failing or not working correctly. Perhaps, this analogy may help to see why:

C and Fortran, in general, use different I/O subsystems. Think of C as writing to buffer CBuf, and Fortran writing to a separate buffer FBuf. The C runtime flushes CBuf based on its conscience, and Fortran does likewise with FBuf. The order in which lines of output appear in the composite output file at the end of the run is indeterminate.
0 Kudos
Steven_L_Intel1
Employee
2,118 Views
With a current 11.1 version, writes to stdout without a console should not cause an error.
0 Kudos
ludovicnorsar_no
Beginner
2,118 Views
Thank you for your reply.
Actually mixing C and Fortran output to the same channel works perfectly well!
It works on Linuxin both debug and release configuration.
But it works on Windows onlyin debug configuration.
In release configuration on Windows, I get only outputfrom C++ to my file, not any longerfrom Fortran.
As I understand, Intel Fortran compiler just ignores outputsif it does not find any console. In my case, I don't need to output to a console but to a file.
Is there any option to force compiler tohandle outputs even if there is no console?
It may seem absurb to ask for such an option, but once again, when redirecting toa file there is no need to have a console.
Thanks,
Ludovic
0 Kudos
ludovicnorsar_no
Beginner
2,118 Views
Steve,
do you think that my problem will be solved by using 11.1 version?
I quote a previous post: "Previous versions of Intel Fortran would silently ignore writes to a non-existent console - this changed in 11.1."
Ludovic
0 Kudos
Steven_L_Intel1
Employee
2,118 Views
If you write to unit 6 without opening it to a file, and there is no console, the write will have no effect in current 11.1 versions.

If you know you will want the output to go to a file, open unit 6 to a file.
0 Kudos
ludovicnorsar_no
Beginner
2,118 Views
Ok, thanks.I will try topass the filename from C++ to Fortran at runtime and open unit 6 to it.
Ludovic
0 Kudos
Darrell
Beginner
2,118 Views
Good answer. I can't find this or the error message below in the 11.1 Release Notes? I'm guessing AllocConsole can be called from Fortran or open CONOUT$?

Intel Visual Fortran run-time error: forrtl: severe (38): error during write, unit 6, file CONOUT$


For multi-user multi-threaded support, we concerned about closing CONOUT$
0 Kudos
Reply