Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on fortran 95 output to file 1

Status
Not open for further replies.

livingenzyme

Technical User
Nov 9, 2010
5
US
Output to file is easy. What I'm trying to do is output to the end of the file so that nothing that was already in the file is lost. Say I have a hypothetical file a.txt. Everytime I run my program, I want it to output certain info to a.txt at the end of the file for record keeping. How do I do this? In other words, I don't want to lose any preexisting info in file a.txt.

Many thanks.
 
A way which works with any FORTRAN compiler (even an old FORTRAN-77 one) consists in :
- opening the file normally,
- reading it up to the end,
- executing a backspace to come back before the "end of file" mark.

With a recent FORTRAN compiler, it is possible to open the file in setting the current position at the end :

Code:
open(unit=15,file="myfile.txt",position='append')
...
write(15,*) .. ! writing the new results
close(15)

The typical solution with an old compiler :

Code:
      OPEN(unit=15,file="myfile.txt")
  10  CONTINUE
        READ(15,*,end=20)
        GOTO 10
  20  CONTINUE
      BACKSPACE(15)
      ...
C     Writing the new results
      WRITE(15,*) ...
      ...
      CLOSE(15)

François Jacq
 
If you were here right now I would give you a big wet kiss.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top