Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python
88 changes: 51 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,65 @@
fortran-legacy-tools
# fortran-legacy-tools

Tools to deal with Fortran code
**Tools to deal with Fortran code**

-------------------------------------------------------------------------------
fixed2free/fixed2free2.py:
-------------------------------------------------------------------------------
**Author:** Elias Rabel

Tool to convert from FORTRAN fixed source form files to free source form.
Supports OpenMP and C-preprocessor statements.
This project includes a suite of tools aimed at facilitating the modernization of Fortran codebases, making them more compatible with contemporary coding standards and practices.

The FORTRAN fixed source format dates back to time when punched cards were
used in programming. Nevertheless it is widespread in the numerical computing
community. Even programs written according to the most recent Fortran 2008
standard can be written in fixed source form, although this is deprecated since
Fortran 2003.
## fixed2free2.py

This script converts fixed source form files to the free source form,
introduced with Fortran 90.
In refactoring legacy Fortran codes this is a useful first step.
### Description

Some similar tools that I tried, attempt to automatically upgrade
deprecated language constructs with varying success.
This tool takes a more minimalistic approach and changes only the source form.
`fixed2free2.py` converts Fortran code from fixed source form to free source form. This tool is particularly useful in refactoring legacy Fortran codes, enhancing their readability and maintainability.

Automatic unit tests are provided with the Test_fixed2free2.py file.
### Background

-------------------------------------------------------------------------------
flowercase/flowercase.py:
-------------------------------------------------------------------------------
The fixed source format is a legacy from the era of punched cards but remains in use within the numerical computing community. Despite Fortran 2018 allowing for fixed source form, it has been deprecated since Fortran 2003 in favor of the free source form introduced in Fortran 90.

Tool to convert free source form Fortran code to lower-case while
leaving comments and strings unchanged.
Mixed case identifiers and keywords are left unchanged.
### Functionality

-------------------------------------------------------------------------------
fdeclarations/fdeclarations.py:
-------------------------------------------------------------------------------
The tool takes a minimalistic approach by changing only the source form without attempting to modify or upgrade deprecated language constructs. It supports OpenMP and C-preprocessor statements, ensuring a smooth transition to free source form.

Tool to separate subroutine arguments from declarations of local variables.
### Usage

Legacy Fortran subroutines often have huge argument lists. Fortran allows
mixing of argument datatype declarations and declarations of local variables,
which can lead to confusion.
```bash
python fixed2free2.py file.f > file.f90
```

This tool generates code for a wrapper of the given subroutine, which
groups declarations into 3 sections:
-) parameters (might be needed for dimensions of array arguments)
-) subroutine arguments
-) local variables (commented out)
### Limitations

While fixed2free2.py aims to accurately transform fixed form code to free form, it has specific limitations regarding whitespace usage that can affect the conversion:

The script cannot handle certain usages of whitespace characters allowed in fixed form but not in free form. This limitation is crucial when dealing with complex formatting that does not directly translate into free form.

For example, the following fixed form source code:

```Fortran
WR IT E(* , *) I J K LM N
```

will not be transformed into correct free form source code, which would be:

```Fortran
WRITE (*,*) IJKLMN
```

[issue2]: https://github.com/ylikx/fortran-legacy-tools/issues/2

## Additional Tools in the Project

### flowercase.py:

A tool to convert free source form Fortran code to lowercase, excluding comments and strings, while leaving mixed case identifiers unchanged.

### fdeclarations.py:

Assists in separating subroutine arguments from local variable declarations, enhancing code clarity and organization.

Legacy Fortran subroutines often have huge argument lists. Fortran allows mixing of argument datatype declarations and declarations of local variables, which can lead to confusion.

This tool generates code for a wrapper of the given subroutine, which groups declarations into 3 sections:

- parameters (might be needed for dimensions of array arguments)
- subroutine arguments
- local variables (commented out)
Loading