Compiling Fortran 66 programs

A general rule for compiling and running old code in any language is to first try to get it working for known input / output via emulation or virtual machine. Many old codes were made before linters and other correctness checks we’ve long taken for granted. The codes may use non-standard tricks to boost efficiency that haven’t been significant for decades.

A modern Fortran compiler that can compile Fortran 66 standard code without modification is Intel oneAPI. The -f66 flag enables Fortran 66 compatibility. A key behavior difference with Fortran 66 is that Do loops always run at least once. This behavior is not available in Gfortran. If one has the ability to use a virtual machine with unmaintained compilers like g77 and the -fonetrip flag, this behavior can be emulated. However, this behavior was simply not addressed in the Fortran 66 standard.

After correct operation is established, Fortran 66 code often needs adjustments to work with modern compilers. The Fortran Wiki has an excellent article on modernizing Fortran syntax.

Always make a copy of the file first. Sometimes 10,000+ lines will match so it can be tedious to check. Similar operations may be needed if a mix of tabs and spaces are used.

To move line numbers left, run this regex and replace with null (nothing):

^\s+(?=\d+\s)

To make code start in column 7, recall that fixed format (Fortran <= 77) code has line numbers in columns 1-5 of each line numbers After the prior operation, push the actual code right of column 6 by replacing this regex with appropriate number of spaces:

(?<=^\d+\s+)

Other compatibility notes:

  • $ can be used like a semicolon in CDC Cyber Fortran
  • put procedures in separate files for duplicated line numbers.