Consider the following Fortran modules:
input.f95
module input
integer, parameter :: identifier_max_length = 8
end module input
utils.f95
module utilities
use input, only: identifier_max_length
integer(kind=identifier_max_length) :: ix ! works !
character(len=identifier_max_length) :: output_dir ! DOES NOT work !
contains
subroutine test
character(len=identifier_max_length) :: output_dir ! works !
write(*, *) ix, output_dir
end subroutine
end module
To compile it with f2py, I first compile input.f95 as a shared lib:
gfortran -shared -O2 -o libinput.so -fPIC input.f95
and then utils.f95 to a python module:
python -m numpy.f2py -c --fcompiler=gfortran -L. -I. -linput -m utils utils.f95
The character length definition for the module-level variable output_dir returns an error use of undeclared identifier 'identifier_max_length' while the integer definition with the variable works. Oddly enough the same character definition at subroutine level actually works fine. I dug into the numpy.f2py.capi_maps.py code where the type mapping and kind conversion takes place and it looks like variables in character lengths are not taken care of like they are for the kind parameter.
Defining the identifier_max_length parameter in the same utils module also solves the problem, but this is not an option in my code base.
Does anyone have a solution for this? Is there a way to convert length statements via the .f2py_f2cmap or can I make the C code aware of the input:identifier_max_length variable?
Cheers