4. Coding Standards/Conventions

Banned functions and syntax

  • line numbers
    they are a relict of the deprecated goto statement and not needed

  • call flush
    use flush(6) instead of call flush(6)
    the subroutine is a vendor extension and Intel Fortran might crash when using call flush() (i.e. without file unit specified), while using flush() is recognized as a syntax error

  • print*,
    use write(6,*) instead of print*,

  • stop
    use the quit() subroutine provided by DAMASK

  • return
    is not needed immediately before end of subroutine/function

  • .lt., .le., .eq., .ne., .gt., and .ge.
    use the more readable comparison symbols <, <=, ==, !=, >, and >=

  • (/ and /)
    use the more readable [ and ]


Data declaration


  • always state implicit none before data declaration
  • use the following order when assigning attributes:
    1. type / kind
    2. dimension
    3. allocatable / pointer / target / parameter
    4. private / public (protected) intent(in/out/inout)
    5. optional


  • always state private after implicit none
  • order of data declaration
    1. constants/variables
      1. public
        1. parameter
        2. protected
      2. private
    2. functions/subroutines
      1. public
      2. private


  • functions have no intent(out) or intent(inout) dummy variables
  • when possible, add the pure statement directly before the declaration
  • return value specification:
    • scalar: use real(pReal) or integer(pInt) before the function declaration
    • array: use the first possible variable (after implicit none and possibly information needed for dimension)
  • order of data declaration
    1. intent(in)
    2. parameter
    3. local variables


  • when possible, add the pure statement directly before the declaration
  • order of data declaration
    1. intent(out)
    2. intent(inout)
    3. intent(in)
    4. parameter
    5. local variables


Naming Scheme

  • global, read-only variables (public, protected) are prefixed by the name of the module
  • parameters are written in CAPITALS
  • global, read-write variables are prefixed only if necessary
  • suffix with shape, but without underscore: C66 instead of C_66
  • i for integration point number
  • e for element number
  • g for grain number
  • h for homogenization instance
  • m for microstructure instance
  • c for constituent instance
  • o for output
  • f for slip/twin family
  • ip for integration point number
  • ipc component-ID of current integration point
  • el for element number
  • gr for grain number
  • is ipc and gr the same?
  • state
  • Tstar_v


Indentation and line format

  • no indentation for modules/programs and functions/subroutines
  • 2 spaces for each further level
  • line ends after 100 characters, hard limit by compiler is 132
  • OMP directions have no effect on indentation



  • use doxygen tags to describe functions, variables and parameters
  • structure longer functions



  • use named control structures (do, if, where, forall, select case)
    DONE                                             ALERT! 
    subIncLooping: do i=1_pInt, 1000_pInt          do i=1_pInt, 1000_pInt
      a=time(i)                                      a=time(i)
    enddo subIncLooping                            enddo

  • use spread when initializing fields instead of explicit loops
    real(pReal), dimension(3,3,10) :: a
    DONE                                             ALERT! 
    a=spread(math_I3,3,10)                         a=0.0_pReal 
                                                   do i=1_pInt, 10_pInt
  • use sum when calculating average fields instead of explicit loops
    real(pReal), dimension(3,3,10) :: a
    real(pReal), dimension(3,3)    :: b
    DONE                                             ALERT! 
    b=sum(a,3)                                     b=0.0_pReal 
                                                   do i=1_pInt, 10_pInt
                                                     b=b + a(1:3,1:3,i)
  • use product when calculating products of array
    integer(pInt), dimension(3) :: res
    integer(pInt),              :: N
    DONE                                             ALERT! 
    N=product(res)                                 N=res(1)*res(2)*res(3)
  • use no assumed size/shape, use explicit ranges
    integer(pInt), dimension(3,3,5,5) :: field
    integer(pInt), dimension(3,3)     :: tensor
    DONE                                             ALERT! 
    field(1:3,1:3,1,1)=tensor                      field(:,:,1,1)=tensor
  • avoid public data, try to use accessor functions


Use statements

  • use the only statement and explicitly include functions of the module
    integer(pInt) function a(b)
    DONE                                             ALERT! 
    use IO, only: &                                    use IO
      IO_error, &



Topic revision: r29 - 21 Aug 2015, FranzRoters

  • News
14 Sep 2020
CMCn2020 & DAMASK user meeting to be hosted at Max-Planck-Institut für Eisenforschung (cancelled)
22 Aug 2020
Release of first preview version of DAMASK 3
19 Feb 2020
DAMASK made it to the Advanved Engineering Materials Hall of Fame
26 Mar 2019
DREAM.3D 6.5.119
(released 2019/03/22) comes with a DAMASK export filter
25 Mar 2019
Release of version v2.0.3
21 Jan 2019
DAMASK overview paper finally published with full citation information available
01 Dec 2018
DAMASK overview paper now online
17 Sep 2018
CMCn2018 & DAMASK user meeting to be hosted at Max-Planck-Institut für Eisenforschung
22 May 2018
Release of version v2.0.2
01 Sep 2016
CMCn2016 & DAMASK user meeting to be hosted at Max-Planck-Institut für Eisenforschung
25 Jul 2016
Release of version v2.0.1
08 Mar 2016
Release of version v2.0.0
22 Feb 2016
New webserver up and running
09 Feb 2016
Migrated code repository from Subversion to GitLab
17 Dec 2014
Release of revision 3813
14 May 2014
Release of revision 3108
02 Apr 2014
Release of revision 3062
16 Oct 2013
Release of revision 2689
15 Jul 2013
Release of revision 2555
15 Feb 2013
Release of revision 2174
13 Feb 2013
Doxygen documentation
16 Dec 2012
Powered by MathJax rendering
23 Nov 2012
Release of revision 1955
15 Nov 2012
Release of revision 1924
01 Nov 2012
Updated sidebar
30 Oct 2012
Significant website updates and content extensions

This site is powered by FoswikiCopyright by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding DAMASK? Send feedback
§ Imprint § Data Protection