[SciPy-user] Problem (bug?) using modules with f2py

Rob Hetland hetland at tamu.edu
Mon Jan 15 11:52:08 CST 2007


I am trying to create a module that will store a model grid, and  
operate on that grid.  The grids for different applications are  
different sizes.  I imagine that I will recompile the module for each  
application separately, defining the grid size at compile time.   
Perhaps this is not the best approach, but the grids may be large,  
and I want to be efficient with memory.

I would like the simple example outlined below to work, but now it  
does not.  It seems that if a matrix is passed to f2py with intent 
(out), it does not acknowledge the parameters in the module.  It  
*does* work without output variable -- i.e., and empty argument list  
to get_array.

There are ways around this, but I think this should work, and suspect  
a bug.  Any suggestions?

-Rob




### TEST MODULE:


       MODULE mod_test

       implicit none
       integer, parameter :: Lm = 512
       integer, parameter :: Mm = 256

       TYPE T_GRID
         real*8 x(1:Lm, 1:Mm)
       END TYPE T_GRID
       TYPE (T_GRID) :: GRID

       CONTAINS


       SUBROUTINE initialize (val)

       integer i, j
       real*8 val

       do i=1,Lm
         do j=1,Mm
             GRID % x(i,j) = val
         end do
       end do

       RETURN
       END SUBROUTINE initialize

       END MODULE mod_test




### PY_TEST.F

       subroutine init(a)

       USE mod_test

       real*8 a

       CALL initialize(a)

       return
       end



       subroutine get_array_dont_work(val)
! does not compile, but does if the above line has an empty argument  
list..

       USE mod_test

       real*8 val(1:Lm, 1:Mm)
cf2py intent(out) val

       integer i, j

       do i=1,Lm
           do j=1,Mm
               val(i,j) = GRID % x(i,j)
           end do
       end do

       return
       end



       subroutine get_array_works()
! This routine, for example, DOES work as expected.

       USE mod_test

       real*8 val(1:Lm, 1:Mm)

       integer i, j

       do i=1,Lm
           do j=1,Mm
               val(i,j) = GRID % x(i,j)
               print *, i, j, val(i,j)
           end do
       end do

       return
       end


----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331




----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331




More information about the SciPy-user mailing list