Codemod to replace Intel/DEC omitted-width FORMATs with standard-conforming Fortran I/O
Project description
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 approvalJOSS/paper.md- Academic paper describing the toolCHANGELOG.md- Version history and changes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fortfmt_fix-0.1.0.tar.gz.
File metadata
- Download URL: fortfmt_fix-0.1.0.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cfd418ee399eb4ac01101f4f63754a189998ead11dedb12182a6bfb98b5c134
|
|
| MD5 |
86860fd8ec91e649bd637f91e7fc2f02
|
|
| BLAKE2b-256 |
f5f90aa50f475defe35a02f5b3ff9de67e87c4abce20681ba2b5aead8e70b192
|
File details
Details for the file fortfmt_fix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fortfmt_fix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
391520e3a67155f602848c7901e6669545bcd535e7ce5d382ae8679728511750
|
|
| MD5 |
6abf018bc3910754989cd9069ded5b38
|
|
| BLAKE2b-256 |
a125a7212c9f3292243ff1abb1516bfb8c2df01d1d51fee846bf78dd26e5858f
|