fortran模块使用错误

时间:2015-01-28 09:37:38

标签: fortran gfortran

以下是VASP的代码框架。我的工作是将它移植到一个新平台上。当我使用该平台的编译器时,我收到了错误。如果我注释掉use m,我也会得到" 必须指定明确的界面。"我只想做一个最小的修改,以避免在程序的其他部分发生错误。

module m
interface 
  subroutine a
  end subroutine
end interface

interface 
  subroutine b
  end subroutine
end interface
end module

subroutine a
  use m

  call b
end subroutine

2 个答案:

答案 0 :(得分:2)

为什么不简单:

module m

contains

subroutine b
    ! code
end subroutine b

subroutine a
    ! code
    call subroutine b
end subroutine a

end module m

根据您发布的内容,我没有看到任何递归(子例程都没有调用,a调用b,但b没有调用{ {1}})也不需要它。我也没有看到明确编写a块的必要性;将子例程打包到一个模块中,让编译器负责检查接口规范和协议。

答案 1 :(得分:2)

在所示的代码中,模块中定义的子例程a的接口可以通过use association在子例程a内访问。由于子程序已为其定义的任何过程定义了显式接口,因此这意味着您可以在同一作用域中访问相同过程的两个单独定义的显式接口。这违反了该语言的规则(F2008 12.4.3.2p7)。

您可以使用USE语句中的ONLY子句排除子例程接口的接口主体变体,使其不被子例程中的use关联访问。

module m
  interface 
    subroutine a
    end subroutine
  end interface

  interface 
    subroutine b
    end subroutine
  end interface
end module

subroutine a
  use m, only: b

  call b
end subroutine