handling files without LF at last line correctly
This commit is contained in:
parent
4f666057a6
commit
b51c3b5a07
|
@ -208,7 +208,7 @@ recursive function IO_recursiveRead(fileName,cnt) result(fileContent)
|
||||||
! count lines to allocate string array
|
! count lines to allocate string array
|
||||||
myTotalLines = 0_pInt
|
myTotalLines = 0_pInt
|
||||||
do l=1_pInt, len(rawData)
|
do l=1_pInt, len(rawData)
|
||||||
if (rawData(l:l) == new_line('')) myTotalLines = myTotalLines+1
|
if (rawData(l:l) == new_line('') .or. l==len(rawData)) myTotalLines = myTotalLines+1 ! end of line or end of file without new line
|
||||||
enddo
|
enddo
|
||||||
allocate(fileContent(myTotalLines))
|
allocate(fileContent(myTotalLines))
|
||||||
|
|
||||||
|
@ -222,6 +222,7 @@ recursive function IO_recursiveRead(fileName,cnt) result(fileContent)
|
||||||
do while (startPos <= len(rawData))
|
do while (startPos <= len(rawData))
|
||||||
l = l + 1_pInt
|
l = l + 1_pInt
|
||||||
endPos = endPos + scan(rawData(startPos:),new_line(''))
|
endPos = endPos + scan(rawData(startPos:),new_line(''))
|
||||||
|
if(endPos < startPos) endPos = len(rawData) ! end of file without end of line
|
||||||
if(endPos - startPos >256) call IO_error(107_pInt,ext_msg=trim(fileName))
|
if(endPos - startPos >256) call IO_error(107_pInt,ext_msg=trim(fileName))
|
||||||
line = rawData(startPos:endPos-1_pInt)
|
line = rawData(startPos:endPos-1_pInt)
|
||||||
startPos = endPos + 1_pInt
|
startPos = endPos + 1_pInt
|
||||||
|
@ -235,6 +236,7 @@ recursive function IO_recursiveRead(fileName,cnt) result(fileContent)
|
||||||
fileContent = [ fileContent(1:l-1_pInt), includedContent, [(dummy,i=1,missingLines)] ] ! add content and grow array
|
fileContent = [ fileContent(1:l-1_pInt), includedContent, [(dummy,i=1,missingLines)] ] ! add content and grow array
|
||||||
l = l - 1_pInt + size(includedContent)
|
l = l - 1_pInt + size(includedContent)
|
||||||
else recursion
|
else recursion
|
||||||
|
write(6,*) fileName, l, line;flush(6)
|
||||||
fileContent(l) = line
|
fileContent(l) = line
|
||||||
endif recursion
|
endif recursion
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue