Types Fortran don'中的子程序;不认识类型
我有以下代码Types Fortran don'中的子程序;不认识类型,types,fortran,subroutine,Types,Fortran,Subroutine,我有以下代码 module oc_tree type star integer :: id real(8) :: v(3)=0, r(3)=0 end type type node real(8) :: corners(3,2) type(node), dimension(:), pointer :: child_nodes type(node), pointer :: father
module oc_tree
type star
integer :: id
real(8) :: v(3)=0, r(3)=0
end type
type node
real(8) :: corners(3,2)
type(node), dimension(:), pointer :: child_nodes
type(node), pointer :: father
type(star), allocatable :: stars_in(:)
real(8) :: tot_mass, center_mass(3)
integer :: id
end type node
contains
subroutine head_node(n2,m, stars, node1)
real(8), intent(IN) ::m
integer, intent(IN) :: n2
type(star), allocatable, dimension(:), intent(in) :: stars
real(8), parameter :: parsec = 3.085677581d16, d = 6661d3*parsec
integer :: i
type(node), intent(OUT) :: node1
procedure...
end subroutine head_node
recursive subroutine tree(m, node1)
type(node), intent(inout), target :: node1
integer :: i, n, j, last_id
real(8) :: c(3,2), r1(3)
type(node), pointer :: node
node => node1
call child_cubes(node)
procedure...
end subroutine tree
subroutine child_cubes(node)
type(node), intent(inout), target :: node
real(8) :: x_mid, y_mid, z_mid, c(3,2)
integer :: i
procedure
end subroutine child_cubes
end module oc_tree
出于某种原因,在子程序“child_cubes”中,编译器说
“/home/avner/Dropbox/final project/grav/main.f95 | 176 |错误:派生
类型“node”在定义之前正在使用“
虽然在两个第一子例程中,他没有问题。我不明白两个第一子例程和这个之间的区别,知道吗?试图用gfortran 4.8.5编译,编译器在第37行抛出以下信息错误
type(node), pointer :: node
1 2
Error: The type 'node' cannot be host associated at (1) because it is
blocked by an incompatible object of the same name declared at (2)
除了第49行的错误之外
type(node), intent(inout), target :: node
1
Error: Derived type 'node' at (1) is being used before it is defined
因此,问题在于,
子例程子多维数据集的伪参数以及子例程树的内部指针变量与类型同名(节点
),因此会对类型进行阴影处理。将这些名称更改为node2
或其他方法可以解决此问题(事实上,英特尔编译器甚至可以使用与类型同名的内部指针变量,只要您重命名subroutine child_cubes
的伪变量,那么哪个子例程会导致问题取决于编译器).就我个人而言,我不太相信错误消息来自发布的代码。我认为a是必需的。子例程之间的一个明显区别是前两个没有一个称为与所需类型相同的伪参数。这方面的规则见F2008标准第16.3.1节(本地标识符的类):“在其范围内,一个类别的本地标识符不得与同一类别的另一个本地标识符相同,但通用名称可能与12.4.3.4中解释的程序名称相同,或与派生类型(4.5.10)的名称相同。一个类的本地标识符可能与另一个类的本地标识符相同。“命名变量和派生类型在同一个类中。我向英特尔报告了在“树”中诊断错误的失败,问题ID 03510955。我还指出,英特尔Fortran的“子多维数据集”错误消息没有太大帮助。