My approach to good practice is to never open a file using a file unit number less than 11. (11 for read, 12 for write) This copes with all fortran compilers I have ever used.
I typically open text files for units 11-19, binary files on 21+ and a log file on unit 98. This approach has been based on once using a compiler that limited the file number to 99.
I am not sure what the maximum number can be, but I have seen examples of unit numbers 1000+. I have never realy had to find out.
Over the years, there have been many posts where people got in trouble with 'reserved' file unit numbers < 10. I did know that units 1,5 and 6 were often special but have never had the need to find out that unit 2 is also reserved in FTN95. There's always somenthig new.
John
integer*4 lu, iostat
character line*80
!
do lu = 1,10
write (lu,*, iostat=iostat) 'successful test for unit',lu
if (iostat /= 0) write (*,*) 'ERROR : unsuccessful test for unit',lu
end do
! write (lu,*) 'error example for unit',lu
!
do lu = 11,11011,500
!
open (unit=lu, file='some_file.txt', iostat=iostat)
if (iostat/=0) then
write (*,*) 'unable to use file unit',lu
cycle
end if
!
if (lu==11) then
write (11,*) 'test line written using file unit',lu
else
!
read (lu,fmt='(a)', iostat=iostat) line
if (iostat/=0) then
write (*,*) 'unable to read file unit',lu
else
write (*,*) lu,' ',trim (line)
end if
end if
!
close (unit=lu,iostat=iostat)
if (iostat/=0) then
write (*,*) 'unable to close file unit',lu
end if
!
end do
!
end
The limit must be a big number !