diff --git a/src/IO.f90 b/src/IO.f90 index c97dcfa9c..39eb0fb70 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -208,7 +208,7 @@ recursive function IO_recursiveRead(fileName,cnt) result(fileContent) ! count lines to allocate string array myTotalLines = 0_pInt 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 allocate(fileContent(myTotalLines)) @@ -222,6 +222,7 @@ recursive function IO_recursiveRead(fileName,cnt) result(fileContent) do while (startPos <= len(rawData)) l = l + 1_pInt 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)) line = rawData(startPos:endPos-1_pInt) startPos = endPos + 1_pInt diff --git a/src/material.f90 b/src/material.f90 index 812b0c55d..45c613420 100644 --- a/src/material.f90 +++ b/src/material.f90 @@ -1144,6 +1144,10 @@ subroutine material_populateGrains do e = 1_pInt, mesh_NcpElems homog = mesh_element(3,e) micro = mesh_element(4,e) + if (homog < 1_pInt .or. homog > size(Nelems,1)) & + call IO_error(154_pInt,e,0_pInt,0_pInt) + if (micro < 1_pInt .or. micro > size(Nelems,2)) & + call IO_error(155_pInt,e,0_pInt,0_pInt) Nelems(homog,micro) = Nelems(homog,micro) + 1_pInt enddo allocate(elemsOfHomogMicro(size(config_homogenization),size(config_microstructure))) @@ -1163,10 +1167,6 @@ subroutine material_populateGrains t = FE_geomtype(mesh_element(2,e)) homog = mesh_element(3,e) micro = mesh_element(4,e) - if (homog < 1_pInt .or. homog > size(config_homogenization)) & ! out of bounds - call IO_error(154_pInt,e,0_pInt,0_pInt) - if (micro < 1_pInt .or. micro > size(config_microstructure)) & ! out of bounds - call IO_error(155_pInt,e,0_pInt,0_pInt) if (microstructure_elemhomo(micro)) then ! how many grains are needed at this element? dGrains = homogenization_Ngrains(homog) ! only one set of Ngrains (other IPs are plain copies) else