It is
call action(mySubX)
假设动作看起来像
subroutine action(sub)
!either - not recommmended, it is old FORTRAN77 style
external sub
!or - recommended
interface
subroutine sub(aA, aB)
integer,intent(...) :: aA, aB
end subroutine
end interface
! NOT BOTH!!
call sub(argA, argB)
假如action
知道该放什么argA, argB
代表aA, aB
.
否则,如果您还想传递参数
call action(mySubX, argA, argB)
subroutine action(sub, argA, argB)
!either - not recommmended, it is old FORTRAN77 style
external sub
!or - recommended
interface
subroutine sub(aA, aB)
integer,intent(...) :: aA, aB
end subroutine
end interface
integer, intent(...) :: argA, argB
call sub(argA, argB)
我认为在这里使用函数指针不好,当您有时必须更改指针(它指向的子例程)的值时,它们很好。正常的过程参数在 FORTRAN77 中有效,并且现在仍然有效。
因此,根据评论中的要求,如果您位于模块中,并且可以从模块访问具有正确接口的过程(可能在同一模块中),则可以使用过程语句来获取接口块的棒:
module subs_mod
contains
subroutine example_sub(aA, aB)
integer,intent(...) :: aA, aB
!the real example code
end subroutine
end module
module action_mod
contains
subroutine action(sub)
use subs_mod
procedure(example_sub) :: sub
call sub(argA, argB)
end subroutine
end module
但更有可能的是,您将创建一个抽象接口,而不是真正的子例程,您将使用过程语句引用该接口,因此最终一切都将与以前相似:
module action_mod
abstract interface
subroutine sub_interface(aA, aB)
integer,intent(...) :: aA, aB
end subroutine
end interface
contains
subroutine action(sub)
procedure(sub_interface) :: sub
call sub(argA, argB)
end subroutine
end module