Changes between Version 11 and Version 12 of doc/tec/developerrules/palmstandard


Ignore:
Timestamp:
Nov 8, 2018 6:15:20 PM (6 years ago)
Author:
kanani
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • doc/tec/developerrules/palmstandard

    v11 v12  
    33Because everyone has her/his own programming style, sort of a dialect, making it difficult for other developers to understand, extend, debug, or optimize the code. So what do we do? We learn and apply the coding standard to make PALM more easily readable for all current and future developers. Let's all work on that together. We are aware that the PALM core doesn't completely comply with the following rules yet, but we are working on that.
    44\\\\
    5 Formulated rules and specifications are based on the specifications given for the ocean dynamics model [add-new-link-to NEMO].
     5Formulated rules are based on the specifications given for the ocean dynamics model [add-new-link-to NEMO].
    66Other work that influenced the development of this standard are [add-link Community Climate System Model], [add-link Software Developer's Guide], [add-link Report on Column Physics Standards], and [add-link European Standards For Writing and Documenting Exchangeable FORTRAN 90 Code].
    77
     
    99= (1) General hints & requirements =
    1010== (1.1) Language ==
    11 * FORTRAN-2003 standard (all FORTRAN compilers can handle this, FORTRAN-2008 standard not yet supported by all compilers)
    12 * Use English language only
    13 * Use ASCII characters only
    14 * Use SI units as physical units
    15 * '''NO''' use of tab characters\\(only exception: Makefile)
     11* '''FORTRAN-2003''' standard (all FORTRAN compilers can handle this, FORTRAN-2008 standard not yet supported by all compilers)
     12* Use '''English''' language only
     13* Use '''ASCII''' characters only
     14* Use '''SI units''' as physical units
     15* '''NO''' use of tab characters (only exception: Makefile), because depending on the text editor, the code indentations might be ruined
    1616
    1717|| '''AVOID''' || '''USE INSTEAD''' ||
     
    1919
    2020== (1.2) Implementing new features to PALM ==
    21 * module structure (template)
     21(will follow)
     22* module structure (attach a template or link to template in repo)
    2223* available interfaces in the PALM core
    2324
    2425\\
    2526= (2) Documenting & commenting =
     27Documentation consists of putting information both internally and externally of the source code. Comments should give a good idea of what the code does and where to look for any special activity. PALM supports the use of [link-to Doxygen], a tool for generating documentation and flow charts from annotated source code. This requires some special formatting, as described below.
     28
     29== (2.1) File header section ==
     30* todos, notes, author,....
     31* Declaration !< Description
     32* see file header
     33* @author etc.
     34* MODULE/SUBROUTINE description !>
     35
     36== (2.2) Internal documentation ==
     37(one variable per declaration statement!)\\\\
     38'''Description of variables'''
     39* Short description for each declared variable, comments should be aligned per declaration block\\
     40{{{
     41LOGICAL ::  conserve_water_content = .TRUE.  !< open or closed bottom surface for the soil model
     42LOGICAL ::  constant_roughness = .FALSE.     !< use fixed/dynamic roughness lengths for water surfaces
     43
     44REAL(wp) ::  c_surface = 20000.0_wp                !< Surface (skin) heat capacity (J m-2 K-1)
     45REAL(wp) ::  deep_soil_temperature = 9999999.9_wp  !< Deep soil temperature (K)
     46}}}
     47* If comment reaches over 120 characters (hard line limit), break comment into (max.) 2 lines
     48{{{
     49LOGICAL ::  conserve_water_content = .TRUE.  !< open or closed bottom surface for the soil model
     50                                             !< in the land-surface model
     51}}}
     52
     53'''Commenting of code blocks'''\\
     54* Carefully comment each block of code
     55* Comments '''always''' start with
     56{{{
     57!
     58!--
     59}}}
     60* Comment text always starts at same position as indented code to be described, and break text into several lines if '''> 80 characters''' are reached
     61{{{
     62       DO  j = nys, nyn
     63!
     64!--       Tendency terms for u-velocity component. Please note, in case of
     65!--       non-cyclic boundary conditions the grid point i=0 is excluded from
     66!--       the prognostic equations for the u-component.   
     67          IF ( i >= nxlu )  THEN
     68
     69             tend(:,j,i) = 0.0_wp
     70             IF ( timestep_scheme(1:5) == 'runge' )  THEN
     71}}}
     72* Avoid superfluous comments like
     73{{{
     74!
     75!-- Loop over all grid indices
     76    DO  i = nxl, nxr
     77       DO  j = nys, nyn
     78}}}
     79
     80== (2.3) External documentation ==
     81You are in the middle of it. We have an extensive online documentation wiki embedded into a [link-to trac] project management system, directly connected to the svn repository, allowing to [link-to-browser browse the PALM code] @ all its former and of course current revision in a web-based environment.\\\\
     82Your carefully developed code can only be used, if there is a documentation that tells the PALM user how to use and steer the feature. All pages can be accessed from the main [link-to Documentation] page (see index on the left). There are pages for [wiki:doc#Modeldescription model/code description], and [wiki:doc#Usermanual user-manual] pages that explain about model steering, data analysis and debugging. Have a look at and discuss with us where your documentation material fits in best.
     83
    2684
    2785\\
     
    3391  * DO, ENDDO, IF, ELSE, etc.
    3492  * READ, WRITE, CALL, etc.
    35   * MPI_ALLTOALL (MPI functions), NF90_CREATE (NetCDF functions), etc.\\
     93  * MPI_ALLTOALL (MPI functions), NF90_CREATE (NetCDF functions), etc.\\\\
    3694* '''Lower case:''' Everything else!
     95
     96== (3.2) Names for routines and variables ==
     97Use clear, unambiguous naming in '''lower-case letters''', with  individual words separated by underscore.
     98* MODULE/SUBROUTINE: name is constructed (if applicable) as verb followed by object, e.g.\\
     99  {{{land_surface_model}}} or {{{read_restart_data}}}
     100* MODULE/SUBROUTINE files: <filename>.f90 --> MODULE <filename> ... END MODULE <filename> (simplification of Make process)
     101* Functions: names provide information about the value it is expected to return, e.g.\\
     102  {{{solar_zenith_angle( )}}}
     103* Variables & constants: names are readable, memorable and descriptive
     104* LOGICAL (boolean) variables: give names that imply\\
     105  {{{TRUE}}} or {{{FALSE}}}
     106
     107'''PROHIBITED:'''
     108* Names that may clash with the operating system or language intrinsic, e.g.\\
     109{{{read( )}}} or {{{access( )}}}
     110* One-letter variable names (only allowed for basic flow variables like velocities (u, v, w), humidity (q) or turbulent kinetic energy (e), as well as loop or other counters (e.g. i, j, k))
    37111
    38112\\
     
    95169* Alignment of related code, e.g. in complex equations or setting of initial values for variables '''(missing in png)'''
    96170
    97 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
     171\\\\
    98172== (4.3) Alphabetical sorting ==
    99173* Members in ONLY lists of USE statements (see e.g. Fig. 3)
     
    104178
    105179
    106 == Commenting & documentation ==
    107 Documentation consists of putting information both internally and externally of the source code. Comments should give a good idea of what the code does and where to look for any special activity. PALM supports the use of Doxygen, a tool for generating documentation and flow charts from annotated source code. This requires some special formatting, as described below.
    108 
    109 '''File header section'''
    110 * todos, notes, author,....
    111 * Declaration !< Description
    112 * see file header
    113 * @author etc.
    114 * MODULE/SUBROUTINE description !>
    115 
    116 '''Inside the code'''
    117 * Examples.png..
    118 * Avoid superfluous comments, such as\\ {{{a = a + 1 ! Increment a by one}}}
    119 * Example for multiple-line declaration comment
    120 !
    121 !-- Text starts at same position as indented code to be described
    122 
    123 '''Outside the code'''
    124 You are in the middle of it. We have an extensive online documentation wiki embedded into a [link-to trac] project management system, directly connected to the svn repository, allowing to [browse the PALM code] @ all its former and of course current revision in a web-based environment.
    125 Your carefully developed code can only be used, if there is a documentation that tells the PALM user how to use and steer the feature.
    126180
    127181= (X) Coding =
     
    131185* one declaration line per variable
    132186
    133 == Naming conventions ==
    134 Use clear, unambiguous naming in '''lower-case letters''', with  individual words separated by underscore.
    135 * MODULE/SUBROUTINE: name is constructed (if applicable) as verb followed by object, e.g.\\
    136   {{{land_surface_model}}} or {{{read_restart_data}}}
    137 * MODULE/SUBROUTINE files: <filename>.f90 --> MODULE <filename> ... END MODULE <filename> (simplification of Make process)
    138 * Functions: names provide information about the value it is expected to return, e.g.\\
    139   {{{solar_zenith_angle( )}}}
    140 * Variables & constants: names are readable, memorable and descriptive
    141 * LOGICAL (boolean) variables: give names that imply\\
    142   {{{TRUE}}} or {{{FALSE}}}
    143 
    144 '''PROHIBITED:'''
    145 * Names that may clash with the operating system or language intrinsics, e.g.\\
    146 {{{read( )}}} or {{{access( )}}}
    147 * One-letter variable names (only allowed for basic flow variables like velocities (u, v, w), humidity (q) or turbulent kinetic energy (e), as well as loop or other counters (e.g. i, j, k))
     187
    148188
    149189== Allowed operators ==