Fortran Coder

查看: 18257|回复: 7
打印 上一主题 下一主题

[数值问题] 关于数组越界的问题

[复制链接]

26

帖子

8

主题

0

精华

熟手

F 币
123 元
贡献
78 点
跳转到指定楼层
楼主
发表于 2015-5-26 13:24:53 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
关于程序编译的时候会出现数组越界的报错,不知道该怎么解决,求助一下,请大神帮忙解答一下呗?
[Fortran] 纯文本查看 复制代码
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
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

26

帖子

8

主题

0

精华

熟手

F 币
123 元
贡献
78 点
沙发
 楼主| 发表于 2015-5-26 15:14:19 | 显示全部楼层
fcode 发表于 2015-5-26 14:32
在我这里运行没有问题啊,也没有越界。

问题1:

改正完之后会报错。。。。我用的是Intel 的编译器

26

帖子

8

主题

0

精华

熟手

F 币
123 元
贡献
78 点
板凳
 楼主| 发表于 2015-5-26 22:08:04 | 显示全部楼层
fcode 发表于 2015-5-26 17:28
关于报错呢,一定要给错误提示的。

只说报错,神仙都不知道为啥。

#1 of the array A has value 0 which is less than the lower bound of 1

26

帖子

8

主题

0

精华

熟手

F 币
123 元
贡献
78 点
地板
 楼主| 发表于 2015-5-27 12:50:37 | 显示全部楼层
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 ...

恩,我也觉得应该是这里的问题。。那么是需要怎么改写的呢??
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-14 00:47

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表