I am trying to modify the contents of an Numpy Array of string in a Fortran code by using the wrapper f2py. I always have the error:
ValueError: Failed to initialize intent (inout) array -- input 'c' not compatible to c.
Here is my code:
module1.f90
module module1
implicit none
contains
subroutine sub1(ddtype,nstr)
integer,intent(in)::nstr
character,intent(inout),dimension(2,nstr)::ddtype
!f2py integer,intent(in)::nstr
!f2py character,intent(inout),dimension(2,nstr)::ddtype
ddtype(1,1) = 'X'
write(*,*) 'From Fortran: ',ddtype
end subroutine sub1
end module module1
the python test: testPython.py
import numpy as np
import Test
arg1 = np.array(['aa','bb','cc'],dtype='c').T
Test.module1.sub1(arg1,arg1.shape[1])
print arg1
I am in linux CentOS 7 and using gfortran, f2py and Python 2.7. I compiled by using:
f2py -c -m Test module1.f90
I can print the array of NumPy strings only if I change the the intent (inout)
to (in)
. Generally the behavior of f2py with array of string seems not clear/stable.