Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: F2py creates bad wrapper functions when fortran code has nested procedures #20103

Open
ShrirajHegde opened this issue Oct 12, 2021 · 13 comments

Comments

@ShrirajHegde
Copy link
Contributor

Describe the issue:

A detailed description is at Stackoverflow, here

to summarize, a procedure like this

subroutine example(array)
    implicit none
    real*8::array(:,:)
    INTEGER::i,j
!f2py intent(inout)::array

    do i=1,3
        do j=1,3
            array(i,j)=10*i+j
        enddo
        ! print*,''
    enddo
    call tentimes(array)
    RETURN

    contains

    subroutine tentimes(array)
        implicit none
!f2py intent(inout):array
        real*8::array(:,:)
        array=array*10
    end subroutine tentimes
end subroutine example

should produce a wrapper function like this

  subroutine f2pywrapexample (array, f2py_array_d0, f2py_array_d1)
      integer f2py_array_d0
      integer f2py_array_d1
      real*8 array(f2py_array_d0,f2py_array_d1)
      interface
      
            subroutine example(array) 
                real*8, dimension(:,:),intent(inout) :: array
            end subroutine example
                      !separate
            subroutine tentimes(array) 
                real*8, dimension(:,:) :: array
            end subroutine tentimes
      end interface
      call example(array)
      end

instead f2py produces a wrapper function like this (notice the nested procedures even in the interface)

!     -*- f90 -*-
!     This file is autogenerated with f2py (version:1.21.2)
!     It contains Fortran 90 wrappers to fortran functions.

      subroutine f2pywrapexample (array, f2py_array_d0, f2py_array_d1)
      integer f2py_array_d0
      integer f2py_array_d1
      real*8 array(f2py_array_d0,f2py_array_d1)
      interface
      
            subroutine example(array) 
                real*8, dimension(:,:),intent(inout) :: array
                subroutine tentimes(array) 
                    real*8, dimension(:,:) :: array
                end subroutine tentimes
            end subroutine example
      end interface
      call example(array)
      end

The bad interface fails to compile. This happens every single time when there are nested procedures.

Reproduce the code example:

import ftest
import numpy as np

a=np.zeros((3,3),order="F")

print(a)
res=ftest.example(a)
print(a)

Error message:

running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "ftest" sources
f2py options: []
f2py:> /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftestmodule.c
creating /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9
Reading fortran codes...
	Reading file 'allocate.f90' (format:free)
{'before': '', 'this': 'intent', 'after': '(inout):array'}
Line #20 in allocate.f90:"      intent(inout):array"
	analyzeline: no name pattern found in intent statement for ':array'. Skipping.
Post-processing...
	Block: ftest
			Block: example
			Block: dummy
Post-processing (stage 2)...
Building modules...
	Building module "ftest"...
		Creating wrapper for Fortran subroutine "example"("example")...
		Constructing wrapper function "example"...
		  example(array)
	Wrote C/API module "ftest" to file "/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftestmodule.c"
	Fortran 90 wrappers are saved to "/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.f90"
  adding '/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/fortranobject.c' to sources.
  adding '/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9' to include_dirs.
copying /home/srj/.local/lib/python3.9/site-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9
copying /home/srj/.local/lib/python3.9/site-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9
  adding '/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.f90' to sources.
build_src: building npy-pkg config files
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
get_default_fcompiler: matching types: '['gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag', 'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor', 'fujitsu']'
customize Gnu95FCompiler
Found executable /usr/bin/gfortran
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'ftest' extension
compiling C sources
C compiler: gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC

creating /tmp/tmpvsa9ua1w/tmp
creating /tmp/tmpvsa9ua1w/tmp/tmpvsa9ua1w
creating /tmp/tmpvsa9ua1w/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9
compile options: '-DNPY_DISABLE_OPTIMIZATION=1 -I/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9 -I/home/srj/.local/lib/python3.9/site-packages/numpy/core/include -I/usr/include/python3.9 -c'
gcc: /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftestmodule.c
gcc: /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/fortranobject.c
In file included from /home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1969,
                 from /home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/fortranobject.h:13,
                 from /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftestmodule.c:16:
/home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
In file included from /home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1969,
                 from /home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/fortranobject.h:13,
                 from /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/fortranobject.c:2:
/home/srj/.local/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftestmodule.c:137:12: warning: ‘f2py_size’ defined but not used [-Wunused-function]
  137 | static int f2py_size(PyArrayObject* var, ...)
      |            ^~~~~~~~~
