Skip to content
Snippets Groups Projects
chap_DIA.tex 106 KiB
Newer Older
\documentclass[../main/NEMO_manual]{subfiles}

\begin{document}

\chapter{Output and Diagnostics (IOM, DIA, TRD, FLO)}
\label{chap:DIA}

%    {\em 4.0} & {\em Mirek Andrejczuk, Massimiliano Drudi} & {\em }  \\
%    {\em }      & {\em Dorotea Iovino, Nicolas Martin} & {\em }  \\
%    {\em 3.6} & {\em Gurvan Madec, Sebastien Masson } & {\em }  \\
%    {\em 3.4} & {\em Gurvan Madec, Rachid Benshila, Andrew Coward } & {\em }  \\
%    {\em }      & {\em Christian Ethe, Sebastien Masson } & {\em }  \\

\chaptertoc

\paragraph{Changes record} ~\\

{\footnotesize
  \begin{tabularx}{\textwidth}{l||X|X}
    Release & Author(s) & Modifications \\
    \hline
    {\em   4.0} & {\em ...} & {\em ...} \\
    {\em   3.6} & {\em ...} & {\em ...} \\
    {\em   3.4} & {\em ...} & {\em ...} \\
    {\em <=3.4} & {\em ...} & {\em ...}
  \end{tabularx}
}

\clearpage

%% =================================================================================================
\section{Model output}
\label{sec:DIA_io_old}

The model outputs are of three types: the output log/progress listings; 
the diagnostic output file(s); and the restart file(s)


The output listing and file(s) are predefined but should be checked and eventually adapted
to the user's needs. The output listing is stored in the \textit{ocean.output} file. The
information is printed from within the code on the logical unit \texttt{numout}. To
locate these prints, use the UNIX command "\textit{grep -i numout}" in the source code
directory. The \textit{ocean.output} file is the first place to check if something appears
to have gone wrong with the model since any detectable errors will be reported here.
Additional progress information can be requested using the options explained in
\autoref{subsec:MISC_statusinfo}.

Diagnostic output files are written in NetCDF format and the structure of legacy output files is predefined.
The legacy output files contain by default the time averaged fields, but by activating the macro \key{diainstant} 
it is possible to switch the full output to the instantaneous time value. 
When compiled with \key{xios}, \NEMO\ can employ the full capability of an I/O server (XIOS)
which provides flexibility in the choice of the fields to be written as well as how the writing tasks are distributed
over the processors in a massively parallel computing environment. A complete description
of the use of this I/O server is presented in the next section.

The restart file is used by the code when the user wants to start the model with initial
conditions defined by a previous simulation.  Restart files are NetCDF files containing
all the information that is necessary in order for there to be no changes in the model
results (even at the computer precision) between a run performed with several stops and
restarts and the same run performed in one continuous integration step.  It should be
noted that this requires that the restart file contains two consecutive time steps for all
the prognostic variables. The default behaviour of \NEMO\ is to generate a restart file
for each MPP region. These files will be read in by the same regions on restarting.
However, if a change in MPP decomposition is required, then the invidual restart files
must first be combined into a whole domain restart file. This can be done using the
\forcode{REBUILD_NEMO} tool.  Alternatively, users may experiment with the new options in
4.2 to write restarts via XIOS (see \autoref{subsec:XIOS_restarts}) with which it is possible to
write a whole domain restart file from a running model.

%% =================================================================================================
\section{Standard model output (\texttt{iom\_put})}
\label{sec:DIA_iom}

Since version 3.2, \rou{iom\_put} is the \NEMO\ output interface of choice.
It has been designed to be simple to use, flexible and efficient.
The two main purposes of \rou{iom\_put} are:

\begin{enumerate}
\item The complete and flexible control of the output files through external XML files adapted by
  the user from standard templates.
\item To achieve high performance and scalable output through the optional distribution of
  all diagnostic output related tasks to dedicated processes.
\end{enumerate}

\noindent The first functionality allows the user to specify, without code changes or recompilation,
aspects of the diagnostic output stream, such as:

\begin{itemize}
\item The choice of output frequencies that can be different for each file (including real months and years).
\item The choice of file contents; includes complete flexibility over which data are written in which files
  (the same data can be written in different files).
\item The possibility to split output files at a chosen frequency.
\item The possibility to extract a vertical or an horizontal subdomain.
\item The choice of the temporal operation to perform, \eg: average, accumulate, instantaneous, min, max and once.
\item Control over metadata via a large XML "database" of possible output fields.
\item Control over the compression and/or precision of output fields (subject to certain conditions)
\end{itemize}

\noindent In addition, \rou{iom\_put}  allows the user to add in the code the output of any new
variable (scalar, 1D, 2D or 3D) in a very easy way.  All details of \rou{iom\_put}
functionalities are listed in the following subsections.  An example of the main XML file
that control the outputs can be found in \path{cfgs/ORCA2_ICE_PISCES/EXPREF/iodef.xml}.\\

\noindent The second functionality targets output performance when running in parallel.  XIOS
provides the possibility to specify N dedicated I/O processes (in addition to the \NEMO\
processes) to collect and write the outputs.  With an appropriate choice of N by the user,
the bottleneck associated with the writing of the output files can be greatly reduced.

