Skip to main content

7.5) All On One Line (cont'd)


However, the code below will not be successful in obtaining the data.

open(22,file=’input.dat’)
read(22,*) a
read(22,*) b
read(22,*) c

The reason is that the read(22,*) a will read the values from the first line and it only requires one value. Once the read statement is finished, a marker in the input file is moved to the second line because the first read statement is complete. Now the read(22,*) b will have no data to read in because the second line has no data on it, and the same for read(22,*) c.

So just be careful about how your data is arranged in the input file and whether or not your read statement is on one or many lines.