我的代码中出现了一些奇怪的问题,我之前从未遇到过这样的问题。我有一个程序计算两个在自身重力下运行的物体和在do循环中运行,我用它来计算它们随时间的运动,我有一个写入语句,将数据写入文件以便稍后绘制。但是,我最近想要删除write语句,但是当我删除它时,程序在几次计算后崩溃,数据被NaN填充。我将在下面添加几行。
open(unit=100,file=datafile) !open file with name datafile (#)
do while(ctime<totaltime) !loop until current time > total time
call calc_semimajor(Objects, a) !calculate semimajor axis
call calc_ecc(Objects, evector, e) !calculate eccentricty
at = (a0**4 - (264.0d0/5.0d0)*beta_time*ctime)**0.25
write(100,*) ctime, Objects(1:2), a, at, e !write to file (#)
!some
!more
!lines
!here...
end do
close(100) !close datafile (#)
我将这个循环存储在一个子程序中供参考,但在我用之前的其他程序之前它从来都不是问题。我已经尝试更改没有工作的单元号。我已经停止传入数据文件字符参数,只是在子程序中将文件定义为'data.txt',但是没有工作。我已经尝试将其复制为纯文本并使用gfortran重新编译,但这并没有奏效。我确实使用nagfor进行编译,并且发出了一个下溢错误并设法在崩溃之前计算了几个时间步,但是当我删除涉及unit = 100(标有(#))的行的注释时,该错误消失了。我甚至尝试重写enitre程序,看看我是否错过了一些东西,但即使重写没有open()语句,我仍然会遇到这个问题。我确实有一些常量存储在一个模块中,如果这可能是一个问题,那么它们会输入子程序吗?我很抱歉,如果措辞不好但我只是想知道是否有人曾经在Fortran之前遇到过这个问题,如果有的话,我怎么能解决它?
谢谢!
编辑:我使用valgrind来帮助找到问题所在。 (使用之前的-g标志进行编译)并且产生了这个重复错误
`==14846== Conditional jump or move depends on uninitialised value(s)
==14846== by 0x40131B: leapfrog_ (/path/to/file)
==14846== by 0x40353C: MAIN__ (/path/to/file)
==14846== by 0x403939: main (/path/to/file)
==14846== Uninitialised value was created by a stack allocation
==14846== at 0x401C12: calc_pnacceleration_ (/path/to/file)
我在子程序的接口中添加并在子程序中放置虚拟变量,而不是使用主体中的相同变量名。这还没有解决问题。但是,我注意到的一件事是,如果我遵守优化标志(-O3),则错误消失,并且运行指定的总时间。这可能表示任何特定错误吗?
第二次编辑:我在使用gfortran -Wall -g -fcheck=all -fbacktrace
Simulation: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:
(.text+0x0): first defined here
Simulation: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o:
(.fini+0x0): first defined here
Simulation:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:
(.rodata.cst4+0x0): first defined here
Simulation: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:
(.data+0x0): first defined here
Simulation: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o:(.data+0x0): first defined
here
Simulation: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o:
(.init+0x0): first defined here
/tmp/ccDIKQQB.o: In function `calc_ecc_':
/path/to/file/Simulation.f90:441: multiple definition of `calc_ecc_'
Simulation:(.text+0xf6): first defined here
/tmp/ccDIKQQB.o: In function `crossproduct_':
/path/to/file/Simulation.f90:466: multiple definition of
`crossproduct_'
Simulation:(.text+0x1624): first defined here
/tmp/ccDIKQQB.o: In function `leapfrog_':
/path/to/file/Simulation.f90:262: multiple definition of `leapfrog_'
Simulation:(.text+0x26d): first defined here
/tmp/ccDIKQQB.o: In function `calc_pnacceleration_':
/path/to/file/Simulation.f90:358: multiple definition of
`calc_pnacceleration_'
Simulation:(.text+0xe57): first defined here
/tmp/ccDIKQQB.o: In function `calc_semimajor_':
/path/to/file/Simulation.f90:426: multiple definition of
`calc_semimajor_'
Simulation:(.text+0xd8b): first defined here
/tmp/ccDIKQQB.o: In function `dotproduct_':
/path/to/file/Simulation.f90:479: multiple definition of
`dotproduct_'
Simulation:(.text+0x15c1): first defined here
/tmp/ccDIKQQB.o: In function `calc_deltaphigr_':
/path/to/file/Simulation.f90:415: multiple definition of
`calc_deltaphigr_'
Simulation:(.text+0x16ed): first defined here
/tmp/ccDIKQQB.o: In function `main':
/path/to/file/Simulation.f90:25: multiple definition of `main'
Simulation:(.text+0x2be5): first defined here
/tmp/ccDIKQQB.o: In function `plotdata_':
/path/to/file/Simulation.f90:231: multiple definition of
`plotdata_'
Simulation:(.text+0x2c20): first defined here
/tmp/ccDIKQQB.o: In function `writeline_':
/path/to/file/Simulation.f90:490: multiple definition of `writeline_'
Simulation:(.text+0x3418): first defined here
/usr/lib/gcc/x86_64-linux-gnu/5/crtend.o:(.tm_clone_table+0x0):
multiple definition of `__TMC_END__'
Simulation:(.data+0x18): first defined here
/usr/bin/ld: error in Simulation(.eh_frame); no .eh_frame_hdr table
will be created.
collect2: error: ld returned 1 exit status
答案 0 :(得分:0)
使用以下选项编译代码:
gdb
修复所有警告。当您运行代码时,请使用&#39; y&#39;和&#39; 1&#39;
作为你的投入。当它因使用未初始化而死亡时
变量。使用const MainNavigator = createBottomTabNavigator({
BookmarksList: createStackNavigator({
BookmarkList: { screen: BookmarkList },
UpdateBookmark: { screen: UpdateForm }
}),
NewBookmark: createStackNavigator({
NewBookmark: { screen: NewBookmarkScreen }
})
});
查看核心转储。