Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*) | :: | FileName |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
FUNCTION FindUnitNumber (FileName) RESULT (UnitNumber)
! FUNCTION INFORMATION:
! AUTHOR Linda K. Lawrie
! DATE WRITTEN September 1997, adapted from reference
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS FUNCTION:
! Returns a unit number for the file name that is either opened or exists.
! METHODOLOGY EMPLOYED:
! Use Inquire function to find out if proposed unit: exists or is opened.
! If not, can be used for a new unit number.
! REFERENCES:
! Copyright (c) 1994 Unicomp, Inc. All rights reserved.
!
! Developed at Unicomp, Inc.
!
! Permission to use, copy, modify, and distribute this
! software is freely granted, provided that this notice
! is preserved.
! USE STATEMENTS:
! na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! FUNCTION ARGUMENT DEFINITIONS:
CHARACTER(len=*) FileName ! File name to be searched.
INTEGER UnitNumber ! Unit number that should be used
! FUNCTION PARAMETER DEFINITIONS:
! Largest allowed unit number (or a large number, if none)
INTEGER, PARAMETER :: MaxUnitNumber = 1000
! INTERFACE BLOCK SPECIFICATIONS
! na
! DERIVED TYPE DEFINITIONS
! na
! FUNCTION LOCAL VARIABLE DECLARATIONS:
CHARACTER(Len=255) TestFileName ! File name returned from opened file
INTEGER TestFileLength ! Length from INQUIRE intrinsic
INTEGER,EXTERNAL :: GetNewUnitNumber ! Function to call if file not opened
LOGICAL :: exists ! True if file already exists
LOGICAL :: opened ! True if file is open
INTEGER Pos ! Position pointer
INTEGER FileNameLength ! Length of requested file
INTEGER :: ios ! Status indicator from INQUIRE intrinsic
INQUIRE (FILE=FileName, EXIST = exists, OPENED = opened, IOSTAT = ios)
IF (.not. OPENED) THEN
UnitNumber=GetNewUnitNumber()
OPEN(UNIT=UnitNumber,FILE=FileName,POSITION='APPEND',iostat=ios)
IF (ios /= 0) THEN
CALL DisplayString('FindUnitNumber: Could not open file "'//trim(FileName)//'" for append.')
ENDIF
ELSE
FileNameLength=LEN_TRIM(FileName)
DO UnitNumber=1,MaxUnitNumber
INQUIRE(UNIT=UnitNumber,NAME=TestFileName,OPENED=opened)
! Powerstation returns just file name
! DVF (Digital Fortran) returns whole path
TestFileLength=LEN_TRIM(TestFileName)
Pos=INDEX(TestFileName,FileName)
IF (Pos .ne. 0) THEN
! Must be the last part of the file
IF (Pos+FileNameLength-1 .eq. TestFileLength) EXIT
ENDIF
END DO
ENDIF
RETURN
END FUNCTION FindUnitNumber