fortran - Fortran 语言中的 sleep

标签 fortran fortran-iso-c-binding

有谁知道 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/

相关文章:

arrays - 错误#6366 : The shapes of the array expressions do not conform

python - Cpython 和 fortran 链表之间的互操作性

c - 将 Fortran 整数数组传递给 C 子例程,仅传递第一个元素

在 Fortran 代码中调用 C 函数/子例程

fortran - Fortran 90 中的优化例程

fortran - 用双冒号声明变量时有区别吗

fortran - 用 Fortran 重载函数

arrays - 在两级子例程中传递假定形状的数组 (Fortran 90)

fortran - 我怎样才能 "re-export"一个现有的 bind(C) 函数,在 Fortran 模块中重载,在其名称下带有 ifort?

c++ - 将字符串从 Fortran 传递到 C/C++ 的正确方法