- Trim all trailing whitespace from every line (some editors can do this
automatically).
- No characters.
- Supply a header for each file with a description of the file and the author(s)
name or GitHub ID.
- A copy of the Gnu Lesser General Public License
must be included at the top of each file.
- Documentation should be written so that it can be parsed by Doxygen.
- All variables should be defined, and include units. Unit-less variables should be marked
unitless
- Provide detailed descriptions of modules, interfaces, functions, and subroutines
- Define all function/subroutine arguments, and function results (see below)
- Follow coding style of the current file, as much as possible.
- Use Fortran 95 standard or newer
- Two space indentation
- Use
KIND
parameters from intrinsic fortran modules such as iso_fortran_env
or iso_c_binding to ensure portability
- Never use implicit variables (i.e., always specify
IMPLICIT NONE
)
- Lines must be <= 120 characters long (including comments)
- logical, compound logical, and relational if statements may be one line,
using “&” for line continuation if necessary:
if(file_exists(fileName)) call open_file(fileObj,fileName, is_restart=.false)
- Avoid the use of
GOTO
statements
- Avoid the use of Fortran reserved words as variables (e.g.
DATA
, NAME
)
- Avoid the use of
COMMON
blocks
- Type names must be in CapitalWord format.
- Variables names must be in underscore_word format.
- All member variables must be private.
- Doxygen description on the line before the type definition.
- Inline doxygen descriptions for all member variables.
- Functions should include a result variable on its own line, that does not have
a specific intent.
- Inline doxygen descriptions for all arguments, except the result variable.
- Doxygen description on the line(s) before the function definition. This must
specify what the function is returning using the
@return
doxygen keyword.
- terminate
do
loops with enddo
- terminate block
if
, then
statements with endif
- Directives should start at the beginning of the line, and be in lowercase.
- All openMP directives should specify default(none), and then explicitly list
all shared and private variables.
- All critical sections must have a unique name.
!> @file
!! @brief Example code
!! @author <developer>
module example_mod
use, intrinsic :: iso_fortran_env, only: INT32, REAL32
use util_mod, only: util_func1
implicit none
private
public :: sub1
public :: func1
!> @brief Doxygen description of type.
type,public :: CustomType
private
integer(kind=INT32) :: a_var !< Inline doxygen description.
real(kind=REAL32),dimension(:),allocatable :: b_arr !< long description
!! continued on
!! multiple lines.
endtype CustomType
contains
!> @brief Doxygen description.
subroutine sub1(arg1, &
& arg2, &
& arg3)
real(kind=REAL32),intent(in) :: arg1 !< Inline doxygen description.
integer(kind=INT32),intent(inout) :: arg2 !< Inline doxygen description.
character(len=*),intent(inout) :: arg3 !< Long inline doxygen
!! description.
end subroutine sub1
!> @brief Doxygen description
!! @return Function return value.
function func1(arg1, &
& arg2) &
& result(res)
integer(kind=INT32),intent(in) :: arg1 !< Inline doxygen description
integer(kind=INT32),intent(in) :: arg2 !< Inline doxygen description
integer(kind=INT32) :: res
end function func1
end module example_mod
- C code is written in GNU style. Each new level in a program block is indented
by 2 spaces. Braces start on a new line, and are also indented by 2 spaces.
- See the Gnome C coding style guide
for more information