回 帖 发 新 帖 刷新版面

主题:[讨论]数组超越上限出错

程序运行时出错
subscript #1 of the array PS have value 3 which is greater than the upper bound of 0 
这个上界0在代码中定义位置在哪



 real(8),dimension(:,:),allocatable::ps,G
后面是do me=1,mesh
        n=ko(me)
         allocate (ps(n,2),G(n-2,2))
        do k=1,n       
        ps(k,1)=a(menode(me,k),1)
        ps(k,2)=a(menode(me,k),2)
        enddo
        
        do
       do i=2,n-1
       G(i-1,:)=(ps(1,:)+ps(i,:)+ps(i+1,:))/3.0d0
       enddo
       if(n.eq.4) then
       cl1=abs((ps(2,1)-ps(1,1))*(ps(3,2)-ps(1,2))-(ps(2,2)-ps(1,2))*(ps(3,1)-ps(1,1)))
       S1=cl1/2.0d0
       cl2=abs((ps(3,1)-ps(1,1))*(ps(4,2)-ps(1,2))-(ps(3,2)-PS(1,2))*(ps(4,1)-ps(1,1)))
       S2=cl2/2.0d0
       centroid(me,1)=(S2*G(1,1)+S1*G(2,1))/(S1+S2)
       centroid(me,2)=(S2*G(1,2)+S1*G(2,2))/(S1+S2)
       area=S1+S2;exit
       else if(n.eq.3) then       
       cl1=abs((ps(2,1)-ps(1,1))*(ps(3,2)-ps(1,2))-(ps(2,2)-ps(1,2))*(ps(3,1)-ps(1,1)))
       area=cl1/2
       centroid(me,1)=G(1,1)
       centroid(me,2)=G(1,2);exit
        endif
       ps(:,:)=0.0d0
       ps(1:n-2,:)=G(1:n-2,:)
       G(:,:)=0.0d0
       n=n-2
    enddo
    open(24, file=fmesh1, action='write')
    write (24,1234) me,area, centroid(me,1),centroid(me,2)
1234 format(4x,i4,f13.2,2f10.2)
deallocate(PS,G)

function centroid2(pin,n1)
!spn1=centroid2(surfp(mms,:,:),ipathn)
implicit none
integer,intent(in)::n1
doubleprecision,dimension(0:2)::centroid2
doubleprecision,dimension(1:n1,0:2),intent(in)::pin
doubleprecision,dimension(:,:),allocatable::PS,G
doubleprecision::S1,S2  !,crossL
integer::i,n

n=(n1)
allocate(PS(n,3),G(n-2,3))
centroid2=0.0d0
do i=1,n
PS(i,:)=pin(i,:)
enddo

do
do i=2,n-1
 G(i-1,:)=(PS(1,:)+PS(i,:)+PS(i+1,:))/3.0d0
enddo
if(n.eq.4) then
 S1=sqrt(sum(crossV( PS(2,:)-PS(1,:), PS(3,:)-PS(1,:) )**2))/2.0d0
 S2=sqrt(sum(crossV( PS(3,:)-PS(1,:), PS(4,:)-PS(1,:) )**2))/2.0d0
 centroid2(:)=(S2*G(1,:)+S1*G(2,:))/(S1+S2);exit
else if(n.eq.3) then
 centroid2(:)=G(1,:);exit
endif
PS(:,:)=0.0d0
PS(1:n-2,:)=G(1:n-2,:)
G(:,:)=0.0d0
n=n-2
enddo

回复列表 (共3个回复)

沙发

Ps没有定义维数大小就使用

板凳


real(8),dimension(:,:),allocatable(ps(-1:3),G(-1:3))
     allocate(ps(5),G(5))
然后我进行了定义  为什么还是出现一样的错误

3 楼

检查一遍发现在这里出现问题       G(i-1,:)=(ps(1,:)+ps(i,:)+ps(i+1,:))/3.0d0

我来回复

您尚未登录,请登录后再回复。点此登录或注册