legacy read function, only needed by MSC.Marc

This commit is contained in:
Martin Diehl 2024-02-04 07:49:47 +01:00 committed by achalhp
parent d153925973
commit 12d7ee165b
3 changed files with 49 additions and 51 deletions

View File

@ -30,7 +30,6 @@ implicit none(type,external)
IO_init, & IO_init, &
IO_selfTest, & IO_selfTest, &
IO_read, & IO_read, &
IO_readlines, &
IO_wrapLines, & IO_wrapLines, &
IO_strPos, & IO_strPos, &
IO_strValue, & IO_strValue, &
@ -63,53 +62,6 @@ subroutine IO_init()
end 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. !> @brief Read ASCII file.
!> @details Proper Unix style (LF line endings and LF at EOF) is ensured. !> @details Proper Unix style (LF line endings and LF at EOF) is ensured.

View File

@ -217,7 +217,7 @@ subroutine inputRead(elem,node0_elem,connectivity_elem,materialAt)
'MSC.Marc input deck') 'MSC.Marc input deck')
call result_closeJobFile() call result_closeJobFile()
inputFile = IO_readlines(trim(getSolverJobName())//InputFileExtension) inputFile = readlines(trim(getSolverJobName())//InputFileExtension)
call inputRead_fileFormat(fileFormatVersion, & call inputRead_fileFormat(fileFormatVersion, &
inputFile) inputFile)
call inputRead_tableStyles(initialcondTableStyle,hypoelasticTableStyle, & call inputRead_tableStyles(initialcondTableStyle,hypoelasticTableStyle, &
@ -249,6 +249,54 @@ subroutine inputRead(elem,node0_elem,connectivity_elem,materialAt)
call inputRead_material(materialAt, & call inputRead_material(materialAt, &
nElems,elem%nNodes,nameElemSet,mapElemSet,& nElems,elem%nNodes,nameElemSet,mapElemSet,&
initialcondTableStyle,inputFile) 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 end subroutine inputRead

View File

@ -33,8 +33,6 @@ subroutine test_IO_run()
str_out = IO_read(fname) str_out = IO_read(fname)
if (rnd_str//IO_EOL /= str_out) error stop 'IO_read' 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 end subroutine test_IO_run