Commit 87d08e25 authored by Henderson, Shane's avatar Henderson, Shane
Browse files

Merge branch 'file_function_access' into 'master'

Make unit number method standalone at FileType_Base

See merge request https://code.ornl.gov/futility/Futility/-/merge_requests/404
parents 02066e59 304fdc3a
Loading
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
!> CodeCoverageReports "Code Coverage Reports" page.
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
MODULE FileType_Base
USE ISO_FORTRAN_ENV
USE IntrType
USE Strings
USE ExceptionHandler
@@ -38,6 +39,7 @@ PRIVATE
PUBLIC :: BaseFileType
PUBLIC :: MAX_FILE_STRING_LEN
PUBLIC :: clear_base_file
PUBLIC :: FileType_get_new_unit

CHARACTER(LEN=*),PARAMETER :: modName='FILETYPE_BASE'
INTEGER(SIK),SAVE :: MAX_FILE_STRING_LEN=0
@@ -390,4 +392,35 @@ SUBROUTINE FileBase_sub_absintfc(file)
  CLASS(BaseFileType),INTENT(INOUT) :: file
ENDSUBROUTINE FileBase_sub_absintfc
!
!-------------------------------------------------------------------------------
!> @brief Returns a unit number that is presently not in use.
!> @param istt optional input for where to start searching for an unused unit
!>        number
!> @returns newlun a unit number that is not currently in use by this process
!>
FUNCTION FileType_get_new_unit(istt) RESULT(newlun)
  INTEGER(SIK),INTENT(IN),OPTIONAL :: istt
  INTEGER(SIK) :: newlun,isafe
  LOGICAL(SBK) :: ostat

  newlun=MAX(OUTPUT_UNIT,ERROR_UNIT,INPUT_UNIT)+1
  IF(PRESENT(istt)) newlun=istt

  INQUIRE(UNIT=newlun,OPENED=ostat)
  isafe=0
  DO WHILE(ostat)
    newlun=newlun+1
    isafe=isafe+1
    INQUIRE(UNIT=newlun,OPENED=ostat)

    !Catch to prevent an infinite loop
    !Return a bad value as apparently all unit numbers
    !are in use.
    IF(isafe == 100000) THEN
      newlun=-666
      EXIT
    ENDIF
  ENDDO
ENDFUNCTION FileType_get_new_unit
!
ENDMODULE FileType_Base
+1 −36
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ PUBLIC :: init_fortran_file
PUBLIC :: clear_fortran_file
PUBLIC :: rewind_fortran_file
PUBLIC :: backspace_fortran_file
PUBLIC :: FortranFile_get_new_unit

!> Module name for error messages
CHARACTER(LEN=*),PARAMETER :: modName='FILETYPE_FORTRAN'
@@ -109,9 +108,6 @@ TYPE,EXTENDS(BaseFileType) :: FortranFileType
!
!List of type bound procedures (methods) for the Fortran File type
  CONTAINS
    !> @copybrief FileType_Fortran::FortranFile_get_new_unit
    !> @copydetails FileType_Fortran::FortranFile_get_new_unit
    PROCEDURE,NOPASS :: newUnitNo => FortranFile_get_new_unit
    !> @copybrief FileType_Fortran::init_fortran_file
    !> @copydetails FileType_Fortran::init_fortran_file
    PROCEDURE,PASS :: initialize => init_fortran_file
@@ -259,7 +255,7 @@ SUBROUTINE init_fortran_file(fileobj,unit,file,status,access,form, &
      ENDIF
    ENDIF
  ELSE
    fileobj%unitno=fileobj%newUnitNo()
    fileobj%unitno=FileType_get_new_unit()
  ENDIF

  !STATUS clause for OPEN statement
@@ -835,35 +831,4 @@ SUBROUTINE write_str_1a_fortran_file(file,lines)
  ENDDO
ENDSUBROUTINE write_str_1a_fortran_file
!
!-------------------------------------------------------------------------------
!> @brief Returns a unit number that is presently not in use.
!> @param istt optional input for where to start searching for an unused unit
!>        number
!> @returns newlun a unit number that is not currently in use by this process
!>
FUNCTION FortranFile_get_new_unit(istt) RESULT(newlun)
  INTEGER(SIK),INTENT(IN),OPTIONAL :: istt
  INTEGER(SIK) :: newlun,isafe
  LOGICAL(SBK) :: ostat

  newlun=MAX(MAX(OUTPUT_UNIT,ERROR_UNIT),INPUT_UNIT)+1
  IF(PRESENT(istt)) newlun=istt

  INQUIRE(UNIT=newlun,OPENED=ostat)
  isafe=0
  DO WHILE(ostat)
    newlun=newlun+1
    isafe=isafe+1
    INQUIRE(UNIT=newlun,OPENED=ostat)

    !Catch to prevent an infinite loop
    !Return a bad value as apparently all unit numbers
    !are in use.
    IF(isafe == 100000) THEN
      newlun=-666
      EXIT
    ENDIF
  ENDDO
ENDFUNCTION FortranFile_get_new_unit
!
ENDMODULE FileType_Fortran