Neko 0.9.99
A portable framework for high-order spectral element flow simulations
|
Fortran code should conform to the Fortran 2008 standard and should use an indentation level of 2, except for the extra indentation within do
if
, select
or where
statements and for each level inside a structure e.g. type
, interface
, where the indentation level is 3, continuation statements, which should be indented by 5 and a 0 indentation is used for module
or contains
(except for contains
inside a derived type, where a single indentation level is used). It should be noted that no indentation should be applied to the case
statements contained in a select case
block.
These are the default rules in Emacs' Fortran mode, an example is given below, additional information on the Emacs' Fortran mode can be found at https://emacsdocs.org and the full formatting script for emacs can be found at the Emacs' GitHub.
For portability reasons, it is essential to only use data type kinds defined in num_types.f90 and avoid legacy constructs like real*8
or integer(kind=8)
Floating-point numbers should be declared using real
with the kind rp
, which is the configured working precision for Neko (defaults to double). If single, double or quad precision is explicitly needed, use the kinds sp
, dp
or qp
, respectively. For 16, 32, or 64-bit integers, Neko has defined the kinds i2
, i4
or i8
, respectively; however, for standard integers, it is perfectly fine to use a plain integer
.
Submitting a pull request to Neko requires that the code adheres to the linting rules and to the formatting. The linting will require that the code does not reduce the linting score of the repository, while the formatting should be completed for any modified files.
In addition to the indentation specified above, the following rules are enforced:
do i = 1, 10
.a .eq. b
.::
must have a spaces around it when declaring variables.foo(b, c)
.if (a .eq. b)
.!$
.type(kind)
instead of type*8
.!
must have a space before and after them ! This is a comment
.end if
.end if
.a = b
.sp
, dp
or qp
.use mpi_f08
instead (or use mpi
if not available).exit
statement is not allowed.goto
statement is not allowed.pause
statement is not allowed.include
statement is not allowed.However, there are some exceptions to these rules:
::
may not have spaces around it in the case of a type declaration.foo(a,b)
and foo(a,10)
are allowed, but foo(a,bb)
and foo(a,100)
are not.=
operator are not required in type declarations.In order to simplify compliance to the formatting and linting rules the following tools can be used:
We have scripts available under the contrib/lint_format
directory that can be used to lint and format the code. The scripts are lint.sh
and format.sh
respectively.
The linting rules are enforced by the flint tool. The rules are defined in the flinter_rc.yml
file in the root of the repository.
Please note, newer versions of flint fails to execute for some of our large files (htable.f90 and stack.f90).
One way to install flint is through pip:
To test your code against the linting rules, you can run the following command:
The whole src directory can be checked with:
This tool can be used to enforce these rules by assigning the following options. The documentation of findent
provide details for emacs, vim and gedit. For VSCode, the Modern Fortran extension provides an integration.