Flushing I/O buffers

To protect data from being lost if a program ends unexpectedly, you can use the FLUSH statement or the flush_ subroutine to write any buffered data to a file.

The FLUSH statement is recommended for better portability and is used in the following example:

INTEGER, PARAMETER :: UNIT = 10
DO I = 1, 1000000
    WRITE(UNIT, *) I
    CALL MIGHT_CRASH
! If the program ends in the middle of the loop, some data
! may be lost.
END DO
DO I = 1, 1000000
    WRITE(UNIT, *) I
    FLUSH(UNIT)
    CALL MIGHT_CRASH
! If the program ends in the middle of the loop, all data written
! up to that point will be safely in the file.
END DO
END
Related information:
See Mixed-language input and output and the FLUSH statement in the XL Fortran Advanced Edition V10.1 for Linux Language Reference.