f2py doesn't like explicit shaped array in subroutine

I am trying to compile a python module from some Fortran code using f2py . The code compiles fine with ifort, but throws up errors when using f2py. Here is the code (it is over two files):

gdat.f90:

  MODULE GDAT
  PUBLIC

  INTEGER :: NX, NY

  END MODULE GDAT

part.f90:

  SUBROUTINE PART(ARR)

  USE GDAT, ONLY: NX, NY
  INTEGER, INTENT(IN) :: ARR(NX,NY)
  PRINT*, ARR

  END SUBROUTINE PART

I compile it using f2py -c gdat.f90 part.f90 -m part , but I get errors about nx and ny not being defined, eg: /var/tmp/tmp2hzU6s/src.linux-x86_64-2.7/untitledmodule.c: In function 'f2py_rout_untitled_part': /var/tmp/tmp2hzU6s/src.linux-x86_64-2.7/untitledmodule.c:180: error: 'nx' undeclared (first use in this function)

It seems to be a problem with the definition of the explicitly shaped array ARR . Like I say, it compiles fine on ifort.

I know this is a simple piece of code and can be written another way, but it is just a test piece that I wrote: I am actually trying to compile a much larger set of fortran modules that have lots of these explicit array definitions in the (using variables from a central module to define the bounds), so I would really like to get this to work rather than rewrite this other code!


As far as I understand this, you have the problem, that the size of arrays has to be dynamic via ALLOCATABLE or already fixed with numerical constants or parameters.

In your case, the variables nx and ny are neither set nor parameters. And if you want to compile your two files separately into modules (with ifort and not f2py ), it should also complain.


Try creating a signature file via

f2py -m pythmod -h signature.pyf gdat.f90 part.f90

and then using it with

f2py -c signature.pyf gdat.f90 part.f90 .

This creates the file pythmod.so .

链接地址: http://www.djcxy.com/p/96136.html

上一篇: f2py与fortran netcdf

下一篇: f2py不喜欢子程序中的显式整形数组