Commit 2fe4025f authored by Graham, Aaron's avatar Graham, Aaron
Browse files

Merge branch 'DBCFileTypeFortran' into 'master'

DBC filetype_fortran/simplify filetype_input

See merge request futility/Futility!343
parents b9c0cbbd 43df951d
Pipeline #159184 passed with stage
in 2 minutes and 2 seconds
......@@ -373,7 +373,7 @@ MODULE CommandLineProcessor
ENDDO
ENDIF
ELSE
CALL GET_COMMAND(cmdline,cmdlinelength,ierr)
CALL GET_COMMAND(cmdline,cmdlinelength,ierr)
IF(ierr /= 0) CALL clp%e%raiseError(modName//'::'//myName// &
' - problem getting command line.')
clp%narg=nFields(cmdline)-1
......
This diff is collapsed.
......@@ -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)
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)
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)
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)
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