Coding style in Fortran code of Elmer

General discussion about Elmer
Post Reply
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Coding style in Fortran code of Elmer

Post by raback »

People have asked about the coding style instructions for Elmer. This is a short summary of coding style conventions followed in Elmer development. The choices have evolved with time and can be argued. Ultimately it is a matter of taste. We have tried to honor the current code base so that this does not give rise to major code modifications.

Coding conventions
- use uppercase for all Fortran constructs (DO, SUBROUTINE, MODULE, ...)
- use lowercase or CamelCase for variablenames
- use long descriptive variable names. Exceptions to this rule are indexes and other variables which have a very local scope.
- use 2 spaces for indentation (*)
- declare INTENT(IN), INTENT(OUT) or INTENT(INOUT) for subroutine arguments where applicable
- use empty lines to improve readability of code
- use doxygen comments (*) for modules and subroutines
- put (L)GPL license header with author info, updated authors for each module
- use Info level conventions (**)

Applying style
- Style will not be enforced for existing code
- New code should rather try to follow the conventions
- Independent modules can be more relaxed in adapting to the conventions
- Automatic emacs tool for performing code polishing to be provided: trailing white spaces, indentation


(*) doxygen example

Code: Select all

!-------------------------------------------------------------------------------
!> Explanation what the module does...
!> ...
!-------------------------------------------------------------------------------
MODULE ...

!-------------------------------------------------------------------------------
!> Explanation what the subroutine or function does...
!> ...
!> Following may optionally be added
!> \deprecated Remarks if this is obsolite !> \todo Remarks what could be done
!-------------------------------------------------------------------------------
SUBROUTINE ExampleRoutine( a, b )
!-------------------------------------------------------------------------------
IMPLICIT NONE
USE DefUtils
(**) Info levels of Elmer code,
CALL Info('SubroutineName',Message,Level=4)
3 = warning
4 = highest priority
5 = default priority
6 = lower priority
...
10 <= debug priority
32 largest known priority index
joeatodd
Posts: 36
Joined: 02 Feb 2012, 18:49
Antispam: Yes

Re: Coding style in Fortran code of Elmer

Post by joeatodd »

Small piece of info regarding emacs, the default indentation level is 3, and this can be changed with:

Code: Select all

(setq f90-do-indent 2)
(setq f90-if-indent 2)
(setq f90-structure-indent 2)
in the .emacs config file.

Also, the following will take care of syntax highlighting and should cause keywords to appear in uppercase:

Code: Select all

  (setq f90-font-lock-keywords f90-font-lock-keywords-3
	f90-auto-keyword-case 'upcase-word)
Post Reply