“分段故障(核心已转储)"; Fortran gfortran Linux中的错误 [英] "Segmentation Fault (core dumped)" error in Fortran gfortran linux

查看:152
本文介绍了“分段故障(核心已转储)"; Fortran gfortran Linux中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个程序,该程序将分析目录中的文件.fits,然后将在另一个目录中创建另一个文件.txt.它只是一个转换器.

I am creating a program which will analyse a file .fits in a directory and then it will create another file .txt in another directory. It is just a converter.

当我尝试执行程序时(编译可以),它给我一个错误消息:

When I tried to execute the program (compiling is OK) it gives me an error message:

程序接收到的信号SIGSEGV:分段错误-无效的内存引用.

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

此错误的回溯: 0 0x7FC5ADB1C117 1 0x7FC5ADB1C6F4 2 0x7FC5AD46C0AF 3 0x44E704在ffthdu中的fitscore.c:6893 4 0x405101 in MAIN__在Codigo.f90 :? 分段错误(核心已转储)

Backtrace for this error: 0 0x7FC5ADB1C117 1 0x7FC5ADB1C6F4 2 0x7FC5AD46C0AF 3 0x44E704 in ffthdu at fitscore.c:6893 4 0x405101 in MAIN__ at Codigo.f90:? Segmentation fault (core dumped)

还有另外一个信息:当我删除一段执行写到新的.txt转换器文件"部分的程序时,该程序运行正常,它将读取整个.fits文件!这是这个范围:

And there is another information: when I delete a stretch of the program which does the "write to the new .txt converter file" part, the program goes OK and it reads the entire .fits file! Here is this stretch:

arq='spec-1.txt'
open (29,file=arq,status='unknown')
write(29,*) '  l(n)                      fa(n)'
do n=1,naxes
   write(29,*) l(n), fa(n)
end do

我已将变量"arq"声明为字符,一切正常.当我删除此拉伸时,不再出现分段错误,但是我不知道现在该怎么办,因为我需要将信息传递给此.txt!而且"arq"字符串还不完整,因为我现在正在测试,以后我将添加整个目录.

I have declared the variable "arq" as a character and everything is OK. When I delete this stretch the segmentation fault does not appear any more, but I do not know what to do now because I need to pass the information to this .txt! And the "arq" string is not complete because I am just testing now, later I will add the entire directory.

这是完整的程序,我使用"gfortran Codigo.f90 -o TESTE -Lcfitsio -lcfitsio"进行编译:

And here is the full program, I am using "gfortran Codigo.f90 -o TESTE -Lcfitsio -lcfitsio" to compile it:

implicit none

integer largo,status,hdnum,n,keysexist,keysadd,bitpix,naxis
integer naxes,readwrite,blocksize
integer i,j,k
integer iF(3),iT(3),iw(3),iwe,il,ib,jb,iFold,iFoldmin(3)
integer iFoldmax(3),iFoldopt(3)
integer iMiMy,iMo,Tymin,Tymax,Timin,Timax,Tyoung(3),Tint(3),Told
integer i912,i45000,Tyin,Tiin,nrows,ncols,datacode,repeat,width
integer nlam_ext
integer fKD,fKK,fKKD
parameter (nlam_ext = 1145)
CHARACTER NAMECH*256,name2*256,alibi*1000,card*80,code*14
CHARACTER arq*1000
CHARACTER name(7)*256,namein*256,nebname*256,nameout*256
CHARACTER nameindva*256,nameoutdva*256,mid(3)*4,line*1000
real fa(10000),fcs(10000),noiz(10000),mask(10000)
real*8 l(10000)
real*8 w_ext(nlam_ext),alam_ext(nlam_ext)
REAL*8 F(3,7),T(3,35),Fl(3,7,36,6900),w(3,6900),y(6900),ye(6900)
REAL*8 SN(6900),xe(6900)
real*8 CHISQU,CHISQUmin(3),CHISQUup,CHISQUdown,CHISQUmid,nf,nfup
real*8 nfdown,nfmid,nfopt(3)
real*8 t4020,y4020,i4020,o4020,t4860,y4860,i4860,o4860
real*8 xd(10000),yd(10000),absorb,ebminv,ke,redshift
real*8 xf(10000),yf(10000),yp(10000)
real*8 x(6900)
real*8 flueks(10000),extcurve(10000)
real*8 xg,yg(10000),x2,y2(10000)
REAL*8 sng,ewa,ewb,ewg,hha,hhb,oldage(3)
REAL*8 Mo(9),MiMy(9),Myoung,Mint,Mold,Myopt(3),Miopt(3),Moopt(3)
REAL*8 Fyoung,Fint,Fold(7),Noise
real*8 a,b,c, plyus,minus,xx,nebemm(6900),yy(6900)
real*8 Flyoung(6900),Flint(6900),Flold(6900)
real*8 ha,Oiii4959,Oiii5007,Nii,Nii2,Sii6717,Sii6731,Oii3727,Hei
real*8 hhg,hg,Oiii4363,Oii7319,Oii7330,Nii6548,Nii6584
real*8 R23,R3,P,XNII,xis,yps,O3N2,R,Z,k0,k1,k2,q,logq
real*8 OHNII,OHZ,OHMcG,OHP,OHKD,I2lOH,OHKK
real*8 OHKKD,OHKKbe,OHPPN2,OHPPO3N2,OHP05,I2lOHbef
logical anynull
  ebminv = 0.
