There's a lot of fortran code still used today that was written decades ago in fortran 77. Sometimes you don't want to mess with the legacy code base but if one realy wants to convert the old 77 fixed source code to modern free form source Fortran, the job becomes really tedious and annoying. This script aims to automate the process to easily produce formatted free form code.
Just run the python script with your FORTRAN 77 file name as argument
python convert.py <file_name>.f
It will output a file named <file_name>.f90
. All avilavle options,
>python convert.py -h
usage: convert.py [-h] [-o PATH] [-maxcol MAXCOL] [-indent INDENT] [-numbereddo] [-keepblank] [-progstate] PATH
Convert fixed source FORTRAN 77 code to indented modern free form Fortran 90 code
positional arguments:
PATH Name of the input file
optional arguments:
-h, --help show this help message and exit
-o PATH Name of the output file
-maxcol MAXCOL Maximum allowed column
-indent INDENT Length of indentation of each labels
-numbereddo Convert numbered do blocks
-keepblank Keep blank lines
-progstate Insert a `program` statement at the top
- Convert comment style
- Convert line continuation
- Removes numbered do loop
- Removes format labels and move them inside respective write statements
- Indent the code
- Removes unwanted blank lines
- Converts to lower case
- Replaces things like '.ge.', '.le.', '.gt', '.lt.' etc
- Removes return and stop before end statements
- Fixes OpenMP multiline directives
- Replacing go to statements.
- Changeing variable declaration i.e implicit declaration, common statements etc.
- Removing block data
- Removing arithmatic if statements
- Handling preprocessing commands.
The script removes numbered do loop and any label associated with it, so if a numbered do loop shares its label with any other goto or arithmatic if statements, the sctipt will break the code. If your script contains such cases you must diable the numbered do loop conversion.
To make things easier the script converts evrything to lowercase. The script doesn't guarentee to covert any error. User must check the resulted code before running.