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.) The following example shows use of the flush_ subroutine:

USE XLFUTILITY
INTEGER, PARAMETER :: UNIT=10
 
DO I=1,1000000
    WRITE (10,*) 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 (10,*) I
    CALL 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 Language Reference.
IBM Copyright 2003