It's true that 20-odd lines of code is not large in current terms, but
Peng Yu has identified what I think is an omission in modern Fortran.
The character type was ahead of its time when introduced in Fortran77
but has not advanced much since. Allocatable strings can get their
length set on assignment but not when present in a READ statement, and
allocatable strings really only work for scalars.
Just for the benefit of Peng Yu: the traditional way of solving this is
to choose a character length much longer than any line you think you can
possibly encounter, then trim it on output.
For example:
program demo
implicit none
character(len=10000) :: buffer
read(*, '(a)') buffer
write(*,*) 'trimmed length=', len_trim(buffer), trim(buffer)
end program
That's a bit of a bodge, and rather inefficient, but if you want
convenience and efficiency in handling text, Fortran is perhaps not the
best choice of language.
--
Clive Page