]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
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. | |
5 | ||
6 | .. index:: FLUSH, file operation, flush | |
7 | ||
8 | .. _flush: | |
9 | ||
10 | FLUSH --- Flush I/O unit(s) | |
11 | *************************** | |
12 | ||
13 | .. function:: FLUSH(UNIT) | |
14 | ||
15 | Flushes Fortran unit(s) currently open for output. Without the optional | |
16 | argument, all units are flushed, otherwise just the unit specified. | |
17 | ||
18 | :param UNIT: | |
19 | (Optional) The type shall be ``INTEGER``. | |
20 | ||
21 | Standard: | |
22 | GNU extension | |
23 | ||
24 | Class: | |
25 | Subroutine | |
26 | ||
27 | Syntax: | |
28 | .. code-block:: fortran | |
29 | ||
30 | CALL FLUSH(UNIT) | |
31 | ||
32 | Note: | |
33 | Beginning with the Fortran 2003 standard, there is a ``FLUSH`` | |
34 | statement that should be preferred over the ``FLUSH`` intrinsic. | |
35 | ||
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. | |
40 | ||
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: | |
45 | ||
46 | .. code-block:: fortran | |
47 | ||
48 | ! Declare the interface for POSIX fsync function | |
49 | interface | |
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 | |
54 | end function fsync | |
55 | end interface | |
56 | ||
57 | ! Variable declaration | |
58 | integer :: ret | |
59 | ||
60 | ! Opening unit 10 | |
61 | open (10,file="foo") | |
62 | ||
63 | ! ... | |
64 | ! Perform I/O on unit 10 | |
65 | ! ... | |
66 | ||
67 | ! Flush and sync | |
68 | flush(10) | |
69 | ret = fsync(fnum(10)) | |
70 | ||
71 | ! Handle possible error | |
3ed1b4ce | 72 | if (ret /= 0) stop "Error calling FSYNC" |