Fortran 90: Alternative to flush() for f90 Compiler

  • Context: Fortran 
  • Thread starter Thread starter natski
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around finding an alternative to the flush() command in Fortran 90, which is not recognized by the f90 compiler. Participants explore potential methods to achieve similar functionality, particularly in the context of file handling and buffering.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes that closing and immediately re-opening the file could achieve a similar result to flush(), though this may not be straightforward due to the file being opened with position='append'.
  • Another participant emphasizes that while closing and re-opening will flush buffers, it is crucial to maintain the current file position, which could complicate the process.
  • There is a suggestion that flush is primarily a C command, but there may be a Fortran equivalent that does not require closing and reopening the file.
  • A participant raises the question of whether the current file position can be determined from the code, suggesting that if it is at a convenient location, repositioning after closing could be feasible.
  • One participant asserts that if the file is opened with the append attribute, closing and reopening it should maintain the file pointer's position, provided it is a sequential text file without concurrent processes.
  • It is mentioned that some f90 dialects might support a flush command without needing to specify the unit number.

Areas of Agreement / Disagreement

Participants express uncertainty about the best approach to replicate the flush() functionality in Fortran 90. There are multiple competing views on how to handle file positioning and buffering, and no consensus is reached on a definitive solution.

Contextual Notes

The discussion highlights the limitations of the f90 compiler regarding the flush() command and the implications of file attributes like position='append' on file handling strategies.

natski
Messages
262
Reaction score
2
Hi all,

I've recently obtained some code in Fortran 90 that was compiled with gfortran. I am compiling with f90 and one of the called statements is not recognised.

I have call flush(1) where 1 is the filename that the code is flushing.

Since flush is not a part of f90, is there an alternative statement which will do the same job in f90?

Thanks,

Natski
 
Technology news on Phys.org
Without looking too deeply into whether there is a direct replacement, one method that should achieve the same result would be to close the file and then immediately re-open it.
 
Hmm, the open command has position='append', so presumably this is why one cannot simply close then open?
 
natski said:
Hmm, the open command has position='append', so presumably this is why one cannot simply close then open?

Yes close and re-open will definitely have the effect of flushing any buffers but as you point out it will be necessary to be able to get back to the same point in the file somehow.
 
Flush is a C command really, but it seems that there must be a Fortran version of this command, without opening and closing?
 
Can you determine (by reading the code) exactly where the current file position is when it's flushed? I mean if it's somewhere convenient like right at the beginning or end then it would be easy enough to just "close/re-open/reposition", but if it's some arbitraty position then yes it would be much better to try and find a replacement for flush.
 
If the file was opened with the append attribute, closing and reopening it with the same append attribute should get the file pointer to point to the same place, as long as we are dealing with a sequential text file and there are no concurrent processes.
Do a little test to confirm it.

Also, some f90 dialects support flush without the unit number, as in flush().
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 34 ·
2
Replies
34
Views
5K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K