@@ -1100,57 +1100,57 @@ pure subroutine split(str,token,chunk_size,vals)
1100
1100
integer ,dimension (:),allocatable :: itokens
1101
1101
logical :: finished ! ! if we are finished counting the tokens
1102
1102
1103
- temp = str ! make a copy of the string
1104
- len_token = len (token) ! length of the token
1105
- n_tokens = 0 ! initialize the number of token counter
1106
- j = 0 ! length of string removed
1103
+ temp = str ! make a copy of the string
1104
+ len_token = len (token) ! length of the token
1105
+ n_tokens = 0 ! initialize the number of token counter
1106
+ j = 0 ! length of string removed
1107
1107
1108
1108
! first, count the number of times the token appears in the string
1109
1109
do
1110
- len_str = len (temp) ! length of the string
1111
- i = index (temp,token) ! location of the next token
1112
- if (i<= 0 ) exit ! no more tokens found
1110
+ len_str = len (temp) ! length of the string
1111
+ i = index (temp,token) ! location of the next token
1112
+ if (i<= 0 ) exit ! no more tokens found
1113
1113
call expand_vector(itokens,n_tokens,chunk_size,i+ j) ! save the token location
1114
- if (i+ len_token> len_str) exit ! if the last bit of the string is a token
1114
+ if (i+ len_token> len_str) exit ! if the last bit of the string is a token
1115
1115
j = j + i
1116
- temp = temp(i+ len_token:len_str) ! remove previously scanned part of string
1116
+ temp = temp(i+ len_token:len_str) ! remove previously scanned part of string
1117
1117
end do
1118
1118
call expand_vector(itokens,n_tokens,chunk_size,finished= .true. ) ! resize the vector
1119
1119
1120
1120
allocate (vals(n_tokens+1 ))
1121
1121
1122
1122
if (n_tokens> 0 ) then
1123
1123
1124
- len_str = len (str)
1125
-
1126
- i1 = 1
1127
- i2 = itokens(1 )- 1
1128
- if (n_tokens> 1 ) then
1129
- vals(1 )% str = str(i1:i2)
1130
- else
1131
- vals(1 )% str = ' ' ! the first character is a token
1132
- end if
1133
-
1134
- ! 1 2 3
1135
- ! 'a,b,c,d'
1136
-
1137
- do i= 2 ,n_tokens
1138
- i1 = itokens(i-1 )+ len_token
1139
- i2 = itokens(i)- 1
1140
- if (i2>= i1) then
1141
- vals(i)% str = str(i1:i2)
1142
- else
1143
- vals(i)% str = ' ' ! empty element (e.g., 'abc,,def')
1144
- end if
1145
- end do
1146
-
1147
- i1 = itokens(n_tokens) + len_token
1148
- i2 = len_str
1149
- if (itokens(n_tokens)+ len_token<= len_str) then
1150
- vals(n_tokens+1 )% str = str(i1:i2)
1151
- else
1152
- vals(n_tokens+1 )% str = ' ' ! the last character was a token
1153
- end if
1124
+ len_str = len (str)
1125
+
1126
+ i1 = 1
1127
+ i2 = itokens(1 )- 1
1128
+ if (n_tokens> 1 ) then
1129
+ vals(1 )% str = str(i1:i2)
1130
+ else
1131
+ vals(1 )% str = ' ' ! the first character is a token
1132
+ end if
1133
+
1134
+ ! 1 2 3
1135
+ ! 'a,b,c,d'
1136
+
1137
+ do i= 2 ,n_tokens
1138
+ i1 = itokens(i-1 )+ len_token
1139
+ i2 = itokens(i)- 1
1140
+ if (i2>= i1) then
1141
+ vals(i)% str = str(i1:i2)
1142
+ else
1143
+ vals(i)% str = ' ' ! empty element (e.g., 'abc,,def')
1144
+ end if
1145
+ end do
1146
+
1147
+ i1 = itokens(n_tokens) + len_token
1148
+ i2 = len_str
1149
+ if (itokens(n_tokens)+ len_token<= len_str) then
1150
+ vals(n_tokens+1 )% str = str(i1:i2)
1151
+ else
1152
+ vals(n_tokens+1 )% str = ' ' ! the last character was a token
1153
+ end if
1154
1154
1155
1155
else
1156
1156
! no tokens present, so just return the original string:
0 commit comments