jameskermode/f90wrap

Extra (unnecessary) newline character in .py file for long variable names

nenanth opened this issue · 3 comments

I tried out the latest f90wrap (0.2.3) for wrapping a legacy fortran project, and noticed that in the f90wrap-generated .py file, there are some unnecessary newline characters introduced in the setter methods when the variable names are over a certain size.

Luckily for me, this happened with only 2 variables, so I could manually change it to continue working. However, for derived types with many long variable names, I can see this being an issue.

Something in the source code generator needs to check whether there is a LHS for the expression in the setter method (is there ever a return value for these?) and not introduce the newline character \

Thanks for reporting, but I don’t quite understand the problem. Could you provide a minimal example?

Sure!
Here's a simple example in zip format. I've also included some Fortran + CMake scripts to handle compilation across all platforms.

To test,

  1. create a build/ directory (can call it anything) under cmake/
  2. cd to build/
  3. FC=gfortran cmake ../../
  4. make

test.py will be created in main folder, try to import it and you may see something like this:

>>> import test

----------------------------------------------------------------------------------------------
<stdin> 1 <module>
1

IndentationError:
expected an indented block
('/Users/ananthsridharan/codes/f90wrap_test/test.py', 33, 13, '            _test.f90wrap_highest_level__set__thisisaveryveryverylongvariablename(thisisaveryveryverylongvariablename)\n')
/Users/ananthsridharan/codes/f90wrap_test/test.py

Actual fortran module looks very simple
module blah
real(kind=8) :: thisisaveryveryveryveryveryverylongvariablename
end module