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