错误:在 (1) (2/1) 处的数组引用中的排名不匹配 [英] Error: Rank mismatch in array reference at (1) (2/1)
本文介绍了错误:在 (1) (2/1) 处的数组引用中的排名不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
恳请您就我不断得到的代码提供帮助一个错误:在 (1) (2/1) 处的数组引用中排名不匹配
.我的目标是遍历立方体中的每个点(p = i+(j-1)*N + (k-1)NN) 并计算沿每个轴的电位梯度 (<代码>gradphi_x、gradphi_y
、gradphi_z
).
I kindly request your help on this code where I kept on getting
an error: Rank mismatch in array reference at (1) (2/1)
. My objective is to go through each point in a cube(p = i+(j-1)*N + (k-1)NN) and calculate the gradient of the potential along each axis (gradphi_x
, gradphi_y
, gradphi_z
).
PROGRAM sub_rho_phi
integer, parameter:: N=3
real, dimension(N):: gradphi_x, gradphi_y, gradphi_z
call output(gradphi_x, gradphi_y, gradphi_z)
open(unit=1,file="grad_phi.dat")
l = 0
do
l=l+1
write(1,*) gradphi_x(l),gradphi_y(l),gradphi_z(l)
if ( l == N**3) then
exit
end if
end do
END
SUBROUTINE output( gradphi_x, gradphi_y, gradphi_z )
real, parameter:: h=0.7,G=6.67,M=1.98892*(10**3)!!in(10**15) kg
integer, parameter:: N=3
real, dimension(N):: r, gradphi_x,gradphi_y,gradphi_z
integer, dimension(N**3):: x,y,z
integer:: p
real:: a
a=500/h !in kpc
do i=0, N
do j=0, N
do k=0, N
p = i+(j-1)*N + (k-1)*N*N
x(p,1)=i
y(p,2)=j
z(p,3)=k
r(p)=sqrt(x(p,1)*x(p,1)+y(p,2)*y(p,2)+z(p,3)*z(p,3))
gradphi_x(p)=(G*M)*x(p,1)/r(p)*(r(p)+a)**2
gradphi_y(p)=(G*M)*y(p,2)/r(p)*(r(p)+a)**2
gradphi_z(p)=(G*M)*z(p,3)/r(p)*(r(p)+a)**2
enddo
enddo
enddo
return
END
推荐答案
您已将 x
、y
和 z
声明为一维数组,但通过 output
一直使用二维索引.
You have declared x
, y
and z
as one dimensional arrays, but are using two dimensional indexing all the way through output
.
这篇关于错误:在 (1) (2/1) 处的数组引用中的排名不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文