subroutine CheckForActualFileName(originalInputFileName,FileFound,CheckedFileName)
! SUBROUTINE INFORMATION:
! AUTHOR Linda Lawrie
! DATE WRITTEN October 2011
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! With the Windows version, there are subfolders set and the input file names may not
! be accurate. This searches a few folders (CurrentWorkingFolder, Program folder) to see
! if the file can be found. (It may have been input with full path so that is checked first.)
! METHODOLOGY EMPLOYED:
! na
! REFERENCES:
! na
! USE STATEMENTS:
! na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
CHARACTER(len=*), INTENT(IN) :: originalInputFileName ! name as input for object
LOGICAL, INTENT(INOUT) :: FileFound ! Set to true if file found and is in CheckedFileName
CHARACTER(len=*), INTENT(INOUT) :: CheckedFileName ! Blank if not found.
! SUBROUTINE PARAMETER DEFINITIONS:
CHARACTER(len=*), PARAMETER :: blank=' '
! INTERFACE BLOCK SPECIFICATIONS:
! na
! DERIVED TYPE DEFINITIONS:
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
LOGICAL :: FileExist
INTEGER, SAVE :: EchoInputFile ! found unit number for "eplusout.audit"
INTEGER, EXTERNAL :: FindUnitNumber
LOGICAL, SAVE :: firstTime=.true.
CHARACTER(len=LEN(originalInputFileName)) :: InputFileName ! save for changing out path characters
INTEGER :: pos
IF (firstTime) THEN
EchoInputFile=FindUnitNumber('eplusout.audit')
envinputpath1=blank
CALL Get_Environment_Variable(cInputPath1,envinputpath1)
IF (envinputpath1 /= blank) THEN
pos=INDEX(envinputpath1,pathchar,.true.) ! look backwards for pathchar
IF (Pos /= 0) envinputpath1=envinputpath1(1:pos)
ENDIF
envinputpath2=blank
CALL Get_Environment_Variable(cInputPath2,envinputpath2)
programpath=blank
CALL Get_Environment_Variable(cProgramPath,programpath)
firsttime=.false.
ENDIF
CheckedFileName=blank
InputFileName=originalInputFileName
pos=INDEX(InputFileName,AltPathChar)
DO WHILE(pos > 0)
InputFileName(pos:pos)=PathChar
pos=INDEX(InputFileName,AltPathChar)
ENDDO
INQUIRE(File=trim(InputFileName),Exist=FileExist)
IF (FileExist) THEN
FileFound=.true.
CheckedFileName=InputFileName
WRITE(EchoInputFile,'(A)') 'found (user input)='//trim(InputFileName)
RETURN
ELSE
WRITE(EchoInputFile,'(A)') 'not found (user input)='//trim(InputFileName)
ENDIF
! Look relative to input path
INQUIRE(File=trim(envinputpath1)//trim(InputFileName),Exist=FileExist)
IF (FileExist) THEN
FileFound=.true.
CheckedFileName=trim(envinputpath1)//trim(InputFileName)
WRITE(EchoInputFile,'(A)') 'found (epin)='//trim(CheckedFileName)
RETURN
ELSE
WRITE(EchoInputFile,'(A)') 'not found (epin)='//trim(envinputpath1)//trim(InputFileName)
ENDIF
! Look relative to input path
INQUIRE(File=trim(envinputpath2)//trim(InputFileName),Exist=FileExist)
IF (FileExist) THEN
FileFound=.true.
CheckedFileName=trim(envinputpath2)//trim(InputFileName)
WRITE(EchoInputFile,'(A)') 'found (input_path)='//trim(CheckedFileName)
RETURN
ELSE
WRITE(EchoInputFile,'(A)') 'not found (input_path)='//trim(envinputpath2)//trim(InputFileName)
ENDIF
! Look relative to program path
INQUIRE(File=trim(envprogrampath)//trim(InputFileName),Exist=FileExist)
IF (FileExist) THEN
FileFound=.true.
CheckedFileName=trim(envprogrampath)//trim(InputFileName)
WRITE(EchoInputFile,'(A)') 'found (program_path)='//trim(CheckedFileName)
RETURN
ELSE
WRITE(EchoInputFile,'(A)') 'not found (program_path)='//trim(envprogrampath)//trim(InputFileName)
ENDIF
IF (.not. TestAllPaths) RETURN
! Look relative to current working folder
INQUIRE(File=trim(CurrentWorkingFolder)//trim(InputFileName),Exist=FileExist)
IF (FileExist) THEN
FileFound=.true.
CheckedFileName=trim(CurrentWorkingFolder)//trim(InputFileName)
WRITE(EchoInputFile,'(A)') 'found (CWF)='//trim(CheckedFileName)
RETURN
ELSE
WRITE(EchoInputFile,'(A)') 'not found (CWF)='//trim(CurrentWorkingFolder)//trim(InputFileName)
ENDIF
! Look relative to program path
INQUIRE(File=trim(ProgramPath)//trim(InputFileName),Exist=FileExist)
IF (FileExist) THEN
FileFound=.true.
CheckedFileName=trim(ProgramPath)//trim(InputFileName)
WRITE(EchoInputFile,'(A)') 'found (program path - ini)='//trim(CheckedFileName)
RETURN
ELSE
WRITE(EchoInputFile,'(A)') 'not found (program path - ini)='//trim(ProgramPath)//trim(InputFileName)
ENDIF
RETURN
end subroutine CheckForActualFileName