How to go to the end of the file?

fortran

Solution

You should open the file with

open(..., position="append",...)

Alternatively, you can inquire for the size of the file

inquire(...,size=some_integer_variable,...)

then if the file is a direct access file, you can use this size to calculate the record number of the final record. Alternatively, if the access mode is "stream", you can use

write(..., pos=some_integer_variable)

to write starting at the end of the file.

Problem

I have opened a file to write a number. I have to write the number at the end of the file so how to go to the last line to write on it?

Original source