Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-advancing read in Fortran with free format

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.

like image 331
FalloutRanger Avatar asked Jun 24 '14 02:06

FalloutRanger


People also ask

What is read statement in Fortran?

The READ statement reads data from a file or the keyboard to items in the list. Note - Use the TOPEN() routines to read from tape devices. See the Fortran Library Reference Manual.

What is read and write in Fortran?

This is sometimes called list directed read/write. read (*,*) list-of-variables write(*,*) list-of-variables. The first statement will read values from the standard input and assign the values to the variables in the variable list, while the second one writes to the standard output.


1 Answers

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).

like image 114
Francois Jacq Avatar answered Sep 28 '22 08:09

Francois Jacq