F2py + g95 + mingw + windows configuration and use

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.