Skip to main content

fortfmt-fix

A small, deterministic codemod that rewrites Intel/DEC omitted-width Fortran FORMAT descriptors (e.g., I, F.d, E.dE#, G.d, L) to standard-conforming forms (e.g., I12, F25.16), improving portability across compilers (gfortran, ifx, etc.).

Quickstart

Installation

# From PyPI (when available)
pip install fortfmt-fix

# From source (development mode)
git clone https://github.com/anl-cec/fortfmt-fix.git
cd fortfmt-fix
pip install -e .

Command Line Usage

# Show proposed changes without modifying files
fortfmt-fix --dry-run path/to/src

# Apply changes in-place
fortfmt-fix --in-place path/to/src

# Process specific files
fortfmt-fix --dry-run file1.f90 file2.f90

# Process directories recursively
fortfmt-fix --in-place src/

Python API

from fortran_format_codemod import transform_source

# Basic usage
result = transform_source("WRITE(*,'(I)') i")
# Returns: "WRITE(*,'(I12)') i"

# With flags
result = transform_source(
    "WRITE(*,'(I)') i", 
    int64=True,           # Use I23 instead of I12
    listify_reads=True,   # Convert safe READ statements to list-directed
    trace=True            # Enable debug output
)

Default Widths

The tool applies the following default widths when omitted:

Descriptor Default With --int64
I I12 I23
L L2 L2
F F25.16 F25.16
E E25.16E3 E25.16E3
D D25.16E3 D25.16E3
G G25.16 G25.16
ES ES25.16E3 ES25.16E3
EN EN25.16E3 EN25.16E3

Examples

Basic FORMAT Statement

! Before
FORMAT(I, F.6, E.12E3)

! After
FORMAT(I12, F25.6, E25.12E3)

Nested Groups with Repeat Counts

! Before
WRITE(*,'(1X, 2(F.6, 1X), I)') a, b, c

! After  
WRITE(*,'(1X, 2(F25.6, 1X), I12)') a, b, c

READ Statement Listification

! Before (with --listify-reads)
read(5, '(I, I, F.6)') i, j, x

! After
read(5, *) i, j, x

Command Line Options

  • --dry-run - Show proposed changes without modifying files
  • --in-place - Apply changes directly to files
  • --int64 - Use wider integer defaults (I23 instead of I12) for 64-bit I/O
  • --listify-reads - Convert safe READ statements to list-directed form
  • --trace - Enable verbose debug output

Safety & Idempotence

fortfmt-fix is designed to be safe and idempotent:

  • Conservative: Only transforms omitted-width descriptors, never touches explicit widths
  • Idempotent: Running the tool multiple times produces identical results
  • Preserves semantics: Quoted strings and non-format content are never modified
  • Deterministic: No random behavior or network calls

Recommended Usage

For best results, use as a pre-commit hook to catch format issues early:

# Install pre-commit
pip install pre-commit

# Add to .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: fortfmt-fix
        name: fortfmt-fix
        entry: fortfmt-fix --dry-run
        language: system
        files: \.(f90|F90|f|F)$

Testing

The package includes comprehensive tests covering:

  • Basic descriptor transformations
  • Nested groups and continuation lines
  • Flag behavior (--int64, --listify-reads)
  • Idempotence verification
  • Edge cases and malformed input handling
  • CLI smoke tests

Run tests with:

pytest -q

See Also

  • docs/OSS-Approval-OnePager.md - Project overview and approval
  • JOSS/paper.md - Academic paper describing the tool
  • CHANGELOG.md - Version history and changes

Metadata

Release files for fortfmt-fix 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fortfmt-fix 0.1.0
File Size Uploaded
fortfmt_fix-0.1.0.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fortfmt-fix 0.1.0
File Interpreter ABI Platform
fortfmt_fix-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.9 kB

Release files / fortfmt_fix-0.1.0.tar.gz

Download URL fortfmt_fix-0.1.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1cfd418ee399eb4ac01101f4f63754a189998ead11dedb12182a6bfb98b5c134
BLAKE2b-256 checksum
How to use checksums
f5f90aa50f475defe35a02f5b3ff9de67e87c4abce20681ba2b5aead8e70b192
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / fortfmt_fix-0.1.0-py3-none-any.whl

Download URL fortfmt_fix-0.1.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
391520e3a67155f602848c7901e6669545bcd535e7ce5d382ae8679728511750
BLAKE2b-256 checksum
How to use checksums
a125a7212c9f3292243ff1abb1516bfb8c2df01d1d51fee846bf78dd26e5858f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page