fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
375 stars 78 forks source link

Failing with F77 #88

Closed tomchor closed 3 years ago

tomchor commented 4 years ago

Hi, I'm trying to prettyfy the code in this repo: https://github.com/tomchor/diablo/tree/master/source

However, when I issue fprettify diablo.f --indent 2 I get this error:

ERROR: File diablo.f, line 69
    Fatal error occured
Traceback (most recent call last):
  File "/glade/u/home/tomasc/miniconda3/envs/test/lib/python3.8/site-packages/fprettify/__init__.py", line 1315, in remove_pre_ampersands
    sep = len(re.search(r'(\s*)&[\s]*(?:!.*)?$',
AttributeError: 'NoneType' object has no attribute 'group'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/glade/u/home/tomasc/miniconda3/envs/test/lib/python3.8/site-packages/fprettify/__init__.py", line 1556, in run
    reformat_inplace(filename,
  File "/glade/u/home/tomasc/miniconda3/envs/test/lib/python3.8/site-packages/fprettify/__init__.py", line 986, in reformat_inplace
    reformat_ffile(infile=infile, outfile=newfile,
  File "/glade/u/home/tomasc/miniconda3/envs/test/lib/python3.8/site-packages/fprettify/__init__.py", line 1088, in reformat_ffile
    lines, pre_ampersand, ampersand_sep = remove_pre_ampersands(
  File "/glade/u/home/tomasc/miniconda3/envs/test/lib/python3.8/site-packages/fprettify/__init__.py", line 1318, in remove_pre_ampersands
    raise FprettifyParseException(
fprettify.fparse_utils.FprettifyParseException: Bad continuation line format

So my first question is: is that format allowed? (I think it's written in F77)

If the answer is yes, then how can I fix my case?

Thanks!

PS: The error happens when I install using both conda and pip.

nbehrnd commented 4 years ago

It is old FORTRAN77 (like Platon's backbone here) as by explicit statement of your code (line 3), comments starting by C -- even if the old standard permits today's ! (a reference), reserving the first 6 columns for a (here not used) GOTO instruction, the author's aim to limit the chars per line (the guide on line 53), etc.

To advance further:

An illustration of this suggestion is attached in the .zip below. If choosing FORTRAN77 instead of e.g., Fortran2018, ftnchek might be useful for you. example.zip

tomchor commented 4 years ago

Thanks! Indeed your example looks really nice. I think I'm going to follow your suggestions, although it looks like some hard work!

pseewald commented 3 years ago

fprettify can not deal with fortran77 so I'll close this. Thanks for the suggestions @nbehrnd