f2py Assumed-Size Array Arguments

Pierre Schnizer Pierre.Schnizer at cern.ch
Tue Aug 27 09:13:42 EDT 2002


Pearu Peterson <pearu at cens.ioc.ee> writes:

> On 26 Aug 2002, Darryl wrote:
> 
> > I am new to python and involved in a software modernization project
> > that involves accessing fortran modules from python using the f2py
> > interface generator.  However, I have problems when trying to generate
> > an interface to a program unit which has assumed-length array
> > arguments.  Is there a compatibility issue here that I should know
> > about and if not, can someone please let me know the procedure for
> > this?
> 
> One cannot construct assumed-size array in C as the underlying
> specification is extremely compiler dependent and compiler vendors do not
> publish this information. This is the reason why you got these
> errors. However, there are some tricks that f2py could do to
> circumvent this issue but they are not implemented yet.
> 
> For now, you could write a simple wrapper to the array_sum(a) function,
> e.g.
> 
>    real function array_sum_wrap(a,n)
>      integer :: n
> !f2py integer intent(hide),depend(a) :: n = len(a)
>      real, intent(in), dimension(n) :: a
>      array_sum_wrap = array_sum( a )
>    end
> 
> and wrap this function with f2py.
> 
> Pearu

Please note that AFAIK the above code will not work as long as you do not
supply a interface definition of the function array_sum. So the above code must
be written as:
    real function array_sum_wrap(a,n)
      integer :: n
 !f2py integer intent(hide),depend(a) :: n = len(a)
      real, intent(in), dimension(n) :: a
	INTERFACE
	   FUNCTION array_sum
	     real       :: array_sum	
	     real, dimension(:) :: a 	
	   END FUNCTION array_sum
	END INTERFACE 
      array_sum_wrap = array_sum( a )
    end
 
Perhaps Pearu's code is ok for Intel's f90, but it will definitely not work for
lahey's f95 or Nag f95.

Pierre



More information about the Python-list mailing list