UU




Mike wrote:
Hi

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?

There is no 100% reliable method, but the INQUIRE statement

INQUIRE(11, OPENED=opened)

where opened is a logical variable comes close.

Bob Corbett

.



Relevant Pages

  • 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: local variable initilization
    ... -|end subroutine subA ... Mike, You might move your program's 4th line up two lines. ... end subroutine subA ...
    (comp.lang.fortran)
  • 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. ...
    (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)