0

i created my signature file which is using the module dimpar. When i try to compile using the signature file, f2py doesn't recognize the msects and maxpar and as a result i get:

/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

How do i make f2py understand that those parameters are coming from the module?

Thanks

Signature file:

!    -*- 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/

the module dimpar:

 module dimpar

  parameter (msects=36) 

  parameter (maxpar=80) 

 end module dimpar

Here is some sample code to replicate the problem:

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

Once compiled i run:

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

f2py --fcompiler=gfortran -c useArray.pyf array.o dimpar.o 
user1964154
  • 416
  • 1
  • 4
  • 10
  • Is that valid Fortran code? Shouldn't it be `integer,parameter :: msects=36, maxpar=80`? – Alexander Vogt Oct 18 '13 at 13:59
  • @AlexanderVogt: Those lines appear to compile with ifort and gfortran. – Kyle Kanos Oct 18 '13 at 14:02
  • @KyleKanos: Yeah, I looked it up in the book of [Chapman](http://www.amazon.com/Fortran-2003-Scientists-amp-Engineers/dp/0073191574/ref=sr_1_1?ie=UTF8&qid=1382105045&sr=8-1&keywords=chapman+fortran). I'm not too firm with FORTRAN 77. – Alexander Vogt Oct 18 '13 at 14:04
  • Did you compile `dimpar`? – Kyle Kanos Oct 18 '13 at 14:05
  • Yes dimpar is compiled and seems to work in the cases where his paramters are not used directly in the signature file like in this case. I may be wrong but i was thinking that my case looks somehow similar to this: http://stackoverflow.com/questions/17156125/f2py-exposing-parameters-from-used-modules Could it be that i need to use something like `!f2py integer, parameter :: a` like in the solution there proposed? – user1964154 Oct 19 '13 at 06:50

1 Answers1

1

Found the problem, to make it work i need to put in the signature file the the module too:

f2py -m useArray -h useArray.pyf dimpar.f90 array.f90
user1964154
  • 416
  • 1
  • 4
  • 10