Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique Unit Number for openeing file

Status
Not open for further replies.

pradeepburla

Programmer
Jan 8, 2015
1
DE
HI Guys,
Happy New Year.
I have a library where I read the same file many times in different source files.
I want to know if there is some way through which I can set a unique Unit Number each time by checking its availability.


Thank You.
 
A first solution already available in Fortran77 :

Code:
    SUBROUTINE odunit(kfile) ! Returns the first file unit which is not presently used
      INTEGER,INTENT(out) :: kfile
      LOGICAL L
      DO kfile=8,200
        INQUIRE(kfile,OPENED=L)
        IF(.NOT.L) RETURN
      ENDDO
      kfile=0
    END SUBROUTINE

The new solution of Fortran2003 : the unit is generated by the OPEN statement

open(file="...",newunit=kfile,...)

Frantois Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top