8

I want to read a line in a file, which includes three real numbers, without advancing the pointer. So I wrote: (TXT is the variable representing my file which has a value of 80)

read(TXT, *, ADVANCE='NO') (numbers(i),i=1,3)

However, I got an error message saying:

"error #6568: This use of the ADVANCE, SIZE, or EOR specifier is invalid."

So how should I write it to make it correct?

Thanks.

Fortranner
  • 2,525
  • 2
  • 22
  • 25
FalloutRanger
  • 127
  • 2
  • 8
  • If the reason you don't want to advance to the next line is that there is more data to read on the line, a common approach is to read the whole line into a string using the "(a)" format and then repeatedly read from the string. – Fortranner Jun 24 '14 at 14:54

1 Answers1

9

You can use advance='no' only with an explicit format. The reason is the following : advance='no' just avoids to go to the next record (notice that the file pointer advances anyway, just after the last read value); but with a directed list (format *), one doesn't know how many record are involved by your read statement (the three numbers may be written on four lines for instance).

Francois Jacq
  • 1,244
  • 10
  • 18
  • Also note that `ADVANCE` can only be used for reading from an external unit. I got burned trying to read from a character array. – pattivacek Feb 16 '17 at 22:24