On Fri, May 6, 2011 at 10:18 PM, DJ Luscher <d...@lanl.gov> wrote: > > I have encountered another minor hangup. For assumed-shape array-valued > functions defined within a fortran module there seems to be some trouble in > the > autogenerated subroutine wrapper interface. I think it has to do with the > order > in which variables are declared in the interface specification. > > for example: > <foo_out.f90> > ! -*- fix -*- > module foo > contains > function outer(a,b) > implicit none > real, dimension(:), intent(in) :: a, b > real, dimension(size(a),size(b)) :: outer > > outer = spread(a,dim=2,ncopies=size(b) ) * > & spread(b,dim=1,ncopies=size(a) ) > > end function outer > end module > > when compiled by f2py creates the file: > <m-f2pywrappers2.f90> > ! -*- f90 -*- > ! This file is autogenerated with f2py (version:2) > ! It contains Fortran 90 wrappers to fortran functions. > > subroutine f2pywrap_foo_outer (outerf2pywrap, a, b, f2py_a_d0, f2p& > &y_b_d0) > use foo, only : outer > integer f2py_a_d0 > integer f2py_b_d0 > real a(f2py_a_d0) > real b(f2py_b_d0) > real outerf2pywrap(size(a),size(b)) > outerf2pywrap = outer(a, b) > end subroutine f2pywrap_foo_outer > > subroutine f2pyinitfoo(f2pysetupfunc) > interface > subroutine f2pywrap_foo_outer (outerf2pywrap, outer, a, b, f2py_a_& > &d0, f2py_b_d0) > integer f2py_a_d0 > integer f2py_b_d0 > real outer(size(a),size(b)) > real a(f2py_a_d0) > real b(f2py_b_d0) > real outerf2pywrap(size(a),size(b)) > end subroutine f2pywrap_foo_outer > end interface > external f2pysetupfunc > call f2pysetupfunc(f2pywrap_foo_outer) > end subroutine f2pyinitfoo > > in the subroutine interface specification the size(a) and size(b) are used > to > dimension outer above (before) the declaration of a and b themselves. This > halts my compiler. The wrapper seems to compile OK if a and b are declared > above outer in the interface. > thanks again for your help, > DJ > > Your example works fine here:
$ f2py -m foo foo_out.f90 -c $ python -c 'import foo; print foo.foo.outer([1,2],[3,4])' [[ 3. 4.] [ 6. 8.]] with outer defined before a and b. I would presume that compiler would give a warning, at least, when this would be a problem. Anyway, try to apply the following patch: -------------------------------------------------------------------- diff --git a/numpy/f2py/func2subr.py b/numpy/f2py/func2subr.py index 0f76920..f746108 100644 --- a/numpy/f2py/func2subr.py +++ b/numpy/f2py/func2subr.py @@ -90,7 +90,6 @@ def createfuncwrapper(rout,signature=0): v['dimension'][i] = dn rout['args'].extend(extra_args) need_interface = bool(extra_args) - ret = [''] def add(line,ret=ret): @@ -143,8 +142,13 @@ def createfuncwrapper(rout,signature=0): dumped_args.append(a) for a in args: if a in dumped_args: continue + if isintent_in(vars[a]): + add(var2fixfortran(vars,a,f90mode=f90mode)) + dumped_args.append(a) + for a in args: + if a in dumped_args: continue add(var2fixfortran(vars,a,f90mode=f90mode)) - + add(l) if need_interface: -------------------------------------------------------------------- to see if changing the order will fix the hang. Pearu
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion