0
我創建了使用模塊dimpar的我的簽名文件。 當我嘗試使用簽名文件來編譯,f2py不承認msects和maxpar,結果我得到:f2py使用模塊 - 簽名文件
/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
Array.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
是否有效的Fortran代碼?不應該是'integer,parameter :: msects = 36,maxpar = 80'? –
@AlexanderVogt:這些行似乎是用ifort和gfortran編譯的。 –
@KyleKanos:是的,我在[Chapman]的書中查了一下(http://www.amazon.com/Fortran-2003-Scientists-amp-Engineers/dp/0073191574/ref=sr_1_1?ie=UTF8&qid= 1382105045&SR = 8-1&關鍵字=查普曼+ FORTRAN)。我對FORTRAN 77並不太確定。 –