Differences between revisions 1 and 5 (spanning 4 versions)
Revision 1 as of 2012-12-05 18:28:46
Size: 359
Editor: MikhailItkin
Comment:
Revision 5 as of 2012-12-05 20:10:30
Size: 1101
Editor: MikhailItkin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= F2PY == F2PY
Line 3: Line 3:
A tool that provides connection between Python and Fortran languages
[[http://www.scipy.org/F2py |Official website]]
<<TableOfContents(4)>>

A tool that provides connection between Python and Fortran languages [[http://www.scipy.org/F2py|Official website]]
Line 8: Line 9:
Enter {{{f2py}}} to see the usage options
Enter {{{f2py -c --help-fcompiler}}} to see what fortran compilers does f2py recognize
{{{
Type:

f2py # to see the usage options
f2py -c --help-fcompiler # to see what local fortran compilers does f2py recognize
}}}


f2py wraps Fortran code and allows to use it as a Python module.

== "Hello world" ==

{{{

C File hello_world.f
      subroutine foo (a)
      integer a
      print*, "Hello from Fortran!"
      print*, "a=",a
      end

}}}

Compile:

{{{
f2py -c -m hello hello.f --fcompiler=gfortran
}}}

Try it in Python:

{{{

import hello
print hello.__doc__
hello.foo(4)

}}}

== Signatures ==


== Compare pure Python and Python+Fortran ==

{{http://www.myrevsource.com/blog/wp-content/uploads/2011/06/treadmill.gif}}

file (watermask, 10x10 degrees, 250m resolution): /home/zmaw/m300036/svn/RemoteSensing/user/mikhail/projects/watermask/MOD44W.A2000055.h18v04.005.2009212173853.hdf

F2PY

A tool that provides connection between Python and Fortran languages Official website

Advanced examples how to use f2py

Type:

f2py # to see the usage options
f2py -c --help-fcompiler # to see what local fortran compilers does f2py recognize

f2py wraps Fortran code and allows to use it as a Python module.

"Hello world"

C File hello_world.f
      subroutine foo (a)
      integer a
      print*, "Hello from Fortran!"
      print*, "a=",a
      end

Compile:

f2py -c -m hello hello.f --fcompiler=gfortran

Try it in Python:

import hello
print hello.__doc__
hello.foo(4)

Signatures

Compare pure Python and Python+Fortran

http://www.myrevsource.com/blog/wp-content/uploads/2011/06/treadmill.gif

file (watermask, 10x10 degrees, 250m resolution): /home/zmaw/m300036/svn/RemoteSensing/user/mikhail/projects/watermask/MOD44W.A2000055.h18v04.005.2009212173853.hdf

LehreWiki: PythonCourse/PythonLES/F2Py (last edited 2012-12-06 09:23:18 by MikhailItkin)