Version 8 (modified by kanani, 6 years ago) (diff)

--

PALM coding rules

Why to follow some standards? - Because everyone has her/his own programming style, sort of a dialect, making it difficult for other developers to understand, extend, debug, or optimize the code. So what do we do? We learn and apply the coding standard to make PALM more easily readable for all current and future developers. Let's all work on that together. We are aware that the PALM core doesn't completely comply with the following rules yet, but we are working on that.
Formulated rules and specifications are based on the specifications given for the ocean dynamics model [add-new-link-to NEMO]. Other work that influenced the development of this standard are [add-link Community Climate System Model], [add-link Software Developer's Guide], [add-link Report on Column Physics Standards], and [add-link European Standards For Writing and Documenting Exchangeable FORTRAN 90 Code].


(1) General language & form requirements

  • FORTRAN-2003 standard (all FORTRAN compilers can handle this, FORTRAN-2008 standard not yet supported by all compilers)
  • Use English language only
  • Use ASCII characters only
  • Use SI units as physical units
  • Line length limit: 80 characters (soft) | 120 characters (hard) --> Optimize readability (FORTRAN-2003 standard allows max. 132 characters)
AVOID USE INSTEAD
COMMON blocks ...


(2) Indenting, spaces & line breaks

General module/subroutine structure (see Fig. 1)


Fig. 1 Indention example with highlighted whitespaces. Click to enlarge.

  • 0 whitespace in front of pre-processor directives
  • 1 whitespace before MODULE, CONTAINS, SUBROUTINE (= first indention level)
  • +3 whitespaces for all following indention levels
    (only exception: ONLY list in USE statements +4 whitespaces)
  • 1 whitespace between individual strings, and between strings and symbols/numbers
  • 1 whitespace after ,
    (only exception: 0 whitespace between array dimensions)
  • 1 whitespace before ::
    (at minimum, see Sect. Alignment)
  • 2 whitespace after : and ::
  • 1 blank line between enclosed blocks of instructions, assignments, clauses, statements, etc.
  • & character for line continuation at position 80 (minimum), max at position 120

Whitespaces between brackets (see Fig. 1)

  • 0 whitespace between string and (
  • 1 whitespace after ( and before )
    (only exception: 0 whitespace in dimensions)













Whitespaces in DO, IF blocks (see Fig. 2)


Fig. 2 Indention & whitespaces in loops. Click to enlarge.

  • In general: 1 whitespace everywhere and 3 whitespace for indention levels
  • But: 2 whitespace
    • between DO and loop index
    • after IF ( ) --> see CALL, THEN
    • in front of and after logical or relational operators (e.g. .OR., see list of allowed operators)






(3) Alignment

(see Fig. 3)


Fig. 3 Alignment example. Click to enlarge.

  • Block-wise alignment of continuation line marker &
  • Alignment of ONLY lists
  • At least block-wise alignment for same type/group of declaration statement
  • Alignment of message_string values
  • Alignment of expressions between brackets (e.g. in IF ( ) THEN or in argument list in subroutine calls)




































Alphabetical sorting

except for CALLs to modules/subroutines

Lower/upper case

Commenting

Naming conventions

Allowed operators

  • Use /=, <, <=, ==, >, >=, etc. as relational operators instead of .GE., .LT., etc.
  • Use .AND., .OR., .NOT. as logical operators

Preprocessor directives

Declaration statements

  • for long lists form groups

File header

  • Files always start with a doxygen-readable comment line including the FORTRAN file name.
  • This is followed by the license section. If your code originates from another model, please clarify the license and permissions for this code to enter the PALM model system. It might be necessary in that case to add some more information to this header.
  • The revisions section will later include short notes of the changes applied to a specific svn revision of this file. The $Id$ string is required so that svn knows to generate the respective time stamp for a revision (see existing SOURCE files).
  • Finally, involved authors are included, followed by a description of the purpose and functions of the module. If necessary, TODOs, notes and known bugs can be added. The "!>" indicate doxygen-readable comment lines, the "@" marks doxygen variables.

Check compilation

  • no warning/error message should remain

Attachments (5)

Download all attachments as: .zip