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


Ignore:
Timestamp:
Nov 12, 2018 4:56:05 PM (6 years ago)
Author:
kanani
Comment:

--

Legend:

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

    v12 v13  
    11= PALM coding rules =
    2 '''Why to follow some standards?'''\\\\
     2= (0) Why to follow some standards? =
    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\\\\
     
    1313* Use '''ASCII''' characters only
    1414* 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
     15* Line-length limit '''132 characters''' (absolute limit for most compilers)
     16* '''NO''' use of tab characters (only exception: Makefile), because depending on the text editor, the code indentations might be corrupted.
    1617
    1718|| '''AVOID''' || '''USE INSTEAD''' ||
     
    2526\\
    2627= (2) Documenting & commenting =
    27 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 [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 !>
     28{{{
     29#!div style="align:'left'; width: 450px; border: 0px solid; float:right"
     30[[Image(rules_header.png, 450px, right, margin-right=2, margin-top=0, border=0)]]\\
     31'''Fig. 4''' PALM source-code header example. Click to enlarge.
     32}}}
     33Documentation 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 [wiki:doc/tec/doxygen Doxygen], a tool for generating documentation and flow charts from annotated source code. This requires some special formatting, as described below.
     34
     35== (2.1) External documentation ==
     36You 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.\\\\
     37Your 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.
    3538
    3639== (2.2) Internal documentation ==
    37 (one variable per declaration statement!)\\\\
     40'''File header section'''
     41(see Fig. 4)
     42a. Doxygen command for FORTRAN file name ('''!>''' starts a doxygen command line)
     43b. PALM license section (you may have to add other licenses if allowedly implementing code from other models)
     44c. Revision comments (see [link-to svn branches and trunk committing])
     45d. Doxygen command for listing authors of the module
     46e. Module description (give a brief description of about the modules purpose)
     47f. Another set of doxygen commands for listing todos, notes and know bugs
     48
    3849'''Description of variables'''
    39 * Short description for each declared variable, comments should be aligned per declaration block\\
     50(one variable per declaration statement!)
     51* Short description for each declared variable, comments should be aligned per declaration block
     52* At minimum, 2 whitespace before '''!<'''
     53* '''!<''' character introduces doxygen comment
    4054{{{
    4155LOGICAL ::  conserve_water_content = .TRUE.  !< open or closed bottom surface for the soil model
     
    4559REAL(wp) ::  deep_soil_temperature = 9999999.9_wp  !< Deep soil temperature (K)
    4660}}}
    47 * If comment reaches over 120 characters (hard line limit), break comment into (max.) 2 lines
     61* If comment reaches over 132 characters (hard limit), break comment into (max.) 2 lines
    4862{{{
    4963LOGICAL ::  conserve_water_content = .TRUE.  !< open or closed bottom surface for the soil model
     
    5872!--
    5973}}}
    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
     74* Comment text always starts at same position as the indented code to be described, and break text into several lines if '''> 132 characters''' are reached
    6175{{{
    6276       DO  j = nys, nyn
     
    7892}}}
    7993
    80 == (2.3) External documentation ==
    81 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 [link-to-browser browse the PALM code] @ all its former and of course current revision in a web-based environment.\\\\
    82 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. 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.
     94
    8395
    8496
     
    107119'''PROHIBITED:'''
    108120* Names that may clash with the operating system or language intrinsic, e.g.\\
    109 {{{read( )}}} or {{{access( )}}}
     121  {{{read( )}}} or {{{access( )}}}
    110122* 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))
    111123
    112124\\
    113125= (4) Formatting & sorting =
    114 Line length limit: '''80''' characters (soft) | '''120''' characters (hard). The absolute limit for compilers is '''132''' characters!
     126Line length limit: '''132''' characters (hard limit)
    115127
    116128== (4.1) Indentation, spaces & line breaks ==
     
    132144* '''1 blank line''' between enclosed/unrelated blocks of instructions, assignments, clauses, statements, etc.
    133145* '''2 blank lines''' in front of each SUBROUTINE within a MODULE
    134 * place '''&''' character for line continuation at position 80 (minimum), max at position 120\\('''Note:''' FORTRAN-2003 defines a limit of 39 continuation lines)
    135146
    136147'''__Whitespaces between brackets'''
     
    169180* Alignment of related code, e.g. in complex equations or setting of initial values for variables '''(missing in png)'''
    170181
    171 \\\\
    172182== (4.3) Alphabetical sorting ==
    173183* Members in ONLY lists of USE statements (see e.g. Fig. 3)
     
    178188
    179189
    180 
    181 = (X) Coding =
    182 == (X.1) Variable & parameter declarations ==
     190\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
     191= (5) Coding =
     192== (5.1) Variable & parameter declarations ==
    183193* clear structure in declaration part (USE, IMPLICIT NONE, declarations, SAVE, PRIVATE, PUBLIC list_of_public_variables)
    184194* for long lists form groups
    185195* one declaration line per variable
    186196
    187 
    188 
    189 == Allowed operators ==
     197== (5.2) Allowed operators ==
    190198* Use /=, <, <=, ==, >, >=, etc. as relational operators instead of .GE., .LT., etc.
    191199* Use .AND., .OR., .NOT. as logical operators
    192200
    193 == Preprocessor directives ==
     201== (5.3) Preprocessor directives ==
    194202PALM works with the C Pre-Processor (CPP), available on any UNIX platform, and covered my most FORTRAN compilers.
    195203Only few pre-processor directives are used in PALM, and activated by the {{{%cpp_options}}} variable in the .palm.config.<configuration_identifier> file.
     
    205213together with the standard logical operators '''!''' (instead of .NOT.), '''||''' (instead of .OR.), '''&&''' (instead of .AND.), e.g.
    206214{{{#if ! defined(__parallel) && (__netcdf)}}}
    207  
    208 
    209 
    210 
    211 == File header ==
    212 * Files always start with a doxygen-readable comment line including the FORTRAN file name.
    213 * This is followed by the license section. If your code originates from another model, please clarify the license and permissions for this code to enter the PALM model system. It might be necessary in that case to add some more information to this header.
    214 * The revisions section will later include short notes of the changes applied to a specific svn revision of this file. The {{{$Id$}}} string is required so that svn knows to automatically generate the respective time stamp for a revision (see existing SOURCE files).\\
    215 --> [link-to How to initialize Id keyword in svn]
    216 * mention revision history and link to [How to commit]
    217 * Finally, involved authors are included, followed by a description of the purpose and functions of the module. If necessary, TODOs, notes and known bugs can be added. The "!>" indicate doxygen-readable comment lines, the "@" marks doxygen variables.
    218 
    219 == (X) Code structure ==
     215
     216== (5.4) Code structure ==
     217'''(move somewhere else)'''
    220218* one module per file (only exception: modules.f90)
    221219* clarify program entities, i.e. use {{{SUBROUTINE <name> ... END SUBROUTINE <name>}}}, same holds for INTERFACE, MODULE, PROGRAM
    222220
    223 -------------------------
    224 == Error messages ==
     221== (5.5) Error messages ==
    225222* Use message routine (explain parameters here...)
    226223* I/O error conditions via IOSTAT (is this fail-safe for different compilers?)
    227224
    228 == Code optimization ==
     225== (5.6) Code optimization ==
    229226???
    230227
    231 == (X) Final steps ==
     228== (6) Final steps ==
    232229'''Good practice'''
    233230* no warning/error message should remain during compile (also try debug options)
     
    236233* PRINT/WRITE statements for debugging
    237234* Check that all parameters are used
     235
     236
     237
     238-------------
     239* place '''&''' character for line continuation at position 80 (minimum), max at position 120\\('''Note:''' FORTRAN-2003 defines a limit of 39 continuation lines)