preventing array index out of bounds in case of empty line, removed to goto statements
This commit is contained in:
parent
5214b93342
commit
9b99825ac6
48
code/IO.f90
48
code/IO.f90
|
@ -462,24 +462,30 @@ function IO_hybridIA(Nast,ODFfileName)
|
|||
real(pReal), dimension(:,:,:), allocatable :: dV_V
|
||||
character(len=80) :: line
|
||||
|
||||
call IO_open_file(999_pInt,ODFfileName)
|
||||
|
||||
!--- parse header of ODF file ---
|
||||
call IO_open_file(999_pInt,ODFfileName)
|
||||
IO_hybridIA = -1.0_pReal ! initialize return value for case of error
|
||||
|
||||
!--- limits in phi1, Phi, phi2 ---
|
||||
read(999,fmt=fileFormat,end=100) line
|
||||
myPos = IO_stringPos(line,3_pInt)
|
||||
if (myPos(1).ne.3) goto 100
|
||||
do i=1_pInt,3_pInt
|
||||
limits(i) = IO_floatValue(line,myPos,i)*INRAD
|
||||
enddo
|
||||
if (myPos(1) == 3) then ! found 3 chunks
|
||||
forall(i=1_pInt:3_pInt) limits(i) = IO_floatValue(line,myPos,i)*INRAD
|
||||
else ! wrong line format
|
||||
close(999)
|
||||
return
|
||||
endif
|
||||
|
||||
!--- deltas in phi1, Phi, phi2 ---
|
||||
read(999,fmt=fileFormat,end=100) line
|
||||
myPos = IO_stringPos(line,3_pInt)
|
||||
if (myPos(1).ne.3) goto 100
|
||||
do i=1_pInt,3_pInt
|
||||
deltas(i) = IO_floatValue(line,myPos,i)*INRAD
|
||||
enddo
|
||||
if (myPos(1) == 3) then ! found 3 chunks
|
||||
forall(i=1_pInt:3_pInt) deltas(i) = IO_floatValue(line,myPos,i)*INRAD
|
||||
else ! wrong line format
|
||||
close(999)
|
||||
return
|
||||
endif
|
||||
|
||||
steps = nint(limits/deltas,pInt)
|
||||
allocate(dV_V(steps(3),steps(2),steps(1)))
|
||||
|
||||
|
@ -569,12 +575,8 @@ function IO_hybridIA(Nast,ODFfileName)
|
|||
IO_hybridIA(3,i) = deltas(3)*(real(mod(bin ,steps(3)),pReal)+center) ! phi2
|
||||
binSet(j) = binSet(i)
|
||||
enddo
|
||||
close(999)
|
||||
return
|
||||
|
||||
! on error
|
||||
100 IO_hybridIA = -1.0_pReal
|
||||
close(999)
|
||||
100 close(999)
|
||||
|
||||
end function IO_hybridIA
|
||||
|
||||
|
@ -1124,8 +1126,11 @@ integer(pInt) function IO_countContinuousIntValues(myUnit)
|
|||
do
|
||||
read(myUnit,'(A300)',end=100) line
|
||||
myPos = IO_stringPos(line,maxNchunks)
|
||||
if (IO_lc(IO_stringValue(line,myPos,2_pInt)) == 'to' ) then ! found range indicator
|
||||
IO_countContinuousIntValues = 1_pInt + IO_intValue(line,myPos,3_pInt) - IO_intValue(line,myPos,1_pInt)
|
||||
if (myPos(1) < 1_pInt) then ! empty line
|
||||
exit
|
||||
elseif (IO_lc(IO_stringValue(line,myPos,2_pInt)) == 'to' ) then ! found range indicator
|
||||
IO_countContinuousIntValues = 1_pInt + IO_intValue(line,myPos,3_pInt) &
|
||||
- IO_intValue(line,myPos,1_pInt)
|
||||
exit ! only one single range indicator allowed
|
||||
else if (IO_lc(IO_stringValue(line,myPos,2_pInt)) == 'of' ) then ! found multiple entries indicator
|
||||
IO_countContinuousIntValues = IO_intValue(line,myPos,1_pInt)
|
||||
|
@ -1190,7 +1195,9 @@ function IO_continuousIntValues(myUnit,maxN,lookupName,lookupMap,lookupMaxN)
|
|||
do
|
||||
read(myUnit,'(A65536)',end=100) line
|
||||
myPos = IO_stringPos(line,maxNchunks)
|
||||
if (verify(IO_stringValue(line,myPos,1_pInt),'0123456789') > 0) then ! a non-int, i.e. set name
|
||||
if (myPos(1) < 1_pInt) then ! empty line
|
||||
exit
|
||||
elseif (verify(IO_stringValue(line,myPos,1_pInt),'0123456789') > 0) then ! a non-int, i.e. set name
|
||||
do i = 1_pInt, lookupMaxN ! loop over known set names
|
||||
if (IO_stringValue(line,myPos,1_pInt) == lookupName(i)) then ! found matching name
|
||||
IO_continuousIntValues = lookupMap(:,i) ! return resp. entity list
|
||||
|
@ -1255,7 +1262,6 @@ function IO_continuousIntValues(myUnit,maxN,lookupName,lookupMap,lookupMaxN)
|
|||
enddo
|
||||
else ! read individual elem nums
|
||||
do i = 1_pInt,myPos(1)
|
||||
! write(*,*)'IO_CIV-int',IO_intValue(line,myPos,i)
|
||||
IO_continuousIntValues(1) = IO_continuousIntValues(1) + 1_pInt
|
||||
IO_continuousIntValues(1+IO_continuousIntValues(1)) = IO_intValue(line,myPos,i)
|
||||
enddo
|
||||
|
@ -1265,6 +1271,10 @@ function IO_continuousIntValues(myUnit,maxN,lookupName,lookupMap,lookupMaxN)
|
|||
|
||||
100 end function IO_continuousIntValues
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief returns format string for integer values without leading zeros
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function IO_intOut(intToPrint)
|
||||
implicit none
|
||||
character(len=16) :: N_Digits
|
||||
|
|
Loading…
Reference in New Issue