需要让 f2py 工作,但不知道任何 fortran
need to get f2py working, but don't know any fortran
我想使用此源代码中的函数 OPAC:
http://opalopacity.llnl.gov/codes/xztrin21.f
我不太理解代码,我只是想将它用作 Python 模块。我 运行 以下内容:
f2py -c xztrin21.f -m opal_opacity
但我总是得到这个错误:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c: In function ‘f2py_init_cst’:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: note: each undeclared identifier is reported only once for each function it appears in
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c: In function ‘f2py_init_cst’:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: note: each undeclared identifier is reported only once for each function it appears in
error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/tmpWe2VM7/src.linux-x86_64-2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c /tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c -o /tmp/tmpWe2VM7/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.o" failed with exit status 1
我不认为代码真的有什么问题。我相信其他人让它工作正常,所以我想我一定是有一个错误的 Fortran 编译器或其他东西。不过我不确定该怎么办。
感谢任何帮助
编辑:
如果我尝试使用 gfortran 编译代码,我会得到以下信息:
xztrin21.f:1025.72:
IF (H.EQ.0.) PAUSE 'Bad XA input.'
1
Warning: Deleted feature: PAUSE statement at (1)
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
好的,这看起来不像是您链接的 Fortran 代码的问题。
你的实际错误都找到了In function ‘f2py_init_cst’
:
:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
从名称来看,这表明 python 包 f2py
存在问题。
上面的语法意味着编译器在 f2py
代码中的 line: 1828, column:35
和 line:1819, column:71
上发现了错误。
- 我建议您查看
f2py
网站上的文档并确保您正确编译它
- 作为测试,work through the examples 显示在
f2py
文档中并确保您可以编译它们
所以我先创建一个签名文件解决了这个问题。我运行命令
f2py -h opal.pyf -m opal xztrin21.f
比
f2py -c add.pyf add.f95
现在可以正常使用了。我使用了这个教程:
http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html
f2py -c --fcompiler=gnu95 -m modulename filename.f95
此命令应该有效。
http://www.ucs.cam.ac.uk/docs/course-notes/unixcourses/pythonfortran/files/f2py.pdf
这是一个非常简单的文档,介绍了如何在 python 中使用 fortran 模块。这对我很有帮助。
我想使用此源代码中的函数 OPAC: http://opalopacity.llnl.gov/codes/xztrin21.f
我不太理解代码,我只是想将它用作 Python 模块。我 运行 以下内容:
f2py -c xztrin21.f -m opal_opacity
但我总是得到这个错误:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c: In function ‘f2py_init_cst’:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: note: each undeclared identifier is reported only once for each function it appears in
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c: In function ‘f2py_init_cst’:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: note: each undeclared identifier is reported only once for each function it appears in
error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/tmpWe2VM7/src.linux-x86_64-2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c /tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c -o /tmp/tmpWe2VM7/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.o" failed with exit status 1
我不认为代码真的有什么问题。我相信其他人让它工作正常,所以我想我一定是有一个错误的 Fortran 编译器或其他东西。不过我不确定该怎么办。
感谢任何帮助
编辑: 如果我尝试使用 gfortran 编译代码,我会得到以下信息:
xztrin21.f:1025.72:
IF (H.EQ.0.) PAUSE 'Bad XA input.'
1
Warning: Deleted feature: PAUSE statement at (1)
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
好的,这看起来不像是您链接的 Fortran 代码的问题。
你的实际错误都找到了In function ‘f2py_init_cst’
:
:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
从名称来看,这表明 python 包 f2py
存在问题。
上面的语法意味着编译器在 f2py
代码中的 line: 1828, column:35
和 line:1819, column:71
上发现了错误。
- 我建议您查看
f2py
网站上的文档并确保您正确编译它 - 作为测试,work through the examples 显示在
f2py
文档中并确保您可以编译它们
所以我先创建一个签名文件解决了这个问题。我运行命令
f2py -h opal.pyf -m opal xztrin21.f
比
f2py -c add.pyf add.f95
现在可以正常使用了。我使用了这个教程: http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html
f2py -c --fcompiler=gnu95 -m modulename filename.f95
此命令应该有效。
http://www.ucs.cam.ac.uk/docs/course-notes/unixcourses/pythonfortran/files/f2py.pdf
这是一个非常简单的文档,介绍了如何在 python 中使用 fortran 模块。这对我很有帮助。