Fortran 77 Coding Guidelines


Introduction

The following guidelines are designed to encourage consistent coding across projects and programmers. Many arbitrary low-level decisions are made during coding. While many of these have no effect on the machine code, they do affect the appearance of the code. And, consistent practices enhance productivity and reusability. Project requirements, when applicable, take precedence.

 The goals of the guidelines are, in decreasing order of importance:
 
 

General

Project Organization

Program Units

Statement format

Statement labels

Capitalization

Spacing

Identifier Selection

Constants

Typing

Operators

Expressions

Arrays

Control structures

Arguments

COMMON blocks

Input/Output

BIBLIOGRAPHY

The contributions of the following individuals are gratefully acknowledged. Many laudable suggestions were unilaterally discarded solely in the interest of keeping this guide as brief as possible. A style guide by its very nature is subjective. The primary intent of this guide is draw attention to some of the intricacies of coding in the interest of encouraging consistency.
 
 

APPENDIX I. Loop Constructs

iterative

      DO 10 I = 1, iterations
         . . .
  10  CONTINUE
OR:
      do I = 1, iterations
         . . .
      end do
Do not modify the loop variable.
 
 

while

  10  CONTINUE
         . . .
         IF ( condition ) GOTO 20
         . . .
         GOTO 10
  20  CONTINUE

do-while or repeat-until (all statements in loop execute at least once)

  10  CONTINUE
         . . .
      IF ( condition ) GOTO 10

APPENDIX II. Suggested Compiler Options

APPENDIX III. Example

Notes on example:
mode         define           use
----------------------------------------- 
IN           not allowed      allowed
OUT          allowed          not allowed
INOUT        allowed          allowed
      SUBROUTINE TEUpCase (String)
*
* ================== Prologue ==========================================
*
* Purpose:
*    Convert a string to all upper case characters.
*
* History:
*    Version   Programmer         Date       Description
*    -------   ----------         ----       -----------
*    1.0       D. Levine          03/16/89   created
*    1.1       D. Levine          12/11/89   changed to INDEX into
*                                            constant string from adding
*                                            'A' - 'a' to each char.
*
* IN args/commons         Units      Description
* ---------------         -----      -----------
*
* OUT args/commons        Units      Description
* ----------------        -----      -----------
*
* INOUT args/commons      Units      Description
* ------------------      -----      -----------
* String                  N/A        string to be converted
*
* Processing:
*    For each character in String, check to see if it is lower case by
* finding its INDEX in the string [a..z].  Then, replace with the
* character at the same position in the string [A..Z].
*
* Special requirements:
*    none
*
* ------------------ Include files -------------------------------------

* ------------------ Constant declarations -----------------------------

* ------------------ Argument declarations -----------------------------

      CHARACTER*(*) String

* ------------------ Global/External declarations ----------------------

* ------------------ Local declarations --------------------------------


      INTEGER Pos, I

      CHARACTER*26 lowers, uppers
      DATA lowers / 'abcdefghijklmnopqrstuvwxyz' /,
     &     uppers / 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /

* ------------------ Code ----------------------------------------------


      DO 100 I = 1, LEN (String)

         Pos = INDEX (lowers, String(I:I))
         IF ( Pos .NE. 0 ) String(I:I) = uppers(Pos:Pos)

  100 CONTINUE

      RETURN
      END
This document was originally written by David L. Levine (levine@ics.uci.edu) and converted to this hypertext format by Shiva Shenoy.

Back to the main menu


James Weighton and R. G. Hindman