Commit 43df951d authored by Henderson, Shane's avatar Henderson, Shane
Browse files

DBC filetype_fortran/simplify filetype_input

parent b9c0cbbd
Pipeline #159108 passed with stage
in 2 minutes and 2 seconds
......@@ -227,10 +227,8 @@ SUBROUTINE init_fortran_file(fileobj,unit,file,status,access,form, &
oldcnt=fileobj%e%getCounter(EXCEPTION_ERROR)
IF(fileobj%initstat) THEN
CALL fileobj%e%raiseError(modName//'::'//myName//' - '// &
'Fortran file has already been initialized!')
ELSE
REQUIRE(.NOT.fileobj%initstat)
!Initialize the file
CALL getFileParts(file,fpath,fname,fext,fileobj%e)
CALL fileobj%setFilePath(CHAR(fpath))
......@@ -423,7 +421,6 @@ SUBROUTINE init_fortran_file(fileobj,unit,file,status,access,form, &
ELSE
fileobj%initstat=.TRUE.
ENDIF
ENDIF
ENDSUBROUTINE init_fortran_file
!
!-------------------------------------------------------------------------------
......@@ -564,13 +561,9 @@ SUBROUTINE open_fortran_file(file)
CHARACTER(LEN=256) :: iomsg
INTEGER(SIK) :: reclval
REQUIRE(file%initstat)
REQUIRE(.NOT.file%isOpen())
!Get the appropriate clause values for the OPEN statement
IF(file%initstat) THEN
IF(file%isOpen()) THEN
WRITE(emesg,'(a,i4,a)') 'Cannot open file (UNIT=', &
file%unitno,') File is already open!'
CALL file%e%raiseError(modName//'::'//myName//' - '//emesg)
ELSE
!STATUS clause value
IF(.NOT.file%isNew()) THEN
statusvar='OLD'
......@@ -658,11 +651,6 @@ SUBROUTINE open_fortran_file(file)
CALL file%setOpenStat(.TRUE.)
CALL file%setEOFStat(.FALSE.)
ENDIF
ENDIF
ELSE
CALL file%e%raiseError(modName//'::'//myName//' - '// &
'Cannot open file! Object has not been initialized!')
ENDIF
ENDSUBROUTINE open_fortran_file
!
!-------------------------------------------------------------------------------
......@@ -675,8 +663,7 @@ SUBROUTINE close_fortran_file(file)
CHARACTER(LEN=*),PARAMETER :: myName='CLOSE_FORTRAN_FILE'
CLASS(FortranFileType),INTENT(INOUT) :: file
IF(file%initstat) THEN
IF(file%isOpen()) THEN
IF(file%initstat .AND. file%isOpen()) THEN
CLOSE(UNIT=file%unitno,STATUS='KEEP',IOSTAT=ioerr)
IF(ioerr /= 0) THEN
WRITE(emesg,'(a,i4,a,i4)') 'Error closing file (UNIT=', &
......@@ -685,14 +672,6 @@ SUBROUTINE close_fortran_file(file)
ELSE
CALL file%setOpenStat(.FALSE.)
ENDIF
ELSE
WRITE(emesg,'(a,i4,a)') 'Cannot close file (UNIT=', &
file%unitno,') File is not open!'
CALL file%e%raiseDebug(modName//'::'//myName//' - '//emesg)
ENDIF
ELSE
CALL file%e%raiseDebug(modName//'::'//myName//' - '// &
'Cannot close file! File object has not been initialized!')
ENDIF
ENDSUBROUTINE close_fortran_file
!
......@@ -706,7 +685,7 @@ SUBROUTINE delete_fortran_file(file)
CHARACTER(LEN=*),PARAMETER :: myName='DELETE_FORTRAN_FILE'
CLASS(FortranFileType),INTENT(INOUT) :: file
IF(file%initstat) THEN
REQUIRE(file%initstat)
IF(file%isOpen()) THEN
CLOSE(UNIT=file%unitno,STATUS='DELETE',IOSTAT=ioerr)
IF(ioerr /= 0) THEN
......@@ -734,10 +713,6 @@ SUBROUTINE delete_fortran_file(file)
CALL file%setOpenStat(.FALSE.)
ENDIF
ENDIF
ELSE
CALL file%e%raiseDebug(modName//'::'//myName//' - '// &
'Cannot delete file! File object has not been initialized!')
ENDIF
ENDSUBROUTINE delete_fortran_file
!
!-------------------------------------------------------------------------------
......@@ -748,7 +723,7 @@ SUBROUTINE rewind_fortran_file(file)
CHARACTER(LEN=*),PARAMETER :: myName='REWIND_FORTRAN_FILE'
CLASS(FortranFileType),INTENT(INOUT) :: file
IF(file%initstat) THEN
REQUIRE(file%initstat)
IF(file%isOpen()) THEN
REWIND(UNIT=file%unitno,IOSTAT=ioerr)
CALL file%setEOFstat(.FALSE.)
......@@ -762,10 +737,6 @@ SUBROUTINE rewind_fortran_file(file)
'). File not is not open!'
CALL file%e%raiseDebug(modName//'::'//myName//' - '//emesg)
ENDIF
ELSE
CALL file%e%raiseDebug(modName//'::'//myName//' - '// &
'Cannot rewind file! File object has not been initialized!')
ENDIF
ENDSUBROUTINE rewind_fortran_file
!
!-------------------------------------------------------------------------------
......@@ -776,7 +747,7 @@ SUBROUTINE backspace_fortran_file(file)
CHARACTER(LEN=*),PARAMETER :: myName='BACKSPACE_FORTRAN_FILE'
CLASS(FortranFileType),INTENT(INOUT) :: file
IF(file%initstat) THEN
REQUIRE(file%initstat)
IF(file%isOpen()) THEN
BACKSPACE(UNIT=file%unitno,IOSTAT=ioerr)
IF(ioerr /= 0) THEN
......@@ -791,10 +762,6 @@ SUBROUTINE backspace_fortran_file(file)
'). File not is not open!'
CALL file%e%raiseDebug(modName//'::'//myName//' - '//emesg)
ENDIF
ELSE
CALL file%e%raiseDebug(modName//'::'// myName//' - '// &
'Cannot backspace file! File object has not been initialized!')
ENDIF
ENDSUBROUTINE backspace_fortran_file
!
!-------------------------------------------------------------------------------
......@@ -822,8 +789,10 @@ SUBROUTINE setStatus_fortran_file(file,status)
CHARACTER(LEN=*),PARAMETER :: myName='setStatus_fortran_file'
CLASS(FortranFileType),INTENT(INOUT) :: file
CHARACTER(LEN=*),INTENT(IN) :: status
!
CHARACTER(LEN=LEN(status)) :: new_status
IF(file%initstat) THEN
REQUIRE(file%initstat)
IF(.NOT.file%isOpen()) THEN
new_status=status
CALL toUPPER(new_status)
......@@ -845,10 +814,6 @@ SUBROUTINE setStatus_fortran_file(file,status)
CALL file%e%raiseError(modName//'::'//myName//' - File status '// &
'cannot be changed while file is open!')
ENDIF
ELSE
CALL file%e%raiseError(modName//'::'//myName//' - File status '// &
'cannot be changed on uninitialized file!')
ENDIF
ENDSUBROUTINE setStatus_fortran_file
!
!------------------------------------------------------------------------------
......
......@@ -68,8 +68,6 @@ PUBLIC :: InputFileType
!> Module name for error messages
CHARACTER(LEN=*),PARAMETER :: modName='FILETYPE_INPUT'
!> Scratch variable for IOSTAT values
INTEGER(SIK) :: ioerr
!> @brief Derived type object for an input file, it is an extension of the
!> @ref FileType_Fortran "FortranFileType" object.
......@@ -85,12 +83,6 @@ TYPE,EXTENDS(FortranFileType) :: InputFileType
LOGICAL(SBK),PRIVATE :: echostat=.FALSE.
!> Unit number for the file to echo result of fgetl to.
INTEGER(SIK),PRIVATE :: echounit=-1
!> The first character of oneline
CHARACTER(LEN=1),PRIVATE :: probe=''
!> The first character of the line before the line that was just read
CHARACTER(LEN=1),PRIVATE :: lastprobe=''
!
!List of type bound procedures (methods) for the Input File type
CONTAINS
!> @copybrief FileType_Input::init_inp_file
!> @copydetails FileType_Input::init_inp_file
......@@ -113,15 +105,6 @@ TYPE,EXTENDS(FortranFileType) :: InputFileType
!> @copybrief FileType_Input::getEchoUnit_inp_file
!> @copydetails FileType_Input::getEchoUnit_inp_file
PROCEDURE,PASS :: getEchoUnit => getEchoUnit_inp_file
!> @copybrief FileType_Input::getProbe_inp_file
!> @copydetails FileType_Input::getProbe_inp_file
PROCEDURE,PASS :: getProbe => getProbe_inp_file
!> @copybrief FileType_Input::rewind_inp_file
!> @copydetails FileType_Input::rewind_inp_file
PROCEDURE,PASS :: frewind => rewind_inp_file
!> @copybrief FileType_Input::backspace_inp_file
!> @copydetails FileType_Input::backspace_inp_file
PROCEDURE,PASS :: fbackspace => backspace_inp_file
ENDTYPE InputFileType
!
......@@ -176,31 +159,6 @@ SUBROUTINE init_inp_file(fileobj,unit,file,status,access,form, &
ENDSUBROUTINE init_inp_file
!
!-------------------------------------------------------------------------------
!> @brief Rewinds an Input file
!> @param file input file object.
!>
!> This is needed to reset probe.
!>
SUBROUTINE rewind_inp_file(file)
CLASS(InputFileType),INTENT(INOUT) :: file
file%probe=''
file%lastprobe=''
CALL rewind_fortran_file(file)
ENDSUBROUTINE rewind_inp_file
!
!-------------------------------------------------------------------------------
!> @brief Backspaces an Input file
!> @param file input file object.
!>
!> This is needed to maintain the correct value for probe.
!>
SUBROUTINE backspace_inp_file(file)
CLASS(InputFileType),INTENT(INOUT) :: file
CALL backspace_fortran_file(file)
file%probe=file%lastprobe
ENDSUBROUTINE backspace_inp_file
!
!-------------------------------------------------------------------------------
!> @brief Clears the log file object and resets its state to the unitialized
!> state.
!> @param file input file object.
......@@ -211,8 +169,6 @@ SUBROUTINE clear_inp_file(file,ldel)
LOGICAL(SBK) :: bool
file%echounit=-1
file%echostat=.FALSE.
file%probe=''
file%lastprobe=''
bool=.FALSE.
IF(PRESENT(ldel)) bool=ldel
CALL clear_fortran_file(file,bool)
......@@ -227,9 +183,10 @@ SUBROUTINE read_oneline_inp_file(file,oneline)
CHARACTER(LEN=*),PARAMETER :: myName='READ_ONELINE_INP_FILE'
CLASS(InputFileType),INTENT(INOUT) :: file
TYPE(StringType),INTENT(OUT) :: oneline
!
CHARACTER(LEN=256) :: buffer
CHARACTER(LEN=4) :: sioerr,sunit
INTEGER(SIK) :: buffer_size,eioerr
INTEGER(SIK) :: buffer_size,eioerr,ioerr
ioerr=0
IF(file%isOpen() .AND. .NOT.file%isEOF()) THEN
......@@ -243,7 +200,6 @@ SUBROUTINE read_oneline_inp_file(file,oneline)
ELSEIF(ioerr == IOSTAT_EOR) THEN
!Done reading line. Append last buffer to oneline.
oneline=oneline//TRIM(buffer)
file%lastprobe=file%probe
IF(file%echostat) THEN
WRITE(UNIT=file%echounit,FMT='(a)',IOSTAT=eioerr) TRIM(oneline)
IF(eioerr /= 0) THEN
......@@ -267,10 +223,7 @@ SUBROUTINE read_oneline_inp_file(file,oneline)
ENDIF
ENDDO
ENDIF
IF(LEN(oneline) > 0) THEN
file%probe=oneline%at(1)
ELSE
file%probe=''
IF(.NOT.(LEN(oneline) > 0)) THEN
oneline=' '
ENDIF
ENDSUBROUTINE read_oneline_inp_file
......@@ -310,7 +263,7 @@ SUBROUTINE setEchoUnit_inp_file(file,iunit)
CHARACTER(LEN=*),PARAMETER :: myName='SETECHOUNIT_INP_FILE'
CLASS(InputFileType),INTENT(INOUT) :: file
INTEGER(SIK),INTENT(IN) :: iunit
IF(0 < iunit .AND. iunit /= OUTPUT_UNIT .AND. iunit /= ERROR_UNIT) THEN
IF(0 < iunit .AND. ANY(iunit /= [OUTPUT_UNIT,ERROR_UNIT,INPUT_UNIT])) THEN
file%echounit=iunit
ELSE
CALL file%e%raiseError('Incorrect input to '//modName//'::'// &
......@@ -330,18 +283,4 @@ PURE FUNCTION getEchoUnit_inp_file(file) RESULT(iunit)
iunit=file%echounit
ENDFUNCTION getEchoUnit_inp_file
!
!-------------------------------------------------------------------------------
!> @brief Returns the value of the PROBE attribute of the input file type
!> object.
!> @param file the input file object
!> @returns c the value of file%probe
!>
PURE FUNCTION getProbe_inp_file(file) RESULT(c)
CLASS(InputFileType),INTENT(IN) :: file
CHARACTER(LEN=1) :: c
c=file%probe
ENDFUNCTION getProbe_inp_file
!
ENDMODULE FileType_Input
......@@ -408,15 +408,15 @@ SUBROUTINE countOccurrences_SchElm(this,inputFile,firstLine,lastLine,firstField,
REQUIRE(fstLine >= 0 .AND. fstLine <= lstLine)
REQUIRE(fstField >= 0 .AND. fstField <= lstField)
iline=0
iline=1
this%nOccurrences=0
DO WHILE(.NOT.atEndOfFile(inputFile))
CALL inputfile%fgetl(line)
DO WHILE(.NOT.(inputFile%isEOF() .OR. line%at(1) == DOT))
CALL stripComment(line)
iline=iline+1
IF(iline > lstLine) EXIT
IF(iline >= fstLine) THEN
IF(atContentLine(inputFile)) THEN
IF(line%at(1) /= BANG .AND. line%at(1) /= DOT) THEN
sttField=1; IF(iline == fstLine) sttField=MAX(fstField,sttField)
stpField=nFields(line); IF(iline == lstLine) stpField=MIN(lstField,stpField)
DO ifield=sttField,stpField
......@@ -425,6 +425,7 @@ SUBROUTINE countOccurrences_SchElm(this,inputFile,firstLine,lastLine,firstField,
ENDDO
ENDIF
ENDIF
CALL inputfile%fgetl(line)
ENDDO
CALL inputfile%frewind()
ENDSUBROUTINE countOccurrences_SchElm
......@@ -471,15 +472,15 @@ SUBROUTINE determineExtentsWithinTextFile_SchElm(this,inputFile,validElements,fi
IF(ALLOCATED(this%lastField)) DEALLOCATE(this%lastField); ALLOCATE(this%lastField(this%nOccurrences))
ioccur=0
iline=0
iline=1
readingThisElement=.FALSE.
DO WHILE(.NOT.atEndOfFile(inputFile))
CALL inputfile%fgetl(line)
DO WHILE(.NOT.(inputFile%isEOF() .OR. line%at(1) == DOT))
CALL stripComment(line)
iline=iline+1
IF(iline > lstLine) EXIT
IF(iline >= fstLine) THEN
IF(atContentLine(inputFile)) THEN
IF(line%at(1) /= BANG .AND. line%at(1) /= DOT) THEN
sttField=1; IF(iline == fstLine) sttField=MAX(fstField,sttField)
stpField=nFields(line); IF(iline == lstLine) stpField=MIN(lstField,stpField)
DO ifield=sttField,stpField
......@@ -499,6 +500,7 @@ SUBROUTINE determineExtentsWithinTextFile_SchElm(this,inputFile,validElements,fi
ENDIF
ENDIF
IF(readingThisElement) this%lastLine(ioccur)=iline
CALL inputfile%fgetl(line)
ENDDO
CALL inputfile%frewind()
ENDSUBROUTINE determineExtentsWithinTextFile_SchElm
......@@ -682,16 +684,17 @@ SUBROUTINE parse_SchPar(this,inputFile,paramList)
REQUIRE(inputFile%isOpen())
!Ensure no line in the input file exceeds the max line limit
DO WHILE(.NOT.atEndOfFile(inputFile))
CALL inputfile%fgetl(line)
DO WHILE(.NOT.(inputFile%isEOF() .OR. line%at(1) == DOT))
CALL stripComment(line)
IF(atContentLine(inputFile)) THEN
IF(line%at(1) /= BANG .AND. line%at(1) /= DOT) THEN
IF(LEN(line)>MAX_LINE_LEN) THEN
CALL eSchemaParser%raiseError(modName//'::'//myName// &
' - "A content line exceeds the max line limit of '//str(MAX_LINE_LEN)//' characters')
RETURN
ENDIF
ENDIF
CALL inputfile%fgetl(line)
ENDDO
CALL inputfile%frewind()
......@@ -889,15 +892,15 @@ SUBROUTINE parse_SchCrd(this,inputFile,paramList,ioccurCrd,pListPathBlk)
nEntries=SIZE(this%entry)
ALLOCATE(entryStr(nEntries))
entryStr=''
iline=0
iline=1
ientry=1
DO WHILE(.NOT.atEndOfFile(inputFile))
CALL inputfile%fgetl(line)
DO WHILE(.NOT.(inputFile%isEOF() .OR. line%at(1) == DOT))
CALL stripComment(line)
iline=iline+1
IF(iline > lstLine) EXIT
IF(iline >= fstLine) THEN
IF(atContentLine(inputFile)) THEN
IF(line%at(1) /= BANG .AND. line%at(1) /= DOT) THEN
sttField=1; IF(iline == fstLine) sttField=MAX(fstField+1,sttField)
stpField=nFields(line); IF(iline == lstLine) stpField=MIN(lstField,stpField)
DO ifield=sttField,stpField
......@@ -910,6 +913,7 @@ SUBROUTINE parse_SchCrd(this,inputFile,paramList,ioccurCrd,pListPathBlk)
ENDDO
ENDIF
ENDIF
CALL inputfile%fgetl(line)
ENDDO
CALL inputfile%frewind()
......@@ -1318,32 +1322,6 @@ FUNCTION findElementByName(elements,name) RESULT(index)
ENDFUNCTION findElementByName
!
!-------------------------------------------------------------------------------
!> @brief Determines if the input text file line is currently at End of the File
!> @param file the file currently being read
!> @param isEOF logical determining whether or not the file is at End of File
!>
FUNCTION atEndOfFile(file) RESULT(isEOF)
TYPE(InputFileType),INTENT(IN) :: file
LOGICAL(SBK) :: isEOF
REQUIRE(file%isOpen())
isEOF=file%isEOF() .OR. file%getProbe() == DOT
ENDFUNCTION atEndOfFile
!
!-------------------------------------------------------------------------------
!> @brief Determines if the input text file line contains readable content
!> @param file the file currently being read
!> @param hasContent logical determining whether or not the file has content
!>
FUNCTION atContentLine(file) RESULT(hasContent)
TYPE(InputFileType),INTENT(IN) :: file
LOGICAL(SBK) :: hasContent
REQUIRE(file%isOpen())
hasContent=file%getProbe() /= BANG .AND. file%getProbe() /= DOT
ENDFUNCTION atContentLine
!
!-------------------------------------------------------------------------------
!> @brief Checks to see if entry string is empty
!> @param string the string to be checked
!> @param isEmpty logical corresponding to if the entry string is empty
......
......@@ -54,11 +54,6 @@ SUBROUTINE testFortranFileType()
!Called for coverage/error checking
COMPONENT_TEST('%initialize()')
CALL testFile%fopen()
CALL testFile%fclose()
CALL testFile%fdelete()
CALL testFile%frewind()
CALL testFile%fbackspace()
CALL testFile%initialize(UNIT=OUTPUT_UNIT,FILE='./testFile.txt',STATUS='OOPS',&
ACCESS='OOPS',FORM='OOPS',POSITION='OOPS',ACTION='OOPS',PAD='OOPS',RECL=-1)
CALL testFile%initialize(UNIT=ERROR_UNIT,FILE='./testFile.txt',STATUS='OLD',&
......@@ -97,34 +92,21 @@ SUBROUTINE testFortranFileType()
ASSERT(testFile%isOpen(),'testFile%fopen()')
!Coverage/Error checking
CALL testFile%fopen()
CALL testFile2%initialize(UNIT=12,FILE='./testFile.txt')
CALL testFile%setStatus('NEW')
CALL e%setStopOnError(.TRUE.)
CALL testFile%fbackspace()
CALL testFile%frewind()
CALL e%setStopOnError(.FALSE.)
CALL testFile%fclose()
ASSERT(.NOT.(testFile%isOpen()),'%fclose()')
CALL testFile%fdelete()
INQUIRE(FILE='./testFile.txt',EXIST=lexist)
ASSERT(.NOT.lexist,'%fdelete()')
CALL testFile%clear()
!Coverage/Error checking
CALL testFile%fclose()
CALL testFile%fbackspace()
CALL testFile%frewind()
CALL testFile%setOpenStat(.TRUE.)
CALL testFile%fbackspace()
CALL testFile%frewind()
CALL testFile%initialize(UNIT=12,FILE='./testFile.txt')
CALL testFile2%initialize(UNIT=13,FILE='./testFile2',ACCESS='DIRECT', &
STATUS='NEW',FORM='UNFORMATTED',RECL=100*NUMERIC_STORAGE_SIZE, &
ACTION='WRITE')
CALL testFile2%fopen()
CALL testFile2%fdelete()
CALL testFile%clear()
CALL testFile%e%addSurrogate(e)
CALL testFile%initialize(UNIT=12,FILE='./testFile.txt',STATUS='OLD', &
ACCESS='DIRECT',ACTION='READ',RECL=100,FORM='FORMATTED')
......
......@@ -57,12 +57,7 @@ SUBROUTINE testInputFileType()
CALL testInpFile%fopen()
CALL testInpFile%fgetl(string)
ASSERT(TRIM(string) == 'sample oneline 1','%fgetl()')
ASSERT(testInpFile%getProbe() == 's','%getProbe()')
CALL testInpFile%frewind()
ASSERT(LEN_TRIM(testInpFile%getProbe()) == 0,'%frewind()')
CALL testInpFile%fgetl(string)
CALL testInpFile%fbackspace()
ASSERT(LEN_TRIM(testInpFile%getProbe()) == 0,'%fbackspace()')
CALL testFile%clear(.TRUE.)
CALL testInpFile%setEchoStat(.FALSE.)
CALL testInpFile%fgetl(string)
......
......@@ -57,9 +57,6 @@ ENDSUBROUTINE SetupError
!-------------------------------------------------------------------------------
SUBROUTINE testClear()
!Test clear
CALL testVTUFile%fopen()
testVTUFile%hasMesh=.TRUE.
!
CALL testVTUFile%clear()
ASSERT(.NOT.testVTUFile%isInit(),'isInit()')
ASSERT(.NOT.testVTUFile%isOpen(),'isOpen()')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment