[f2py] f2py failed for keyword error

Evan Mason evanmason at gmail.com
Tue Apr 5 15:18:02 EEST 2011


Hi, I'm struggling with getting started with f2py.


I get the pyf:

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

python module testfillnans ! in
    interface  ! in :testfillnans
        subroutine testfillnans(lx,rn,cn,lrn) ! in: testfillnans:testfillnans.f90
            integer :: lx
            integer dimension(lrn) :: rn
            integer dimension(lrn),depend(lrn) :: cn
            integer optional,check(len(rn)>=lrn),depend(rn)
 :: lrn=len(rn)
        end subroutine testfillnans
    end interface
end python module testfillnans

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


from this f90 routine:

subroutine testfillnans (lx,rn,cn,lrn)

  implicit none
  integer                      :: lx
  integer                      :: lrn
  integer, dimension(lrn)      :: rn
  integer, dimension(lrn)      :: cn

  print*, lx,rn(1:5),rn(lrn-5:lrn),cn(1:5),cn(lrn-5:lrn),
lrn
  print*,'end'

end subroutine testfillnans


When called from a python script the above works fine.


However, if I add an extra argument (e.g., lr) to the f90
 routine, i.e.:

 subroutine testfillnans (lx,rn,cn,lrn,lr)

  implicit none
  integer                      :: lx
  integer                      :: lrn
  integer, dimension(lrn)      :: rn
  integer, dimension(lrn)      :: cn
  integer                      :: lr

  print*, lx,rn(1:5),rn(lrn-5:lrn),cn(1:5),cn(lrn-5:lrn),
lrn,lr
  print*,'end'

end subroutine testfillnans

so that the pyf is now:

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

python module testfillnans ! in
    interface  ! in :testfillnans
        subroutine testfillnans(lx,rn,cn,lrn,lr) ! testfillnans:testfillnans.f90
            integer :: lx
            integer dimension(lrn) :: rn
            integer dimension(lrn),depend(lrn) :: cn
            integer optional,check(len(rn)>=lrn),depend(rn) :: lrn=len(rn)
            integer :: lr
        end subroutine testfillnans
    end interface
end python module testfillnans

! This file was auto-generated with f2py (version:1_8464).


I find when I call from python I get:

[emason at acacia tools]$ python test_fillnans.py
Traceback (most recent call last):
  File "test_fillnans.py", line 62, in <module>
    fn.testfillnans(lx,rn,cn,lrn,lr)
testfillnans.error: (len(rn)>=lrn) failed for 1st keyword lrn: 
estfillnans:lrn=8340


But lrn=2110, it is lr that equals 8340.  I'd be grateful for
 any help on this.

Thanks, Evan






More information about the f2py-users mailing list