关于数组越界的问题
关于程序编译的时候会出现数组越界的报错,不知道该怎么解决,求助一下,请大神帮忙解答一下呗?program dla
implicit none
parameter M=100
parameter N=100
parameter Particles=2000
integer::A(M,N)
integer::i, j, count, p
real*8::s,num1,num2,num3
open(13,file="dla.txt")
do i=1,M
do j=1,N
A(i,j)=0
end do
end do
A(50,50)=1
count=0
do while (cout<Particles)
count=count+1
write(*,*)'Current Particles is',count
call random_number(num1)
i=1+int(num1*(N-1))
call random_number(num2)
j=1+int(num2*(N-1))
p=0
55 do while(p==0)
call random_number(num3)
s=num3
if(s<=0.25) then
j=j+1
else if(s<=0.50) then
j=j-1
else if(s<=0.75) then
i=i+1
else
i=i-1
endif
if (j==N+1) then
j=1
goto 55
endif
if (j==0) then
j=N
goto 55
endif
if (i==M+1) then
i=1
goto 55
endif
if (i==0) then
i=M
goto 55
endif
if(A(i,j-1)==1.OR.A(i,j+1)==1.OR.A(i+1,j)==1.OR.A(i-1,j)==1) then
A(i,j)=1
write(30,*) i, j
p=10
endif
enddo
enddo
end program dla 在我这里运行没有问题啊,也没有越界。
问题1:
do while (cout<Particles)
应该是
do while (count<Particles)
问题2:
打开文件通道号是 13,输出文件通道号是30
修改后,部分输出结果为:
8 100
50 49
8 99
8 98
9 98
51 49
7 99
50 48
9 99
51 50
49 48
48 48
50 47
52 49
48 49
53 49
48 47
52 50
10 98
10 97
11 97
10 96
52 48
6 99 fcode 发表于 2015-5-26 14:32
在我这里运行没有问题啊,也没有越界。
问题1:
改正完之后会报错。。。。我用的是Intel 的编译器 关于报错呢,一定要给错误提示的。
只说报错,神仙都不知道为啥。 fcode 发表于 2015-5-26 17:28
关于报错呢,一定要给错误提示的。
只说报错,神仙都不知道为啥。
#1 of the array A has value 0 which is less than the lower bound of 1 if(A(i,j-1)==1.OR.A(i,j+1)==1.OR.A(i+1,j)==1.OR.A(i-1,j)==1) then
这里你要考虑 i = 1 或 j = 1 的情况。以及 i = 100 或 j = 100 的情况。 fcode 发表于 2015-5-27 08:31
if(A(i,j-1)==1.OR.A(i,j+1)==1.OR.A(i+1,j)==1.OR.A(i-1,j)==1) then
这里你要考虑 i = 1 或 j = 1 ...
恩,我也觉得应该是这里的问题。。那么是需要怎么改写的呢?? 那要看你是怎么打算处理边界的问题咯。
是在这个方向的边界上,就不再判断该边界,还是其他处理方式?
页:
[1]