1

I have written a very simple module (test.f90)

module tt

implicit none
character(:),allocatable :: hh
contains
subroutine test()
    implicit none
    integer :: i
end subroutine
end module tt

I want now to wrap it into an object for Python using f2py.

I use the following commands:

gfortran-9 -c test.f90 -Wall
f2py -m g -c test.f90

But I obtain the following errors. These errors seems to be correlated with the allocatable string and I am currently not able to find a solution to remove it.

/var/folders/fg/53phbn8n6nd3vrhm3sh_36w40000gn/T/tmpjtueazku/src.macosx-10.7-x86_64-3.6/g-f2pywrappers2.f90:25:17:

   25 |        allocate(d(s(1)))
      |                 1
Error: Shape specification for allocatable scalar at (1)
/var/folders/fg/53phbn8n6nd3vrhm3sh_36w40000gn/T/tmpjtueazku/src.macosx-10.7-x86_64-3.6/g-f2pywrappers2.f90:16:22:

   16 |             if ((size(d,i).ne.s(i)).and.(s(i).ge.0)) then
      |                      1
Error: 'array' argument of 'size' intrinsic at (1) must be an array
/var/folders/fg/53phbn8n6nd3vrhm3sh_36w40000gn/T/tmpjtueazku/src.macosx-10.7-x86_64-3.6/g-f2pywrappers2.f90:29:24:

   29 |             s(i) = size(d,i)
      |                        1
Error: 'array' argument of 'size' intrinsic at (1) must be an array
Guuk
  • 505
  • 3
  • 17
  • The errors that you show have no relation to the Fortran code you posted. Try again? – evets Feb 09 '20 at 23:29
  • 1
    The error is not directly due to the fortran code but it is due to the fortran code generated by f2py. Thus gfortran gives no error but f2py does. – Guuk Feb 10 '20 at 06:59
  • 1
    The specification statement `character(:),allocatable :: hh` means that the array length is not yet defined. I don't know if f2py can manage allocatable character variables. Allocatable arrays of length 1 character variables `chracter, allocatable :: hh(:)` should work. For info, f2py Fortran understanding stop at Fortran 95. – Pierre de Buyl Feb 10 '20 at 09:28
  • @PierredeBuyl, `character(:), allocatable :: hh` is not an array, so your first sentence makes no sense. `hh` is a deferred-length scalar variable. Looks the f2py does not support this feature of Fortran or it is broken. – evets Feb 10 '20 at 15:15
  • I mistyped, I meant length of character variable. f2py does support arrays of characters though. But not deferred length character variables (either as scalars or elements of an array). – Pierre de Buyl Feb 10 '20 at 16:26

0 Answers0