Clicky

Fortran Wiki
notopen (Rev #4, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #3 to #4: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

#ifdef TESTPRG
program testit
integer,external :: notopen
write(*,*)'check for preassigned files from unit 0 to unit 1000'
write(*,*)'(5 and 6 always return -1)'
do i10=0,1000
 if(notopen(i10,i10) .ne. i10)then
 write(*,*)'INUSE:',i10, notopen(i10,i10)
 endif
enddo
end program testit
#endif
!-------------------------------------------------------------------------------
FUNCTION NOTOPEN(ISTART,IEND)
!-------------------------------------------------------------------------------
! #(@)notopen(3f): find free FORTRAN unit number to OPEN() a file.
!
! NOTOPEN() returns a FORTRAN unit number from ISTART to IEND not
! currently associated with an I/O unit.
!
! If NOTOPEN() returns -1, then no free FORTRAN unit could be found,
! although all units were checked (except for units 5 and 6).
!
! Otherwise, notopen() returns an integer representing a
! free FORTRAN unit. Note that NOTOPEN() assumes units 5 and 6
! are special, and will never return those values.
!
! The range 1 to 99 is standard. Many machines allow other ranges 
! and/or reserve certain units like 0 and 101 for standard input,
! standard output, ...
!
! An environment may impose a limit on the number of simultaneously 
 ! open files (which some compilers work around);(削除) may (削除ここまで)(追記) many (追記ここまで) systems extend
! the upper limit well above 99.
!-------------------------------------------------------------------------------
! Beginning with f2008, you can probably use OPEN(NEWUNIT=...) instead
!-------------------------------------------------------------------------------
 USE ISO_FORTRAN_ENV, ONLY : ERROR_UNIT ! access computing environment
 IMPLICIT NONE
 INTEGER :: NOTOPEN ! function return value
 INTEGER,INTENT(IN) :: ISTART ! unit number to start looking at
 INTEGER,INTENT(IN) :: IEND ! last unit number to look at
 INTEGER :: I10 ! counter from istart to iend
 INTEGER :: IOS ! iostatus from INQUIRE
 LOGICAL :: LOPEN ! returned from INQUIRE
 NOTOPEN=(-1)
 DO I10=ISTART,IEND
 IF ( I10 ==5 .OR. I10 == 6 ) CYCLE ! always skip these two units
 INQUIRE( UNIT=I10, OPENED=LOPEN, IOSTAT=IOS )
 IF( IOS == 0 )THEN ! no error on INQUIRE
 IF( .NOT. LOPEN )THEN ! if unit number not in use, return it
 NOTOPEN = I10
 EXIT ! only need to find one, so return
 ENDIF
 ELSE
 WRITE(ERROR_UNIT,*)'*NOTOPEN*:E-R-R-O-R ON UNIT ',I10,'=',IOS
 ENDIF
 ENDDO 
 RETURN
END FUNCTION NOTOPEN
!-------------------------------------------------------------------------------

category: code

Revision from June 28, 2009 21:12:07 by Anonymous Coward
Forward in time (to current) | Back in time (3 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: Code

AltStyle によって変換されたページ (->オリジナル) /