compiling Fortran sources
Fortran f77 compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
compile options: '-I/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9 -I/home/srj/.local/lib/python3.9/site-packages/numpy/core/include -I/usr/include/python3.9 -c'
gfortran:f90: allocate.f90
gfortran:f90: /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.f90
/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.f90:13:17:

   13 |                 subroutine tentimes(array)
      |                 1
Error: Unclassifiable statement at (1)
/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.f90:14:51:

   14 |                     real*8, dimension(:,:) :: array
      |                                                   1
Error: Symbol ‘array’ at (1) already has basic type of REAL
/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.f90:15:39:

   15 |                 end subroutine tentimes
      |                                       1
Error: Expected label ‘example’ for END SUBROUTINE statement at (1)
error: Command "/usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops -I/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9 -I/home/srj/.local/lib/python3.9/site-packages/numpy/core/include -I/usr/include/python3.9 -c -c /tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.f90 -o /tmp/tmpvsa9ua1w/tmp/tmpvsa9ua1w/src.linux-x86_64-3.9/ftest-f2pywrappers2.o" failed with exit status 1

NumPy/Python version information:

❯ python          
Python 3.9.7 (default, Aug 30 2021, 00:00:00) 
[GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.version.version
'1.21.2'
>>> 
❯ python
Python 3.9.7 (default, Aug 30 2021, 00:00:00) 
[GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, numpy; print(numpy.__version__, sys.version)
1.21.2 3.9.7 (default, Aug 30 2021, 00:00:00) 
[GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
>>> 

@bjmueller
Copy link

We find the same issue with a contained function for a similar example.

@ShrirajHegde
Copy link
Contributor Author

Please also note that generating a signature file as given in the smart way does not have this problem.

@2sn
Copy link
Contributor

2sn commented Nov 17, 2021

here is a minimal example that fails, and I am not sure why.

SUBROUTINE s(n, m, k, l, c, x)
  IMPLICIT NONE
  INTEGER, INTENT(in) :: n, m, k, l
  REAL*8, INTENT(out), dimension(n,m,k,l) :: x
  REAL*8, INTENT(in) :: c(:)
end SUBROUTINE s

I find this peculiar because both

SUBROUTINE s(n, m, k, l, c, x)
  IMPLICIT NONE
  INTEGER, INTENT(in) :: n, m, k, l
  REAL*8, INTENT(inout), dimension(:,:,:,:) :: x
  REAL*8, INTENT(in) :: c(:)
end SUBROUTINE s

and

SUBROUTINE s(n, m, k, l, c, x)
  IMPLICIT NONE
  INTEGER, INTENT(in) :: n, m, k, l
  REAL*8, INTENT(out), dimension(n,m,k,l) :: x
  REAL*8, INTENT(in) :: c(n)
end SUBROUTINE s

work. What am I missing here?

BYW, the error message I get is

/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90:21:24:

   21 |                 real*8, dimension(n,m,k,l),intent(out),depend(n,m,k,l) :&
      |                        1
Error: Invalid character in name at (1)
/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90:25:30:

   25 |       call s(n, m, k, l, c, x)
      |                              1
Error: Type mismatch in argument ‘x’ at (1); passed REAL(8) to REAL(4)

(only the first error is relevant)

@2sn
Copy link
Contributor

2sn commented Nov 17, 2021

for completeness, I also add the pyf file it generates

!     -*- f90 -*-
!     This file is autogenerated with f2py (version:1.21.4)
!     It contains Fortran 90 wrappers to fortran functions.

      subroutine f2pywraps (n, m, k, l, c, x, f2py_c_d0)
      integer n
      integer m
      integer k
      integer l
      integer f2py_c_d0
      real*8 c(f2py_c_d0)
      real*8 x(n,m,k,l)
      interface
      
            subroutine s(n,m,k,l,c,x) 
                integer, intent(in) :: n
                integer, intent(in) :: m
                integer, intent(in) :: k
                integer, intent(in) :: l
                real*8, dimension(:),intent(in) :: c
                real*8, dimension(n,m,k,l),intent(out),depend(n,m,k,l) :&
     &: x
            end subroutine s
      end interface
      call s(n, m, k, l, c, x)
      end

@ShrirajHegde
Copy link
Contributor Author

here is a minimal example that fails, and I am not sure why.

that is really weird, because it doesn't fail if you use python -m numpy.f2py -c file.f90 -m foo

@2sn
Copy link
Contributor

2sn commented Nov 17, 2021

we create an intermediate pyf file from a build script.

@melissawm
Copy link
Member

melissawm commented Nov 17, 2021

here is a minimal example that fails, and I am not sure why.

Your example works for me; from the generated pyf file I can see there is more going on (see f2py_c_d0). Can you clarify the exact steps you are taking? sorry my bad, just realized this is the wrapper.

@melissawm
Copy link
Member

@ShrirajHegde you have a typo here: !f2py intent(inout):array (should be f2py intent(inout) :: array)

However after fixing this, the issue of not being able to deal with the nested submodules is there.

Full output
$ f2py -c subsuborig.f90 -m subsub
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "subsub" sources
f2py options: []
f2py:> /tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsubmodule.c
creating /tmp/tmp2hukv23f/src.linux-x86_64-3.9
Reading fortran codes...
        Reading file 'subsuborig.f90' (format:free)
Post-processing...
        Block: subsub
                        Block: example
Post-processing (stage 2)...
Building modules...
        Building module "subsub"...
                Creating wrapper for Fortran subroutine "example"("example")...
                Constructing wrapper function "example"...
                  example(array)
        Wrote C/API module "subsub" to file "/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsubmodule.c"
        Fortran 90 wrappers are saved to "/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.f90"
  adding '/tmp/tmp2hukv23f/src.linux-x86_64-3.9/fortranobject.c' to sources.
  adding '/tmp/tmp2hukv23f/src.linux-x86_64-3.9' to include_dirs.
copying /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmp2hukv23f/src.linux-x86_64-3.9
copying /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmp2hukv23f/src.linux-x86_64-3.9
  adding '/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.f90' to sources.
build_src: building npy-pkg config files
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
get_default_fcompiler: matching types: '['gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag', 'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor', 'fujitsu']'
customize Gnu95FCompiler
Found executable /usr/bin/gfortran
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'subsub' extension
compiling C sources
C compiler: gcc -pthread -B /opt/miniconda/envs/numpy121/compiler_compat -Wl,--sysroot=/ -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/miniconda/envs/numpy121/include -fPIC -O2 -isystem /opt/miniconda/envs/numpy121/include -fPIC

creating /tmp/tmp2hukv23f/tmp
creating /tmp/tmp2hukv23f/tmp/tmp2hukv23f
creating /tmp/tmp2hukv23f/tmp/tmp2hukv23f/src.linux-x86_64-3.9
compile options: '-DNPY_DISABLE_OPTIMIZATION=1 -I/tmp/tmp2hukv23f/src.linux-x86_64-3.9 -I/opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include -I/opt/miniconda/envs/numpy121/include/python3.9 -c'
gcc: /tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsubmodule.c
gcc: /tmp/tmp2hukv23f/src.linux-x86_64-3.9/fortranobject.c
In file included from /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1969,
                 from /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /tmp/tmp2hukv23f/src.linux-x86_64-3.9/fortranobject.h:13,
                 from /tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsubmodule.c:16:
/opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
In file included from /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1969,
                 from /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /tmp/tmp2hukv23f/src.linux-x86_64-3.9/fortranobject.h:13,
                 from /tmp/tmp2hukv23f/src.linux-x86_64-3.9/fortranobject.c:2:
/opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsubmodule.c:137:12: warning: ‘f2py_size’ defined but not used [-Wunused-function]
  137 | static int f2py_size(PyArrayObject* var, ...)
      |            ^~~~~~~~~
compiling Fortran sources
Fortran f77 compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
compile options: '-I/tmp/tmp2hukv23f/src.linux-x86_64-3.9 -I/opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include -I/opt/miniconda/envs/numpy121/include/python3.9 -c'
gfortran:f90: subsuborig.f90
gfortran:f90: /tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.f90
/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.f90:13:17:

   13 |                 subroutine tentimes(array)
      |                 1
Error: Unclassifiable statement at (1)
/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.f90:14:65:

   14 |                     real*8, intent(inout),dimension(:,:) :: array
      |                                                                 1
Error: Symbol ‘array’ at (1) already has basic type of REAL
/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.f90:15:39:

   15 |                 end subroutine tentimes
      |                                       1
Error: Expected label ‘example’ for END SUBROUTINE statement at (1)
error: Command "/usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops -I/tmp/tmp2hukv23f/src.linux-x86_64-3.9 -I/opt/miniconda/envs/numpy121/lib/python3.9/site-packages/numpy/core/include -I/opt/miniconda/envs/numpy121/include/python3.9 -c -c /tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.f90 -o /tmp/tmp2hukv23f/tmp/tmp2hukv23f/src.linux-x86_64-3.9/subsub-f2pywrappers2.o" failed with exit status 1

@2sn
Copy link
Contributor

2sn commented Nov 17, 2021

@melissawm OK, I include the full call from my script. Eventually it is supposed to link with an external library in the build framework, os there is a but extra fuzz. The good thing is that the framework prints out the calls to f2py it makes as well as what f2py returns.

In [1]: import mapping_loop
make: 'mapping_loop.a' is up to date.
 [DEBUG][f2py] f2py3.9 --verbose -m _interface -h _interface.pyf --include-paths /home/alex/python/mapping_loop --f2cmap /home/alex/python/mapping_loop/.f2py_f2cmap interface.f90 --overwrite-signature
Reading f2cmap from '/home/alex/python/mapping_loop/.f2py_f2cmap' ...
Failed to apply user defined f2cmap changes: [Errno 2] No such file or directory: '/home/alex/python/mapping_loop/.f2py_f2cmap'. Skipping.
Reading fortran codes...
        Reading file 'interface.f90' (format:free)
analyzeline: Creating module block '_interface'
analyzeline: Creating additional interface block (groupcounter=2).
Post-processing...
        Block: _interface
                        Block: mappingx
In: :_interface:interface.f90:mappingx
buildimplicitrules: no implicit rules for routine 'mappingx'.
In: :_interface:interface.f90:mappingx
buildimplicitrules: no implicit rules for routine 'mappingx'.
Post-processing (stage 2)...
Saving signatures to file "./_interface.pyf"
Stopping. Edit the signature file and then run f2py on the signature file: f2py3.9 ./_interface.pyf
 [DEBUG][f2py] Result: CompletedProcess(args=['f2py3.9', '--verbose', '-m', '_interface', '-h', '_interface.pyf', '--include-paths', '/home/alex/python/mapping_loop', '--f2cmap', '/home/alex/python/mapping_loop/.f2py_f2cmap', 'interface.f90', '--overwrite-signature'], returncode=0)
 [DEBUG][f2py] f2py3.9 --verbose --build-dir /home/alex/python/mapping_loop --f90flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop --f77flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop --include-paths /home/alex/python/mapping_loop --f2cmap /home/alex/python/mapping_loop/.f2py_f2cmap -c -m _interface mapping_loop.a interface.f90 _interface.pyf
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "_interface" sources
f2py options: ['--include-paths', '/home/alex/python/mapping_loop', '--f2cmap', '/home/alex/python/mapping_loop/.f2py_f2cmap']
f2py: _interface.pyf
Reading f2cmap from '/home/alex/python/mapping_loop/.f2py_f2cmap' ...
Failed to apply user defined f2cmap changes: [Errno 2] No such file or directory: '/home/alex/python/mapping_loop/.f2py_f2cmap'. Skipping.
Reading fortran codes...
        Reading file '_interface.pyf' (format:free)
Post-processing...
        Block: _interface
                        Block: mappingx
Post-processing (stage 2)...
Building modules...
        Building module "_interface"...
                Creating wrapper for Fortran subroutine "mappingx"("mappingx")...
                Constructing wrapper function "mappingx"...
                  mappingx(nr,nth,nph,yywt_,nx,ny,nz,nnuc,x0,y0,z0,rho_,xnu_,r3c_,r3l_,r3r_,dx,dy,dz,dphi,rhonew_,xnunew_,muc_,mul_,mur_,phic_,phil_,phir_)
        Wrote C/API module "_interface" to file "/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c"
        Fortran 90 wrappers are saved to "/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90"
  adding '/home/alex/python/mapping_loop/src.linux-x86_64-3.9/fortranobject.c' to sources.
  adding '/home/alex/python/mapping_loop/src.linux-x86_64-3.9' to include_dirs.
  adding '/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90' to sources.
build_src: building npy-pkg config files
running build_ext
new_compiler returns <class 'distutils.unixccompiler.UnixCCompiler'>
customize UnixCCompiler
customize UnixCCompiler using build_ext
********************************************************************************
<class 'distutils.unixccompiler.UnixCCompiler'>
preprocessor  = ['gcc', '-pthread', '-E']
compiler      = ['gcc', '-pthread', '-Wno-unused-result', '-Wsign-compare', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall']
compiler_so   = ['gcc', '-pthread', '-Wno-unused-result', '-Wsign-compare', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall', '-fPIC']
compiler_cxx  = ['g++', '-pthread']
linker_so     = ['gcc', '-pthread', '-shared']
linker_exe    = ['gcc', '-pthread']
archiver      = ['ar', 'rcs']
ranlib        = None
libraries     = []
library_dirs  = ['/home/alex/Python/lib']
include_dirs  = ['/home/alex/Python/include/python3.9']
********************************************************************************
get_default_fcompiler: matching types: '['gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag', 'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor', 'fujitsu']'
customize Gnu95FCompiler
find_executable('gfortran')
Found executable /usr/bin/gfortran
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
********************************************************************************
<class 'numpy.distutils.fcompiler.gnu.Gnu95FCompiler'>
version_cmd     = ['/usr/bin/gfortran', '-dumpversion']
compiler_f77    = ['/usr/bin/gfortran', '-fPIC', '-O3', '-funroll-loops', '-fno-second-underscore', '-fconvert=big-endian', '-I/home/alex/python/mapping_loop', '-fPIC', '-O3', '-funroll-loops']
compiler_f90    = ['/usr/bin/gfortran', '-fPIC', '-O3', '-funroll-loops', '-fno-second-underscore', '-fconvert=big-endian', '-I/home/alex/python/mapping_loop', '-fPIC', '-O3', '-funroll-loops']
compiler_fix    = ['/usr/bin/gfortran', '-Wall', '-g', '-ffixed-form', '-fno-second-underscore', '-fPIC', '-O3', '-funroll-loops', '-fno-second-underscore', '-fconvert=big-endian', '-I/home/alex/python/mapping_loop', '-fPIC', '-O3', '-funroll-loops']
linker_so       = ['/usr/bin/gfortran', '-Wall', '-g', '-Wall', '-g', '-shared']
archiver        = ['/usr/bin/gfortran', '-cr']
ranlib          = ['/usr/bin/gfortran']
linker_exe      = ['/usr/bin/gfortran', '-Wall', '-Wall']
version         = LooseVersion ('11')
libraries       = ['gfortran']
library_dirs    = ['/usr/lib/gcc/x86_64-redhat-linux/11', '/usr/lib/gcc/x86_64-redhat-linux/11', '/home/alex/Python/lib']
object_switch   = '-o '
compile_switch  = '-c'
include_dirs    = ['/home/alex/Python/include/python3.9']
********************************************************************************
building '_interface' extension
compiling C sources
C compiler: gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC

compile options: '-DNPY_DISABLE_OPTIMIZATION=1 -I/home/alex/python/mapping_loop/src.linux-x86_64-3.9 -I/home/alex/Python/lib/python3.9/site-packages/numpy/core/include -I/home/alex/Python/include/python3.9 -c'
gcc: /home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c
In file included from /home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1969,
                 from /home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /home/alex/python/mapping_loop/src.linux-x86_64-3.9/fortranobject.h:13,
                 from /home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c:16:
/home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c:137:12: warning: ‘f2py_size’ defined but not used [-Wunused-function]
  137 | static int f2py_size(PyArrayObject* var, ...)
      |            ^~~~~~~~~
compiling Fortran sources
Fortran f77 compiler: /usr/bin/gfortran -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop -fPIC -O3 -funroll-loops
compile options: '-I/home/alex/python/mapping_loop/src.linux-x86_64-3.9 -I/home/alex/Python/lib/python3.9/site-packages/numpy/core/include -I/home/alex/Python/include/python3.9 -c'
gfortran:f90: interface.f90
gfortran:f90: /home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90
/usr/bin/gfortran -Wall -g -Wall -g -shared /home/alex/python/mapping_loop/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.o /home/alex/python/mapping_loop/home/alex/python/mapping_loop/src.linux-x86_64-3.9/fortranobject.o /home/alex/python/mapping_loop/interface.o /home/alex/python/mapping_loop/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.o mapping_loop.a -L/usr/lib/gcc/x86_64-redhat-linux/11 -L/usr/lib/gcc/x86_64-redhat-linux/11 -L/home/alex/Python/lib -lgfortran -o ./_interface.cpython-39-x86_64-linux-gnu.so
 [DEBUG][f2py] Result: CompletedProcess(args=['f2py3.9', '--verbose', '--build-dir', '/home/alex/python/mapping_loop', '--f90flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop', '--f77flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop', '--include-paths', '/home/alex/python/mapping_loop', '--f2cmap', '/home/alex/python/mapping_loop/.f2py_f2cmap', '-c', '-m', '_interface', 'mapping_loop.a', 'interface.f90', '_interface.pyf'], returncode=0)

In [2]: import mapping_loop

In [3]:                                                                                                                         
~/python>ip
Python 3.9.7 (default, Sep 11 2021, 13:22:48) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.29.0 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: Qt5Agg
Populating the interactive namespace from numpy and matplotlib

In [1]: import mapping_loop
make: 'mapping_loop.a' is up to date.
 [DEBUG][f2py] f2py3.9 --verbose -m _interface -h _interface.pyf --include-paths /home/alex/python/mapping_loop --f2cmap /home/alex/python/mapping_loop/.f2py_f2cmap interface.f90 --overwrite-signature
Reading f2cmap from '/home/alex/python/mapping_loop/.f2py_f2cmap' ...
Failed to apply user defined f2cmap changes: [Errno 2] No such file or directory: '/home/alex/python/mapping_loop/.f2py_f2cmap'. Skipping.
Reading fortran codes...
        Reading file 'interface.f90' (format:free)
analyzeline: Creating module block '_interface'
analyzeline: Creating additional interface block (groupcounter=2).
Post-processing...
        Block: _interface
                        Block: s
In: :_interface:interface.f90:s
buildimplicitrules: no implicit rules for routine 's'.
In: :_interface:interface.f90:s
buildimplicitrules: no implicit rules for routine 's'.
Post-processing (stage 2)...
Saving signatures to file "./_interface.pyf"
Stopping. Edit the signature file and then run f2py on the signature file: f2py3.9 ./_interface.pyf
 [DEBUG][f2py] Result: CompletedProcess(args=['f2py3.9', '--verbose', '-m', '_interface', '-h', '_interface.pyf', '--include-paths', '/home/alex/python/mapping_loop', '--f2cmap', '/home/alex/python/mapping_loop/.f2py_f2cmap', 'interface.f90', '--overwrite-signature'], returncode=0)
 [DEBUG][f2py] f2py3.9 --verbose --build-dir /home/alex/python/mapping_loop --f90flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop --f77flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop --include-paths /home/alex/python/mapping_loop --f2cmap /home/alex/python/mapping_loop/.f2py_f2cmap -c -m _interface mapping_loop.a interface.f90 _interface.pyf
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "_interface" sources
f2py options: ['--include-paths', '/home/alex/python/mapping_loop', '--f2cmap', '/home/alex/python/mapping_loop/.f2py_f2cmap']
f2py: _interface.pyf
Reading f2cmap from '/home/alex/python/mapping_loop/.f2py_f2cmap' ...
Failed to apply user defined f2cmap changes: [Errno 2] No such file or directory: '/home/alex/python/mapping_loop/.f2py_f2cmap'. Skipping.
Reading fortran codes...
        Reading file '_interface.pyf' (format:free)
Post-processing...
        Block: _interface
                        Block: s
Post-processing (stage 2)...
Building modules...
        Building module "_interface"...
                Creating wrapper for Fortran subroutine "s"("s")...
                Constructing wrapper function "s"...
                  x = s(n,m,k,l,c)
        Wrote C/API module "_interface" to file "/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c"
        Fortran 90 wrappers are saved to "/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90"
  adding '/home/alex/python/mapping_loop/src.linux-x86_64-3.9/fortranobject.c' to sources.
  adding '/home/alex/python/mapping_loop/src.linux-x86_64-3.9' to include_dirs.
  adding '/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90' to sources.
build_src: building npy-pkg config files
running build_ext
new_compiler returns <class 'distutils.unixccompiler.UnixCCompiler'>
customize UnixCCompiler
customize UnixCCompiler using build_ext
********************************************************************************
<class 'distutils.unixccompiler.UnixCCompiler'>
preprocessor  = ['gcc', '-pthread', '-E']
compiler      = ['gcc', '-pthread', '-Wno-unused-result', '-Wsign-compare', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall']
compiler_so   = ['gcc', '-pthread', '-Wno-unused-result', '-Wsign-compare', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall', '-fPIC']
compiler_cxx  = ['g++', '-pthread']
linker_so     = ['gcc', '-pthread', '-shared']
linker_exe    = ['gcc', '-pthread']
archiver      = ['ar', 'rcs']
ranlib        = None
libraries     = []
library_dirs  = ['/home/alex/Python/lib']
include_dirs  = ['/home/alex/Python/include/python3.9']
********************************************************************************
get_default_fcompiler: matching types: '['gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag', 'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor', 'fujitsu']'
customize Gnu95FCompiler
find_executable('gfortran')
Found executable /usr/bin/gfortran
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
********************************************************************************
<class 'numpy.distutils.fcompiler.gnu.Gnu95FCompiler'>
version_cmd     = ['/usr/bin/gfortran', '-dumpversion']
compiler_f77    = ['/usr/bin/gfortran', '-fPIC', '-O3', '-funroll-loops', '-fno-second-underscore', '-fconvert=big-endian', '-I/home/alex/python/mapping_loop', '-fPIC', '-O3', '-funroll-loops']
compiler_f90    = ['/usr/bin/gfortran', '-fPIC', '-O3', '-funroll-loops', '-fno-second-underscore', '-fconvert=big-endian', '-I/home/alex/python/mapping_loop', '-fPIC', '-O3', '-funroll-loops']
compiler_fix    = ['/usr/bin/gfortran', '-Wall', '-g', '-ffixed-form', '-fno-second-underscore', '-fPIC', '-O3', '-funroll-loops', '-fno-second-underscore', '-fconvert=big-endian', '-I/home/alex/python/mapping_loop', '-fPIC', '-O3', '-funroll-loops']
linker_so       = ['/usr/bin/gfortran', '-Wall', '-g', '-Wall', '-g', '-shared']
archiver        = ['/usr/bin/gfortran', '-cr']
ranlib          = ['/usr/bin/gfortran']
linker_exe      = ['/usr/bin/gfortran', '-Wall', '-Wall']
version         = LooseVersion ('11')
libraries       = ['gfortran']
library_dirs    = ['/usr/lib/gcc/x86_64-redhat-linux/11', '/usr/lib/gcc/x86_64-redhat-linux/11', '/home/alex/Python/lib']
object_switch   = '-o '
compile_switch  = '-c'
include_dirs    = ['/home/alex/Python/include/python3.9']
********************************************************************************
building '_interface' extension
compiling C sources
C compiler: gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC

compile options: '-DNPY_DISABLE_OPTIMIZATION=1 -I/home/alex/python/mapping_loop/src.linux-x86_64-3.9 -I/home/alex/Python/lib/python3.9/site-packages/numpy/core/include -I/home/alex/Python/include/python3.9 -c'
gcc: /home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c
In file included from /home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1969,
                 from /home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /home/alex/python/mapping_loop/src.linux-x86_64-3.9/fortranobject.h:13,
                 from /home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c:16:
/home/alex/Python/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interfacemodule.c:137:12: warning: ‘f2py_size’ defined but not used [-Wunused-function]
  137 | static int f2py_size(PyArrayObject* var, ...)
      |            ^~~~~~~~~
compiling Fortran sources
Fortran f77 compiler: /usr/bin/gfortran -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop -fPIC -O3 -funroll-loops
compile options: '-I/home/alex/python/mapping_loop/src.linux-x86_64-3.9 -I/home/alex/Python/lib/python3.9/site-packages/numpy/core/include -I/home/alex/Python/include/python3.9 -c'
gfortran:f90: interface.f90
gfortran:f90: /home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90
/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90:21:24:

   21 |                 real*8, dimension(n,m,k,l),intent(out),depend(n,m,k,l) :&
      |                        1
Error: Invalid character in name at (1)
/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90:25:30:

   25 |       call s(n, m, k, l, c, x)
      |                              1
Error: Type mismatch in argument ‘x’ at (1); passed REAL(8) to REAL(4)
error: Command "/usr/bin/gfortran -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop -fPIC -O3 -funroll-loops -I/home/alex/python/mapping_loop/src.linux-x86_64-3.9 -I/home/alex/Python/lib/python3.9/site-packages/numpy/core/include -I/home/alex/Python/include/python3.9 -c -c /home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.f90 -o /home/alex/python/mapping_loop/home/alex/python/mapping_loop/src.linux-x86_64-3.9/_interface-f2pywrappers2.o" failed with exit status 1
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
~/python/mapping_loop/build.py in build_module(self, debug, ncpu)
    218         try:
--> 219             self.f2py([
    220                 # '--debug',

~/python/mapping_loop/build.py in f2py(self, args)
     97         print(' [DEBUG][f2py] ' + ' '.join(args))
---> 98         result = subprocess.run(
     99             args,

~/Python/lib/python3.9/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    527         if check and retcode:
--> 528             raise CalledProcessError(retcode, process.args,
    529                                      output=stdout, stderr=stderr)

CalledProcessError: Command '['f2py3.9', '--verbose', '--build-dir', '/home/alex/python/mapping_loop', '--f90flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop', '--f77flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop', '--include-paths', '/home/alex/python/mapping_loop', '--f2cmap', '/home/alex/python/mapping_loop/.f2py_f2cmap', '-c', '-m', '_interface', 'mapping_loop.a', 'interface.f90', '_interface.pyf']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-1-ea746761c6b5> in <module>
----> 1 import mapping_loop

~/python/mapping_loop/__init__.py in <module>
      2 
      3 _build = Build()
----> 4 _build.run()
      5 del _build
      6 

~/python/mapping_loop/build.py in run(self)
    117         kw = dict(debug=self.debug, ncpu=self.ncpu)
    118         if self.build_library_check(**kw) or self.build_check(**kw):
--> 119             self.build_module(**kw)
    120 
    121     def test_executable(self):

~/python/mapping_loop/build.py in build_module(self, debug, ncpu)
    248                 ])
    249         except subprocess.CalledProcessError:
--> 250             raise Exception("creating module failed")
    251         os.chdir(cwd)
    252 

Exception: creating module failed

the first call seems to be

f2py3.9 --verbose -m _interface -h _interface.pyf --include-paths /home/alex/python/mapping_loop --f2cmap /home/alex/python/mapping_loop/.f2py_f2cmap interface.f90 --overwrite-signature

and the second

 f2py3.9 --verbose --build-dir /home/alex/python/mapping_loop --f90flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop --f77flags=-fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -I/home/alex/python/mapping_loop --include-paths /home/alex/python/mapping_loop --f2cmap /home/alex/python/mapping_loop/.f2py_f2cmap -c -m _interface mapping_loop.a interface.f90 _interface.pyf

(it appears not all the " are preserved in this output, for the --f77flags and --f90flags but one can see in the f2py output that they go in the right place)

@melissawm
Copy link
Member

It looks like the .f2py_f2cmap file can't be found: Failed to apply user defined f2cmap changes: [Errno 2] No such file or directory: '/home/alex/python/mapping_loop/.f2py_f2cmap'. Skipping.

Anyway, I think this is a different issue and should be discussed separately, can you please create a separate issue for this problem not involving the nested procedures if the error persists? Thanks.

@2sn
Copy link
Contributor

2sn commented Nov 18, 2021

yes, the .f2py_f2cmap was just a wrong include by the build script, but other than this warning has no effect here as we only use pre-defined types.

@melissawm You think that this issue I get is a different one than what started this thread?
I thought it was related.

@melissawm
Copy link
Member

melissawm commented Nov 18, 2021

@2sn With this code:

SUBROUTINE s(n, m, k, l, c, x)
  IMPLICIT NONE
  INTEGER, INTENT(in) :: n, m, k, l
  REAL*8, INTENT(out), dimension(n,m,k,l) :: x
  REAL*8, INTENT(in) :: c(:)
end SUBROUTINE s

I get the following pyf file:

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

subroutine s(n,m,k,l,c,x) ! in subsub.f90
    integer intent(in) :: n
    integer intent(in) :: m
    integer intent(in) :: k
    integer intent(in) :: l
    real*8 dimension(:),intent(in) :: c
    real*8 dimension(n,m,k,l),intent(out),depend(n,m,k,l) :: x
end subroutine s

! This file was auto-generated with f2py (version:1.20.3).
! See http://cens.ioc.ee/projects/f2py2e/

Editing it to read

!    -*- f90 -*-
! Note: the context of this file is case sensitive.

python module usermodule
   interface
		subroutine s(n,m,k,l,c,x) ! in subsub.f90
    		integer intent(in) :: n
    		integer intent(in) :: m
    		integer intent(in) :: k
    		integer intent(in) :: l
    		real*8 dimension(:),intent(in) :: c
    		real*8 dimension(n,m,k,l),intent(out) :: x
		end subroutine s
	end interface
end python module usermodule
! This file was auto-generated with f2py (version:1.20.3).
! See http://cens.ioc.ee/projects/f2py2e/

and compiling with

f2py -c usermodule.pyf usermodule.f90

everything works fine. I see no nested subroutines or any other issues.

Note that the problem here was the depend directive, which is not necessary in this case.

@2sn
Copy link
Contributor

2sn commented Nov 19, 2021

I think the issue I have is that the auto-generated f2py causes some issues with line continuation I do not understand.

In development we continuously change the fortran file, so editing pyf by hand is not ideal.

the example may be slightly atypical (was code written by a student doing this for the first time).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants