[707] | 1 | % ================================================================ |
---|
[817] | 2 | % Appendix D Ñ Coding Rules |
---|
[707] | 3 | % ================================================================ |
---|
[817] | 4 | \chapter{Coding Rules} |
---|
[707] | 5 | \label{Apdx_D} |
---|
| 6 | \minitoc |
---|
| 7 | |
---|
[2282] | 8 | \newpage |
---|
| 9 | $\ $\newline % force a new ligne |
---|
| 10 | $\ $\newline % force a new ligne |
---|
[707] | 11 | |
---|
[2282] | 12 | |
---|
[1223] | 13 | A "model life" is more than ten years. Its software, composed of a few |
---|
| 14 | hundred modules, is used by many people who are scientists or students |
---|
| 15 | and do not necessarily know every aspect of computing very well. |
---|
| 16 | Moreover, a well thought-out program is easier to read and understand, |
---|
| 17 | less difficult to modify, produces fewer bugs and is easier to maintain. |
---|
| 18 | Therefore, it is essential that the model development follows some rules : |
---|
[707] | 19 | |
---|
| 20 | - well planned and designed |
---|
| 21 | |
---|
| 22 | - well written |
---|
| 23 | |
---|
| 24 | - well documented (both on- and off-line) |
---|
| 25 | |
---|
| 26 | - maintainable |
---|
| 27 | |
---|
| 28 | - easily portable |
---|
| 29 | |
---|
| 30 | - flexible. |
---|
| 31 | |
---|
[817] | 32 | To satisfy part of these aims, \NEMO is written with a coding standard which |
---|
[1223] | 33 | is close to the ECMWF rules, named DOCTOR \citep{Gibson_TR86}. |
---|
| 34 | These rules present some advantages like : |
---|
[707] | 35 | |
---|
| 36 | - to provide a well presented program |
---|
| 37 | |
---|
| 38 | - to use rules for variable names which allow recognition of their type |
---|
[2282] | 39 | (integer, real, parameter, local or shared variables, etc. ). |
---|
[707] | 40 | |
---|
[2282] | 41 | This facilitates both the understanding and the debugging of an algorithm. |
---|
| 42 | |
---|
[817] | 43 | % ================================================================ |
---|
| 44 | % The program structure |
---|
| 45 | % ================================================================ |
---|
| 46 | \section{The program structure} |
---|
| 47 | \label{Apdx_D_structure} |
---|
[707] | 48 | |
---|
| 49 | Each program begins with a set of headline comments containing : |
---|
| 50 | |
---|
| 51 | - the program title |
---|
| 52 | |
---|
| 53 | - the purpose of the routine |
---|
| 54 | |
---|
| 55 | - the method and algorithms used |
---|
| 56 | |
---|
| 57 | - the detail of input and output interfaces |
---|
| 58 | |
---|
[1223] | 59 | - the external routines and functions used (if they exist) |
---|
[707] | 60 | |
---|
[1223] | 61 | - references (if they exist) |
---|
[707] | 62 | |
---|
[1223] | 63 | - the author name(s), the date of creation and any updates. |
---|
[707] | 64 | |
---|
[1223] | 65 | - Each program is split into several well separated sections and |
---|
| 66 | sub-sections with an underlined title and specific labelled statements. |
---|
[707] | 67 | |
---|
| 68 | - A program has not more than 200 to 300 lines. |
---|
| 69 | |
---|
[2282] | 70 | A template of a module style can be found on the NEMO depository |
---|
| 71 | in the following file : NEMO/OPA\_SRC/module\_example. |
---|
[817] | 72 | % ================================================================ |
---|
| 73 | % Coding conventions |
---|
| 74 | % ================================================================ |
---|
| 75 | \section{Coding conventions} |
---|
| 76 | \label{Apdx_D_coding} |
---|
[707] | 77 | |
---|
[1223] | 78 | - Use of the universal language \textsc{Fortran} 90, and try to avoid obsolescent |
---|
| 79 | features like statement functions, do not use GO TO and EQUIVALENCE statements. |
---|
[707] | 80 | |
---|
[2282] | 81 | - A continuation line begins with the character {\&} indented by three spaces |
---|
| 82 | compared to the previous line, while the previous line ended with the character {\&}. |
---|
[707] | 83 | |
---|
[2282] | 84 | - All the variables must be declared. The code is usually compiled with implicit none. |
---|
| 85 | |
---|
| 86 | - Never use continuation lines in the declaration of a variable. When searching a |
---|
| 87 | variable in the code through a \textit{grep} command, the declaration line will be found. |
---|
| 88 | |
---|
| 89 | - In the declaration of a PUBLIC variable, the comment part at the end of the line |
---|
[2541] | 90 | should start with the two characters "\verb?!:?". the following UNIX command, \\ |
---|
| 91 | \verb?grep var_name *90 \ grep \!: ? \\ |
---|
[2282] | 92 | will display the module name and the line where the var\_name declaration is. |
---|
| 93 | |
---|
[1223] | 94 | - Always use a three spaces indentation in DO loop, CASE, or IF-ELSEIF-ELSE-ENDIF |
---|
| 95 | statements. |
---|
[707] | 96 | |
---|
[2282] | 97 | - use a space after a comma, except when it appears to separate the indices of an array. |
---|
| 98 | |
---|
[1223] | 99 | - use call to ctl\_stop routine instead of just a STOP. |
---|
[707] | 100 | |
---|
[2282] | 101 | |
---|
| 102 | \newpage |
---|
[817] | 103 | % ================================================================ |
---|
| 104 | % Naming Conventions |
---|
| 105 | % ================================================================ |
---|
| 106 | \section{Naming Conventions} |
---|
| 107 | \label{Apdx_D_naming} |
---|
[707] | 108 | |
---|
| 109 | The purpose of the naming conventions is to use prefix letters to classify |
---|
[2282] | 110 | model variables. These conventions allow the variable type to be easily |
---|
| 111 | known and rapidly identified. The naming conventions are summarised |
---|
| 112 | in the Table below: |
---|
[707] | 113 | |
---|
[2282] | 114 | |
---|
[707] | 115 | %--------------------------------------------------TABLE-------------------------------------------------- |
---|
[2282] | 116 | \begin{table}[htbp] \label{Tab_VarName} |
---|
[707] | 117 | \begin{center} |
---|
[2282] | 118 | \begin{tabular}{|p{45pt}|p{35pt}|p{45pt}|p{40pt}|p{40pt}|p{40pt}|p{40pt}|p{40pt}|} |
---|
| 119 | \hline Type \par / Status & integer& real& logical & character & structure & double \par precision& complex \\ |
---|
[707] | 120 | \hline |
---|
[1223] | 121 | public \par or \par module variable& |
---|
[2282] | 122 | \textbf{m n} \par \textit{but not} \par \textbf{nn\_}& |
---|
| 123 | \textbf{a b e f g h o q r} \par \textbf{t} \textit{to} \textbf{x} \par but not \par \textbf{fs rn\_}& |
---|
| 124 | \textbf{l} \par \textit{but not} \par \textbf{lp ld} \par \textbf{ ll ln\_}& |
---|
| 125 | \textbf{c} \par \textit{but not} \par \textbf{cp cd} \par \textbf{cl cn\_}& |
---|
| 126 | \textbf{s} \par \textit{but not} \par \textbf{sd sd} \par \textbf{sl sn\_}& |
---|
| 127 | \textbf{d} \par \textit{but not} \par \textbf{dp dd} \par \textbf{dl dn\_}& |
---|
| 128 | \textbf{y} \par \textit{but not} \par \textbf{yp yd} \par \textbf{yl yn} \\ |
---|
[707] | 129 | \hline |
---|
| 130 | dummy \par argument& |
---|
| 131 | \textbf{k} \par \textit{but not} \par \textbf{kf}& |
---|
[2282] | 132 | \textbf{p} \par \textit{but not} \par \textbf{pp pf}& |
---|
[707] | 133 | \textbf{ld}& |
---|
| 134 | \textbf{cd}& |
---|
[2282] | 135 | \textbf{sd}& |
---|
[707] | 136 | \textbf{dd}& |
---|
| 137 | \textbf{yd} \\ |
---|
| 138 | \hline |
---|
| 139 | local \par variable& |
---|
| 140 | \textbf{i}& |
---|
| 141 | \textbf{z}& |
---|
| 142 | \textbf{ll}& |
---|
| 143 | \textbf{cl}& |
---|
[2282] | 144 | \textbf{sl}& |
---|
| 145 | \textbf{dl}& |
---|
[707] | 146 | \textbf{yl} \\ |
---|
| 147 | \hline |
---|
| 148 | loop \par control& |
---|
[2282] | 149 | \textbf{j} \par \textit{but not} \par \textbf{jp}& |
---|
[707] | 150 | & |
---|
| 151 | & |
---|
[2282] | 152 | & |
---|
[707] | 153 | & |
---|
| 154 | & |
---|
| 155 | \\ |
---|
| 156 | \hline |
---|
| 157 | parameter& |
---|
| 158 | \textbf{jp}& |
---|
| 159 | \textbf{pp}& |
---|
| 160 | \textbf{lp}& |
---|
| 161 | \textbf{cp}& |
---|
[2282] | 162 | \textbf{sp}& |
---|
[707] | 163 | \textbf{dp}& |
---|
| 164 | \textbf{yp} \\ |
---|
| 165 | \hline |
---|
[1223] | 166 | |
---|
| 167 | namelist& |
---|
| 168 | \textbf{nn\_}& |
---|
| 169 | \textbf{rn\_}& |
---|
| 170 | \textbf{ln\_}& |
---|
| 171 | \textbf{cn\_}& |
---|
[2282] | 172 | \textbf{sn\_}& |
---|
[1223] | 173 | \textbf{dn\_}& |
---|
[2282] | 174 | \textbf{yn\_} |
---|
[1223] | 175 | \\ |
---|
| 176 | \hline |
---|
| 177 | CPP \par macro& |
---|
[707] | 178 | \textbf{kf}& |
---|
[2282] | 179 | \textbf{fs} \par & |
---|
[707] | 180 | & |
---|
[2282] | 181 | & |
---|
[707] | 182 | & |
---|
| 183 | & |
---|
| 184 | \\ |
---|
| 185 | \hline |
---|
| 186 | \end{tabular} |
---|
| 187 | \label{tab1} |
---|
| 188 | \end{center} |
---|
| 189 | \end{table} |
---|
| 190 | %-------------------------------------------------------------------------------------------------------------- |
---|
[2349] | 191 | |
---|
| 192 | \newpage |
---|
| 193 | % ================================================================ |
---|
| 194 | % The program structure |
---|
| 195 | % ================================================================ |
---|
| 196 | \section{The program structure} |
---|
| 197 | \label{Apdx_D_structure} |
---|
[2414] | 198 | |
---|
| 199 | To be done.... |
---|