[NumPy-Tickets] [NumPy] #1532: f2py does not respect assumed size arrays of fortran 90

NumPy Trac numpy-tickets@scipy....
Sat Feb 26 16:14:51 CST 2011


#1532: f2py does not respect assumed size arrays of fortran 90
--------------------------+-------------------------------------------------
  Reporter:  ozn          |       Owner:  pearu      
      Type:  enhancement  |      Status:  reopened   
  Priority:  normal       |   Milestone:  Unscheduled
 Component:  numpy.f2py   |     Version:  devel      
Resolution:               |    Keywords:             
--------------------------+-------------------------------------------------

Comment(by lorenz):

 Thanks for your enthusiasm! I did try out your f2py, and it works great
 for the example I gave above. However, for my actual problem I still
 encountered some
 little issues:

 I would include the "use" statements of the original routine in the
 wrapper
 routine, as variable definitions might depend on definitions made there,
 one
 possible example would be where the kind specifier is stored in some
 module:

 precision.f90:
 {{{
 module precision
   integer, parameter :: rk = selected_real_kind(8)
   integer, parameter :: ik = selected_real_kind(4)
 end module
 }}}

 test2.f90:
 {{{
 subroutine assumed_shape_test(x, res)
   use precision

   implicit none

   real(kind=rk), intent(in) :: x(:)
   real(kind=rk), intent(out) :: res

   integer :: i

   print *, "size(x) = ", size(x)

   res = 0.0

   do i = 1, size(x)
     res = x(i)
   enddo

 end subroutine
 }}}

 We end up with the f2py generated wrapper test2-f2pywrappers.f:
 {{{
 C     -*- fortran -*-
 C     This file is autogenerated with f2py (version:2)
 C     It contains Fortran 77 wrappers to fortran functions.

       subroutine f2pywrapassumed_shape_test (x, res, f2py_x_d0)
       real(kind=rk) res
       integer f2py_x_d0
       real(kind=rk) x(f2py_x_d0)
       interface
       subroutine assumed_shape_test(x,res)
           use precision
           real(kind=rk) ,intent(in),dimension(:) :: x
           real(kind=rk) ,intent(out) :: res
       end subroutine assumed_shape_test
       end interface
       call assumed_shape_test(x, res)
       end
 }}}
 which does not compile, as rk is not defined in the subroutine itself.

 When creating this example, I first put the module definition in the same
 file
 and discovered another issue, see #1750.

 In this specific example, f2py apparently tried to translate the kind
 specifiers automatically, but failed. Without your patch, the kind
 statements are just
 ignored and the kind is assumed to be float(?). With your patch, this now
 even
 leads to a defect wrapper file: There, the variables are declared
 with "kind=selected":
 {{{
 C     -*- fortran -*-
 C     This file is autogenerated with f2py (version:2)
 C     It contains Fortran 77 wrappers to fortran functions.

       subroutine f2pywrapassumed_shape_test (x, res, f2py_x_d0)
       real(kind=selected) res
       integer f2py_x_d0
       real(kind=selected) x(f2py_x_d0)
       interface
       subroutine assumed_shape_test(x,res)
           use precision
           real(kind=rk) ,intent(in),dimension(:) :: x
           real(kind=rk) ,intent(out) :: res
       end subroutine assumed_shape_test
       end interface
       call assumed_shape_test(x, res)
       end
 }}}
 Which does of course not compile.

 Thank you for your work, I'm glad to be of some help,
    Lorenz

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1532#comment:9>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list