Error using Internal WRITE

Error using Internal WRITE

I have been having an problem using internal write with a library
I created in Fortran. I am using CVF 6.1 and have VS 6.0 SP4. The
problem is that the following typical code causes any windows program
to crash. If I create a console application it works just fine.
I have tried creating a LIB and an DLL and the problem is
the same.

I need to format data into character string that will be outputted
to another application or returned to the calling program. Here is
how I have been doing it in the past. Also, I have tried a lot
of different permutations, but I must have just missed something.

WRITE(BUFFER,'(A)') 'Program Finished'
! or WRITE(BUFFER,100) 'Program Finished'
! 100 FORMAT(A)

ENCODE works in a few places, but I would rather not change nearly
500 lines of code where these statements are located.

Any suggestions would be welcomed.

Thanks for any help.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

WRITE(BUFFER,'(A)') 'Program Finished' should not work with CHARACTER*1 BUFFER(1024) (an array with 1024 elements one character long each).


Fortran Windows programs do crash (typically just disappearing, without any error message) when a I/O error _or_ OUTPUT TO SCREEN (Write (*))is encountered in fortran code.

Now, there's nothing wrong in the code you posted, but perhaps there
is something wrong in the actual code. My guess is that you have output to screen somewhere. You can remove it or change it to write to a file, or
put AllocConsole call on the beginning and FreeConsole at the end of the fortran code, which would create a console window.

If that's not the case, try adding IOSTAT=iError in WRITE statement and
examine the value of iError after that. If that's 0, everything is OK; otherwise, it's an I/O error code (meanings can be found somewhere in
programmers' guide).



I thank Sabalan and Jugoslav for their suggestions. In reply to Sabalan, I have tried every combination of CHARACTER*1024 BUFFER and CHARACTER*1 BUFFER(1024) in combination with WRITE(BUFFER,'(A)'), BUFFER and WRITE(BUFFER,'(1024A)'). I have use the formatting in a FORMAT statement as well. Every combination works in a console application and has for ten years.

I will try AllocConsole as Jugoslav suggested today and see what happens. The error check should help too.

If you're calling a DLL from Visual Basic, and the DLL code gets an error, VB just dies - there's nothing Fortran can do about it. One of the things that can cause an error is to do a write to a non-existent console, which is where the AllocConsole comes in.

The point to remember here is that it is the "main program" that determines the error handling behavior - if you're calling from a Fortran or C console application, everything works fine. If you call a DLL from VB, then you had better hope that nothing goes wrong.


Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today