回 帖 发 新 帖 刷新版面

主题:array bounds exceed

编译的时候没提示有错误,可是运行的时候就出错了,说主要是A(i+360*(j-1))=1/2*RA(j+1)**2*pi-1/2*RA(j)**2*pi这句有问题,说array bounds exceed,可是我在子程序yi中也用到这个循环,却没出错,搞不清什么原因,哪位高手帮忙指点下,谢谢

program main
    implicit none
    integer::d,t,k,i,j
    real::Ae,Sey,ye,Iey,Ie,E0,E
    real,parameter::pi=3.1415926
    real,allocatable::y(:),A(:),RA(:)
    open(unit=10,file="input.txt")
    open(unit=20,file="output.txt")
    read(10,*)d,t
    k=360*t
    E0=206000
    E=206000
    allocate(y(k),A(k),RA(t))
    call yi(d,t,k,y)
    Ae=0.0
    Sey=0.0
    Iey=0.0
    do j=1,t,1
       RA(j)=(D-2*t)/2+j-1
    end do
    do j=1,t,1
       do i=1,360,1
       A(i+360*(j-1))=1/2*RA(j+1)**2*pi-1/2*RA(j)**2*pi
       end do
    end do
    do i=1,k
        Ae=Ae+E/E0*A(i)
        Sey=Sey+E/E0*y(i)*A(i)
        Iey=Iey+E/E0*y(i)*y(i)*A(i)
    end do
    ye=Sey/Ae
    Ie=Iey-Sey*ye
    if(Ae<=1E-4)then
        write(*,*)"全截面屈服!"
        stop
    end if
    write(20,*)Ae,ye,Iey                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
    close(10)
    close(20)
    stop
end program main

subroutine yi(d,t,k,y)
    implicit none
    integer::d,t,k,i,j
    real::y(k)
    real,parameter::pi=3.1415926
    do j=1,t,1
       do i=1,360,1
           y(i+360*(j-1))=((d-2*t)/2+j-1/2)*sin(i*pi/180-pi/360)
       end do
    end do
    return
end subroutine yi

回复列表 (共6个回复)

沙发


input.txt 传上来

板凳

一个明显的错误

A(i+360*(j-1))=1/2*RA(j+1)**2*pi-1/2*RA(j)**2*pi

1/2=0!!!!

3 楼


1/2=0什么意思啊,不好意思,我是新手

4 楼


RA(j+1)会越界。

5 楼

[quote]
1/2=0什么意思啊,不好意思,我是新手[/quote]

整型除以整型得到的还是整型,改成0.5即可。

6 楼

现在的新人都直接上马的... 以后大程序抓bug恐怕就没人帮了.

我来回复

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