From fixed form to free form

Contents
What fixed form was
Convert mechanically
Replace COMMON with modules
Re-test everything

What fixed form was

Very old Fortran used fixed columns inherited from punch cards: labels at the start, code in a narrow middle area, and sequence numbers at the end.

The tiny block below is a historic fixed form excerpt only. Do not compile it and do not write new code in this style.

! historic fixed form excerpt, do not use ! code started in column 7 in old files ! X = 1 with six leading blanks

Convert mechanically

Modern free form removes column rules. Statements start anywhere, lines run to 132 characters, and the exclamation mark starts a comment.

Rewrite each old line as plain free form with a program unit and implicit none, then let the compiler check the result.

program converted implicit none integer :: x x = 1 x = x + 2 print *, "x =", x end program converted

Replace COMMON with modules

Old code shared global data through COMMON blocks, which hide dependencies and break type checking across files.

Replace each shared block with one small module that owns the data and offers procedures to read and change it.

module shared_state implicit none integer :: counter = 0 contains subroutine bump() implicit none counter = counter + 1 end subroutine bump end module shared_state

Re-test everything

Migration changes layout and data flow, so every converted unit needs a fresh run with checks on.

Compile with checks, run the old and new versions on the same input, and compare numeric results before deleting the old file.

program check_migration implicit none integer :: got got = 3 if (got .ne. 3) then print *, "migration mismatch" error stop 1 end if print *, "migration ok" end program check_migration

Next: Numeric models

Article author: Arthur Isaev

Related articles
Fortran
Fortran course: zero to hero in 50 lessons
What is Fortran and where it runs
Install gfortran
Your first program
Program structure
Types: integer real complex logical character
Kind parameters
Operators
Conditions
DO loops
Arrays
Array sections
Character strings
Formatted IO
Files
Subroutines and functions
Modules
USE with ONLY
INTENT
OPTIONAL and PRESENT
Explicit interfaces
Derived types
Type-bound procedures
Object orientation
Operator overloading
Finalization
Allocatable arrays
Pointers in Fortran
DO CONCURRENT
Coarrays
OpenMP basics
Namelists
IEEE arithmetic
Intrinsic matrix math
Random numbers
String tools
Command-line arguments
Environment variables
error stop
Testing
Build with gfortran and make
Debugging
C interoperability
From fixed form to free form
Numeric models
Performance
Modern Fortran tour: 2008, 2018, 2023
Capstone: stats tool
Capstone: 1D heat equation
Style guide
Hero roadmap: the whole course on one page
Install gfortran on Windows 11
Install gfortran on Ubuntu
Install gfortran on Rocky Linux
Install gfortran on macOS
Install gfortran on FreeBSD
Fortran in Docker
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: