Skip to content

Commit 9ac942d

Browse files
committed
loadtxt/savetxt: do not require space after last entry
1 parent c663dc1 commit 9ac942d

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

src/stdlib_io.fypp

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -144,53 +144,28 @@ contains
144144
do i = 1, skiprows_
145145
read(s, *)
146146
end do
147-
148-
#:if 'real' in t1
147+
149148
! Default to format used for savetxt if fmt not specified.
150-
fmt_ = optval(fmt, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",1x))")
151-
152-
if ( fmt_ == '*' ) then
153-
! Use list directed read if user has specified fmt='*'
154-
do i = 1, max_rows_
155-
read (s,*) d(i, :)
156-
enddo
157-
else
158-
! Otherwise pass default or user specified fmt string.
159-
do i = 1, max_rows_
160-
read (s,fmt_) d(i, :)
161-
enddo
162-
endif
149+
#:if 'real' in t1
150+
fmt_ = optval(fmt, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",:,1x))")
163151
#:elif 'complex' in t1
164-
! Default to format used for savetxt if fmt not specified.
165-
fmt_ = optval(fmt, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",1x))")
166-
if ( fmt_ == '*' ) then
167-
! Use list directed read if user has specified fmt='*'
168-
do i = 1, max_rows_
169-
read (s,*) d(i, :)
170-
enddo
171-
else
172-
! Otherwise pass default or user specified fmt string.
173-
do i = 1, max_rows_
174-
read (s,fmt_) d(i, :)
175-
enddo
176-
endif
152+
fmt_ = optval(fmt, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",:,1x))")
177153
#:else
178-
! Default to list directed for integer
179154
fmt_ = optval(fmt, "*")
180-
! Use list directed read if user has specified fmt='*'
155+
#:endif
156+
181157
if ( fmt_ == '*' ) then
158+
! Use list directed read if user has specified fmt='*'
182159
do i = 1, max_rows_
183160
read (s,*) d(i, :)
184161
enddo
185162
else
186-
! Otherwise pass default user specified fmt string.
163+
! Otherwise pass default or user specified fmt string.
187164
do i = 1, max_rows_
188165
read (s,fmt_) d(i, :)
189166
enddo
190167
endif
191168

192-
#:endif
193-
194169
close(s)
195170

196171
end subroutine loadtxt_${t1[0]}$${k1}$
@@ -222,11 +197,11 @@ contains
222197
s = open(filename, "w")
223198
do i = 1, size(d, 1)
224199
#:if 'real' in t1
225-
write(s, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",1x))") d(i, :)
200+
write(s, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",:,1x))") d(i, :)
226201
#:elif 'complex' in t1
227-
write(s, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",1x))") d(i, :)
202+
write(s, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",:,1x))") d(i, :)
228203
#:elif 'integer' in t1
229-
write(s, "(*"//FMT_INT(1:len(FMT_INT)-1)//",1x))") d(i, :)
204+
write(s, "(*"//FMT_INT(1:len(FMT_INT)-1)//",:,1x))") d(i, :)
230205
#:else
231206
write(s, *) d(i, :)
232207
#:endif

0 commit comments

Comments
 (0)