[Fortran] 纯文本查看 复制代码
type octree_node
type(point), dimension(:), pointer :: points
type(octree_node), dimension(:), pointer :: children
real :: x_min, x_max, y_min, y_max, z_min, z_max
integer :: num_points
end type octree_node
Contains
recursive subroutine build_octree(node, points, x_min, x_max, &
y_min, y_max, z_min, z_max)
type(octree_node), pointer :: node
type(point), dimension(:), pointer :: points
real, intent(in) :: x_min, x_max, y_min, y_max, z_min, z_max
integer :: i, j, k, num_points, num_children
real :: x_mid, y_mid, z_mid
do k = 0, 1
do j = 0, 1
do i = 0, 1
num_children = num_children + 1
allocate(node%children(num_children))
call build_octree(node%children(num_children), points,& !这里报错,error #7121: A ptr dummy may only be argument associated with a ptr, and this array element or section does not inherit the POINTER attr from its parent array. [CHILDREN]
x_min + i*(x_mid - x_min), x_min + (i+1)*(x_mid - x_min),&
y_min + j*(y_mid - y_min), y_min + (j+1)*(y_mid - y_min),&
z_min + k*(z_mid - z_min), z_min + (k+1)*(z_mid - z_min))
end do
end do
end do
end subroutine build_octree
这里截取了一部分问题代码,在递归调用函数时第一个变量出现了问题,如果第一个变量改为node则可以运行,是因为node%children(num_children)不是指针吗,不太明白,希望大佬们帮忙看看。