Skip to content

f2py fails for functions returning character(len=len(input_string)) #3425

@chatcannon

Description

@chatcannon

I've written simple toupper() and tolower() functions in Fortran that start like this:

pure function toupper(str)
  character(len=*) intent(in) :: str
  character(len=len(str)) :: toupper
  ...

When wrapping these with f2py, I get an error looking like this:

/tmp/tmpmrZ5Ra/src.linux-x86_64-2.7/RMCfunctionsmodule.c: In function ‘f2py_rout_RMCfunctions_mod_functions_toupper’:
/tmp/tmpmrZ5Ra/src.linux-x86_64-2.7/RMCfunctionsmodule.c:926:23: error: ‘str_Dims’ undeclared (first use in this function)

slen(toupper) = len(str);
                      ^

I guess the len(str) needs to be replaced by slen(str).

This problem occurs with both f2py-2.7 and f2py-3.3
It does not depend on the name of the variable str - I tried a couple of other names.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions