有谁知道 Fortran 中休眠指定毫秒数的方法吗?我不想使用不可移植的系统调用,因此 Fortran 或 C 库固有的任何内容都是首选。
最佳答案
使用Fortran ISO C Binding使用C库sleep以秒为单位休眠:
module Fortran_Sleep
use, intrinsic :: iso_c_binding, only: c_int
implicit none
interface
! should be unsigned int ... not available in Fortran
! OK until highest bit gets set.
function FortSleep (seconds) bind ( C, name="sleep" )
import
integer (c_int) :: FortSleep
integer (c_int), intent (in), VALUE :: seconds
end function FortSleep
end interface
end module Fortran_Sleep
program test_Fortran_Sleep
use, intrinsic :: iso_c_binding, only: c_int
use Fortran_Sleep
implicit none
integer (c_int) :: wait_sec, how_long
write (*, '( "Input sleep time: " )', advance='no')
read (*, *) wait_sec
how_long = FortSleep ( wait_sec )
write (*, *) how_long
stop
end program test_Fortran_Sleep
关于fortran - Fortran 语言中的 sleep ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6931846/