Commit 304fdc3a authored by aarograh's avatar aarograh Committed by Henderson, Shane
Browse files

Move FortranFile_get_new_unit from a FileType_Fortran

Squash branch 'file_function_access' into 'master'

* Move FortranFile_get_new_unit from a FileType_Fortran
method to a standalone FileType_Base function

Make unit number method standalone at FileType_Base

**Developer Checklist:**
- [x] Have you done a self-review after creating the merge request?
- [x] Have you filled in the Merge Request information (title, description) thoroughly?
- [x] Have you updated the relevant tickets (if this MR is linked to any VERA-dev tickets)?
- [x] Have you addressed all suggested feedback and commented on it to let the reviewer know? (Do not resolve discussions that the reviewer started)

**Reviewer Checklist:**
- [x] Have you confirmed all discussions were adequately addressed and resolved them all?
- [x] Does it conform to formatting guidelines?
- [x] Are there adequate and clear comments?
- [x] Is the design clean and sensible?
- [x] Are the changes optimal/efficient?
- [x] Were sufficient DBC checks added?
- [x] Are there unit tests? (if necessary)
- [x] Is the MR description clear, including a link to the VERA-Dev issue if appropriate?

**PSM Checklist**
- [x] Have you confirmed that all discussions were addressed, or that follow-on issues have been created for them?
- [x] Have you confirmed sufficient testing was conducted?
- [x] Does this impact other repositories?
- [x] Does the MR have an adequate description?
- [x] If the MR has multiple commits, did you set the MR to squash merge?

See merge request https://code.ornl.gov/futility/Futility/-/merge_requests/404
parent 02066e59
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