Fortran 中的子例程不识别类型

Subroutine in Fortran don't recognize type

我有以下代码

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|Error: Derived type ‘node’ is being used before it is defined"

虽然在第一个子程序中他没有 problem.I 不明白第一个子程序和这个子程序之间的区别,知道吗?

尝试使用 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

所以问题是,subroutine child_cubes 的虚拟参数以及 subroutine tree 的内部指针变量与类型,从而隐藏类型。将这些名称更改为 node2 或其他东西可以解决此问题(事实上,只要重命名 [=12= 的虚拟变量,英特尔编译器甚至可以使用与类型同名的内部指针变量]],因此哪些子例程会导致问题取决于编译器)。