Common Fortran Errors

P. A. Robinson

The vast majority of Fortran programming errors (not including trivial typos and syntax errors) fall under the following eight categories.

  1. Wrong Placement of Text

    • If you run beyond the 72nd character on the line, the remaining characters will be ignored.

    • Placing continuation characters in other than the 5th column, or omitting them entirely causes continuation lines to be misinterpreted.

    • Omitting a comment character from the first column of a comment line causes the comment line to be interpreted as Fortran code.

    • Labels must be placed in the first 5 columns.

  2. Wrong Variable or Function Type

    • This often occurs when variables are implicitly typed (either by you or using the default types, i-n = integer, a-h and o-z = single precision real). You need to ensure that the types of all functions and variables are declared wherever they differ from the implicit types.

    • This problem can occur when a typo causes the compiler to assume that you have introduced a new variable (e.g., you type the variable name ``variab1e'' instead of ``variable''; or, worse, ``variab le'' instead of ``variable'').

  3. Decimal Point in Reals

      Be sure to use a decimal point at the correct location whenever

    • Inputting a real from the terminal or a data file. Otherwise it may be misread.

    • Using a real constant in the program. Otherwise it may be mistaken for an integer.

  4. Double Precision Constants

    • Be sure to use double precision constants if you want your program to be truly double precision - you must write 1.d0, not 1., for example.

  5. Integer Division.

      If you divide an integer by an integer the compiler assumes you want integer division with remainders discarded.

    • To ensure a real answer when dividing by an integer, divide by real("integer variable").

    • This problem often occurs when the decimal point is accidentally omitted when dividing by a real constant (cf., Category 3 above).

  6. Ordering in Common Blocks

    • The order and type of variables in a common block must be the same wherever that block is used.

  7. Mismatch of Numbers or Types of Variables in Subroutine/Function Calls

    • The number and type of variables in a call to a subroutine or function must match those occurring in the definition of the subroutine/function.

  8. Writing Beyond an Array or Variable

    • If you assign values to array elements beyond the defined bounds of an array you may overwrite other variables (with bizarre results). This can also happen if you accidentally assign a complex, double precision, or real to an integer, or assign a double precision or complex to a real, for example. Don't forget that the array defined by ``array(n)'' consists of the elements 1 to n, not 0 to n-1.

University of Sydney | Faculty of Science | School of Physics | Science Foundation | Back to Top