Skip to content

Commit

Permalink
loadtxt/savetxt: do not require space after last entry
Browse files Browse the repository at this point in the history
  • Loading branch information
perazz committed Sep 27, 2024
1 parent c663dc1 commit 9ac942d
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions src/stdlib_io.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -144,53 +144,28 @@ contains
do i = 1, skiprows_
read(s, *)
end do

#:if 'real' in t1

! Default to format used for savetxt if fmt not specified.
fmt_ = optval(fmt, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",1x))")

if ( fmt_ == '*' ) then
! Use list directed read if user has specified fmt='*'
do i = 1, max_rows_
read (s,*) d(i, :)
enddo
else
! Otherwise pass default or user specified fmt string.
do i = 1, max_rows_
read (s,fmt_) d(i, :)
enddo
endif
#:if 'real' in t1
fmt_ = optval(fmt, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",:,1x))")
#:elif 'complex' in t1
! Default to format used for savetxt if fmt not specified.
fmt_ = optval(fmt, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",1x))")
if ( fmt_ == '*' ) then
! Use list directed read if user has specified fmt='*'
do i = 1, max_rows_
read (s,*) d(i, :)
enddo
else
! Otherwise pass default or user specified fmt string.
do i = 1, max_rows_
read (s,fmt_) d(i, :)
enddo
endif
fmt_ = optval(fmt, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",:,1x))")
#:else
! Default to list directed for integer
fmt_ = optval(fmt, "*")
! Use list directed read if user has specified fmt='*'
#:endif

if ( fmt_ == '*' ) then
! Use list directed read if user has specified fmt='*'
do i = 1, max_rows_
read (s,*) d(i, :)
enddo
else
! Otherwise pass default user specified fmt string.
! Otherwise pass default or user specified fmt string.
do i = 1, max_rows_
read (s,fmt_) d(i, :)
enddo
endif

#:endif

close(s)

end subroutine loadtxt_${t1[0]}$${k1}$
Expand Down Expand Up @@ -222,11 +197,11 @@ contains
s = open(filename, "w")
do i = 1, size(d, 1)
#:if 'real' in t1
write(s, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",1x))") d(i, :)
write(s, "(*"//FMT_REAL_${k1}$(1:len(FMT_REAL_${k1}$)-1)//",:,1x))") d(i, :)
#:elif 'complex' in t1
write(s, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",1x))") d(i, :)
write(s, "(*"//FMT_COMPLEX_${k1}$(1:len(FMT_COMPLEX_${k1}$)-1)//",:,1x))") d(i, :)
#:elif 'integer' in t1
write(s, "(*"//FMT_INT(1:len(FMT_INT)-1)//",1x))") d(i, :)
write(s, "(*"//FMT_INT(1:len(FMT_INT)-1)//",:,1x))") d(i, :)
#:else
write(s, *) d(i, :)
#:endif
Expand Down

0 comments on commit 9ac942d

Please sign in to comment.