Skip to content

Commit

Permalink
number_of_columns: read whole line (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
perazz authored Jan 30, 2025
2 parents 52d3baa + 4708a0a commit 399f9a1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/stdlib_io.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ contains

integer :: ios, skiprows_, i
character :: c
character(len=:), allocatable :: line
logical :: lastblank

skiprows_ = optval(skiprows, 0)
Expand All @@ -261,12 +262,15 @@ contains
do i = 1, skiprows_
read(s, *)
end do

number_of_columns = 0

! Read first non-skipped line as a whole
call getline(s, line, ios)
if (ios/=0 .or. .not.allocated(line)) return

lastblank = .true.
do
read(s, '(a)', advance='no', iostat=ios) c
if (ios /= 0) exit
do i = 1,len(line)
c = line(i:i)
if (lastblank .and. .not. is_blank(c)) number_of_columns = number_of_columns + 1
lastblank = is_blank(c)
end do
Expand Down

0 comments on commit 399f9a1

Please sign in to comment.