Fortran Coder

标题: fortran 循环调用数组值时为什么会超过数组上界 [打印本页]

作者: yufeng98    时间: 2020-3-9 20:56
标题: fortran 循环调用数组值时为什么会超过数组上界
用循环语句调用数组XX(4)的值,为什么最后会显示循环变量I变成5导致数组XX超过定义的上界?但我在测试程序test中却没有发现相同现象,想请教下这是什么情况

QQ截图20200309205505.jpg (34.94 KB, 下载次数: 119)

QQ截图20200309205505.jpg

QQ截图20200309205102.jpg (23.55 KB, 下载次数: 121)

QQ截图20200309205102.jpg

QQ截图20200309205133.jpg (51.88 KB, 下载次数: 126)

QQ截图20200309205133.jpg

作者: vvt    时间: 2020-3-9 22:11
请给出所有代码。(复制粘贴,不截图)
作者: yufeng98    时间: 2020-3-9 22:52
本帖最后由 kyra 于 2020-3-10 09:31 编辑

[Fortran] 纯文本查看 复制代码
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

作者: yufeng98    时间: 2020-3-9 22:53
vvt 发表于 2020-3-9 22:11
请给出所有代码。(复制粘贴,不截图)

源代码已上传,,,,,,
作者: kyra    时间: 2020-3-10 09:29
本帖最后由 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




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2