Fortran projects often rely on large and long-lived codebases that evolve over many years and across different teams. In this context, defining and applying coding guidelines is essential to ensure code quality, maintainability, and consistent development practices.
This article explains why coding guidelines are important for Fortran projects, the difficulties of enforcing them manually, and how Codee can be used to automate this process.
This article is based on concepts discussed in a technical session on Fortran coding guidelines. You can watch the full webinar recording here.
The role of coding guidelines in Fortran projects

Coding guidelines help development teams establish a common set of rules that define how code should be written and maintained. These rules are applicable to both small and large teams and are typically based on a combination of team conventions and established best practices. Clear coding guidelines help teams:
- Write higher-quality code
- Improve team productivity
- Maintain projects more effectively over time
What coding guidelines usually define
In Fortran projects, coding guidelines typically address the following areas:
- Code formatting
Guidelines often define how the code should be formatted, including- Code indentation
- Line length limits
- Overall layout and style
- Use of the Fortran language
Guidelines also describe how Fortran features should be used to avoid common errors. Examples include:- Avoiding implicit variable declarations
- Specifying intent in procedure arguments
- Restricting the use of certain language constructs
- Use of the development environment
Some guidelines take into account aspects related to the development environment, such as:- Portability issues between different compilers
- Constraints related to parallel programming models
The challenge of enforcing coding guidelines
Even when coding guidelines are clearly defined, enforcing them consistently is difficult. The process is time-consuming, and some rules may be overlooked during development or code reviews.
For this reason, it is important to rely on tools that can automatically enforce coding guidelines and help developers apply them consistently across the codebase.
Enforcing Fortran coding guidelines with Codee
Codee provides a set of tools to help enforce coding guidelines in Fortran projects:
- Formatting:
Codee supports both fixed-form and free-form Fortran. Its formatting capabilities allow teams to automatically apply coding style rules and maintain a consistent format across the entire codebase. Formatting options can be customized to match project-specific guidelines.
- Deep Static Analysis:
In addition to formatting, Codee analyzes Fortran, C and C++ code to detect issues related to correctness, modernization, security, portability and optimization. These analyses are based on recommendations defined in Codee’s Open Catalog of Coding Guidelines.
For each recommendation, the Open Catalog provides a description of the issue, guidance on how to address it and a before-and-after code examples.
Some recommendations support AutoFixes. For recommendations that do not support automatic fixing, Codee identifies the exact location of the issue and provides guidance to apply the fix manually.
All formatting options and analysis checks can be customized to meet the specific needs of a development team.
Applying coding guidelines to real Fortran projects
Codee can be adapted to enforce coding guidelines defined by real-world Fortran projects. The examples below illustrate how selected guidelines from WRF, CP2K, and FMS can be mapped to Codee formatting capabilities and analysis checks.
Codee analysis checks are defined in the Open Catalog of Coding Guidelines, where each recommendation is identified by a unique PWR ID and documented with a description, guidance, and code examples.
WRF (Weather Research and Forecasting Model)
The WRF coding guidelines include both formatting rules and recommendations on how to use Fortran language features to write robust code. Codee can enforce a subset of these guidelines through formatting and static analysis.
| Guideline example | Codee capability | Reference | AutoFix |
| Indentation and maximum line length (132 columns) | Formatting options | — | ✓ |
| Follow existing code style when modifying modules | Formatting (configurable) | — | ✓ |
| Use IMPLICIT NONE and declare all variables | Analysis check | PWR007 | ✓ |
| Specify INTENT for procedure arguments | Analysis check | PWR008 | ✓ |
| Avoid legacy constructs (STOP, PAUSE) | Analysis check | PWR063 | – |
| Do not use COMMON blocks that are outside of a self-contained module | Analysis check | PWR073 | ✓ |
| … | |||
CP2K
CP2K defines detailed formatting requirements as well as rules related to correctness and parallel programming. Codee supports these guidelines through fine-grained formatting customization and targeted analysis checks.
| Guideline example | Codee capability | Reference | AutoFix |
| Indentation with a relative width of 3 characters | Formatting options | — | ✓ |
| Whitespace rules around operators | Formatting options | — | ✓ |
| USE statements must include an ONLY clause | Analysis check | PWR069 | ✓ |
| Explicit scoping in OpenMP parallel regions | Analysis check | PWR005 | – |
| Avoid GO TO statements | Analysis check | PWR063 | – |
| … | |||
FMS (Flexible Modeling System)
The FMS coding guidelines combine formatting consistency with recommendations related to data flow and arithmetic optimizations. These guidelines can also be enforced using Codee.
| Guideline example | Codee capability | Reference | AutoFix |
| Line length limits | Formatting options | — | ✓ |
| Consistent end statements (end do, end subroutine) | Formatting options | — | ✓ |
| Module use statements | Analysis check | PWR069 | ✓ |
| Implicit variables | Analysis check | PWR007 | ✓ |
| Data flow | Analysis check | PWR001 / PWR008 | – / ✓ |
| Optimization for divides | Analysis check | PWR045 / PWR046 | – |
| …. | |||
📃 The examples above show only a subset of the supported guidelines. A complete and up-to-date mapping between project-specific coding guidelines and Codee formatting and analysis capabilities is available for download in this whitepaper.
Takeaways
Coding guidelines help Fortran teams write higher-quality code, improve productivity, and maintain projects over the long term.
Codee provides a set of tools that combines formatting and deep static analysis to help enforce these guidelines. Its capabilities are customizable and can be adapted to real-world Fortran projects.
👉 You can download Codee Formatter for free to start applying consistent formatting to your Fortran codebases:
Download Codee Formatter
Build correct, secure, modern and fast Fortran, C and C++ scientific software
This company is capitalized by INNVIERTE, AN INVESTMENT PROGRAM OF CDTI, E.P.E
Leave a Reply