Reading values from text file of unknown structure

A list-directed read of array x will read values from each line and skip to the next line when the line is exhausted, until x is filled. For example the output with gfortran of the code

implicit none
real :: x(8)
open (unit=20, file="numbers.txt", action="read")
read (20, *) x
print*,x
end

for the file numbers.txt containing

1.1 2.1 3.1
4.1 5.1
6.1
7.1 8.1

is

   1.10000002       2.09999990       3.09999990       4.09999990       5.09999990       6.09999990       7.09999990       8.10000038    ```
1 Like