diff --git a/src/IO.f90 b/src/IO.f90 index 6348c1c92..764d3a4c4 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -30,7 +30,6 @@ implicit none(type,external) IO_init, & IO_selfTest, & IO_read, & - IO_readlines, & IO_wrapLines, & IO_strPos, & IO_strValue, & @@ -63,53 +62,6 @@ subroutine IO_init() end subroutine IO_init -!-------------------------------------------------------------------------------------------------- -!> @brief Read ASCII file and split at EOL. -!-------------------------------------------------------------------------------------------------- -function IO_readlines(fileName) result(fileContent) - - character(len=*), intent(in) :: fileName - character(len=pSTRLEN), dimension(:), allocatable :: fileContent !< file content, separated per lines - - character(len=pSTRLEN) :: line - character(len=:), allocatable :: rawData - integer :: & - startPos, endPos, & - N_lines, & !< # lines in file - l - logical :: warned - - - rawData = IO_read(fileName) - - N_lines = count([(rawData(l:l) == IO_EOL,l=1,len(rawData))]) - allocate(fileContent(N_lines)) - -!-------------------------------------------------------------------------------------------------- -! split raw data at end of line - warned = .false. - startPos = 1 - l = 1 - do while (l <= N_lines) - endPos = startPos + scan(rawData(startPos:),IO_EOL) - 2 - if (endPos - startPos > pSTRLEN-1) then - line = rawData(startPos:startPos+pSTRLEN-1) - if (.not. warned) then - call IO_warning(207,trim(fileName),label1='line',ID1=l) - warned = .true. - end if - else - line = rawData(startPos:endpos) - end if - startPos = endPos + 2 ! jump to next line start - - fileContent(l) = trim(line)//'' - l = l + 1 - end do - -end function IO_readlines - - !-------------------------------------------------------------------------------------------------- !> @brief Read ASCII file. !> @details Proper Unix style (LF line endings and LF at EOF) is ensured. diff --git a/src/Marc/discretization_Marc.f90 b/src/Marc/discretization_Marc.f90 index 5e42180de..aa7d9b000 100644 --- a/src/Marc/discretization_Marc.f90 +++ b/src/Marc/discretization_Marc.f90 @@ -217,7 +217,7 @@ subroutine inputRead(elem,node0_elem,connectivity_elem,materialAt) 'MSC.Marc input deck') call result_closeJobFile() - inputFile = IO_readlines(trim(getSolverJobName())//InputFileExtension) + inputFile = readlines(trim(getSolverJobName())//InputFileExtension) call inputRead_fileFormat(fileFormatVersion, & inputFile) call inputRead_tableStyles(initialcondTableStyle,hypoelasticTableStyle, & @@ -249,6 +249,54 @@ subroutine inputRead(elem,node0_elem,connectivity_elem,materialAt) call inputRead_material(materialAt, & nElems,elem%nNodes,nameElemSet,mapElemSet,& initialcondTableStyle,inputFile) + +contains +!-------------------------------------------------------------------------------------------------- +!> @brief Read ASCII file and split at EOL. +!-------------------------------------------------------------------------------------------------- +function readlines(fileName) result(fileContent) + + character(len=*), intent(in) :: fileName + character(len=pSTRLEN), dimension(:), allocatable :: fileContent !< file content, separated per lines + + character(len=pSTRLEN) :: line + character(len=:), allocatable :: rawData + integer :: & + startPos, endPos, & + N_lines, & !< # lines in file + l + logical :: warned + + + rawData = IO_read(fileName) + + N_lines = count([(rawData(l:l) == IO_EOL,l=1,len(rawData))]) + allocate(fileContent(N_lines)) + +!-------------------------------------------------------------------------------------------------- +! split raw data at end of line + warned = .false. + startPos = 1 + l = 1 + do while (l <= N_lines) + endPos = startPos + scan(rawData(startPos:),IO_EOL) - 2 + if (endPos - startPos > pSTRLEN-1) then + line = rawData(startPos:startPos+pSTRLEN-1) + if (.not. warned) then + call IO_warning(207,trim(fileName),label1='line',ID1=l) + warned = .true. + end if + else + line = rawData(startPos:endpos) + end if + startPos = endPos + 2 ! jump to next line start + + fileContent(l) = trim(line)//'' + l = l + 1 + end do + +end function readlines + end subroutine inputRead diff --git a/src/test/test_IO.f90 b/src/test/test_IO.f90 index 0ec2495a0..6e260afa2 100644 --- a/src/test/test_IO.f90 +++ b/src/test/test_IO.f90 @@ -33,8 +33,6 @@ subroutine test_IO_run() str_out = IO_read(fname) if (rnd_str//IO_EOL /= str_out) error stop 'IO_read' - strarray_out = IO_readlines(fname) - if (rnd_str /= strarray_out(1)) error stop 'IO_readlines' end subroutine test_IO_run