bugfix
- IO_read sanities files such that they end with EOL (unless 0 byte) - IO_readline simply counts EOL to determine number of lines
This commit is contained in:
parent
9cd9ee71c5
commit
5c544a6e4e
12
src/IO.f90
12
src/IO.f90
|
@ -85,7 +85,6 @@ function IO_readlines(fileName) result(fileContent)
|
||||||
do l=1, len(rawData)
|
do l=1, len(rawData)
|
||||||
if (rawData(l:l) == IO_EOL) N_lines = N_lines+1
|
if (rawData(l:l) == IO_EOL) N_lines = N_lines+1
|
||||||
enddo
|
enddo
|
||||||
if (l>1) then; if(rawData(l-1:l-1) /= IO_EOL) N_lines = N_lines+1; endif ! no EOL@EOF, need exception for empty file
|
|
||||||
allocate(fileContent(N_lines))
|
allocate(fileContent(N_lines))
|
||||||
|
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
@ -94,7 +93,7 @@ function IO_readlines(fileName) result(fileContent)
|
||||||
startPos = 1
|
startPos = 1
|
||||||
l = 1
|
l = 1
|
||||||
do while (l <= N_lines)
|
do while (l <= N_lines)
|
||||||
endPos = merge(startPos + scan(rawData(startPos:),IO_EOL) - 2,len(rawData)-1,l /= N_lines)
|
endPos = startPos + scan(rawData(startPos:),IO_EOL) - 2
|
||||||
if (endPos - startPos > pStringLen-1) then
|
if (endPos - startPos > pStringLen-1) then
|
||||||
line = rawData(startPos:startPos+pStringLen-1)
|
line = rawData(startPos:startPos+pStringLen-1)
|
||||||
if (.not. warned) then
|
if (.not. warned) then
|
||||||
|
@ -114,7 +113,8 @@ end function IO_readlines
|
||||||
|
|
||||||
|
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
!> @brief reads an entire ASCII file into a string
|
!> @brief read ASCII file into a string
|
||||||
|
!> @details ensures that the string ends with a new line (expected UNIX behavior)
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
function IO_read(fileName) result(fileContent)
|
function IO_read(fileName) result(fileContent)
|
||||||
|
|
||||||
|
@ -130,10 +130,14 @@ function IO_read(fileName) result(fileContent)
|
||||||
status='old', position='rewind', action='read',iostat=myStat)
|
status='old', position='rewind', action='read',iostat=myStat)
|
||||||
if(myStat /= 0) call IO_error(100,ext_msg=trim(fileName))
|
if(myStat /= 0) call IO_error(100,ext_msg=trim(fileName))
|
||||||
allocate(character(len=fileLength)::fileContent)
|
allocate(character(len=fileLength)::fileContent)
|
||||||
|
if(fileLength==0) return
|
||||||
|
|
||||||
read(fileUnit,iostat=myStat) fileContent
|
read(fileUnit,iostat=myStat) fileContent
|
||||||
if(myStat > 0) call IO_error(102,ext_msg=trim(fileName)) ! <0 for ifort (https://software.intel.com/en-us/comment/1960081)
|
if(myStat /= 0) call IO_error(102,ext_msg=trim(fileName))
|
||||||
close(fileUnit)
|
close(fileUnit)
|
||||||
|
|
||||||
|
if(fileContent(fileLength:fileLength) /= IO_EOL) fileContent = fileContent//IO_EOL ! ensure EOL@EOF
|
||||||
|
|
||||||
end function IO_read
|
end function IO_read
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue