need to handle case of zero length file when splitting

This commit is contained in:
Martin Diehl 2020-06-05 13:38:40 +02:00
parent f24a580554
commit a9e0e93213
2 changed files with 4 additions and 3 deletions

View File

@ -11,7 +11,6 @@ module IO
implicit none implicit none
private private
character(len=*), parameter, public :: & character(len=*), parameter, public :: &
IO_EOF = '#EOF#', & !< end of file string
IO_WHITESPACE = achar(44)//achar(32)//achar(9)//achar(10)//achar(13) !< whitespace characters IO_WHITESPACE = achar(44)//achar(32)//achar(9)//achar(10)//achar(13) !< whitespace characters
character, parameter, public :: & character, parameter, public :: &
IO_EOL = new_line('DAMASK'), & !< end of line character IO_EOL = new_line('DAMASK'), & !< end of line character
@ -86,6 +85,7 @@ 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 +94,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 = startPos + scan(rawData(startPos:),IO_EOL) - 2 endPos = merge(startPos + scan(rawData(startPos:),IO_EOL) - 2,len(rawData),l /= N_lines)
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

View File

@ -140,7 +140,8 @@ program DAMASK_grid
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
! reading information from load case file and to sanity checks ! reading information from load case file and to sanity checks
fileContent = IO_read_ASCII(trim(loadCaseFile)) fileContent = IO_readlines(trim(loadCaseFile))
if(size(fileContent) == 0) call IO_error(307,ext_msg='No load case specified')
allocate (loadCases(0)) ! array of load cases allocate (loadCases(0)) ! array of load cases
do currentLoadCase = 1, size(fileContent) do currentLoadCase = 1, size(fileContent)