8000 f2py - f2cmap fails on common blocks in f90 · Issue #19161 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

f2py - f2cmap fails on common blocks in f90 #19161

@2sn

Description

@2sn

Reproducing code example:

The code (data.f90)

module data
  use typedef, only: real64
  implicit none
  real(kind=real64) :: x
  common/test/x
end module data

fails compile with f2py, whereas without the common block,

module data
  use typedef, only: real64
  implicit none
  real(kind=real64) :: x
  save
end module data

it just compiles fine. (Sadly, I require common blocks since I cannot import data from external modules.)
I use a custom .f2py_f2cmap file

{
   'real': {'real32': 'float', 'real64': 'double', 'real128': 'long_double'},
   'integer': {'int8': 'signed_char', 'int16': 'short', 'int32': 'int', 'int64': 'long', 'int128': 'long_long'},
   'complex': {'comp32': 'complex_float', 'comp64': 'complex_double', 'comp128': 'complex_long_double'},
   'character': {'char8' : 'char'},
}

and I do get affirmative output

Reading f2cmap from '/home/alex/python/source/kepler/.f2py_f2cmap' ...
        Mapping "real(kind=real32)" to "float"
        Mapping "real(kind=real64)" to "double"
        Mapping "real(kind=real128)" to "long_double"
        Mapping "integer(kind=int8)" to "signed_char"
        Mapping "integer(kind=int16)" to "short"
        Mapping "integer(kind=int32)" to "int"
        Mapping "integer(kind=int64)" to "long"
        Mapping "integer(kind=int128)" to "long_long"
        Mapping "complex(kind=comp32)" to "complex_float"
        Mapping "complex(kind=comp64)" to "complex_double"
        Mapping "complex(kind=comp128)" to "complex_long_double"
        Mapping "character(kind=char8)" to "char"
Successfully applied user defined f2cmap changes

It applease some F77 module file is created, but my use statement may be ignored.

when I directly add the line

INTEGER, PARAMETER :: real64 = SELECTED_REAL_KIND(15)

instead of

  use typedef, only: real64

It appears to work.

Would it be possible to have f2py not create F77 interface module for .f90 codes even if they use common blocks?

(that might resolve it)

Error message:

/tmp/tmpnlatc0rg/src.linux-x86_64-3.9/_kepler_ARCH_native_NBURN_8192_JMZ_1983_FULDEF_fuldef1_f90_CPU_Intel_R_Xeon_R_W_2145_CPU_3_70GHz-f2pywrappers.f:7:16:

    7 |       real(kind=real64) x
      |                1
Error: Parameter ‘real64’ at (1) has not been declared or is a variable, which does not reduce to a constant expression
error: Command "/usr/bin/gfortran -fPIC -O3 -funroll-loops -fno-second-underscore -fconvert=big-endian -cpp -Djmzmacro=1983 -cpp -Djmzmacro=1983 -Dnburnmacro=8192 -I/home/alex/kepler/source -I/home/alex/python/source/kepler/code/_kepler_ARCH_native_NBURN_8192_JMZ_1983_FULDEF_fuldef1_f90_CPU_Intel_R_Xeon_R_W_2145_CPU_3_70GHz -fPIC -O3 -funroll-loops -Djmzmacro=1983 -Djmzmacro=1983 -Dnburnmacro=8192 -I/tmp/tmpnlatc0rg/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 /tmp/tmpnlatc0rg/src.linux-x86_64-3.9/_kepler_ARCH_native_NBURN_8192_JMZ_1983_FULDEF_fuldef1_f90_CPU_Intel_R_Xeon_R_W_2145_CPU_3_70GHz-f2pywrappers.f -o /tmp/tmpnlatc0rg/tmp/tmpnlatc0rg/src.linux-x86_64-3.9/_kepler_ARCH_native_NBURN_8192_JMZ_1983_FULDEF_fuldef1_f90_CPU_Intel_R_Xeon_R_W_2145_CPU_3_70GHz-f2pywrappers.o -J/tmp/tmpnlatc0rg/ -I/tmp/tmpnlatc0rg/" failed with exit status 1

NumPy/Python version information:

1.20.3 3.9.5 (default, May  7 2021, 05:52:00) 
[GCC 11.1.1 20210428 (Red Hat 11.1.1-1)]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0