namech='/home/matheus/Desktop/IC/Spectra/Elliptical/spec-0266-51602-0467.fits'
write(6,*)namech
readwrite=0
status=0
call ftopen(17,namech,readwrite,blocksize,status)
call ftghsp(17,keysexist,keysadd,status)
do n=1,keysexist
  call ftgrec(17,n,card,status)
  if (card(1:9)=='CRVAL1  =') then
    read(card,'(a9,e21.14)')alibi,a
  endif
  if (card(1:6)=='NAXIS1') then
    read(card,'(a9,i21)')alibi,
   endif
  if (card(1:6)=='Z     ') then
    read(card,'(a9,e21.14)')alibi,redshift
  endif
  if (card(1:6)=='SN_G  ') then
    read(card,'(a9,e21.14)')alibi,sng 
  endif
enddo
l(1)=10.**a/(1.+redshift)
l(naxes)=10.**(a+0.0001*float(naxes-1))/(1.+redshift)
  do n=1,naxes
  l(n)=10.**(a+0.0001*float(n-1))
enddo
 call ftthdu(17,hdnum,status)
call ftgidt(17,bitpix,status)
call ftgtcl(17,1,datacode,repeat,width,status)
call ftgpve(17,1,1,naxes,0.,fa,anynull,status)
call ftgpve(17,1,naxes+1,naxes,0.,fcs,anynull,status)
call ftgpve(17,1,2*naxes+1,naxes,0.,noiz,anynull,status)
call ftgpve(17,1,3*naxes+1,naxes,0.,mask,anynull,status)
call ftclos(17,status) 
write(6,*)'spectra read in',l(1),l(naxes)
arq='spec-1.txt'
open (29,file=arq,status='unknown')
write(29,*) '  l(n)','                      fa(n)'
do n=1,naxes
   write(29,*) l(n), fa(n)
end do


 close(25)
write(6,*)
write(6,'(a)')'Justice is done'
 end


实际上会发生错误,因为它使naxes始终为零值!


Actually the error happens because it gives to naxes always a zero value!

推荐答案

Fortran中致命内存错误的最常见原因是非法数组下标以及对过程(子例程或函数)的调用参数之间的不一致以及声明的过程参数.首先,打开运行时下标检查.使用gfortran,-fcheck=bounds或更高版本,请使用-fcheck=all启用其他运行时检查.对于过程参数问题,请将所有过程放入任何调用任何过程的例程中的模块中,并use这些模块中的那些模块中.这将使编译器能够在编译时检查参数的一致性.

The most frequent causes of fatal memory errors in Fortran are illegal array subscripts and inconsistency between the arguments of the call to a procedure (subroutine or function) and what the declared arguments of the procedure. For the first, turn on run-time subscript checking. With gfortran, -fcheck=bounds, or better, turn on additional run-time checks with -fcheck=all. For the procedure argument issue, place all of your procedures into module(s) and use those module(s) from any routine that calls any of the procedures. This will enable the compiler to check argument consistency at compile time.

这篇关于“分段故障(核心已转储)"; Fortran gfortran Linux中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