我想用python运行一些fortran代码,并使用f2py -c -m 。 但是,似乎只有FUNCTION被打包到.so文件中,而不是打包到PROGRAM中 。 那我怎么处理全局变量呢? 例如,变量c放在模块中
MODULE nfw double precision :: c END MODULE nfw,在PROGRAM中被修改,并由隐含的同一文件中的FUNCTION使用
PROGRAM Compute_Profile USE nfw c = 5.0 END PROGRAM Compute_Profile DOUBLE PRECISION FUNCTION y(x) USE nfw double precision :: x y = c * x return END FUNCTION y我如何调用让函数y(x)知道python中c的值?
I want to run some fortran codes with python and am using f2py -c -m for it. However, it seems that only the FUNCTIONs are packed into the .so file, but not the PROGRAM. How can I deal with global variables then? For example, a variable c is put in a module
MODULE nfw double precision :: c END MODULE nfw,is modified in the PROGRAM, and is used by a FUNCTION in the same file implicitly
PROGRAM Compute_Profile USE nfw c = 5.0 END PROGRAM Compute_Profile DOUBLE PRECISION FUNCTION y(x) USE nfw double precision :: x y = c * x return END FUNCTION yHow can I call let the function y(x) know about the value of c in python?
最满意答案
在你的f2py模块下应该是另一个模块,Fortran一个名为nfw。 应该在那里。
$ f2py -c -m mod nfw.f90 $ python import mod mod.nfw.c array(0.0)确保使用带有f2py的模块编译源文件。
Under your f2py module should be another module, the Fortran one named nfw. It should be there.
$ f2py -c -m mod nfw.f90 $ python import mod mod.nfw.c array(0.0)Make sure you compile the source file with the module with f2py.
更多推荐
发布评论