gpt4 book ai didi

linux - 程序收到信号SIGSEGV : Segmentation fault - invalid memory reference

转载 作者:太空宇宙 更新时间:2023-11-04 06:05:46 25 4
gpt4 key购买 nike

program height_sand
implicit none
integer tmax, nmax
real zmax, maxx
parameter (nmax=200000)
real x1(nmax),y1(nmax),z1(nmax),teta
!real d, zmax, xmax
integer t,ntot
integer i, j, id, tip(nmax)
open(unit=1,file='vmdfile.xyz')
open(unit=3,file='height.dat')
ntot=3000
tmax=51
maxx=0
zmax=0

do t=1,tmax
read(1,*)
read(1,*)


do i=1,ntot
read(1,*)tip(id),x1(id),y1(id),z1(id)

if (z1(id).gt.zmax) then
zmax=z1(id)

end if

if (x1(id).gt.maxx) then
maxx=x1(id)
end if

end do

teta=zmax/maxx
write(3,*)t,zmax,teta
end do


!110 format(I8, f15.6)
END

最佳答案

这一行

         read(1,*)tip(id),x1(id),y1(id),z1(id)

很可能是您报告的错误的根源。在执行时,id 尚未被赋予值。如果您假设它会自动设置为 0,那么 (a) 您假设错误,并且 (b) tip(0) 无论如何都是无效的数组元素引用,因为 Fortran 索引从 1 开始(除非您专门将它们设置为另一个起始值,但显示的代码没有这样做)。

我强烈怀疑您向我们展示了不成熟的代码,因为循环控制变量(tmaxntot)未在循环内部使用。

关于linux - 程序收到信号SIGSEGV : Segmentation fault - invalid memory reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com