-
Notifications
You must be signed in to change notification settings - Fork 27
WIP: Code style conventions
There are resources available online on best practices when writing modern Fortran code:
- http://fortranwiki.org/fortran/show/Source+conventions
- http://www.fortran90.org/src/best-practices.html
Grasp2k-specific conventions:
-
New code should be written in the Fortran 90 free-form style. Code should may use Fortran 2003 features (i.e. it is expected that compilers will support Fortran 2003).
-
Variable names, Fortran statements etc. should be written in lowercase. Preprocessor directives should be uppercase.
-
Underscores should be used to make long names readable (e.g.
long_variable_name
) -
Lines should wrapped around the 80-character mark. 92 characters should be considered a hard limit, although exceptions are OK if it improves readability.
-
There should be no extra whitespace at the ends of lines, nor should there be extra empty lines at the ends of files.
-
Indentation should be done with four spaces.
-
Fortran 77 code must use the
.f
extension, modern code should use the.f90
extension.Proposal: to make it more clear that the f77 code is legacy, we could switch to
.f
for modern free-form code and use.f77
for the old code. -
In order to have a common namespace, Grasp2k-specific modules should be prefixed with
g2k_
(e.g.g2k_quad
). -
Kinds should be used for floating point variables. For 64-bit floats, the
real64
anddp
parameters should be defined once and then used (i.e.real(real64) :: ...
for declarations,2.341_dp
for floating point literals). They can (should) be defined via theiso_fortran_env
intrinsic as follows:use, intrinsic :: iso_fortran_env, only: real64 integer, parameter :: dp = real64