发生“分段错误”的错误 [英] errors with "segmentation fault occurred "
问题描述
do j = 1,nmax
if(zb(iz,im,j) .ne.0),然后
调用Romberg(dix,dDistCa,zb(iz,im,j),zup(iz))!COMOVING DISTANCE
Vmax = dix * S!COMOVINF VOLUME
fi = fi + 1 / Vmax!亮度函数
写(2,'(i5,2x,f9.4,2x,f8.5,2x,3f14.10)')j,magbin,zbin,S, Vmax,dix
endif
enddo
if(Nbin.ge.n_thresh)then
Nrow = Nrow + 1
write(4 ,'(3i7,2x,f25.8,2x,2f20.8,2x,f9.4,2x中,f 8.5)')Nrow,iz,Nbin,fi,fiStdDev,fiAvr,magbin,zup(iz)
endif
enddo loopmag
倒带(4)
close (4)
写(*,*)Nrow
open(4,file ='luminosity_func_I.asc')
分配(fiStdDev2( ),
分配(fi_expected(Nrow),stat = ok)
分配(DFI(Nrow),stat = ok)
分配(CHISQ(Nrow),stat =好的)
! Ln10 = 2.3025
A = 0.4 * 2.3025
do I = 1,Nrow! NDATA = NMAX
write(*,*)I
read(4,*)NNrow(I),Niz(I),NNbin(I),Nfi(I),NfiStdDev(I),NfiAvr (I),NMagbin(I),Nzup(I)
fiStdDev2(I)= 1 / NfiStdDev(I)* NfiStdDev(I)
write(*,*)fiStdDev2 )(*)* *(*)* *(* * * * * * * * * * * * * * *我))))
DFI(I)= fi_expected(I)-NFI(I)
CHISQ(I)= DFI(I)* DFI(I)* fiStdDev2(I)
END DO
据我所见,在读取
语句中出现两种情况:
-
您是试图存储数组之外的信息,即
单位很低,你可以访问一个保留单位 - 尝试类似于i>大小(<一个数组>)
。你可以用-fbounds-check
来检查gfortran
和- 检查界限 code>为
ifort
。
- 从文件中读取内容时出现错误:
1234
。另请参阅此帖:针对ansys的linux分段错误 - 您在文件末尾阅读
- 没有足够的列可以从文件中读取
>
您可以将 I have some values written in file 4 and I need them to call again for new calculations but I have some problem in read line " read (4,*) NNrow(I),Niz(I),NNbin(I),Nfi(I),NfiStdDev(I),NfiAvr(I),NMagbin(I),Nzup(I) "
when I want to run the code I'm receiving the error "segmentation fault occurred" how I can use this file again?
As far as I can see, there could be two things going wrong in that You are trying to store the information outside the arrays, i.e. There's something wrong while reading in from the file: You could put 这篇关于发生“分段错误”的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! iostat = ierror
放入您的 code>语句来检查在读入时是否发生了错误。
ierror <0
意味着您正在尝试读取超出文件末尾的内容,而 ierror> 0
对应于读取文件时的错误。 do j=1,nmax
if (zb(iz,im,j).ne.0) then
call Romberg (dix,dDistCa,zb(iz,im,j),zup(iz)) !COMOVING DISTANCE
Vmax=dix*S !COMOVINF VOLUME
fi=fi+1/Vmax !LUMINOSITY FUNCTION
write(2,'(i5,2x,f9.4,2x,f8.5,2x,3f14.10)')j,magbin,zbin,S,Vmax,dix
endif
enddo
if (Nbin.ge.n_thresh) then
Nrow=Nrow+1
write(4,'(3i7,2x,f25.8,2x,2f20.8,2x,f9.4,2x,f8.5)')Nrow,iz,Nbin,fi,fiStdDev,fiAvr,magbin,zup(iz)
endif
enddo loopmag
rewind(4)
close(4)
write(*,*)Nrow
open(4,file='luminosity_func_I.asc')
allocate (fiStdDev2(Nrow),stat=ok)
allocate (fi_expected(Nrow),stat=ok)
allocate (DFI(Nrow),stat=ok)
allocate (CHISQ(Nrow),stat=ok)
! Ln10=2.3025
A=0.4*2.3025
do I=1,Nrow ! NDATA=NMAX
write(*,*)I
read (4,*) NNrow(I),Niz(I),NNbin(I),Nfi(I),NfiStdDev(I),NfiAvr(I),NMagbin(I),Nzup(I)
fiStdDev2(I)=1/NfiStdDev(I)*NfiStdDev(I)
write(*,*)fiStdDev2(I)
fi_expected(I)=A*fi_star*10**(0.4*(alpha+1)*(M_star-NMagbin(I)))*exp(-10**(0.4*(M_star-NMagbin(I))))
DFI(I)=fi_expected(I)-NFI(I)
CHISQ(I)=DFI(I)*DFI(I)*fiStdDev2(I)
END DO
read
statement:
i > size(<one of the arrays>)
. You can check for this with -fbounds-check
for gfortran
and -check bounds
for ifort
.
1234
. See also this post: segmentation error in linux for ansysiostat=ierror
into your read
statement to check whether an error occured while reading in. ierror<0
would mean that you are trying to read beyond the end of the file, while ierror>0
corresponds to an error while reading the file.