Sunday, 12 September 2021

compiling basic fortran module with f2py

I am trying to use F2py but am getting some error messages or warnings on compilation involving `deprecated numpy'. I'm unsure how to fix this. I'm using python 2.7.17 and fortran90.

I compile by writing
f2py -c f2py_F90.f90 -m fortran

Note, compiling with : f2py -c f2py_F90.f90 -m fortran \
doesn't fix the problem either.

Below are the basic fortran and python codes that indicate the problem I'm having. This example is minimal, complete and verifiable. How can I fix this problem and succesfully have python execute the fortran module I'm passing into it?

The message I get is

warning "Using deprecated NumPy API"

The expected output should give a = [2,1,3] but instead I get the warning described above.

!fortran code
module fmodule
   implicit none
contains
   subroutine fast_reverse(a,n)

   integer, intent(in) :: n
   real, intent(inout) :: a(:)

   a(1:n) = a(n:1:-1)

   end subroutine fast_reverse
end module fmodule

#python code
import fortran
import numpy as np

a = np.array([1,2,3],np.float32)

fortran.fmodule.fast_reverse(a,2)

a #the output should give a = [2,1,3] 


from compiling basic fortran module with f2py

No comments:

Post a Comment