1 | % ================================================================ |
---|
2 | % Appendix D Ñ Coding Rules |
---|
3 | % ================================================================ |
---|
4 | \chapter{Coding Rules} |
---|
5 | \label{Apdx_D} |
---|
6 | \minitoc |
---|
7 | |
---|
8 | |
---|
9 | A "model life" is more than ten years. Its software, composed by a few |
---|
10 | hundred modules, is used by many people who are scientists or students and |
---|
11 | do not necessary know very well all computer aspects. Moreover, a well |
---|
12 | thought-out programme is easy to read and understand, less difficult to |
---|
13 | modify, produces fewer bugs and is easier to maintain. Therefore, it is |
---|
14 | essential that the model development follows some rules : |
---|
15 | |
---|
16 | - well planned and designed |
---|
17 | |
---|
18 | - well written |
---|
19 | |
---|
20 | - well documented (both on- and off-line) |
---|
21 | |
---|
22 | - maintainable |
---|
23 | |
---|
24 | - easily portable |
---|
25 | |
---|
26 | - flexible. |
---|
27 | |
---|
28 | To satisfy part of these aims, \NEMO is written with a coding standard which |
---|
29 | is close to the ECMWF rules, named DOCTOR \citep{Gibson_TR86}. These rules present some advantages like : |
---|
30 | |
---|
31 | - to provide a well presented program |
---|
32 | |
---|
33 | - to use rules for variable names which allow recognition of their type |
---|
34 | (integer, real, parameter, local or shared variables, etc. ) so that debugging is |
---|
35 | facilitated. |
---|
36 | |
---|
37 | % ================================================================ |
---|
38 | % The program structure |
---|
39 | % ================================================================ |
---|
40 | \section{The program structure} |
---|
41 | \label{Apdx_D_structure} |
---|
42 | |
---|
43 | Each program begins with a set of headline comments containing : |
---|
44 | |
---|
45 | - the program title |
---|
46 | |
---|
47 | - the purpose of the routine |
---|
48 | |
---|
49 | - the method and algorithms used |
---|
50 | |
---|
51 | - the detail of input and output interfaces |
---|
52 | |
---|
53 | - the external routines and functions used (if exist) |
---|
54 | |
---|
55 | - references (if exist) |
---|
56 | |
---|
57 | - the author name (s), the date of creation and of updates. |
---|
58 | |
---|
59 | - Each program is splitted into several well separated sections and |
---|
60 | sub-sections with a underlined title and specific labelled statements. |
---|
61 | |
---|
62 | - A program has not more than 200 to 300 lines. |
---|
63 | |
---|
64 | % ================================================================ |
---|
65 | % Coding conventions |
---|
66 | % ================================================================ |
---|
67 | \section{Coding conventions} |
---|
68 | \label{Apdx_D_coding} |
---|
69 | |
---|
70 | - Use of the universal language \textsc{Fortran} 5 ANSI 77, with non |
---|
71 | standard extensions, NAMELIST and \textsc{Fortran} 90 (matrix resolution |
---|
72 | algorithm), and some well-identified particular statements or functions for |
---|
73 | weak and massive parallelism, and vectorization |
---|
74 | |
---|
75 | - A comment line begins with a uppercase character C at the first column. A |
---|
76 | space line must have a C. For the on-line documentation, comments are |
---|
77 | classified into three levels : |
---|
78 | |
---|
79 | Overview, triggered by CCC in columns 1 to 3. Only the title and the purpose |
---|
80 | of the program are identified like that. This overview documentation can be |
---|
81 | extracted by the UNIX function : grep -e '\^{}CCC' * |
---|
82 | |
---|
83 | External, triggered by CC in columns 1 to 2, and which correspond to |
---|
84 | headlines of each programme, extracted by : grep -e '\^{}CC' * |
---|
85 | |
---|
86 | Internal which are all the comments, extracted by : grep -e '\^{}C' * |
---|
87 | |
---|
88 | - Statements GO TO, EQUIVALENCE are forbidden. |
---|
89 | |
---|
90 | - A section is numbered with labels which are in agreement with the |
---|
91 | paragraph label and increase from the begin to the end of routine. Labels of |
---|
92 | a hundred ( 200, 201.. 220..) are reserved to a unique section. The |
---|
93 | \textsc{Fortran} 90 extension syntax DO/ENDDO is used except for multitasked |
---|
94 | do-loop. In this case labels 1000, 2000, ... are used. The FORMAT statement |
---|
95 | are labelled with numbers in the range 9000 to 9999. |
---|
96 | |
---|
97 | - A continuation line begins with the character {\$} in column 6. |
---|
98 | |
---|
99 | - All statements begin in column 7 with the following gaps : |
---|
100 | |
---|
101 | 2 spaces toward the right in a DO loop. |
---|
102 | |
---|
103 | 4 spaces toward the right in IF, ELSEIF, ELSE and ENDIF statements, with |
---|
104 | only 2 spaces for ELSE and ELSEIF lines. All IF statement must be followed |
---|
105 | by a ELSE statement. |
---|
106 | |
---|
107 | Some spaces in the continuation line for alignment. |
---|
108 | |
---|
109 | - Use of different labels for each DO loop statement. |
---|
110 | |
---|
111 | - STOP must be well documented with the name of the subroutine or a number. |
---|
112 | |
---|
113 | % ================================================================ |
---|
114 | % Naming Conventions |
---|
115 | % ================================================================ |
---|
116 | \section{Naming Conventions} |
---|
117 | \label{Apdx_D_naming} |
---|
118 | |
---|
119 | The purpose of the naming conventions is to use prefix letters to classify |
---|
120 | model variables. These conventions allow to know easily the variable type |
---|
121 | and to identify them rapidly: |
---|
122 | |
---|
123 | |
---|
124 | %--------------------------------------------------TABLE-------------------------------------------------- |
---|
125 | \begin{table}[htbp] |
---|
126 | \begin{center} |
---|
127 | \begin{tabular}{|p{50pt}|p{50pt}|p{50pt}|p{50pt}|p{50pt}|p{50pt}|p{50pt}|} |
---|
128 | \hline Type \par / Status & integer& real& logical & character& double \par precision& complex \\ |
---|
129 | \hline |
---|
130 | public & |
---|
131 | \textbf{m n} \par \textit{but not } \par \textbf{nam}& |
---|
132 | \textbf{a b e f g h o} \textbf{q} \textit{to} \textbf{x} \par but not \par \textbf{sf}& |
---|
133 | \textbf{l} \par \textit{but not} \par \textbf{lp ld ll}& |
---|
134 | \textbf{c} \par \textit{but not} \par \textbf{cp cd cl } \par \textbf{com cim}& |
---|
135 | \textbf{d} \par \textit{but not} \par \textbf{dp dd dl}& |
---|
136 | \textbf{y} \par \textit{but not} \par \textbf{yp yd yl} \\ |
---|
137 | \hline |
---|
138 | dummy \par argument& |
---|
139 | \textbf{k} \par \textit{but not} \par \textbf{kf}& |
---|
140 | \textbf{p} \par \textit{but not} \par \textbf{pp pf}& |
---|
141 | \textbf{ld}& |
---|
142 | \textbf{cd}& |
---|
143 | \textbf{dd}& |
---|
144 | \textbf{yd} \\ |
---|
145 | \hline |
---|
146 | local \par variable& |
---|
147 | \textbf{i}& |
---|
148 | \textbf{z}& |
---|
149 | \textbf{ll}& |
---|
150 | \textbf{cl}& |
---|
151 | \textbf{cd}& |
---|
152 | \textbf{yl} \\ |
---|
153 | \hline |
---|
154 | loop \par control& |
---|
155 | \textbf{j} \par \textit{but not } \par \textbf{jp}& |
---|
156 | & |
---|
157 | & |
---|
158 | & |
---|
159 | & |
---|
160 | \\ |
---|
161 | \hline |
---|
162 | parameter& |
---|
163 | \textbf{jp}& |
---|
164 | \textbf{pp}& |
---|
165 | \textbf{lp}& |
---|
166 | \textbf{cp}& |
---|
167 | \textbf{dp}& |
---|
168 | \textbf{yp} \\ |
---|
169 | \hline |
---|
170 | statement \par function& |
---|
171 | \textbf{kf}& |
---|
172 | \textbf{sf} \par & |
---|
173 | & |
---|
174 | & |
---|
175 | & |
---|
176 | \\ |
---|
177 | \hline |
---|
178 | \end{tabular} |
---|
179 | \label{tab1} |
---|
180 | \end{center} |
---|
181 | \end{table} |
---|
182 | %-------------------------------------------------------------------------------------------------------------- |
---|