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

Rules regarding implicit write

smedvedoff
Beginner
1,464 Views

I inadvertently executed an implicit unformatted write to a specific unit number in a FORTRAN program (I neglected to open the file first). The documentation states that a file named fort.n, where n is the unit number, will be generated in such cases (or depending on project settings I can be prompted for a file to use). Neither of these is happening. What I'm seeing instead is that another file I've opened for read access and subsequently closed is being overwritten by the unformatted data. This file happens to be listed as a command line argument. After some experimentation I've determined that if I have any files listed as command line arguments, one of them will be overwritten by the unformatted data (sometimes the first, sometimes the second, depending on where I do the implicit write in my code). If I have none listed, them I'm prompted for a file name. Can anyone explain this?

Thanks,
Steve

0 Kudos
5 Replies
mecej4
Honored Contributor III
1,464 Views
Which version of the Intel compiler is this in reference to? Can you provide a small code example which reproduces the behavior that you have described?

Since Fortran programs traditionally did not process command line arguments (in fact, before Fortran 2003, one had to call compiler-specific subroutines/functions even to obtain command line arguments), there is something in the source code beyond what you have written. Without having lines of code that obtain the command line arguments, there is no obvious way for your program to perform differently with no arguments as compared to running with one or more arguments.

What you are seeing may be the result of taking a program which connected files to unit numbers based on command line arguments, and putting some additional file I/O which does not adhere to the original assumptions.

You may put in a number of INQUIRE statements to understand what is happening to the file status at various points in the program.
0 Kudos
Steven_L_Intel1
Employee
1,464 Views
The symptom suggests that the previous unit was not, in fact, closed.

The prompt comes from the /fpscomp:filesfromcmd option when you open a file with an empty filename.
0 Kudos
Arjen_Markus
Honored Contributor II
1,464 Views
I have seen that sort of behaviour with the ancient MicroSoft Fortran compilers. Is this a matter of compatibility with previous compilers?

Regards,

Arjen
0 Kudos
Steven_L_Intel1
Employee
1,464 Views
Exactly. That's why its under the control of /fpscomp.
0 Kudos
smedvedoff
Beginner
1,464 Views
Thanks to everyone for their replies. I was unaware of the filesfromcmd option. It turns out that I do have it set, and the FORTRAN documentation states that this causes command line arguments to be used as filenames when writing to files that aren't explicitly opened - which is what I'm seeing. If the command line options are removed, then I get the prompt. Thanks again.

Steve
0 Kudos
Reply