F2py is used to create interfaces so that python can call the FORTRAN program. It supports many Fortran compilers, such:
Absoft, Lahey, IBM, gfortran, and g95.
F2py is now part of numpy.
1. Install python25
Create distutils. cfg in C:/python25/lib/distutils
[Build]
Compiler = mingw32
2. Install mingw
3. Install g95
When compiling a FORTRAN program, g95 sometimes prompts that files such as crt2.o cannot be found, so you need to configure g95:
Copy g95/lib/*. O *. A to g95/lib/GCC-lib/i686-pc-mingw32/4.0.4
4. f2py application example
A) create a FORTRAN file HW. F with the following content:
Program hwtest
Real * 8 R1, R2, S
R1 = 1.0
R2 = 0.0
S = hw1 (R1, R2)
Write (*, *) 'hw1, result: ', S
End
Function hw1 (R1, R2)
Real * 8 R1, R2
Hw1 = sin (R1 + R2)
Return
End
B) cmd
C) f2py-m hw-c hw. f
HW. PYD is generated in the directory.
D) Python
>>> Import HW
>>> HW. hw1 (1, 0)