【问题标题】:Does Fortran 95 allow two subroutines to have the same name if the argument lists are different?如果参数列表不同,Fortran 95 是否允许两个子例程具有相同的名称?
【发布时间】:2014-06-12 15:10:31
【问题描述】:

如果参数列表的长度不同,Fortran 95 标准是否允许两个子例程(或函数)具有相同的名称?例如,

subroutine a(i)
! code here
end subroutine a

subroutine a(j,k)
! code here
end subroutine a

【问题讨论】:

  • 除了阅读 Alexander Vogt 关于 INTERFACE 的回复外,您还应该知道,如果某些参数被声明为 OPTIONAL,则可以使用不同数量的参数调用子例程。
  • @Fortranner:确实。您也可以在链接帖子的答案中找到一个示例;-)

标签: fortran fortran90 fortran95


【解决方案1】:

不是问题中给出的字面意思,而是使用interface

module a_wrapper

  interface a
    module procedure a_1
    module procedure a_2
  end interface

contains
  subroutine a_1(i)
  ! code here
  end subroutine a

  subroutine a_2(j,k)
  ! code here
  end subroutine a
end module

program test
  use a_wrapper, only: a

  call a(.....)
end program

另请参阅我对这篇帖子的回答:Passing different set of variables in a FORTRAN subroutine 或 M.S.B. 对此帖子的回答:how to write wrapper for 'allocate'

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
相关资源
最近更新 更多