New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 11799 for NEMO/branches/2019/dev_r11470_HPC_12_mpi3/doc/latex/global/coding_rules.tex – NEMO

Ignore:
Timestamp:
2019-10-25T16:27:34+02:00 (5 years ago)
Author:
mocavero
Message:

Update the branch to v4.0.1 of the trunk

Location:
NEMO/branches/2019/dev_r11470_HPC_12_mpi3/doc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2019/dev_r11470_HPC_12_mpi3/doc

    • Property svn:externals set to
      ^/utils/badges badges
      ^/utils/logos logos
  • NEMO/branches/2019/dev_r11470_HPC_12_mpi3/doc/latex

    • Property svn:ignore deleted
  • NEMO/branches/2019/dev_r11470_HPC_12_mpi3/doc/latex/global

    • Property svn:ignore deleted
  • NEMO/branches/2019/dev_r11470_HPC_12_mpi3/doc/latex/global/coding_rules.tex

    r11433 r11799  
    11 
    22\chapter{Coding Rules} 
    3 \label{apdx:coding} 
    4  
    5 \minitoc 
     3\label{apdx:CODING} 
     4 
     5\chaptertoc 
    66 
    77\newpage 
     
    1313produces fewer bugs and is easier to maintain. 
    1414Therefore, it is essential that the model development follows some rules: 
     15 
    1516\begin{itemize} 
    16    \item well planned and designed 
    17    \item well written 
    18    \item well documented (both on- and off-line) 
    19    \item maintainable 
    20    \item easily portable 
    21    \item flexible. 
     17\item well planned and designed 
     18\item well written 
     19\item well documented (both on- and off-line) 
     20\item maintainable 
     21\item easily portable 
     22\item flexible. 
    2223\end{itemize} 
    2324 
    24 To satisfy part of these aims, \NEMO is written with a coding standard which is close to the ECMWF rules, 
    25 named DOCTOR \citep{gibson_rpt86}.  
     25To satisfy part of these aims, \NEMO\ is written with a coding standard which is close to the ECMWF rules, 
     26named DOCTOR \citep{gibson_rpt86}. 
    2627These rules present some advantages like: 
     28 
    2729\begin{itemize} 
    28    \item to provide a well presented program 
    29    \item to use rules for variable names which allow recognition of their type 
    30    (integer, real, parameter, local or shared variables, etc. ).  
     30\item to provide a well presented program 
     31\item to use rules for variable names which allow recognition of their type   (integer, real, parameter, local or shared variables, etc. ). 
    3132\end{itemize} 
    3233 
     
    3536\section{Introduction} 
    3637 
    37 This document describes conventions used in \NEMO coding and suggested for its development. 
    38 The objectives are to offer a guide to all readers of the \NEMO code, and to facilitate the work of 
     38This document describes conventions used in \NEMO\ coding and suggested for its development. 
     39The objectives are to offer a guide to all readers of the \NEMO\ code, and to facilitate the work of 
    3940all the developers, including the validation of their developments, and 
    40 eventually the implementation of these developments within the \NEMO platform. 
     41eventually the implementation of these developments within the \NEMO\ platform. 
    4142 
    4243A first approach of these rules can be found in the code in \path{./src/OCE/module_example} where 
     
    4546 
    4647This work is based on the coding conventions in use for the Community Climate System Model 
    47 \footnote {\href{http://www.cesm.ucar.edu/working_groups/Software/dev_guide/dev_guide/node7.html}{UCAR conventions}},  
     48\footnote {\href{http://www.cesm.ucar.edu/working_groups/Software/dev_guide/dev_guide/node7.html}{UCAR conventions}}, 
    4849the previous version of this document (``FORTRAN coding standard in the OPA System'') and 
    49 the expertise of the \NEMO System Team. 
     50the expertise of the \NEMO\ System Team. 
    5051After a general overview below, this document will describe: 
    5152 
    5253\begin{itemize} 
    53    \item The style rules, $i.e.$ the syntax, appearance and naming conventions chosen to improve readability of the code; 
    54    \item The content rules, $i.e.$ the conventions to improve the reliability of the different parts of the code; 
    55    \item The package rules to go a step further by improving the reliability of the whole and 
     54\item The style rules, $i.e.$ the syntax, appearance and naming conventions chosen to improve readability of the code; 
     55\item The content rules, $i.e.$ the conventions to improve the reliability of the different parts of the code; 
     56\item The package rules to go a step further by improving the reliability of the whole and 
    5657   interfaces between routines and modules. 
    5758\end{itemize} 
     
    5960\section{Overview and general conventions} 
    6061 
    61 \NEMO has 3 major components: ocean dynamics (\path{./src/OCE}), sea-ice (\path{./src/ICE}) and 
     62\NEMO\ has 3 major components: ocean dynamics (\path{./src/OCE}), sea-ice (\path{./src/ICE}) and 
    6263marine biogeochemistry (\path{./src/MBG}). 
    6364%, linear-tangent and adjoint of the dynamics ($TAM$) each of them corresponding to a directory. 
     
    7980 
    8081\begin{itemize} 
    81    \item \path{SBC}             surface module 
    82    \item \path{IOM}             management of the I/O 
    83    \item \path{NST}             interface to AGRIF (nesting model) for dynamics and biogeochemistry 
    84    \item \path{OBC}, \path{BDY} management of structured and unstructured open boundaries  
    85    \item \path{C1D}             1D (vertical) configuration for dynamics, sea-ice and biogeochemistry 
    86    \item \path{OFF}             off-line module: passive tracer or biogeochemistry alone 
    87    \item \path{...} 
     82\item \path{SBC}             surface module 
     83\item \path{IOM}             management of the I/O 
     84\item \path{NST}             interface to AGRIF (nesting model) for dynamics and biogeochemistry 
     85\item \path{OBC}, \path{BDY} management of structured and unstructured open boundaries 
     86\item \path{C1D}             1D (vertical) configuration for dynamics, sea-ice and biogeochemistry 
     87\item \path{OFF}             off-line module: passive tracer or biogeochemistry alone 
     88\item \path{...} 
    8889\end{itemize} 
    8990 
     
    142143 
    143144All FORTRAN keywords are in capital: \forcode{DIMENSION}, \forcode{WRITE}, \forcode{DO}, \forcode{END DO}, 
    144 \forcode{NAMELIST}, ... All other parts of the \NEMO code will be written in lower case. 
     145\forcode{NAMELIST}, ... All other parts of the \NEMO\ code will be written in lower case. 
    145146 
    146147\subsection{Comments} 
     
    216217\subsection{F90 Standard} 
    217218 
    218 \NEMO software adheres to the \fninety language standard and does not rely on any specific language or 
     219\NEMO\ software adheres to the \fninety language standard and does not rely on any specific language or 
    219220vendor extensions. 
    220221 
     
    268269For example, zdftke, where ``zdf'' stands for vertical diffusion, and ``tke'' for turbulent kinetic energy. \\ 
    269270Note that by implication multiple modules are not allowed in a single file. 
    270 The use of common blocks is deprecated in \fortran 90 and their use in \NEMO is strongly discouraged. 
     271The use of common blocks is deprecated in \fortran 90 and their use in \NEMO\ is strongly discouraged. 
    271272Modules are a better way to declare static data. 
    272273Among the advantages of modules is the ability to freely mix data of various types, and 
     
    292293      complex                                                                                     \\ 
    293294      \hline 
    294       public \par or \par module variable                                                         &  
    295       \textbf{m n} \par \textit{but not} \par \textbf{nn\_}                                       &  
     295      public \par or \par module variable                                                         & 
     296      \textbf{m n} \par \textit{but not} \par \textbf{nn\_}                                       & 
    296297      \textbf{a b e f g h o} \textbf{q} \textit{to} \textbf{x} \par but not \par \textbf{fs rn\_} & 
    297298      \textbf{l} \par \textit{but not} \par \textbf{lp ld ll ln\_}                                & 
     
    301302      \hline 
    302303      dummy \par argument                                                                         & 
    303       \textbf{k} \par \textit{but not} \par \textbf{kf}                                           &  
    304       \textbf{p} \par \textit{but not} \par \textbf{pp pf}                                        &  
     304      \textbf{k} \par \textit{but not} \par \textbf{kf}                                           & 
     305      \textbf{p} \par \textit{but not} \par \textbf{pp pf}                                        & 
    305306      \textbf{ld}                                                                                 & 
    306307      \textbf{cd}                                                                                 & 
     
    309310      \hline 
    310311      local \par variable                                                                         & 
    311       \textbf{i}                                                                                  &  
     312      \textbf{i}                                                                                  & 
    312313      \textbf{z}                                                                                  & 
    313314      \textbf{ll}                                                                                 & 
     
    333334      \hline 
    334335      namelist                                                                                    & 
    335       \textbf{nn\_}                                                                               &  
     336      \textbf{nn\_}                                                                               & 
    336337      \textbf{rn\_}                                                                               & 
    337338      \textbf{ln\_}                                                                               & 
     
    388389Is to be used rather than the \#ifdef abbreviate form since it may have conflicts with some Unix scripts. 
    389390 
    390 Tests on cpp keys included in \NEMO at compilation step: 
     391Tests on cpp keys included in \NEMO\ at compilation step: 
    391392 
    392393\begin{itemize} 
     
    402403\subsection{Configurations} 
    403404 
    404 The configuration defines the domain and the grid on which \NEMO is running. 
     405The configuration defines the domain and the grid on which \NEMO\ is running. 
    405406It may be useful to associate a CPP key and some variables to a given configuration, although 
    406407the part of the code changed under each of those keys should be minimized. 
     
    487488\subsection{Headers} 
    488489 
    489 Prologues are not used in \NEMO for now, although it may become an interesting tool in combination with 
     490Prologues are not used in \NEMO\ for now, although it may become an interesting tool in combination with 
    490491ProTeX auto documentation script in the future. 
    491492Rules to code the headers and layout of a module or a routine are illustrated in the example module available with 
     
    563564\subsection{Bounds checking} 
    564565 
    565 \NEMO is able to run when an array bounds checking option is enabled 
     566\NEMO\ is able to run when an array bounds checking option is enabled 
    566567(provided the cpp key \texttt{key\_vectopt\_loop} is not defined). \\ 
    567568Thus, constructs of the following form are disallowed: 
     
    606607the \texttt{stat=<integer\ variable>} optional argument. \\ 
    607608 
    608 In addition to arrays contained within modules, many routines in \NEMO require local, ``workspace'' arrays to 
     609In addition to arrays contained within modules, many routines in \NEMO\ require local, ``workspace'' arrays to 
    609610hold the intermediate results of calculations. 
    610611In previous versions of \NEMO, these arrays were declared in such a way as to be automatically allocated on 
     
    697698It is then associated with a sub-array of \texttt{wrk\_3d\_5} once the call to 
    698699\texttt{wrk\_in\_use()} has completed successfully. 
    699 Note that in F95 (to which \NEMO conforms) it is not possible for either the upper or lower array bounds of 
     700Note that in F95 (to which \NEMO\ conforms) it is not possible for either the upper or lower array bounds of 
    700701the pointer object to differ from those of the target array. \\ 
    701702 
     
    710711This should enable the developer to choose alternatives for use in the subroutine being worked on. \\ 
    711712 
    712 When compiling \NEMO for production runs, 
     713When compiling \NEMO\ for production runs, 
    713714the calls to {\texttt{wrk\_in\_use()} / \texttt{wrk\_not\_released()} can be reduced to stubs that just 
    714715return \forcode{.false.} by setting the cpp key \texttt{key\_no\_workspace\_check}. 
     
    732733\subsection{Parallelism using MPI} 
    733734 
    734 \NEMO is written in order to be able to run on one processor, or on one or more using MPI 
     735\NEMO\ is written in order to be able to run on one processor, or on one or more using MPI 
    735736($i.e.$ activating the cpp key $key\_mpp\_mpi$). 
    736 The domain decomposition divides the global domain in cubes (see \NEMO reference manual). 
     737The domain decomposition divides the global domain in cubes (see \NEMO\ reference manual). 
    737738Whilst coding a new development, the MPI compatibility has to be taken in account 
    738739(see \path{./src/LBC/lib_mpp.F90}) and should be tested. 
     
    748749Below is a list of features to avoid: 
    749750\begin{itemize} 
    750 \item 
    751   \forcode{COMMON} block 
     751\item \forcode{COMMON} block 
    752752  (use the declaration part of \forcode{MODULE} instead) 
    753 \item 
    754   \forcode{EQUIVALENCE} 
     753\item \forcode{EQUIVALENCE} 
    755754  (use \forcode{POINTER} or derived data type instead to form data structure) 
    756 \item 
    757   Assigned and computed \forcode{GOTO} 
     755\item Assigned and computed \forcode{GOTO} 
    758756  (use the \forcode{CASE} construct instead) 
    759 \item 
    760   Arithmetic \forcode{IF} statement 
     757\item Arithmetic \forcode{IF} statement 
    761758  (use the block \forcode{IF}, \forcode{ELSE}, \forcode{ELSEIF}, \forcode{ENDIF} or 
    762759  \forcode{SELECT CASE} construct instead) 
    763 \item 
    764   Labelled \forcode{DO} construct 
     760\item Labelled \forcode{DO} construct 
    765761  (use unlabelled \forcode{END DO} instead) 
    766 \item 
    767   \forcode{FORMAT} statement 
     762\item \forcode{FORMAT} statement 
    768763  (use character parameters or 
    769764  explicit format- specifiers inside the \forcode{READ} or \forcode{WRITE} statement instead) 
    770 \item 
    771   \forcode{GOTO} and \forcode{CONTINUE} statements 
     765\item \forcode{GOTO} and \forcode{CONTINUE} statements 
    772766  (use \forcode{IF}, \forcode{CASE}, \forcode{DO WHILE}, \forcode{EXIT} or \forcode{CYCLE} statements or 
    773767  a contained ?) 
    774 \item 
    775   \forcode{PAUSE} 
    776 \item 
    777   \forcode{ENTRY} statement: a sub-program must only have one entry point. 
    778 \item 
    779   \forcode{RETURN} is obsolete and so not necessary at the end of program units 
    780 \item 
    781   \forcode{FUNCTION} statement 
    782 \item 
    783   Avoid functions with side effects. 
     768\item \forcode{PAUSE} 
     769\item \forcode{ENTRY} statement: a sub-program must only have one entry point. 
     770\item \forcode{RETURN} is obsolete and so not necessary at the end of program units 
     771\item \forcode{FUNCTION} statement 
     772\item Avoid functions with side effects. 
    784773  \footnote{ 
    785774    First, the code is easier to understand, if you can rely on 
     
    790779    This is especially important on massive parallel and as well on vector machines. 
    791780  } 
    792 \item 
    793   \forcode{DATA} and \forcode{BLOCK DATA} 
     781\item \forcode{DATA} and \forcode{BLOCK DATA} 
    794782  (use initialisers) 
    795783\end{itemize} 
    796784 
     785%% Imported from introduction 
     786%%gm    To be put somewhere else .... 
     787%%nm    We should consider creating a glossary for all this kind of stuff (terms, acronyms and symbols) 
     788%%      http://en.wikibooks.org/wiki/LaTeX/Glossary 
     789%\noindent CPP keys and namelists are used as inputs to the code. 
     790 
     791%\noindent \index{CPP keys} CPP keys 
     792 
     793%Some CPP keys are implemented in the \fortran code to allow code selection at compiling step. 
     794%This selection of code at compilation time reduces the reliability of the whole platform since 
     795%it changes the code from one set of CPP keys to the other. 
     796%It is used only when the addition/suppression of the part of code highly changes the amount of memory at run time. 
     797%Usual coding looks like: 
     798 
     799%\begin{forlines} 
     800%#if defined key_option1 
     801%  ! This part of the \fortran code will be active 
     802%  ! only if key_option1 is activated at compiling step 
     803%#endif 
     804%\end{forlines} 
     805 
     806%\noindent \index{Namelist} Namelists 
     807 
     808%The namelist allows to input variables (character, logical, real and integer) into the code. 
     809%There is one namelist file for each component of \NEMO\ (dynamics, sea-ice, biogeochemistry...) 
     810%containing all the \fortran namelists needed. 
     811%The implementation in \NEMO\ uses a 2-step process. 
     812%For each \fortran namelist, two files are read: 
     813 
     814%\begin{enumerate} 
     815%\item 
     816%  A reference namelist (in \path{./cfgs/SHARED/namelist_ref}) is read first. 
     817%  This file contains all the namelist variables which are initialised to default values 
     818%\item 
     819%  A configuration namelist (in \path{./cfgs/CFG_NAME/EXP00/namelist_cfg}) is read aferwards. 
     820%  This file contains only the namelist variables which are changed from default values, and overwrites those. 
     821%\end{enumerate} 
     822%A template can be found in \path{NEMO/OPA_SRC/module.example}. 
     823%The effective namelist, taken in account during the run, is stored at execution time in 
     824%an \texttt{output\_namelist\_dyn} (or \texttt{\_ice} or \texttt{\_top}) file. 
     825%%gm  end 
     826 
     827%%nm: Add some words on the \NEMO\ dependencies 
     828%The model is implemented in \fninety, with preprocessing (C pre-processor). 
     829%It runs under UNIX. 
     830%It is optimized for vector computers and parallelised by domain decomposition with MPI. 
     831%All input and output is done in NetCDF (Network Common Data Format) with a optional direct access format for output. 
     832%To ensure the clarity and readability of the code it is necessary to follow coding rules. 
     833%The coding rules for OPA include conventions for naming variables, 
     834%with different starting letters for different types of variables (real, integer, parameter\ldots). 
     835%Those rules are briefly presented in \autoref{apdx:coding} and a more complete document is available . 
     836 
     837%The model is organized with a high internal modularity based on physics. 
     838%For example, each trend (\ie, a term in the RHS of the prognostic equation) for momentum and tracers 
     839%is computed in a dedicated module. 
     840%To make it easier for the user to find his way around the code, the module names follow a three-letter rule. 
     841%For example, \mdl{traldf} is a module related to the TRAcers equation, computing the Lateral DiFfussion. 
     842%The complete list of module names is presented in \autoref{apdx:coding}.      %====>>>> to be done ! 
     843%Furthermore, modules are organized in a few directories that correspond to their category, 
     844%as indicated by the first three letters of their name (\autoref{tab:chapters}). 
Note: See TracChangeset for help on using the changeset viewer.