f2py+g95+mingw+windows的配置和使用

來源:互聯網
上載者:User

f2py用於建立介面,使得Python可以調用fortran程式,它支援諸多fortran編譯器,如:

Absoft, Lahey, IBM, gfortran和g95。

f2py現在是numpy的一部分。

1. 安裝python25

   建立distutils.cfg在 c:/python25/lib/distutils

   [build]

   compiler=mingw32

2. 安裝mingw

3. 安裝g95 

   由於編譯fortran程式時,g95有時會提示找不到crt2.o等檔案,因此需要對g95進行配置:   

   copy  g95/lib/*.o *.a to g95/lib/gcc-lib/i686-pc-mingw32/4.0.4 

4. f2py應用樣本

   a)建立一fortran檔案 hw.f,檔案內容如下:

      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

    d)python

      >>>import hw

      >>>hw.hw1(1,0)      

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.