【发布时间】:2015-12-21 20:25:51
【问题描述】:
我在使用 f2py 编译的 fortran 模块从 ipython 中的 ascii 文件中读取浮点数时发现了一个奇怪的行为。测试文件 'test.txt' 只包含一个浮点数:
5.945
我用来读取文件的子程序可以是这样的:
subroutine read_test
implicit none
real :: dum
open(10,file='test.txt')
read(10,*) dum
print*, dum
close(10)
return
end subroutine read_test
编译
f2py -c test.f90 -m test
如果我只是使用没有命令行选项的 python 或 ipython,则读取的数字就像它们在文件中一样。
In [1]: import test
In [2]: test.read_test()
5.94500017
使用 ipython --pylab 或 --matplotlib 给出
In [1]: import test
In [2]: test.read_test()
5.00000000
这发生在 python 2.7.6、ipython 2.3.0、numpy 1.8.2 和 matplotlib 1.4.3 上。我也尝试过 ipython 3.0.0、4.0.0 和 4.0.1,numpy 1.9.2 和 1.10.2,以及 matplotlib 1.4.3 或 1.5.10。只有切换到 python 2.7.10 似乎会改变预期的行为。
谁能给我解释一下出了什么问题。不幸的是,2.7.6 是我们整个环境的默认版本,升级会有点麻烦。
【问题讨论】:
-
你看过生成的python代码了吗?
-
不,但你到底是什么意思?只有 f2py 生成的共享库 test.so。
-
我有一个模糊的记忆,在邮件列表中看到这样的问题,它与
locale设置有关。 python3也会出现这种情况吗?
标签: python matplotlib ipython f2py