0

我创建了使用模块 dimpar 的签名文件。当我尝试使用签名文件进行编译时,f2py 无法识别 msects 和 maxpar,结果我得到:

/tmp/tmpj4zcO9/src.linux-i686-2.6/AtlasGeneratormodule.c:360: error: ‘msects’         undeclared here (not in a function)
/tmp/tmpj4zcO9/src.linux-i686-2.6/AtlasGeneratormodule.c:413: error: ‘maxpar’ undeclared here (not in a function)
/tmp/tmpj4zcO9/src.linux-i686-2.6/AtlasGeneratormodule.c:413: error: initializer element is not constant
/tmp/tmpj4zcO9/src.linux-i686-2.6/AtlasGeneratormodule.c:413: error: (near initialization for ‘f2py_parms_def[0].dims.d[0]’)
/tmp/tmpj4zcO9/src.linux-i686-2.6/AtlasGeneratormodule.c:360: error: ‘msects’ undeclared here (not in a function)
/tmp/tmpj4zcO9/src.linux-i686-2.6/AtlasGeneratormodule.c:413: error: ‘maxpar’ undeclared here (not in a function)
/tmp/tmpj4zcO9/src.linux-i686-2.6/AtlasGeneratormodule.c:413: error: initializer element is not constant

我如何让 f2py 了解这些参数来自模块?

谢谢

签名文件

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module AtlasGenerator ! in 
interface  ! in :AtlasGenerator
    subroutine loadhistogramdata(wdo,xlat,xlon,ah,nhs,nhb,fs,bins) ! in :AtlasGenerator:AtlasGenerator.f90
        use dimpar  
          ... 
        real dimension((msects)) :: a
        real dimension((msects)) :: c
          ...    
        real dimension((maxpar)) :: param
          ...
    end subroutine loadhistogramdata
end interface 
end python module AtlasGenerator

! This file was auto-generated with f2py (version:2).
! See http://cens.ioc.ee/projects/f2py2e/

模块 dimpar

 module dimpar

  parameter (msects=36) 

  parameter (maxpar=80) 

 end module dimpar

这是一些复制问题的示例代码:

dimpar.f90

module dimpar

      parameter (msects=36) 
end module dimpar

数组.f90

SUBROUTINE FIB(A,N)

use dimpar
REAL*8 A(msects)
DO I=1,N
 IF (I.EQ.1) THEN
    A(I) = 0.0D0
 ELSEIF (I.EQ.2) THEN
    A(I) = 1.0D0
 ELSE 
    A(I) = msects
 ENDIF
ENDDO
END

编译后我运行:

f2py -m useArray -h useArray.pyf array.f90

f2py --fcompiler=gfortran -c useArray.pyf array.o dimpar.o 
4

1 回答 1

1

发现了问题,为了让它工作,我也需要将签名文件放入模块中:

f2py -m useArray -h useArray.pyf dimpar.f90 array.f90
于 2013-10-21T08:19:30.720 回答