Re: io-unit has been opened



Brooks Moses wrote:
Mike wrote:
I would like to know whether a file with io-unit has been opened.
To prevent from the following situation:

program main
open(11,file='a.dat',....
call suba()
close(11)
end
subroutine suba()
open(11,file='a.dat',....
......
close(11)
end subroutine suba

Can I detect if io-unit in suba has been used in somewhere else, like
main?

You've actually got two "errors" [1] going on there -- first, you're opening the same io-unit twice, and second, you're opening the same file twice (which is illegal).

If it is "illegal" to open the same file twice, then the Intel Fortran compiler has a bug. One of my student's wrote a program that opened the same file using two different unit numbers on successive statements. The file position "cursor" associated with each unit number operated independently of one another, much like record sets from two database queries. Very strange, but it worked! He could read the file completely through with one unit number and then again with the other without doing a rewind first.

.



Relevant Pages

  • Re: io-unit has been opened
    ... subroutine suba() ... end subroutine suba ... If it is "illegal" to open the same file twice, then the Intel Fortran compiler has a bug. ... Support the Original G95 Project: http://www.g95.org ...
    (comp.lang.fortran)
  • Re: io-unit has been opened
    ... subroutine suba() ... end subroutine suba ... opening the same io-unit twice, and second, you're opening the same file twice. ... you use the INQUIRE statement. ...
    (comp.lang.fortran)
  • Re: io-unit has been opened
    ... subroutine suba() ... end subroutine suba ... opening the same io-unit twice, and second, you're opening the same file twice. ...
    (comp.lang.fortran)
  • UU
    ... Mike wrote: ... I would like to know whether a file with io-unit has been opened. ... subroutine suba() ... end subroutine suba ...
    (comp.lang.fortran)