2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. index:: FLUSH, file operation, flush
10 FLUSH --- Flush I/O unit(s)
11 ***************************
13 .. function:: FLUSH(UNIT)
15 Flushes Fortran unit(s) currently open for output. Without the optional
16 argument, all units are flushed, otherwise just the unit specified.
19 (Optional) The type shall be ``INTEGER``.
28 .. code-block:: fortran
33 Beginning with the Fortran 2003 standard, there is a ``FLUSH``
34 statement that should be preferred over the ``FLUSH`` intrinsic.
36 The ``FLUSH`` intrinsic and the Fortran 2003 ``FLUSH`` statement
37 have identical effect: they flush the runtime library's I/O buffer so
38 that the data becomes visible to other processes. This does not guarantee
39 that the data is committed to disk.
41 On POSIX systems, you can request that all data is transferred to the
42 storage device by calling the ``fsync`` function, with the POSIX file
43 descriptor of the I/O unit as argument (retrieved with GNU intrinsic
44 ``FNUM``). The following example shows how:
46 .. code-block:: fortran
48 ! Declare the interface for POSIX fsync function
50 function fsync (fd) bind(c,name="fsync")
51 use iso_c_binding, only: c_int
52 integer(c_int), value :: fd
53 integer(c_int) :: fsync
57 ! Variable declaration
64 ! Perform I/O on unit 10
71 ! Handle possible error
72 if (ret /= 0) stop "Error calling FSYNC"