Skip to content

An opinionated one-stop shop for new and old Fortran projects, offering seamless compiling, building, packaging, linting, formatting, and more, with modern tools like FPM, pre-commit, fprettify, and ford.

License

Notifications You must be signed in to change notification settings

MatthAlex/fortran-project-template

Repository files navigation

Fortran Project Template

Modern Fortran development made simple - an opinionated, batteries-included project template that brings contemporary development practices to Fortran projects.

Why This Template?

Fortran remains a crucial language in scientific computing, engineering, and high-performance computing. However, while the language has modernized significantly, the development workflow often lags behind contemporary software engineering practices. This template bridges that gap by providing:

  • modern development features like code completion, automated testing, and documentation generation out of the box.
  • seamless integration of Fortran codebases with modern DevOps practices, including continuous integration, code quality checks, and automated documentation.
  • IDE-like tooling integration with VS Code and extensions.

Key Benefits

  • 🚀 Instant Modern Setup: Get a fully configured development environment in minutes, not days
  • 🔍 Code Intelligence: Real-time error detection, code completion, and refactoring support via VS Code integration
  • 📊 Quality Assurance: Automated testing, formatting, and linting integrated with git workflow
  • 📚 Automated Documentation: Generate professional documentation from your code comments
  • 🛠️ Best Practices Built-in: Pre-configured tools enforce consistent code style and quality
  • 🔄 Modern Workflow: Brings git-based workflow, dependency management, and automated builds to Fortran

Traditional vs Modern Fortran Development

Aspect Traditional Approach With This Template
Setup Time Hours/days configuring tools Minutes with pre-configured environment
Error Detection At compile time Real-time as you type
Code Style Manual enforcement Automated formatting and checks
Documentation Manual maintenance Generated from code comments
Testing Often manual or ad-hoc Automated with each commit
Dependencies Manual management Handled by package manager

Getting Started

Prerequisites

  • Linux OS or WSL2 via Windows
  • GFortran or oneAPI Fortran compiler

Optional

  • VS Code installation
  • Modern Fortran extension installation

Step-by-step instructions

  1. Load compiler modules (if on a compute cluster):

    module load gcc
    # or
    module load intel
  2. Create and activate a Python environment:

    python3 -m venv .venv
    source .venv/bin/activate

    Remember to activate your enviroment before runtime or development tasks.

  3. Install the runtime and development packages:

    pip3 install .  # Install runtime dependencies from pyproject.toml
    pip3 install .[dev]  # Install development dependencies
  4. Run the tests and main program:

    fpm test  # by default it uses gcc/gfortran to compile and run
    fpm run
  5. Migrate your project:

    See a step-by-step guide on how to migrate your project.

Code Quality

This template integrates several tools to maintain high code quality:

IDE Integration

  • Real-time error detection and linting via the Modern Fortran extension and fortls language server
  • Intelligent code completion and navigation
  • Code formatting with fprettify for consistent style

Automated Checks

  • Pre-commit hooks run tests and quality checks before git commit and push
  • Automated testing with fpm test
  • Compile-time checks with fpm build (debug/release modes)

For detailed configuration and usage instructions, see TOOLING.md.

Documentation

Automated documentation is generated by using the ford package. For example config files and usage, see here.

To generate dcoumentation for this sample project, and then view it on the browser, run:

ford ford.md
firefox docs/ford/index.html  # Alternatively, use your preferred browser

Development Tools

The template includes preconfigured development tools and settings for Modern Fortran development, with optimized configurations for:

  • VS Code integration
  • Language server features
  • Code formatting
  • Automated testing
  • Package management

For detailed setup instructions and tool configurations, see TOOLING.md.

Contributing

Contributions from the community are welcome. To contribute, consider opening an issue or pull request with changes and suggestions.

Contact

For questions or suggestions, please contact us at email or open an issue.

License

The project is operating under an MIT license. You are free to use, modify, and distribute the code as needed for your project. Feel free to adapt and customize it to suit your requirements.

Appendix

Project Directory Structure

$ tree -Ia '__pycache__|.git|.pytest_cache|.venv|build|.gen*|ford'
.
├── app  # The main program driver(s) resides here
│   └── main.f90
├── docs
│   ├── MIGRATION.md
│   └── TOOLING.md
├── ford.md  # FORD config file
├── .fortls  # VSCode Modern Fortran config file
├── fpm.toml  # Fortran Package Manager config file
├── .fprettify.rc  # fprettify config file
├── .gitignore  # Git ignore list of files and directories
├── LICENSE
├── .pre-commit-config.yaml  # pre-commit config file
├── pyproject.toml  # config file
├── README.md  # you are here!
├── src  # All source code files are placed in here, except main driver
│   └── first_steps.f90
├── test  # All tests are placed in here
│   └── check.f90
└── .vscode  # Holds VSCode configs and runtime/debugging tasks
    ├── extensions.json  # simply populates the "Recommended" Extensions tab
    └── settings.json  # also referred to as "Workspace Settings (JSON)"

References and Links

This repository takes a lot of inspiration (and actual code) from easy.

About

An opinionated one-stop shop for new and old Fortran projects, offering seamless compiling, building, packaging, linting, formatting, and more, with modern tools like FPM, pre-commit, fprettify, and ford.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published