Skip to content

Commit 5a789aa

Browse files
committed
number_of_columns: use getline instead of non-advancing io
1 parent 6ec8cd0 commit 5a789aa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/stdlib_io.fypp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ contains
252252

253253
integer :: ios, skiprows_, i
254254
character :: c
255+
character(len=:), allocatable :: line
255256
logical :: lastblank
256257

257258
skiprows_ = optval(skiprows, 0)
@@ -261,12 +262,16 @@ contains
261262
do i = 1, skiprows_
262263
read(s, *)
263264
end do
264-
265+
265266
number_of_columns = 0
267+
268+
! Read first non-skipped line as a whole
269+
call getline(s, line, ios)
270+
if (ios/=0 .or. .not.allocated(line)) return
271+
266272
lastblank = .true.
267-
do
268-
read(s, '(a)', advance='no', iostat=ios) c
269-
if (ios /= 0) exit
273+
do i = 1,len(line)
274+
c = line(i:i)
270275
if (lastblank .and. .not. is_blank(c)) number_of_columns = number_of_columns + 1
271276
lastblank = is_blank(c)
272277
end do

0 commit comments

Comments
 (0)