fortran 循环调用数组值时为什么会超过数组上界
用循环语句调用数组XX(4)的值,为什么最后会显示循环变量I变成5导致数组XX超过定义的上界?但我在测试程序test中却没有发现相同现象,想请教下这是什么情况 请给出所有代码。(复制粘贴,不截图) 本帖最后由 kyra 于 2020-3-10 09:31 编辑include "link_fnl_shared.h"
module constant
implicit none
real,parameter :: pi = 3.1415926
real,parameter :: lc=9, lt=1.2, ls = 0.545, L= 100, x00=10,mr=60.64
real,parameter :: xx(4)=(/x00, x00+2*lt, x00+2*lc, x00+2*(lc+lt)/)
integer,parameter :: NM = 120 ,dof_c=10
integer,parameter :: N = floor(L/ls), DOF=dof_c+NM+2*N
contains
subroutine Zp_Zw(Zpp,Zww)
implicit none
integer :: I,J,I1,J1
real(kind=4) :: Zpp(NM,N),Zww(NM,4)
do I = 1,NM
do J = 1,4
Zww(I,J)=((2/(mr*L))**0.5)*sin(I*pi*xx(J)/L)
end do
end do
do I1 = 1,NM
do J1 = 1,N
Zpp(I1,J1)= ((2/(mr*L))**0.5)*sin(I1*pi*xx(J1)/L)
end do
end do
end subroutine
end module constant
Program test_IMSL
use constant
use operation_x
implicit none
real(kind=4) :: Zp(NM,N),Zw(NM,4)
call Zp_Zw(Zp,Zw)
pause
end program vvt 发表于 2020-3-9 22:11
请给出所有代码。(复制粘贴,不截图)
源代码已上传,,,,,, 本帖最后由 kyra 于 2020-3-10 09:30 编辑
integer,parameter :: N = floor(L/ls)
ls = 0.545, L= 100
所以 N = 183
real,parameter :: xx(4)=(/x00, x00+2*lt, x00+2*lc, x00+2*(lc+lt)/)
xx的大小是4
do I1 = 1,NM
do J1 = 1,N
Zpp(I1,J1)= ((2/(mr*L))**0.5)*sin(I1*pi*xx(J1)/L)!//此处J1循环到N,当循环到5时,xx越界(因为xx大小为4)
end do
end do
页:
[1]