Re: Program compiled on intel acting weired

From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 04/20/04


Date: Tue, 20 Apr 2004 09:01:49 -0500

MISHAL ALHARBI wrote:

> The data file is open for read but then it gets overwritten by what
> WRITE(*,*) is doing. When the READ statment tries to access the file, I get
> the error message "read after write". I understand the reason for the error
> but I don't understand why things got "short circuited" between the data
> file and the screet output. In other words, why did WRITE(*,*) points to
> the file that was opened for READ. The program runs with no problems when
> compiled with CVF which overrules any bugs in the code. This is my first
> attempt to use Intel Fortan 7 and I am not sure if there are cmpiler
> specific issues that cause this.

Perhaps the key to your problem is that you are using logical unit
number 6 for I/O to your file. Are you _trying_ to redirect I/O to the
default unit into a file? Richard seems to assume that you are, but I'm
not so sure. He did recommend that you not do that, and I'll second him
there.

Assuming, though, that redirection of console I/O is _not_ your plan,
assigning unit 6 to a user file is a bad idea, because that unit number
is the one most commonly "prewired" to standard output. (As unit 5 is
the one most commonly prewired to standard input.) Intel's would not be
the first Fortran to perform I/O redirection of the default unit (*) via
user files assigned unit 5 and/or 6, but by no means do all Fortran
implementations do so. To avoid portability problems, don't use these
particular unit numbers for user files. In fact, some, including me,
would recommend that you not assign any unit numbers less than, say, ten
to user files. I personally start at 20; that may be execessively
cautious, but there are plenty of unit numbers to go around.

It does sound like Intel Fortran is a bit buggy in this area, but that
doesn't solve your problem. Chances are that you will have to use a
different unit number. Take this opportunity to do as Richard advised
and use a variable (presumably a module variable) to hold the lun --
you'll have to change the unit numbers to _something_ else, and a
variable both gives you an easy way to change the actual number later
and documents (by way of its name) what that unit is for. This is what
I do for anything complex, but not necessarilly for quick, one-off programs.

John Bollinger
jobollin@indiana.edu



Relevant Pages

  • Re: printing in fortran
    ... Printf has a variable ... be aware of the fine print relating to I/O and C interop. ... If you open a file in Fortran, ...
    (comp.lang.fortran)
  • Re: a mergesort
    ... That would depend on how many records are processed, the quality of the I/O runtime, ... True for all lanuages but Fortran ... whereas comparison-based sorting takes time proportional to N.log N. ... 272343 calls to MergeLCP, 46442 skipped merges, 1320049 string comparisons ...
    (comp.lang.fortran)
  • Re: a mergesort
    ... That would depend on how many records are processed, the quality of the I/O runtime, ... True for all lanuages but Fortran ... whereas comparison-based sorting takes time proportional to N.log N. ... 272343 calls to MergeLCP, 46442 skipped merges, 1320049 string comparisons ...
    (comp.lang.fortran)
  • Re: a modest proposal
    ... OS/360 object programs are 80 byte fixed ... I/O using A format. ... file with JCL and associate it with a Fortran I/O unit number? ...
    (comp.lang.fortran)
  • Re: a modest proposal
    ... OS/360 object programs are 80 byte fixed ... I/O using A format. ... file with JCL and associate it with a Fortran I/O unit number? ...
    (comp.lang.fortran)