Fortran stream buffering
Fortran programs, like most other programming languages, can access the standard input, output, and error streams, which usually connect to the terminal.
Stream buffering generally increases efficiency of small bursts or groups of text typical to interactive applications.
Buffering means that data is not immediately written to the terminal or console until the buffer is full or flushed.
The Fortran statement to flush is flush(unit)
, where unit
is the unit number of the stream to flush.
Fortran statement print
automatically flush the stream.
Fortran statement write
flushes the stream unless the advance
specifier is set to no
.
Different compilers have distinct default stream buffering behavior.
- Gfortran: streams buffered by default. Environment variable GFORTRAN_UNBUFFERED_PRECONNECTED can be set to “y” to disable buffering.
- Intel Fortran “ifx”: streams unbuffered by default. Environment variable FORT_BUFFERED can be set to “TRUE” to enable buffering.