Since version 3.6, the \rou{iom\_put} interface depends on an external code called \XIOS, 
which is developed independently and has its own repository and support pages. Further details
are available in the \href{https://sites.nemo-ocean.io/user-guide/}{NEMO User guide}. 
Note that by default the model is interfaced with the trunk version of 
\href{https://forge.ipsl.jussieu.fr/ioserver/browser/XIOS2/trunk}{XIOS2}, but it is possible to use also 
the more recent version \href{https://forge.ipsl.jussieu.fr/ioserver/browser/XIOS3/trunk}{XIOS3} 
by adding the macro \key{xios3} in the configuration cpp file.\\

The IO server can also take advantage of the parallel I/O functionality of NetCDF4 to
create a single output file and therefore to bypass any rebuilding phase. This facility is ideal for
small to moderate size configurations but can be problematic with large models due to the large memory
requirements and the inability to use NetCDF4's compression capabilities in this "one\_file" mode.
XIOS now has the option of using two levels of I/O servers so it may be possible, in some circumstances,
to use a single I/O server at the second level to enable compression. In many cases. though, it is
often more robust to use "multiple\_file" mode (where each XIOS server writes its own file) and to
recombine these files as a post-processing step. The \forcode{REBUILD_NEMO} tool in the \forcode{tools}
directory is provided for this purpose.

Note that writing in parallel into the same NetCDF files requires that your NetCDF4 library is linked to
an HDF5 library that has been correctly compiled (\ie\ with the configure option $--$enable-parallel).
Note that the files created by \rou{iom\_put} through XIOS are incompatible with NetCDF3.
All post-processsing and visualization tools must therefore be compatible with NetCDF4 and not only NetCDF3.

Even when not using the "one\_file" functionality of NetCDF4, using N dedicated I/O
servers, where N is typically much less than the number of \NEMO\ processors, will reduce
the number of output files created.  This can greatly reduce the post-processing burden
otherwise associated with using large numbers of \NEMO\ processors.  Note that for smaller
configurations, the rebuilding phase can be avoided, even without a parallel-enabled
NetCDF4 library, simply by employing only one dedicated I/O server.

%% =================================================================================================
\subsection{XIOS: Reading and writing restart file}
\label{subsec:XIOS_restarts}


New from version 4.2, XIOS may be used to read from a single file restart produced by \NEMO. 
This does not add a new functionality (since NEMO has long had the capability for all
processes to read their patch from a single, combined restart file) but it may be advantageous 
on systems which struggle with too many simultaneous accesses to one file.  The
variables written to file \forcode{numror} (OCE), \forcode{numrir} (SI3), \forcode{numrtr}
(TOP), \forcode{numrsr} (SED) can be handled by XIOS.  To activate restart reading using
XIOS, set \np[=.true. ]{ln_xios_read}{ln\_xios\_read} in \textit{namelist\_cfg}. This
setting will be ignored when multiple restart files are present, and default \NEMO
functionality will be used for reading. There is no need to change iodef.xml file to use
XIOS to read restart, all definitions are done within the \NEMO\ code. For high resolution
configurations, however, there may be a need to add the following line in iodef.xml (xios
context):

\begin{xmllines}
<variable id="recv_field_timeout"        type="double">1800</variable>
\end{xmllines}

\noindent This variable sets timeout for reading.

\noindent If XIOS is to be used to read restart from files generated with an earlier \NEMO\ version (3.6 for instance),
dimension \forcode{z} defined in restart file must be renamed to \forcode{nav_lev}.\\

XIOS can also be used to write \NEMO\ restarts. A namelist parameter
\np{nn_wxios}{nn\_wxios} is used to determine the type of restart \NEMO\ will write. If it
is set to 0, default \NEMO\ functionality will be used - each processor writes its own
restart file; if it is set to 1 XIOS will write restart into a single file; for
\np[=2]{nn_wxios}{nn\_wxios} the restart will be written by XIOS into multiple files, one
for each XIOS server.  Note, however, that \textbf{\NEMO\ will not read restart generated
by XIOS when \np[=2]{nn_wxios}{nn\_wxios}}. The restart will have to be rebuilt before
continuing the run. This option aims to reduce number of restart files generated by \NEMO\
only, and may be useful when there is a need to change number of processors used to run
simulation.

The use of XIOS to read and write restart files is in preparation of NEMO for exascale
computing platforms. There may not be any performance gains on current clusters but it
should reduce file system bottlenecks in any future attempts to run NEMO on hundreds of
thousands of cores.

%% =================================================================================================
\subsection{XIOS: XML Inputs-Outputs Server}

%% =================================================================================================
\subsubsection{Attached or detached mode?}

\rou{iom\_put} is based on \href{http://forge.ipsl.jussieu.fr/ioserver/wiki}{XIOS},
the io\_server developed by Yann Meurdesoif from IPSL.
The behaviour of the I/O subsystem is controlled by settings in the external XML files listed above.
Key settings in the iodef.xml file are the tags associated with each defined file.

\xmlline|<variable id="using_server" type="bool"></variable>|

The \texttt{using\_server} setting determines whether or not the server will be used in
\textit{attached mode}
(as a library) [\texttt{.false.}] or in \textit{detached mode}
(as an external executable on N additional, dedicated cpus) [\texttt{.true.}].
The \textit{attached mode} is simpler to use but much less efficient for
massively parallel applications.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
The type of each file can be either ''multiple\_file'' or ''one\_file''.

In \textit{attached mode} and if the type of file is ''multiple\_file'',
then each \NEMO\ process will also act as an IO server and produce its own set of output files.
Superficially, this emulates the standard behaviour in previous versions.
However, the subdomain written out by each process does not correspond to
the \forcode{jpi x jpj x jpk} domain actually computed by the process (although it may if \forcode{jpni=1}).
Instead each process will have collected and written out a number of complete longitudinal strips.
If the ''one\_file'' option is chosen then all processes will collect their longitudinal strips and
write (in parallel) to a single output file.

In \textit{detached mode} and if the type of file is ''multiple\_file'',
then each stand-alone XIOS process will collect data for a range of complete longitudinal strips and
write to its own set of output files.
If the ''one\_file'' option is chosen then all XIOS processes will collect their longitudinal strips and
write (in parallel) to a single output file.
Note running in detached mode requires launching a Multiple Process Multiple Data (MPMD) parallel job.
The following subsection provides a typical example but the syntax will vary in different MPP environments.

%% =================================================================================================
\subsubsection{Number of cpu used by XIOS in detached mode}

The number of cores used by the XIOS is specified when launching the model.  The number of
cores dedicated to XIOS should be from \texttildelow1/10 to \texttildelow1/50 of the
number of cores dedicated to \NEMO.  Some manufacturers suggest using O($\sqrt{N}$)
dedicated IO processors for N processors but this is a general recommendation and not
specific to \NEMO.  It is difficult to provide precise recommendations because the optimal
choice will depend on the particular hardware properties of the target system (parallel
filesystem performance, available memory, memory bandwidth etc.) and the volume and
frequency of data to be created.  Here is an example of 2 cpus for the io\_server and 62
cpu for nemo using mpirun:

\begin{cmds}
  mpirun -np 62 ./nemo.exe : -np 2 ./xios_server.exe
\end{cmds}

%% =================================================================================================
\subsubsection{Control of XIOS: the context in iodef.xml}

As well as the \texttt{using\_server} flag, other controls on the use of XIOS are set in
the XIOS context in \textit{iodef.xml}.
See the XML basics section below for more details on XML syntax and rules.

\begin{table}
  \begin{tabularx}{\textwidth}{|lXl|}
    \hline
    variable name                                                           &
    description                                                             &
    example  \\
    \hline
    \hline
    info\_level                                                             &
    verbosity level (0 to 100)                                              &
    0        \\
    \hline
    using\_server                                                           &
    activate attached(false) or detached(true) mode                         &
    true     \\
    \hline
    using\_oasis                                                            &
    XIOS is used with OASIS(true) or not (false)                            &
    false    \\
    \hline
    oasis\_codes\_id                                                        &
    when using oasis, define the identifier of \NEMO\ in the namcouple.
    Note that the identifier of XIOS is xios.x                              &
    oceanx   \\
    \hline
  \end{tabularx}
\end{table}

The rest of the XML controls and definitions for XIOS-\NEMO\  interaction are contained in a series of 
XML files included via the \texttt{context\_nemo.xml} file which, is itself, included in iodef.xml. E.g.:
\begin{xmllines}
iodef.xml:           <context id="nemo" src="./context_nemo.xml"/>           <!--  NEMO                -->
context_nemo.xml:    <field_definition  src="./field_def_nemo-oce.xml"/>     <!--  NEMO ocean dynamics -->
context_nemo.xml:    <field_definition  src="./field_def_nemo-ice.xml"/>     <!--  NEMO sea-ice model  -->
context_nemo.xml:    <field_definition  src="./field_def_nemo-pisces.xml"/>  <!--  NEMO ocean biology  -->
context_nemo.xml:    <file_definition   src="./file_def_nemo-oce.xml"/>      <!--  NEMO ocean dynamics -->
context_nemo.xml:    <file_definition   src="./file_def_nemo-ice.xml"/>      <!--  NEMO sea-ice model  -->
context_nemo.xml:    <file_definition   src="./file_def_nemo-pisces.xml"/>   <!--  NEMO ocean biology  -->
context_nemo.xml:    <axis_definition   src="./axis_def_nemo.xml"/>
context_nemo.xml:    <domain_definition src="./domain_def_nemo.xml"/>
context_nemo.xml:    <grid_definition   src="./grid_def_nemo.xml"/>
\end{xmllines}
which shows the hierarchy of XML files in use by the ORCA2\_ICE\_PISCES reference configuration. This nesting
of XML files will be explained further in later sections.

%% =================================================================================================
\subsection{Practical issues}

%% =================================================================================================
\subsubsection{Installation}

As mentioned, XIOS is supported separately and must be downloaded and compiled before it can be used with \NEMO.
See the installation guide on the \href{http://forge.ipsl.jussieu.fr/ioserver/wiki}{XIOS} wiki for help and guidance.
\NEMO\ will need to link to the compiled XIOS library.
The \href{https://forge.ipsl.jussieu.fr/nemo/chrome/site/doc/NEMO/guide/html/install.html#extract-and-install-xios}
{Extract and install XIOS} guide provides an example illustration of how this can be achieved.

%% =================================================================================================
\subsubsection{Add your own outputs}

It is very easy to add your own outputs with iom\_put.
Many standard fields and diagnostics are already prepared (\ie, steps 1 to 3 below have been done) and
simply need to be activated by including the required output in a file definition in iodef.xml (step 4).
To add new output variables, all 4 of the following steps must be taken.

\begin{enumerate}
\item in \NEMO\ code, add a \forcode{CALL iom_put( 'identifier', array )} where you want
to output an array. In most cases, this will be in a part of the code which is executed
only once per timestep and after the array has been updated for that timestep. Note,
adding this call enables the possibility of outputing this array; whether or not and at
which frequency the values are actually written will be determined but the content of
associated XML files.
\item If necessary, add \forcode{USE iom ! I/O manager library} to the list of used
modules in the upper part of your module.
\item in the appropriate \path{cfgs/SHARED/field_def_nemo-....xml} files, add the
definition of your variable using the same identifier you used in the f90 code (see
subsequent sections for a details of the XML syntax and rules).  For example:
\begin{xmllines}
   <field_definition>
         <field_group id="grid_T" grid_ref="grid_T_3D"> <!-- T grid -->
         ...
                  <field id="identifier" long_name="blabla" ... />
                  ...
   </field_definition>
\end{xmllines}
Note your definition must be added to the field\_group whose reference grid is consistent
with the size of the array passed to \rou{iom\_put}. The grid\_ref attribute refers to
definitions set in grid\_def\_nemo.xml which, in turn, reference domains and axes either
defined in the code (iom\_set\_domain\_attr and iom\_set\_axis\_attr in \mdl{iom}) or
defined in the domain\_def\_nemo.xml and axis\_def\_nemo.xml files.  \eg:
\begin{xmllines}
  <grid id="grid_T_3D" >
    <domain domain_ref="grid_T" />
    <axis axis_ref="deptht" />
  </grid>
\end{xmllines}
Note, if your array is computed within the surface module each \np{nn_fsbc}{nn\_fsbc}
time\_step, add the field definition within the field\_group defined with the id "SBC":
\xmlcode{<field_group id="SBC" ...>} which has been defined with the correct frequency of
operations (iom\_set\_field\_attr in \mdl{iom}) \item Finally, to activate actual output,
add your field in one or more of the output files defined in file\_def\_nemo-*.xml (again
see subsequent sections for syntax and rules)
\begin{xmllines}
<file id="file1" ... />
...
   <field field_ref="identifier" />
   ...
</file>
\end{xmllines}
\end{enumerate}

%% =================================================================================================
\subsection{XML fundamentals}

%% =================================================================================================
\subsubsection{ XML basic rules}

XML tags begin with the less-than character ("$<$") and end with the greater-than character ("$>$").
You use tags to mark the start and end of elements, which are the logical units of information in an XML document.
In addition to marking the beginning of an element, XML start tags also provide a place to specify attributes.
An attribute specifies a single property for an element, using a name/value pair, for example:
\xmlcode{<a b="x" c="y" d="z"> ... </a>}.
See \href{http://www.xmlnews.org/docs/xml-basics.html}{here} for more details.

%% =================================================================================================
\subsubsection{Structure of the XML file used in \NEMO}

The XML file used in XIOS is structured by 7 families of tags:
context, axis, domain, grid, field, file and variable.
Each tag family has hierarchy of three flavors (except for context):

\begin{table}
  \begin{tabular*}{\textwidth}{|p{0.15\textwidth}p{0.4\textwidth}p{0.35\textwidth}|}
    \hline
    flavor  & description                                                                 &
                                                                                            example                          \\
    \hline
    \hline
    root    & declaration of the root element that can contain element groups or elements &
                                                                                            \xmlcode{<file_definition ... >} \\
    \hline
    group   & declaration of a group element that can contain element groups or elements  &
                                                                                            \xmlcode{<file_group      ... >} \\
    \hline
    element & declaration of an element that can contain elements                         &
                                                                                            \xmlcode{<file            ... >} \\
    \hline
  \end{tabular*}
\end{table}

Each element may have several attributes.
Some attributes are mandatory, other are optional but have a default value and other are completely optional.
Id is a special attribute used to identify an element or a group of elements.
It must be unique for a kind of element.
It is optional, but no reference to the corresponding element can be done if it is not defined.

The XML file is split into context tags that are used to isolate IO definition from
different codes or different parts of a code.
No interference is possible between 2 different contexts.
Each context has its own calendar and an associated timestep.
In \NEMO, we used the following contexts (that can be defined in any order):

\begin{table}
  \begin{tabular}{|p{0.15\textwidth}p{0.4\textwidth}p{0.35\textwidth}|}
    \hline
    context         &	description                                                                &
                                                                                                     example                              \\
    \hline
    \hline
    context xios    &	context containing information for XIOS                                    &
                                                                                                     \xmlcode{<context id="xios" ... >}   \\
    \hline
    context nemo    &	context containing IO information for \NEMO\ (mother grid when using AGRIF)  &
                                                                                                     \xmlcode{<context id="nemo" ... >}   \\
    \hline
    context 1\_nemo &	context containing IO information for \NEMO\ child grid 1 (when using AGRIF) &
                                                                                                     \xmlcode{<context id="1_nemo" ... >} \\
    \hline
    context n\_nemo &	context containing IO information for \NEMO\ child grid n (when using AGRIF) &
                                                                                                     \xmlcode{<context id="n_nemo" ... >} \\
    \hline
  \end{tabular}
\end{table}

\noindent The xios context contains only 1 tag:

\begin{table}
  \begin{tabular}{|p{0.15\textwidth}p{0.4\textwidth}p{0.35\textwidth}|}
    \hline
    context tag                                      &
                                                       description                                      &
                                                                                                          example                              \\
    \hline
    \hline
    variable\_definition                             &
                                                       define variables needed by XIOS.
                                                       This can be seen as a kind of namelist for XIOS. &
                                                                                                          \xmlcode{<variable_definition ... >} \\
    \hline
	\end{tabular}
\end{table}

\noindent Each context tag related to \NEMO\ (mother or child grids) is divided into 5 parts
(that can be defined in any order):

\begin{table}
  \begin{tabular}{|p{0.15\textwidth}p{0.4\textwidth}p{0.35\textwidth}|}
    \hline
    context tag        &	description                                                               &
                                                                                                       example                            \\
    \hline
    \hline
    field\_definition  &	define all variables that can potentially be outputted                    &
                                                                                                       \xmlcode{<field_definition ... >}  \\
    \hline
    file\_definition   &	define the netcdf files to be created and the variables they will contain &
                                                                                                       \xmlcode{<file_definition ... >}   \\
    \hline
    axis\_definition   &	define vertical axis                                                      &
                                                                                                       \xmlcode{<axis_definition ... >}   \\
    \hline
    domain\_definition &	define the horizontal grids                                               &
                                                                                                       \xmlcode{<domain_definition ... >} \\
    \hline
    grid\_definition   &	define the 2D and 3D grids (association of an axis and a domain)          &
                                                                                                       \xmlcode{<grid_definition ... >}   \\
    \hline
  \end{tabular}
\end{table}

%% =================================================================================================
\subsubsection{Nesting XML files}

The XML file can be split in different parts to improve its readability and facilitate its use.
The inclusion of XML files into the main XML file can be done through the attribute src:
\begin{xmllines}
<context id="nemo" src="./context_nemo.xml"/>
\end{xmllines}

\noindent In \NEMO, by default, the field definition is done in 4 separate files (
\path{cfgs/SHARED/field_def_nemo-oce.xml},
\path{cfgs/SHARED/field_def_nemo-pisces.xml}, \path{cfgs/SHARED/field_def_nemo-innerttrc.xml} and
\path{cfgs/SHARED/field_def_nemo-ice.xml} ) and the grid definition is done in another 3 files (\path{cfgs/SHARED/grid_def_nemo.xml}, \path{cfgs/SHARED/axis_def_nemo.xml} and \path{cfgs/SHARED/domain_def_nemo.xml})
that
are included in each context\_nemo.xml file through the following commands:
\begin{xmllines}
<!-- Fields definition -->
    <field_definition src="./field_def_nemo-oce.xml"      />   <!--  NEMO ocean dynamics               -->
    <field_definition src="./field_def_nemo-ice.xml"      />   <!--  NEMO ocean sea ice                -->
    <field_definition src="./field_def_nemo-pisces.xml"   />   <!--  NEMO ocean biogeochemical         -->
    <field_definition src="./field_def_nemo-innerttrc.xml"/>   <!--  NEMO ocean inert passive tracer   -->

<!-- Files definition -->
    <file_definition src="./file_def_nemo-oce.xml"/>       <!--  NEMO ocean dynamics                   -->
    <file_definition src="./file_def_nemo-ice.xml"/>       <!--  NEMO ocean sea ice                    -->
    <file_definition src="./file_def_nemo-innerttrc.xml"/> <!--  NEMO ocean inert passive tracer       -->

    <axis_definition src="./axis_def_nemo.xml"/>           <!-- Axis definition -->
    <domain_definition src="./domain_def_nemo.xml"/>       <!-- Domain definition -->
    <grid_definition   src="./grid_def_nemo.xml"/>         <!-- Grids definition -->
\end{xmllines}

%% =================================================================================================
\subsubsection{Use of inheritance}

XML extensively uses the concept of inheritance.
XML has a tree based structure with a parent-child oriented relation: all children inherit attributes from parent,
but an attribute defined in a child replace the inherited attribute value.
Note that the special attribute ''id'' is never inherited.
\\
\\
example 1: Direct inheritance.

\begin{xmllines}
<field_definition operation="average" >
     <field id="sst"                    />   <!-- averaged      sst -->
     <field id="sss" operation="instant"/>   <!-- instantaneous sss -->
</field_definition>
\end{xmllines}

\noindent The field ''sst'' which is part (or a child) of the field\_definition will inherit the value ''average'' of
the attribute ''operation'' from its parent.
Note that a child can overwrite the attribute definition inherited from its parents.
In the example above, the field ''sss'' will for example output instantaneous values instead of average values.
\\
\\
example 2: Inheritance by reference: inherit (and overwrite, if needed) the attributes of a tag you are refering to:


\begin{xmllines}
<field_definition>
   <field id="sst" long_name="sea surface temperature" />
   <field id="sss" long_name="sea surface salinity"    />
</field_definition>
<file_definition>
   <file id="myfile" output_freq="1d" />
      <field field_ref="sst"                            />  <!-- default def -->
      <field field_ref="sss" long_name="my description" />  <!-- overwrite   -->
   </file>
</file_definition>
\end{xmllines}

%% =================================================================================================
\subsubsection{Use of groups}

Groups can be used for 2 purposes.
Firstly, the group can be used to define common attributes to be shared by the elements of
the group through inheritance.
In the following example, we define a group of field that will share a common grid ''grid\_T\_2D''.
Note that for the field ''toce'', we overwrite the grid definition inherited from the group by ''grid\_T\_3D''.

\begin{xmllines}
   <field_group id="grid_T" grid_ref="grid_T_2D">
   <field id="toce" long_name="temperature"             unit="degC" grid_ref="grid_T_3D"/>
   <field id="sst"  long_name="sea surface temperature" unit="degC"                     />
   <field id="sss"  long_name="sea surface salinity"    unit="psu"                      />
   <field id="ssh"  long_name="sea surface height"      unit="m"                        />
   ...
\end{xmllines}

\noindent Secondly, the group can be used to replace a list of elements.
Several examples of groups of fields are proposed at the end of the XML field files (
\path{cfgs/SHARED/field_def_nemo-oce.xml},
\path{cfgs/SHARED/field_def_nemo-pisces.xml} and
\path{cfgs/SHARED/field_def_nemo-ice.xml} ) .
For example, a short list of the usual variables related to the U grid:

\begin{xmllines}
<field_group id="groupU" >
   <field field_ref="uoce"  />
   <field field_ref="ssu" />
   <field field_ref="utau"  />
</field_group>
\end{xmllines}

\noindent that can be directly included in a file through the following syntax:

\begin{xmllines}
<file id="myfile_U" output_freq="1d" />
   <field_group group_ref="groupU" />
   <field field_ref="uocetr_eff"   />  <!-- add another field -->
</file>
\end{xmllines}

%% =================================================================================================
\subsection{Detailed functionalities}

The files \path{cfgs/ORCA2_ICE_PISCES/EXPREF/*.xml} provide several examples of the use of
the new functionalities offered by the XML interface of XIOS.

%% =================================================================================================
\subsubsection{Define horizontal subdomains}

Horizontal subdomains are defined through the attributes zoom\_ibegin, zoom\_jbegin, zoom\_ni, zoom\_nj of
the tag family domain.
It must therefore be done in the domain part of the XML file.
For example, in \path{cfgs/SHARED/domain_def.xml}, we provide the following example of a definition of
a 5 by 5 box with the bottom left corner at point (10,10).

\begin{xmllines}
<domain id="myzoomT" domain_ref="grid_T">
    <zoom_domain ibegin="10" jbegin="10" ni="5" nj="5" />
\end{xmllines}

The use of this subdomain is done through the redefinition of the attribute domain\_ref of the tag family field.
For example:

\begin{xmllines}
<file id="myfile_vzoom" output_freq="1d" >
   <field field_ref="toce" domain_ref="myzoomT"/>
</file>
\end{xmllines}

\noindent Moorings are seen as an extreme case corresponding to a 1 by 1 subdomain.
The Equatorial section, the TAO, RAMA and PIRATA moorings are already registered in the code and
can therefore be outputted without taking care of their (i,j) position in the grid.
These predefined domains can be activated by the use of specific domain\_ref:
''EqT'', ''EqU'' or ''EqW'' for the equatorial sections and
the mooring position for TAO, RAMA and PIRATA followed by ''T'' (for example: ''8s137eT'', ''1.5s80.5eT'' ...)

\begin{xmllines}
<file id="myfile_vzoom" output_freq="1d" >
   <field field_ref="toce" domain_ref="0n180wT"/>
</file>
\end{xmllines}

\noindent Note that if the domain decomposition used in XIOS cuts the subdomain in several parts and if
you use the ''multiple\_file'' type for your output files,
you will end up with several files you will need to rebuild using unprovided tools (like ncpdq and ncrcat,
\href{http://nco.sourceforge.net/nco.html#Concatenation}{see nco manual}).
We are therefore advising to use the ''one\_file'' type in this case.

%% =================================================================================================
\subsubsection{Define vertical zooms}

Vertical zooms are defined through the attributes begin and n of the zoom\_axis tag family.
It must therefore be done in the axis part of the XML file.
For example, in \path{cfgs/ORCA2_ICE_PISCES/EXPREF/axis_def_nemo.xml}, we provide the following example:

\begin{xmllines}
<axis_definition>
   <axis id="deptht" long_name="Vertical T levels" unit="m" positive="down" />
   <axis id="deptht300" azix_ref="deptht" >
     <zoom_axis begin="1" n="19" />
</axis>
\end{xmllines}

\noindent The use of this vertical zoom is done through the definition of a new grid in \texttt{grid\_def\_nemo.xml}:

\begin{xmllines}
<grid id="grid_T_zoom_300">
   <domain domain_ref="grid_T" />
   <axis axis_ref="deptht300" />
</grid>
\end{xmllines}

\noindent and subsequent application in a field definition (e.g. \texttt{field\_def\_nemo-oce.xml}):

\begin{xmllines}
<field id="toce_e3t_300"    field_ref="toce_e3t"          unit="degree_C"     
                            grid_ref="grid_T_zoom_300"    detect_missing_value="true" />
\end{xmllines}

\noindent This variable can then be added to a file\_definition for actual output.

%% =================================================================================================
\subsubsection{Control of the output file names}

The output file names are defined by the attributs ''name'' and ''name\_suffix'' of the tag family file.
For example:

\begin{xmllines}
<file_group id="1d" output_freq="1d" name="myfile_1d" >
   <file id="myfileA" name_suffix="_AAA" > <!-- will create file "myfile_1d_AAA"  -->
   ...
   </file>
   <file id="myfileB" name_suffix="_BBB" > <!-- will create file "myfile_1d_BBB" -->
   ...
   </file>
</file_group>
\end{xmllines}

However it is often very convienent to define the file name with the name of the experiment,
the output file frequency and the date of the beginning and the end of the simulation
(which are informations stored either in the namelist or in the XML file).
To do so, we added the following rule:
if the id of the tag file is ''fileN'' (where N = 1 to 999 on 1 to 3 digits) or
one of the predefined sections or moorings (see next subsection),
the following part of the name and the name\_suffix (that can be inherited) will be automatically replaced by:

\begin{table}
  \begin{tabularx}{\textwidth}{|lX|}
    \hline
    \centering placeholder string &
    automatically replaced by                          \\
    \hline
    \hline
    \centering @expname@          &
    the experiment name (from cn\_exp in the namelist) \\
    \hline
    \centering @freq@             &
    output frequency (from attribute output\_freq)     \\
    \hline
    \centering @startdate@        &
    starting date of the simulation (from nn\_date0 in the restart or the namelist).
    \newline
    \verb?yyyymmdd?          format                   \\
    \hline
    \centering @startdatefull@    &
    starting date of the simulation (from nn\_date0 in the restart or the namelist).
    \newline
    \verb?yyyymmdd_hh:mm:ss? format                    \\
    \hline
    \centering @enddate@          &
    ending date of the simulation   (from nn\_date0 and nn\_itend  in the namelist).
    \newline
    \verb?yyyymmdd?          format                    \\
    \hline
    \centering @enddatefull@      &
    ending date of the simulation   (from nn\_date0 and nn\_itend  in the namelist).
    \newline
    \verb?yyyymmdd_hh:mm:ss? format                    \\
    \hline
  \end{tabularx}
\end{table}

\noindent For example,
\begin{xmllines}
<file id="myfile_hzoom" name="myfile_@expname@_@startdate@_freq@freq@" output_freq="1d" >
\end{xmllines}

\noindent with the namelist:
\begin{forlines}
cn_exp    = "ORCA2"
nn_date0  = 19891231
ln_rstart = .false.
\end{forlines}

\noindent will give the following file name radical: \textit{myfile\_ORCA2\_19891231\_freq1d}

%% =================================================================================================
\subsubsection{Other controls of the XML attributes from \NEMO}

The values of some attributes are defined by subroutine calls within \NEMO
(calls to iom\_set\_domain\_attr, iom\_set\_axis\_attr and iom\_set\_field\_attr in \mdl{iom}).
Any definition given in the XML file will be overwritten.
By convention, these attributes are defined to ''auto'' (for string) or ''0000'' (for integer) in the XML file
(but this is not necessary).
\\

There is the list of these attributes in the previous table.
\\
\begin{table}
  \begin{tabular}{|l|c|c|}
    \hline
    tag ids affected by automatic definition &
    name attribute                                                       &
    attribute value                                                      \\
    of some of their attributes &
                                                           &
                                                          \\
    \hline
    \hline
    field\_definition                                                    &
    freq\_op                                                             &
    \np{rn_rdt}{rn\_rdt}                                                         \\
    \hline
    SBC                                                                  &
    freq\_op                                                             &
    \np{rn_rdt}{rn\_rdt} $\times$ \np{nn_fsbc}{nn\_fsbc}                                  \\
    \hline
    ptrc\_T                                                              &
    freq\_op                                                             &
    \np{rn_rdt}{rn\_rdt} $\times$ \np{nn_dttrc}{nn\_dttrc}                                 \\
    \hline
    diad\_T                                                              &
    freq\_op                                                             &
    \np{rn_rdt}{rn\_rdt} $\times$ \np{nn_dttrc}{nn\_dttrc}                                 \\
    \hline
    EqT, EqU, EqW                                                        &
    jbegin, ni,                                                          &
    according to the grid                                                \\
                                                                         &
    name\_suffix                                                         &
                                                                         \\
    \hline
    TAO, RAMA and PIRATA moorings                                        &
    zoom\_ibegin, zoom\_jbegin,                                          &
    according to the grid                                                \\
                                                                         &
    name\_suffix                                                         &
                                                                         \\
    \hline
  \end{tabular}
\end{table}

%% =================================================================================================
\subsubsection{Advanced use of XIOS functionalities}

%% =================================================================================================
\subsection{XML reference tables}
\label{subsec:DIA_IOM_xmlref}

\begin{enumerate}
\item Simple computation: directly define the computation when refering to the variable in the file definition.

\begin{xmllines}
<field field_ref="sst"  name="tosK"  unit="degK" > sst + 273.15 </field>
<field field_ref="taum" name="taum2" unit="N2/m4" long_name="square of wind stress module" >   taum * taum </field>
<field field_ref="qt"   name="stupid_check" > qt - qsr - qns </field>
\end{xmllines}

\item Simple computation: define a new variable and use it in the file definition.

in field\_definition:

\begin{xmllines}
<field id="sst2" long_name="square of sea surface temperature" unit="degC2" >  sst * sst </field >
\end{xmllines}

in file\_definition:

\begin{xmllines}
<field field_ref="sst2" > sst2 </field>
\end{xmllines}

Note that in this case, the following syntaxe \xmlcode{<field field_ref="sst2" />} is not working as
sst2 won't be evaluated.

\item Change of variable precision:

\begin{xmllines}
<!-- force to keep real 8 -->
<field field_ref="sst" name="tos_r8" prec="8" />
<!-- integer 2  with add_offset and scale_factor attributes -->
<field field_ref="sss" name="sos_i2" prec="2" add_offset="20." scale_factor="1.e-3" />
\end{xmllines}

Note that, then the code is crashing, writting real4 variables forces a numerical conversion from
real8 to real4 which will create an internal error in NetCDF and will avoid the creation of the output files.
Forcing double precision outputs with prec="8" (for example in the field\_definition) will avoid this problem.

\item add user defined attributes:

\begin{xmllines}
<file_group id="1d" output_freq="1d" output_level="10" enabled=".true."> <!-- 1d files -->
   <file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
      <field field_ref="sst" name="tos" >
         <variable id="my_attribute1" type="string"  > blabla </variable>
         <variable id="my_attribute2" type="integer" > 3      </variable>
         <variable id="my_attribute3" type="float"   > 5.0    </variable>
      </field>
      <variable id="my_global_attribute" type="string" > blabla_global </variable>
   </file>
</file_group>
\end{xmllines}

\item use of the ``@'' function: example 1, weighted temporal average

 - define a new variable in field\_definition

\begin{xmllines}
<field id="toce_e3t" long_name="temperature * e3t" unit="degC*m" grid_ref="grid_T_3D" >toce * e3t</field>
\end{xmllines}

 - use it when defining your file.

\begin{xmllines}
<file_group id="5d" output_freq="5d"  output_level="10" enabled=".true." >  <!-- 5d files -->
   <file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
      <field field_ref="toce" operation="instant" freq_op="5d" > @toce_e3t / @e3t </field>
   </file>
</file_group>
\end{xmllines}

The freq\_op="5d" attribute is used to define the operation frequency of the ``@'' function: here 5 day.
The temporal operation done by the ``@'' is the one defined in the field definition:
here we use the default, average.
So, in the above case, @toce\_e3t will do the 5-day mean of toce*e3t.
Operation="instant" refers to the temporal operation to be performed on the field''@toce\_e3t / @e3t'':
here the temporal average is alreday done by the ``@'' function so we just use instant to do the ratio of
the 2 mean values.
field\_ref="toce" means that attributes not explicitely defined, are inherited from toce field.
Note that in this case, freq\_op must be equal to the file output\_freq.

\item use of the ``@'' function: example 2, monthly SSH standard deviation

 - define a new variable in field\_definition

\begin{xmllines}
<field id="ssh2" long_name="square of sea surface temperature" unit="degC2" > ssh * ssh </field >
\end{xmllines}

 - use it when defining your file.

\begin{xmllines}
<file_group id="1m" output_freq="1m"  output_level="10" enabled=".true." >  <!-- 1m files -->
   <file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
      <field field_ref="ssh" name="sshstd" long_name="sea_surface_temperature_standard_deviation"
                        operation="instant" freq_op="1m" >
                        sqrt( @ssh2 - @ssh * @ssh )
      </field>
   </file>
</file_group>
\end{xmllines}

The freq\_op="1m" attribute is used to define the operation frequency of the ``@'' function: here 1 month.
The temporal operation done by the ``@'' is the one defined in the field definition:
here we use the default, average.
So, in the above case, @ssh2 will do the monthly mean of ssh*ssh.
Operation="instant" refers to the temporal operation to be performed on the field ''sqrt( @ssh2 - @ssh * @ssh )'':
here the temporal average is alreday done by the ``@'' function so we just use instant.
field\_ref="ssh" means that attributes not explicitely defined, are inherited from ssh field.
Note that in this case, freq\_op must be equal to the file output\_freq.

\item use of the ``@'' function: example 3, monthly average of SST diurnal cycle

 - define 2 new variables in field\_definition

\begin{xmllines}
   <field id="sstmax" field_ref="sst" long_name="max of sea surface temperature" operation="maximum" />
   <field id="sstmin" field_ref="sst" long_name="min of sea surface temperature" operation="minimum" />
\end{xmllines}

 - use these 2 new variables when defining your file.

\begin{xmllines}
<file_group id="1m" output_freq="1m"  output_level="10" enabled=".true." >  <!-- 1m files -->
   <file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
      <field field_ref="sst" name="sstdcy" long_name="amplitude of sst diurnal cycle" operation="average" freq_op="1d" >
                        @sstmax - @sstmin
      </field>
   </file>
</file_group>
\end{xmllines}

\end{enumerate}

The freq\_op="1d" attribute is used to define the operation frequency of the ``@'' function: here 1 day.
The temporal operation done by the ``@'' is the one defined in the field definition:
here maximum for sstmax and minimum for sstmin.
So, in the above case, @sstmax will do the daily max and @sstmin the daily min.
Operation="average" refers to the temporal operation to be performed on the field ``@sstmax - @sstmin'':
here monthly mean (of daily max - daily min of the sst).
field\_ref="sst" means that attributes not explicitely defined, are inherited from sst field.

%% =================================================================================================
\subsubsection{Tag list per family}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|X|l|X|}
    \hline
    tag name                                                                                     &
    description                                                                                  &
    accepted attribute                                                                           &
    child of                                                                                     &
    parent of                       \\
    \hline
    \hline
    simulation                                                                                   &
    this tag is the root tag which encapsulates all the content of the XML file                  &
    none                                                                                         &
    none                                                                                         &
    context                         \\
    \hline
    context                                                                                      &
    encapsulates parts of the XML file dedicated to different codes or different parts of a code &
    id (''xios'', ''nemo'' or ''n\_nemo'' for the nth AGRIF zoom), src, time\_origin             &
    simulation                                                                                   &
    all root tags: ... \_definition \\
    \hline
  \end{tabularx}
  \caption{XIOS: context tags}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|X|X|l|}
    \hline
    tag name                                                                                &
    description                                                                             &
    accepted attribute                                                                      &
    child of                                                                                &
    parent of             \\
    \hline
    \hline
    field\_definition                                                                       &
    encapsulates the definition of all the fields that can potentially be outputted         &
    axis\_ref, default\_value, domain\_ref, enabled, grid\_ref, level, operation, prec, src &
    context                                                                                 &
    field or field\_group \\
    \hline
    field\_group                                                                            &
    encapsulates a group of fields                                                          &
    axis\_ref, default\_value, domain\_ref, enabled, group\_ref, grid\_ref,
    id, level, operation, prec, src                                                         &
    field\_definition, field\_group, file                                                   &
    field or field\_group \\
    \hline
    field                                                                                   &
    define a specific field                                                                 &
    axis\_ref, default\_value, domain\_ref, enabled, field\_ref, grid\_ref,
    id, level, long\_name, name, operation, prec, standard\_name, unit                      &
    field\_definition, field\_group, file                                                   &
    none                  \\
    \hline
  \end{tabularx}
  \caption{XIOS: field tags ("\texttt{field\_*}")}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|X|X|l|}
    \hline
    tag name                                                            &
    description                                                         &
    accepted attribute                                                  &
    child of                                                            &
    parent of           \\
    \hline
    \hline
    file\_definition                                                    &
    encapsulates the definition of all the files that will be outputted &
    enabled, min\_digits, name, name\_suffix, output\_level,
    split\_freq\_format, split\_freq, sync\_freq, type, src             &
    context                                                             &
    file or file\_group \\
    \hline
    file\_group                                                         &
    encapsulates a group of files that will be outputted                &
    enabled, description, id, min\_digits, name, name\_suffix, output\_freq, output\_level,
    split\_freq\_format, split\_freq, sync\_freq, type, src             &
    file\_definition, file\_group                                       &
    file or file\_group \\
    \hline
    file                                                                &
    define the contents of a file to be outputted                       &
    enabled, description, id, min\_digits, name, name\_suffix, output\_freq, output\_level,
    split\_freq\_format, split\_freq, sync\_freq, type, src             &
    file\_definition, file\_group                                       &
    field               \\
    \hline
  \end{tabularx}
  \caption{XIOS: file tags ("\texttt{file\_*}")}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|X|X|X|}
    \hline
    tag name                                                                               &
    description                                                                            &
    accepted attribute                                                                     &
    child of                                                                               &
    parent of         \\
    \hline
    \hline
    axis\_definition                                                                       &
    define all the vertical axis potentially used by the variables                         &
    src                                                                                    &
    context                                                                                &
    axis\_group, axis \\
    \hline
    axis\_group                                                                            &
    encapsulates a group of vertical axis                                                  &
    id, lon\_name, positive, src, standard\_name, unit, zoom\_begin, zoom\_end, zoom\_size &
    axis\_definition, axis\_group                                                          &
    axis\_group, axis \\
    \hline
    axis                                                                                   &
    define a vertical axis                                                                 &
    id, lon\_name, positive, src, standard\_name, unit, zoom\_begin, zoom\_end, zoom\_size &
    axis\_definition, axis\_group                                                          &
    none					\\
    \hline
  \end{tabularx}
  \caption{XIOS: axis tags ("\texttt{axis\_*}")}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|X|X|X|}
    \hline
    tag name                                                            &
    description                                                         &
    accepted attribute                                                  &
    child of                                                            &
    parent of               \\
    \hline
    \hline
    domain\_\-definition                                                &
    define all the horizontal domains potentially used by the variables &
    src                                                                 &
    context                                                             &
    domain\_\-group, domain \\
    \hline
    domain\_group                                                       &
    encapsulates a group of horizontal domains                          &
    id, lon\_name, src, zoom\_ibegin, zoom\_jbegin, zoom\_ni, zoom\_nj  &
    domain\_\-definition, domain\_group                                 &
    domain\_\-group, domain \\
    \hline
    domain                                                              &
    define an horizontal domain                                         &
    id, lon\_name, src, zoom\_ibegin, zoom\_jbegin, zoom\_ni, zoom\_nj  &
    domain\_\-definition, domain\_group                                 &
    none                    \\
    \hline
  \end{tabularx}
  \caption{XIOS: domain tags ("\texttt{domain\_*)}"}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|X|X|X|}
    \hline
    tag name                                                                                     &
    description                                                                                  &
    accepted attribute                                                                           &
    child of                                                                                     &
    parent of                       \\
    \hline
    \hline
    grid\_definition                                                                               &
    define all the grid (association of a domain and/or an axis) potentially used by the variables &
    src                                                                                            &
    context                                                                                        &
    grid\_group, grid	\\
    \hline
    grid\_group                                                                                    &
    encapsulates a group of grids                                                                  &
    id, domain\_ref,axis\_ref                                                                      &
    grid\_definition, grid\_group                                                                  &
    grid\_group, grid	\\
    \hline
    grid                                                                                           &
    define a grid                                                                                  &
    id, domain\_ref,axis\_ref                                                                      &
    grid\_definition, grid\_group                                                                  &
    none 					\\
    \hline
  \end{tabularx}
  \caption{XIOS: grid tags ("\texttt{grid\_*}")}
\end{table}

%% =================================================================================================
\subsubsection{Attributes list per family}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|l|l|}
    \hline
    attribute name                           &
    description                              &
    example                                  &
    accepted by            \\
    \hline
    \hline
    axis\_ref                                &
    refers to the id of a vertical axis      &
    axis\_ref="deptht"                       &
    field, grid families   \\
    \hline
    domain\_ref                              &
    refers to the id of a domain             &
    domain\_ref="grid\_T"                    &
    field or grid families \\
    \hline
    field\_ref                               &
    id of the field we want to add in a file &
    field\_ref="toce"                        &
    field                  \\
    \hline
    grid\_ref                                &
    refers to the id of a grid               &
    grid\_ref="grid\_T\_2D"                  &
    field family           \\
    \hline
    group\_ref                               &
    refer to a group of variables            &
    group\_ref="mooring"                     &
    field\_group           \\
    \hline
  \end{tabularx}
  \caption{XIOS: reference attributes ("\texttt{*\_ref}")}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|l|l|}
    \hline
    attribute name                                     &
    description                                        &
    example                                            &
    accepted by   \\
    \hline
    \hline
    zoom\_ibegin                                       &
    starting point along x direction of the zoom.
    Automatically defined for TAO/RAMA/PIRATA moorings &
    zoom\_ibegin="1"                                   &
    domain family \\
    \hline
    zoom\_jbegin                                       &
    starting point along y direction of the zoom.
    Automatically defined for TAO/RAMA/PIRATA moorings &
    zoom\_jbegin="1"                                   &
    domain family \\
    \hline
    zoom\_ni                                           &
    zoom extent along x direction                      &
    zoom\_ni="1"                                       &
    domain family \\
    \hline
    zoom\_nj                                           &
    zoom extent along y direction                      &
    zoom\_nj="1"                                       &
    domain family \\
    \hline
  \end{tabularx}
  \caption{XIOS: domain attributes ("\texttt{zoom\_*}")}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|l|l|}
    \hline
    attribute name                                                                                       &
    description                                                                                          &
    example                                                                                              &
    accepted by                            \\
    \hline
    \hline
    min\_digits                                                                                          &
    specify the minimum of digits used in the core number in the name of the NetCDF file                 &
    min\_digits="4"                                                                                      &
    file family                            \\
    \hline
    name\_suffix                                                                                         &
    suffix to be inserted after the name and before the cpu number and the ''.nc'' termination of a file &
    name\_suffix="\_myzoom"                                                                              &
    file family                            \\
    \hline
    output\_level                                                                                        &
    output priority of variables in a file: 0 (high) to 10 (low).
    All variables listed in the file with a level smaller or equal to output\_level will be output.
    Other variables won't be output even if they are listed in the file.                                 &
    output\_level="10"                                                                                   &
    file family                            \\
    \hline
    split\_freq                                                                                          &
    frequency at which to temporally split output files.
    Units can be ts (timestep), y, mo, d, h, mi, s.
    Useful for long runs to prevent over-sized output files.                                             &
    split\_freq="1mo"                                                                                    &
    file family                            \\
    \hline
    split\_freq\-\_format                                                                                &
    date format used in the name of temporally split output files.
    Can be specified using the following syntaxes: \%y, \%mo, \%d, \%h \%mi and \%s                      &
    split\_freq\_format= "\%y\%mo\%d"                                                                    &
    file family                            \\
    \hline
    sync\_freq                                                                                           &
    NetCDF file synchronization frequency (update of the time\_counter).
    Units can be ts (timestep), y, mo, d, h, mi, s.                                                      &
    sync\_freq="10d"                                                                                     &
    file family                            \\
    \hline
    type (1)                                                                                             &
    specify if the output files are to be split spatially (multiple\_file) or not (one\_file)            &
    type="multiple\_file"                                                                                &
    file familly                           \\
    \hline
  \end{tabularx}
  \caption{XIOS: file attributes}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|l|l|}
    \hline
    attribute name                                                                                       &
    description                                                                                          &
    example                                                                                              &
    accepted by                            \\
    \hline
    \hline
    default\_value                                                                                       &
    missing\_value definition                                                                            &
    default\_value="1.e20"                                                                               &
    field family                           \\
    \hline
    level                                                                                                &
    output priority of a field: 0 (high) to 10 (low)                                                     &
    level="1"                                                                                            &
    field family                           \\
    \hline
    operation                                                                                            &
    type of temporal operation: average, accumulate, instantaneous, min, max and once                    &
    operation="average"                                                                                  &
    field family                           \\
    \hline
    output\_freq                                                                                         &
    operation frequency. units can be ts (timestep), y, mo, d, h, mi, s.                                 &
    output\_freq="1d12h"                                                                                 &
    field family                           \\
    \hline
    prec                                                                                                 &
    output precision: real 4 or real 8                                                                   &
    prec="4"                                                                                             &
    field family                           \\
    \hline
    long\_name                                                                                           &
    define the long\_name attribute in the NetCDF file                                                   &
    long\_name="Vertical T levels"                                                                       &
    field                                  \\
    \hline
    standard\_name                                                                                       &
    define the standard\_name attribute in the NetCDF file                                               &
    standard\_name= "Eastward\_Sea\_Ice\_Transport"                                                      &
    field                                  \\
    \hline
  \end{tabularx}
  \caption{XIOS: field attributes}
\end{table}

\begin{table}
  \begin{tabularx}{\textwidth}{|l|X|X|X|}
    \hline
    attribute name                                                                                       &
    description                                                                                          &
    example                                                                                              &
    accepted by                            \\
    \hline
    \hline
    enabled                                                                                              &
    switch on/off the output of a field or a file                                                        &
    enabled=".true."                                                                                     &
    field, file families                   \\
    \hline
    description                                                                                          &
    just for information, not used                                                                       &
    description="ocean T grid variables"                                                                 &
    all tags                               \\
    \hline
    id                                                                                                   &
    allow to identify a tag                                                                              &
    id="nemo"                                                                                            &
    accepted by all tags except simulation \\
    \hline
    name                                                                                                 &
    name of a variable or a file. If the name of a file is undefined, its id is used as a name           &
    name="tos"                                                                                           &
    field or file families                 \\
    \hline
    positive                                                                                             &
    convention used for the orientation of vertival axis (positive downward in \NEMO).                   &
    positive="down"                                                                                      &
    axis family                            \\
    \hline
    src                                                                                                  &
    allow to include a file                                                                              &
    src="./field\_def.xml"                                                                               &
    accepted by all tags except simulation \\
    \hline
    time\_origin                                                                                         &
    specify the origin of the time counter                                                               &
    time\_origin="1900-01-01 00:00:00"                                                                   &
    context                                \\
    \hline
    type (2)                                                                                             &
    define the type of a variable tag                                                                    &
    type="boolean"                                                                                       &
    variable                               \\
    \hline
    unit                                                                                                 &
    unit of a variable or the vertical axis                                                              &
    unit="m"                                                                                             &
    field and axis families                \\
    \hline
  \end{tabularx}
  \caption{XIOS: miscellaneous attributes}
\end{table}

%% =================================================================================================
\subsection{CF metadata standard compliance}

Output from the XIOS IO server is compliant with
\href{http://cfconventions.org/Data/cf-conventions/cf-conventions-1.5/build/cf-conventions.html}{version 1.5} of
the CF metadata standard.
Therefore while a user may wish to add their own metadata to the output files (as demonstrated in example 4 of
section \autoref{subsec:DIA_IOM_xmlref}) the metadata should, for the most part, comply with the CF-1.5 standard.

Some metadata that may significantly increase the file size (horizontal cell areas and vertices) are controlled by
the namelist parameter \np{ln_cfmeta}{ln\_cfmeta} in the \nam{run}{run} namelist.
This must be set to true if these metadata are to be included in the output files.

%% =================================================================================================
\subsection{Enabling NetCDF4 compression with XIOS}

XIOS supports the use of gzip compression when compiled with NetCDF4 libraries but is subject to the
same restrictions as the underlying HDF5 component. That is, compression is not availiable when the
IO servers are writing in parallel to shared output files. Thus, compression can only be applied in
multiple\_file mode only or with two-levels of servers with multiple servers feeding a single server.
The XML tag to activate compression is:

\begin{xmllines}
   compression_level="n"
\end{xmllines}

where n is an integer between 0 and 9. A value of 2 is normally recommended as a suitable trade-off between
algorithm performance and compression levels. This tag can be applied either at file level or to indivdual
fields, e.g.:

\begin{xmllines}
   <file_definition>
      <file name="output" output_freq="1ts" compression_level="2">
         <field id="field_A" grid_ref="grid_A" operation="average" compression_level=" 4" />
         <field id="field_B" grid_ref="grid_A" operation="average" compression_level=" 0" />
         <field id="field_C" grid_ref="grid_A" operation="average" />
      </file> 
   </file_definition>
\end{xmllines}

It is unclear how XIOS decides on suitable chunking parameters before applying compression so it may
be necessary to rechunk data whilst combining multiple\_file output. \forcode{REBUILD_NEMO} is capable
of doing this.

\section[NetCDF4 support (\texttt{\textbf{key\_netcdf4}})]{NetCDF4 support (\protect\key{netcdf4})}
\label{sec:DIA_nc4}

Since version 3.3, support for NetCDF4 chunking and (loss-less) compression has been
included.  These options build on the standard NetCDF output and allow the user control
over the size of the chunks via namelist settings.  Chunking and compression can lead to
significant reductions in file sizes for a small runtime overhead.  For a fuller
discussion on chunking and other performance issues the reader is referred to the NetCDF4
documentation found
\href{https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_perf_chunking.html}{here}.

This section only applies to the NetCDF output written directly by \NEMO; i.e. restart
files and mean files produced via the old IOIPSL interface when \key{xios} is not being
used. As such it has limited use since chunking and compression can be applied at the
rebuilding phase of such output.

The features are only available when the code has been linked with a NetCDF4 library
(version 4.1 onwards, recommended) which has been built with HDF5 support (version 1.8.4
onwards, recommended).  Datasets created with chunking and compression are not backwards
compatible with NetCDF3 "classic" format but most analysis codes can be relinked simply
with the new libraries and will then read both NetCDF3 and NetCDF4 files.  \NEMO\
executables linked with NetCDF4 libraries can be made to produce NetCDF3 files by setting
the \np{ln_nc4zip}{ln\_nc4zip} logical to false in the \nam{nc4}{nc4} namelist:

\begin{listing}
  \nlst{namnc4}
  \caption{\forcode{&namnc4}}
  \label{lst:namnc4}
\end{listing}

If \key{netcdf4} has not been defined, these namelist parameters are not read.  In this
case, \np{ln_nc4zip}{ln\_nc4zip} is set false and dummy routines for a few
NetCDF4-specific functions are defined.  These functions will not be used but need to be
included so that compilation is possible with NetCDF3 libraries.

When using NetCDF4 libraries, \key{netcdf4} should be defined even if the intention is to
create only NetCDF3-compatible files.  This is necessary to avoid duplication between the
dummy routines and the actual routines present in the library.  Most compilers will fail
at compile time when faced with such duplication.  Thus when linking with NetCDF4
libraries the user must define \key{netcdf4} and control the type of NetCDF file produced
via the namelist parameter.

Chunking and compression is applied only to 4D fields and there is no advantage in
chunking across more than one time dimension since previously written chunks would have to
be read back and decompressed before being added to.  Therefore, user control over chunk
sizes is provided only for the three space dimensions.  The user sets an approximate
number of chunks along each spatial axis.  The actual size of the chunks will depend on
global domain size for mono-processors or, more likely, the local processor domain size
for distributed processing.  The derived values are subject to practical minimum values
(to avoid wastefully small chunk sizes) and cannot be greater than the domain size in any
dimension.  The algorithm used is:

\begin{forlines}
ichunksz(1) = MIN(idomain_size, MAX((idomain_size-1) / nn_nchunks_i + 1 ,16 ))
ichunksz(2) = MIN(jdomain_size, MAX((jdomain_size-1) / nn_nchunks_j + 1 ,16 ))
ichunksz(3) = MIN(kdomain_size, MAX((kdomain_size-1) / nn_nchunks_k + 1 , 1 ))
ichunksz(4) = 1
\end{forlines}

\noindent As an example, setting:

\begin{forlines}
nn_nchunks_i=4, nn_nchunks_j=4 and nn_nchunks_k=31
\end{forlines}

\noindent for a standard ORCA2\_LIM configuration gives chunksizes of {\small\texttt 46x38x1} respectively in
the mono-processor case (\ie\ global domain of {\small\texttt 182x149x31}).
An illustration of the potential space savings that NetCDF4 chunking and compression provides is given in
table \autoref{tab:DIA_NC4} which compares the results of two short runs of the ORCA2\_LIM reference configuration with
a 4x2 mpi partitioning.
Note the variation in the compression ratio achieved which reflects chiefly the dry to wet volume ratio of
each processing region.

\begin{table}
  \centering
  \begin{tabular}{lrrr}
    Filename                    & NetCDF3	& NetCDF4  & Reduction \\
                                & filesize	& filesize & \%        \\
                                & (KB)		& (KB)	  &           \\
    ORCA2\_restart\_0000.nc     & 16420 	& 8860 	  & 47\%      \\
    ORCA2\_restart\_0001.nc     & 16064 	& 11456    & 29\%      \\
    ORCA2\_restart\_0002.nc     & 16064		& 9744	  & 40\%      \\
    ORCA2\_restart\_0003.nc     & 16420		& 9404	  & 43\%      \\
    ORCA2\_restart\_0004.nc     & 16200 	& 5844	  & 64\%      \\
    ORCA2\_restart\_0005.nc     & 15848 	& 8172	  & 49\%      \\
    ORCA2\_restart\_0006.nc     & 15848 	& 8012 	  & 50\%      \\
    ORCA2\_restart\_0007.nc     & 16200 	& 5148 	  & 69\%      \\
    ORCA2\_2d\_grid\_T\_0000.nc & 2200 		& 1504	  & 32\%      \\
    ORCA2\_2d\_grid\_T\_0001.nc & 2200 		& 1748	  & 21\%      \\
    ORCA2\_2d\_grid\_T\_0002.nc & 2200 		& 1592	  & 28\%      \\
    ORCA2\_2d\_grid\_T\_0003.nc & 2200 		& 1540	  & 30\%      \\
    ORCA2\_2d\_grid\_T\_0004.nc & 2200 		& 1204	  & 46\%      \\
    ORCA2\_2d\_grid\_T\_0005.nc & 2200 		& 1444	  & 35\%      \\
    ORCA2\_2d\_grid\_T\_0006.nc & 2200 		& 1428	  & 36\%      \\
    ORCA2\_2d\_grid\_T\_0007.nc & 2200		& 1148	  & 48\%      \\
    ...                         & ...		& ...      & ...       \\
    ORCA2\_2d\_grid\_W\_0000.nc & 4416		& 2240	  & 50\%      \\
    ORCA2\_2d\_grid\_W\_0001.nc & 4416		& 2924	  & 34\%      \\
    ORCA2\_2d\_grid\_W\_0002.nc & 4416		& 2512	  & 44\%      \\
    ORCA2\_2d\_grid\_W\_0003.nc & 4416		& 2368	  & 47\%      \\
    ORCA2\_2d\_grid\_W\_0004.nc & 4416		& 1432	  & 68\%      \\
    ORCA2\_2d\_grid\_W\_0005.nc & 4416		& 1972	  & 56\%      \\
    ORCA2\_2d\_grid\_W\_0006.nc & 4416		& 2028	  & 55\%      \\
    ORCA2\_2d\_grid\_W\_0007.nc & 4416		& 1368	  & 70\%      \\
  \end{tabular}
  \caption{Filesize comparison between NetCDF3 and NetCDF4 with chunking and compression}
  \label{tab:DIA_NC4}
\end{table}

%% =================================================================================================
\section[Tracer/Dynamics trends (\forcode{&namtrd})]{Tracer/Dynamics trends (\protect\nam{trd}{trd})}
\label{sec:DIA_trd}

\begin{listing}
  \nlst{namtrd}
  \caption{\forcode{&namtrd}}
  \label{lst:namtrd}
\end{listing}

Each trend of the dynamics and/or temperature and salinity time evolution equations can be send to
\mdl{trddyn} and/or \mdl{trdtra} modules (see TRD directory) just after their computation
(\ie\ at the end of each \textit{dyn....F90} and/or \textit{tra....F90} routines).
This capability is controlled by options offered in \nam{trd}{trd} namelist.
Note that the output are done with XIOS, and therefore the \key{xios} is required.

What is done depends on the \nam{trd}{trd} logical set to \forcode{.true.}:

\begin{description}
\item [{\np{ln_glo_trd}{ln\_glo\_trd}}]: at each \np{nn_trd}{nn\_trd} time-step a check of the basin averaged properties of
  the momentum and tracer equations is performed.
  This also includes a check of $T^2$, $S^2$, $\tfrac{1}{2} (u^2+v2)$,
  and potential energy time evolution equations properties;
\item [{\np{ln_dyn_trd}{ln\_dyn\_trd}}]: each 3D trend of the evolution of the two momentum components is output;
\item [{\np{ln_dyn_mxl}{ln\_dyn\_mxl}}]: each 3D trend of the evolution of the two momentum components averaged over the mixed layer is output;
\item [{\np{ln_vor_trd}{ln\_vor\_trd}}]: a vertical summation of the moment tendencies is performed,
  then the curl is computed to obtain the barotropic vorticity tendencies which are output;
Loading
Loading full blame...