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