[f2py] Return a 3D array

Trond Kristiansen trond.kristiansen at imr.no
Sat Dec 13 18:38:55 EET 2008

Hi again all, Pearu.
Yesterday I emailed the list, but my message was in html and not  
easily readable so I try one more time. Sorry for the double ups.

I am trying to return a 3D array from a successfully wrapped fortran  
subroutine. The routine runs perfectly, but when I return to Python  
the expected 3D array is a "None" object. The output 3D array is  
passed as a zero 3D array into Fortran, then filled up with values in  
Fortran, and then returned (as a result of the intent(out) statement).  
I assume I am doing something wrong in how to declare the return  
array, and I appreciate help to solve my problem.

Thank you very much and sorry for the double postings.

Cheers, Trond Kristiansen

The top part of my Fortran subroutine looks like this:

subroutine doVertInter(dat,outdat,zr,zs,Nroms,Nsoda,II,JJ)
double precision rz2, rz1
integer II, JJ, ic, jc, kc, kT, Nsoda, Nroms
double precision, dimension(Nsoda,JJ,II) :: dat
double precision, dimension(Nroms,JJ,II) :: zr, outdat
double precision, dimension(Nsoda) ::  zs

!cf2py intent(in) dat, zr, zs, Nroms, Nsoda
!cf2py intent(out) outdat
!cf2py intent(hide) ic,jc,kc,kT,rz1,rz2,JJ,II

My wrapped pyf file looks like this:

python module vertInterp ! in
     interface  ! in :vertInterp
         module interpolation ! in :vertInterp:verticalInterp.f90
dovertinter(dat,outdat,zr,zs,nroms,nsoda,ii,jj) !  
in :vertInterp:verticalInterp.f90:interpolation
                 double precision dimension(nsoda,jj,ii) :: dat
                 double precision  
dimension(nroms,jj,ii),depend(jj,ii) :: outdat
                 double precision  
dimension(nroms,jj,ii),depend(nroms,jj,ii) :: zr
                 double precision dimension(nsoda),depend(nsoda) :: zs
                 integer optional,check(shape(outdat, 
0)==nroms),depend(outdat) :: nroms=shape(outdat,0)
                 integer optional,check(shape(dat, 
0)==nsoda),depend(dat) :: nsoda=shape(dat,0)
                 integer optional,check(shape(dat, 
2)==ii),depend(dat) :: ii=shape(dat,2)
                 integer optional,check(shape(dat, 
1)==jj),depend(dat) :: jj=shape(dat,1)
             end subroutine dovertinter
         end module interpolation
     end interface
end python module vertInterp

More information about the f2py-users mailing list