The problem here is with the len=*
character declaration. you're telling the fortran compiler to accept any length string which was input. That's great except when you wrap it with f2py
and have intent out
, f2py needs to guess what length string to allocate and pass to your function and it has no way of doing that. (After all, what length string should it assume?).
It looks to me like f2py assumes a 0 length string. When you assign a bigger string to a smaller string in fortran, the result gets truncated (although I would need to go back and read the standard to find out if that could result memory errors). In any event, it looks like that's what the gnu compiler is doing.
If you change it to len=3
, it works.
Alternatively, doing something like this can make this work for f2py without modifying the original code (except for some comments):
!f2py character(len=256),intent(out):: chid
character(len=*),intent(out):: chid ! char. identifier