從Gfortran manual:
與Fortran 2003標準開始,有一個FLUSH
聲明應優先於FLUSH
內在。
FLUSH
內部函數和Fortran 2003 FLUSH
語句具有相同的效果:它們刷新運行時庫的I/O緩衝區,以便數據對其他進程可見。這並不保證數據被提交到磁盤。
在POSIX系統上,您可以通過調用fsync函數並將I/O單元的POSIX文件描述符作爲參數(通過GNU固有FNUM檢索)來請求將所有數據傳輸到存儲設備。以下示例顯示如何:
! Declare the interface for POSIX fsync function
interface
function fsync (fd) bind(c,name="fsync")
use iso_c_binding, only: c_int
integer(c_int), value :: fd
integer(c_int) :: fsync
end function fsync
end interface
! Variable declaration
integer :: ret
! Opening unit 10
open (10,file="foo")
! ...
! Perform I/O on unit 10
! ...
! Flush and sync
flush(10)
ret = fsync(fnum(10))
! Handle possible error
if (ret /= 0) stop "Error calling FSYNC"
如何查看文件運行時的內容? –
而不是打開,寫入,關閉,打開,讀取......,你可以打開,寫入,倒帶,閱讀。 –
懷疑他想通過外部查看文件來監視進度。 – agentp