Coding style

The aim of this style guide is the make the uEMEP code base as easy as possible to read and collaborate on.

Note

The style guide is currently not complete or finalized.

Module structure

  • Structure code in modules (module)

  • In most cases, module variables should be private by default. Declare public variables and procedures using the public keyword

  • Use explicit import when possible (i.e., use module, only: var, func is better than ude module)

Example of module structure:

module module_name

    use module, only: imported_variable, imported_procedure

    implicit none
    private

    public :: public_function

    real, public :: public_real
    real :: private_real

contains

    function public_function(par) result(res)
        real, intent(in) :: par
        real :: res
        ...
    end public_function

    subroutine private_subroutine(par, res)
        real, intent(in) :: par
        real, intent(out) :: res
        ...
    end subroutine private_subroutine

end module module_name

Indentation and white space

  • Indent using 4 spaces

  • Lines should be no longer than 132 characters, including indentation

  • Use vertical white space to structure code into logical units

  • Use horizontal white space to help reader, e.g.,

    • a = 2.0 is better than a=2.0

    • 2.0 + 3.0*sqrt(r) - 2.0 is better than 2.0+3.0*sqrt(r)-2.0

    • if (i == 1 .and. l <= limit) then is better than if(i==1.and.l<=limit)then

Variable names

  • Variables names should be lower case only

  • Use descriptive variable names, and use underscore to seperate words (e.g., use_meteorology)

Values

  • Explicitly state preceeding or exceeding zeroes (e.g., 2.0 and 0.5 is better than 2. and .5)