Skip to content

Commit 283fe20

Browse files
committed
Update strings.f90
Update str_split. Correcting logic that was causing crashes with Intel compilers. The function will now append a delimiter to the end of the input string prior to work to get the column string. This is done because the logic of finding the column is based on a right-justified delimiter.
1 parent 92d8cf5 commit 283fe20

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

strings.f90

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,27 @@ function str_split(str,delim,col) result(strout)
106106
character(len=1), intent(in) :: delim
107107
integer, intent(in) :: col
108108
character(len=:), allocatable :: strout
109-
integer :: i,cnt
109+
character(len=:), allocatable :: ctemp
110+
character(len=:), allocatable :: cwork
111+
integer :: i,cnt,lastpos
110112
cnt=0
113+
lastpos=0
111114
if(col.le.0.or.col.gt.(str_count(str,delim)+1).or.str_count(str,delim).eq.0)then
112115
strout=str
113116
return
114117
endif
115-
do i=1,len_trim(str)
116-
if(str(i:i).eq.delim)then
118+
ctemp=str//delim
119+
do i=1,len_trim(ctemp)
120+
if(ctemp(i:i).eq.delim)then
117121
cnt=cnt+1
118122
if(cnt.eq.col)then
123+
cwork=ctemp(lastpos+1:i-1)
119124
exit
120-
else
121-
strout=""
122125
endif
123-
else
124-
strout=strout//str(i:i)
126+
lastpos=i
125127
endif
126128
end do
129+
strout=cwork
127130
end function str_split
128131

129132
! -------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)