【发布时间】:2015-05-26 12:40:37
【问题描述】:
我正在向开源科学代码添加一些功能。我使用了很多可分配对象,但是在正确打印它们时遇到了一些麻烦。比如我声明并分配,然后使用:
real(dp), allocatable :: psi_n_phi(:)
! some other stuff here
allocate(psi_n_phi(1:fock_info%nocc(isp)))
! nocc(isp) is simply equal to 1 in this context
! some other stuff here
do n = 1, fock_info%nocc(isp)
psi_n_phi(n) = dot_product(fock_info%psi(:, n, isp), p)
enddo
我后来得到一个数组不匹配,我正在使用 gdb 找出原因。如果我打印:
(gdb) p psi_n_phi
$23 = (0)
但显然情况并非如此,如下所示:
(gdb) p psi_n_phi@1
$25 = (( 0) )
(gdb) p psi_n_phi@2
$26 = (( 0) ( 0) )
(gdb) p psi_n_phi@10
$28 = (( 0) ( 0) ( 0) ( 2.0162819006781271e-320) ( 2.2600760244771319e-316) ( 2.3792209431030402e-316) ( 6.9179818424594845e-310) ( 2.2598704931684619e-316) ( 6.9179818424672413e-310) ( 0) )
我从http://numericalnoob.blogspot.co.il/2012/08/fortran-allocatable-arrays-and-pointers.html 获得了有关使用@ 表示法的信息。这只是我能找到的关于这个问题的唯一来源,尽管我看到了一些其他问题,人们遇到了类似的问题(但没有一个能够解决它)。
这里有什么想法吗?我想了解为什么将它打印为((0)),以及如何让它像普通数组一样打印。
【问题讨论】:
标签: gdb fortran gfortran fortran95