<?xml version="1.0"?>
<!DOCTYPE texinfo PUBLIC "-//GNU//DTD TexinfoML V7.1//EN" "http://www.gnu.org/software/texinfo/dtd/7.1/texinfo.dtd">
<texinfo>
<filename file="nco.xml"></filename>
<preamblebeforebeginning>\input texinfo @c -*-texinfo-*- 
</preamblebeforebeginning><!-- c \input /home/zender/texinfo_fedora.tex -->
<!-- c \input /home/zender/texinfo_ubuntu.tex -->

<!-- c 19980817: TeX-based systems (texi2dvi, texi2dvi -pdf) require texinfo.tex -->
<!-- c Hyper-text systems (texi2html, makeinfo) do not require texinfo.tex -->

<ignore endspaces=" ">
$Header$

Purpose: TeXInfo documentation for netCDF Operators (NCO)

URL: http://nco.sf.net/nco.texi

Copyright (C) 1995--present Charlie Zender
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. The license is available online at 
http://www.gnu.org/copyleft/fdl.html

The original author of this software, Charlie Zender, seeks to improve
it with your suggestions, contributions, bug-reports, and patches.
Charlie Zender &lt;surname at uci dot edu&gt; (yes, my surname is zender)
Department of Earth System Science
3200 Croul Hall
University of California, Irvine
Irvine, CA 92697-3100

After editing any hyperlink locations, Emacs users update indices with
C-c C-u C-a	texinfo-all-menus-update
C-c C-u C-e	texitnfo-every-node-update

Multiple files:
M-x texinfo-multiple-files-update

Usage:
export TEX='tex --src-specials'
cd ~/nco/doc;texi2dvi nco.texi;makeinfo --html --ifinfo --no-split --output=nco.html nco.texi;makeinfo nco.texi;dvips -o nco.ps nco.dvi;texi2dvi --pdf nco.texi;makeinfo --xml --ifinfo --no-split --output=nco.xml nco.texi;makeinfo --no-headers --output=nco.txt nco.texi
cd ~/nco/doc;/usr/bin/scp index.shtml nco_news.shtml ChangeLog TODO VERSION nco.dvi nco.html nco.info* nco.pdf nco.ps nco.texi nco.txt nco.xml ../README ../data/ncap.in ../data/ncap2.in zender,nco@web.sf.net:/home/project-web/nco/htdocs;cd -
cd ~/nco/doc;/usr/bin/scp index.shtml nco_news.shtml ChangeLog TODO VERSION nco.dvi nco.html nco.info* nco.pdf nco.ps nco.texi nco.txt nco.xml ../README ../data/ncap.in ../data/ncap2.in dust.ess.uci.edu:Sites/nco;cd -
dvips -o nco.ps nco.dvi 
dvips -Ppdf -G0 -o nco.ps nco.dvi
makeinfo --html --ifinfo --no-split --output=nco.html nco.texi
makeinfo --no-split --output=nco.info nco.texi
makeinfo --no-headers --no-split --output=nco.txt nco.texi
makeinfo --xml --no-split --output=nco.xml nco.texi
makeinfo --docbook --no-split --output=nco.xml nco.texi
pdftotext nco.pdf nco.txt
ps2pdf -dMaxSubsetPct=100 -dCompatibilityLevel=1.2 -dSubsetFonts=true -dEmbedAllFonts=true nco.ps nco.pdf
texi2dvi --output=nco.dvi nco.texi 
texi2dvi --pdf --output=nco.pdf nco.texi
texi2html -monolithic -verbose nco.texi
texi2html -l2h -l2h_tmp=./l2h_tmp -monolithic -verbose nco.texi # Invoke latex2html
# 20130806 Copy CMIP5 images (takes additional time)
cd ~/nco/doc/xmp;/usr/bin/scp fgr*.png fgr*.eps zender,nco@web.sf.net:/home/project-web/nco/htdocs/xmp;cd -
# 20120203 Copy all nco.html PNG images (takes additional time)
cd ~/nco/doc;/usr/bin/scp nco_*.png zender,nco@web.sf.net:/home/project-web/nco/htdocs;cd -
# 20130801 Copy nco.texi to Ubuntu machine for quick build-tests
scp ~/nco/doc/nco.texi givre.ess.uci.edu:nco/doc

NB: @cindex references in footnotes propagate to PDF file, not to
    HTML files, bug-report sent to makeinfo people 20040229

Producing HTML, makeinfo vs. texi2html:
makeinfo: Better format overall 
          Uses node names for cross references and index
          Acronyms look better
          Excludes @ifinfo sections by default (override with --ifinfo)
texi2html: Index sub-divided by first character
           More fancy options (e.g., latex2html), though none very useful 
           Misprints title
           Includes @ifinfo sections by default

Official TeXInfo documentation:
http://www.gnu.org/software/texinfo/manual/texinfo/texinfo.html

Legend (defined in &quot;highlighting&quot; section of TeXInfo manual):
@b{}: Selects bold face
@i{}: Selects an italic font
@r{}: Selects a Roman font (usefule in example-like environments to have comments in Roman)
@t{}: Selects the fixed-width font used by @code{}
@sansserif{}: Selects a sanserif font
@slanted{}: Selects a slanted font
@caption{}: Caption of floating figures
@code{}: Program text, e.g., @code{if(foo) x=y;}
@command{}: Commands, e.g., @command{ncra}
@dfn{}: Define use of term, e.g., @dfn{supercalifragilisticexpialidocious}
@email{}: E-mail address, e.g., @email{surname at uci dot edu}
@emph{}: Emphasize text, e.g., @emph{important}
@env{}: Environment variable, e.g., @env{HOME}
@file{}: Filename, e.g., @file{in.nc}
@float: Environment for TeX floating figures (e.g., @float Figure,fgr:glb)
@image{drc/nm,sz} Directory, filename (w/o suffix) and figure horizontal size
@html: Text until @end html passed without translation
@ifhtml: Text until @end ifhtml passed with translation
@kbd{}: Keyboard input, e.g., @kbd{ncra in.nc out.nc}
@key{}: Key name, e.g., @key{ESC} (rarely needed)
@option{}: Command-line option, e.g., @option{--dbg}
@samp{}: Extended commands, character sequences, e.g., @samp{ncra in.nc out.nc}
@uref{}: URL with optional alternate text, e.g., @uref{http://nco.sf.net,NCO homepage}
@url{}: URL, synonym for @uref
@var{}: Metasyntactic variable, e.g., @var{fl_in}
@verbatim: Anything goes inside environment (no @'s needed to protect special characters like braces)
@verbatiminclude: Insert contents of file here, e.g., @verbatiminclude{nco.sh}
@example: Quoted environment (@'s needed to protect special characters like braces)
@w{}: Unbreakable text, e.g., @w{of 1}

Use '@*' to force hard carriage return
Use '@:', after periods, questions marks, exclamation marks, or colons
that do not end sentences, e.g., 'vs.@:'
Use '@.', '@!', and `@?' to end sentences that end with single capital letters (e.g., initials)

Outline Hierarchy:
@section
@subsection
@unnumberedsubsec

Resources:
Octave TeXInfo manual shows clean TeXInfo structure
/usr/share/doc/octave-2.1.34/interpreter/octave.texi
</ignore>

<!-- c Start of header -->

<!-- c No variables may be defined before TeXInfo @setfilename header -->
<setfilename file="nco.info" spaces=" ">nco.info</setfilename>

<!-- c Define edition, date, ... -->
<set name="nco-edition" line=" nco-edition 5.2.9-alpha02">5.2.9-alpha02</set>
<set name="doc-edition" line=" doc-edition 5.2.9-alpha02">5.2.9-alpha02</set>
<set name="copyright-years" line=" copyright-years 1995--2024">1995--2024</set>
<set name="update-year" line=" update-year 2024">2024</set>
<set name="update-date" line=" update-date 4 October 2024">4 October 2024</set>
<set name="update-month" line=" update-month October 2024">October 2024</set>

<settitle spaces=" "><acronym><acronymword>NCO</acronymword></acronym> 5.2.9-alpha02 User Guide</settitle>

<!-- c Uncomment following line to produce guide in smallbook format -->
<!-- c @smallbook -->
<!-- c Merge function index into concept index -->
<syncodeindex spaces=" " from="fn" to="cp" line="fn cp"></syncodeindex>

<!-- c 20090226 Add bibliography capabilities as per -->
<!-- c http://lists.gnu.org/archive/html//help-texinfo/2004-12/txtPW9h_VG8ez.txt -->
<!-- c % csz 20100313 remove next line to prevent "\input texinfo" from -->
<!-- c % appearing in printed output -->
<!-- c %% \input texinfo   @c -*-texinfo-*- -->

<!-- c %% my-bib-macros.texi - Texinfo macros providing a crude -->
<!-- c %% bibliography and citation capability. -->

<!-- c % Copyright (C) 2004  Aaron S. Hawley -->

<!-- c % Author: Aaron S. Hawley <ashawley@gnu.uvm.edu> -->
<!-- c % Keywords: docs, texinfo, extensions, bib -->

<!-- c % This file is free software; you can redistribute it and/or modify -->
<!-- c % it under the terms of the GNU General Public License as published by -->
<!-- c % the Free Software Foundation; either version 2, or (at your option) -->
<!-- c % any later version. -->

<!-- c % This file is distributed in the hope that it will be useful, -->
<!-- c % but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- c % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -->
<!-- c % GNU General Public License for more details. -->

<!-- c % You should have received a copy of the GNU General Public License -->
<!-- c % along with GNU Emacs; see the file COPYING.  If not, write to -->
<!-- c % the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -->
<!-- c % Boston, MA 02111-1307, USA. -->

<!-- c %% Commentary: -->

<!-- c %%% Introduction -->

<!-- c %% Creates references to a ``Bibliography'' or ``References'' -->
<!-- c %% section of a Texinfo document, using Texinfo's -->
<!-- c %% macro system.  Although not as terse a way to cite systems as is -->
<!-- c %% found in document systems like TeX, the format is simpler and -->
<!-- c %% the rendering  is easier for non-academic readers. -->

<!-- c % -->

<!-- c %%% Usage -->

<!-- c %% References to cited works can be put in any section of a document. -->
<!-- c %% The cited works must be put in either a Texinfo table (for -->
<!-- c %% instance with ``@table @asis ... @end table'') or within a -->
<!-- c %% Texinfo list (something like ``@enumerate ... @end enumerate'' -->
<!-- c %% or ``@itemize @bullet ... @end itemize'').  They are created -->
<!-- c %% with the command ``@mybibitem{REF-NAME}''.  To cite a reference -->
<!-- c %% with a @mybibitem use ``@mybibcite{REF-NAME}''. -->

<!-- c %% The beginning of a document must include (using the @include -->
<!-- c %% command) the file my-bib-macros.texi, which should be made -->
<!-- c %% available in the current directory of the parent file.  A single -->
<!-- c %% call should be made to choose to use a list or a table.  The -->
<!-- c %% command to chose is called @mybibuselist{NODE}, where NODE is -->
<!-- c %% the node containing the location where the references are listed. -->

<!-- c % -->

<!-- c %%% Example -->

<!-- c %% \input texinfo   @c -*-texinfo-*- -->
<!-- c %% @comment %**start of header -->
<!-- c %% @setfilename my-file-with-bib.info -->
<!-- c %% @settitle Texinfo with a Bibliography and References -->
<!-- c %% -->
<!-- c %% @include my-bib-macros.texi -->
<!-- c %% @mybibuselist{References} -->
<!-- c %% -->
<!-- c %% @comment %**end of header -->
<!-- c %% -->
<!-- c %% @node Top -->
<!-- c %% @top Top -->
<!-- c %% -->
<!-- c %% @menu -->
<!-- c %% * Introduction:: -->
<!-- c %% * @mybibnode{}:: -->
<!-- c %% -->
<!-- c %% @end menu -->
<!-- c %% -->
<!-- c %% @node Introduction -->
<!-- c %% @chapter Introduction -->
<!-- c %% -->
<!-- c %% The ability of a documentation format to make cross references to a -->
<!-- c %% bibliography, a feature of LaTeX @mybibcite{LaTeX2e}, isn't -->
<!-- c %% currently supported in Texinfo. -->
<!-- c %% -->
<!-- c %% @node @mybibnode{} -->
<!-- c %% @chapter References -->
<!-- c %% -->
<!-- c %% @itemize @asis -->
<!-- c %% -->
<!-- c %% @mybibitem{LaTeX2e} Leslie Lamport, LaTeX User's Guide and -->
<!-- c %% Reference Manual, 2nd edition, Addison-Wesley, Reading, -->
<!-- c %% Massachusetts, 1994. -->
<!-- c %% -->
<!-- c %% @end itemize -->
<!-- c %% -->
<!-- c %% @bye -->

<!-- c %% -->

<!-- c %% This example produces (in Info): -->

<!-- c %%       1 Introduction -->
<!-- c %%       ************** -->
<!-- c %% -->
<!-- c %%       The ability of a documentation format to make cross -->
<!-- c %%       references to a bibliography, a feature of LaTeX (See item -->
<!-- c %%       [LaTeX2e] in *Note LaTeX2e: References.), is not currently -->
<!-- c %%       supported in Texinfo. -->
<!-- c %% -->
<!-- c %% -->
<!-- c %%       2 References -->
<!-- c %%       ************ -->
<!-- c %% -->
<!-- c %%       [LaTeX2e] Leslie Lamport, LaTeX User's Guide and Reference -->
<!-- c %%       Manual, 2nd edition, Addison-Wesley, Reading, -->
<!-- c %%       Massachusetts, 1994. -->

<!-- c %% and (in printed output): -->

<!-- c %%       1 Introduction -->
<!-- c %%       ************** -->
<!-- c %% -->
<!-- c %%       The ability of a documentation format to make cross -->
<!-- c %%       references to a bibliography, a feature of LaTeX (See item -->
<!-- c %%       [LaTeX2e] in Chapter 2 [References], page 3.), is not -->
<!-- c %%       currently supported in Texinfo. -->
<!-- c %% -->
<!-- c %% -->
<!-- c %%       2 References -->
<!-- c %%       ************ -->
<!-- c %% -->
<!-- c %%       [LaTeX2e] Leslie Lamport, LaTeX User's Guide and Reference -->
<!-- c %%       Manual, 2nd edition, Addison-Wesley, Reading, -->
<!-- c %%       Massachusetts, 1994. -->

<!-- c % -->

<!-- c %%% Notes -->

<!-- c %% The pointers to references will be functional in hypertext -->
<!-- c %% documentation (info, HTML, XML and others) and properly rendered -->
<!-- c %% in print documents, because they are implemented with Texinfo's -->
<!-- c %% cross referencing capabilities (using @anchor and @ref).  Failures -->
<!-- c %% by an author to make proper references with ``my-bib-macros'' in -->
<!-- c %% their document will give cross referencing errors by Texinfo -->
<!-- c %% conversion tools. -->

<!-- c %% Only one ``Reference'' section is allowed per document. -->

<!-- c %% An improvement of this system would create cross references -->
<!-- c %% (with @xref) at each cited work to all the originating cross -->
<!-- c %% refererences. -->

<!-- c % -->

<!-- c %% Code: -->

<!-- c % Configuration Options -->

<!-- c %% @mybibsetrefnode : Defines the name of the node to contain -->
<!-- c %% references. -->

<macro name="mybibsetrefnode" line=" mybibsetrefnode{node}" endspaces=" "><formalarg>node</formalarg>
@set mybibrefnode \node\
</macro>

<!-- c %% @mybibnode{} : Macro to be placed at node containing references -->
<!-- c %% and calls to @mybibcite{} -->

<macro name="mybibnode" line=" mybibnode{}" endspaces=" ">
@value{mybibrefnode}
</macro>

<!-- c %% @mybibusetable : Whether each @mybibitem will be put in a -->
<!-- c %% table. -->

<macro name="mybibusetable" line=" mybibusetable{node}" endspaces=" "><formalarg>node</formalarg>
@set mybibtable true
@ifset mybiblist
@clear mybiblist
@end ifset
@mybibsetrefnode{\node\}
</macro>

<!-- c %% @mybibuselist : Whether each @mybibitem will be put in a -->
<!-- c %% list. -->

<macro name="mybibuselist" line=" mybibuselist{node}" endspaces=" "><formalarg>node</formalarg>
@set mybiblist true
@ifset mybibtable
@clear mybibtable
@end ifset
@mybibsetrefnode{\node\}
</macro>


<!-- c %% @mybibcite{REF} : Cites the cross reference REF. -->

<macro name="mybibcite" line=" mybibcite{ref}" endspaces=" "><formalarg>ref</formalarg>
@ifclear mybibrefnode
@mybibmakeref{mybibsetrefnode was not used, \ref\}
@end ifclear
@c %**else if
@ifset mybibrefnode
@mybibmakeref{@mybibnode{}, \ref\}
@end ifset

</macro>

<macro name="mybibmakeref" line=" mybibmakeref{node, ref}" endspaces=" "><formalarg>node</formalarg><formalarg>ref</formalarg>
(See item [\ref\] in @ref{\node\, \ref\}.)
</macro>

<!-- c %% @mybibcite{REF} : Creates a cross referenced citation REF. -->

<macro name="mybibitem" line=" mybibitem{ref}" endspaces=" "><formalarg>ref</formalarg>
@ifclear mybiblist
@ifclear mybibtable
@set mybiblist true
@end ifclear
@end ifclear
@ifset mybiblist
@item
@anchor{\ref\}[\ref\]
@end ifset
@c %**else if
@ifset mybibtable
@item @anchor{\ref\}[\ref\]
@end ifset

</macro>

<!-- c %% my-bib-macros.texi ends here -->
<set name="mybiblist" line=" mybiblist true">true</set>
<set name="mybibrefnode" line=" mybibrefnode References">References</set>

<!-- c 20150616 Add version info as per -->
<!-- c http://www.gnu.org/software/automake/manual/html_node/Texinfo.html -->
<!-- c Seems to require running automake -add-missing on local machine -->
<!-- c Nightmare because it means clients must run autoconf! Fuggetaboutit -->
<!-- c @include version.texi -->

<!-- c end of header -->

<!-- c TeXInfo macros may not appear before TeXInfo @setfilename header -->
<!-- c [idx] Index -->
<macro name="idx" line=" idx {}" endspaces=" ">
i
</macro>
<!-- c [m s-1] Meridional wind speed -->
<macro name="wndmrd" line=" wndmrd {}" endspaces=" ">
v
</macro>
<!-- c [m s-1] Zonal wind speed -->
<macro name="wndznl" line=" wndznl {}" endspaces=" ">
u
</macro>
<macro name="xxx" line=" xxx {}" endspaces=" ">
x
</macro>
<!-- c [K] Temperature -->
<macro name="tpt" line=" tpt {}" endspaces=" ">
T
</macro>
<!-- c TeX macros may appear anywhere after line 1 -->
<tex endspaces=" ">
% Define TeX macros to roughly correspond to LaTeX style files
% Use \gdef instead of \def to make definition persistent across TeX blocks
% These should be consistent with any TeXInfo macros
% 0. Alphabet
\gdef\ddd{d} % [ltr] d
\gdef\iii{i} % [ltr] i
\gdef\jjj{j} % [ltr] j
\gdef\kkk{k} % [ltr] k
\gdef\qqq{q} % [ltr] q
\gdef\sss{s} % [ltr] s
\gdef\vvv{v} % [ltr] v
\gdef\xxx{x} % [ltr] x
\gdef\yyy{y} % [ltr] y
% 1. Primary commands
\gdef\cod{{\rm CO}_{2}} % [frc] Math pi
\gdef\dfr{{\rm d}} % [frc] Math differential fxm: upright
\gdef\dmnidx{n} % [idx] Dimension index
\gdef\clmnbr{I} % [nbr] Column number
\gdef\rownbr{J} % [nbr] Row number
\gdef\dmnnbr{N} % [nbr] Dimension number
\gdef\dmn{D} % [dmn] Variable dimension
\gdef\frcdst{f} % [flg] Destination grid fraction
\gdef\frcsgs{s} % [flg] Sub-gridscale fraction
\gdef\idx{i} % [idx] Index
\gdef\lmnidx{i} % [idx] Element index
\gdef\lmnnbr{N} % [nbr] Number of elements in input hyperslab
\gdef\me{{\rm e}} % [frc] Math e fxm: upright
\gdef\mi{{\rm i}} % [frc] Math i fxm: upright
\gdef\mpi{\pi} % [frc] Math pi
\gdef\mpp{\cal{M}} % [map] Map
\gdef\mskflg{m} % [flg] Mask flag
\gdef\mssflg{\mu} % [flg] Missing value flag
\gdef\outnbr{J} % [nbr] Number of elements in output hyperslab
\gdef\prmsbs{\prime} % [sbs] Prime subscript
\gdef\psl{\epsilon} % [frc] epsilon
\gdef\rdridx{r} % [idx] Re-order index
\gdef\rdrnbr{R} % [nbr] Re-order number
\gdef\rdr{R} % [dmn] Re-order dimension
\gdef\shridx{s} % [idx] Share index
\gdef\shrnbr{S} % [nbr] Share number
\gdef\shr{S} % [dmn] Share dimension
\gdef\tllnbr{M} % [nbr] Tally (number of valid elements in input hyperslab)
\gdef\tm{t} % [s] Time
\gdef\wgt{w} % [frc] Weight
\gdef\wndmrd{v} % [m s-1] Meridional wind speed
\gdef\wndznl{u} % [m s-1] Zonal wind speed

% 2. Derived commands
\gdef\pslavg{\bar{\epsilon}} % [frc] Mean error
\gdef\pslmax{\epsilon_{\rm max}} % [frc] Maximum error
\gdef\pslmin{\epsilon_{\rm min}} % [frc] Minimum error
\gdef\pslmabs{\epsilon_{\rm mabs}^{+}} % [frc] Maximum absolute error
\gdef\pslmibs{\epsilon_{\rm mibs}^{+}} % [frc] Minimum absolute error
\gdef\pslmebs{\bar{\epsilon}^{+}} % [frc] Mean absolute error
\gdef\dmnvct{{\bf \dmn}} % [vct] Dimension vector
\gdef\dmnprm{\dmn^{\prmsbs}} % [vct] Dimension prime
\gdef\dmnsubnnn{\dmn_{\dmnidx}} % [dmn] Dimension sub nnn
\gdef\shrsubnnn{\shr_{\dmnidx}} % [dmn] Share dimension sub nnn
\gdef\shrsubsss{\shr_{\shridx}} % [dmn] Share dimension sub sss
\gdef\dmnsubnnnprm{\dmn_{\dmnidx}^{\prmsbs}} % [vct] Dimension prime sub nnn 
\gdef\dmnvctprm{{\bf \dmn}^{\prmsbs}} % [vct] Dimension vector prime
\gdef\rdrvct{{\bf \rdr}} % [vct] Re-order vector
\gdef\shrvct{{\bf \shr}} % [vct] Share vector
\gdef\xxxprm{\xxx^{\prmsbs}} % [ltr] x prime

% 3. Doubly derived commands

</tex>

<!-- c install-info installs NCO info into this category -->
<dircategory spaces=" ">netCDF</dircategory>
<direntry endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>NCO</menunode><menuseparator>::        </menuseparator><menudescription><pre xml:space="preserve">User Guide for the netCDF Operator suite
</pre></menudescription></menuentry></direntry>

<!-- c Set smallbook if printing in smallbook format -->
<!-- c Example of smallbook font is actually written using smallbook -->
<!-- c In bigbook, a kludge is used for TeX output -->
<!-- c set smallbook -->
<clear name="smallbook" line=" smallbook"></clear>

<tex endspaces=" ">
% fxm: Try to get thumbnails working with texinfo --pdf -generated PDF files
% \input thumbpdf.sty
% Experiment with smaller amounts of whitespace between chapters and sections
\global\chapheadingskip = 15pt plus 4pt minus 2pt 
\global\secheadingskip = 12pt plus 3pt minus 2pt
\global\subsecheadingskip = 9pt plus 2pt minus 2pt
</tex>

<!-- c Experiment with smaller amounts of whitespace between paragraphs in the 8.5 by 11 inch format -->
<tex endspaces=" ">
\global\parskip 6pt plus 1pt
</tex>

<!-- c Uncomment next line to remove ugly TeX warning blocks from overfull hboxes -->
<finalout></finalout>

<para>This file documents <acronym><acronymword>NCO</acronymword></acronym>, a collection of utilities to
manipulate and analyze netCDF files.
</para>
<para>Copyright &copyright; 1995&textndash;2024 Charlie Zender
</para>
<para>This is the first edition of the <cite>NCO User Guide</cite>,&linebreak;
and is consistent with <w>version 2</w> of <file>texinfo.tex</file>.
</para>
<para>Permission is granted to copy, distribute and/or modify this document 
under the terms of the <acronym><acronymword>GNU</acronymword></acronym> Free Documentation License, <w>Version 1.3</w>
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. The license is available online at 
<uref><urefurl>http://www.gnu.org/copyleft/fdl.html</urefurl></uref>
</para>
<para>The original author of this software, Charlie Zender, wants to improve it
with the help of your suggestions, improvements, bug-reports, and patches.&linebreak;
Charlie Zender &lt;surname at uci dot edu&gt; (yes, my surname is zender)&linebreak;
3200 Croul Hall&linebreak;
Department of Earth System Science&linebreak;
University of California, Irvine&linebreak;
Irvine, CA 92697-3100&linebreak;
</para>
<ignore endspaces=" ">
Permission is granted to process this file through TeX and print the 
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
</ignore>

<setchapternewpage spaces=" " value="odd" line="odd"></setchapternewpage>

<titlepage endspaces=" ">
<html endspaces=" ">
&lt;meta name=&quot;Author&quot; content=&quot;Charlie Zender&quot;&gt;
&lt;meta name=&quot;Keywords&quot; content=&quot;NCO documentation, NCO User Guide,
netCDF, operator, GCM, CCM, scientific data, ncbo, ncchecker, ncclimo, ncfe, ncecat,
ncflint, ncks, ncra, ncrcat, ncremap, ncrename, ncwa&quot;&gt;
</html>
<html endspaces=" ">
&lt;body text=&quot;#000000&quot; link=&quot;#0000EF&quot; vlink=&quot;#008080&quot; alink=&quot;#FF0000&quot;&gt;
&lt;font face=&quot;Arial&quot;&gt;
</html>
<title spaces=" ">NCO User Guide</title>
<subtitle spaces=" ">A suite of netCDF operators</subtitle>
<subtitle spaces=" ">Edition 5.2.9-alpha02, for <acronym><acronymword>NCO</acronymword></acronym> Version 5.2.9-alpha02</subtitle>
<subtitle spaces=" ">October 2024</subtitle>

<author spaces=" ">by Charlie Zender</author>
<author spaces=" ">Departments of Earth System Science and Computer Science</author>
<author spaces=" ">University of California, Irvine</author>
<html endspaces=" ">
&lt;p&gt;WWW readers: Having trouble finding the section you want?&lt;/p&gt; 
&lt;p&gt;Search for keywords in the &lt;a href=&quot;#index&quot;&gt;(hyper) index&lt;/a&gt; at the end&lt;/p&gt;
</html>

<!-- c Include Distribution inside titlepage so that headings are turned off -->
<page></page>
<vskip> 0pt plus 1filll</vskip>
<para>Copyright &copyright; 1995&textndash;2024 Charlie Zender.
</para>
<sp spaces=" " value="2" line="2"></sp>
<para>This is the first edition of the <cite>NCO User Guide</cite>,&linebreak;
and is consistent with <w>version 2</w> of <file>texinfo.tex</file>.
</para><sp spaces=" " value="2" line="2"></sp>

<para>Published by Charlie Zender&linebreak;
Department of Earth System Science&linebreak;
3200 Croul Hall&linebreak;
University of California, Irvine&linebreak;
Irvine, CA 92697-3100 USA&linebreak;
</para>
<para>Permission is granted to copy, distribute and/or modify this document
under the terms of the <acronym><acronymword>GNU</acronymword></acronym> Free Documentation License, <w>Version 1.3</w>
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. The license is available online at 
<uref><urefurl>http://www.gnu.org/copyleft/fdl.html</urefurl></uref>
</para><sp spaces=" " value="2" line="2"></sp>
<para>We gratefully acknowledge support for <acronym><acronymword>NCO</acronymword></acronym> development and
maintenance provided by these institutions and programs:
<acronym><acronymword>DOE</acronymword></acronym> <acronym><acronymword>ACME</acronymword></acronym> <acronym><acronymword>DE-SC0012998</acronymword></acronym>,
<acronym><acronymword>LLNL-B625903</acronymword></acronym>, <acronym><acronymword>LLNL-B632442</acronymword></acronym>, 
<acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>ACCESS</acronymword></acronym> <acronym><acronymword>NNX12AF48A</acronymword></acronym> and
<acronym><acronymword>NNX14AH55A</acronymword></acronym>, and <acronym><acronymword>NSF</acronymword></acronym> <acronym><acronymword>SEI</acronymword></acronym>
<acronym><acronymword>IIS-0431203</acronymword></acronym>, <acronym><acronymword>AGS-1541031</acronymword></acronym>, and <acronym><acronymword>OAC-2004993</acronymword></acronym>. 
This research was supported as part of the Energy Exascale Earth System
Model (<acronym><acronymword>E3SM</acronymword></acronym>) project, formerly known as Accelerated Climate
Modeling for Energy (<acronym><acronymword>ACME</acronymword></acronym>),
funded by the U.S. Department of Energy, Office of Science, Office of
Biological and Environmental Research.
This material is based upon work supported by the National Science
Foundation.
</para><sp spaces=" " value="2" line="2"></sp>
<para>The original author of this software, Charlie Zender, wants to improve it
with the help of your suggestions, improvements, bug-reports, and patches.&linebreak;
Charlie Zender &lt;surname at uci dot edu&gt; (yes, my surname is zender)&linebreak;
Department of Earth System Science&linebreak;
3200 Croul Hall&linebreak;
University of California, Irvine&linebreak;
Irvine, CA 92697-3100&linebreak;
</para><sp spaces=" " value="2" line="2"></sp>
</titlepage>

<!-- c Print table of contents -->
<contents></contents>

<node name="Top" spaces=" "><nodename>Top</nodename><nodenext spaces=" ">Foreword</nodenext><nodeprev spaces=" ">(dir)</nodeprev><nodeup spaces=" ">(dir)</nodeup></node>
<top spaces=" "><sectiontitle>NCO User Guide</sectiontitle>
<!-- c node format: node-name, next, previous, up -->

<para><emph>Note to readers of the NCO User Guide in Info format</emph>: 
<emph>The <uref><urefurl>./nco.pdf</urefurl><urefdesc>NCO User Guide in PDF format</urefdesc></uref>
(also on <uref><urefurl>http://nco.sf.net/nco.pdf</urefurl><urefdesc>SourceForge</urefdesc></uref>)
contains the complete <acronym><acronymword>NCO</acronymword></acronym> documentation.</emph>
This Info documentation is equivalent except it refers you to the 
printed (i.e., DVI, PostScript, and PDF) documentation for description 
of complex mathematical expressions. 
</para>
<para>The netCDF Operators, or <acronym><acronymword>NCO</acronymword></acronym>, are a suite of programs known as 
operators. 
The operators facilitate manipulation and analysis of data stored in the 
self-describing netCDF format, available from
(<uref><urefurl>http://www.unidata.ucar.edu/software/netcdf</urefurl></uref>).
Each <acronym><acronymword>NCO</acronymword></acronym> operator (e.g., <command>ncks</command>) takes netCDF input
file(s), performs an operation (e.g., averaging, hyperslabbing, or
renaming), and outputs a processed netCDF file. 
Although most users of netCDF data are involved in scientific research,
these data formats, and thus <acronym><acronymword>NCO</acronymword></acronym>, are generic and are equally
useful in fields from agriculture to zoology.
The <acronym><acronymword>NCO</acronymword></acronym> User Guide illustrates <acronym><acronymword>NCO</acronymword></acronym> use with
examples from the field of climate modeling and analysis. 
The <acronym><acronymword>NCO</acronymword></acronym> homepage is <uref><urefurl>http://nco.sf.net</urefurl></uref>, and the 
source code is maintained at <uref><urefurl>http://github.com/nco/nco</urefurl></uref>.
</para>
<para>This documentation is for <acronym><acronymword>NCO</acronymword></acronym> version 5.2.9-alpha02.
It was last updated 4 October 2024.
Corrections, additions, and rewrites of this documentation are
gratefully welcome.
</para>
<para>Enjoy,&linebreak;
Charlie Zender
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Foreword</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Summary</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Introduction</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Strategies</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Shared features</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Reference Manual</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Contributing</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Quick Start</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>CMIP5 Example</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Parallel</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>CCSM Example</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>mybibnode</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>General Index</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;fwd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fwd --&gt;
</html>
</top>
<node name="Foreword" spaces=" "><nodename>Foreword</nodename><nodenext spaces=" ">Summary</nodenext><nodeprev spaces=" ">Top</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<unnumbered spaces=" "><sectiontitle>Foreword</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1">foreword</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2">Charlie Zender</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> is the result of software needs that arose while I worked
on projects funded by <acronym><acronymword>NCAR</acronymword></acronym>, <acronym><acronymword>NASA</acronymword></acronym>, and <acronym><acronymword>ARM</acronymword></acronym>.
Thinking they might prove useful as tools or templates to others,  
it is my pleasure to provide them freely to the scientific community.  
Many users (most of whom I have never met) have encouraged the
development of <acronym><acronymword>NCO</acronymword></acronym>.  
Thanks espcially to Jan Polcher, Keith Lindsay, Arlindo <w>da Silva</w>,
John Sheldon, and William Weibel for stimulating suggestions and
correspondence. 
Your encouragment motivated me to complete the <cite>NCO User Guide</cite>.
So if you like <acronym><acronymword>NCO</acronymword></acronym>, send me a note!
<w>I should</w> mention that <acronym><acronymword>NCO</acronymword></acronym> is not connected to or
officially endorsed by Unidata, <acronym><acronymword>ACD</acronymword></acronym>, <acronym><acronymword>ASP</acronymword></acronym>,
<acronym><acronymword>CGD</acronymword></acronym>, or Nike.&linebreak; 
</para><sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
May 1997&linebreak;
Boulder, Colorado&linebreak;
</para>
<sp spaces=" " value="2" line="2"></sp>
<para>Major feature improvements entitle me to write another Foreword.
In the last five years a lot of work has been done to refine
<acronym><acronymword>NCO</acronymword></acronym>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3">open source</indexterm></cindex>
<acronym><acronymword>NCO</acronymword></acronym> is now an open source project and appears to be much
healthier for it. 
The list of illustrious institutions that do not endorse <acronym><acronymword>NCO</acronymword></acronym>     
continues to grow, and now includes <acronym><acronymword>UCI</acronymword></acronym>.&linebreak; 
</para><sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
October 2000&linebreak;
Irvine, California&linebreak;
</para>
<sp spaces=" " value="2" line="2"></sp>
<para>The most remarkable advances in <acronym><acronymword>NCO</acronymword></acronym> capabilities in the last  
few years are due to contributions from the Open Source community.
Especially noteworthy are the contributions of Henry Butowsky and Rorik 
Peterson.&linebreak; 
</para><sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
January 2003&linebreak;
Irvine, California&linebreak;
</para>
<sp spaces=" " value="2" line="2"></sp>
<para><acronym><acronymword>NCO</acronymword></acronym> was generously supported from 2004&textndash;2008 by US 
National Science Foundation (<acronym><acronymword>NSF</acronymword></acronym>) grant 
<uref><urefurl>http://www.nsf.gov/awardsearch/showAward.do?AwardNumber=0431203</urefurl><urefdesc>IIS-0431203</urefdesc></uref>. 
This support allowed me to maintain and extend core <acronym><acronymword>NCO</acronymword></acronym> code,
and others to advance <acronym><acronymword>NCO</acronymword></acronym> in new directions: 
Gayathri Venkitachalam helped implement <acronym><acronymword>MPI</acronymword></acronym>;
Harry Mangalam improved regression testing and benchmarking;
Daniel Wang developed the server-side capability, <acronym><acronymword>SWAMP</acronymword></acronym>;
and Henry Butowsky, a long-time contributor, developed <command>ncap2</command>.
This support also led <acronym><acronymword>NCO</acronymword></acronym> to debut in professional journals
and meetings.  
The personal and professional contacts made during this evolution have
been immensely rewarding.&linebreak;
</para><sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
March 2008&linebreak;
Grenoble, France&linebreak;
</para>
<sp spaces=" " value="2" line="2"></sp>
<para>The end of the <acronym><acronymword>NSF</acronymword></acronym> <acronym><acronymword>SEI</acronymword></acronym> grant in August, 2008 curtailed
<acronym><acronymword>NCO</acronymword></acronym> development.  
Fortunately we could justify supporting Henry Butowsky on other research  
grants until May, 2010 while he developed the key <command>ncap2</command>
features used in our climate research.
And recently the <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>ACCESS</acronymword></acronym> program commenced
funding us to support netCDF4 group functionality.
Thus <acronym><acronymword>NCO</acronymword></acronym> will grow and evade bit-rot for the foreseeable
future. 
</para>
<para>I continue to receive with gratitude the thanks of <acronym><acronymword>NCO</acronymword></acronym> users
at nearly every scientific meeting I attend.  
People introduce themselves, shake my hand and extol <acronym><acronymword>NCO</acronymword></acronym>,
often effusively, while I grin in stupid embarassment. 
These exchanges lighten me like anti-gravity.
Sometimes I daydream how many hours <acronym><acronymword>NCO</acronymword></acronym> has turned from grunt
work to productive research for researchers world-wide, or from research
into early happy-hours. 
It&textrsquo;s a cool feeling.
</para>
<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
April, 2012&linebreak;
Irvine, California&linebreak;
</para>
<sp spaces=" " value="2" line="2"></sp>
<!-- c 20150619 Test values automagically installed by version.texi, which is a nightmare -->
<!-- c Test print @value{EDITION}, @value{VERSION}, @value{UPDATED}, @value{UPDATED-MONTH}. -->
<para>The <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>ACCESS</acronymword></acronym> 2011 program generously supported 
(Cooperative Agreement NNX12AF48A) <acronym><acronymword>NCO</acronymword></acronym> from 2012&textndash;2014.
This allowed us to produce the first iteration of a Group-oriented 
Data Analysis and Distribution (<acronym><acronymword>GODAD</acronymword></acronym>) software ecosystem. 
Shifting more geoscience data analysis to <acronym><acronymword>GODAD</acronymword></acronym> is a 
long-term plan.
Then the <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>ACCESS</acronymword></acronym> 2013 program agreed to
support (Cooperative Agreement NNX14AH55A) <acronym><acronymword>NCO</acronymword></acronym> from
2014&textndash;2016.  
This support permits us to implement support for Swath-like Data
(<acronym><acronymword>SLD</acronymword></acronym>).
Most recently, the <acronym><acronymword>DOE</acronymword></acronym> has funded me to implement 
<acronym><acronymword>NCO</acronymword></acronym> re-gridding and parallelization in support of their 
<acronym><acronymword>ACME</acronymword></acronym> program.
After many years of crafting <acronym><acronymword>NCO</acronymword></acronym> as an after-hours hobby,
I finally have the cushion necessary to give it some real attention. 
And I&textrsquo;m looking forward to this next, and most intense yet, phase of
<acronym><acronymword>NCO</acronymword></acronym> development.
</para><sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
June, 2015&linebreak;
Irvine, California&linebreak;
</para>
<para>The <acronym><acronymword>DOE</acronymword></acronym> Energy Exascale Earth System Model (<acronym><acronymword>E3SM</acronymword></acronym>)
project (formerly <acronym><acronymword>ACME</acronymword></acronym>) has generously supported <acronym><acronymword>NCO</acronymword></acronym>
development for the past four years.
Supporting <acronym><acronymword>NCO</acronymword></acronym> for a mission-driven, high-performance
climate model development effort has brought unprecedented challenges 
and opportunities.
After so many years of staid progress, the recent development speed
has been both exhilirating and terrifying.
</para>
<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
May, 2019&linebreak;
Laguna Beach, California&linebreak;
</para>
<para>The <acronym><acronymword>DOE</acronymword></acronym> <acronym><acronymword>E3SM</acronymword></acronym> project has supported <acronym><acronymword>NCO</acronymword></acronym>
development and maintenance since 2015. 
This is an eternity in the world of research funding!
Their reliable support has enabled us to add cutting-edge features
including quantization, vertical interpolation, and support for
multiple regridding weight-generators.
Recently <acronym><acronymword>NSF</acronymword></acronym> supported us to enable user-friendly support
for modern compression algorithms that can make geoscience data 
analysis greener by reducing dataset size, and thereby storage,
power, and associated greenhouse gas emissions.
I am grateful for this this agency support that inspires me to create
new features that help my amazing colleagues pursue their scientific
ideas.  
</para>
<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent>
<para>Charlie Zender&linebreak;
July, 2022&linebreak;
Laguna Beach, California&linebreak;
<ignore endspaces=" ">
</ignore>
</para>
<html endspaces=" ">
&lt;a name=&quot;smr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#smr --&gt;
</html>
</unnumbered>
<node name="Summary" spaces=" "><nodename>Summary</nodename><nodenext spaces=" ">Introduction</nodenext><nodeprev spaces=" ">Foreword</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<unnumbered spaces=" "><sectiontitle>Summary</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="4">operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="5">summary</indexterm></cindex>
<para>This manual describes <acronym><acronymword>NCO</acronymword></acronym>, which stands for netCDF Operators.
<acronym><acronymword>NCO</acronymword></acronym> is a suite of programs known as <dfn>operators</dfn>.
Each operator is a standalone, command line program executed at the
shell-level like, e.g., <command>ls</command> or <command>mkdir</command>.  
The operators take netCDF files (including <acronym><acronymword>HDF5</acronymword></acronym> files
constructed using the netCDF <acronym><acronymword>API</acronymword></acronym>) as input, perform an
operation (e.g., averaging or hyperslabbing), and produce a netCDF file 
as output.  
The operators are primarily designed to aid manipulation and analysis of 
data.
The examples in this documentation are typical applications of the
operators for processing climate model output. 
This stems from their origin, though the operators are as general as
netCDF itself.
</para>
<html endspaces=" ">
&lt;a name=&quot;ntr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ntr --&gt;
</html>
</unnumbered>
<node name="Introduction" spaces=" "><nodename>Introduction</nodename><nodenext spaces=" ">Strategies</nodenext><nodeprev spaces=" ">Summary</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>Introduction</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="6">introduction</indexterm></cindex>

<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Availability</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>How to Use This guide</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Compatability</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Symbolic Links</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Libraries</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>netCDF2/3/4 and HDF4/5 Support</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Help Requests and Bug Reports</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="Availability" spaces=" "><nodename>Availability</nodename><nodenext spaces=" ">How to Use This guide</nodenext><nodeprev spaces=" ">Introduction</nodeprev><nodeup spaces=" ">Introduction</nodeup></node>
<section spaces=" "><sectiontitle>Availability</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="7"><acronym><acronymword>NCO</acronymword></acronym> availability</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="8">source code</indexterm></cindex>
<para>The complete <acronym><acronymword>NCO</acronymword></acronym> source distribution is currently distributed
as a <dfn>compressed tarfile</dfn> from
<uref><urefurl>http://sf.net/projects/nco</urefurl></uref>
and from
<uref><urefurl>http://dust.ess.uci.edu/nco/nco.tar.gz</urefurl></uref>.
The compressed tarfile must be uncompressed and untarred before building
<acronym><acronymword>NCO</acronymword></acronym>.
Uncompress the file with <samp>gunzip nco.tar.gz</samp>. 
Extract the source files from the resulting tarfile with <samp>tar -xvf
nco.tar</samp>.    
<acronym><acronymword>GNU</acronymword></acronym> <code>tar</code> lets you perform both operations in one step
with <samp>tar -xvzf nco.tar.gz</samp>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="9">documentation</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="10"><acronym><acronymword>WWW</acronymword></acronym> documentation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="11">on-line documentation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="12"><acronym><acronymword>HTML</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="13">&tex;info</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="14">Info</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="15"><cite>User Guide</cite></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="16"><cite>NCO User Guide</cite></indexterm></cindex>
<para>The documentation for <acronym><acronymword>NCO</acronymword></acronym> is called the 
<cite>NCO User Guide</cite>. 
The <cite>User Guide</cite> is available in <acronym><acronymword>PDF</acronymword></acronym>, Postscript,
<acronym><acronymword>HTML</acronymword></acronym>, <acronym><acronymword>DVI</acronymword></acronym>, &tex;info, and Info formats.
These formats are included in the source distribution in the files
<file>nco.pdf</file>, <file>nco.ps</file>, <file>nco.html</file>, <file>nco.dvi</file>,
<file>nco.texi</file>, and <file>nco.info*</file>, respectively.
All the documentation descends from a single source file,
<file>nco.texi</file>
<footnote spaces="   \n"><para>To produce these formats, <file>nco.texi</file> was simply run through the
freely available programs <code>texi2dvi</code>, <code>dvips</code>,
<code>texi2html</code>, and <code>makeinfo</code>.    
Due to a bug in &tex;, the resulting Postscript file, <file>nco.ps</file>,
contains the Table of Contents as the final pages. 
Thus if you print <file>nco.ps</file>, remember to insert the Table of
Contents after the cover sheet before you staple the manual.
</para></footnote>.
Hence the documentation in every format is very similar.
However, some of the complex mathematical expressions needed to describe
<command>ncwa</command> can only be displayed in <acronym><acronymword>DVI</acronymword></acronym>, Postscript, and 
<acronym><acronymword>PDF</acronymword></acronym> formats. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="17">publications</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="18">presentations</indexterm></cindex>
<para>A complete list of papers and publications on/about <acronym><acronymword>NCO</acronymword></acronym> 
is available on the <acronym><acronymword>NCO</acronymword></acronym> homepage.
Most of these are freely available. 
<!-- c 20130526 fxm Replace mybibnode with @mybibnode{} -->
<!-- c 20130526 Doing so, unfortunately, produces error "TeX capacity exceeded, sorry [input stack size=5000]." -->
<!-- c 20130526 Denude document of @mybibcite{} until it works -->
<!-- c The primary refereed publications are @mybibcite{ZeM06} and @mybibcite{Zen08}.  -->
The primary refereed publications are ZeM06 and Zen08. 
These contain copyright restrictions which limit their redistribution,
but they are freely available in preprint form from the <acronym><acronymword>NCO</acronymword></acronym>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="19"><acronym><acronymword>NCO</acronymword></acronym> homepage</indexterm></cindex>
<para>If you want to quickly see what the latest improvements in <acronym><acronymword>NCO</acronymword></acronym>
are (without downloading the entire source distribution), visit the
<acronym><acronymword>NCO</acronymword></acronym> homepage at 
<uref><urefurl>http://nco.sf.net</urefurl></uref>.
The <acronym><acronymword>HTML</acronymword></acronym> version of the <cite>User Guide</cite> is also available 
online through the World Wide Web at <acronym><acronymword>URL</acronymword></acronym>
<uref><urefurl>http://nco.sf.net/nco.html</urefurl></uref>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="20">netCDF</indexterm></cindex>
To build and use <acronym><acronymword>NCO</acronymword></acronym>, you must have netCDF installed.
The netCDF homepage is
<uref><urefurl>http://www.unidata.ucar.edu/software/netcdf</urefurl></uref>.
</para>
<para>New <acronym><acronymword>NCO</acronymword></acronym> releases are announced on the netCDF list 
and on the <code>nco-announce</code> mailing list 
<uref><urefurl>http://lists.sf.net/mailman/listinfo/nco-announce</urefurl></uref>.
</para>
<ignore endspaces=" ">
This tests incorporates an image using the @code{@@image} command.
@image{/data/zender/ps/odxc,6in,}
</ignore>

</section>
<node name="How-to-Use-This-guide" spaces=" "><nodename>How to Use This guide</nodename><nodenext spaces=" ">Compatability</nodenext><nodeprev spaces=" ">Availability</nodeprev><nodeup spaces=" ">Introduction</nodeup></node>
<section spaces=" "><sectiontitle>How to Use This Guide</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="21">contents</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="22">introduction</indexterm></cindex>
<para>Detailed instructions about
<uref><urefurl>http://nco.sf.net/#Source</urefurl><urefdesc spaces=" ">how to download the newest version</urefdesc></uref>, 
and <uref><urefurl>http://nco.sf.net/#bld</urefurl><urefdesc spaces=" ">how to complie source code</urefdesc></uref>,
as well as a <uref><urefurl>http://nco.sf.net/#FAQ</urefurl><urefdesc spaces=" "><acronym><acronymword>FAQ</acronymword></acronym></urefdesc></uref> and 
descriptions of <uref><urefurl>http://nco.sf.net/#bug</urefurl><urefdesc spaces=" ">Known Problems</urefdesc></uref> etc.
are on our homepage 
(<uref><urefurl>http://nco.sf.net/</urefurl></uref>).
</para>
<para>There are twelve operators in the current version (5.2.9-alpha02).
The function of each is explained in <ref label="Reference-Manual"><xrefnodename>Reference Manual</xrefnodename><xrefinfoname spaces=" ">Reference Manual</xrefinfoname></ref>.
Many of the tasks that <acronym><acronymword>NCO</acronymword></acronym> can accomplish are described during
the explanation of common <acronym><acronymword>NCO</acronymword></acronym> Features (<pxref label="Shared-features"><xrefnodename>Shared features</xrefnodename></pxref>).
More specific use examples for each operator can be seen by visiting the
operator-specific examples in the <ref label="Reference-Manual"><xrefnodename>Reference Manual</xrefnodename></ref>.
These can be found directly by prepending the operator name with the
<code>xmp_</code> tag, e.g., <uref><urefurl>http://nco.sf.net/nco.html#xmp_ncks</urefurl></uref>.
Also, users can type the operator name on the shell command line to 
see all the available options, or type, e.g., <samp>man ncks</samp> to see
a help man-page.
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> is a command-line language.
You may either use an operator after the prompt (e.g., <samp>$</samp> here),
like, 
</para><example endspaces=" ">
<pre xml:space="preserve">$ <command>operator</command> <option>[options]</option> <file>input</file> <file>[output]</file>
</pre></example>
<para>or write all commands lines into a shell script, as in
the <acronym><acronymword>CMIP5</acronymword></acronym> Example (<pxref label="CMIP5-Example"><xrefnodename>CMIP5 Example</xrefnodename></pxref>).
</para>
<para>If you are new to <acronym><acronymword>NCO</acronymword></acronym>, the Quick Start (<pxref label="Quick-Start"><xrefnodename>Quick Start</xrefnodename></pxref>)
shows simple examples about how to use <acronym><acronymword>NCO</acronymword></acronym> on different kinds
of data files.  
More detailed &textldquo;real-world&textrdquo; examples are in the
<ref label="CMIP5-Example"><xrefnodename>CMIP5 Example</xrefnodename><xrefinfoname spaces=" "><acronym><acronymword>CMIP5</acronymword></acronym> Example</xrefinfoname></ref>. 
The <ref label="General-Index"><xrefnodename>General Index</xrefnodename><xrefinfoname spaces=" ">Index</xrefinfoname></ref> is presents multiple keyword entries for
the same subject. 
If these resources do not help enough, please 
<pxref label="Help-Requests-and-Bug-Reports"><xrefnodename>Help Requests and Bug Reports</xrefnodename></pxref>.
</para>
</section>
<node name="Compatability" spaces=" "><nodename>Compatability</nodename><nodenext spaces=" ">Symbolic Links</nodenext><nodeprev spaces=" ">How to Use This guide</nodeprev><nodeup spaces=" ">Introduction</nodeup></node>
<section spaces=" "><sectiontitle>Operating systems compatible with <acronym><acronymword>NCO</acronymword></acronym></sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="23"><acronym><acronymword>OS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="24"><acronym><acronymword>IBM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="25"><acronym><acronymword>NEC</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="26"><acronym><acronymword>SGI</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="27"><acronym><acronymword>HP</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="28"><acronym><acronymword>DEC</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="29"><acronym><acronymword>PGI</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="30">Cray</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="31">Digital</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="32">Sun</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="33">Intel</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="34">Comeau</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="35">Compaq</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="36">Macintosh</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="37">Microsoft</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="38">Windows</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="39">PathScale</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="40">QLogic</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="41">compatability</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="42">portability</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="43">installation</indexterm></cindex>
<para>In its time on Earth, <acronym><acronymword>NCO</acronymword></acronym> has been successfully ported and
tested on so many 32- and 64-bit platforms that if we did not write
them down here we would forget their names:  
<!-- c alphabetize by OS name -->
<acronym><acronymword>IBM AIX</acronymword></acronym> 4.x, 5.x,
FreeBSD 4.x, 
<acronym><acronymword>GNU</acronymword></acronym>/Linux 2.x, LinuxPPC, LinuxAlpha, LinuxARM, LinuxSparc64,
LinuxAMD64, 
<acronym><acronymword>SGI IRIX</acronymword></acronym> 5.x and 6.x,
<w>MacOS X</w> 10.x, 
<acronym><acronymword>DEC OSF</acronymword></acronym>, 
<acronym><acronymword>NEC</acronymword></acronym> Super-UX 10.x, 
Sun SunOS 4.1.x, Solaris 2.x, 
<acronym><acronymword>Cray UNICOS</acronymword></acronym> 8.x&textndash;10.x,
and Microsoft Windows (95, 98, <acronym><acronymword>NT</acronymword></acronym>, 2000, <acronym><acronymword>XP</acronymword></acronym>, Vista,
7, 8, 10).
If you port the code to a new operating system, please send me a note 
and any patches you required.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="44"><acronym><acronymword>UNIX</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="45">Unidata</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="46">UDUnits</indexterm></cindex>
<para>The major prerequisite for installing <acronym><acronymword>NCO</acronymword></acronym> on a particular
platform is the successful, prior installation of the netCDF library
(and, as of 2003, the UDUnits library).
Unidata has shown a commitment to maintaining netCDF and UDUnits on all
popular <acronym><acronymword>UNIX</acronymword></acronym> platforms, and is moving towards full support for 
the Microsoft Windows operating system (<acronym><acronymword>OS</acronymword></acronym>).
Given this, the only difficulty in implementing <acronym><acronymword>NCO</acronymword></acronym> on a
particular platform is standardization of various <w>C</w>-language API
system calls. 
<acronym><acronymword>NCO</acronymword></acronym> code is tested for <acronym><acronymword>ANSI</acronymword></acronym> compliance by
compiling with <w>C99 compilers</w> including those from 
<cindex index="cp" spaces=" "><indexterm index="cp" number="47"><command>CC</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="48"><command>c++</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="49"><command>cc</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="50"><command>clang</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="51"><command>como</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="52"><command>cxx</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="53"><command>gcc</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="54"><command>g++</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="55"><command>icc</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="56"><command>MVS</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="57"><command>pgcc</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="58"><command>pgCC</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="59"><command>pathcc</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="60"><command>pathCC</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="61"><command>xlC</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="62"><command>xlc</command></indexterm></cindex>
<acronym><acronymword>GNU</acronymword></acronym> (<samp>gcc -std=c99 -pedantic -D_BSD_SOURCE -D_POSIX_SOURCE</samp> -Wall)
<footnote spaces="\n"><para>The <samp>_BSD_SOURCE</samp> token is required on some Linux platforms where 
<command>gcc</command> dislikes the network header files like
<file>netinet/in.h</file>).</para></footnote>,
Comeau Computing (<samp>como --c99</samp>),
Cray (<samp>cc</samp>),
<acronym><acronymword>HP</acronymword></acronym>/Compaq/<acronym><acronymword>DEC</acronymword></acronym> (<samp>cc</samp>),
<acronym><acronymword>IBM</acronymword></acronym> (<samp>xlc -c -qlanglvl=extc99</samp>),
Intel (<samp>icc -std=c99</samp>),
<cindex index="cp" spaces=" "><indexterm index="cp" number="63"><acronym><acronymword>LLVM</acronymword></acronym></indexterm></cindex>
<acronym><acronymword>LLVM</acronymword></acronym> (<samp>clang</samp>),
<acronym><acronymword>NEC</acronymword></acronym> (<samp>cc</samp>),
PathScale (QLogic) (<samp>pathcc -std=c99</samp>),
<acronym><acronymword>PGI</acronymword></acronym> (<samp>pgcc -c9x</samp>),
<acronym><acronymword>SGI</acronymword></acronym> (<samp>cc -c99</samp>),
and
Sun (<samp>cc</samp>).
<cindex index="cp" spaces=" "><indexterm index="cp" number="64">C++</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="65"><acronym><acronymword>ISO</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="66"><command>libnco</command></indexterm></cindex>
<acronym><acronymword>NCO</acronymword></acronym> (all commands and the <command>libnco</command> library) and
the C++ interface to netCDF (called <command>libnco_c++</command>) comply with
the <acronym><acronymword>ISO</acronymword></acronym> C++ standards as implemented by
Comeau Computing (<samp>como</samp>),
Cray (<samp>CC</samp>),
<acronym><acronymword>GNU</acronymword></acronym> (<samp>g++ -Wall</samp>),
<acronym><acronymword>HP</acronymword></acronym>/Compaq/<acronym><acronymword>DEC</acronymword></acronym> (<samp>cxx</samp>),
<acronym><acronymword>IBM</acronymword></acronym> (<samp>xlC</samp>),
Intel (<samp>icc</samp>),
Microsoft (<samp>MVS</samp>),
<acronym><acronymword>NEC</acronymword></acronym> (<samp>c++</samp>),
PathScale (Qlogic) (<samp>pathCC</samp>),
<acronym><acronymword>PGI</acronymword></acronym> (<samp>pgCC</samp>),
<acronym><acronymword>SGI</acronymword></acronym> (<samp>CC -LANG:std</samp>),
and
Sun (<samp>CC -LANG:std</samp>).
<cindex index="cp" spaces=" "><indexterm index="cp" number="67"><file>Makefile</file></indexterm></cindex>
See <file>nco/bld/Makefile</file> and <file>nco/src/nco_c++/Makefile.old</file> for
more details and exact settings. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="68"><acronym><acronymword>ANSI</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="69">C89</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="70"><code>printf</code></indexterm></cindex> 
<para>Until recently (and not even yet), <acronym><acronymword>ANSI</acronymword></acronym>-compliant has meant
compliance with the 1989 <acronym><acronymword>ISO</acronymword></acronym> C-standard, usually called C89 (with
minor revisions made in 1994 and 1995).
C89 lacks variable-size arrays, restricted pointers, some useful
<code>printf</code> formats, and many mathematical special functions.
<cindex index="cp" spaces=" "><indexterm index="cp" number="71">C99</indexterm></cindex>
These are valuable features of C99, the 1999 <acronym><acronymword>ISO</acronymword></acronym> C-standard. 
<acronym><acronymword>NCO</acronymword></acronym> is C99-compliant where possible and C89-compliant where
necessary. 
Certain branches in the code are required to satisfy the native
<acronym><acronymword>SGI</acronymword></acronym> and SunOS <w>C compilers</w>, which are strictly <acronym><acronymword>ANSI</acronymword></acronym> 
C89 compliant, and cannot benefit from C99 features.
However, C99 features are fully supported by modern <acronym><acronymword>AIX</acronymword></acronym>,
<acronym><acronymword>GNU</acronymword></acronym>, Intel, <acronym><acronymword>NEC</acronymword></acronym>, Solaris, and <acronym><acronymword>UNICOS</acronymword></acronym>
compilers. 
<acronym><acronymword>NCO</acronymword></acronym> requires a C99-compliant compiler as of <acronym><acronymword>NCO</acronymword></acronym>
<w>version 2.9.8</w>, released in August, 2004.
</para>
<para>The most time-intensive portion of <acronym><acronymword>NCO</acronymword></acronym> execution is spent in
arithmetic operations, e.g., multiplication, averaging, subtraction.
These operations were performed in Fortran by default until August,
1999.
This was a design decision based on the relative speed of Fortran-based
object code vs.&noeos; C-based object code in late 1994.
<w>C compiler</w> vectorization capabilities have dramatically improved 
since 1994.
We have accordingly replaced all Fortran subroutines with <w>C functions</w>.
This greatly simplifies the task of building <acronym><acronymword>NCO</acronymword></acronym> on nominally
unsupported platforms.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="72">C language</indexterm></cindex>
As of August 1999, <acronym><acronymword>NCO</acronymword></acronym> built entirely <w>in C</w> by default.
This allowed <acronym><acronymword>NCO</acronymword></acronym> to compile on any machine with an
<acronym><acronymword>ANSI</acronymword></acronym> <w>C compiler</w>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="73">C99</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="74">C89</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="75"><code>restrict</code></indexterm></cindex>
In August 2004, the first C99 feature, the <code>restrict</code> type
qualifier, entered <acronym><acronymword>NCO</acronymword></acronym> in version 2.9.8. 
<w>C compilers</w> can obtain better performance with C99 restricted 
pointers since they inform the compiler when it may make Fortran-like
assumptions regarding pointer contents alteration.
Subsequently, <acronym><acronymword>NCO</acronymword></acronym> requires a C99 compiler to build correctly
<footnote><para><acronym><acronymword>NCO</acronymword></acronym> may still build with an 
<acronym><acronymword>ANSI</acronymword></acronym> or <acronym><acronymword>ISO</acronymword></acronym> C89 or C94/95-compliant compiler if the
<w>C pre-processor</w> undefines the <code>restrict</code> type qualifier, e.g.,
by invoking the compiler with <samp>-Drestrict=''</samp>.</para></footnote>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="76"><acronym><acronymword>GSL</acronymword></acronym></indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="1" mergedindex="cp">ncap2</indexterm></findex>
<para>In January 2009, <acronym><acronymword>NCO</acronymword></acronym> version 3.9.6 was the first to link
to the <acronym><acronymword>GNU</acronymword></acronym> Scientific Library (<acronym><acronymword>GSL</acronymword></acronym>).
<acronym><acronymword>GSL</acronymword></acronym> must be <w>version 1.4</w> or later. 
<acronym><acronymword>NCO</acronymword></acronym>, in particular <command>ncap2</command>, uses the <acronym><acronymword>GSL</acronymword></acronym>
special function library to evaluate geoscience-relevant mathematics
such as Bessel functions, Legendre polynomials, and incomplete gamma
functions (<pxref label="GSL-special-functions"><xrefnodename>GSL special functions</xrefnodename></pxref>).
</para> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="77"><var>gamma</var></indexterm></cindex>
<para>In June 2005, <acronym><acronymword>NCO</acronymword></acronym> version 3.0.1 began to take advantage
of C99 mathematical special functions.
These include the standarized gamma function (called <code>tgamma()</code> 
for &textldquo;true gamma&textrdquo;). 
<cindex index="cp" spaces=" "><indexterm index="cp" number="78">automagic</indexterm></cindex>
<acronym><acronymword>NCO</acronymword></acronym> automagically takes advantage of some <acronym><acronymword>GNU</acronymword></acronym>
Compiler Collection (<acronym><acronymword>GCC</acronymword></acronym>) extensions to <w><acronym><acronymword>ANSI</acronymword></acronym> C</w>.
</para>
<para>As of July 2000 and <acronym><acronymword>NCO</acronymword></acronym> <w>version 1.2</w>, <acronym><acronymword>NCO</acronymword></acronym> no
longer performs arithmetic operations in Fortran.
We decided to sacrifice executable speed for code maintainability.
Since no objective statistics were ever performed to quantify 
the difference in speed between the Fortran and <w>C code</w>,
the performance penalty incurred by this decision is unknown.
Supporting Fortran involves maintaining two sets of routines for every
arithmetic operation. 
The <code>USE_FORTRAN_ARITHMETIC</code> flag is still retained in the
<file>Makefile</file>.
The file containing the Fortran code, <file>nco_fortran.F</file>, has been
deprecated but a volunteer (<w>Dr.&noeos; Frankenstein</w>?) could resurrect it.
If you would like to volunteer to maintain <file>nco_fortran.F</file> please 
contact me. 
</para>
<!-- c Following section is obsolete -->
<ignore endspaces=" ">
It is still possible to request Fortran routines to perform arithmetic
operations, however.
@cindex preprocessor tokens
@cindex @code{USE_FORTRAN_ARITHMETIC}
This can be accomplished by defining the preprocessor token
@code{USE_FORTRAN_ARITHMETIC} and rebuilding @acronym{NCO}.
@cindex performance
As its name suggests, the @code{USE_FORTRAN_ARITHMETIC} token instructs
@acronym{NCO} to attempts to interface the @w{C routines} with Fortran
arithmetic. 
Although using Fortran calls instead @w{of C} reduces the portability and
and increases the maintenance of the @acronym{NCO} operators, it may
also increase the performance of the numeric operators.
Presumably this will depend on your machine type, the quality of @w{the C}
and Fortran compilers, and the size of the data files
@footnote{If you decide to test the efficiency of the averagers compiled
with @code{USE_FORTRAN_ARITHMETIC} versus the default @w{C averagers} I
would be most interested to hear the results.
Please E-mail me the results including the size of the datasets, the
platform, and the change in the wallclock time for execution.}.
</ignore>

<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Windows Operating System</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;wnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wnd --&gt;
&lt;a name=&quot;windows&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#windows --&gt;
&lt;a name=&quot;qt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#qt --&gt;
</html>
<node name="Windows-Operating-System" spaces=" "><nodename>Windows Operating System</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Compatability</nodeprev><nodeup spaces=" ">Compatability</nodeup></node>
<subsection spaces=" "><sectiontitle>Compiling <acronym><acronymword>NCO</acronymword></acronym> for Microsoft Windows <acronym><acronymword>OS</acronymword></acronym></sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="79">Windows</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="80">Microsoft</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="81"><acronym><acronymword>XP</acronymword></acronym> (Microsoft operating system)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="82"><acronym><acronymword>NT</acronymword></acronym> (Microsoft operating system)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="83">Vista (Microsoft operating system)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="84"><acronym><acronymword>MVS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="85">Microsoft Visual Studio</indexterm></cindex>

<para><acronym><acronymword>NCO</acronymword></acronym> has been successfully ported and tested on most Microsoft  
Windows operating systems including: <acronym><acronymword>XP</acronymword></acronym> SP2/Vista/7/10.
Support is provided for compiling either native Windows executables,
using the Microsoft Visual Studio Compiler (<acronym><acronymword>MVSC</acronymword></acronym>), or with
Cygwin, the <acronym><acronymword>UNIX</acronymword></acronym>-emulating compatibility layer with the
<acronym><acronymword>GNU</acronymword></acronym> toolchain. 
The switches necessary to accomplish both are included in the standard
distribution of <acronym><acronymword>NCO</acronymword></acronym>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="86">C99</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="87">CMake</indexterm></cindex>
<html endspaces=" ">
&lt;a name=&quot;CMake&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#CMake --&gt;
&lt;a name=&quot;cmake&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cmake --&gt;
&lt;a name=&quot;cmk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cmk --&gt;
</html>
<para>With Microsoft Visual Studio compiler, one must build <acronym><acronymword>NCO</acronymword></acronym>
with C++ since <acronym><acronymword>MVSC</acronymword></acronym> does not support C99.
Support for Qt, a convenient integrated development environment, was
deprecated in 2017.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.9 (September, 2017) please build native
Windows executables with CMake:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
cd ~/nco/cmake
cmake .. -DCMAKE_INSTALL_PREFIX=${HOME}
make install
</verbatim>
</example>
<para>The file <file>nco/cmake/build.bat</file> shows how deal with various path
issues. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="88">Anaconda</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="89">Conda</indexterm></cindex>
<html endspaces=" ">
&lt;a name=&quot;anaconda&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#anaconda --&gt;
&lt;a name=&quot;cnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnd --&gt;
&lt;a name=&quot;conda&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#conda --&gt;
</html>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.7.1 (December, 2017) the Conda package
for <acronym><acronymword>NCO</acronymword></acronym> is available from the <code>conda-forge</code> channel on
all three smithies: Linux, MacOS, and Windows. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Recommended install with Conda
conda config --add channels conda-forge # Permananently add conda-forge
conda install nco
# Or, specify conda-forge explicitly as a one-off:
conda install -c conda-forge nco
</verbatim>
</example>

<para>Using the freely available Cygwin (formerly gnu-win32) development
environment  
<footnote><para>The Cygwin package is available from&linebreak;
<code>http://sourceware.redhat.com/cygwin</code>&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="90"><code>gcc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="91"><code>g++</code></indexterm></cindex>
Currently, <w>Cygwin 20.x</w> comes with the <acronym><acronymword>GNU</acronymword></acronym> C/C++
compilers (<command>gcc</command>, <command>g++</command>.
These <acronym><acronymword>GNU</acronymword></acronym> compilers may be used to build the netCDF
distribution itself.</para></footnote>, the compilation process is very similar to
installing <acronym><acronymword>NCO</acronymword></acronym> on a <acronym><acronymword>UNIX</acronymword></acronym> system.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="92">preprocessor tokens</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="93">Cygwin</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="94"><code>gnu-win32</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="95"><code>WIN32</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="96"><file>GNUmakefile</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="97"><file>Makefile</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="98"><code>f90</code></indexterm></cindex>
Set the <code>PVM_ARCH</code> preprocessor token to <code>WIN32</code>.  
Note that defining <code>WIN32</code> has the side effect of disabling
Internet features of <acronym><acronymword>NCO</acronymword></acronym> (see below). 
<acronym><acronymword>NCO</acronymword></acronym> should now build like it does on <acronym><acronymword>UNIX</acronymword></acronym>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="99"><acronym><acronymword>UNIX</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="100"><code>getuid</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="101"><code>gethostname</code></indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="2" mergedindex="cp"><file>&lt;arpa/nameser.h&gt;</file></indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="3" mergedindex="cp"><file>&lt;resolv.h&gt;</file></indexterm></findex>
<para>The least portable section of the code is the use of standard
<acronym><acronymword>UNIX</acronymword></acronym> and Internet protocols (e.g., <code>ftp</code>, <code>rcp</code>,
<code>scp</code>, <code>sftp</code>, <code>getuid</code>, <code>gethostname</code>, and header
files <file>&lt;arpa/nameser.h&gt;</file> and 
<file>&lt;resolv.h&gt;</file>). 
<cindex index="cp" spaces=" "><indexterm index="cp" number="102"><code>ftp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="103"><code>sftp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="104"><code>rcp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="105"><code>scp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="106"><acronym><acronymword>SSH</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="107">remote files</indexterm></cindex>
Fortunately, these <acronym><acronymword>UNIX</acronymword></acronym>-y calls are only invoked by the single  
<acronym><acronymword>NCO</acronymword></acronym> subroutine which is responsible for retrieving files
stored on remote systems (<pxref label="Remote-storage"><xrefnodename>Remote storage</xrefnodename></pxref>).
In order to support <acronym><acronymword>NCO</acronymword></acronym> on the Microsoft Windows platforms,
this single feature was disabled (on Windows <acronym><acronymword>OS</acronymword></acronym> only).
This was required by <w>Cygwin 18.x</w>&textmdash;newer versions of Cygwin may
support these protocols (let me know if this is the case).
The <acronym><acronymword>NCO</acronymword></acronym> operators should behave identically on Windows and
<acronym><acronymword>UNIX</acronymword></acronym> platforms in all other respects.
</para>
<html endspaces=" ">
&lt;a name=&quot;sym&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sym --&gt;
</html>
</subsection>
</section>
<node name="Symbolic-Links" spaces=" "><nodename>Symbolic Links</nodename><nodenext spaces=" ">Libraries</nodenext><nodeprev spaces=" ">Compatability</nodeprev><nodeup spaces=" ">Introduction</nodeup></node>
<section spaces=" "><sectiontitle>Symbolic Links</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="108">symbolic links</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> relies on a common set of underlying algorithms.
To minimize duplication of source code, multiple operators sometimes
share the same underlying source.
This is accomplished by symbolic links from a single underlying
executable program to one or more invoked executable names.
For example, <command>nces</command> and <command>ncrcat</command> are symbolically linked  
to the <command>ncra</command> executable.
The <command>ncra</command> executable behaves slightly differently based on its
invocation name (i.e., <samp>argv[0]</samp>), which can be 
<command>nces</command>, <command>ncra</command>, or <command>ncrcat</command>.
Logically, these are three different operators that happen to share 
the same executable.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="109">Cygwin</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="110">synonym</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="111">pseudonym</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="112"><code>--pseudonym</code></indexterm></cindex>
<para>For historical reasons, and to be more user friendly, multiple synonyms 
(or pseudonyms) may refer to the same operator invoked with different
switches. 
For example, <command>ncdiff</command> is the same as <command>ncbo</command> and
<command>ncpack</command> is the same as <command>ncpdq</command>.
We implement the symbolic links and synonyms by the executing the
following <acronym><acronymword>UNIX</acronymword></acronym> commands in the directory where the
<acronym><acronymword>NCO</acronymword></acronym> executables are installed.
</para><example endspaces=" ">
<pre xml:space="preserve">ln -s -f ncbo ncdiff    # ncbo --op_typ='-'
ln -s -f ncra nces      # ncra --pseudonym='nces'
ln -s -f ncra ncrcat    # ncra --pseudonym='ncrcat'
ln -s -f ncbo ncadd     # ncbo --op_typ='+'
ln -s -f ncbo ncsubtract # ncbo --op_typ='-'
ln -s -f ncbo ncmultiply # ncbo --op_typ='*'
ln -s -f ncbo ncdivide   # ncbo --op_typ='/'
ln -s -f ncpdq ncpack    # ncpdq
ln -s -f ncpdq ncunpack  # ncpdq --unpack
# NB: Windows/Cygwin executable/link names have '.exe' suffix, e.g.,
ln -s -f ncbo.exe ncdiff.exe
...
</pre></example>
<para>The imputed command called by the link is given after the comment.
As can be seen, some these links impute the passing of a command line
argument to further modify the behavior of the underlying executable.
For example, <command>ncdivide</command> is a pseudonym for
<command>ncbo --op_typ='/'</command>.
</para>
<html endspaces=" ">
&lt;a name=&quot;lbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lbr --&gt;
</html>
</section>
<node name="Libraries" spaces=" "><nodename>Libraries</nodename><nodenext spaces=" ">netCDF2/3/4 and HDF4/5 Support</nodenext><nodeprev spaces=" ">Symbolic Links</nodeprev><nodeup spaces=" ">Introduction</nodeup></node>
<section spaces=" "><sectiontitle>Libraries</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="113">libraries</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="114"><code>LD_LIBRARY_PATH</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="115">dynamic linking</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="116">static linking</indexterm></cindex>
<para>Like all executables, the <acronym><acronymword>NCO</acronymword></acronym> operators can be built using dynamic
linking. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="117">performance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="118">operator speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="119">speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="120">execution time</indexterm></cindex>
This reduces the size of the executable and can result in significant
performance enhancements on multiuser systems.
Unfortunately, if your library search path (usually the
<env>LD_LIBRARY_PATH</env> environment variable) is not set correctly, or if
the system libraries have been moved, renamed, or deleted since
<acronym><acronymword>NCO</acronymword></acronym> was installed, it is possible <acronym><acronymword>NCO</acronymword></acronym> operators
will fail with a message that they cannot find a dynamically loaded (aka
<dfn>shared object</dfn> or <samp>.so</samp>) library. 
This will produce a distinctive error message, such as
<samp>ld.so.1:&hyphenbreak; /usr/local/bin/nces:&hyphenbreak; fatal:&hyphenbreak; libsunmath.&hyphenbreak;so.1:&hyphenbreak; can't
open&hyphenbreak; file:&hyphenbreak; errno&hyphenbreak;=2</samp>.   
If you received an error message like this, ask your system 
administrator to diagnose whether the library is truly missing
<footnote><para>The <command>ldd</command> command, if it is available on your system,
will tell you where the executable is looking for each dynamically
loaded library. Use, e.g., <code>ldd `which nces`</code>.</para></footnote>, or whether you
simply need to alter your library search path.
As a final remedy, you may re-compile and install <acronym><acronymword>NCO</acronymword></acronym> with all
operators statically linked.  
</para>
</section>
<node name="netCDF2_002f3_002f4-and-HDF4_002f5-Support" spaces=" "><nodename>netCDF2/3/4 and HDF4/5 Support</nodename><nodenext spaces=" ">Help Requests and Bug Reports</nodenext><nodeprev spaces=" ">Libraries</nodeprev><nodeup spaces=" ">Introduction</nodeup></node>
<section spaces=" "><sectiontitle>netCDF2/3/4 and HDF4/5 Support</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="121">netCDF2</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="122">netCDF3</indexterm></cindex>
<para>netCDF <w>version 2</w> was released in 1993.
<acronym><acronymword>NCO</acronymword></acronym> (specifically <command>ncks</command>) began soon after this in 1994.  
<w>netCDF 3.0</w> was released in 1996, and we were not exactly eager to 
convert all code to the newer, less tested netCDF implementation.
One <w>netCDF3</w> interface call (<code>nc_inq_libvers</code>) was added to 
<acronym><acronymword>NCO</acronymword></acronym> in January, 1998, to aid in maintainance and debugging. 
In March, 2001, the final <acronym><acronymword>NCO</acronymword></acronym> conversion to <w>netCDF3</w> 
was completed (coincidentally on the same day <w>netCDF 3.5</w> was
released). 
<acronym><acronymword>NCO</acronymword></acronym> <w>versions 2.0</w> and higher are built with the
<code>-DNO_NETCDF_2</code> flag to ensure no <w>netCDF2</w> interface calls   
are used.
<cindex index="cp" spaces=" "><indexterm index="cp" number="123"><code>NO_NETCDF_2</code></indexterm></cindex>
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="124"><acronym><acronymword>HDF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="125">Hierarchical Data Format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="126">Mike Folk</indexterm></cindex>
<para>However, the ability to compile <acronym><acronymword>NCO</acronymword></acronym> with only <w>netCDF2</w>
calls is worth maintaining because <acronym><acronymword>HDF</acronymword></acronym> <w>version 4</w>, 
aka <acronym><acronymword>HDF4</acronymword></acronym> or simply <acronym><acronymword>HDF</acronymword></acronym>, 
<footnote><para>The Hierarchical Data Format, or <acronym><acronymword>HDF</acronymword></acronym>, is another
self-describing data format similar to, but more elaborate than,
netCDF. 
<acronym><acronymword>HDF</acronymword></acronym> comes in two flavors, <acronym><acronymword>HDF4</acronymword></acronym> and <acronym><acronymword>HDF5</acronymword></acronym>. 
Often people use the shorthand <acronym><acronymword>HDF</acronymword></acronym> to refer to the older
format <acronym><acronymword>HDF4</acronymword></acronym>.
People almost always use <acronym><acronymword>HDF5</acronymword></acronym> to refer to <acronym><acronymword>HDF5</acronymword></acronym>.</para></footnote> 
(available from <uref><urefurl>http://hdfgroup.org</urefurl><urefdesc spaces=" ">HDF</urefdesc></uref>)
supports only the <w>netCDF2</w> library calls
(see <uref><urefurl>http://hdfgroup.org/UG41r3_html/SDS_SD.fm12.html#47784</urefurl></uref>).
There are two versions of <acronym><acronymword>HDF</acronymword></acronym>.
Currently <acronym><acronymword>HDF</acronymword></acronym> <w>version 4.x</w> supports the full <w>netCDF2</w>
<acronym><acronymword>API</acronymword></acronym> and thus <acronym><acronymword>NCO</acronymword></acronym> <w>version 1.2.x</w>. 
If <acronym><acronymword>NCO</acronymword></acronym> <w>version 1.2.x</w> (or earlier) is built with only
<w>netCDF2</w> calls then all <acronym><acronymword>NCO</acronymword></acronym> operators should work with 
<acronym><acronymword>HDF4</acronymword></acronym> files as well as netCDF files
<footnote><para>One must link the <acronym><acronymword>NCO</acronymword></acronym> code to the <acronym><acronymword>HDF4</acronymword></acronym>
<acronym><acronymword>MFHDF</acronymword></acronym> library instead of the usual netCDF library. 
Apparently <samp>MF</samp> stands for Multi-file not for Mike Folk.
In any case, until about 2007 the <acronym><acronymword>MFHDF</acronymword></acronym> library only
supported <w>netCDF2</w> calls. 
Most people will never again install <acronym><acronymword>NCO</acronymword></acronym> 1.2.x and so will
never use <acronym><acronymword>NCO</acronymword></acronym> to write <acronym><acronymword>HDF4</acronymword></acronym> files.
It is simply too much trouble.</para></footnote>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="127"><code>NETCDF2_ONLY</code></indexterm></cindex>
The preprocessor token <code>NETCDF2_ONLY</code> exists
in <acronym><acronymword>NCO</acronymword></acronym> <w>version 1.2.x</w> to eliminate all <w>netCDF3</w>
calls.  
Only versions of <acronym><acronymword>NCO</acronymword></acronym> numbered 1.2.x and earlier have this
capability. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="128">Unidata</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="129"><acronym><acronymword>NCSA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="130">netCDF4</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="131"><acronym><acronymword>HDF5</acronymword></acronym></indexterm></cindex>
<para><acronym><acronymword>HDF</acronymword></acronym> <w>version 5</w> became available in 1999, but did not
support netCDF (or, for that matter, Fortran) as of December 1999.
By early 2001, <acronym><acronymword>HDF5</acronymword></acronym> did support Fortran90.
Thanks to an <acronym><acronymword>NSF</acronymword></acronym>-funded &textldquo;harmonization&textrdquo; partnership,
<acronym><acronymword>HDF</acronymword></acronym> began to fully support the <w>netCDF3</w> read interface
(which is employed by <w><acronym><acronymword>NCO</acronymword></acronym> 2.x</w> and later). 
In 2004, Unidata and <acronym><acronymword>THG</acronymword></acronym> began a project to implement
the <acronym><acronymword>HDF5</acronymword></acronym> features necessary to support the netCDF API.
<acronym><acronymword>NCO</acronymword></acronym> version 3.0.3 added support for reading/writing
netCDF4-formatted <acronym><acronymword>HDF5</acronymword></acronym> files in October, 2005.
See <ref label="File-Formats-and-Conversion"><xrefnodename>File Formats and Conversion</xrefnodename></ref> for more details.
</para>
<para>HDF support for netCDF was completed with HDF5 version 
<w>version 1.8</w> in 2007. 
The netCDF front-end that uses this <acronym><acronymword>HDF5</acronymword></acronym> back-end 
was completed and released soon after as netCDF <w>version 4</w>.
Download it from the
<uref><urefurl>http://my.unidata.ucar.edu/content/software/netcdf/netcdf-4</urefurl><urefdesc>netCDF4</urefdesc></uref>
website. 
</para>
<html endspaces=" ">
&lt;a name=&quot;nco4&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco4 --&gt;
</html>
<para><acronym><acronymword>NCO</acronymword></acronym> version 3.9.0, released in May, 2007, added support for
all netCDF4 atomic data types except <code>NC_STRING</code>.
Support for <code>NC_STRING</code>, including ragged arrays of strings,
was finally added in version 3.9.9, released in June, 2009.
Support for additional netCDF4 features has been incremental.
We add one netCDF4 feature at a time.
You must build <acronym><acronymword>NCO</acronymword></acronym> with netCDF4 to obtain this support.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="132"><code>NC_UBYTE</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="133"><code>NC_USHORT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="134"><code>NC_UINT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="135"><code>NC_INT64</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="136"><code>NC_UINT64</code></indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> supports many netCDF4 features including atomic data
types, Lempel-Ziv compression (deflation), chunking, and groups.  
The new atomic data types are <code>NC_UBYTE</code>, <code>NC_USHORT</code>, 
<code>NC_UINT</code>, <code>NC_INT64</code>, and <code>NC_UINT64</code>.
Eight-byte integer support is an especially useful improvement from
netCDF3. 
All <acronym><acronymword>NCO</acronymword></acronym> operators support these types, e.g., <command>ncks</command>
copies and prints them, <command>ncra</command> averages them, and
<command>ncap2</command> processes algebraic scripts with them.
<command>ncks</command> prints compression information, if any, to screen.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="137">deflation</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> version 3.9.1 (June, 2007) added support for netCDF4 
Lempel-Ziv deflation.
Lempel-Ziv deflation is a lossless compression technique.
See <ref label="Deflation"><xrefnodename>Deflation</xrefnodename></ref> for more details.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="138">chunking</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> version 3.9.9 (June, 2009) added support for netCDF4
chunking in <command>ncks</command> and <command>ncecat</command>.
<acronym><acronymword>NCO</acronymword></acronym> version 4.0.4 (September, 2010) completed support for
netCDF4 chunking in the remaining operators.
See <ref label="Chunking"><xrefnodename>Chunking</xrefnodename></ref> for more details.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="139">groups</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> version 4.2.2 (October, 2012) added support for netCDF4
groups in <command>ncks</command> and <command>ncecat</command>.
Group support for these operators was complete (e.g., regular
expressions to select groups and Group Path Editing) as of 
<acronym><acronymword>NCO</acronymword></acronym> version 4.2.6 (March, 2013).
See <ref label="Group-Path-Editing"><xrefnodename>Group Path Editing</xrefnodename></ref> for more details.
Group support for all other operators was finished in the
<acronym><acronymword>NCO</acronymword></acronym> version 4.3.x series completed in December, 2013.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="140">broadcasting groups</indexterm></cindex>
<para>Support for netCDF4 in the first arithmetic operator, <command>ncbo</command>,
was introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.3.0 (March, 2013).
<acronym><acronymword>NCO</acronymword></acronym> version 4.3.1 (May, 2013) completed this support and
introduced the first example of automatic group broadcasting.
See <ref label="ncbo-netCDF-Binary-Operator"><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></ref> for more details.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="141"><acronym><acronymword>HDF5</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="142"><code>-4</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="143"><code>-3</code></indexterm></cindex>
<para>netCDF4-enabled <acronym><acronymword>NCO</acronymword></acronym> handles netCDF3 files without change.
In addition, it automagically handles netCDF4 (<acronym><acronymword>HDF5</acronymword></acronym>) files:
If you feed <acronym><acronymword>NCO</acronymword></acronym> netCDF3 files, it produces netCDF3 output.
If you feed <acronym><acronymword>NCO</acronymword></acronym> netCDF4 files, it produces netCDF4 output.
Use the handy-dandy <samp>-4</samp> switch to request netCDF4 output from 
netCDF3 input, i.e., to convert netCDF3 to netCDF4.
See <ref label="File-Formats-and-Conversion"><xrefnodename>File Formats and Conversion</xrefnodename></ref> for more details.
</para>
<html endspaces=" ">
&lt;a name=&quot;hdf4&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdf4 --&gt;
&lt;a name=&quot;HDF4&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#HDF4 --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="144"><acronym><acronymword>HDF4</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="145"><samp>--hdf4</samp></indexterm></cindex>
<para>When linked to a netCDF library that was built with <acronym><acronymword>HDF4</acronymword></acronym>
support
<footnote><para>The procedure for doing this is documented at
<uref><urefurl>http://www.unidata.ucar.edu/software/netcdf/docs/build_hdf4.html</urefurl></uref>.</para></footnote>,
<acronym><acronymword>NCO</acronymword></acronym> automatically supports reading <acronym><acronymword>HDF4</acronymword></acronym> 
files and writing them as netCDF3/netCDF4/<acronym><acronymword>HDF5</acronymword></acronym> files.
<acronym><acronymword>NCO</acronymword></acronym> can only write through the netCDF <acronym><acronymword>API</acronymword></acronym>, which
can only write netCDF3/netCDF4/<acronym><acronymword>HDF5</acronymword></acronym> files. 
So <acronym><acronymword>NCO</acronymword></acronym> can <emph>read</emph> <acronym><acronymword>HDF4</acronymword></acronym> files, perform
manipulations and calculations, and then it must <emph>write</emph> the
results in netCDF format. 
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> support for <acronym><acronymword>HDF4</acronymword></acronym> has been quite functional since
December, 2013.
For best results install <acronym><acronymword>NCO</acronymword></acronym> versions 4.4.0 or later on top of 
netCDF versions 4.3.1 or later. 
Getting to this point has been an iterative effort where Unidata
improved netCDF library capabilities in response to our requests.
<acronym><acronymword>NCO</acronymword></acronym> versions 4.3.6 and earlier do not explicitly support
<acronym><acronymword>HDF4</acronymword></acronym>, yet should work with <acronym><acronymword>HDF4</acronymword></acronym> if compiled with 
a version of netCDF (4.3.2 or later?) that does not unexpectedly die
when probing <acronym><acronymword>HDF4</acronymword></acronym> files with standard netCDF calls.
<acronym><acronymword>NCO</acronymword></acronym> versions 4.3.7&textndash;4.3.9 (October&textndash;December, 2013)
use a special flag to circumvent netCDF <acronym><acronymword>HDF4</acronymword></acronym> issues.
The user must tell these versions of <acronym><acronymword>NCO</acronymword></acronym> that an input file is 
<acronym><acronymword>HDF4</acronymword></acronym> format by using the <samp>--hdf4</samp> switch. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="146"><code>HDF4_UNKNOWN</code></indexterm></cindex>
<para>When compiled with netCDF version 4.3.1 (20140116) or later, 
<acronym><acronymword>NCO</acronymword></acronym> versions 4.4.0 (January, 2014) and later more gracefully 
handle <acronym><acronymword>HDF4</acronymword></acronym> files.
In particular, the <samp>--hdf4</samp> switch is obsolete. 
Current versions of <acronym><acronymword>NCO</acronymword></acronym> use netCDF to determine automatically
whether the underlying file is <acronym><acronymword>HDF4</acronymword></acronym>, and then take appropriate
precautions to avoid netCDF4 <acronym><acronymword>API</acronymword></acronym> calls that fail when applied
to <acronym><acronymword>HDF4</acronymword></acronym> files (e.g., <code>nc_inq_var_chunking()</code>,
<code>nc_inq_var_deflate()</code>).  
When compiled with netCDF version 4.3.2 (20140423) or earlier,
<acronym><acronymword>NCO</acronymword></acronym> will report that chunking and deflation properties of
<acronym><acronymword>HDF4</acronymword></acronym> files as <code>HDF4_UNKNOWN</code>, because determining 
those properties was impossible.
When compiled with netCDF version 4.3.3-rc2 (20140925) or later, 
<acronym><acronymword>NCO</acronymword></acronym> versions 4.4.6 (October, 2014) and later fully support  
chunking and deflation features of <acronym><acronymword>HDF4</acronymword></acronym> files.
Unfortunately, netCDF version 4.7.4 (20200327) introduced a regression 
that breaks this functionality for all <acronym><acronymword>NCO</acronymword></acronym> versions until
we first noticed the regression a year later and implemented a
workaround to restore this functionality as of 4.9.9-alpha02
(20210327). 
The <samp>--hdf4</samp> switch is supported (for backwards compatibility) yet
redundant (i.e., does no harm) with current versions of <acronym><acronymword>NCO</acronymword></acronym>
and netCDF. 
</para>
<para>Converting <acronym><acronymword>HDF4</acronymword></acronym> files to netCDF:
Since <acronym><acronymword>NCO</acronymword></acronym> reads <acronym><acronymword>HDF4</acronymword></acronym> files natively, it is now easy  
to convert <acronym><acronymword>HDF4</acronymword></acronym> files to netCDF files directly, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">ncks        fl.hdf fl.nc # Convert HDF4-&gt;netCDF4 (NCO 4.4.0+, netCDF 4.3.1+)
ncks --hdf4 fl.hdf fl.nc # Convert HDF4-&gt;netCDF4 (NCO 4.3.7-4.3.9)
</pre></example>
<para>The most efficient and accurate way to convert <acronym><acronymword>HDF4</acronymword></acronym> data to
netCDF format is to convert to netCDF4 using <acronym><acronymword>NCO</acronymword></acronym> as above.
Many <acronym><acronymword>HDF4</acronymword></acronym> producers (<acronym><acronymword>NASA</acronymword></acronym>!) love to use netCDF4
types, e.g., unsigned bytes, so this procedure is the most typical.
Conversion of <acronym><acronymword>HDF4</acronymword></acronym> to netCDF4 as above suffices when the data
will only be processed by <acronym><acronymword>NCO</acronymword></acronym> and other netCDF4-aware tools.  
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="147"><command>ncl_convert2nc</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="148"><command>nc3tonc4</command></indexterm></cindex>
<para>However, many tools are not fully netCDF4-aware, and so conversion to
netCDF3 may be desirable.
Obtaining any netCDF file from an <acronym><acronymword>HDF4</acronymword></acronym> is easy:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -3 fl.hdf fl.nc      # HDF4-&gt;netCDF3 (NCO 4.4.0+, netCDF 4.3.1+)
ncks -4 fl.hdf fl.nc      # HDF4-&gt;netCDF4 (NCO 4.4.0+, netCDF 4.3.1+)
ncks -6 fl.hdf fl.nc      # HDF4-&gt;netCDF3 64-bit  (NCO 4.4.0+, ...)
ncks -7 -L 1 fl.hdf fl.nc # HDF4-&gt;netCDF4 classic (NCO 4.4.0+, ...)
ncks --hdf4 -3 fl.hdf fl.nc # HDF4-&gt;netCDF3 (netCDF 4.3.0-)
ncks --hdf4 -4 fl.hdf fl.nc # HDF4-&gt;netCDF4 (netCDF 4.3.0-)
ncks --hdf4 -6 fl.hdf fl.nc # HDF4-&gt;netCDF3 64-bit  (netCDF 4.3.0-)
ncks --hdf4 -7 fl.hdf fl.nc # HDF4-&gt;netCDF4 classic (netCDF 4.3.0-)
</pre></example>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.0 (January, 2014), these commands work
even when the <acronym><acronymword>HDF4</acronymword></acronym> file contains netCDF4 atomic types (e.g.,
unsigned bytes, 64-bit integers) because <acronym><acronymword>NCO</acronymword></acronym> can autoconvert
everything to atomic types supported by netCDF3
<footnote spaces="\n"><para>Prior to <acronym><acronymword>NCO</acronymword></acronym> version 4.4.0 (January, 2014), we recommended the 
<command>ncl_convert2nc</command> tool to convert <acronym><acronymword>HDF</acronymword></acronym> to netCDF3 when
both these are true: <w>1. You</w> must have netCDF3 and <w>2. the</w>
<acronym><acronymword>HDF</acronymword></acronym> file contains netCDF4 atomic types. 
More recent versions of <acronym><acronymword>NCO</acronymword></acronym> handle this problem fine, and
include other advantages so we no longer recommend
<command>ncl_convert2nc</command> because <command>ncks</command> is faster and more
space-efficient. 
Both automatically convert netCDF4 types to netCDF3 types, yet
<command>ncl_convert2nc</command> cannot produce full netCDF4 files.
In contrast, <command>ncks</command> will happily convert <acronym><acronymword>HDF</acronymword></acronym> straight
to netCDF4 files with netCDF4 types. 
Hence <command>ncks</command> can and does preserve the variable types.
Unsigned bytes stay unsigned bytes. 
64-bit integers stay 64-bit integers. 
Strings stay strings. 
Hence, <command>ncks</command> conversions often result in smaller files than
<command>ncl_convert2nc</command> conversions.
Another tool useful for converting netCDF3 to netCDF4 files, and whose
functionality is, we think, also matched or exceeded by <command>ncks</command>,
is the Python script <command>nc3tonc4</command> by Jeff Whitaker.</para></footnote>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="149"><code>hdf_name</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="150">illegal names</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.4 (May, 2014) both
<command>ncl_convert2nc</command> and <acronym><acronymword>NCO</acronymword></acronym> have built-in, automatic
workarounds to handle element names that contain characters that are
legal in <acronym><acronymword>HDF</acronymword></acronym> though are illegal in <acronym><acronymword>netCDF</acronymword></acronym>. 
For example, slashes and leading special characters are are legal in
<acronym><acronymword>HDF</acronymword></acronym> and illegal in <acronym><acronymword>netCDF</acronymword></acronym> element (i.e., group,
variable, dimension, and attribute) names.
<acronym><acronymword>NCO</acronymword></acronym> converts these forbidden characters to underscores, and
retains the original names of variables in automatically produced
attributes named <code>hdf_name</code>
<footnote><para>Two real-world examples: <acronym><acronymword>NCO</acronymword></acronym> translates the
<acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>CERES</acronymword></acronym> dimension <code>(FOV) Footprints</code> to
<code>_FOV_ Footprints</code>, and 
<code>Cloud &amp; Aerosol, Cloud Only, Clear Sky w/Aerosol, and Clear Sky</code> 
(yes, the dimension name includes whitespace and special characters) to 
<code>Cloud &amp; Aerosol, Cloud Only, Clear Sky w_Aerosol, and Clear Sky</code>
<command>ncl_convert2nc</command> makes the element name netCDF-safe in a
slightly different manner, and also stores the original name in the
<code>hdf_name</code> attribute.</para></footnote>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="151"><acronym><acronymword>H4CF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="152"><command>h4tonccf</command></indexterm></cindex>
<para>Finally, in February 2014, we learned that the <acronym><acronymword>HDF</acronymword></acronym> group
has a project called <acronym><acronymword>H4CF</acronymword></acronym> 
(described <uref><urefurl>http://hdfeos.org/software/h4cflib.php</urefurl><urefdesc spaces=" ">here</urefdesc></uref>)
whose goal is to make <acronym><acronymword>HDF4</acronymword></acronym> files accessible to <acronym><acronymword>CF</acronymword></acronym>
tools and conventions. 
Their project includes a tool named <command>h4tonccf</command> that converts
<acronym><acronymword>HDF4</acronymword></acronym> files to netCDF3 or netCDF4 files.
We are not yet sure what advantages or features <command>h4tonccf</command> has
that are not in <acronym><acronymword>NCO</acronymword></acronym>, though we suspect both methods have their
own advantages. Corrections welcome.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="153"><acronym><acronymword>RPM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="154">Debian</indexterm></cindex>
<para>As of 2012, netCDF4 is relatively stable software.
Problems with netCDF4 and <acronym><acronymword>HDF</acronymword></acronym> libraries have mainly been fixed.
Binary <acronym><acronymword>NCO</acronymword></acronym> distributions shipped as <acronym><acronymword>RPM</acronymword></acronym>s and as debs
have used the netCDF4 library since 2010 and 2011, respectively.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="155"><code>NETCDF4_ROOT</code></indexterm></cindex>
<para>One must often build <acronym><acronymword>NCO</acronymword></acronym> from source to obtain netCDF4
support. 
Typically, one specifies the root of the netCDF4
installation directory. Do this with the <code>NETCDF4_ROOT</code> variable.
Then use your preferred <acronym><acronymword>NCO</acronymword></acronym> build mechanism, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">export NETCDF4_ROOT=/usr/local/netcdf4 # Set netCDF4 location
cd ~/nco;./configure --enable-netcdf4  # Configure mechanism -or-
cd ~/nco/bld;./make NETCDF4=Y allinone # Old Makefile mechanism
</pre></example>

<para>We carefully track the netCDF4 releases, and keep the netCDF4 atomic
type support and other features working.
Our long term goal is to utilize more of the extensive new netCDF4
feature set. The next major netCDF4 feature we are likely to utilize
is parallel I/O. We will enable this in the <acronym><acronymword>MPI</acronymword></acronym> netCDF
operators. 
</para>
<html endspaces=" ">
&lt;a name=&quot;help&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#help --&gt;
&lt;a name=&quot;hlp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hlp --&gt;
&lt;a name=&quot;bug&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bug --&gt;
</html>
</section>
<node name="Help-Requests-and-Bug-Reports" spaces=" "><nodename>Help Requests and Bug Reports</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">netCDF2/3/4 and HDF4/5 Support</nodeprev><nodeup spaces=" ">Introduction</nodeup></node>
<section spaces=" "><sectiontitle>Help Requests and Bug Reports</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="156">reporting bugs</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="157">bugs, reporting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="158">core dump</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="159">help</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="160">features, requesting</indexterm></cindex>
<para>We generally receive three categories of mail from users: help requests,
bug reports, and feature requests.
Notes saying the equivalent of &textldquo;Hey, <acronym><acronymword>NCO</acronymword></acronym> continues to work
great and it saves me more time everyday than it took to write this
note&textrdquo; are a distant fourth.
</para>
<para>There is a different protocol for each type of request.
The preferred etiquette for all communications is via <acronym><acronymword>NCO</acronymword></acronym>
Project Forums. 
Do not contact project members via personal e-mail unless your request
comes with money or you have damaging information about our personal
lives.
<emph>Please use the Forums</emph>&textmdash;they preserve a record of the questions
and answers so that others can learn from our exchange.
Also, since <acronym><acronymword>NCO</acronymword></acronym> is both volunteer-driven and
government-funded, this record helps us provide program officers with 
information they need to evaluate our project. 
</para>
<para>Before posting to the <acronym><acronymword>NCO</acronymword></acronym> forums described below, you might
first <uref><urefurl>https://sf.net/account/register.php</urefurl><urefdesc spaces=" ">register</urefdesc></uref>
your name and email address with SourceForge.net or else all of your
postings will be attributed to <emph>nobody</emph>.
Once registered you may choose to <emph>monitor</emph> any forum and to receive
(or not) email when there are any postings including responses to your
questions.
We usually reply to the forum message, not to the original poster.
</para>
<para>If you want us to include a new feature in <acronym><acronymword>NCO</acronymword></acronym>, please 
consider implementing the feature yourself and sending us the patch.
If that is beyond your ken, then send a note to the
<uref><urefurl>http://sf.net/p/nco/discussion/9829</urefurl><urefdesc spaces=" ">NCO Discussion forum</urefdesc></uref>.
</para>
<para>Read the manual before reporting a bug or posting a help request.
Sending questions whose answers are not in the manual is the best
way to motivate us to write more documentation.  
We would also like to accentuate the contrapositive of this statement.  
If you think you have found a real bug <emph>the most helpful thing you 
can do is simplify the problem to a manageable size and then report it</emph>.
The first thing to do is to make sure you are running the latest
publicly released version of <acronym><acronymword>NCO</acronymword></acronym>.  
</para>
<para>Once you have read the manual, if you are still unable to get
<acronym><acronymword>NCO</acronymword></acronym> to perform a documented function, submit a help request.
Follow the same procedure as described below for reporting bugs
(after all, it might be a bug).
<cindex index="cp" spaces=" "><indexterm index="cp" number="161">debugging</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="162"><code>-r</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="163"><code>-D</code></indexterm></cindex>
That is, describe what you are trying to do, and include the complete
commands (run with <samp>-D 5</samp>), error messages, and version of
<acronym><acronymword>NCO</acronymword></acronym> (with <samp>-r</samp>).  
Some commands behave differently depending on the exact order and
rank of dimensions in the pertinent variables.
In such cases we need you to provide that metadata, e.g., the text
results of <samp>ncks -m</samp> on your input and/or output files.
Post your help request to the 
<uref><urefurl>http://sf.net/p/nco/discussion/9830</urefurl><urefdesc spaces=" ">NCO Help forum</urefdesc></uref>.
</para>
<para>If you think you used the right command when <acronym><acronymword>NCO</acronymword></acronym> misbehaves,
then you might have found a bug.  
Incorrect numerical answers are the highest priority.
We usually fix those within one or two days.
Core dumps and sementation violations receive lower priority.
They are always fixed, eventually. 
</para>
<para>How do you simplify a problem that reveal a bug?
Cut out extraneous variables, dimensions, and metadata from the
offending files and re-run the command until it no longer breaks.  
Then back up one step and report the problem.
Usually the file(s) will be very small, i.e., one variable with one or
two small dimensions ought to suffice.
<html endspaces=" ">
&lt;a name=&quot;dbg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dbg --&gt;
&lt;a name=&quot;-D&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-D --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="164"><code>-r</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="165"><code>--revision</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="166"><code>--version</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="167"><code>--vrs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="168"><code>-D <var>debug-level</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="169"><code>--debug-level <var>debug-level</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="170"><code>--dbg_lvl <var>debug-level</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="171"><var>debug-level</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="172"><var>dbg_lvl</var></indexterm></cindex>
Run the operator with <samp>-r</samp> and then run the command with 
<samp>-D 5</samp> to increase the verbosity of the debugging output.
It is very important that your report contain the exact error messages 
and compile-time environment.
Include a copy of your sample input file, or place one on a 
publicly accessible location, of the file(s).
If you are sure it is a bug, post the full report to the 
<uref><urefurl>http://sf.net/p/nco/bugs</urefurl><urefdesc spaces=" ">NCO Project buglist</urefdesc></uref>.
Otherwise post all the information to 
<uref><urefurl>http://sf.net/p/nco/discussion/9830</urefurl><urefdesc spaces=" ">NCO Help forum</urefdesc></uref>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="173">installation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="174"><command>autoconf</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="175"><file>nco.configure.$&lbrace;GNU_TRP&rbrace;.foo</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="176"><file>nco.config.log.$&lbrace;GNU_TRP&rbrace;.foo</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="177"><file>nco.make.$&lbrace;GNU_TRP&rbrace;.foo</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="178"><file>config.guess</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="179"><file>configure.eg</file></indexterm></cindex>
<para>Build failures count as bugs.
Our limited machine access means we cannot fix all build failures.
The information we need to diagnose, and often fix, build failures
are the three files output by <acronym><acronymword>GNU</acronymword></acronym> build tools,  
<file>nco.config.log.$&lbrace;GNU_TRP&rbrace;.foo</file>,
<file>nco.configure.$&lbrace;GNU_TRP&rbrace;.foo</file>, 
and <file>nco.make.$&lbrace;GNU_TRP&rbrace;.foo</file>.
The file <file>configure.eg</file> shows how to produce these files.
Here <code>$&lbrace;GNU_TRP&rbrace;</code> is the &textldquo;<acronym><acronymword>GNU</acronymword></acronym> architecture triplet&textrdquo;,
the <var>chip-vendor-OS</var> string returned by <file>config.guess</file>.
Please send us your improvements to the examples supplied in
<file>configure.eg</file>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="180">regressions archive</indexterm></cindex>
The regressions archive at <url><urefurl>http://dust.ess.uci.edu/nco/rgr</urefurl></url>
contains the build output from our standard test systems.
You may find you can solve the build problem yourself by examining the
differences between these files and your own.
</para>
<html endspaces=" ">
&lt;a name=&quot;str&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#str --&gt;
</html>
</section>
</chapter>
<node name="Strategies" spaces=" "><nodename>Strategies</nodename><nodenext spaces=" ">Shared features</nodenext><nodeprev spaces=" ">Introduction</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>Operator Strategies</sectiontitle>

<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Philosophy</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Climate Model Paradigm</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Temporary Output Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Appending Variables</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Simple Arithmetic and Interpolation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Statistics vs Concatenation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Large Numbers of Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Large Datasets</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Memory Requirements</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Performance</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;phl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#phl --&gt;
</html>
<node name="Philosophy" spaces=" "><nodename>Philosophy</nodename><nodenext spaces=" ">Climate Model Paradigm</nodenext><nodeprev spaces=" ">Strategies</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Philosophy</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="181">philosophy</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="182">climate model</indexterm></cindex>

<para>The main design goal is command line operators which perform useful,
scriptable operations on netCDF files.  
Many scientists work with models and observations which produce too much
data to analyze in tabular format.
Thus, it is often natural to reduce and massage this raw or primary
level data into summary, or second level data, e.g., temporal or spatial
averages. 
These second level data may become the inputs to graphical and
statistical packages, and are often more suitable for archival and
dissemination to the scientific community.
<acronym><acronymword>NCO</acronymword></acronym> performs a suite of operations useful in manipulating data
from the primary to the second level state.
<cindex index="cp" spaces=" "><indexterm index="cp" number="183"><acronym><acronymword>IDL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="184">Matlab</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="185"><acronym><acronymword>NCL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="186">Perl</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="187">Yorick</indexterm></cindex>
Higher level interpretive languages (e.g., <acronym><acronymword>IDL</acronymword></acronym>, Yorick,
Matlab, <acronym><acronymword>NCL</acronymword></acronym>, Perl, Python),
and lower level compiled languages (e.g., C, Fortran) can always perform  
any task performed by <acronym><acronymword>NCO</acronymword></acronym>, but often with more overhead.
NCO, on the other hand, is limited to a much smaller set of arithmetic
and metadata operations than these full blown languages.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="188">command line switches</indexterm></cindex>
<para>Another goal has been to implement enough command line switches so that 
frequently used sequences of these operators can be executed from a
shell script or batch file.
Finally, <acronym><acronymword>NCO</acronymword></acronym> was written to consume the absolute minimum
amount of system memory required to perform a given job.
The arithmetic operators are extremely efficient; their exact memory
usage is detailed in <ref label="Memory-Requirements"><xrefnodename>Memory Requirements</xrefnodename></ref>.
</para>
<html endspaces=" ">
&lt;a name=&quot;clm_mdl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm_mdl --&gt;
</html>
</section>
<node name="Climate-Model-Paradigm" spaces=" "><nodename>Climate Model Paradigm</nodename><nodenext spaces=" ">Temporary Output Files</nodenext><nodeprev spaces=" ">Philosophy</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Climate Model Paradigm</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="189">climate model</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="190"><acronym><acronymword>NCAR</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="191"><acronym><acronymword>GCM</acronymword></acronym></indexterm></cindex>

<para><acronym><acronymword>NCO</acronymword></acronym> was developed at <acronym><acronymword>NCAR</acronymword></acronym> to aid analysis and
manipulation of datasets produced by General Circulation Models
(<acronym><acronymword>GCM</acronymword></acronym>s).  
<acronym><acronymword>GCM</acronymword></acronym> datasets share many features with other gridded scientific
datasets and so provide a useful paradigm for the explication of the
<acronym><acronymword>NCO</acronymword></acronym> operator set. 
Examples in this manual use a <acronym><acronymword>GCM</acronymword></acronym> paradigm because latitude,
longitude, time, temperature and other fields related to our natural
environment are as easy to visualize for the layman as the expert.
</para>
<html endspaces=" ">
&lt;a name=&quot;out&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#out --&gt;
</html>
</section>
<node name="Temporary-Output-Files" spaces=" "><nodename>Temporary Output Files</nodename><nodenext spaces=" ">Appending Variables</nodenext><nodeprev spaces=" ">Climate Model Paradigm</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Temporary Output Files </sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="192">data safety</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="193">error tolerance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="194">safeguards</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="195">temporary output files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="196">temporary files</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> operators are designed to be reasonably fault tolerant, so
that a system failure or user-abort of the operation (e.g., with
<kbd>C-c</kbd>) does not cause loss of data.
The user-specified <var>output-file</var> is only created upon successful
completion of the operation  
<footnote><para>The <command>ncrename</command> and <command>ncatted</command> operators are
exceptions to this rule.
<xref label="ncrename-netCDF-Renamer"><xrefnodename>ncrename netCDF Renamer</xrefnodename></xref>.</para></footnote>.
This is accomplished by performing all operations in a temporary copy
of <var>output-file</var>.
The name of the temporary output file is constructed by appending
<code>.pid<var>&lt;process ID&gt;</var>.<var>&lt;operator name&gt;</var>.tmp</code> to the
user-specified <var>output-file</var> name.  
When the operator completes its task with no fatal errors, the temporary
output file is moved to the user-specified <var>output-file</var>.
This imbues the process with fault-tolerance since fatal error
(e.g., disk space fills up) affect only the temporary output file,
leaving the final output file not created if it did not already exist. 
Note the construction of a temporary output file uses more disk space
than just overwriting existing files &textldquo;in place&textrdquo; (because there may be
two copies of the same file on disk until the <acronym><acronymword>NCO</acronymword></acronym> operation
successfully concludes and the temporary output file overwrites the
existing <var>output-file</var>).  
<cindex index="cp" spaces=" "><indexterm index="cp" number="197">performance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="198">operator speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="199">speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="200">execution time</indexterm></cindex>
Also, note this feature increases the execution time of the operator
by approximately the time it takes to copy the <var>output-file</var>
<footnote><para>The OS-specific system move command is used.
This is <command>mv</command> for <acronym><acronymword>UNIX</acronymword></acronym>, and <command>move</command> for Windows.</para></footnote>.
Finally, note this fault-tolerant feature allows the <var>output-file</var>
to be the same as the <var>input-file</var> without any danger of
&textldquo;overlap&textrdquo;. 
</para>
<html endspaces=" ">
&lt;a name=&quot;tmp_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tmp_fl --&gt;
&lt;a name=&quot;no_tmp_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_tmp_fl --&gt;
&lt;a name=&quot;wrt_tmp_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wrt_tmp_fl --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="201"><code>--no_tmp_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="202"><code>--wrt_tmp_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="203"><code>--write_tmp_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="204"><code>--create_ram</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="205"><code>--open_ram</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="206"><acronym><acronymword>RAM</acronymword></acronym> disks</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="207"><acronym><acronymword>RAM</acronymword></acronym> files</indexterm></cindex>
<para>Over time many &textldquo;power users&textrdquo; have requested a way to turn-off the
fault-tolerance safety feature that automatically creates a temporary
file. 
Often these users build and execute production data analysis scripts
that are repeated frequently on large datasets.
Obviating an extra file write can then conserve significant disk space
and time.  
For this purpose <acronym><acronymword>NCO</acronymword></acronym> has, since version 4.2.1 in August, 2012, 
made configurable the controls over temporary file creation.
The <samp>--wrt_tmp_fl</samp> and equivalent <samp>--write_tmp_fl</samp> switches 
ensure <acronym><acronymword>NCO</acronymword></acronym> writes output to an intermediate temporary file.
This is and has always been the default behavior so there is currently
no need to specify these switches.
However, the default may change some day, especially since writing to
RAM disks (<pxref label="RAM-disks"><xrefnodename>RAM disks</xrefnodename></pxref>) may some day become the default.
The <samp>--no_tmp_fl</samp> switch causes <acronym><acronymword>NCO</acronymword></acronym> to write directly to
the final output file instead of to an intermediate temporary file. 
&textldquo;Power users&textrdquo; may wish to invoke this switch to increase performance
(i.e., reduce wallclock time) when manipulating large files. 
When eschewing temporary files, users may forsake the ability to have
the same name for both <var>output-file</var> and <var>input-file</var> since, as   
described above, the temporary file prevented overlap issues.
However, if the user creates the output file in <acronym><acronymword>RAM</acronymword></acronym>
(<pxref label="RAM-disks"><xrefnodename>RAM disks</xrefnodename></pxref>) then it is still possible to have the same name
for both <var>output-file</var> and <var>input-file</var>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncks in.nc out.nc # Default: create out.pid.tmp.nc then move to out.nc
ncks --wrt_tmp_fl in.nc out.nc # Same as default
ncks --no_tmp_fl in.nc out.nc # Create out.nc directly on disk
ncks --no_tmp_fl in.nc in.nc # ERROR-prone! Overwrite in.nc with itself
ncks --create_ram --no_tmp_fl in.nc in.nc # Create in RAM, write to disk
ncks --open_ram --no_tmp_fl in.nc in.nc # Read into RAM, write to disk
</pre></example>
<noindent></noindent>
<para>There is no reason to expect the fourth example to work.
The behavior of overwriting a file while reading from the same file is
undefined, much as is the shell command <samp>cat foo &gt; foo</samp>.
Although it may &textldquo;work&textrdquo; in some cases, it is unreliable.
One way around this is to use <samp>--create_ram</samp> so that the
output file is not written to disk until the input file is closed,
<xref label="RAM-disks"><xrefnodename>RAM disks</xrefnodename></xref>.
However, as of 20130328, the behavior of the <samp>--create_ram</samp> and
<samp>--open_ram</samp> examples has not been thoroughly tested.
</para>
<para>The <acronym><acronymword>NCO</acronymword></acronym> authors have seen compelling use cases for utilizing
the <acronym><acronymword>RAM</acronymword></acronym> switches, though not (yet) for combining them with
<samp>--no_tmp_fl</samp>. 
<acronym><acronymword>NCO</acronymword></acronym> implements both options because they are largely
independent of eachother.
It is up to &textldquo;power users&textrdquo; to discover which best fit their needs.
We welcome accounts of your experiences posted to the forums.
</para>
<html endspaces=" ">
&lt;a name=&quot;-A&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-A --&gt;
&lt;a name=&quot;-O&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-O --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="208"><code>-A</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="209"><code>-O</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="210"><code>--apn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="211"><code>--append</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="212"><code>--ovr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="213"><code>--overwrite</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="214">overwriting files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="215">appending variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="216">appending to files</indexterm></cindex>
<para>Other safeguards exist to protect the user from inadvertently
overwriting data.
If the <var>output-file</var> specified for a command is a pre-existing file,
then the operator will prompt the user whether to overwrite (erase) the
existing <var>output-file</var>, attempt to append to it, or abort the
operation. 
However, in processing large amounts of data, too many interactive
questions slows productivity.
Therefore <acronym><acronymword>NCO</acronymword></acronym> also implements two ways to override its own
safety features, the <samp>-O</samp> and <samp>-A</samp> switches.
Specifying <samp>-O</samp> tells the operator to overwrite any existing
<var>output-file</var> without prompting the user interactively.
Specifying <samp>-A</samp> tells the operator to attempt to append to any
existing <var>output-file</var> without prompting the user interactively.
These switches are useful in batch environments because they suppress
interactive keyboard input.
</para>
<html endspaces=" ">
&lt;a name=&quot;apn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#apn --&gt;
&lt;a name=&quot;append&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#append --&gt;
</html>
</section>
<node name="Appending-Variables" spaces=" "><nodename>Appending Variables</nodename><nodenext spaces=" ">Simple Arithmetic and Interpolation</nodenext><nodeprev spaces=" ">Temporary Output Files</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Appending Variables</sectiontitle>
<para>Adding variables from one file to another is often desirable.
<cindex index="cp" spaces=" "><indexterm index="cp" number="217">concatenation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="218">appending variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="219">merging files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="220">pasting variables</indexterm></cindex>
This is referred to as <dfn>appending</dfn>, although some prefer the
terminology <dfn>merging</dfn> <footnote><para>The terminology <dfn>merging</dfn> is
reserved for an (unwritten) operator which replaces hyperslabs of a
variable in one file with hyperslabs of the same variable from another 
file</para></footnote> or <dfn>pasting</dfn>. 
Appending is often confused with what <acronym><acronymword>NCO</acronymword></acronym> calls
<dfn>concatenation</dfn>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="221">record dimension</indexterm></cindex>
In <acronym><acronymword>NCO</acronymword></acronym>, concatenation refers to splicing a variable
along the record dimension.  
The length along the record dimension of the output is the sum of the
lengths of the input files. 
Appending, on the other hand, refers to copying a variable from one file
to another file which may or may not already contain the variable 
<footnote><para>Yes, the terminology is confusing. 
By all means mail me if you think of a better nomenclature.
Should <acronym><acronymword>NCO</acronymword></acronym> use <dfn>paste</dfn> instead of <dfn>append</dfn>?
</para></footnote>. 
<acronym><acronymword>NCO</acronymword></acronym> can append or concatenate just one variable, or all the
variables in a file at the same time.
</para>
<para>In this sense, <command>ncks</command> can append variables from one file to
another file. 
This capability is invoked by naming two files on the command line,
<var>input-file</var> and <var>output-file</var>. 
When <var>output-file</var> already exists, the user is prompted whether to
<dfn>overwrite</dfn>, <dfn>append/replace</dfn>, or <dfn>exit</dfn> from the command.
Selecting <dfn>overwrite</dfn> tells the operator to erase the existing
<var>output-file</var> and replace it with the results of the operation.
Selecting <dfn>exit</dfn> causes the operator to exit&textmdash;the <var>output-file</var>
will not be touched in this case.
Selecting <dfn>append/replace</dfn> causes the operator to attempt to place
the results of the operation in the existing <var>output-file</var>, 
<xref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref>.
</para>
<html endspaces=" ">
&lt;a name=&quot;unn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#unn --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="222">union of files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="223">disjoint files</indexterm></cindex>
<para>The simplest way to create the union of two files is
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -A fl_1.nc fl_2.nc
</pre></example>
<para>This puts the contents of <file>fl_1.nc</file> into <file>fl_2.nc</file>. 
The <samp>-A</samp> is optional. 
On output, <file>fl_2.nc</file> is the union of the input files,
regardless of whether they share dimensions and variables, 
or are completely disjoint.
The append fails if the input files have differently named record
dimensions (since netCDF supports only one), or have dimensions of the
same name but different sizes.
</para>
<html endspaces=" ">
&lt;a name=&quot;bnr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bnr --&gt;
</html>
</section>
<node name="Simple-Arithmetic-and-Interpolation" spaces=" "><nodename>Simple Arithmetic and Interpolation</nodename><nodenext spaces=" ">Statistics vs Concatenation</nodenext><nodeprev spaces=" ">Appending Variables</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Simple Arithmetic and Interpolation</sectiontitle>

<para>Users comfortable with <acronym><acronymword>NCO</acronymword></acronym> semantics may find it easier to
perform some simple mathematical operations in <acronym><acronymword>NCO</acronymword></acronym> rather than  
higher level languages. 
<command>ncbo</command> (<pxref label="ncbo-netCDF-Binary-Operator"><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></pxref>) does file
addition, subtraction, multiplication, division, and broadcasting. 
It even does group broadcasting.
<command>ncflint</command> (<pxref label="ncflint-netCDF-File-Interpolator"><xrefnodename>ncflint netCDF File Interpolator</xrefnodename></pxref>) does
file addition, subtraction, multiplication and interpolation. 
Sequences of these commands can accomplish simple yet powerful
operations from the command line.
</para>
<html endspaces=" ">
&lt;a name=&quot;statisticians&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#statisticians --&gt;
&lt;a name=&quot;averagers&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#averagers --&gt;
</html>
</section>
<node name="Statistics-vs-Concatenation" spaces=" "><nodename>Statistics vs Concatenation</nodename><nodenext spaces=" ">Large Numbers of Files</nodenext><nodeprev spaces=" ">Simple Arithmetic and Interpolation</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Statistics vs Concatenation</sectiontitle>

<html endspaces=" ">
&lt;a name=&quot;sym_ncea&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sym_ncea --&gt;
&lt;a name=&quot;sym_nces&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sym_nces --&gt;
&lt;a name=&quot;sym_ncrcat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sym_ncrcat --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="224">symbolic links</indexterm></cindex>
<para>The most frequently used operators of <acronym><acronymword>NCO</acronymword></acronym> are probably the
<dfn>statisticians</dfn> (i.e., tools that do statistics) and concatenators.
Because there are so many types of statistics like averaging (e.g.,
across files, within a file, over the record dimension, over other
dimensions, with or without weights and masks) and of concatenating
(across files, along the record dimension, along other dimensions),
there are currently no fewer than five operators which tackle these two
purposes: <command>ncra</command>, <command>nces</command>, <command>ncwa</command>,
<command>ncrcat</command>, and <command>ncecat</command>.  
These operators do share many capabilities <footnote><para>Currently
<command>nces</command> and <command>ncrcat</command> are symbolically linked to the
<command>ncra</command> executable, which behaves slightly differently based on
its invocation name (i.e., <samp>argv[0]</samp>). 
These three operators share the same source code, and merely have
different inner loops.</para></footnote>, though each has its unique specialty.
Two of these operators, <command>ncrcat</command> and <command>ncecat</command>, 
concatenate hyperslabs across files. 
The other two operators, <command>ncra</command> and <command>nces</command>, compute
statistics across (and/or within) files 
<footnote><para>The third averaging operator, <command>ncwa</command>, is the most
sophisticated averager in <acronym><acronymword>NCO</acronymword></acronym>. 
However, <command>ncwa</command> is in a different class than <command>ncra</command> and
<command>nces</command> because it operates on a single file per invocation (as
opposed to multiple files).    
On that single file, however, <command>ncwa</command> provides a richer set of 
averaging options&textmdash;including weighting, masking, and broadcasting.</para></footnote>.  
First, let&textrsquo;s describe the concatenators, then the statistics tools.
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Concatenation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Averaging</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Interpolating</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;cnc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnc --&gt;
</html>
<node name="Concatenation" spaces=" "><nodename>Concatenation</nodename><nodenext spaces=" ">Averaging</nodenext><nodeprev spaces=" ">Statistics vs Concatenation</nodeprev><nodeup spaces=" ">Statistics vs Concatenation</nodeup></node>
<subsection spaces=" "><sectiontitle>Concatenators <command>ncrcat</command> and <command>ncecat</command></sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="225"><command>ncecat</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="226"><command>ncrcat</command></indexterm></cindex>

<para>Joining together independent files along a common record dimension is
called <dfn>concatenation</dfn>.    
<command>ncrcat</command> is designed for concatenating record variables, while
<command>ncecat</command> is designed for concatenating fixed length variables.
Consider five files, <file>85.nc</file>, <file>86.nc</file>, 
<w>&dots; <file>89.nc</file></w> each containing a year&textrsquo;s worth of data.  
Say you wish to create from them a single file, <file>8589.nc</file>
containing all the data, i.e., spanning all five years.
If the annual files make use of the same record variable, then
<command>ncrcat</command> will do the job nicely with, e.g., 
<code>ncrcat 8?.nc 8589.nc</code>. 
The number of records in the input files is arbitrary and can vary from
file to file. 
<xref label="ncrcat-netCDF-Record-Concatenator"><xrefnodename>ncrcat netCDF Record Concatenator</xrefnodename></xref>, for a complete description of
<command>ncrcat</command>. 
</para>
<para>However, suppose the annual files have no record variable, and thus
their data are all fixed length. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="227">ensemble</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="228">climate model</indexterm></cindex>
For example, the files may not be conceptually sequential, but rather
members of the same group, or <dfn>ensemble</dfn>. 
Members of an ensemble may have no reason to contain a record dimension.
<command>ncecat</command> will create a new record dimension (named <var>record</var>
by default) with which to glue together the individual files into the
single ensemble file.
If <command>ncecat</command> is used on files which contain an existing record
dimension, that record dimension is converted to a fixed-length
dimension of the same name and a new record dimension (named
<code>record</code>) is created.  
Consider five realizations, <file>85a.nc</file>, <file>85b.nc</file>, 
<w>&dots; <file>85e.nc</file></w> of 1985 predictions from the same climate
model. 
Then <code>ncecat 85?.nc 85_ens.nc</code> glues together the individual
realizations into the single file, <file>85_ens.nc</file>. 
If an input variable was dimensioned [<code>lat</code>,<code>lon</code>], it will
have dimensions [<code>record</code>,<code>lat</code>,<code>lon</code>] in the output file.
<w>A restriction</w> of <command>ncecat</command> is that the hyperslabs of the
processed variables must be the same from file to file.
Normally this means all the input files are the same size, and contain 
data on different realizations of the same variables.
<xref label="ncecat-netCDF-Ensemble-Concatenator"><xrefnodename>ncecat netCDF Ensemble Concatenator</xrefnodename></xref>, for a complete description
of <command>ncecat</command>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="229"><command>ncpdq</command></indexterm></cindex>
<html endspaces=" ">
&lt;a name=&quot;dmn_cat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dmn_cat --&gt;
</html>
<para><command>ncpdq</command> makes it possible to concatenate files along any
dimension, not just the record dimension.
First, use <command>ncpdq</command> to convert the dimension to be concatenated
(i.e., extended with data from other files) into the record dimension. 
Second, use <command>ncrcat</command> to concatenate these files.
Finally, if desirable, use <command>ncpdq</command> to revert to the original
dimensionality.
As a concrete example, say that files <file>x_01.nc</file>, <file>x_02.nc</file>,
<w>&dots; <file>x_10.nc</file></w> contain time-evolving datasets from spatially
adjacent regions.
The time and spatial coordinates are <code>time</code> and <code>x</code>, respectively.
Initially the record dimension is <code>time</code>.
Our goal is to create a single file that contains joins all the
spatially adjacent regions into one single time-evolving dataset.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for idx in 01 02 03 04 05 06 07 08 09 10; do # Bourne Shell
  ncpdq -a x,time x_${idx}.nc foo_${idx}.nc  # Make x record dimension
done
ncrcat foo_??.nc out.nc       # Concatenate along x
ncpdq -a time,x out.nc out.nc # Revert to time as record dimension
</verbatim>
</example>

<para>Note that <command>ncrcat</command> will not concatenate fixed-length variables, 
whereas <command>ncecat</command> concatenates both fixed-length and record
variables along a new record variable.
To conserve system memory, use <command>ncrcat</command> where possible.
</para>
<html endspaces=" ">
&lt;a name=&quot;avg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#avg --&gt;
</html>
</subsection>
<node name="Averaging" spaces=" "><nodename>Averaging</nodename><nodenext spaces=" ">Interpolating</nodenext><nodeprev spaces=" ">Concatenation</nodeprev><nodeup spaces=" ">Statistics vs Concatenation</nodeup></node>
<subsection spaces=" "><sectiontitle>Averagers <command>nces</command>, <command>ncra</command>, and <command>ncwa</command> </sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="230"><command>nces</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="231"><command>ncra</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="232"><command>ncwa</command></indexterm></cindex>

<para>The differences between the averagers <command>ncra</command> and <command>nces</command>
are analogous to the differences between the concatenators.
<command>ncra</command> is designed for averaging record variables from at least
one file, while <command>nces</command> is designed for averaging fixed length
variables from multiple files.
<command>ncra</command> performs a simple arithmetic average over the record
dimension of all the input files, with each record having an equal
weight in the average. 
<command>nces</command> performs a simple arithmetic average of all the input
files, with each file having an equal weight in the average. 
Note that <command>ncra</command> cannot average fixed-length variables,
but <command>nces</command> can average both fixed-length and record variables.  
To conserve system memory, use <command>ncra</command> rather than
<command>nces</command> where possible (e.g., if each <var>input-file</var> is one
record long). 
The file output from <command>nces</command> will have the same dimensions
(meaning dimension names as well as sizes) as the input hyperslabs  
(<pxref label="nces-netCDF-Ensemble-Statistics"><xrefnodename>nces netCDF Ensemble Statistics</xrefnodename></pxref>, for a complete description of 
<command>nces</command>).  
The file output from <command>ncra</command> will have the same dimensions as
the input hyperslabs except for the record dimension, which will have a   
size <w>of 1</w> (<pxref label="ncra-netCDF-Record-Averager"><xrefnodename>ncra netCDF Record Averager</xrefnodename></pxref>, for a complete
description of <command>ncra</command>). 
</para>
<html endspaces=" ">
&lt;a name=&quot;ntp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ntp --&gt;
</html>
</subsection>
<node name="Interpolating" spaces=" "><nodename>Interpolating</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Averaging</nodeprev><nodeup spaces=" ">Statistics vs Concatenation</nodeup></node>
<subsection spaces=" "><sectiontitle>Interpolator <command>ncflint</command></sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="233"><command>ncflint</command></indexterm></cindex>

<para><command>ncflint</command> can interpolate data between or two files.
Since no other operators have this ability, the description of
interpolation is given fully on the <command>ncflint</command> reference page
(<pxref label="ncflint-netCDF-File-Interpolator"><xrefnodename>ncflint netCDF File Interpolator</xrefnodename></pxref>). 
Note that this capability also allows <command>ncflint</command> to linearly
rescale any data in a netCDF file, e.g., to convert between differing
units. 
</para>
<html endspaces=" ">
&lt;a name=&quot;lrg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lrg --&gt;
&lt;a name=&quot;input_files&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#input_files --&gt;
</html>
</subsection>
</section>
<node name="Large-Numbers-of-Files" spaces=" "><nodename>Large Numbers of Files</nodename><nodenext spaces=" ">Large Datasets</nodenext><nodeprev spaces=" ">Statistics vs Concatenation</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Large Numbers of Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="234">files, numerous input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="235"><code>-n <var>loop</var></code></indexterm></cindex>

<para>Occasionally one desires to digest (i.e., concatenate or average)
hundreds or thousands of input files.
<cindex index="cp" spaces=" "><indexterm index="cp" number="236">automagic</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="237"><acronym><acronymword>NASA EOSDIS</acronymword></acronym></indexterm></cindex>
Unfortunately, data archives (e.g., <acronym><acronymword>NASA EOSDIS</acronymword></acronym>) may not
name netCDF files in a format understood by the <samp>-n <var>loop</var></samp>
switch (<pxref label="Specifying-Input-Files"><xrefnodename>Specifying Input Files</xrefnodename></pxref>) that automagically generates
arbitrary numbers of input filenames. 
The <samp>-n <var>loop</var></samp> switch has the virtue of being concise,
and of minimizing the command line.
This helps keeps output file small since the command line is stored
as metadata in the <code>history</code> attribute 
(<pxref label="History-Attribute"><xrefnodename>History Attribute</xrefnodename></pxref>). 
However, the <samp>-n <var>loop</var></samp> switch is useless when there is no
simple, arithmetic pattern to the input filenames (e.g.,
<file>h00001.nc</file>, <file>h00002.nc</file>, <w>&dots; <file>h90210.nc</file></w>).
Moreover, filename globbing does not work when the input files are too
numerous or their names are too lengthy (when strung together as a
single argument) to be passed by the calling shell to the <acronym><acronymword>NCO</acronymword></acronym>
operator
<footnote><para>The exact length which exceeds the operating system internal
limit for command line lengths varies across <acronym><acronymword>OS</acronymword></acronym>s and shells.
<acronym><acronymword>GNU</acronymword></acronym> <code>bash</code> may not have any arbitrary fixed limits to the
size of command line arguments. 
Many <acronym><acronymword>OS</acronymword></acronym>s cannot handle command line arguments (including
results of file globbing) exceeding 4096 characters.</para></footnote>.
When this occurs, the <acronym><acronymword>ANSI</acronymword></acronym> C-standard <code>argc</code>-<code>argv</code> 
method of passing arguments from the calling shell to a C-program (i.e.,
an <acronym><acronymword>NCO</acronymword></acronym> operator) breaks down. 
There are (at least) three alternative methods of specifying the input 
filenames to <acronym><acronymword>NCO</acronymword></acronym> in environment-limited situations.
</para>
<html endspaces=" ">
&lt;a name=&quot;stdin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#stdin --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="238">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="239">provenance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="240"><code>stdin</code></indexterm></cindex>
<para>The recommended method for sending very large numbers (hundreds or
more, typically) of input filenames to the multi-file operators is
to pass the filenames with the <acronym><acronymword>UNIX</acronymword></acronym> <dfn>standard input</dfn>
feature, aka <code>stdin</code>: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Pipe large numbers of filenames to stdin
/bin/ls | grep ${CASEID}_'......'.nc | ncecat -o foo.nc
</verbatim>
</example>
<para>This method avoids all constraints on command line size imposed by
the operating system. 
A drawback to this method is that the <code>history</code> attribute
(<pxref label="History-Attribute"><xrefnodename>History Attribute</xrefnodename></pxref>) does not record the name of any input 
files since the names were not passed as positional arguments
on the command line.
This makes it difficult later to determine the data provenance.
<cindex index="cp" spaces=" "><indexterm index="cp" number="241"><code>nco_input_file_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="242"><code>nco_input_file_list</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="243">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="244">attributes, global</indexterm></cindex>
To remedy this situation, operators store the number of input files in
the <code>nco_input_file_number</code> global attribute and the input file
list itself in the <code>nco_input_file_list</code> global attribute
(<pxref label="File-List-Attributes"><xrefnodename>File List Attributes</xrefnodename></pxref>). 
Although this does not preserve the exact command used to generate the
file, it does retains all the information required to reconstruct the
command and determine the data provenance.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.1.1</w>, released in November, 2022,
all operators support specifying input files via <code>stdin</code>
(<pxref label="Specifying-Input-Files"><xrefnodename>Specifying Input Files</xrefnodename></pxref>), and also store such input filenames
in the <ref label="File-List-Attributes"><xrefnodename>File List Attributes</xrefnodename></ref>).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="245">globbing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="246">shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="247">extended regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="248">regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="249">pattern matching</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="250"><command>xargs</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="251"><acronym><acronymword>UNIX</acronymword></acronym></indexterm></cindex>
<para>A second option is to use the <acronym><acronymword>UNIX</acronymword></acronym> <command>xargs</command> command.
This simple example selects as input to <command>xargs</command> all the
filenames in the current directory that match a given pattern.
For illustration, consider a user trying to average millions of 
files which each have a six character filename. 
If the shell buffer cannot hold the results of the corresponding
globbing operator, <file>??????.nc</file>, then the filename globbing
technique will fail. 
Instead we express the filename pattern as an extended regular 
expression, <file>......\.nc</file> (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>).
We use <command>grep</command> to filter the directory listing for this pattern
and to pipe the results to <command>xargs</command> which, in turn, passes the
matching filenames to an <acronym><acronymword>NCO</acronymword></acronym> multi-file operator, e.g.,
<command>ncecat</command>.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Use xargs to transfer filenames on the command line
/bin/ls | grep ${CASEID}_'......'.nc | xargs -x ncecat -o foo.nc
</verbatim>
</example>
<cindex index="cp" spaces=" "><indexterm index="cp" number="252">pipes</indexterm></cindex>
<para>The single quotes protect the only sensitive parts of the extended
regular expression (the <command>grep</command> argument), and allow shell
interpolation (the <code>$&lbrace;CASEID&rbrace;</code> variable substitution) to
proceed unhindered on the rest of the command.
<command>xargs</command> uses the <acronym><acronymword>UNIX</acronymword></acronym> pipe feature to append the
suitably filtered input file list to the end of the <command>ncecat</command>
command options.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="253">output file</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="254">input files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="255"><code>-o <var>fl_out</var></code></indexterm></cindex>
The <code>-o foo.nc</code> switch ensures that the input files supplied by
<command>xargs</command> are not confused with the output file name. 
<command>xargs</command> does, unfortunately, have its own limit (usually about 
20,000 characters) on the size of command lines it can pass.
Give <command>xargs</command> the <samp>-x</samp> switch to ensure it dies if it
reaches this internal limit.
When this occurs, use either the <code>stdin</code> method above, or the
symbolic link presented next.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="256">symbolic links</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="257">Perl</indexterm></cindex>
<para>Even when its internal limits have not been reached, the
<command>xargs</command> technique may not be flexible enough to handle 
all situations. 
A full scripting language like Perl or Python can handle any level of
complexity of filtering input filenames, and any number of filenames.
The technique of last resort is to write a script that creates symbolic 
links between the irregular input filenames and a set of regular,
arithmetic filenames that the <samp>-n <var>loop</var></samp> switch understands. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="258">Perl</indexterm></cindex>
For example, the following Perl script creates a monotonically
enumerated symbolic link to up to one million <file>.nc</file> files in a
directory. If there are 999,999 netCDF files present, the links are
named <file>000001.nc</file> to <file>999999.nc</file>: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="259"><code>-n <var>loop</var></code></indexterm></cindex>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Create enumerated symbolic links
/bin/ls | grep \.nc | perl -e \
'$idx=1;while(&lt;STDIN&gt;){chop;symlink $_,sprintf(&quot;%06d.nc&quot;,$idx++);}'
ncecat -n 999999,6,1 000001.nc foo.nc
# Remove symbolic links when finished
/bin/rm ??????.nc
</verbatim>
</example>
<para>The <samp>-n <var>loop</var></samp> option tells the <acronym><acronymword>NCO</acronymword></acronym> operator to
automatically generate the filnames of the symbolic links.
This circumvents any <acronym><acronymword>OS</acronymword></acronym> and shell limits on command-line size.
The symbolic links are easily removed once <acronym><acronymword>NCO</acronymword></acronym> is finished.
<cindex index="cp" spaces=" "><indexterm index="cp" number="260"><code>history</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="261">provenance</indexterm></cindex>
One drawback to this method is that the <code>history</code> attribute
(<pxref label="History-Attribute"><xrefnodename>History Attribute</xrefnodename></pxref>) retains the filename list of the symbolic
links, rather than the data files themselves. 
This makes it difficult to determine the data provenance at a later
date. 
</para>
</section>
<node name="Large-Datasets" spaces=" "><nodename>Large Datasets</nodename><nodenext spaces=" ">Memory Requirements</nodenext><nodeprev spaces=" ">Large Numbers of Files</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Large Datasets</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="262">large datasets</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="263"><acronym><acronymword>LFS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="264">Large File Support</indexterm></cindex>

<para><dfn>Large datasets</dfn> are those files that are comparable in size to the
amount of random access memory (<acronym><acronymword>RAM</acronymword></acronym>) in your computer.
Many users of <acronym><acronymword>NCO</acronymword></acronym> work with files larger than <w>100 MB</w>.
Files this large not only push the current edge of storage technology, 
they present special problems for programs which attempt to access the  
entire file at once, such as <command>nces</command> and <command>ncecat</command>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="265">swap space</indexterm></cindex>
If you work with a <w>300 MB</w> files on a machine with only <w>32 MB</w> of
memory then you will need large amounts of swap space (virtual memory on
disk) and <acronym><acronymword>NCO</acronymword></acronym> will work slowly, or even fail. 
There is no easy solution for this.
The best strategy is to work on a machine with sufficient amounts of
memory and swap space. 
Since about 2004, many users have begun to produce or analyze files
exceeding <w>2 GB</w> in size. 
These users should familiarize themselves with <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s Large
File Support (<acronym><acronymword>LFS</acronymword></acronym>) capabilities (<pxref label="Large-File-Support"><xrefnodename>Large File Support</xrefnodename></pxref>).
The next section will increase your familiarity with <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s
memory requirements.
With this knowledge you may re-design your data reduction approach to
divide the problem into pieces solvable in memory-limited situations.   
</para>
<html endspaces=" ">
&lt;a name=&quot;ulimit&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ulimit --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="266">server</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="267"><acronym><acronymword>UNICOS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="268">Cray</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="269"><acronym><acronymword>GNU</acronymword></acronym>/Linux</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="270"><code>ulimit</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="271"><code>core dump</code></indexterm></cindex>
<para>If your local machine has problems working with large files, try running
<acronym><acronymword>NCO</acronymword></acronym> from a more powerful machine, such as a network server.  
If you get a memory-related core dump 
(e.g., <samp>Error exit (core dumped)</samp>) on a <acronym><acronymword>GNU</acronymword></acronym>/Linux system,
or the operation ends before the entire output file is written,
try increasing the process-available memory with <code>ulimit</code>:
</para><example endspaces=" ">
<pre xml:space="preserve">ulimit -f unlimited
</pre></example>
<para>This may solve constraints on clusters where sufficient hardware
resources exist yet where system administrators felt it wise to prevent 
any individual user from consuming too much of resource. 
Certain machine architectures, e.g., Cray <acronym><acronymword>UNICOS</acronymword></acronym>, have special 
commands which allow one to increase the amount of interactive memory.
<cindex index="cp" spaces=" "><indexterm index="cp" number="272"><code>ilimit</code></indexterm></cindex>
On Cray systems, try to increase the available memory with the
<code>ilimit</code> command.    
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="273">speed</indexterm></cindex>
<para>The speed of the <acronym><acronymword>NCO</acronymword></acronym> operators also depends on file size.
When processing large files the operators may appear to hang, or do
nothing, for large periods of time.
In order to see what the operator is actually doing, it is useful to
activate a more verbose output mode.
This is accomplished by supplying a number greater <w>than 0</w> to the
<samp>-D <var>debug-level</var></samp> (or <samp>--debug-level</samp>, or
<samp>--dbg_lvl</samp>) switch.
<cindex index="cp" spaces=" "><indexterm index="cp" number="274"><code>-D <var>debug-level</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="275"><code>--debug-level <var>debug-level</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="276"><code>--dbg_lvl <var>debug-level</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="277"><var>debug-level</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="278"><var>dbg_lvl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="279">debugging</indexterm></cindex>
When the <var>debug-level</var> is non-zero, the operators report their
current status to the terminal through the <var>stderr</var> facility.
Using <samp>-D</samp> does not slow the operators down. 
Choose a <var>debug-level</var> <w>between 1</w> <w>and 3</w> for most situations,
e.g., <code>nces -D 2 85.nc 86.nc 8586.nc</code>.
<w>A full</w> description of how to estimate the actual amount of memory the
multi-file <acronym><acronymword>NCO</acronymword></acronym> operators consume is given in 
<ref label="Memory-Requirements"><xrefnodename>Memory Requirements</xrefnodename></ref>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;mmr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mmr --&gt;
</html>
</section>
<node name="Memory-Requirements" spaces=" "><nodename>Memory Requirements</nodename><nodenext spaces=" ">Performance</nodenext><nodeprev spaces=" ">Large Datasets</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Memory Requirements</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="280">memory requirements</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="281">memory available</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="282"><acronym><acronymword>RAM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="283">swap space</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="284">peak memory usage</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="285"><code>--ram_all</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="286"><code>--open_ram</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="287"><code>--diskless_all</code></indexterm></cindex>

<para>Many people use <acronym><acronymword>NCO</acronymword></acronym> on gargantuan files which dwarf the
memory available (free <acronym><acronymword>RAM</acronymword></acronym> plus swap space) even on today&textrsquo;s powerful
machines. 
These users want <acronym><acronymword>NCO</acronymword></acronym> to consume the least memory possible
so that their scripts do not have to tediously cut files into smaller
pieces that fit into memory. 
We commend these greedy users for pushing <acronym><acronymword>NCO</acronymword></acronym> to its limits!
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="288">threads</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="289">OpenMP</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="290">shared memory machines</indexterm></cindex>
<para>This section describes the memory <acronym><acronymword>NCO</acronymword></acronym> requires during
operation.
The required memory depends on the underlying algorithms, datatypes,
and compression, if any. 
The description below is the memory usage per thread.
Users with shared memory machines may use the threaded <acronym><acronymword>NCO</acronymword></acronym>
operators (<pxref label="OpenMP-Threading"><xrefnodename>OpenMP Threading</xrefnodename></pxref>).
The peak and sustained memory usage will scale accordingly,
i.e., by the number of threads.
In all cases the memory use refers to the <emph>uncompressed</emph> size of
the data. 
The netCDF4 library automatically decompresses variables during reads. 
The filesize can easily belie the true size of the uncompressed data.
In other words, the usage below can be taken at face value for netCDF3
datasets only.
Chunking will also affect memory usage on netCDF4 operations.
Memory consumption patterns of all operators are similar, with
the exception of <command>ncap2</command>.
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Single and Multi-file Operators</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Memory for ncap2</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="Single-and-Multi_002dfile-Operators" spaces=" "><nodename>Single and Multi-file Operators</nodename><nodenext spaces=" ">Memory for ncap2</nodenext><nodeprev spaces=" ">Memory Requirements</nodeprev><nodeup spaces=" ">Memory Requirements</nodeup></node>
<subsection spaces=" "><sectiontitle>Single and Multi-file Operators</sectiontitle>

<cindex index="cp" spaces=" "><indexterm index="cp" number="291">multi-file operators</indexterm></cindex>
<para>The multi-file operators currently comprise the record operators,
<command>ncra</command> and <command>ncrcat</command>, and the ensemble operators,
<command>nces</command> and <command>ncecat</command>. 
The record operators require <emph>much less</emph> memory than the ensemble 
operators. 
This is because the record operators operate on one single record (i.e.,
time-slice) at a time, whereas the ensemble operators retrieve the
entire variable into memory. 
Let <math>MS</math> be the peak sustained memory demand of an operator,
<math>FT</math> be the memory required to store the entire contents of all the 
variables to be processed in an input file,
<math>FR</math> be the memory required to store the entire contents of a
single record of each of the variables to be processed in an input file, 
<math>VR</math> be the memory required to store a single record of the
largest record variable to be processed in an input file, 
<math>VT</math> be the memory required to store the largest variable 
to be processed in an input file,
<math>VI</math> be the memory required to store the largest variable 
which is not processed, but is copied from the initial file to the
output file. 
All operators require <math>MI = VI</math> during the initial copying of
variables from the first input file to the output file. 
This is the <emph>initial</emph> (and transient) memory demand.
The <emph>sustained</emph> memory demand is that memory required by the
operators during the processing (i.e., averaging, concatenation)
phase which lasts until all the input files have been processed.
The operators have the following memory requirements: 
<command>ncrcat</command> requires <math>MS &lt;= VR</math>. 
<command>ncecat</command> requires <math>MS &lt;= VT</math>. 
<command>ncra</command> requires <math>MS = 2FR + VR</math>. 
<command>nces</command> requires <math>MS = 2FT + VT</math>. 
<command>ncbo</command> requires <math>MS &lt;= 3VT</math> 
(both input variables and the output variable).
<command>ncflint</command> requires <math>MS &lt;= 3VT</math>
(both input variables and the output variable).
<command>ncpdq</command> requires <math>MS &lt;= 2VT</math>
(one input variable and the output variable).
<command>ncwa</command> requires <math>MS &lt;= 8VT</math> (see below).
Note that only variables that are processed, e.g., averaged,
concatenated, or differenced, contribute to <math>MS</math>. 
Variables that do not appear in the output file 
(<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>) are never read and contribute nothing
to the memory requirements. 
</para>
<para>Further note that some operators perform internal type-promotion on some
variables prior to arithmetic (<pxref label="Type-Conversion"><xrefnodename>Type Conversion</xrefnodename></pxref>).
For example, <command>ncra</command>, <command>nces</command>, and <command>ncwa</command> all
promote integer types to double-precision floating-point prior to
arithmetic, then perform the arithmetic, then demote back to the
original integer type after arithmetic.
This preserves the on-disk storage type while obtaining the precision
advantages of double-precision floating-point arithmetic. 
Since version 4.3.6 (released in September, 2013), <acronym><acronymword>NCO</acronymword></acronym> also
by default converts single-precision floating-point to double-precision
prior to arithmetic, which incurs the same <acronym><acronymword>RAM</acronymword></acronym> penalty.
Hence, the sustained memory required for integer variables and
single-precision floats are two or four-times their on-disk,
uncompressed, unpacked sizes if they meet the rules for automatic
internal promotion. 
Put another way, disabling auto-promotion of single-precision variables
(with <samp>--flt</samp>) considerably reduces the <acronym><acronymword>RAM</acronymword></acronym> footprint 
of arithmetic operators.
</para>
<para>The <samp>--open_ram</samp> switch (and switches that invoke it like
<samp>--ram_all</samp> and <samp>--diskless_all</samp>) incurs a <acronym><acronymword>RAM</acronymword></acronym>
penalty.
These switches cause each input file to be copied to <acronym><acronymword>RAM</acronymword></acronym> upon
opening. 
Hence any operator invoking these switches utilizes an additional
<math>FT</math> of <acronym><acronymword>RAM</acronymword></acronym> (i.e., <math>MS += FT</math>).
See <ref label="RAM-disks"><xrefnodename>RAM disks</xrefnodename></ref> for further details. 
</para>
<html endspaces=" ">
&lt;a name=&quot;mmr_ncwa&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mmr_ncwa --&gt;
</html>
<para><command>ncwa</command> consumes between two and eight times the memory of an
<code>NC_DOUBLE</code> variable in order to process it. 
Peak consumption occurs when storing simultaneously in memory 
one input variable, one tally array,
one input weight, one conformed/working weight, one weight tally, 
one input mask, one conformed/working mask, and
one output variable. 
<acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s tally arrays are of type C-type <code>long</code>, whose size 
is eight-bytes on all modern computers, the same as <code>NC_DOUBLE</code>
<footnote><para>By contrast <code>NC_INT</code> and its deprecated synonym
<code>NC_LONG</code> are only four-bytes.
Perhaps this is one reason why the <code>NC_LONG</code> token is
deprecated.</para></footnote>. 
When invoked, the weighting and masking features contribute up to
three-eighths and two-eighths of these requirements apiece.
If weights and masks are <emph>not</emph> specified 
(i.e., no <samp>-w</samp> or <samp>-a</samp> options)
then <command>ncwa</command> requirements drop to <math>MS &lt;= 3VT</math>
(one input variable, one tally array, and the output variable). 
The output variable is the same size as the input variable when 
averaging only over a degenerate dimension.
However, normally the output variable is much smaller than the input, 
and is often a simple scalar, in which case the memory requirements
drop by <math>1VT</math> since the output array requires essentially no
memory. 
</para>
<para>All of this is subject to the type promotion rules mentioned above.
For example, <command>ncwa</command> averaging a variable of type
<code>NC_FLOAT</code> requires <math>MS &lt;= 16VT</math> (rather than <math>MS &lt;= 8VT</math>) 
since all arrays are (at least temporarily) composed of eight-byte
elements, twice the size of the values on disk.
Without mask or weights, the requirements for <code>NC_FLOAT</code> are
<math>MS &lt;= 6VT</math> (rather than <math>MS &lt;= 3VT</math> as for <code>NC_DOUBLE</code>) 
due to temporary internal promotion of both the input variable and the
output variable to type <code>NC_DOUBLE</code>. 
The <samp>--flt</samp> option that suppresses promotion reduces this to
<math>MS &lt;= 4VT</math> (the tally elements do not change size), and to
<math>MS &lt;= 3VT</math> when the output array is a scalar.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="292">OpenMP</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="293">threads</indexterm></cindex>
<para>The above memory requirements must be multiplied by the number of
threads <var>thr_nbr</var> (<pxref label="OpenMP-Threading"><xrefnodename>OpenMP Threading</xrefnodename></pxref>).
<cindex index="cp" spaces=" "><indexterm index="cp" number="294"><code>-t <var>thr_nbr</var></code></indexterm></cindex>
If this causes problems then reduce (with <samp>-t <var>thr_nbr</var></samp>) the
number of threads.
</para>
</subsection>
<node name="Memory-for-ncap2" spaces=" "><nodename>Memory for ncap2</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Single and Multi-file Operators</nodeprev><nodeup spaces=" ">Memory Requirements</nodeup></node>
<subsection spaces=" "><sectiontitle>Memory for <command>ncap2</command></sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="295"><command>ncap2</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="296">binary operations</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="297">unary operations</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="298">memory leaks</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="299">left hand casting</indexterm></cindex>
<para><command>ncap2</command> has unique memory requirements due its ability to process
arbitrarily long scripts of any complexity.
All scripts acceptable to <command>ncap2</command> are ultimately processed as a
sequence of binary or unary operations.
<command>ncap2</command> requires <math>MS &lt;= 2VT</math> under most conditions.
An exception to this is when left hand casting (<pxref label="Left-hand-casting"><xrefnodename>Left hand
casting</xrefnodename></pxref>) is used to stretch the size of derived variables beyond the
size of any input variables.
Let <math>VC</math> be the memory required to store the largest variable
defined by left hand casting.
In this case, <math>MS &lt;= 2VC</math>.
</para>
<findex index="fn" spaces=" "><indexterm index="fn" number="4" mergedindex="cp">malloc()</indexterm></findex>
<para><command>ncap2</command> scripts are complete dynamic and may be of arbitrary
length. 
A script that contains many thousands of operations, may uncover a
slow memory leak even though each single operation consumes little
additional memory. 
Memory leaks are usually identifiable by their memory usage signature.
Leaks cause peak memory usage to increase monotonically with time
regardless of script complexity. 
Slow leaks are very difficult to find.
Sometimes a <command>malloc()</command> (or <command>new[]</command>) failure is the
only noticeable clue to their existence.
If you have good reasons to believe that a memory allocation failure  
is ultimately due to an <acronym><acronymword>NCO</acronymword></acronym> memory leak (rather than
inadequate <acronym><acronymword>RAM</acronymword></acronym> on your system), then we would be very
interested in receiving a detailed bug report. 
</para>
</subsection>
</section>
<node name="Performance" spaces=" "><nodename>Performance</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Memory Requirements</nodeprev><nodeup spaces=" ">Strategies</nodeup></node>
<section spaces=" "><sectiontitle>Performance</sectiontitle>

<cindex index="cp" spaces=" "><indexterm index="cp" number="300">papers</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="301">overview</indexterm></cindex>
<para>An overview of <acronym><acronymword>NCO</acronymword></acronym> capabilities as of about 2006 is in
Zender, C. S. (2008), 
&textldquo;Analysis of Self-describing Gridded Geoscience Data with netCDF Operators (NCO)&textrdquo;,
Environ. Modell. Softw., doi:10.1016/j.envsoft.2008.03.004.
This paper is also available at
<url><urefurl>http://dust.ess.uci.edu/ppr/ppr_Zen08.pdf</urefurl></url>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="302">scaling</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="303">performance</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> performance and scaling for arithmetic operations is
described in 
Zender, C. S., and H. J. Mangalam (2007), 
&textldquo;Scaling Properties of Common Statistical Operators for Gridded Datasets&textrdquo;, 
Int. <w>J. High</w> Perform. Comput. Appl., 21(4), 485-498,
doi:10.1177/1094342007083802. 
This paper is also available at
<url><urefurl>http://dust.ess.uci.edu/ppr/ppr_ZeM07.pdf</urefurl></url>.
</para>
<para>It is helpful to be aware of the aspects of <acronym><acronymword>NCO</acronymword></acronym> design 
that can limit its performance:
</para><enumerate first="1" endspaces=" ">
<listitem> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="304">buffering</indexterm></cindex>
<para>No data buffering is performed during <command>nc_get_var</command> and
<command>nc_put_var</command> operations.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="305">performance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="306">operator speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="307">speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="308">execution time</indexterm></cindex>
Hyperslabs too large to hold in core memory will suffer substantial
performance penalties because of this. 
</para>
</listitem><listitem> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="309">monotonic coordinates</indexterm></cindex>
<para>Since coordinate variables are assumed to be monotonic, the search for 
bracketing the user-specified limits should employ a quicker algorithm,
like bisection, than the two-sided incremental search currently
implemented.  
</para>
</listitem><listitem> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="310"><var>C_format</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="311"><var>FORTRAN_format</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="312"><var>signedness</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="313"><var>scale_format</var></indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="314"><var>add_offset</var></indexterm></cindex> 
<para><var>C_format</var>, <var>FORTRAN_format</var>, <var>signedness</var>,
<var>scale_format</var> and <var>add_offset</var> attributes are ignored by
<command>ncks</command> when printing variables to screen. 
</para>
</listitem><listitem>
<cindex index="cp" spaces=" "><indexterm index="cp" number="315">Yorick</indexterm></cindex>
<para>In the late 1990s it was discovered that some random access operations
on large files on certain architectures (e.g., <acronym><acronymword>UNICOS</acronymword></acronym>) were
much slower with <acronym><acronymword>NCO</acronymword></acronym> than with similar operations performed
using languages that bypass the netCDF interface (e.g., Yorick).    
This may have been a penalty of unnecessary byte-swapping in the netCDF 
interface.  
It is unclear whether such problems exist in present day (2007)
netCDF/<acronym><acronymword>NCO</acronymword></acronym> environments, where unnecessary byte-swapping has
been reduced or eliminated.
</para></listitem></enumerate>

<html endspaces=" ">
&lt;a name=&quot;ftr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ftr --&gt;
</html>
</section>
</chapter>
<node name="Shared-features" spaces=" "><nodename>Shared features</nodename><nodenext spaces=" ">Reference Manual</nodenext><nodeprev spaces=" ">Strategies</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>Shared Features</sectiontitle>

<para>Many features have been implemented in more than one operator and are
described here for brevity. 
The description of each feature is preceded by a box listing the
operators for which the feature is implemented. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="316">command line switches</indexterm></cindex>
Command line switches for a given feature are consistent across all
operators wherever possible. 
If no &textldquo;key switches&textrdquo; are listed for a feature, then that particular
feature is automatic and cannot be controlled by the user. 
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Internationalization</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Metadata Optimization</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>OpenMP Threading</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Command Line Options</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Sanitization of Input</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Specifying Input Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Specifying Output Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Remote storage</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Retaining Retrieved Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>File Formats and Conversion</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Zarr and NCZarr</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Large File Support</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Subsetting Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Subsetting Coordinate Variables</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Group Path Editing</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>C and Fortran Index Conventions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Hyperslabs</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Stride</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Record Appending</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Subcycle</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Interleave</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Multislabs</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Wrapped Coordinates</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Auxiliary Coordinates</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Grid Generation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Regridding</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Climatology and Bounds Support</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>UDUnits Support</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Rebasing Time Coordinate</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Multiple Record Dimensions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Missing Values</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Chunking</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Quantization Algorithms</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Compression</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Deflation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>MD5 digests</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Buffer sizes</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>RAM disks</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Unbuffered I/O</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Packed data</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Operation Types</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Type Conversion</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Batch Mode</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Global Attribute Addition</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>History Attribute</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>File List Attributes</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>CF Conventions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ARM Conventions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Operator Version</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;i18n&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#i18n --&gt;
</html>
<node name="Internationalization" spaces=" "><nodename>Internationalization</nodename><nodenext spaces=" ">Metadata Optimization</nodenext><nodeprev spaces=" ">Shared features</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Internationalization</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="317">Internationalization</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="318">I18N</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
</para></cartouche>
<cindex index="cp" spaces=" "><indexterm index="cp" number="319">L10N</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> support for <dfn>internationalization</dfn> of textual input
and output (e.g., Warning messages) is nascent.
We introduced the first foreign language string catalogues (French and
Spanish) in 2004, yet did not activate these in distributions because 
the catalogues were nearly empty.
We seek volunteers to populate our templates with translations for their
favorite languages.
<!-- c fxm: Work on this section -->
</para>
<html endspaces=" ">
&lt;a name=&quot;hdr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdr --&gt;
&lt;a name=&quot;hdr_pad&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdr_pad --&gt;
</html>
</section>
<node name="Metadata-Optimization" spaces=" "><nodename>Metadata Optimization</nodename><nodenext spaces=" ">OpenMP Threading</nodenext><nodeprev spaces=" ">Internationalization</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Metadata Optimization</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="320">metadata optimization</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="321">performance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="322">operator speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="323">speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="324">execution time</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="325"><code>nc__enddef()</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="326"><code>--hdr_pad <var>hdr_pad</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="327"><code>--header_pad <var>hdr_pad</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: None&linebreak;
Long options: <samp>--hdr_pad</samp>, <samp>--header_pad</samp>&linebreak; 
</para></cartouche>
<para><acronym><acronymword>NCO</acronymword></acronym> supports padding headers to improve the speed of future
metadata operations.
Use the <samp>--hdr_pad</samp> and <samp>--header_pad</samp> switches to request
that <var>hdr_pad</var> bytes be inserted into the metadata section of the
output file.
There is little downside to padding a header with kilobyte of space,
since subsequent manipulation of the file will annotate the
<code>history</code> attribute with all commands, let alone any explicit
metadata additions with <command>ncatted</command>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --hdr_pad=1000  in.nc out.nc # Pad header with  1 kB space
ncks --hdr_pad=10000 in.nc out.nc # Pad header with 10 kB space
</pre></example>
<para>Future metadata expansions will not incur the netCDF3 performance
penalty of copying the entire output file unless the expansion exceeds
the amount of header padding.
This can be beneficial when it is known that some metadata will be added
at a future date.
The operators that benefit most from judicious use of header padding
are <command>ncatted</command> and <command>ncrename</command>, since they only alter
metadata. 
</para>
<para>This optimization exploits the netCDF library <code>nc__enddef()</code>
function.
This function behaves differently with different storage formats.
It will improve speed of future metadata expansion with <code>CLASSIC</code>
and <code>64bit</code> netCDF files, though not necessarily with <code>NETCDF4</code> 
files, i.e., those created by the netCDF interface to the <acronym><acronymword>HDF5</acronymword></acronym>
library (<pxref label="File-Formats-and-Conversion"><xrefnodename>File Formats and Conversion</xrefnodename></pxref>).
netCDF3 formats use a simple sequential ordering that requires copying
the file if the size of new metadata exceeds the available padding.
netCDF4 files use internal file pointers that allow flexibility at
inserting and removing data without necessitating copying the whole
file.
</para>
<html endspaces=" ">
&lt;a name=&quot;omp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#omp --&gt;
&lt;a name=&quot;openmp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#openmp --&gt;
</html>
</section>
<node name="OpenMP-Threading" spaces=" "><nodename>OpenMP Threading</nodename><nodenext spaces=" ">Command Line Options</nodenext><nodeprev spaces=" ">Metadata Optimization</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>OpenMP Threading</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="328">OpenMP</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="329">threads</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="330"><acronym><acronymword>SMP</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="331">shared memory parallelism</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="332">parallelism</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="333"><code>nco_openmp_thread_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="334"><code>--thr_nbr <var>thr_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="335"><code>--threads <var>thr_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="336"><code>--omp_num_threads <var>thr_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="337"><code>-t <var>thr_nbr</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncclimo</command>, <command>ncks</command>, <command>ncremap</command>&linebreak;
Short options: <samp>-t</samp>&linebreak;
Long options: <samp>--thr_nbr</samp>, <samp>--threads</samp>,
<samp>--omp_num_threads</samp>&linebreak; 
</para></cartouche>
<para><acronym><acronymword>NCO</acronymword></acronym> supports shared memory parallelism (<acronym><acronymword>SMP</acronymword></acronym>) when
compiled with an OpenMP-enabled compiler.
Threads requests and allocations occur in two stages.
First, users may request a specific number of threads <var>thr_nbr</var> with
the <samp>-t</samp> switch (or its long option equivalents, <samp>--thr_nbr</samp>,
<samp>--threads</samp>, and <samp>--omp_num_threads</samp>).
If not user-specified, OpenMP obtains <var>thr_nbr</var> from the
<env>OMP_NUM_THREADS</env> environment variable, if present, or from the
<acronym><acronymword>OS</acronymword></acronym>, if not.
</para>
<cartouche endspaces=" ">
<para>Caveat:
Unfortunately, threading does not improve <acronym><acronymword>NCO</acronymword></acronym> throughput (i.e.,
wallclock time) because nearly all <acronym><acronymword>NCO</acronymword></acronym> operations are
I/O-bound. 
This means that <acronym><acronymword>NCO</acronymword></acronym> spends negligible time doing anything
compared to reading and writing. 
The only exception is regridding with <command>ncremap</command> which uses
<command>ncks</command> under-the-hood.
As of 2017, threading works only for regridding, thus this section is
relevant only to <command>ncclimo</command>, <command>ncks</command>, and
<command>ncremap</command>. 
We have seen some and can imagine other use cases where <command>ncwa</command>,
<command>ncpdq</command>, and <command>ncap2</command> (with long scripts) will complete
faster due to threading.  
The main benefits of threading so far have been to isolate the serial
from parallel portions of code. 
This parallelism is now exploited by OpenMP but then runs into the I/O
bottleneck during output. 
The bottleneck will be ameliorated for large files by the use of
MPI-enabled calls in the netCDF4 library when the underlying filesystem
is parallel (e.g., <acronym><acronymword>PVFS</acronymword></acronym> or <acronym><acronymword>JFS</acronymword></acronym>).
Implementation of the parallel output calls in <acronym><acronymword>NCO</acronymword></acronym> is not a
goal of our current funding and would require new volunteers or funding.   
</para></cartouche>

<cindex index="cp" spaces=" "><indexterm index="cp" number="338"><var>thr_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="339"><env>OMP_NUM_THREADS</env></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="340"><command>ncrcat</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="341"><command>ncwa</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="342"><command>ncap2</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="343"><command>ncpdq</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="344">large datasets</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> may modify <var>thr_nbr</var> according to its own internal
settings before it requests any threads from the system.
Certain operators contain hard-code limits to the number of threads they
request.
We base these limits on our experience and common sense, and to reduce
potentially wasteful system usage by inexperienced users.
For example, <code>ncrcat</code> is extremely I/O-intensive so we restrict
<math><var>thr_nbr</var> &lt;= 2</math> for <code>ncrcat</code>.
This is based on the notion that the best performance that can be
expected from an operator which does no arithmetic is to have one thread
reading and one thread writing simultaneously.
In the future (perhaps with netCDF4), we hope to demonstrate significant
threading improvements with operators like <code>ncrcat</code> by performing
multiple simultaneous writes. 
</para>
<para>Compute-intensive operators (<code>ncremap</code>) benefit most from
threading. 
The greatest increases in throughput due to threading occur on
large datasets where each thread performs millions, at least,
of floating-point operations.
Otherwise, the system overhead of setting up threads probably outweighs 
the speed enhancements due to <acronym><acronymword>SMP</acronymword></acronym> parallelism.
However, we have not yet demonstrated that the <acronym><acronymword>SMP</acronymword></acronym> parallelism 
scales beyond four threads for these operators.
Hence we restrict <math><var>thr_nbr</var> &lt;= 4</math> for all operators.
We encourage users to play with these limits (edit file
<file>nco_omp.c</file>) and send us their feedback.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="345">debugging</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="346"><var>dbg_lvl</var></indexterm></cindex>
<para>Once the initial <var>thr_nbr</var> has been modified for any
operator-specific limits, <acronym><acronymword>NCO</acronymword></acronym> requests the system to allocate 
a team of <var>thr_nbr</var> threads for the body of the code.
The operating system then decides how many threads to allocate
based on this request.
Users may keep track of this information by running the operator with
<math><var>dbg_lvl</var> &gt; 0</math>.
</para>
<para>By default, threaded operators attach one global attribute,
<code>nco_openmp_thread_number</code>, to any file they create or modify. 
This attribute contains the number of threads the operator used to
process the input files. 
This information helps to verify that the answers with threaded and
non-threaded operators are equal to within machine precision.
<cindex index="cp" spaces=" "><indexterm index="cp" number="347">benchmarks</indexterm></cindex>
This information is also useful for benchmarking.
</para>
<html endspaces=" ">
&lt;a name=&quot;cmd_ln&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cmd_ln --&gt;
</html>
</section>
<node name="Command-Line-Options" spaces=" "><nodename>Command Line Options</nodename><nodenext spaces=" ">Sanitization of Input</nodenext><nodeprev spaces=" ">OpenMP Threading</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Command Line Options</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="348">command line options</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
</para></cartouche>
<cindex index="cp" spaces=" "><indexterm index="cp" number="349"><acronym><acronymword>POSIX</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="350"><acronym><acronymword>UNIX</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="351"><acronym><acronymword>GNU</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="352">switches</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> achieves flexibility by using <dfn>command line options</dfn>.
These options are implemented in all traditional <acronym><acronymword>UNIX</acronymword></acronym> commands 
as single letter <dfn>switches</dfn>, e.g., <samp>ls -l</samp>.
For many years <acronym><acronymword>NCO</acronymword></acronym> used only single letter option names.
In late 2002, we implemented <acronym><acronymword>GNU</acronymword></acronym>/<acronym><acronymword>POSIX</acronymword></acronym> extended
or long option names for all options.
This was done in a backward compatible way such that the full
functionality of <acronym><acronymword>NCO</acronymword></acronym> is still available through the familiar 
single letter options.
Many features of <acronym><acronymword>NCO</acronymword></acronym> introduced since 2002 now require the 
use of long options, simply because we have nearly run out of single
letter options.
More importantly, mnemonics for single letter options are often
non-intuitive so that long options provide a more natural way of
expressing intent.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="353">long options</indexterm></cindex>
<para>Extended options, also called long options, are implemented using the
system-supplied <file>getopt.h</file> header file, if possible. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="354"><code>BSD</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="355"><code>getopt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="356"><code>getopt_long</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="357"><file>getopt.h</file></indexterm></cindex>
This provides the <command>getopt_long</command> function to <acronym><acronymword>NCO</acronymword></acronym>
<footnote spaces="\n"><para>If a <command>getopt_long</command> function cannot be found on the system, 
<acronym><acronymword>NCO</acronymword></acronym> will use the <command>getopt_long</command> from the
<command>my_getopt</command> package by Benjamin Sittler
<email><emailaddress>bsittler&arobase;iname.com</emailaddress></email>.
This is <acronym><acronymword>BSD</acronymword></acronym>-licensed software available from  
<uref><urefurl>http://www.geocities.com/ResearchTriangle/Node/9405/#my_getopt</urefurl></uref>.</para></footnote>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="358"><code>-D <var>debug-level</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="359"><code>--dbg_lvl <var>debug-level</var></code></indexterm></cindex>
<para>The syntax of <dfn>short options</dfn> (single letter options) is
<kbd>-<var>key</var> <var>value</var></kbd> (dash-key-space-value).
Here, <var>key</var> is the single letter option name, e.g., 
<samp>-D 2</samp>.
</para>
<para>The syntax of <dfn>long options</dfn> (multi-letter options) is 
<kbd>--<var>long_name</var> <var>value</var></kbd>
(dash-dash-key-space-value), e.g., <samp>--dbg_lvl 2</samp> or
<kbd>--<var>long_name</var>=<var>value</var></kbd>
(dash-dash-key-equal-value), e.g., <samp>--dbg_lvl=2</samp>.
Thus the following are all valid for the <samp>-D</samp> (short version)
or <samp>--dbg_lvl</samp> (long version) command line option.
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -D 3 in.nc        # Short option, preferred form
ncks -D3 in.nc         # Short option, alternate form
ncks --dbg_lvl=3 in.nc # Long option, preferred form
ncks --dbg_lvl 3 in.nc # Long option, alternate form
</pre></example>
<noindent></noindent>
<para>The third example is preferred for two reasons.
First, <samp>--dbg_lvl</samp> is more specific and less ambiguous than
<samp>-D</samp>.
The long option format makes scripts more self documenting and less
error-prone.   
Often long options are named after the source code variable whose value 
they carry.
Second, the equals sign <kbd>=</kbd> joins the key (i.e., <var>long_name</var>) to   
the value in an uninterruptible text block. 
Experience shows that users are less likely to mis-parse commands when
restricted to this form.
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Truncating Long Options</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Multi-arguments</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="Truncating-Long-Options" spaces=" "><nodename>Truncating Long Options</nodename><nodenext spaces=" ">Multi-arguments</nodenext><nodeprev spaces=" ">Command Line Options</nodeprev><nodeup spaces=" ">Command Line Options</nodeup></node>
<subsection spaces=" "><sectiontitle>Truncating Long Options</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="360">Truncating options</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="361">Options, truncating</indexterm></cindex>
<para><acronym><acronymword>GNU</acronymword></acronym> implements a superset of the <acronym><acronymword>POSIX</acronymword></acronym> standard.
Their superset accepts any unambiguous truncation of a valid option:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -D 3 in.nc        # Short option
ncks --dbg_lvl=3 in.nc # Long option, full form
ncks --dbg=3 in.nc     # Long option, OK unambiguous truncation
ncks --db=3 in.nc      # Long option, OK unambiguous truncation
ncks --d=3 in.nc       # Long option, ERROR ambiguous truncation
</pre></example>
<noindent></noindent>
<para>The first four examples are equivalent and will work as expected.
The final example will exit with an error since <command>ncks</command> cannot
disambiguate whether <samp>--d</samp> is intended as a truncation of
<samp>--dbg_lvl</samp>, of <samp>--dimension</samp>, or of some other long option.  
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> provides many long options for common switches.
For example, the debugging level may be set in all operators with any
of the switches <samp>-D</samp>, <samp>--debug-level</samp>, or <samp>--dbg_lvl</samp>.
This flexibility allows users to choose their favorite mnemonic.
For some, it will be <samp>--debug</samp> (an unambiguous truncation of
<samp>--debug-level</samp>, and other will prefer <samp>--dbg</samp>.
Interactive users usually prefer the minimal amount of typing, i.e.,
<samp>-D</samp>.
We recommend that re-usable scripts employ long options to facilitate
self-documentation and maintainability.  
</para>
<para>This manual generally uses the short option syntax in examples.
This is for historical reasons and to conserve space in printed output.
Users are expected to pick the unambiguous truncation of each option
name that most suits their taste.
</para>
<html endspaces=" ">
&lt;a name=&quot;MTA&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#MTA --&gt;
&lt;a name=&quot;mta&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mta --&gt;
&lt;a name=&quot;multi-arguments&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#multi-arguments --&gt;
&lt;a name=&quot;Multi-arguments&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#Multi-arguments --&gt;
</html>
</subsection>
<node name="Multi_002darguments" spaces=" "><nodename>Multi-arguments</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Truncating Long Options</nodeprev><nodeup spaces=" ">Command Line Options</nodeup></node>
<subsection spaces=" "><sectiontitle>Multi-arguments</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="362">Multi-arguments</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="363"><acronym><acronymword>MTA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="364">Options, multi-argument</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="365"><code>--gaa <var>key</var>=<var>val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="366"><code>--ppc <var>key</var>=<var>val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="367"><code>--qnt <var>key</var>=<var>val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="368"><code>--rgr <var>key</var>=<var>val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="369"><code>--trr <var>key</var>=<var>val</var></code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.2 (November, 2016), <acronym><acronymword>NCO</acronymword></acronym> accepts
multiple key-value pair options for a single feature to be joined
together into a single extended argument called a <dfn>multi-argument</dfn>,
sometimes abbreviated <acronym><acronymword>MTA</acronymword></acronym>. 
Only four <acronym><acronymword>NCO</acronymword></acronym> features accept multiple key-value pairs that
can be aggregated into multi-arguments. 
These features are:
Global Attribute Addition options indicated via <samp>--gaa</samp> (<pxref label="Global-Attribute-Addition"><xrefnodename>Global Attribute Addition</xrefnodename></pxref>);
Image Manipulation indicated via <samp>--trr</samp><footnote spaces="\n"><html endspaces=" ">
&lt;a name=&quot;envi&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#envi --&gt;
&lt;a name=&quot;ENVI&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ENVI --&gt;
&lt;a name=&quot;BIL&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BIL --&gt;
&lt;a name=&quot;BSQ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BSQ --&gt;
&lt;a name=&quot;BIP&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BIP --&gt;
&lt;a name=&quot;bil&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bil --&gt;
&lt;a name=&quot;bsq&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bsq --&gt;
&lt;a name=&quot;bip&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bip --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="370"><acronym><acronymword>ENVI</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="371"><acronym><acronymword>DOE</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="372"><acronym><acronymword>BIL</acronymword></acronym> format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="373"><acronym><acronymword>BSQ</acronymword></acronym> format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="374"><acronym><acronymword>BIP</acronymword></acronym> format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="375">Terraref</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="376"><samp>--trr</samp></indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> supports decoding <acronym><acronymword>ENVI</acronymword></acronym> images in support of the
<acronym><acronymword>DOE</acronymword></acronym> Terraref project.
These options are indicated via the <command>ncks</command> <samp>--trr</samp> switch,
and are otherwise undocumented.
Please contact us if more support and documentation of handling of
<acronym><acronymword>ENVI</acronymword></acronym> <acronym><acronymword>BIL</acronymword></acronym>, <acronym><acronymword>BSQ</acronymword></acronym>, and <acronym><acronymword>BIP</acronymword></acronym> images
would be helpful</para></footnote>,
Precision-Preserving Compression options are indicated via
<samp>--ppc</samp> (<pxref label="Precision_002dPreserving-Compression"><xrefnodename>Precision-Preserving Compression</xrefnodename></pxref>); and 
Regridding options are indicated via <samp>--rgr</samp> (<pxref label="Regridding"><xrefnodename>Regridding</xrefnodename></pxref>).
Arguments to these four indicator options take the form of key-value
pairs, e.g., <samp>--rgr <var>key</var>=<var>val</var></samp>. 
As of <w>version 5.2.5</w> (May 2024), <acronym><acronymword>NCO</acronymword></acronym> changed to
preferring <samp>--qnt</samp> over <samp>--ppc</samp> for quantization
algorithms.
The two are simply synonyms, and backward compatibility is maintained.
</para>
<para>These features have so many options that making each key its own
command line option would pollute the namespace of <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s
global options. 
Yet supplying multiple options to each indicator option one-at-a-time
can result in command lines overpopulated with indicator switches (e.g.,
<samp>--rgr</samp>): 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks --rgr grd_ttl='Title' --rgr grid=grd.nc --rgr latlon=129,256 \
     --rgr lat_typ=fv --rgr lon_typ=grn_ctr ...
</verbatim>
</example>

<para>Multi-arguments combine all the indicator options into one option that
receives a single argument that comprises all the original arguments
glued together by a delimiter, which is, by default, <samp>#</samp>.
Thus the multi-argument version of the above example is
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks --rgr grd_ttl='Title'#grid=grd.nc#latlon=129,256#lat_typ=fv#lon_typ=grn_ctr
</verbatim>
</example>
<para>Note the aggregation of all <var>key</var>=<var>val</var> pairs into a single
argument.
<acronym><acronymword>NCO</acronymword></acronym> simply splits this argument at each delimiter, and
processes the sub-arguments as if they had been passed with their own
indicator option.
Multi-arguments produce the same results, and may be mixed with,
traditional indicator options supplied one-by-one.
</para>
<para>As mentioned previously, the multi-argument delimiter string is, by
default, the hash-sign <samp>#</samp>. 
When any <var>key</var>=<var>val</var> pair contains the default delimiter, the
user must specify a custom delimiter string so that options are parsed
correctly. 
The options to change the multi-argument delimiter string are
<samp>--mta_dlm=<var>delim_string</var></samp> or
<samp>--dlm_mta=<var>delim_string</var></samp>, where <var>delim_string</var> can be any
single or multi-character string that (1) is not contained in any
<var>key</var> or <var>val</var> string; and (2) will not confuse the shell.
For example, to use multi-arguments to pass a string that includes 
the hash symbol (the default delimiter is <samp>#</samp>), one must also
change the delimiter so something besides hash, e.g., a colon <samp>:</samp>: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks --dlm=&quot;:&quot; --gaa foo=bar:foo2=bar2:foo3,foo4=&quot;hash # is in value&quot; 
ncks --dlm=&quot;:&quot; --gaa foo=bar:foo2=bar2:foo3,foo4=&quot;Thu Sep 15 13\:03\:18 PDT 2016&quot;
ncks --dlm=&quot;csz&quot; --gaa foo=barcszfoo2=bar2cszfoo3,foo4=&quot;Long text&quot;
</verbatim>
</example>
<para>In the second example, the colons that are escaped with the backslash
become literal characters.  
Many characters have special shell meanings and so must be escaped by a 
single or double backslash or enclosed in single quotes to prevent
interpolation. 
These special characters include <samp>:</samp>, <samp>$</samp>, <samp>%</samp>, <samp>*</samp>,
<samp>&arobase;</samp>, and <samp>&amp;</samp>. 
If <var>val</var> is a long text string that could contain the default
delimiter, then delimit with a unique multi-character string such as
<samp>csz</samp> in the third example. 
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.7 (May, 2017), multi-argument
flags no longer need be specified as key-value pairs.
By definition a flag sets a boolean value to either True or False.
Previously <acronym><acronymword>MTA</acronymword></acronym> flags had to employ key-value pair syntax,
e.g., <samp>--rgr infer=Y</samp> or <samp>--rgr no_cll_msr=anything</samp> in order 
to parse correctly.
Now the <acronym><acronymword>MTA</acronymword></acronym> parser accepts flags in the more intuitive syntax
where they are listed by name, i.e., the flag name alone indicates the
flag to set, e.g., <samp>--rgr infer</samp> or <samp>--rgr no_cll_msr</samp> are
valid. 
A consequence of this is that flags in multi-argument strings appear
as straightforward flag names, e.g.,
<samp>--rgr infer#no_cll_msr#latlon=129,256</samp>.
It is also valid to prefix flags in multi-arument strings with
single or double-dashes to make the flags more visible, e.g.,
<samp>--rgr latlon=129,256#--infer#-no_cll_msr</samp>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;scr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#scr --&gt;
&lt;a name=&quot;sntz&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sntz --&gt;
&lt;a name=&quot;security&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#security --&gt;
&lt;a name=&quot;sanitize&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sanitize --&gt;
&lt;a name=&quot;whitelist&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#whitelist --&gt;
&lt;a name=&quot;wht_lst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wht_lst --&gt;
</html>
</subsection>
</section>
<node name="Sanitization-of-Input" spaces=" "><nodename>Sanitization of Input</nodename><nodenext spaces=" ">Specifying Input Files</nodenext><nodeprev spaces=" ">Command Line Options</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Sanitization of Input</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="377">sanitize</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="378">security</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="379">whitelist</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="380">blacklist</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
</para></cartouche>
<para><acronym><acronymword>NCO</acronymword></acronym> is often installed in system directories (although not
with Conda), and on some production machines it may have escalated
privileges. 
Since <acronym><acronymword>NCO</acronymword></acronym> manipulates files by using <code>system()</code> calls (e.g., to 
move and copy them with <code>mv</code> and <code>cp</code>) it makes sense to audit it for vulnerabilities and 
protect it from malicious users trying to exploit security gaps.
Securing <acronym><acronymword>NCO</acronymword></acronym> against malicious attacks is multi-faceted, and
involves careful memory management and auditing of user-input.
In versions 4.7.3&textndash;4.7.6 (March-September, 2018), <acronym><acronymword>NCO</acronymword></acronym>
implements a whitelist of characters allowed in user-specified
filenames.
This whitelist proved unpopular mainly because it proscribed certain
character combinations that could appear in automatically generated
files, and was therefore turned-off in 4.7.7 and following versions.
The whitelist is described here for posterity and for possible
improvement and re-introduction:
The purpose of the whitelist was to prevent malicious users from injecting
filename strings that could be used for attacks. 
The whitelist allowed only these characters:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890_-.@ :%/
</verbatim>
</example>
<para>The backslash character <kbd>\</kbd> was also whitelisted for Windows only.
This whitelist allows filenames to be <acronym><acronymword>URL</acronymword></acronym>s, include username
prefixes, and standard non-alphabetic characters. 
The implied blacklist included these characters
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
;|&lt;&gt;[](),&amp;*?'&quot;
</verbatim>
</example>
<para>This blacklist rules-out strings that may contain dangerous commands and 
injection attacks.
If you would like any of these characters whitelisted, please contact
us and include a compelling real-world use-case.
</para>
<para>The <acronym><acronymword>DAP</acronymword></acronym> protocol supports accessing files with so-called
&textldquo;constraint expressions&textrdquo;.
<acronym><acronymword>NCO</acronymword></acronym> allows access to a wider set of whitelisted characters
for files whose names indicate the <acronym><acronymword>DAP</acronymword></acronym> protocol.
This is defined as any filename beginning with the string <samp>http://</samp>, <samp>https://</samp>, 
or <samp>dap4://</samp>.
The whitelist for these files is expanded to include these characters:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
#=:[];|{}/&lt;&gt;
</verbatim>
</example>

<para>The whitelist method is straightforward, and does not interfere
with <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s globbing feature.
The whitelist applies only to filenames because they are handled by
shell commands passed to the <command>system()</command> function.  
However, the whitelist method is applicable to other user-input such
as variable lists, hyperslab arguments, etc.
Hence, the whitelist could be applied to other user-input in the future.
</para>
<html endspaces=" ">
&lt;a name=&quot;fl_in&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_in --&gt;
&lt;a name=&quot;in&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#in --&gt;
&lt;a name=&quot;input&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#input --&gt;
</html>
</section>
<node name="Specifying-Input-Files" spaces=" "><nodename>Specifying Input Files</nodename><nodenext spaces=" ">Specifying Output Files</nodenext><nodeprev spaces=" ">Sanitization of Input</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Specifying Input Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="381">input files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="382">globbing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="383">regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="384">wildcards</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="385"><code>NINTAP</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="386">Processor, <acronym><acronymword>CCM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="387"><acronym><acronymword>CCM</acronymword></acronym> Processor</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="388">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="389"><code>stdin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="390"><code>-n <var>loop</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="391"><code>--nintap <var>loop</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="392"><code>-p <var>input-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="393"><code>--pth <var>input-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="394"><code>--path <var>input-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="395"><var>input-path</var></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability (<code>-n</code>): <command>nces</command>, <command>ncecat</command>, <command>ncra</command>, <command>ncrcat</command>&linebreak;
Availability (<code>-p</code>): All operators&linebreak;
Availability (<code>stdin</code>): All operators&linebreak;
Short options: <samp>-n</samp>, <samp>-p</samp>&linebreak;
Long options: <samp>--nintap</samp>, <samp>--pth</samp>, <samp>--path</samp>&linebreak;
</para></cartouche>
<para>It is important that users be able to specify multiple input files
without typing every filename in full, often a tedious task even
by graduate student standards.
<cindex index="cp" spaces=" "><indexterm index="cp" number="396"><acronym><acronymword>UNIX</acronymword></acronym></indexterm></cindex>
There are four different ways of specifying input files to <acronym><acronymword>NCO</acronymword></acronym>:
explicitly typing each, using <acronym><acronymword>UNIX</acronymword></acronym> shell wildcards, and using
the <acronym><acronymword>NCO</acronymword></acronym> <samp>-n</samp> and <samp>-p</samp> switches (or their long option
equivalents, <samp>--nintap</samp> or <samp>--pth</samp> and <samp>--path</samp>,
respectively). 
Techniques to augment these methods to specify arbitrary numbers (e.g.,
thousands) and patterns of filenames are discussed separately 
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>).
</para>
<para>To illustrate these methods, consider the simple problem of using
<command>ncra</command> to average five input files, <file>85.nc</file>, <file>86.nc</file>,
<w>&dots; <file>89.nc</file></w>, and store the results in <file>8589.nc</file>.
Here are the four methods in order.
They produce identical answers.
</para><example endspaces=" ">
<pre xml:space="preserve">ncra 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
ncra 8[56789].nc 8589.nc
ncra 8?.nc 8589.nc
ncra -p <var>input-path</var> 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
ncra -n 5,2,1 85.nc 8589.nc
</pre></example>
<para>The first method (explicitly specifying all filenames) works by brute 
force. 
The second method relies on the operating system shell to <dfn>glob</dfn>
(expand) the <dfn>regular expression</dfn> <code>8[56789].nc</code>.
The shell then passes the valid filenames (those which match the
regular expansion) to <command>ncra</command>.
In this case <command>ncra</command> never knows that a regular expression was
used, because the shell intercepts and expands and matches the regular
expression before <command>ncra</command> is actually invoked.
The third method is uses globbing with a different regular expression
that is less safe (it will also match unwanted files such as
<file>81.nc</file> and <file>8Z.nc</file> if present). 
The fourth method uses the <samp>-p <var>input-path</var></samp> argument to
specify the directory where all the input files reside.
<acronym><acronymword>NCO</acronymword></acronym> prepends <var>input-path</var> (e.g.,
<file>/data/username/model</file>) to all <var>input-files</var> (though not to
<var>output-file</var>).  
Thus, using <samp>-p</samp>, the path to any number of input files need only
be specified once.
Note <var>input-path</var> need not end with <samp>/</samp>; the <samp>/</samp> is
automatically generated if necessary. 
</para>
<para>The last method passes (with <samp>-n</samp>) syntax concisely describing 
the entire set of filenames
<footnote><para>The <samp>-n</samp> option is a backward-compatible superset of the 
<code>NINTAP</code> option from the <acronym><acronymword>NCAR</acronymword></acronym> <acronym><acronymword>CCM</acronymword></acronym> Processor.
The <acronym><acronymword>CCM</acronymword></acronym> Processor was custom-written Fortran code maintained
for many years by Lawrence Buja at <acronym><acronymword>NCAR</acronymword></acronym>, and phased-out in 
the late 1990s.
<acronym><acronymword>NCO</acronymword></acronym> copied some ideas, like <code>NINTAP</code>-functionality,
from <acronym><acronymword>CCM</acronymword></acronym> Processor capabilities.</para></footnote>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="397">multi-file operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="398">files, multiple</indexterm></cindex>
This option is only available with the <dfn>multi-file operators</dfn>:
<command>ncra</command>, <command>ncrcat</command>, <command>nces</command>, and <command>ncecat</command>.
By definition, multi-file operators are able to process an arbitrary
number of <var>input-files</var>.
This option is very useful for abbreviating lists of filenames
representable as
<var>alphanumeric_prefix</var>+<var>numeric_suffix</var>+<file>.</file>+<var>filetype</var>
where <var>alphanumeric_prefix</var> is a string of arbitrary length and
composition, <var>numeric_suffix</var> is a fixed width field of digits, and
<var>filetype</var> is a standard filetype indicator. 
For example, in the file <file>ccm3_h0001.nc</file>, we have
<var>alphanumeric_prefix</var> = <file>ccm3_h</file>, <var>numeric_suffix</var> =
<file>0001</file>, and <var>filetype</var> = <file>nc</file>.
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> decodes lists of such filenames encoded using the
<samp>-n</samp> syntax. 
The simpler (three-argument) <samp>-n</samp> usage takes the form 
<code>-n <var>file_number</var>,<var>digit_number</var>,<var>numeric_increment</var></code>
where <var>file_number</var> is the number of files, <var>digit_number</var> is
the fixed number of numeric digits comprising the <var>numeric_suffix</var>,
and <var>numeric_increment</var> is the constant, integer-valued difference
between the <var>numeric_suffix</var> of any two consecutive files.
The value of <var>alphanumeric_prefix</var> is taken from the input file,
which serves as a template for decoding the filenames.
In the example above, the encoding <code>-n 5,2,1</code> along with the input
file name <file>85.nc</file> tells <acronym><acronymword>NCO</acronymword></acronym> to
construct five (5) filenames identical to the template <file>85.nc</file>
except that the final two (2) digits are a numeric suffix to be
incremented by one (1) for each successive file.
Currently <var>filetype</var> may be either be empty, <file>nc</file>, <file>h5</file>,
<file>cdf</file>, <file>hdf</file>, <file>hd5</file>, or <file>he5</file>.
If present, these <var>filetype</var> suffixes (and the preceding <file>.</file>)
are ignored by <acronym><acronymword>NCO</acronymword></acronym> as it uses the <samp>-n</samp> arguments to
locate, evaluate, and compute the <var>numeric_suffix</var> component of
filenames. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="399">wrapped filenames</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="400">climate model</indexterm></cindex>
<para>Recently the <samp>-n</samp> option has been extended to allow convenient
specification of filenames with &textldquo;circular&textrdquo; characteristics.
This means it is now possible for <acronym><acronymword>NCO</acronymword></acronym> to automatically
generate filenames which increment regularly until a specified maximum
value, and then wrap back to begin again at a specified minimum value. 
The corresponding <samp>-n</samp> usage becomes more complex, taking one or
two additional arguments for a total of four or five, respectively: 
<code>-n
<var>file_number</var>,<var>digit_number</var>,<var>numeric_increment</var>[,<var>numeric_max</var>[,<var>numeric_min</var>]]</code>
where <var>numeric_max</var>, if present, is the maximum integer-value of 
<var>numeric_suffix</var> and <var>numeric_min</var>, if present, is the minimum
integer-value of <var>numeric_suffix</var>.
Consider, for example, the problem of specifying non-consecutive input
files where the filename suffixes end with the month index.  
In climate modeling it is common to create summertime and wintertime
averages which contain the averages of the months June&textndash;July&textndash;August,
and December&textndash;January&textndash;February, respectively:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -n 3,2,1 85_06.nc 85_0608.nc
ncra -n 3,2,1,12 85_12.nc 85_1202.nc
ncra -n 3,2,1,12,1 85_12.nc 85_1202.nc
</pre></example>
<para>The first example shows that three arguments to the <samp>-n</samp> option
suffice to specify consecutive months (<code>06, 07, 08</code>) which do not
&textldquo;wrap&textrdquo; back to a minimum value.
The second example shows how to use the optional fourth and fifth
elements of the <samp>-n</samp> option to specify a wrap value.
The fourth argument to <samp>-n</samp>, when present, specifies the maximum
integer value of <var>numeric_suffix</var>.
In the example the maximum value <w>is 12,</w> which will be formatted as
<file>12</file> in the filename string. 
The fifth argument to <samp>-n</samp>, when present, specifies the minimum
integer value of <var>numeric_suffix</var>.
The default minimum filename suffix <w>is 1,</w> which is formatted as
<file>01</file> in this case.   
Thus the second and third examples have the same effect, that is, they
automatically generate, in order, the filenames <file>85_12.nc</file>,
<file>85_01.nc</file>, and <file>85_02.nc</file> as input to <acronym><acronymword>NCO</acronymword></acronym>.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.5.2 (September, 2015), <acronym><acronymword>NCO</acronymword></acronym>
supports an optional sixth argument to <samp>-n</samp>, the month-indicator. 
The month-indicator affirms to <acronym><acronymword>NCO</acronymword></acronym> that the right-most digits
being manipulated in the generated filenames correspond to month numbers 
(with January formatted as <file>01</file> and December as <file>12</file>). 
Moreover, it assumes digits to the left of the month are the year.
The full (six-argument) <samp>-n</samp> usage takes the form 
<code>-n <var>file_number</var>,<var>digit_number</var>,<var>month_increment</var>,<var>max_month</var>,<var>min_month</var>,<samp>yyyymm</samp></code>.
The <samp>yyyymm</samp> string is a clunky way (can you think of a clearer
way?) to tell <acronym><acronymword>NCO</acronymword></acronym> to enumerate files in year-month mode.
When present, <samp>yyyymm</samp> string causes <acronym><acronymword>NCO</acronymword></acronym> to automatically
generate a filename series whose right-most two digits increment from
<var>min_month</var> by <var>month_increment</var> up to <var>max_month</var> and then
the leftmost digits (i.e., the year) increment by one, and the whole
process is repeated until the <var>file_number</var> filenames are
generated. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat -n 3,6,1,12,1         198512.nc 198512_198502.nc
ncrcat -n 3,6,1,12,1,yyyymm  198512.nc 198512_198602.nc
ncrcat -n 3,6,1,12,12,yyyymm 198512.nc 198512_198712.nc
</pre></example>
<para>The first command above concatenates three files (<file>198512.nc</file>, 
<file>198501.nc</file>, <file>198502.nc</file>) into the output file.
The second command above concatenates three files (<file>198512.nc</file>, 
<file>198601.nc</file>, <file>198602.nc</file>).
The <samp>yyyymm</samp>-indicator causes the left-most digits to
increment each time the right-most two digits reach their
maximum and then wrap.
The first command does not have the indicator so it is always 1985.  
The third command concatenates three files (<file>198512.nc</file>,
<file>198612.nc</file>, <file>198712.nc</file>).
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.1.1</w>, released in November, 2022,
all operators support specifying input files via <code>stdin</code>.
This capability was implemented with NCZarr in mind, though it can
also be used with traditional <acronym><acronymword>POSIX</acronymword></acronym> files.
The <command>ncap2</command>, <command>ncks</command>, <command>ncrename</command>, and
<command>ncatted</command> operators accept one or two filenames as positional
arguments.
If the input file for these operators is provided via <code>stdin</code>,
then the output file, if any, must be specified with <samp>-o out.nc</samp>
so the operators know whether to check <code>stdin</code>.
Multi-file operators (<command>ncra</command>, <command>ncea</command>,
<command>ncrcat</command>, <command>ncecat</command>) will continue to identify the last
positional argument as the output file unless the <samp>-o out.nc</samp>
form is used.
The best best practice is to use <samp>-o out.nc</samp> to specify output
filenames when <code>stdin</code> is used for input filenames: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
echo in.nc | ncks            
echo in.nc | ncks -o out.nc
echo &quot;in1.nc in2.nc&quot; | ncbo -o out.nc
echo &quot;in1.nc in2.nc&quot; | ncflint -o out.nc
</verbatim>
</example>
<para>For the provenance reasons dicussed above
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>), all filenames input via <code>stdin</code>
are stored as global attributes in the <ref label="File-List-Attributes"><xrefnodename>File List Attributes</xrefnodename></ref>).
</para>
<html endspaces=" ">
&lt;a name=&quot;-o&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-o --&gt;
&lt;a name=&quot;--output&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#--output --&gt;
&lt;a name=&quot;fl_out&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_out --&gt;
&lt;a name=&quot;out&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#out --&gt;
&lt;a name=&quot;output&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#output --&gt;
</html>
</section>
<node name="Specifying-Output-Files" spaces=" "><nodename>Specifying Output Files</nodename><nodenext spaces=" ">Remote storage</nodenext><nodeprev spaces=" ">Specifying Input Files</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Specifying Output Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="401">output file</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="402">input files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="403">positional arguments</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="404">command line switches</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="405"><code>-o <var>fl_out</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="406"><code>--output <var>fl_out</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="407"><code>--fl_out <var>fl_out</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: <samp>-o</samp>&linebreak;
Long options: <samp>--fl_out</samp>, <samp>--output</samp>&linebreak;
</para></cartouche>
<para><acronym><acronymword>NCO</acronymword></acronym> commands produce no more than one output file, <var>fl_out</var>. 
Traditionally, users specify <var>fl_out</var> as the final argument to the
operator, following all input file names. 
This is the <dfn>positional argument</dfn> method of specifying input and
ouput file names.
The positional argument method works well in most applications.
<acronym><acronymword>NCO</acronymword></acronym> also supports specifying <var>fl_out</var> using the command
line switch argument method, <samp>-o <var>fl_out</var></samp>.
</para>
<para>Specifying <var>fl_out</var> with a switch, rather than as a positional
argument, allows <var>fl_out</var> to precede input files in the argument
list. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="408">multi-file operators</indexterm></cindex>
This is particularly useful with multi-file operators for three reasons.
Multi-file operators may be invoked with hundreds (or more) filenames.
Visual or automatic location of <var>fl_out</var> in such a list is
difficult when the only syntactic distinction between input and output
files is their position.
<cindex index="cp" spaces=" "><indexterm index="cp" number="409"><command>xargs</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="410">input files</indexterm></cindex>
Second, specification of a long list of input files may be difficult
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>).
Making the input file list the final argument to an operator facilitates 
using <command>xargs</command> for this purpose.
Some alternatives to <command>xargs</command> are heinous and undesirable.
Finally, many users are more comfortable specifying output files 
with <samp>-o <var>fl_out</var></samp> near the beginning of an argument list.
<cindex index="cp" spaces=" "><indexterm index="cp" number="411">compilers</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="412">linkers</indexterm></cindex>
Compilers and linkers are usually invoked this way.
</para>
<para>Users should specify <var>fl_out</var> using either (not both) method.
If <var>fl_out</var> is specified twice (once with the switch and once as
the last positional argument), then the positional argument takes
precedence. 
</para>
<html endspaces=" ">
&lt;a name=&quot;rmt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rmt --&gt;
</html>
</section>
<node name="Remote-storage" spaces=" "><nodename>Remote storage</nodename><nodenext spaces=" ">Retaining Retrieved Files</nodenext><nodeprev spaces=" ">Specifying Output Files</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Accessing Remote Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="413"><code>rcp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="414"><code>scp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="415"><file>.rhosts</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="416"><acronym><acronymword>NCAR MSS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="417"><acronym><acronymword>MSS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="418">Mass Store System</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="419"><acronym><acronymword>URL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="420"><code>ftp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="421"><code>sftp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="422"><code>wget</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="423">remote files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="424">synchronous file access</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="425">asynchronous file access</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="426"><code>--pth <var>input-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="427"><code>--path <var>input-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="428"><code>--lcl <var>output-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="429"><code>--local <var>output-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="430"><code>-l <var>output-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="431"><file>.netrc</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="432"><code>history</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: <samp>-p</samp>, <samp>-l</samp>&linebreak;
Long options: <samp>--pth</samp>, <samp>--path</samp>, <samp>--lcl</samp>, <samp>--local</samp>&linebreak;
</para></cartouche>
<para>All <acronym><acronymword>NCO</acronymword></acronym> operators can retrieve files from remote sites as well 
as from the local file system.
<w>A remote</w> site can be an anonymous <acronym><acronymword>FTP</acronymword></acronym> server, a machine on
which the user has <command>rcp</command>, <command>scp</command>, or <command>sftp</command>
privileges, <acronym><acronymword>NCAR</acronymword></acronym>&textrsquo;s Mass Storage System (<acronym><acronymword>MSS</acronymword></acronym>), or
an <acronym><acronymword>OPeNDAP</acronymword></acronym> server.
Examples of each are given below, following a brief description of the 
particular access protocol.
</para>
<html endspaces=" ">
&lt;a name=&quot;ftp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ftp --&gt;
</html>
<para>To access a file via an anonymous <acronym><acronymword>FTP</acronymword></acronym> server, simply supply
the remote file&textrsquo;s <acronym><acronymword>URL</acronymword></acronym>.
Anonymous <acronym><acronymword>FTP</acronymword></acronym> usually requires no further credentials,
e.g., no <file>.netrc</file> file is necessary.
<acronym><acronymword>FTP</acronymword></acronym> is an intrinsically insecure protocol because it transfers
passwords in plain text format.  
Users should access sites using anonymous <acronym><acronymword>FTP</acronymword></acronym>, or better yet,
secure <acronym><acronymword>FTP</acronymword></acronym> (<acronym><acronymword>SFTP</acronymword></acronym>, see below) when possible. 
Some <acronym><acronymword>FTP</acronymword></acronym> servers require a login/password combination for a
valid user account.
<acronym><acronymword>NCO</acronymword></acronym> allows transactions that require additional credentials
so long as the required information is stored in the <file>.netrc</file> file.  
Usually this information is the remote machine name, login, and
password, in plain text, separated by those very keywords, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">machine dust.ess.uci.edu login zender password bushlied
</pre></example>
<para>Eschew using valuable passwords for <acronym><acronymword>FTP</acronymword></acronym> transactions, since
<file>.netrc</file> passwords are potentially exposed to eavesdropping
software
<footnote><para><acronym><acronymword>NCO</acronymword></acronym> does not implement command line options to
specify <acronym><acronymword>FTP</acronymword></acronym> logins and passwords because copying those data
into the <code>history</code> global attribute in the output file (done by
default) poses an unacceptable security risk. 
</para></footnote>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;sftp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sftp --&gt;
</html>
<para><acronym><acronymword>SFTP</acronymword></acronym>, i.e., secure <acronym><acronymword>FTP</acronymword></acronym>, uses <acronym><acronymword>SSH</acronymword></acronym>-based 
security protocols that solve the security issues associated with
plain <acronym><acronymword>FTP</acronymword></acronym>.  
<acronym><acronymword>NCO</acronymword></acronym> supports <acronym><acronymword>SFTP</acronymword></acronym> protocol access to files
specified with a homebrew syntax of the form
</para><example endspaces=" ">
<pre xml:space="preserve">sftp://machine.domain.tld:/path/to/filename
</pre></example>
<para>Note the second colon following the top-level-domain, <code>tld</code>.
This syntax is a hybrid between an <acronym><acronymword>FTP URL</acronymword></acronym> and standard
remote file syntax.
</para>
<html endspaces=" ">
&lt;a name=&quot;rcp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rcp --&gt;
&lt;a name=&quot;scp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#scp --&gt;
</html>
<para>To access a file using <command>rcp</command> or <command>scp</command>, specify the
Internet address of the remote file.
Of course in this case you must have <command>rcp</command> or <command>scp</command>
privileges which allow transparent (no password entry required) access
to the remote machine. 
This means that <file>~/.rhosts</file> or <file>~/ssh/authorized_keys</file> must
be set accordingly on both local and remote machines.   
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="433"><acronym><acronymword>HPSS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="434"><command>hsi</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="435"><command>msrcp</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="436"><command>msread</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="437"><command>nrnet</command></indexterm></cindex>
<html endspaces=" ">
&lt;a name=&quot;hpss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hpss --&gt;
&lt;a name=&quot;HPSS&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#HPSS --&gt;
&lt;a name=&quot;hsi&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hsi --&gt;
&lt;a name=&quot;HSI&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#HSI --&gt;
&lt;a name=&quot;msrcp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msrcp --&gt;
&lt;a name=&quot;msread&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msread --&gt;
&lt;a name=&quot;nrnet&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nrnet --&gt;
</html>
<para>To access a file on a High Performance Storage System (<acronym><acronymword>HPSS</acronymword></acronym>) 
(such as that at <acronym><acronymword>NCAR</acronymword></acronym>, <acronym><acronymword>ECMWF</acronymword></acronym>, <acronym><acronymword>LANL</acronymword></acronym>,
<acronym><acronymword>DKRZ</acronymword></acronym>, <acronym><acronymword>LLNL</acronymword></acronym>) specify the full <acronym><acronymword>HPSS</acronymword></acronym> pathname
of the remote file and use the <samp>--hpss</samp> flag.
Then <acronym><acronymword>NCO</acronymword></acronym> will attempt to detect whether the local machine has direct 
(synchronous) <acronym><acronymword>HPSS</acronymword></acronym> access. 
If so, <acronym><acronymword>NCO</acronymword></acronym> attempts to use the Hierarchical Storage
Interface (<acronym><acronymword>HSI</acronymword></acronym>) command <command>hsi get</command>
<footnote><para>The <command>hsi</command> command must be in the user&textrsquo;s path in one of
the following directories: <code>/usr/local/bin</code>, <code>/opt/hpss/bin</code>,
or <code>/ncar/opt/hpss/hsi</code>.
Tell us if the <acronym><acronymword>HPSS</acronymword></acronym> installation at your site places the
<command>hsi</command> command in a different location, and we will add that
location to the list of acceptable paths to search for <command>hsi</command>.
</para></footnote>.
</para>
<para>The following examples show how one might analyze files stored on  
remote systems.
<!-- c HPSS syntax at http://www2.cisl.ucar.edu/docs/hpss/hsi -->
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -l . ftp://dust.ess.uci.edu/pub/zender/nco/in.nc
ncks -l . sftp://dust.ess.uci.edu:/home/ftp/pub/zender/nco/in.nc
ncks -l . dust.ess.uci.edu:/home/zender/nco/data/in.nc
ncks -l . /ZENDER/nco/in.nc # NCAR (broken old MSS path)
ncks -l . --hpss /home/zender/nco/in.nc # NCAR HPSS
ncks -l . http://thredds-test.ucar.edu/thredds/dodsC/testdods/in.nc 
</pre></example>
<noindent></noindent>
<!-- c ncks -l . /home/z/zender/in.nc # NERSC -->
<para>The first example works verbatim if your system is connected to the
Internet and is not behind a firewall. 
The second example works if you have <command>sftp</command> access to the
machine <code>dust.ess.uci.edu</code>.
The third example works if you have <command>rcp</command> or <command>scp</command>
access to the machine <code>dust.ess.uci.edu</code>. 
The fourth and fifth examples work on <acronym><acronymword>NCAR</acronymword></acronym> computers with
local access to the <acronym><acronymword>HPSS</acronymword></acronym> <command>hsi get</command> command
<footnote><para><acronym><acronymword>NCO</acronymword></acronym> supported the old <acronym><acronymword>NCAR</acronymword></acronym> Mass Storage
System (<acronym><acronymword>MSS</acronymword></acronym>) until version 4.0.7 in April, 2011.
<acronym><acronymword>NCO</acronymword></acronym> supported <acronym><acronymword>MSS</acronymword></acronym>-retrievals via a variety of
mechanisms including the <command>msread</command>, <command>msrcp</command>, and
<command>nrnet</command> commands invoked either automatically or with sentinels
like <command>ncks -p mss:/ZENDER/nco -l . in.nc</command>.
Once the <acronym><acronymword>MSS</acronymword></acronym> was decommissioned in March, 2011, support for
these retrieval mechanisms was replaced by support for <acronym><acronymword>HPSS</acronymword></acronym>.
</para></footnote>.
The sixth command works if your local version of <acronym><acronymword>NCO</acronymword></acronym> is
<acronym><acronymword>OPeNDAP</acronymword></acronym>-enabled (this is fully described in <ref label="OPeNDAP"><xrefnodename>OPeNDAP</xrefnodename></ref>),
or if the remote file is accessible via <command>wget</command>.
The above commands can be rewritten using the <samp>-p <var>input-path</var></samp> 
option as follows: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="438"><code>-p <var>input-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="439"><var>input-path</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="440"><code>-l <var>output-path</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="441"><var>output-path</var></indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -p ftp://dust.ess.uci.edu/pub/zender/nco -l . in.nc
ncks -p sftp://dust.ess.uci.edu:/home/ftp/pub/zender/nco -l . in.nc
ncks -p dust.ess.uci.edu:/home/zender/nco -l . in.nc
ncks -p /ZENDER/nco -l . in.nc
ncks -p /home/zender/nco -l . --hpss in.nc # HPSS
ncks -p http://thredds-test.ucar.edu/thredds/dodsC/testdods \ 
     -l . in.nc
</pre></example>
<noindent></noindent>
<para>Using <samp>-p</samp> is recommended because it clearly separates the
<var>input-path</var> from the filename itself, sometimes called the
<dfn>stub</dfn>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="442">stub</indexterm></cindex>
When <var>input-path</var> is not explicitly specified using <samp>-p</samp>,
<acronym><acronymword>NCO</acronymword></acronym> internally generates an <var>input-path</var> from the first
input filename.  
The automatically generated <var>input-path</var> is constructed by stripping 
the input filename of everything following the final <samp>/</samp> character
(i.e., removing the stub).
The <samp>-l <var>output-path</var></samp> option tells <acronym><acronymword>NCO</acronymword></acronym> where to
store the remotely retrieved file.
It has no effect on locally-retrieved files, or on the output file.
Often the path to a remotely retrieved file is quite different than the
path on the local machine where you would like to store the file.
If <samp>-l</samp> is not specified then <acronym><acronymword>NCO</acronymword></acronym> internally generates an
<var>output-path</var> by simply setting <var>output-path</var> equal to
<var>input-path</var> stripped of any machine names.
If <samp>-l</samp> is not specified and the remote file resides on a detected
<acronym><acronymword>HPSS</acronymword></acronym> system, then the leading character of
<var>input-path</var>, <samp>/</samp>, is also stripped from <var>output-path</var>.
Specifying <var>output-path</var> as <samp>-l ./</samp> tells <acronym><acronymword>NCO</acronymword></acronym> to
store the remotely retrieved file and the output file in the current
directory. 
Note that <samp>-l .</samp> is equivalent to <samp>-l ./</samp> though the latter is
syntactically more clear.
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>OPeNDAP</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;dap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dap --&gt;
&lt;a name=&quot;DAP&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#DAP --&gt;
&lt;a name=&quot;DODS&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#DODS --&gt;
&lt;a name=&quot;OPeNDAP&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#OPeNDAP --&gt;
&lt;a name=&quot;dods&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dods --&gt;
&lt;a name=&quot;opendap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#opendap --&gt;
</html>
<node name="OPeNDAP" spaces=" "><nodename>OPeNDAP</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Remote storage</nodeprev><nodeup spaces=" ">Remote storage</nodeup></node>
<subsection spaces=" "><sectiontitle><acronym><acronymword>OPeNDAP</acronymword></acronym></sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="443"><acronym><acronymword>DAP</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="444"><acronym><acronymword>DODS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="445"><acronym><acronymword>HTTP</acronymword></acronym> protocol</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="446"><env>DODS_ROOT</env></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="447">Distributed Oceanographic Data System</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="448">oceanography</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="449">data access protocol</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="450">Open-source Project for a Network Data Access Protocol</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="451"><acronym><acronymword>OPeNDAP</acronymword></acronym>.</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="452">server</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="453">client-server</indexterm></cindex>
<para>The Distributed Oceanographic Data System (<acronym><acronymword>DODS</acronymword></acronym>) provides
useful replacements for common data interface libraries like netCDF.
The <acronym><acronymword>DODS</acronymword></acronym> versions of these libraries implement network
transparent access to data via a client-server data access protocol
that uses the <acronym><acronymword>HTTP</acronymword></acronym> protocol for communication.
Although <acronym><acronymword>DODS</acronymword></acronym>-technology originated with oceanography data,
it applyies to virtually all scientific data.
In recognition of this, the data access protocol underlying
<acronym><acronymword>DODS</acronymword></acronym> (which is what <acronym><acronymword>NCO</acronymword></acronym> cares about) has been 
renamed the Open-source Project for a Network Data Access Protocol, 
<acronym><acronymword>OPeNDAP</acronymword></acronym>.
We use the terms <acronym><acronymword>DODS</acronymword></acronym> and <acronym><acronymword>OPeNDAP</acronymword></acronym> interchangeably,
and often write <acronym><acronymword>OPeNDAP</acronymword></acronym>/<acronym><acronymword>DODS</acronymword></acronym> for now. 
In the future we will deprecate <acronym><acronymword>DODS</acronymword></acronym> in favor of
<acronym><acronymword>DAP</acronymword></acronym> or <acronym><acronymword>OPeNDAP</acronymword></acronym>, as appropriate
<footnote spaces="\n"><cindex index="cp" spaces=" "><indexterm index="cp" number="454"><acronym><acronymword>NVODS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="455">National Virtual Ocean Data System</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="456">open source</indexterm></cindex>
<para><acronym><acronymword>DODS</acronymword></acronym> is being deprecated because it is ambiguous, referring
both to a protocol and to a collection of (oceanography) data.
It is superceded by two terms.
<acronym><acronymword>DAP</acronymword></acronym> is the discipline-neutral Data Access Protocol at the
heart of <acronym><acronymword>DODS</acronymword></acronym>.
The National Virtual Ocean Data System (<acronym><acronymword>NVODS</acronymword></acronym>) refers to the
collection of oceanography data and oceanographic extensions to
<acronym><acronymword>DAP</acronymword></acronym>. 
In other words, <acronym><acronymword>NVODS</acronymword></acronym> is implemented with <acronym><acronymword>OPeNDAP</acronymword></acronym>.
<acronym><acronymword>OPeNDAP</acronymword></acronym> is <emph>also</emph> the open source project which
maintains, develops, and promulgates the <acronym><acronymword>DAP</acronymword></acronym> standard. 
<acronym><acronymword>OPeNDAP</acronymword></acronym> and <acronym><acronymword>DAP</acronymword></acronym> really are interchangeable.
Got it yet?</para></footnote>.
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> may be <acronym><acronymword>DAP</acronymword></acronym>-enabled by linking
<acronym><acronymword>NCO</acronymword></acronym> to the <acronym><acronymword>OPeNDAP</acronymword></acronym> libraries. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="457"><file>Makefile</file></indexterm></cindex>
This is described in the <acronym><acronymword>OPeNDAP</acronymword></acronym> documentation and
automagically implemented in <acronym><acronymword>NCO</acronymword></acronym> build mechanisms
<footnote spaces="\n"><para>Automagic support for <acronym><acronymword>DODS</acronymword></acronym> version 3.2.x was deprecated in 
December, 2003 after <acronym><acronymword>NCO</acronymword></acronym> version 2.8.4.
<acronym><acronymword>NCO</acronymword></acronym> support for <acronym><acronymword>OPeNDAP</acronymword></acronym> versions 3.4.x commenced in
December, 2003, with <acronym><acronymword>NCO</acronymword></acronym> version 2.8.5.
<acronym><acronymword>NCO</acronymword></acronym> support for <acronym><acronymword>OPeNDAP</acronymword></acronym> versions 3.5.x commenced in
June, 2005, with <acronym><acronymword>NCO</acronymword></acronym> version 3.0.1.
<acronym><acronymword>NCO</acronymword></acronym> support for <acronym><acronymword>OPeNDAP</acronymword></acronym> versions 3.6.x commenced in
June, 2006, with <acronym><acronymword>NCO</acronymword></acronym> version 3.1.3.
<acronym><acronymword>NCO</acronymword></acronym> support for <acronym><acronymword>OPeNDAP</acronymword></acronym> versions 3.7.x commenced in
January, 2007, with <acronym><acronymword>NCO</acronymword></acronym> version 3.1.9.</para></footnote>.
The <file>./configure</file> mechanism automatically enables <acronym><acronymword>NCO</acronymword></acronym> as
<acronym><acronymword>OPeNDAP</acronymword></acronym> clients if it can find the required
<acronym><acronymword>OPeNDAP</acronymword></acronym> libraries.
Since about 2010 the netCDF library can be configured (with
<code>--enable-dap</code>) to build <acronym><acronymword>DAP</acronymword></acronym> directly into the netCDF
library, which <acronym><acronymword>NCO</acronymword></acronym> automatically links to, so <acronym><acronymword>DAP</acronymword></acronym>
need not be installed as a third-party library.
It has been so many years since <acronym><acronymword>NCO</acronymword></acronym> has needed to support
linking to <acronym><acronymword>DAP</acronymword></acronym> installed outside of the netCDF library that
is is unclear whether this configuration 
<footnote spaces="\n"><para>The minimal set of libraries required to build <acronym><acronymword>NCO</acronymword></acronym> as
<acronym><acronymword>OPeNDAP</acronymword></acronym> clients, where <acronym><acronymword>OPeNDAP</acronymword></acronym> is supplied as a
separate library apart from <file>libnetcdf.a</file>, are, in link order,
<file>libnc-dap.a</file>, <file>libdap.a</file>, and 
<file>libxml2</file> and <file>libcurl.a</file>.</para></footnote>.
still works.
The <env>$DODS_ROOT</env> environment variable may be used to override the 
default <acronym><acronymword>OPeNDAP</acronymword></acronym> library location at <acronym><acronymword>NCO</acronymword></acronym>
compile-time.  
Building <acronym><acronymword>NCO</acronymword></acronym> with <file>bld/Makefile</file> and the command
<code>make DODS=Y</code> adds the (non-intuitive) commands to link to the
<acronym><acronymword>OPeNDAP</acronymword></acronym> libraries installed in the <env>$DODS_ROOT</env>
directory.  
The file <file>doc/opendap.sh</file> contains a generic script intended to help
users install <acronym><acronymword>OPeNDAP</acronymword></acronym> before building <acronym><acronymword>NCO</acronymword></acronym>.
The documentation at the 
<uref><urefurl>http://www.opendap.org</urefurl><urefdesc spaces=" ">OPeNDAP Homepage</urefdesc></uref>
is voluminous.
Check there and on the
<uref><urefurl>http://www.unidata.ucar.edu/software/dods/home/mailLists/</urefurl><urefdesc spaces=" ">DODS mail lists</urefdesc></uref>.
to learn more about the extensive capabilities of <acronym><acronymword>OPeNDAP</acronymword></acronym>
<footnote spaces="\n"><para>We are most familiar with the <acronym><acronymword>OPeNDAP</acronymword></acronym> ability to enable 
network-transparent data access.
<cindex index="cp" spaces=" "><indexterm index="cp" number="458">constraint expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="459">server-side processing</indexterm></cindex>
<acronym><acronymword>OPeNDAP</acronymword></acronym> has many other features, including sophisticated
hyperslabbing and server-side processing via <dfn>constraint expressions</dfn>.
If you know more about this, please consider writing a section
on &textldquo;<acronym><acronymword>OPeNDAP</acronymword></acronym> Capabilities of Interest to <acronym><acronymword>NCO</acronymword></acronym> Users&textrdquo;
for incorporation in the <cite>NCO User Guide</cite>.</para></footnote>.
</para>
<para>Once <acronym><acronymword>NCO</acronymword></acronym> is <acronym><acronymword>DAP</acronymword></acronym>-enabled the operators are
<acronym><acronymword>OPeNDAP</acronymword></acronym> clients.  
All <acronym><acronymword>OPeNDAP</acronymword></acronym> clients have network transparent access to
any files controlled by a <acronym><acronymword>OPeNDAP</acronymword></acronym> server. 
Simply specify the input file path(s) in <acronym><acronymword>URL</acronymword></acronym> notation and all 
<acronym><acronymword>NCO</acronymword></acronym> operations may be performed on remote files made
accessible by a <acronym><acronymword>OPeNDAP</acronymword></acronym> server. 
This command tests the basic functionality of <acronym><acronymword>OPeNDAP</acronymword></acronym>-enabled  
<acronym><acronymword>NCO</acronymword></acronym> clients: 
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -O -o ~/foo.nc -C -H -v one -l /tmp \
  -p http://thredds-test.ucar.edu/thredds/dodsC/testdods in.nc
% ncks -H -v one ~/foo.nc
one = 1
</pre></example>
<para>The <code>one = 1</code> outputs confirm (first) that <command>ncks</command> correctly
retrieved data via the  <acronym><acronymword>OPeNDAP</acronymword></acronym> protocol and (second) that 
<command>ncks</command> created a valid local copy of the subsetted remote file.
With minor changes to the above command, netCDF4 can be used as both the
input and output file format:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -4 -O -o ~/foo.nc -C -H -v one -l /tmp \
  -p http://thredds-test.ucar.edu/thredds/dodsC/testdods in_4.nc
% ncks -H -v one ~/foo.nc
one = 1
</pre></example>
<para>And, of course, <acronym><acronymword>OPeNDAP</acronymword></acronym>-enabled <acronym><acronymword>NCO</acronymword></acronym> clients continue
to support orthogonal features such as UDUnits 
(<pxref label="UDUnits-Support"><xrefnodename>UDUnits Support</xrefnodename></pxref>):
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -u -C -H -v wvl -d wvl,'0.4 micron','0.7 micron' \
  -p http://thredds-test.ucar.edu/thredds/dodsC/testdods in_4.nc
% wvl[0]=5e-07 meter
</pre></example>

<para>The next command is a more advanced example which demonstrates the real
power of <acronym><acronymword>OPeNDAP</acronymword></acronym>-enabled <acronym><acronymword>NCO</acronymword></acronym> clients.
The <command>ncwa</command> client requests an equatorial hyperslab from remotely
stored <acronym><acronymword>NCEP reanalyses data</acronymword></acronym> of the <w>year 1969</w>.
The <acronym><acronymword>NOAA</acronymword></acronym> <acronym><acronymword>OPeNDAP</acronymword></acronym> server (hopefully!) serves these data. 
The local <command>ncwa</command> client then computes and stores (locally) the
regional mean surface pressure <w>(in Pa)</w>. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -O -C -a lat,lon,time -d lon,-10.,10. -d lat,-10.,10. \
http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis.dailyavgs/surface/pres.sfc.1969.nc ~/foo.nc
</pre></example>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="460">packing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="461">unpacking</indexterm></cindex>
<para>All with one command!
The data in this particular input file also happen to be packed
(<pxref label="Methods-and-functions"><xrefnodename>Methods and functions</xrefnodename></pxref>), although this complication is
transparent to the user since <acronym><acronymword>NCO</acronymword></acronym> automatically unpacks data
before attempting arithmetic. 
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> obtains remote files from the <acronym><acronymword>OPeNDAP</acronymword></acronym> server
(e.g., <file>www.cdc.noaa.gov</file>) rather than the local machine. 
Input files are first copied to the local machine, then processed.
The <acronym><acronymword>OPeNDAP</acronymword></acronym> server performs data access, hyperslabbing,
and transfer to the local machine.
<cindex index="cp" spaces=" "><indexterm index="cp" number="462">I/O</indexterm></cindex>
This allows the I/O to appear to <acronym><acronymword>NCO</acronymword></acronym> as if the input files
were local.  
The local machine performs all arithmetic operations.
Only the hyperslabbed output data are transferred over the network (to
the local machine) for the number-crunching to begin.
The advantages of this are obvious if you are examining small parts of
large files stored at remote locations.
</para>
<para>Natually there are many versions of <acronym><acronymword>OPeNDAP</acronymword></acronym> servers supplying
data and bugs in the server can appear to be bugs in <acronym><acronymword>NCO</acronymword></acronym>.
However, with very few exceptions
<footnote><para>For example, <acronym><acronymword>DAP</acronymword></acronym> servers do not like variables with
periods (&textldquo;.&textrdquo;) in their names even though this is perfectly legal with
netCDF. 
Such names may cause the <acronym><acronymword>DAP</acronymword></acronym> service to fail because 
<acronym><acronymword>DAP</acronymword></acronym> interprets the period as structure delimiter in an 
<acronym><acronymword>HTTP</acronymword></acronym> query string.</para></footnote> an <acronym><acronymword>NCO</acronymword></acronym> command that works
on a local file must work across an <acronym><acronymword>OPeNDAP</acronymword></acronym> connection or else 
there is a bug in the server. 
This is because <acronym><acronymword>NCO</acronymword></acronym> does nothing special to handle files
served by <acronym><acronymword>OPeNDAP</acronymword></acronym>, the whole process is (supposed to be)
completely transparent to the client <acronym><acronymword>NCO</acronymword></acronym> software.
Therefore it is often useful to try <acronym><acronymword>NCO</acronymword></acronym> commands on various
<acronym><acronymword>OPeNDAP</acronymword></acronym> servers in order to isolate whether a problem may be
due to a bug in the <acronym><acronymword>OPeNDAP</acronymword></acronym> server on a particular machine.
For this purpose, one might try variations of the following commands
that access files on public <acronym><acronymword>OPeNDAP</acronymword></acronym> servers:
</para><example endspaces=" ">
<pre xml:space="preserve"># Strided access to HDF5 file
ncks -v Time -d Time,0,10,2 http://eosdap.hdfgroup.uiuc.edu:8080/opendap/data/NASAFILES/hdf5/BUV-Nimbus04_L3zm_v01-00-2012m0203t144121.h5
# Strided access to netCDF3 file
ncks -O -D 1 -d time,1 -d lev,0 -d lat,0,100,10 -d lon,0,100,10 -v u_velocity http://nomads.ncep.noaa.gov:9090/dods/rtofs/rtofs_global20140303/rtofs_glo_2ds_forecast_daily_prog ~/foo.nc
</pre></example>
<noindent></noindent>
<para>These servers were operational at the time of writing, March 2014.
Unfortunately, administrators often move or rename path directories.
Recommendations for additional public <acronym><acronymword>OPeNDAP</acronymword></acronym> servers on
which to test <acronym><acronymword>NCO</acronymword></acronym> are welcome.
</para>
<html endspaces=" ">
&lt;a name=&quot;rtn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rtn --&gt;
</html>
</subsection>
</section>
<node name="Retaining-Retrieved-Files" spaces=" "><nodename>Retaining Retrieved Files</nodename><nodenext spaces=" ">File Formats and Conversion</nodenext><nodeprev spaces=" ">Remote storage</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Retaining Retrieved Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="463">file deletion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="464">file removal</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="465">file retention</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="466"><code>-R</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="467"><code>--rtn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="468"><code>--retain</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: <samp>-R</samp>&linebreak;
Long options: <samp>--rtn</samp>, <samp>--retain</samp>&linebreak;
</para></cartouche>
<para>In order to conserve local file system space, files retrieved from
remote locations are automatically deleted from the local file system 
once they have been processed.
Many <acronym><acronymword>NCO</acronymword></acronym> operators were constructed to work with numerous
large (e.g., <w>200 MB</w>) files. 
Retrieval of multiple files from remote locations is done serially. 
Each file is retrieved, processed, then deleted before the cycle
repeats.  
In cases where it is useful to keep the remotely-retrieved files on the
local file system after processing, the automatic removal feature may be 
disabled by specifying <samp>-R</samp> on the command line.
</para>
<para>Invoking <code>-R</code> disables the default printing behavior of
<command>ncks</command>.
This allows <command>ncks</command> to retrieve remote files without
automatically trying to print them.
See <ref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></ref>, for more details.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="469"><acronym><acronymword>FTP</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="470"><acronym><acronymword>SSH</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="471"><acronym><acronymword>msrcp</acronymword></acronym></indexterm></cindex>
<para>Note that the remote retrieval features of <acronym><acronymword>NCO</acronymword></acronym> can always be
used to retrieve <emph>any</emph> file, including non-netCDF files, via
<command>SSH</command>, anonymous <acronym><acronymword>FTP</acronymword></acronym>, or <command>msrcp</command>.
Often this method is quicker than using a browser, or running an
<acronym><acronymword>FTP</acronymword></acronym> session from a shell window yourself.
<cindex index="cp" spaces=" "><indexterm index="cp" number="472">server</indexterm></cindex>
For example, say you want to obtain a <acronym><acronymword>JPEG</acronymword></acronym> file from a weather
server. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -R -p ftp://weather.edu/pub/pix/jpeg -l . storm.jpg
</pre></example>
<noindent></noindent>
<para>In this example, <command>ncks</command> automatically performs an anonymous
<acronym><acronymword>FTP</acronymword></acronym> login to the remote machine and retrieves the specified
file. 
When <command>ncks</command> attempts to read the local copy of <file>storm.jpg</file>
as a netCDF file, it fails and exits, leaving  <file>storm.jpg</file> in
the current directory.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="473"><acronym><acronymword>DODS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="474">server</indexterm></cindex>
<para>If your <acronym><acronymword>NCO</acronymword></acronym> is <acronym><acronymword>DAP</acronymword></acronym>-enabled (<pxref label="OPeNDAP"><xrefnodename>OPeNDAP</xrefnodename></pxref>),
then you may use <acronym><acronymword>NCO</acronymword></acronym> to retrieve any files (including netCDF,
<acronym><acronymword>HDF</acronymword></acronym>, etc.) served by an <acronym><acronymword>OPeNDAP</acronymword></acronym> server to your local 
machine. 
For example, 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -R -l . -p \
http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis.dailyavgs/surface \
  pres.sfc.1969.nc
</pre></example>
<para>It may occasionally be useful to use <acronym><acronymword>NCO</acronymword></acronym> to transfer files
when your other preferred methods are not available locally.
</para>
<html endspaces=" ">
&lt;a name=&quot;conversion&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#conversion --&gt;
&lt;a name=&quot;fl_fmt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_fmt --&gt;
&lt;a name=&quot;hdf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdf --&gt;
&lt;a name=&quot;cdf5&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cdf5 --&gt;
&lt;a name=&quot;64bit&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#64bit --&gt;
&lt;a name=&quot;64bit-data&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#64bit-data --&gt;
&lt;a name=&quot;64bit-offset&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#64bit-offset --&gt;
&lt;a name=&quot;netcdf4&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#netcdf4 --&gt;
</html>
</section>
<node name="File-Formats-and-Conversion" spaces=" "><nodename>File Formats and Conversion</nodename><nodenext spaces=" ">Zarr and NCZarr</nodenext><nodeprev spaces=" ">Retaining Retrieved Files</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>File Formats and Conversion</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="475"><acronym><acronymword>HDF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="476">CDF5</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="477">netCDF2</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="478">netCDF3</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="479">netCDF4</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="480"><code>NETCDF4_CLASSIC</code> files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="481"><code>NETCDF4</code> files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="482"><code>CLASSIC</code> files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="483"><code>64BIT_OFFSET</code> files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="484"><code>64BIT_DATA</code> files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="485"><code>CDF5</code> files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="486"><code>--3</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="487"><code>-3</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="488"><code>-4</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="489"><code>-5</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="490"><code>-6</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="491"><code>-7</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="492"><code>--4</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="493"><code>--5</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="494"><code>--6</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="495"><code>--7</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="496"><code>--netcdf4</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="497"><code>--fl_fmt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="498"><code>--file_format</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="499"><code>--64bit_offset</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="500"><code>--64bit_data</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncap2</command>, <command>nces</command>,
<command>ncecat</command>, <command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>,
<command>ncra</command>, <command>ncrcat</command>, <command>ncwa</command>&linebreak;
Short options: <samp>-3</samp>, <samp>-4</samp>, <samp>-5</samp>, <samp>-6</samp>, <samp>-7</samp>&linebreak;
Long options: <samp>--3</samp>, <samp>--4</samp>, <samp>--5</samp>, <samp>--6</samp>, <samp>--64bit_offset</samp>, <samp>--7</samp>, <samp>--fl_fmt</samp>,
<samp>--netcdf4</samp>&linebreak;  
</para></cartouche>
<para>All <acronym><acronymword>NCO</acronymword></acronym> operators support (read and write) all three (or four, 
depending on how one counts) file formats supported by netCDF4.
The default output file format for all operators is the input file
format. 
The operators listed under &textldquo;Availability&textrdquo; above allow the user to
specify the output file format independent of the input file format. 
These operators allow the user to convert between the various file
formats. 
(The operators <command>ncatted</command> and <command>ncrename</command> do not support
these switches so they always write the output netCDF file in the same
format as the input netCDF file.) 
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>File Formats</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Determining File Format</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>File Conversion</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Autoconversion</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="File-Formats" spaces=" "><nodename>File Formats</nodename><nodenext spaces=" ">Determining File Format</nodenext><nodeprev spaces=" ">File Formats and Conversion</nodeprev><nodeup spaces=" ">File Formats and Conversion</nodeup></node>
<subsection spaces=" "><sectiontitle>File Formats</sectiontitle>
<para>netCDF supports five types of files: <code>CLASSIC</code>,
<code>64BIT_OFFSET</code>, <code>64BIT_DATA</code>, <code>NETCDF4</code>, and
<code>NETCDF4_CLASSIC</code>.
The <code>CLASSIC</code> (aka <code>CDF1</code>) format is the traditional 32-bit offset written by netCDF2 and netCDF3. 
As of 2005, nearly all netCDF datasets were in <code>CLASSIC</code> format. 
The <code>64BIT_OFFSET</code> (originally called plain old <code>64BIT</code>)
(aka <code>CDF2</code>) format was added in Fall, 2004. 
As of 2010, many netCDF datasets were in <code>64BIT_OFFSET</code> format. 
As of 2013, an increasing number of netCDF datasets were in
<code>NETCDF4_CLASSIC</code> format.
The <code>64BIT_DATA</code> (aka <code>CDF5</code> or <code>PNETCDF</code>)
format was added to netCDF in January, 2016 and immediately supported
by <acronym><acronymword>NCO</acronymword></acronym>.
Support for <ref label="Zarr-and-NCZarr"><xrefnodename>Zarr and NCZarr</xrefnodename></ref> backend storage formats was added to  
netCDF in 2021 and supported by <acronym><acronymword>NCO</acronymword></acronym> in 2022.
</para>
<para>The <code>NETCDF4</code> format uses <acronym><acronymword>HDF5</acronymword></acronym> as the file storage layer. 
The files are (usually) created, accessed, and manipulated using the 
traditional netCDF3 <acronym><acronymword>API</acronymword></acronym> (with numerous extensions).
The <code>NETCDF4_CLASSIC</code> format refers to netCDF4 files created with
the <code>NC_CLASSIC_MODEL</code> mask.
Such files use <acronym><acronymword>HDF5</acronymword></acronym> as the back-end storage format (unlike
netCDF3), though they incorporate only netCDF3 features.
Hence <code>NETCDF4_CLASSIC</code> files are entirely readable by applications 
that use only the netCDF3 <acronym><acronymword>API</acronymword></acronym> (though the applications must be
linked with the netCDF4 library).
<acronym><acronymword>NCO</acronymword></acronym> must be built with <w>netCDF4</w> to write files in the new
<code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code> formats, and to read files in
these formats. 
Datasets in the default <code>CLASSIC</code> or the newer <code>64BIT_OFFSET</code>
formats have maximum backwards-compatibility with older applications. 
<acronym><acronymword>NCO</acronymword></acronym> has deep support for <code>NETCDF4</code> formats.
If backwards compatibility is important, and your datasets are too large
for netCDF3, use <code>NETCDF4_CLASSIC</code> instead of <code>CLASSIC</code> format
files.  
<acronym><acronymword>NCO</acronymword></acronym> support for the <code>NETCDF4</code> format is complete and many
high-performance disk/<acronym><acronymword>RAM</acronymword></acronym> efficient workflows utilize this
format.   
</para>
<para>As mentioned above, all operators write use the input file format for
output files unless told otherwise.
Toggling the short option <samp>-6</samp> or the long option <samp>--6</samp> or
<samp>--64bit_offset</samp> (or their <var>key</var>-<var>value</var> equivalent
<samp>--fl_fmt=64bit_offset</samp>) produces the netCDF3 64-bit offset format 
named <code>64BIT_OFFSET</code>.
<acronym><acronymword>NCO</acronymword></acronym> must be built with <w>netCDF 3.6</w> or higher to produce
a <code>64BIT_OFFSET</code> file.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.9 (September, 2017), toggling the short
option <samp>-5</samp> or the long options <samp>--5</samp>, <samp>--64bit_data</samp>,
<samp>--cdf5</samp>, or <samp>--pnetcdf</samp> (or their <var>key</var>-<var>value</var>
equivalent <samp>--fl_fmt=64bit_data</samp>) produces the netCDF3 64-bit data
format named <code>64BIT_DATA</code>. 
This format is widely used by <acronym><acronymword>MPI</acronymword></acronym>-enabled modeling codes
because of its long association with PnetCDF.
<acronym><acronymword>NCO</acronymword></acronym> must be built with <w>netCDF 4.4</w> or higher to produce
a <code>64BIT_DATA</code> file.
</para>
<para>Using the <samp>-4</samp> switch (or its long option equivalents
<samp>--4</samp> or <samp>--netcdf4</samp>), or setting its <var>key</var>-<var>value</var>
equivalent <samp>--fl_fmt=netcdf4</samp> produces a <code>NETCDF4</code> file
(i.e., with all supported <acronym><acronymword>HDF5</acronymword></acronym> features).
Using the <samp>-7</samp> switch (or its long option equivalent
<samp>--7</samp>
<footnote spaces="\n"><para>The reason (and mnemonic) for <samp>-7</samp> is that <code>NETCDF4_CLASSIC</code>
files include great features of both netCDF3 (compatibility) and
netCDF4 (compression, chunking) and, well, <math>3+4=7</math>.</para></footnote>, or 
setting its <var>key</var>-<var>value</var> equivalent
<samp>--fl_fmt=netcdf4_classic</samp> produces a <code>NETCDF4_CLASSIC</code>  
file (i.e., with all supported <acronym><acronymword>HDF5</acronymword></acronym> features like compression
and chunking but without groups or new atomic types).
Operators given the <samp>-3</samp> (or <samp>--3</samp>) switch without arguments
will (attempt to) produce netCDF3 <code>CLASSIC</code> output, even from
netCDF4 input files.  
</para>
<para>Note that <code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code> are the same
binary format. 
The latter simply causes a writing application to fail if it attempts to 
write a <code>NETCDF4</code> file that cannot be completely read by the
netCDF3 library. 
Conversely, <code>NETCDF4_CLASSIC</code> indicates to a reading application
that all of the file contents are readable with the netCDF3 library. 
<acronym><acronymword>NCO</acronymword></acronym> has supported reading/writing basic <code>NETCDF4</code> and
<code>NETCDF4_CLASSIC</code> files since October, 2005.
</para>
<html endspaces=" ">
&lt;a name=&quot;fmt_inq&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fmt_inq --&gt;
</html>
</subsection>
<node name="Determining-File-Format" spaces=" "><nodename>Determining File Format</nodename><nodenext spaces=" ">File Conversion</nodenext><nodeprev spaces=" ">File Formats</nodeprev><nodeup spaces=" ">File Formats and Conversion</nodeup></node>
<subsection spaces=" "><sectiontitle>Determining File Format</sectiontitle>
<para>Input files often end with the generic <code>.nc</code> suffix that leaves
(perhaps by intention) the internal file format ambiguous.
There are at least three ways to discover the internal format of a
netCDF-supported file.
These methods determine whether it is a classic (32-bit offset) or newer
64-bit offset netCDF3 format, or is a netCDF4 format. 
Each method returns the information using slightly different terminology 
that becomes easier to understand with practice.
</para>
<para>First, examine the first line of global metadata output by <samp>ncks -M</samp>:  
<cindex index="cp" spaces=" "><indexterm index="cp" number="501">netCDF3 classic file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="502">netCDF4 classic file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="503">netCDF4 file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="504">32-bit offset file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="505">64-bit offset file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="506">64-bit data file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="507">PnetCDF file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="508"><command>ncks</command></indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="509"><code>-M</code></indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -M foo_3.nc
Summary of foo_3.nc: filetype = NC_FORMAT_CLASSIC, 0 groups ...
% ncks -M foo_6.nc
Summary of foo_6.nc: filetype = NC_FORMAT_64BIT_OFFSET, 0 groups ...
% ncks -M foo_5.nc
Summary of foo_5.nc: filetype = NC_FORMAT_CDF5, 0 groups ...
% ncks -M foo_7.nc
Summary of foo_7.nc: filetype = NC_FORMAT_NETCDF4_CLASSIC, 0 groups ...
% ncks -M foo_4.nc
Summary of foo_4.nc: filetype = NC_FORMAT_NETCDF4, 0 groups ...
</pre></example>
<para>This method requires a netCDF4-enabled <acronym><acronymword>NCO</acronymword></acronym> version 3.9.0+
(i.e., from 2007 or later).
<cindex index="cp" spaces=" "><indexterm index="cp" number="510">extended file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="511">underlying file format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="512"><code>NC_FORMATX_NC3</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="513"><code>NC_FORMATX_NC_HDF5</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="514"><code>NC_FORMATX_NC_HDF4</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="515"><code>NC_FORMATX_PNETCDF</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="516"><code>NC_FORMATX_DAP2</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="517"><code>NC_FORMATX_DAP4</code></indexterm></cindex>
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.0 (January, 2014), <command>ncks</command> will
also print the extended or underlying format of the input file.
The extended filetype will be one of the six underlying formats that
are accessible through the netCDF <acronym><acronymword>API</acronymword></acronym>.
These formats are
<code>NC_FORMATX_NC3</code> (classic and 64-bit versions of netCDF3 formats),
<code>NC_FORMATX_NC_HDF5</code> (classic and extended versions of netCDF4, and
&textldquo;pure&textrdquo; HDF5 format),
<code>NC_FORMATX_NC_HDF4</code> (HDF4 format),
<code>NC_FORMATX_PNETCDF</code> (PnetCDF format),
<code>NC_FORMATX_DAP2</code> (accessed via DAP2 protocol), and
<code>NC_FORMATX_DAP4</code> (accessed via DAP4 protocol).
For example,
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -D 2 -M hdf.hdf
Summary of hdf.hdf: filetype = NC_FORMAT_NETCDF4 (representation of \
  extended/underlying filetype NC_FORMAT_HDF4), 0 groups ...
% ncks -D 2 -M http://thredds-test.ucar.edu/thredds/dodsC/testdods/in.nc
Summary of http://thredds-test.ucar.edu/thredds/dodsC/testdods/in.nc: \
  filetype = NC_FORMAT_CLASSIC (representation of extended/underlying \
  filetype NC_FORMATX_DAP2), 0 groups  
% ncks -D 2 -M foo_4.nc
Summary of foo_4.nc: filetype = NC_FORMAT_NETCDF4 (representation of \
  extended/underlying filetype NC_FORMAT_HDF5), 0 groups  
</pre></example>
<para>The extended filetype determines some of the capabilities that netCDF
has to alter the file.
</para>
<para>Second, query the file with <samp>ncdump -k</samp>:
<cindex index="cp" spaces=" "><indexterm index="cp" number="518"><command>ncdump</command></indexterm></cindex> 
</para><example endspaces=" ">
<pre xml:space="preserve">% ncdump -k foo_3.nc
classic
% ncdump -k foo_6.nc
64-bit offset
% ncdump -k foo_5.nc
cdf5
% ncdump -k foo_7.nc
netCDF-4 classic model
% ncdump -k foo_4.nc
netCDF-4
</pre></example>
<para>This method requires a netCDF4-enabled <acronym><acronymword>netCDF</acronymword></acronym> 3.6.2+
(i.e., from 2007 or later).
</para>
<para>The third option uses the POSIX-standard <command>od</command> (octal dump)
command:   
<cindex index="cp" spaces=" "><indexterm index="cp" number="519"><command>od</command></indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="520">octal dump</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">% od -An -c -N4 foo_3.nc
   C   D   F 001
% od -An -c -N4 foo_6.nc
   C   D   F 002
% od -An -c -N4 foo_5.nc
   C   D   F 005
% od -An -c -N4 foo_7.nc
 211   H   D   F
% od -An -c -N4 foo_4.nc
 211   H   D   F
</pre></example>
<para>This option works without <acronym><acronymword>NCO</acronymword></acronym> and <command>ncdump</command>.
Values of <samp>C D F 001</samp> and <samp>C D F 002</samp> indicate 32-bit
(classic) and 64-bit netCDF3 formats, respectively, while values of
<samp>211 H D F</samp> indicate either of the newer netCDF4 file formats.
</para>
<html endspaces=" ">
&lt;a name=&quot;hdf2nc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdf2nc --&gt;
&lt;a name=&quot;3to4&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#3to4 --&gt;
&lt;a name=&quot;4to3&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#4to3 --&gt;
</html>
</subsection>
<node name="File-Conversion" spaces=" "><nodename>File Conversion</nodename><nodenext spaces=" ">Autoconversion</nodenext><nodeprev spaces=" ">Determining File Format</nodeprev><nodeup spaces=" ">File Formats and Conversion</nodeup></node>
<subsection spaces=" "><sectiontitle>File Conversion</sectiontitle>
<para>Let us demonstrate converting a file from any netCDF-supported
input format into any netCDF output format (subject to limits of the
output format).  
Here the input file <file>in.nc</file> may be in any of these formats:
netCDF3 (classic, 64bit_offset, 64bit_data), netCDF4 (classic and
extended), HDF4, HDF5, HDF-EOS (version 2 or 5), and DAP. 
The switch determines the output format written in the comment:
<footnote><para>The switches <samp>-5</samp>, <samp>--5</samp>, and <samp>pnetcdf</samp> are
reserved for PnetCDF files, i.e., <code>NC_FORMAT_CDF5</code>.
Such files are similar to netCDF3 classic files, yet also support
64-bit offsets and the additional netCDF4 atomic types.</para></footnote>
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --fl_fmt=classic in.nc foo_3.nc # netCDF3 classic
ncks --fl_fmt=64bit_offset in.nc foo_6.nc # netCDF3 64bit-offset
ncks --fl_fmt=64bit_data in.nc foo_5.nc # netCDF3 64bit-data
ncks --fl_fmt=cdf5 in.nc foo_5.nc # netCDF3 64bit-data
ncks --fl_fmt=netcdf4_classic in.nc foo_7.nc # netCDF4 classic
ncks --fl_fmt=netcdf4 in.nc foo_4.nc # netCDF4 
ncks -3 in.nc foo_3.nc # netCDF3 classic
ncks --3 in.nc foo_3.nc # netCDF3 classic
ncks -6 in.nc foo_6.nc # netCDF3 64bit-offset
ncks --64 in.nc foo_6.nc # netCDF3 64bit-offset
ncks -5 in.nc foo_5.nc # netCDF3 64bit-data
ncks --5 in.nc foo_5.nc # netCDF3 64bit-data
ncks -4 in.nc foo_4.nc # netCDF4 
ncks --4 in.nc foo_4.nc # netCDF4 
ncks -7 in.nc foo_7.nc # netCDF4 classic
ncks --7 in.nc foo_7.nc # netCDF4 classic
</pre></example>
<para>Of course since most operators support these switches, the
&textldquo;conversions&textrdquo; can be done at the output stage of arithmetic
or metadata processing rather than requiring a separate step.
Producing (netCDF3) <code>CLASSIC</code> or <code>64BIT_OFFSET</code> or
<code>64BIT_DATA</code> files from <code>NETCDF4_CLASSIC</code> files always 
works.  
</para>
<html endspaces=" ">
&lt;a name=&quot;autoconversion&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#autoconversion --&gt;
&lt;a name=&quot;autocnv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#autocnv --&gt;
</html>
</subsection>
<node name="Autoconversion" spaces=" "><nodename>Autoconversion</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">File Conversion</nodeprev><nodeup spaces=" ">File Formats and Conversion</nodeup></node>
<subsection spaces=" "><sectiontitle>Autoconversion</sectiontitle>
<para>Because of the dearth of support for netCDF4 amongst tools and user
communities (including the <acronym><acronymword>CF</acronymword></acronym> conventions), it is often useful
to convert netCDF4 to netCDF3 for certain applications.
Until <acronym><acronymword>NCO</acronymword></acronym> version 4.4.0 (January, 2014), producing netCDF3
files from netCDF4 files only worked if the input files contained no 
netCDF4-specific features (e.g., atomic types, multiple record
dimensions, or groups). 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.0, <command>ncks</command> supports
<dfn>autoconversion</dfn> of many netCDF4 features to their closest
netCDF3-compatible representations.
Since converting netCDF4 to netCDF3 results in loss of features, 
&textldquo;automatic down-conversion&textrdquo; may be a more precise description of what  
we term autoconversion.
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> employs three algorithms to downconvert netCDF4 to netCDF3:
</para><enumerate first="1" endspaces=" ">
<listitem> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="521">autoconversion</indexterm></cindex>
<para>Autoconversion of atomic types:
Autoconversion automatically promotes <code>NC_UBYTE</code> to <code>NC_SHORT</code>, 
and <code>NC_USHORT</code> to <code>NC_INT</code>.
It automatically demotes the three types <code>NC_UINT</code>,
<code>NC_UINT64</code>, and <code>NC_INT64</code> to <code>NC_INT</code>. 
And it converts <code>NC_STRING</code> to <code>NC_CHAR</code>.
All numeric conversions work for attributes and variables of any rank.
Two numeric types (<code>NC_UBYTE</code> and <code>NC_USHORT</code>) are
<emph>promoted</emph> to types with greater range (and greater storage). 
This extra range is often not used so promotion perhaps conveys
the wrong impression.
However, promotion never truncates values or loses data (this perhaps
justifies the extra storage).
Three numeric types (<code>NC_UINT</code>, <code>NC_UINT64</code> and
<code>NC_INT64</code>) are <emph>demoted</emph>.
Since the input range is larger than the output range, demotion can
result in numeric truncation and thus loss of data. 
In such cases, it would possible to convert the data to floating-point
values instead. 
If this feature interests you, please be the squeaky wheel and let us
know.
</para>
<para>String conversions (to <code>NC_CHAR</code>) work for all attributes, but
not for variables.
This is because attributes are at most one-dimensional and may be of any
size whereas variables require gridded dimensions that usually do not
fit the ragged sizes of text strings.
Hence scalar <code>NC_STRING</code> attributes are correctly converted to and
stored as <code>NC_CHAR</code> attributes in the netCDF3 output file, but
<code>NC_STRING</code> variables are not correctly converted. 
If this limitation annoys or enrages you, please let us know by being
the squeaky wheel.
</para>
</listitem><listitem>
<cindex index="cp" spaces=" "><indexterm index="cp" number="522"><code>--fix_rec_dmn all</code></indexterm></cindex>
<para>Convert multiple record dimensions to fixed-size dimensions.
Many netCDF4 and <acronym><acronymword>HDF5</acronymword></acronym> datasets have multiple unlimited
dimensions.
Since a netCDF3 file may have at most one unlimited dimension, all but
possibly one unlimited dimension from the input file must be converted
to fixed-length dimensions prior to storing netCDF4 input as netCDF3
output.
By invoking <code>--fix_rec_dmn all</code> the user ensures the output file
will adhere to netCDF3 conventions and the user need not know the names
of the specific record dimensions to fix.
See <ref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></ref> for a description of the
<samp>--fix_rec_dmn</samp> option. 
</para>
</listitem><listitem>
<cindex index="cp" spaces=" "><indexterm index="cp" number="523">flattening</indexterm></cindex>
<para>Flattening (removal) of groups.
Many netCDF4 and <acronym><acronymword>HDF5</acronymword></acronym> datasets have group hierarchies.
Since a netCDF3 file may not have any groups, groups in the input file
must be removed.
This is also called &textldquo;flattening&textrdquo; the hierarchical file.
See <ref label="Group-Path-Editing"><xrefnodename>Group Path Editing</xrefnodename></ref> for a description of the <acronym><acronymword>GPE</acronymword></acronym>
option <samp>-G :</samp> to flatten files.
</para></listitem></enumerate>

<para>Putting the three algorithms together, one sees that the recipe to 
convert netCDF4 to netCDF4 becomes increasingly complex as the netCDF4
features in the input file become more elaborate:
</para><example endspaces=" ">
<pre xml:space="preserve"># Convert file with netCDF4 atomic types
ncks -3 in.nc4 out.nc3
# Convert file with multiple record dimensions + netCDF4 atomic types
ncks -3 --fix_rec_dmn=all in.nc4 out.nc3
# Convert file with groups, multiple record dimensions + netCDF4 atomic types
ncks -3 -G : --fix_rec_dmn=all in.nc4 out.nc3
</pre></example>
<para>Future versions of <acronym><acronymword>NCO</acronymword></acronym> may automatically invoke the record
dimension fixation and group flattening when converting to netCDF3
(rather than requiring it be specified manually).
If this feature would interest you, please let us know.
</para>
<html endspaces=" ">
&lt;a name=&quot;Zarr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#Zarr --&gt;
&lt;a name=&quot;NCZarr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#NCZarr --&gt;
&lt;a name=&quot;zarr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#zarr --&gt;
&lt;a name=&quot;nczarr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nczarr --&gt;
&lt;a name=&quot;conversion&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#conversion --&gt;
&lt;a name=&quot;zarr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncz --&gt;
&lt;a name=&quot;ncz2psx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncz2psx --&gt;
&lt;a name=&quot;fl_fmt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_fmt --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="524">Zarr</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="525">NCZarr</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="526"><command>ncz2psx</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="527"><acronym><acronymword>POSIX</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="528"><acronym><acronymword>S3</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="529"><code>stdin</code></indexterm></cindex>
</subsection>
</section>
<node name="Zarr-and-NCZarr" spaces=" "><nodename>Zarr and NCZarr</nodename><nodenext spaces=" ">Large File Support</nodenext><nodeprev spaces=" ">File Formats and Conversion</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Zarr and NCZarr</sectiontitle>
<cartouche endspaces=" ">
<para>Availability: All Operators&linebreak;
</para></cartouche>
<para>As of <w>version 5.1.1</w> (November 2022), all <acronym><acronymword>NCO</acronymword></acronym> operators
support NCZarr I/O.
This support is currently limited to the <code>file://</code> scheme.
Support for the <acronym><acronymword>S3</acronymword></acronym> scheme is next.
All <acronym><acronymword>NCO</acronymword></acronym> commands should work as expected independent of the
back-end storage format of the I/O.
Operators can ingest and output <code>POSIX</code> or Zarr backend file
formats:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
in_ncz=&quot;file://${HOME}/in_zarr4#mode=nczarr,file&quot;
in_psx=&quot;${HOME}/in_zarr4.nc&quot;
out_ncz=&quot;file://${HOME}/foo#mode=nczarr,file&quot;
out_psx=&quot;${HOME}/foo.nc&quot;

ncks ${in_ncz} # Print contents of Zarr file
ncks -O -v var ${in_psx} ${out_psx} # POSIX input to POSIX output
ncks -O -v var ${in_psx} ${out_ncz} # POSIX input to Zarr output
ncks -O -v var ${in_ncz} ${out_psx} # Zarr input to  POSIX output
ncks -O -v var ${in_ncz} ${out_ncz} # Zarr input to Zarr output
ncks -O --cmp='gbr|shf|zst' ${in_psx} ${out_ncz} # Quantize/Compress
ncks -O --cmp='gbr|shf|zst' ${in_ncz} ${out_ncz} # Quantize/Compress
</verbatim>
</example>
<para>Note that NCZarr only supports the netCDF4 (not netCDF3) data model.
This is because NCZarr needs to know chunking and compression
information by default (it is not optional).
Hence if the input format is netCDF3, then the user must explicitly
specify a netCDF4 format for the output NCZarr storage:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
in_psx=&quot;${HOME}/in_zarr3.nc&quot; # As above, but a netCDF3 input file

ncks -O -4 ${in_psx} ${out_ncz} # netCDF3 POSIX input to Zarr output
ncks -O -7 ${in_psx} ${out_ncz} # netCDF3 POSIX input to Zarr output
</verbatim>
</example>
<para>Furthermore, the current NCZarr library (version 4.9.2, March 2023)
does not yet support record dimensions (this is a significant and high
priority netCDF library limitation, not an <acronym><acronymword>NCO</acronymword></acronym> limitation).
All dimensions must be fixed, not record
To workaround this limitation, first fix any record dimensions with,
e.g., 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -O --fix_rec_dmn=all ${in_psx} ${in_psx}
</verbatim>
</example>

<para>Commands with Zarr I/O behave mostly as expected.
<acronym><acronymword>NCO</acronymword></acronym> treats Zarr and <acronym><acronymword>POSIX</acronymword></acronym> files identically once
they are opened via the netCDF <acronym><acronymword>API</acronymword></acronym>.
The main difference between Zarr and <acronym><acronymword>POSIX</acronymword></acronym>, from the
viewpoint of <acronym><acronymword>NCO</acronymword></acronym>, is in handling the filenames.
By default <acronym><acronymword>NCO</acronymword></acronym> performs operations in temporary files that
it moves to a final destination once the rest of the command
succeeds.
Supporting Zarr in <acronym><acronymword>NCO</acronymword></acronym> requires applying the correct
procedures to create, copy, move/rename, and delete files and
directories correctly depending on the backend format.
</para>
<para>Many <acronym><acronymword>NCO</acronymword></acronym> users rely on <acronym><acronymword>POSIX</acronymword></acronym> filename globbing for
multi-file operations, e.g., <samp>ncra in*.nc out.nc</samp>.
Globbing returns matches in <acronym><acronymword>POSIX</acronymword></acronym> format (e.g.,
<code>in1.nc in2.nc in3.nc</code>) which lacks the <code>scheme://</code>
indicator and the <code>#mode=...</code> fragment that the netCDF
<acronym><acronymword>API</acronymword></acronym> needs to open a Zarr store.
There is no perfect solution to this.
</para>
<para>A partial solution is available by judiciously using <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s
new <code>stdin</code> capabilities for all operators
(<pxref label="Specifying-Input-Files"><xrefnodename>Specifying Input Files</xrefnodename></pxref>).
The procedure uses the <command>ls</command> command (instead of globbing) to
identify the desired Zarr stores, and pipes the
(<acronym><acronymword>POSIX</acronymword></acronym>-style) results of that through the newly supplied 
<acronym><acronymword>NCO</acronymword></acronym> filter-script <command>ncz2psx</command> that will prepend the
desired scheme and append the desired fragment to the matched Zarr
stores, and pipe those results onward to an <acronym><acronymword>NCO</acronymword></acronym> operator: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
nces in*.nc out.nc      # POSIX input files via globbing
ls in*.nc | nces out.nc # POSIX input files via stdin
ls -d in* | ncz2psx | nces out.nc # Zarr input via stdin
ls -d in* | ncz2psx --scheme=file --mode=nczarr,file | nces out.nc
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;lfs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lfs --&gt;
</html>
</section>
<node name="Large-File-Support" spaces=" "><nodename>Large File Support</nodename><nodenext spaces=" ">Subsetting Files</nodenext><nodeprev spaces=" ">Zarr and NCZarr</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Large File Support</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="530"><acronym><acronymword>LFS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="531">Large File Support</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: none&linebreak;
Long options: none&linebreak;
</para></cartouche>
<para><acronym><acronymword>NCO</acronymword></acronym> has Large File Support (<acronym><acronymword>LFS</acronymword></acronym>), meaning that 
<acronym><acronymword>NCO</acronymword></acronym> can write files larger than <w>2 GB</w> on some 32-bit
operating systems with netCDF libraries earlier than <w>version 3.6</w>. 
If desired, <acronym><acronymword>LFS</acronymword></acronym> support must be configured when both netCDF and
<acronym><acronymword>NCO</acronymword></acronym> are installed.
netCDF <w>versions 3.6</w> and higher support 64-bit file addresses as part
of the netCDF standard.
We recommend that users ignore <acronym><acronymword>LFS</acronymword></acronym> support which is difficult to
configure and is implemented in <acronym><acronymword>NCO</acronymword></acronym> only to support netCDF
versions prior <w>to 3.6</w>.  
This obviates the need for configuring explicit <acronym><acronymword>LFS</acronymword></acronym> support in
applications (such as <acronym><acronymword>NCO</acronymword></acronym>) that now support 64-bit files   
directly through the netCDF interface.
See <ref label="File-Formats-and-Conversion"><xrefnodename>File Formats and Conversion</xrefnodename></ref> for instructions on accessing 
the different file formats, including 64-bit files, supported by the
modern netCDF interface. 
</para>
<para>If you are still interested in explicit <acronym><acronymword>LFS</acronymword></acronym> support for netCDF versions
prior <w>to 3.6</w>, know that <acronym><acronymword>LFS</acronymword></acronym> support depends on a complex,
interlocking set of operating system  
<footnote spaces="\n"><para>Linux and <acronym><acronymword>AIX</acronymword></acronym> do support <acronym><acronymword>LFS</acronymword></acronym>.</para></footnote>
and netCDF support issues.
The netCDF <acronym><acronymword>LFS</acronymword></acronym> 
<uref><urefurl>http://my.unidata.ucar.edu/content/software/netcdf/faq-lfs.html</urefurl><urefdesc>FAQ</urefdesc></uref>
describes the various file size limitations imposed by different
versions of the netCDF standard.
<acronym><acronymword>NCO</acronymword></acronym> and netCDF automatically attempt to configure <acronym><acronymword>LFS</acronymword></acronym> at
build time. 
</para>
<html endspaces=" ">
&lt;a name=&quot;x&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#x --&gt;
&lt;a name=&quot;grp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grp --&gt;
&lt;a name=&quot;var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#var --&gt;
&lt;a name=&quot;xcl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xcl --&gt;
&lt;a name=&quot;exclude&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#exclude --&gt;
&lt;a name=&quot;sbs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sbs --&gt;
&lt;a name=&quot;subset&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#subset --&gt;
</html>
</section>
<node name="Subsetting-Files" spaces=" "><nodename>Subsetting Files</nodename><nodenext spaces=" ">Subsetting Coordinate Variables</nodenext><nodeprev spaces=" ">Large File Support</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Subsetting Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="532">subsetting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="533">union</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="534">intersection</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="535">exclusion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="536">extraction</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="537"><code>-v <var>var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="538"><code>--variable <var>var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="539"><code>-g <var>grp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="540"><code>--grp <var>grp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="541"><code>--group <var>grp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="542"><code>-x</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="543"><code>--exclude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="544"><code>--xcl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="545"><code>--unn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="546"><code>--union</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="547"><code>--gxvx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="548"><code>--grp_xtr_var_xcl</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Options <code>-g <var>grp</var></code>&linebreak;
Availability: <command>ncbo</command>, <command>nces</command>,
<command>ncecat</command>, <command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>,
<command>ncra</command>, <command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: <samp>-g</samp>&linebreak;
Long options: <samp>--grp</samp> and <samp>--group</samp>&linebreak;
Options <code>-v <var>var</var></code> and <code>-x</code>&linebreak;
Availability: (<command>ncap2</command>), <command>ncbo</command>, <command>nces</command>,
<command>ncecat</command>, <command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>,
<command>ncra</command>, <command>ncrcat</command>, <command>ncwa</command>&linebreak;
Short options: <samp>-v</samp>, <samp>-x</samp>&linebreak;
Long options: <samp>--variable</samp>, <samp>--exclude</samp> or <samp>--xcl</samp>&linebreak;
Options <code>--unn</code>&linebreak;
Availability: <command>ncbo</command>, <command>nces</command>,
<command>ncecat</command>, <command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>,
<command>ncra</command>, <command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: &linebreak;
Long options: <samp>--unn</samp> and <samp>--union</samp>&linebreak;
Options <code>--grp_xtr_var_xcl</code>&linebreak;
Availability: <command>ncks</command>&linebreak;
Short options: &linebreak;
Long options: <samp>--gxvx</samp> and <samp>--grp_xtr_var_xcl</samp>&linebreak;
</para></cartouche>
<para>Subsetting variables refers to explicitly specifying variables and
groups to be included or excluded from operator actions.
Subsetting is controlled by the <samp>-v <var>var</var>[,&dots;]</samp> and
<samp>-x</samp> options for directly specifying variables.  
Specifying groups, whether in addition to or instead of variables,
is quite similar and is controlled by the <samp>-g <var>grp</var>[,&dots;]</samp>
and <samp>-x</samp> options.
<w>A list</w> of variables or groups to extract is specified following the
<samp>-v</samp> and <samp>-g</samp> options, e.g., <samp>-v time,lat,lon</samp> or
<samp>-g grp1,grp2</samp>.
Both options may be specified simultaneously and <acronym><acronymword>NCO</acronymword></acronym> will
extract the intersection of the lists, i.e., only variables of the
specified names found in groups of the specified names.
The <samp>--unn</samp> option causes <acronym><acronymword>NCO</acronymword></acronym> to extract the
union, rather than the intersection, of the specified groups and
variables. 
Not using the <samp>-v</samp> or <samp>-g</samp> option is equivalent to specifying
all variables or groupp, respectively.  
</para>
<para>The <samp>-x</samp> option causes the list of variables specified with
<samp>-v</samp> to be <emph>excluded</emph> rather than <emph>extracted</emph>.
Thus <samp>-x</samp> saves typing when you only want to extract fewer than
half of the variables in a file.
</para><example endspaces=" ">       
<verbatim xml:space="preserve" endspaces=" ">
ncks -x -v v1,v2 in.nc out.nc # Extract all variables except v1, v2
ncks -C -x -v lat,lon in.nc out.nc # Extract all except lat, lon
</verbatim>
</example>
<para>The first example above shows the typical use of <samp>-x</samp> to
subset all variables except a few into the output.
Note that <code>v1</code> and <code>v2</code> will be retained in the
output if they are coordinate-like variables
(<pxref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></pxref>)
associated with any extracted variable.
If one wishes to exclude coordinate-like variables despite their
being referenced by extracted variables, one must use the <samp>-C</samp>  
(or synonym <samp>--xcl_ass_var</samp>) option as shown in the second
example.
</para>
<para>Variables or groups explicitly specified for extraction with
<samp>-v <var>var</var>[,&dots;]</samp> or <samp>-g <var>grp</var>[,&dots;]</samp>
<emph>must</emph> be present in the input file or an error will result.
Variables explicitly specified for <emph>exclusion</emph> with
<samp>-x -v <var>var</var>[,&dots;]</samp> need not be present in the input
file.
To accord with the sophistication of the underlying hierarchy,
group subsetting is controlled by a few powerful yet subtle syntactical
distinctions.
When learning this syntax it is helpful to keep in mind the similarity
between group hierarchies and directory structures. 
</para>
<html endspaces=" ">
&lt;a name=&quot;gxvx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gxvx --&gt;
&lt;a name=&quot;grp_xtr_var_xcl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grp_xtr_var_xcl --&gt;
</html>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> 4.4.4 (June, 2014), <command>ncks</command> (alone) supports 
an option to include specified groups yet exclude specified variables.
The <samp>--grp_xtr_var_xcl</samp> switch (with long option equivalent
<samp>--gxvx</samp>) extracts all contents of groups given as arguments to
<samp>-g <var>grp</var>[,&dots;]</samp>, except for variables given as arguments
to <samp>-v <var>var</var>[,&dots;]</samp>.
Use this when one or a few variables in hierarchical files are not to be
extracted, and all other variables are.  
This is useful when coercing netCDF4 files into netCDF3 files such as
with converting, flattening, or dismembering files 
(see <ref label="Flattening-Groups"><xrefnodename>Flattening Groups</xrefnodename></ref>).
</para><example endspaces=" ">       
<pre xml:space="preserve">ncks --grp_xtr_var_xcl -g g1 -v v1 # Extract all of group g1 except v1
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="549"><command>mv</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="550"><command>cp</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="551">recursion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="552">recursive</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="553">anchor</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="554">anchoring</indexterm></cindex>
<html endspaces=" ">
&lt;a name=&quot;rcr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rcr --&gt;
&lt;a name=&quot;recursion&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#recursion --&gt;
&lt;a name=&quot;recursive&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#recursive --&gt;
&lt;a name=&quot;ncr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncr --&gt;
&lt;a name=&quot;anchor&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#anchor --&gt;
&lt;a name=&quot;anchoring&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#anchoring --&gt;
</html>
<para>Two properties of subsetting, recursion and anchoring, are best
illustrated by reminding the user of their <acronym><acronymword>UNIX</acronymword></acronym> equivalents.
The <acronym><acronymword>UNIX</acronymword></acronym> command <command>mv src dst</command> moves <file>src</file>
<emph>and all its subdirectories</emph> (and all their subdirectories etc.)
to <file>dst</file>.
In other words <command>mv</command> is, by default, <emph>recursive</emph>.
In contrast, the <acronym><acronymword>UNIX</acronymword></acronym> command <command>cp src dst</command> moves
<file>src</file>, and only <file>src</file>, to <file>dst</file>,
If <file>src</file> is a directory, not a file, then that command fails.
One must explicitly request to copy directories recursively, i.e.,
with <command>cp -r src dst</command>.
In <acronym><acronymword>NCO</acronymword></acronym> recursive extraction (and copying) of groups is the
default (like with <command>mv</command>, not with <command>cp</command>).
Recursion is turned off by appending a trailing slash to the path.
</para>
<para>These <acronym><acronymword>UNIX</acronymword></acronym> commands also illustrate a property we call
<emph>anchoring</emph>. 
The command <command>mv src dst</command> moves (recursively) the source
directory <file>src</file> to the destination directory <file>dst</file>. 
If <file>src</file> begins with the slash character then the specified path is
relative to the root directory, otherwise the path is relative to the
current working directory. 
In other words, an initial slash character anchors the subsequent path
to the root directory.
In <acronym><acronymword>NCO</acronymword></acronym> an initial slash anchors the path at the root group.
Paths that begin and end with slash characters (e.g., <file>//</file>,
<file>/g1/</file>, and <file>/g1/g2/</file>) are both anchored and non-recursive. 
</para>
<para>Consider the following commands, all of which may be assumed to end with
<samp>in.nc out.nc</samp>:
</para><example endspaces=" ">       
<pre xml:space="preserve">ncks -g  g1  # Extract, recursively, all groups with a g1 component
ncks -g  g1/ # Extract, non-recursively, all groups terminating in g1
ncks -g /g1  # Extract, recursively, root group g1
ncks -g /g1/ # Extract, non-recursively root group g1
ncks -g //   # Extract, non-recursively the root group
</pre></example>
<para>The first command is probably the most useful and common.
It would extract these groups, if present, and all their direct
ancestors and children:
<file>/g1</file>, <file>/g2/g1</file>, and <file>/g3/g1/g2</file>.
In other words, the simplest form of <samp>-g grp</samp> grabs all groups that 
(and their direct ancestors and children, recursively) that have
<file>grp</file> as a complete component of their path.
A simple string match is insufficient, <var>grp</var> must be a complete 
component (i.e., group name) in the path.
The option <samp>-g g1</samp> would not extract these groups because <file>g1</file> 
is not a complete component of the path: <file>/g12</file>, <file>/fg1</file>, and
<file>/g1g1</file>.
The second command above shows how a terminating slash character
<kbd>/</kbd> cancels the recursive copying of groups.
An argument to <samp>-g</samp> which terminates with a slash character
extracts the group and its direct ancestors, but none of its children. 
The third command above shows how an initial slash character <kbd>/</kbd>
anchors the argument to the root group.
The third command would not extract the group <file>/g2/g1</file> because 
the <file>g1</file> group is not at the root level, but it would extract,
any group <file>/g1</file> at the root level and all its children,
recursively.  
The fourth command is the non-recursive version of the third command.
The fifth command is a special case of the fourth command.
</para>
<html endspaces=" ">
&lt;a name=&quot;unn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#unn --&gt;
&lt;a name=&quot;nsx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nsx --&gt;
&lt;a name=&quot;union&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#union --&gt;
&lt;a name=&quot;intersection&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#intersection --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="555">union</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="556">intersection</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="557"><code>--unn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="558"><code>--union</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="559"><code>--nsx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="560"><code>--intersection</code></indexterm></cindex>
<para>As mentioned above, both <samp>-v</samp> and <samp>-g</samp> options may be
specified simultaneously and <acronym><acronymword>NCO</acronymword></acronym> will, by default, extract the
intersection of the lists, i.e., the specified variables found in the
specified groups
<footnote spaces="\n"><para>Intersection-mode can also be explicitly invoked with the <samp>--nsx</samp>
or <samp>--intersection</samp> switches.
These switches are supplied for clarity and consistency and do
absolutely nothing since intersection-mode is the default.</para></footnote>.
The <samp>--unn</samp> option causes <acronym><acronymword>NCO</acronymword></acronym> to extract the
union, rather than the intersection, of the specified groups and
variables. 
Consider the following commands (which may be assumed to end with
<samp>in.nc out.nc</samp>):
</para><example endspaces=" ">       
<pre xml:space="preserve"># Intersection-mode subsetting (default)
ncks -g  g1  -v v1 # Yes: /g1/v1, /g2/g1/v1. No: /v1, /g2/v1
ncks -g /g1  -v v1 # Yes: /g1/v1, /g1/g2/v1. No: /v1, /g2/v1, /g2/g1/v1
ncks -g  g1/ -v v1 # Yes: /g1/v1, /g2/g1/v1. No: /v1, /g2/v1, /g1/g2/v1
ncks -v  g1/v1     # Yes: /g1/v1, /g2/g1/v1. No: /v1, /g2/v1, /g1/g2/v1
ncks -g /g1/ -v v1 # Yes: /g1/v1. No: /g2/g1/v1, /v1, /g2/v1 ...
ncks -v /g1/v1     # Yes: /g1/v1. No: /g2/g1/v1, /v1, /g2/v1 ...

# Union-mode subsetting (invoke with --unn or --union)
ncks -g  g1  -v v1 --unn # All variables in  g1 or progeny, or named v1
ncks -g /g1  -v v1 --unn # All variables in /g1 or progeny, or named v1
ncks -g  g1/ -v v1 --unn # All variables in  g1 or named v1
ncks -g /g1/ -v v1 --unn # All variables in /g1 or named v1
</pre></example>
<para>The first command (<samp>-g g1 -v v1</samp>) extracts the variable <file>v1</file>
from any group named <file>g1</file> or descendent <file>g1</file>.
The second command extracts <file>v1</file> from any root group
named <file>g1</file> and any descendent groups as well.
The third and fourth commands are equivalent ways of extracting
<file>v1</file> only from the root group named <file>g1</file> (not its
descendents). 
The fifth and sixth commands are equivalent ways of extracting the 
variable <file>v1</file> only from the root group named <file>g1</file>.
Subsetting in union-mode (with <samp>--unn</samp>) causes all variables to be
extracted which meet either one or both of the specifications of the 
variable and group specifications.
Union-mode subsetting is simply the logical &textldquo;OR&textrdquo; of intersection-mode
subsetting. 
As discussed below, the group and variable specifications may be comma
separated lists of regular expressions for added control over
subsetting. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="561">memory requirements</indexterm></cindex>
<para>Remember, if averaging or concatenating large files stresses your
systems memory or disk resources, then the easiest solution is often to
subset (with <samp>-g</samp> and/or <samp>-v</samp>) to retain only the most
important variables (<pxref label="Memory-Requirements"><xrefnodename>Memory Requirements</xrefnodename></pxref>).
</para><example endspaces=" ">       
<pre xml:space="preserve">ncks          in.nc out.nc # Extract all groups and variables
ncks -v scl   # Extract variable scl from all groups
ncks -g g1    # Extract group g1 and descendents
ncks -x -g g1 # Extract all groups except g1 and descendents
ncks -g g2,g3 -v scl # Extract scl from groups g2 and g3
</pre></example>
<para>Overwriting and appending work as expected:
</para><example endspaces=" ">
<pre xml:space="preserve"># Replace scl in group g2 in out.nc with scl from group g2 from in.nc
ncks -A -g g2 -v scl in.nc out.nc
</pre></example>

<para>Due to its special capabilities, <command>ncap2</command> interprets the
<samp>-v</samp> switch differently 
(<pxref label="ncap2-netCDF-Arithmetic-Processor"><xrefnodename>ncap2 netCDF Arithmetic Processor</xrefnodename></pxref>). 
For <command>ncap2</command>, the <samp>-v</samp> switch takes no arguments and
indicates that <emph>only</emph> user-defined variables should be output. 
<command>ncap2</command> neither accepts nor understands the <var>-x</var> and
<var>-g</var> switches.
</para>
<html endspaces=" ">
&lt;a name=&quot;rx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rx --&gt;
&lt;a name=&quot;wildcarding&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wildcarding --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="562">extended regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="563">regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="564">pattern matching</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="565">wildcards</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="566"><command>grep -E</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="567"><command>egrep</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="568"><command>ncatted</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="569"><acronym><acronymword>GNU</acronymword></acronym></indexterm></cindex>
<para>Regular expressions the syntax that <acronym><acronymword>NCO</acronymword></acronym> use pattern-match
object names in netCDF file against user requests.
The user can select all variables beginning with the string <samp>DST</samp>
from an input file by supplying the regular expression <samp>^DST</samp> to
the <samp>-v</samp> switch, i.e., <samp>-v '^DST'</samp>. 
The meta-characters used to express pattern matching operations are
<samp>^$+?.*[]&lbrace;&rbrace;|</samp>. 
If the regular expression pattern matches <emph>any</emph> part of a variable 
name then that variable is selected.
This capability is also called <dfn>wildcarding</dfn>, and is very useful for 
sub-setting large data files.
</para>
<para>Extended regular expressions are defined by the <acronym><acronymword>POSIX</acronymword></acronym>
<command>grep -E</command> (aka <command>egrep</command>) command.  
As of <acronym><acronymword>NCO</acronymword></acronym> 2.8.1 (August, 2003), variable name arguments
to the <samp>-v</samp> switch may contain <dfn>extended regular expressions</dfn>.
As of <acronym><acronymword>NCO</acronymword></acronym> 3.9.6 (January, 2009), variable names arguments 
to <command>ncatted</command> may contain <dfn>extended regular expressions</dfn>. 
As of <acronym><acronymword>NCO</acronymword></acronym> 4.2.4 (November, 2012), group name arguments 
to the <samp>-g</samp> switch may contain <dfn>extended regular expressions</dfn>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="570"><acronym><acronymword>POSIX</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="571"><code>regex</code></indexterm></cindex>
<para>Because of its wide availability, <acronym><acronymword>NCO</acronymword></acronym> uses the <acronym><acronymword>POSIX</acronymword></acronym>  
regular expression library <code>regex</code>.  
Regular expressions of arbitary complexity may be used.
Since netCDF variable names are relatively simple constructs, only a 
few varieties of variable wildcards are likely to be useful.
For convenience, we define the most useful pattern matching operators
here: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="572"><code>.</code> (wildcard character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="573"><code>$</code> (wildcard character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="574"><code>^</code> (wildcard character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="575"><code>?</code> (filename expansion)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="576"><code>*</code> (filename expansion)</indexterm></cindex>
</para><table commandarg="samp" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="samp">^</itemformat></item>
</tableterm><tableitem><para>Matches the beginning of a string
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">$</itemformat></item>
</tableterm><tableitem><para>Matches the end of a string
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">.</itemformat></item>
</tableterm><tableitem><para>Matches any single character
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>The most useful repetition and combination operators are
<cindex index="cp" spaces=" "><indexterm index="cp" number="577"><code>?</code> (wildcard character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="578"><code>*</code> (wildcard character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="579"><code>+</code> (wildcard character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="580"><code>|</code> (wildcard character)</indexterm></cindex>
</para><table commandarg="samp" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="samp">?</itemformat></item>
</tableterm><tableitem><para>The preceding regular expression is optional and matched at most once
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">*</itemformat></item>
</tableterm><tableitem><para>The preceding regular expression will be matched zero or more times
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">+</itemformat></item>
</tableterm><tableitem><para>The preceding regular expression will be matched one or more times
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">|</itemformat></item>
</tableterm><tableitem><para>The preceding regular expression will be joined to the following regular
expression.
The resulting regular expression matches any string matching either
subexpression. 
</para></tableitem></tableentry></table>
<noindent></noindent>

<para>To illustrate the use of these operators in extracting variables
and groups, consider file <file>in_grp.nc</file> with groups
<code>g0</code>&textndash;<code>g9</code>, and subgroups <code>s0</code>&textndash;<code>s9</code>, in each of
those groups, and file <file>in.nc</file> with variables <code>Q</code>,
<code>Q01</code>&textndash;<code>Q99</code>, <code>Q100</code>, <code>QAA</code>&textndash;<code>QZZ</code>,
<code>Q_H2O</code>, <code>X_H2O</code>, <code>Q_CO2</code>, <code>X_CO2</code>.  
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -v '.+' in.nc               # All variables (default)
ncks -v 'Q.?' in.nc              # Variables that contain Q
ncks -v '^Q.?' in.nc             # Variables that start with Q
ncks -v '^Q+.?.' in.nc           # Q, Q0--Q9, Q01--Q99, QAA--QZZ, etc.
ncks -v '^Q..' in.nc             # Q01--Q99, QAA--QZZ, etc.
ncks -v '^Q[0-9][0-9]' in.nc     # Q01--Q99, Q100
ncks -v '^Q[[:digit:]]{2}' in.nc # Q01--Q99
ncks -v 'H2O$' in.nc             # Q_H2O, X_H2O 
ncks -v 'H2O$|CO2$' in.nc        # Q_H2O, X_H2O, Q_CO2, X_CO2 
ncks -v '^Q[0-9][0-9]$' in.nc    # Q01--Q99
ncks -v '^Q[0-6][0-9]|7[0-3]' in.nc # Q01--Q73, Q100
ncks -v '(Q[0-6][0-9]|7[0-3])$' in.nc # Q01--Q73
ncks -v '^[a-z]_[a-z]{3}$' in.nc # Q_H2O, X_H2O, Q_CO2, X_CO2
ncks -g 'g.' in_grp.nc           # 10 Groups g0-g9
ncks -g 's.' in_grp.nc       # 100 sub-groups g0/s0, g0/s1, ... g9/s9
ncks -g 'g.' -v 'v.' in_grp.nc   # All variables 'v.' in groups 'g.'
</verbatim>
</example>
<para>Beware&textmdash;two of the most frequently used repetition pattern matching
operators, <samp>*</samp> and <samp>?</samp>, are also valid pattern matching
operators for filename expansion (globbing) at the shell-level.
Confusingly, their meanings in extended regular expressions and in
shell-level filename expansion are significantly different.
In an extended regular expression, <samp>*</samp> matches zero or more
occurences of the preceding regular expression. 
Thus <samp>Q*</samp> selects all variables, and <samp>Q+.*</samp> selects all
variables containing <samp>Q</samp> (the <samp>+</samp> ensures the preceding item 
matches at least once).
To match zero or one occurence of the preceding regular expression,   
use <samp>?</samp>.
Documentation for the <acronym><acronymword>UNIX</acronymword></acronym> <command>egrep</command> command details the
extended regular expressions which <acronym><acronymword>NCO</acronymword></acronym> supports.
</para>
<html endspaces=" ">
&lt;a name=&quot;globbing&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#globbing --&gt;
&lt;a name=&quot;glb&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#glb --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="581">globbing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="582">shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="583"><command>bash</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="584"><command>csh</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="585">quotes</indexterm></cindex>
<para>One must be careful to protect any special characters in the regular
expression specification from being interpreted (globbed) by the shell.
This is accomplish by enclosing special characters within single or
double quotes
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -v Q?? in.nc out.nc   # Error: Shell attempts to glob wildcards
ncra -v '^Q+..' in.nc out.nc # Correct: NCO interprets wildcards
ncra -v '^Q+..' in*.nc out.nc # Correct: NCO interprets, Shell globs 
</pre></example>
<para>The final example shows that commands may use a combination of variable
wildcarding and shell filename expansion (globbing).
For globbing, <samp>*</samp> and <samp>?</samp> <emph>have nothing to do</emph> with the 
preceding regular expression!
In shell-level filename expansion, <samp>*</samp> matches any string,
including the null string and <samp>?</samp> matches any single character. 
Documentation for <command>bash</command> and <command>csh</command> describe the rules of
filename expansion (globbing).
</para>
<html endspaces=" ">
&lt;a name=&quot;no_coord&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_coord --&gt;
&lt;a name=&quot;no_crd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_crd --&gt;
&lt;a name=&quot;crd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#crd --&gt;
&lt;a name=&quot;-C&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-C --&gt;
&lt;a name=&quot;-c&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-c --&gt;
&lt;a name=&quot;xcl_ass_var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xcl_ass_var --&gt;
&lt;a name=&quot;xtr_ass_var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xtr_ass_var --&gt;
</html>
</section>
<node name="Subsetting-Coordinate-Variables" spaces=" "><nodename>Subsetting Coordinate Variables</nodename><nodenext spaces=" ">Group Path Editing</nodenext><nodeprev spaces=" ">Subsetting Files</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Subsetting Coordinate Variables</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="586">subsetting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="587"><code>-C</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="588"><code>-c</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="589"><code>--xcl_ass_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="590"><code>--xtr_ass_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="591"><code>--no_coords</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="592"><code>--no_crd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="593"><code>--coords</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="594"><code>--crd</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>nces</command>,
<command>ncecat</command>, <command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>,
<command>ncra</command>, <command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: <samp>-C</samp>, <samp>-c</samp>&linebreak;
Long options: <samp>--no_coords</samp>, <samp>--no_crd</samp>, <samp>--xcl_ass_var</samp>, 
<samp>--crd</samp>, <samp>--coords</samp>, <samp>--xtr_ass_var</samp>&linebreak;
</para></cartouche>
<para>By default, coordinates variables associated with any variable appearing
in the <var>input-file</var> will be placed in the <var>output-file</var>, even
if they are not explicitly specified, e.g., with the <samp>-v</samp> switch.
Thus variables with a latitude coordinate <code>lat</code> always carry the
values of <code>lat</code> with them into the <var>output-file</var>.
This automatic inclusion feature can be disabled with <samp>-C</samp>, which
causes <acronym><acronymword>NCO</acronymword></acronym> to exclude (or, more precisely, not to
automatically include) coordinates and associated variables from the
extraction list.
However, using <samp>-C</samp> does not preclude the user from including some
coordinates in the output files simply by explicitly selecting the
coordinates and associated variables with the <var>-v</var> option.
The <samp>-c</samp> option, on the other hand, is a shorthand way of
automatically specifying that <emph>all</emph> coordinate and associated
variables in <var>input-files</var> should appear in <var>output-file</var>.
The user can thereby select all coordinate variables without even
knowing their names.  
</para>
<para>The meaning of &textldquo;coordinates&textrdquo; in these two options has expanded since
about 2009 from simple one dimensional coordinates (per the
<acronym><acronymword>NUG</acronymword></acronym>) definition) to any and all associated variables.
This includes multi-dimensional coordinates as well as a menagerie
of associated variables defined by the <acronym><acronymword>CF</acronymword></acronym> metadata
conventions: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="595"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm></cindex>
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.5 (July, 2014) 
both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>ancillary_variables</code>
convention described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.8 (April, 2011) 
both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>bounds</code>
convention described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.4 (January, 2017) 
both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>cell_measures</code>
convention described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.9 (May, 2015) 
both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>climatology</code>
convention described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 3.9.6 (January, 2009) 
both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code>
convention described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.4 (January, 2017) 
both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>formula_terms</code>
convention described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.0 (May, 2016) 
both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>grid_mapping</code>
convention described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>. 
</para>
<para>The expanded categories of variables controlled by <samp>-c</samp> and
<samp>-C</samp> justified adding a more descriptive switch.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.8.0 (May, 2019) the switch
<samp>--xcl_ass_var</samp>, which stands for &textldquo;exclude associated variables&textrdquo;, 
is synonymous with <samp>-C</samp> and <samp>--xtr_ass_var</samp>, which stands
for &textldquo;extract associated variables&textrdquo;, is synonymous with <samp>-c</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;gpe&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gpe --&gt;
</html>
</section>
<node name="Group-Path-Editing" spaces=" "><nodename>Group Path Editing</nodename><nodenext spaces=" ">C and Fortran Index Conventions</nodenext><nodeprev spaces=" ">Subsetting Coordinate Variables</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Group Path Editing</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="596"><code>-G <var>gpe_dsc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="597"><code>--gpe <var>gpe_dsc</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Options <code>-G <var>gpe_dsc</var></code>&linebreak;
Availability: <command>ncbo</command>, <command>ncecat</command>, <command>nces</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>, <command>ncwa</command>&linebreak;
Short options: <samp>-G</samp>&linebreak;
Long options: <samp>--gpe</samp>&linebreak;
</para></cartouche>

<para><dfn>Group Path Editing</dfn>, or <acronym><acronymword>GPE</acronymword></acronym>, allows the user to
restructure (i.e., add, remove, and rename groups) in the output file 
relative to the input file based on the instructions they provide.
As of  <acronym><acronymword>NCO</acronymword></acronym> 4.2.3 (November, 2012), all operators that accept  
netCDF4 files with groups accept the <samp>-G</samp> switch, or its
long-option equivalent <samp>--gpe</samp>.
To master <acronym><acronymword>GPE</acronymword></acronym> one must understand the meaning of the
required <var>gpe_dsc</var> structure/argument that specifies the
transformation of input-to-output group paths.
</para>
<para>Each <var>gpe_dsc</var> contains up to three elements (two are optional) in
the following order:&linebreak;   
<var>gpe_dsc</var> = <var>grp_pth</var>:<var>lvl_nbr</var> or <var>grp_pth</var>&arobase;<var>lvl_nbr</var>
</para>
<table commandarg="var" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="var">grp_pth</itemformat></item>
</tableterm><tableitem><para>Group Path.
<cindex index="cp" spaces=" "><indexterm index="cp" number="598">group path</indexterm></cindex>
This (optional) component specifies the output group path that should be 
appended after any editing (i.e., deletion or truncation) of the input
path is performed.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="var">lvl_nbr</itemformat></item>
</tableterm><tableitem><para>The number of levels to delete (from the head) or truncate (from the
tail) of the input path.
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>If both components of the argument are present, then a single character,
either the colon or at-sign (<code>:</code> or <code>&arobase;</code>), must separate them.
If only <var>grp_pth</var> is specifed, the separator character may be
omitted, e.g., <samp>-G g1</samp>.
If only <var>lvl_nbr</var> is specifed, the separator character is still
required to indicate it is a <var>lvl_nbr</var> arugment and not a
<var>grp_pth</var>, e.g., <samp>-G :-1</samp> or <samp>-G &arobase;1</samp>.
</para>
<para>If the at-sign separator character <code>&arobase;</code> is used instead of the colon
separator character <code>:</code>, then the following <var>lvl_nbr</var> arugment 
must be positive and it will be assumed to refer to Truncation-Mode.
Hence, <samp>-G :-1</samp> is the same as <samp>-G &arobase;1</samp>. 
This is simply a way of making the <var>lvl_nbr</var> argument
positive-definite. 
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Flattening Groups</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Moving Groups</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Dismembering Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Checking CF-compliance</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>
<node name="Flattening-Groups" spaces=" "><nodename>Flattening Groups</nodename><nodenext spaces=" ">Moving Groups</nodenext><nodeprev spaces=" ">Group Path Editing</nodeprev><nodeup spaces=" ">Group Path Editing</nodeup></node>
<subsection spaces=" "><sectiontitle>Deletion, Truncation, and Flattening of Groups</sectiontitle>
<html endspaces=" ">
&lt;a name=&quot;flatten&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#flatten --&gt;
&lt;a name=&quot;delete&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#delete --&gt;
&lt;a name=&quot;truncate&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#truncate --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="599"><code>&arobase;</code> (separator character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="600"><code>:</code> (separator character)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="601">delete (groups)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="602">truncate (groups)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="603">flatten (groups)</indexterm></cindex>
<para><acronym><acronymword>GPE</acronymword></acronym> has three editing modes: Delete, Truncate, and
Flatten.
Select one of <acronym><acronymword>GPE</acronymword></acronym>&textrsquo;s three editing modes by supplying a
<var>lvl_nbr</var> that is positive, negative, or zero for Delete-, 
Truncate- and Flatten-mode, respectively. 
</para>
<para>In Delete-mode, <var>lvl_nbr</var> is a positive integer which specifies
the maximum number of group path components (i.e., groups) that
<acronym><acronymword>GPE</acronymword></acronym> will try to delete from the head of <var>grp_pth</var>. 
For example <math><var>lvl_nbr</var> = 3</math> changes the input path
<file>/g1/g2/g3/g4/g5</file> to the output path <file>/g4/g5</file>.
Input paths with <var>lvl_nbr</var> or fewer components (groups)
are completely erased and the output path commences from the root  
level. 
</para>
<para>In other words, <acronym><acronymword>GPE</acronymword></acronym> is tolerant of specifying too many group
components to delete. 
It deletes as many as possible, without complaint, and then begins to
flatten the file (which fails if namespace conflicts arise).
</para>
<para>In Truncate-mode, <var>lvl_nbr</var> is a negative integer which specifies
the maximum number of group path components (i.e., groups) that
<acronym><acronymword>GPE</acronymword></acronym> will try to truncate from the tail of <var>grp_pth</var>. 
For example <math><var>lvl_nbr</var> = -3</math> changes the input path
<file>/g1/g2/g3/g4/g5</file> to the output path <file>/g1/g2</file>.
Input paths with <var>lvl_nbr</var> or fewer components (groups)
are completely erased and the output path commences from the root  
level. 
</para>
<para>In Flatten-mode, indicated by the separator character alone
or with <math><var>lvl_nbr</var> = 0</math>, <acronym><acronymword>GPE</acronymword></acronym> removes the entire group
path from the input file and constructs the output path beginning at the
root level.  
For example <code>-G :0</code> and <code>-G :</code> are identical and change the
input path <file>/g1/g2/g3/g4/g5</file> to the output path <file>/</file> whereas
<code>-G g1:0</code> and <code>-G g1:</code> are identical and result in the output 
path <file>/g1</file> for all variables.
</para>
<para>Subsequent to the alteration of the input path by the specified
editing mode, if any, <acronym><acronymword>GPE</acronymword></acronym> prepends (in Delete Mode)
or Appends (in Truncate-mode) any specifed <var>grp_pth</var> to the output
path. 
For example <code>-G g2</code> changes the input paths <file>/</file> and <file>/g1</file>
to <file>/g2</file> and <file>/g1/g2</file>, respectively.
Likewise, <code>-G g2/g3</code> changes the input paths <file>/</file> and <file>/g1</file>
to <file>/g2/g3</file> and <file>/g1/g2/g3</file>, respectively.
When <var>grp_pth</var> and <var>lvl_nbr</var> are both specified, the editing
actions are taken in sequence so that, e.g., <code>-G g1/g2:2</code> 
changes the input paths <file>/</file> and <file>/h1/h2/h3/h4</file>
to <file>/g1/g2</file> and <file>/g1/g2/h3/h4</file>, respectively.
Likewise, <code>-G g1/g2:-2</code> changes the input paths <file>/</file> and
<file>/h1/h2/h3/h4</file> to <file>/g1/g2</file> and <file>/h1/h2/g1/g2</file>,
respectively. 
</para>
<para>Combining <acronym><acronymword>GPE</acronymword></acronym> with subsetting (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>) 
yields powerful control over the extracted (or excluded) variables and
groups and their placement in the output file as shown by the following
commands. 
All commands below may be assumed to end with <samp>in.nc out.nc</samp>.
</para><example endspaces=" ">       
<verbatim xml:space="preserve" endspaces=" ">
# Prepending paths without editing:
ncks                   # /g?/v? -&gt; /g?/v?
ncks             -v v1 # /g?/v1 -&gt; /g?/v1
ncks       -g g1       # /g1/v? -&gt; /g1/v?
ncks -G o1             # /g?/v? -&gt; /o1/g?/v?
ncks -G o1 -g g1       # /g1/v? -&gt; /o1/g1/v?
ncks       -g g1 -v v1 # /g1/v1 -&gt; /g1/v1
ncks -G o1       -v v1 # /g?/v1 -&gt; /o1/g?/v1
ncks -G o1 -g g1 -v v1 # /g1/v1 -&gt; /o1/g1/v1
ncks -G g1 -g /  -v v1 # /v1    -&gt; /g1/v1
ncks -G g1/g2    -v v1 # /g?/v1 -&gt; /g1/g2/g?/v1
# Delete-mode: Delete from and Prepend to path head
# Syntax: -G [ppn]:lvl_nbr = # of levels to delete
ncks -G :1    -g g1    -v v1 # /g1/v1    -&gt; /v1
ncks -G :1    -g g1/g1 -v v1 # /g1/g1/v1 -&gt; /g1/v1
ncks -G :2    -g g1/g1 -v v1 # /g1/g1/v1 -&gt; /v1
ncks -G :2    -g g1    -v v1 # /g1/v1    -&gt; /v1
ncks -G g2:1  -g g1    -v v1 # /g1/v1    -&gt; /g2/v1
ncks -G g2:2  -g g1/g1 -v v1 # /g1/g1/v1 -&gt; /g2/v1
ncks -G g2:1  -g /     -v v1 # /v1       -&gt; /g2/v1
ncks -G g2:1           -v v1 # /v1       -&gt; /g2/v1
ncks -G g2:1  -g g1/g1 -v v1 # /g1/g1/v1 -&gt; /g2/g1/v1
# Flatten-mode: Remove all input path components
# Syntax: -G [apn]: colon without numerical argument
ncks -G :            -v v1 # /g?/v1    -&gt; /v1
ncks -G :   -g g1    -v v1 # /g1/v1    -&gt; /v1
ncks -G :   -g g1/g1 -v v1 # /g1/g1/v1 -&gt; /v1
ncks -G g2:          -v v1 # /g?/v1    -&gt; /g2/v1
ncks -G g2:                # /g?/v?    -&gt; /g2/v?
ncks -G g2: -g g1/g1 -v v1 # /g1/g1/v1 -&gt; /g2/v1
# Truncate-mode: Truncate from and Append to path tail
# Syntax: -G [apn]:-lvl_nbr = # of levels to truncate
# NB: -G [apn]:-lvl_nbr is equivalent to -G [apn]@lvl_nbr
ncks -G :-1   -g g1    -v v1 # /g1/v1    -&gt; /v1
ncks -G :-1   -g g1/g2 -v v1 # /g1/g2/v1 -&gt; /g1/v1
ncks -G :-2   -g g1/g2 -v v1 # /g1/g2/v1 -&gt; /v1
ncks -G :-2   -g g1    -v v1 # /g1/v1    -&gt; /v1
ncks -G g2:-1          -v v1 # /g?/v1    -&gt; /g2/v1
ncks -G g2:-1 -g g1    -v v1 # /g1/v1    -&gt; /g2/v1
ncks -G g1:-1 -g g1/g2 -v v1 # /g1/g2/v1 -&gt; /g1/g1/v1
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;mv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mv --&gt;
&lt;a name=&quot;move&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#move --&gt;
</html>
</subsection>
<node name="Moving-Groups" spaces=" "><nodename>Moving Groups</nodename><nodenext spaces=" ">Dismembering Files</nodenext><nodeprev spaces=" ">Flattening Groups</nodeprev><nodeup spaces=" ">Group Path Editing</nodeup></node>
<subsection spaces=" "><sectiontitle>Moving Groups</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="604">move groups</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="605">groups, moving</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="606">rename groups</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="607">groups, renaming</indexterm></cindex>
<para>Until fall 2013 (netCDF version 4.3.1-pre1), netCDF contained no library
function for renaming groups, and therefore <command>ncrename</command> cannot
rename groups.
However, <acronym><acronymword>NCO</acronymword></acronym> built on earlier versions of netCDF than 4.3.1
can use a <acronym><acronymword>GPE</acronymword></acronym>-based workaround mechanism to &textldquo;rename&textrdquo;
groups. 
The <acronym><acronymword>GPE</acronymword></acronym> mechanism actually <emph>moves</emph> (i.e., copies to a new
location) groups, a more arduous procedure than simply renaming them.
<acronym><acronymword>GPE</acronymword></acronym> applies to all selected groups, so, in the general case,
one must move only the desired group to a new file, and then merge that
new file with the original to obtain a file where the desired group has
been &textldquo;renamed&textrdquo; and all else is unchanged.
Here is how to &textldquo;rename&textrdquo; group <file>/g4</file> to group <file>/f4</file> with
<acronym><acronymword>GPE</acronymword></acronym> instead of <command>ncrename</command>
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -O -G f4:1 -g g4 ~/nco/data/in_grp.nc ~/tmp.nc # Move /g4 to /f4
ncks -O -x -g g4 ~/nco/data/in_grp.nc ~/out.nc # Excise /g4
ncks -A ~/tmp.nc ~/out.nc # Add /f4 to new file
</pre></example>
<para>If the original group <file>g4</file> is not excised from <file>out.nc</file> (step
two above), then the final output file would contain both <file>g4</file> and
a copy named <file>f4</file>.
Thus GPE can be used to both &textldquo;rename&textrdquo; and copy groups.
The recommended way to rename groups when when netCDF version 4.3.1 is
availale is to use <command>ncrename</command> (<pxref label="ncrename-netCDF-Renamer"><xrefnodename>ncrename netCDF Renamer</xrefnodename></pxref>).
</para>
<html endspaces=" ">
&lt;a name=&quot;xmp_flt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_flt --&gt;
</html>
<para>One may wish to flatten hierarchical group files for many reasons.
These include <w>1. To</w> obtain flat netCDF3 files for use with tools
that do not work with netCDF4 files, <w>2. To</w> split-apart
hierarchies to re-assemble into different hierarchies, and
<w>3. To</w> provide a subset of a hierarchical file with the simplest
possible storage structure.
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -O -G : -g cesm -3 ~/nco/data/cmip5.nc ~/cesm.nc # Extract /cesm to /
</pre></example>
<para>The <option>-3</option> switch
<footnote><para>Note that the <option>-3</option> switch should appear <emph>after</emph> the
<option>-G</option> and <option>-g</option> switches. 
This is due to an artifact of the <acronym><acronymword>GPE</acronymword></acronym> implementation which we
wish to remove in the future.</para></footnote>
specifies the output dataset should be in netCDF3
format, the <option>-G :</option> option flattens all extracted groups, and the
<option>-g cesm</option> option extracts only the <code>cesm</code> group and leaves
all other groups (e.g., <code>ecmwf</code>, <code>giss</code>).
</para>
<html endspaces=" ">
&lt;a name=&quot;dismember&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dismember --&gt;
&lt;a name=&quot;disaggregate&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#disaggregate --&gt;
&lt;a name=&quot;ncdismember&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncdismember --&gt;
</html>
</subsection>
<node name="Dismembering-Files" spaces=" "><nodename>Dismembering Files</nodename><nodenext spaces=" ">Checking CF-compliance</nodenext><nodeprev spaces=" ">Moving Groups</nodeprev><nodeup spaces=" ">Group Path Editing</nodeup></node>
<subsection spaces=" "><sectiontitle>Dismembering Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="608">disaggregate</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="609">dismember</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="5" mergedindex="cp">ncdismember</indexterm></findex>
<para>Let us show how to completely disaggregate (or, more memorably)
<emph>dismember</emph> a hierarchical dataset.
For now we take this to mean: store each group as a standalone flat
dataset in netCDF3 format.
This can be accomplished by looping the previous example over all
groups. 
This script <file>ncdismember</file> dismembers the input file <var>fl_in</var>
specified in the first argument and places the resulting files in the
directory <var>drc_out</var> specified by the second argument:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
cat &gt; ~/ncdismember &lt;&lt; 'EOF'
#!/bin/sh

# Purpose: Dismember netCDF4/HDF5 hierarchical files. CF-check them.
# Place each input file group in separate netCDF3 output file
# Described in NCO User Guide at http://nco.sf.net/nco.html#dismember
# Requirements: NCO 4.3.x+, UNIX shell utilities awk, grep, sed
# Optional: Decker CFchecker https://bitbucket.org/mde_/cfchecker

# Usage:
# ncdismember &lt;fl_in&gt; &lt;drc_out&gt; [cf_chk] [cf_vrs] [opt]
# where fl_in is input file/URL to dismember, drc_out is output directory
# CF-compliance check is performed when optional third argument is not '0'
# Default checker is Decker's cfchecker installed locally
# Specify cf_chk=nerc for smallified uploads to NERC checker
# Optional fourth argument cf_vrs is CF version to check
# Optional fifth argument opt passes straight-through to ncks
# Arguments must not use shell expansion/globbing
# NB: ncdismember does not clean-up output directory, so user must
# chmod a+x ~/sh/ncdismember
# Examples:
# ncdismember ~/nco/data/mdl_1.nc /data/zender/tmp
# ncdismember http://dust.ess.uci.edu/nco/mdl_1.nc /tmp
# ncdismember http://thredds-test.ucar.edu/thredds/dodsC/testdods/foo.nc /tmp
# ncdismember ~/nco/data/mdl_1.nc /data/zender/nco/tmp cf
# ncdismember ~/nco/data/mdl_1.nc /data/zender/nco/tmp nerc
# ncdismember ~/nco/data/mdl_1.nc /data/zender/nco/tmp cf 1.3
# ncdismember ~/nco/data/mdl_1.nc /data/zender/nco/tmp cf 1.5 --fix_rec_dmn=all

# Command-line argument defaults
fl_in=&quot;${HOME}/nco/data/mdl_1.nc&quot; # [sng] Input file to dismember/check
drc_out=&quot;${DATA}/nco/tmp&quot; # [sng] Output directory
cf_chk='0' # [flg] Perform CF-compliance check? Which checker?
cf_vrs='1.5' # [sng] Compliance-check this CF version (e.g., '1.5')
opt='' # [flg] Additional ncks options (e.g., '--fix_rec_dmn=all')
# Use single quotes to pass multiple arguments to opt=${5}
# Otherwise arguments would be seen as ${5}, ${6}, ${7} ...

# Command-line argument option parsing
if [ -n &quot;${1}&quot; ]; then fl_in=${1}; fi
if [ -n &quot;${2}&quot; ]; then drc_out=${2}; fi
if [ -n &quot;${3}&quot; ]; then cf_chk=${3}; fi
if [ -n &quot;${4}&quot; ]; then cf_vrs=${4}; fi
if [ -n &quot;${5}&quot; ]; then opt=${5}; fi

# Prepare output directory
echo &quot;NCO dismembering file ${fl_in}&quot;
fl_stb=$(basename ${fl_in})
drc_out=${drc_out}/${fl_stb}
mkdir -p ${drc_out}
cd ${drc_out}
chk_dck='n'
chk_nrc='n'
if [ ${cf_chk} = 'nerc' ]; then
    chk_nrc='y'
fi # chk_nrc
if [ ${cf_chk} != '0' ] &amp;&amp; [ ${cf_chk} != 'nerc' ]; then
    chk_dck='y'
    hash cfchecker 2&gt;/dev/null || { echo &gt;&amp;2 &quot;Local cfchecker command not found, will smallify and upload to NERC checker instead&quot;; chk_nrc='y'; chk_dck='n'; }
fi # !cf_chk
# Obtain group list
grp_lst=`ncks -m ${fl_in} | grep '// group' | awk '{$1=$2=$3=&quot;&quot;;sub(/^  */,&quot;&quot;,$0);print}'`
IFS=$'\n' # Change Internal-Field-Separator from &lt;Space&gt;&lt;Tab&gt;&lt;Newline&gt; to &lt;Newline&gt;
for grp_in in ${grp_lst} ; do
    # Replace slashes by dots for output group filenames
    grp_out=`echo ${grp_in} | sed 's/\///' | sed 's/\//./g'`
    if [ &quot;${grp_out}&quot; = '' ]; then grp_out='root' ; fi
    # Tell older NCO/netCDF if HDF4 with --hdf4 switch (signified by .hdf/.HDF suffix)
    hdf4=`echo ${fl_in} | awk '{if(match(tolower($1),&quot;.hdf$&quot;)) hdf4=&quot;--hdf4&quot;; print hdf4}'`
    # Flatten to netCDF3, anchor, no history, no temporary file, padding, HDF4 flag, options
    cmd=&quot;ncks -O -3 -G : -g ${grp_in}/ -h --no_tmp_fl --hdr_pad=40 ${hdf4} ${opt} ${fl_in} ${drc_out}/${grp_out}.nc&quot;
    # Use eval in case ${opt} contains multiple arguments separated by whitespace
    eval ${cmd}
    if [ ${chk_dck} = 'y' ]; then
       # Decker checker needs Conventions &lt;= 1.6
       no_bck_sls=`echo ${drc_out}/${grp_out} | sed 's/\\\ / /g'`
       ncatted -h -a Conventions,global,o,c,CF-${cf_vrs} ${no_bck_sls}.nc
    else # !chk_dck
       echo ${drc_out}/${grp_out}.nc
    fi # !chk_dck
done
if [ ${chk_dck} = 'y' ]; then
    echo 'Decker CFchecker reports CF-compliance of each group in flat netCDF3 format'
    cfchecker -c ${cf_vrs} *.nc
fi
if [ ${chk_nrc} = 'y' ]; then
    # Smallification and NERC upload from qdcf script by Phil Rasch (PJR)
    echo 'Using remote CFchecker http://puma.nerc.ac.uk/cgi-bin/cf-checker.pl'
    cf_lcn='http://puma.nerc.ac.uk/cgi-bin/cf-checker.pl'
    for fl in ${drc_out}/*.nc ; do
	fl_sml=${fl}
	cf_out=${fl%.nc}.html
	dmns=`ncdump -h ${fl_in} | sed -n -e '/dimensions/,/variables/p' | grep = | sed -e 's/=.*//'`
	hyp_sml=''
	for dmn in ${dmns}; do
	    dmn_lc=`echo ${dmn} | tr &quot;[:upper:]&quot; &quot;[:lower:]&quot;`
	    if [ ${dmn_lc} = 'lat' ] || [ ${dmn_lc} = 'latitude' ] || [ ${dmn_lc} = 'lon' ] || [ ${dmn_lc} = 'longitude' ] || [ ${dmn_lc} = 'time' ]; then
		hyp_sml=`echo ${hyp_sml}&quot; -d ${dmn},0&quot;`
	    fi # !dmn_lc
	done
	# Create small version of input file by sampling only first element of lat, lon, time
	ncks -O ${hyp_sml} ${fl} ${fl_sml}
	# Send small file to NERC checker
	curl --form cfversion=1.6 --form upload=@${fl_sml} --form press=&quot;Check%20file&quot; ${cf_lcn} -o ${cf_out}
	# Strip most HTML to improve readability
	cat ${cf_out} | sed -e &quot;s/&lt;[^&gt;]*&gt;//g&quot; -e &quot;/DOCTYPE/,/\]\]/d&quot; -e &quot;s/CF-Convention//g&quot; -e &quot;s/Output of//g&quot; -e &quot;s/Compliance Checker//g&quot; -e &quot;s/Check another//g&quot; -e &quot;s/CF-Checker follows//g&quot; -e &quot;s/Received//g&quot; -e &quot;s/for NetCDF//g&quot; -e &quot;s/NetCDF format//g&quot; -e &quot;s/against CF version 1//g&quot; -e &quot;s/\.\.\.//g&quot;
	echo &quot;Full NERC compliance-check log for ${fl} in ${cf_out}&quot;
    done
fi # !nerc
EOF
chmod 755 ~/ncdismember # Make command executable
/bin/mv -f ~/ncdismember ~/sh # Store in location on $PATH, e.g., /usr/local/bin

zender@roulee:~$ ncdismember ~/nco/data/mdl_1.nc ${DATA}/nco/tmp
NCO dismembering file /home/zender/nco/data/mdl_1.nc
/data/zender/nco/tmp/mdl_1.nc/cesm.cesm_01.nc
/data/zender/nco/tmp/mdl_1.nc/cesm.cesm_02.nc
/data/zender/nco/tmp/mdl_1.nc/cesm.nc
/data/zender/nco/tmp/mdl_1.nc/ecmwf.ecmwf_01.nc
/data/zender/nco/tmp/mdl_1.nc/ecmwf.ecmwf_02.nc
/data/zender/nco/tmp/mdl_1.nc/ecmwf.nc
/data/zender/nco/tmp/mdl_1.nc/root.nc
</verbatim>
</example>
<para>A (potentially more portable) binary executable could be written to
dismember all groups with a single invocation, yet dismembering without
loss of information is possible now with this simple script on all 
platforms with <acronym><acronymword>UNIX</acronymword></acronym>y utilities.
Note that all dimensions inherited by groups in the input file are
correctly placed by <command>ncdismember</command> into the flat files.
Moreover, each output file preserves the group metadata of all ancestor
groups, including the global metadata from the input file.
As written, the script could fail on groups that contain advanced
netCDF4 features because the user requests (with the <samp>-3</samp> switch)
that output be netCDF3 classic format.  
However, <command>ncks</command> detects many format incompatibilities in advance
and works around them.
For example, <command>ncks</command> autoconverts netCDF4-only atomic-types (such
as <code>NC_STRING</code> and <code>NC_UBYTE</code>) to corresponding netCDF3
atomic types (<code>NC_CHAR</code> and <code>NC_SHORT</code>) when the output format
is netCDF3. 
</para>
<html endspaces=" ">
&lt;a name=&quot;cf-compliance&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cf-compliance --&gt;
&lt;a name=&quot;nccf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nccf --&gt;
</html>
</subsection>
<node name="Checking-CF_002dcompliance" spaces=" "><nodename>Checking CF-compliance</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Dismembering Files</nodeprev><nodeup spaces=" ">Group Path Editing</nodeup></node>
<subsection spaces=" "><sectiontitle>Checking CF-compliance</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="610"><acronym><acronymword>CF</acronymword></acronym> compliance checker</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="6" mergedindex="cp">cfchecker</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="7" mergedindex="cp">ncdismember</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="611">compliance checker</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="612">Martin Schultz</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="613">Michael Decker</indexterm></cindex>
<para>One application of dismembering is to check the <acronym><acronymword>CF</acronymword></acronym>-compliance of each 
group in a file. 
When invoked with the optional third argumnt <samp>cf</samp>,
<command>ncdismember</command> passes each file it generates to freely available 
compliance checkers, such as <command>cfchecker</command>
<footnote><para>CFchecker is developed by Michael Decker and Martin Schultz at
Forschungszentrum J<accent type="uml" bracketed="off">u</accent>lich and distributed at
<uref><urefurl>https://bitbucket.org/mde_/cfchecker</urefurl></uref>.</para></footnote>.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@roulee:~$ ncdismember ~/nco/data/mdl_1.nc /data/zender/nco/tmp cf
NCO dismembering file /home/zender/nco/data/mdl_1.nc
CFchecker reports CF-compliance of each group in flat netCDF3 format
WARNING: Using the default (non-CF) Udunits database
cesm.cesm_01.nc: 
INFO: INIT:     running CFchecker version 1.5.15
INFO: INIT:     checking compliance with convention CF-1.5
INFO: INIT:     using standard name table version: 25, last modified: 2013-07-05T05:40:30Z
INFO: INIT:     using area type table version: 2, date: 10 July 2013
INFO: 2.4:      no axis information found in dimension variables, not checking dimension order
WARNING: 3:     variable &quot;tas1&quot; contains neither long_name nor standard_name attribute
WARNING: 3:     variable &quot;tas2&quot; contains neither long_name nor standard_name attribute
INFO: 3.1:      variable &quot;tas1&quot; does not contain units attribute
INFO: 3.1:      variable &quot;tas2&quot; does not contain units attribute
--------------------------------------------------
cesm.cesm_02.nc: 
...
</verbatim>
</example>
<para>By default the <acronym><acronymword>CF</acronymword></acronym> version checked is determined automatically by
<command>cfchecker</command>. 
The user can override this default by supplying a supported <acronym><acronymword>CF</acronymword></acronym>
version, e.g., <samp>1.3</samp>, as an optional fourth argument to
<command>ncdismember</command>. 
Current valid <acronym><acronymword>CF</acronymword></acronym> options are <samp>1.0</samp>, <samp>1.1</samp>,
<samp>1.2</samp>, <samp>1.3</samp>, <samp>1.4</samp>, and <samp>1.5</samp>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;diwg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#diwg --&gt;
</html>
<para>Our development and testing of <command>ncdismember</command> is funded by our
involvement in <acronym><acronymword>NASA</acronymword></acronym>&textrsquo;s Dataset Interoperability Working Group 
(<uref><urefurl>https://wiki.earthdata.nasa.gov/display/ESDSWG/Dataset+Interoperability+Working+Group</urefurl><urefdesc spaces="\n">DIWG</urefdesc></uref>), though our interest extends beyond <acronym><acronymword>NASA</acronymword></acronym> datasets.
Taken together, <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s features (autoconversion to netCDF3  
atomic types, fixing multiple record dimensions, autosensing
<acronym><acronymword>HDF4</acronymword></acronym> input, scoping rules for CF conventions) make 
<command>ncdismember</command> reliable and friendly for both dismembering 
hierarchical files and for <acronym><acronymword>CF</acronymword></acronym>-compliance checks. 
Most <acronym><acronymword>HDF4</acronymword></acronym> and <acronym><acronymword>HDF5</acronymword></acronym> datasets can be checked for 
<acronym><acronymword>CF</acronymword></acronym>-compliance with a one-line command. 
Example compliance checks of common <acronym><acronymword>NASA</acronymword></acronym> datasets are at
<uref><urefurl>http://dust.ess.uci.edu/diwg</urefurl></uref>.
Our long-term goal is to enrich the hierarchical data model with the 
expressivity and syntactic power of <acronym><acronymword>CF</acronymword></acronym> conventions.
</para>
<html endspaces=" ">
&lt;a name=&quot;daac&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#daac --&gt;
</html>
<para><acronym><acronymword>NASA</acronymword></acronym> asked the <acronym><acronymword>DIWG</acronymword></acronym> to prepare a one-page summary
of the procedure necessary to check <acronym><acronymword>HDF</acronymword></acronym> files for
<acronym><acronymword>CF</acronymword></acronym>-compliance: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
cat &gt; ~/ncdismember.txt &lt;&lt; 'EOF'
    Preparing an RPM-based OS to Test HDF &amp; netCDF Files for CF-Compliance

By Charlie Zender, UCI &amp; NASA Dataset Interoperability Working Group (DIWG)

Installation Summary:
1. HDF4 [with internal netCDF support _disabled_]
2. HDF5
3. netCDF [with external HDF4 support _enabled_]
4. NCO
5. numpy
6. netcdf4-python
7. python-lxml
8. CFunits-python
9. CFChecker
10. ncdismember

All 10 packages can use default installs _except_ HDF4 and netCDF.
Following instructions for Fedora Core 20 (FC20), an RPM-based Linux OS
Feedback and changes for other Linux-based OS's welcome to zender at uci.edu
${H4DIR}, ${H5DIR}, ${NETCDFDIR}, ${NCODIR}, may all be different
For simplicity CZ sets them all to /usr/local

# 1. HDF4. Build in non-default manner. Turn-off its own netCDF support.
# Per http://www.unidata.ucar.edu/software/netcdf/docs/build_hdf4.html
# HDF4 support not necessary though it makes ncdismember more comprehensive
wget -c http://www.hdfgroup.org/ftp/HDF/HDF_Current/src/hdf-4.2.9.tar.gz
tar xvzf hdf-4.2.9.tar.gz
cd hdf-4.2.9
./configure --enable-shared --disable-netcdf --disable-fortran --prefix=${H4DIR}
make &amp;&amp; make check &amp;&amp; make install

# 2. HDF5. Build normally. RPM may work too. Please let me know if so.
# HDF5 is a necessary pre-requisite for netCDF4
wget -c ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/hdf5-1.8.11.tar.gz
tar xvzf hdf5-1.8.11.tar.gz
cd hdf5-1.8.11
./configure --enable-shared --prefix=${H5DIR}
make &amp;&amp; make check &amp;&amp; make install

# 3. netCDF version 4.3.1 or later. Build in non-default manner with HDF4.
# Per http://www.unidata.ucar.edu/software/netcdf/docs/build_hdf4.html
# Earlier versions of netCDF may fail checking some HDF4 files
wget -c ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.3.2.tar.gz
tar xvzf netcdf-4.3.2.tar.gz
cd netcdf-4.3.2
CPPFLAGS=&quot;-I${H5DIR}/include -I${H4DIR}/include&quot; \
LDFLAGS=&quot;-L${H5DIR}/lib -L${H4DIR}/lib&quot; \
./configure --enable-hdf4 --enable-hdf4-file-tests
make &amp;&amp; make check &amp;&amp; make install

# 4. NCO version 4.4.0 or later. Some RPMs available. Or install by hand.
# Later versions of NCO have much better support for ncdismember
wget http://nco.sourceforge.net/src/nco-4.4.4.tar.gz .
tar xvzf nco-4.4.4.tar.gz
cd nco-4.4.4
./configure --prefix=${NCODIR}
make &amp;&amp; make install

# 5. numpy
sudo yum install numpy -y

# 6. netcdf4-python
sudo yum install netcdf4-python -y

# 7. python-lxml
sudo yum install python-lxml -y

# 8. CFunits-python. No RPM available. Must install by hand.
# http://code.google.com/p/cfunits-python/
wget http://cfunits-python.googlecode.com/files/cfunits-0.9.6.tar.gz .
tar xvzf cfunits-0.9.6.tar.gz
cd cfunits-0.9.6
sudo python setup.py install

# 9. CFChecker. No RPM available. Must install by hand.
# https://bitbucket.org/mde_/cfchecker
wget https://bitbucket.org/mde_/cfchecker/downloads/CFchecker-1.5.15.tar.bz2 . 
tar xvjf CFchecker-1.5.15.tar.bz2 
cd CFchecker
sudo python setup.py install

# 10. ncdismember. Copy script from http://nco.sf.net/nco.html#ncdismember
# Store dismembered files somewhere, e.g., ${DATA}/nco/tmp/hdf
mkdir -p ${DATA}/nco/tmp/hdf
# Many datasets work with a simpler command...
ncdismember ~/nco/data/in.nc ${DATA}/nco/tmp/hdf cf 1.5
ncdismember ~/nco/data/mdl_1.nc ${DATA}/nco/tmp/hdf cf 1.5
ncdismember ${DATA}/hdf/AMSR_E_L2_Rain_V10_200905312326_A.hdf \
            ${DATA}/nco/tmp/hdf cf 1.5
ncdismember ${DATA}/hdf/BUV-Nimbus04_L3zm_v01-00-2012m0203t144121.h5 \
            ${DATA}/nco/tmp/hdf cf 1.5
ncdismember ${DATA}/hdf/HIRDLS-Aura_L3ZAD_v06-00-00-c02_2005d022-2008d077.he5 ${DATA}/nco/tmp/hdf cf 1.5
# Some datasets, typically .h5, require the --fix_rec_dmn=all argument
ncdismember_${DATA}/hdf/GATMO_npp_d20100906_t1935191_e1935505_b00012_c20110707155932065809_noaa_ops.h5 ${DATA}/nco/tmp/hdf cf 1.5 --fix_rec_dmn=all
ncdismember ${DATA}/hdf/mabel_l2_20130927t201800_008_1.h5 \
            ${DATA}/nco/tmp/hdf cf 1.5 --fix_rec_dmn=all
EOF
</verbatim>
</example>
<!-- c scp ~/ncdismember.pdf dust.ess.uci.edu:/var/www/html/diwg -->
<para>A <acronym><acronymword>PDF</acronymword></acronym> version of these instructions is available
<uref><urefurl>http://dust.ess.uci.edu/diwg/ncdismember.pdf</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
</para>
<html endspaces=" ">
&lt;a name=&quot;fortran&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fortran --&gt;
&lt;a name=&quot;ftn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ftn --&gt;
&lt;a name=&quot;-F&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-F --&gt;
</html>
</subsection>
</section>
<node name="C-and-Fortran-Index-Conventions" spaces=" "><nodename>C and Fortran Index Conventions</nodename><nodenext spaces=" ">Hyperslabs</nodenext><nodeprev spaces=" ">Group Path Editing</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>C and Fortran Index conventions</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="614">index convention</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="615">Fortran index convention</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="616">C index convention</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="617"><code>-F</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="618"><code>--fortran</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>nces</command>, <command>ncecat</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: <samp>-F</samp>&linebreak;
Long options: <samp>--fortran</samp>&linebreak;
</para></cartouche>
<cindex index="cp" spaces=" "><indexterm index="cp" number="619">I/O</indexterm></cindex>
<para>The <samp>-F</samp> switch changes <acronym><acronymword>NCO</acronymword></acronym> to read and write with
the Fortran index convention. 
By default, <acronym><acronymword>NCO</acronymword></acronym> uses C-style (0-based) indices for all I/O. 
<w>In C</w>, indices count <w>from 0</w> (rather <w>than 1</w>), and
dimensions are ordered from slowest (inner-most) to fastest
(outer-most) varying.
In Fortran, indices count <w>from 1</w> (rather <w>than 0</w>), and
dimensions are ordered from fastest (inner-most) to slowest 
(outer-most) varying.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="620">transpose</indexterm></cindex>
Hence <w>C and</w> Fortran data storage conventions represent mathematical
transposes of eachother.
<cindex index="cp" spaces=" "><indexterm index="cp" number="621">record variable</indexterm></cindex>
Note that record variables contain the record dimension as the most
slowly varying dimension.  
See <ref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></ref> for techniques
to re-order (including transpose) dimensions and to reverse data
storage order.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="622">record dimension</indexterm></cindex>
<para>Consider a file <file>85.nc</file> containing <w>12 months</w> of data in the
record dimension <code>time</code>.
The following hyperslab operations produce identical results, a
June-July-August average of the data:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -d time,5,7 85.nc 85_JJA.nc
ncra -F -d time,6,8 85.nc 85_JJA.nc
</pre></example>

<para>Printing variable <var>three_dmn_var</var> in file <file>in.nc</file> first with
the <w>C indexing</w> convention, then with Fortran indexing convention
results in the following output formats: 
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks --trd -v three_dmn_var in.nc
lat[0]=-90 lev[0]=1000 lon[0]=-180 three_dmn_var[0]=0 
...
% ncks --trd -F -v three_dmn_var in.nc
lon(1)=0 lev(1)=100 lat(1)=-90 three_dmn_var(1)=0 
...
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;-d&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-d --&gt;
&lt;a name=&quot;-0&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-0 --&gt;
&lt;a name=&quot;dmn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dmn --&gt;
&lt;a name=&quot;hyp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hyp --&gt;
&lt;a name=&quot;hyperslab&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hyperslab --&gt;
</html>
</section>
<node name="Hyperslabs" spaces=" "><nodename>Hyperslabs</nodename><nodenext spaces=" ">Stride</nodenext><nodeprev spaces=" ">C and Fortran Index Conventions</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Hyperslabs </sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="623">hyperslab</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="624">dimension limits</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="625">coordinate limits</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="626"><code>-0</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="627"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="628"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="629"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>nces</command>, <command>ncecat</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: <samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
Long options: 
<samp>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>,&linebreak; 
<samp>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
</para></cartouche>
<para><w>A <dfn>hyperslab</dfn></w> is a subset of a variable&textrsquo;s data.
The coordinates of a hyperslab are specified with the 
<code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code> short
option (or with the same arguments to the <samp>--dimension</samp> or
<samp>--dmn</samp> long options).   
At least one hyperslab argument (<var>min</var>, <var>max</var>, or <var>stride</var>)
must be present. 
The bounds of the hyperslab to be extracted are specified by the
associated <var>min</var> and <var>max</var> values. 
<w>A half</w>-open range is specified by omitting either the <var>min</var> or
<var>max</var> parameter.
The separating comma must be present to indicate the omission of one of
these arguments.
The unspecified limit is interpreted as the maximum or minimum value in 
the unspecified direction.  
<w>A cross</w>-section at a specific coordinate is extracted by specifying only
the <var>min</var> limit and omitting a trailing comma. 
Dimensions not mentioned are passed with no reduction in range.
The dimensionality of variables is not reduced (in the case of a
cross-section, the size of the constant dimension will be one). 
</para><example endspaces=" ">
<pre xml:space="preserve"># First and second longitudes
ncks -F -d lon,1,2 in.nc out.nc
# Second and third longitudes
ncks -d lon,1,2 in.nc out.nc
</pre></example>

<para>As of version 4.2.1 (August, 2012), <acronym><acronymword>NCO</acronymword></acronym> allows one to extract
the last <var>N</var> elements of a hyperslab.
Negative integers as <var>min</var> or <var>max</var> elements of a hyperslab
specification indicate offsets from the end (Python also uses this
convention). 
Consistent with this convention, the value <samp>-1</samp> (negative one)
indicates the last element of a dimension, and negative zero is
algebraically equivalent to zero and so indicates the first element of a
dimension. 
Previously, for example, <samp>-d time,-2,-1</samp> caused a domain error. 
Now it means select the penultimate and last timesteps, independent of
the size of the <code>time</code> dimension.
Select only the first and last timesteps, respectively, with 
<samp>-d time,0</samp> and <samp>-d time,-1</samp>.
Negative integers work for <var>min</var> and <var>max</var> indices, though not
for <var>stride</var>. 
</para><example endspaces=" ">
<pre xml:space="preserve"># Second through penultimate longitudes
ncks -d lon,1,-2 in.nc out.nc
# Second through last longitude
ncks -d lon,1,-1 in.nc out.nc
# Second-to-last to last longitude
ncks -d lon,-3,-1 in.nc out.nc
# Second-to-last to last longitude 
ncks -d lon,-3, in.nc out.nc
</pre></example>
<noindent></noindent>
<para>The <samp>-F</samp> argument, if any, applies the Fortran index convention
only to indices specified as positive integers:
</para><example endspaces=" ">
<pre xml:space="preserve"># First through penultimate longitudes
ncks -F -d lon,1,-2 in.nc out.nc (-F affects only start index)
# First through last longitude
ncks -F -d lon,1,-1 in.nc out.nc
# Second-to-last to penultimate longitude (-F has no effect)
ncks -F -d lon,-3,-1 in.nc out.nc
# Second-to-last to last longitude (-F has no effect)
ncks -F -d lon,-3, in.nc out.nc
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="630">stride</indexterm></cindex>
<para>Coordinate values should be specified using real notation with a decimal 
point required in the value, whereas dimension indices are specified
using integer notation without a decimal point. 
This convention serves only to differentiate coordinate values from
dimension indices.
It is independent of the type of any netCDF coordinate variables.
In other words, even if coordinates are defined as integers, specify
them with decimal points to have the command interpret them as values,
rather than indices.
For a given dimension, the specified limits must both be coordinate
values (with decimal points) or dimension indices (no decimal points).
</para>
<para>If values of a coordinate-variable are used to specify a range or
cross-section, then the coordinate variable must be monotonic (values
either increasing or decreasing). 
In this case, command-line values need not exactly match coordinate
values for the specified dimension. 
Ranges are determined by seeking the first coordinate value to occur in
the closed range [<var>min</var>,<var>max</var>] and including all subsequent
values until one falls outside the range. 
The coordinate value for a cross-section is the coordinate-variable
value closest to the specified value and must lie within the range or
coordinate-variable values. 
The <var>stride</var> argument, if any, must be a dimension index, not a
coordinate value.
<xref label="Stride"><xrefnodename>Stride</xrefnodename></xref>, for more information on the <var>stride</var> option.
</para><example endspaces=" ">
<pre xml:space="preserve"># All longitude values between 1 and 2 degrees
ncks -d lon,1.0,2.0 in.nc out.nc
# All longitude values between 1 and 2 degrees
ncks -F -d lon,1.0,2.0 in.nc out.nc
# Every other longitude value between 0 and 90 degrees
ncks -F -d lon,0.0,90.0,2 in.nc out.nc
</pre></example>
<para>As shown, we recommend using a full floating-point suffix of <code>.0</code>
instead of simply <code>.</code> in order to make obvious the selection of
hyperslab elements based on coordinate value rather than index.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="631"><code>NC_CHAR</code></indexterm></cindex>
<para>User-specified coordinate limits are promoted to double-precision values 
while searching for the indices which bracket the range. 
Thus, hyperslabs on coordinates of type <code>NC_CHAR</code> are computed
numerically rather than lexically, so the results are unpredictable. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="632">wrapped coordinates</indexterm></cindex>
<para>The relative magnitude of <var>min</var> and <var>max</var> indicate to the
operator whether to expect a <dfn>wrapped coordinate</dfn>
(<pxref label="Wrapped-Coordinates"><xrefnodename>Wrapped Coordinates</xrefnodename></pxref>), such as longitude.
If <math><var>min</var> &gt; <var>max</var></math>, the <acronym><acronymword>NCO</acronymword></acronym> expects the
coordinate to be wrapped, and a warning message will be printed.
When this occurs, <acronym><acronymword>NCO</acronymword></acronym> selects all values outside the domain
[<math><var>max</var> &lt; <var>min</var></math>], i.e., all the values exclusive of the
values which would have been selected if <var>min</var> and <var>max</var> were
swapped. 
If this seems confusing, test your command on just the coordinate
variables with <command>ncks</command>, and then examine the output to ensure
<acronym><acronymword>NCO</acronymword></acronym> selected the hyperslab you expected (coordinate wrapping
is currently only supported by <command>ncks</command>). 
</para>
<para>Because of the way wrapped coordinates are interpreted, it is very
important to make sure you always specify hyperslabs in the
monotonically increasing sense, i.e., <math><var>min</var> &lt; <var>max</var></math>
(even if the underlying coordinate variable is monotonically
decreasing). 
The only exception to this is when you are indeed specifying a wrapped
coordinate.  
The distinction is crucial to understand because the points selected by, 
e.g., <code>-d longitude,50.,340.</code>, are exactly the complement of the
points selected by <code>-d longitude,340.,50.</code>.
</para>
<para>Not specifying any hyperslab option is equivalent to specifying full
ranges of all dimensions. 
This option may be specified more than once in a single command 
(each hyperslabbed dimension requires its own <code>-d</code> option).
</para>
<html endspaces=" ">
&lt;a name=&quot;srd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#srd --&gt;
&lt;a name=&quot;stride&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#stride --&gt;
</html>
</section>
<node name="Stride" spaces=" "><nodename>Stride</nodename><nodenext spaces=" ">Record Appending</nodenext><nodeprev spaces=" ">Hyperslabs</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Stride </sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="633">stride</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="634"><code>-d <var>dim</var>,[<var>min</var>],[<var>max</var>],<var>stride</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="635"><code>--dimension <var>dim</var>,[<var>min</var>],[<var>max</var>],<var>stride</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="636"><code>--dmn <var>dim</var>,[<var>min</var>],[<var>max</var>],<var>stride</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>nces</command>, <command>ncecat</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: <samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
Long options: 
<samp>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>,&linebreak; 
<samp>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
</para></cartouche>
<para>All data operators support specifying a <dfn>stride</dfn> for any and all
dimensions at the same time.
The <var>stride</var> is the spacing between consecutive points in a
hyperslab. 
<w>A <var>stride</var></w> <w>of 1</w> picks all the elements of the hyperslab, and
a <var>stride</var> <w>of 2</w> skips every other element, etc.&eosperiod;
<command>ncks</command> multislabs support strides, and are more powerful than
the regular hyperslabs supported by the other operators
(<pxref label="Multislabs"><xrefnodename>Multislabs</xrefnodename></pxref>).
Using the <var>stride</var> option for the record dimension with
<command>ncra</command> and <command>ncrcat</command> makes it possible, for instance, to
average or concatenate regular intervals across multi-file input data sets.
</para>
<para>The <var>stride</var> is specified as the optional fourth argument to the
<samp>-d</samp> hyperslab specification:  
<code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code>.
Specify <var>stride</var> as an integer (i.e., no decimal point) following
the third comma in the <samp>-d</samp> argument.  
There is no default value for <var>stride</var>. 
Thus using <samp>-d time,,,2</samp> is valid but <samp>-d time,,,2.0</samp> and
<samp>-d time,,,</samp> are not.
When <var>stride</var> is specified but <var>min</var> is not, there is an
ambiguity as to whether the extracted hyperslab should begin with (using
C-style, 0-based indexes) <w>element 0</w> or element <samp>stride-1</samp>.
<acronym><acronymword>NCO</acronymword></acronym> must resolve this ambiguity and it chooses <w>element 0</w>
as the first element of the hyperslab when <var>min</var> is not specified.
Thus <samp>-d time,,,<var>stride</var></samp> is syntactically equivalent to
<samp>-d time,0,,<var>stride</var></samp>.
This means, for example, that specifying the operation 
<samp>-d time,,,2</samp> on the array <samp>1,2,3,4,5</samp> selects the hyperslab
<samp>1,3,5</samp>. 
To obtain the hyperslab <samp>2,4</samp> instead, simply explicitly specify
the starting index <w>as 1,</w> i.e., <samp>-d time,1,,2</samp>. 
</para>
<para>For example, consider a file <file>8501_8912.nc</file> which contains 60
consecutive months of data. 
Say you wish to obtain just the March data from this file.
Using 0-based subscripts (<pxref label="C-and-Fortran-Index-Conventions"><xrefnodename>C and Fortran Index Conventions</xrefnodename></pxref>) these 
data are stored in records <w>2, 14, &dots; 50</w> so the desired
<var>stride</var> <w>is 12.</w>
Without the <var>stride</var> option, the procedure is very awkward.
One could use <command>ncks</command> five times and then use <command>ncrcat</command> to  
concatenate the resulting files together:
<cindex index="cp" spaces=" "><indexterm index="cp" number="637">Bourne Shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="638">C Shell</indexterm></cindex>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for idx in 02 14 26 38 50; do # Bourne Shell
  ncks -d time,${idx} 8501_8912.nc foo.${idx}
done
foreach idx (02 14 26 38 50) # C Shell
  ncks -d time,${idx} 8501_8912.nc foo.${idx}
end
ncrcat foo.?? 8589_03.nc
rm foo.??
</verbatim>
</example>
<para>With the <var>stride</var> option, <command>ncks</command> performs this hyperslab
extraction in one operation:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -d time,2,,12 8501_8912.nc 8589_03.nc
</pre></example>
<para><xref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref>, for more information on <command>ncks</command>.
</para>
<para>Applying the <var>stride</var> option to the record dimension in
<command>ncra</command> and <command>ncrcat</command> makes it possible, for instance, to
average or concatenate regular intervals across multi-file input data
sets. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -F -d time,3,,12 85.nc 86.nc 87.nc 88.nc 89.nc 8589_03.nc
ncrcat -F -d time,3,,12 85.nc 86.nc 87.nc 88.nc 89.nc 8503_8903.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;rec_apn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rec_apn --&gt;
&lt;a name=&quot;record_append&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#record_append --&gt;
</html>
</section>
<node name="Record-Appending" spaces=" "><nodename>Record Appending</nodename><nodenext spaces=" ">Subcycle</nodenext><nodeprev spaces=" ">Stride</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Record Appending</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="639">record append</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="640"><code>--rec_apn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="641"><code>--record_append</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncra</command>, <command>ncrcat</command>&linebreak; 
Short options: None&linebreak;
Long options: 
<samp>--rec_apn</samp>, <samp>--record_append</samp>&linebreak;
</para></cartouche>
<para>As of version 4.2.6 (March, 2013), <acronym><acronymword>NCO</acronymword></acronym> allows both
Multi-File, Multi-Record operators (<command>ncra</command> and <command>ncrcat</command>)
to append their output directly to the end of an existing file.
This feature may be used to augment a target file, rather than construct
it from scratch. 
This helps, for example, when a timeseries is concatenated from input
data that becomes available in stages rather than all at once.
In such cases this switch significantly speeds writing.
</para>
<para>Consider the use case where one wishes to preserve the contents of
<file>fl_1.nc</file>, and add to them new records contained in
<file>fl_2.nc</file>. 
Previously the output had to be placed in a third file, <file>fl_3.nc</file>
(which could also safely be named <file>fl_2.nc</file>), via
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat -O fl_1.nc fl_2.nc fl_3.nc
</pre></example>
<para>Under the hood this operation copies all information in
<file>fl_1.nc</file> and <file>fl_2.nc</file> not once but twice.
The first copy is performed through the netCDF interface, as all
data from <file>fl_1.nc</file> and <file>fl_2.nc</file> are extracted and placed in
the output file.
The second copy occurs (usually much) more quickly as the (by default)
temporary output file is copied (sometimes a quick re-link suffices) to
the final output file (<pxref label="Temporary-Output-Files"><xrefnodename>Temporary Output Files</xrefnodename></pxref>).
All this copying is expensive for large files. 
</para>
<para>The <samp>--record_append</samp> switch appends all records in <file>fl_2.nc</file> 
to the end (after the last record) of <file>fl_1.nc</file>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat --rec_apn fl_2.nc fl_1.nc
</pre></example>
<para>The ordering of the filename arguments may seem non-intuitive.
If the record variable represents time in these files, then the
values in <file>fl_1.nc</file> precede those in <file>fl_2.nc</file>, so why
do the files appear in the reverse order on the command line?
<file>fl_1.nc</file> is the last file named because it is the pre-existing
output file to which we will append all the other input files listed
(in this case only <file>fl_2.nc</file>).
The contents of <file>fl_1.nc</file> are completely preserved, and only
values in <file>fl_2.nc</file> (and any other input files) are copied. 
This switch avoids the necessity of copying all of <file>fl_1.nc</file> 
through the netCDF interface to a new output file.
The <samp>--rec_apn</samp> switch automatically puts <acronym><acronymword>NCO</acronymword></acronym> into 
append mode (<pxref label="Appending-Variables"><xrefnodename>Appending Variables</xrefnodename></pxref>), so specifying <samp>-A</samp> is
redundant, and simultaneously specifying overwrite mode with <samp>-O</samp>
causes an error.  
By default, NCO works in an intermediate temporary file.
Power users may combine <samp>--rec_apn</samp> with the <samp>--no_tmp_fl</samp>
switch (<pxref label="Temporary-Output-Files"><xrefnodename>Temporary Output Files</xrefnodename></pxref>):
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat --rec_apn --no_tmp_fl fl_2.nc fl_1.nc
</pre></example>
<para>This avoids creating an intermediate file, and copies only the
minimal amount of data (i.e., all of <file>fl_2.nc</file>). 
Hence, it is fast.
We recommend users try to understand the safety trade-offs involved. 
</para>
<para>One side-effect of <samp>--rec_apn</samp> to be aware of is how attributes
are handled.
When appending files, <acronym><acronymword>NCO</acronymword></acronym> typically overwrites attributes
for existing variables in the destination file with the corresponding
attributes from the same variable in the source file.
The exception to this rule is when <samp>--rec_apn</samp> is invoked.
As of version 4.7.9 (January, 2019), <acronym><acronymword>NCO</acronymword></acronym> leaves unchanged
the attributes for existing variables in the destination file.
This is primarily to ensure that calendar attributes (e.g.,
<code>units</code>, <code>calendar</code>) of the record coordinate, if any, are
maintained, so that the data appended to them can be re-based to the
existing units.
Otherwise rebasing would fail or require rewriting the entire file
which is counter to the purpose of <samp>--rec_apn</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;subcycle&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#subcycle --&gt;
&lt;a name=&quot;ssc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ssc --&gt;
&lt;a name=&quot;duration&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#duration --&gt;
&lt;a name=&quot;drn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drn --&gt;
&lt;a name=&quot;mro&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mro --&gt;
</html>
</section>
<node name="Subcycle" spaces=" "><nodename>Subcycle</nodename><nodenext spaces=" ">Interleave</nodenext><nodeprev spaces=" ">Record Appending</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Subcycle</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="642">duration</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="643">sub-cycle</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="644">subcycle</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="645">MRO</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="646">Multi-Record Operator</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="647"><code>--mro</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="648"><code>-d <var>dim</var>,[<var>min</var>],[<var>max</var>],[<var>stride</var>],[<var>subcycle</var>]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="649"><code>--dimension <var>dim</var>,[<var>min</var>],[<var>max</var>],[<var>stride</var>],[<var>subcycle</var>]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="650"><code>--dmn <var>dim</var>,[<var>min</var>],[<var>max</var>],[<var>stride</var>],<var>subcycle</var>]</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncra</command>, <command>ncrcat</command>&linebreak; 
Short options: <samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>]]]]</samp>&linebreak;
Long options: 
<samp>--mro</samp>
<samp>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>]]]]</samp>&linebreak;
<samp>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>]]]]</samp>&linebreak;
</para></cartouche>
<para>As of version 4.2.1 (August, 2012), <acronym><acronymword>NCO</acronymword></acronym> allows both Multi-File,
Multi-Record operators, <command>ncra</command> and <command>ncrcat</command>, to extract
and operate on multiple groups of records. 
These groups may be connected to physical <emph>sub-cycles</emph> of a
periodic nature, e.g., months of a year, or hours of a day. 
Or they may be thought of as groups of a specifed duration.
We call this the <dfn>subcycle feature</dfn>, sometimes abbreviated
<acronym><acronymword>SSC</acronymword></acronym>
<footnote><para>When originally released in 2012 this was called the
<dfn>duration feature</dfn>, and was abbreviated <acronym><acronymword>DRN</acronymword></acronym>.</para></footnote>.
</para>
<para>The subcycle feature allows processing of groups of records separated
by regular intervals of records. 
It is perhaps best illustrated by an extended example that describes 
how to solve the same problem both with and without the <acronym><acronymword>SSC</acronymword></acronym>
feature. 
</para>
<para>Creating seasonal cycles is a common task in climate data processing.
Suppose a 150-year climate simulation produces 150 output files, each
comprising 12 records, each record a monthly mean:
<file>1850.nc</file>, <file>1851.nc</file>, ... <file>1999.nc</file>.
Our goal is to create a single file that contains the climatological
summertime (June, July, and August, aka JJA) mean.
Traditionally, we would first compute the climatological monthly
mean for each month of summer. 
Each of these is a 150-year mean, i.e., 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Step 1: Create climatological monthly files clm06.nc..clm08.nc
for mth in {6..8}; do
  mm=`printf &quot;%02d&quot; $mth`
  ncra -O -F -d time,${mm},,12 -n 150,4,1 1850.nc clm${mm}.nc
done
# Step 2: Average climatological monthly files into summertime mean
ncra -O clm06 clm07.nc clm08.nc clm_JJA.nc
</verbatim>
</example>
<noindent></noindent>
<para>So far, nothing is unusual and this task can be performed by any
<acronym><acronymword>NCO</acronymword></acronym> version. 
The <acronym><acronymword>SSC</acronymword></acronym> feature makes obsolete the need for the shell loop
used in <w>Step 1</w> above. 
</para>
<para>The new <acronym><acronymword>SSC</acronymword></acronym> option aggregates more than one input record at
a time before performing arithmetic operations, and, with an
additional switch, allows archival of those results in
multiple-record output (MRO) files.  
This reduces the task of producing the climatological summertime
mean to <emph>one</emph> step:
</para><example endspaces=" ">
<pre xml:space="preserve"># Step 1: Compute climatological summertime mean
ncra -O -F -d time,6,,12,3 -n 150,4,1 1850.nc clm_JJA.nc
</pre></example>
<noindent></noindent>
<para>The <acronym><acronymword>SSC</acronymword></acronym> option instructs <command>ncra</command> (or <command>ncrcat</command>)
to process files in groups of three records. 
To better understand the meaning of each argument to the <samp>-d</samp>
hyperslab option, read it this way: &textldquo;for the time dimension start with
the sixth record, continue without end, repeat the process every twelfth
record, and define a sub-cycle as three consecutive records&textrdquo;. 
</para>
<para>A separate option, <samp>--mro</samp>, instructs <command>ncra</command> to output 
its results from each sub-group, and to produce a <dfn>Multi-Record Output</dfn>
(<acronym><acronymword>MRO</acronymword></acronym>) file rather than a <dfn>Single-Record Output</dfn>
(<acronym><acronymword>SRO</acronymword></acronym>) file. 
Unless Multi-Record-Output is indicated (either with <samp>--mro</samp> or
implicitly, as with interleave-mode), <command>ncra</command> collects together 
all sub-groups, operates on their ensemble, and produces a single
output record. 
Adding <samp>--mro</samp> to the above example causes <command>ncra</command> to
archive all (150) annual summertime means to one file: 
</para><example endspaces=" ">
<pre xml:space="preserve"># Step 1: Archive all 150 summertime means in one file
ncra --mro -O -F -d time,6,,12,3 -n 150,4,1 1850.nc 1850_2009_JJA.nc
# ...or all (150) annual means...
ncra --mro -O -d time,,,12,12 -n 150,4,1 1850.nc 1850_2009.nc
</pre></example>
<noindent></noindent>
<para>These operations generate and require no intermediate files.
This contrasts to previous <acronym><acronymword>NCO</acronymword></acronym> methods, which require
generating, averaging, then catenating 150 files.  
The <samp>--mro</samp> option only works on <command>ncra</command> and has no effect
on (or rather is redundant for) <command>ncrcat</command>, since
<command>ncrcat</command> always outputs all selected records.
</para>
<html endspaces=" ">
&lt;a name=&quot;interleave&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#interleave --&gt;
&lt;a name=&quot;ilv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ilv --&gt;
</html>
</section>
<node name="Interleave" spaces=" "><nodename>Interleave</nodename><nodenext spaces=" ">Multislabs</nodenext><nodeprev spaces=" ">Subcycle</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Interleave</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="651">interleave</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="652"><code>--mro</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="653"><code>-d <var>dim</var>,[<var>min</var>],[<var>max</var>],[<var>stride</var>],[<var>subcycle</var>],[<var>interleave</var>]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="654"><code>--dimension <var>dim</var>,[<var>min</var>],[<var>max</var>],[<var>stride</var>],[<var>subcycle</var>],[<var>interleave</var>]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="655"><code>--dmn <var>dim</var>,[<var>min</var>],[<var>max</var>],[<var>stride</var>],<var>subcycle</var>],[<var>interleave</var>]</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncra</command>, <command>ncrcat</command>&linebreak; 
Short options: <samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>][,[<var>interleave</var>]]]]]</samp>&linebreak;
Long options: 
<samp>--mro</samp>
<samp>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>][,[<var>interleave</var>]]]]]</samp>&linebreak;
<samp>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>][,[<var>interleave</var>]]]]]</samp>&linebreak;
</para></cartouche>

<html endspaces=" ">
&lt;a name=&quot;bug_ilv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bug_ilv --&gt;
</html>
<cartouche endspaces=" ">
<para>Caveat lector: Unforunately <acronym><acronymword>NCO</acronymword></acronym> versions from 4.9.4&textndash;5.1.8
(September, 2020 through October, 2023) contained a bug that affected
the subcycle and interleave (<acronym><acronymword>SSC</acronymword></acronym> and <acronym><acronymword>ILV</acronymword></acronym>)
hyperslab features.
The bug was triggered by invoking the <acronym><acronymword>SSC</acronymword></acronym> feature without
explicitly providing an <acronym><acronymword>ILV</acronymword></acronym> parameter.
The software failed to initialize an internal flag that indicated
whether <acronym><acronymword>ILV</acronymword></acronym> had been invoked.
The resulting behavior was compiler-dependent.
Most compilers set the flag to false (as it should have been), but
occasionally it was set to true).
The bug expressed itself by extracting only a single timestep,
rather than the number of timesteps indicated by the SSC parameter.
This behavior was fixed in <acronym><acronymword>NCO</acronymword></acronym> version 5.1.9 (November,
2023). 
</para></cartouche>

<para>As of version 4.9.4 (September, 2020), <acronym><acronymword>NCO</acronymword></acronym> allows both Multi-File,
Multi-Record operators (<command>ncra</command> and <command>ncrcat</command>) to
extract, interleave, and operate on multiple groups of records. 
Interleaving (or de-interleaving, depending on one&textrsquo;s perspective)
means altering the order of records in a group to be processed.
Specifically, the interleaving feature (sometimes abbreviated
<acronym><acronymword>ILV</acronymword></acronym>) causes the operator to treat as sequential records
those that are separated by multiples of the specified
<var>interleave</var> parameter within a group or sub-cycle of records.
</para>
<para>The interleave feature sequences records with respect to their
position relative to the beginning of each sub-cycle.
Records an integer multiple of <var>interleave</var> from the sub-cycle
start are first extracted (<command>ncrcat</command>) or reduced
(<command>ncra</command>), then records offset from these by one, two, et
cetera up to <math><var>interleave</var>-1</math>. 
In this manner interleaving extracts an inner (intra-sub-cycle) loop  
that preserves high-frequency signals relative to the longer
stride between sub-cycles.
Thus interleaving allows deconvolution of periodic phenomena within a
time-series.
</para>
<para>Processing simple arithmetic sequences is a helpful way to 
understand what interleaving does. 
Here are some examples to reify the abstract.
Let <file>in1.nc</file> contain the record-array [1..10],
<file>in2.nc</file> contain [11..20], and <file>in12.nc</file> contain [1..20].
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncra   -O -d time,,,,10,5 ~/in1.nc ~/foo.nc # 3.5, 4.5, 5.5, 6.5, 7.5
ncrcat -O -d time,0,4,,6,2 ~/in1.nc ~/foo.nc # 1, 3, 5, 2, 4, 6 (+WARNING)
ncrcat -O -d time,2,,10,4,2 ~/in12.nc ~/foo.nc # 3, 5, 4, 6, 13, 15, 14, 16
ncra   -O -d time,2,,10,4,2 ~/in12.nc ~/foo.nc # 4, 5, 14, 15
ncra   -O -d time,,,,10,2 ~/in1.nc ~/in2.nc ~/foo.nc # 5, 6, 15, 16
ncra   -O -d time,,,,10,2 ~/in12.nc ~/foo.nc # 5, 6, 15, 16
</verbatim>
</example>

<para>Interleaving is perhaps best illustrated by an extended example that
describes how to solve the same problem both with and without the
<acronym><acronymword>ILV</acronymword></acronym> feature. 
Consider as an example an interannual timeseries archived at a
high-enough temporal frequency to resolve the diurnal cycle with
<var>tpd</var> timesteps-per-day.
Many climate models and re-analyses are archived at hourly,
tri-hourly, or six-hourly resolution yielding
<math><var>tpd</var> = 24, 8</math>, or <math>6</math>, respectively.
Our goal is to extract a monthly mean diurnal cycle from this
timeseries.
</para>
<para>Suppose a 150-year climate simulation produces 150 output files, each
comprising 365 days of hourly data, or 8760 records, each record an
hourly mean: 
<file>1850.nc</file>, <file>1851.nc</file>, ... <file>1999.nc</file>.
Our goal is to create a single file that contains the climatological
monthly mean diurnal cycle for, say, March, which contains <w>31 days</w>
or <w>744 hourly</w> records that commence on the 60th day of the 356-day
year, with record index 1416.
Traditionally, we might first compute the climatological monthly
mean for hour of the day, then combine those into a full diurnal cycle:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Step 1: Create climatological hourly files hr00.nc..hr23.nc 
for hr in {0..23}; do
  hh=`printf &quot;%02d&quot; $hr`
  let srt=${hr}+1416
  # Alternatively, use UDUnits by setting srt=1850-03-01T00:00:01 
  ncra -O -d time,${srt},,8760 -n 150,4,1 1850.nc hr${hh}.nc
done
# Step 2: Concatenate climatological hourly files into diurnal cycle
ncrcata -O hr??.nc clm_drn.nc
</verbatim>
</example>
<noindent></noindent>
<para>So far, nothing is unusual and this task can be performed by any
<acronym><acronymword>NCO</acronymword></acronym> version. 
The <acronym><acronymword>ILV</acronymword></acronym> feature obsoletes the need for the shell loop
used in <w>Step 1</w> above. 
</para>
<para>The new <acronym><acronymword>ILV</acronymword></acronym> option aggregates more than one input record at
a time before performing arithmetic operations, and, with an
additional switch, allows archival of those results in
multiple-record output (MRO) files.  
This reduces the task of producing the climatological summertime
mean to <emph>one</emph> step:
</para><example endspaces=" ">
<pre xml:space="preserve"># Step 1: Archive all 150 March-mean diurnal cycles in one file
ncra -O -d time,1850-03-01T00:00:01,,8760,744,24 -n 150,4,1 1850.nc clm_drn.nc
</pre></example>
<noindent></noindent>
<para>The <acronym><acronymword>ILV</acronymword></acronym> option instructs <command>ncra</command> (or <command>ncrcat</command>)
to process files in groups of 31 days (744 hourly records) interleaved
with a 24-record cycle.
The end result will have 150 sets of 24-timesteps representing the
diurnal cycle of March in every year.
A given timestep is the mean of the same hour of the day for every day
in March of that year.
</para>
<html endspaces=" ">
&lt;a name=&quot;multislab&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#multislab --&gt;
&lt;a name=&quot;multislabs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#multislabs --&gt;
&lt;a name=&quot;msa&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msa --&gt;
&lt;a name=&quot;mlt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mlt --&gt;
</html>
</section>
<node name="Multislabs" spaces=" "><nodename>Multislabs</nodename><nodenext spaces=" ">Wrapped Coordinates</nodenext><nodeprev spaces=" ">Interleave</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Multislabs </sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="656">multislab</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="657">multi-hyperslab</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="658"><acronym><acronymword>MSA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="659"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="660"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="661"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="662"><code>--msa</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="663"><code>--msa_usr_rdr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="664"><code>--msa_user_order</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>nces</command>, <command>ncecat</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>&linebreak; 
Short options: <samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
Long options: 
<samp>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>,&linebreak; 
<samp>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
<samp>--msa_usr_rdr</samp>, <samp>--msa_user_order</samp>&linebreak;
</para></cartouche>
<para>A <w>multislab</w> is a union of one or more hyperslabs.
One defines multislabs by chaining together hyperslab commands, i.e., 
<kbd>-d</kbd> options (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>).
Support for specifying a <dfn>multi-hyperslab</dfn> or <dfn>multislab</dfn> for
any variable was first added to <command>ncks</command> in late 2002.
The other operators received these capabilities in April 2008.
Multi-slabbing is often referred to by the acronym <acronym><acronymword>MSA</acronymword></acronym>,
which stands for &textldquo;Multi-Slabbing Algorithm&textrdquo;.
As explained below, the user may additionally request that the
multislabs be returned in the user-specified order, rather than the
on-disk storage order. 
Although <acronym><acronymword>MSA</acronymword></acronym> user-ordering has been available in all operators
since 2008, most users were unaware of it since the documentation
(below, and in the man pages) was not written until July 2013.
</para>
<para>Multislabs overcome many restraints that limit simple hyperslabs.
<w>A single</w> <kbd>-d</kbd> option can only specify a contiguous and/or
a regularly spaced multi-dimensional data array.
Multislabs are constructed from multiple <kbd>-d</kbd> options and may
therefore have non-regularly spaced arrays.
For example, suppose it is desired to operate on all longitudes
from 10.0 to 20.0 and from 80.0 to <w>90.0 degrees</w>.
The combined range of longitudes is not selectable in a single 
hyperslab specfication of the form 
<samp>-d <var>dimension</var>,<var>min</var>,<var>max</var></samp> or  
<samp>-d <var>dimension</var>,<var>min</var>,<var>max</var>,<var>stride</var></samp> because its
elements are irregularly spaced in coordinate space (and presumably 
in index space too). 
The multislab specification for obtaining these values is simply
the union of the hyperslabs specifications that comprise the multislab,
i.e., 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -d lon,10.,20. -d lon,80.,90. in.nc out.nc
ncks -d lon,10.,15. -d lon,15.,20. -d lon,80.,90. in.nc out.nc
</pre></example>
<noindent></noindent>
<para>Any number of hyperslabs specifications may be chained together
to specify the multislab.
<acronym><acronymword>MSA</acronymword></acronym> creates an output dimension equal in size to the sum of
the sizes of the multislabs.
This can be used to extend and or pad coordinate grids.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="665">stride</indexterm></cindex>
<para>Users may specify redundant ranges of indices in a multislab, e.g., 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -d lon,0,4 -d lon,2,9,2 in.nc out.nc
</pre></example>
<noindent></noindent>
<para>This command retrieves the first five longitudes, and then every other
longitude value up to the tenth.
Elements 0, 2, <w>and 4</w> are specified by both hyperslab arguments (hence
this is redundant) but will count only once if an arithmetic operation
is being performed.  
This example uses index-based (not coordinate-based) multislabs because
the <var>stride</var> option only supports index-based hyper-slabbing. 
<xref label="Stride"><xrefnodename>Stride</xrefnodename></xref>, for more information on the <var>stride</var> option.
</para>
<para>Multislabs are more efficient than the alternative of sequentially
performing hyperslab operations and concatenating the results.
<cindex index="cp" spaces=" "><indexterm index="cp" number="666">I/O</indexterm></cindex>
This is because <acronym><acronymword>NCO</acronymword></acronym> employs a novel multislab algorithm to
minimize the number of I/O operations when retrieving irregularly spaced
data from disk.
The <acronym><acronymword>NCO</acronymword></acronym> multislab algorithm retrieves each element from disk
once and only once.
Thus users may take some shortcuts in specifying multislabs and the
algorithm will obtain the intended values.
Specifying redundant ranges is not encouraged, but may be useful on
occasion and will not result in unintended consequences.
</para>
<para>Suppose the <var>Q</var> variable contains three dimensional arrays of
distinct chemical constituents in no particular order.
We are interested in the NOy species in a certain geographic range. 
Say that NO, NO2, and N2O5 are <w>elements 0</w>, 1, <w>and 5</w> of the
<var>species</var> dimension of <var>Q</var>.
The multislab specification might look something like
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -d species,0,1 -d species,5 -d lon,0,4 -d lon,2,9,2 in.nc out.nc
</pre></example>
<noindent></noindent>
<para>Multislabs are powerful because they may be specified for every
dimension at the same time.
Thus multislabs obsolete the need to execute multiple <command>ncks</command>
commands to gather the desired range of data.
</para>
<html endspaces=" ">
&lt;a name=&quot;msa_usr_rdr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msa_usr_rdr --&gt;
&lt;a name=&quot;rotate_longitude&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rotate_longitude --&gt;
</html>
<para>The <acronym><acronymword>MSA</acronymword></acronym> user-order switch <samp>--msa_usr_rdr</samp> (or
<samp>--msa_user_order</samp>, both of which shorten to <samp>--msa</samp>) 
requests that the multislabs be output in the user-specified
order from the command-line, rather than in the input-file on-disk
storage order.  
This allows the user to perform complex data re-ordering in one
operation that would otherwise require cumbersome steps of
hyperslabbing, concatenating, and permuting. 
Consider the example of converting datasets stored with the longitude
coordinate <code>Lon</code> ranging from [&minus;180,180) to datasets that
follow the [0,360) convention.
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -H -v Lon in.nc
Lon[0]=-180
Lon[1]=-90
Lon[2]=0
Lon[3]=90
</pre></example>
<noindent></noindent>
<para>What is needed is a simple way to rotate longitudes.
Although simple in theory, this task requires both mathematics to
change the numerical value of the longitude coordinate, data
hyperslabbing to split the input on-disk arrays at Greenwich, and data
re-ordering within to stitch the western hemisphere onto the eastern
hemisphere at the date-line.
The <samp>--msa</samp> user-order switch overrides the default that data are
output in the same order in which they are stored on-disk in the input
file, and instead stores them in the same order as the multi-slabs are
given to the command line.
This default is intuitive and is not important in most uses.
However, the <acronym><acronymword>MSA</acronymword></acronym> user-order switch allows users to meet
their output order needs by specifying multi-slabs in a certain order.
Compare the results of default ordering to user-ordering for longitude:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -O -H       -v Lon -d Lon,0.,180. -d Lon,-180.,-1.0 in.nc
Lon[0]=-180 
Lon[1]=-90 
Lon[2]=0 
Lon[3]=90 
% ncks -O -H --msa -v Lon -d Lon,0.,180. -d Lon,-180.,-1.0 in.nc
Lon[0]=0 
Lon[1]=90 
Lon[2]=-180 
Lon[3]=-90 
</pre></example>
<noindent></noindent>
<para>The two multi-slabs are the same but they can be presented to screen,
or to an output file, in either order. 
The second example shows how to place the western hemisphere after the
eastern hemisphere, although they are stored in the opposite order in
the input file. 
</para>
<para>With this background, one sees that the following commands suffice to
rotate the input file by <w>180 degrees</w> longitude:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -O -v LatLon --msa -d Lon,0.,180. -d Lon,-180.,-1.0 in.nc out.nc
% ncap2 -O -s 'where(Lon &lt; 0) Lon=Lon+360' out.nc out.nc
% ncks --trd -C -H -v LatLon ~/nco/data/in.nc
Lat[0]=-45 Lon[0]=-180 LatLon[0]=0 
Lat[0]=-45 Lon[1]=-90 LatLon[1]=1 
Lat[0]=-45 Lon[2]=0 LatLon[2]=2 
Lat[0]=-45 Lon[3]=90 LatLon[3]=3 
Lat[1]=45 Lon[0]=-180 LatLon[4]=4 
Lat[1]=45 Lon[1]=-90 LatLon[5]=5 
Lat[1]=45 Lon[2]=0 LatLon[6]=6 
Lat[1]=45 Lon[3]=90 LatLon[7]=7 
% ncks --trd -C -H -v LatLon ~/out.nc
Lat[0]=-45 Lon[0]=0 LatLon[0]=2 
Lat[0]=-45 Lon[1]=90 LatLon[1]=3 
Lat[0]=-45 Lon[2]=180 LatLon[2]=0 
Lat[0]=-45 Lon[3]=270 LatLon[3]=1 
Lat[1]=45 Lon[0]=0 LatLon[4]=6 
Lat[1]=45 Lon[1]=90 LatLon[5]=7 
Lat[1]=45 Lon[2]=180 LatLon[6]=4 
Lat[1]=45 Lon[3]=270 LatLon[7]=5 
</pre></example>
<noindent></noindent>
<para>The analogous commands to rotate all fields in a global dataset by
<w>180 degrees</w> in the other direction, i.e., from [0,360) to
[&minus;180,180), are:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -O --msa -d lon,181.,360. -d lon,0.,180.0 in.nc out.nc
ncap2 -O -s 'where(lon &gt; 180) lon=lon-360' out.nc out.nc
</pre></example>

<para>There are other workable, valid methods to rotate data, yet
none are simpler nor more efficient than utilizing <acronym><acronymword>MSA</acronymword></acronym>
user-ordering. 
Some final comments on applying this algorithm:
Be careful to specify hemispheres that do not overlap, e.g., by
inadvertently specifying coordinate ranges that both include Greenwich
or the date-line.
Some users will find using index-based rather than coordinate-based
hyperslabs makes this clearer.
</para>
<html endspaces=" ">
&lt;a name=&quot;wrp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wrp --&gt;
</html>
</section>
<node name="Wrapped-Coordinates" spaces=" "><nodename>Wrapped Coordinates</nodename><nodenext spaces=" ">Auxiliary Coordinates</nodenext><nodeprev spaces=" ">Multislabs</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Wrapped Coordinates</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="667">wrapped coordinates</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="668">longitude</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="669"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="670"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="671"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncks</command>&linebreak;
Short options: <samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
Long options: 
<samp>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>,&linebreak; 
<samp>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
</para></cartouche>
<para><w>A <dfn>wrapped coordinate</dfn></w> is a coordinate whose values increase or
decrease monotonically (nothing unusual so far), but which represents a
dimension that ends where it begins (i.e., wraps around on itself).
Longitude (i.e., degrees on a circle) is a familiar example of a wrapped
coordinate.
Longitude increases to the East of Greenwich, England, where it is
defined to be zero.
Halfway around the globe, the longitude is <w>180 degrees</w> East (or West). 
Continuing eastward, longitude increases to <w>360 degrees</w> East at
Greenwich. 
The longitude values of most geophysical data are either in the range
[0,360), or [&minus;180,180).
In either case, the Westernmost and Easternmost longitudes are
numerically separated by <w>360 degrees</w>, but represent contiguous
regions on the globe.
For example, the Saharan desert stretches from roughly 340 to 
<w>50 degrees</w> East.
Extracting the hyperslab of data representing the Sahara from a global
dataset presents special problems when the global dataset is stored
consecutively in longitude from 0 to <w>360 degrees</w>.
This is because the data for the Sahara will not be contiguous in the
<var>input-file</var> but is expected by the user to be contiguous in the
<var>output-file</var>. 
In this case, <command>ncks</command> must invoke special software routines to
assemble the desired output hyperslab from multiple reads of the
<var>input-file</var>. 
</para>
<para>Assume the domain of the monotonically increasing longitude coordinate
<code>lon</code> is <math>0 &lt; <var>lon</var> &lt; 360</math>. 
<command>ncks</command> will extract a hyperslab which crosses the Greenwich
meridian simply by specifying the westernmost longitude as <var>min</var> and
the easternmost longitude as <var>max</var>.
The following commands extract a hyperslab containing the Saharan desert:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -d lon,340.,50. in.nc out.nc
ncks -d lon,340.,50. -d lat,10.,35. in.nc out.nc
</pre></example>
<noindent></noindent>
<para>The first example selects data in the same longitude range as the Sahara. 
The second example further constrains the data to having the same
latitude as the Sahara.
The coordinate <code>lon</code> in the <var>output-file</var>, <file>out.nc</file>, will
no longer be monotonic! 
The values of <code>lon</code> will be, e.g., <samp>340, 350, 0, 10, 20, 30,
40, 50</samp>. 
This can have serious implications should you run <file>out.nc</file> through
another operation which expects the <code>lon</code> coordinate to be
monotonically increasing.
Fortunately, the chances of this happening are slim, since <code>lon</code>
has already been hyperslabbed, there should be no reason to hyperslab
<code>lon</code> again.
Should you need to hyperslab <code>lon</code> again, be sure to give
dimensional indices as the hyperslab arguments, rather than coordinate
values (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>).
</para>
<html endspaces=" ">
&lt;a name=&quot;aux&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#aux --&gt;
&lt;a name=&quot;auxiliary&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#auxiliary --&gt;
&lt;a name=&quot;-X&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-X --&gt;
&lt;a name=&quot;std_nm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#std_nm --&gt;
&lt;a name=&quot;standard_name&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#standard_name --&gt;
</html>
</section>
<node name="Auxiliary-Coordinates" spaces=" "><nodename>Auxiliary Coordinates</nodename><nodenext spaces=" ">Grid Generation</nodenext><nodeprev spaces=" ">Wrapped Coordinates</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Auxiliary Coordinates</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="672"><code>-X</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="673"><code>--auxiliary</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="674"><code>standard_name</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="675"><code>coordinates</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="676">auxiliary coordinates</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="677"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="678"><code>-X <var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="679"><code>--auxiliary <var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>nces</command>, <command>ncecat</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>&linebreak; 
Short options: <samp>-X <var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var></samp>&linebreak;
Long options: 
<samp>--auxiliary <var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var></samp>&linebreak;
</para></cartouche>
<para>Utilize auxiliary coordinates specified in values of the coordinate
variable&textrsquo;s <code>standard_name</code> attributes, if any, when interpreting 
hyperslab and multi-slab options. 
Also <samp>--auxiliary</samp>.
This switch supports hyperslabbing cell-based grids (aka unstructured
grids) over coordinate ranges. 
When these grids are stored as 1D-arrays of cell data, this feature is
helpful at hyperslabbing and/or performing arithmetic on selected
geographic regions.
This feature cannot be used to select regions of 2D grids (instead use
the <command>ncap2</command> <code>where</code> statement for such grids 
<ref label="Where-statement"><xrefnodename>Where statement</xrefnodename></ref>).
This feature works on datasets that associate coordinate variables to 
grid-mappings using the <acronym><acronymword>CF</acronymword></acronym>-convention (<pxref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></pxref>)   
<code>coordinates</code> and <code>standard_name</code> attributes described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#coordinate-system</urefurl><urefdesc spaces=" ">here</urefdesc></uref>. 
Currently, <acronym><acronymword>NCO</acronymword></acronym> understands auxiliary coordinate variables 
pointed to by the <code>standard_name</code> attributes for <var>latitude</var> and  
<var>longitude</var>.   
Cells that contain a value within the user-specified
West-East-South-North (aka <acronym><acronymword>WESN</acronymword></acronym>) bounding box 
[<var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var>] are
included in the output hyperslab.
</para>
<para>The sides of the <acronym><acronymword>WESN</acronymword></acronym>) bounding box must be specified in
degrees (not radians).
The specified coordinates must be within the valid data range.
This includes boxes that wrap the origin of the longitude coordinate.
For example, if the longitude coordinate is stored in [0,360], then
a bounding box that straddles the Greenwich meridian in Africa would
be specified as, e.g., <math>[350,10,-20,20]</math>, not as
<math>[350,370,-20,20]</math>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="680">unstructured grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="681">cell-based grid</indexterm></cindex>
<para>A cell-based or unstructured grid collapses the horizontal spatial
information  (latitude and longitude) and stores it along a one-dimensional
coordinate that has a one-to-one mapping to both latitude and longitude
coordinates. 
Rectangular (in longitude and latitude) horizontal hyperslabs cannot
be selected using the typical procedure (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>) of
separately specifying <samp>-d</samp> arguments for longitude and latitude.
Instead, when the <samp>-X</samp> is used, <acronym><acronymword>NCO</acronymword></acronym> learns the names of
the latitude and longitude coordinates by searching the
<code>standard_name</code> attribute of all variables until it finds
the two variables whose <code>standard_name</code>&textrsquo;s are &textldquo;latitude&textrdquo; and 
&textldquo;longitude&textrdquo;, respectively. 
This <code>standard_name</code> attribute for latitude and longitude
coordinates follows the <acronym><acronymword>CF</acronymword></acronym>-convention  
(<pxref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></pxref>). 
</para>
<para>Putting it all together, consider a variable <var>gds_3dvar</var> output from 
simulations on a cell-based geodesic grid. 
Although the variable contains three dimensions of data (time, latitude,
and longitude), it is stored in the netCDF file with only two dimensions,
<code>time</code> and <code>gds_crd</code>.  
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -m -C -v gds_3dvar ~/nco/data/in.nc
gds_3dvar: type NC_FLOAT, 2 dimensions, 4 attributes, chunked? no, \
 compressed? no, packed? no, ID = 41
gds_3dvar RAM size is 10*8*sizeof(NC_FLOAT) = 80*4 = 320 bytes
gds_3dvar dimension 0: time, size = 10 NC_DOUBLE, dim. ID = 20 \ 
 (CRD)(REC)
gds_3dvar dimension 1: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
gds_3dvar attribute 0: long_name, size = 17 NC_CHAR, value = \ 
 Geodesic variable
gds_3dvar attribute 1: units, size = 5 NC_CHAR, value = meter
gds_3dvar attribute 2: coordinates, size = 15 NC_CHAR, value = \
 lat_gds lon_gds
gds_3dvar attribute 3: purpose, size = 64 NC_CHAR, value = \ 
 Test auxiliary coordinates like those that define geodesic grids
</pre></example>
<para>The <code>coordinates</code> attribute lists the names of the latitude and
longitude coordinates, <code>lat_gds</code> and <code>lon_gds</code>, respectively. 
The <code>coordinates</code> attribute is recommended though optional.
With it, the user can immediately identify which variables contain
the latitude and longitude coordinates.
Without a <code>coordinates</code> attribute it would be unclear at first
glance whether a variable resides on a cell-based grid.
In this example, <code>time</code> is a normal record dimension and
<code>gds_crd</code> is the cell-based dimension.
</para>
<para>The cell-based grid file must contain two variables whose
<code>standard_name</code> attributes are &textldquo;latitude&textrdquo;, and &textldquo;longitude&textrdquo;:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -m -C -v lat_gds,lon_gds ~/nco/data/in.nc
lat_gds: type NC_DOUBLE, 1 dimensions, 4 attributes, \
 chunked? no, compressed? no, packed? no, ID = 37
lat_gds RAM size is 8*sizeof(NC_DOUBLE) = 8*8 = 64 bytes
lat_gds dimension 0: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
lat_gds attribute 0: long_name, size = 8 NC_CHAR, value = Latitude
lat_gds attribute 1: standard_name, size = 8 NC_CHAR, value = latitude
lat_gds attribute 2: units, size = 6 NC_CHAR, value = degree
lat_gds attribute 3: purpose, size = 62 NC_CHAR, value = \ 
 1-D latitude coordinate referred to by geodesic grid variables

lon_gds: type NC_DOUBLE, 1 dimensions, 4 attributes, \
 chunked? no, compressed? no, packed? no, ID = 38
lon_gds RAM size is 8*sizeof(NC_DOUBLE) = 8*8 = 64 bytes
lon_gds dimension 0: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
lon_gds attribute 0: long_name, size = 9 NC_CHAR, value = Longitude
lon_gds attribute 1: standard_name, size = 9 NC_CHAR, value = longitude
lon_gds attribute 2: units, size = 6 NC_CHAR, value = degree
lon_gds attribute 3: purpose, size = 63 NC_CHAR, value = \
 1-D longitude coordinate referred to by geodesic grid variables
</pre></example>
<para>In this example <code>lat_gds</code> and <code>lon_gds</code> represent the 
latitude or longitude, respectively, of cell-based variables.
These coordinates (must) have the same single dimension (<code>gds_crd</code>,
in this case) as the cell-based variables.
And the coordinates must be one-dimensional&textmdash;multidimensional
coordinates will not work.
</para>
<para>This infrastructure allows <acronym><acronymword>NCO</acronymword></acronym> to identify, interpret, and
process (i.e., hyperslab) the variables on cell-based grids as easily
as it works with regular grids.
To time-average all the values between zero and <w>180 degrees</w>
longitude and between plus and minus <w>30 degress</w> latitude, we use
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -O -X 0.,180.,-30.,30. -v gds_3dvar in.nc out.nc
</pre></example>
<para><acronym><acronymword>NCO</acronymword></acronym> accepts multiple <samp>-X</samp> arguments for cell-based grid
multi-slabs, just as it accepts multiple <samp>-d</samp> arguments for 
multi-slabs of regular coordinates.
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -O -X 0.,180.,-30.,30. -X 270.,315.,45.,90. in.nc out.nc
</pre></example>
<para>The arguments to <samp>-X</samp> are always interpreted as floating-point
numbers, i.e., as coordinate values rather than dimension indices
so that these two commands produce identical results
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -X 0.,180.,-30.,30. in.nc out.nc
ncra -X 0,180,-30,30 in.nc out.nc
</pre></example>
<para>By contrast, arguments to <samp>-d</samp> require decimal places to be
recognized as coordinates not indices (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>).  
We recommend always using decimal points with <samp>-X</samp> arguments
to avoid confusion.
</para>
<html endspaces=" ">
&lt;a name=&quot;scrip&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#scrip --&gt;
&lt;a name=&quot;grid&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grid --&gt;
&lt;a name=&quot;grd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grd --&gt;
</html>
</section>
<node name="Grid-Generation" spaces=" "><nodename>Grid Generation</nodename><nodenext spaces=" ">Regridding</nodenext><nodeprev spaces=" ">Auxiliary Coordinates</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Grid Generation</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="682">Gaussian grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="683">Equi-Angular grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="684">FV grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="685">FV grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="686">CAM-FV grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="687">grid, Fixed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="688">grid, Offset</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="689">grid, FV</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="690">grid, CAM-FV</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="691">grid, Equi-Angular</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="692">grid, Gaussian</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="693">gridfile</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="694"><code>--map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="695"><acronym><acronymword>ESMF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="696"><acronym><acronymword>SCRIP</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="697"><code>--rgr <var>key</var>=<var>val</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncks</command>&linebreak; 
Short options: None&linebreak;
Long options: 
<samp>--rgr <var>key</var>=<var>val</var></samp> (multiple invocations allowed)&linebreak;
</para></cartouche>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.5.2 (August, 2015), <command>ncks</command>
generates accurate and complete SCRIP-format gridfiles for select grid 
types, including uniform, capped and Gaussian rectangular,
latitude/longitude grids, global or regional.
The grids are stored in an external <var>grid-file</var>.
</para>
<para>All options pertinent to the grid geometry and metadata are passed to
<acronym><acronymword>NCO</acronymword></acronym> via key-value pairs prefixed by the <samp>--rgr</samp> option,
or its synonym, <samp>--regridding</samp>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="698">indicator option</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="699">multi-arguments</indexterm></cindex>
The option <samp>--rgr</samp> (and its long option equivalents such
as <samp>--regridding</samp>) indicates the argument syntax will be
<var>key</var>=<var>val</var>.
As such, <samp>--rgr</samp> and its synonyms are indicator options that accept
arguments supplied one-by-one like 
<samp>--rgr <var>key1</var>=<var>val1</var> --rgr <var>key2</var>=<var>val2</var></samp>, or
aggregated together in multi-argument format like
<samp>--rgr <var>key1</var>=<var>val1</var>#<var>key2</var>=<var>val2</var></samp>
(<pxref label="Multi_002darguments"><xrefnodename>Multi-arguments</xrefnodename></pxref>).
</para>
<para>The text strings that describe the grid and name the file are important 
aids to convey the grid geometry to other users.
These arguments, and their corresponding keys, are the grid title
(<var>grd_ttl</var>), and grid filename (<var>grid</var>), respectively.
The numbers of latitudes (<var>lat_nbr</var>) and longitudes (<var>lon_nbr</var>)   
are independent, and together determine the grid storage size.
These four options should be considered mandatory, although
<acronym><acronymword>NCO</acronymword></acronym> provides defaults for any arguments omitted.
</para>
<para>The remaining arguments depend on the whether the grid is global or
regional.
For global grids, one should specify only two more arguments, the
latitude (<var>lat_typ</var>) and longitude (<var>lon_typ</var>) grid-types.
These types are chosen as described below from a small selection of
options that together define the most common rectangular global grids.
For regional grids, one must specify the bounding box, i.e., the edges
of the rectangular grid on the North (<var>lat_nrt</var>), South (<var>lat_sth</var>), 
East (<var>lat_est</var>), and West (<var>lat_nrt</var>) sides. 
Specifying a bounding box for global grids is redundant and will cause
an error to ensure the user intends a global grid.
<acronym><acronymword>NCO</acronymword></acronym> assumes that regional grids are uniform, though it will 
attempt to produce regional grids of other types if the user specifies
other latitude (<var>lat_typ</var>) and longitude (<var>lon_typ</var>) grid-types,
e.g., Gaussian or Cap.
Edges of a regional bounding box may be specified individually, or in
the single-argument forms.
</para>
<para>The full description of grid-generation arguments, and their
corresponding keys, is:
</para><table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="700"><var>grd_ttl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="701"><samp>--rgr grd_ttl=<var>grd_ttl</var></samp></indexterm></cindex>
<item spaces=" "><itemformat command="dfn">Grid Title: <var>grd_ttl</var></itemformat></item>
</tableterm><tableitem><para>It is surprisingly difficult to discern the geometric configuration of
a grid from the coordinates of a <acronym><acronymword>SCRIP</acronymword></acronym>-format gridfile.  
A human-readable grid description should be placed in <var>grd_ttl</var>.
Examples include &textldquo;CAM-FV scalar grid 129x256&textrdquo; and &textldquo;T42 Gaussian grid&textrdquo;. 
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="702"><var>scrip_grid</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="703"><samp>--rgr grid=<var>scrip_grid</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="704"><samp>--rgr scrip=<var>scrip_grid</var></samp></indexterm></cindex>
<item spaces=" "><itemformat command="dfn">Grid File: <var>scrip_grid</var></itemformat></item>
</tableterm><tableitem><para>The grid-generation <acronym><acronymword>API</acronymword></acronym> was bolted-on to <acronym><acronymword>NCO</acronymword></acronym>
and contains some temporary kludges.
For example, the output grid filename is distinct from the output
filename of the host <command>ncks</command> command.  
Specify the output gridfile name <var>scrip_grid</var> with keywords
<code>grid</code> or <code>scrip</code>, e.g., <samp>--rgr grid=<var>scrip_grid</var></samp> or  
<samp>--rgr scrip=<file>t42_SCRIP.20150901.nc</file></samp>.
It is conventional to include a datestamp in the gridfile name.
This helps users identify up-to-date and out-of-date grids.
Any valid netCDF file may be named as the source (e.g., <file>in.nc</file>). 
It will not be altered. 
The destination file (e.g., <file>foo.nc</file>) will be overwritten. 
Its contents are immaterial. 
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="705"><var>lat_typ</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="706"><var>lon_typ</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="707"><samp>--rgr lon_typ=<var>lon_typ</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="708"><samp>--rgr lat_typ=<var>lat_typ</var></samp></indexterm></cindex>
<item spaces=" "><itemformat command="dfn">Grid Types: <var>lat_typ</var>, <var>lon_typ</var></itemformat></item>
</tableterm><tableitem><para>The keys that hold the longitude and latitude gridtypes (which
are, by the way, independent of eachother) are <var>lon_typ</var> and
<var>lat_typ</var>. 
The <var>lat_typ</var> options for global grids are <samp>uni</samp> for
Uniform, <samp>cap</samp> (or <samp>fv</samp>) for Cap<footnote spaces="\n"><para>The term <acronym><acronymword>FV</acronymword></acronym> confusing because it is correct to call
any Finite Volume grid (including arbitrary polygons) an
<acronym><acronymword>FV</acronymword></acronym> grid.
However, an <acronym><acronymword>FV</acronymword></acronym> grid has also been used for many years
to described the particular type of rectangular grid with caps
at the poles used to discretize global model grids for use with
the Lin-Rood dynamical core.
To reduce confusion, we use &textldquo;Cap grid&textrdquo; to refer to the latter
and reserv <acronym><acronymword>FV</acronymword></acronym> as a straightforward acronym for Finite
Volume.</para></footnote>,
and <samp>gss</samp> for Gaussian.
</para>
<para>These values are all case-independent, so <samp>Gss</samp> and <samp>gss</samp> both
work.
As of version 4.7.7 (September, 2018), <acronym><acronymword>NCO</acronymword></acronym> generates perfectly
symmetric interface latitudes for Gaussian grids.
Previously the interface latitude generation mechanism could accumulate
small rounding errors (~1.0e-14).
Now symmetry properties are used to ensure perfect symmetry.
All other Gaussian grids we have seen compute interfaces as the
arithmetic mean of the adjacent Gaussian latitudes, which is patently
wrong. 
To our knowledge <acronym><acronymword>NCO</acronymword></acronym> is the only map software that generates
accurate interface latitudes for a Gaussian grid.
We use a Newton-Raphson iteration technique to identify the interface
latitudes that enclose the area indicated by the Gaussian weight.
</para>
<para>As its name suggests, the latitudes in a Uniform-latitude grid are
uniformly spaced  
<footnote spaces="\n"><para>A Uniform grid in latitude could be called &textldquo;equi-angular&textrdquo; in
latitude, but <acronym><acronymword>NCO</acronymword></acronym> reserves the term Equi-angular or &textldquo;eqa&textrdquo; 
for grids that have the same uniform spacing in both latitude and
longitude, e.g., 1&deg;x1&deg; or
2&deg;x2&deg;. 
<acronym><acronymword>NCO</acronymword></acronym> reserves the term Regular to refer to grids that are
monotonic and rectangular grids. 
Confusingly, the angular spacing in a Regular grid need not be uniform,  
it could be irregular, such as in a Gaussian grid.
The term Regular is not too useful in grid-generation, because so many
other parameters (spacing, centering) are necessary to disambiguate it.</para></footnote>. 
The Uniform-latitude grid may have any number of latitudes. 
<acronym><acronymword>NCO</acronymword></acronym> can only generate longitude grids (below) that are
uniformly spaced, so the Uniform-latitude grids we describe are
also uniform in the 2D sense.
Uniform grids are intuitive, easy to visualize, and simple to program.
Hence their popularity in data exchange, visualization, and archives.
Moreover, regional grids (unless they include the poles), are free
of polar singularities, and thus are well-suited to storage on Uniform 
grids. 
Theoretically, a Uniform-latitude grid could have non-uniform
longitudes, but <acronym><acronymword>NCO</acronymword></acronym> currently does not implement non-uniform
longitude grids.
</para>
<para>Their mathematical properties (convergence and excessive resolution at
the poles, which can appear as singularities) make Uniform grids fraught
for use in global models.  
One purpose Uniform grids serve in modeling is as &textldquo;offset&textrdquo; or
&textldquo;staggered&textrdquo; grids, meaning grids whose centers are the interfaces of 
another grid. 
The Finite-Volume (<acronym><acronymword>FV</acronymword></acronym>) method is often used to represent 
and solve the equations of motion in climate-related fields.
Many <acronym><acronymword>FV</acronymword></acronym> solutions (including the popular Lin-Rood method as
used in the <acronym><acronymword>CESM</acronymword></acronym> <acronym><acronymword>CAM-FV</acronymword></acronym> atmospheric model) evaluate
scalar (i.e., non-vector) fields (e.g., temperature, water vapor) at
gridcell centers of what is therefore called the scalar grid. 
<acronym><acronymword>FV</acronymword></acronym> methods (like Lin-Rood) that employ an Arakawa C-grid or
D-grid formulation define velocities on the edges of the scalar grid.
This <acronym><acronymword>CAM-FV</acronymword></acronym> velocity grid is therefore &textldquo;staggered&textrdquo; or
&textldquo;offset&textrdquo; from the <acronym><acronymword>CAM-FV</acronymword></acronym> scalar grid by one-half gridcell.  
The <acronym><acronymword>CAM-FV</acronymword></acronym> scalar latitude grid has gridpoints (the
&textldquo;caps&textrdquo;) centered on each pole to avoid singularities.
The offset of a Cap-grid is a Uniform-grid, so the Uniform grid is 
often called an <acronym><acronymword>FV</acronymword></acronym>-&textrdquo;offset&textrdquo; or &textldquo;staggered&textrdquo; grid.
Hence an <acronym><acronymword>NCO</acronymword></acronym> Uniform grid is equivalent to an <acronym><acronymword>NCL</acronymword></acronym>  
&textldquo;Fixed Offset&textrdquo; grid.
For example, a 128x256 Uniform grid is the offset or staggered version
of a 129x256 Cap grid (aka <acronym><acronymword>FV</acronymword></acronym>-grid).
</para>
<para>Referring the saucer-like cap-points at the poles, <acronym><acronymword>NCO</acronymword></acronym> uses
the term &textldquo;Cap grid&textrdquo; to describe the latitude portion of the
<acronym><acronymword>FV</acronymword></acronym>-scalar grid as used by the <acronym><acronymword>CAM-FV</acronymword></acronym> Lin-Rood
dynamics formulation. 
<acronym><acronymword>NCO</acronymword></acronym> accepts the shorthand <acronym><acronymword>FV</acronymword></acronym>, and the more
descriptive &textldquo;Yarmulke&textrdquo;, as synonyms for Cap. 
A Cap-latitude grid differs from a Uniform-latitude grid in many ways:
</para>
<para>Most importantly, Cap grids are 2D-representations of numerical grids
with cap-midpoints instead of zonal-teeth convergence at the poles.  
The rectangular 2D-representation of each cap contains gridcells shaped
like sharp teeth that converge at the poles similar to the Uniform grid,  
but the Cap gridcells are meant to be aggregated into a single cell
centered at the pole in a dynamical transport algorithm.  
In other words, the polar teeth are a convenient way to encode a
non-rectangular grid in memory into a rectangular array on disk.  
Hence Cap grids have the unusual property that the poles are labeled as
being both the centers and the outer interfaces of all polar gridcells. 
Second, Cap grids are uniform in angle except at the poles, where the
latitudes span half the meridional range of the rest of the gridcells. 
Even though in the host dynamical model the Cap grid polar points are
melded into caps uniform (in angle) with the rest of the grid, the disk
representation on disk is not uniform.
Nevertheless, some call the Cap grid a uniform-angle grid because the
information contained at the poles is aggregated in memory to span twice
the range of a single polar gridcell (which has half the normal width). 
<acronym><acronymword>NCL</acronymword></acronym> uses the term &textldquo;Fixed grid&textrdquo; for a Cap grid.
The &textldquo;Fixed&textrdquo; terminology seems broken.
</para>
<html endspaces=" ">
&lt;a name=&quot;gss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gss --&gt;
</html>
<para>Finally, Gaussian grids are the Cartesian representation of global
spectral transform models. 
Gaussian grids typically have an even number of latitudes and so  
do not have points at the poles.
All three latitude grid-type supported by <acronym><acronymword>NCO</acronymword></acronym> (Uniform, Cap, 
and Gaussian) are Regular grids in that they are monotonic. 
</para>
<para>The <var>lon_typ</var> options for global grids are <samp>grn_ctr</samp> and
<samp>180_ctr</samp> for the first gridcell centered at Greenwich or 
<w>180 degrees</w>, respecitvely.   
And <samp>grn_wst</samp> and <samp>180_wst</samp> for Greenwich or <w>180 degress</w>
lying on the western edge of the first gridcell.
Many global models use the <samp>grn_ctr</samp> longitude grid as their
&textldquo;scalar grid&textrdquo; (where, e.g., temperature, humidity, and other scalars
are defined).
The &textldquo;staggered&textrdquo; or &textldquo;offset&textrdquo; grid (where often the dynamics variables
are defined) then must have the <samp>grn_wst</samp> longitude convention.
That way the centers of the scalar grid are the vertices of the offset
grid, and visa versa.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="709"><var>lat_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="710"><var>lon_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="711"><samp>--rgr latlon=<var>lat_nbr</var>,<var>lon_nbr</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="712"><samp>--rgr lon_nbr=<var>lon_nbr</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="713"><samp>--rgr lat_nbr=<var>lat_nbr</var></samp></indexterm></cindex>
<item spaces=" "><itemformat command="dfn">Grid Resolution: <var>lat_nbr</var>, <var>lon_nbr</var></itemformat></item>
</tableterm><tableitem><para>The number of gridcells in the horizontal spatial dimensions
are <var>lat_nbr</var> and <var>lon_nbr</var>, respectively.
There are no restrictions on <var>lon_nbr</var> for any gridtype.
Latitude grids do place some restrictions on <var>lat_nbr</var> (see above). 
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.5.3</w>, released in October, 2015,
the <samp>--rgr latlon=<var>lat_nbr</var>,<var>lon_nbr</var></samp> switch may be
used to simultaneously specify both latitude and longitude, e.g., 
<samp>--rgr latlon=180,360</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;lat_drc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lat_drc --&gt;
&lt;a name=&quot;lat_drc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#n2s --&gt;
&lt;a name=&quot;lat_drc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#s2n --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="714"><code>n2s</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="715"><code>s2n</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="716"><var>lat_drc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="717"><samp>--rgr lat_drc=<var>lat_drc</var></samp></indexterm></cindex>
<item spaces=" "><itemformat command="dfn">Latitude Direction: <var>lat_drc</var></itemformat></item>
</tableterm><tableitem><para>The <var>lat_drc</var> option is specifies whether latitudes monotonically
increase or decrease in rectangular grids.
The two possible values are
<samp>s2n</samp> for grids that begin with the most southerly latitude and end
with the most northerly, and 
<samp>n2s</samp> for grids that begin with the most northerly latitude and end
with the most southerly.
By default <acronym><acronymword>NCO</acronymword></acronym> creates grids whose latitudes run
south-to-north.
Hence this option is only necessary to create a grid whose latitudes run
north-to-south.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="718"><var>lat_nrt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="719"><var>lat_sth</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="720"><var>lat_est</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="721"><var>lat_wst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="722"><var>wesn</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="723"><var>snwe</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="724"><samp>--rgr wesn=<var>lon_wst</var>,<var>lon_est</var>,<var>lat_sth</var>,<var>lon_nrt</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="725"><samp>--rgr snwe=<var>lat_sth</var>,<var>lat_nrt</var>,<var>lon_wst</var>,<var>lon_est</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="726"><samp>--rgr lat_nrt=<var>lat_nrt</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="727"><samp>--rgr lat_nbr=<var>lat_nbr</var></samp></indexterm></cindex>
<item spaces=" "><itemformat command="dfn">Grid Edges: <var>lon_wst</var>, <var>lon_est</var>, <var>lat_sth</var>, <var>lat_nrt</var></itemformat></item>
</tableterm><tableitem><para>The outer edges of a regional rectangular grid are specified by
the North (<var>lat_nrt</var>), South (<var>lat_sth</var>), East (<var>lat_est</var>),
and West (<var>lat_nrt</var>) sides. 
Latitudes and longigudes must be specified in degrees (not radians).
Latitude edges must be between <w>-90 and 90</w>.
Longitude edges may be positive or negative and separated by no more
than 360 degrees.
The edges may be specified individually with four arguments, 
consecutively separated by the multi-argument delimiter (<samp>#</samp> by
default), or together in a short list to the pre-ordered options
<samp>wesn</samp> or <samp>snwe</samp>. 
These three specifications are equivalent:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks ... --rgr lat_sth=30.0 --rgr lat_nrt=70.0 --rgr lon_wst=-120.0 --rgr lon_est=-90.0 ...
ncks ... --rgr lat_sth=30.0#lat_nrt=70.0#lon_wst=-120.0#lon_est=-90.0 ...
ncks ... --rgr snwe=30.0,70.0,-120.0,-90.0 ...
</verbatim>
</example>
</tableitem></tableentry></table>
<para>The first example above supplies the bounding box with four
<var>key</var>=<var>val</var> pairs. 
The second example above supplies the bounding box with a single option
in multi-argument format (<pxref label="Multi_002darguments"><xrefnodename>Multi-arguments</xrefnodename></pxref>).
The third example uses a convenience switch introduced to reduce typing.
</para>
<html endspaces=" ">
&lt;a name=&quot;grd_cmd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grd_cmd --&gt;
&lt;a name=&quot;xmp_grd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_grd --&gt;
</html>
<para>Generating common grids:
<cindex index="cp" spaces=" "><indexterm index="cp" number="728"><acronym><acronymword>ECMWF IFS</acronymword></acronym> grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="729"><acronym><acronymword>ECMWF ERA5</acronymword></acronym> grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="730"><acronym><acronymword>NCEP2</acronymword></acronym> grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="731"><acronym><acronymword>NASA CMG</acronymword></acronym> grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="732"><acronym><acronymword>NASA MERRA2</acronymword></acronym> grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="733"><acronym><acronymword>CAM-FV</acronymword></acronym> grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="734"><acronym><acronymword>Equi-angular</acronymword></acronym> grid</indexterm></cindex>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Access to grid-generation was through ncks, not ncremap, until version 4.7.6
# 180x360 (1x1 degree) Equi-Angular grid, first longitude centered at Greenwich
# This is NOT the CMIP6 1x1 grid
ncks --rgr ttl='Equi-Angular grid 180x360'#latlon=180,360#lat_typ=uni#lon_typ=grn_ctr \
     --rgr scrip=${DATA}/grids/180x360_SCRIP.20150901.nc \
     ~zender/nco/data/in.nc ~/foo.nc

# Version 4.7.6+ (August, 2018), supports the preferred, more concise, ncremap syntax:
# This is NOT the CMIP6 1x1 grid
ncremap -G ttl='Equi-Angular grid 180x360'#latlon=180,360#lat_typ=uni#lon_typ=grn_ctr \
        -g ${DATA}/grids/180x360_SCRIP.20180901.nc

# 180x360 (1x1 degree) Equi-Angular grid, first longitude west edge at Greenwich
# This IS the CMIP6 1x1 grid
ncremap -G ttl='Equi-Angular grid 180x360'#latlon=180,360#lat_typ=uni#lon_typ=grn_wst \
        -g ${DATA}/grids/180x360wst_SCRIP.20180301.nc

# 129x256 CAM-FV grid, first longitude centered at Greenwich
ncremap -G ttl='CAM-FV scalar grid 129x256'#latlon=129,256#lat_typ=fv#lon_typ=grn_ctr \
        -g ${DATA}/grids/129x256_SCRIP.20150901.nc

# 192x288 CAM-FV grid, first longitude centered at Greenwich
ncremap -G ttl='CAM-FV scalar grid 192x288'#latlon=192,288#lat_typ=fv#lon_typ=grn_ctr \
        -g ${DATA}/grids/192x288_SCRIP.20160301.nc

# 361x576 NASA MERRA2 FV grid, first longitude centered at DateLine
ncremap -G ttl='NASA MERRA2 Cap grid 361x576'#latlon=361,576#lat_typ=cap#lon_typ=180_ctr \
        -g ${DATA}/grids/merra2_361x576.20201001.nc

# 1441x2880 CAM-FV grid, first longitude centered at Greenwich
ncremap -G ttl='CAM-FV scalar grid 1441x2880'#latlon=1441,2880#lat_typ=fv#lon_typ=grn_ctr \
        -g ${DATA}/grids/1441x2880_SCRIP.20170901.nc

# 1440x2880 ELM/MOSART grid, first longitude west edge at DateLine
ncremap -7 -L 1 \
        -G ttl='ELM/MOSART 1440x2880 one-eighth degree uniform grid (r0125)'#latlon=1440,2880#lat_typ=uni#lon_typ=180_wst \
        -g ${DATA}/grids/r0125_1440x2880.20210401.nc

# 91x180 CAM-FV grid, first longitude centered at Greenwich (2 degree grid)
ncremap -G ttl='CAM-FV scalar grid 91x180'#latlon=91,180#lat_typ=fv#lon_typ=grn_ctr \
        -g ${DATA}/grids/91x180_SCRIP.20170401.nc

# 25x48 CAM-FV grid, first longitude centered at Greenwich (7.5 degree grid)
ncremap -G ttl='CAM-FV scalar grid 25x48'#latlon=25,48#lat_typ=fv#lon_typ=grn_ctr \
        -g ${DATA}/grids/25x48_SCRIP.20170401.nc

# 128x256 Equi-Angular grid, Greenwich west edge of first longitude
# CAM-FV offset grid for 129x256 CAM-FV scalar grid above
ncremap -G ttl='Equi-Angular grid 128x256'#latlon=128,256#lat_typ=uni#lon_typ=grn_wst \
        -g ${DATA}/grids/128x256_SCRIP.20150901.nc

# T42 Gaussian grid, first longitude centered at Greenwich
ncremap -G ttl='T42 Gaussian grid'#latlon=64,128#lat_typ=gss#lon_typ=grn_ctr \
        -g ${DATA}/grids/t42_SCRIP.20180901.nc

# T62 Gaussian grid, first longitude centered at Greenwich, NCEP2 T62 Gaussian grid 
ncremap -G ttl='NCEP2 T62 Gaussian grid'#latlon=94,192#lat_typ=gss#lon_typ=grn_ctr#lat_drc=n2s \
        -g ${DATA}/grids/ncep2_t62_SCRIP.20191001.nc

# F256 Full Gaussian grid, first longitude centered at Greenwich
ncremap -7 -L 1 \
        -G ttl='ECMWF IFS F256 Full Gaussian grid 512x1024'#latlon=512,1024#lat_typ=gss#lon_typ=grn_ctr#lat_drc=n2s \
        -g ${DATA}/grids/f256_scrip.20201001.nc

# 513x1024 FV grid, first longitude centered at Greenwich
ncremap -7 -L 1 \
        -G ttl='FV scalar grid 513x1024'#latlon=513,1024#lat_typ=fv#lon_typ=grn_ctr \
        -g ${DATA}/grids/513x1024_SCRIP.20201001.nc

# 1025x2048 FV grid, first longitude centered at Greenwich
ncremap -7 -L 1 \
        -G ttl='FV scalar grid 1025x2048'#latlon=1025,2048#lat_typ=fv#lon_typ=grn_ctr \
        -g ${DATA}/grids/1025x2048_SCRIP.20201001.nc

# F640 Full Gaussian grid, first longitude centered at Greenwich
ncremap -7 -L 1 \
     -G ttl='ECMWF IFS F640 Full Gaussian grid 1280x2560'#latlon=1280,2560#lat_typ=gss#lon_typ=grn_ctr#lat_drc=n2s \
     -g ${DATA}/grids/f640_scrip.20190601.nc

# NASA Climate Modeling Grid (CMG) 3600x7200 (0.05x0.05 degree) Equi-Angular grid
# Date-line west edge of first longitude, east edge of last longitude
# Write to compressed netCDF4-classic file to reduce filesize ~140x from 2.2 GB to 16 MB
ncremap -7 -L 1 \
     -G ttl='Equi-Angular grid 3600x7200 (NASA CMG)'#latlon=3600,7200#lat_typ=uni#lon_typ=180_wst \
     -g ${DATA}/grids/3600x7200_SCRIP.20160301.nc

# DOE E3SM/ACME High Resolution Topography (1 x 1 km grid) for Elevation Classes
# Write to compressed netCDF4-classic file to reduce filesize from ~85 GB to 607 MB
ncremap -7 -L 1 \
     -G ttl='Global latxlon = 18000x36000 ~1 x 1 km'#latlon=18000,36000#lat_typ=uni#lon_typ=grn_ctr \
     -g ${DATA}/grids/grd_18000x36000_SCRIP.nc

# 1x1 degree Equi-Angular Regional grid over Greenland, centered longitudes
ncremap -G ttl='Equi-Angular Greenland 1x1 degree grid'#latlon=30,90#snwe=55.0,85.0,-90.0,0.0#lat_typ=uni#lon_typ=grn_ctr \
        -g ${HOME}/greenland_1x1.nc

# 721x1440 ECMWF ERA5 resolution in north-to-south order (ERA5/CAMS default order)
ncremap -7 --dfl_lvl=1 -G ttl='Cap/FV ECMWF ERA5 grid 0.25x0.25 degree, dimensions 721x1440, cell centers on Poles/Equator (in north-to-south order) and Prime Meridian/Date Line'#latlon=721,1440#lat_drc=n2s#lat_typ=cap#lon_typ=grn_ctr \
         -g ${DATA}/grids/era5_n2s_721x1440.nc

# 721x1440 ECMWF ERA5 resolution in south-to-north order (E3SM/ELM-offline forcing order)
ncremap -7 --dfl_lvl=1 -G ttl='Cap/FV ECMWF ERA5 grid 0.25x0.25 degree, dimensions 721x1440, cell centers on Poles/Equator (in south-to-north order) and Prime Meridian/Date Line'#latlon=721,1440#lat_drc=s2n#lat_typ=cap#lon_typ=grn_ctr \
        -g ${DATA}/grids/era5_s2n_721x1440.nc

# 360x720 CRUNCEP (E3SM/ELM-offline forcing grid) (NB: CRUNCEP starts at Greenwich, is not r05)
ncremap -7 --dfl_lvl=1 -G ttl='CRUNCEP Equi-Angular 0.5x0.5 degree uniform grid, dimensions 360x720, cell edges on Poles/Equator and Prime Meridian/Date Line'#latlon=360,720#lat_typ=uni#lon_typ=Grn_wst \
        -g ${DATA}/grids/cruncep_360x720.nc

# 360x720 ELM/MOSART grid, first longitude west edge at DateLine (NB: starts at Dateline, &quot;r&quot; stands for &quot;river&quot; grid)
ncremap -7 --dfl_lvl=1 -G ttl='Equi-Angular 0.5x0.5 degree uniform grid (r05), dimensions 360x720, cell edges on Poles/Equator and Date Line/Prime Meridian'#latlon=360,720#lat_typ=uni#lon_typ=180_wst \
        -g ${DATA}/grids/r05_360x720.nc

# 720x1440 ELM/MOSART grid, first longitude west edge at DateLine (NB: starts at Dateline, &quot;r&quot; stands for &quot;river&quot; grid)
ncremap -7 --dfl_lvl=1 -G ttl='Equi-Angular 0.25x0.25 degree uniform grid (r025), dimensions 720x1440, cell edges on Poles/Equator and Date Line/Prime Meridian'#latlon=720,1440#lat_typ=uni#lon_typ=180_wst \
        -g ${DATA}/grids/r025_720x1440.nc

# 105x401 Greenland ERA5
ncremap -G ttl='Equi-Angular Greenland 0.25x0.25 degree ERA5 north-to-south grid'#latlon=105,401#snwe=58.875,85.125,-87.125,13.125#lat_typ=uni#lat_drc=n2s#lon_typ=grn_ctr \
        -g ${DATA}/grids/greenland_0.25x0.25_era5.nc

# Greenland r025 with SNWE = 59,84,-73,-11 (in round numbers) with RACMO ice mask
ncremap -G ttl='Equi-Angular Greenland 0.25x0.25 degree r025 south-to-north grid'#latlon=100,250#snwe=58.875,83.875,-73.25,-10.75#lat_typ=uni#lat_drc=s2n#lon_typ=grn_ctr \
        -g ${DATA}/grids/greenland_r025_100x250.nc

# NASA Climate Modeling Grid (CMG) 3600x7200 (0.05x0.05 degree, 3'x3') Equi-Angular grid
# With land mask derived mainly from GLOBE 30&quot; topography and anywhere Gardner 30&quot; land ice data is valid
# Date-line west edge of first longitude, east edge of last longitude
# Write to compressed netCDF4-classic file to reduce filesize ~140x from 2.2 GB to 16 MB
ncremap -7 -L 1 \
     -G ttl='Equi-Angular grid 3-minute=0.05 degree resolution = 3600x7200, NASA CMG boundaries, with land mask derived mainly from GLOBE 30&quot; topography and anywhere Gardner 30&quot; land ice data is valid'#latlon=3600,7200#lat_typ=uni#lon_typ=180_wst \
     -g ${DATA}/grids/r005_3600x7200_globe_gardner_landmask.20210501.nc
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;nfr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nfr --&gt;
&lt;a name=&quot;infer&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#infer --&gt;
&lt;a name=&quot;ugrid&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ugrid --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="735">infer</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="736"><code>--rgr nfr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="737"><code>--rgr infer</code></indexterm></cindex>
<para>Often researchers face the problem not of generating a known, idealized
grid but of understanding an unknown, possibly irregular or curvilinear
grid underlying a dataset produced elsewhere.
<acronym><acronymword>NCO</acronymword></acronym> will <dfn>infer</dfn> the grid of a datafile by examining its
coordinates (and boundaries, if available), reformat that information
as necessary to diagnose gridcell areas, and output the results in
<acronym><acronymword>SCRIP</acronymword></acronym> format.
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.5.3</w>, released in October, 2015,
the <samp>--rgr infer</samp> flag activates the machinery to infer the grid
rather than construct the grid from other user-specified switches.
To infer the grid properties, <acronym><acronymword>NCO</acronymword></acronym> interrogates
<var>input-file</var> for horizontal coordinate information, such as the
presence of dimension names rooted in latitude/longitude-naming
traditions and conventions. 
Once <acronym><acronymword>NCO</acronymword></acronym> identifies the likely horizontal dimensions it looks
for horizontal coordinates and bounds.
If bounds are not found, <acronym><acronymword>NCO</acronymword></acronym> assumes the underlying grid
comprises quadrilateral cells whose edges are midway between cell
centers, for both rectilinear and curvilinear grids. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Infer AIRS swath grid from input, write it to grd_scrip.nc
ncks --rgr infer --rgr scrip=${DATA}/sld/rgr/grd_scrip.nc \
     ${DATA}/sld/raw/AIRS.2014.10.01.202.L2.TSurfStd.Regrid010.1DLatLon.nc ~/foo.nc
</verbatim>
</example>
<para>When inferring grids, the grid file (<file>grd_scrip.nc</file>) is written
in <acronym><acronymword>SCRIP</acronymword></acronym> format, the input file (<file>AIRS...nc</file>) is read,
and the output file (<file>foo.nc</file>) is overwritten (its contents are
immaterial). 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="738"><acronym><acronymword>UGRID</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="739"><code>--rgr ugrid</code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.6.6</w>, released in April, 2017,
inferred 2D rectangular grids may also be written in
<acronym><acronymword>UGRID</acronymword></acronym>-format (defined
<uref><urefurl>http://ugrid-conventions.github.io/ugrid-conventions</urefurl><urefdesc spaces=" ">here</urefdesc></uref>).
Request a <acronym><acronymword>UGRID</acronymword></acronym> mesh with the option
<samp>--rgr ugrid=<var>fl_ugrid</var></samp>.
Currently both <acronym><acronymword>UGRID</acronymword></acronym> and <acronym><acronymword>SCRIP</acronymword></acronym> grids must be
requested in order to produce the <acronym><acronymword>UGRID</acronymword></acronym> output, e.g., 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks --rgr infer --rgr ugrid=${HOME}/grd_ugrid.nc \
     --rgr scrip=${HOME}/grd_scrip.nc ~/skl_180x360.nc ~/foo.nc
</verbatim>
</example>

<para>The <acronym><acronymword>SCRIP</acronymword></acronym> gridfile and <acronym><acronymword>UGRID</acronymword></acronym> meshfile metadata
produced for the equiangular <w>1-by-1 degree</w> global grid are:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@aerosol:~$ ncks -m ~/grd_scrip.nc 
netcdf grd_scrip {
  dimensions:
    grid_corners = 4 ;
    grid_rank = 2 ;
    grid_size = 64800 ;

  variables:
    double grid_area(grid_size) ;
      grid_area:units = &quot;steradian&quot; ;

    double grid_center_lat(grid_size) ;
      grid_center_lat:units = &quot;degrees&quot; ;

    double grid_center_lon(grid_size) ;
      grid_center_lon:units = &quot;degrees&quot; ;

    double grid_corner_lat(grid_size,grid_corners) ;
      grid_corner_lat:units = &quot;degrees&quot; ;

    double grid_corner_lon(grid_size,grid_corners) ;
      grid_corner_lon:units = &quot;degrees&quot; ;

    int grid_dims(grid_rank) ;

    int grid_imask(grid_size) ;
} // group /

zender@aerosol:~$ ncks -m ~/grd_ugrid.nc 
netcdf grd_ugrid {
  dimensions:
    maxNodesPerFace = 4 ;
    nEdges = 129240 ;
    nFaces = 64800 ;
    nNodes = 64442 ;
    two = 2 ;

  variables:
    int mesh ;
      mesh:cf_role = &quot;mesh_topology&quot; ;
      mesh:standard_name = &quot;mesh_topology&quot; ;
      mesh:long_name = &quot;Topology data&quot; ;
      mesh:topology_dimension = 2 ;
      mesh:node_coordinates = &quot;mesh_node_x mesh_node_y&quot; ;
      mesh:face_node_connectivity = &quot;mesh_face_nodes&quot; ;
      mesh:face_coordinates = &quot;mesh_face_x mesh_face_y&quot; ;
      mesh:face_dimension = &quot;nFaces&quot; ;
      mesh:edge_node_connectivity = &quot;mesh_edge_nodes&quot; ;
      mesh:edge_coordinates = &quot;mesh_edge_x mesh_edge_y&quot; ;
      mesh:edge_dimension = &quot;nEdges&quot; ;

    int mesh_edge_nodes(nEdges,two) ;
      mesh_edge_nodes:cf_role = &quot;edge_node_connectivity&quot; ;
      mesh_edge_nodes:long_name = &quot;Maps every edge to the two nodes that it connects&quot; ;
      mesh_edge_nodes:start_index = 0 ;

    double mesh_edge_x(nEdges) ;
      mesh_edge_x:standard_name = &quot;longitude&quot; ;
      mesh_edge_x:long_name = &quot;Characteristic longitude of 2D mesh face&quot; ;
      mesh_edge_x:units = &quot;degrees_east&quot; ;

    double mesh_edge_y(nEdges) ;
      mesh_edge_y:standard_name = &quot;latitude&quot; ;
      mesh_edge_y:long_name = &quot;Characteristic latitude of 2D mesh face&quot; ;
      mesh_edge_y:units = &quot;degrees_north&quot; ;

    int mesh_face_nodes(nFaces,maxNodesPerFace) ;
      mesh_face_nodes:cf_role = &quot;face_node_connectivity&quot; ;
      mesh_face_nodes:long_name = &quot;Maps every face to its corner nodes&quot; ;
      mesh_face_nodes:start_index = 0 ;
      mesh_face_nodes:_FillValue = -2147483648 ;

    double mesh_face_x(nFaces) ;
      mesh_face_x:standard_name = &quot;longitude&quot; ;
      mesh_face_x:long_name = &quot;Characteristic longitude of 2D mesh edge&quot; ;
      mesh_face_x:units = &quot;degrees_east&quot; ;

    double mesh_face_y(nFaces) ;
      mesh_face_y:standard_name = &quot;latitude&quot; ;
      mesh_face_y:long_name = &quot;Characteristic latitude of 2D mesh edge&quot; ;
      mesh_face_y:units = &quot;degrees_north&quot; ;

    double mesh_node_x(nNodes) ;
      mesh_node_x:standard_name = &quot;longitude&quot; ;
      mesh_node_x:long_name = &quot;Longitude of mesh nodes&quot; ;
      mesh_node_x:units = &quot;degrees_east&quot; ;

    double mesh_node_y(nNodes) ;
      mesh_node_y:standard_name = &quot;latitude&quot; ;
      mesh_node_y:long_name = &quot;Latitude of mesh nodes&quot; ;
      mesh_node_y:units = &quot;degrees_north&quot; ;
} // group /
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;skl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#skl --&gt;
&lt;a name=&quot;skeleton&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#skeleton --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="740">skeleton</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="741"><code>--rgr skl</code></indexterm></cindex>
<para>Another task that arises in regridding is characterizing new grids.
In such cases it can be helpful to have a &textldquo;skeleton&textrdquo; version of a
dataset on the grid, so that grid center and interfaces locations can be
assessed, continental outlines can be examined, or the skeleton can be
manually populated with data rather than relying on a model.
<acronym><acronymword>SCRIP</acronymword></acronym> files can be difficult to visualize and manipulate, so 
<acronym><acronymword>NCO</acronymword></acronym> will provide, if requested, a so-called skeleton file on
the user-specified grid.
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.5.3</w>, released in October, 2015,
the <samp>--rgr skl=<var>fl_skl</var></samp> switch outputs the skeleton file to
<var>fl_skl</var>.
The skeleton file may then be examined in a dataset viewer, populated
with data, and generally serve as a template for what to expect from
datasets of the same geometry.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Generate T42 Gaussian grid file t42_SCRIP.nc and skeleton file t42_skl.nc
ncks --rgr skl=${DATA}/grids/t42_skl.nc --rgr scrip=${DATA}/grids/t42_SCRIP.nc \
     --rgr latlon=64,128#lat_typ=gss#lon_typ=Grn_ctr \
     ~zender/nco/data/in.nc ~/foo.nc
</verbatim>
</example>
<para>When generating skeleton files, both the grid file (<file>t42_SCRIP.nc</file>)
and the skeleton file (<file>t42_skl.nc</file>) are written, the input file
(<file>in.nc</file>) is ignored, and the output file (<file>foo.nc</file>) is
overwritten (its contents are immaterial). 
</para>
<html endspaces=" ">
&lt;a name=&quot;map&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#map --&gt;
&lt;a name=&quot;esmf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#esmf --&gt;
&lt;a name=&quot;tr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tr --&gt;
&lt;a name=&quot;tempest&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tempest --&gt;
&lt;a name=&quot;scrip&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#scrip --&gt;
&lt;a name=&quot;rgr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr --&gt;
&lt;a name=&quot;rgr_map&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr_map --&gt;
&lt;a name=&quot;regrid&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#regrid --&gt;
</html>
</section>
<node name="Regridding" spaces=" "><nodename>Regridding</nodename><nodenext spaces=" ">Climatology and Bounds Support</nodenext><nodeprev spaces=" ">Grid Generation</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Regridding</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="742">map</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="743">grid-file</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="744">map-file</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="745">regridding</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="746"><code>--map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="747"><acronym><acronymword>ESMF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="748"><acronym><acronymword>MOAB</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="749"><acronym><acronymword>TR</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="750"><acronym><acronymword>SCRIP</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="751">TempestRemap</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="752">OpenMP</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="753"><code>--rgr <var>key</var>=<var>val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="754"><code>--rgr_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="755"><var>&textndash;map-file</var></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncclimo</command>, <command>ncks</command>, <command>ncremap</command>&linebreak;
Short options: None&linebreak;
Long options: 
<samp>--map <var>map-file</var></samp> or <samp>--rgr_map <var>map-file</var></samp>&linebreak;
<samp>--rgr <var>key</var>=<var>val</var></samp> (multiple invocations allowed)&linebreak;
<samp>--rnr=<var>rnr_thr</var></samp> or <samp>--rgr_rnr=<var>rnr_thr</var></samp> or 
<samp>--renormalize=<var>rnr_thr</var></samp> or
<samp>--renormalization_threshold=<var>rnr_thr</var></samp>&linebreak;
</para></cartouche>

<para><acronym><acronymword>NCO</acronymword></acronym> includes extensive regridding features in 
<command>ncclimo</command> (as of version 4.6.0 in May, 2016),
<command>ncremap</command> (as of version 4.5.4 in November, 2015)
and <command>ncks</command> (since version 4.5.0 in June, 2015). 
Regridding can involve many choices, options, inputs, and outputs.
The appropriate operator for this workflow is the <command>ncremap</command>
script which automatically handles many details of regridding and
passes the required commands to <command>ncks</command> and external programs.
Occasionally users need access to lower-level remapping functionality
present in <command>ncks</command> and not exposed to direct manipulation
through <command>ncremap</command> or <command>ncclimo</command>.
This section describes the lower-level functionality and switches
as implemented in <command>ncks</command>.
Knowing what these features are will help <command>ncremap</command> and
<command>ncclimo</command> users understand the full potential of these
operators. 
</para>
<para><command>ncks</command> supports horizontal regridding of datasets where the
grids and weights are all stored in an external <var>map-file</var>.
Use the <samp>--map</samp> or <samp>--rgr_map</samp> options to specify the
<var>map-file</var>, and <acronym><acronymword>NCO</acronymword></acronym> will regrid the <var>input-file</var> to
a new (or possibly the same, aka, an identity mapping) horizontal grid
in the <var>output-file</var>, using the input and output grids and mapping
weights specified in the <acronym><acronymword>ESMF</acronymword></acronym>- or <acronym><acronymword>SCRIP</acronymword></acronym>-format
<var>map-file</var>. 
Currently <acronym><acronymword>NCO</acronymword></acronym> understands the mapfile formats pioneered
by <acronym><acronymword>SCRIP</acronymword></acronym> 
(<url><urefurl>http://oceans11.lanl.gov/svn/SCRIP/trunk/SCRIP</urefurl></url>)
and later extended by <acronym><acronymword>ESMF</acronymword></acronym> 
(<uref><urefurl>http://www.earthsystemcog.org/projects/regridweightgen</urefurl></uref>),
and adopted (along with Exodus) by TempestRemap
(<uref><urefurl>https://github.com/ClimateGlobalChange/tempestremap.git</urefurl></uref>).
Those references document quirks in their respectively
weight-generation algorithms as to map formats, grid specification,
and weight generation.
<acronym><acronymword>NCO</acronymword></acronym> itself produces map-files in the format recommended by
<acronym><acronymword>CMIP6</acronymword></acronym> and described  
<uref><urefurl>https://docs.google.com/document/d/1BfVVsKAk9MAsOYstwFSWI2ZBt5mrO_Nmcu7rLGDuL08</urefurl><urefdesc spaces="\n">here</urefdesc></uref>.
This format differs from <acronym><acronymword>ESMF</acronymword></acronym> map-file format chiefly in
that its metadata are slightly more evolved, self-descriptive, and
standardized.
</para>
<para>Originally <acronym><acronymword>NCO</acronymword></acronym> supported only weight-application, which is
what most people mean by &textldquo;regridding&textrdquo;. 
As of <w>version 4.9.0</w>, released in December, 2019, <acronym><acronymword>NCO</acronymword></acronym>
also supports weight-generation by its own conservative algorithm.
Thus <acronym><acronymword>NCO</acronymword></acronym> can now apply weights generated by <acronym><acronymword>ESMF</acronymword></acronym>, 
<acronym><acronymword>NCO</acronymword></acronym>, <acronym><acronymword>SCRIP</acronymword></acronym>, and TempestRemap.
<acronym><acronymword>NCO</acronymword></acronym> reads-in pre-stored weights from the <var>map-file</var> and
applies them to (almost) every variable, thereby creating a regridded
<var>output-file</var>. 
Specify regridding with a standard <command>ncks</command> command and options
along with the additional specification of a <var>map-file</var>: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Regrid entire file, same output format as input:
ncks --map=map.nc in.nc out.nc
# Entire file, netCDF4 output:
ncks -4 --map=map.nc in.nc out.nc
# Deflated netCDF4 output
ncks -4 -L 1 --map=map.nc in.nc out.nc
# Selected variables
ncks -v FS.?,T --map=map.nc in.nc out.nc
# Threading
ncks -t 8 --map=map.nc in.nc out.nc
# Deflated netCDF4 output, threading, selected variables:
ncks -4 -L 1 -t 8 -v FS.?,T --map=map.nc in.nc out.nc
</verbatim>
</example>
<para>OpenMP threading works well with regridding large datasets.
Threading improves throughput of regridding <w>1&textndash;10 GB</w> files by 
factors of 2&textndash;5.
Options specific to regridding are described below.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="756">equiangular grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="757">Gaussian grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="758">cubed-sphere grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="759"><acronym><acronymword>FV</acronymword></acronym> grid</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> supports 1D&result;1D, 1D&result;2D, 2D&result;1D, and
2D&result;2D regridding for any unstructured 
1D-grid and any rectangular 2D-grid.  
This has been tested by converting among and between Gaussian,
equiangular, <acronym><acronymword>FV</acronymword></acronym>, unstructured cubed-sphere grids, and
regionally refined grids.
Support for irregular 2D- and regional grids (e.g., swath-like data) is
planned.  
</para>
<unnumberedsubsec spaces=" "><sectiontitle>Renormalization</sectiontitle>
<html endspaces=" ">
&lt;a name=&quot;rnr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rnr --&gt;
&lt;a name=&quot;renormalize&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#renormalize --&gt;
&lt;a name=&quot;renormalization_threshold&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#renormalization_threshold --&gt;
&lt;a name=&quot;rgr_rnr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr_rnr --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="760">conservative regridding</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="761">renormalized regridding</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="762">missing values</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="763">data, missing</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="764"><code>missing_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="765"><code>_FillValue</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="766"><code>--rnr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="767"><code>--renormalize</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="768"><code>--renormalization_threshold</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="769"><code>--rgr_rnr</code></indexterm></cindex>
<para>Conservative regridding is, for first-order accurate algorithms,
a straightforward procedure of identifying gridcell overlap and
apportioning values correctly from source to destination.
The presence of missing values forces a decision on how to handle
destination gridcells where some but not all source cells are valid. 
<acronym><acronymword>NCO</acronymword></acronym> allows the user to choose between two distinct
weight-application algorithms:
&textldquo;conservative&textrdquo; and &textldquo;renormalized&textrdquo;.
The &textldquo;conservative&textrdquo; algorithm uses all valid data from the input grid
on the output grid once and only once.
Destination cells receive the weighted valid values of the source cells.
This is conservative because the global integrals of the source and
destination fields are equal.
Another name for the &textldquo;conservative&textrdquo; weight-application method is
therefore &textldquo;integral-preserving&textrdquo;.
The &textldquo;renormalized&textrdquo; algorithm divides the destination value by the sum
of the valid weights.
This produces values equal to the mean of the valid input values, but
extended to the entire destination gridcell. 
Thus renormalization is equivalent to extrapolating valid data to
missing regions.  
Another name for the &textldquo;renormalized&textrdquo; weight-application method is
therefore &textldquo;mean-preserving&textrdquo;.
Input and output integrals are unequal and renormalized regridding is
not conservative. 
Both algorithms produce identical answers when no missing data maps to 
the destination gridcell.
</para>
<para>The renormalized algorithm is useful because it solves some problems,
like producing physically unrealistic temperature values, at the expense
of incurring others, like non-conservation.
Many land and ocean modelers eschew unrealistic gridpoint values, and
conservative weight-application often produces &textldquo;weird&textrdquo; values along
coastlines or missing data gaps where state variables are regridded
to/from small fractions of a gridcell.
Renormalization ensures the output values are physically consistent,
although the integral of their value times area is not preserved.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="770"><var>rnr_thr</var></indexterm></cindex>
<para>By default, <acronym><acronymword>NCO</acronymword></acronym> implements the &textldquo;conservative&textrdquo; algorithm
because it has useful properties, is simpler to understand, and requires
no additional parameters.
To employ the &textldquo;renormalized&textrdquo; algorithm instead, use the <samp>--rnr</samp>,
<samp>--rgr_rnr</samp>, <samp>--rnr_thr</samp>, or <samp>--renormalize</samp> options to
supply <var>rnr_thr</var>, the threshold weight for valid destination values.
Valid values must cover at least the fraction <var>rnr_thr</var> of the
destination gridcell to meet the threshold for a non-missing destination
value. 
When <var>rnr_thr</var> is exceeded, the mean valid value is renormalized by
the valid area and placed in the destination gridcell. 
If the valid area covers less than <var>rnr_thr</var>, then the destination
gridcell is assigned the missing value.
Valid values of <var>rnr_thr</var> range from zero to one.
Keep in mind though, that this threshold is potentially a divisor, and 
values of zero or very near to zero can lead to floating-point underflow
and divide-by-zero errors.
For convenience <acronym><acronymword>NCO</acronymword></acronym> permits users to specify a 
<math><var>rnr_thr</var> = 0.0</math> threshold weight.
This indicates that any valid data should be represented and
renormalized on the output grid. 
Also, renormalization can be explicitly prevented or turned-off by
setting <var>rnr_thr</var> to either of the values <samp>off</samp> or <samp>none</samp>: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks           --map=map.nc in.nc out.nc # Conservative (global integral-preserving)
ncks --rnr=off --map=map.nc in.nc out.nc # Conservative (global integral-preserving)
ncks --rnr=0.1 --map=map.nc in.nc out.nc # Renormalized (local mean-preserving with threshold)
ncks --rnr=0.0 --map=map.nc in.nc out.nc # Renormalized (local mean-preserving)
</verbatim>
</example>
<para>The first and second examples use the default conservative algorithm.
The third example specifies that valid values must cover at least 10%
of the destination gridcell to meet the threshold for a non-missing
destination value. 
With valid destination areas of, say 25% or 50%, the renormalized
algorithm would produce destination values greater than the conservative
algorithm by factors of four or two, respectively.
</para>
<para>In practice, it may make sense to use the default &textldquo;conservative&textrdquo;
algorithm when performing conservative regridding, and the
&textldquo;renormalized&textrdquo; algorithm when performing other regridding such as
bilinear interpolation or nearest-neighbor.
Another consideration is whether the fields being regridded are fluxes
or state variables. 
For example, temperature (unlike heat) and concentrations (amount per
unit volume) are not physically conserved quantities under
areal-regridding so it often makes sense to interpolate them in a 
non-conservative fashion, to preserve their fine-scale structure. 
Few researchers can digest the unphysical values of temperature that the  
&textldquo;conservative&textrdquo; option will produce in regions rife with missing
values.
A counter-example is fluxes, which should be physically conserved under 
areal-regridding.
One should consider both the type of field and its conservation
properties when choosing a regridding strategy.
</para>

<tex endspaces=" ">
The regridded value of a variable $\xxx$ at a destination location
$\ddd$ can be generally represented as
$$
\xxx_{\ddd} = {\sum_{\sss=1}^{\sss=\lmnnbr}
\mssflg_{\sss} \sigma_{\sss,\ddd} \xxx_{\sss} \over
\sum_{\sss=1}^{\sss=\lmnnbr} \mssflg_{\sss} \sigma_{\sss,\ddd}}  
$$
where $\xxx_{\ddd}$ is the $\ddd$'th element of the regridded
variable, $\xxx_{\sss}$ is the $\sss$'th element of the raw (native grid)
variable, $\mssflg_{\sss} = 1$ if $\xxx_{\sss}$ is valid and
$\mssflg_{\sss} = 0$ if $\xxx_{\sss}$ is the missing value, and
$\sigma_{\sss,\ddd}$ is the overlap weight of $\sss$'th source gridcell
with the $\ddd$'th destination gridcell, and $\lmnnbr$ is the
total number of source gridcells that overlap (partially or fully)
with the destination gridcell.

The number of overlap gridcells $\lmnnbr$ is a property of the source
and destination grids and the regridding algorithm.
The weight-generation software determines $\lmnnbr$ by
``intersecting'' the grids, taking into account higher-order
(e.g., local gradient) contributions if the algorithm so-demands,
and then generates the overlap weights $\sigma_{\sss,\ddd}$
accordingly.  
Both source and destination grids may indicate valid gridcells with
a mask flag that is binary-valued, zero or one, such that
$\mskflg_{\sss} = 1$ (i.e., unmasked) for source gridcells allowed to
contribute to the destination grid, and $\mskflg_{\sss} = 0$ (i.e.,
masked) for gridcells that are forbidden from contributing to the
destination grid. 
There are subtle distinctions between the mask flag $\mskflg_{\sss}$,
and the missing value flag $\mssflg_{\sss}$.
The mask flag $\mskflg_{\sss}$ does not appear in the formula above
because the weight-generator produces no weights for masked source
gridcells.
Doing otherwise would waste storage space in the map-file, because
such weights are, by definition, zero.
Furthermore the masks $\mskflg_{\sss}$ and $\mskflg_{\ddd}$ are 
time-invariant properties of the grids, whereas missing value fields
$\mssflg_{\sss}$ (and thus $\mssflg_{\ddd}$) are potentially
time-varying characteristics of the fields.
Although $\mssflg_{\sss}$ should in theory be treated the same as
$\mskflg_{\sss}$ when computing mapping weights $\sigma_{\sss,\ddd}$,
in practice this is not done.
Different fields may have different patterns of missing values,
and managing per-field map-files would be difficult, so traditionally 
all fields are remapped with the same map-file.
That said, it can make sense to treat flux fields and state-variable
fields with distinct algorithms, so that a different map-file might
be employed for each class of fields.

The weight-generation software normalizes $\sigma_{\sss,\ddd}$
such that $\sum_{\sss=1}^{\sss=\lmnnbr} \sigma_{\sss,\ddd} = 1$
when unmasked ($\mskflg_{\sss}=1$) source gridcells completely overlap
the destination gridcell. 
In this case we also have
$\sum_{\sss=1}^{\sss=\lmnnbr} \mskflg_{\sss} = \lmnnbr$.
Furthermore, if all contributing gridpoints are valid values
(i.e., not missing values) then $\mssflg_{\sss} = 1$ so that
$\sum_{\sss=1}^{\sss=\lmnnbr} \mssflg_{\sss} = \lmnnbr$.
For complete overlap with no masked values and no missing values,
then $\mssflg_{\sss} = \mskflg_{\sss} = \sum\sigma_{\sss,\ddd} = 1$
and the generic averaging expression above reduces to a simple
weighted mean
$\xxx_{\ddd} = \sum_{\sss=1}^{\sss=\lmnnbr} \sigma_{\sss,\ddd} \xxx_{\sss}$.

$$
\xxx_{\ddd} = {\sum_{\sss=1}^{\sss=\lmnnbr} \mssflg_{\sss}
\frcsgs_{\sss} \sigma_{\sss,\ddd} \xxx_{\sss} \over
\sum_{\sss=1}^{\sss=\lmnnbr} \mssflg_{\sss} \frcsgs_{\sss} \sigma_{\sss,\ddd}}  
$$
</tex>

</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Regridder Options Table</sectiontitle>
<html endspaces=" ">
&lt;a name=&quot;rgr_tbl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr_tbl --&gt;
</html>
<para><acronym><acronymword>NCO</acronymword></acronym> automatically annotates the output with relevant metadata
such as coordinate bounds, axes, and vertices (<w><accent type="grave">a</accent> la</w> <acronym><acronymword>CF</acronymword></acronym>). 
These annotations include
</para><table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="771"><var>lat_dmn_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="772"><var>lon_dmn_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="773"><samp>--rgr lon_dmn_nm=<var>lon_dmn_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="774"><samp>--rgr lat_dmn_nm=<var>lat_dmn_nm</var></samp></indexterm></cindex>
<item spaces=" "><itemformat command="dfn">Horizontal Dimension Names: <var>lat_dmn</var>, <var>lon_dmn</var></itemformat></item>
</tableterm><tableitem>    <para>The name of the horizontal spatial dimensions assumed to represent
    latitude and longitude in 2D rectangular input files are
    <var>lat_dmn_nm</var> and <var>lon_dmn_nm</var>, which default to <code>lat</code>
    and <code>lon</code>, respectively.  
    Variables that contain a <var>lat_dmn_nm</var>-dimension and a
    <var>lon_dmn_nm</var>-dimension on a 2D-rectangular input grid will be 
    regridded, and variables regridded to a 2D-rectangular output grid 
    will all contain the <var>lat_dmn_nm</var>- and <var>lon_dmn_nm</var>-dimensions.
    To treat different dimensions as latitude and longitude, use the
    options <samp>--rgr lat_dmn_nm=<var>lat_dmn_nm</var></samp> and
    <samp>--rgr lon_dmn_nm=<var>lon_dmn_nm</var></samp>.  
    These options applied only to inferring and generating grids until
    <acronym><acronymword>NCO</acronymword></acronym> version 4.7.9 (February, 2019).
    Since then, these options also determine the dimension names in
    regridded output files. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="775"><var>lat_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="776"><var>lon_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="777"><samp>--rgr lon_nm=<var>lon_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="778"><samp>--rgr lat_nm=<var>lat_nm</var></samp></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Horizontal Coordinate Names: <var>lat</var>, <var>lon</var></itemformat></item>
</tableterm><tableitem>    <para>The name of the horizontal spatial coordinates that represent
    latitude and longitude in input files are <var>lat_nm</var> and
    <var>lon_nm</var>, and default to <code>lat</code> and <code>lon</code>,
    respectively.  
    Variables that contain a <var>lat_dmn_nm</var>-dimension and a
    <var>lon_dmn_nm</var>-dimension on a 2D input grid will be 
    regridded, and output regridded variables will all contain the 
    <var>lat_nm</var>- and <var>lon_nm</var>-variables.
    Unless the <var>lat_dmn_nm</var>- and <var>lon_dmn_nm</var>-dimensions
    are explicitly configured otherwise, they will share the same
    name as the <var>lat_nm</var>- and <var>lon_nm</var>-variables.
    Thus variables regridded to a 2D-rectangular output grid usually
    have <var>lat_nm</var>- and <var>lon_nm</var> as coordinate variables.
    Variables regridded to a 1D-unstructured output grid will have
    <var>lat_nm</var> and <var>lon_nm</var> as auxiliary coordinate variables.
    Variables regridded to a 2D-curvilinear output grid will have
    <var>lat_nm</var> and <var>lon_nm</var> as multi-dimensional auxiliary
    coordinate variables.
    To treat different variables as latitude and longitude, use the
    options <samp>--rgr lat_nm=<var>lat_nm</var></samp> and
    <samp>--rgr lon_nm=<var>lon_nm</var></samp>.   
    Before <acronym><acronymword>NCO</acronymword></acronym> version 4.7.9 (February, 2019), <var>lat_nm</var>
    and <var>lon_nm</var> specified both the variable names <emph>and</emph>,
    where applicable (i.e., on 2D-grids), the dimensions of the
    horizontal coordinates in output files.
    Now the horizontal variable and dimension names in output files
    may be separately specified.
<cindex index="cp" spaces=" "><indexterm index="cp" number="779"><code>ncol</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="780"><var>col_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="781"><samp>--rgr col_nm=<var>col_nm</var></samp></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Unstructured Dimension Name: <var>col</var></itemformat></item>
</tableterm><tableitem>    <para>The name of the horizontal spatial dimension assumed to delineate
    an unstructured grid is <var>col_nm</var>, which defaults to <code>ncol</code>
    (number of columns), the name <acronym><acronymword>CAM</acronymword></acronym> employs.
    Other common names for the columns in an unstructured grid include
    <code>lndgrid</code> (used by <acronym><acronymword>CLM</acronymword></acronym>), and <code>nCells</code> (used by 
    <acronym><acronymword>MPAS-O</acronymword></acronym>). 
    Variables that contain the <var>col_nm</var>-dimension on an
    unstructured input grid will be regridded, and regridded variables
    written to an unstructured output grid will all contain the 
    <var>col_nm</var>-dimension.
    To treat a different dimension as unstructured, use the option
    <samp>--rgr col_nm=<var>col_nm</var></samp>. 
    Note: Often there is no coordinate variable for the
    <var>col_nm</var>-dimension, i.e., there is no variable named
    <var>col_nm</var>, although such a coordinate could contain useful
    information about the unstructured grid.
<cindex index="cp" spaces=" "><indexterm index="cp" number="782"><acronym><acronymword>CF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="783"><code>latitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="784"><code>longitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="785"><code>axes</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="786"><code>standard_name</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="787"><code>degrees_east</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="788"><code>degrees_north</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="789"><code>units</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="790"><code>X</code> axis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="791"><code>Y</code> axis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="792">auxiliary coordinates</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Structured Grid Standard Names and Units</itemformat></item>
</tableterm><tableitem>    <para>Longitude and latitude coordinates (both regular and auxiliary,
    i.e., for unstructured grids) receive <acronym><acronymword>CF</acronymword></acronym>
    <code>standard_name</code> values of <code>latitude</code> and <code>longitude</code>,
    <acronym><acronymword>CF</acronymword></acronym> <code>axes</code> attributes with values <code>X</code> and
    <code>Y</code>, and <code>units</code> attributes with values
    <code>degrees_east</code> and <code>degrees_north</code>, respectively.
<cindex index="cp" spaces=" "><indexterm index="cp" number="793"><code>lat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="794"><code>lon</code></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Unstructured Grid Auxiliary Coordinates</itemformat></item>
</tableterm><tableitem>    <para>Unstructured grid auxiliary coordinates for longitude and latitude
    receive <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code> attributes with values
    <code>lon</code> and <code>lat</code>, respectively.
<cindex index="cp" spaces=" "><indexterm index="cp" number="795"><code>lon_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="796"><code>lat_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="797"><code>nbnd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="798"><code>time_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="799"><var>lat_bnd_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="800"><var>lon_bnd_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="801"><samp>--rgr lat_bnd_nm=<var>lat_bnd_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="802"><samp>--rgr lon_bnd_nm=<var>lon_bnd_nm</var></samp></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Structured Grid Bounds Variables: <var>bnd</var>, <var>lat_bnd</var>, <var>lon_bnd</var></itemformat></item>
</tableterm><tableitem>    <para>Structured grids with 1D-coordinates use the dimension
    <var>bnd_nm</var> (which defaults to <code>nbnd</code>) with the spatial bounds
    variables in <var>lat_bnd_nm</var> and <var>lon_bnd_nm</var> which default to
    <code>lon_bnds</code> and <code>lat_bnds</code>, respectively.
    By default spatial bounds for such structured grids parallel the
    oft-used temporal bounds dimension (<code>nbnd=2</code>) and variable 
    (<code>time_bnds</code>).
    Bounds are attached to the horizontal spatial dimensions via their
    <code>bounds</code> attributes. 
    Change the spatial bounds dimension with the option 
    <samp>--rgr bnd_nm=<var>bnd_nm</var></samp>.
    Rename the spatial bounds variables with the options 
    <samp>--rgr lat_bnd_nm=<var>lat_bnd_nm</var></samp> and 
    <samp>--rgr lon_bnd_nm=<var>lon_bnd_nm</var></samp>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="803"><code>lat_vertices</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="804"><code>lon_vertices</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="805"><code>nv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="806"><code>bounds</code></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Unstructured Grid Bounds Variables: <var>bnd</var>, <var>lat_bnd</var>, <var>lon_bnd</var> </itemformat></item>
</tableterm><tableitem>    <para>Unstructured grids with 1D-coordinates use the dimension
    <var>bnd_nm</var> (which defaults to <code>nv</code>, number of vertices) 
    for the spatial bounds variables <var>lat_bnd_nm</var> and
    <var>lon_bnd_nm</var> which default to <code>lat_vertices</code> and
    <code>lon_vertices</code>, respectively. 
    It may be impossible to re-use the temporal bounds dimension (often
    <code>nbnd</code>) for unstructure grids, because the gridcells are not
    rectangles, and thus require specification of all vertices for each
    gridpoint, rather than only two parallel interfaces per dimension.
    These bounds are attached to the horizontal spatial dimensions
    via their <code>bounds</code> attributes.
    Change the spatial bounds dimension with the option 
    <samp>--rgr bnd_nm=<var>bnd_nm</var></samp>.
    Rename the spatial bounds variables with the options 
    <samp>--rgr lat_bnd_nm=<var>lat_bnd_nm</var></samp> and
    <samp>--rgr lon_bnd_nm=<var>lon_bnd_nm</var></samp>.
    The temporal bounds dimension in unstructured grid output remains as
    in the <var>input-file</var>, usually <code>nbnd</code>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="807"><var>lev_dmn_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="808"><var>ilev_dmn_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="809"><samp>--rgr ilev_dmn_nm=<var>ilev_dmn_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="810"><samp>--rgr lev_dmn_nm=<var>lev_dmn_nm</var></samp></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Vertical Dimension Names: <var>lev_dmn</var>, <var>ilev_dmn</var></itemformat></item>
</tableterm><tableitem>    <para>The name of the dimension(s) associated with the vertical
    coordinate(s) in multi-level input files are <var>lev_dmn_nm</var> and
    <var>ilev_dmn_nm</var>, which default to <code>lev</code> and <code>ilev</code>,
    respectively.
    Variables that contain a <var>lev_dmn_nm</var>-dimension or an
    <var>ilev_dmn_nm</var>-dimension will be vertically interpolated to the 
    specified (with <samp>vrt_out=<var>vrt_fl</var></samp>) vertical output grid,
    and will all contain the <var>lev_dmn_nm</var>- and, for
    hybrid-sigma/pressure interface variables,
    <var>ilev_dmn_nm</var>-dimensions.
    To treat different dimensions as the midlayer and interface level
    dimensions, use the options <samp>--rgr lev_dmn_nm=<var>lev_dmn_nm</var></samp>
    and <samp>--rgr ilev_dmn_nm=<var>ilev_dmn_nm</var></samp> options.
    Pure-pressure grids should use the
    <samp>--rgr lev_dmn_nm=<var>lev_dmn_nm</var></samp> option (to reduce option
    proliferation, there is no <var>plev_dmn_nm</var> option).
    These options were introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.9.0 (December, 2019).
    These options also determine the vertical dimension names in
    vertically interpolated output files. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="811"><var>lev_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="812"><var>ilev_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="813"><var>plev_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="814"><samp>--rgr lev_nm=<var>lev_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="815"><samp>--rgr ilev_nm=<var>ilev_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="816"><samp>--rgr plev_nm=<var>plev_nm</var></samp></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Vertical Coordinate Names: <var>lev</var>, <var>ilev</var>, <var>plev</var></itemformat></item>
</tableterm><tableitem>    <para>The name of the vertical coordinate variables that represent
    midpoint levels and interface levels in hybrid-sigma/pressuure
    input files are <var>lev_nm</var> and <var>ilev_nm</var>, and default to
    <code>lev</code> and <code>ilev</code>, respectively.  
    While the vertical coordinate in pure-pressure vertical grid files
    (i.e., the template-file to which data will be interpolated) must 
    be named <code>plev</code>, the vertical coordinate in pure-pressure
    <emph>data</emph> files (i.e., the files to be interpolated) may be
    changed with the <samp>--rgr plev_nm=<var>plev_nm</var></samp> option.
    The name of the vertical coordinate variable that represents
    pressure levels in pure-pressure grid input data files is
    <var>plev_nm</var>, and it defaults to <code>plev</code>.
    To reduce proliferation of command-line options and internal code 
    complexity, the variable and dimension options for pure-pressure
    vertical coordinate output names re-use the &textldquo;lev&textrdquo; options, i.e.,
    <samp>--rgr lev_nm_out=<var>lev_nm_out</var></samp> option.
    Variables that contain a <var>lev_dmn_nm</var>-dimension or a
    <var>ilev_dmn_nm</var>-dimension on hybrid-sigma/pressure input grid,
    or a <var>plev_dmn_nm</var>-dimension on a pure pressure grid,
    will be regridded, and output in vertically interpolated files on
    a hybrid-sigma/pressure grid will all contain the <var>lev_nm</var>-
    and <var>ilev_nm</var>-variables, and output on a pure-pressure grid
    will contain the <var>lev_nm</var> coordinate.
    Unless the <var>lev_dmn_nm</var> and <var>ilev_dmn_nm</var> dimensions
    are explicitly configured otherwise, they will share the same
    name as the <var>lev_nm</var>/<var>plev_nm</var> and
    <var>ilev_nm</var>-variables, respectively.
    Thus variables regridded to a hybrid-sigma/pressure output grid
    usually have <var>lev_nm</var>- and <var>ilev_nm</var> as coordinate
    variables. 
    Variables regridded to a pure-pressure output grid will only have 
    a single vertical coordinate variable, <var>lev_nm</var>, which will be
    an associated coordinate variable if <var>lev_dmn_nm</var> differs from
    <var>lev_nm</var>.
    To treat different variables as level and interface-level
    coordinates, use the options <samp>--rgr lev_nm=<var>lev_nm</var></samp> and 
    <samp>--rgr ilev_nm=<var>ilev_nm</var></samp>.   
    Before <acronym><acronymword>NCO</acronymword></acronym> version 4.9.0 (December, 2019), <var>lev_nm</var>
    and <var>ilev_nm</var> specified both the variable names <emph>and</emph>,
    where applicable (i.e., on 2D-grids), the dimensions of the
    vertical coordinates in output files.
    Now the vertical variable and dimension names in output files
    may be separately specified.
<cindex index="cp" spaces=" "><indexterm index="cp" number="817"><var>ps_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="818"><samp>--rgr ps_nm=<var>ps_nm</var></samp></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Surface Pressure Names: <var>ps</var>, <var>PS</var></itemformat></item>
</tableterm><tableitem>    <para>The name of the surface pressure field necessary to reconstruct
    the layer pressures in the hybrid-sigma/pressure coordinate system 
    is <var>ps_nm</var> which defaults to <code>PS</code>.
    As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.1.2</w>, released in November, 2022,
    one may change this with the <samp>--rgr ps_nm=<var>ps_nm</var></samp> option.
    There are, in fact, three similar options, one each for the
    surface pressure variable in the input data file, the vertical
    grid file, and in the output (interpolated file).
    The full option key names are <code>ps_nm</code> (equivalent to
    <code>ps_nm_in</code>), <code>ps_nm_tpl</code>, and <code>ps_nm_out</code>,
    respectively.
<cindex index="cp" spaces=" "><indexterm index="cp" number="819"><code>area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="820"><code>cell_methods</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="821"><code>cell_area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="822"><code>steradian</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="823"><samp>--no_cll_msr</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="824"><samp>--rgr no_area_out</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="825"><samp>--rgr no_area</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="826"><samp>--rgr area_out=<var>area_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="827"><var>area_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="828"><acronym><acronymword>SI</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="829">solid angle</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="830">extensive variable</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Gridcell Area: <var>area</var></itemformat></item>
</tableterm><tableitem>    <para>The variable <var>area_nm</var> (which defaults to <code>area</code>) is, by 
    default, (re-)created in the <var>output_file</var> to hold the gridcell 
    area in steradians.     
    To store the area in a different variable, use the option
    <samp>--rgr area=<var>area_nm</var></samp>.
    The <var>area_nm</var> variable receives a <code>standard_name</code> attribute 
    of <code>cell_area</code>, a <code>units</code> attribute of <code>steradian</code>
    (the <acronym><acronymword>SI</acronymword></acronym> unit of solid angle),
    and a <code>cell_methods</code> attribute with value <code>lat, lon: sum</code>,
    which indicates that <var>area_nm</var> is <dfn>extensive</dfn>, meaning 
    that its value depends on the gridcell boundaries.  
    Since <var>area_nm</var> is a property of the grid, it is read directly
    from the <var>map-file</var> rather than regridded itself. 
    To omit the area variable from the output file, set the
    <var>no_area_out</var> flag.
    The <code>--no_cll_msr</code> switch to <command>ncremap</command> and
    <command>ncclimo</command> does this automatically.
<cindex index="cp" spaces=" "><indexterm index="cp" number="831"><code>frc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="832"><samp>--rgr frc_nm=<var>frc_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="833"><var>frc_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="834">extensive variable</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Gridcell Fraction: <var>frc</var></itemformat></item>
</tableterm><tableitem>    <para>The variable <var>frc_nm</var> (which defaults to <code>frac_b</code>) is
    automatically copied to the <var>output_file</var> to hold the valid
    fraction of each gridcell when certain conditions are met.
    First, the regridding method must be conservative.
    Second, at least one value of <var>frc_nm</var> must be non-unity.
    These conditions ensure that whenever fractional gridcells affect
    the regridding, they are also placed in the output file.
    To store the fraction in a different variable, use the option
    <samp>--rgr frc_nm=<var>frc_nm</var></samp>.
    The <var>frc_nm</var> variable receives a <code>cell_methods</code> attribute
    with value <code>lat, lon: sum</code>, which indicates that <var>frc_nm</var>
    is <dfn>extensive</dfn>, meaning that its value depends on the gridcell
    boundaries.   
    Since <var>frc_nm</var> is a property of the grid, it is read directly
    from the <var>map-file</var> rather than regridded itself. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="835"><code>mask</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="836"><samp>--no_msk</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="837"><samp>--no_mask</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="838"><samp>--msk_out</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="839"><samp>--mask_out</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="840"><samp>--rgr no_msk_out</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="841"><samp>--rgr no_mask</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="842"><samp>--rgr msk_nm=<var>msk_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="843">infer</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="844"><var>msk_nm</var></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Gridcell Mask: <var>mask</var></itemformat></item>
</tableterm><tableitem>    <para>The variable <var>msk_nm</var> (which defaults to <code>mask_b</code>) can, if
    present, be copied from the <var>map-file</var> to hold the gridcell mask 
    on the destination grid in <var>output-file</var>.
    To name the mask differently in the output file, use the option <samp>--rgr msk_nm=<var>msk_nm</var></samp>.
    Since <var>msk_nm</var> is a property of the grid, it is read directly
    from the <var>map-file</var> rather than regridded itself.
    To include the mask variable in the output file, set the <var>msk_out</var> flag.
    To omit the mask variable from the output file, set the <var>no_msk_out</var> flag.
    In grid inferral and map-generation modes, this option tells the
    regridder to generate an integer mask map from the variable
    <var>msk_nm</var>. 
    The mask will be one (i.e., points at that location will contribute
    to regridding weights) where <var>msk_nm</var> has valid values. 
    The mask will be zero (i.e., points at that location will not
    contribute to regridding weights) where <var>msk_nm</var> has a missing
    value.
    This feature is useful when creating weights between masked grids,
    e.g., ocean-only points or land-only points.
<cindex index="cp" spaces=" "><indexterm index="cp" number="845"><code>gw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="846"><samp>--rgr lat_weight=<var>lat_wgt_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="847"><var>lat_wgt_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="848">Gaussian weight</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Latitude weights: <var>lat_wgt</var></itemformat></item>
</tableterm><tableitem>    <para>Rectangular 2D-grids use the variable <var>lat_wgt_nm</var>, which
    defaults to <code>gw</code> (originally for &textldquo;Gaussian weight&textrdquo;), to store 
    the 1D-weight appropriate for area-weighting the latitude grid.
    To store the latitude weight in a different variable, use the option
    <samp>--rgr lat_wgt=<var>lat_wgt_nm</var></samp>.
    The <var>lat_wgt_nm</var> variable will not appear in 1D-grid output.
    Weighting statistics by latitude (i.e., by <var>lat_wgt_nm</var> will
    produce the same answers (up-to round-off error) as weighting by
    area (i.e., by <var>area_nm</var>) in grids that have both variables.
    The former requires less memory because <var>lat_wgt_nm</var> is 1D), 
    whereas the latter is more general because <var>area_nm</var> works on
    <emph>any</emph> grid.
<cindex index="cp" spaces=" "><indexterm index="cp" number="849"><code>mapping_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="850"><code>source_file</code></indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Provenance Attributes</itemformat></item>
</tableterm><tableitem>    <para>The <var>map-file</var> and <var>input-file</var> names are stored in the
    <var>output-file</var> global attributes <code>mapping_file</code> and
    <code>source_file</code>, respectively.
<html endspaces=" ">
&lt;a name=&quot;slat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#slat --&gt;
&lt;a name=&quot;slon&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#slon --&gt;
&lt;a name=&quot;stg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#stg --&gt;
&lt;a name=&quot;stagger&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#stagger --&gt;
&lt;a name=&quot;no_stagger&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_stagger --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="851"><code>--no_stg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="852"><code>--no_stagger</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="853"><code>--no_stg_grd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="854"><code>--stg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="855"><code>--stagger</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="856"><code>--stg_grd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="857"><code>slat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="858"><code>slon</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="859"><code>w_stag</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="860"><acronym><acronymword>CAM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="861"><acronym><acronymword>FV</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="862"><acronym><acronymword>AMWG</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="863">staggered-grid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="864">no stagger</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="865">stagger</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Staggered Grid Coordinates and Weights</itemformat></item>
</tableterm><tableitem>    <para>Owing to its heritage as an early <acronym><acronymword>CCM</acronymword></acronym> analysis tool,
    <acronym><acronymword>NCO</acronymword></acronym> tries to create output interoperable with other
    <acronym><acronymword>CESM</acronymword></acronym> analysis tools. 
    Like many models, <acronym><acronymword>CAM</acronymword></acronym> computes and archives thermodynamic
    state variables on gridcell centers, and computes dynamics variables
    (zonal and meridional winds <var>U</var> and <var>V</var>, respectively) on
    gridcell edges (interfaces). 
    The dual-grid, sometimes called the &textldquo;staggered grid&textrdquo;, formed
    by connecting edge centers is thus the natural location for 
    storing output dynamics variables.
    Most dynamical cores of <acronym><acronymword>CAM</acronymword></acronym> archives horizontal winds at
    gridcell centers under the names <code>U</code>, and <code>V</code>.
    For <acronym><acronymword>CAM-FV</acronymword></acronym>, these are interpolated from the computed
    interface winds archived as <code>US</code>, and <code>VS</code> (which are
    on the staggered grid coordinate system). 
    Some analysis packages, such as the <acronym><acronymword>AMWG</acronymword></acronym> diagnostics, 
    require access to these dual-grid coordinates with the names
    <code>slat</code> and <code>slon</code> (for &textldquo;staggered&textrdquo; latitude and
    longitude).
    Until <acronym><acronymword>NCO</acronymword></acronym> version 4.9.8 (released March, 2021),
    the <acronym><acronymword>NCO</acronymword></acronym> regridder output these coordinates,
    along with the latitude weights (called <code>w_stag</code>), by default
    when the input was on a cap (aka <acronym><acronymword>FV</acronymword></acronym>) grid so that the
    result could be processed by <acronym><acronymword>AMWG</acronymword></acronym> diagnostics. 
    Setting the <var>no_stagger</var> flag turns-off archiving the
    staggered grid (i.e., <code>slat</code>, <code>slon</code>, and
    <code>w_stag</code>). 
    Do this with the <code>--no_stg_grd</code> flag in <command>ncremap</command>.
    <command>ncclimo</command> always sets this <code>--no_stagger</code> flag.
    As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.8 (released March, 2021),
    the default <command>ncremap</command> and <command>ncclimo</command> behavior
    is to omit the staggered grid.
    The new flag <code>--stg_grd</code> turns-on outputting the staggered
    grid, and thus recovers the previous default behavior. 
</para></tableitem></tableentry></table>

<para>One may supply muliple <samp>--rgr <var>key</var>=<var>value</var></samp> options
to simultaneously customize multiple grid-field names.
The following examples may all be assumed to end with the standard
options <samp>--map=map.nc in.nc out.nc</samp>.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks --rgr lat_nm=latitude --rgr lon_nm=longitude
ncks --rgr col_nm=column --rgr lat_wgt=lat_wgt
ncks --rgr bnd_nm=bounds --rgr lat_bnd_nm=lat_bounds --rgr lon_bnd_nm=lon_bounds
ncks --rgr bnd_nm=vertices --rgr lat_bnd_nm=lat_vrt --rgr lon_bnd_nm=lon_vrt
</verbatim>
</example>
<para>The first command causes the regridder to associate the latitude and
longitude dimensions with the dimension names <code>latitude</code> and
<code>longitude</code> (instead of the defaults, <code>lat</code> and <code>lon</code>). 
The second command causes the regridder to associate the independent
columns in an unstructured grid with the dimension name <code>column</code>
(instead of the default, <code>ncol</code>) and the variable containing
latitude weights to be named <code>lat_wgt</code> (instead of the default,
<code>gw</code>). 
The third command associates the latitude and longitude bounds with the
dimension <code>bounds</code> (instead of the default, <code>nbnd</code>) and the
variables <code>lat_bounds</code> and <code>lon_bounds</code> (instead of the
defaults, <code>lat_bnds</code> and  <code>lon_bnds</code>, respectively). 
The fourth command associates the latitude and longitude bounds with the
dimension <code>vertices</code> (instead of the default, <code>nv</code>) and the
variables <code>lat_vrt</code> and <code>lon_vrt</code> (instead of the defaults,
<code>lat_vertices</code> and <code>lon_vertices</code>, respectively). 
</para>
<para>When used with an identity remapping files, regridding can signficantly
enhance the metadata and therefore the dataset usability.
Consider these selected metadata (those unchanged are not shown for
brevity) associated with the variable <code>FSNT</code> from typical
unstructured grid (<acronym><acronymword>CAM-SE</acronymword></acronym> cubed-sphere) output before and
after an identity regridding: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Raw model output before regridding
netcdf ne30_FSNT {
  dimensions:
    nbnd = 2 ;
    ncol = 48602 ;
    time = UNLIMITED ; // (1 currently)

  variables:
    float FSNT(time,ncol) ;
      FSNT:long_name = &quot;Net solar flux at top of model&quot; ;

    double time(time) ;
      time:long_name = &quot;time&quot; ;
      time:bounds = &quot;time_bnds&quot; ;

    double time_bnds(time,nbnd) ;
      time_bnds:long_name = &quot;time interval endpoints&quot; ;
} // group /

# Same model output after identity regridding
netcdf dogfood {
  dimensions:
    nbnd = 2 ;
    ncol = 48602 ;
    nv = 5 ;
    time = 1 ;

  variables:
    float FSNT(time,ncol) ;
      FSNT:long_name = &quot;Net solar flux at top of model&quot; ;
      FSNT:coordinates = &quot;lat lon&quot; ;

    double lat(ncol) ;
      lat:long_name = &quot;latitude&quot; ;
      lat:standard_name = &quot;latitude&quot; ;
      lat:units = &quot;degrees_north&quot; ;
      lat:axis = &quot;Y&quot; ;
      lat:bounds = &quot;lat_vertices&quot; ;
      lat:coordinates = &quot;lat lon&quot; ;

    double lat_vertices(ncol,nv) ;
      lat_vertices:long_name = &quot;gridcell latitude vertices&quot; ;

    double lon(ncol) ;
      lon:long_name = &quot;longitude&quot; ;
      lon:standard_name = &quot;longitude&quot; ;
      lon:units = &quot;degrees_east&quot; ;
      lon:axis = &quot;X&quot; ;
      lon:bounds = &quot;lon_vertices&quot; ;
      lon:coordinates = &quot;lat lon&quot; ;

    double lon_vertices(ncol,nv) ;
      lon_vertices:long_name = &quot;gridcell longitude vertices&quot; ;

    double time(time) ;
      time:long_name = &quot;time&quot; ;
      time:bounds = &quot;time_bnds&quot; ;

    double time_bnds(time,nbnd) ;
      time_bnds:long_name = &quot;time interval endpoints&quot; ;
} // group /
</verbatim>
</example>
<para>The raw model output lacks the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code> and
<code>bounds</code> attributes that the regridder adds.
The metadata turns <code>lat</code> and <code>lon</code> into auxiliary coordinate
variables (<pxref label="Auxiliary-Coordinates"><xrefnodename>Auxiliary Coordinates</xrefnodename></pxref>) which can then be hyperslabbed
(with <samp>-X</samp>) using latitude/longitude coordinates bounding the
region of interest:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks -u -H -X 314.6,315.3,-35.6,-35.1 -v FSNT dogfood.nc
time[0]=31 ncol[0] FSNT[0]=344.575 W/m2

ncol[0] lat[0]=-35.2643896828 degrees_north

ncol[0] nv[0] lat_vertices[0]=-35.5977213708 
ncol[0] nv[1] lat_vertices[1]=-35.5977213708 
ncol[0] nv[2] lat_vertices[2]=-35.0972113817 
ncol[0] nv[3] lat_vertices[3]=-35.0972113817 
ncol[0] nv[4] lat_vertices[4]=-35.0972113817 

ncol[0] lon[0]=315 degrees_east

ncol[0] nv[0] lon_vertices[0]=315 
ncol[0] nv[1] lon_vertices[1]=315 
ncol[0] nv[2] lon_vertices[2]=315.352825437 
ncol[0] nv[3] lon_vertices[3]=314.647174563 
ncol[0] nv[4] lon_vertices[4]=314.647174563 

time[0]=31 days since 1979-01-01 00:00:00

time[0]=31 nbnd[0] time_bnds[0]=0 
time[0]=31 nbnd[1] time_bnds[1]=31 
</verbatim>
</example>
<para>Thus auxiliary coordinate variables help to structure unstructured grids.
The expanded metadata annotations from an identity regridding may
obviate the need to place unstructured data on a rectangular grid. 
For example, statistics for regions that can be expressed as unions of 
rectangular regions can now be performed on the native (unstructured)
grid. 
</para>
<para>Here are some quick examples of regridding from common models.
All examples require <samp>in.nc out.nc</samp> at the end.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Identity re-map E3SM/ACME CAM-SE Cubed-Sphere output (to improve metadata)
ncks --map=${DATA}/maps/map_ne30np4_to_ne30np4_aave.20150603.nc
# Convert E3SM/ACME CAM-SE Cubed Sphere output to rectangular lat/lon
ncks --map=${DATA}/maps/map_ne30np4_to_fv129x256_aave.150418.nc
# Convert CAM3 T42 output to Cubed-Sphere grid
ncks --map=${DATA}/maps/map_ne30np4_to_t42_aave.20150601.nc
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;clm_nfo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm_nfo --&gt;
&lt;a name=&quot;cb&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cb --&gt;
&lt;a name=&quot;clm_bnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm_bnd --&gt;
&lt;a name=&quot;climatology_information&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#climatology_information --&gt;
</html>
</unnumberedsubsec>
</section>
<node name="Climatology-and-Bounds-Support" spaces=" "><nodename>Climatology and Bounds Support</nodename><nodenext spaces=" ">UDUnits Support</nodenext><nodeprev spaces=" ">Regridding</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Climatology and Bounds Support</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="866"><code>--clm_nfo</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="867"><code>--cb</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="868"><code>--clm_bnd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="869"><code>--climatology_information</code></indexterm></cindex>
<para>Availability: <command>nces</command>, <command>ncra</command>, <command>ncrcat</command>&linebreak;
Short options: None&linebreak;
Long options: 
<samp>--cb=<var>yr_srt</var>,<var>yr_end</var>,<var>mth_srt</var>,<var>mth_end</var>,<var>tpd</var></samp>&linebreak;
<samp>--clm_bnd=<var>yr_srt</var>,<var>yr_end</var>,<var>mth_srt</var>,<var>mth_end</var>,<var>tpd</var></samp>&linebreak;
<samp>--clm_nfo=<var>yr_srt</var>,<var>yr_end</var>,<var>mth_srt</var>,<var>mth_end</var>,<var>tpd</var></samp>&linebreak;
<samp>--climatology_information=<var>yr_srt</var>,<var>yr_end</var>,<var>mth_srt</var>,<var>mth_end</var>,<var>tpd</var></samp>&linebreak;
</para>
<para>(NB: This section describes support for generating 
<acronym><acronymword>CF</acronymword></acronym>-compliant bounds variables and attributes, i.e.,
metadata. For instructions on constructing climatologies themselves,
see the <command>ncclimo</command> documentation).
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.4 (September, 2020) <command>ncra</command>
introduces the <samp>--clm_bnd</samp> option, a powerful method to
fully implement the <acronym><acronymword>CF</acronymword></acronym> <code>bounds</code>, <code>climatology</code>,
and <code>cell_methods</code> attributes defined by <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>.
The new method updates the previous <samp>--cb</samp> and <samp>--c2b</samp>
methods introduced in version 4.6.0 which only worked for monthly mean 
data.
The newer <code>--cb</code> method also works for climatological diurnally
resolved input, and for datasets that contain more than more than one
record. 
This option takes as argument a comma-separated list of five relevant
input parameters: 
<samp>--cb=<var>yr_srt</var>,<var>yr_end</var>,<var>mth_srt</var>,<var>mth_end</var>,<var>tpd</var></samp>, 
where
<var>yr_srt</var> is the climatology start-year,
<var>yr_end</var> is the climatology end-year,
<var>mth_srt</var> is the climatology start-month (in <code>[1..12]</code> format),
<var>mth_end</var> is the climatology end-month (in <code>[1..12]</code> format), and
<var>tpd</var> is the number of timestpes per day (with the special
exception that <math><var>tpd</var>=0</math> indicates monthly data, not
diurnally-resolved data).
For example, a seasonal summer climatology created from monthly mean
input data spanning June, 2000 to August, 2020 should call
<command>ncra</command> with <samp>--clm_bnd=2000,2020,6,8,0</samp>, whereas a
diurnally resolved climatology of the same period with 6-hourly input
data resolution would use <samp>--clm_bnd=2000,2020,6,8,4</samp>.
The <command>ncclimo</command> command internally uses <code>--clm_bnd</code>
extensively. 
</para>
<example endspaces=" ">
<pre xml:space="preserve"># Average monthly means into a climatological month
ncra --cb=2014,2016,1,1,0 2014_01.nc 2015_01.nc 2016_01.nc clm_JAN.nc
# Average seasonally contiguous climatological monthly means into NH winter
ncra --cb=2013,2016,12,2,0 -w 31,31,28 DEC.nc JAN.nc FEB.nc DJF.nc
# Average seasonally discontiguous climatological means into NH winter
ncra --cb=2014,2016,1,12,0 -w 31,28,31 JAN.nc FEB.nc DEC.nc JFD.nc
# Reduce four climatological seasons to make an annual climatology
ncra --cb=2014,2016,1,12,0 -w 92,92,91,90 MAM.nc JJA.nc SON.nc DJF.nc ANN.nc
# Reduce twelve monthly climatologies to make into an annual climatology
ncra --cb=2014,2016,1,12,0 -w 31,28,31,30,31,30,31,31,30,31,30,31 clm_??.nc ANN.nc
</pre></example>
<para>In the fourth and fifth examples, <acronym><acronymword>NCO</acronymword></acronym> uses the number of
input files (3 and 4, respectively) to discriminate between seasonal
and annual climatologies since the other arguments to <samp>--cb</samp>
are identical.
</para>
<para>When using this option, <acronym><acronymword>NCO</acronymword></acronym> expects each output file to
contain <code>max(1,<var>tpd</var>)</code> records.
<command>nces</command> and <command>ncra</command> both accept the <samp>--cb</samp> option.
While <command>ncra</command> almost always reduces the input dataset over the
record dimension, <command>nces</command> never does.
This makes it easy to use <command>nces</command> to combine and create
climatologies of diurnally resolved input files.
</para><example endspaces=" ">
<pre xml:space="preserve"># Average diurnally resolved monthly means into a climatology
nces --cb=2014,2016,1,1,8 2014_01.nc 2015_01.nc 2016_01.nc clm_JAN.nc
# Average seasonally contiguous diurnally resolved means into a season
nces --cb=2013,2016,12,2,8 -w 31,31,28 DEC.nc JAN.nc FEB.nc DJF.nc
# Average seasonally discontiguous diurnally resolved means into a season
nces --cb=2014,2016,1,12,8 -w 31,28,31 JAN.nc FEB.nc DEC.nc JFD.nc
# Reduce four diurnally resolved seasons to make an annual climatology
nces --cb=2014,2016,1,12,8 -w 92,92,91,90 MAM.nc JJA.nc SON.nc DJF.nc ANN.nc
# Reduce twelve diurnally resolved months to make into an annual climatology
nces --cb=2014,2016,1,12,8 -w 31,28,31,30,31,30,31,31,30,31,30,31 clm_??.nc ANN.nc
</pre></example>
<para>Every input in the above set of examples must have eight records,
and that number will appear in the output as well.
</para>
<html endspaces=" ">
&lt;a name=&quot;udunits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#udunits --&gt;
&lt;a name=&quot;UDUnits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#UDUnits --&gt;
&lt;a name=&quot;UDUnits2&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#UDUnits2 --&gt;
</html>
</section>
<node name="UDUnits-Support" spaces=" "><nodename>UDUnits Support</nodename><nodenext spaces=" ">Rebasing Time Coordinate</nodenext><nodeprev spaces=" ">Climatology and Bounds Support</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>UDUnits Support </sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="870">UDUnits</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="871">Unidata</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="872"><code>units</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="873">attribute, <code>units</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="874"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="875"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="876"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>nces</command>, <command>ncecat</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: <samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
Long options: 
<samp>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>,&linebreak; 
<samp>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp>&linebreak;
</para></cartouche>
<para>There is more than one way to hyperskin a cat.
The <uref><urefurl>http://www.unidata.ucar.edu/software/udunits</urefurl><urefdesc spaces=" ">UDUnits</urefdesc></uref> package 
provides a library which, if present, <acronym><acronymword>NCO</acronymword></acronym> uses to translate
user-specified physical dimensions into the physical dimensions of data
stored in netCDF files.
Unidata provides UDUnits under the same terms as netCDF, so sites should
install both.
Compiling <acronym><acronymword>NCO</acronymword></acronym> with UDUnits support is currently optional but
may become required in a future version of <acronym><acronymword>NCO</acronymword></acronym>.
</para>
<para>Two examples suffice to demonstrate the power and convenience of UDUnits  
support. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="877">MKS units</indexterm></cindex>
First, consider extraction of a variable containing non-record
coordinates with physical dimensions stored in MKS units.
In the following example, the user extracts all wavelengths
in the visible portion of the spectrum in terms of the units
very frequently used in visible spectroscopy, microns:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks --trd -C -H -v wvl -d wvl,&quot;0.4 micron&quot;,&quot;0.7 micron&quot; in.nc
wvl[0]=5e-07 meter
</pre></example>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="878"><code>units</code></indexterm></cindex>
<para>The hyperslab returns the correct values because the <var>wvl</var> variable
is stored on disk with a length dimension that UDUnits recognizes in the 
<code>units</code> attribute.
The automagical algorithm that implements this functionality is worth
describing since understanding it helps one avoid some potential
pitfalls. 
First, the user includes the physical units of the hyperslab dimensions 
she supplies, separated by a simple space from the numerical values of
the hyperslab limits.
She encloses each coordinate specifications in quotes so that the shell
does not break the <emph>value-space-unit</emph> string into separate
arguments before passing them to <acronym><acronymword>NCO</acronymword></acronym>. 
Double quotes (<kbd>&quot;foo&quot;</kbd>) or single quotes (<kbd>'foo'</kbd>) are equally
valid for this purpose. 
Second, <acronym><acronymword>NCO</acronymword></acronym> recognizes that units translation is requested
because each hyperslab argument contains text characters and non-initial
spaces.  
Third, <acronym><acronymword>NCO</acronymword></acronym> determines whether the <var>wvl</var> is dimensioned
with a coordinate variable that has a <code>units</code> attribute. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="879">coordinate variable</indexterm></cindex> 
In this case, <var>wvl</var> itself is a coordinate variable.
The value of its <code>units</code> attribute is <code>meter</code>. 
Thus <var>wvl</var> passes this test so UDUnits conversion is attempted. 
If the coordinate associated with the variable does not contain a 
<code>units</code> attribute, then <acronym><acronymword>NCO</acronymword></acronym> aborts.
Fourth, <acronym><acronymword>NCO</acronymword></acronym> passes the specified and desired dimension strings  
(microns are specified by the user, meters are required by
<acronym><acronymword>NCO</acronymword></acronym>) to the UDUnits library.
Fifth, the UDUnits library that these dimension are commensurate
and it returns the appropriate linear scaling factors to convert from 
microns to meters to <acronym><acronymword>NCO</acronymword></acronym>.
If the units are incommensurate (i.e., not expressible in the same
fundamental MKS units), or are not listed in the UDUnits database, then 
NCO aborts since it cannot determine the user&textrsquo;s intent.
Finally, <acronym><acronymword>NCO</acronymword></acronym> uses the scaling information to convert the
user-specified hyperslab limits into the same physical dimensions as
those of the corresponding cooridinate variable on disk.
At this point, <acronym><acronymword>NCO</acronymword></acronym> can perform a coordinate hyperslab using
the same algorithm as if the user had specified the hyperslab without
requesting units conversion.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="880"><code>units</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="881"><code>time</code></indexterm></cindex> 
<para>The translation and dimensional interpretation of time coordinates
shows a more powerful, and probably more common, UDUnits application.
In this example, the user prints all data between <w>4 PM</w> and <w>7 PM</w>
on <w>December 8</w>, 1999, from a variable whose time dimension is hours 
since the year 1900:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -u -H -C -v time_udunits -d time_udunits,&quot;1999-12-08 \
  16:00:0.0&quot;,&quot;1999-12-08 19:00:0.0&quot; in.nc
time_udunits[1]=876018 hours since 1900-01-01 00:00:0.0
</pre></example>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="882">stride</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="883">whitespace</indexterm></cindex>
<para>Here, the user invokes the stride (<pxref label="Stride"><xrefnodename>Stride</xrefnodename></pxref>) capability to obtain 
every other timeslice.
This is possible because the UDUnits feature is additive, not
exclusive&textmdash;it works in conjunction with all other hyperslabbing
(<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>) options and in all operators which support
hyperslabbing.
The following example shows how one might average data in a 
time period spread across multiple input files
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -d time,&quot;1939-09-09 12:00:0.0&quot;,&quot;1945-05-08 00:00:0.0&quot; \
  in1.nc in2.nc in3.nc out.nc
</pre></example>
<noindent></noindent>
<para>Note that there is no excess whitespace before or after the individual
elements of the <samp>-d</samp> argument.
<cindex index="cp" spaces=" "><indexterm index="cp" number="884">shell</indexterm></cindex> 
This is important since, as far as the shell knows, <samp>-d</samp> takes
only <emph>one</emph> command-line argument.
Parsing this argument into its component
<code><var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code> elements 
(<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>) is the job of <acronym><acronymword>NCO</acronymword></acronym>.
When unquoted whitespace is present between these elements, the shell
passes <acronym><acronymword>NCO</acronymword></acronym> arugment fragments which will not parse as
intended. 
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> implemented support for the UDUnits2 library with version   
3.9.2 (August, 2007).
The
<uref><urefurl>http://www.unidata.ucar.edu/software/udunits/udunits-2/udunits2.html</urefurl><urefdesc spaces="\n">UDUnits2</urefdesc></uref> package supports non-ASCII characters and logarithmic units. 
We are interested in user-feedback on these features.
</para>
<html endspaces=" ">
&lt;a name=&quot;UDUNITS2_XML_PATH&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#UDUNITS2_XML_PATH --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="885"><code>UDUNITS2_XML_PATH</code></indexterm></cindex>
<para>One aspect that deserves mention is that UDUnits, and thus
<acronym><acronymword>NCO</acronymword></acronym>, supports run-time definition of the location of the
relevant UDUnits databases. 
UDUnits2 (specifically, the function <code>ut_read_xml()</code>) uses the
environment variable <code>UDUNITS2_XML_PATH</code>, if any, to find its
all-important <acronym><acronymword>XML</acronymword></acronym> database, named <file>udunits2.xml</file> by
default.   
If <code>UDUNITS2_XML_PATH</code> is undefined, then UDUnits2 looks in the
fall-back default initial location that was hardcoded when the
UDUnits2 library was built. 
This location varies depending upon your operating system and UDUnits2
ncompilation settings. 
If UDUnits2 is correctly linked yet cannot find the <acronym><acronymword>XML</acronymword></acronym>
database in either of these locations, then <acronym><acronymword>NCO</acronymword></acronym> will report
that the UDUnits2 library has failed to initialize. 
To fix this, export the full location (path+name) of the UDUnits2
<acronym><acronymword>XML</acronymword></acronym> database file <file>udunits2.xml</file> to the shell:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Example UDUnits2 XML database locations:
export UDUNITS2_XML_PATH='/opt/homebrew/share/udunits/udunits2.xml' # Homebrew
export UDUNITS2_XML_PATH='/opt/local/share/udunits/udunits2.xml' # MacPorts
export UDUNITS2_XML_PATH=&quot;${HOME}/anaconda/share/udunits/udunits2.xml&quot; # Anaconda
</verbatim>
</example>
<para>One can then invoke (without recompilation) <acronym><acronymword>NCO</acronymword></acronym> again, and
UDUnits2 should work. 
This run-time flexibility can enable the full functionality of
pre-built binaries on machines with libraries in different locations.
</para>
<ignore endspaces=" ">
@cindex @code{UDUNITS_PATH}
@acronym{NCO} supported for UDUnits @w{version 1} for many years, 
and deprecated this feature in about 2015.
Some UDUnits @w{version 1} feature may still work (we do not know).
If you are stuck with a UDUnits @w{version 1} installation
you might try to specify the directory which contains the UDUnits
database, @file{udunits.dat}, via the @code{UDUNITS_PATH} environment
variable: 
@example
# UDUnits1
export UDUNITS_PATH='/unusual/location/share/udunits'
@end example
</ignore>

<cindex index="cp" spaces=" "><indexterm index="cp" number="886">Climate and Forecast Metadata Convention</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="887"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm></cindex>
<para>The <uref><urefurl>http://www.unidata.ucar.edu/software/udunits</urefurl><urefdesc spaces=" ">UDUnits</urefdesc></uref>
package documentation describes the supported formats of time
dimensions. 
Among the metadata conventions that adhere to these formats are the  
<uref><urefurl>http://cf-pcmdi.llnl.gov</urefurl><urefdesc spaces=" \n">Climate and Forecast (CF) Conventions</urefdesc></uref> and the 
<uref><urefurl>http://ferret.wrc.noaa.gov/noaa_coop/coop_cdf_profile.html</urefurl><urefdesc spaces="\n">Cooperative Ocean/Atmosphere Research Data Service (COARDS) Conventions</urefdesc></uref>.
The following <samp>-d arguments</samp> extract the same data using 
commonly encountered time dimension formats: 
<!-- c fxm add more formats here -->
</para><example endspaces=" ">
<pre xml:space="preserve">-d time,'1918-11-11 00:00:0.0','1939-09-09 00:00:0.0'
-d time,'1918-11-11 00:00:0.0','1939-09-09 00:00:0.0'
-d time,'1918-11-11T00:00:0.0Z','1939-09-09T00:00:0.0Z'
-d time,'1918-11-11','1939-09-09'
-d time,'1918-11-11','1939-9-9'
</pre></example>
<noindent></noindent>
<para>All of these formats include at least one dash <kbd>-</kbd> in a
non-leading character position (a dash in a leading character position 
is a negative sign). 
<acronym><acronymword>NCO</acronymword></acronym> assumes that a space, colon, or non-leading dash in a
limit string indicates that a UDUnits units conversion is requested.
Some date formats like YYYYMMDD that are valid in UDUnits are ambiguous
to <acronym><acronymword>NCO</acronymword></acronym> because it cannot distinguish a purely numerical date
(i.e., no dashes or text characters in it) from a coordinate or index
value: 
</para><example endspaces=" ">
<pre xml:space="preserve">-d time,1918-11-11 # Interpreted as the date November 11, 1918
-d time,19181111   # Interpreted as time-dimension index 19181111
-d time,19181111.  # Interpreted as time-coordinate value 19181111.0
</pre></example>
<para>Hence, use the YYYY-MM-DD format rather than YYYYMMDD for dates.
</para>
<noindent></noindent>
<para>As of version 4.0.0 (January, 2010), <acronym><acronymword>NCO</acronymword></acronym> supports some
calendar attributes specified by the <acronym><acronymword>CF</acronymword></acronym> conventions. 
</para><table commandarg="asis" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="asis"><strong>Supported types:</strong> </itemformat></item>
</tableterm><tableitem><para>&quot;365_day&quot;/&quot;noleap&quot;, &quot;360_day&quot;, &quot;gregorian&quot;, &quot;standard&quot; 
</para></tableitem></tableentry><tableentry><tableterm><item spaces="  "><itemformat command="asis"><strong>Unsupported types:</strong> </itemformat></item>
</tableterm><tableitem><para>&quot;366_day&quot;/&quot;all_leap&quot;,&quot;proleptic_gregorian&quot;,&quot;julian&quot;,&quot;none&quot; 
</para></tableitem></tableentry></table>
<para>Unsupported types default to mixed Gregorian/Julian as defined by  
UDUnits. 
</para>
<noindent></noindent> <para>An Example: Consider the following netCDF variable
</para><example endspaces=" ">
<pre xml:space="preserve">variables:
  double lon_cal(lon_cal) ;
    lon_cal:long_name = &quot;lon_cal&quot; ;
    lon_cal:units = &quot;days since 1964-2-28 0:0:0&quot; ;
    lon_cal:calendar = &quot;365_day&quot; ;
data:
  lon_cal = 1,2,3,4,5,6,7,8,9,10;
</pre></example> 
<para><samp>ncks -v lon_cal -d lon_cal,'1964-3-1 0:00:0.0','1964-3-4 00:00:0.0'</samp>
results in <code>lon_cal=1,2,3,4</code>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="888">MKS units</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="889">God</indexterm></cindex>
<para>netCDF variables should always be stored with <acronym><acronymword>MKS</acronymword></acronym> (i.e.,
God&textrsquo;s) units, so that application programs may assume <acronym><acronymword>MKS</acronymword></acronym>
dimensions apply to all input variables. 
The UDUnits feature is intended to alleviate <acronym><acronymword>NCO</acronymword></acronym> users&textrsquo;
pain when handling <acronym><acronymword>MKS</acronymword></acronym> units. 
It connects users who think in human-friendly units (e.g.,
miles, millibars, days) to extract data which are always stored in
God&textrsquo;s units, <acronym><acronymword>MKS</acronymword></acronym> (e.g., meters, Pascals, seconds). 
The feature is not intended to encourage writers to store data in 
esoteric units (e.g., furlongs, pounds per square inch, fortnights). 
</para>
<html endspaces=" ">
&lt;a name=&quot;time_rebase&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#time_rebase --&gt;
&lt;a name=&quot;rbs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rbs --&gt;
</html>
</section>
<node name="Rebasing-Time-Coordinate" spaces=" "><nodename>Rebasing Time Coordinate</nodename><nodenext spaces=" ">Multiple Record Dimensions</nodenext><nodeprev spaces=" ">UDUnits Support</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Rebasing Time Coordinate</sectiontitle>
<cartouche endspaces=" ">
<para>Availability: 
<command>ncra</command>, <command>ncrcat</command> 
Short options: None&linebreak;
</para></cartouche>

<para>Time rebasing is invoked when numerous files share a common record
coordinate, and the record coordinate basetime (not the time increment,
e.g., days or hours) changes among input files. 
The rebasing is performed automatically if and only if UDUnits is
installed. 
Rebasing occurs when the record coordinate is a time-based variable, and
times are recorded in units of a time-since-basetime, and the basetime
changes from file to file. 
Since the output file can have only one unit (i.e., one basetime) for
the record coordinate, <acronym><acronymword>NCO</acronymword></acronym>, in such cases, chooses the units
of the first input file to be the units of the output file.
It is necessary to &textldquo;rebase&textrdquo; all the input record variables to this
output time unit in order for the output file to have the correct
values.  
</para>
<para>For example suppose the time coordinate is in hours and each day in
January is stored in its own daily file.
Each daily file records the temperature variable <code>tpt(time)</code> 
with an (unadjusted) <code>time</code> coordinate value between 0&textndash;23 hours,
and uses the <code>units</code> attribute to advance the base time:
</para><example endspaces=" ">
<pre xml:space="preserve">file01.nc time:units=&quot;hours since 1990-1-1&quot;   
file02.nc time:units=&quot;hours since 1990-1-2&quot;   
...
file31.nc time:units=&quot;hours since 1990-1-31&quot;   
</pre></example>

<example endspaces=" ">
<pre xml:space="preserve">// Mean noontime temperature in January
ncra -v tpt -d time,&quot;1990-1-1 12:00:00&quot;,&quot;1990-1-31 23:59:59&quot;,24 \
      file??.nc noon.nc    

// Concatenate day2 noon through day3 noon records
ncrcat -v tpt -d time,&quot;1990-1-2 12:00:00&quot;,&quot;1990-1-3 11:59:59&quot; \ 
      file01.nc file02.nc file03.nc noon.nc    

// Results: time is &quot;re-based&quot; to the time units in &quot;file01.nc&quot;
time=36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, \
     51, 52, 53, 54, 55, 56, 57, 58, 59 ;
  
// If we repeat the above command but with only two input files...
ncrcat -v tpt -d time,&quot;1990-1-2 12:00:00&quot;,&quot;1990-1-3 11:59:59&quot; \
      file02.nc file03 noon.nc    

// ...then output time coordinate is based on time units in &quot;file02.nc&quot;
time = 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, \ 
     26, 27, 28, 29, 30, 31, 32, 33, 34, 35 ;
</pre></example>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.2.1 (August, 2012), <acronym><acronymword>NCO</acronymword></acronym>
automatically rebases not only the record coordinate (<code>time</code>, here) 
but also any cell boundaries associated with the record coordinate
(e.g., <code>time_bnds</code>) (<pxref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></pxref>). 
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.9 (May, 2015), <acronym><acronymword>NCO</acronymword></acronym>
also rebases any climatology boundaries associated with the record
coordinate (e.g., <code>climatology_bounds</code>) (<pxref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></pxref>). 
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.3 (December, 2016), <acronym><acronymword>NCO</acronymword></acronym>
also rebases the time coordinate when the units differ between files.
For example the first file may have <code>units=&quot;days since 2014-03-01&quot;</code> 
and the second file <code>units=&quot;hours since 2014-03-10 00:00&quot;</code>.
</para>
<html endspaces=" ">
&lt;a name=&quot;mrd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mrd --&gt;
</html>
</section>
<node name="Multiple-Record-Dimensions" spaces=" "><nodename>Multiple Record Dimensions</nodename><nodenext spaces=" ">Missing Values</nodenext><nodeprev spaces=" ">Rebasing Time Coordinate</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Multiple Record Dimensions</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="890">netCDF4</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="891"><code>--mrd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="892"><code>--multiple_record_dimensions</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: 
<command>ncecat</command>, <command>ncpdq</command> 
Short options: None&linebreak;
Long options: <samp>--mrd</samp>&linebreak;
</para></cartouche>
<para>The netCDF3 file format allows only one record dimension, and that
dimension must be the first dimension (i.e., the least rapidly varying 
dimension) of any variable in which it appears.
This imposes certain rules on how operators must perform operations
that alter the ordering of dimensions or the number of record variables.
The netCDF4 file format has no such restrictions.
Files and variables may have any number of record dimensions in any
order.
This additional flexibility of netCDF4 can only be realized by
selectively abandoning the constraints that would make operations
behave completely consistently between netCDF3 and netCDF4 files.
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> chooses, by default, to impose netCDF3-based constraints
on netCDF4 files. 
This reduces the number of unanticipated consequences and keeps the
operators functioning in a familiar way.
Put another way, <acronym><acronymword>NCO</acronymword></acronym> limits production of additional record
dimensions so processing netCDF4 files leads to the same results as
processing netCDF3 files.
Users can override this default with the <samp>--mrd</samp> (or 
<samp>--multiple_record_dimension</samp>) switch, which enables netCDF4
variables to accumulate additional record dimensions.
</para>
<para>How can additional record dimensions be produced?
Most commonly <command>ncecat</command> (in record-aggregate mode) defines a new
leading record dimension.
In netCDF4 files this becomes an additional record dimension unless the
original record dimension is changed to a fixed dimension (as must be
done in netCDF3 files). 
Also when <command>ncpdq</command> reorders dimensions it can preserve the
&textldquo;record&textrdquo; property of record variables.
<command>ncpdq</command> tries to define as a record dimension whichever
dimension ends up first in a record variable, and, in netCDF4 files,
this becomes an additional record dimension unless the original record
dimension is changed to a fixed dimension (as must be done in netCDF3
files). 
It it easier if <command>ncpdq</command> and <command>ncecat</command> do not increase
the number of record dimensions in a variable so that is the default.
Use <samp>--mrd</samp> to override this.
</para>
<html endspaces=" ">
&lt;a name=&quot;missing_value&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#missing_value --&gt;
&lt;a name=&quot;_FillValue&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#_FillValue --&gt;
&lt;a name=&quot;fll_val&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fll_val --&gt;
&lt;a name=&quot;mss_val&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mss_val --&gt;
&lt;a name=&quot;mss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mss --&gt;
</html>
</section>
<node name="Missing-Values" spaces=" "><nodename>Missing Values</nodename><nodenext spaces=" ">Chunking</nodenext><nodeprev spaces=" ">Multiple Record Dimensions</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Missing values</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="893">missing values</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="894">data, missing</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="895">averaging data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="896"><code>missing_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="897"><code>_FillValue</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncclimo</command>,
<command>nces</command>, <command>ncflint</command>, <command>ncpdq</command>, <command>ncra</command>,  
<command>ncremap</command>, <command>ncwa</command>&linebreak; 
Short options: None&linebreak;
</para></cartouche>

<para>The phrase <dfn>missing data</dfn> refers to data points that are missing,
invalid, or for any reason not intended to be arithmetically processed
in the same fashion as valid data.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="898">arithmetic operators</indexterm></cindex>
All <acronym><acronymword>NCO</acronymword></acronym> arithmetic operators attempt to handle missing data in 
an intelligent fashion. 
There are four steps in the <acronym><acronymword>NCO</acronymword></acronym> treatment of missing data:
</para><enumerate first="1" endspaces=" ">
<listitem> 
<para>Identifying variables that may contain missing data. 
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> follows the convention that missing data should be stored
with the <var>_FillValue</var> specified in the variable&textrsquo;s <code>_FillValue</code> 
attributes. 
The <emph>only</emph> way <acronym><acronymword>NCO</acronymword></acronym> recognizes that a variable <emph>may</emph>
contain missing data is if the variable has a <code>_FillValue</code>
attribute. 
In this case, any elements of the variable which are numerically equal
to the <var>_FillValue</var> are treated as missing data.
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> adopted the behavior that the default attribute name, if 
any, assumed to specify the value of data to ignore is <code>_FillValue</code> 
with version 3.9.2 (August, 2007).
Prior to that, the <code>missing_value</code> attribute, if any, was assumed to  
specify the value of data to ignore.
Supporting both of these attributes simultaneously is not practical.
Hence the behavior <acronym><acronymword>NCO</acronymword></acronym> once applied to <var>missing_value</var> it
now applies to any <var>_FillValue</var>. 
<acronym><acronymword>NCO</acronymword></acronym> now treats any <var>missing_value</var> as normal data 
<footnote spaces="\n"><para>The old functionality, i.e., where the ignored values are indicated by
<code>missing_value</code> not <code>_FillValue</code>, may still be selected 
<emph>at <acronym><acronymword>NCO</acronymword></acronym> build time</emph> by compiling <acronym><acronymword>NCO</acronymword></acronym> 
with the token definition 
<!-- c @kbd{CPPFLAGS='-DNCO_MSS_VAL_SNG=missing_value'}. -->
<kbd>CPPFLAGS='-UNCO_USE_FILL_VALUE'</kbd>.
</para></footnote>.
</para>
<findex index="fn" spaces=" "><indexterm index="fn" number="8" mergedindex="cp">ncrename</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="9" mergedindex="cp">ncatted</indexterm></findex>
<para>It has been and remains most advisable to create both <code>_FillValue</code> 
and <code>missing_value</code> attributes with identical values in datasets.
Many legacy datasets contain only <code>missing_value</code> attributes.
<acronym><acronymword>NCO</acronymword></acronym> can help migrating datasets between these conventions.
One may use <command>ncrename</command> (<pxref label="ncrename-netCDF-Renamer"><xrefnodename>ncrename netCDF Renamer</xrefnodename></pxref>) to
rename all <code>missing_value</code> attributes to <code>_FillValue</code>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncrename -a .missing_value,_FillValue inout.nc
</pre></example>
<para>Alternatively, one may use
<command>ncatted</command> (<pxref label="ncatted-netCDF-Attribute-Editor"><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></pxref>) to
add a <code>_FillValue</code> attribute to all variables
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -O -a _FillValue,,o,f,1.0e36 inout.nc
</pre></example>

</listitem><listitem> 
<para>Converting the <var>_FillValue</var> to the type of the variable, if
neccessary. 
</para>
<para>Consider a variable <var>var</var> of type <var>var_type</var> with a
<code>_FillValue</code> attribute of type <var>att_type</var> containing the
value <var>_FillValue</var>.  
As a guideline, the type of the <code>_FillValue</code> attribute should be
the same as the type of the variable it is attached to.
If <var>var_type</var> equals <var>att_type</var> then <acronym><acronymword>NCO</acronymword></acronym>
straightforwardly compares each value of <var>var</var> to
<var>_FillValue</var> to determine which elements of <var>var</var> are to be
treated as missing data. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="899">C language</indexterm></cindex>
If not, then <acronym><acronymword>NCO</acronymword></acronym> converts <var>_FillValue</var> from
<var>att_type</var> to <var>var_type</var> by using the implicit conversion rules
<w>of C</w>, or, if <var>att_type</var> is <code>NC_CHAR</code>
<footnote><para>For example, the <acronym><acronymword>DOE</acronymword></acronym> <acronym><acronymword>ARM</acronymword></acronym> program often
uses <var>att_type</var> = <code>NC_CHAR</code> and <var>_FillValue</var> =
<samp>-99999.</samp>. 
</para></footnote>, by typecasting the results of the <w>C function</w>
<code>strtod(<var>_FillValue</var>)</code>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="900"><command>ncatted</command></indexterm></cindex>
You may use the <acronym><acronymword>NCO</acronymword></acronym> operator <command>ncatted</command> to change the
<code>_FillValue</code> attribute and all data whose data is
<var>_FillValue</var> to a new value
(<pxref label="ncatted-netCDF-Attribute-Editor"><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></pxref>).
</para>
</listitem><listitem> 
<para>Identifying missing data during arithmetic operations.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="901">performance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="902">operator speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="903">speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="904">execution time</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="905">arithmetic operators</indexterm></cindex>
<para>When an <acronym><acronymword>NCO</acronymword></acronym> arithmetic operator processes a variable <var>var</var>
with a <code>_FillValue</code> attribute, it compares each value of
<var>var</var> to <var>_FillValue</var> before performing an operation.
Note the <var>_FillValue</var> comparison imposes a performance penalty
on the operator.
Arithmetic processing of variables which contain the
<code>_FillValue</code> attribute always incurs this penalty, even when
none of the data are missing.
Conversely, arithmetic processing of variables which do not contain the
<code>_FillValue</code> attribute never incurs this penalty.
In other words, do not attach a <code>_FillValue</code> attribute to a
variable which does not contain missing data.
This exhortation can usually be obeyed for model generated data, but it
may be harder to know in advance whether all observational data will be
valid or not.
</para>
</listitem><listitem> 
<para>Treatment of any data identified as missing in arithmetic operators.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="906"><command>nces</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="907"><command>ncra</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="908"><command>ncwa</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="909"><command>ncbo</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="910"><command>ncflint</command></indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> averagers (<command>ncra</command>, <command>nces</command>, <command>ncwa</command>)
do not count any element with the value <var>_FillValue</var> towards the
average. 
<command>ncbo</command> and <command>ncflint</command> define a <var>_FillValue</var> result  
when either of the input values is a <var>_FillValue</var>.
Sometimes the <var>_FillValue</var> may change from file to file in a
multi-file operator, e.g., <command>ncra</command>.
<acronym><acronymword>NCO</acronymword></acronym> is written to account for this (it always compares a
variable to the <var>_FillValue</var> assigned to that variable in the
current file). 
Suffice it to say that, in all known cases, <acronym><acronymword>NCO</acronymword></acronym> does &textldquo;the
right thing&textrdquo;. 
</para>
<para>It is impossible to determine and store the correct result of a binary  
operation in a single variable.
One such corner case occurs when both operands have differing
<var>_FillValue</var> attributes, i.e., attributes with different
numerical values.
Since the output (result) of the operation can only have one
<var>_FillValue</var>, some information may be lost.
In this case, <acronym><acronymword>NCO</acronymword></acronym> always defines the output variable to have
the same <var>_FillValue</var> as the first input variable.
Prior to performing the arithmetic operation, all values of the second
operand equal to the second <var>_FillValue</var> are replaced with the
first <var>_FillValue</var>.
Then the arithmetic operation proceeds as normal, comparing each element 
of each operand to a single <var>_FillValue</var>.
Comparing each element to two distinct <var>_FillValue</var>&textrsquo;s would be
much slower and would be no likelier to yield a more satisfactory
answer. 
In practice, judicious choice of <var>_FillValue</var> values prevents any
important information from being lost.
</para></listitem></enumerate>

<html endspaces=" ">
&lt;a name=&quot;chunking&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chunking --&gt;
&lt;a name=&quot;cnk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnk --&gt;
&lt;a name=&quot;cnk_sz&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnk_sz --&gt;
&lt;a name=&quot;chunk_size&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chunk_size --&gt;
</html>
</section>
<node name="Chunking" spaces=" "><nodename>Chunking</nodename><nodenext spaces=" ">Quantization Algorithms</nodenext><nodeprev spaces=" ">Missing Values</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Chunking</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="911"><code>--cnk_byt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="912"><code>--cnk_csh</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="913"><code>--cnk_dmn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="914"><code>--cnk_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="915"><code>--cnk_min</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="916"><code>--cnk_plc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="917"><code>--cnk_scl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="918"><code>--chunk_byte</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="919"><code>--chunk_cache</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="920"><code>--chunk_dimension</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="921"><code>--chunk_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="922"><code>--chunk_min</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="923"><code>--chunk_policy</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="924"><code>--chunk_scalar</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="925">chunking</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>nces</command>,
<command>ncecat</command>, <command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>,
<command>ncra</command>, <command>ncrcat</command>, <command>ncwa</command>&linebreak;
Short options: none&linebreak;
Long options: 
<samp>--cnk_byt <var>sz_byt</var></samp>, <samp>--chunk_byte <var>sz_byt</var></samp>&linebreak;
<samp>--cnk_csh <var>sz_byt</var></samp>, <samp>--chunk_cache <var>sz_byt</var></samp>&linebreak;
<samp>--cnk_dmn <var>dmn_nm</var>,<var>sz_lmn</var></samp>,
<samp>--chunk_dimension <var>dmn_nm</var>,<var>sz_lmn</var></samp>&linebreak;,
<samp>--cnk_map <var>cnk_map</var></samp>, <samp>--chunk_map <var>cnk_map</var></samp>,&linebreak;
<samp>--cnk_min <var>sz_byt</var></samp>, <samp>--chunk_min <var>sz_byt</var></samp>,&linebreak;
<samp>--cnk_plc <var>cnk_plc</var></samp>, <samp>--chunk_policy <var>cnk_plc</var></samp>,&linebreak;
<samp>--cnk_scl <var>sz_lmn</var></samp>, <samp>--chunk_scalar <var>sz_lmn</var></samp>&linebreak;
</para></cartouche>

<para>All netCDF4-enabled <acronym><acronymword>NCO</acronymword></acronym> operators that define variables 
support a plethora of chunksize options.
Chunking can significantly accelerate or degrade read/write access
to large datasets.
Dataset chunking issues are described by <acronym><acronymword>THG</acronymword></acronym> and Unidata 
<uref><urefurl>http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html</urefurl><urefdesc>here</urefdesc></uref>,
<uref><urefurl>http://www.unidata.ucar.edu/blogs/developer/en/entry/chunking_data_why_it_matters</urefurl><urefdesc>here</urefdesc></uref>,
and
<uref><urefurl>http://www.unidata.ucar.edu/blogs/developer/en/entry/chunking_data_choosing_shapes</urefurl><urefdesc>here</urefdesc></uref>.
<acronym><acronymword>NCO</acronymword></acronym> authors are working on generalized algorithms and
applications of chunking strategies (stay tuned for more in 2018).
</para>
<html endspaces=" ">
&lt;a name=&quot;chunk_cache&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chunk_cache --&gt;
&lt;a name=&quot;cnk_csh&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnk_csh --&gt;
&lt;a name=&quot;cache&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cache --&gt;
&lt;a name=&quot;csh&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#csh --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="926">chunk cache size</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="927">cache size</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="928"><code>--cnk_csh <var>sz</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="929"><code>--chunk_cache <var>sz</var></code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.5 (March, 2017), <acronym><acronymword>NCO</acronymword></acronym> supports
run-time alteration of the chunk cache size.
By default, the cache size is set (by the <code>--with-chunk-cache-size</code>
option to <command>configure</command>) at netCDF compile time. 
The <code>--cnk_csh <var>sz</var></code> option sets the cache size to <var>sz</var>
bytes for all variables.
When the debugging level is set (with <code>-D <var>dbg_lvl</var></code>) to three
or higher, <acronym><acronymword>NCO</acronymword></acronym> prints the current value of the cache settings
for informational purposes. 
Also <samp>--chunk_cache</samp>.
</para>
<para>Increasing cache size from the default can dramatically accelerate time
to aggregate and rechunk multiple large input datasets, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat -4 -L 1 --cnk_csh=1000000000 --cnk_plc=g3d --cnk_dmn=time,365 \
       --cnk_dmn=lat,1800 --cnk_dmn=lon,3600 in*.nc4 out.nc
</pre></example>
<para>In this example all 3D variables the input datasets (which may or may
not be chunked already) are re-chunked to a size of 365 along the time
dimension. 
Because the default chunk cache size of about <w>4 MB</w> is too small to
manipulate the large chunks, we reset the cache to <w>1 GB</w>.
The operation completes much faster, and subsequent reads along the
time dimension will be much more rapid.
</para>
<html endspaces=" ">
&lt;a name=&quot;blocksize&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#blocksize --&gt;
&lt;a name=&quot;blk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#blk --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="930">chunking policy</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="931">chunking map</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="932">chunksize</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="933">blocksize</indexterm></cindex>
<para>The <acronym><acronymword>NCO</acronymword></acronym> chunking implementation is designed to be flexible. 
Users control four aspects of the chunking implementation.
These are the <dfn>chunking policy</dfn>, <dfn>chunking map</dfn>,
<dfn>chunksize</dfn>, and <dfn>minimum chunksize</dfn>.
The chunking policy determines <emph>which</emph> variables to chunk, and
the chunking map determines how (with what exact sizes) to chunk
those variables.
These are high-level mechanisms that apply to an entire file and all
variables and dimensions.
The chunksize option allows per-dimension specification of sizes that 
will override the selected (or default) chunking map.
</para>
<para>The distinction between elements and bytes is subtle yet crucial to
understand. 
Elements refers to values of an array, whereas bytes refers to the
memory size required to hold the elements. 
These measures differ by a factor of four or eight for <code>NC_FLOAT</code>
or <code>NC_DOUBLE</code>, respectively. 
The option <samp>--cnk_scl</samp> takes an argument <var>sz_lmn</var> measured in
elements.
The options <samp>--cnk_byt</samp>, <samp>--cnk_csh</samp>, and <samp>--cnk_min</samp>
take arguments <var>sz_byt</var> measured in bytes.
</para>
<para>Use the <samp>--cnk_min=<var>sz_byt</var></samp> option to set the minimum size in
bytes (not elements) of variables to chunk.  
This threshold is intended to restrict use of chunking to variables
for which it is efficient. 
By default this minimum variable size for chunking is twice the system 
blocksize (when available) and is <w>8192 bytes</w> otherwise. 
Users may set this to any value with the <samp>--cnk_min=<var>sz_byt</var></samp>
switch. 
To guarantee that chunking is performed on all arrays, regardless of
size, set the minimum size to one byte (not to zero bytes).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="934">hyperslab</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="10" mergedindex="cp">ncpdq</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="935">packing</indexterm></cindex>
<para>The chunking implementation is similar to a hybrid of the
<command>ncpdq</command> packing policies 
(<pxref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></pxref>) and hyperslab
specifications (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>).  
Each aspect is intended to have a sensible default, so that many users 
only need to set one switch to obtain sensible chunking. 
Power users can tune chunking with the three switches in tandem to
obtain optimal performance. 
</para>
<para>By default, <acronym><acronymword>NCO</acronymword></acronym> preserves the chunking characteristics
of the input file in the output file
<footnote><para>This behavior became the default in November 2014 with
<acronym><acronymword>NCO</acronymword></acronym> version 4.4.7.
Prior versions would always use netCDF default chunking in the output
file when no <acronym><acronymword>NCO</acronymword></acronym> chunking switches were activated, regardless
of the chunking in the input file.</para></footnote>.
In other words, preserving chunking requires no switches or user
intervention.
</para>
<para>Users specify the desired chunking policy with the <samp>-P</samp> switch 
(or its long option equivalents, <samp>--cnk_plc</samp> and
<samp>--chunk_policy</samp>) and its <var>cnk_plc</var> argument.
As of August, 2014, six chunking policies are implemented:&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="936"><samp>all</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="937"><samp>g2d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="938"><samp>g3d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="939"><samp>r1d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="940"><samp>xpl</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="941"><samp>xst</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="942"><samp>cnk_all</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="943"><samp>cnk_g2d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="944"><samp>cnk_g3d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="945"><samp>cnk_r1d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="946"><samp>cnk_xpl</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="947"><samp>cnk_xst</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="948"><samp>plc_all</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="949"><samp>plc_g2d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="950"><samp>plc_g3d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="951"><samp>plc_r1d</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="952"><samp>plc_xpl</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="953"><samp>plc_xst</samp></indexterm></cindex>
</para><table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunk All Variables</itemformat></item>
</tableterm><tableitem><para>Definition: Chunk all variables possible.
For obvious reasons, scalar variables cannot be chunked.&linebreak;
Alternate invocation: <code>ncchunk</code>&linebreak;
<var>cnk_plc</var> key values: <samp>all</samp>, <samp>cnk_all</samp>, <samp>plc_all</samp>&linebreak;
Mnemonic: All&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunk Variables with at least Two Dimensions [<emph>default</emph>]</itemformat></item>
</tableterm><tableitem><para>Definition: Chunk all variables possible with at least two dimensions&linebreak;
Alternate invocation: none&linebreak;
<var>cnk_plc</var> key values: <samp>g2d</samp>, <samp>cnk_g2d</samp>, <samp>plc_g2d</samp>&linebreak;
Mnemonic: <emph>G</emph>reater than or equal to <emph>2</emph> <emph>D</emph>imensions&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunk Variables with at least Three Dimensions</itemformat></item>
</tableterm><tableitem><para>Definition: Chunk all variables possible with at least three dimensions&linebreak;
Alternate invocation: none&linebreak;
<var>cnk_plc</var> key values: <samp>g3d</samp>, <samp>cnk_g3d</samp>, <samp>plc_g3d</samp>&linebreak;
Mnemonic: <emph>G</emph>reater than or equal to <emph>3</emph> <emph>D</emph>imensions&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunk One-Dimensional Record Variables</itemformat></item>
</tableterm><tableitem><para>Definition: Chunk all 1-D record variables&linebreak;
Alternate invocation: none&linebreak;
Any specified (with <samp>--cnk_dmn</samp>) record dimension chunksizes will
be applied only to 1-D record variables (and to no other variables).
Other dimensions may be chunked with their own <samp>--cnk_dmn</samp> options 
that will apply to all variables. 
<var>cnk_plc</var> key values: <samp>r1d</samp>, <samp>cnk_r1d</samp>, <samp>plc_r1d</samp>&linebreak;
Mnemonic: <emph>R</emph>ecord <emph>1</emph>-<emph>D</emph> variables&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunk Variables Containing Explicitly Chunked Dimensions</itemformat></item>
</tableterm><tableitem><para>Definition: Chunk all variables possible that contain at least one
dimension whose chunksize was explicitly set with the <samp>--cnk_dmn</samp> option.
Alternate invocation: none&linebreak;
<var>cnk_plc</var> key values: <samp>xpl</samp>, <samp>cnk_xpl</samp>, <samp>plc_xpl</samp>&linebreak;
Mnemonic: E<emph>XPL</emph>icitly specified dimensions&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunk Variables that are already Chunked</itemformat></item>
</tableterm><tableitem><para>Definition: Chunk only variables that are already chunked in the input
file. 
When used in conjunction with <samp>cnk_map=xst</samp> this option preserves
and copies the chunking parameters from the input to the output file.
Alternate invocation: none&linebreak;
<var>cnk_plc</var> key values: <samp>xst</samp>, <samp>cnk_xst</samp>, <samp>plc_xst</samp>&linebreak;
Mnemonic: E<emph>X</emph>i<emph>ST</emph>ing chunked variables&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunk Variables with <acronym><acronymword>NCO</acronymword></acronym> recommendations</itemformat></item>
</tableterm><tableitem><para>Definition: Chunk all variables according to <acronym><acronymword>NCO</acronymword></acronym> best
practices. 
This is a virtual option that ensures the chunking policy is (in the 
subjective opinion of the authors) the best policy for typical usage.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.8 (February, 2015), this virtual policy
implements <samp>map_rew</samp> for 3-D variables and <samp>map_lfp</samp> for all
other variables.&linebreak;
Alternate invocation: none&linebreak;
<var>cnk_plc</var> key values: <samp>nco</samp>, <samp>cnk_nco</samp>, <samp>plc_nco</samp>&linebreak;
Mnemonic: <emph>N</emph>et<emph>C</emph>DF<emph>O</emph>perator&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Unchunking</itemformat></item>
</tableterm><tableitem><para>Definition: Unchunk all variables possible. 
The <acronym><acronymword>HDF5</acronymword></acronym> storge layer requires that record variables (i.e.,
variables that contain at least one record dimension) must be chunked.
Also variables that are compressed or use checksums must be chunked.
Such variables cannot be unchunked.&linebreak;  
Alternate invocation: <code>ncunchunk</code>&linebreak;
<var>cnk_plc</var> key values: <samp>uck</samp>, <samp>cnk_uck</samp>, <samp>plc_uck</samp>, <samp>none</samp>, <samp>unchunk</samp>&linebreak;
Mnemonic: <emph>U</emph>n<emph>C</emph>hun<emph>K</emph>&linebreak;
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>Equivalent key values are fully interchangeable.
Multiple equivalent options are provided to satisfy disparate needs
and tastes of <acronym><acronymword>NCO</acronymword></acronym> users working with scripts and from the
command line.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="954">chunking map</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="955">degenerate dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="956"><var>cnk_map</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="957"><code>-M <var>cnk_map</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="958"><code>--cnk_map <var>cnk_map</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="959"><code>--map <var>cnk_map</var></code></indexterm></cindex>
<para>The chunking algorithms must know the chunksizes of each dimension of
each variable to be chunked.
The correspondence between the input variable shape and the chunksizes
is called the <dfn>chunking map</dfn>. 
The user specifies the desired chunking map with the <samp>-M</samp> switch
(or its long option equivalents, <samp>--cnk_map</samp> and
<samp>--chunk_map</samp>) and its <var>cnk_map</var> argument.
Nine chunking maps are currently implemented:&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="960"><samp>dmn</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="961"><samp>scl</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="962"><samp>prd</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="963"><samp>lfp</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="964"><samp>rd1</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="965"><samp>xst</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="966"><samp>rew</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="967"><samp>nc4</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="968"><samp>nco</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="969"><samp>cnk_dmn</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="970"><samp>cnk_scl</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="971"><samp>cnk_prd</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="972"><samp>cnk_lfp</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="973"><samp>cnk_rd1</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="974"><samp>cnk_xst</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="975"><samp>cnk_rew</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="976"><samp>cnk_nc4</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="977"><samp>cnk_nco</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="978"><samp>map_dmn</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="979"><samp>map_scl</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="980"><samp>map_prd</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="981"><samp>map_lfp</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="982"><samp>map_rd1</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="983"><samp>map_xst</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="984"><samp>map_rew</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="985"><samp>map_nc4</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="986"><samp>map_nco</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="987">Chris Barker</indexterm></cindex>
</para><table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksize Equals Dimension Size</itemformat></item>
</tableterm><tableitem><para>Definition: Chunksize defaults to dimension size. 
Explicitly specify chunksizes for particular dimensions with
<samp>--cnk_dmn</samp> option.
In most cases this chunksize will be applied in all variables
that contain the specified dimension.
Some chunking policies noted above allow (fxm), and others (fxm) 
prevent this chunksize from applying to all variables.&linebreak;
<var>cnk_map</var> key values: <samp>dmn</samp>, <samp>cnk_dmn</samp>, <samp>map_dmn</samp>&linebreak;
Mnemonic: <emph>D</emph>i<emph>M</emph>e<emph>N</emph>sion&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksize Equals Dimension Size except Record Dimension</itemformat></item>
</tableterm><tableitem><para>Definition: Chunksize equals dimension size except record dimension has size one.
Explicitly specify chunksizes for particular dimensions with
<samp>--cnk_dmn</samp> option.&linebreak;
<var>cnk_map</var> key values: <samp>rd1</samp>, <samp>cnk_rd1</samp>, <samp>map_rd1</samp>&linebreak;
Mnemonic: <emph>R</emph>ecord <emph>D</emph>imension size <emph>1</emph>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksize Equals Scalar Size Specified</itemformat></item>
</tableterm><tableitem><para>Definition: Chunksize for all dimensions is set with the
<samp>--cnk_scl=<var>sz_lmn</var></samp> option.
For this map <var>sz_lmn</var> itself becomes the chunksize of each
dimension.  
This is in contrast to the <var>cnk_prd</var> map, where the <var>r</var>th root
of <var>sz_lmn</var>) becomes the chunksize of each dimension.&linebreak; 
<var>cnk_map</var> key values: <samp>scl</samp>, <samp>cnk_scl</samp>, <samp>map_scl</samp>&linebreak;
Mnemonic: <emph>SC</emph>a<emph>L</emph>ar&linebreak;
<var>cnk_map</var> key values: <samp>xpl</samp>, <samp>cnk_xpl</samp>, <samp>map_xpl</samp>&linebreak;
Mnemonic: E<emph>XPL</emph>icitly specified dimensions&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksize Product Matches Scalar Size Specified</itemformat></item>
</tableterm><tableitem><para>Definition: The product of the chunksizes for each variable
matches (approximately equals) the size specified with the
<samp>--cnk_scl=<var>sz_lmn</var></samp> option.
A dimension of size one is said to be <emph>degenerate</emph>.
For a variable of rank <var>R</var> (i.e., with <var>R</var> non-degenerate
dimensions), the chunksize in each non-degenerate dimension is
(approximately) the <var>R</var>th root of <var>sz_lmn</var>.
This is in contrast to the <var>cnk_scl</var> map, where <var>sz_lmn</var> itself
becomes the chunksize of each dimension.&linebreak; 
<var>cnk_map</var> key values: <samp>prd</samp>, <samp>cnk_prd</samp>, <samp>map_prd</samp>&linebreak;
Mnemonic: <emph>PR</emph>o<emph>D</emph>uct&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksize Lefter Product Matches Scalar Size Specified</itemformat></item>
</tableterm><tableitem><para>Definition: The product of the chunksizes for each variable
(approximately) equals the size specified with the
<samp>--cnk_byt=<var>sz_byt</var></samp> (not <samp>--cnk_dfl</samp>) option.
This is accomplished by using dimension sizes as chunksizes for the
rightmost (most rapidly varying) dimensions, and then &textldquo;flexing&textrdquo; the
chunksize of the leftmost (least rapidly varying) dimensions such that 
the product of all chunksizes matches the specified size.
All <var>L</var>-dimensions to the left of and including the first record 
dimension define the left-hand side.
To be precise, if the total size (in bytes) of the variable is
<var>var_sz</var>, and if the specified (with <samp>--cnk_byt</samp>) product of
the <var>R</var> &textldquo;righter&textrdquo; dimensions (those that vary more rapidly than
the first record dimension) is <var>sz_byt</var>, then chunksize (in bytes)
of each of the <var>L</var> lefter dimensions is (approximately) the
<var>L</var>th root of <math><var>var_sz</var>/<var>sz_byt</var></math>.
This map was first proposed by Chris Barker.&linebreak;
<var>cnk_map</var> key values: <samp>lfp</samp>, <samp>cnk_lfp</samp>, <samp>map_lfp</samp>&linebreak;
Mnemonic: <emph>L</emph>e<emph>F</emph>ter <emph>P</emph>roduct&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksize Equals Existing Chunksize</itemformat></item>
</tableterm><tableitem><para>Definition: Chunksizes are copied from the input to the output
file for every variable that is chunked in the input file.
Variables not chunked in the input file will be chunked with 
default mappings.&linebreak;
<var>cnk_map</var> key values: <samp>xst</samp>, <samp>cnk_xst</samp>, <samp>map_xst</samp>&linebreak;
Mnemonic: E<emph>X</emph>i<emph>ST</emph>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksize Balances 1D and (N-1)-D Access to N-D Variable [<emph>default for netCDF4 input</emph>]</itemformat></item>
</tableterm><tableitem><para>Definition: Chunksizes are chosen so that 1-D and (<var>N-1</var>)-D
hyperslabs of <var>3</var>-D variables (e.g., point-timeseries or
latitude/longitude surfaces of 3-D fields) both require approximately
the same number of chunks. 
Hence their access time should be balanced.
Russ Rew explains the motivation and derivation for this strategy 
<uref><urefurl>http://www.unidata.ucar.edu/blogs/developer/en/entry/chunking_data_choosing_shapes</urefurl><urefdesc spaces="\n">here</urefdesc></uref>.&linebreak;
<var>cnk_map</var> key values: <samp>rew</samp>, <samp>cnk_rew</samp>, <samp>map_rew</samp>&linebreak;
Mnemonic: Russ <emph>REW</emph>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksizes use netCDF4 defaults</itemformat></item>
</tableterm><tableitem><para>Definition: Chunksizes are determined by the underlying netCDF library.
All variables selected by the current chunking policy have their
chunksizes determined by netCDF library defaults. 
The default algorithm netCDF uses to determine chunksizes has changed
through the years, and thus depends on the netCDF library version.
This map can be used to reset (portions of) previously chunked files to
default chunking values.&linebreak;
<var>cnk_map</var> key values: <samp>nc4</samp>, <samp>cnk_nc4</samp>, <samp>map_nc4</samp>&linebreak;
Mnemonic: <emph>N</emph>et<emph>C</emph>DF<emph>4</emph>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Chunksizes use <acronym><acronymword>NCO</acronymword></acronym> recommendations [<emph>default for netCDF3 input</emph>]</itemformat></item>
</tableterm><tableitem><para>Definition: Chunksizes are determined by the currently recommended
<acronym><acronymword>NCO</acronymword></acronym> map.
This is a virtual option that ensures the chunking map is (in the 
subjective opinion of the authors) the best map for typical usage.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.9 (May, 2015), this virtual map
calls <samp>map_lfp</samp>.&linebreak;
<!-- c for 3-D variables and @samp{map_lfp} for all others.@*   -->
<var>cnk_map</var> key values: <samp>nco</samp>, <samp>cnk_nco</samp>, <samp>map_nco</samp>&linebreak;
Mnemonic: <emph>N</emph>et<emph>C</emph>DF<emph>O</emph>perator&linebreak;
</para>
</tableitem></tableentry></table>
<noindent></noindent>
<para>It is possible to combine the above chunking map algorithms with
user-specified per-dimension (though not per-variable) chunksizes that 
override specific chunksizes determined by the maps above. 
The user specifies the per-dimension chunksizes with the (equivalent) 
long options <samp>--cnk_dmn</samp> or <samp>--chunk_dimension</samp>).
The option takes two comma-separated arguments,
<var>dmn_nm</var>,<var>sz_lmn</var>, which are the dimension name and its
chunksize (in elements, not bytes), respectively. 
The <samp>--cnk_dmn</samp> option may be used as many times as necessary.
</para>
<para>The default behavior of chunking depends on several factors.
As mentioned above, when no chunking options are explicitly specified by
the user, then <acronym><acronymword>NCO</acronymword></acronym> preserves the chunking characteristics of
the input file in the output file.
This is equivalent to specifying both <var>cnk_plc</var> and <var>cnk_map</var> 
as &textldquo;existing&textrdquo;, i.e., <samp>--cnk_plc=xst --cnk_map=xst</samp>.
If 
output netCDF4 files are chunked with the default behavior of the 
netCDF4 library.
</para>
<para>When any chunking parameter <emph>except</emph> <samp>cnk_plc</samp> or
<samp>cnk_map</samp> is specified (such as <samp>cnk_dmn</samp> or
<samp>cnk_scl</samp>), then the &textldquo;existing&textrdquo; policy and map are
retained and the output chunksizes are modified where necessary in
accord with the user-specified parameter.
When <samp>cnk_map</samp> is specified and <samp>cnk_plc</samp> is not, then
<acronym><acronymword>NCO</acronymword></acronym> picks (what it thinks is) the optimal chunking policy. 
This has always been policy <samp>map_g2d</samp>.
When <samp>cnk_plc</samp> is specified and <samp>cnk_map</samp> is not, then
<acronym><acronymword>NCO</acronymword></acronym> picks (what it thinks is) the optimal chunking map.
This has always been map <samp>map_rd1</samp>.
</para>
<para>To start afresh and return to netCDF4 chunking defaults, select
<samp>cnk_map=nc4</samp>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;xmp_cnk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_cnk --&gt;
&lt;a name=&quot;xmp_chunk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_chunk --&gt;
</html>
<example endspaces=" ">
<pre xml:space="preserve"># Simple chunking and unchunking
ncks -O -4 --cnk_plc=all     in.nc out.nc # Chunk in.nc
ncks -O -4 --cnk_plc=unchunk in.nc out.nc # Unchunk in.nc

# Chunk data then unchunk it, printing informative metadata
ncks -O -4 -D 4 --cnk_plc=all ~/nco/data/in.nc ~/foo.nc
ncks -O -4 -D 4 --cnk_plc=uck ~/foo.nc ~/foo.nc

# Set total chunksize to 8192 B
ncks -O -4 -D 4 --cnk_plc=all --cnk_byt=8192 ~/nco/data/in.nc ~/foo.nc

# More complex chunking procedures, with informative metadata
ncks -O -4 -D 4 --cnk_scl=8 ~/nco/data/in.nc ~/foo.nc
ncks -O -4 -D 4 --cnk_scl=8 dstmch90_clm.nc ~/foo.nc
ncks -O -4 -D 4 --cnk_dmn lat,64 --cnk_dmn lon,128 dstmch90_clm.nc \ 
 ~/foo.nc 
ncks -O -4 -D 4 --cnk_plc=uck ~/foo.nc ~/foo.nc
ncks -O -4 -D 4 --cnk_plc=g2d --cnk_map=rd1 --cnk_dmn lat,32 \
 --cnk_dmn lon,128 dstmch90_clm_0112.nc ~/foo.nc

# Chunking works with all operators...
ncap2 -O -4 -D 4 --cnk_scl=8 -S ~/nco/data/ncap2_tst.nco \ 
 ~/nco/data/in.nc ~/foo.nc
ncbo -O -4 -D 4 --cnk_scl=8 -p ~/nco/data in.nc in.nc ~/foo.nc
ncecat -O -4 -D 4 -n 12,2,1 --cnk_dmn lat,32 \ 
 -p /data/zender/dstmch90 dstmch90_clm01.nc ~/foo.nc
ncflint -O -4 -D 4 --cnk_scl=8 ~/nco/data/in.nc ~/foo.nc
ncpdq -O -4 -D 4 -P all_new --cnk_scl=8 -L 5 ~/nco/data/in.nc ~/foo.nc
ncrcat -O -4 -D 4 -n 12,2,1 --cnk_dmn lat,32 \ 
 -p /data/zender/dstmch90 dstmch90_clm01.nc ~/foo.nc
ncwa -O -4 -D 4 -a time --cnk_plc=g2d --cnk_map=rd1 --cnk_dmn lat,32 \ 
 --cnk_dmn lon,128 dstmch90_clm_0112.nc ~/foo.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;r1d&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#r1d --&gt;
</html>
<para>Chunking policy <samp>r1d</samp> changes the chunksize of 1-D record variables
(and no other variables) to that specified (with <samp>--cnk_dmn</samp>)
chunksize. 
Any specified record dimension chunksizes will be applied to 1-D
record variables only. 
Other dimensions may be chunked with their own <samp>--cnk_dmn</samp> options
that will apply to all variables. 
For example, 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --cnk_plc=r1d --cnk_dmn=time,1000. in.nc out.nc
</pre></example>
<para>This sets <code>time</code> chunks to 1000 only in 1-D record variables. 
Without the <samp>r1d</samp> policy, <code>time</code> chunks would change in all 
variables.   
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="988">record dimension</indexterm></cindex>
<para>It is appropriate to conclude by informing users about an aspect of
chunking that may not be expected.
Three types of variables are <emph>always</emph> chunked: Record variables,
Deflated (compressed) variables, and Checksummed variables.
Hence all variables that contain a record dimension are also chunked
(since data must be chunked in all dimensions, not just one).
Unless otherwise specified by the user, the other (fixed, non-record) 
dimensions of record variables are assigned default chunk sizes. 
The <acronym><acronymword>HDF5</acronymword></acronym> layer does all this automatically to optimize the
on-disk variable/file storage geometry of record variables.
Do not be surprised to learn that files created without any explicit
instructions to activate chunking nevertheless contain chunked
variables. 
</para>
<html endspaces=" ">
&lt;a name=&quot;qnt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#qnt --&gt;
&lt;a name=&quot;qnt_alg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#qnt_alg --&gt;
&lt;a name=&quot;quantize_algorithm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#quantize_algorithm --&gt;
&lt;a name=&quot;ppq&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ppq --&gt;
&lt;a name=&quot;PPQ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#PPQ --&gt;
&lt;a name=&quot;gbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gbr --&gt;
&lt;a name=&quot;GBR&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#GBR --&gt;
&lt;a name=&quot;BitGroom&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BitGroom --&gt;
&lt;a name=&quot;GranularBitRound&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#GranularBitRound --&gt;
&lt;a name=&quot;BitShave&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BitShave --&gt;
&lt;a name=&quot;BitSet&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BitSet --&gt;
&lt;a name=&quot;DigitRound&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#DigitRound --&gt;
&lt;a name=&quot;BitGroomRound&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BitGroomRound --&gt;
&lt;a name=&quot;HalfShave&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#HalfShave --&gt;
&lt;a name=&quot;BruteForce&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BruteForce --&gt;
&lt;a name=&quot;BitRound&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BitRound --&gt;
</html>
</section>
<node name="Quantization-Algorithms" spaces=" "><nodename>Quantization Algorithms</nodename><nodenext spaces=" ">Compression</nodenext><nodeprev spaces=" ">Chunking</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Quantization Algorithms</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="989"><acronym><acronymword>PPQ</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="990"><acronym><acronymword>GBR</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="991"><acronym><acronymword>BAA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="992">BitGroom</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="993">Granular BitRound</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="994">BitShave</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="995">BitSet</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="996">DigitRound</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="997">BitGroomRound</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="998">HalfShave</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="999">BruteForce</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1000">BitRound</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1001"><code>--qnt_alg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1002"><code>--quantize_algorithm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1003">Quantization algorithm</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>ncecat</command>, <command>nces</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: None&linebreak;
Long options: <samp>--qnt_alg <var>alg_nm</var></samp>&linebreak;
<samp>--quantize_algorithm <var>alg_nm</var></samp>&linebreak;
</para></cartouche>

<para>As of <w>version 5.2.5</w> (May 2024), <acronym><acronymword>NCO</acronymword></acronym> supports a simple
<acronym><acronymword>API</acronymword></acronym> to specify quantization algorithms.
This method uses the <samp>--qnt_alg=alg_nm</samp> option, where
<code>alg_nm</code> is a happy, friendly, abbreviation or full English
string for the quantization algorithm name.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -7 -L 1               --qnt default=3 in.nc out.nc # Granular BitRound (NSD)
ncks -7 -L 1 --qnt_alg=btg --qnt default=3 in.nc out.nc # BitGroom (NSD)
ncks -7 -L 1 --qnt_alg=shv --qnt default=3 in.nc out.nc # BitShave (NSD)
ncks -7 -L 1 --qnt_alg=set --qnt default=3 in.nc out.nc # BitSet (NSD)
ncks -7 -L 1 --qnt_alg=dgr --qnt default=3 in.nc out.nc # DigitRound (NSD)
ncks -7 -L 1 --qnt_alg=gbr --qnt default=3 in.nc out.nc # Granular BitRound (NSD)
ncks -7 -L 1 --qnt_alg=bgr --qnt default=3 in.nc out.nc # BitGroomRound (NSD)
ncks -7 -L 1 --qnt_alg=sh2 --qnt default=9 in.nc out.nc # HalfShave (NSB)
ncks -7 -L 1 --qnt_alg=brt --qnt default=3 in.nc out.nc # BruteForce (NSD)
ncks -7 -L 1 --qnt_alg=btr --qnt default=9 in.nc out.nc # BitRound (NSB)
</verbatim>
</example>
<para>The algorithm strings shown above give only a hint as to the
flexibility of synonyms recognized as algorithm names.
For example, synonyms for <samp>btr</samp> include (case-insensitive
versions of) <samp>bitround</samp>, <samp>bit round</samp>, and <samp>bit-round</samp>. 
Try it and see!
</para>
<para>Behind the scenes, <acronym><acronymword>NCO</acronymword></acronym> translates the algorithm name to an
enumerated bit-adjustment-algorithm <acronym><acronymword>BAA</acronymword></acronym> value.
The <acronym><acronymword>BAA</acronymword></acronym> interface is undocumented and unsupported, however.
This is to give the maintainers to change the unlying algorithm
organization. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -7 -L 1         --ppc default=3 in.nc out.nc # Granular BitRound (NSD)
ncks -7 -L 1 --baa=0 --ppc default=3 in.nc out.nc # BitGroom (NSD)
ncks -7 -L 1 --baa=1 --ppc default=3 in.nc out.nc # BitShave (NSD)
ncks -7 -L 1 --baa=2 --ppc default=3 in.nc out.nc # BitSet (NSD)
ncks -7 -L 1 --baa=3 --ppc default=3 in.nc out.nc # DigitRound (NSD)
ncks -7 -L 1 --baa=4 --ppc default=3 in.nc out.nc # Granular BitRound (NSD)
ncks -7 -L 1 --baa=5 --ppc default=3 in.nc out.nc # BitGroomRound (NSD)
ncks -7 -L 1 --baa=6 --ppc default=9 in.nc out.nc # HalfShave (NSB)
ncks -7 -L 1 --baa=7 --ppc default=3 in.nc out.nc # BruteForce (NSD)
ncks -7 -L 1 --baa=8 --ppc default=9 in.nc out.nc # BitRound (NSB)
</verbatim>
</example>
<para>Although the <code>qnt_alg</code> and <acronym><acronymword>BAA</acronymword></acronym> <acronym><acronymword>API</acronymword></acronym>s are
equivalent, the <acronym><acronymword>BAA</acronymword></acronym> values may change in the future so using
the <samp>qnt_alg</samp> interface is recommended.
</para>
<html endspaces=" ">
&lt;a name=&quot;bg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bg --&gt;
&lt;a name=&quot;bitgrooming&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bitgrooming --&gt;
&lt;a name=&quot;Bit-Grooming&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#Bit-Grooming --&gt;
&lt;a name=&quot;BG&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#BG --&gt;
&lt;a name=&quot;ppc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ppc --&gt;
&lt;a name=&quot;PPC&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#PPC --&gt;
&lt;a name=&quot;compression&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#compression --&gt;
&lt;a name=&quot;cmp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cmp --&gt;
&lt;a name=&quot;nsd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nsd --&gt;
&lt;a name=&quot;NSD&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#NSD --&gt;
&lt;a name=&quot;dsd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dsd --&gt;
&lt;a name=&quot;DSD&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#DSD --&gt;
&lt;a name=&quot;qnt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#qnt --&gt;
</html>
</section>
<node name="Compression" spaces=" "><nodename>Compression</nodename><nodenext spaces=" ">Deflation</nodenext><nodeprev spaces=" ">Quantization Algorithms</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Compression</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1004"><code>--cmp_sng</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1005"><code>--compression</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1006">codecs</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1007">Zstandard</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1008">Bzip2</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1009">Granular BitRound</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1010"><code>--ppc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1011"><code>--precision_preserving_compression</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1012"><code>--quantize</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1013"><code>--qnt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1014">lossy compression</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1015">quantization</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1016">rounding</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1017">Huffman coding</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1018"><command>gzip</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1019"><command>zlib</command></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>ncecat</command>, <command>nces</command>,
<command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>, <command>ncra</command>,
<command>ncrcat</command>, <command>ncwa</command>&linebreak; 
Short options: None&linebreak;
Long options: <samp>--ppc <var>var1</var>[,<var>var2</var>[,...]]=<var>prc</var></samp>,&linebreak;
<samp>--precision_preserving_compression <var>var1</var>[,<var>var2</var>[,...]]=<var>prc</var></samp>,&linebreak;
<samp>--qnt <var>var1</var>[,<var>var2</var>[,...]]=<var>prc</var></samp>&linebreak;
<samp>--quantize <var>var1</var>[,<var>var2</var>[,...]]=<var>prc</var></samp>&linebreak;
<samp>--qnt_alg <var>alg_nm</var></samp>&linebreak;
<samp>--quantize_algorithm <var>alg_nm</var></samp>&linebreak;
<samp>--cmp cmp_sng</samp>&linebreak;
<samp>--cmp <var>codec1</var>[,<var>params1</var>[|<var>codec2</var>[,<var>params2</var>[|...]]]]</samp>&linebreak;
<samp>--codec <var>codec1</var>[,<var>params1</var>[|<var>codec2</var>[,<var>params2</var>[|...]]]]</samp>&linebreak;
</para></cartouche>

<para>Compression is a rapidly developing area in geoscientific software,
and <acronym><acronymword>NCO</acronymword></acronym> is no exception.
Documentation of these features can quickly become out-of-date.
A brief review of compression support from the early days until now:
<acronym><acronymword>NCO</acronymword></acronym> first supported Linear Packing with <command>ncpdq</command>
in 2004.
The advent of netCDF4 allowed <acronym><acronymword>NCO</acronymword></acronym> to support lossless
compression with the <acronym><acronymword>DEFLATE</acronymword></acronym> algorithm beginning in 2007.
Nearly a decade elapsed before the next features came in 2015 when,
thanks to support from the <acronym><acronymword>DOE</acronymword></acronym>, we developed the lossy
BitGroom quantization algorithm.
<acronym><acronymword>NCO</acronymword></acronym> soon introduced a flexible per-variable <acronym><acronymword>API</acronymword></acronym>
(<samp>--ppc</samp> and <samp>--qnt</samp>) to support it, and its relatives
BitShave, and BitSet, in all arithmetic operators. 
This work helped spur interest and research on other Bit Adjustment
Algorithms (<acronym><acronymword>BAA</acronymword></acronym>s) that perform quantization.
</para>
<para>In 2020 we reduced the quantization error of BitGroom by implementing
<acronym><acronymword>IEEE</acronymword></acronym>-rounding (aka BitRound), and newer quantization
algorithms including BitGroomRound, HalfShave, and DigitRound
<footnote><para>R. Kouznetsov contributed the masking techinques used in
BitRound, BitGroomRound, and HalfShave. Thanks Rostislav!</para></footnote>.
These algorithms are all accessible via the <samp>--baa</samp> option.
In 2020 <acronym><acronymword>NSF</acronymword></acronym> awarded support for us to develop the Community 
Codec Respository to put a friendlier <acronym><acronymword>API</acronymword></acronym> on the
<acronym><acronymword>HDF5</acronymword></acronym> shared-library filter mechanism so that all netCDF
users could shift to more modern and efficient codecs than
<acronym><acronymword>DEFLATE</acronymword></acronym>. 
This strategy aligned with needs of operational forecasters supported
by software engineers at the <acronym><acronymword>NOAA</acronymword></acronym> Environmental Modeling
Center (<acronym><acronymword>EMC</acronymword></acronym>), who contributed to developing and testing the
<acronym><acronymword>CCR</acronymword></acronym> <footnote><para>E. Hartnett of <acronym><acronymword>NOAA</acronymword></acronym> <acronym><acronymword>EMC</acronymword></acronym> is 
co-founder and co-maintainer of the <acronym><acronymword>CCR</acronymword></acronym>. Thanks Ed!</para></footnote>.
By the end of 2021 the <acronym><acronymword>CCR</acronymword></acronym> supported codecs for Bzip2,
Zstandard, BitGroom, and Granular BitRound. 
The <acronym><acronymword>CCR</acronymword></acronym> performance helped persuade the netCDF team at
Unidata of the importance and practicality of expanding compression
options in the base netCDF C-library beyond the venerable
<acronym><acronymword>DEFLATE</acronymword></acronym> algorithm.
Together, we merged the quantization, Bzip2, and Zstandard codecs and
<acronym><acronymword>API</acronymword></acronym> from the <acronym><acronymword>CCR</acronymword></acronym> into what became (in June, 2022)
netCDF version 4.9.0
<footnote><para>D. Heimbigner (Unidata) helped implement all these features
into netCDF. Thanks Dennis!</para></footnote>.
<acronym><acronymword>NCO</acronymword></acronym> version 5.1.0 (released in July, 2022) unified these
advances by fully supporting its own quantization methods,
<acronym><acronymword>CCR</acronymword></acronym> codecs, generic (i.e., non-<acronym><acronymword>CCR</acronymword></acronym>) <acronym><acronymword>HDF5</acronymword></acronym>
codecs, and the quantization algorithms and modern lossless codecs in
netCDF 4.9.0.  
</para>
<para>Access to the quantization and compression options is available
through three complementary, backwards-compatible, and overlapping
<acronym><acronymword>API</acronymword></acronym>s designed to accomodate the successive generations of
compression features. 
The original generation of compression options remain accessible
through the standard <command>ncpdq</command> (for Linear Packing) and
<acronym><acronymword>NCO</acronymword></acronym>-wide <code>-L</code> option (or its synonyms <code>--deflate</code>
and <code>--dfl_lvl</code>) for <acronym><acronymword>DEFLATE</acronymword></acronym>. 
The second generation of compression options refers to the
<code>--qnt</code>, <code>--ppc</code>, and <code>--baa</code> (and related synonyms)
options that control the type and level of quantization algorithm, and
the variables to operate on.
These options call quantization and rounding routines implemented
within <acronym><acronymword>NCO</acronymword></acronym> itself, rather than in external libraries.
The new <code>--cmp_sng</code> (and synonyms) option provides an
<acronym><acronymword>API</acronymword></acronym> for <acronym><acronymword>NCO</acronymword></acronym> to invoke all lossy and lossless
codecs in external libraries, including the netCDF C-library, the
<acronym><acronymword>CCR</acronymword></acronym>, and generic <acronym><acronymword>HDF5</acronymword></acronym> codecs.
</para>
<para>The <code>--cmp_sng</code> (and synonyms <code>--cmp</code> and
<code>--compression</code>) options take as argument a string <var>cmp_sng</var>
which contains a list of quantization and compression algorithms and
their respective parameters.
The <var>cmp_sng</var> must adhere to a superset of the filter-list
<acronym><acronymword>API</acronymword></acronym> introduced by the <command>nccopy</command> command and reported
in the netCDF <code>_Filter</code> attribute.
This <acronym><acronymword>API</acronymword></acronym> uses the <acronym><acronymword>UNIX</acronymword></acronym> pipe symbole <code>|</code> to
separate the codecs applied as <acronym><acronymword>HDF5</acronymword></acronym> filters to a variable:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --hdn -m in.nc | grep _Filter
      u:_Filter = &quot;307,2|32015,3&quot; ;
      U:_Filter = &quot;32001,2,2,4,4185932,5,1,1&quot; ;
% ncdump -h -s in.nc | grep _Filter
		u:_Filter = &quot;307,2|32015,3&quot; ;
                U:_Filter = &quot;32001,2,2,4,4185932,5,1,1&quot; ;
</verbatim>
</example>
<para>The above example shows variables compressed with two successive
codecs.
The variable <code>u</code> was compressed with codecs with <acronym><acronymword>HDF5</acronymword></acronym>
filter <acronym><acronymword>ID</acronymword></acronym>s 307 and 32015, respectively.  
<acronym><acronymword>NCO</acronymword></acronym> translates these mysterious <acronym><acronymword>HDF5</acronymword></acronym> numeric
filter <acronym><acronymword>ID</acronymword></acronym>s into filter names in the <acronym><acronymword>CDL</acronymword></acronym> comments
when invoked with a higher debugging level: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks -D 2 --hdn -m in.nc | grep _Filter
      u:_Filter = &quot;307,2|32015,3&quot; ; // char codec(s): Bzip2, Zstandard
      U:_Filter = &quot;32001,2,2,4,4185932,5,1,1&quot; ; // char codec(s): \
                                              Blosc Shuffle, Blosc LZ4
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;qnt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#qnt --&gt;
&lt;a name=&quot;dfl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dfl --&gt;
&lt;a name=&quot;zst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#zst --&gt;
&lt;a name=&quot;bz2&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bz2 --&gt;
&lt;a name=&quot;shf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#shf --&gt;
&lt;a name=&quot;gbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gbr --&gt;
&lt;a name=&quot;btg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#btg --&gt;
&lt;a name=&quot;bgr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bgr --&gt;
&lt;a name=&quot;btr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#btr --&gt;
&lt;a name=&quot;f32&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#f32 --&gt;
&lt;a name=&quot;dns&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dns --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1020"><code>dfl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1021"><code>zst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1022"><code>bz2</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1023"><code>shf</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1024"><code>gbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1025"><code>btg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1026"><code>bgr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1027"><code>f32</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1028"><code>dns</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1029">Shuffle</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1030">Fletcher32</indexterm></cindex>
<para>You may provide any operator (besides <command>ncrename</command> and
<command>ncatted</command>) with a <var>cmp_sng</var> comprised of an arbitrary
number of <acronym><acronymword>HDF5</acronymword></acronym> filters specified either by numeric
<acronym><acronymword>ID</acronymword></acronym> or by name, including <acronym><acronymword>NCO</acronymword></acronym>-supported synonyms:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp=&quot;307,2|32015,3&quot; in.nc out.nc # Filter numeric IDs
% ncks --cmp=&quot;Bzip2,2|Zstandard,3&quot; in.nc out.nc # Filter names
% ncks --cmp=&quot;bzp,2|zst,3&quot; in.nc out.nc # Filter abbreviations
</verbatim>
</example>
<para><acronym><acronymword>NCO</acronymword></acronym> also uses this <acronym><acronymword>API</acronymword></acronym> to invoke the netCDF
quantization algorithms such as Granular BitGroom and BitRound. 
netCDF records the operation of quantization algorithms in a
<code>_Quantize</code> attribute.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp=&quot;gbr,2|zst,3&quot; in.nc out.nc 
% ncks -D 2 --hdn -m out.nc | grep 'Filt|Quant'
      u:_QuantizeGranularBitRoundNumberOfSignificantDigits = 2 ;
      u:_Filter = &quot;32015,3&quot; ; // char Codec(s): Zstandard
</verbatim>
</example>
<para><acronym><acronymword>NCO</acronymword></acronym> calls the filters in the order specified.
Thus, it is important to follow the above example and to specify
compression pre-filters like quantization and Shuffle prior to any
lossless codecs.  
However, the netCDF library imposes rules that can override the
user-specified order for the Shuffle and Fletcher32 filters as
described below (these are always helpful in real-world situations).
</para>
<para>The <samp>--cmp</samp> option specifies a global compression configuration.
This is fine for lossless codecs, since there is little evidence to
motivate per-variable lossless compression levels for real-world data.
By contrast, it is often desirable to configure quantization levels on
a per-variable basis.
This is because the real information content of geophysical variables
can differ strongly due to a multitude of factors including the field
meaning, spatial location, and dimensional units.
<acronym><acronymword>NCO</acronymword></acronym> applies any quantization filter specified in
<var>cmp_sng</var> uniformly to all variables encountered (the <samp>--qnt</samp>
quantization option/<acronym><acronymword>API</acronymword></acronym> is still available for per-variable
quantization parameters, as discussed below). 
The one exception is that <acronym><acronymword>NCO</acronymword></acronym> prohibits quantization of
&textldquo;coordinate-like variables&textrdquo;.
Variables that are tradiational (1-dimensional) coordinates, or that
are mentioned in the values of <acronym><acronymword>CF</acronymword></acronym> <code>bounds</code>,
<code>climatology</code>, <code>coordinates</code>, or <code>grid_mapping</code>
attributes, all count as coordinate-like variables.
Such variables include quantities like gridcell areas and boundaries.
<acronym><acronymword>NCO</acronymword></acronym> eschews quantizing such variables to avoid unforeseen
or unanticipated degradation of numerical accuracy due to propagation
of quantization errors in post-processing.
</para>
<para>Specifying the compression string with codec names should make
lossy and lossless compression easier for users to understand and
employ. 
There are, however, a few wrinkles and legacy conventions that
might surprise users when first encountered.
For instance, the codecs for <acronym><acronymword>DEFLATE</acronymword></acronym>, Shuffle, and
Fletcher32 have always been built-in to netCDF.
Users can instruct <acronym><acronymword>NCO</acronymword></acronym> to apply these filters with the
new <acronym><acronymword>API</acronymword></acronym>, yet their application to a dataset will still
be reported using the &textldquo;old&textrdquo; per-filter attributes:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp=&quot;fletcher32|shuffle|deflate&quot; in.nc out.nc
% ncks --hdn -m out.nc
...
      u:_DeflateLevel = 1 ;
      u:_Shuffle = &quot;true&quot; ;
      u:_Fletcher32 = &quot;true&quot; ;
...
</verbatim>
</example>
<para>As this example shows, it is not required to give filter parameter
arguments to all filters.
When the user omits filter parameters (e.g., compression level,
<acronym><acronymword>NSD</acronymword></acronym>, <acronym><acronymword>NSB</acronymword></acronym>, or other filter configurator) 
for select filters that require such a parameter, <acronym><acronymword>NCO</acronymword></acronym>
automatically inserts an appropriate default filter parameter.
<acronym><acronymword>NCO</acronymword></acronym> assumes default parameters 1, 4, 1, and 3, for the
lossless filters <acronym><acronymword>DEFLATE</acronymword></acronym>, Shuffle, Bzip2, and Zstandard,
respectively.   
<acronym><acronymword>NCO</acronymword></acronym> assumes default parameters 3, 3, and 9, for the lossy
quantization algorithms BitGroom, Granular BitGroom, and BitRound,
respectively.   
Note that the netCDF filter for the Fletcher32 checksum algorithm
does not accept a parameter argument, and <acronym><acronymword>NCO</acronymword></acronym> ignores
any parameters provided to this filter.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp=&quot;fletcher32|shuffle|granularbr|deflate|zstandard&quot; ...
% ncks --cmp=&quot;f32|shf|gbr|dfl|zst&quot; ... # Shorthand, default parameters
% ncks --cmp=&quot;f32|shf,4|gbr,3|dfl,1|zst,3&quot; ... # Explicit parameters
</verbatim>
</example>

<para>The <code>cmd_sng</code> option supports an arbitrary number of filters.
An example that compressess then reads a file with most
netCDF-supported algorithms shows the mixture of filter-specific
attributes (<code>_Shuffle</code>, <code>_DeflateLevel</code>, <code>_Fletcher32</code>)
and generic filter attributes (<code>_Filter</code>) that result:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp='f32|shf|gbr|dfl|bz2|zst' in.nc out.nc
% ncks --hdn -m out.nc
    float u(time) ;
      u:long_name = &quot;Zonal wind speed&quot; ;
      u:units = &quot;meter second-1&quot; ;
      u:_QuantizeGranularBitRoundNumberOfSignificantDigits = 3 ;
      u:_Storage = &quot;chunked&quot; ;
      u:_ChunkSizes = 1024 ;
      u:_Filter = &quot;307,1|32015,3&quot; ;
      u:_DeflateLevel = 1 ;
      u:_Shuffle = &quot;true&quot; ;
      u:_Fletcher32 = &quot;true&quot; ;
      u:_Endianness = &quot;little&quot; ;
</verbatim>
</example>
<para>Note that the <code>_Filter</code> value is a valid <var>cmp_sng</var> for
use as an argument to the <code>--cmp_sng</code> option.
This enables users to easily duplicate the compression settings
of one dataset in another dataset.
One can also find the global <var>cmp_sng</var> that <acronym><acronymword>NCO</acronymword></acronym> used to 
compress a dataset in the global <code>history</code> attribute.
</para>
<para>In the absence of instructions to the contrary, <acronym><acronymword>NCO</acronymword></acronym>
preserves the compression settings of datasets that it copies or
subsets. 
It simply defaults to copying the per-variable compression settings 
from the input file.
If the copy or subset command includes global compression instructions
(i.e., the <samp>--cmp</samp> or <samp>-L</samp> options), those instructions will
override the per-variable settings in the input file.
The user can eliminate all compression filters by setting
<var>cmp_sng</var> to the special value <code>none</code> (or to its synonyms
<code>uncompress</code>, <code>decompress</code>, <code>defilter</code>, or
<code>unset</code>).  
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp='f32|shf|gbr|dfl|bz2|zst' in.nc out.nc
% ncks --cmp='none' out.nc none.nc
% ncks --hdn -m none.nc
    float u(time) ;
      u:long_name = &quot;Zonal wind speed&quot; ;
      u:units = &quot;meter second-1&quot; ;
      u:_QuantizeGranularBitRoundNumberOfSignificantDigits = 3 ;
      u:_Storage = &quot;chunked&quot; ;
      u:_ChunkSizes = 1024 ;
      u:_Endianness = &quot;little&quot; ;
</verbatim>
</example>
<para>The uncompressed copy has no filter attributes remaining because all
filters have been removed.
The <code>_Quantize</code> attribute remains because the quantization was
applied as an internal algorithm not as an <acronym><acronymword>HDF5</acronymword></acronym> filter.
In contrast to lossless compression filters, lossy quantization
algorithms can never be &textldquo;removed&textrdquo; much less undone because, by
definition, they are lossy.
Removing compression is &textldquo;all or nothing&textrdquo; in that there is currently
no way to remove only one or a few codecs and leave the rest in place.
To do that, the user must instead recompress the dataset using a
<var>cmp_sng</var> that includes only the desired codecs.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp='shf|zst' ... # Compress
% ncks --cmp='none' ...    # Decompress (remove Shuffle and Zstd)
% ncks --cmp=zst,4 ...     # Recompress to new Zstd level, no Shuffle
</verbatim>
</example>

<para>Shuffle is an important filter than can boost lossless compression
ratios of geoscientific data by 10&textndash;20% (<pxref label="fgr_003aqnt_005fcr_005fdfl"><xrefnodename>fgr:qnt_cr_dfl</xrefnodename></pxref>).
</para><float name="fgr_003aqnt_005fcr_005fdfl" type="Figure" number="3.1" spaces=" " endspaces=" "><floattype>Figure</floattype><floatname>fgr:qnt_cr_dfl</floatname>
<image><imagefile>fgr/qnt_cr_dfl</imagefile><imagewidth>5.5in</imagewidth></image> 
<caption><para>Quantization and then compression by <acronym><acronymword>DEFLATE</acronymword></acronym>,
including the contribution of Shuffle.</para></caption>
</float>
<para>Both the netCDF library and <acronym><acronymword>NCO</acronymword></acronym> continue to treat the
Shuffle filter specially. 
If the Shuffle and <acronym><acronymword>DEFLATE</acronymword></acronym> algorithms are both invoked
through the standard netCDF <acronym><acronymword>API</acronymword></acronym> (i.e.,
<code>nc_def_var_deflate()</code>), then the netCDF library ensures that the
Shuffle filter is called before <acronym><acronymword>DEFLATE</acronymword></acronym>, indeed before any
filter except <code>Fletcher32</code> (which performs a checksum, not
compression).  
This behavior is welcome as it avoids inadvertent mis-use of Shuffle.
Prior to version 5.1.0, <acronym><acronymword>NCO</acronymword></acronym> always invoked Shuffle with
<acronym><acronymword>DEFLATE</acronymword></acronym>, and did not expose the Shuffle filter to user
control.
<acronym><acronymword>NCO</acronymword></acronym> now exposes Shuffle to user control for all filters.
To preserve backward compatibility, invoking the <acronym><acronymword>DEFLATE</acronymword></acronym>
algorithm with the <code>dfl</code> or <code>deflate</code> names (or with the
numeric <acronym><acronymword>HDF5</acronymword></acronym> filter <acronym><acronymword>ID</acronymword></acronym> of <code>1</code>) still sets
the Shuffle filter to true.
To invoke <acronym><acronymword>DEFLATE</acronymword></acronym> without Shuffle, use the special filter
names <code>dns</code> or <code>DEFLATE No Shuffe</code>.
Specifying the Shuffle filter along with any Blosc compressor causes
<acronym><acronymword>NCO</acronymword></acronym> to invoke the Blosc version of Shuffle instead of the
<acronym><acronymword>HDF5</acronymword></acronym> version of Shuffle.
The Blosc Shuffle should execute more rapidly because it takes
advantage of <acronym><acronymword>AVX2</acronymword></acronym> instructions, etc.
In summary, users must explicitly request Shuffle for all
non-<acronym><acronymword>DEFLATE</acronymword></acronym> codecs, otherwise Shuffle will not be
employed prior to those codecs.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --cmp='dfl' ...     # Invoke Shuffle then DEFLATE
% ncks --cmp='shf|dfl' ... # Same (default Shuffle stride 4-bytes)
% ncks --cmp='dns' ...     # Invoke DEFLATE (no Shuffle)
% ncks --cmp='shf|dns' ... # Invoke Shuffle then DEFLATE
% ncks --cmp='zst' ...     # Invoke Zstandard (no Shuffle)
% ncks --cmp='shf|zst' ... # Invoke Shuffle then Zstandard
% ncks --cmp='zst|shf' ... # Same (netCDF enforces Shuffle-first rule)
% ncks --cmp='shf' ...     # Invoke only Shuffle
% ncks --cmp='shf,8|zst' ... # Shuffle stride 8-bytes then Zstandard
% ncks --cmp='shf,8|dfl' ... # Shuffle stride remains default 4-bytes
% ncks --cmp='bls' ...     # Invoke Blosc (LZ by default) without Shuffle
% ncks --cmp='shf|bls' ... # Invoke Blosc (not HDF5) Shuffle, then Blosc LZ
</verbatim>
</example>
<para>The last example above shows how to invoke Shuffle with non-default
byte stride
<footnote><para>Full disclosure:
Documentation of the meaning of the Shuffle parameter is scarce.
I think though am not certain that the Shuffle parameter refers to the
number of contiguous byte-groups that the algorithm rearranges a chunk
of data into. 
I call this the stride.
Thus the default stride of 4 means that Shuffle rearranges a chunk of
4-byte integers into four consecutive sequences, the first comprises
all the leading bytes, the second comprises all the second bytes, etc.
A well-behaved stride should evenly divide the number of bytes in a
data chunk.</para></footnote>.
The netCDF library, and thus <acronym><acronymword>NCO</acronymword></acronym>, always uses the default
Shuffle stride (4 bytes) with the <acronym><acronymword>DEFLATE</acronymword></acronym> filter.
Specifying a different stride only has an effect with
non-<acronym><acronymword>DEFLATE</acronymword></acronym> filters.  
This ensures <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s default behavior with <acronym><acronymword>DEFLATE</acronymword></acronym>
does not change.
As explained above, invoke <acronym><acronymword>DEFLATE</acronymword></acronym> with <samp>--cmp=dns</samp>
instead of <samp>--cmp=dfl</samp> if you wish to suppress the otherwise
automatic invocation of Shuffle.
</para>
<para>Note that <acronym><acronymword>NCO</acronymword></acronym> and netCDF implement their quantization
algorithms internally, whereas the <acronym><acronymword>CCR</acronymword></acronym> implements them as
external shared-library codecs (valid only with netCDF4 files).
Since these quantization algorithms leave data in <acronym><acronymword>IEEE</acronymword></acronym>
format no codec/filter is required to read (or write) them.
Quantization therefore works with netCDF3 datasets, not just netCDF4.
netCDF applications that attempt to read data compressed with
shared-library filters must be linked to the same shared filters 
or the &textldquo;decompression&textrdquo; step will fail.
Datasets produced with netCDF or <acronym><acronymword>CCR</acronymword></acronym>-supported codecs
(Bzip2, <acronym><acronymword>DEFLATE</acronymword></acronym>, Zstandard) will be readable by all users
who upgrade to netCDF 4.9.0 or later or who install the
<acronym><acronymword>CCR</acronymword></acronym>.
There is no difference between a losslessly compressed dataset
produced with a <acronym><acronymword>CCR</acronymword></acronym>-supplied vs.&noeos; a netCDF-supplied
filter.
However, reading a dataset quantized by a <acronym><acronymword>CCR</acronymword></acronym> filter (e.g.,
BitGroom or GranularBG) requires access to the <acronym><acronymword>CCR</acronymword></acronym> filter,
which forces users to take an extra step to install the
<acronym><acronymword>CCR</acronymword></acronym>. 
This is an unfortunate artifact of implementing quantization as a
codec (which the <acronym><acronymword>CCR</acronymword></acronym> must do) vs.&noeos; an internal numerical
function (which netCDF and <acronym><acronymword>NCO</acronymword></acronym> do).
Where possible, people should encode datasets with netCDF-supported 
algorithms and codecs in preference to <acronym><acronymword>CCR</acronymword></acronym> or raw
<acronym><acronymword>HDF5</acronymword></acronym> codecs. 
Doing so will increase dataset portability.
</para>
<unnumberedsubsec spaces=" "><sectiontitle>Limitations of Current Compression <acronym><acronymword>API</acronymword></acronym></sectiontitle>
<para>The <acronym><acronymword>NCO</acronymword></acronym> filter <acronym><acronymword>API</acronymword></acronym> will evolve in a (hopefully)
backward-compatible manner as experience and feedback are gained.
All filter parameters are eventually passed to <acronym><acronymword>HDF5</acronymword></acronym> as
unsigned integers. 
By contrast, the current <acronym><acronymword>API</acronymword></acronym> treats all input arguments in
<var>cmp_sng</var> signed integers for ease-of-use.
For example, it is easier to specify a Zstandard filter level of
negative one as <samp>zstd,-1</samp> than as <samp>zstd,4294967295</samp>. 
<acronym><acronymword>NCO</acronymword></acronym> currently has no easy way to specify
the floating-point configuration parameters required by some
<acronym><acronymword>CCR</acronymword></acronym> filters and many external filters.
That said, most of the code to support the filter parameter syntax
documented at
<url><urefurl>https://docs.unidata.ucar.edu/netcdf-c/current/filters.html</urefurl></url>
and implemented in <command>ncgen</command> and <command>nccopy</command> is ready and
we expect to support that syntax in <acronym><acronymword>NCO</acronymword></acronym> 5.0.9.
That syntax is backward compatible with the integer-only input
assumptions already embedded in <acronym><acronymword>NCO</acronymword></acronym> 5.1.0.
In the meantime, we request your feedback, use-cases, and suggestions
before adopting a final approach.
</para>
<para>Another limitation of <acronym><acronymword>NCO</acronymword></acronym> 5.1.0 was that the Blosc filters
would fail without explanation.
This is why the manual does not yet document much about Blosc filters.
The Blosc issues were fixed upstream in netCDF version 4.9.1.
</para>
<para>netCDF 4.9.0 contained some other inadvertent mistakes that were fixed 
in 4.9.1.
First, the quantization algorithms internal to netCDF work only on
datasets of type <acronym><acronymword>NETCDF4</acronymword></acronym> in netCDF 4.9.0.
A recently discovered bug prevents them from working on
<acronym><acronymword>NETCDF4_CLASSIC</acronymword></acronym>-format datasets 
<footnote><para>Quantization may never be implemented in netCDF for any 
<acronym><acronymword>CLASSIC</acronymword></acronym> or other netCDF3 formats since there is no
compression advantage to doing so.
Use the <acronym><acronymword>NCO</acronymword></acronym> implementation to quantize to netCDF3 output
formats.</para></footnote>.
The fix to the <acronym><acronymword>NETCDF4_CLASSIC</acronymword></acronym> bug was officially released
in netCDF 4.9.1.
Note that this bug did not affect the same quantization algorithms as
implemented in <acronym><acronymword>NCO</acronymword></acronym> (or in the <acronym><acronymword>CCR</acronymword></acronym>, for that
matter). 
In other words, quantization to netCDF3 and
<acronym><acronymword>NETCDF4_CLASSIC</acronymword></acronym>-format output files <emph>always</emph> works
when invoked through the <samp>--qnt</samp> (not <samp>--cmp</samp>) option. 
This restriction will only affects netCDF prior to 4.9.1. 
Per-variable quantization settings must also be invoked through
<samp>--qnt</samp> (not <samp>--cmp</samp>) for all output formats, until and
unless this feature is migrated to <samp>--cmp</samp> (there are no plans
to do so).
</para>
<para>Another sticky wicket expected that was fixed in netCDF 4.9.1
was the use of the Blosc codec.
NCZarr uses Blosc internally, however the <acronym><acronymword>HDF5</acronymword></acronym> Blosc codec
in netCDF 4.9.0 was not robust.
We plan to advertise the advantages of Blosc more fully in future
versions of <acronym><acronymword>NCO</acronymword></acronym>.
Feedback on any or all of these constraints is welcome.
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Best Practices for Real World Lossy Compression</sectiontitle>
<para>The workflow to compress large-scale, user-facing datasets requires 
consideration of multiple factors including storage space, speed,
accuracy, information content, portability, and user-friendliness.
We have found that this blend is best obtained by using per-variable
quantization together with global lossless compression.
<acronym><acronymword>NCO</acronymword></acronym> can configure per-variable quantization levels together
with global lossless filters when the quantization algorithm is
specified with the <samp>--qnt</samp> option/<acronym><acronymword>API</acronymword></acronym> and the lossless
filters are specified with the <samp>--cmp_sng</samp> option/<acronym><acronymword>API</acronymword></acronym>.
Granular BitRound (GranularBR) and BitRound are state-of-the-art
quantization algorithms that are configured with the number of
significant decimal digits (<acronym><acronymword>NSD</acronymword></acronym>) or number of significant
bits (<acronym><acronymword>NSB</acronymword></acronym>), respectively.
</para>
<para>One can devise an optimal approach in about four steps: 
First, select a global lossless codec that produces a reasonable
tradeoff between compression ratio (<acronym><acronymword>CR</acronymword></acronym>) and speed.
The speed of the final workflow will depend mostly on the lossless
codec employed and its compression settings.
Try a few standard codecs with Shuffle to explore this tradeoff:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -7 --cmp='shf|zst' ...
ncks -7 --cmp='shf|dfl' ...
ncks -7 --cmp='shf|bz2' ...
</verbatim>
</example>
<para>The <samp>-7</samp> switch creates output in <acronym><acronymword>NETCDF4_CLASSIC</acronymword></acronym>
format.
This highly portable format supports codecs and is also mandated by
many archives such as <acronym><acronymword>CMIP6</acronymword></acronym>.
The only other viable format choice is <samp>-4</samp> for <acronym><acronymword>NETCDF4</acronymword></acronym>. 
That format must be used if any variables make use of the extended
netCDF4 atomic types.
Our experience with <acronym><acronymword>ESM</acronymword></acronym> data shows that Bzip2 often yields
the best <acronym><acronymword>CR</acronymword></acronym> (<pxref label="fgr_003aqnt_005fcr_005fbz2"><xrefnodename>fgr:qnt_cr_bz2</xrefnodename></pxref>).
However Bzip2 is much slower than Zstandard which yields a comparable
<acronym><acronymword>CR</acronymword></acronym>.
</para><float name="fgr_003aqnt_005fcr_005fbz2" type="Figure" number="3.2" spaces=" " endspaces=" "><floattype>Figure</floattype><floatname>fgr:qnt_cr_bz2</floatname>
<image><imagefile>fgr/qnt_cr_bz2</imagefile><imagewidth>5.5in</imagewidth></image> 
<caption><para>Quantization and then compression by Bzip2,
including the contribution of Shuffle.</para></caption>
</float>

<para>The second step is to choose the quantization algorithm and
its default level.
Quantization can significantly improve the <acronym><acronymword>CR</acronymword></acronym> without
sacrificing any scientifically meaningful data.
Lossless algorithms are unlikely to significantly alter the workflow
throughput unless applied so agressively that they considerably
reduce the entropy seen by the lossless codec.
The goal in this step is to choose the strongest quantization that
preserves all the meaningful precision of <emph>most</emph> fields, and
that dials-in the <acronym><acronymword>CR</acronymword></acronym> to the desired value.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -7 --qnt default=3 ... # GranularBR, NSD=3
ncks -7 --qnt default=3 ... # Same
ncks -7 --qnt_alg=gbr --ppc default=3 ...  # Same
ncks -7 --qnt_alg=gbr --ppc dfl=3 ...      # Same
ncks -7 --qnt_alg=btr --ppc dfl=9 ...      # BitRound, NSB=9
ncks -7 --baa=8 --ppc default=9  ...       # Same
</verbatim>
</example>
<para>As an argument to <samp>--qnt</samp>, the keyword <code>dfl</code> is just a
synonym for <code>default</code> and has nothing to do with
<acronym><acronymword>DEFLATE</acronymword></acronym>.  
</para>
<para>The third step is to develop per-variable exceptions to the
default quantization of the previous step.
This can be a process of trial-and-error, or semi-automated through
techniques such as determining an acceptable information content
threshold for each variable
<footnote><para>See, e.g., the procedure described in &textldquo;Compressing
atmospheric data into its real information content&textrdquo; by M.~Klower et
al., available at <url><urefurl>https://doi.org/10.1038/s43588-021-00156-2</urefurl></url>.</para></footnote>.
The per-variable arguments to <samp>--qnt</samp> can take many forms:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks --qnt p,w,z=5 --qnt q,RH=4 --qnt T,u,v=3 # Multiple options
ncks --qnt p,w,z=5#q,RH=4#T,u,v=3 ...  # Combined option
ncks --qnt Q.?=5#FS.?,FL.?=4#RH=.3 ... # Regular expressions
ncks --qnt_alg=btr --qnt p,w,z=15#q,RH=12#T,u,v=9 ... # BitRound (NSB)
ncks --qnt_alg=btr --qnt CO2=15#AER.?=12#U,V=6 ... # Klower et al. 
</verbatim>
</example>
<para>No compression is necessary in this step, which presumably involves 
evaluating the adequacy of the quantized values at matching
observations or at meeting other error metrics.
</para>
<para>The fourth and final step combines the lossless and lossy algorithms
to produce the final workflow:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -7 --qnt dfl=3 --cmp='shf|zst' ... # A useful starting point?
ncks -7 --qnt default=3#Q.?=5#FS.?,FL.?=4 --cmp='shf|zst' ...
ncks -7 --qnt_alg=gbr --qnt default=3#Q.?=5#FS.?,FL.?=4 --cmp='shf|zst' ...
ncks -7 --qnt_alg=btr --qnt default=9#Q.?=15#FS.?,FL.?=12 --cmp='shf|zst' ...
</verbatim>
</example>
<para>The example above uses Zstandard (<pxref label="fgr_003aqnt_005fcr_005fzst"><xrefnodename>fgr:qnt_cr_zst</xrefnodename></pxref>) because it
is significant faster than other codecs with comparable <acronym><acronymword>CR</acronymword></acronym>s,
e.g., Bzip2. 
</para><float name="fgr_003aqnt_005fcr_005fzst" type="Figure" number="3.3" spaces=" " endspaces=" "><floattype>Figure</floattype><floatname>fgr:qnt_cr_zst</floatname>
<image><imagefile>fgr/qnt_cr_zst</imagefile><imagewidth>5.5in</imagewidth></image> 
<caption><para>Quantization and then compression by Zstandard,
including the contribution of Shuffle.</para></caption>
</float>

</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Older Compression <acronym><acronymword>API</acronymword></acronym></sectiontitle>
<para><acronym><acronymword>NCO</acronymword></acronym> implements or accesses four different compression
algorithms, the standard lossless <acronym><acronymword>DEFLATE</acronymword></acronym> algorithm
and three lossy compression algorithms.
All four algorithms reduce the on-disk size of a dataset while
sacrificing no (lossless) or a tolerable amount (lossy) of precision. 
First, <acronym><acronymword>NCO</acronymword></acronym> can access the lossless <acronym><acronymword>DEFLATE</acronymword></acronym> algorithm,
a combination of Lempel-Ziv encoding and Huffman coding, algorithm on
any netCDF4 dataset (<pxref label="Deflation"><xrefnodename>Deflation</xrefnodename></pxref>). 
Because it is lossless, this algorithm re-inflates deflated data to
their full original precision. 
This algorithm is accessed via the <acronym><acronymword>HDF5</acronymword></acronym> library layer
(which itself calls the <command>zlib</command> library also used by
<command>gzip</command>), and is unavailable with netCDF3.   
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Linear Packing</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Precision-Preserving Compression</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

</unnumberedsubsec>
<node name="Linear-Packing" spaces=" "><nodename>Linear Packing</nodename><nodenext spaces=" ">Precision-Preserving Compression</nodenext><nodeprev spaces=" ">Compression</nodeprev><nodeup spaces=" ">Compression</nodeup></node>
<subsection spaces=" "><sectiontitle>Linear Packing</sectiontitle>
<para>The three lossy compression algorithms are Linear Packing 
(<pxref label="Packed-data"><xrefnodename>Packed data</xrefnodename></pxref>), and two precision-preserving algorithms.
Linear packing quantizes data of a higher precision type into a lower
precision type (often <code>NC_SHORT</code>) that thus stores a fewer (though
constant) number of bytes per value. 
Linearly packed data unpacks into a (much) smaller dynamic range than the
floating-point data can represent.  
The type-conversion and reduced dynamic range of the data allows packing
to eliminate bits typically used to store an exponent, thus improving 
its packing efficiency.
Packed data also can also be deflated for additional space savings. 
</para>
<para>A limitation of linear packing is that unpacking data stored as integers 
into the linear range defined by <code>scale_factor</code> and
<code>add_offset</code> rapidly loses precision outside of a narrow range of
floating-point values.  
Variables packed as <code>NC_SHORT</code>, for example, can represent only
about 64000 discrete values in the range 
<math>-32768*scale_factor+add_offset</math> to
<math>32767*scale_factor+add_offset</math>. 
The precision of packed data equals the value of <code>scale_factor</code>,
and <code>scale_factor</code> is usually chosen to span the range of valid
data, not to represent the intrinsic precision of the variable.
In other words, the precision of packed data cannot be specified in
advance because it depends on the range of values to quantize.
</para>
</subsection>
<node name="Precision_002dPreserving-Compression" spaces=" "><nodename>Precision-Preserving Compression</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Linear Packing</nodeprev><nodeup spaces=" ">Compression</nodeup></node>
<subsection spaces=" "><sectiontitle>Precision-Preserving Compression</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1031"><acronym><acronymword>PPC</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1032"><acronym><acronymword>LSD</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1033">Least Significant Digit</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1034">quantization</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> implemented the final two lossy compression algorithms
in version 4.4.8 (February, 2015).
These are both <dfn>Precision-Preserving Compression</dfn> (<acronym><acronymword>PPC</acronymword></acronym>)
algorithms and since standard terminology for precision is remarkably 
imprecise, so is our nomenclature. 
The operational definition of &textldquo;significant digit&textrdquo; in our precision
preserving algorithms is that the exact value, before rounding or
quantization, is within one-half the value of the decimal place occupied
by the <dfn>Least Significant Digit</dfn> (<acronym><acronymword>LSD</acronymword></acronym>) of the rounded value.
For example, the value <math>pi = 3.14</math> correctly represents the exact
mathematical constant <var>pi</var> to three significant digits because the
<acronym><acronymword>LSD</acronymword></acronym> of the rounded value <w>(i.e., 4)</w> is in the one-hundredths 
digit place, and the difference between the exact value and the rounded
value is less than one-half of one one-hundredth, i.e., 
(<math>3.14159265358979323844 - 3.14 = 0.00159 &lt; 0.005</math>).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1035">Number of Significant Digits</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1036"><acronym><acronymword>NSD</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1037">Bit-Grooming</indexterm></cindex>
<para>One <acronym><acronymword>PPC</acronymword></acronym> algorithm preserves the specified total 
<dfn>Number of Signifcant Digits</dfn> (<acronym><acronymword>NSD</acronymword></acronym>) of the value.
For example there is only one significant digit in the weight of
most &textldquo;eight-hundred pound gorillas&textrdquo; that you will encounter, 
i.e., so <math><var>nsd=1</var></math>.
This is the most straightforward measure of precision, and thus
<acronym><acronymword>NSD</acronymword></acronym> is the default <acronym><acronymword>PPC</acronymword></acronym> algorithm.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1038">Decimal Significant Digits</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1039"><acronym><acronymword>DSD</acronymword></acronym></indexterm></cindex>
<para>The other <acronym><acronymword>PPC</acronymword></acronym> algorithm preserves the number of 
<dfn>Decimal Significant Digits</dfn> (<acronym><acronymword>DSD</acronymword></acronym>), i.e., the number of
significant digits following (positive, by convention) or preceding
(negative) the decimal point.  
For example, <samp>0.008</samp> and <samp>800</samp> have, respectively, three and 
negative two digits digits following the decimal point, corresponding 
to <math><var>dsd=3</var></math> and <math><var>dsd=-2</var></math>. 
</para>
<para>The only justifiable <acronym><acronymword>NSD</acronymword></acronym> for a given value depends on 
intrinsic accuracy and error characteristics of the model or
measurements, and not on the units with which the value is stored.
The appropriate <acronym><acronymword>DSD</acronymword></acronym> for a given value depends on these
intrinsic characteristics and, in addition, the units of storage.
This is the fundamental difference between the <acronym><acronymword>NSD</acronymword></acronym> and 
<acronym><acronymword>DSD</acronymword></acronym> approaches. 
The eight-hundred pound gorilla always has <math><var>nsd=1</var></math> regardless 
of whether the value is stored in pounds or in some other unit.
<acronym><acronymword>DSD</acronymword></acronym> corresponding to this weight is <math><var>dsd=-2</var></math> if the
value is stored in pounds, <math><var>dsd=4</var></math> if stored in megapounds.
</para>
<para>Users may wish to express the precision to be preserved as either
<acronym><acronymword>NSD</acronymword></acronym> or <acronym><acronymword>DSD</acronymword></acronym>.
Invoke <acronym><acronymword>PPC</acronymword></acronym> with the long option <samp>--ppc var=prc</samp>, or give
the same arguments to the synonyms
<samp>--precision_preserving_compression</samp>, <samp>--qnt</samp>, or
<samp>--quantize</samp>.
Here <var>var</var> is the variable to quantize, and <var>prc</var> is its
precision.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1040">indicator option</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1041">multi-arguments</indexterm></cindex>
The option <samp>--qnt</samp> (and its long option equivalents such
as <samp>--ppc</samp> and <samp>--quantize</samp>) indicates the argument syntax
will be <var>key</var>=<var>val</var>.
As such, <samp>--qnt</samp> and its synonyms are indicator options that accept
arguments supplied one-by-one like 
<samp>--qnt <var>key1</var>=<var>val1</var> --qnt <var>key2</var>=<var>val2</var></samp>, or
aggregated together in multi-argument format like
<samp>--qnt <var>key1</var>=<var>val1</var>#<var>key2</var>=<var>val2</var></samp>
(<pxref label="Multi_002darguments"><xrefnodename>Multi-arguments</xrefnodename></pxref>).
The default algorithm assumes <var>prc</var> specifies <acronym><acronymword>NSD</acronymword></acronym>
precision, e.g., <samp>T=2</samp> means <math><var>nsd=2</var></math>.
Prepend <var>prc</var> with a decimal point to specify <acronym><acronymword>DSD</acronymword></acronym>
precision, e.g., <samp>T=.2</samp> means <math><var>dsd=2</var></math>.
<acronym><acronymword>NSD</acronymword></acronym> precision must be specified as a positive integer.
<acronym><acronymword>DSD</acronymword></acronym> precision may be a positive or negative integer;
and is specified as the negative <w>base 10</w> logarithm of the desired 
precision, in accord with common usage. 
For example, specifying <samp>T=.3</samp> or <samp>T=.-2</samp> tells the
<acronym><acronymword>DSD</acronymword></acronym> algorithm to store only enough bits to preserve the  
value of <var>T</var> rounded to the nearest thousandth or hundred,
respectively. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1042"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1043"><code>coordinates</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1044"><code>climatology</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1045"><code>bounds</code> attribute</indexterm></cindex>
<para>Setting <var>var</var> to <code>default</code> has the special meaning of applying 
the associated <acronym><acronymword>NSD</acronymword></acronym> or <acronym><acronymword>DSD</acronymword></acronym> algorithm to all floating
point variables except coordinate variables.
Variables <emph>not affected</emph> by <code>default</code> include integer and
non-numeric atomic types, coordinates, and variables mentioned in 
the <code>bounds</code>, <code>climatology</code>, or <code>coordinates</code> attribute
of any variable. 
<acronym><acronymword>NCO</acronymword></acronym> applies <acronym><acronymword>PPC</acronymword></acronym> to coordinate variables only if 
those variables are explicitly specified (i.e., not with the
<samp>default=<var>prc</var></samp> mechanism. 
<acronym><acronymword>NCO</acronymword></acronym> applies <acronym><acronymword>PPC</acronymword></acronym> to integer-type variables only if 
those variables are explicitly specified (i.e., not with the
<samp>default=<var>prc</var></samp>, and only if the <acronym><acronymword>DSD</acronymword></acronym> algorithm is
invoked with a negative <var>prc</var>.
To prevent <acronym><acronymword>PPC</acronymword></acronym> from applying to certain non-coordinate
variables (e.g., <code>gridcell_area</code> or <code>gaussian_weight</code>),
explicitly specify a precision <w>exceeding 7</w> (for <code>NC_FLOAT</code>)
<w>or 15</w> (for <code>NC_DOUBLE</code>) for those variables. 
Since these are the maximum representable precisions in decimal digits,
<acronym><acronymword>NCO</acronymword></acronym> <emph>turns-off</emph> <acronym><acronymword>PPC</acronymword></acronym> (i.e., does nothing)
when more precision is requested.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1046">bitmask</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1047">significand</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1048"><w><acronym><acronymword>IEEE</acronymword></acronym> 754</w></indexterm></cindex>
<para>The time-penalty for compressing and uncompressing data varies according 
to the algorithm.
The Number of Significant Digit (<acronym><acronymword>NSD</acronymword></acronym>) algorithm quantizes by
bitmasking, and employs no floating-point math.
The Decimal Significant Digit (<acronym><acronymword>DSD</acronymword></acronym>) algorithm quantizes by
rounding, which does require floating-point math.
Hence <acronym><acronymword>NSD</acronymword></acronym> is likely faster than <acronym><acronymword>DSD</acronymword></acronym>, though
the difference has not been measured.
<acronym><acronymword>NSD</acronymword></acronym> creates a bitmask to alter the <dfn>significand</dfn> of
<w><acronym><acronymword>IEEE</acronymword></acronym> 754</w> floating-point data.
The bitmask is one for all bits to be retained and zero or one for all
bits to be ignored.
The algorithm assumes that the number of binary digits (i.e., bits)
necessary to represent a single base-10 digit is 
<math>ln(10)/ln(2) = 3.32</math>.
The exact numbers of bits <var>Nbit</var> retained for single and double
precision values are <math>ceil(3.32*<var>nsd</var>)+1</math> and
<math>ceil(3.32*<var>nsd</var>)+2</math>, respectively.
Once these <w>reach 23</w> <w>and 53</w>, respectively, bitmasking is
completely ineffective. 
This occurs at <math><var>nsd</var>=6.3</math> <w>and 15.4</w>, respectively.
</para>
<para>The <acronym><acronymword>DSD</acronymword></acronym> algorithm, by contrast, uses rounding to remove
undesired precision.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="1049"><command>rint()</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1050">C99</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1051"><acronym><acronymword>IEEE</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1052">significand</indexterm></cindex>
The rounding 
<footnote spaces="\n"><para>Rounding is performed by the internal math library <command>rint()</command> 
family of functions that were standardized in C99.
The exact alorithm employed is
<math><var>val</var> := rint(<var>scale</var>*<var>val</var>)/<var>scale</var></math> where
<var>scale</var> is the nearest power <w>of 2</w> that exceeds 
<math>10**<var>prc</var></math>, and the inverse of <var>scale</var> is used when 
<math><var>prc</var> &lt; 0</math>.
For <math><var>qnt</var> = 3</math> or <math><var>qnt</var> = -2</math>, for example, we have
<math><var>scale</var> = 1024</math> and <math><var>scale</var> = 1/128</math>.</para></footnote>
zeroes the greatest number of significand bits consistent with
the desired precision.
</para>
<para>To demonstrate the change in <acronym><acronymword>IEEE</acronymword></acronym> representation caused by
<acronym><acronymword>PPC</acronymword></acronym> rounding algorithms, consider again the case of <var>pi</var>,
represented as an <code>NC_FLOAT</code>.
The <w><acronym><acronymword>IEEE</acronymword></acronym> 754</w> single precision representations of the exact
value (3.141592...), the value with only three significant digits treated
as exact (3.140000...), and the value as stored (3.140625) after
<acronym><acronymword>PPC</acronymword></acronym>-rounding with either the <acronym><acronymword>NSD</acronymword></acronym> (<math><var>prc</var>=3</math>)
or <acronym><acronymword>DSD</acronymword></acronym> (<math><var>prc</var>=2</math>) algorithm are, respectively,
<ignore endspaces=" ">
ncks -O -v pi --qnt pi=1  ~/nco/data/in.nc ~/foo_nsd1.nc 
ncks -O -v pi --qnt pi=2  ~/nco/data/in.nc ~/foo_nsd2.nc 
ncks -O -v pi --qnt pi=3  ~/nco/data/in.nc ~/foo_nsd3.nc 
ncks -O -v pi --qnt pi=4  ~/nco/data/in.nc ~/foo_nsd4.nc 
ncks -O -v pi --qnt pi=5  ~/nco/data/in.nc ~/foo_nsd5.nc 
ncks -O -v pi --qnt pi=6  ~/nco/data/in.nc ~/foo_nsd6.nc 
ncks -O -v pi --qnt pi=7  ~/nco/data/in.nc ~/foo_nsd7.nc 
ncks -O -v pi --qnt pi=8  ~/nco/data/in.nc ~/foo_nsd8.nc 
ncks -O -v pi --qnt pi=9  ~/nco/data/in.nc ~/foo_nsd9.nc 
ncks -O -v pi --qnt pi=.2 ~/nco/data/in.nc ~/foo_dsd2.nc 
ncks -s %20.16e -C -H ~/foo_nsd.nc
ncks -s %20.16e -C -H ~/foo_dsd.nc
ccc --tst=bnr --flt_foo=3.14159265358979323844 2&gt; /dev/null | grep &quot;Binary of float&quot;
ccc --tst=bnr --flt_foo=3.14000000000000000000 2&gt; /dev/null | grep &quot;Binary of float&quot;
ccc --tst=bnr --flt_foo=3.00000000000000000000 2&gt; /dev/null | grep &quot;Binary of float&quot;
ccc --tst=bnr --flt_foo=3.12500000000000000000 2&gt; /dev/null | grep &quot;Binary of float&quot;
ccc --tst=bnr --flt_foo=3.14062500000000000000 2&gt; /dev/null | grep &quot;Binary of float&quot;
ccc --tst=bnr --flt_foo=3.14062500000000000000 2&gt; /dev/null | grep &quot;Binary of float&quot;
ccc --tst=bnr --flt_foo=3.14147949218750000000 2&gt; /dev/null | grep &quot;Binary of float&quot;
</ignore>
</para><example endspaces=" ">
<pre xml:space="preserve">S Exponent  Fraction (Significand)   Decimal    Notes
0 100000001 0010010000111111011011 # 3.14159265 Exact
0 100000001 0010001111010111000011 # 3.14000000
0 100000001 0010010000000000000000 # 3.14062500 NSD = 3
0 100000001 0010010000000000000000 # 3.14062500 DSD = 2
</pre></example>
<para>The string of trailing zero-bits in the rounded values facilitates
byte-stream compression. 
Note that the <acronym><acronymword>NSD</acronymword></acronym> and <acronym><acronymword>DSD</acronymword></acronym> algorithms do not always
produce results that are bit-for-bit identical, although they do in this
particular case.
</para>
<html endspaces=" ">
&lt;a name=&quot;ppc_tbl_bit&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ppc_tbl_bit --&gt;
</html>
<para>Reducing the preserved precision of <acronym><acronymword>NSD</acronymword></acronym>-rounding produces
increasingly long strings of identical-bits amenable to compression: 
</para><example endspaces=" ">
<pre xml:space="preserve">S Exponent  Fraction (Significand)   Decimal    Notes
0 100000001 0010010000111111011011 # 3.14159265 Exact
0 100000001 0010010000111111011011 # 3.14159265 NSD = 8
0 100000001 0010010000111111011010 # 3.14159262 NSD = 7
0 100000001 0010010000111111011000 # 3.14159203 NSD = 6
0 100000001 0010010000111111000000 # 3.14158630 NSD = 5
0 100000001 0010010000111100000000 # 3.14154053 NSD = 4
0 100000001 0010010000000000000000 # 3.14062500 NSD = 3
0 100000001 0010010000000000000000 # 3.14062500 NSD = 2
0 100000001 0010000000000000000000 # 3.12500000 NSD = 1
</pre></example>
<para>The consumption of about <w>3 bits</w> per digit of base-10 precision is
evident, as is the coincidence of a quantized value that greatly
exceeds the mandated precision for <math><acronym><acronymword>NSD</acronymword></acronym> = 2</math>.
Although the <acronym><acronymword>NSD</acronymword></acronym> algorithm generally masks some bits for all 
<math><var>nsd</var> &lt;= 7</math> (for <code>NC_FLOAT</code>), compression algorithms like
<acronym><acronymword>DEFLATE</acronymword></acronym> may need byte-size-or-greater (i.e., at least
eight-bit) bit patterns before their algorithms can take advantage of
of encoding such patterns for compression.
Do not expect significantly enhanced compression from 
<math><var>nsd</var> &gt; 5</math> (for <code>NC_FLOAT</code>) or <math><var>nsd</var> &gt; 14</math> (for
<code>NC_DOUBLE</code>). 
Clearly values stored as <code>NC_DOUBLE</code> (i.e., eight-bytes) are
susceptible to much greater compression than <code>NC_FLOAT</code> for a given
precision because their significands explicitly contain <w>53 bits</w>
rather than <w>23 bits</w>.
</para>
<para>Maintaining non-biased statistical properties during lossy compression
requires special attention. 
The <acronym><acronymword>DSD</acronymword></acronym> algorithm uses <code>rint()</code>, which rounds toward the
nearest even integer. 
Thus <acronym><acronymword>DSD</acronymword></acronym> has no systematic bias.
However, the <acronym><acronymword>NSD</acronymword></acronym> algorithm uses a bitmask technique
susceptible to statistical bias.
Zeroing all non-significant bits is guaranteed to produce numbers 
quantized to the specified tolerance, i.e., half of the decimal value
of the position occupied by the <acronym><acronymword>LSD</acronymword></acronym>. 
However, always zeroing the non-significant bits results in quantized
numbers that never exceed the exact number.
This would produce a negative bias in statistical quantities (e.g., the
average) subsequently derived from the quantized numbers. 
To avoid this bias, our <acronym><acronymword>NSD</acronymword></acronym> implementation rounds
non-significant bits down (to zero) or up (to one) in an alternating
fashion when processing array data.
In general, the first element is rounded down, the second up, and so
on. 
This results in a mean bias quite close to zero.
The only exception is that the floating-point value of zero is never 
quantized upwards.
For simplicity, <acronym><acronymword>NSD</acronymword></acronym> always rounds scalars downwards.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1053"><acronym><acronymword>DEFLATE</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1054"><acronym><acronymword>HDF5</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1055"><command>gzip</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1056"><command>gunzip</command></indexterm></cindex>
<para>Although <acronym><acronymword>NSD</acronymword></acronym> or <acronym><acronymword>DSD</acronymword></acronym> are different algorithms under
the hood, they both replace the (unwanted) least siginificant bits of
the <acronym><acronymword>IEEE</acronymword></acronym> significand with a string of consecutive zeroes.  
Byte-stream compression techniques, such as the <command>gzip</command>
<acronym><acronymword>DEFLATE</acronymword></acronym> algorithm compression available in <acronym><acronymword>HDF5</acronymword></acronym>, 
always compress zero-strings more efficiently than random digits. 
The net result is netCDF files that utilize compression can be
significantly reduced in size.  
This feature only works when the data are compressed, either internally 
(by netCDF) or externally (by another user-supplied mechanism).
It is most straightfoward to compress data internally using the built-in 
compression and decompression supported by netCDF4.
For convenience, <acronym><acronymword>NCO</acronymword></acronym> automatically activates file-wide
Lempel-Ziv deflation (<pxref label="Deflation"><xrefnodename>Deflation</xrefnodename></pxref>) level one (i.e., <samp>-L 1</samp>)
when <acronym><acronymword>PPC</acronymword></acronym> is invoked on any variable in a netCDF4 output file. 
This makes <acronym><acronymword>PPC</acronymword></acronym> easier to use effectively, since the user
need not explicitly specify deflation.
Any explicitly specified deflation (including no deflation, <samp>-L 0</samp>) 
will override the <acronym><acronymword>PPC</acronymword></acronym> deflation default.
If the output file is a netCDF3 format, <acronym><acronymword>NCO</acronymword></acronym> will emit a
message suggesting internal netCDF4 or external netCDF3 compression. 
netCDF3 files compressed by an external utility such as <command>gzip</command>
accrue approximately the same benefits (shrinkage) as netCDF4, although
with netCDF3 the user or provider must uncompress (e.g.,
<command>gunzip</command>) the file before accessing the data. 
There is no benefit to rounding numbers and storing them in netCDF3
files unless such custom compression/decompression is employed.
Without that, one may as well maintain the undesired precision. 
</para>
<para>The user accesses <acronym><acronymword>PPC</acronymword></acronym> through a single switch, <samp>--ppc</samp>,
repeated as many times as necessary.
To apply the <acronym><acronymword>NSD</acronymword></acronym> algorithm to variable <var>u</var> use, e.g., 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -7 --qnt u=2 in.nc out.nc
</pre></example>
<para>The output file will preserve only two significant digits of <var>u</var>.
The options <samp>-4</samp> or <samp>-7</samp> ensure a netCDF4-format output 
(regardless of the input file format) to support internal compression.
It is recommended though not required to write netCDF4 files after 
<acronym><acronymword>PPC</acronymword></acronym>.
For clarity the <samp>-4/-7</samp> switches are omitted in subsequent
examples. 
<html endspaces=" ">
&lt;a name=&quot;QuantizeBitGroomNumberOfSignificantDigits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeBitGroomNumberOfSignificantDigits --&gt;
&lt;a name=&quot;QuantizeGranularBitRoundNumberOfSignificantDigits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeGranularBitRoundNumberOfSignificantDigits --&gt;
&lt;a name=&quot;QuantizeBitShaveNumberOfSignificantDigits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeBitShaveNumberOfSignificantDigits --&gt;
&lt;a name=&quot;QuantizeBitSetNumberOfSignificantDigits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeBitSetNumberOfSignificantDigits --&gt;
&lt;a name=&quot;QuantizeDigitRoundNumberOfSignificantDigits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeDigitRoundNumberOfSignificantDigits --&gt;
&lt;a name=&quot;QuantizeBitGroomRoundNumberOfSignificantDigits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeBitGroomRoundNumberOfSignificantDigits --&gt;
&lt;a name=&quot;QuantizeHalfShaveNumberOfSignificantBits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeHalfShaveNumberOfSignificantBits --&gt;
&lt;a name=&quot;QuantizeBruteForceNumberOfSignificantDigits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeBruteForceNumberOfSignificantDigits --&gt;
&lt;a name=&quot;QuantizeBitRoundNumberOfSignificantBits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#QuantizeBitRoundNumberOfSignificantBits --&gt;
&lt;a name=&quot;number_of_significant_digits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#number_of_significant_digits --&gt;
&lt;a name=&quot;least_significant_digit&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#least_significant_digit --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1057"><code>QuantizeBitGroomNumberOfSignificantDigits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1058"><code>QuantizeBitSetNumberOfSignificantDigits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1059"><code>QuantizeBitShaveNumberOfSignificantDigits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1060"><code>QuantizeDigitRoundNumberOfSignificantDigits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1061"><code>QuantizeGranularBitRoundNumberOfSignificantDigits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1062"><code>QuantizeBitGroomRoundNumberOfSignificantDigits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1063"><code>QuantizeHalfShaveNumberOfSignificantBits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1064"><code>QuantizeBruteForceNumberOfSignificantDigits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1065"><code>QuantizeBitRoundNumberOfSignificantBits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1066"><code>number_of_significant_digits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1067"><code>number_of_significant_bits</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1068"><code>least_significant_digit</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1069">Jeff Whitaker</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1070">Rich Signell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1071">John Caron</indexterm></cindex>
<acronym><acronymword>NCO</acronymword></acronym> attaches attributes that indicate the algorithm used and
degree of precision retained for each variable affected by
<acronym><acronymword>PPC</acronymword></acronym>. 
The <acronym><acronymword>NSD</acronymword></acronym> and <acronym><acronymword>DSD</acronymword></acronym> algorithms store the attributes
<code>QuantizeBitGroomNumberOfSignificantDigits</code>
<footnote spaces="\n"><para>Prior to <acronym><acronymword>NCO</acronymword></acronym> version 5.0.3 (October, 2021), <acronym><acronymword>NCO</acronymword></acronym>
stored the <acronym><acronymword>NSD</acronymword></acronym> attribute
<code>number_of_significant_digits</code>.
However, this was deemed too ambiguous, given the increasing number of
supported quantization methods.
The new attribute names better disambiguate which algorithm was used
to quantize the data.
They also harmonize better with the metadata produced by the upcoming
netCDF library quantization features.
</para></footnote>
and <code>least_significant_digit</code>
<footnote spaces="\n"><para>A suggestion by Rich Signell and the <command>nc3tonc4</command> tool by Jeff
Whitaker inspired <acronym><acronymword>NCO</acronymword></acronym> to implement <acronym><acronymword>PPC</acronymword></acronym>.
Note that <acronym><acronymword>NCO</acronymword></acronym> implements a different <acronym><acronymword>DSD</acronymword></acronym> algorithm
than <command>nc3tonc4</command>, and produces slightly different (not
bit-for-bit) though self-consistent and equivalent results.
<command>nc3tonc4</command> records the precision of its <acronym><acronymword>DSD</acronymword></acronym> algorithm 
in the attribute <code>least_significant_digit</code> and <acronym><acronymword>NCO</acronymword></acronym> 
does the same for consistency.
The Unidata blog 
<uref><urefurl>http://www.unidata.ucar.edu/blogs/developer/en/entry/compression_by_bit_shaving</urefurl><urefdesc spaces="  \n">here</urefdesc></uref> also shows how to compress <acronym><acronymword>IEEE</acronymword></acronym> floating-point data by
zeroing insignificant bits.
The author, John Caron, writes that the technique has been called
&textldquo;bit-shaving&textrdquo;.
We call the algorithm of always rounding-up &textldquo;bit-setting&textrdquo;.
And we named the algorithm produced by alternately rounding up and
down (with a few other bells and whistles) &textldquo;bit-grooming&textrdquo;.
Imagine orthogonally raking an already-groomed Japanese rock garden.
The criss-crossing tracks increase the pattern&textrsquo;s entropy, and this
entropy produces self-compensating instead of accumulating errors
during statistical operations.</para></footnote>, respectively.
</para>
<para>As of <w>version 5.0.3</w> (October 2021), <acronym><acronymword>NCO</acronymword></acronym> supports a more
complete set of Precision-Preserving Quantization (<acronym><acronymword>PPQ</acronymword></acronym>)
filters than was previously documented here. 
The default algorithm has been changed from BitGroom with BitRound
masks from R. Kouznetsov (2021), to what we call Granular BitRound
(<acronym><acronymword>GBR</acronymword></acronym>).
<acronym><acronymword>GBR</acronymword></acronym> combines features of BitGroom, BitRound, and DigitRound by
Delaunay et al. (2019).
<acronym><acronymword>GBR</acronymword></acronym> improves compression ratios by ~20% relative to BitGroom
for <acronym><acronymword>NSD</acronymword></acronym>=3 on our benchmark <w>1 GB</w> climate model output
dataset.
Since it quantizes a few more bits than BitGroom (and BitGroomRound)
for a given <acronym><acronymword>NSD</acronymword></acronym>, <acronym><acronymword>GBR</acronymword></acronym> produces significantly larger
quantization errors than those algorithms as well.
</para>
<para>These <acronym><acronymword>NSD</acronymword></acronym> algorithms write an algorithm-specific attribute,
e.g., <code>QuantizeGranularBitRoundNumberOfSignificantDigits</code> or
<code>QuantizeDigitRoundNumberOfSignificantDigits</code>.
Documentation on these algorithms is best found in the literature.
While Bit-Groom/Shave/Set are described above, documentation on
Bit-Adjustment-Algorithms (<acronym><acronymword>BAA</acronymword></acronym>) 3&textndash;8 will be improved in the 
future.  
</para>
<!-- c keepbits=number_significant_bits-1 -->
<!-- c number_significant_bits=keepbits+1 -->
<!-- c keepbits=number_stored_bits (NSB) = number_explicit_significant_bits (NESB) -->

<para>As of <w>version 5.0.5</w> (January 2022), <acronym><acronymword>NCO</acronymword></acronym> supports
two quantization codecs (BitRound and HalfShave) that expect a
user-specified number of explicit significant bits (<acronym><acronymword>NSB</acronymword></acronym>,
or &textldquo;keepbits&textrdquo;) to retain
<footnote spaces="\n"><para>The terminology of significant bits (not to mention digits) can be
confusing.
The <acronym><acronymword>IEEE</acronymword></acronym> standard devotes 24 and 53 bits, respectively,
to the mantissas that determine the precision of single and double
precision floating-point numbers. 
However, the first (i.e., the most significant) of those bits is
<emph>implicit</emph>, and is not explicitly stored.
Its value is one unless all of the exponent bits are zero.
The implicit bit is <emph>significant</emph> thought it is not explicitly stored
and so cannot be quantized.
Therefore single and double precision floats have only 23 and 52
explicitly stored bits, respectively, that can be &textldquo;kept&textrdquo; and
therefore quantized. 
Each explicit bit kept is as significant as the implicit bit.
Thus the number of &textldquo;keepbits&textrdquo; is one less than the number of
significant bits, i.e., the bits that contribute to the precision of an
<acronym><acronymword>IEEE</acronymword></acronym> value. 
The BitRound quantization algorithm in <acronym><acronymword>NCO</acronymword></acronym> and in netCDF
accept as an input parameter the number of keepbits, i.e., the number
of explicit significant bits <acronym><acronymword>NESB</acronymword></acronym> to retain (i.e., not mask
to zero). 
Unfortunately the acronym <acronym><acronymword>NSB</acronymword></acronym> has been used instead of
the more accurate acronym <acronym><acronymword>NESB</acronymword></acronym>, and at this point it is
difficult to change. 
Therefore the <acronym><acronymword>NSB</acronymword></acronym> acronym and parameter as used by
<acronym><acronymword>NCO</acronymword></acronym> and netCDF should be interpreted as &textldquo;number of stored
bits&textrdquo; (i.e., keepbits) not the &textldquo;number of significant bits&textrdquo;.
</para></footnote>.
The <acronym><acronymword>NSB</acronymword></acronym> argument contrasts with the number of significant 
digits (<acronym><acronymword>NSD</acronymword></acronym>) parameter expected by the other codecs
(like BitGroom, DigitRound, and GranularBR).
The valid ranges of <acronym><acronymword>NSD</acronymword></acronym> are 1&textndash;7 for <acronym><acronymword>NC_FLOAT</acronymword></acronym>
and 1&textndash;15 for <acronym><acronymword>NC_DOUBLE</acronymword></acronym>.
The valid ranges of <acronym><acronymword>NSB</acronymword></acronym> are 1&textndash;23 for <acronym><acronymword>NC_FLOAT</acronymword></acronym>
and 1&textndash;52 for <acronym><acronymword>NC_DOUBLE</acronymword></acronym>.
The upper limits of <acronym><acronymword>NSB</acronymword></acronym> are the number of explicitly
represented bits in the <acronym><acronymword>IEEE</acronymword></acronym> single- and double-precision
formats (the implicit bit does not count).
</para>
<para>It is safe to attempt <acronym><acronymword>PPC</acronymword></acronym> on input that has already been
rounded. 
Variables can be made rounder, not sharper, i.e., variables cannot be
&textldquo;un-rounded&textrdquo;. 
Thus <acronym><acronymword>PPC</acronymword></acronym> attempted on an input variable with an existing
<acronym><acronymword>PPC</acronymword></acronym> attribute proceeds only if the new rounding level exceeds
the old, otherwise no new rounding occurs (i.e., a &textldquo;no-op&textrdquo;), and the
original <acronym><acronymword>PPC</acronymword></acronym> attribute is retained rather than replaced with
the newer value of <var>prc</var>.
</para>
<para>To request, say, five significant digits (<math><var>nsd=5</var></math>) for all
fields, except, say, wind speeds which are only known to integer values
(<math><var>dsd=0</var></math>) in the supplied units, requires <samp>--ppc</samp> twice: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -4 --qnt default=5 --qnt u,v=.0 in.nc out.nc
</pre></example>
<para>To preserve five digits in all variables except coordinate variables
and <var>u</var> and <var>v</var>, first specify a default value with the
<samp>default</samp> keyword (or synonym keywords <samp>dfl</samp>, <samp>global</samp>,
or <samp>glb</samp>), and separately specify the exceptions with
per-variable key-value pairs: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --qnt default=5 --qnt u,v=20 in.nc out.nc
</pre></example>
<para>The <samp>--qnt</samp> option may be specified any number of times to
support varying precision types and levels, and each option may
aggregate all the variables with the same precision
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --qnt p,w,z=5 --qnt q,RH=4 --qnt T,u,v=3 in.nc out.nc
ncks --qnt p,w,z=5#q,RH=4#T,u,v=3 in.nc out.nc # Multi-argument format
</pre></example>
<para>Any <var>var</var> argument may be a regular expression.
This simplifies generating lists of related variables:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --qnt Q.?=5 --qnt FS.?,FL.?=4 --qnt RH=.3 in.nc out.nc
ncks --qnt Q.?=5#FS.?,FL.?=4#RH=.3 in.nc out.nc # Multi-argument format
</pre></example>
<para>Although <acronym><acronymword>PPC</acronymword></acronym>-rounding instantly reduces data precision,
on-disk storage reduction only occurs once the data are compressed.  
</para>
<html endspaces=" ">
&lt;a name=&quot;ppc_tbl_ffc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ppc_tbl_ffc --&gt;
</html>
<para>How can one be sure the lossy data are sufficiently precise?
<acronym><acronymword>PPC</acronymword></acronym> preserves all significant digits of every value.
The <acronym><acronymword>DSD</acronymword></acronym> algorithm uses floating-point math to round each 
value optimally so that it has the maximum number of zeroed bits
that preserve the specified precision.
The <acronym><acronymword>NSD</acronymword></acronym> algorithm uses a theoretical approach (3.2 bits per
base-10 digit), tuned and tested to ensure the <emph>worst</emph> case
quantization error is less than half the value of the minimum increment
in the least significant digit. 
</para>
<para><emph>Note for Info users</emph>: 
The definition of error metrics relies heavily on mathematical
expressions which cannot be easily represented in Info.
<emph>See the <uref><urefurl>./nco.pdf</urefurl><urefdesc spaces=" ">printed manual</urefdesc></uref> for much more detailed
and complete documentation of this subject.</emph>
</para>
<tex endspaces=" ">
We define several metrics to quantify the quantization error.
The mean error~$\pslavg$ and mean absolute error~$\pslmebs$ incurred in
quantizing a variable from its true values~$\xxx_{\idx}$ to quantized
values~$\qqq_{\idx}$ are, respectively,
$$
\pslavg = {\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} ( \xxx_{\idx} - \qqq_{\idx} ) \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}}\qquad\hbox{and}\qquad
\pslmebs = {\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} | \xxx_{\idx} - \qqq_{\idx} | \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}}  
$$
where $\mssflg_{\idx}$ is~1 unless $\xxx_{\idx}$~equals the missing
value, $\mskflg_{\idx}$ is~1 unless $\xxx_{\idx}$~is masked, and
$\wgt_{\idx}$~is the weight.
The maximum and minimum errors $\pslmax$ and~$\pslmin$ are both signed 
$$
\pslmax = {\rm max}(\xxx_{\idx} - \qqq_{\idx})\qquad\hbox{and}\qquad
\pslmin = {\rm min}(\xxx_{\idx} - \qqq_{\idx})
$$
while the maximum and minimum absolute errors $\pslmabs$ and $\pslmibs$
are positive-definite. 
$$
\pslmabs = {\rm max}|\xxx_{\idx} - \qqq_{\idx}| = {\rm max}(|\pslmax|,|\pslmin|)
$$
$$
\pslmibs = {\rm min}|\xxx_{\idx} - \qqq_{\idx}| = {\rm min}(|\pslmax|,|\pslmin|)
$$
Typically $\pslmibs = 0$ for quantization, since many exact values
need no quantization.
Bit-shifting zeros into the least significant bits (@acronym{LSB}s)
always underestimates true values so that $\pslmax = 0$.
Conversely, bit-shifting ones into the @acronym{LSB}s always
overestimates true values so that $\pslmin = 0$. 
Our @acronym{NSD} algorithm is balanced because it alternates
bit-shifting zeroes and ones.
Balanced algorithms should yield $\pslmax \approx -\pslmin$,
$\pslmabs \approx \pslmibs$, and $\pslavg \approx 0$.

The three most important error metrics for quantization are 
$\pslmabs$, $\pslmebs$, and~$\pslavg$.
The upper bound (worst case) quantization performance is~$\pslmabs$.
$\pslmebs$~measures the absolute mean accuracy of quantization, and does
not allow positive and negative offsets to compensate eachother and
conceal poor performance.
The difference bewtween~$\pslmabs$ and~$\pslmebs$ indicates how much 
of an outlier the worst case is.
The mean accuracy~$\pslavg$ indicates whether statistical properties of 
quantized numbers will accurately reflect the true values. 
</tex>

<para>All three metrics are expressed in terms of the fraction of the ten&textrsquo;s
place occupied by the <acronym><acronymword>LSD</acronymword></acronym>.
If the <acronym><acronymword>LSD</acronymword></acronym> is the hundreds digit or the thousandths digit,
then the metrics are fractions <w>of 100</w>, or <w>of 1/100</w>,
respectively. 
<acronym><acronymword>PPC</acronymword></acronym> algorithms should produce maximum absolute errors no
greater <w>than 0.5</w> in these units.
If the <acronym><acronymword>LSD</acronymword></acronym> is the hundreds digit, then quantized versions of
true values will be within fifty of the true value.
It is much easier to satisfy this tolerance for a true value 
<w>of 100</w> (only 50% accuracy required) than <w>for 999</w> 
<w>(5% accuracy</w> required). 
Thus the minimum accuracy guaranteed for <math><var>nsd</var>=1</math> ranges
from 5&textndash;50%.
For this reason, the best and worst cast performance usually occurs for
true values whose <acronym><acronymword>LSD</acronymword></acronym> value is close to one and nine,
respectively. 
Of course most users prefer <math><var>prc</var> &gt; 1</math> because accuracies
increase exponentially with <var>prc</var>.
Continuing the previous example to <math><var>prc</var>=2</math>, 
quantized versions of true values from 1000&textndash;9999 will also be 
<w>within 50</w> of the true value, i.e., have accuracies from 0.5&textndash;5%.
In other words, only two significant digits are necessary to guarantee 
better <w>than 5%</w> accuracy in quantization. 
We recommend that dataset producers and users consider quantizing
datasets with <math><var>nsd</var>=3</math>.
This guarantees accuracy of 0.05&textndash;0.5% for individual values.
Statistics computed from ensembles of quantized values will, assuming
the mean error 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$\pslavg$
@clear flg
</tex>
<math><var>Emean</var></math>
<clear name="flg" line=" flg"></clear>
is small, have much better accuracy <w>than 0.5%</w>.
This accuracy is the most that can be justified for many applications.   
</para>
<para>To demonstrate these principles we conduct error analyses on an
artificial, reproducible dataset, and on an actual dataset of
observational analysis values. 
<footnote><para>The artificial dataset employed is one million evenly spaced
values from 1.0&textndash;2.0.
The analysis data are <math>N=13934592</math> values of the temperature field
from the <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>MERRA</acronymword></acronym> analysis of 20130601.</para></footnote>
The table summarizes quantization accuracy based on the three metrics.
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">NSD</itemformat></item>
</tableterm><tableitem><para>Number of Significant Digits.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">Emabs</itemformat></item>
</tableterm><tableitem><para>Maximum absolute error.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">Emebs</itemformat></item>
</tableterm><tableitem><para>Mean absolute error.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">Emean</itemformat></item>
</tableterm><tableitem><para>Mean error.
</para></tableitem></tableentry></table>

<ignore endspaces=" ">
9.9692099683868690e+36f = 0 1111100 111100000000000000000000 NC_FILL_FLOAT
2.3509885615147286E-38f = 0 0000000 111111111111111111111111 Recommended
9.9692099683868690e+36  = 0 1000111100 11110000000000000000000000000000000000000000000000000 NC_FILL_DOUBLE
2.84809453888921745415348453979E-306 = 0 0000000111 11111111111111111111111111111111111111111111111111111 Recommended

2.22507385850720088902458687609E-308 = 0 0000000000 11111111111111111111111111111111111111111111111111111
1.17549435082228737746264717725E-38  = 0 0111000000 11111111111111111111111111111111111111111111111111111
1.17549435082228737746264717725E-38  = 0 0000000    100000000000000000000000

# Accuracy tests

# Satellite:
ncks -3 -O -v T ${DATA}/hdf/MERRA300.prod.assim.inst3_3d_asm_Cp.20130601.nc ~/foo_T.nc
ncatted -a scale_factor,,d,, -a add_offset,,d,, ~/foo_T.nc
ncap2 -O -v -s 'ppc=T;nsd1=ppc;nsd2=ppc;nsd3=ppc;nsd4=ppc;nsd5=ppc;nsd6=ppc;nsd7=ppc' ~/foo_T.nc ~/foo_ppc_in.nc
# Artificial double
ncap2 -O -v -s 'defdim(&quot;dmn&quot;,1000000);ppc=array(1.0,1.e-6,$dmn);nsd1=ppc;nsd2=ppc;nsd3=ppc;nsd4=ppc;nsd5=ppc;nsd6=ppc;nsd7=ppc' ~/nco/data/in.nc ~/foo_ppc_in.nc
# Artificial float
ncap2 -O -v -s 'defdim(&quot;dmn&quot;,1000000);ppc=float(array(1.0,1.e-6,$dmn));nsd1=ppc;nsd2=ppc;nsd3=ppc;nsd4=ppc;nsd5=ppc;nsd6=ppc;nsd7=ppc' ~/nco/data/in.nc ~/foo_ppc_in.nc

# nc3tonc4
nc3tonc4 -o --quantize=nsd1=1,nsd2=2,nsd3=3,nsd4=4,nsd5=5,nsd6=6,nsd7=7 --quiet=1 ~/foo_ppc_in.nc ~/foo_ppc_out.nc
# DSD
ncks -O -C --ppc nsd1=.1 --ppc nsd2=.2 --ppc nsd3=.3 --ppc nsd4=.4 --ppc nsd5=.5 --ppc nsd6=.6 --ppc nsd7=.7 ~/foo_ppc_in.nc ~/foo_ppc_out.nc
# NSD
ncks -O -C --ppc nsd1=1 --ppc nsd2=2 --ppc nsd3=3 --ppc nsd4=4 --ppc nsd5=5 --ppc nsd6=6 --ppc nsd7=7 ~/foo_ppc_in.nc ~/foo_ppc_out.nc

# Generic rounding test:
ncbo -O -C ~/foo_ppc_out.nc ~/foo_ppc_in.nc ~/foo_ppc_dff.nc
ncbo -O -C -y dvd ~/foo_ppc_dff.nc ~/foo_ppc_in.nc ~/foo_ppc_rat.nc
ncap2 -O -v -s 'nsd1*=10;nsd2*=100;nsd3*=1000;nsd4*=10000;nsd5*=100000;nsd6*=1000000;nsd7*=10000000' ~/foo_ppc_rat.nc ~/foo_ppc_rat_scl.nc
ncwa -O -C -y avg ~/foo_ppc_rat_scl.nc ~/foo_ppc_avg.nc
ncwa -O -C -y max ~/foo_ppc_rat_scl.nc ~/foo_ppc_max.nc
ncwa -O -C -y min ~/foo_ppc_rat_scl.nc ~/foo_ppc_min.nc
ncwa -O -C -y mabs ~/foo_ppc_rat_scl.nc ~/foo_ppc_mabs.nc
ncwa -O -C -y mebs ~/foo_ppc_rat_scl.nc ~/foo_ppc_mebs.nc
ncwa -O -C -y mibs ~/foo_ppc_rat_scl.nc ~/foo_ppc_mibs.nc
</ignore>
<example endspaces=" ">
<pre xml:space="preserve">Artificial Data: N=1000000 values in [1.0,2.0) in steps of 1.0e-6
Single-Precision        Double-Precision   Single-Precision
NSD Emabs Emebs Emean   Emabs Emebs Emean  DSD Emabs Emebs Emean
 1  0.31  0.11  4.1e-4  0.31  0.11  4.0e-4  1  0.30  0.11 -8.1e-4  
 2  0.39  0.14  6.8e-5  0.39  0.14  5.5e-5  2  0.39  0.14 -1.3e-4
 3  0.49  0.17  1.0e-6  0.49  0.17 -5.5e-7  3  0.49  0.17 -2.0e-5
 4  0.30  0.11  3.2e-7  0.30  0.11 -6.1e-6  4  0.30  0.11  5.1e-8
 5  0.37  0.13  3.1e-7  0.38  0.13 -5.6e-6  5  0.38  0.13  2.6e-6
 6  0.36  0.12 -4.4e-7  0.48  0.17 -4.1e-7  6  0.48  0.17  7.2e-6
 7  0.00  0.00  0.0     0.30  0.10  1.5e-7  7  0.00  0.00  0.0     

Observational Analysis: N=13934592 values MERRA Temperature 20130601
Single-Precision        
NSD Emabs Emebs Emean   
 1  0.31  0.11  2.4e-3
 2  0.39  0.14  3.8e-4
 3  0.49  0.17 -9.6e-5 
 4  0.30  0.11  2.3e-3
 5  0.37  0.13  2.2e-3
 6  0.36  0.13  1.7e-2
 7  0.00  0.00  0.0     
</pre></example>
<para>All results show that <acronym><acronymword>PPC</acronymword></acronym> quantization performs as expected.
Absolute maximum errors <math><var>Emabs</var> &lt; 0.5</math> for all <var>prc</var>.
For <math>1 &lt;= <var>prc</var> &lt;= 6</math>, quantization results in comparable
maximum absolute and mean absolute errors <var>Emabs</var> and <var>Emebs</var>,
respectively. 
Mean errors <var>Emean</var> are orders of magnitude smaller because 
quantization produces over- and under-estimated values in balance.
When <math><var>prc</var>=7</math>, quantization of single-precision values is
ineffective, because all available bits are used to represent the 
maximum precision of seven digits.
The maximum and mean absolute errors <var>Emabs</var> and <var>Emebs</var> are
nearly identical across algorithms, precisions, and dataset types.
This is consistent with both the artificial data and empirical data
being random, and thus exercising equally strengths and weaknesses of
the algorithms over the course of millions of input values.
We generated artificial arrays with many different starting values
and interval spacing and all gave qualitatively similar results.
The results presented are the worst obtained.
</para>
<para>The artificial data has much smaller mean error <var>Emean</var> than the
observational analysis. 
The reason why is unclear.
It may be because the temperature field is concentrated in particular
ranges of values (and associated quantization errors) prevalent on
Earth, e.g., <math>200 &lt; <var>T</var> &lt; 320</math>. 
It is worth noting that the mean error <math><var>Emean</var> &lt; 0.01</math> for
<math>1 &lt;= <var>prc</var> &lt; 6</math>, and that <var>Emean</var> is typically at least 
two or more orders of magnitude less than <var>Emabs</var>.
Thus quantized values with precisions as low as <math><var>prc</var>=1</math> 
still yield highly significant statistics by contemporary scientific
standards. 
</para>
<para>Testing shows that <acronym><acronymword>PPC</acronymword></acronym> quantization enhances compression of 
typical climate datasets. 
The degree of enhancement depends, of course, on the required
precision. 
Model results are often computed as <code>NC_DOUBLE</code> then archived 
as <code>NC_FLOAT</code> to save space. 
<ignore endspaces=" ">
# Unidata Compression Blog:
# http://www.unidata.ucar.edu/blogs/developer/en/entry/netcdf_compression

# Table entries
fl=${DATA}/dstmch90/dstmch90_clm.nc
fl=${DATA}/hdf/b1850c5cn_doe_polar_merged_0_cesm1_2_0_HD+MAM4+tun2b.hp.e003.cam.h0.0001-01.nc
fl=${DATA}/hdf/MERRA300.prod.assim.inst3_3d_asm_Cp.20130601.nc
fl=${DATA}/hdf/OMI-Aura_L2-OMIAuraSO2_2012m1222-o44888_v01-00-2014m0107t114720.h5

# ncks PPC only
sz_rgn=`ls -l ${fl} | cut -d ' ' -f 5`
fmt_fnc(){ gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}';} 
cmd=&quot;ls -l ${fl}&quot;;sz_new=`${cmd} | cut -d ' ' -f 5`;fmt_fnc ${sz_rgn} ${sz_new}

sz_new=`bzip2 -1 -f ${fl};ls -l ${fl}.bz2 | cut -d ' ' -f 5`;bunzip2 ${fl}.bz2;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`bzip2 -9 -f ${fl};ls -l ${fl}.bz2 | cut -d ' ' -f 5`;bunzip2 ${fl}.bz2;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 0 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 9 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncpdq -O -7 -L 0 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncpdq -O -7 -L 1 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 --ppc default=7 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 --ppc default=6 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 --ppc default=5 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 --ppc default=4 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 --ppc default=3 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 --ppc default=2 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncks -O -7 -L 1 --ppc default=1 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncpdq -O -7 -L 1 --ppc default=4 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncpdq -O -7 -L 9 --ppc default=4 ${fl} ~/foo.nc;ls -l ~/foo.nc | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
sz_new=`ncpdq -O -3 --ppc default=4 ${fl} ~/foo.nc;bzip2 -1 -f ~/foo.nc;ls -l ~/foo.nc.bz2 | cut -d ' ' -f 5`;echo ${sz_rgn} ${sz_new} | gawk '{print &quot;old=&quot; $1/1000000 &quot; MB, new=&quot; $2/1000000 &quot; MB, cmp=&quot; 100*$2/$1 &quot;%&quot;}'
</ignore>
<html endspaces=" ">
&lt;a name=&quot;ppc_tbl_nc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ppc_tbl_nc --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1072">Burrows-Wheeler algorithm</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1073"><command>bzip2</command></indexterm></cindex>
This table summarizes the performance of lossless and lossy compression
on two typical, or at least random, netCDF data files.  
The files were taken from representative model-simulated and
satellite-retrieved datasets.
Only floating-point data were compressed.
No attempt was made to compress integer-type variables as they occupy an 
insignificant fraction of every dataset.
The columns are
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">Type </itemformat></item>
</tableterm><tableitem><para>File-type: 
<kbd>N3</kbd> for netCDF <code>CLASSIC</code>,
<kbd>N4</kbd> for <code>NETCDF4</code>, 
<kbd>N7</kbd> for <code>NETCDF4_CLASSIC</code> (which comprises netCDF3
data types and structures with netCDF4 storage features like
compression),  
<kbd>H4</kbd> for <acronym><acronymword>HDF4</acronymword></acronym>, and
<kbd>H5</kbd> for <acronym><acronymword>HDF5</acronymword></acronym>.
<kbd>N4/7</kbd> means results apply to both <kbd>N4</kbd> and <kbd>N7</kbd> filetypes.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">LLC</itemformat></item>
</tableterm><tableitem><para>Type of lossless compression employed, if any.
Bare numbers refer to the strength of the <acronym><acronymword>DEFLATE</acronymword></acronym> algorithm
employed internally by netCDF4/<acronym><acronymword>HDF5</acronymword></acronym>, while numbers prefixed
with <kbd>B</kbd> refer to the block size employed by the Burrows-Wheeler
algorithm in <command>bzip2</command>. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">PPC </itemformat></item>
</tableterm><tableitem><para>Number of significant digits retained by the precision-preserving
compression <acronym><acronymword>NSD</acronymword></acronym> algorithm.  
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">Pck </itemformat></item>
</tableterm><tableitem><para><kbd>Y</kbd> if the default <command>ncpdq</command> packing algorithm (convert
floating-point types to <code>NC_SHORT</code>) was employed.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">Size</itemformat></item>
</tableterm><tableitem><para>Resulting filesize in <acronym><acronymword>MB</acronymword></acronym>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">%</itemformat></item>
</tableterm><tableitem><para>Compression ratio, i.e., resulting filesize relative to original size,
in percent. 
In some cases the original files is already losslessly compressed. 
The compression ratios reported are relative to the size of the original
file as distributed, not as optimally losslessly compressed. 
</para></tableitem></tableentry></table>
<para>A dash (<kbd>-</kbd>) indicates the associated compression feature
was not employed.
<ignore endspaces=" ">
# Lines trimmed from table as redundant/misleading
  N7   1   4  Y    7.9  22.9  ncpdq --ppc default=4
  N7   9   4  Y    7.7  22.1  ncpdq -L 9 --ppc default=4
  N3  B1   4  Y    6.3  18.1  ncpdq --ppc default=4 bzip2 -1

  N7   1   4  Y   26.3  21.9  ncpdq --ppc default=4
  N7   9   4  Y   25.6  21.4  ncpdq -L 9 --ppc default=4
  N3  B1   4  Y   20.9  17.4  ncpdq --ppc default=4 bzip2 -1

N4/7   1   4  Y  133.6  54.7  ncpdq -L 1 --ppc default=4
N4/7   9   4  Y  127.0  52.0  ncpdq -L 9 --ppc default=4
  N3  B1   4  Y  114.0  46.7  ncpdq --ppc default=4 bzip2 -1

  N4   1   4  Y   13.0  44.0  ncpdq -L 1 --ppc default=4
  N4   9   4  Y   12.5  42.5  ncpdq -L 9 --ppc default=4
</ignore>
</para><example endspaces=" ">
<pre xml:space="preserve"># dstmch90_clm.nc
Type LLC PPC Pck  Size   %    Flags and Notes
  N3   -   -  -   34.7 100.0  Original is not compressed
  N3  B1   -  -   28.9  83.2  bzip2 -1
  N3  B9   -  -   29.3  84.4  bzip2 -9
  N7   -   -  -   35.0 101.0     
  N7   1   -  -   28.2  81.3  -L 1
  N7   9   -  -   28.0  80.8  -L 9
  N7   -   -  Y   17.6  50.9  ncpdq -L 0
  N7   1   -  Y    7.9  22.8  ncpdq -L 1
  N7   1   7  -   28.2  81.3  --ppc default=7
  N7   1   6  -   27.9  80.6  --ppc default=6
  N7   1   5  -   25.9  74.6  --ppc default=5
  N7   1   4  -   22.3  64.3  --ppc default=4
  N7   1   3  -   18.9  54.6  --ppc default=3
  N7   1   2  -   14.5  43.2  --ppc default=2
  N7   1   1  -   10.0  29.0  --ppc default=1

# b1850c5cn_doe_polar_merged_0_cesm1_2_0_HD+MAM4+tun2b.hp.e003.cam.h0.0001-01.nc
Type LLC PPC Pck  Size   %    Flags and Notes
  N3   -   -  -  119.8 100.0  Original is not compressed
  N3  B1   -  -   84.2  70.3  bzip2 -1
  N3  B9   -  -   84.8  70.9  bzip2 -9
  N7   -   -  -  120.5 100.7     
  N7   1   -  -   82.6  69.0  -L 1
  N7   9   -  -   82.1  68.6  -L 9
  N7   -   -  Y   60.7  50.7  ncpdq -L 0
  N7   1   -  Y   26.0  21.8  ncpdq -L 1
  N7   1   7  -   82.6  69.0  --ppc default=7
  N7   1   6  -   81.9  68.4  --ppc default=6
  N7   1   5  -   77.2  64.5  --ppc default=5
  N7   1   4  -   69.0  57.6  --ppc default=4
  N7   1   3  -   59.3  49.5  --ppc default=3
  N7   1   2  -   49.5  41.3  --ppc default=2
  N7   1   1  -   38.2  31.9  --ppc default=1

# MERRA300.prod.assim.inst3_3d_asm_Cp.20130601.hdf
Type LLC PPC Pck  Size   %    Flags and Notes
  H4   5   -  -  244.3 100.0  Original is compressed
  H4  B1   -  -  244.7 100.1  bzip2 -1
  N4   5   -  -  214.5  87.8
  N7   5   -  -  210.6  86.2  
  N4  B1   -  -  215.4  88.2  bzip2 -1
  N4  B9   -  -  214.8  87.9  bzip2 -9
  N3   -   -  -  617.1 252.6
N4/7   -   -  -  694.0 284.0  -L 0
N4/7   1   -  -  223.2  91.3  -L 1
N4/7   9   -  -  207.3  84.9  -L 9
N4/7   -   -  Y  347.1 142.1  ncpdq -L 0
N4/7   1   -  Y  133.6  54.7  ncpdq -L 1
N4/7   1   7  -  223.1  91.3  --ppc default=7
N4/7   1   6  -  225.1  92.1  --ppc default=6
N4/7   1   5  -  221.4  90.6  --ppc default=5
N4/7   1   4  -  201.4  82.4  --ppc default=4
N4/7   1   3  -  185.3  75.9  --ppc default=3
N4/7   1   2  -  150.0  61.4  --ppc default=2
N4/7   1   1  -  100.8  41.3  --ppc default=1

# OMI-Aura_L2-OMIAuraSO2_2012m1222-o44888_v01-00-2014m0107t114720.h5
Type LLC PPC Pck  Size   %    Flags and Notes
  H5   5   -  -   29.5 100.0  Original is compressed
  H5  B1   -  -   29.3  99.6  bzip2 -1
  N4   5   -  -   29.5 100.0
  N4  B1   -  -   29.3  99.6  bzip2 -1
  N4  B9   -  -   29.3  99.4  bzip2 -9
  N4   -   -  -   50.7 172.3  -L 0
  N4   1   -  -   29.8 101.3  -L 1
  N4   9   -  -   29.4  99.8  -L 9
  N4   -   -  Y   27.7  94.0  ncpdq -L 0
  N4   1   -  Y   12.9  43.9  ncpdq -L 1
  N4   1   7  -   29.7 100.7  --ppc default=7
  N4   1   6  -   29.7 100.8  --ppc default=6
  N4   1   5  -   27.3  92.8  --ppc default=5
  N4   1   4  -   23.8  80.7  --ppc default=4
  N4   1   3  -   20.3  69.0  --ppc default=3
  N4   1   2  -   15.1  51.2  --ppc default=2
  N4   1   1  -    9.9  33.6  --ppc default=1
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="1074"><acronym><acronymword>NCAR</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1075"><acronym><acronymword>CAM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1076"><acronym><acronymword>GCM</acronymword></acronym></indexterm></cindex>
<para>A selective, per-variable approach to <acronym><acronymword>PPC</acronymword></acronym> yields the
best balance of precision and compression yet requires the dataset
producer to understand the intrinsic precision of each variable.
Such a specification for a <acronym><acronymword>GCM</acronymword></acronym> dataset might look like this 
(using names for the <acronym><acronymword>NCAR</acronymword></acronym> <acronym><acronymword>CAM</acronymword></acronym> model):
</para><example endspaces=" ">
<pre xml:space="preserve"># Be conservative on non-explicit quantities, so default=5
# Some quantities deserve four significant digits
# Many quantities, such as aerosol optical depths and burdens, are 
# highly uncertain and only useful to three significant digits.
ncks -7 -O \
--qnt default=5 \
--qnt AN.?,AQ.?=4 \
--qnt AER.?,AOD.?,ARE.?,AW.?,BURDEN.?=3 \
ncar_cam.nc ~/foo.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;dfl_lvl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dfl_lvl --&gt;
&lt;a name=&quot;dfl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dfl --&gt;
&lt;a name=&quot;lz&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lz --&gt;
&lt;a name=&quot;lz77&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lz77 --&gt;
&lt;a name=&quot;deflate&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#deflate --&gt;
&lt;a name=&quot;deflation&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#deflation --&gt;
</html>
</subsection>
</section>
<node name="Deflation" spaces=" "><nodename>Deflation</nodename><nodenext spaces=" ">MD5 digests</nodenext><nodeprev spaces=" ">Compression</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Deflation</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1077"><code>-L</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1078"><code>--deflate</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1079"><code>--dfl_lvl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1080">Lempel-Ziv deflation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1081">compression</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1082">deflation</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncclimo</command>, <command>nces</command>,
<command>ncecat</command>, <command>ncflint</command>, <command>ncks</command>, <command>ncpdq</command>,
<command>ncra</command>, <command>ncrcat</command>, <command>ncremap</command>, <command>ncwa</command>&linebreak;
Short options: <samp>-L</samp>&linebreak;
Long options: <samp>--dfl_lvl</samp>, <samp>--deflate</samp>&linebreak;  
</para></cartouche>

<para>All <acronym><acronymword>NCO</acronymword></acronym> operators that define variables support the netCDF4
feature of storing variables compressed with the lossless
<acronym><acronymword>DEFLATE</acronymword></acronym> compression algorithm.
<acronym><acronymword>DEFLATE</acronymword></acronym> combines the Lempel-Ziv encoding with Huffman coding.
The specific version used by netCDF4/<acronym><acronymword>HDF5</acronymword></acronym> is that implemented
in the <command>zlib</command> library used by <command>gzip</command>.
Activate deflation with the <code>-L <var>dfl_lvl</var></code> short option (or
with the same argument to the <samp>--dfl_lvl</samp> or <samp>--deflate</samp> long
options). 
Specify the deflation level <var>dfl_lvl</var> on a scale from no deflation
(<var>dfl_lvl = 0</var>) to maximum deflation (<var>dfl_lvl = 9</var>).
Under the hood, this selects the compression blocksize.
Minimal deflation (<var>dfl_lvl = 1</var>) achieves considerable storage
compression with little time penalty.
Higher deflation levels require more time for compression.
File sizes resulting from minimal (<var>dfl_lvl = 1</var>) and maximal   
(<var>dfl_lvl = 9</var>) deflation levels typically differ by less 
<w>than 10%</w> in size. 
</para>
<para>To compress an entire file using deflation, use
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -4 -L 0 in.nc out.nc # No deflation (fast, no time penalty)
ncks -4 -L 1 in.nc out.nc # Minimal deflation (little time penalty)
ncks -4 -L 9 in.nc out.nc # Maximal deflation (much slower)
</pre></example>

<para>Unscientific testing shows that deflation compresses typical climate
datasets by 30-60%.  
Packing, a lossy compression technique available for all netCDF files 
(see <ref label="Packed-data"><xrefnodename>Packed data</xrefnodename></ref>), can easily compress files by 50%.
Packed data may be deflated to squeeze datasets by about 80%:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks  -4 -L 1 in.nc out.nc # Minimal deflation (~30-60% compression)
ncks  -4 -L 9 in.nc out.nc # Maximal deflation (~31-63% compression)
ncpdq         in.nc out.nc # Standard packing  (~50% compression)
ncpdq -4 -L 9 in.nc out.nc # Deflated packing  (~80% compression)
</pre></example>
<findex index="fn" spaces=" "><indexterm index="fn" number="11" mergedindex="cp">ncks</indexterm></findex>
<para><command>ncks</command> prints deflation parameters, if any, to screen
(<pxref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></pxref>).
</para>
<html endspaces=" ">
&lt;a name=&quot;md5&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#md5 --&gt;
&lt;a name=&quot;digest&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#digest --&gt;
&lt;a name=&quot;hash&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hash --&gt;
&lt;a name=&quot;integrity&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#integrity --&gt;
&lt;a name=&quot;security&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#security --&gt;
</html>
</section>
<node name="MD5-digests" spaces=" "><nodename>MD5 digests</nodename><nodenext spaces=" ">Buffer sizes</nodenext><nodeprev spaces=" ">Deflation</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>MD5 digests</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1083"><code>--md5_digest</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1084"><code>--md5_dgs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1085"><code>--md5_wrt_att</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1086"><code>--md5_write_attribute</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1087">integrity</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1088">security</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1089">digest</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1090">hash</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1091">MD5 digest</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: 
<command>ncecat</command>, <command>ncks</command>, <command>ncrcat</command>&linebreak;
Short options: &linebreak;
Long options: <samp>--md5_dgs</samp>, <samp>--md5_digest</samp>, <samp>--md5_wrt_att</samp>, <samp>--md5_write_attribute</samp>&linebreak;
</para></cartouche>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.1.0 (April, 2012), <acronym><acronymword>NCO</acronymword></acronym> 
supports data integrity verification using the <acronym><acronymword>MD5</acronymword></acronym> digest
algorithm. 
This support is currently implemented in <command>ncks</command> and in the
multi-file concatenators <command>ncecat</command> and <command>ncrcat</command>.
Activate it with the <samp>--md5_dgs</samp> or <samp>--md5_digest</samp> long
options. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.3.3 (July, 2013), <acronym><acronymword>NCO</acronymword></acronym> 
will write the <acronym><acronymword>MD5</acronymword></acronym> digest of each variable as an
<code>NC_CHAR</code> attribute named <code>MD5</code>.
This support is currently implemented in <command>ncks</command> and in the
multi-file concatenators <command>ncecat</command> and <command>ncrcat</command>.
Activate it with the <samp>--md5_wrt_att</samp> or
<samp>--md5_write_attribute</samp> long options.
</para>
<para>The behavior and verbosity of the <acronym><acronymword>MD5</acronymword></acronym> digest is
operator-dependent.
<acronym><acronymword>MD5</acronymword></acronym> digests may be activated in both <command>ncks</command> invocation
types, the one-filename argument mode for printing sub-setted and
hyperslabbed data, and the two-filename argument mode for copying that
data to a new file. 
Both modes will incur minor overhead from performing the hash
algorithm for each variable read, and each variable written will
have an additional attribute named <code>MD5</code>.
When activating <acronym><acronymword>MD5</acronymword></acronym> digests with <command>ncks</command> it is assumed
that the user wishes to print the digest of every variable when the
debugging level exceeds one. 
</para>
<para><command>ncks</command> displays an <acronym><acronymword>MD5</acronymword></acronym> digest as a 32-character
hexadecimal string in which each two characters represent one byte of 
the 16-byte digest: 
</para><example endspaces=" ">
<pre xml:space="preserve">&gt; ncks --trd -D 2 -C --md5 -v md5_a,md5_abc ~/nco/data/in.nc
...
ncks: INFO MD5(md5_a) = 0cc175b9c0f1b6a831c399e269772661
md5_a = 'a' 
ncks: INFO MD5(md5_abc) = 900150983cd24fb0d6963f7d28e17f72
lev[0]=100 md5_abc[0--2]='abc' 
&gt; ncks --trd -D 2 -C -d lev,0 --md5 -v md5_a,md5_abc ~/nco/data/in.nc
...
ncks: INFO MD5(md5_a) = 0cc175b9c0f1b6a831c399e269772661
md5_a = 'a' 
ncks: INFO MD5(md5_abc) = 0cc175b9c0f1b6a831c399e269772661
lev[0]=100 md5_abc[0--0]='a' 
</pre></example>
<para>In fact these examples demonstrate the validity of the hash algorithm
since the <acronym><acronymword>MD5</acronymword></acronym> hashes of the strings &textldquo;a&textrdquo; and &textldquo;abc&textrdquo; are
widely known.
The second example shows that the hyperslab of variable <code>md5_abc</code>
(= &textldquo;abc&textrdquo;) consisting of only its first letter (= &textldquo;a&textrdquo;) has the same
hash as the variable <code>md5_a</code> (&textldquo;a&textrdquo;).
This illustrates that <acronym><acronymword>MD5</acronymword></acronym> digests act only on variable data,
not on metadata. 
</para>
<para>When activating <acronym><acronymword>MD5</acronymword></acronym> digests with <command>ncecat</command> or
<command>ncrcat</command> it is assumed that the user wishes to verify
that every variable written to disk has the same <acronym><acronymword>MD5</acronymword></acronym> digest 
as when it is subsequently read from disk.
This incurs the major additional overhead of reading in each variable
after it is written and performing the hash algorithm again on that to
compare to the original hash.
Moreover, it is assumed that such operations are generally done in
&textldquo;production mode&textrdquo; where the user is not interested in actually
examining the digests herself.
The digests proceed silently unless the debugging level exceeds three:
</para><example endspaces=" ">
<pre xml:space="preserve">&gt; ncecat -O -D 4 --md5 -p ~/nco/data in.nc in.nc ~/foo.nc | grep MD5
...
ncecat: INFO MD5(wnd_spd) = bec190dd944f2ce2794a7a4abf224b28
ncecat: INFO MD5 digests of RAM and disk contents for wnd_spd agree
&gt; ncrcat -O -D 4 --md5 -p ~/nco/data in.nc in.nc ~/foo.nc | grep MD5
...
ncrcat: INFO MD5(wnd_spd) = 74699bb0a72b7f16456badb2c995f1a1
ncrcat: INFO MD5 digests of RAM and disk contents for wnd_spd agree
</pre></example>
<para>Regardless of the debugging level, an error is returned when the digests
of the variable read from the source file and from the output file
disagree.  
</para>
<para>These rules may further evolve as <acronym><acronymword>NCO</acronymword></acronym> pays more attention to 
data integrity. 
We welcome feedback and suggestions from users.
</para>
<html endspaces=" ">
&lt;a name=&quot;bfr_sz_hnt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bfr_sz_hnt --&gt;
&lt;a name=&quot;bfr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bfr --&gt;
&lt;a name=&quot;buffer&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#buffer --&gt;
</html>
</section>
<node name="Buffer-sizes" spaces=" "><nodename>Buffer sizes</nodename><nodenext spaces=" ">RAM disks</nodenext><nodeprev spaces=" ">MD5 digests</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Buffer sizes</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1092"><code>--bfr_sz_hnt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1093">Buffer sizes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1094">File buffers</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1095"><command>stat() system call</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1096">I/O block size</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1097">System calls</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: &linebreak;
Long options: <samp>--bfr_sz_hnt</samp>, <samp>--buffer_size_hint</samp>&linebreak;  
</para></cartouche>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.2.0 (May, 2012), <acronym><acronymword>NCO</acronymword></acronym> 
allows the user to request specific buffer sizes to allocate for reading 
and writing files.
This buffer size determines how many system calls the netCDF layer must
invoke to read and write files.
By default, netCDF uses the preferred I/O block size returned as the
<samp>st_blksize</samp> member of the <samp>stat</samp> structure returned by the
<command>stat()</command> system call
<footnote spaces="\n"><para>On modern Linux systems the block size defaults to <w>8192 B</w>.
The GLADE filesystem at NCAR has a block size of <w>512 kB</w>.</para></footnote>.
Otherwise, netCDF uses twice the system pagesize.
Larger sizes can increase access speed by reducing the number of 
system calls netCDF makes to read/write data from/to disk.
Because netCDF cannot guarantee the buffer size request will be met, the 
actual buffer size granted by the system is printed as an INFO
statement. 
</para><example endspaces=" ">
<pre xml:space="preserve"># Request 2 MB file buffer instead of default 8 kB buffer
&gt; ncks -O -D 3 --bfr_sz=2097152 ~/nco/data/in.nc ~/foo.nc
...
ncks: INFO nc__open() will request file buffer size = 2097152 bytes
ncks: INFO nc__open() opened file with buffer size = 2097152 bytes
...
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ram_all&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ram_all --&gt;
&lt;a name=&quot;ram&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ram --&gt;
&lt;a name=&quot;diskless&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#diskless --&gt;
</html>
</section>
<node name="RAM-disks" spaces=" "><nodename>RAM disks</nodename><nodenext spaces=" ">Unbuffered I/O</nodenext><nodeprev spaces=" ">Buffer sizes</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>RAM disks</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1098"><code>--ram_all</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1099"><code>--create_ram</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1100"><code>--open_ram</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1101"><code>--diskless_all</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1102"><acronym><acronymword>RAM</acronymword></acronym> disks</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1103"><acronym><acronymword>RAM</acronymword></acronym> files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1104"><code>NC_DISKLESS</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1105">diskless files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1106">memory requirements</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1107">memory available</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1108"><acronym><acronymword>RAM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1109">swap space</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1110">peak memory usage</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators (works with netCDF3 files only)&linebreak;
Short options: &linebreak;
Long options: <samp>--ram_all</samp>, <samp>--create_ram</samp>, <samp>--open_ram</samp>,
<samp>--diskless_all</samp>&linebreak;   
</para></cartouche>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.2.1 (August, 2012), <acronym><acronymword>NCO</acronymword></acronym> supports
the use of diskless files, aka <acronym><acronymword>RAM</acronymword></acronym> disks, for access and
creation of netCDF3 files (these options have no effect on netCDF4 files). 
Two independent switches, <samp>--open_ram</samp> and <samp>--create_ram</samp>,
control this feature. 
Before describing the specifics of these switches, we describe why many 
<acronym><acronymword>NCO</acronymword></acronym> operations will not benefit from them.
Essentially, reading/writing from/to <acronym><acronymword>RAM</acronymword></acronym> rather than disk only hastens 
the task when reads/writes to disk are avoided.
Most <acronym><acronymword>NCO</acronymword></acronym> operations are simple enough that they require a
single read-from/write-to disk for every block of input/output. 
Diskless access does not change this, but it does add an extra
read-from/write-to <acronym><acronymword>RAM</acronymword></acronym>. 
However this extra <acronym><acronymword>RAM</acronymword></acronym> write/read does avoid contention for limited
system resources like disk-head access.
Operators which may benefit from <acronym><acronymword>RAM</acronymword></acronym> disks include
<command>ncwa</command>, which may need to read weighting variables multiple
times, the multi-file  operators <command>ncra</command>, <command>ncrcat</command>, and
<command>ncecat</command>, which may try to write output at least once per input
file, and <command>ncap2</command> scripts which may be arbitrarily long and
convoluted.  
</para>
<para>The <samp>--open_ram</samp> switch causes input files to copied to <acronym><acronymword>RAM</acronymword></acronym> when
opened. 
All further metadata and data access occurs in <acronym><acronymword>RAM</acronymword></acronym> and thus avoids
access time delays caused by disk-head movement.
Usually input data is read at most once so it is unlikely that
requesting input files be stored in <acronym><acronymword>RAM</acronymword></acronym> will save much time.
The likeliest exceptions are files that are accessed numerous times,
such as those repeatedly analyzed by <command>ncap2</command>. 
</para>
<para>Invoking <samp>--open_ram</samp>, <samp>--ram_all</samp>, or <samp>--diskless_all</samp>
uses much more system memory.
To copy the input file to <acronym><acronymword>RAM</acronymword></acronym> increases the sustained
memory use by exactly the on-disk filesize of the input file, i.e.,
<math>MS += FT</math>.
For large input files this can be a huge memory burden that starves
the rest of the <acronym><acronymword>NCO</acronymword></acronym> analysis of sufficient <acronym><acronymword>RAM</acronymword></acronym>.
To be safe, use <samp>--open_ram</samp>, <samp>--ram_all</samp>, or
<samp>--diskless_all</samp> only on files that are much (say at least a factor
of four) smaller than your available system <acronym><acronymword>RAM</acronymword></acronym>.
See <ref label="Memory-Requirements"><xrefnodename>Memory Requirements</xrefnodename></ref> for further details. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1111"><acronym><acronymword>RAM</acronymword></acronym> variables</indexterm></cindex>
<para>The <samp>--create_ram</samp> switch causes output files to be created in
<acronym><acronymword>RAM</acronymword></acronym>, rather than on disk. 
These files are copied to disk only when closed, i.e., when the
operator completes.
Creating files in <acronym><acronymword>RAM</acronymword></acronym> may save time, especially with
<command>ncap2</command> computations that are iterative, e.g., loops, and for
multi-file operators that write output every record (timestep) or file. 
<acronym><acronymword>RAM</acronymword></acronym> files provide many of the same benefits as <acronym><acronymword>RAM</acronymword></acronym>
variables in such cases (<pxref label="RAM-variables"><xrefnodename>RAM variables</xrefnodename></pxref>). 
</para>
<para>Two switches, <samp>--ram_all</samp> and <samp>--diskless_all</samp>, are convenient
shortcuts for specifying both <samp>--create_ram</samp> and <samp>--open_ram</samp>. 
Thus
</para><example endspaces=" ">
<pre xml:space="preserve">ncks in.nc out.nc # Default: Open in.nc on disk, write out.nc to disk
ncks --open_ram in.nc out.nc # Open in.nc in RAM, write out.nc to disk
ncks --create_ram in.nc out.nc # Create out.nc in RAM, write to disk
# Open in.nc in RAM, create out.nc in RAM, then write out.nc to disk
ncks --open_ram --create_ram in.nc out.nc
ncks --ram_all in.nc out.nc # Same as above
ncks --diskless_all in.nc out.nc # Same as above
</pre></example>

<para>It is straightforward to demonstrate the efficacy of <acronym><acronymword>RAM</acronymword></acronym>
disks.
For <acronym><acronymword>NASA</acronymword></acronym> we constructed a test that employs <command>ncecat</command> 
an arbitrary number (set to one hundred thousand) of files that are all 
symbolically linked to the same file. 
Everything is on the local filesystem (not <acronym><acronymword>DAP</acronymword></acronym>).
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Create symbolic links for benchmark
cd ${DATA}/nco # Do all work here
for idx in {1..99999}; do
  idx_fmt=`printf &quot;%05d&quot; ${idx}`
  /bin/ln -s ${DATA}/nco/LPRM-AMSR_E_L3_D_SOILM3_V002-20120512T111931Z_20020619.nc \
             ${DATA}/nco/${idx_fmt}.nc
done
# Benchmark time to ncecat one hundred thousand files
time ncecat --create_ram -O -u time -v ts -d Latitude,40.0 \ 
 -d Longitude,-105.0 -p ${DATA}/nco -n 99999,5,1 00001.nc ~/foo.nc
</verbatim>
</example>
<para>Run normally on a laptop in 201303, this completes in <w>21 seconds</w>.
The <samp>--create_ram</samp> reduces the elapsed time to <w>9 seconds</w>.
Some of this speed may be due to using symlinks and caching.
However, the efficacy of <samp>--create_ram</samp> is clear.
Placing the output file in <acronym><acronymword>RAM</acronymword></acronym> avoids thousands of disk
writes.
It is not unreasonable to for <acronym><acronymword>NCO</acronymword></acronym> to process a million files 
like this in a few minutes. 
However, there is no substitute for benchmarking with real files.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1112">temporary output files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1113">temporary files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1114"><code>--no_tmp_fl</code></indexterm></cindex>
<para>A completely independent way to reduce time spent writing files is 
to refrain from writing temporary output files.
This is accomplished with the <samp>--no_tmp_fl</samp> switch 
(<pxref label="Temporary-Output-Files"><xrefnodename>Temporary Output Files</xrefnodename></pxref>).
</para>
<html endspaces=" ">
&lt;a name=&quot;share_all&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#share_all --&gt;
&lt;a name=&quot;share&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#share --&gt;
&lt;a name=&quot;create_share&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#create_share --&gt;
&lt;a name=&quot;open_share&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#open_share --&gt;
&lt;a name=&quot;unbuffered_io&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#unbuffered_io --&gt;
&lt;a name=&quot;unbuffered&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#unbuffered --&gt;
&lt;a name=&quot;uio&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#uio --&gt;
</html>
</section>
<node name="Unbuffered-I_002fO" spaces=" "><nodename>Unbuffered I/O</nodename><nodenext spaces=" ">Packed data</nodenext><nodeprev spaces=" ">RAM disks</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Unbuffered I/O</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1115"><code>--share_all</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1116"><code>--create_share</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1117"><code>--open_share</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1118"><code>--unbuffered_io</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1119"><code>--uio</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1120">unbuffered I/O</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1121"><code>NC_SHARE</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1122">concurrent access</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1123">shared access</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1124">caching</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators (works on netCDF3 files only)&linebreak;
Short options: &linebreak;
Long options: <samp>--share_all</samp>, <samp>--create_share</samp>,
<samp>--open_share</samp>, <samp>--unbuffered_io</samp>, <samp>--uio</samp>&linebreak;   
</para></cartouche>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.4 (July, 2020), <acronym><acronymword>NCO</acronymword></acronym> supports
unbuffered I/O with netCDF3 files when requested with the
<samp>--unbuffered_io</samp> flag, or its synonyms <samp>--uio</samp> or
<samp>--share_all</samp>. 
(Note that these options work only with netCDF3 files and have no
affect on netCDF4 files). 
These flags turn-off the default I/O buffering mode for both newly
created and existing datasets.
For finer-grained control, use the <code>--create_share</code> switch to
request unbuffered I/O only for newly created datasets, and the
<code>--open_share</code> switch to request unbuffered I/O only for
existing datasets.
Typically these options only significantly reduce throughput time
when large record variables are written or read.
Normal I/O buffering copies the data to be read/written into an
intermediate buffer in order to avoid numerous small reads/writes.
Unbuffered I/O avoids this intermediate step and can therefore
execute (sometimes much) faster when read/write lengths are large.
</para>
<html endspaces=" ">
&lt;a name=&quot;pck&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#pck --&gt;
&lt;a name=&quot;pack&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#pack --&gt;
</html>
</section>
<node name="Packed-data" spaces=" "><nodename>Packed data</nodename><nodenext spaces=" ">Operation Types</nodenext><nodeprev spaces=" ">Unbuffered I/O</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Packed data</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1125">packing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1126">unpacking</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1127"><code>add_offset</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1128"><code>scale_factor</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1129"><code>missing_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1130"><code>_FillValue</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1131"><command>pack(x)</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1132"><command>unpack(x)</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1133"><code>--hdf_upk</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1134"><code>--hdf_unpack</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>nces</command>,
<command>ncflint</command>, <command>ncpdq</command>, <command>ncra</command>, <command>ncwa</command>&linebreak; 
Short options: None&linebreak;
Long options: <samp>--hdf_upk</samp>, <samp>--hdf_unpack</samp>&linebreak;
</para></cartouche>

<para>The phrase <dfn>packed data</dfn> refers to data which are stored in the
standard netCDF3 lossy linear packing format.
See <ref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></ref> for a description of deflation, a 
lossless compression technique available with netCDF4 only.
Packed data may be deflated to save additional space.
</para>
<unnumberedsubsec spaces=" "><sectiontitle>Standard Packing Algorithm</sectiontitle>
<para><dfn>Packing</dfn>
The standard netCDF linear packing algorithm (described
<uref><urefurl>http://www.unidata.ucar.edu/software/netcdf/docs/netcdf/Attribute-Conventions.html</urefurl><urefdesc spaces=" ">here</urefdesc></uref>)
produces packed data with the same dynamic range as the original but
which requires no more than half the space to store.
<acronym><acronymword>NCO</acronymword></acronym> will always use this algorithm for packing.
Like all packing algorithms, linear packing is <emph>lossy</emph>.
Just how lossy depends on the values themselves, especially their range.
The packed variable is stored (usually) as type <code>NC_SHORT</code>
with the two attributes required to unpack the variable,
<code>scale_factor</code> and <code>add_offset</code>, stored at the original
(unpacked) precision of the variable
<footnote><para>Although not a part of the standard, <acronym><acronymword>NCO</acronymword></acronym> enforces
the policy that the <code>_FillValue</code> attribute, if any, of a packed
variable is also stored at the original precision.</para></footnote>.
Let <var>min</var> and <var>max</var> be the minimum and maximum values 
<w>of <var>x</var>.</w> 
<tex endspaces=" ">
$$
\rm
\eqalign{\hbox{scale\_factor} &amp;= (\hbox{max}-\hbox{min})/\hbox{ndrv}\cr
\hbox{add\_offset} &amp;= (\hbox{min}+\hbox{max})/2\cr
\hbox{pck} &amp;= (\hbox{upk}-\hbox{add\_offset})/\hbox{scale\_factor}\cr
 &amp;= {\hbox{ndrv}\times[\hbox{upk}-(\hbox{min}+\hbox{max})/2]\over\hbox{max}-\hbox{min}}\cr}
$$
</tex>
</para><sp spaces=" " value="1" line="1"></sp>
<para><var>scale_factor</var> = (<var>max</var>-<var>min</var>)/<var>ndrv</var>&linebreak;
<var>add_offset</var> = 0.5*(<var>min</var>+<var>max</var>)&linebreak;
<var>pck</var> = (<var>upk</var>-<var>add_offset</var>)/<var>scale_factor</var> = (<var>upk</var>-0.5*(<var>min</var>+<var>max</var>))*<var>ndrv</var>/(<var>max</var>-<var>min</var>)&linebreak; 
</para><sp spaces=" " value="1" line="1"></sp>
<para>where <var>ndrv</var> is the number of discrete representable values for
given type of packed variable.
The theoretical maximum value for <var>ndrv</var> is two raised to the
number of bits used to store the packed variable.
Thus if the variable is packed into type <code>NC_SHORT</code>, a two-byte
datatype, then there are at most <math>2^{16} = 65536</math> distinct values
representable.
In practice, the number of discretely representible values is taken
to be two less than the theoretical maximum.
This leaves space for a missing value and solves potential problems with
rounding that may occur during the unpacking of the variable.
Thus for <code>NC_SHORT</code>, <math>ndrv = 65536 - 2 = 65534</math>.
Less often, the variable may be packed into type <code>NC_CHAR</code>, 
where <math>ndrv = 2^{8} - 2 = 256 - 2 = 254</math>, or type <code>NC_INT</code> where
where <math>ndrv = 2^{32} - 2 = 4294967295 - 2 = 4294967293</math>.
One useful feature of the (lossy) netCDF packing algorithm is that 
lossless packing algorithms perform well on top of it. 
</para>
<html endspaces=" ">
&lt;a name=&quot;upk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#upk --&gt;
&lt;a name=&quot;unpack&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#unpack --&gt;
</html>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Standard (Default) Unpacking Algorithm</sectiontitle>
<para><dfn>Unpacking</dfn>
The unpacking algorithm depends on the presence of two attributes,
<code>scale_factor</code> and <code>add_offset</code>.
If <code>scale_factor</code> is present for a variable, the data are
multiplied by the value <var>scale_factor</var> after the data are read.
If <code>add_offset</code> is present for a variable, then the
<var>add_offset</var> value is added to the data after the data are read.
If both <code>scale_factor</code> and <code>add_offset</code> attributes are
present, the data are first scaled by <var>scale_factor</var> before the
offset <var>add_offset</var> is added.   
<tex endspaces=" ">
$$
\rm
\eqalign{\hbox{upk} &amp;= \hbox{scale\_factor}\times\hbox{pck} + \hbox{add\_offset}\cr 
&amp;= {\hbox{pck}\times(\hbox{max}-\hbox{min})\over\hbox{ndrv}} + {\hbox{min}+\hbox{max}\over2}\cr} 
$$
</tex>
</para><sp spaces=" " value="1" line="1"></sp>
<para><var>upk</var> = <var>scale_factor</var>*<var>pck</var> + <var>add_offset</var> = (<var>max</var>-<var>min</var>)*<var>pck</var>/<var>ndrv</var> + 0.5*(<var>min</var>+<var>max</var>)&linebreak;
</para><sp spaces=" " value="1" line="1"></sp>
<para><acronym><acronymword>NCO</acronymword></acronym> will use this algorithm for unpacking unless told
otherwise as described below.
When <code>scale_factor</code> and <code>add_offset</code> are used for packing, the
associated variable (containing the packed data) is typically of type
<code>byte</code> or <code>short</code>, whereas the unpacked values are intended to
be of type <code>int</code>, <code>float</code>, or <code>double</code>. 
An attribute&textrsquo;s <code>scale_factor</code> and <code>add_offset</code> and
<code>_FillValue</code>, if any, should all be of the type intended for the
unpacked data, i.e., <code>int</code>, <code>float</code> or <code>double</code>. 
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Non-Standard Packing and Unpacking Algorithms</sectiontitle>
<html endspaces=" ">
&lt;a name=&quot;hdf_upk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdf_upk --&gt;
&lt;a name=&quot;hdf_unpack&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdf_unpack --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1135">interoperability</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1136"><acronym><acronymword>HDF</acronymword></acronym> unpacking</indexterm></cindex>
<para>Many (most?) files originally written in <acronym><acronymword>HDF4</acronymword></acronym> format use
poorly documented packing/unpacking algorithms that are incompatible and
easily confused with the netCDF packing algorithm described above.   
The unpacking component of the &textldquo;conventional&textrdquo; <acronym><acronymword>HDF</acronymword></acronym> algorithm
(described <uref><urefurl>http://www.hdfgroup.org/HDF5/doc/UG/UG_frame10Datasets.html</urefurl><urefdesc spaces=" ">here</urefdesc></uref>
and in Section 3.10.6 of the <acronym><acronymword>HDF4</acronymword></acronym> Users Guide
<uref><urefurl>http://www.hdfgroup.org/release4/doc/UsrGuide_html/UG_PDF.pdf</urefurl><urefdesc spaces="\n">here</urefdesc></uref>, 
and in the <acronym><acronymword>FAQ</acronymword></acronym> for <acronym><acronymword>MODIS</acronymword></acronym> <acronym><acronymword>MOD08</acronymword></acronym> data
<uref><urefurl>http://modis-atmos.gsfc.nasa.gov/MOD08_D3/faq.html</urefurl><urefdesc spaces=" ">here</urefdesc></uref>) 
is
<tex endspaces=" ">
$$
\rm
\hbox{upk} = \hbox{scale\_factor}\times(\hbox{pck} - \hbox{add\_offset})
$$
</tex>
</para><sp spaces=" " value="1" line="1"></sp>
<para><var>upk</var> = <var>scale_factor</var>*(<var>pck</var> - <var>add_offset</var>)&linebreak;
</para><sp spaces=" " value="1" line="1"></sp>

<para>The unpacking component of the <acronym><acronymword>HDF</acronymword></acronym> algorithm employed
for <acronym><acronymword>MODIS</acronymword></acronym> <acronym><acronymword>MOD13</acronymword></acronym> data
is
<tex endspaces=" ">
$$
\rm
\hbox{upk} = (\hbox{pck} - \hbox{add\_offset})/\hbox{scale\_factor}
$$
</tex>
</para><sp spaces=" " value="1" line="1"></sp>
<para><var>upk</var> = (<var>pck</var> - <var>add_offset</var>)/<var>scale_factor</var>&linebreak;
</para><sp spaces=" " value="1" line="1"></sp>

<para>The unpacking component of the <acronym><acronymword>HDF</acronymword></acronym> algorithm employed
for <acronym><acronymword>MODIS</acronymword></acronym> <acronym><acronymword>MOD04</acronymword></acronym> data is the same as the netCDF
algorithm.
</para>
<ignore endspaces=" ">
@acronym{HDF5} only implements D-scaling, aka, decimal-scaling
bit-packing. 
D-Scaling uses @code{add_offset} as a minimum data value, and
@code{scale_factor} as the integer power @w{of 10} by which the
@code{add_offset} corrected data are divided before storage.
</ignore>
<para>Confusingly, the (incompatible) netCDF and <acronym><acronymword>HDF</acronymword></acronym> algorithms both 
store their parameters in attributes with the same names
(<code>scale_factor</code> and <code>add_offset</code>).
Data packed with one algorithm should never be unpacked with the other;
doing so will result in incorrect answers.
Unfortunately, few users are aware that their datasets may be packed,
and fewer know the details of the packing algorithm employed.
This is what we in the &textldquo;bizness&textrdquo; call an <dfn>interoperability</dfn> issue
because it hampers data analysis performed on heterogeneous systems.
</para>
<para>As described below, <acronym><acronymword>NCO</acronymword></acronym> automatically unpacks data before
performing arithmetic.
This automatic unpacking occurs silently since there is usually no
reason to bother users with these details. 
There is as yet no generic way for <acronym><acronymword>NCO</acronymword></acronym> to know which
packing convention was used, so <acronym><acronymword>NCO</acronymword></acronym> <emph>assumes</emph> the netCDF 
convention was used. 
<acronym><acronymword>NCO</acronymword></acronym> uses the same convention for unpacking unless explicitly
told otherwise with the <samp>--hdf_upk</samp> (also <samp>--hdf_unpack</samp>)
switch. 
Until and unless a method of automatically detecting the packing method 
is devised, it must remain the user&textrsquo;s responsibility to tell
<acronym><acronymword>NCO</acronymword></acronym> when to use the <acronym><acronymword>HDF</acronymword></acronym> convention instead of the
netCDF convention to unpack. 
</para>
<para>If your data originally came from an <acronym><acronymword>HDF</acronymword></acronym> file (e.g.,
<acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>EOS</acronymword></acronym>) then it was likely packed with the
<acronym><acronymword>HDF</acronymword></acronym> convention and must be unpacked with the same convention.
Our recommendation is to only request <acronym><acronymword>HDF</acronymword></acronym> unpacking when you 
are certain. 
Most packed datasets encountered by <acronym><acronymword>NCO</acronymword></acronym> will have used the
netCDF convention.
Those that were not will hopefully produce noticeably weird values when
unpacked by the wrong algorithm.
Before or after panicking, treat this as a clue to re-try your commands
with the <samp>--hdf_upk</samp> switch.
See <ref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></ref> for an easy technique
to unpack data packed with the <acronym><acronymword>HDF</acronymword></acronym> convention, and then
re-pack it with the netCDF convention.
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Handling of Packed Data by Other Operators</sectiontitle>
<para>All <acronym><acronymword>NCO</acronymword></acronym> arithmetic operators understand packed data.
The operators automatically unpack any packed variable in the input 
file which will be arithmetically processed.
For example, <command>ncra</command> unpacks all record variables, 
and <command>ncwa</command> unpacks all variable which contain a dimension to 
be averaged.
These variables are stored unpacked in the output file.
</para>
<para>On the other hand, arithmetic operators do not unpack non-processed
variables. 
For example, <command>ncra</command> leaves all non-record variables packed, 
and <command>ncwa</command> leaves packed all variables lacking an averaged
dimension.  
These variables (called fixed variables) are passed unaltered from the
input to the output file. 
Hence fixed variables which are packed in input files remain packed in
output files.
Completely packing and unpacking files is easily accomplished with
<command>ncpdq</command> (<pxref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></pxref>).
Pack and unpack individual variables with <command>ncpdq</command> and the
<command>ncap2</command> <command>pack()</command> and <command>unpack()</command> functions
(<pxref label="Methods-and-functions"><xrefnodename>Methods and functions</xrefnodename></pxref>).
</para>
<html endspaces=" ">
&lt;a name=&quot;op_typ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#op_typ --&gt;
</html>
</unnumberedsubsec>
</section>
<node name="Operation-Types" spaces=" "><nodename>Operation Types</nodename><nodenext spaces=" ">Type Conversion</nodenext><nodeprev spaces=" ">Packed data</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Operation Types</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1137">operation types</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1138"><code>avg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1139"><code>sqravg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1140"><code>avgsqr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1141"><code>min</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1142"><code>max</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1143"><code>mabs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1144"><code>mebs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1145"><code>mibs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1146"><code>rmssdn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1147"><code>rms</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1148"><code>tabs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1149"><code>ttl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1150"><code>sqrt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1151">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1152">mean</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1153">total</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1154">minimum</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1155">maximum</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1156">root-mean-square</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1157">standard deviation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1158">variance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1159"><code>-y <var>op_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1160"><code>--operation <var>op_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1161"><code>--op_typ <var>op_typ</var></code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncap2</command>, <command>ncra</command>, <command>nces</command>, <command>ncwa</command>&linebreak;
Short options: <samp>-y</samp>&linebreak;
Long options: <samp>--operation</samp>, <samp>--op_typ</samp>&linebreak;
</para></cartouche>
<noindent></noindent>
<para>The <samp>-y <var>op_typ</var></samp> switch allows specification of many different
types of operations 
Set <var>op_typ</var> to the abbreviated key for the corresponding operation:
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">avg</itemformat></item>
</tableterm><tableitem><para>Mean value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">sqravg</itemformat></item>
</tableterm><tableitem><para>Square of the mean
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">avgsqr</itemformat></item>
</tableterm><tableitem><para>Mean of sum of squares
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">max</itemformat></item>
</tableterm><tableitem><para>Maximum value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">min</itemformat></item>
</tableterm><tableitem><para>Minimum value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">mabs</itemformat></item>
</tableterm><tableitem><para>Maximum absolute value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">mebs</itemformat></item>
</tableterm><tableitem><para>Mean absolute value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">mibs</itemformat></item>
</tableterm><tableitem><para>Minimum absolute value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">rms</itemformat></item>
</tableterm><tableitem><para>Root-mean-square (normalized by <var>N</var>)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">rmssdn</itemformat></item>
</tableterm><tableitem><para>Root-mean square (normalized by <var>N-1</var>)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">sqrt</itemformat></item>
</tableterm><tableitem><para>Square root of the mean
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">tabs</itemformat></item>
</tableterm><tableitem><para>Sum of absolute values
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ttl</itemformat></item>
</tableterm><tableitem><para>Sum of values
</para></tableitem></tableentry></table>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1162">coordinate variable</indexterm></cindex> 
<para><acronym><acronymword>NCO</acronymword></acronym> assumes coordinate variables represent grid axes, e.g.,
longitude. 
The only rank-reduction which makes sense for coordinate variables
is averaging.
Hence <acronym><acronymword>NCO</acronymword></acronym> implements the operation type requested with
<samp>-y</samp> on all non-coordinate variables, not on coordinate variables.  
When an operation requires a coordinate variable to be reduced in
rank, i.e., from one dimension to a scalar or from one dimension to
a degenerate (single value) array, then <acronym><acronymword>NCO</acronymword></acronym> 
<emph>always averages</emph> the coordinate variable regardless of the
arithmetic operation type performed on the non-coordinate variables.
</para>
<para>The mathematical definition of each arithmetic operation is given below. 
<xref label="ncwa-netCDF-Weighted-Averager"><xrefnodename>ncwa netCDF Weighted Averager</xrefnodename></xref>, for additional information on
masks and normalization.
If an operation type is not specified with <samp>-y</samp> then the operator
performs an arithmetic average by default.
Averaging is described first so the terminology for the other operations
is familiar. 
</para>
<para><emph>Note for Info users</emph>: 
The definition of mathematical operations involving rank reduction
(e.g., averaging) relies heavily on mathematical expressions which
cannot be easily represented in Info.
<emph>See the <uref><urefurl>./nco.pdf</urefurl><urefdesc spaces=" ">printed manual</urefdesc></uref> for much more detailed and
complete documentation of this subject.</emph>
</para>
<tex endspaces=" ">
The masked, weighted average of a variable $\xxx$ can be generally
represented as
$$
\bar \xxx_{\jjj} = {\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} \xxx_{\idx} \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}}  
$$
where $\bar \xxx_{\jjj}$ is the $\jjj$'th element of the output
hyperslab, $\xxx_{\idx}$ is the $\idx$'th element of the input
hyperslab, $\mssflg_{\idx}$ is~1 unless $\xxx_{\idx}$ equals the missing  
value, $\mskflg_{\idx}$ is~1 unless $\xxx_{\idx}$ is masked, and
$\wgt_{\idx}$ is the weight.  
This formiddable formula represents a simple weighted average
whose bells and whistles are all explained below. 
It is not too early to note, however, that when 
$\mssflg_{\idx} = \mskflg_{\idx} = \wgt_{\idx} = 1$, the 
generic averaging expression above reduces to a simple arithmetic
average.  
Furthermore, $\mskflg_{\idx} = \wgt_{\idx} = 1$ for all operators
except @command{ncwa}.
These variables are included in the discussion below for completeness,
and for possible future use in other operators. 

The size $\outnbr$ of the output hyperslab for a given variable is the
product of all the dimensions of the input variable which are not
averaged over. 
The size $\lmnnbr$ of the input hyperslab contributing to each 
$\bar \xxx_{\jjj}$ is simply the product of the sizes of all dimensions
which are averaged over (i.e., dimensions specified with @samp{-a}).  
Thus $\lmnnbr$ is the number of input elements which @emph{potentially} 
contribute to each output element.
An input element $\xxx_{\idx}$ contributes to the output element
$\xxx_{\jjj}$ except in two conditions:  
@cindex missing values
@enumerate
@item $\xxx_{\idx}$ equals the @var{missing value} 
(@pxref{Missing Values}) for the variable. 
@item $\xxx_{\idx}$ is located at a point where the mask condition 
(@pxref{Mask condition}) is false.
@end enumerate
Points $\xxx_{\idx}$ in either of these two categories do not contribute 
to $\xxx_{\jjj}$---they are ignored.
We now define these criteria more rigorously.

Each~$\xxx_{\idx}$ has an associated Boolean weight~$\mssflg_{\idx}$
whose value is~0 or~1 (false or true). 
The value of~$\mssflg_{\idx}$ is~1 (true) unless $\xxx_{\idx}$ equals
the @var{missing value} (@pxref{Missing Values}) for the variable. 
Thus, for a variable with no @code{_FillValue} attribute,
$\mssflg_{\idx}$~is always~1.
All @acronym{NCO} arithmetic operators (@command{ncbo},
@command{ncra}, @command{nces}, @command{ncflint}, @command{ncwa}) treat  
missing values analogously. 

Besides (weighted) averaging, @command{ncwa}, @command{ncra}, and
@command{nces} also compute some common non-linear operations which may
be specified with the @samp{-y} switch (@pxref{Operation Types}).
The other rank-reducing operations are simple variations of the generic
weighted mean described above.
The total value of~$\xxx$ (@code{-y ttl}) is 
$$
\bar \xxx_{\jjj} = \sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} \xxx_{\idx}  
$$
@cindex @code{-N}
@cindex @code{numerator}
Note that the total is the same as the numerator of the mean
of~$\xxx$, and may also be obtained in @command{ncwa} by using the
@samp{-N} switch (@pxref{ncwa netCDF Weighted Averager}).

The minimum value of~$\xxx$ (@code{-y min}) is 
$$
\bar \xxx_{\jjj} = \min [ \mssflg_{1} \mskflg_{1} \wgt_{1} \xxx_{1},
\mssflg_{2} \mskflg_{2} \wgt_{2} \xxx_{2}, \ldots, \mssflg_{\lmnnbr} 
\mskflg_{\lmnnbr} \wgt_{\lmnnbr} \xxx_{\lmnnbr} ] 
$$
Analogously, the maximum value of~$\xxx$ (@code{-y max}) is 
$$
\bar \xxx_{\jjj} = \max [ \mssflg_{1} \mskflg_{1} \wgt_{1} \xxx_{1},
\mssflg_{2} \mskflg_{2} \wgt_{2} \xxx_{2}, \ldots, \mssflg_{\lmnnbr} 
\mskflg_{\lmnnbr} \wgt_{\lmnnbr} \xxx_{\lmnnbr} ] 
$$
Thus the minima and maxima are determined after any weights are applied.

The total absolute value of~$\xxx$ (@code{-y tabs}) is 
$$
\bar \xxx_{\jjj} = \sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} |\xxx_{\idx}|
$$

The minimum absolute value of~$\xxx$ (@code{-y mibs}) is 
$$
\bar \xxx_{\jjj} = \min [ \mssflg_{1} \mskflg_{1} \wgt_{1} |\xxx_{1}|,
\mssflg_{2} \mskflg_{2} \wgt_{2} |\xxx_{2}|, \ldots, \mssflg_{\lmnnbr} 
\mskflg_{\lmnnbr} \wgt_{\lmnnbr} |\xxx_{\lmnnbr}| ] 
$$
Analogously, the maximum absolute value of~$\xxx$ (@code{-y mabs}) is 
$$
\bar \xxx_{\jjj} = \max [ \mssflg_{1} \mskflg_{1} \wgt_{1} |\xxx_{1}|,
\mssflg_{2} \mskflg_{2} \wgt_{2} |\xxx_{2}|, \ldots, \mssflg_{\lmnnbr} 
\mskflg_{\lmnnbr} \wgt_{\lmnnbr} |\xxx_{\lmnnbr}| ] 
$$
Thus the minimum and maximum absolute values are determined after any weights are applied.
The mean absolute value of~$\xxx$ (@code{-y mebs}) is 
$$
\bar \xxx_{\jjj} = {\sum_{\idx=1}^{\idx=\lmnnbr}
\mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx} |\xxx_{\idx}| \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}} 
$$

The square of the mean value of~$\xxx$ (@code{-y sqravg}) is 
$$
\bar \xxx_{\jjj} = \left( {\sum_{\idx=1}^{\idx=\lmnnbr}
\mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx} \xxx_{\idx} \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}} 
\right)^{2}    
$$
The mean of the sum of squares of~$\xxx$ (@code{-y avgsqr}) is 
$$
\bar \xxx_{\jjj} = {\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} \xxx^{2}_{\idx} \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}} 
$$
If $\xxx$ represents a deviation from the mean of another variable,
$\xxx_{\idx} = \yyy_{\idx} - \bar{\yyy}$ (possibly created by
@command{ncbo} in a previous step), then applying @code{avgsqr} to
$\xxx$ computes the approximate variance of $\yyy$. 
Computing the true variance of~$\yyy$ requires subtracting~1 from the
denominator, discussed below.
For a large sample size however, the two results will be nearly
indistinguishable. 

The root mean square of~$\xxx$ (@code{-y rms}) is 
$$
\bar \xxx_{\jjj} = \sqrt{ {\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} x^{2}_{\idx} \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}}} 
$$
Thus @code{rms} simply computes the squareroot of the quantity computed
by @code{avgsqr}.

The root mean square of~$\xxx$ with standard-deviation-like
normalization (@code{-y rmssdn}) is implemented as follows.
When weights are not specified, this function is the same as the root
mean square of~$\xxx$ except one is subtracted from the sum in the
denominator 
$$
\bar \xxx_{\jjj} = \sqrt{ {\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} 
\mskflg_{\idx} x^{2}_{\idx} \over -1 + \sum_{\idx=1}^{\idx=\lmnnbr}
\mssflg_{\idx} \mskflg_{\idx}} } 
$$
If $\xxx$ represents the deviation from the mean of another variable, 
$\xxx_{\idx} = \yyy_{\idx} - \bar{\yyy}$, then applying @code{rmssdn} to
$\xxx$ computes the standard deviation of~$\yyy$.
In this case the $-1$ in the denominator compensates for the degree of
freedom already used in computing $\bar{\yyy}$ in the numerator.
Consult a statistics book for more details.

When weights are specified it is unclear how to compensate for this
extra degree of freedom.
Weighting the numerator and denominator of the above by $\wgt_{\idx}$
and subtracting one from the denominator is only appropriate when all
the weights are~1.0.
When the weights are arbitrary (e.g., Gaussian weights), subtracting one 
from the sum in the denominator does not necessarily remove one degree
of freedom. 
Therefore when @code{-y rmssdn} is requested and weights are specified,
@command{ncwa} actually implements the @code{rms} procedure.
@command{nces} and @command{ncra}, which do not allow weights to be
specified, always implement the @code{rmssdn} procedure when asked.

@ignore
20130827: Fedora Core 19 (FC19) broke here with &quot;./nco.texi:6394: Missing dollarsign inserted.&quot;
Ubuntu always built nco.texi fine
Adding a dollarsign character right here breaks Ubuntu builds too
Hence I must carefully spell-out the word dollarsign instead
20130829: Making many smaller TeX environments does not solve problem
20130910: Using latest texinfo.tex from GNU does not solve problem
20130910: Karl Berry solved problem by fixing bug in texinfo.tex
Bug was triggered in Fedora by apostrophe in &quot;User's Guide&quot; (manual title)
Bug not present in texinfo.tex version 2008-04-18.10 (used by Ubuntu 13.04)
Bug     present in texinfo.tex version 2013-02-01.11 (used by FC19)
Bug just fixed  in texinfo.tex version 2013-09-11 (committed by Karl)
nco/autobld/texinfo.tex now contains fixed version
Breakage always occurs near here
@end ignore
The square root of the mean of~$\xxx$ (@code{-y sqrt}) is 
$$
\bar \xxx_{\jjj} = \sqrt{ {\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx}
\mskflg_{\idx} \wgt_{\idx} \xxx_{\idx} \over
\sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} \wgt_{\idx}}}  
$$
</tex>
<para>The definitions of some of these operations are not universally useful.
Mostly they were chosen to facilitate standard statistical
computations within the <acronym><acronymword>NCO</acronymword></acronym> framework.
We are open to redefining and or adding to the above. 
If you are interested in having other statistical quantities
defined in <acronym><acronymword>NCO</acronymword></acronym> please contact the <acronym><acronymword>NCO</acronymword></acronym> project
(<pxref label="Help-Requests-and-Bug-Reports"><xrefnodename>Help Requests and Bug Reports</xrefnodename></pxref>).  
</para>
<noindent></noindent>
<para>EXAMPLES
</para>
<html endspaces=" ">
&lt;a name=&quot;mabs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mabs --&gt;
&lt;a name=&quot;mebs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mebs --&gt;
&lt;a name=&quot;mibs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mibs --&gt;
&lt;a name=&quot;min&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#min --&gt;
&lt;a name=&quot;max&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#max --&gt;
&lt;a name=&quot;rms&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rms --&gt;
</html>
<noindent></noindent>
<para>Suppose you wish to examine the variable <code>prs_sfc(time,lat,lon)</code> 
which contains a time series of the surface pressure as a function of
latitude and longitude.
Find the minimum value of <code>prs_sfc</code> over all dimensions:
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -y min -v prs_sfc in.nc foo.nc 
</pre></example>
<noindent></noindent>
<para>Find the maximum value of <code>prs_sfc</code> at each time interval for each
latitude: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -y max -v prs_sfc -a lon in.nc foo.nc
</pre></example>
<noindent></noindent>
<para>Find the root-mean-square value of the time-series of <code>prs_sfc</code> at
every gridpoint:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -y rms -v prs_sfc in.nc foo.nc
ncwa -y rms -v prs_sfc -a time in.nc foo.nc
</pre></example>
<noindent></noindent>
<para>The previous two commands give the same answer but <command>ncra</command> is
preferred because it has a smaller memory footprint.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1163">degenerate dimension</indexterm></cindex>
A dimension of size one is said to be <dfn>degenerate</dfn>.
By default, <command>ncra</command> leaves the (degenerate) <code>time</code>
dimension in the output file (which is usually useful) whereas
<command>ncwa</command> removes the <code>time</code> dimension (unless <samp>-b</samp> is
given).
</para>
<noindent></noindent>
<para>These operations work as expected in multi-file operators.
Suppose that <code>prs_sfc</code> is stored in multiple timesteps per file
across multiple files, say <file>jan.nc</file>, <file>feb.nc</file>,
<file>march.nc</file>.  
We can now find the three month maximum surface pressure at every point.
</para><example endspaces=" ">
<pre xml:space="preserve">nces -y max -v prs_sfc jan.nc feb.nc march.nc out.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;standard_deviation&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#standard_deviation --&gt;
&lt;a name=&quot;stddvn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#stddvn --&gt;
&lt;a name=&quot;sdn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sdn --&gt;
&lt;a name=&quot;sdv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sdv --&gt;
&lt;a name=&quot;xmp_sdn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_sdn --&gt;
</html>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1164">standard deviation</indexterm></cindex>
<para>It is possible to use a combination of these operations to compute
the variance and standard deviation of a field stored in a single file
or across multiple files.
The procedure to compute the temporal standard deviation of the surface
pressure at all points in a single file <file>in.nc</file> involves three
steps. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -O -v prs_sfc -a time in.nc out.nc
ncbo -O -v prs_sfc in.nc out.nc out.nc 
ncra -O -y rmssdn out.nc out.nc
</pre></example>
<para>First construct the temporal mean of <code>prs_sfc</code> in the file
<file>out.nc</file>.
Next overwrite <file>out.nc</file> with the anomaly (deviation from the mean).
Finally overwrite <file>out.nc</file> with the root-mean-square of itself. 
Note the use of <samp>-y rmssdn</samp> (rather than <samp>-y rms</samp>) in the
final step. 
This ensures the standard deviation is correctly normalized by one fewer
than the number of time samples.
The procedure to compute the variance is identical except for the use of 
<samp>-y avgsqr</samp> instead of <samp>-y rmssdn</samp> in the final step.
</para>
<para><command>ncap2</command> can also compute statistics like standard deviations.
Brute-force implementation of formulae is one option, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'prs_sfc_sdn=sqrt((prs_sfc-prs_sfc.avg($time)^2). \
      total($time)/($time.size-1))' in.nc out.nc
</pre></example>
<para>The operation may, of course, be broken into multiple steps in order  
to archive intermediate quantities, such as the time-anomalies
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'prs_sfc_anm=prs_sfc-prs_sfc.avg($time)' \
      -s 'prs_sfc_sdn=sqrt((prs_sfc_anm^2).total($time)/($time.size-1))' \
      in.nc out.nc
</pre></example>

<para><command>ncap2</command> supports intrinsic standard deviation functions
(<pxref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></pxref>) which simplify the above expression to
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'prs_sfc_sdn=(prs_sfc-prs_sfc.avg($time)).rmssdn($time)' in.nc out.nc
</pre></example>
<para>These instrinsic functions compute the answer quickly and concisely.
</para>
<para>The procedure to compute the spatial standard deviation of a field
in a single file <file>in.nc</file> involves three steps.
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -O -v prs_sfc,gw -a lat,lon -w gw in.nc out.nc
ncbo -O -v prs_sfc,gw in.nc out.nc out.nc
ncwa -O -y rmssdn -v prs_sfc -a lat,lon -w gw out.nc out.nc
</pre></example>
<para>First the spatially weighted (by <samp>-w gw</samp>) mean values
are written to the output file, as are the mean weights.
The initial output file is then overwritten with the gridpoint
deviations from the spatial mean.
It is important that the output file after the second line contain
the original, non-averaged weights.
This will be the case if the weights are named so that <acronym><acronymword>NCO</acronymword></acronym>
treats them like a coordinate (<pxref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></pxref>).
One such name is <code>gw</code>, and any variable whose name begins with
<code>msk_</code> (for &textldquo;mask&textrdquo;) or <code>wgt_</code> (for &textldquo;weight&textrdquo;) will likewise
be treated as a coordinate, and will be copied (not differenced)
straight from <file>in.nc</file> to <file>out.nc</file> in the second step.
When using weights to compute standard deviations one must remember to
include the weights in the initial output files so that they may be used
again in the final step. 
Finally the root-mean-square of the appropriately weighted spatial
deviations is taken.  
</para>
<para>No elegant <command>ncap2</command> solution exists to compute weighted standard
deviations.  
Those brave of heart may try to formulate one.
A general formula should allow weights to have fewer than and variables
to have more than the minimal spatial dimensions (latitude and
longitude). 
<ignore endspaces=" ">
@c Until 20151229 ncap2 example was FUBAR, and did not handle weights in denominator
@example
ncap2 -s 'prs_sfc_sdn=((gw*(prs_sfc-((gw*prs_sfc).ttl($lat,$lon)/gw.ttl($lat,$lon)))^2).ttl($lat,$lon)/ \ 
      gw.ttl()).sqrt()' in.nc out.nc
@end example
Note how the weight multiplies the variable prior to computing the
the anomalies and the standard deviation.
</ignore>
</para>
<para>The procedure to compute the standard deviation of a time-series across
multiple files involves one extra step since all the input must first be
collected into one file. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat -O -v tpt in.nc in.nc foo1.nc
ncwa -O -a time foo1.nc foo2.nc
ncbo -O -v tpt foo1.nc foo2.nc foo3.nc
ncra -O -y rmssdn foo3.nc out.nc
</pre></example>
<para>The first step assembles all the data into a single file.
Though this may consume a lot of temporary disk space, it is more or
less required by the <command>ncbo</command> operation in the third step.
</para>
<html endspaces=" ">
&lt;a name=&quot;typ_cnv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#typ_cnv --&gt;
</html>
</section>
<node name="Type-Conversion" spaces=" "><nodename>Type Conversion</nodename><nodenext spaces=" ">Batch Mode</nodenext><nodeprev spaces=" ">Operation Types</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Type Conversion</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1165">type conversion</indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability (automatic type conversion): <command>ncap2</command>, <command>ncbo</command>, <command>nces</command>,
<command>ncflint</command>, <command>ncra</command>, <command>ncwa</command>&linebreak; 
Short options: None (it&textrsquo;s <emph>automatic</emph>)&linebreak;
Availability (manual type conversion): <command>nces</command>, <command>ncra</command>, <command>ncwa</command>&linebreak; 
Short options: None&linebreak;
Long options: <samp>--dbl</samp>, <samp>--flt</samp>, <samp>--rth_dbl</samp>, <samp>--rth_flt</samp>&linebreak; 
</para></cartouche>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1166">promotion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1167">demotion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1168">automatic type conversion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1169">manual type conversion</indexterm></cindex>
<para>Type conversion refers to the casting or coercion of one fundamental or
atomic data type to another, e.g., converting <code>NC_SHORT</code> (two
bytes) to <code>NC_DOUBLE</code> (eight bytes).  
Type conversion always <dfn>promotes</dfn> or <dfn>demotes</dfn> the range and/or 
precision of the values a variable can hold.
Type conversion is automatic when the language carries out this
promotion according to an internal set of rules without explicit user 
intervention. 
In contrast, manual type conversion refers to explicit user commands to
change the type of a variable or attribute.
Most type conversion happens automatically, yet there are situations in
which manual type conversion is advantageous.
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Automatic type conversion</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Promoting Single-precision to Double</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Manual type conversion</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="Automatic-type-conversion" spaces=" "><nodename>Automatic type conversion</nodename><nodenext spaces=" ">Promoting Single-precision to Double</nodenext><nodeprev spaces=" ">Type Conversion</nodeprev><nodeup spaces=" ">Type Conversion</nodeup></node>
<subsection spaces=" "><sectiontitle>Automatic type conversion</sectiontitle>

<para>There are at least two reasons to avoid type conversions.
First, type conversions are expensive since they require creating
(temporary) buffers and casting each element of a variable from its 
storage type to some other type and then, often, converting it back.
Second, a dataset&textrsquo;s creator perhaps had a good reason for storing 
data as, say, <code>NC_FLOAT</code> rather than <code>NC_DOUBLE</code>.  
In a scientific framework there is no reason to store data with more
precision than the observations merit.
Normally this is single-precision, which guarantees 6&textndash;9 digits of
precision. 
Reasons to engage in type conversion include avoiding rounding 
errors and out-of-range limitations of less-precise types.
This is the case with most integers.
Thus <acronym><acronymword>NCO</acronymword></acronym> defaults to automatically promote integer types to
floating-point when performing lengthy arithmetic, yet <acronym><acronymword>NCO</acronymword></acronym>
defaults to not promoting single to double-precision floats.
</para>
<para>Before discussing the more subtle floating-point issues, we first
examine integer promotion. 
We will show how following parsimonious conversion rules dogmatically
can cause problems, and what <acronym><acronymword>NCO</acronymword></acronym> does about that. 
That said, there are situations in which implicit conversion of
single- to double-precision is also warranted.
Understanding the narrowness of these situations takes time, and we
hope the reader appreciates the following detailed discussion.
</para>
<para>Consider the average of the two <code>NC_SHORT</code>s <code>17000s</code> and
<code>17000s</code>.
A straightforward average without promotion results in garbage since the
intermediate value which holds their sum is also of type <code>NC_SHORT</code>
and thus overflows on (i.e., cannot represent) values greater than
32,767 
<footnote spaces="\n"><set name="flg" line=" flg"></set>
<tex endspaces=" ">
$32767 = 2^{15}-1$
@clear flg
</tex>
<para><math>32767 = 2^15-1</math>
<clear name="flg" line=" flg"></clear>
</para></footnote>.
There are valid reasons for expecting this operation to succeed and 
the <acronym><acronymword>NCO</acronymword></acronym> philosophy is to make operators do what you want, not
what is purest.
Thus, unlike C and Fortran, but like many other higher level interpreted
languages, <acronym><acronymword>NCO</acronymword></acronym> arithmetic operators will perform automatic type
conversion on integers when all the following conditions are met
<footnote><para>Operators began performing automatic type conversions before
arithmetic in <acronym><acronymword>NCO</acronymword></acronym> <w>version 1.2</w>, August, 2000. 
Previous versions never performed unnecessary type conversion for
arithmetic.</para></footnote>: 
</para><enumerate first="1" endspaces=" ">
<listitem> <para>The requested operation is arithmetic.
This is why type conversion is limited to the operators <command>ncap2</command>, 
<command>ncbo</command>, <command>nces</command>, <command>ncflint</command>, <command>ncra</command>, and
<command>ncwa</command>.   
</para></listitem><listitem> <para>The arithmetic operation could benefit from type conversion.
Operations that could benefit include averaging, summation, or any
&textldquo;hard&textrdquo; arithmetic that could overflow or underflow.  
Larger representable sums help avoid overflow, and more precision
helps to avoid underflow.
Type conversion does not benefit searching for minima and maxima
(<samp>-y min</samp>, or <samp>-y max</samp>).
</para></listitem><listitem> <para>The variable on disk is of type <code>NC_BYTE</code>, <code>NC_CHAR</code>,
<code>NC_SHORT</code>, or <code>NC_INT</code>.
Type <code>NC_DOUBLE</code> is not promoted because there is no type of
higher precision.
Conversion of type <code>NC_FLOAT</code> is discussed in detail below. 
When it occurs, it follows the same procedure (promotion then
arithmetic then demotion) as conversion of integer types.
</para></listitem></enumerate>

<para>When these criteria are all met, the operator promotes the variable in
question to type <code>NC_DOUBLE</code>, performs all the arithmetic
operations, casts the <code>NC_DOUBLE</code> type back to the original type,
and finally writes the result to disk. 
The result written to disk may not be what you expect, because of
incommensurate ranges represented by different types, and because of
(lack of) rounding.
First, continuing the above example, the average (e.g., <samp>-y avg</samp>)
of <code>17000s</code> and <code>17000s</code> is written to disk as <code>17000s</code>. 
The type conversion feature of <acronym><acronymword>NCO</acronymword></acronym> makes this possible since
the arithmetic and intermediate values are stored as <code>NC_DOUBLE</code>s,
i.e., <code>34000.0d</code> and only the final result must be represented
as an <code>NC_SHORT</code>.
Without the type conversion feature of <acronym><acronymword>NCO</acronymword></acronym>, the average would
have been garbage (albeit predictable garbage near <code>-15768s</code>). 
Similarly, the total (e.g., <samp>-y ttl</samp>) of <code>17000s</code> and
<code>17000s</code> written to disk is garbage (actually <code>-31536s</code>) since 
the final result (the true total) of <math>34000</math> is outside the range
of type <code>NC_SHORT</code>.  
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1170"><code>trunc()</code></indexterm></cindex>
<para>After arithmetic is computed in double-precision for promoted variables,
the intermediate double-precision values must be demoted to the
variables&textrsquo; original storage type (e.g., from <code>NC_DOUBLE</code> to
<code>NC_SHORT</code>). 
<acronym><acronymword>NCO</acronymword></acronym> has handled this demotion in three ways in its history.
Prior to October, 2011 (version 4.0.8), <acronym><acronymword>NCO</acronymword></acronym> employed the
<w>C library</w> truncate function, <code>trunc()</code>
<footnote spaces="\n"><cindex index="cp" spaces=" "><indexterm index="cp" number="1171">C language</indexterm></cindex>
<para>The actual type conversions with trunction were handled by intrinsic
type conversion, so the <code>trunc()</code> function was never explicitly
called, although the results would be the same if it were.</para></footnote>.
Truncation rounds <var>x</var> to the nearest integer not larger in absolute 
value.
For example, truncation rounds <code>1.0d</code>, <code>1.5d</code>, and
<code>1.8d</code> to the same value, <code>1s</code>. 
Clearly, truncation does not round floating-point numbers to the nearest
integer! 
Yet truncation is how the <w>C language</w> performs implicit conversion of 
real numbers to integers.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1172">Neil Davis</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> stopped using truncation for demotion when an alert user
(Neil Davis) informed us that this caused a small bias in the packing
algorithm employed by <command>ncpdq</command>.
This led to <acronym><acronymword>NCO</acronymword></acronym> adopting rounding functions for demotion.
Rounding functions eliminated the small bias in the packing algorithm.
</para>
<findex index="fn" spaces=" "><indexterm index="fn" number="12" mergedindex="cp"><code>lround()</code>.</indexterm></findex> 
<para>From February, 2012 through March, 2013 (versions 4.0.9&textndash;4.2.6),
<acronym><acronymword>NCO</acronymword></acronym> employed the <w>C library</w> family of rounding functions,
<code>lround()</code>. 
These functions round <var>x</var> to the nearest integer, halfway cases away
from zero.
The problem with <code>lround()</code> is that it always rounds real values
ending in <code>.5</code> away from zero.
This rounds, for example, <code>1.5d</code> and <code>2.5d</code> to <code>2s</code>
and <code>3s</code>, respectively.
</para>
<findex index="fn" spaces=" "><indexterm index="fn" number="13" mergedindex="cp"><code>lrint()</code>.</indexterm></findex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1173"><acronym><acronymword>IEEE</acronymword></acronym></indexterm></cindex>
<para>Since April, 2013 (version 4.3.0), <acronym><acronymword>NCO</acronymword></acronym> has employed the 
other <w>C library</w> family of rounding functions, <code>lrint()</code>. 
This algorithm rounds <var>x</var> to the nearest integer, using the current 
rounding direction.
Halfway cases are rounded to the nearest even integer.
This rounds, for example, both <code>1.5d</code> and <code>2.5d</code> to the same
value, <code>2s</code>, as recommended by the <acronym><acronymword>IEEE</acronymword></acronym>.
This rounding is symmetric: up half the time, down half the time.
This is the current and hopefully final demotion algorithm employed by  
<acronym><acronymword>NCO</acronymword></acronym>.
</para>
<para>Hence because of automatic conversion, <acronym><acronymword>NCO</acronymword></acronym> will compute the
average of <code>2s</code> and <code>3s</code> in double-precision arithmetic as 
<math>(<code>2.0d</code> + <code>3.0d</code>)/<code>2.0d</code>) = <code>2.5d</code></math>.
It then demotes this intermediate result back to <code>NC_SHORT</code> and
stores it on disk as  
<math><code>trunc(2.5d)</code> = <code>2s</code></math> (versions up to 4.0.8), 
<math><code>lround(2.5d)</code> = <code>3s</code></math> (versions 4.0.9&textndash;4.2.6), and
<math><code>lrint(2.5d)</code> = <code>2s</code></math> (versions 4.3.0 and later).
</para>
<html endspaces=" ">
&lt;a name=&quot;sp_dp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sp_dp --&gt;
&lt;a name=&quot;dbl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dbl --&gt;
</html>
</subsection>
<node name="Promoting-Single_002dprecision-to-Double" spaces=" "><nodename>Promoting Single-precision to Double</nodename><nodenext spaces=" ">Manual type conversion</nodenext><nodeprev spaces=" ">Automatic type conversion</nodeprev><nodeup spaces=" ">Type Conversion</nodeup></node>
<subsection spaces=" "><sectiontitle>Promoting Single-precision to Double</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1174">promotion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1175">implicit conversion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1176"><code>--dbl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1177"><code>--rth_dbl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1178"><code>--flt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1179"><code>--rth_flt</code></indexterm></cindex>
<para>Promotion of real numbers from single- to double-precision is
fundamental to scientific computing.
When it should occur depends on the precision of the inputs and the
number of operations.
Single-precision (four-byte) numbers contain about seven significant
figures, while double-precision contain about sixteen.
More, err, precisely, the <acronym><acronymword>IEEE</acronymword></acronym> single-precision representation
gives from <w>6 to 9</w> significant decimal digits precision
<footnote><para>According to Wikipedia&textrsquo;s summary of <acronym><acronymword>IEEE</acronymword></acronym> 
<w>standard 754</w>, &textldquo;If a decimal string with at most <w>6 significant</w> 
digits is converted to <w><acronym><acronymword>IEEE</acronymword></acronym> 754</w> single-precision and then
converted back to the same number of significant decimal, then the final
string should match the original; and if an <w><acronym><acronymword>IEEE</acronymword></acronym> 754</w>
single-precision is converted to a decimal string with at <w>leastn 9</w>
significant decimal and then converted back to single, then the final
number must match the original&textrdquo;.</para></footnote>. 
And the <acronym><acronymword>IEEE</acronymword></acronym> double-precision representation
gives from <w>15 to 17</w> significant decimal digits precision
<footnote><para>According to Wikipedia&textrsquo;s summary of <acronym><acronymword>IEEE</acronymword></acronym> 
<w>standard 754</w>, &textldquo;If a decimal string with at most <w>15 significant</w>
digits is converted to <w><acronym><acronymword>IEEE</acronymword></acronym> 754</w> double-precision
representation and then converted back to a string with the same number
of significant digits, then the final string should match the original;
and if an <w><acronym><acronymword>IEEE</acronymword></acronym> 754</w> double precision is converted to a
decimal string with at least <w>17 significant</w> digits and then
converted back to double, then the final number must match the
original&textrdquo;.</para></footnote>.  
Hence double-precision numbers represent about nine digits more
precision than single-precision numbers.
</para>
<para>Given these properties, there are at least two possible arithmetic
conventions for the treatment of real numbers:
<cindex index="cp" spaces=" "><indexterm index="cp" number="1180">C language</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1181">Fortran</indexterm></cindex>
</para><enumerate first="1" endspaces=" ">
<listitem> <para>Conservative, aka Fortran Convention
Automatic type conversion during arithmetic in the Fortran language is,
by default, performed only when necessary. 
All operands in an operation are converted to the most precise type
involved the operation before the arithmetic operation.
Expressions which involve only single-precision numbers are computed
entirely in single-precision.
Expressions involving mixed precision types are computed in the type
of higher precision.
<acronym><acronymword>NCO</acronymword></acronym> by default employs the Fortan Convention for promotion.
</para></listitem><listitem> <para>Aggressive, aka C Convention
The <w>C language</w> is by default much more aggressive (and thus
wasteful) than Fortran, and will always implicitly convert single- 
to double-precision numbers, even when there is no good reason.
All real-number standard <w>C library</w> functions are double-precision, 
and <w>C programmers</w> must take extra steps to only utilize single
precision arithmetic.
The high-level interpreted data analysis languages <acronym><acronymword>IDL</acronymword></acronym>,
Matlab, and <acronym><acronymword>NCL</acronymword></acronym> all adopt the <w>C Convention</w>.
</para></listitem></enumerate>

<para><acronym><acronymword>NCO</acronymword></acronym> does not automatically promote <code>NC_FLOAT</code> because, in
our judgement, the performance penalty of always doing so would outweigh
the potential benefits. 
The now-classic text &textldquo;Numerical Recipes <w>in C</w>&textrdquo; discusses this point
under the section &textldquo;Implicit Conversion of Float to Double&textrdquo;
<footnote><para>See <w>page 21</w> in Section 1.2 of the First edition for this
gem:
</para><quotation endspaces=" ">
<para>One does not need much experience in scientific computing to recognize
that the implicit conversion rules are, in fact, sheer madness!
In effect, they make it impossible to write efficient numerical
programs. 
</para></quotation>
</footnote>.
That said, such promotion is warranted in some circumstances.
</para>
<para>For example, rounding errors can accumulate to worrisome levels during
arithmetic performed on large arrays of single-precision floats. 
This use-case occurs often in geoscientific studies of climate where
thousands-to-millions of gridpoints may contribute to a single average.
If the inputs are all single-precision, then so should be the output.
However the intermediate results where running sums are accumulated may  
suffer from too much rounding or from underflow unless computed in
double-precision. 
</para>
<para>The order of operations matters to floating-point math even when the
analytic expressions are equal. 
Cautious users feel disquieted when results from equally valid analyses
differ in the final bits instead of agreeing bit-for-bit.
For example, averaging arrays in multiple stages produces different
answers than averaging them in one step. 
This is easily seen in the computation of ensemble averages by two
different methods.
The <acronym><acronymword>NCO</acronymword></acronym> test file <file>in.nc</file> contains single- and
double-precision representations of the same temperature timeseries as 
<code>tpt_flt</code> and <code>tpt_dbl</code>.  
Pretend each datapoint in this timeseries represents a monthly-mean
temperature. 
We will mimic the derivation of a fifteen-year ensemble-mean January
temperature by concatenating the input file five times, and then
averaging the datapoints representing January two different ways.
In <w>Method 1</w> we derive the 15-year ensemble January average in two 
steps, as the average of three five-year averages.
This method is naturally used when each input file contains multiple
years and multiple input files are needed
<footnote><para>For example, the <acronym><acronymword>CMIP5</acronymword></acronym> archive tends to distribute
monthly average timeseries in 50-year chunks.</para></footnote>.
In <w>Method 2</w> we obtain 15-year ensemble January average in a single
step, by averaging all 15 Januaries at one time:
</para><example endspaces=" ">
<pre xml:space="preserve"># tpt_flt and tpt_dbl are identical except for precision
ncks -C -v tpt_flt,tpt_dbl ~/nco/data/in.nc
# tpt_dbl = 273.1, 273.2, 273.3, 273.4, 273.5, 273.6, 273.7, 273.8, 273.9, 274
# tpt_flt = 273.1, 273.2, 273.3, 273.4, 273.5, 273.6, 273.7, 273.8, 273.9, 274
# Create file with five &quot;ten-month years&quot; (i.e., 50 timesteps) of temperature data
ncrcat -O -v tpt_flt,tpt_dbl -p ~/nco/data in.nc in.nc in.nc in.nc in.nc ~/foo.nc
# Average 1st five &quot;Januaries&quot; (elements 1, 11, 21, 31, 41)
ncra --flt -O -F -d time,1,,10 ~/foo.nc ~/foo_avg1.nc
# Average 2nd five &quot;Januaries&quot; (elements 2, 12, 22, 32, 42)
ncra --flt -O -F -d time,2,,10 ~/foo.nc ~/foo_avg2.nc
# Average 3rd five &quot;Januaries&quot; (elements 3, 13, 23, 33, 43)
ncra --flt -O -F -d time,3,,10 ~/foo.nc ~/foo_avg3.nc
# Method 1: Obtain ensemble January average by averaging the averages
ncra --flt -O ~/foo_avg1.nc ~/foo_avg2.nc ~/foo_avg3.nc ~/foo_avg_mth1.nc
# Method 2: Obtain ensemble January average by averaging the raw data
# Employ ncra's &quot;subcycle&quot; feature (http://nco.sf.net/nco.html#ssc)
ncra --flt -O -F -d time,1,,10,3 ~/foo.nc ~/foo_avg_mth2.nc
# Difference the two methods
ncbo -O ~/foo_avg_mth1.nc ~/foo_avg_mth2.nc ~/foo_avg_dff.nc
ncks ~/foo_avg_dff.nc
# tpt_dbl = 5.6843418860808e-14 ;
# tpt_flt = -3.051758e-05 ;
</pre></example>
<para>Although the two methods are arithmetically equivalent, they produce
slightly different answers due to the different order of operations.
Moreover, it appears at first glance that the single-precision
answers suffer from greater error than the double-precision answers.
In fact both precisions suffer from non-zero rounding errors.
The answers differ negligibly to machine precision, which is about 
seven significant figures for single precision floats (<code>tpt_flt</code>),
and sixteen significant figures for double precision (<code>tpt_dbl</code>).
The input precision determines the answer precision.
</para>
<para><acronym><acronymword>IEEE</acronymword></acronym> arithmetic guarantees that two methods will produce
bit-for-bit identical answers only if they compute the same operations
in the same order.  
Bit-for-bit identical answers may also occur by happenstance when 
rounding errors exactly compensate one another.
This is demonstrated by repeating the example above with the
<samp>--dbl</samp> (or <samp>--rth_dbl</samp> for clarity) option which forces
conversion of single-precision numbers to double-precision prior to
arithmetic. 
Now <command>ncra</command> will treat the first value of <code>tpt_flt</code>,
<code>273.1000f</code>, as <code>273.1000000000000d</code>. 
Arithmetic on <code>tpt_flt</code> then proceeds in double-precision until the
final answer, which is converted back to single-precision for final
storage. 
</para><example endspaces=" ">
<pre xml:space="preserve"># Average 1st five &quot;Januaries&quot; (elements 1, 11, 21, 31, 41)
ncra --dbl -O -F -d time,1,,10 ~/foo.nc ~/foo_avg1.nc
# Average 2nd five &quot;Januaries&quot; (elements 2, 12, 22, 32, 42)
ncra --dbl -O -F -d time,2,,10 ~/foo.nc ~/foo_avg2.nc
# Average 3rd five &quot;Januaries&quot; (elements 3, 13, 23, 33, 43)
ncra --dbl -O -F -d time,3,,10 ~/foo.nc ~/foo_avg3.nc
# Method 1: Obtain ensemble January average by averaging the averages
ncra --dbl -O ~/foo_avg1.nc ~/foo_avg2.nc ~/foo_avg3.nc ~/foo_avg_mth1.nc
# Method 2: Obtain ensemble January average by averaging the raw data
# Employ ncra's &quot;subcycle&quot; feature (http://nco.sf.net/nco.html#ssc)
ncra --dbl -O -F -d time,1,,10,3 ~/foo.nc ~/foo_avg_mth2.nc
# Difference the two methods
ncbo -O ~/foo_avg_mth1.nc ~/foo_avg_mth2.nc ~/foo_avg_dff.nc
# Show differences
ncks ~/foo_avg_dff.nc
# tpt_dbl = 5.6843418860808e-14 ;
# tpt_flt = 0 ;
</pre></example>
<para>The <samp>--dbl</samp> switch has no effect on the results computed from
double-precision inputs.
But now the two methods produce bit-for-bit identical results from the
single-precision inputs!
This is due to the happenstance of rounding along with the effects of 
the <samp>--dbl</samp> switch.
The <samp>--flt</samp> and <samp>--rth_flt</samp> switches are provided for
symmetry.
They enforce the traditional <acronym><acronymword>NCO</acronymword></acronym> and Fortran convention of
keeping single-precision arithmetic in single-precision unless a
double-precision number is explicitly involved.
</para>
<para>We have shown that forced promotion of single- to double-precision
prior to arithmetic has advantages and disadvantages. 
The primary disadvantages are speed and size. 
Double-precision arithmetic is 10&textndash;60% slower than, and requires
twice the memory of single-precision arithmetic. 
The primary advantage is that rounding errors in double-precision are 
much less likely to accumulate to values near the precision of the 
underlying geophysical variable. 
</para>
<para>For example, if we know temperature to five significant digits, then a
rounding error of 1-bit could affect the least precise digit of
temperature after 1,000&textndash;10,000 consecutive one-sided rounding
errors under the worst possible scenario.
Many geophysical grids have tens-of-thousands to millions of points
that must be summed prior to normalization to compute an average.
It is possible for single-precision rouding errors to accumulate and
degrade the precision in such situtations. 
Double-precision arithmetic mititgates this problem, so <samp>--dbl</samp>
would be warranted. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1182"><acronym><acronymword>TREFHT</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1183"><acronym><acronymword>CAM3</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1184"><acronym><acronymword>GCM</acronymword></acronym></indexterm></cindex>
<para>This can be seen with another example, averaging a global surface
temperature field with <command>ncwa</command>.
The input contains a single-precision global temperature field
(stored in <code>TREFHT</code>) produced by the <acronym><acronymword>CAM3</acronymword></acronym> general
circulation model (<acronym><acronymword>GCM</acronymword></acronym>) run and stored at <w>1.9 by 2.5</w>
degrees resolution. 
This requires <w>94 latitudes</w> and <w>144 longitudes</w>, or <math>13,824</math> 
total surface gridpoints, a typical GCM resolution in 2008&textndash;2013.
These input characteristics are provided only to show the context
to the interested reader, equivalent results would be found in 
statistics of any dataset of comparable size.
Models often represent Earth on a spherical grid where global averages 
must be created by weighting each gridcell by its latitude-dependent
weight (e.g., a Gaussian weight stored in <code>gw</code>), or by the
surface area of each contributing gridpoint (stored in <code>area</code>).
</para>
<para>Like many geophysical models and most <acronym><acronymword>GCM</acronymword></acronym>s, <acronym><acronymword>CAM3</acronymword></acronym>
runs completely in double-precision yet stores its archival output in
single-precision to save space.
In practice such models usually save multi-dimensional prognostic and
diagnostic fields (like <code>TREFHT(lat,lon)</code>) as single-precision,
while saving all one-dimensional coordinates and weights (here
<code>lat</code>, <code>lon</code>, and <code>gw(lon)</code>) as double-precision.  
The gridcell area <code>area(lat,lon)</code> is an extensive grid property
that should be, but often is not, stored as double-precision.
To obtain pure double-precision arithmetic <emph>and</emph> storage of the 
globla mean temperature, we first create and store double-precision
versions of the single-precision fields:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -O -s 'TREFHT_dbl=double(TREFHT);area_dbl=double(area)' in.nc in.nc
</pre></example>
<para>The single- and double-precision temperatures may each be averaged
globally using four permutations for the precision of the weight
and of the intermediate arithmetic representation:
</para><enumerate first="1" endspaces=" ">
<listitem> <para>Single-precision weight (<code>area</code>), single-precision arithmetic
</para></listitem><listitem> <para>Double-precision weight (<code>gw</code>),   single-precision arithmetic
</para></listitem><listitem> <para>Single-precision weight (<code>area</code>), double-precision arithmetic
</para></listitem><listitem> <para>Double-precision weight (<code>gw</code>),   double-precision arithmetic
</para></listitem></enumerate>
<example endspaces=" ">
<pre xml:space="preserve"># NB: Values below are printed with C-format %5.6f using
# ncks -H -C -s '%5.6f' -v TREFHT,TREFHT_dbl out.nc
# Single-precision weight (area), single-precision arithmetic
ncwa --flt -O -a lat,lon -w area in.nc out.nc
# TREFHT     = 289.246735 
# TREFHT_dbl = 289.239964
# Double-precision weight (gw),   single-precision arithmetic
ncwa --flt -O -a lat,lon -w gw   in.nc out.nc
# TREFHT     = 289.226135
# TREFHT_dbl = 289.239964
# Single-precision weight (area), double-precision arithmetic
ncwa --dbl -O -a lat,lon -w area in.nc out.nc
# TREFHT     = 289.239960
# TREFHT_dbl = 289.239964
# Double-precision weight (gw),   double-precision arithmetic
ncwa --dbl -O -a lat,lon -w gw   in.nc out.nc
# TREFHT     = 289.239960
# TREFHT_dbl = 289.239964
</pre></example>
<para>First note that the <code>TREFHT_dbl</code> average never changes because 
<code>TREFHT_dbl(lat,lon)</code> is double-precision in the input file.
As described above, <acronym><acronymword>NCO</acronymword></acronym> automatically converts all operands
involving to the highest precision involved in the operation.
So specifying <samp>--dbl</samp> is redundant for double-precision inputs.
</para>
<para>Second, the single-precision arithmetic averages of the single-precision
input <code>TREFHT</code> differ by <math>289.246735 - 289.226135 = 0.0206</math>
from eachother, and, more importantly, by as much as 
<math>289.239964 - 289.226135 = 0.013829</math> from the correct
(double-precision) answer.
These averages differ in the fifth digit, i.e., they agree only to four
significant figures!
Given that climate scientists are concerned about global temperature
variations of a tenth of a degree or less, this difference is large.
Global mean temperature changes significant to climate scientists are  
comparable in size to the numerical artifacts produced by the averaging
procedure.  
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1185">rounding</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1186">random walk</indexterm></cindex>
<para>Why are the single-precision numerical artifacts so large?
Each global average is the result of multiplying almost 15,000 elements
each by its weight, summing those, and then dividing by the summed 
weights.  
Thus about 50,000 single-precision floating-point operations caused
the loss of two to three significant digits of precision.
The net error of a series of independent rounding errors is a random
walk phenomena
<footnote spaces="\n"><cindex index="cp" spaces=" "><indexterm index="cp" number="1187">Michael Prather</indexterm></cindex>
<para>Thanks to <w>Michael J.</w> Prather for explaining this to me.</para></footnote>.
Successive rounding errors displace the answer further from the truth.
An ensemble of such averages will, on average, have no net bias.
In other words, the expectation value of a series of <acronym><acronymword>IEEE</acronymword></acronym>
rounding errors is zero.
And the error of any given sequence of rounding errors obeys, for large 
series, a Gaussian distribution centered on zero.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1188">mantissa</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1189">exponent</indexterm></cindex>
<para>Single-precision numbers use three of their four eight-bit bytes to
represent the mantissa so the smallest representable single-precision
mantissa is <math>\epsilon \equiv 2^{-23} = 1.19209 \times 10^{-7}</math>.
This <math>\epsilon</math> is the smallest <var>x</var> such that 
<math>1.0 + x \ne 1.0</math>.
This is the rounding error for non-exact precision-numbers.
Applying random walk theory to rounding, it can be shown that the
expected rounding error after <var>n</var> inexact operations is
<math>\sqrt{2n/\pi}</math> for <w>large <var>n</var></w>.
The expected (i.e., mean absolute) rounding error in our example with
<math>13,824</math> additions is about 
<math>\sqrt{2 \times 13824 / \pi} = 91.96</math>.
Hence, addition alone of about fifteen thousand single-precision floats
is expected to consume about two significant digits of precision.
This neglects the error due to the inner product (weights times values)
and normalization (division by tally) aspects of a weighted average.
The ratio of two numbers each containing a numerical bias can magnify
the size of the bias. 
In summary, a global mean number computed from about 15,000 gridpoints
each with weights can be expected to lose up to three significant digits.
Since single-precision starts with about seven significant digits, we
should not expect to retain more than four significant digits after
computing weighted averages in single-precision.
The above example with <code>TREFHT</code> shows the expected four digits of
agreement. 
<!-- c For example, 50,000 coin flips would lead to 25,500 or more ``heads'' -->
<!-- c only a small percentage of the time. -->
<!-- c P(k,n)= 50000_C_25500 p^k(1-p)^(n-k) -->
<!-- c P(25500,50000)= 50000_C_25500 (0.5)^(25500)(0.5)^(24500) -->
<!-- c P(>=25500,50000)= ? -->
<!-- c fxm: Use Gaussian distribution/Random Walk -->
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1190">beer</indexterm></cindex>
<para>The <acronym><acronymword>NCO</acronymword></acronym> results have been independently validated to the
extent possible in three other languages: 
<w>C</w>, Matlab, and <acronym><acronymword>NCL</acronymword></acronym>. 
C and <acronym><acronymword>NCO</acronymword></acronym> are the only languages that permit single-precision 
numbers to be treated with single precision arithmetic:
</para><example endspaces=" ">
<pre xml:space="preserve"># Double-precision weight (gw),   single-precision arithmetic (C)
ncwa_3528514.exe
# TREFHT     = 289.240112
# Double-precision weight (gw),   double-precision arithmetic (C)
# TREFHT     = 289.239964
# Single-precision weight (area), double-precision arithmetic (Matlab)
# TREFHT     = 289.239964
# Double-precision weight (gw),   double-precision arithmetic (Matlab)
# TREFHT     = 289.239964
# Single-precision weight (area), double-precision arithmetic (NCL)
ncl &lt; ncwa_3528514.ncl
# TREFHT     = 289.239960
# TREFHT_dbl = 289.239964
# Double-precision weight (gw),   double-precision arithmetic (NCL)
# TREFHT     = 289.239960
# TREFHT_dbl = 289.239964
</pre></example>
<para>All languages tested (C, Matlab, <acronym><acronymword>NCL</acronymword></acronym>, and <acronym><acronymword>NCO</acronymword></acronym>) agree
to machine precision with double-precision arithmetic.
Users are fortunate to have a variety of high quality software that 
liberates them from the drudgery of coding their own.
Many packages are free (as in beer)!
As shown above <acronym><acronymword>NCO</acronymword></acronym> permits one to shift to their
float-promotion preferences as desired. 
No other language allows this with a simple switch.
</para>
<para>To summarize, until version 4.3.6 (September, 2013), the default
arithmetic convention of <acronym><acronymword>NCO</acronymword></acronym> adhered to Fortran behavior,
and automatically promoted single-precision to double-precision in all 
mixed-precision expressions, and left-alone pure single-precision
expressions.  
This is faster and more memory efficient than other conventions.
However, pure single-precision arithmetic can lose too much precision
when used to condense (e.g., average) large arrays.
Statistics involving about <math>n = 10,000</math> single-precision inputs
will lose about <w>2&textndash;3</w> digits if not promoted to double-precision
prior to arithmetic. 
The loss scales with the squareroot <w>of <var>n</var></w>. 
For larger <var>n</var>, users should promote floats with the <samp>--dbl</samp> 
option if they want to preserve more than four significant digits in
their results. 
</para>
<para>The <samp>--dbl</samp> and <samp>--flt</samp> switches are only available with the
<acronym><acronymword>NCO</acronymword></acronym> arithmetic operators that could potentially perform more
than a few  single-precision floating-point operations per result.
These are <command>nces</command>, <command>ncra</command>, and <command>ncwa</command>.
Each is capable of thousands to millions or more operations per result. 
By contrast, the arithmetic operators <command>ncbo</command> and
<command>ncflint</command> perform at most one floating-point operation per
result. 
Providing the <samp>--dbl</samp> option for such trivial operations makes 
little sense, so the option is not currently made available.
</para>
<para>We are interested in users&textrsquo; opinions on these matters. 
The default behavior was changed from <samp>--flt</samp> to <samp>--dbl</samp>
with the release of <acronym><acronymword>NCO</acronymword></acronym> version 4.3.6 (October 2013).
We will change the default back to <samp>--flt</samp> if users prefer.
Or we could set a threshold (e.g., <math>n \ge 10000</math>) after which
single- to double-precision promotion is automatically invoked.
Or we could make the default promotion convention settable via an
environment variable (<acronym><acronymword>GSL</acronymword></acronym> does this a lot).
Please let us know what you think of the selected defaults and options.
</para>
</subsection>
<node name="Manual-type-conversion" spaces=" "><nodename>Manual type conversion</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Promoting Single-precision to Double</nodeprev><nodeup spaces=" ">Type Conversion</nodeup></node>
<subsection spaces=" "><sectiontitle>Manual type conversion</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1191"><command>ncap2</command></indexterm></cindex>
<para><command>ncap2</command> provides intrinsic functions for performing manual type
conversions.
This, for example, converts variable <code>tpt</code> to external type
<code>NC_SHORT</code> (a C-type <code>short</code>), and variable <code>prs</code> to
external type <code>NC_DOUBLE</code> (a C-type <code>double</code>). 
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'tpt=short(tpt);prs=double(prs)' in.nc out.nc
</pre></example>
<para>With ncap2 there also is the <code>convert()</code> method that takes an integer 
argument. For example the above statements become:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'tpt=tpt.convert(NC_SHORT);prs=prs.convert(NC_DOUBLE)' in.nc out.nc
</pre></example>
<para>Can also use <code>convert()</code> in combination with <code>type()</code> so to make variable 
<code>ilev_new</code> the same type as <code>ilev</code> just do:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'ilev_new=ilev_new.convert(ilev.type())' in.nc out.nc
</pre></example>


<para><xref label="ncap2-netCDF-Arithmetic-Processor"><xrefnodename>ncap2 netCDF Arithmetic Processor</xrefnodename></xref>, for more details.
</para>
<html endspaces=" ">
&lt;a name=&quot;ovr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ovr --&gt;
&lt;a name=&quot;-O&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-O --&gt;
</html>
</subsection>
</section>
<node name="Batch-Mode" spaces=" "><nodename>Batch Mode</nodename><nodenext spaces=" ">Global Attribute Addition</nodenext><nodeprev spaces=" ">Type Conversion</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Batch Mode</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1192">batch mode</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1193">overwriting files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1194">appending to files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1195">force overwrite</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1196">force append</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1197"><code>-O</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1198"><code>-A</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1199"><code>--overwrite</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1200"><code>--ovr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1201"><code>--apn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1202"><code>--append</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: <samp>-O</samp>, <samp>-A</samp>&linebreak;
Long options: <samp>--ovr</samp>, <samp>--overwrite</samp>, <samp>--apn</samp>, <samp>--append</samp>&linebreak;
</para></cartouche>
<para>If the <var>output-file</var> specified for a command is a pre-existing file,
then the operator will prompt the user whether to overwrite (erase) the
existing <var>output-file</var>, attempt to append to it, or abort the
operation. 
However, interactive questions reduce productivity when processing large
amounts of data.
Therefore <acronym><acronymword>NCO</acronymword></acronym> also implements two ways to override its own safety
features, the <samp>-O</samp> and <samp>-A</samp> switches.
Specifying <samp>-O</samp> tells the operator to overwrite any existing
<var>output-file</var> without prompting the user interactively.
Specifying <samp>-A</samp> tells the operator to attempt to append to any
existing <var>output-file</var> without prompting the user interactively.
These switches are useful in batch environments because they suppress
interactive keyboard input.
NB: As of 20120515, <command>ncap2</command> is unable to append to files that
already contain the appended dimensions. 
</para>
<html endspaces=" ">
&lt;a name=&quot;gaa&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gaa --&gt;
&lt;a name=&quot;glb&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#glb --&gt;
&lt;a name=&quot;glb_att_add&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#glb_att_add --&gt;
</html>
</section>
<node name="Global-Attribute-Addition" spaces=" "><nodename>Global Attribute Addition</nodename><nodenext spaces=" ">History Attribute</nodenext><nodeprev spaces=" ">Batch Mode</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Global Attribute Addition</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1203">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1204">attributes, global</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1205"><code>--gaa</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1206"><code>--glb <var>att_nm</var>=<var>att_val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1207"><code>--glb</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1208"><code>--glb_att_add</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1209"><command>ncatted</command></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: None&linebreak;
Long options: <samp>--glb</samp>, <samp>--gaa</samp>, <samp>--glb_att_add</samp>&linebreak;
<samp>--glb <var>att_nm</var>=<var>att_val</var></samp> (multiple invocations allowed)&linebreak;
</para></cartouche>
<para>All operators can add user-specified global attributes to output files.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.5.2 (July, 2015), <acronym><acronymword>NCO</acronymword></acronym> supports
multiple uses of the <samp>--glb</samp> (or equivalent <samp>--gaa</samp> or
<samp>--glb_att_add</samp>) switch.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1210">indicator option</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1211">multi-arguments</indexterm></cindex>
The option <samp>--gaa</samp> (and its long option equivalents such as
<samp>--glb_att_add</samp>) indicates the argument syntax will be
<var>key</var>=<var>val</var>. 
As such, <samp>--gaa</samp> and its synonyms are indicator options that accept
arguments supplied one-by-one like 
<samp>--gaa <var>key1</var>=<var>val1</var> --gaa <var>key2</var>=<var>val2</var></samp>, or
aggregated together in multi-argument format like
<samp>--gaa <var>key1</var>=<var>val1</var>#<var>key2</var>=<var>val2</var></samp>
(<pxref label="Multi_002darguments"><xrefnodename>Multi-arguments</xrefnodename></pxref>).
</para>
<para>The switch takes mandatory arguments 
<samp>--glb <var>att_nm</var>=<var>att_val</var></samp>   
where <var>att_nm</var> is the desired name of the global attribute to add, 
and <var>att_val</var> is its value.
Currently only text attributes are supported (recorded as type
<code>NC_CHAR</code>), and regular expressions are not allowed (unlike
<pxref label="ncatted-netCDF-Attribute-Editor"><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></pxref>).    
Attributes are added in &textldquo;Append&textrdquo; mode, meaning that values are
appended to pre-existing values, if any. 
Multiple invocations can simplify the annotation of output file at
creation (or modification) time:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncra --glb machine=${HOSTNAME} --glb created_by=${USER} in*.nc out.nc
</verbatim>
</example>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.2 (October, 2016), one may instead
combine the separate invocations into a single list of invocations
separated by colons:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncra --glb machine=${HOSTNAME}:created_by=${USER} in*.nc out.nc
</verbatim>
</example>
<para>The list may contain any number of key-value pairs.
Special care must be taken should a key or value contain a delimiter
(i.e., a colon) otherwise <command>NCO</command> will interpret the colon as
a delimiter and will attempt to create a new attribute.
To protect a colon from being interpreted as an argument delimiter,
precede it with a backslash.
</para>
<para>The global attribution addition feature helps to avoid the performance
penalty incurred by using <command>ncatted</command> separately to annotate large files. 
Should users emit a loud hue and cry, we will consider ading the
functionality of ncatted to the front-end of all operators, i.e.,
accepting valid <command>ncatted</command> arguments to modify attributes of any
type and to apply regular expressions.
</para>
<html endspaces=" ">
&lt;a name=&quot;hst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hst --&gt;
&lt;a name=&quot;history&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#history --&gt;
&lt;a name=&quot;-h&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-h --&gt;
</html>
</section>
<node name="History-Attribute" spaces=" "><nodename>History Attribute</nodename><nodenext spaces=" ">File List Attributes</nodenext><nodeprev spaces=" ">Global Attribute Addition</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>History Attribute</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1212"><code>history</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1213">timestamp</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1214">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1215">attributes, global</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1216"><code>-h</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1217"><code>--hst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1218"><code>--history</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: <samp>-h</samp>&linebreak;
Long options: <samp>--hst</samp>, <samp>--history</samp>&linebreak;
</para></cartouche>
<para>All operators automatically append a <code>history</code> global attribute to
any file they create or modify.
The <code>history</code> attribute consists of a timestamp and the full string
of the invocation command to the operator, e.g., <samp>Mon May 26 20:10:24
1997: ncks in.nc out.nc</samp>.
The full contents of an existing <code>history</code> attribute are copied
from the first <var>input-file</var> to the <var>output-file</var>.
The timestamps appear in reverse chronological order, with the most
recent timestamp appearing first in the <code>history</code> attribute.
Since <acronym><acronymword>NCO</acronymword></acronym> adheres to the <code>history</code> convention, the entire
data processing path of a given netCDF file may often be deduced from
examination of its <code>history</code> attribute. 
As of May, 2002, <acronym><acronymword>NCO</acronymword></acronym> is case-insensitive to the spelling
of the <code>history</code> attribute name.
Thus attributes named <code>History</code> or <code>HISTORY</code> (which are
non-standard and not recommended) will be treated as valid history
attributes. 
When more than one global attribute fits the case-insensitive search
for &textldquo;history&textrdquo;, the first one found is used.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1219"><command>ncatted</command></indexterm></cindex>
To avoid information overkill, all operators have an optional switch
(<samp>-h</samp>, <samp>--hst</samp>, or <samp>--history</samp>) to override
automatically appending the <code>history</code> attribute 
(<pxref label="ncatted-netCDF-Attribute-Editor"><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></pxref>).   
Note that the <samp>-h</samp> switch also turns off writing the
<code>nco_input_file_list</code>-attribute for multi-file operators
(<pxref label="File-List-Attributes"><xrefnodename>File List Attributes</xrefnodename></pxref>).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1220"><code>history_of_appended_files</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1221">provenance</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.5.0 (June, 2015), <acronym><acronymword>NCO</acronymword></acronym> 
supports its own convention to retain the <code>history</code>-attribute 
contents of all files that were appended to a file
<footnote><para>Note that before version 4.5.0, <acronym><acronymword>NCO</acronymword></acronym> could,
in append (<samp>-A</samp>) mode only, inadvertently overwrite the global
metadata (including  <code>history</code>) of the output file with that of the
input file. 
This is opposite the behavior most would want.</para></footnote>.
This convention stores those contents in the
<code>history_of_appended_files</code> attribute, which complements
the <code>history</code>-attribute to provide a more complete provenance.
These attributes may appear something like this in output:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
// global attributes:
:history = &quot;Thu Jun  4 14:19:04 2015: ncks -A /home/zender/foo3.nc /home/zender/tmp.nc\n&quot;,
  &quot;Thu Jun  4 14:19:04 2015: ncks -A /home/zender/foo2.nc /home/zender/tmp.nc\n&quot;,
  &quot;Thu Jun  4 14:19:04 2015: ncatted -O -a att1,global,o,c,global metadata only in foo1 /home/zender/foo1.nc\n&quot;,
  &quot;original history from the ur-file serving as the basis for subsequent appends.&quot; ;
:history_of_appended_files = &quot;Thu Jun  4 14:19:04 2015: Appended file \
  /home/zender/foo3.nc had following \&quot;history\&quot; attribute:\n&quot;,
  &quot;Thu Jun  4 14:19:04 2015: ncatted -O -a att2,global,o,c,global metadata only in foo3 /home/zender/foo3.nc\n&quot;,
  &quot;history from foo3 from which data was appended to foo1 after data from foo2 was appended\n&quot;,
  &quot;Thu Jun  4 14:19:04 2015: Appended file /home/zender/foo2.nc had following \&quot;history\&quot; attribute:\n&quot;,
  &quot;Thu Jun  4 14:19:04 2015: ncatted -O -a att2,global,o,c,global metadata only in foo2 /home/zender/foo2.nc\n&quot;,
  &quot;history of some totally different file foo2 from which data was appended to foo1 before foo3 was appended\n&quot;,
:att1 = &quot;global metadata only in foo1&quot; ;
</verbatim>
</example>
<para>Note that the <code>history_of_appended_files</code>-attribute is only
created, and will only exist, in a file that is, or descends from
a file that was, appended to.
The optional switch <samp>-h</samp> (or <samp>--hst</samp> or <samp>--history</samp>)  
also overrides automatically appending the
<code>history_of_appended_files</code> attribute.
</para>
<html endspaces=" ">
&lt;a name=&quot;fl_lst_in_att&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_lst_in_att --&gt;
</html>
</section>
<node name="File-List-Attributes" spaces=" "><nodename>File List Attributes</nodename><nodenext spaces=" ">CF Conventions</nodenext><nodeprev spaces=" ">History Attribute</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>File List Attributes</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1222"><code>nco_input_file_list</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1223"><code>nco_input_file_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1224"><code>stdin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1225">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1226">attributes, global</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1227"><code>-H</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1228"><code>--fl_lst_in</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1229"><code>--file_list</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All binary executables&linebreak;
Short options: <samp>-H</samp>&linebreak;
Long options: <samp>--fl_lst_in</samp>, <samp>--file_list</samp>&linebreak;
</para></cartouche>
<para>Many methods of specifying large numbers of input file names pass
these names via pipes, encodings, or argument transfer programs
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>).
When these methods are used, the input file list is not explicitly
passed on the command line.
This results in a loss of information since the <code>history</code>
attribute no longer contains the complete input information from which
the file was created.
</para>
<para><acronym><acronymword>NCO</acronymword></acronym> solves this dilemma by archiving an attribute that
contains the input file list.
When the input file list to an operator is specified via <code>stdin</code>,
the operator, by default, attaches two global attributes to any file(s)
they create or modify. 
The <code>nco_input_file_number</code> global attribute contains the number of
input files, and <code>nco_input_file_list</code> contains the file names,
specified as standard input to the multi-file operator. 
This information helps to verify that all input files the user thinks
were piped through <code>stdin</code> actually arrived.
Without the <code>nco_input_file_list</code> attribute, the information is lost
forever and the &textldquo;chain of evidence&textrdquo; would be broken.
</para>
<para>The <samp>-H</samp> switch overrides (turns off) the default behavior of
writing the input file list global attributes when input is from
<code>stdin</code>. 
The <samp>-h</samp> switch does this too, and turns off the <code>history</code>
attribute as well (<pxref label="History-Attribute"><xrefnodename>History Attribute</xrefnodename></pxref>).
Hence both switches allows space-conscious users to avoid storing what
may amount to many thousands of filenames in a metadata attribute.
</para>
<html endspaces=" ">
&lt;a name=&quot;CF&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#CF --&gt;
&lt;a name=&quot;cnv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv --&gt;
&lt;a name=&quot;cnv_ACME&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_ACME --&gt;
&lt;a name=&quot;ACME&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ACME --&gt;
&lt;a name=&quot;acme&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#acme --&gt;
&lt;a name=&quot;cnv_E3SM&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_E3SM --&gt;
&lt;a name=&quot;E3SM&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#E3SM --&gt;
&lt;a name=&quot;e3sm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#e3sm --&gt;
&lt;a name=&quot;cnv_CF&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF --&gt;
&lt;a name=&quot;cnv_CCSM&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CCSM --&gt;
</html>
</section>
<node name="CF-Conventions" spaces=" "><nodename>CF Conventions</nodename><nodenext spaces=" ">ARM Conventions</nodenext><nodeprev spaces=" ">File List Attributes</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle><acronym><acronymword>CF</acronymword></acronym> Conventions</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1230"><acronym><acronymword>ACME</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1231"><acronym><acronymword>E3SM</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1232"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1233"><acronym><acronymword>CCSM</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1234"><acronym><acronymword>MPAS</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1235">UDUnits</indexterm></cindex>
<!-- c CESM: -->
<cindex index="cp" spaces=" "><indexterm index="cp" number="1236"><code>ORO</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1237"><code>area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1238"><code>datesec</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1239"><code>date</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1240"><code>gw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1241"><code>hyai</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1242"><code>hyam</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1243"><code>hybi</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1244"><code>hybm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1245"><code>lat_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1246"><code>lon_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1247"><code>msk_*</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1248"><code>wgt_*</code></indexterm></cindex>
<!-- c MPAS: -->
<cindex index="cp" spaces=" "><indexterm index="cp" number="1249"><code>angleEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1250"><code>areaCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1251"><code>areaTriangle</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1252"><code>cellMask</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1253"><code>cellsOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1254"><code>cellsOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1255"><code>cellsOnVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1256"><code>dcEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1257"><code>dvEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1258"><code>edgesOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1259"><code>edgesOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1260"><code>edgesOnVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1261"><code>indexToCellID</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1262"><code>indexToEdgeID</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1263"><code>indexToVertexID</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1264"><code>kiteAreasOnVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1265"><code>latCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1266"><code>latEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1267"><code>latVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1268"><code>lonCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1269"><code>lonEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1270"><code>lonVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1271"><code>maxLevelCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1272"><code>meshDensity</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1273"><code>nEdgesOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1274"><code>nEdgesOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1275"><code>vertexMask</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1276"><code>verticesOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1277"><code>verticesOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1278"><code>weightsOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1279"><code>xCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1280"><code>xEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1281"><code>xVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1282"><code>yCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1283"><code>yEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1284"><code>yVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1285"><code>zCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1286"><code>zEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1287"><code>zVertex</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncbo</command>, <command>nces</command>, <command>ncecat</command>,
<command>ncflint</command>, <command>ncpdq</command>, <command>ncra</command>, <command>ncwa</command>&linebreak;
Short options: None&linebreak;
</para></cartouche>
<para><acronym><acronymword>NCO</acronymword></acronym> recognizes some Climate and Forecast (<acronym><acronymword>CF</acronymword></acronym>)
metadata conventions, and applies special rules to such data.
<acronym><acronymword>NCO</acronymword></acronym> was contemporaneous with <acronym><acronymword>COARDS</acronymword></acronym> and still
contains some rules to handle older model datasets that pre-date
<acronym><acronymword>CF</acronymword></acronym>, such as <acronym><acronymword>NCAR</acronymword></acronym> <acronym><acronymword>CCM</acronymword></acronym> and early
<acronym><acronymword>CCSM</acronymword></acronym> datasets.
Such datasets may not contain an explicit <code>Conventions</code> attribute
(e.g., <samp>CF-1.0</samp>). 
Nevertheless, we refer to all such metadata collectively as <acronym><acronymword>CF</acronymword></acronym>  
metadata. 
Skip this section if you never work with <acronym><acronymword>CF</acronymword></acronym> metadata.
</para>
<para>The latest <acronym><acronymword>CF</acronymword></acronym> netCDF conventions are described 
<uref><urefurl>http://cfconventions.org/1.10.html</urefurl><urefdesc spaces=" ">here</urefdesc></uref>. 
Most <acronym><acronymword>CF</acronymword></acronym> netCDF conventions are transparent to <acronym><acronymword>NCO</acronymword></acronym>.
There are no known pitfalls associated with using any <acronym><acronymword>NCO</acronymword></acronym>
operator on files adhering to these conventions.
<acronym><acronymword>NCO</acronymword></acronym> applies some rules that are not in <acronym><acronymword>CF</acronymword></acronym>, or
anywhere else, because experience shows that they simplify
data analysis, and stay true to the <acronym><acronymword>NCO</acronymword></acronym> mantra to do what 
users want.
</para>
<para>Here is a general sense of <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s <acronym><acronymword>CF</acronymword></acronym>-support: 
</para><itemize commandarg="bullet" spaces=" " endspaces=" "><itemprepend><formattingcommand command="bullet"/></itemprepend>
<listitem><prepend>&bullet;</prepend> <para>Understand and implement <acronym><acronymword>NUG</acronymword></acronym> recommendations such
as the history attribute, packing conventions, and attention to units. 
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Special handling of variables designated as coordinates, bounds,
or ancillary variables, so that users subsetting a certain variable
automatically obtain all related variables.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Special handling and prevention of meaningless operations 
(e.g., the root-mean-square of latitude) so that coordinates and bounds
preserve meaningful information even as normal (non-coordinate) fields
are statistically transformed.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Understand units and certain calendars so that hyperslabs
may be specified in physical units, and so that user needs not manually
decode per-file time specifications.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Understand auxiliary coordinates so that irregular hyperslabs may
be specified on complex geometric grids.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Check for CF-compliance on netCDF3 and netCDF4 and <acronym><acronymword>HDF</acronymword></acronym>
files. 
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Convert netCDF4 and <acronym><acronymword>HDF</acronymword></acronym> files to netCDF3 for strict
<acronym><acronymword>CF</acronymword></acronym>-compliance. 
</para></listitem></itemize>
<para>Finally, a main use of <acronym><acronymword>NCO</acronymword></acronym> is to &textldquo;produce <acronym><acronymword>CF</acronymword></acronym>&textrdquo;, 
i.e., to improve <acronym><acronymword>CF</acronymword></acronym>-compliance by annotating metadata,
renaming objects (attributes, variables, and dimensions), permuting and
inverting dimensions, recomputing values, and data compression.
</para>
<html endspaces=" ">
&lt;a name=&quot;prc_xcp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prc_xcp --&gt;
</html>
<para>Currently, <acronym><acronymword>NCO</acronymword></acronym> determines whether a datafile is a
<acronym><acronymword>CF</acronymword></acronym> output datafile simply by checking (case-insensitively)
whether the value of the global attribute <code>Conventions</code> (if any)
equals <samp>CF-1.0</samp> or <samp>NCAR-CSM</samp> 
Should <code>Conventions</code> equal either of these in the (first)
<var>input-file</var>, <acronym><acronymword>NCO</acronymword></acronym> will apply special rules to certain
variables because of their usual meaning in <acronym><acronymword>CF</acronymword></acronym> files. 
<acronym><acronymword>NCO</acronymword></acronym> will not average the following variables often found in
<acronym><acronymword>CF</acronymword></acronym> files: 
<code>ntrm</code>, <code>ntrn</code>, <code>ntrk</code>, <code>ndbase</code>, <code>nsbase</code>,
<code>nbdate</code>, <code>nbsec</code>, <code>mdt</code>, <code>mhisf</code>.
These variables contain scalar metadata such as the resolution of the
host geophysical model and it makes no sense to change their values.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1288">non-coordinate grid properties</indexterm></cindex>
<para>Furthermore, the <dfn>size and rank-preserving arithmetic operators</dfn> try
not to operate on certain grid properties.
These operators are <command>ncap2</command>, <command>ncbo</command>, <command>nces</command>,
<command>ncflint</command>, and <command>ncpdq</command> (when used for packing, not for
permutation).  
These operators do not operate, by default, on (i.e., add, subtract,
pack, etc.) the following variables:   
<code>ORO</code>, 
<code>area</code>, 
<code>datesec</code>, 
<code>date</code>, 
<code>gw</code>, 
<code>hyai</code>, 
<code>hyam</code>,
<code>hybi</code>. 
<code>hybm</code>, 
<code>lat_bnds</code>, 
<code>lon_bnds</code>,
<code>msk_*</code>, and
<code>wgt_*</code>.
These variables represent Gaussian weights, land/sea masks,
time fields, hybrid pressure coefficients, and latititude/longitude
boundaries.
We call these fields non-coordinate <dfn>grid properties</dfn>.
Coordinate grid properties are easy to identify because they are 
coordinate variables such as <code>latitude</code> and <code>longitude</code>.
</para>
<para>Users usually want <emph>all</emph> grid properties to remain unaltered in the 
output file. 
To be treated as a grid property, the variable name must <emph>exactly</emph>
match a name in the above list, or be a coordinate variable. 
Handling of <code>msk_*</code> and <code>wgt_*</code> is exceptional in that
<emph>any</emph> variable whose name starts with <code>msk_</code> or <code>wgt_</code> 
is considered to be a &textldquo;mask&textrdquo; or a &textldquo;weight&textrdquo; and is thus preserved
(not operated on when arithmetic can be avoided). 
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.7.7 (September, 2018), <acronym><acronymword>NCO</acronymword></acronym> began
to explicitly identify files adhering to the <acronym><acronymword>MPAS</acronymword></acronym> convention.
These files have a global attribute <code>Conventions</code> attribute that
contains the string or <samp>MPAS</samp>.
Size and rank-preserving arithmetic operators will not operate on these
<acronym><acronymword>MPAS</acronymword></acronym> non-coordinate grid properties:
<code>angleEdge</code>, 
<code>areaCell</code>, 
<code>areaTriangle</code>, 
<code>cellMask</code>, 
<code>cellsOnCell</code>, 
<code>cellsOnEdge</code>, 
<code>cellsOnVertex</code>, 
<code>dcEdge</code>, 
<code>dvEdge</code>, 
<code>edgesOnCell</code>, 
<code>edgesOnEdge</code>, 
<code>edgesOnVertex</code>, 
<code>indexToCellID</code>, 
<code>indexToEdgeID</code>, 
<code>indexToVertexID</code>, 
<code>kiteAreasOnVertex</code>, 
<code>latCell</code>, 
<code>latEdge</code>, 
<code>latVertex</code>, 
<code>lonCell</code>, 
<code>lonEdge</code>, 
<code>lonVertex</code>, 
<code>maxLevelCell</code>, 
<code>meshDensity</code>, 
<code>nEdgesOnCell</code>, 
<code>nEdgesOnEdge</code>, 
<code>vertexMask</code>, 
<code>verticesOnCell</code>, 
<code>verticesOnEdge</code>, 
<code>weightsOnEdge</code>, 
<code>xCell</code>, 
<code>xEdge</code>, 
<code>xVertex</code>, 
<code>yCell</code>, 
<code>yEdge</code>, 
<code>yVertex</code>, 
<code>zCell</code>, 
<code>zEdge</code>, and
<code>zVertex</code>.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.5.0 (June, 2015), <acronym><acronymword>NCO</acronymword></acronym> began
to support behavior required for the <acronym><acronymword>DOE</acronymword></acronym> <acronym><acronymword>E3SM/ACME</acronymword></acronym>
program, and we refer to these rules collectively as the <acronym><acronymword>E3SM/ACME</acronymword></acronym> 
convention. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1289"><acronym><acronymword>GMT</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1290"><code>date_written</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1291"><code>time_written</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1292"><code>gmtime()</code></indexterm></cindex>
The first <acronym><acronymword>E3SM/ACME</acronymword></acronym> rule implemented is that the contents of
<var>input-file</var> variables named <code>date_written</code> and
<code>time_written</code>, if any, will be updated to the current 
system-supplied (with <code>gmtime()</code>) <acronym><acronymword>GMT</acronymword></acronym>-time as the
variables are copied to the <var>output-file</var>.
</para>
<para>You must spoof <acronym><acronymword>NCO</acronymword></acronym> if you would like any grid properties
or other special <acronym><acronymword>CF</acronymword></acronym> fields processed normally.
For example rename the variables first with <command>ncrename</command>, 
or alter the <code>Conventions</code> attribute.
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_bnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_bnd --&gt;
&lt;a name=&quot;bnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bnd --&gt;
&lt;a name=&quot;bounds&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bounds --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1293"><code>bounds</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1294">bounds convention</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.8 (April, 2011), <acronym><acronymword>NCO</acronymword></acronym> 
supports the <acronym><acronymword>CF</acronymword></acronym> <code>bounds</code> convention for cell boundaries 
described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#cell-boundaries</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
This convention allows coordinate variables (including multidimensional
coordinates) to describe the boundaries of their cells.
This is done by naming the variable which contains the bounds in
in the <code>bounds</code> attribute. 
Note that coordinates of rank <math>N</math> have bounds of rank <math>N+1</math>.
NCO-generated subsets of <acronym><acronymword>CF</acronymword></acronym>-compliant files with <code>bounds</code>
attributes will include the coordinates specified by the <code>bounds</code>
attribute, if any.  
Hence the subsets will themselves be <acronym><acronymword>CF</acronymword></acronym>-compliant.
Bounds are subject to the user-specified override switches
(including <samp>-c</samp> and <samp>-C</samp>) described in 
<ref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></ref>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1295"><code>lev</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1296"><code>ilev</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1297"><code>hyai</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1298"><code>hybi</code></indexterm></cindex>
<para>The <acronym><acronymword>CAM</acronymword></acronym>/<acronym><acronymword>EAM</acronymword></acronym> family of atmospheric models does not
output a <code>bounds</code> variable or attribute corresponding to the
<code>lev</code> coordinate.
This prevents <acronym><acronymword>NCO</acronymword></acronym> from activating its <acronym><acronymword>CF</acronymword></acronym> bounds
machinery when <code>lev</code> is extracted.
As of version 4.7.7 (September, 2018), <acronym><acronymword>NCO</acronymword></acronym> works around this
by outputting the <code>ilev</code> coordinate (and <code>hyai</code>, <code>hybi</code>)
whenever the <code>lev</code> coordinate is also output. 
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_clm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_clm --&gt;
&lt;a name=&quot;clm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm --&gt;
&lt;a name=&quot;climatology&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#climatology --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1299"><code>climatology</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1300">climatology convention</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.9 (May, 2015), <acronym><acronymword>NCO</acronymword></acronym> 
supports the <acronym><acronymword>CF</acronymword></acronym> <code>climatology</code> convention for climatological 
statistics described 
<uref><urefurl>http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/build/cf-conventions.html#climatological-statistics</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
This convention allows coordinate variables (including multidimensional
coordinates) to describe the (possibly nested) periods and statistical
methods of their associated statistics.
This is done by naming the variable which contains the periods and
methods in the <code>climatology</code> attribute. 
Note that coordinates of rank <math>N</math> have climatology bounds of rank 
<math>N+1</math>. 
NCO-generated subsets of <acronym><acronymword>CF</acronymword></acronym>-compliant files with <code>climatology</code>
attributes will include the variables specified by the <code>climatology</code>
attribute, if any.  
Hence the subsets will themselves be <acronym><acronymword>CF</acronymword></acronym>-compliant.
Climatology variables are subject to the user-specified override switches 
(including <samp>-c</samp> and <samp>-C</samp>) described in 
<ref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></ref>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_ncl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_ncl --&gt;
&lt;a name=&quot;ncl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncl --&gt;
&lt;a name=&quot;ancillary&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ancillary --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1301"><code>ancillary_variables</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1302">ancillary variables convention</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.5 (July, 2014), <acronym><acronymword>NCO</acronymword></acronym> 
supports the <acronym><acronymword>CF</acronymword></acronym> <code>ancillary_variables</code> convention for 
described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#ancillary-data</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
This convention allows ancillary variables to be associated with one or
more primary variables.
<acronym><acronymword>NCO</acronymword></acronym> attaches any such variables to the extraction list along 
with the primary variable and its usual (one-dimensional) coordinates,
if any. 
Ancillary variables are subject to the user-specified override switches 
(including <samp>-c</samp> and <samp>-C</samp>) described in 
<ref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></ref>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_cll_msr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_cll_msr --&gt;
&lt;a name=&quot;cll_msr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cll_msr --&gt;
&lt;a name=&quot;cell_measures&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cell_measures --&gt;
&lt;a name=&quot;no_cll_msr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_cll_msr --&gt;
&lt;a name=&quot;no_cell_measures&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_cell_measures --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1303"><code>cell_measures</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1304">cell measures convention</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.4 (January, 2017), <acronym><acronymword>NCO</acronymword></acronym> 
supports the <acronym><acronymword>CF</acronymword></acronym> <code>cell_measures</code> convention 
described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#cell-measures</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
This convention allows variables to indicate which other variable or
variables contains area or volume information about a gridcell.
These measures variables are pointed to by the <code>cell_measures</code>
attribute.
The <acronym><acronymword>CDL</acronymword></acronym> specification of a measures variable for area looks
like 
</para><example endspaces=" ">
<pre xml:space="preserve">orog:cell_measures = &quot;area: areacella&quot;
</pre></example>
<para>where <code>areacella</code> is the name of the measures variable.
Unless the default behavior is overridden, <acronym><acronymword>NCO</acronymword></acronym> attaches any
measures variables to the extraction list along with the primary
variable and other associated variables. 
By definition, measures variables are a subset of the rank of the
variable they measure.
The most common case is that the measures variable for area is the same
size as <w>2D fields</w> (like surface air temperature) and much smaller
than <w>3D fields</w> (like full air temperature). 
In such cases the measures variable might occupy 50% of the space of a
dataset consisting of only one <w>2D field</w>.
Extraction of measures variables is subject to the user-specified
override switches (including <samp>-c</samp> and <samp>-C</samp>) described in  
<ref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></ref>. 
To conserve space without sacrificing too much metadata, <acronym><acronymword>NCO</acronymword></acronym>
makes it possible to override the extraction of measures variables
independent of extracting other associated variables.
Override the default with <samp>--no_cell_measures</samp> or
<samp>--no_cll_msr</samp>. 
These options are available in all operators that perform subsetting
(i.e., all operators except <command>ncatted</command> and <command>ncrename</command>).
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_frm_trm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_frm_trm --&gt;
&lt;a name=&quot;frm_trm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#frm_trm --&gt;
&lt;a name=&quot;formula_terms&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#formula_terms --&gt;
&lt;a name=&quot;no_frm_trm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_frm_trm --&gt;
&lt;a name=&quot;no_formula_terms&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_formula_terms --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1305"><code>formula_terms</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1306">cell measures convention</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.4 (January, 2017), <acronym><acronymword>NCO</acronymword></acronym> 
supports the <acronym><acronymword>CF</acronymword></acronym> <code>formula_terms</code> convention 
described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#formula-terms</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
This convention encodes formulas used to construct (usually vertical)
coordinate grids.
The <acronym><acronymword>CDL</acronymword></acronym> specification of a vertical coordinate formula for
looks like 
</para><example endspaces=" ">
<pre xml:space="preserve">lev:standard_name = &quot;atmosphere_hybrid_sigma_pressure_coordinate&quot;
lev:formula_terms = &quot;a: hyam b: hybm p0: P0 ps: PS&quot;
</pre></example>
<para>where <code>standard_name</code> contains the standardized name of the
formula variable and <code>formula_terms</code> contains a list of the
variables used, called formula variables.
Above the formula variables are <code>hyam</code>, <code>hybm</code>, <code>P0</code>, and
<code>PS</code>. 
Unless the default behavior is overridden, <acronym><acronymword>NCO</acronymword></acronym> attaches any 
formula variables to the extraction list along with the primary
variable and other associated variables. 
By definition, formula variables are a subset of the rank of the
variable they define.
One common case is that the formula variables for constructing a 
<w>3D height</w> grid involves a 2D variable (like surface pressure,
or elevation).
In such cases the formula variables typically constitute only a 
small fraction of a dataset consisting of one <w>3D field</w>.
Extraction of formula variables is subject to the user-specified
override switches (including <samp>-c</samp> and <samp>-C</samp>) described in  
<ref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></ref>. 
To conserve space without sacrificing too much metadata, <acronym><acronymword>NCO</acronymword></acronym>
makes it possible to override the extraction of formula variables
independent of extracting other associated variables.
Override the default with <samp>--no_formula_terms</samp> or
<samp>--no_frm_trm</samp>. 
These options are available in all operators that perform subsetting
(i.e., all operators except <command>ncatted</command> and <command>ncrename</command>).
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_grd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_grd --&gt;
&lt;a name=&quot;grd_map&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grd_map --&gt;
&lt;a name=&quot;grid_mapping&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grid_mapping --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1307"><code>grid_mapping</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1308">ancillary variables convention</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.0 (May, 2016), <acronym><acronymword>NCO</acronymword></acronym> 
supports the <acronym><acronymword>CF</acronymword></acronym> <code>grid_mapping</code> convention for 
described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#grid-mappings-and-projections</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
This convention allows descriptions of map-projections to be associated    
with variables.
<acronym><acronymword>NCO</acronymword></acronym> attaches any such map-projection variables to the
extraction list along with the primary variable and its usual
(one-dimensional) coordinates, if any. 
Map-projection variables are subject to the user-specified override
switches (including <samp>-c</samp> and <samp>-C</samp>) described in 
<ref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></ref>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_crd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_crd --&gt;
&lt;a name=&quot;coordinates&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#coordinates --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1309"><code>coordinates</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1310">coordinates convention</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1311">coordinate variable</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1312">auxiliary coordinates</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1313">subsetting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1314"><code>-C</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1315"><code>-c</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1316"><code>--no_coords</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1317"><code>--no_crd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1318"><code>--coords</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1319"><code>--crd</code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 3.9.6 (January, 2009), <acronym><acronymword>NCO</acronymword></acronym>
supports the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code> convention described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#coordinate-system</urefurl><urefdesc spaces=" ">here</urefdesc></uref>. 
This convention allows variables to specify additional coordinates
(including mult-idimensional coordinates) in a space-separated string 
attribute named <code>coordinates</code>. 
<acronym><acronymword>NCO</acronymword></acronym> attaches any such coordinates to the extraction list along
with the variable and its usual (one-dimensional) coordinates, if any. 
These auxiliary coordinates are subject to the user-specified override
switches (including <samp>-c</samp> and <samp>-C</samp>) described in 
<ref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></ref>. 
</para>
<para>Elimination of reduced dimensions from the <code>coordinates</code> attribute
helps ensure that rank-reduced variables become completely independent
from their former dimensions.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.9 (May, 2015), <acronym><acronymword>NCO</acronymword></acronym>
may modify the <code>coordinates</code> attribute to assist this.
In particular, <command>ncwa</command> eliminates from the <code>coordinates</code>
attribute any dimension that it collapses, e.g., by averaging.
The former presence of this dimension will usually be indicated by the 
<acronym><acronymword>CF</acronymword></acronym> <code>cell_methods</code> convention described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#cell-methods</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
Hence the <acronym><acronymword>CF</acronymword></acronym> <code>cell_methods</code> and <code>coordinates</code> 
conventions can be said to work in tandem to characterize the state and
history of a variable&textrsquo;s analysis.
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_CF_cll_mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_CF_cll_mth --&gt;
&lt;a name=&quot;cll_mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cll_mth --&gt;
&lt;a name=&quot;cell_methods&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cell_methods --&gt;
&lt;a name=&quot;no_cll_mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_cll_mth --&gt;
&lt;a name=&quot;no_cell_methods&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_cell_methods --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1320"><code>cell_methods</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1321"><code>--cll_mth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1322"><code>--no_cll_mth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1323"><code>--cell_methods</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1324"><code>--no_cell_methods</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1325">cell methods convention</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.2 (February, 2014), <acronym><acronymword>NCO</acronymword></acronym> 
supports some of the <acronym><acronymword>CF</acronymword></acronym> <code>cell_methods</code> 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#cell-methods</urefurl><urefdesc spaces=" ">convention</urefdesc></uref>
to describe the analysis procedures that have been applied to data.
The convention creates (or appends to an existing) <code>cell_methods</code>
attribute a space-separated list of couplets of the form <var>dmn: op</var>
where <var>dmn</var> is a comma-separated list of dimensions previously
contained in the variable that have been reduced by the arithmetic
operation <var>op</var>.
For example, the <code>cell_methods</code> value <code>time: mean</code> says that
the variable in question was averaged over the <code>time</code> dimension.
In such cases <code>time</code> will either be a scalar variable or a
degenerate dimension or coordinate. 
This simply means that it has been averaged-over.
The value <code>time, lon: mean lat: max</code> says that the variable in
question is the maximum zonal mean of the time averaged original
variable.
Which is to say that the variable was first averaged over time and
longitude, and then the residual latitudinal array was reduced by
choosing the maximum value.
Since the <code>cell methods</code> convention may alter metadata in an
undesirable (or possibly incorrect) fashion, we provide switches
to ensure it is always or never used.
Use long-options <samp>--cll_mth</samp> or <samp>--cell_methods</samp> to invoke the
algorithm (true by default), and options <samp>--no_cll_mth</samp> or 
<samp>--no_cell_methods</samp> to turn it off.
These options are only available in the operators <command>ncwa</command> and
<command>ncra</command>.
</para>
<html endspaces=" ">
&lt;a name=&quot;cnv_ARM&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnv_ARM --&gt;
&lt;a name=&quot;ARM&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ARM --&gt;
&lt;a name=&quot;arm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#arm --&gt;
</html>
</section>
<node name="ARM-Conventions" spaces=" "><nodename>ARM Conventions</nodename><nodenext spaces=" ">Operator Version</nodenext><nodeprev spaces=" ">CF Conventions</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle><acronym><acronymword>ARM</acronymword></acronym> Conventions</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1326"><acronym><acronymword>ARM</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1327"><code>time_offset</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1328"><code>base_time</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1329"><code>time</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: <command>ncrcat</command>&linebreak;
Short options: None&linebreak;
</para></cartouche>
<para><command>ncrcat</command> has been programmed to correctly handle data files
which utilize the Atmospheric Radiation Measurement (<acronym><acronymword>ARM</acronymword></acronym>)
Program <uref><urefurl>http://www.arm.gov/data/time.stm</urefurl><urefdesc>convention</urefdesc></uref> for
time and time offsets.
If you do not work with <acronym><acronymword>ARM</acronymword></acronym> data then you may skip this
section. 
<acronym><acronymword>ARM</acronymword></acronym> data files store time information in two variables, a
scalar, <code>base_time</code>, and a record variable, <code>time_offset</code>.
Subtle but serious problems can arise when these type of files are
blindly concatenated without <acronym><acronymword>CF</acronymword></acronym> or <acronym><acronymword>ARM</acronymword></acronym> support. 
<command>NCO</command> implements rebasing (<pxref label="Rebasing-Time-Coordinate"><xrefnodename>Rebasing Time Coordinate</xrefnodename></pxref>) 
as necessary on both <acronym><acronymword>CF</acronymword></acronym> and <acronym><acronymword>ARM</acronymword></acronym> files.
Rebasing chains together consecutive <var>input-files</var> and produces an
<var>output-file</var> which contains the correct time information. 
For <acronym><acronymword>ARM</acronymword></acronym> files this is expecially complex because the time
coordinates are often stored as type <code>NC_CHAR</code>.
Currently, <command>ncrcat</command> determines whether a datafile is an
<acronym><acronymword>ARM</acronymword></acronym> datafile simply by testing for the existence of the
variables <code>base_time</code>, <code>time_offset</code>, and the dimension
<code>time</code>.  
If these are found in the <var>input-file</var> then <command>ncrcat</command> will 
automatically perform two non-standard, but hopefully useful,
procedures. 
First, <command>ncrcat</command> will ensure that values of <code>time_offset</code>
appearing in the <var>output-file</var> are relative to the <code>base_time</code>
appearing in the first <var>input-file</var> (and presumably, though not
necessarily, also appearing in the <var>output-file</var>).
Second, if a coordinate variable named <code>time</code> is not found in the
<var>input-files</var>, then <command>ncrcat</command> automatically creates the
<code>time</code> coordinate in the <var>output-file</var>.  
The values of <code>time</code> are defined by the <acronym><acronymword>ARM</acronymword></acronym> conventions 
<math><var>time</var> = <var>base_time</var> + <var>time_offset</var></math>.
Thus, if <var>output-file</var> contains the <code>time_offset</code>
variable, it will also contain the <code>time</code> coordinate.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1330"><code>history</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1331">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1332">attributes, global</indexterm></cindex>
<w>A short</w> message is added to the <code>history</code> global attribute
whenever these <acronym><acronymword>ARM</acronymword></acronym>-specific procedures are executed.
</para>
<html endspaces=" ">
&lt;a name=&quot;vrs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrs --&gt;
&lt;a name=&quot;version&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#version --&gt;
</html>
</section>
<node name="Operator-Version" spaces=" "><nodename>Operator Version</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">ARM Conventions</nodeprev><nodeup spaces=" ">Shared features</nodeup></node>
<section spaces=" "><sectiontitle>Operator Version</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1333">version</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1334"><acronym><acronymword>RCS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1335"><code>-r</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1336"><code>--revision</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1337"><code>--version</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1338"><code>--vrs</code></indexterm></cindex>
<cartouche endspaces=" ">
<para>Availability: All operators&linebreak;
Short options: <samp>-r</samp>&linebreak;
Long options: <samp>--revision</samp>, <samp>--version</samp>, or <samp>--vrs</samp>&linebreak;
</para></cartouche>
<para>All operators can be told to print their version information,
library version, copyright notice, and compile-time configuration 
with the <samp>-r</samp> switch, or its long-option equivalent
<samp>revision</samp>. 
The <samp>--version</samp> or <samp>--vrs</samp> switches print the operator
version information only.
The internal version number varies between operators, and indicates the 
most recent change to a particular operator&textrsquo;s source code.
This is useful in making sure you are working with the most recent
operators.
The version of <acronym><acronymword>NCO</acronymword></acronym> you are using might be, e.g., <code>3.9.5</code>.
Using <samp>-r</samp> on, say, <command>ncks</command>, produces something like 
<samp>NCO netCDF Operators version &quot;3.9.5&quot; last modified 2008/05/11 built May 12 2008 on neige by zender 
Copyright (C) 1995--2008 Charlie Zender
ncks version 20090918</samp>.
This tells you that <command>ncks</command> contains all patches up to version 
<code>3.9.5</code>, which dates from <w>May 11</w>, 2008.
<html endspaces=" ">
&lt;a name=&quot;rfr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rfr --&gt;
</html>
</para></section>
</chapter>
<node name="Reference-Manual" spaces=" "><nodename>Reference Manual</nodename><nodenext spaces=" ">Contributing</nodenext><nodeprev spaces=" ">Shared features</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>Reference Manual</sectiontitle>

<para>This chapter presents reference pages for each of the operators
individually. 
The operators are presented in alphabetical order.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1339">command line switches</indexterm></cindex>
All valid command line switches are included in the syntax statement.
Recall that descriptions of many of these command line switches are
provided only in <ref label="Shared-features"><xrefnodename>Shared features</xrefnodename></ref>, to avoid redundancy.
Only options specific to, or most useful with, a particular operator are 
described in any detail in the sections below.  
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>ncap2 netCDF Arithmetic Processor</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncatted netCDF Attribute Editor</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncbo netCDF Binary Operator</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncchecker netCDF Compliance Checker</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncclimo netCDF Climatology Generator</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncecat netCDF Ensemble Concatenator</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>nces netCDF Ensemble Statistics</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncflint netCDF File Interpolator</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncks netCDF Kitchen Sink</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncpdq netCDF Permute Dimensions Quickly</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncra netCDF Record Averager</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncrcat netCDF Record Concatenator</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncremap netCDF Remapper</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncrename netCDF Renamer</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ncwa netCDF Weighted Averager</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap --&gt;
&lt;a name=&quot;ncap2&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap2 --&gt;
</html>
<node name="ncap2-netCDF-Arithmetic-Processor" spaces=" "><nodename>ncap2 netCDF Arithmetic Processor</nodename><nodenext spaces=" ">ncatted netCDF Attribute Editor</nodenext><nodeprev spaces=" ">Reference Manual</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncap2</command> netCDF Arithmetic Processor</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1340">parser</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1341">lexer</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1342">arithmetic processor</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="14" mergedindex="cp">ncap</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="15" mergedindex="cp">ncap2</indexterm></findex>
<cartouche endspaces=" ">
<para><command>ncap2</command> understands a relatively full-featured 
language of operations, including loops, conditionals, arrays,
and math functions.
<command>ncap2</command> is the most rapidly changing <acronym><acronymword>NCO</acronymword></acronym> operator and
its documentation is incomplete.
The distribution file <file>data/ncap2_tst.nco</file> contains an up-to-date
overview of its syntax and capabilities. 
The <file>data/*.nco</file> distribution files (especially
<file>bin_cnt.nco</file>, <file>psd_wrf.nco</file>, and <file>rgr.nco</file>) contain
in-depth examples of <command>ncap2</command> solutions to complex problems.
</para></cartouche>

<!-- c fxm: TODO nco549 hyper-link all switches to explanatory sections? -->
<!-- c Problem is that only works well in HTML mode -->
<!-- c TeXInfo has no native mode for concise hyperlinks in text mode -->
<!-- c Currently in TeX/PDF mode, TeXInfo opens browser to find link, -->
<!-- c rather than jumping to internal link within document -->
<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 [-3] [-4] [-5] [-6] [-7] [<uref><urefurl>http://nco.sf.net/nco.html#-A</urefurl><urefreplacement>-A</urefreplacement></uref>] [-C] [-c] 
[-D <var>dbg</var>] [-F] [-f] [--glb ...] [-H] [-h] [--hdf] [--hdr_pad <var>nbr</var>] [--hpss]
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [--no_tmp_fl] [-O] [-o <var>output-file</var>]
[-p <var>path</var>] [-R] [-r] [--ram_all]
[-s <var>algebra</var>] [-S <var>fl.nco</var>] [-t <var>thr_nbr</var>] [-v]
[<var>input-file</var>] [<var>output-file</var>]  
</pre></example>
 
<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncap2</command> arithmetically processes netCDF files.
<command>ncap2</command> is the successor to <command>ncap</command> which was put into
maintenance mode in November, 2006, and completely removed from
<acronym><acronymword>NCO</acronymword></acronym> in March, 2018. 
This documentation refers to <command>ncap2</command> implements its own
domain-specific language to produc a powerful superset
<command>ncap</command>-functionality.
<command>ncap2</command> may be renamed <command>ncap</command> one day!
<cindex index="cp" spaces=" "><indexterm index="cp" number="1343">script file</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1344"><code>--script-file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1345"><code>--fl_spt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1346"><code>--script</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1347"><code>--spt</code></indexterm></cindex>
The processing instructions are contained either in the <acronym><acronymword>NCO</acronymword></acronym>
script file <file>fl.nco</file> or in a sequence of command line arguments.
The options <samp>-s</samp> (or long options <samp>--spt</samp> or <samp>--script</samp>)
are used for in-line scripts and <samp>-S</samp> (or long options
<samp>--fl_spt</samp>, <samp>--nco_script</samp>, or <samp>--script-file</samp>) are used to provide the
filename where (usually multiple) scripting commands are pre-stored.   
<command>ncap2</command> was written to perform arbitrary algebraic
transformations of data and archive the results as easily as
possible. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1348">derived fields</indexterm></cindex>
<xref label="Missing-Values"><xrefnodename>Missing Values</xrefnodename></xref>, for treatment of missing values.
The results of the algebraic manipulations are called 
<dfn>derived fields</dfn>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1349"><code>--usr_dfn_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1350"><code>--output_user_defined_variables</code></indexterm></cindex>
<para>Unlike the other operators, <command>ncap2</command> does not accept a list of
variables to be operated on as an argument to the <samp>-v</samp> option
(<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>).
In <command>ncap2</command>, <samp>-v</samp> is a switch that takes no arguments and
indicates that <command>ncap2</command> should output <emph>only</emph> user-defined
variables (and coordinates associated with variables used in deriving
them). 
<command>ncap2</command> neither accepts nor understands the <var>-x</var> switch.
We recommend making this distinction clear by using 
<samp>--usr_dfn_var</samp> (or its synonym,
<samp>--output_user_defined_variables</samp>, both introduced in
<acronym><acronymword>NCO</acronymword></acronym> version 5.1.9 in October, 2023) instead of <samp>-v</samp>,
which may be deprecated.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1351">appending variables</indexterm></cindex>
NB: As of 20120515, <command>ncap2</command> is unable to append to files that
already contain the appended dimensions. 
</para>
<para>Providing a name for <var>output-file</var> is optional if <var>input-file</var>
is a netCDF3 format, in which case <command>ncap2</command> attempts to write
modifications directly to <var>input-file</var> (similar to the behavior of
<command>ncrename</command> and <command>ncatted</command>).
Format-constraints prevent this type of appending from working on a
netCDF4 format <var>input-file</var>.
In any case, reading and writing the same file can be risky and lead
to unexpected consequences (since the file is being both read and
written), so in normal usage we recommend providing <var>output-file</var>
(which can be the same as <var>input-file</var> since the changes are first
written to an intermediate file).
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.8.0 (released May, 2019),
<command>ncap2</command> does not require that <var>input-file</var> be specified
when <var>output-file</var> has no dependency on it.
Prior to this, <command>ncap2</command> required users to specify a dummy
<var>input-file</var> even if it was not used to construct
<var>output-file</var>.
Input files are always read by <command>ncap2</command>, and dummy input
files are read though not used for anything nor modified.
Now 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -s 'quark=1' ~/foo.nc # Create new foo.nc
ncap2 -s 'print(quark)' ~/foo.nc # Print existing foo.nc
ncap2 -O -s 'quark=1' ~/foo.nc # Overwrite old with new foo.nc
ncap2 -s 'quark=1' ~/foo.nc ~/foo.nc # Add to old foo.nc
</verbatim>
</example>

<!-- c @subsection Scripting Mathematical Processing with @command{ncap2} -->

<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Syntax of ncap2 statements</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Expressions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Dimensions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Left hand casting</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Arrays and hyperslabs</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Attributes</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Value List</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Number literals</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>if statement</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Print &amp; String methods</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Missing values ncap2</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Methods and functions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>RAM variables</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Where statement</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Loops</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Include files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Sort methods</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>UDUnits script</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Vpointer</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Irregular grids</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Bilinear interpolation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>GSL special functions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>GSL interpolation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>GSL least-squares fitting</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>GSL statistics</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>GSL random number generation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Examples ncap2</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Intrinsic mathematical methods</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Operator precedence and associativity </menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>ID Quoting</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>make_bounds() function</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>solar_zenith_angle function</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;att_prp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_prp --&gt;
</html>
<para>Defining new variables in terms of existing variables is a powerful
feature of <command>ncap2</command>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1352">derived fields</indexterm></cindex>
Derived fields inherit the metadata (i.e., attributes) of their
ancestors, if any, in the script or input file. 
When the derived field is completely new (no identically-named ancestors
exist), then it inherits the metadata (if any) of the left-most variable
on the right hand side of the defining expression.
This metadata inheritance is called <dfn>attribute propagation</dfn>.
Attribute propagation is intended to facilitate well-documented 
data analysis, and we welcome suggestions to improve this feature.
</para>
<para>The only exception to this rule of attribute propagation is in cases of
left hand casting (<pxref label="Left-hand-casting"><xrefnodename>Left hand casting</xrefnodename></pxref>).
The user must manually define the proper metadata for variables defined
using left hand casting. 
</para>
<html endspaces=" ">
&lt;a name=&quot;syn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#syn --&gt;
</html>
<node name="Syntax-of-ncap2-statements" spaces=" "><nodename>Syntax of ncap2 statements</nodename><nodenext spaces=" ">Expressions</nodenext><nodeprev spaces=" ">ncap2 netCDF Arithmetic Processor</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Syntax of <command>ncap2</command> statements</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1353">statement</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1354">syntax</indexterm></cindex>
<para>Mastering <command>ncap2</command> is relatively simple.
Each valid statement <var>statement</var> consists of standard forward
algebraic expression. 
The <file>fl.nco</file>, if present, is simply a list of such statements,
whitespace, and comments.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1355">C language</indexterm></cindex>
The syntax of statements is most like the computer <w>language C</w>.
The following characteristics <w>of C</w> are preserved:
</para><table commandarg="asis" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="asis">Array syntax</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1356">array syntax</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1357"><code>[]</code> (array delimiters)</indexterm></cindex>
<para>Arrays elements are placed within <code>[]</code> characters;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Array indexing</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1358">array indexing</indexterm></cindex>
<para>Arrays are 0-based;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Array storage</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1359">array storage</indexterm></cindex>
<para>Last dimension is most rapidly varying;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Assignment statements</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1360">assignment statement</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1361">semi-colon</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1362"><code>;</code> (end of statement)</indexterm></cindex>
<para><w>A semi</w>-colon <samp>;</samp> indicates the end of an assignment statement.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Comments</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1363">comments</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1364"><code>/*...*/</code> (comment)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1365"><code>//</code> (comment)</indexterm></cindex>
<para>Multi-line comments are enclosed within <code>/* */</code> characters.
Single line comments are preceded by <code>//</code> characters.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Nesting</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1366">including files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1367">nesting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1368"><code>#include</code></indexterm></cindex>
<para>Files may be nested in scripts using <code>#include <var>script</var></code>.
The <code>#include</code> command is not followed by a semi-colon because it
is a pre-processor directive, not an assignment statement. 
The filename <file>script</file> is interpreted relative to the run directory.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Attribute syntax</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1369">attribute syntax</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1370"><code>&arobase;</code> (attribute)</indexterm></cindex>
<para>The at-sign <code>&arobase;</code> is used to delineate an attribute name from a
variable name.
</para></tableitem></tableentry></table> 

<html endspaces=" ">
&lt;a name=&quot;ncap_xpr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_xpr --&gt;
</html>
</subsection>
<node name="Expressions" spaces=" "><nodename>Expressions</nodename><nodenext spaces=" ">Dimensions</nodenext><nodeprev spaces=" ">Syntax of ncap2 statements</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1371">expressions</indexterm></cindex>
<subsection spaces=" "><sectiontitle>Expressions</sectiontitle>
<para>Expressions are the fundamental building block of <command>ncap2</command>. 
Expressions are composed of variables, numbers, literals, and
attributes. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1372">C language</indexterm></cindex>
The following <w>C operators</w> are &textldquo;overloaded&textrdquo; and work with scalars 
and multi-dimensional arrays:
</para><example endspaces=" ">
<pre xml:space="preserve">Arithmetic Operators: * / % + - ^
Binary Operators:     &gt; &gt;= &lt; &lt;= == != == || &amp;&amp; &gt;&gt; &lt;&lt;
Unary Operators:      + - ++ -- !
Conditional Operator: exp1 ? exp2 : exp3
Assign Operators:     = += -= /= *=
</pre></example>

<para>In the following section a <dfn>variable</dfn> also refers to a 
number literal which is read in as a scalar variable:
</para>
<para><strong>Arithmetic and Binary Operators </strong>
</para>
<para>Consider <emph>var1 &textrsquo;op&textrsquo; var2</emph>
</para>
<para><strong>Precision</strong>
</para><itemize commandarg="bullet" spaces=" " endspaces=" "><itemprepend><formattingcommand command="bullet"/></itemprepend>
<listitem><prepend>&bullet;</prepend> <para>When both operands are variables, the result has the precision of the higher precision operand.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>When one operand is a variable and the other an attribute, the result has the precision of the variable. 
</para></listitem><listitem><prepend>&bullet;</prepend> <para>When both operands are attributes, the result has the precision of the more precise attribute.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>The exponentiation operator &textldquo;^&textrdquo; is an exception to the above rules. 
When both operands have type less than <code>NC_FLOAT</code>, the result is <code>NC_FLOAT</code>. 
When either type is <code>NC_DOUBLE</code>, the result is also <code>NC_DOUBLE</code>. 
</para></listitem></itemize>
<!-- c csz got to here editing -->

<cindex index="cp" spaces=" "><indexterm index="cp" number="1373">broadcasting variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1374">rank</indexterm></cindex>
<para><strong>Rank</strong>
</para><itemize commandarg="bullet" spaces=" " endspaces=" "><itemprepend><formattingcommand command="bullet"/> </itemprepend>
<listitem><prepend>&bullet;</prepend> <para>The Rank of the result is generally equal to Rank of the operand
that has the greatest number of dimensions.  
</para></listitem><listitem><prepend>&bullet;</prepend> <para>If the dimensions in var2 are a subset of the dimensions in var1
then its possible to  make var2 conform to var1 through broadcasting and
or dimension reordering.  
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Broadcasting a variable means creating data in non-existing
dimensions by copying data in existing dimensions. 
</para></listitem><listitem><prepend>&bullet;</prepend> <para>More specifically: If the numbers of dimensions in var1 is greater 
than or equal to the number of dimensions in var2 then an attempt is
made to make var2 conform to var1 ,else var1 is made to conform to
var2. If conformance  is not possible then an error message will be
emitted and script execution will cease.&linebreak; 
</para></listitem></itemize>

<noindent></noindent> <para>Even though the logical operators return True(1) or False(0)
they are treated in the same way as the arithmetic operators with regard
to precision and rank.&linebreak; 
Examples:
</para>
<example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
dimensions: time=10, lat=2, lon=4
Suppose we have the two variables:

double  P(time,lat,lon);
float   PZ0(lon,lat);  // PZ0=1,2,3,4,5,6,7,8;

Consider now the expression:
 PZ=P-PZ0

PZ0 is made to conform to P and the result is
PZ0 =
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,
   1,3,5,7,2,4,6,8,

Once the expression is evaluated then PZ will be of type double;

Consider now 
 start=four-att_var@double_att;  // start =-69  and is of type intger;
 four_pow=four^3.0f               // four_pow=64 and is of type float  
 three_nw=three_dmn_var_sht*1.0f; // type is now float
 start@n1=att_var@short_att*att_var@int_att; 
                                  // start@n1=5329 and is type int 
</verbatim>
</example>

<noindent></noindent> <para><strong>Binary Operators</strong> &linebreak; 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1375">binary Operators</indexterm></cindex>
Unlike C the binary operators return an array of values. 
There is no such thing as short circuiting with the AND/OR operators. 
Missing values are carried into the result in the same way they are with
the arithmetic operators. 
When an expression is evaluated in an if() the missing values are
treated as true.&linebreak;  
The binary operators are, in order of precedence: 
</para><example endspaces=" ">
<pre xml:space="preserve">	
!   Logical Not
----------------------------
&lt;&lt;  Less Than Selection
&gt;&gt;  Greater Than Selection
----------------------------
&gt;   Greater than
&gt;=  Greater than or equal to
&lt;   Less than
&lt;=  Less than or equal to
----------------------------
==  Equal to
!=  Not equal to
----------------------------
&amp;&amp;  Logical AND
----------------------------
||  Logical OR
----------------------------
</pre></example>

<para>To see all operators: <pxref label="Operator-precedence-and-associativity"><xrefnodename>Operator precedence and associativity</xrefnodename></pxref> 
Examples:
</para><example endspaces=" ">
<pre xml:space="preserve">tm1=time&gt;2 &amp;&amp; time &lt;7;  // tm1=0, 0, 1, 1, 1, 1, 0, 0, 0, 0 double
tm2=time==3 || time&gt;=6; // tm2=0, 0, 1, 0, 0, 1, 1, 1, 1, 1 double
tm3=int(!tm1);          // tm3=1, 1, 0, 0, 0, 0, 1, 1, 1, 1 int
tm4=tm1 &amp;&amp; tm2;         // tm4=0, 0, 1, 0, 0, 1, 0, 0, 0, 0 double
tm5=!tm4;               // tm5=1, 1, 0, 1, 1, 0, 1, 1, 1, 1 double
</pre></example>
	
<noindent></noindent> <para><strong>Regular Assign Operator</strong>&linebreak;
<emph>var1 &textrsquo;=&textrsquo; exp1</emph> &linebreak;
If var1 does not already exist in Input or Output then var1 is written to Output with the values, type and dimensions from expr1. If var1 is in Input only it is copied to Output first. Once the var is in Ouptut then the only reqirement on expr1 is that the number of elements must match the number already on disk. The type of expr1 is converted as necessary to the disk type.
</para>
<para>If you wish to change the type or shape of a variable in Input then you
must cast the variable.
See <pxref label="Left-hand-casting"><xrefnodename>Left hand casting</xrefnodename></pxref>
</para><example endspaces=" ">
<pre xml:space="preserve">time[time]=time.int();
three_dmn_var_dbl[time,lon,lat]=666L;
</pre></example>

<noindent></noindent> <para><strong> Other Assign Operators +=,-=,*=./= </strong>&linebreak;
<emph>var1 &textrsquo;ass_op&textrsquo; exp1 </emph>&linebreak;
if exp1 is a variable and it doesn&textrsquo;t conform to var1 then an attempt is made to make it conform to var1. If exp1 is an attribute it must have unity size or else have the same number of elements as var1. If expr1 has a different type to var1 the it is converted to the var1 type.
</para><example endspaces=" ">
<pre xml:space="preserve">z1=four+=one*=10 // z1=14 four=14 one=10;	
time-=2          // time= -1,0,1,2,3,4,5,6,7,8
</pre></example>

<noindent></noindent> <para><strong>Increment/Decrement Operators &linebreak;</strong> 
These work in a similar fashion to their regular C counterparts. If say the variable <code>four</code> is input only then the statement <code>++four</code> effectively means read <code>four</code> from input increment each element by one, then write the new values to Output;
</para>
<para>Example:
</para><example endspaces=" ">
<pre xml:space="preserve">n2=++four;   n2=5, four=5 
n3=one--+20; n3=21  one=0;	 
n4=--time;   n4=time=0.,1.,2.,3.,4.,5.,6.,7.,8.,9.;
</pre></example>

<noindent></noindent> <para><strong>Conditional Operator ?:</strong>&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="1376">conditional Operator</indexterm></cindex>
<emph>exp1 ? exp2 : exp3 </emph> &linebreak;
The conditional operator (or ternary Operator) is a succinct way
of writing an if/then/else. If exp1 evaluates to true then exp2 is
returned else exp3 is returned. 
</para>
<para>Example:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
weight_avg=weight.avg();
weight_avg@units= (weight_avg == 1 ? &quot;kilo&quot; : &quot;kilos&quot;);  
PS_nw=PS-(PS.min() &gt; 100000 ? 100000 : 0);
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;clp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clp --&gt;
&lt;a name=&quot;clipping&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clipping --&gt;
</html>
<noindent></noindent> <para><strong>Clipping Operators</strong>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1377">clipping operators</indexterm></cindex>
</para><table commandarg="asis" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="asis">&lt;&lt; Less-than Clipping&linebreak;</itemformat></item>
</tableterm><tableitem><para>For arrays, the less-than selection operator selects all values in the
left operand that are less than the corresponding value in the right
operand. 
If the value of the left side is greater than or equal to the
corresponding value of the right side, then the right side value is 
placed in the result	 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">&gt;&gt; Greater-than Clipping&linebreak;</itemformat></item>
</tableterm><tableitem><para>For arrays, the greater-than selection operator selects all values in
the left operand that are greater than the corresponding value in the
right operand. 
If the value of the left side is less than or equal to the corresponding
value of the right side, then the right side value is placed in the
result.  
</para></tableitem></tableentry></table>

<para>Example:
</para><example endspaces=" ">
<pre xml:space="preserve">RDM2=RDM &gt;&gt; 100.0 // 100,100,100,100,126,126,100,100,100,100 double
RDM2=RDM &lt;&lt;  90s  // 1, 9, 36, 84, 90, 90, 84, 36, 9, 1 int
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ncap_dims&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_dims --&gt;
&lt;a name=&quot;defdim&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#defdim --&gt;
</html>
</subsection>
<node name="Dimensions" spaces=" "><nodename>Dimensions</nodename><nodenext spaces=" ">Left hand casting</nodenext><nodeprev spaces=" ">Expressions</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Dimensions</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1378">defining dimensions in <command>ncap2</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1379"><code>defdim()</code></indexterm></cindex>
<para>Dimensions are defined in Output using the <code>defdim()</code> function.
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;cnt&quot;,10); # Dimension size is fixed by default
defdim(&quot;cnt&quot;,10,NC_UNLIMITED); # Dimension is unlimited (record dimension)
defdim(&quot;cnt&quot;,10,0); # Dimension is unlimited (record dimension)
defdim(&quot;cnt&quot;,10,1); # Dimension size is fixed
defdim(&quot;cnt&quot;,10,737); # All non-zero values indicate dimension size is fixed
</pre></example>

<para>This dimension name must then be prefixed with a dollar-sign <samp>$</samp>
when referred to in method arguments or left-hand-casting, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">new_var[$cnt]=time;
temperature[$time,$lat,$lon]=35.5;
temp_avg=temperature.avg($time);
</pre></example>

<para>The <code>size</code> method allows dimension sizes to be used in 
arithmetic expressions:
</para><example endspaces=" ">
<pre xml:space="preserve">time_avg=time.total()/$time.size;
</pre></example>

<para>Increase the size of a new variable by one and set new member to zero:
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;cnt_new&quot;,$cnt.size+1);
new_var[$cnt_new]=0.0;
new_var(0:($cnt_new.size-2))=old_var;
</pre></example>

<para>To define an unlimited dimension, simply set the size to zero
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;time2&quot;,0)
</pre></example>

<noindent></noindent> <para><strong>Dimension Abbreviations &linebreak;</strong>
It is possible to use dimension abbreviations as method arguments:&linebreak;
<code>$0</code> is the first dimension of a variable&linebreak;
<code>$1</code> is the second dimension of a variable&linebreak;
<code>$n</code> is the n+1 dimension of a variable&linebreak;
</para>
<example endspaces=" ">
<pre xml:space="preserve">float four_dmn_rec_var(time,lat,lev,lon);
double three_dmn_var_dbl(time,lat,lon);

four_nw=four_dmn_rev_var.reverse($time,$lon)
four_nw=four_dmn_rec_var.reverse($0,$3);

four_avg=four_dmn_rec_var.avg($lat,$lev);  
four_avg=four_dmn_rec_var.avg($1,$2);  

three_mw=three_dmn_var_dbl.permute($time,$lon,$lat);
three_mw=three_dmn_var_dbl.permute($0,$2,$1);
</pre></example>

<noindent></noindent> <para><strong>ID Quoting &linebreak;</strong>
If the dimension name contains non-regular characters use ID quoting:
See <pxref label="ID-Quoting"><xrefnodename>ID Quoting</xrefnodename></pxref>
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;a--list.A&quot;,10);
A1['$a--list.A']=30.0;
</pre></example>

<noindent></noindent> <para><strong>GOTCHA &linebreak;</strong>
It is not possible to manually define in Output any dimensions that exist in Input. When a variable from Input appears in an expression or statement its  dimensions in Input are  automagically copied to Output (if they are not already present)
</para>
<html endspaces=" ">
&lt;a name=&quot;lhc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lhc --&gt;
&lt;a name=&quot;lhs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lhs --&gt;
</html>
</subsection>
<node name="Left-hand-casting" spaces=" "><nodename>Left hand casting</nodename><nodenext spaces=" ">Arrays and hyperslabs</nodenext><nodeprev spaces=" ">Dimensions</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Left hand casting</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1380">hybrid coordinate system</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1381">left hand casting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1382"><acronym><acronymword>LHS</acronymword></acronym></indexterm></cindex>
<para>The following examples demonstrate the utility of the 
<dfn>left hand casting</dfn> ability of <command>ncap2</command>.
Consider first this simple, artificial, example.
If <var>lat</var> and <var>lon</var> are one dimensional coordinates of
dimensions <var>lat</var> and <var>lon</var>, respectively, then addition
of these two one-dimensional arrays is intrinsically ill-defined because 
whether <var>lat_lon</var> should be dimensioned <var>lat</var> by <var>lon</var>
or <var>lon</var> by <var>lat</var> is ambiguous (assuming that addition is to
remain a <dfn>commutative</dfn> procedure, i.e., one that does not depend on 
the order of its arguments).
Differing dimensions are said to be <dfn>orthogonal</dfn> to one another,
and sets of dimensions which are mutually exclusive are orthogonal
as a set and any arithmetic operation between variables in orthogonal
dimensional spaces is ambiguous without further information.
</para>
<para>The ambiguity may be resolved by enumerating the desired dimension 
ordering of the output expression inside square brackets on the
left hand side (<acronym><acronymword>LHS</acronymword></acronym>) of the equals sign.
This is called <dfn>left hand casting</dfn> because the user resolves the 
dimensional ordering of the <acronym><acronymword>RHS</acronymword></acronym> of the expression by
specifying the desired ordering on the <acronym><acronymword>LHS</acronymword></acronym>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'lat_lon[lat,lon]=lat+lon' in.nc out.nc
ncap2 -s 'lon_lat[lon,lat]=lat+lon' in.nc out.nc
</pre></example>
<para>The explicit list of dimensions on the <acronym><acronymword>LHS</acronymword></acronym>, <code>[lat,lon]</code>
resolves the otherwise ambiguous ordering of dimensions in
<var>lat_lon</var>. 
In effect, the <acronym><acronymword>LHS</acronymword></acronym> <dfn>casts</dfn> its rank properties onto the 
<acronym><acronymword>RHS</acronymword></acronym>.
Without <acronym><acronymword>LHS</acronymword></acronym> casting, the dimensional ordering of <var>lat_lon</var>
would be undefined and, hopefully, <command>ncap2</command> would print an error
message. 
</para>
<html endspaces=" ">
&lt;a name=&quot;prs_mdp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prs_mdp --&gt;
</html>
<para>Consider now a slightly more complex example.
In geophysical models, a coordinate system based on 
a blend of terrain-following and density-following surfaces is 
called a <dfn>hybrid coordinate system</dfn>.
In this coordinate system, four variables must be manipulated to
obtain the pressure of the vertical coordinate:
<var>PO</var> is the domain-mean surface pressure offset (a scalar),
<var>PS</var> is the local (time-varying) surface pressure (usually two
horizontal spatial dimensions, i.e. latitude by longitude), <var>hyam</var>
is the weight given to surfaces of constant density (one spatial
dimension, pressure, which is orthogonal to the horizontal
dimensions), and <var>hybm</var> is the weight given to surfaces of
constant elevation (also one spatial dimension). 
This command constructs a four-dimensional pressure <code>prs_mdp</code>
from the four input variables of mixed rank and orthogonality:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'prs_mdp[time,lat,lon,lev]=P0*hyam+PS*hybm' in.nc out.nc
</pre></example>
<para>Manipulating the four fields which define the pressure in a hybrid
coordinate system is easy with left hand casting.
</para>
<html endspaces=" ">
&lt;a name=&quot;pdel&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#pdel --&gt;
&lt;a name=&quot;prs_ntf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prs_ntf --&gt;
</html>
<para>Finally, we show how to use interface quantities to define midpoint
quantities.
In particular, we will define interface pressures using the standard
<acronym><acronymword>CESM</acronymword></acronym> output hybrid coordinate parameters, and then difference
those interface pressures to obtain the pressure difference between
the interfaces. 
The pressure difference is necessary obtain gridcell mass path
and density (which are midpoint quantities).
Definitions are as in the above example, with new variables
<var>hyai</var> and <var>hybi</var> defined at grid cell vertical
interfaces (rather than midpoints like <var>hyam</var> and <var>hybm</var>).
The approach naturally fits into two lines:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
cat &gt; ~/pdel.nco &lt;&lt; 'EOF'
*prs_ntf[time,lat,lon,ilev]=P0*hyai+PS*hybi;
// Requires NCO 4.5.4 and later:
prs_dlt[time,lat,lon,lev]=prs_ntf(:,:,:,1:$ilev.size-1)-prs_ntf(:,:,:,0:$ilev.size-2);
// Derived variable that require pressure thickness:
// Divide by gravity to obtain total mass path in layer aka mpl [kg m-2] 
mpl=prs_dlt/grv_sfc;
// Multiply by mass mixing ratio to obtain mass path of constituent
mpl_CO2=mpl*mmr_CO2;
EOF
ncap2 -O -v -S ~/pdel.nco ~/nco/data/in.nc ~/foo.nc
ncks -O -C -v prs_dlt ~/foo.nc
</verbatim>
</example>
<para>The first line defines the four-dimensional interface pressures 
<code>prs_ntf</code> as a <acronym><acronymword>RAM</acronymword></acronym> variable because those are not desired 
in the output file. 
The second differences each pressure level from the pressure above it
to obtain the pressure difference. 
This line employs both left-hand casting and array hyperslabbing.
However, this syntax only works with <acronym><acronymword>NCO</acronymword></acronym> version 4.5.4
(November, 2015) and later because earlier versions require that 
<acronym><acronymword>LHS</acronymword></acronym> and <acronym><acronymword>RHS</acronymword></acronym> dimension names (not just sizes) match. 
From the pressure differences, one can obtain the mass path in each
layer as shown.
</para>
<para>Another reason to cast a variable is to modify the shape or type 
of a variable already in Input 
</para><example endspaces=" ">
<pre xml:space="preserve">gds_var[gds_crd]=gds_var.double();
three_dmn_var_crd[lat,lon,lev]=10.0d;
four[]=four.int();
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ncap_arr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_arr --&gt;
&lt;a name=&quot;array&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#array --&gt;
</html>
</subsection>
<node name="Arrays-and-hyperslabs" spaces=" "><nodename>Arrays and hyperslabs</nodename><nodenext spaces=" ">Attributes</nodenext><nodeprev spaces=" ">Left hand casting</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Arrays and hyperslabs</sectiontitle>

<findex index="fn" spaces=" "><indexterm index="fn" number="16" mergedindex="cp">array</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1383"><code>array</code> function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1384">arrays</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1385">findgen-equivalent</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1386">indgen-equivalent</indexterm></cindex>
<para>Generating a regularly spaced n-dimensional array with <command>ncap2</command>
is simple with the <code>array()</code> function. 
The function comes in three (overloaded) forms
</para><example endspaces=" ">
<pre xml:space="preserve">(A) var_out=array(val_srt,val_inc,$dmn_nm); // One-dimensional output
(B) var_out=array(val_srt,val_inc,var_tpl); // Multi-dimensional output
(C) var_out=array(val_srt,val_inc,/$dmn1,$dmn2...,$dmnN/); // Multi-dimensional output
</pre></example>
<noindent></noindent>

<table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="dfn">val_srt</itemformat></item>
</tableterm><tableitem><para>Starting value of the array. The <var>type</var> of the array will be the <var>type</var> of this starting value.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">val_inc</itemformat></item>
</tableterm><tableitem><para>Spacing (or increment) between elements. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">var_tpl</itemformat></item>
</tableterm><tableitem><para>Variable from which the array can derive its shape 1D or nD
</para></tableitem></tableentry></table>

<noindent></noindent> <para><strong>One-Dimensional Arrays&linebreak;</strong>
Use form (A) or (B) above for 1D arrays:
</para><example endspaces=" ">
<pre xml:space="preserve"># var_out will be NC_DOUBLE:
var_out=array(10.0,2,$time) // 10.5,12.5,14.5,16.5,18.5,20.5,22.5,24.5,26.5,28.5

// var_out will be NC_UINT, and &quot;shape&quot; will duplicate &quot;ilev&quot;
var_out=array(0ul,2,ilev) // 0,2,4,6

// var_out will be NC_FLOAT
var_out=array(99.0f,2.5,$lon) // 99,101.5,104,106.5

// Create an array of zeros 
var_out=array(0,0,$time) // 0,0,0,0,0,0,0,0,0,0 

// Create array of ones
var_out=array(1.0,0.0,$lon) // 1.0,1.0,1.0,1.0 
</pre></example>

<noindent></noindent> <para><strong>n-Dimensional Arrays&linebreak;</strong>
Use form (B) or (C) for creating n-D arrays.&linebreak; 
NB: In (C) the final argument is a list of dimensions
</para><example endspaces=" ">
<pre xml:space="preserve">// These are equivalent
var_out=array(1.0,2.0,three_dmn_var);
var_out=array(1.0,2.0,/$lat,$lev,$lon/);

// var_out is NC_BYTE
var_out=array(20b, -4, /$lat,$lon/); // 20,16,12,8,4,0,-4,-8  

srt=3.14159f;
inc=srt/2.0f;
var_out(srt,inc,var_2D_rrg);
// 3.14159, 4.712385, 6.28318, 7.853975, 9.42477, 10.99557, 12.56636, 14.13716 ; 
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="1387">hyperslabs</indexterm></cindex>
<para>Hyperslabs in <command>ncap2</command> are more limited than hyperslabs with the
other <acronym><acronymword>NCO</acronymword></acronym> operators. 
<command>ncap2</command> does not understand the shell command-line syntax
used to specify multi-slabs, wrapped co-ordinates, negative stride or
coordinate value limits.
However with a bit of syntactic magic they are all are possible. 
<command>ncap2</command> accepts (in fact, it requires) <var>N</var>-hyperslab
arguments for a variable of rank <var>N</var>:
</para><example endspaces=" ">
<pre xml:space="preserve">var1(arg1,arg2 ... argN);
</pre></example>
<para>where each hyperslab argument is of the form
</para><example endspaces=" ">
<pre xml:space="preserve">start:end:stride 
</pre></example>
<para>and the arguments for different dimensions are separated by commas.
If <var>start</var> is omitted, it defaults to zero.
If <var>end</var> is omitted, it defaults to dimension size minus one.
If <var>stride</var> is omitted, it defaults to one.
</para><sp spaces=" " value="1" line="1"></sp>
<noindent></noindent> <para>If a single value is present then it is assumed that that
dimension collapses to a single value (i.e., a cross-section). 
The number of hyperslab arguments MUST equal the variable&textrsquo;s rank.
</para><sp spaces=" " value="1" line="1"></sp>

<noindent></noindent> <para><strong>Hyperslabs on the Right Hand Side of an assign&linebreak;</strong>
</para>
<para>A simple 1D example:
</para><example endspaces=" "> 
<verbatim xml:space="preserve" endspaces=" ">
($time.size=10)
od[$time]={20,22,24,26,28,30,32,34,36,38};

od(7);     // 34
od(7:);    // 34,36,38
od(:7);    // 20,22,24,26,28,30,32,34 
od(::4);   // 20,28,36
od(1:6:2)  // 22,26,30
od(:)      // 20,22,24,26,28,30,32,34,36,38 
</verbatim>
</example>

<para>A more complex three dimensional example:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
($lat.size=2,$lon.size=4)
th[$time,$lat,$lon]=      
                          {1, 2, 3, 4, 5, 6, 7, 8,
                          9,10,11,12,13,14,15,16,
                          17,18,19,20,21,22,23,24,
                          -99,-99,-99,-99,-99,-99,-99,-99,
                          33,34,35,36,37,38,39,40,
                          41,42,43,44,45,46,47,48,
                          49,50,51,52,53,54,55,56,
                          -99,58,59,60,61,62,63,64,
                          65,66,67,68,69,70,71,72,
                          -99,74,75,76,77,78,79,-99 };

th(1,1,3);        // 16
th(2,0,:);        // 17, 18, 19, 20
th(:,1,3);        // 8, 16, 24, -99, 40, 48, 56, 64, 72, -99 
th(::5,:,0:3:2); // 1, 3, 5, 7, 41, 43, 45, 47
</verbatim>
</example>

<para>If hyperslab arguments collapse to a single value (a cross-section has
been specified), then that dimension is removed from the returned
variable. 
If all the values collapse then a scalar variable is returned.
So, for example, the following is valid: 
</para><example endspaces=" ">
<pre xml:space="preserve">th_nw=th(0,:,:)+th(9,:,:); 
// th_nw has dimensions $lon,$lat 
// NB: the time dimension has become degenerate
</pre></example>

<para>The following is invalid:
</para><example endspaces=" ">
<pre xml:space="preserve">th_nw=th(0,:,0:1)+th(9,:,0:1);
</pre></example>
<para>because the <code>$lon</code> dimension now only has two elements.
The above can be calculated by using a LHS cast with 
<code>$lon_nw</code> as replacement dim for <code>$lon</code>: 
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;lon_nw&quot;,2);
th_nw[$lat,$lon_nw]=th(0,:,0:1)+th(9,:,0:1);
</pre></example>

<noindent></noindent> <para><strong>Hyperslabs on the Left Hand Side of an assign&linebreak;</strong>
When hyperslabing on the LHS, the expression on the RHS must 
evaluate to a scalar or a variable/attribute with the same number of 
elements as the LHS hyperslab.
Set all elements of the last record to zero:
</para><example endspaces=" ">
<pre xml:space="preserve">th(9,:,:)=0.0;
</pre></example>
<para>Set first element of each lon element to 1.0:
</para><example endspaces=" ">
<pre xml:space="preserve">th(:,:,0)=1.0;
</pre></example>
<para>One may hyperslab on both sides of an assign.
For example, this sets the last record to the first record:
</para><example endspaces=" ">
<pre xml:space="preserve">th(9,:,:)=th(0,:,:);
</pre></example>
<para>Say <var>th0</var> represents pressure at height=0 and 
<var>th1</var> represents pressure at height=1.
Then it is possible to insert these hyperslabs into the records
</para><example endspaces=" ">
<pre xml:space="preserve">prs[$time,$height,$lat,$lon]=0.0;
prs(:,0,:,:)=th0;
prs(:,1,:,:)=th1;
</pre></example>

<noindent></noindent> <para><strong>Reverse method</strong>&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="1388">reverse()</indexterm></cindex>
Use the <code>reverse()</code> method to reverse a dimension&textrsquo;s elements in a
variable with at least one dimension.
This is equivalent to a negative stride, e.g., 
</para><example endspaces=" "> 
<verbatim xml:space="preserve" endspaces=" ">
th_rv=th(1,:,:).reverse($lon); // {12,11,10,9 }, {16,15,14,13}
od_rv=od.reverse($time);        // {38,36,34,32,30,28,26,24,22,20}
</verbatim>
</example>

<noindent></noindent> <para><strong>Permute method</strong>p&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="1389">permute()</indexterm></cindex>
Use the <code>permute()</code> method to swap the dimensions of a variable.
The number and names of dimension arguments must match the dimensions in
the variable. 
If the first dimension in the variable is of record type then this must
remain the first dimension. 
If you want to change the record dimension then consider using
<command>ncpdq</command>. 
</para>
<para>Consider the variable:
</para><example endspaces=" ">
<pre xml:space="preserve">float three_dmn_var(lat,lev,lon);
three_dmn_var_prm=three_dmn_var.permute($lon,$lat,$lev);
// The permuted values are
three_dmn_var_prm= 
  0,4,8,
  12,16,20,
  1,5,9,
  13,17,21,
  2,6,10,
  14,18,22,
  3,7,11,
  15,19,23;
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ncap_att&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_att --&gt;
</html>
</subsection>
<node name="Attributes" spaces=" "><nodename>Attributes</nodename><nodenext spaces=" ">Value List</nodenext><nodeprev spaces=" ">Arrays and hyperslabs</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Attributes</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1390">attributes<command>ncap2</command></indexterm></cindex>
<para>Refer to attributes with <emph>var_nm&arobase;att_nm</emph>.
The following are all valid statements:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
global@text=&quot;Test Attributes&quot;; /* Assign a global variable attribute */
a1[$time]=time*20;
a1@long_name=&quot;Kelvin&quot;;
a1@min=a1.min();
a1@max=a1.max();
a1@min++;
--a1@max; 
a1(0)=a1@min;
a1($time.size-1)=a1@max;
</verbatim>
</example>

<para>NetCDF allows all attribute types to have a size between one
<code>NC_MAX_ATTRS</code>. 
Here is the metadata for variable <var>a1</var>:
</para><example endspaces=" "> 
<pre xml:space="preserve">double a1(time) ;
  a1:long_name = &quot;Kelvin&quot; ;
  a1:max = 199. ;
  a1:min = 21. ;
  a1:trip1 = 1, 2, 3 ;
  a1:triplet = 21., 110., 199. ;
</pre></example>

<para>These basic methods can be used with attributes:
<code>size()</code>, <code>type()</code>, and <code>exists()</code>.
For example, to save an attribute text string in a variable:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
defdim(&quot;sng_len&quot;,a1@long_name.size());
sng_arr[$sng_len]=a1@long_name; // sng_arr now contains &quot;Kelvin&quot; 
</verbatim>
</example>
<para>Attributes defined in a script are stored in memory and are written to
the output file after script completion. 
To stop the attribute being written use the <code>ram_delete()</code> method
or use a bogus variable name. 
</para>
<noindent></noindent> <para><strong>Attribute Propagation and Inheritance</strong>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1391">attribute propagation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1392">attribute inheritance</indexterm></cindex>
</para><itemize commandarg="bullet" spaces=" " endspaces=" "><itemprepend><formattingcommand command="bullet"/></itemprepend>
<beforefirstitem>  </beforefirstitem><listitem><prepend>&bullet;</prepend> <para>Attribute propagation occurs in a regular assign statement. The variable being defined on the LHS gets copies of the attributes from the leftermost variable on the RHS.
  </para></listitem><listitem><prepend>&bullet;</prepend> <para>Attribute Inheritance: The LHS variable &textldquo;inherits&textrdquo; attributes from an Input variable with the same name
  </para></listitem><listitem><prepend>&bullet;</prepend> <para>It is possible to have a regular assign statement for which both propagation and inheritance occur.
</para></listitem></itemize>

<example endspaces=" ">
<pre xml:space="preserve">// prs_mdp inherits attributes from P0:
prs_mdp[time,lat,lon,lev]=P0*hyam+hybm*PS;
// th_min inherits attributes from three_dmn_var_dbl:
th_min=1.0 + 2*three_dmn_var_dbl.min($time);
</pre></example>

<noindent></noindent> <para><strong>Attribute Concatenation&linebreak;</strong>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1393">attribute concatenation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1394">push</indexterm></cindex>
</para>
<para>The push() function concatenates attributes, or appends an &textldquo;expression&textrdquo; to a pre-existing attribute.
It comes in two forms
</para><example endspaces=" ">
<pre xml:space="preserve">(A) att_new=push(att_exp, expr)
(B) att_size=push(&amp;att_nm,expr)
</pre></example>

<noindent></noindent> <para>In form (A) The first argument should be an attribute
identifier or an expression that evaluates to an attribute. 
The second argument can evalute to an attribute or a variable. 
The second argument is then converted to the type of <var>att_exp</var>; 
and appended to <var>att_exp</var> ; and the resulting attribute is returned.&linebreak;
</para>
<noindent></noindent> <para>In form (B) the first argument is a call-by-reference
attribute identifier (which may not yet exist). 
The second argument is then evaluated (and type-converted as needed) and
appended to the call-by-reference atttribute. 
The final size of the attribute is then returned. 
</para>
<example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
temp@range=-10.0;
push(&amp;temp@range,12.0); // temp@range=-10.0,12.0

numbers@squares=push(1,4);
numbers@squares=push(numbers@squares,9);
push(&amp;number@squares,16.0); 
push(&amp;number@squares,25ull); // numbers@squares=1,4,9,16,25  
</verbatim>
</example>

<noindent></noindent> <para>Now some text examples.&linebreak; 
Remember, an atttribute identifier that begins with &arobase; implies a global
attribute.
For example, &textrsquo;&arobase;institution&textrsquo; is short for &textrsquo;global&arobase;institution&textrsquo;.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
global@greetings=push(&quot;hello&quot;,&quot; world !!&quot;);
global@greek={&quot;alpha&quot;s,&quot;beta&quot;s,&quot;gamma&quot;s};
// Append an NC_STRING
push(&amp;@greek,&quot;delta&quot;s);
// Pushing an NC_CHAR to a NC_STRING attribute is allowed, it is converted to an an NC_CHAR
@e=&quot;epsilon&quot;;
push(&amp;@greek,@e);
push(&amp;@greek,&quot;zeta&quot;); 

// Pushing a single NC_STRING to an NC_CHAR is not allowed
@h=&quot;hello&quot;;
push(&amp;@h,&quot; again&quot;s); // BAD PUSH
</verbatim>
</example>

<para>If the attribute name contains non-regular characters use ID quoting:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
'b..m1@c--lost'=23;
</verbatim>
</example>
<para>See <pxref label="ID-Quoting"><xrefnodename>ID Quoting</xrefnodename></pxref>.
</para>
<html endspaces=" ">
&lt;a name=&quot;value_list&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#value_list --&gt;
&lt;a name=&quot;initialize&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#initialize --&gt;
</html>
</subsection>
<node name="Value-List" spaces=" "><nodename>Value List</nodename><nodenext spaces=" ">Number literals</nodenext><nodeprev spaces=" ">Attributes</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Value List</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1395">value list<command>ncap2</command></indexterm></cindex>

<para>A <emph>value list</emph> is a special type of attribute. 
It can only be used on the RHS of the assign family of statements.&linebreak;
That is <emph>=, +=, -=, *=, /=</emph>&linebreak;
A value list CANNOT be involved in any logical, binary, or arithmetical operations (except those above).&linebreak; 
A value list CANNOT be used as a function argument.&linebreak;
A value list CANNOT have nested value lists.&linebreak;
The type of a value list is the type of the member with the highest type.&linebreak;
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1396">value list</indexterm></cindex>
<example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
a1@trip={1,2,3};
a1@trip+={3,2,1}; // 4,4,4
a1@triplet={a1@min,(a1@min+a1@max)/2,a1@max}; 
lon[lon]={0.0,90.0,180.0,270.0};
lon*={1.0,1.1,1.2,1.3} 
dlon[lon]={1b,2s,3ull,4.0f}; // final type NC_FLOAT

a1@ind={1,2,3}+{4,4,4}; // BAD
a1@s=sin({1.0,16.0}); // BAD
</verbatim>
</example>

<noindent></noindent> <para>One can also use a value_list to create an attribute of type
NC_STRING. 
Remember, a literal string of type NC_STRING has a postfix &textrsquo;s&textrsquo;. 
A value list of NC_CHAR has no semantic meaning and is plain wrong.   
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
array[lon]={1.0,2.,4.0,7.0};
array@numbers={&quot;one&quot;s, &quot;two&quot;s, &quot;four&quot;s, &quot;seven&quot;s}; // GOOD

ar[lat]={0,20} 
ar@numbers={&quot;zero&quot;,&quot;twenty&quot;}; // BAD
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;ncap_num&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_num --&gt;
&lt;a name=&quot;ncap_string&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_string --&gt;
</html>
</subsection>
<node name="Number-literals" spaces=" "><nodename>Number literals</nodename><nodenext spaces=" ">if statement</nodenext><nodeprev spaces=" ">Value List</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Number literals</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1397">number literals <command>ncap2</command></indexterm></cindex>
<para>The table below lists the postfix character(s) to add to a number
literal (aka, a naked constant) for explicit type specification.
The same type-specification rules are used for variables and
attributes. 
A floating-point number without a postfix defaults to <code>NC_DOUBLE</code>, 
while an integer without a postfix defaults to type <code>NC_INT</code>:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
var[$rlev]=0.1;     // Variable will be type NC_DOUBLE
var[$lon_grd]=2.0;  // Variable will be type NC_DOUBLE
var[$gds_crd]=2e3;  // Variable will be type NC_DOUBLE
var[$gds_crd]=2.0f; // Variable will be type NC_FLOAT (note &quot;f&quot;)
var[$gds_crd]=2e3f; // Variable will be type NC_FLOAT (note &quot;f&quot;)
var[$gds_crd]=2;    // Variable will be type NC_INT
var[$gds_crd]=-3;   // Variable will be type NC_INT
var[$gds_crd]=2s;   // Variable will be type NC_SHORT
var[$gds_crd]=-3s;  // Variable will be type NC_SHORT
var@att=41.;        // Attribute will be type NC_DOUBLE
var@att=41.f;       // Attribute will be type NC_FLOAT
var@att=41;         // Attribute will be type NC_INT
var@att=-21s;       // Attribute will be type NC_SHORT  
var@units=&quot;kelvin&quot;; // Attribute will be type NC_CHAR
</verbatim>
</example> 
<para>There is no postfix for characters, use a quoted string instead for 
<code>NC_CHAR</code>.
<command>ncap2</command> interprets a standard double-quoted string as a value
of type <code>NC_CHAR</code>. 
In this case, any receiving variable must be dimensioned as an array
of <code>NC_CHAR</code> long enough to hold the value.
</para>
<para>To use the newer netCDF4 types <acronym><acronymword>NCO</acronymword></acronym> must be compiled/linked to
the netCDF4 library and the output file must be of type <code>NETCDF4</code>:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
var[$time]=1UL;    // Variable will be type @code{NC_UINT}
var[$lon]=4b;      // Variable will be type @code{NC_BYTE}
var[$lat]=5ull;    // Variable will be type @code{NC_UINT64}  
var[$lat]=5ll;     // Variable will be type @code{NC_INT64}  
var@att=6.0d;      // Attribute will be type @code{NC_DOUBLE}
var@att=-666L;     // Attribute will be type @code{NC_INT}
var@att=&quot;kelvin&quot;s; // Attribute will be type @code{NC_STRING} (note the &quot;s&quot;)
</verbatim>
</example>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1398"><code>NC_CHAR</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1399"><code>NC_STRING</code></indexterm></cindex>
<para>Use a post-quote <samp>s</samp> for <code>NC_STRING</code>.
Place the letter <samp>s</samp> immediately following the double-quoted string
to indicate that the value is of type <code>NC_STRING</code>.
In this case, the receiving variable need not have any memory allocated
to hold the string because netCDF4 handles that memory allocation.
</para>
<para>Suppose one creates a file containing an ensemble of model results, and
wishes to label the record coordinate with the name of each model.
The <code>NC_STRING</code> type is well-suited to this because it facilitates
storing arrays of strings of arbitrary length.
This is sophisticated, though easy with <command>ncap2</command>:
</para><example endspaces=" "> 
<verbatim xml:space="preserve" endspaces=" ">
% ncecat -O -u model cesm.nc ecmwf.nc giss.nc out.nc
% ncap2 -4 -O -s 'model[$model]={&quot;cesm&quot;s,&quot;ecmwf&quot;s,&quot;giss&quot;s}' out.nc out.nc
</verbatim>
</example> 
<para>The key here to place an <samp>s</samp> character after each double-quoted
string value to indicate an <code>NC_STRING</code> type. 
The <samp>-4</samp> ensures the output filetype is netCDF4 in case the input
filetype is not. 
</para>
<table commandarg="asis" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="asis"><strong>netCDF3/4 Types</strong></itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">b|B	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_BYTE</code>, a signed 1-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">none	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_CHAR</code>, an ISO/ASCII character 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">s|S	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_SHORT</code>, a signed 2-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">l|L	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_INT</code>, a signed 4-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">f|F	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_FLOAT</code>, a single-precision (4-byte) floating-point number 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">d|D</itemformat></item>
</tableterm><tableitem>  <para><code>NC_DOUBLE</code>, a double-precision (8-byte) floating-point number 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><strong>netCDF4 Types</strong></itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">ub|UB	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_UBYTE</code>, an unsigned 1-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">us|US </itemformat></item>
</tableterm><tableitem>  <para><code>NC_USHORT</code>, an unsigned 2-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">u|U|ul|UL	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_UINT</code>, an unsigned 4-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">ll|LL	 </itemformat></item>
</tableterm><tableitem>  <para><code>NC_INT64</code>, a signed 8-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">ull|ULL </itemformat></item>
</tableterm><tableitem>  <para><code>NC_UINT64</code>, an unsigned 8-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">s </itemformat></item>
</tableterm><tableitem>  <para><code>NC_STRING</code>, a string of arbitrary length
</para></tableitem></tableentry></table>

<html endspaces=" ">
&lt;a name=&quot;ncap_if&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_if --&gt;
</html>
</subsection>
<node name="if-statement" spaces=" "><nodename>if statement</nodename><nodenext spaces=" ">Print &amp; String methods</nodenext><nodeprev spaces=" ">Number literals</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>if statement</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1400">if()</indexterm></cindex> 
<para>The syntax of the if statement is similar to its C counterpart. 
The <emph>Conditional Operator (ternary operator)</emph> has also been
implemented. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
if(exp1)
   stmt1;
else if(exp2)     
   stmt2;
else
   stmt3;

# Can use code blocks as well:
if(exp1){
   stmt1;
   stmt1a;
   stmt1b;
}else if(exp2)     
   stmt2; 
else{
   stmt3;
   stmt3a;
   stmt3b;
}   
</verbatim>
</example>

<!-- comment Truth -->
<noindent></noindent> <para>For a variable or attribute expression to be logically true
all its non-missing value elements must be logically true, i.e.,
non-zero. 
The expression can be of any type. 
<w>Unlike C</w> there is no short-circuiting of an expression with the 
OR (<code>||</code>) and AND (<code>&amp;&amp;</code>) operators. 
The whole expression is evaluated regardless if one of the AND/OR
operands are True/False.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Simple example
if(time &gt; 0)
  print(&quot;All values of time are greater than zero\n&quot;);
else if(time &lt; 0)
  print(&quot;All values of time are less than zero\n&quot;);   
else {
  time_max=time.max();
  time_min=time.min();
  print(&quot;min value of time=&quot;);print(time_min,&quot;%f&quot;);
  print(&quot;max value of time=&quot;);print(time_max,&quot;%f&quot;);
}

# Example from ddra.nco
if(fl_typ == fl_typ_gcm){
  var_nbr_apx=32;
  lmn_nbr=1.0*var_nbr_apx*varsz_gcm_4D; /* [nbr] Variable size */
  if(nco_op_typ==nco_op_typ_avg){
    lmn_nbr_avg=1.0*var_nbr_apx*varsz_gcm_4D; // Block size
    lmn_nbr_wgt=dmnsz_gcm_lat; /* [nbr] Weight size */
  } // !nco_op_typ_avg
}else if(fl_typ == fl_typ_stl){
  var_nbr_apx=8;
  lmn_nbr=1.0*var_nbr_apx*varsz_stl_2D; /* [nbr] Variable size */
  if(nco_op_typ==nco_op_typ_avg){
    lmn_nbr_avg=1.0*var_nbr_apx*varsz_stl_2D; // Block size
    lmn_nbr_wgt=dmnsz_stl_lat; /* [nbr] Weight size */
  } // !nco_op_typ_avg
} // !fl_typ
</verbatim>
</example>

<noindent></noindent> <para><strong>Conditional Operator&linebreak;</strong>
</para><example endspaces=" ">
<pre xml:space="preserve">// netCDF4 needed for this example
th_nw=(three_dmn_var_sht &gt;= 0 ? three_dmn_var_sht.uint() : \
       three_dmn_var_sht.int()); 
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ncap_prn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_prn --&gt;
</html>
</subsection>
<node name="Print-_0026-String-methods" spaces=" "><nodename>Print &amp; String methods</nodename><nodenext spaces=" ">Missing values ncap2</nodenext><nodeprev spaces=" ">if statement</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Print &amp; String methods</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1401">print() <command>ncap2</command></indexterm></cindex>

<para>The print statement comes in a variety of forms:
</para><example endspaces=" ">
<pre xml:space="preserve">(A)   print(variable_name, format string?);
(A1)  print(expression/string, format string?);

(B)   sprint(expression/string, format string?);
(B1)  sprint4(expression/string, format string?);
</pre></example>  

<noindent></noindent> <para><strong>print() &linebreak;&linebreak;</strong>
If the variable exists in I/O then it is printed in a similar fashion to <code>ncks -H</code>.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
print(lon);
lon[0]=0 
lon[1]=90 
lon[2]=180 
lon[3]=270 

print(byt_2D)
lat[0]=-90 lon[0]=0 byt_2D[0]=0 
lat[0]=-90 lon[1]=90 byt_2D[1]=1 
lat[0]=-90 lon[2]=180 byt_2D[2]=2 
lat[0]=-90 lon[3]=270 byt_2D[3]=3 
lat[1]=90 lon[0]=0 byt_2D[4]=4 
lat[1]=90 lon[1]=90 byt_2D[5]=5 
lat[1]=90 lon[2]=180 byt_2D[6]=6 
lat[1]=90 lon[3]=270 byt_2D[7]=7 
</verbatim>
</example>

<noindent></noindent> <para>If the first argument is NOT a variable the form (A1) is invoked.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
print(mss_val_fst@_FillValue);
mss_val_fst@_FillValue, size = 1 NC_FLOAT, value = -999

print(&quot;This function \t is monotonic\n&quot;);
This function is 	  monotonic

print(att_var@float_att)
att_var@float_att, size = 7 NC_FLOAT, value = 73, 72, 71, 70.01, 69.001, 68.01, 67.01

print(lon*10.0)
lon, size = 4 NC_DOUBLE, value = 0, 900, 1800, 2700
</verbatim>
</example>

<noindent></noindent> <para>If the format string is specified then the results from (A) and (A1) forms are the same
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
print(lon_2D_rrg,&quot;%3.2f,&quot;);
0.00,0.00,180.00,0.00,180.00,0.00,180.00,0.00,

print(lon*10.0,&quot;%g,&quot;)
0,900,1800,2700,

print(att_var@float_att,&quot;%g,&quot;)
73,72,71,70.01,69.001,68.01,67.01,
</verbatim>
</example>

<noindent></noindent> <para><strong>sprint() &amp; sprint4() &linebreak;&linebreak;</strong>
These functions work in an identical fashion to (A1) except that <code>sprint()</code> outputs a regular netCDF3 <code>NC_CHAR</code> attribute 
and <code>sprint4()</code> outputs a netCDF4 <code>NC_STRING</code> attribute
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
time@units=sprint(yyyy,&quot;days since %d-1-1&quot;)
bnd@num=sprint4(bnd_idx,&quot;Band number=%d&quot;)

time@arr=sprint4(time,&quot;%.2f,&quot;) // &quot;1.00,2.00,3.00,4.00,5.00,6.00,7.00,8.00,9.00,10.00,&quot;
</verbatim>
</example>

<noindent></noindent> <para>You can also use <code>sprint4()</code> to convert a <code>NC_CHAR</code> string to a <code>NC_STRING</code> string 
and <code>sprint()</code> to convert a <code>NC_STRING</code> to a <code>NC_CHAR</code>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
lat_1D_rct@long_name = &quot;Latitude for 2D rectangular grid stored as 1D arrays&quot;; // 

// convert to NC_STRING
lat_1D_rct@long_name = sprint4(lat_1D_rct@long_name) 
</verbatim>
</example>

<noindent></noindent> <para><strong>hyperslab a netCDF string &linebreak;&linebreak;</strong>
It is possible to index-into an NC_CHAR string, similar to a C-String.
Unlike a C-String, however, an NC_CHAR string has no null-character to
mark its termination.
One CANNOT index into an NC_STRING string.
One must must convert to an NC_CHAR first. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
global@greeting=&quot;hello world!!!&quot;
@h=@greeting(0:4);  // &quot;hello&quot;
@w=@greeting(6:11); // &quot;world&quot;

// can use negative inidices
@x=@greeting(-3:-1);  // &quot;!!!&quot;

// can  use stride
@n=@greeting(::2);  // &quot;hlowrd!&quot;

// concatenation
global@new_greeting=push(@h, &quot; users !!!&quot;); // &quot;hello users!!!&quot;

@institution=&quot;hotel california&quot;s; 
@h=@institution(0:4); // BAD 

// convert NC_STRING to NC_CHAR
@is=sprint(@institution);
@h=@is(0:4);  // &quot;hotel&quot;

// convert NC_CHAR to NC_STRING
@h=sprint4(@h);
</verbatim>
</example>

<noindent></noindent> <para><strong>get_vars_in() &amp; get_vars_out()</strong>
</para><example endspaces=" ">
<pre xml:space="preserve">att_lst=get_vars_in(att_regexp?) 
att_lst=get_vars_out(att_regexp?) 
</pre></example>

<para>These functions are used to create a list of vars in Input or Output. The optional arg &textrsquo;att_regexp&textrsquo;. Can be an NC_CHAR att or a NC_STRING att. If NC_CHAR then only a single reg-exp can be specified. If NC_STRING then multiple reg-exp can be specified.  The output is allways an NC_STRING att. The matching works in an identical fashion to the -v switch in ncks. if there is no arg then all vars are returned.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
@slist=get_vars_in(&quot;^time&quot;);  // &quot;time&quot;, &quot;time_bnds&quot;, &quot;time_lon&quot;, &quot;time_udunits&quot;
// Use NC_STRINGS
@regExp={&quot;.*_bnd&quot;s,&quot;.*_grd&quot;s}
@slist=get_vars_in(@regExp);  // &quot;lat_bnd&quot;, &quot;lat_grd&quot;, &quot;lev_bnd&quot;, &quot;lon_grd&quot;, &quot;time_bnds&quot;, &quot;cnv_CF_grd&quot;
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;ncap_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_miss --&gt;
</html>
</subsection>
<node name="Missing-values-ncap2" spaces=" "><nodename>Missing values ncap2</nodename><nodenext spaces=" ">Methods and functions</nodenext><nodeprev spaces=" ">Print &amp; String methods</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Missing values ncap2</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1402">missing values ncap2</indexterm></cindex>
<para>Missing values operate slightly differently in <command>ncap2</command> 
Consider the expression where op is any of the following operators (excluding &textrsquo;=&textrsquo;)
</para><example endspaces=" ">
<pre xml:space="preserve">Arithmetic operators ( * / % + - ^ )
Binary Operators     ( &gt; &gt;= &lt; &lt;= == != == || &amp;&amp; &gt;&gt; &lt;&lt; ) 
Assign Operators     ( += -= /= *= ) 

var1 'op' var2
</pre></example>

<noindent></noindent> <para>If var1 has a missing value then this is the value used in the 
operation, otherwise the missing value for var2 is used. 
If during the element-by-element operation an element from either
operand is equal to the missing value then the missing value is carried 
through. 
In this way missing values &textrsquo;percolate&textrsquo; or propagate through an
expression.&linebreak;  
Missing values associated with Output variables are stored in memory and
are written to disk after the script finishes. 
During script execution its possible (and legal) for the missing value
of a variable to take on several different values. 
</para><example endspaces=" "> 
<pre xml:space="preserve"># Consider the variable:
int rec_var_int_mss_val_int(time); =-999,2,3,4,5,6,7,8,-999,-999;
rec_var_int_mss_val_int:_FillValue = -999;

n2=rec_var_int_mss_val_int + rec_var_int_mss_val_int.reverse($time); 

n2=-999,-999,11,11,11,11,11,11,999,-999;
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;missing&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#missing --&gt;
&lt;a name=&quot;mask_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mask_miss --&gt;
&lt;a name=&quot;has_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#has_miss --&gt;
&lt;a name=&quot;delete_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#delete_miss --&gt;
&lt;a name=&quot;set_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#set_miss --&gt;
&lt;a name=&quot;get_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#get_miss --&gt;
&lt;a name=&quot;change_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#change_miss --&gt;
&lt;a name=&quot;number_miss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#number_miss --&gt;
</html>

<para>The following methods query or manipulate missing value (aka
<code>_FillValue</code> information associated with a variable.
The methods that &textldquo;manipulate&textrdquo; only succeed on variables in Output.
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">set_miss(expr)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1403"><code>set_miss()</code></indexterm></cindex>
 <para>The numeric argument <var>expr</var> becomes the new missing value,
 overwriting the old missing value, if any.
 The argument given is converted if necessary to the variable&textrsquo;s type.
 NB: This only changes the missing value attribute.
 Missing values in the original variable remain unchanged, and thus 
 are no long considered missing values.
 They are effectively &textldquo;orphaned&textrdquo;.
 Thus <code>set_miss()</code> is normally used only when creating new
 variables.
 The intrinsic function <code>change_miss()</code> (see below) is typically 
 used to edit values of existing variables.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">change_miss(expr)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1404"><code>change_miss()</code></indexterm></cindex>
 <para>Sets or changes (any pre-existing) missing value attribute and missing 
 data values to <var>expr</var>. 
 NB: This is an expensive function since all values must be examined. 
 Use this function when changing missing values for pre-existing
 variables. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">get_miss() </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1405"><code>get_miss()</code></indexterm></cindex>
 <para>Returns the missing value of a variable. 
 If the variable exists in Input and Output then the missing value of
 the variable in Output is returned. 
 If the variable has no missing value then an error is returned.   
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">delete_miss()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1406"><code>delete_miss()</code></indexterm></cindex>
 <para>Delete the missing value associated with a variable.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">number_miss()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1407"><code>number_miss()</code></indexterm></cindex>
 <para>Count the number of missing values a variable contains.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">has_miss()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1408"><code>has_miss()</code></indexterm></cindex>
<para>Returns 1 (True) if the variable has a missing value associated with it. 
else returns 0 (False)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">missing()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1409"><code>missing(), mask_miss()</code></indexterm></cindex>
<para>This function creates a True/False mask array of where the missing value is set.
It is syntatically equivalent to <code>(var_in == var_in.get_miss())</code>,
except that requires deleting the missing value before-hand.
</para></tableitem></tableentry></table>

<example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
th=three_dmn_var_dbl;
th.change_miss(-1e10d);
/* Set values less than 0 or greater than 50 to missing value */
where(th &lt; 0.0 || th &gt; 50.0) th=th.get_miss();

# Another example:
new[$time,$lat,$lon]=1.0;
new.set_miss(-997.0);

// Extract all elements evenly divisible by 3
where (three_dmn_var_dbl%3 == 0)
     new=three_dmn_var_dbl; 
elsewhere
     new=new.get_miss();   

// Print missing value and variable summary
mss_val_nbr=three_dmn_var_dbl.number_miss();
print(three_dmn_var_dbl@_FillValue);
print(&quot;Number of missing values in three_dmn_var_dbl: &quot;);
print(mss_val_nbr,&quot;%d&quot;);
print(three_dmn_var_dbl);

// Find total number of missing values along dims $lat and $lon
mss_ttl=three_dmn_var_dbl.missing().ttl($lat,$lon);
print(mss_ttl); // 0, 0, 0, 8, 0, 0, 0, 1, 0, 2 ;
</verbatim>
</example>

<table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">simple_fill_miss(var)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1410"><code>simple_fill_miss()</code></indexterm></cindex>
<para>This function takes a variable and attempts to fill missing values using an average
of up to the 4 nearest neighbour grid points. The method used is iterative (up to 1000 cycles).
For very large areas of missing values results can be unpredictable.
The given variable must be at least 2D; and the algorithm assumes that the last two dims are lat/lon
or y/x
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">weighted_fill_miss(var)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1411"><code>weighted_fill_miss()</code></indexterm></cindex>
<para>Weighted_fill_miss is more sophisticated. Up to 8 nearest neighbours  are used to calculate a weighted average.
The weighting used is the inverse  square of distance. Again the method is iterative (up to 1000 cycles).
The area filled is defined by the final  two dims of the variable. In addition this function assumes the existance of
coordinate vars the same name as the last two dims. if it doesn&textrsquo;t find these dims it will gently exit with warning.
</para></tableitem></tableentry></table>

<html endspaces=" ">
&lt;a name=&quot;ncap_mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_mth --&gt;
&lt;a name=&quot;ncap2_mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap2_mth --&gt;
</html>
</subsection>
<node name="Methods-and-functions" spaces=" "><nodename>Methods and functions</nodename><nodenext spaces=" ">RAM variables</nodenext><nodeprev spaces=" ">Missing values ncap2</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Methods and functions</sectiontitle>

<para>The convention within this document is that methods can be used as 
functions. 
However, functions are not and cannot be used as methods.
Methods can be daisy-chained d and their syntax is cleaner than functions. 
Method names are reserved words and CANNOT be used as variable names.  
The command <code>ncap2 -f</code> shows the complete list of methods available
on your build. 
</para><example endspaces=" ">
<pre xml:space="preserve">n2=sin(theta) 
n2=theta.sin() 
n2=sin(theta)^2 + cos(theta)^2 
n2=theta.sin().pow(2) + theta.cos()^2
</pre></example>

<para>This statement chains together methods to convert three_dmn_var_sht to
type double, average it, then convert this back to type short: 
</para><example endspaces=" ">
<pre xml:space="preserve">three_avg=three_dmn_var_sht.double().avg().short();
</pre></example>

<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent> <para><strong>Aggregate Methods &linebreak;</strong> 
These methods mirror the averaging types available in <command>ncwa</command>. The arguments to the methods are the dimensions to average over. Specifying no dimensions is equivalent to specifying all dimensions i.e., averaging over all dimensions. A masking variable and a weighting variable can be manually created and applied as needed.
</para>
<table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">avg()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1412">avg()</indexterm></cindex>
<para>Mean value 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">sqravg()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1413">sqravg()</indexterm></cindex>
<para>Square of the mean
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">avgsqr()</itemformat></item>
</tableterm><tableitem><para>Mean of sum of squares
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">max()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1414">max()</indexterm></cindex>
<para>Maximum value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">min()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1415">min()</indexterm></cindex>
<para>Minimum value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">mabs()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1416">mabs()</indexterm></cindex>
<para>Maximum absolute value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">mebs()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1417">mebs()</indexterm></cindex>
<para>Mean absolute value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">mibs()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1418">mibs()</indexterm></cindex>
<para>Minimum absolute value
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">rms()</itemformat></item>
</tableterm><tableitem><para>Root-mean-square (normalize by <var>N</var>)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">rmssdn()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1419">rmssdn()</indexterm></cindex>
<para>Root-mean square (normalize by <var>N-1</var>)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">tabs() or ttlabs()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1420">tabs()</indexterm></cindex>
<para>Sum of absolute values
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ttl() or total() or sum()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1421">ttl()</indexterm></cindex>
<para>Sum of values
</para></tableitem></tableentry></table>

<example endspaces=" ">
<pre xml:space="preserve">// Average a variable over time
four_time_avg=four_dmn_rec_var($time);
</pre></example>

<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent> <para><strong>Packing Methods &linebreak;</strong>
For more information see <pxref label="Packed-data"><xrefnodename>Packed data</xrefnodename></pxref> and <pxref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></pxref>&linebreak;
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">pack() &amp; pack_short()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1422">pack()</indexterm></cindex>
<para>The default packing algorithm is applied and variable is packed to <code>NC_SHORT</code>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">pack_byte()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1423">pack_byte()</indexterm></cindex>
<para>Variable is packed to <code>NC_BYTE</code>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">pack_short()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1424">pack_short()</indexterm></cindex>
<para>Variable is packed to <code>NC_SHORT</code>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">pack_int()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1425">pack_int()</indexterm></cindex>
<para>Variable is packed to <code>NC_INT</code>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">unpack()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1426">unpack()</indexterm></cindex>
<para>The standard unpacking algorithm is applied. 
</para></tableitem></tableentry></table>
<para><acronym><acronymword>NCO</acronymword></acronym> automatically unpacks packed data before arithmetically
modifying it. 
After modification <acronym><acronymword>NCO</acronymword></acronym> stores the unpacked data.
To store it as packed data again, repack it with, e.g., the 
<code>pack()</code> function.
To ensure that <code>temperature</code> is packed in the output file,
regardless of whether it is packed in the input file, one uses, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'temperature=pack(temperature-273.15)' in.nc out.nc
</pre></example>

<para>All the above pack functions also take the additional two arguments
<code>scale_factor, add_offset</code>.
Both arguments must be included:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -v -O -s 'rec_pck=pack(three_dmn_rec_var,-0.001,40.0);' in.nc foo.nc
</pre></example>

<para><strong>Basic Methods &linebreak;</strong>
These methods work with variables and attributes. They have no arguments.
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">size()	</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1427">size()</indexterm></cindex>
<para>Total number of elements 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ndims()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1428">ndims()</indexterm></cindex>
<para>Number of dimensions in variable
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">type() </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1429">type()</indexterm></cindex>
<para>Returns the netcdf type (see previous section)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">exists()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1430">exists()</indexterm></cindex>
<para>Return 1 (true) if var or att is present in I/O else return 0 (false)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">getdims()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1431">getdims()</indexterm></cindex>
<para>Returns an NC_STRING attribute of all the dim names of a variable
</para></tableitem></tableentry></table>

<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent> <para><strong>Utility Methods &linebreak;</strong>
These functions are used to manipulate missing values and <acronym><acronymword>RAM</acronymword></acronym> variables.
<pxref label="Missing-values-ncap2"><xrefnodename>Missing values ncap2</xrefnodename></pxref> 
</para>
<table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">set_miss(expr)</itemformat></item>
</tableterm><tableitem> <para>Takes one argument, the missing value. Sets or overwrites the existing
 missing value. The argument given is converted if necessary to the
 variable type. (NB: pre-existing missing values, if any, are not converted).
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">change_miss(expr)</itemformat></item>
</tableterm><tableitem> <para>Changes the missing value elements of the variable to the new missing
 value (NB: an expensive function).
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">get_miss() </itemformat></item>
</tableterm><tableitem> <para>Returns the missing value of a variable in Input or Output  
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">delete_miss()</itemformat></item>
</tableterm><tableitem> <para>Deletes the missing value associated with a variable.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">has_miss()</itemformat></item>
</tableterm><tableitem> <para>Returns 1 (True) if the variable has a missing else returns 0 (False)
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">number_miss</itemformat></item>
</tableterm><tableitem> <para>Returns the number of missing values a variable contains
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ram_write()</itemformat></item>
</tableterm><tableitem> <para>Writes a <acronym><acronymword>RAM</acronymword></acronym> variable to disk i.e., converts it to a regular disk type variable
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ram_delete()</itemformat></item>
</tableterm><tableitem> <para>Deletes a <acronym><acronymword>RAM</acronymword></acronym> variable or an attribute 
</para></tableitem></tableentry></table>

<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent> <para><strong>PDQ Methods&linebreak;</strong>
See <pxref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></pxref>
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">reverse(dim args)</itemformat></item>
</tableterm><tableitem> <para>Reverse the dimension ordering of elements in a variable. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">permute(dim args)</itemformat></item>
</tableterm><tableitem> <para>Re-shape variables by re-ordering the dimensions. 
 All the dimensions of the variable must be specified in the
 arguments. 
 A limitation of this permute (unlike <command>ncpdq</command>) is that the
 record dimension cannot be re-assigned.  
</para></tableitem></tableentry></table> 
<para>// Swap dimensions about and reorder along lon
</para><example endspaces=" ">
<pre xml:space="preserve">lat_2D_rrg_new=lat_2D_rrg.permute($lon,$lat).reverse($lon);
lat_2D_rrg_new=0,90,-30,30,-30,30,-90,0
</pre></example>

<sp spaces=" " value="1" line="1"></sp>
<noindent></noindent> <para><strong>Type Conversion Methods and Functions&linebreak;</strong>
These methods allow <command>ncap2</command> to convert variables and
attributes to the different netCDF types. 
For more details on automatic and manual type conversion see
(<pxref label="Type-Conversion"><xrefnodename>Type Conversion</xrefnodename></pxref>). 
netCDF4 types are only available if you have compiled/links
<acronym><acronymword>NCO</acronymword></acronym> with the netCDF4 library and the Output file is
<acronym><acronymword>HDF5</acronymword></acronym>.
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code"><strong>netCDF3/4 Types</strong></itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">byte()	 </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1432">byte()</indexterm></cindex>
 <para>convert to <code>NC_BYTE</code>,  a signed 1-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">char()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1433">char()</indexterm></cindex>	 
 <para>convert to <code>NC_CHAR</code>,  an ISO/ASCII character
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">short()	</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1434">sshort()</indexterm></cindex> 
 <para>convert to <code>NC_SHORT</code>, a signed 2-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">int()	 </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1435">int()</indexterm></cindex>
 <para>convert to <code>NC_INT</code>,   a signed 4-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">float()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1436">float()</indexterm></cindex>	 
 <para>convert to <code>NC_FLOAT</code>, a single-precision (4-byte) floating-point number 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">double() </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1437">double()</indexterm></cindex>
 <para>convert to <code>NC_DOUBLE</code>, a double-precision (8-byte) floating-point number 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code"><strong>netCDF4 Types</strong></itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ubyte()	 </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1438">ubyte()</indexterm></cindex>
 <para>convert to <code>NC_UBYTE</code>, an unsigned 1-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ushort() </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1439">ushort()</indexterm></cindex>
 <para>convert to <code>NC_USHORT</code>, an unsigned 2-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">uint()</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1440">uint()</indexterm></cindex>	 
 <para>convert to <code>NC_UINT</code>, an unsigned 4-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">int64()	</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1441">int64()</indexterm></cindex> 
 <para>convert to <code>NC_INT64</code>, a signed 8-byte integer 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">uint64() </itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1442">unit64()</indexterm></cindex>
 <para>convert to <code>NC_UINT64</code>, an unsigned 8-byte integer
</para></tableitem></tableentry></table>

<para>You can also use the <code>convert()</code> method to do type conversion. 
This takes an integer agument. 
For convenience, <command>ncap2</command> defines the netCDF pre-processor tokens
as <acronym><acronymword>RAM</acronymword></acronym> variables. 
For example you may wish to convert a non-floating point variable to the
same type as another variable. 
</para><example endspaces=" ">
<pre xml:space="preserve">lon_type=lon.type();
if(time.type() != NC_DOUBLE &amp;&amp; time.type() != NC_FLOAT) 
   time=time.convert(lon_type);
</pre></example>

<noindent></noindent> <para><strong>Intrinsic Mathematical Methods &linebreak;</strong>
The list of mathematical methods is system dependant.
For the full list <pxref label="Intrinsic-mathematical-methods"><xrefnodename>Intrinsic mathematical methods</xrefnodename></pxref> 
</para>
<para>All the mathematical methods take a single argument except <code>atan2()</code>
and <code>pow()</code> which take two. 
If the operand type is less than <emph>float</emph> then the result will be of
type <emph>float</emph>. 
Arguments of type <emph>double</emph> yield results of type <emph>double</emph>. 
Like the other methods, you are free to use the mathematical methods as functions. 
</para>
<example endspaces=" ">
<pre xml:space="preserve">n1=pow(2,3.0f)    // n1 type float
n2=atan2(2,3.0)   // n2 type double
n3=1/(three_dmn_var_dbl.cos().pow(2))-tan(three_dmn_var_dbl)^2; // n3 type double
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ncap_ram&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_ram --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1443"><acronym><acronymword>RAM</acronymword></acronym> variables</indexterm></cindex>
</subsection>
<node name="RAM-variables" spaces=" "><nodename>RAM variables</nodename><nodenext spaces=" ">Where statement</nodenext><nodeprev spaces=" ">Methods and functions</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle><acronym><acronymword>RAM</acronymword></acronym> variables</sectiontitle>
<para>Unlike regular variables, <acronym><acronymword>RAM</acronymword></acronym> variables are never written to disk.
Hence using <acronym><acronymword>RAM</acronymword></acronym> variables in place of regular variables (especially
within loops) significantly increases execution speed.
Variables that are frequently accessed within <code>for</code> or <code>where</code>
clauses provide the greatest opportunities for optimization. 
To declare and define a <acronym><acronymword>RAM</acronymword></acronym> variable simply prefix the variable name
with an asterisk (<code>*</code>) when the variable is declared/initialized.
To delete <acronym><acronymword>RAM</acronymword></acronym> variables (and recover their memory) use the
<code>ram_delete()</code> method. 
To write a <acronym><acronymword>RAM</acronymword></acronym> variable to disk (like a regular variable) use
<code>ram_write()</code>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1444">ram_write()</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1445">ram_delete()</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">*temp[$time,$lat,$lon]=10.0;     // Cast
*temp_avg=temp.avg($time);      // Regular assign
temp.ram_delete();              // Delete RAM variable
temp_avg.ram_write();           // Write Variable to output

// Create and increment a RAM variable from &quot;one&quot; in Input
*one++;   
// Create RAM variables from the variables three and four in Input.
// Multiply three by 10 and add it to four. 
*four+=*three*=10; // three=30, four=34 
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;where&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#where --&gt;
&lt;a name=&quot;ncap_whr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_whr --&gt;
&lt;a name=&quot;ncap_where&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_where --&gt;
</html>
</subsection>
<node name="Where-statement" spaces=" "><nodename>Where statement</nodename><nodenext spaces=" ">Loops</nodenext><nodeprev spaces=" ">RAM variables</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Where statement</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1446">where()</indexterm></cindex>
<para>The <code>where()</code> statement combines the definition and application of
a mask and can lead to succinct code.  
The syntax of a <code>where()</code> statement is:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
// Single assign ('elsewhere' is optional)
where(mask)
   var1=expr1;
elsewhere
   var1=expr2;	   	

// Multiple assigns
where(mask){
    var1=expr1;
    var2=expr2;
    ...
}elsewhere{
    var1=expr3
    var2=expr4
    var3=expr5;
    ...
}
</verbatim>
</example>

<itemize commandarg="bullet" spaces=" " endspaces=" "><itemprepend><formattingcommand command="bullet"/></itemprepend>
<listitem><prepend>&bullet;</prepend> <para>The only expression allowed in the predicate of a where is assign,
i.e., &textrsquo;var=expr&textrsquo;. 
This assign differs from a regular <command>ncap2</command> assign. 
The LHS var must already exist in Input or Output. 
The RHS expression must evaluate to a scalar or a variable/attribute of
the same size as the LHS variable.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Consider when both the LHS and RHS are variables: 
For every element where mask condition is True, the corresponding LHS
variable element is re-assigned to its partner element on the RHS. 
In the elsewhere part the mask is logically inverted and the assign
process proceeds as before.
</para></listitem><listitem><prepend>&bullet;</prepend> <para>If the mask dimensions are a subset of the LHS variable&textrsquo;s
dimensions, then it is made to conform; if it cannot be made to conform 
then script execution halts.   
</para></listitem><listitem><prepend>&bullet;</prepend> <para>Missing values in the mask evaluate to False in the where 
code/block statement and to True in the elsewhere block/statement. 
</para></listitem><listitem><prepend>&bullet;</prepend> <para>LHS variable elements set to missing value are treated just like any other
 elements and can be re-assigned as the mask dictates
</para></listitem><listitem><prepend>&bullet;</prepend> <para>LHS variable cannot include subscripts.
If they do script execution will terminate. 
See below example for work-araound.
</para></listitem></itemize>

<para>Consider the variables <code>float lon_2D_rct(lat,lon);</code> and
<code>float var_msk(lat,lon);</code>. 
Suppose we wish to multiply by two the elements for which <code>var_msk</code> 
<w>equals 1</w>: 
</para><example endspaces=" ">
<pre xml:space="preserve">where(var_msk == 1) lon_2D_rct=2*lon_2D_rct;
</pre></example>
<para>Suppose that we have the variable <code>int RDM(time)</code> and that we want
to set its values less than 8 or greater than 80 <w>to 0</w>:
</para><example endspaces=" ">
<pre xml:space="preserve">where(RDM &lt; 8 || RDM &gt; 80) RDM=0;          
</pre></example>

<para>To use <command>where</command> on a variable hyperslab, define and use a temporary
variable, e.g., 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
*var_tmp=var2(:,0,:,:); 
where (var1 &lt; 0.5) var_tmp=1234; 
var2(;,0,:,;)=var_tmp;
ram_delete(var_tmp);
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;WRF&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#WRF --&gt;
&lt;a name=&quot;SLD&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#SLD --&gt;
&lt;a name=&quot;wrf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wrf --&gt;
&lt;a name=&quot;sld&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sld --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1447">Weather and Research Forecast (<acronym><acronymword>WRF</acronymword></acronym>) Model</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1448">Swath-like Data (<acronym><acronymword>SLD</acronymword></acronym>)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1449"><acronym><acronymword>WRF</acronymword></acronym> (Weather and Research Forecast Model)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1450"><acronym><acronymword>SLD</acronymword></acronym> (Swath-like Data)</indexterm></cindex>
<para>Consider irregularly gridded data, described using <w>rank 2</w> coordinates: 
<code>double lat(south_north,east_west)</code>,
<code>double lon(south_north,east_west)</code>, 
<code>double temperature(south_north,east_west)</code>.
This type of structure is often found in regional weather/climate model
(such as <acronym><acronymword>WRF</acronymword></acronym>) output, and in satellite swath data.
For this reason we call it &textldquo;Swath-like Data&textrdquo;, or <acronym><acronymword>SLD</acronymword></acronym>.
To find the average temperature in a region bounded by
[<var>lat_min</var>,<var>lat_max</var>] and [<var>lon_min</var>,<var>lon_max</var>]:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
temperature_msk[$south_north,$east_west]=0.0;
where((lat &gt;= lat_min &amp;&amp; lat &lt;= lat_max) &amp;&amp; (lon &gt;= lon_min &amp;&amp; lon &lt;= lon_max))
  temperature_msk=temperature;	
elsewhere
  temperature_msk=temperature@_FillValue;

temp_avg=temperature_msk.avg();
temp_max=temperature.max();
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;NARR&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#NARR --&gt;
&lt;a name=&quot;narr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#narr --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1451"><acronym><acronymword>NARR</acronymword></acronym> (North American Regional Reanalysis)a</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1452">North American Regional Reanalysis (<acronym><acronymword>NARR</acronymword></acronym>)</indexterm></cindex>
<para>For North American Regional Reanalysis (<acronym><acronymword>NARR</acronymword></acronym>) data
(example
<uref><urefurl>http://dust.ess.uci.edu/diwg/narr_uwnd.199605.nc</urefurl><urefdesc spaces=" ">dataset</urefdesc></uref>)
the procedure looks like this
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -O -v -S ~/narr.nco ${DATA}/hdf/narr_uwnd.199605.nc ~/foo.nc
</verbatim>
</example>
<para>where <file>narr.nco</file> is an <command>ncap2</command> script like this:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
/* North American Regional Reanalysis (NARR) Statistics
   NARR stores grids with 2-D latitude and longitude, aka Swath-like Data (SLD) 
   Here we work with three variables:
   lat(y,x), lon(y,x), and uwnd(time,level,y,x);
   To study sub-regions of SLD, we use masking techniques:
   1. Define mask as zero times variable to be masked
      Then mask automatically inherits variable attributes
      And average below will inherit mask attributes
   2. Optionally, create mask as RAM variable (as below with asterisk *)
      NCO does not write RAM variable to output
      Masks are often unwanted, and can be big, so this speeds execution
   3. Example could be extended to preserve mean lat and lon of sub-region
      Follow uwnd example to do this: lat_sk=0.0*lat ... lat_avg=lat.avg($y,$x) */
*uwnd_msk=0.0*uwnd;
where((lat &gt;= 35.6 &amp;&amp; lat &lt;= 37.0) &amp;&amp; (lon &gt;= -100.5 &amp;&amp; lon &lt;= -99.0))
  uwnd_msk=uwnd;
elsewhere
  uwnd_msk=uwnd@_FillValue;

// Average only over horizontal dimensions x and y (preserve level and time)
uwnd_avg=uwnd_msk.avg($y,$x); 
</verbatim>
</example>
<para>Stripped of comments and formatting, this example is a three-statement
script executed by a one-line command. 
<acronym><acronymword>NCO</acronymword></acronym> needs only this meagre input to unpack and copy the input
data and attributes, compute the statistics, and then define and write
the output file.  
Unless the comments pointed out that wind variable (<code>uwnd</code>) was
four-dimensional and the latitude/longitude grid variables were both
two-dimensional, there would be no way to tell.
This shows how <acronym><acronymword>NCO</acronymword></acronym> hides from the user the complexity of
analyzing multi-dimensional <acronym><acronymword>SLD</acronymword></acronym>. 
We plan to extend such <acronym><acronymword>SLD</acronymword></acronym> features to more operators soon.
</para>
<html endspaces=" ">
&lt;a name=&quot;ncap_lop&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_lop --&gt;
</html>
</subsection>
<node name="Loops" spaces=" "><nodename>Loops</nodename><nodenext spaces=" ">Include files</nodenext><nodeprev spaces=" ">Where statement</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Loops</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1453">while()</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1454">for()</indexterm></cindex>
<para><command>ncap2</command> supplies <command>for()</command> loops and <command>while()</command> loops. 
They are completely unoptimized so use them only with <acronym><acronymword>RAM</acronymword></acronym> 
variables unless you want thrash your disk to death. 
To break out of a loop use the <command>break</command> command. 
To iterate to the next cycle use the <command>continue</command> command. 
</para>
<example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
// Set elements in variable double temp(time,lat) 
// If element &lt; 0 set to 0, if element &gt; 100 set to 100
*sz_idx=$time.size;
*sz_jdx=$lat.size;

for(*idx=0;idx&lt;sz_idx;idx++)
  for(*jdx=0;jdx&lt;sz_jdx;jdx++)
    if(temp(idx,jdx) &gt; 100) temp(idx,jdx)=100.0; 
      else if(temp(idx,jdx) &lt; 0) temp(idx,jdx)=0.0;

// Are values of co-ordinate variable double lat(lat) monotonic?
*sz=$lat.size;

for(*idx=1;idx&lt;sz;idx++)
  if(lat(idx)-lat(idx-1) &lt; 0.0) break;

if(idx == sz) print(&quot;lat co-ordinate is monotonic\n&quot;);
   else print(&quot;lat co-ordinate is NOT monotonic\n&quot;);

// Sum odd elements	
*idx=0;
*sz=$lat_nw.size;
*sum=0.0;

while(idx&lt;sz){
  if(lat(idx)%2) sum+=lat(idx);
  idx++;
}

ram_write(sum);
print(&quot;Total of odd elements &quot;);print(sum);print(&quot;\n&quot;); 
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;ncap_inc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_inc --&gt;
</html>
</subsection>
<node name="Include-files" spaces=" "><nodename>Include files</nodename><nodenext spaces=" ">Sort methods</nodenext><nodeprev spaces=" ">Loops</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Include files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1455"><command>include</command></indexterm></cindex>
<para>The syntax of an <var>include-file</var> is:
</para><example endspaces=" ">
<pre xml:space="preserve">#include &quot;script.nco&quot;
#include &quot;/opt/SOURCES/nco/data/tst.nco&quot;
</pre></example>
<para>If the filename is relative and not absolute then the directory searched is relative to the run-time directory. 
It is possible to nest include files to an arbitrary depth. 
A handy use of inlcude files is to store often used constants. 
Use <acronym><acronymword>RAM</acronymword></acronym> variables if you do not want these constants written to nc-file.
</para>
<para><var>output-file</var>.  
</para><example endspaces=" ">
<pre xml:space="preserve">// script.nco
// Sample file to #include in ncap2 script
*pi=3.1415926535; // RAM variable, not written to output
*h=6.62607095e-34; // RAM variable, not written to output
e=2.71828; // Regular (disk) variable, written to output
</pre></example>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.3 (December, 2016), The user can specify the directory(s) to be searched by specifing them in the UNIX environment var <code>NCO_PATH</code>. The format used is identical to the UNIX <code>PATH</code>. The directory(s) are only searched if the include filename is relative.   
</para>
<example endspaces=" ">
<pre xml:space="preserve">export NCO_PATH=&quot;:/home/henryb/bin/:/usr/local/scripts:/opt/SOURCES/nco/data:&quot;
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;srt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#srt --&gt;
&lt;a name=&quot;sort&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sort --&gt;
&lt;a name=&quot;remap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#remap --&gt;
</html>
</subsection>
<node name="Sort-methods" spaces=" "><nodename>Sort methods</nodename><nodenext spaces=" ">UDUnits script</nodenext><nodeprev spaces=" ">Include files</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle><command>sort</command> methods</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1456"><command>sort</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1457"><command>asort</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1458"><command>dsort</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1459"><command>remap</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1460"><command>unmap</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1461"><command>invert_map</command></indexterm></cindex>
<para>In <acronym><acronymword>ncap2</acronymword></acronym> there are multiple ways to sort data. 
Beginning with <acronym><acronymword>NCO</acronymword></acronym> 4.1.0 (March, 2012), <acronym><acronymword>ncap2</acronymword></acronym> 
support six sorting functions:
</para><example endspaces=" ">
<pre xml:space="preserve">var_out=sort(var_in,&amp;srt_map); // Ascending sort
var_out=asort(var_in,&amp;srt_map); // Accending sort 
var_out=dsort(var_in,&amp;srt_map); // Desending sort     
var_out=remap(var_in,srt_map); // Apply srt_map to var_in
var_out=unmap(var_in,srt_map); // Reverse what srt_map did to var_in
dsr_map=invert_map(srt_map); // Produce &quot;de-sort&quot; map that inverts srt_map
</pre></example>
<para>The first two functions, <command>sort()</command> and <command>asort()</command>
sort, in ascending order, all the elements of <var>var_in</var> (which can be
a variable or attribute) without regard to any dimensions.
The third function, <command>dsort()</command> does the same but sorts in
descending order. 
Remember that ascending and descending sorts are specified by
<command>asort()</command> and <command>dsort()</command>, respectively.
</para>
<para>These three functions are overloaded to take a second, optional argument 
called the sort map <var>srt_map</var>, which should be supplied as a
call-by-reference variable, i.e., preceded with an ampersand.
If the sort map does not yet exist, then it will be created and 
returned as an integer type the same shape as the input variable.
</para>
<para>The output <var>var_out</var> of each sort function is a sorted version of
the input, <var>var_in</var>.
The output <var>var_out</var> of the two mapping functions the result of
applying (with <command>remap()</command> or un-applying (with <command>unmap()</command>) 
the sort map <var>srt_map</var> to the input <var>var_in</var>.
To apply the sort map with <command>remap()</command> the size of the variable
must be exactly divisible by the size of the sort map. 
</para>
<para>The final function <command>invert_map()</command> returns the so-called
de-sorting map <var>dsr_map</var> which is the inverse of the input map
<var>srt_map</var>. 
This gives the user access to both the forward and inverse sorting maps: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
a1[$time]={10,2,3,4,6,5,7,3,4,1};
a1_sort=sort(a1);
print(a1_sort);
// 1, 2, 3, 3, 4, 4, 5, 6, 7, 10;

a2[$lon]={2,1,4,3};
a2_sort=sort(a2,&amp;a2_map);
print(a2);
// 1, 2, 3, 4
print(a2_map);
// 1, 0, 3, 2;
</verbatim>
</example>  

<para>If the map variable does not exist prior to the <command>sort()</command> call,
then it will be created with the same shape as the input variable and be
of type <code>NC_INT</code>. 
If the map variable already exists, then the only restriction is that it
be of at least the same size as the input variable. 
To apply a map use <code>remap(var_in,srt_map)</code>. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
defdim(&quot;nlat&quot;,5);

a3[$lon]={2,5,3,7};
a4[$nlat,$lon]={
 1, 2, 3, 4, 
 5, 6, 7, 8,
 9,10,11,12,
 13,14,15,16,
 17,18,19,20};

a3_sort=sort(a3,&amp;a3_map);
print(a3_map);
// 0, 2, 1, 3;

a4_sort=remap(a4,a3_map);
print(a4_sort);
// 1, 3, 2, 4,
// 5, 7, 6, 8,
// 9,11,10,12,
// 13,15,14,16,
// 17,19,18,20;

a3_map2[$nlat]={4,3,0,2,1};

a4_sort2=remap(a4,a3_map2);
print(a4_sort2);
// 3, 5, 4, 2, 1
// 8, 10, 9,7, 6, 
// 13,15,14,12,11, 
// 18,20,19,17,16
</verbatim>
</example>
<para>As in the above example you may create your own sort map.
To sort in descending order, apply the <code>reverse()</code> method after the
<command>sort()</command>.    
</para>
<para>Here is an extended example of how to use <command>ncap2</command> features to
hyperslab an irregular region based on the values of a variable not a
coordinate. 
The distinction is crucial: hyperslabbing based on dimensional indices
or coordinate values is straightforward.
Using the values of single or multi-dimensional variable to define a
hyperslab is quite different.
</para><example endspaces=" ">
<pre xml:space="preserve">cat &gt; ~/ncap2_foo.nco &lt;&lt; 'EOF'
// Purpose: Save irregular 1-D regions based on variable values

// Included in NCO User Guide at http://nco.sf.net/nco.html#sort

/* NB: Single quotes around EOF above turn off shell parameter 
    expansion in &quot;here documents&quot;. This in turn prevents the
    need for protecting dollarsign characters in NCO scripts with
    backslashes when the script is cut-and-pasted (aka &quot;moused&quot;) 
    from an editor or e-mail into a shell console window */

/* Copy coordinates and variable(s) of interest into RAM variable(s)
   Benefits:
   1. ncap2 defines writes all variables on LHS of expression to disk
      Only exception is RAM variables, which are stored in RAM only
      Repeated operations on regular variables takes more time, 
      because changes are written to disk copy after every change.
      RAM variables are only changed in RAM so script works faster
      RAM variables can be written to disk at end with ram_write()
   2. Script permutes variables of interest during processing
      Safer to work with copies that have different names
      This discourages accidental, mistaken use of permuted versions
   3. Makes this script a more generic template:
      var_in instead of specific variable names everywhere */
*var_in=one_dmn_rec_var;
*crd_in=time;
*dmn_in_sz=$time.size; // [nbr] Size of input arrays

/* Create all other &quot;intermediate&quot; variables as RAM variables 
   to prevent them from cluttering the output file.
   Mask flag and sort map are same size as variable of interest */
*msk_flg=var_in;
*srt_map=var_in;

/* In this example we mask for all values evenly divisible by 3
   This is the key, problem-specific portion of the template
   Replace this where() condition by that for your problem
   Mask variable is Boolean: 1=Meets condition, 0=Fails condition */
where(var_in % 3 == 0) msk_flg=1; elsewhere msk_flg=0;

// print(&quot;msk_flg = &quot;);print(msk_flg); // For debugging...

/* The sort() routine is overloaded, and takes one or two arguments
   The second argument (optional) is the &quot;sort map&quot; (srt_map below)
   Pass the sort map by reference, i.e., prefix with an ampersand
   If the sort map does not yet exist, then it will be created and 
   returned as an integer type the same shape as the input variable.
   The output of sort(), on the LHS, is a sorted version of the input
   msk_flg is not needed in its original order after sort()
   Hence we use msk_flg as both input to and output from sort()
   Doing this prevents the need to define a new, unneeded variable */
msk_flg=sort(msk_flg,&amp;srt_map);

// Count number of valid points in mask by summing the one's
*msk_nbr=msk_flg.total();

// Define output dimension equal in size to number of valid points
defdim(&quot;crd_out&quot;,msk_nbr);

/* Now sort the variable of interest using the sort map and remap()
   The output, on the LHS, is the input re-arranged so that all points
   meeting the mask condition are contiguous at the end of the array
   Use same srt_map to hyperslab multiple variables of the same shape
   Remember to apply srt_map to the coordinate variables */
crd_in=remap(crd_in,srt_map);
var_in=remap(var_in,srt_map);

/* Hyperslab last msk_nbr values of variable(s) of interest */
crd_out[crd_out]=crd_in((dmn_in_sz-msk_nbr):(dmn_in_sz-1));
var_out[crd_out]=var_in((dmn_in_sz-msk_nbr):(dmn_in_sz-1));

/* NB: Even though we created all variables possible as RAM variables,
   the original coordinate of interest, time, is written to the ouput.
   I'm not exactly sure why. For now, delete it from the output with: 
   ncks -O -x -v time ~/foo.nc ~/foo.nc
   */ 
EOF
ncap2 -O -v -S ~/ncap2_foo.nco ~/nco/data/in.nc ~/foo.nc
ncks -O -x -v time ~/foo.nc ~/foo.nc
ncks ~/foo.nc
</pre></example>

<para>Here is an extended example of how to use <command>ncap2</command> features to
sort multi-dimensional arrays based on the coordinate values along a
single dimension. 
</para><example endspaces=" ">
<pre xml:space="preserve">cat &gt; ~/ncap2_foo.nco &lt;&lt; 'EOF'
/* Purpose: Sort multi-dimensional array based on coordinate values
   This example sorts the variable three_dmn_rec_var(time,lat,lon)
   based on the values of the time coordinate. */

// Included in NCO User Guide at http://nco.sf.net/nco.html#sort

// Randomize the time coordinate
time=10.0*gsl_rng_uniform(time);
//print(&quot;original randomized time = \n&quot;);print(time);

/* The sort() routine is overloaded, and takes one or two arguments
   The first argument is a one dimensional array
   The second argument (optional) is the &quot;sort map&quot; (srt_map below)
   Pass the sort map by reference, i.e., prefix with an ampersand
   If the sort map does not yet exist, then it will be created and 
   returned as an integer type the same shape as the input variable.
   The output of sort(), on the LHS, is a sorted version of the input */

time=sort(time,&amp;srt_map);
//print(&quot;sorted time (ascending order) and associated sort map =\n&quot;);print(time);print(srt_map);

/* sort() always sorts in ascending order
   The associated sort map therefore re-arranges the original,
   randomized time array into ascending order.
   There are two methods to obtain the descending order the user wants
   1) We could solve the problem in ascending order (the default)
   and then apply the reverse() method to re-arrange the results.
   2) We could change the sort map to return things in descending
   order of time and solve the problem directly in descending order. */

// Following shows how to do method one:

/* Expand the sort map to srt_map_3d, the size of the data array
   1. Use data array to provide right shape for the expanded sort map
   2. Coerce data array into an integer so srt_map_3d is an integer
   3. Multiply data array by zero so 3-d map elements are all zero
   4. Add the 1-d sort map to the 3-d sort map (NCO automatically resizes)
   5. Add the spatial (lat,lon) offsets to each time index 
   6. de-sort using the srt_map_3d
   7. Use reverse to obtain descending in time order
   Loops could accomplish the same thing (exercise left for reader)
   However, loops are slow for large datasets */

/* Following index manipulation requires understanding correspondence
   between 1-d (unrolled, memory order of storage) and access into that
   memory as a multidimensional (3-d, in this case) rectangular array.
   Key idea to understand is how dimensionality affects offsets */ 
// Copy 1-d sort map into 3-d sort map
srt_map_3d=(0*int(three_dmn_rec_var))+srt_map;
// Multiply base offset by factorial of lesser dimensions
srt_map_3d*=$lat.size*$lon.size;
lon_idx=array(0,1,$lon);
lat_idx=array(0,1,$lat)*$lon.size;
lat_lon_idx[$lat,$lon]=lat_idx+lon_idx;
srt_map_3d+=lat_lon_idx;

print(&quot;sort map 3d =\n&quot;);print(srt_map_3d);

// Use remap() to re-map the data
three_dmn_rec_var=remap(three_dmn_rec_var,srt_map_3d);

// Finally, reverse data so time coordinate is descending
time=time.reverse($time);
//print(&quot;sorted time (descending order) =\n&quot;);print(time);
three_dmn_rec_var=three_dmn_rec_var.reverse($time);

// Method two: Key difference is srt_map=$time.size-srt_map-1;
EOF
ncap2 -O -v -S ~/ncap2_foo.nco ~/nco/data/in.nc ~/foo.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;udunits_fnc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#udunits_fnc --&gt;
&lt;a name=&quot;units_cnv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#units_cnv --&gt;
</html>
</subsection>
<node name="UDUnits-script" spaces=" "><nodename>UDUnits script</nodename><nodenext spaces=" ">Vpointer</nodenext><nodeprev spaces=" ">Sort methods</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>UDUnits script</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1462">UDUnits</indexterm></cindex>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.3 (December, 2016), <acronym><acronymword>ncap2</acronymword></acronym>
includes support for UDUnits conversions. 
The function is called <code>udunits</code>. 
Its syntax is
</para><example endspaces=" ">
<pre xml:space="preserve">varOut=udunits(varIn,&quot;UnitsOutString&quot;)
</pre></example>

<para>The <code>udunits()</code> function looks for the attribute of
<code>varIn&arobase;units</code> and fails if it is not found. 
A quirk of this function that due to attribute propagation
<code>varOut&arobase;units</code> will be overwritten by <code>varIn&arobase;units</code>. 
It is best to re-initialize this attribute AFTER the call. 
In addition if <code>varIn&arobase;units</code> is of the form 
<code>&quot;time_interval since basetime&quot;</code> then the calendar attribute
<code>varIn&arobase;calendar</code> will read it.
If it does not exist then the calendar used defaults to mixed
Gregorian/Julian as defined by UDUnits. 
</para> 
<para>If <code>varIn</code> is not a floating-point type then it is promoted to
<code>NC_DOUBLE</code> for the system call in the UDUnits library,   
and then demoted back to its original type after.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
T[lon]={0.0,100.0,150.0,200.0};
T@units=&quot;Celsius&quot;;
// Overwrite variable
T=udunits(T,&quot;kelvin&quot;); 
print(T);  
// 273.15, 373.15, 423.15, 473.15 ;
T@units=&quot;kelvin&quot;;

// Rebase coordinate days to hours 
timeOld=time;
print(timeOld);
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
timeOld@units=&quot;days since 2012-01-30&quot;;

@units=&quot;hours since 2012-02-01 01:00&quot;;
timeNew=udunits(timeOld, @units);
timeNew@units=@units;
print(timeNew);
// -25, -1, 23, 47, 71, 95, 119, 143, 167, 191 ;

tOld=time;
// NB: Calendar=365_day has NO Leap year
tOld@calendar=&quot;365_day&quot;;
tOld@units=&quot;minutes since 2012-02-28 23:58:00.00&quot;;

@units=&quot;seconds since 2012-03-01 00:00&quot;;
tNew=udunits(tOld, @units);
tNew@units=@units;
print(tNew);
// -60, 0, 60, 120, 180, 240, 300, 360, 420, 480 
</verbatim>
</example>

<noindent></noindent> <para>strftime()
The <code>var_str=strtime(var_time,fmt_sng)</code> method takes a time-based variable and a format string and returns an <code>NC_STRING</code> variable (of the same shape as var_time) of time-stamps in the form specified by &textrsquo;fmt_sng&textrsquo;. In order to run this command output type must be netCDF4.
</para><example endspaces=" "> 
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -4  -v -O -s 'time_str=strftime(time,&quot;%Y-%m-%d&quot;);' in.nc foo.nc

time_str=&quot;1964-03-13&quot;, &quot;1964-03-14&quot;, &quot;1964-03-15&quot;, &quot;1964-03-16&quot;, 
         &quot;1964-03-17&quot;, &quot;1964-03-18&quot;, &quot;1964-03-19&quot;, &quot;1964-03-20&quot;, 
         &quot;1964-03-21&quot;, &quot;1964-03-22&quot; ;
</verbatim>
</example>

<para>Under the hood there are  a few steps invoved:
First the method reads <code>var_time&arobase;units</code> and
<code>var_time&arobase;calendar</code> (if present) then converts <code>var_time</code> to
<code>seconds since 1970-01-01</code>.
It then converts these possibly UTC seconds to the standard struture
<code>struct *tm</code>.
Finally <code>strftime()</code> is called with <code>fmt_sng</code> and the
<code>*tm</code> struct.
The C-standard <code>strftime()</code> is used as defined in <file>time.h</file>.
If the method is called without <var>fmt_sng</var> then the following default is
used: <code>&quot;%Y-%m-%d %H:%M:%S&quot;</code>.
The method <code>regular</code> takes a single var argument and uses the
above default string. 
</para><example endspaces=" "> 
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -4  -v -O -s 'time_str=regular(time);' in.nc foo.nc

time_str = &quot;1964-03-13 21:09:00&quot;, &quot;1964-03-14 21:09:00&quot;, &quot;1964-03-15 21:09:00&quot;, 
           &quot;1964-03-16 21:09:00&quot;, &quot;1964-03-17 21:09:00&quot;, &quot;1964-03-18 21:09:00&quot;, 
           &quot;1964-03-19 21:09:00&quot;, &quot;1964-03-20 21:09:00&quot;, &quot;1964-03-21 21:09:00&quot;, 
           &quot;1964-03-22 21:09:00&quot; ;
</verbatim>
</example>

<noindent></noindent> <para>Another working example
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -v -O -s 'ts=strftime(frametime(0),&quot;%Y-%m-%d/envlog_netcdf_L1_ua-mac_%Y-%m-%d.nc&quot;);' in.nc out.nc
ts=&quot;2017-08-11/envlog_netcdf_L1_ua-mac_2017-08-11.nc&quot; 
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;vpointer&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vpointer --&gt;
&lt;a name=&quot;vp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vp --&gt;
</html>
</subsection>
<node name="Vpointer" spaces=" "><nodename>Vpointer</nodename><nodenext spaces=" ">Irregular grids</nodenext><nodeprev spaces=" ">UDUnits script</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Vpointer</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1463">vpointer</indexterm></cindex>

<noindent></noindent> <para>A variable-pointer or <emph>vpointer</emph> is a pointer to a
variable or attribute.
It is most useful when one needs to apply a set of operations on a list
of variables.
For example, after regular processing one may wish to set the
<code>_FillValue</code> of all <code>NC_FLOAT</code> variables to a particular
value, or to create min/max attributes for all 3D variables of type
<code>NC_DOUBLE</code>.
A vpointer is not a &textrsquo;pointer&textrsquo; to a memory location in the C/C++
sense.
Rather the vpointer is a text attribute that contains the name of a
variable.
To use the pointer simply prefix the pointer with <code>*</code>.
Then, most places where you use <code>VAR_ID</code> you can use
*vpointer_nm.
There are a variety of ways to maintain a list of strings in
<command>ncap2</command>.
The easiest method is to use an <code>NC_STRING</code> attribute.  
</para>
<para>Below is a simple illustration that uses a vpointer of type
<code>NC_CHAR</code>. 
Remember an attribute starting with <code>&arobase;</code> implies &textrsquo;global&textrsquo;, e.g.,  
<code>&arobase;vpx</code> is short for <code>global&arobase;vpx</code>. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
idx=9;
idy=20;
t2=time;

global@vpx=&quot;idx&quot;;

// Increment idx by one
*global@vpx++;  
print(idx);

// Multiply by 5
*@vpx*=5; // idx now 50
print(idx);

// Add 200 (long method)
*@vpx=*@vpx+200; //idx now 250
print(idx);

@vpy=&quot;idy&quot;;

// Add idx idy to get idz
idz=*@vpx+*@vpy; // idz == 270
print(idz);

// We can also reference variables in the input file
// Can use an existing attribute pointer since attributes are not written
// to the netCDF file until after the script has finished.
@vpx=&quot;three_dmn_var&quot;;

// We can convert this variable to type NC_DOUBLE and
// write it to ouptut all at once
*@vpx=*@vpx.double();
</verbatim>
</example>

<para>The following script writes to the output files all variables that are
of type <code>NC_DOUBLE</code> and that have at least two dimensions.
It then changes their <code>_FillValue</code> to <code>1.0E-9</code>.  
The function <code>get_vars_in()</code> creates an <code>NC_STRING</code> attribute
that contains all of the variable names in the input file.
Note that a vpointer must be a plain attribute, NOT an a attribute
expression. 
Thus in the below script using <code>*all(idx)</code> would be a fundamental
mistake.
In the below example the vpointer <code>var_nm</code> is of type
<code>NC_STRING</code>. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
@all=get_vars_in();

*sz=@all.size();
*idx=0;

for(idx=0;idx&lt;sz;idx++){
  // @var_nm is of type NC_STRING
  @var_nm=@all(idx);
 
  if(*@var_nm.type() == NC_DOUBLE &amp;&amp; *@var_nm.ndims() &gt;= 2){
     *@var_nm=*@var_nm; 
     *@var_nm.change_miss(1e-9d);
  }
}
</verbatim>
</example> 

<para>The following script writes to the output file all 3D/4D
variables of type <code>NC_FLOAT</code>.
Then for each variable it calculates a <code>range</code> attribute that 
contains the maximum and minimum values, and a <code>total</code> attribute
that is the sum of all the elements.
In this example vpointers are used to &textrsquo;point&textrsquo; to attributes.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
@all=get_vars_in();
*sz=@all.size();
for(*idx=0;idx&lt;sz;idx++){
  @var_nm=@all(idx);
  if(*@var_nm.ndims() &gt;= 3){
    *@var_nm=*@var_nm.float();
    // The push function also takes a call-by-ref attribute: if it does not already exist then it will be created
    // The call below pushes a NC_STRING to an att so the end result is a list of NC_STRINGS   
    push(&amp;@prc,@var_nm); 
  }
} 

*sz=@prc.size();
for(*idx=0;idx&lt;sz;idx++){
  @var_nm=@prc(idx);

  // We can work with attribute pointers as well 
  // sprint() ouptut is of type NC_CHAR
  @att_total=sprint(@var_nm,&quot;%s@total&quot;); 
  @att_range=sprint(@var_nm,&quot;%s@range&quot;); 

  // If you are still confused then print out the attributes 
  print(@att_total); 
  print(@att_range);
 
  *@att_total=*@var_nm.total();
  *@att_range={min(*@var_nm),max(*@var_nm)};
} 
</verbatim>
</example>

<noindent></noindent> <para>This is the <acronym><acronymword>CDL</acronymword></acronym> dump of a variable processed by the above script:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
float three_dmn_var_int(time, lat, lon) ;
three_dmn_var_int:_FillValue = -99.f ;
three_dmn_var_int:long_name = &quot;three dimensional record variable of type int&quot; ;
three_dmn_var_int:range = 1.f, 80.f ;
three_dmn_var_int:total = 2701.f ;
three_dmn_var_int:units = &quot;watt meter-2&quot; ;
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;rct&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rct --&gt;
</html>

</subsection>
<node name="Irregular-grids" spaces=" "><nodename>Irregular grids</nodename><nodenext spaces=" ">Bilinear interpolation</nodenext><nodeprev spaces=" ">Vpointer</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Irregular Grids</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1464">irregular grids</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1465">rectangular grids</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1466">non-rectangular grids</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1467">non-standard grids</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1468">mask</indexterm></cindex>
<!-- c fxm need to edit rrg sxn beginning here -->
<para><acronym><acronymword>NCO</acronymword></acronym> is capable of analyzing datasets for many different
underlying coordinate grid types.
netCDF was developed for and initially used with grids comprised of
orthogonal dimensions forming a rectangular coordinate system.
We call such grids <emph>standard</emph> grids.
It is increasingly common for datasets to use metadata to describe
much more complex grids.
Let us first define three important coordinate grid properties:
regularity, rectangularity, and structure.
</para>
<para>Grids are <emph>regular</emph> if the spacing between adjacent is constant. 
For example, a 4-by-5 degree latitude-longitude grid is regular
because the spacings between adjacent latitudes (<w>4 degrees</w>) are
constant as are the (<w>5 degrees</w>) spacings between adjacent
longitudes. 
Spacing in <emph>irregular</emph> grids depends on the location along the
coordinate. 
Grids such as Gaussian grids have uneven spacing in latitude (points 
cluster near the equator) and so are irregular.
</para>
<para>Grids are <emph>rectangular</emph> if the number of elements in any
dimension is not a function of any other dimension.
For example, a T42 Gaussian latitude-longitude grid is rectangular
because there are the same number of longitudes (128) for each of the 
(64) latitudes.
Grids are <emph>non-rectangular</emph> if the elements in any dimension
depend on another dimension.
Non-rectangular grids present many special challenges to 
analysis software like <acronym><acronymword>NCO</acronymword></acronym>.
</para>
<para>Grids are <emph>structured</emph> if they are represented as functions
of two horizontal spatial dimensions.
For example, grids with latitude and longitude dimensions are
structured, and so are curvilinear grids with along-track and
cross-track dimensions.
A grid with a single dimension is <emph>unstructured</emph>.
For example, icosohedral grids are usually unstructured, as are
<acronym><acronymword>MPAS</acronymword></acronym> grids.
</para>
<para>Wrapped coordinates (<pxref label="Wrapped-Coordinates"><xrefnodename>Wrapped Coordinates</xrefnodename></pxref>), such as longitude,
are independent of these grid properties (regularity, rectangularity,
structure). 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1469">wrapped coordinates</indexterm></cindex>
<para>The preferred <acronym><acronymword>NCO</acronymword></acronym> technique to analyze data on non-standard
coordinate grids is to create a region mask with <command>ncap2</command>, and
then to use the mask within <command>ncap2</command> for variable-specific
processing, and/or with other operators (e.g., <command>ncwa</command>,
<command>ncdiff</command>) for entire file processing. 
</para>
<para>Before describing the construction of masks, let us review how
irregularly gridded geoscience data are described.
Say that latitude and longitude are stored as <var>R</var>-dimensional
arrays and the product of the dimension sizes is the total number of  
elements N in the other variables.
Geoscience applications tend to use <math><var>R</var>=1</math>, 
<math><var>R</var>=2</math>, and <math><var>R</var>=3</math>.
</para>
<para>If the grid is has no simple representation (e.g., discontinuous) then
it makes sense to store all coordinates as 1D arrays with the same
size as the number of grid points. 
These gridpoints can be completely independent of all the other (own
weight, area, etc.).  
</para>
<para><var>R</var>=1: lat(number_of_gridpoints) and lon(number_of_gridpoints)
</para>
<para>If the horizontal grid is time-invariant then <var>R</var>=2 is common:
</para>
<para><var>R</var>=2: lat(south_north,east_west) and lon(south_north,east_west)
</para>
<para>The Weather and Research Forecast (<acronym><acronymword>WRF</acronymword></acronym>) model uses <var>R</var>=3:
</para>
<para><var>R</var>=3: lat(time,south_north,east_west), lon(time,south_north,east_west)
</para>
<para>and so supports grids that change with time.
</para>
<para>Grids with <var>R</var> &gt; 1 often use missing values to indicated empty points.
For example, so-called &textldquo;staggered grids&textrdquo; will use fewer east_west
points near the poles and more near the equator. netCDF only accepts
rectangular arrays so space must be allocated for the maximum number
of east_west points at all latitudes. Then the application writes
missing values into the unused points near the poles.
</para>
<para>We demonstrate the <command>ncap2</command> analysis technique for irregular
regions by constructing a mask for an <var>R</var>=2 grid.
We wish to find, say, the mean temperature within 
[<var>lat_min</var>,<var>lat_max</var>] and [<var>lon_min</var>,<var>lon_max</var>]: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'mask_var= (lat &gt;= lat_min &amp;&amp; lat &lt;= lat_max) &amp;&amp; \
                    (lon &gt;= lon_min &amp;&amp; lon &lt;= lon_max);' in.nc out.nc
</pre></example>
<para>Arbitrarily shaped regions can be defined by more complex conditional
statements. 
Once defined, masks can be applied to specific variables,
and to entire files:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'temperature_avg=(temperature*mask_var).avg()' in.nc out.nc
ncwa -a lat,lon -m mask_var -w area in.nc out.nc
</pre></example>
<para>Crafting such commands on the command line is possible though unwieldy.
In such cases, a script is often cleaner and allows you to document the
procedure:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
cat &gt; ncap2.in &lt;&lt; 'EOF'
mask_var = (lat &gt;= lat_min &amp;&amp; lat &lt;= lat_max) &amp;&amp; (lon &gt;= lon_min &amp;&amp; &gt; lon &lt;= lon_max);
if(mask_var.total() &gt; 0){ // Check that mask contains some valid values
  temperature_avg=(temperature*mask_var).avg(); // Average temperature
  temperature_max=(temperature*mask_var).max(); // Maximum temperature
}
EOF
ncap2 -S ncap2.in in.nc out.nc
</verbatim>
</example>

<ignore endspaces=" ">
http://foehn.colorado.edu/wrfout_to_cf/wrfout_to_cf.ncl
ncl 'file_in=&quot;wrfout.nc&quot;' 'file_out=&quot;wrfpost.nc&quot;' wrfout_to_cf.ncl
ncl 'file_in=&quot;wrfout_d02_2013-10-04_20:00:00&quot;' 'file_out=&quot;wrfout_d02_2013-10-04_20:00:00_cf.nc&quot;' wrfout_to_cf.ncl
ncl 'file_in=&quot;wrfout_v2_Lambert&quot;' 'file_out=&quot;wrfout_v2_Lambert.nc&quot;' wrfout_to_cf.ncl
</ignore>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1470"><acronym><acronymword>WRF</acronymword></acronym></indexterm></cindex>
<para>Grids like those produced by the <acronym><acronymword>WRF</acronymword></acronym> model are complex because
one must use global metadata to determine the grid staggering and
offsets to translate <code>XLAT</code> and <code>XLONG</code> into real latitudes, 
longitudes, and missing points. 
The <acronym><acronymword>WRF</acronymword></acronym> grid documentation should describe this.
For <acronym><acronymword>WRF</acronymword></acronym> files creating regional masks looks, in general, like 
</para><example endspaces=" ">
<pre xml:space="preserve">mask_var = (XLAT &gt;= lat_min &amp;&amp; XLAT &lt;= lat_max) &amp;&amp; (XLONG &gt;= lon_min &amp;&amp; XLONG &lt;= lon_max);
</pre></example>

<para>A few notes:
Irregular regions are the union of arrays of lat/lon min/max&textrsquo;s. 
The mask procedure is identical for all <var>R</var>.
<!-- c fxm need to edit rrg sxn down to here -->
</para>
<html endspaces=" ">
&lt;a name=&quot;bln_ntp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bln_ntp --&gt;
&lt;a name=&quot;bil_int&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bil_int --&gt;
</html>
</subsection>
<node name="Bilinear-interpolation" spaces=" "><nodename>Bilinear interpolation</nodename><nodenext spaces=" ">GSL special functions</nodenext><nodeprev spaces=" ">Irregular grids</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Bilinear interpolation</sectiontitle>
<noindent></noindent> <para>As of version 4.0.0 <acronym><acronymword>NCO</acronymword></acronym> has internal routines to
perform bilinear interpolation on gridded data sets.
In mathematics, bilinear interpolation is an extension of linear
interpolation for interpolating functions of two variables on a regular
grid. 
The idea is to perform linear interpolation first in one direction, and
then again in the other direction.
</para>
<para>Suppose we have an irregular grid of data <code>temperature[lat,lon]</code>,
with co-ordinate vars <code>lat[lat], lon[lon]</code>. 
We wish to find the temperature at an arbitary point [<var>X</var>,<var>Y</var>]
within the grid. 
If we can locate lat_min,lat_max and lon_min,lon_max such that 
<code>lat_min &lt;= X &lt;= lat_max</code> and <code>lon_min &lt;= Y &lt;= lon_max</code> 
then we can interpolate in two dimensions the temperature at
[<var>X</var>,<var>Y</var>]. 
</para>
<para>The general form of the <command>ncap2</command> interpolation function is
</para><example endspaces=" ">
<pre xml:space="preserve">var_out=bilinear_interp(grid_in,grid_out,grid_out_x,grid_out_y,grid_in_x,grid_in_y)
</pre></example>
<para>where
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">grid_in</itemformat></item>
</tableterm><tableitem><para>Input function data. 
Usually a two dimensional variable. 
It must be of size <code>grid_in_x.size()*grid_in_y.size()</code>        
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">grid_out</itemformat></item>
</tableterm><tableitem><para>This variable is the shape of <code>var_out</code>. 
Usually a two dimensional variable. 
It must be of size <code>grid_out_x.size()*grid_out_y.size()</code>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">grid_out_x</itemformat></item>
</tableterm><tableitem><para><var>X</var> output values 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">grid_out_y</itemformat></item>
</tableterm><tableitem><para><var>Y</var> output values 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">grid_in_x</itemformat></item>
</tableterm><tableitem><para><var>X</var> input values values. Must be monotonic (increasing or decreasing).
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">grid_in_y</itemformat></item>
</tableterm><tableitem><para><var>Y</var> input values values. Must be monotonic (increasing or decreasing).
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>Prior to calculations all arguments are converted to type
<code>NC_DOUBLE</code>.
After calculations <code>var_out</code> is converted to the input type of
<code>grid_in</code>. 
</para>
<para>Suppose the first part of an <command>ncap2</command> script is
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
defdim(&quot;X&quot;,4);
defdim(&quot;Y&quot;,5);

// Temperature
T_in[$X,$Y]=
 {100, 200, 300, 400, 500,
  101, 202, 303, 404, 505,
  102, 204, 306, 408, 510,
  103, 206, 309, 412, 515.0 };

// Coordinate variables
x_in[$X]={0.0,1.0,2.0,3.01};
y_in[$Y]={1.0,2.0,3.0,4.0,5};
</verbatim>
</example>
<para>Now we interpolate with the following variables:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
defdim(&quot;Xn&quot;,3);
defdim(&quot;Yn&quot;,4); 
T_out[$Xn,$Yn]=0.0;
x_out[$Xn]={0.0,0.02,3.01};
y_out[$Yn]={1.1,2.0,3,4};

var_out=bilinear_interp(T_in,T_out,x_out,y_out,x_in,y_in);
print(var_out);
// 110, 200, 300, 400,
// 110.022, 200.04, 300.06, 400.08,
// 113.3, 206, 309, 412 ;
</verbatim>
</example> 

<para>It is possible to interpolate a single point:
</para><example endspaces=" ">
<pre xml:space="preserve">var_out=bilinear_interp(T_in,0.0,3.0,4.99,x_in,y_in);
print(var_out);
// 513.920594059406
</pre></example>

<noindent></noindent> <para><strong>Wrapping and Extrapolation</strong> &linebreak;
The function <code>bilinear_interp_wrap()</code> takes the same
arguments as <code>bilinear_interp()</code> but performs wrapping (<var>Y</var>)
and extrapolation (<var>X</var>) for points off the edge of the grid.
If the given range of longitude is say (25-335) and we have a point at
20 degrees, then the endpoints of the range are used for the
interpolation. 
This is what wrapping means.   
For wrapping to occur <var>Y</var> must be longitude and must be in the range
(0,360) or (-180,180). 
There are no restrictions on the longitude (<var>X</var>) values, though
typically these are in the range (-90,90).
This <command>ncap2</command> script illustrates both wrapping and extrapolation
of end points:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
defdim(&quot;lat_in&quot;,6);
defdim(&quot;lon_in&quot;,5);

// Coordinate input vars
lat_in[$lat_in]={-80,-40,0,30,60.0,85.0};
lon_in[$lon_in]={30, 110, 190, 270, 350.0};

T_in[$lat_in,$lon_in]=
  {10,40,50,30,15,   
    12,43,52,31,16,   
    14,46,54,32,17,   
    16,49,56,33,18,   
    18,52,58,34,19,   
    20,55,60,35,20.0 };
   
defdim(&quot;lat_out&quot;,4);
defdim(&quot;lon_out&quot;,3);

// Coordinate variables
lat_out[$lat_out]={-90,0,70,88.0};   
lon_out[$lon_out]={0,190,355.0};

T_out[$lat_out,$lon_out]=0.0;

T_out=bilinear_interp_wrap(T_in,T_out,lat_out,lon_out,lat_in,lon_in);
print(T_out); 
// 13.4375, 49.5, 14.09375,
// 16.25, 54, 16.625,
// 19.25, 58.8, 19.325,
// 20.15, 60.24, 20.135 ;
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;gsl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gsl --&gt;
</html>
</subsection>
<node name="GSL-special-functions" spaces=" "><nodename>GSL special functions</nodename><nodenext spaces=" ">GSL interpolation</nodenext><nodeprev spaces=" ">Bilinear interpolation</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>GSL special functions</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1471"><acronym><acronymword>GSL</acronymword></acronym></indexterm></cindex>
<noindent></noindent> <para>As of version 3.9.6 (released January, 2009), <acronym><acronymword>NCO</acronymword></acronym> 
can link to the <acronym><acronymword>GNU</acronymword></acronym> Scientific Library (<acronym><acronymword>GSL</acronymword></acronym>). 
<command>ncap2</command> can access most <acronym><acronymword>GSL</acronymword></acronym> special functions including
Airy, Bessel, error, gamma, beta, hypergeometric, and Legendre functions
and elliptical integrals. 
<acronym><acronymword>GSL</acronymword></acronym> must be <w>version 1.4</w> or later. 
To list the <acronym><acronymword>GSL</acronymword></acronym> functions available with your <acronym><acronymword>NCO</acronymword></acronym> 
build, use <command>ncap2 -f | grep ^gsl</command>.
</para>
<noindent></noindent> <para>The function names used by <acronym><acronymword>ncap2</acronymword></acronym> mirror their
<acronym><acronymword>GSL</acronymword></acronym> names.
The <acronym><acronymword>NCO</acronymword></acronym> wrappers for <acronym><acronymword>GSL</acronymword></acronym> functions automatically
call the error-handling version of the <acronym><acronymword>GSL</acronymword></acronym> function when
available  
<footnote spaces="   \n"><para>These are the <acronym><acronymword>GSL</acronymword></acronym> standard function names postfixed with
<code>_e</code>.  
<acronym><acronymword>NCO</acronymword></acronym> calls these functions automatically, without the 
<acronym><acronymword>NCO</acronymword></acronym> command having to specifically indicate the <code>_e</code>
function suffix.
</para></footnote>.
This allows <acronym><acronymword>NCO</acronymword></acronym> to return a missing value when the
<acronym><acronymword>GSL</acronymword></acronym> library encounters a domain error or a floating-point 
exception. 
The slow-down due to calling the error-handling version of the 
<acronym><acronymword>GSL</acronymword></acronym> numerical functions was found to be negligible (please let
us know if you find otherwise).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1472">gamma function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1473"><var>gsl_sf_gamma</var></indexterm></cindex>
<noindent></noindent> <para>Consider the gamma function.&linebreak;
The <acronym><acronymword>GSL</acronymword></acronym> function prototype is &linebreak;
<code>int gsl_sf_gamma_e(const double x, gsl_sf_result * result)</code>
The <command>ncap2</command> script would be:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
lon_in[lon]={-1,0.1,0,2,0.3};
lon_out=gsl_sf_gamma(lon_in);
lon_out= _, 9.5135, 4.5908, 2.9915 
</verbatim>
</example>

<noindent></noindent> <para>The first value is set to <code>_FillValue</code> since the gamma
function is undefined for negative integers.
If the input variable has a missing value then this value is used.
Otherwise, the default double fill value is used
(defined in the netCDF header <file>netcdf.h</file> as 
<code>NC_FILL_DOUBLE = 9.969e+36</code>).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1474">Bessel function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1475"><var>gsl_sf_bessel_Jn</var></indexterm></cindex>
<noindent></noindent> <para>Consider a call to a Bessel function with <acronym><acronymword>GSL</acronymword></acronym>
prototype&linebreak; 
<code>int gsl_sf_bessel_Jn_e(int n, double x, gsl_sf_result * result)</code> 
</para>
<para>An <command>ncap2</command> script would be
</para><example endspaces=" ">
<pre xml:space="preserve">lon_out=gsl_sf_bessel_Jn(2,lon_in);  
lon_out=0.11490, 0.0012, 0.00498, 0.011165
</pre></example>
<para>This computes the Bessel function of order <var>n=2</var> for every value in
<code>lon_in</code>.
The Bessel order argument, an integer, can also be a non-scalar
variable, i.e., an array.  
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
n_in[lon]={0,1,2,3};
lon_out=gsl_sf_bessel_Jn(n_in,0.5);
lon_out= 0.93846, 0.24226, 0.03060, 0.00256
</verbatim>
</example>

<noindent></noindent> <para>Arguments to <acronym><acronymword>GSL</acronymword></acronym> wrapper functions in <command>ncap2</command>
must conform to one another, i.e., they must share the same sub-set of
dimensions.  
For example: <code>three_out=gsl_sf_bessel_Jn(n_in,three_dmn_var_dbl)</code>
is valid because the variable <code>three_dmn_var_dbl</code> has a <var>lon</var> 
dimension, so <code>n_in</code> in can be broadcast to conform to
<code>three_dmn_var_dbl</code>.  
However <code>time_out=gsl_sf_bessel_Jn(n_in,time)</code> is invalid.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1476">Elliptic integrals</indexterm></cindex>
<para>Consider the elliptical integral with prototype
<code>int gsl_sf_ellint_RD_e(double x, double y, double z, gsl_mode_t mode, gsl_sf_result * result)</code>
</para><example endspaces=" ">
<pre xml:space="preserve">three_out=gsl_sf_ellint_RD(0.5,time,three_dmn_var_dbl);
</pre></example>

<noindent></noindent> <para>The three arguments are all conformable so the above <command>ncap2</command> call is valid. The mode argument in the function prototype controls the convergence of the algorithm. It also appears  in the Airy Function prototypes. It can be set by defining the environment variable <code>GSL_PREC_MODE</code>. If unset it defaults to the value <code>GSL_PREC_DOUBLE</code>. See the <acronym><acronymword>GSL</acronymword></acronym> manual for more details. 
</para><example endspaces=" ">
<pre xml:space="preserve">export GSL_PREC_MODE=0 // GSL_PREC_DOUBLE
export GSL_PREC_MODE=1 // GSL_PREC_SINGLE
export GSL_PREC_MODE=2 // GSL_PREC_APPROX
</pre></example>

<noindent></noindent> <para>The <command>ncap2</command> wrappers to the array functions are
slightly different. 
Consider the following <acronym><acronymword>GSL</acronymword></acronym> prototype &linebreak; 
<code>int gsl_sf_bessel_Jn_array(int nmin, int nmax, double x, double *result_array)</code>
</para><example endspaces=" ">
<pre xml:space="preserve">b1=lon.double();
x=0.5;
status=gsl_sf_bessel_Jn_array(1,4,x,&amp;b1);
print(status);
b1=0.24226,0.0306,0.00256,0.00016;
</pre></example>
<noindent></noindent> <para>This calculates the Bessel function of <var>x</var>=0.5 for
<var>n</var>=1 to 4. 
The first three arguments are scalar values. 
If a non-scalar variable is supplied as an argument then only the first
value is used. 
The final argument is the variable where the results are stored (NB: the
<code>&amp;</code> indicates this is a call by reference). 
This final argument must be of type <code>double</code> and must be of least
size <var>nmax-nmin+1</var>. 
If either of these conditions is not met then then the function 
returns an error message. 
The function/wrapper returns a status flag. 
Zero indicates success. 
</para>
<noindent></noindent> <para>Consider another array function &linebreak; 
<code>int gsl_sf_legendre_Pl_array(int lmax, double x, double *result_array);</code>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1477">Legendre polynomial</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="17" mergedindex="cp">gsl_sf_legendre_Pl</indexterm></findex>
</para><example endspaces=" ">
<pre xml:space="preserve">a1=time.double();
x=0.3;
status=gsl_sf_legendre_Pl_array(a1.size()-1, x,&amp;a1);  
print(status);
</pre></example>
<noindent></noindent> <para>This call calculates <var>P_l</var>(0.3) for <var>l</var>=0..9. 
Note that <var>|x|&lt;=1</var>, otherwise there will be a domain error. 
See the <acronym><acronymword>GSL</acronymword></acronym> 
documentation for more details.  
</para>
<noindent></noindent> <para>The <acronym><acronymword>GSL</acronymword></acronym> functions implemented in <acronym><acronymword>NCO</acronymword></acronym> are 
listed in the table below. 
This table is correct for <acronym><acronymword>GSL</acronymword></acronym> version 1.10. 
To see what functions are available on your build run the command
<command>ncap2 -f |grep ^gsl</command> . 
To see this table along with the <acronym><acronymword>GSL</acronymword></acronym> <w>C-function</w>
prototypes look at the spreadsheet <strong>doc/nco_gsl.ods</strong>. &linebreak; &linebreak; 
</para>
<multitable spaces=" " endspaces=" "><columnfractions spaces=" " line=".35 .05 .60 "><columnfraction value=".35"></columnfraction><columnfraction value=".05"></columnfraction><columnfraction value=".60"></columnfraction></columnfractions>
<tbody><row><entry command="item"> <para><strong>GSL NAME</strong> </para></entry><entry command="tab"> <para><strong>I</strong> </para></entry><entry command="tab"> <para><strong>NCAP FUNCTION CALL</strong>
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Ai_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Ai(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Bi_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Bi(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Ai_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Ai_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Bi_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Bi_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Ai_deriv_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Ai_deriv(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Bi_deriv_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Bi_deriv(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Ai_deriv_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Ai_deriv_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_Bi_deriv_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_Bi_deriv_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_zero_Ai_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_zero_Ai(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_zero_Bi_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_zero_Bi(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_zero_Ai_deriv_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_zero_Ai_deriv(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_airy_zero_Bi_deriv_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_airy_zero_Bi_deriv(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_J0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_J0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_J1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_J1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Jn_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Jn(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Jn_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_Jn_array(int,int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Y0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Y0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Y1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Y1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Yn_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Yn(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Yn_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Yn_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_I0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_I0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_I1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_I1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_In_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_In(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_In_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_In_array(int,int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_I0_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_I0_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_I1_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_I1_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_In_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_In_scaled(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_In_scaled_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>staus=gsl_sf_bessel_In_scaled_array(int,int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_K0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_K0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_K1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_K1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Kn_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Kn(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Kn_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_Kn_array(int,int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_K0_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_K0_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_K1_scaled_e  </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_K1_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Kn_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Kn_scaled(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Kn_scaled_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_Kn_scaled_array(int,int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_j0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_J0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_j1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_J1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_j2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_j2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_jl_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_jl(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_jl_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_jl_array(int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_jl_steed_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_jl_steed_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_y0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Y0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_y1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Y1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_y2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_y2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_yl_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_yl(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_yl_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_yl_array(int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_i0_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_I0_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_i1_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_I1_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_i2_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_i2_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_il_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_il_scaled(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_il_scaled_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_il_scaled_array(int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_k0_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_K0_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_k1_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_K1_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_k2_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_k2_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_kl_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_kl_scaled(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_kl_scaled_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_bessel_kl_scaled_array(int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Jnu_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Jnu(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Ynu_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Ynu(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_sequence_Jnu_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_bessel_sequence_Jnu
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Inu_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Inu_scaled(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Inu_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Inu(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Knu_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Knu_scaled(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_Knu_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_Knu(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_lnKnu_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_lnKnu(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_zero_J0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_zero_J0(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_zero_J1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_bessel_zero_J1(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_bessel_zero_Jnu_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_bessel_zero_Jnu
</para></entry></row><row><entry command="item"> <para>gsl_sf_clausen_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_clausen(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hydrogenicR_1_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_hydrogenicR_1
</para></entry></row><row><entry command="item"> <para>gsl_sf_hydrogenicR_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_hydrogenicR
</para></entry></row><row><entry command="item"> <para>gsl_sf_coulomb_wave_FG_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coulomb_wave_FG
</para></entry></row><row><entry command="item"> <para>gsl_sf_coulomb_wave_F_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coulomb_wave_F_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_coulomb_wave_FG_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coulomb_wave_FG_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_coulomb_wave_FGp_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coulomb_wave_FGp_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_coulomb_wave_sphF_array  </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coulomb_wave_sphF_array 
</para></entry></row><row><entry command="item"> <para>gsl_sf_coulomb_CL_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coulomb_CL
</para></entry></row><row><entry command="item"> <para>gsl_sf_coulomb_CL_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coulomb_CL_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_coupling_3j_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coupling_3j
</para></entry></row><row><entry command="item"> <para>gsl_sf_coupling_6j_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coupling_6j
</para></entry></row><row><entry command="item"> <para>gsl_sf_coupling_RacahW_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coupling_RacahW
</para></entry></row><row><entry command="item"> <para>gsl_sf_coupling_9j_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_coupling_9j
</para></entry></row><row><entry command="item"> <para>gsl_sf_coupling_6j_INCORRECT_e </para></entry><entry command="tab"> <para>N  </para></entry><entry command="tab"> <para>gsl_sf_coupling_6j_INCORRECT
</para></entry></row><row><entry command="item"> <para>gsl_sf_dawson_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_dawson(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_debye_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_debye_1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_debye_2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_debye_2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_debye_3_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_debye_3(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_debye_4_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_debye_4(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_debye_5_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_debye_5(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_debye_6_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_debye_6(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_dilog_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_dilog
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_dilog_xy_e  </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_dilog_xy_e 
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_dilog_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_dilog
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_spence_xy_e   </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_spence_xy_e  
</para></entry></row><row><entry command="item"> <para>gsl_sf_multiply_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_multiply
</para></entry></row><row><entry command="item"> <para>gsl_sf_multiply_err_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_multiply_err
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_Kcomp_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_Kcomp(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_Ecomp_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_Ecomp(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_Pcomp_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_Pcomp(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_Dcomp_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_Dcomp(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_F_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_F(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_E_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_E(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_P_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_P(dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_D_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_D(dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_RC_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_RC(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_RD_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_RD(dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_RF_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_RF(dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_ellint_RJ_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_ellint_RJ(dbl_expr,dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_elljac_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_elljac
</para></entry></row><row><entry command="item"> <para>gsl_sf_erfc_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_erfc(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_log_erfc_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_log_erfc(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_erf_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_erf(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_erf_Z_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_erf_Z(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_erf_Q_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_erf_Q(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hazard_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hazard(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_exp(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_e10_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_exp_e10
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_mult_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_exp_mult(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_mult_e10_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_exp_mult_e10
</para></entry></row><row><entry command="item"> <para>gsl_sf_expm1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expm1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exprel_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_exprel(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exprel_2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_exprel_2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exprel_n_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_exprel_n(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_err_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_exp_err(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_err_e10_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_exp_err_e10
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_mult_err_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_exp_mult_err
</para></entry></row><row><entry command="item"> <para>gsl_sf_exp_mult_err_e10_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_exp_mult_err_e10
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_E1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_E1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_E2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_E2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_En_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_En(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_E1_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_E1_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_E2_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_E2_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_En_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_En_scaled(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_Ei_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_Ei(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_Ei_scaled_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_Ei_scaled(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_Shi_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_Shi(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_Chi_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_Chi(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_expint_3_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_expint_3(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_Si_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_Si(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_Ci_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_Ci(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_atanint_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_atanint(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_m1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_m1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_int(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_mhalf_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_mhalf(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_half_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_half(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_3half_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_3half(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fermi_dirac_inc_0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fermi_dirac_inc_0(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lngamma_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_lngamma(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lngamma_sgn_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_lngamma_sgn 
</para></entry></row><row><entry command="item"> <para>gsl_sf_gamma_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gamma(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gammastar_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gammastar(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gammainv_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gammainv(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lngamma_complex_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_lngamma_complex
</para></entry></row><row><entry command="item"> <para>gsl_sf_taylorcoeff_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_taylorcoeff(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_fact_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_fact(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_doublefact_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_doublefact(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lnfact_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_lnfact(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lndoublefact_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_lndoublefact(uint_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lnchoose_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_lnchoose
</para></entry></row><row><entry command="item"> <para>gsl_sf_choose_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_choose
</para></entry></row><row><entry command="item"> <para>gsl_sf_lnpoch_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_lnpoch(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lnpoch_sgn_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_lnpoch_sgn
</para></entry></row><row><entry command="item"> <para>gsl_sf_poch_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_poch(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_pochrel_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_pochrel(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gamma_inc_Q_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gamma_inc_Q(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gamma_inc_P_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gamma_inc_P(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gamma_inc_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gamma_inc(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lnbeta_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_lnbeta(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lnbeta_sgn_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_lnbeta_sgn
</para></entry></row><row><entry command="item"> <para>gsl_sf_beta_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_beta(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_beta_inc_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_beta_inc
</para></entry></row><row><entry command="item"> <para>gsl_sf_gegenpoly_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gegenpoly_1(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gegenpoly_2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gegenpoly_2(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gegenpoly_3_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gegenpoly_3(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_gegenpoly_n_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_gegenpoly_n
</para></entry></row><row><entry command="item"> <para>gsl_sf_gegenpoly_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_gegenpoly_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_0F1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_0F1(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_1F1_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_1F1_int(int_expr,int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_1F1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_1F1(dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_U_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_U_int(int_expr,int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_U_int_e10_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_hyperg_U_int_e10
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_U_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_U(dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_U_e10_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_hyperg_U_e10
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_2F1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_2F1(dbl_expr,dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_2F1_conj_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_2F1_conj(dbl_expr,dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_2F1_renorm_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_2F1_renorm(dbl_expr,dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_2F1_conj_renorm_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_2F1_conj_renorm(dbl_expr,dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hyperg_2F0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hyperg_2F0(dbl_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_laguerre_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_laguerre_1(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_laguerre_2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_laguerre_2(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_laguerre_3_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_laguerre_3(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_laguerre_n_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_laguerre_n(int_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lambert_W0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_lambert_W0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_lambert_Wm1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_lambert_Wm1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Pl_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_Pl(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Pl_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_legendre_Pl_array(int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Pl_deriv_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_legendre_Pl_deriv_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_P1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_P1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_P2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_P2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_P3_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_P3(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Q0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_Q0(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Q1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_Q1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Ql_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_Ql(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Plm_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_Plm(int_expr,int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Plm_array  </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_legendre_Plm_array(int,int,double,&amp;var_out) 
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_Plm_deriv_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_legendre_Plm_deriv_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_sphPlm_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_sphPlm(int_expr,int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_sphPlm_array </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>status=gsl_sf_legendre_sphPlm_array(int,int,double,&amp;var_out)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_sphPlm_deriv_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_legendre_sphPlm_deriv_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_array_size </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_legendre_array_size
</para></entry></row><row><entry command="item"> <para>gsl_sf_conicalP_half_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_conicalP_half(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_conicalP_mhalf_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_conicalP_mhalf(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_conicalP_0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_conicalP_0(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_conicalP_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_conicalP_1(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_conicalP_sph_reg_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_conicalP_sph_reg(int_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_conicalP_cyl_reg_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_conicalP_cyl_reg(int_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_H3d_0_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_H3d_0(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_H3d_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_H3d_1(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_H3d_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_legendre_H3d(int_expr,dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_H3d_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_legendre_H3d_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_legendre_array_size </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_legendre_array_size
</para></entry></row><row><entry command="item"> <para>gsl_sf_log_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_log(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_log_abs_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_log_abs(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_log_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_log
</para></entry></row><row><entry command="item"> <para>gsl_sf_log_1plusx_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_log_1plusx(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_log_1plusx_mx_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_log_1plusx_mx(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_a_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_a_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_b_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_b_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_a </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_a
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_b </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_b
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_a_coeff </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_a_coeff
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_b_coeff </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_b_coeff
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_ce </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_ce
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_se </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_se
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_ce_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_ce_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_se_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_se_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_Mc </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_Mc
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_Ms </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_Ms
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_Mc_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_Mc_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_mathieu_Ms_array </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_mathieu_Ms_array
</para></entry></row><row><entry command="item"> <para>gsl_sf_pow_int_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_pow_int
</para></entry></row><row><entry command="item"> <para>gsl_sf_psi_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_psi_int(int_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_psi_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_psi(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_psi_1piy_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_psi_1piy(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_psi_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_psi
</para></entry></row><row><entry command="item"> <para>gsl_sf_psi_1_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_psi_1_int(int_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_psi_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_psi_1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_psi_n_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_psi_n(int_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_synchrotron_1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_synchrotron_1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_synchrotron_2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_synchrotron_2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_transport_2_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_transport_2(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_transport_3_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_transport_3(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_transport_4_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_transport_4(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_transport_5_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_transport_5(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_sin_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_sin
</para></entry></row><row><entry command="item"> <para>gsl_sf_cos_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_cos
</para></entry></row><row><entry command="item"> <para>gsl_sf_hypot_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_hypot
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_sin_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_sin
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_cos_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_cos
</para></entry></row><row><entry command="item"> <para>gsl_sf_complex_logsin_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_complex_logsin
</para></entry></row><row><entry command="item"> <para>gsl_sf_sinc_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_sinc
</para></entry></row><row><entry command="item"> <para>gsl_sf_lnsinh_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_lnsinh
</para></entry></row><row><entry command="item"> <para>gsl_sf_lncosh_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_lncosh
</para></entry></row><row><entry command="item"> <para>gsl_sf_polar_to_rect </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_polar_to_rect
</para></entry></row><row><entry command="item"> <para>gsl_sf_rect_to_polar </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_rect_to_polar
</para></entry></row><row><entry command="item"> <para>gsl_sf_sin_err_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_sin_err
</para></entry></row><row><entry command="item"> <para>gsl_sf_cos_err_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_cos_err
</para></entry></row><row><entry command="item"> <para>gsl_sf_angle_restrict_symm_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_angle_restrict_symm
</para></entry></row><row><entry command="item"> <para>gsl_sf_angle_restrict_pos_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_angle_restrict_pos
</para></entry></row><row><entry command="item"> <para>gsl_sf_angle_restrict_symm_err_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_angle_restrict_symm_err
</para></entry></row><row><entry command="item"> <para>gsl_sf_angle_restrict_pos_err_e </para></entry><entry command="tab"> <para>N </para></entry><entry command="tab"> <para>gsl_sf_angle_restrict_pos_err
</para></entry></row><row><entry command="item"> <para>gsl_sf_zeta_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_zeta_int(int_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_zeta_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_zeta(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_zetam1_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_zetam1(dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_zetam1_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_zetam1_int(int_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_hzeta_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_hzeta(dbl_expr,dbl_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_eta_int_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_eta_int(int_expr)
</para></entry></row><row><entry command="item"> <para>gsl_sf_eta_e </para></entry><entry command="tab"> <para>Y </para></entry><entry command="tab"> <para>gsl_sf_eta(dbl_expr)
</para></entry></row></tbody></multitable>

<html endspaces=" ">
&lt;a name=&quot;gsl_int&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gsl_int --&gt;
</html>
</subsection>
<node name="GSL-interpolation" spaces=" "><nodename>GSL interpolation</nodename><nodenext spaces=" ">GSL least-squares fitting</nodenext><nodeprev spaces=" ">GSL special functions</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>GSL interpolation</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1478"><acronym><acronymword>GSL</acronymword></acronym></indexterm></cindex>
<noindent></noindent> <para>As of version 3.9.9 (released July, 2009), <acronym><acronymword>NCO</acronymword></acronym> has wrappers to the <acronym><acronymword>GSL</acronymword></acronym> interpolation functions.
</para>
<noindent></noindent>  <para>Given a set of data points (x1,y1)...(xn, yn) the <acronym><acronymword>GSL</acronymword></acronym> functions computes a continuous interpolating function <acronym><acronymword>Y(x)</acronymword></acronym> such that <acronym><acronymword>Y(xi) = yi</acronymword></acronym>. The interpolation is piecewise smooth, and its behavior at the end-points is determined by the type of interpolation used. For more information consult the <acronym><acronymword>GSL</acronymword></acronym> manual. 
</para>
<noindent></noindent> <para>Interpolation with <command>ncap2</command> is a two stage process. In the first stage, a <acronym><acronymword>RAM</acronymword></acronym> variable is created from the chosen interpolating function and the data set. This <acronym><acronymword>RAM</acronymword></acronym> variable holds in memory a <acronym><acronymword>GSL</acronymword></acronym> interpolation object. In the second stage, points along the interpolating function are calculated. If you have a very large data set or are interpolating many sets then consider deleting the <acronym><acronymword>RAM</acronymword></acronym> variable when it is redundant. Use the command <command>ram_delete(var_nm)</command>.   
</para>
<noindent></noindent> <para>A simple example
</para>
<example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
x_in[$lon]={1.0,2.0,3.0,4.0};
y_in[$lon]={1.1,1.2,1.5,1.8};

// Ram variable is declared and defined here 
gsl_interp_cspline(&amp;ram_sp,x_in,y_in);

x_out[$lon_grd]={1.1,2.0,3.0,3.1,3.99};

y_out=gsl_spline_eval(ram_sp,x_out);
y2=gsl_spline_eval(ram_sp,1.3);
y3=gsl_spline_eval(ram_sp,0.0);
ram_delete(ram_sp);

print(y_out); // 1.10472, 1.2, 1.4, 1.42658, 1.69680002 
print(y2);    // 1.12454 
print(y3);    // '_' 
</verbatim>
</example>

<noindent></noindent> <para>Note in the above example y3 is set to &textrsquo;missing value&textrsquo; because 0.0 isn&textrsquo;t within the input X range.  
</para>
<para><strong><acronym><acronymword>GSL</acronymword></acronym> Interpolation Types</strong>&linebreak;
All the interpolation functions have been implemented. These are:&linebreak;
gsl_interp_linear() &linebreak; gsl_interp_polynomial() &linebreak; gsl_interp_cspline()&linebreak;
gsl_interp_cspline_periodic()&linebreak; gsl_interp_akima() &linebreak; gsl_interp_akima_periodic() &linebreak;
</para>
&linebreak; &linebreak;
<para><strong> Evaluation of Interpolating Types </strong> &linebreak;
<strong>Implemented</strong> &linebreak;
gsl_spline_eval() &linebreak;
<strong>Not implemented</strong> &linebreak;
gsl_spline_deriv()&linebreak;
gsl_spline_deriv2()&linebreak;
gsl_spline_integ()&linebreak;
</para>
<html endspaces=" ">
&lt;a name=&quot;ncap_lsqf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_lsqf --&gt;
</html>
</subsection>
<node name="GSL-least_002dsquares-fitting" spaces=" "><nodename>GSL least-squares fitting</nodename><nodenext spaces=" ">GSL statistics</nodenext><nodeprev spaces=" ">GSL interpolation</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces="  "><sectiontitle>GSL least-squares fitting       </sectiontitle>
<para>Least Squares fitting is a method of calculating a straight line
through a set of experimental data points in the XY plane.
Data may be weighted or unweighted.
For more information please refer to the <acronym><acronymword>GSL</acronymword></acronym> manual. 
</para>
<noindent></noindent> <para>These <acronym><acronymword>GSL</acronymword></acronym> functions fall into three categories:&linebreak;
<strong>A)</strong> Fitting data to Y=c0+c1*X&linebreak;
<strong>B)</strong> Fitting data (through the origin) Y=c1*X&linebreak;
<strong>C)</strong> Multi-parameter fitting (not yet implemented)&linebreak; 
</para>
<para><strong>Section A</strong> &linebreak;
<code>status=<strong>gsl_fit_linear</strong> (data_x,stride_x,data_y,stride_y,n,&amp;co,&amp;c1,&amp;cov00,&amp;cov01,&amp;cov11,&amp;sumsq)</code>
</para>
<noindent></noindent> <para><strong>Input variables</strong>: data_x, stride_x, data_y, stride_y, n &linebreak; 
From the above variables an X and Y vector both of length &textrsquo;n&textrsquo; are derived. 
If data_x or data_y is less than type double then it is converted to type <code>double</code>. 
It is up to you to do bounds checking on the input data. 
For example if stride_x=3 and n=8 then the size of data_x must be at least 24
</para>
<noindent></noindent> <para><strong>Output variables</strong>: c0, c1, cov00, cov01, cov11,sumsq &linebreak; 
The &textrsquo;&amp;&textrsquo; prefix indicates that these are call-by-reference variables.
If any of the output variables don&textrsquo;t exist prior to the call then they are created on the fly as scalar variables of type <code>double</code>. If they already exist then their existing value is overwritten. If the function call is successful then <code>status=0</code>. 
</para>
<para><code>status= <strong>gsl_fit_wlinear</strong>(data_x,stride_x,data_w,stride_w,data_y,stride_y,n,&amp;co,&amp;c1,&amp;cov00,&amp;cov01,&amp;cov11,&amp;chisq) </code>
</para>
<noindent></noindent> <para>Similar to the above call except it creates an additional weighting vector from the variables data_w, stride_w, n  
</para>

<para><code> data_y_out=<strong>gsl_fit_linear_est</strong>(data_x,c0,c1,cov00,cov01,cov11) </code>
</para>
<noindent></noindent> <para>This function calculates y values along the line Y=c0+c1*X &linebreak; &linebreak;
</para>
<para><strong>Section B</strong> &linebreak;
<code>status=<strong>gsl_fit_mul</strong>(data_x,stride_x,data_y,stride_y,n,&amp;c1,&amp;cov11,&amp;sumsq)</code>
</para>
<noindent></noindent> <para><strong>Input variables</strong>: data_x, stride_x, data_y, stride_y, n &linebreak; 
From the above variables an X and Y vector both of length &textrsquo;n&textrsquo; are derived. 
If data_x or data_y is less than type <code>double</code> then it is converted to type <code>double</code>. &linebreak;
</para>
<noindent></noindent> <para><strong>Output variables</strong>: c1,cov11,sumsq &linebreak; 
</para>
<para><code>status= <strong>gsl_fit_wmul</strong>(data_x,stride_x,data_w,stride_w,data_y,stride_y,n,&amp;c1,&amp;cov11,&amp;sumsq)</code>
</para>
<noindent></noindent> <para>Similar to the above call except it creates an additional weighting vector from the variables data_w, stride_w, n  
</para>
<para><code>data_y_out=<strong>gsl_fit_mul_est</strong>(data_x,c0,c1,cov11)</code>
</para>
<noindent></noindent> <para>This function calculates y values along the line Y=c1*X &linebreak;
</para>
<noindent></noindent> <para>The below example shows <strong>gsl_fit_linear()</strong> in action
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
defdim(&quot;d1&quot;,10);
xin[d1]={1,2,3,4,5,6,7,8,9,10.0};
yin[d1]={3.1,6.2,9.1,12.2,15.1,18.2,21.3,24.0,27.0,30.0};
gsl_fit_linear(xin,1,yin,1,$d1.size,&amp;c0,&amp;c1,&amp;cov00,&amp;cov01,&amp;cov11,&amp;sumsq);
print(c0);  // 0.2
print(c1);  // 2.98545454545

defdim(&quot;e1&quot;,4);
xout[e1]={1.0,3.0,4.0,11};
yout[e1]=0.0;

yout=gsl_fit_linear_est(xout,c0,c1,cov00,cov01,cov11,sumsq);

print(yout); // 3.18545454545, 9.15636363636, 12.1418181818, 33.04
</verbatim>
</example>

<noindent></noindent> <para>The following code does linear regression of sst(time,lat,lon) for each time-step&linebreak;
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
// Declare variables
c0[$lat, $lon]=0.; // Intercept
c1[$lat, $lon]=0.; // Slope
sdv[$lat, $lon]=0.; // Standard deviation
covxy[$lat, $lon]=0.; // Covariance
for (i=0;i&lt;$lat.size;i++) // Loop over lat
{
  for (j=0;j&lt;$lon.size;j++) // Loop over lon
  {
      // Linear regression function
      gsl_fit_linear(time,1,sst(:, i, j),1,$time.size,&amp;tc0,&amp;tc1,&amp;cov00,&amp;cov01,&amp;cov11,&amp;sumsq); 
      c0(i,j)=tc0; // Output results
      c1(i,j)=tc1; // Output results
      // Covariance function
      covxy(i,j)=gsl_stats_covariance(time,1,$time.size,double(sst(:,i,j)),1,$time.size); 
      // Standard deviation function
      sdv(i,j)=gsl_stats_sd(sst(:,i,j),1,$time.size); 
  }
 }
// slope (c1) missing values are set to '0', change to -999. (variable c0 intercept value)
where(c0 == -999) c1=-999;
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;ncap_stat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_stat --&gt;
</html>

</subsection>
<node name="GSL-statistics" spaces=" "><nodename>GSL statistics</nodename><nodenext spaces=" ">GSL random number generation</nodenext><nodeprev spaces=" ">GSL least-squares fitting</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>GSL statistics</sectiontitle>

<noindent></noindent> <para>Wrappers for most of the <acronym><acronymword>GSL</acronymword></acronym> Statistical functions have been implemented. The <acronym><acronymword>GSL</acronymword></acronym> function names include a type specifier (except for type double functions). To obtain the equivalent <acronym><acronymword>NCO</acronymword></acronym> name simply remove the type specifier; then depending on the data type the appropriate <acronym><acronymword>GSL</acronymword></acronym> function  is called. The weighed statistical functions e.g., <code> gsl_stats_wvariance()</code> are only defined in <acronym><acronymword>GSL</acronymword></acronym> for floating-point types; so your data must of type <code>float</code> or <code>double</code> otherwise ncap2 will emit an error message. To view the implemented functions use the shell command <command>ncap2 -f|grep _stats</command>   
</para>
<noindent></noindent> <para><acronym><acronymword>GSL</acronymword></acronym> Functions
</para><example endspaces=" ">
<pre xml:space="preserve">short gsl_stats_max (short data[], size_t stride, size_t n);
double gsl_stats_int_mean (int data[], size_t stride, size_t n);
double gsl_stats_short_sd_with_fixed_mean (short data[], size_t stride, size_t n, double mean);
double gsl_stats_wmean (double w[], size_t wstride, double data[], size_t stride, size_t n);
double gsl_stats_quantile_from_sorted_data (double sorted_data[], size_t stride, size_t n, double f) ;
</pre></example>

<noindent></noindent> <para>Equivalent ncap2 wrapper functions
</para><example endspaces=" ">
<pre xml:space="preserve">short gsl_stats_max (var_data, data_stride, n);
double gsl_stats_mean (var_data, data_stride, n);
double gsl_stats_sd_with_fixed_mean (var_data, data_stride, n, var_mean);
double gsl_stats_wmean (var_weight, weight_stride, var_data, data_stride, n, var_mean);
double gsl_stats_quantile_from_sorted_data (var_sorted_data, data_stride, n, var_f) ;
</pre></example>

<noindent></noindent> <para><acronym><acronymword>GSL</acronymword></acronym> has no notion of missing values or dimensionality beyond one. If your data has missing values which you want ignored in the calculations then use the <command>ncap2</command> built in aggregate functions(<ref label="Methods-and-functions"><xrefnodename>Methods and functions</xrefnodename></ref>). The <acronym><acronymword>GSL</acronymword></acronym> functions operate on a vector of values created from the var_data/stride/n arguments. The ncap wrappers check that there is no bounding error with regard to the size of the data and the final value in the vector. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
a1[time]={1,2,3,4,5,6,7,8,9,10};

a1_avg=gsl_stats_mean(a1,1,10);
print(a1_avg); // 5.5

a1_var=gsl_stats_variance(a1,4,3);
print(a1_var); // 16.0

// bounding error, vector attempts to access element a1(10)
a1_sd=gsl_stats_sd(a1,5,3); 
</verbatim>
</example>

<noindent></noindent> <para>For functions with the signature 
<strong>func_nm(var_data,data_stride,n)</strong>, 
one may omit the second or third arguments. 
The default value for <var>stride</var> is <code>1</code>. 
The default value for <var>n</var> is <code>1+(data.size()-1)/stride</code>.
</para>
<example endspaces=" ">
<pre xml:space="preserve">// Following statements are equvalent
n2=gsl_stats_max(a1,1,10)
n2=gsl_stats_max(a1,1);
n2=gsl_stats_max(a1);

// Following statements are equvalent
n3=gsl_stats_median_from_sorted_data(a1,2,5);
n3=gsl_stats_median_from_sorted_data(a1,2);

// Following statements are NOT equvalent
n4=gsl_stats_kurtosis(a1,3,2);
n4=gsl_stats_kurtosis(a1,3); //default n=4
</pre></example> 

<para>The following example illustrates some of the weighted functions.
The data are randomly generated. 
In this case the value of the weight for each datum is either 0.0 or 1.0   
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;r1&quot;,2000);
data[r1]=1.0;

// Fill with random numbers [0.0,10.0)
data=10.0*gsl_rng_uniform(data);

// Create a weighting variable
weight=(data&gt;4.0);

wmean=gsl_stats_wmean(weight,1,data,1,$r1.size);
print(wmean);

wsd=gsl_stats_wsd(weight,1,data,1,$r1.size);
print(wsd);

// number of values in data that are greater than 4
weight_size=weight.total();
print(weight_size);

// print min/max of data 
dmin=data.gsl_stats_min();
dmax=data.gsl_stats_max();
print(dmin);print(dmax);
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ncap_rng&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_rng --&gt;
</html>

</subsection>
<node name="GSL-random-number-generation" spaces=" "><nodename>GSL random number generation</nodename><nodenext spaces=" ">Examples ncap2</nodenext><nodeprev spaces=" ">GSL statistics</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>GSL random number generation</sectiontitle>
<para>The <acronym><acronymword>GSL</acronymword></acronym> library has a large number of random number generators. In addition there are a large set of functions for turning uniform random numbers into discrete or continuous probabilty distributions. The random number generator algorithms vary in terms of quality numbers output, speed of execution and maximum number output. For more information see the <acronym><acronymword>GSL</acronymword></acronym> documentation. The algorithm and seed are set via environment variables, these are picked up by the <code>ncap2</code> code.
</para>
<noindent></noindent> <para><strong>Setup</strong> &linebreak;  
The number algorithm is set by the environment variable <code>GSL_RNG_TYPE</code>. If this variable isn&textrsquo;t set then the default rng algorithm is gsl_rng_19937. The seed is set with the environment variable <code>GSL_RNG_SEED</code>. The following wrapper functions in ncap2 provide information about the chosen algorithm. &linebreak; 
</para>
<table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">gsl_rng_min() </itemformat></item>
</tableterm><tableitem><para>the minimum value returned by the rng algorithm.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">gsl_rng_max()</itemformat></item>
</tableterm><tableitem><para>the maximum value returned by the rng algorithm. 
</para></tableitem></tableentry></table>

<noindent></noindent> <para><strong>Uniformly Distributed Random Numbers</strong> 
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">gsl_rng_get(var_in)</itemformat></item>
</tableterm><tableitem><para>This function returns var_in with integers from the chosen rng algorithm. The min and max values depend uoon the chosen rng algorthm.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">gsl_rng_uniform_int(var_in)</itemformat></item>
</tableterm><tableitem><para>This function returns var_in with random integers from 0 to n-1. The value n must be less than or equal to the maximum value of the chosen rng algorithm. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">gsl_rng_uniform(var_in)</itemformat></item>
</tableterm><tableitem><para>This function returns var_in with double-precision numbers in the range [0.0,1). The range includes 0.0 and excludes 1.0.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">gsl_rng_uniform_pos(var_in)</itemformat></item>
</tableterm><tableitem><para>This function returns var_in with double-precision numbers in the range (0.0,1), excluding both 0.0 and 1.0.
</para></tableitem></tableentry></table>

<noindent></noindent> <para>Below are examples of <code>gsl_rng_get()</code> and <code>gsl_rng_uniform_int()</code> in action.
</para>
<example endspaces=" ">
<pre xml:space="preserve">export GSL_RNG_TYPE=ranlux
export GSL_RNG_SEED=10
ncap2 -v -O -s 'a1[time]=0;a2=gsl_rng_get(a1);' in.nc foo.nc 
// 10 random numbers from the range 0 - 16777215
// a2=9056646, 12776696, 1011656, 13354708, 5139066, 1388751, 11163902, 7730127, 15531355, 10387694 ;

ncap2 -v -O -s 'a1[time]=21;a2=gsl_rng_uniform_int(a1).sort();' in.nc foo.nc
// 10 random numbers from the range 0 - 20
a2 = 1, 1, 6, 9, 11, 13, 13, 15, 16, 19 ;

</pre></example>

<noindent></noindent> <para>The following example produces an <code>ncap2</code> runtime error. This is because the chose rng algorithm has a maximum value greater than <code>NC_MAX_INT=2147483647</code>; the wrapper functions to <code>gsl_rng_get()</code> and <code>gsl_rng_uniform_int()</code> return variable of type <code>NC_INT</code>. Please be aware of this when using random number distribution functions functions from the <acronym><acronymword>GSL</acronymword></acronym> library which return <code>unsigned int</code>. Examples of these are <code>gsl_ran_geometric()</code> and <code>gsl_ran_pascal()</code>. 
</para>
<example endspaces=" ">
<pre xml:space="preserve">export GSL_RNG_TYPE=mt19937
ncap2 -v -O -s 'a1[time]=0;a2=gsl_rng_get(a1);' in.nc foo.nc 
</pre></example>

<noindent></noindent> <para>To find the maximum value of the chosen rng algorithm use the following code snippet.
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -v -O -s 'rng_max=gsl_rng_max();print(rng_max)' in.nc foo.nc
</pre></example>

<noindent></noindent> <para><strong>Random Number Distributions</strong> &linebreak;
The <acronym><acronymword>GSL</acronymword></acronym> library has a rich set of random number disribution functions. The library also provides cumulative distribution functions and inverse cumulative distribution functions sometimes referred to a quantile functions. To see whats available on your build use the shell command <code>ncap2 -f|grep -e _ran -e _cdf</code>.
</para>
<noindent></noindent> <para>The following examples all return variables of type <code>NC_INT</code> &linebreak;
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;out&quot;,15);
a1[$out]=0.5;
a2=gsl_ran_binomial(a1,30).sort();
//a2 = 10, 11, 12, 12, 13, 14, 14, 15, 15, 16, 16, 16, 16, 17, 22 ;
a3=gsl_ran_geometric(a2).sort();
//a2 = 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 4, 5 ;
a4=gsl_ran_pascal(a2,50);
//a5 = 37, 40, 40, 42, 43, 45, 46, 49, 52, 58, 60, 62, 62, 65, 67 ;
</pre></example>

<noindent></noindent> <para>The following all return variables of type <code>NC_DOUBLE</code>;
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;b1&quot;,1000);
b1[$b1]=0.8;
b2=gsl_ran_exponential(b1);
b2_avg=b2.avg();
print(b2_avg);
// b2_avg = 0.756047976787

b3=gsl_ran_gaussian(b1);
b3_avg=b3.avg();
b3_rms=b3.rms();
print(b3_avg);
// b3_avg = -0.00903446534258;
print(b3_rms);
// b3_rms = 0.81162979889;

b4[$b1]=10.0;
b5[$b1]=20.0;
b6=gsl_ran_flat(b4,b5);
b6_avg=b6.avg();
print(b6_avg);
// b6_avg=15.0588129413
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ncap_emp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_emp --&gt;
</html>
</subsection>
<node name="Examples-ncap2" spaces=" "><nodename>Examples ncap2</nodename><nodenext spaces=" ">Intrinsic mathematical methods</nodenext><nodeprev spaces=" ">GSL random number generation</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Examples ncap2</sectiontitle>

<para>See the <file>ncap.in</file> and <file>ncap2.in</file> scripts released with <acronym><acronymword>NCO</acronymword></acronym> 
for more complete demonstrations of <command>ncap2</command> functionality
(script available on-line at <url><urefurl>http://nco.sf.net/ncap2.in</urefurl></url>).
</para>
<para>Define new attribute <var>new</var> for existing variable <var>one</var>
as twice the existing attribute <var>double_att</var> of variable
<var>att_var</var>: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -s 'one@new=2*att_var@double_att' in.nc out.nc
</verbatim>
</example>

<para>Average variables of mixed types (result is of type <code>double</code>):
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'average=(var_float+var_double+var_int)/3' in.nc out.nc 
</pre></example>

<para>Multiple commands may be given to <command>ncap2</command> in three ways.
First, the commands may be placed in a script which is executed, e.g.,
<file>tst.nco</file>. 
Second, the commands may be individually specified with multiple
<samp>-s</samp> arguments to the same <command>ncap2</command> invocation.
Third, the commands may be chained into a single <samp>-s</samp>
argument to <command>ncap2</command>.
Assuming the file <file>tst.nco</file> contains the commands
<code>a=3;b=4;c=sqrt(a^2+b^2);</code>, then the following <command>ncap2</command>
invocations produce identical results:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -v -S tst.nco in.nc out.nc
ncap2 -v -s 'a=3' -s 'b=4' -s 'c=sqrt(a^2+b^2)' in.nc out.nc
ncap2 -v -s 'a=3;b=4;c=sqrt(a^2+b^2)' in.nc out.nc
</pre></example>
<para>The second and third examples show that <command>ncap2</command> does not require
that a trailing semi-colon <samp>;</samp> be placed at the end of a <samp>-s</samp>
argument, although a trailing semi-colon <samp>;</samp> is always allowed.
However, semi-colons are required to separate individual assignment
statements chained together as a single <samp>-s</samp> argument. 
</para>
<html endspaces=" ">
&lt;a name=&quot;xmp_grw&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_grw --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1479">growing dimensions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1480">dimensions, growing</indexterm></cindex>
<para><command>ncap2</command> may be used to &textldquo;grow&textrdquo; dimensions, i.e., to increase
dimension sizes without altering existing data.
Say <file>in.nc</file> has <code>ORO(lat,lon)</code> and the user wishes a new
file with <code>new_ORO(new_lat,new_lon)</code> that contains zeros in the
undefined portions of the new grid.
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;new_lat&quot;,$lat.size+1); // Define new dimension sizes
defdim(&quot;new_lon&quot;,$lon.size+1);
new_ORO[$new_lat,$new_lon]=0.0f; // Initialize to zero
new_ORO(0:$lat.size-1,0:$lon.size-1)=ORO; // Fill valid data
</pre></example>
<para>The commands to define new coordinate variables <code>new_lat</code>
and <code>new_lon</code> in the output file follow a similar pattern.
One would might store these commands in a script <file>grow.nco</file>
and then execute the script with
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -v -S grow.nco in.nc out.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;flg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#flg --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1481">flags</indexterm></cindex>
<para>Imagine you wish to create a binary flag based on the value of 
an array.
The flag should have <w>value 1.0</w> where the array <w>exceeds 1.0</w>,
and <w>value 0.0</w> elsewhere.
This example creates the binary flag <code>ORO_flg</code> in <file>out.nc</file>
from the continuous array named <code>ORO</code> in <file>in.nc</file>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'ORO_flg=(ORO &gt; 1.0)' in.nc out.nc
</pre></example>
<para>Suppose your task is to change all values of <code>ORO</code> which 
<w>equal 2.0</w> to the new <w>value 3.0</w>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'ORO_msk=(ORO==2.0);ORO=ORO_msk*3.0+!ORO_msk*ORO' in.nc out.nc
</pre></example>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1482">mask</indexterm></cindex>
<para>This creates and uses <code>ORO_msk</code> to mask the subsequent arithmetic
operation.
Values of <code>ORO</code> are only changed where <code>ORO_msk</code> is true,
i.e., where <code>ORO</code> <w>equals 2.0</w> &linebreak;
Using the <code>where</code> statement the above code simplifies to :
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'where(ORO == 2.0) ORO=3.0;' in.nc foo.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;cvr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cvr --&gt;
</html>
<para>This example uses <command>ncap2</command> to compute the covariance of two
variables. 
Let the variables <var>u</var> and <var>v</var> be the horizontal 
wind components. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1483">covariance</indexterm></cindex>
<!-- c fxm 20030423: texi2html 1.64 has problems with this legal syntax but makeinfo -html does not -->
The <dfn>covariance</dfn> of <var>u</var> and <var>v</var> is defined
as the time mean product of the deviations of <var>u</var> and
<var>v</var> from their respective time means.
Symbolically, the covariance 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$[\wndznl^{\prime} \wndmrd^{\prime}] =
[\wndznl\wndmrd]-[\wndznl][\wndmrd]$ where $[\xxx]$ denotes the
time-average of~$\xxx$, 
$[\xxx] \equiv {1 \over \tau} \int_{\tm=0}^{\tm=\tau} \xxx(\tm) \,\dfr\tm$
and $\xxx^{\prime}$ 
@clear flg 
</tex>
<math>[<var>u'v'</var>] =
[<var>uv</var>]-[<var>u</var>][<var>v</var>]</math> 
where <math>[<var>x</var>]</math> denotes the time-average of
<math><var>x</var></math> and <math><var>x'</var></math> 
<clear name="flg" line=" flg"></clear>
denotes the deviation from the time-mean. 
The covariance tells us how much of the correlation of two signals
arises from the signal fluctuations versus the mean signals.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1484">eddy covariance</indexterm></cindex>
Sometimes this is called the <dfn>eddy covariance</dfn>.
We will store the covariance in the variable <code>uprmvprm</code>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -O -a time -v u,v in.nc foo.nc # Compute time mean of u,v
ncrename -O -v u,uavg -v v,vavg foo.nc # Rename to avoid conflict
ncks -A -v uavg,vavg foo.nc in.nc # Place time means with originals
ncap2 -O -s 'uprmvprm=u*v-uavg*vavg' in.nc in.nc # Covariance
ncra -O -v uprmvprm in.nc foo.nc # Time-mean covariance
</pre></example>
<para>The mathematically inclined will note that the same covariance would be
obtained by replacing the step involving <command>ncap2</command> with
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -O -s 'uprmvprm=(u-uavg)*(v-vavg)' foo.nc foo.nc # Covariance
</pre></example>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 3.1.8 (December, 2006), <command>ncap2</command>
can compute averages, and thus covariances, by itself:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'uavg=u.avg($time);vavg=v.avg($time);uprmvprm=u*v-uavg*vavg' \
      -s 'uprmvrpmavg=uprmvprm.avg($time)' in.nc foo.nc
</pre></example>
<para>We have not seen a simpler method to script and execute powerful
arithmetic than <command>ncap2</command>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1485">globbing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1486">shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1487">quotes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1488">extended regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1489">regular expressions</indexterm></cindex>
<para><command>ncap2</command> utilizes many meta-characters 
(e.g., <samp>$</samp>, <samp>?</samp>, <samp>;</samp>, <samp>()</samp>, <samp>[]</samp>)
that can confuse the command-line shell if not quoted properly.
The issues are the same as those which arise in utilizing extended
regular expressions to subset variables (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>).
The example above will fail with no quotes and with double quotes.
This is because shell globbing tries to <dfn>interpolate</dfn> the value of
<code>$time</code> from the shell environment unless it is quoted:
</para><example endspaces=" ">
<pre xml:space="preserve">ncap2 -s 'uavg=u.avg($time)'  in.nc foo.nc # Correct (recommended)
ncap2 -s  uavg=u.avg('$time') in.nc foo.nc # Correct (and dangerous)
ncap2 -s  uavg=u.avg($time)   in.nc foo.nc # Wrong ($time = '')
ncap2 -s &quot;uavg=u.avg($time)&quot;  in.nc foo.nc # Wrong ($time = '')
</pre></example>
<para>Without the single quotes, the shell replaces <code>$time</code> with an
empty string.
The command <command>ncap2</command> receives from the shell is
<code>uavg=u.avg()</code>. 
This causes <command>ncap2</command> to average over all dimensions rather than
just the <var>time</var> dimension, and unintended consequence.
</para>
<para>We recommend using single quotes to protect <command>ncap2</command>
command-line scripts from the shell, even when such protection is not
strictly necessary. 
Expert users may violate this rule to exploit the ability to use shell
variables in <command>ncap2</command> command-line scripts 
(<pxref label="CCSM-Example"><xrefnodename>CCSM Example</xrefnodename></pxref>). 
In such cases it may be necessary to use the shell backslash character
<samp>\</samp> to protect the <command>ncap2</command> meta-character.
</para>

<cindex index="cp" spaces=" "><indexterm index="cp" number="1490">appending data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1491">time-averaging</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="18" mergedindex="cp">ncks</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="19" mergedindex="cp">ncwa</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="20" mergedindex="cp">ncra</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1492">degenerate dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1493"><samp>-b</samp></indexterm></cindex>
<para>A dimension of size one is said to be <emph>degenerate</emph>.
Whether a degenerate record dimension is desirable or not
depends on the application.
Often a degenerate <var>time</var> dimension is useful, e.g., for
concatenating, though it may cause problems with arithmetic.
Such is the case in the above example, where the first step employs
<command>ncwa</command> rather than <command>ncra</command> for the time-averaging.
Of course the numerical results are the same with both operators.
The difference is that, unless <samp>-b</samp> is specified, <command>ncwa</command>
writes no <var>time</var> dimension to the output file, while <command>ncra</command>
defaults to keeping <var>time</var> as a degenerate (<w>size 1</w>) dimension. 
Appending <code>u</code> and <code>v</code> to the output file would cause
<command>ncks</command> to try to expand the degenerate time axis of <code>uavg</code>
and <code>vavg</code> to the size of the non-degenerate <var>time</var> dimension
in the input file.
Thus the append (<command>ncks -A</command>) command would be undefined (and
should fail) in this case. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1494"><code>-C</code></indexterm></cindex>
Equally important is the <samp>-C</samp> argument 
(<pxref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></pxref>) to <command>ncwa</command> to prevent
any scalar <var>time</var> variable from being written to the output file.  
Knowing when to use <command>ncwa -a time</command> rather than the default
<command>ncra</command> for time-averaging takes, well, time.
</para>
<html endspaces=" ">
&lt;a name=&quot;mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mth --&gt;
</html>
</subsection>
<node name="Intrinsic-mathematical-methods" spaces=" "><nodename>Intrinsic mathematical methods</nodename><nodenext spaces=" " trailingspaces=" ">Operator precedence and associativity</nodenext><nodeprev spaces=" ">Examples ncap2</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Intrinsic mathematical methods</sectiontitle>
<para><command>ncap2</command> supports the standard mathematical functions supplied with
most operating systems.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1495">addition</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1496">subtraction</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1497">multiplication</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1498">division</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1499">exponentiation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1500">power</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1501">modulus</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1502"><code>+</code> (addition)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1503"><code>-</code> (subtraction)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1504"><code>*</code> (multiplication)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1505"><code>/</code> (division)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1506"><code>^</code> (power)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1507"><code>%</code> (modulus)</indexterm></cindex>
Standard calculator notation is used for addition <kbd>+</kbd>, subtraction
<kbd>-</kbd>, multiplication <kbd>*</kbd>, division <kbd>/</kbd>, exponentiation
<kbd>^</kbd>, and modulus <kbd>%</kbd>.
The available elementary mathematical functions are: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1508"><var>abs</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1509"><var>acosh</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1510"><var>acos</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1511"><var>asinh</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1512"><var>asin</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1513"><var>atanh</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1514"><var>atan</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1515"><var>ceil</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1516"><var>cosh</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1517"><var>cos</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1518"><var>erfc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1519"><var>erf</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1520"><var>exp</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1521"><var>floor</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1522"><var>gamma</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1523"><var>ln</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1524"><var>log10</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1525"><var>log</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1526"><var>nearbyint</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1527"><var>pow</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1528"><var>rint</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1529"><var>round</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1530"><var>sinh</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1531"><var>sin</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1532"><var>sqrt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1533"><var>tanh</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1534"><var>tan</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1535"><var>trunc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1536">mathematical functions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1537">nearest integer function (inexact)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1538">nearest integer function (exact)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1539">rounding functions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1540">truncation function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1541">absolute value</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1542">arccosine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1543">arcsine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1544">arctangent function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1545">ceiling function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1546">complementary error function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1547">cosine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1548">error function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1549">exponentiation function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1550">floor function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1551">gamma function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1552">hyperbolic arccosine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1553">hyperbolic arcsine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1554">hyperbolic arctangent function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1555">hyperbolic cosine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1556">hyperbolic sine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1557">hyperbolic tangent</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1558">logarithm, base 10</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1559">logarithm, natural</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1560">power function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1561">sine function</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1562">square root function</indexterm></cindex>
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">abs(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Absolute value</dfn>
<tex endspaces=" ">
Absolute value of $x$, $|x|$.
</tex>
Absolute value of <var>x</var>.
Example: 
<tex endspaces=" ">
abs$(-1) = 1$
</tex>
<math>abs(-1) = 1</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">acos(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Arc-cosine</dfn>
Arc-cosine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
acos$(1.0) = 0.0$
</tex>
<math>acos(1.0) = 0.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">acosh(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Hyperbolic arc-cosine</dfn>
Hyperbolic arc-cosine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
acosh$(1.0) = 0.0$
</tex>
<math>acosh(1.0) = 0.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">asin(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Arc-sine</dfn>
Arc-sine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
asin$(1.0) = 1.57079632679489661922$
</tex>
<math>asin(1.0) = 1.57079632679489661922</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">asinh(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Hyperbolic arc-sine</dfn>
Hyperbolic arc-sine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
asinh$(1.0) = 0.88137358702$
</tex>
<math>asinh(1.0) = 0.88137358702</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">atan(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Arc-tangent</dfn>
Arc-tangent of <var>x</var> where <var>x</var> is specified in radians between 
<tex endspaces=" ">
$-\pi/2$ and $\pi/2$.
</tex>
<math>-pi/2</math> and <math>pi/2</math>.
Example: 
<tex endspaces=" ">
atan$(1.0) = 0.78539816339744830961$
</tex>
<math>atan(1.0) = 0.78539816339744830961</math>
</para>
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">atan2(y,x)</itemformat></item>
</tableterm><tableitem><para><dfn>Arc-tangent2</dfn>
Arc-tangent of <var>y/x</var> 
<math>:Example atan2(1,3) =  0.321689857</math>
</para>
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">atanh(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Hyperbolic arc-tangent</dfn>
Hyperbolic arc-tangent of <var>x</var> where <var>x</var> is specified in radians between 
<tex endspaces=" ">
$-\pi/2$ and $\pi/2$.
</tex>
<math>-pi/2</math> and <math>pi/2</math>.
Example:
<tex endspaces=" ">
atanh$(3.14159265358979323844) = 1.0$
</tex>
<math>atanh(3.14159265358979323844) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ceil(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Ceil</dfn>
Ceiling of <var>x</var>. Smallest integral value not less than argument.
Example: 
<tex endspaces=" ">
ceil$(0.1) = 1.0$
</tex>
<math>ceil(0.1) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">cos(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Cosine</dfn>
Cosine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
cos$(0.0) = 1.0$
</tex>
<math>cos(0.0) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">cosh(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Hyperbolic cosine</dfn>
Hyperbolic cosine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
cosh$(0.0) = 1.0$
</tex>
<math>cosh(0.0) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">erf(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Error function</dfn>
Error function of <var>x</var> where <var>x</var> is specified between
<tex endspaces=" ">
$-1$ and $1$.
</tex>
<math>-1</math> and <math>1</math>.
Example: 
<tex endspaces=" ">
erf$(1.0) = 0.842701$
</tex>
<math>erf(1.0) = 0.842701</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">erfc(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Complementary error function</dfn>
Complementary error function of <var>x</var> where <var>x</var> is specified between
<tex endspaces=" ">
$-1$ and $1$.
</tex>
<math>-1</math> and <math>1</math>.
Example: 
<tex endspaces=" ">
erfc$(1.0) = 0.15729920705$
</tex>
<math>erfc(1.0) = 0.15729920705</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">exp(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Exponential</dfn>
Exponential of <var>x</var>,
<tex endspaces=" ">
$e^{x}$.
</tex>
<math>e^x</math>.
Example: 
<tex endspaces=" ">
exp$(1.0) = 2.71828182845904523536$
</tex>
<math>exp(1.0) = 2.71828182845904523536</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">floor(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Floor</dfn>
Floor of <var>x</var>. Largest integral value not greater than argument.
Example: 
<tex endspaces=" ">
floor$(1.9) = 1$
</tex>
<math>floor(1.9) = 1</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">gamma(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Gamma function</dfn>
Gamma function of <var>x</var>,
<tex endspaces=" ">
$\Gamma(x)$.
</tex>
<math>Gamma(x)</math>.
The well-known and loved continuous factorial function.
Example: 
<tex endspaces=" ">
gamma$(0.5) = \sqrt{\pi}$
</tex>
<math>gamma(0.5) = sqrt(pi)</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">gamma_inc_P(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Incomplete Gamma function</dfn>
Incomplete Gamma function of parameter <var>a</var> and variable <var>x</var>,
<tex endspaces=" ">
$P(a,x)$.
</tex>
<math>gamma_inc_P(a,x)</math>.
One of the four incomplete gamma functions.
Example: 
<tex endspaces=" ">
gamma\_inc\_P$(1,1) = 1-\me^{-1}$
</tex>
<math>gamma_inc_P(1,1) = 1-1/e</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ln(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Natural Logarithm</dfn>
Natural logarithm of <var>x</var>,
<tex endspaces=" ">
$\ln(x)$.
</tex>
<math>ln(x)</math>.
Example: 
<tex endspaces=" ">
ln$(2.71828182845904523536) = 1.0$
</tex>
<math>ln(2.71828182845904523536) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">log(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Natural Logarithm</dfn>
Exact synonym for <code>ln(x)</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">log10(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Base 10 Logarithm</dfn>
<w>Base 10</w> logarithm of <var>x</var>, 
<tex endspaces=" ">
$\log_{10}(x)$.
</tex>
<math>log10(x)</math>.
Example: 
<tex endspaces=" ">
log$(10.0) = 1.0$
</tex>
<math>log(10.0) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">nearbyint(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Round inexactly</dfn>
Nearest integer to <var>x</var> is returned in floating-point format.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1563">inexact conversion</indexterm></cindex>
No exceptions are raised for <dfn>inexact conversions</dfn>.
Example: 
<tex endspaces=" ">
nearbyint$(0.1) = 0.0$
</tex>
<math>nearbyint(0.1) = 0.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">pow(x,y)</itemformat></item>
</tableterm><tableitem><para><dfn>Power</dfn>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1564">promotion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1565">automatic type conversion</indexterm></cindex>
Value of <var>x</var> is raised to the power of <var>y</var>.
Exceptions are raised for <dfn>domain errors</dfn>.
Due to type-limitations in the <w>C language</w> <code>pow</code> function,
integer arguments are promoted (<pxref label="Type-Conversion"><xrefnodename>Type Conversion</xrefnodename></pxref>) to type
<code>NC_FLOAT</code> before evaluation. 
Example: 
<tex endspaces=" ">
pow$(2,3) = 8$
</tex>
<math>pow(2,3) = 8</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">rint(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Round exactly</dfn>
Nearest integer to <var>x</var> is returned in floating-point format.
Exceptions are raised for <dfn>inexact conversions</dfn>.
Example: 
<tex endspaces=" ">
rint$(0.1) = 0.0$
</tex>
<math>rint(0.1) = 0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">round(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Round</dfn>
Nearest integer to <var>x</var> is returned in floating-point format.
Round halfway cases away from zero, regardless of current <acronym><acronymword>IEEE</acronymword></acronym>
rounding direction.  
Example: 
<tex endspaces=" ">
round$(0.5) = 1.0$
</tex>
<math>round(0.5) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">sin(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Sine</dfn>
Sine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
sin$(1.57079632679489661922) = 1.0$
</tex>
<math>sin(1.57079632679489661922) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">sinh(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Hyperbolic sine</dfn>
Hyperbolic sine of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
sinh$(1.0) = 1.1752$
</tex>
<math>sinh(1.0) = 1.1752</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">sqrt(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Square Root</dfn>
Square Root of <var>x</var>,
<tex endspaces=" ">
$\sqrt{x}$.
</tex>
<math>sqrt(x)</math>.
Example: 
<tex endspaces=" ">
sqrt$(4.0) = 2.0$
</tex>
<math>sqrt(4.0) = 2.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">tan(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Tangent</dfn>
Tangent of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
tan$(0.78539816339744830961) = 1.0$
</tex>
<math>tan(0.78539816339744830961) = 1.0</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">tanh(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Hyperbolic tangent</dfn>
Hyperbolic tangent of <var>x</var> where <var>x</var> is specified in radians.
Example: 
<tex endspaces=" ">
tanh$(1.0) = 0.761594155956$
</tex>
<math>tanh(1.0) = 0.761594155956</math>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">trunc(x)</itemformat></item>
</tableterm><tableitem><para><dfn>Truncate</dfn>
Nearest integer to <var>x</var> is returned in floating-point format.
Round halfway cases toward zero, regardless of current <acronym><acronymword>IEEE</acronymword></acronym>
rounding direction.  
Example: 
<tex endspaces=" ">
trunc$(0.5) = 0.0$
</tex>
<math>trunc(0.5) = 0.0</math>
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>The complete list of mathematical functions supported is
platform-specific.  
Functions mandated by <w>ANSI C</w> are <emph>guaranteed</emph> to be present
and are indicated with an asterisk 
<!-- c fxm No they are not, not yet -->
<cindex index="cp" spaces=" "><indexterm index="cp" number="1566"><code>ANSI C</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1567"><code>float</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1568">precision</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1569">quadruple-precision</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1570">single-precision</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1571">double-precision</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1572"><code>long double</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1573"><code>NC_DOUBLE</code></indexterm></cindex>
<footnote spaces="\n"><para><w>ANSI C</w> compilers are guaranteed to support double-precision versions
of these functions.
These functions normally operate on netCDF variables of type <code>NC_DOUBLE</code>
without having to perform intrinsic conversions.
For example, <acronym><acronymword>ANSI</acronymword></acronym> compilers provide <code>sin</code> for the sine of C-type
<code>double</code> variables. 
The <acronym><acronymword>ANSI</acronymword></acronym> standard does not require, but many compilers provide,
an extended set of mathematical functions that apply to single
(<code>float</code>) and quadruple (<code>long double</code>) precision variables. 
Using these functions (e.g., <code>sinf</code> for <code>float</code>, 
<code>sinl</code> for <code>long double</code>), when available, is (presumably)
more efficient than casting variables to type <code>double</code>,
performing the operation, and then re-casting.
<acronym><acronymword>NCO</acronymword></acronym> uses the faster intrinsic functions when they are
available, and uses the casting method when they are not.
</para></footnote>.
and are indicated with an asterisk. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1574"><code>-f</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1575"><code>--prn_fnc_tbl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1576"><code>--fnc_tbl</code></indexterm></cindex>
Use the <samp>-f</samp> (or <samp>fnc_tbl</samp> or <samp>prn_fnc_tbl</samp>) switch
to print a complete list of functions supported on your platform.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1577">Linux</indexterm></cindex>
<footnote><para>Linux supports more of these intrinsic functions than
other OSs.</para></footnote>
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncap --&gt;
&lt;a name=&quot;xmp_ncap2&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncap2 --&gt;
</html>

<!-- c Begin HMB documentation -->

<html endspaces=" ">
&lt;a name=&quot;ncap_opts&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_opts --&gt;
</html>
</subsection>
<node name="Operator-precedence-and-associativity" spaces=" "><nodename trailingspaces=" ">Operator precedence and associativity</nodename><nodenext spaces=" ">ID Quoting</nodenext><nodeprev spaces=" ">Intrinsic mathematical methods</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>Operator precedence and associativity</sectiontitle>
<para>This page lists the <command>ncap2</command> operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied.
</para>
<multitable spaces=" " endspaces=" "><columnfractions spaces=" " line=".18 .62 .20"><columnfraction value=".18"></columnfraction><columnfraction value=".62"></columnfraction><columnfraction value=".20"></columnfraction></columnfractions>
<thead><row><entry command="headitem"> <para>Operator </para></entry><entry command="tab"> <para>Description </para></entry><entry command="tab"> <para>Associativity
</para></entry></row></thead><tbody><row><entry command="item"> <para><code>++ --</code> </para></entry><entry command="tab"> <para>Postfix Increment/Decrement </para></entry><entry command="tab"> <para>Right to Left
</para></entry></row><row><entry command="item"> <para><code>()</code> </para></entry><entry command="tab"> <para>Parentheses (function call)
</para></entry></row><row><entry command="item"> <para><code>.</code>	</para></entry><entry command="tab"> <para>Method call
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>++ --</code> </para></entry><entry command="tab"> <para>Prefix Increment/Decrement </para></entry><entry command="tab"> <para>Right to Left
</para></entry></row><row><entry command="item"> <para><code>+ -</code> </para></entry><entry command="tab">  <para>Unary  Plus/Minus
</para></entry></row><row><entry command="item"> <para><code>!</code> </para></entry><entry command="tab"> <para>Logical Not
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>^</code> </para></entry><entry command="tab"> <para>Power of Operator </para></entry><entry command="tab"> <para>Right to Left
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>* / %</code> </para></entry><entry command="tab"> <para>Multiply/Divide/Modulus </para></entry><entry command="tab"> <para>Left To Right
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>+ -</code> </para></entry><entry command="tab"> <para>Addition/Subtraction </para></entry><entry command="tab"> <para>Left To Right
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>&gt;&gt; &lt;&lt;</code> </para></entry><entry command="tab"> <para>Fortran style array clipping </para></entry><entry command="tab"> <para>Left to Right
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>&lt; &lt;=</code> </para></entry><entry command="tab"> <para>Less than/Less than or equal to </para></entry><entry command="tab"> <para>Left to Right
</para></entry></row><row><entry command="item"> <para><code>&gt; &gt;=</code> </para></entry><entry command="tab"> <para>Greater than/Greater than or equal to
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>== !=</code> </para></entry><entry command="tab"> <para>Equal to/Not equal to </para></entry><entry command="tab"> <para>Left to Right
</para></entry></row><row><entry command="item"> 
</entry></row><row><entry command="item"> <para><code>&amp;&amp;</code>	</para></entry><entry command="tab"> <para>Logical AND </para></entry><entry command="tab"> <para>Left to Right
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>||</code>	</para></entry><entry command="tab"> <para>Logical OR </para></entry><entry command="tab"> <para>Left to Right
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>?:</code> </para></entry><entry command="tab"> <para>Ternary Operator </para></entry><entry command="tab"> <para>Right to Left
</para></entry></row><row><entry command="item">
</entry></row><row><entry command="item"> <para><code>=</code>	</para></entry><entry command="tab"> <para>Assignment	</para></entry><entry command="tab"> <para>Right to Left
</para></entry></row><row><entry command="item"> <para><code>+= -=</code> </para></entry><entry command="tab">	<para>Addition/subtraction assignment	
</para></entry></row><row><entry command="item"> <para><code>*= /=</code> </para></entry><entry command="tab">	<para>Multiplication/division assignment
</para></entry></row></tbody></multitable>

<html endspaces=" ">
&lt;a name=&quot;ncap_nmc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncap_nmc --&gt;
</html>
</subsection>
<node name="ID-Quoting" spaces=" "><nodename>ID Quoting</nodename><nodenext spaces=" ">make_bounds() function</nodenext><nodeprev spaces=" " trailingspaces=" ">Operator precedence and associativity</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>ID Quoting</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1578">ID Quoting</indexterm></cindex>
<para>In this section a name refers to a variable, attribute, or dimension name.
The allowed characters in a valid netCDF name vary from release to
release. (See end section).
To use metacharacters in a name, or to use a method name as a variable
name, the name must be quoted wherever it occurs. 
</para>
<noindent></noindent> <para>The default <acronym><acronymword>NCO</acronymword></acronym> name is specified by the regular expressions:
</para>
<example endspaces=" ">
<pre xml:space="preserve">DGT:     ('0'..'9');
LPH:     ( 'a'..'z' | 'A'..'Z' | '_' );
name:    (LPH)(LPH|DGT)+
</pre></example>

<noindent></noindent> <para>The first character of a valid name must be alphabetic or the underscore.
Subsequent characters must be alphanumeric or underscore, e.g., a1, _23, hell_is_666.
</para>
<noindent></noindent> <para>The valid characters in a quoted name are specified by the regular expressions:
</para><example endspaces=" ">
<pre xml:space="preserve">LPHDGT:  ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9');
name:    (LPHDGT|'-'|'+'|'.'|'('|')'|':' )+  ;      
</pre></example>

<noindent></noindent> <para>Quote a variable:&linebreak;
&textrsquo;avg&textrsquo; , &textrsquo;10_+10&textrsquo;,&textrsquo;set_miss&textrsquo; &textrsquo;+-90field&textrsquo; , &textrsquo;&textndash;test&textrsquo;=10.0d&linebreak; &linebreak; 
Quote an attribute:&linebreak;
&textrsquo;three&arobase;10&textrsquo;, &textrsquo;set_mss&arobase;+10&textrsquo;, &textrsquo;666&arobase;hell&textrsquo;, &textrsquo;t1&arobase;+units&textrsquo;=&quot;kelvin&quot; &linebreak; &linebreak;
Quote a dimension: &linebreak;
&textrsquo;$10&textrsquo;, &textrsquo;$t1&textndash;&textrsquo;, &textrsquo;$&textndash;odd&textrsquo;, c1[&textrsquo;$10&textrsquo;,&textrsquo;$t1&textndash;&textrsquo;]=23.0d &linebreak; 
</para>
<sp spaces=" " value="1" line="1"></sp>
<para>The following comments are from the netCDF library definitions and
detail the naming conventions for each release. 
netcdf-3.5.1 &linebreak;
netcdf-3.6.0-p1 &linebreak;
netcdf-3.6.1 &linebreak;
netcdf-3.6.2 &linebreak;
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
/*
 * ( [a-zA-Z]|[0-9]|'_'|'-'|'+'|'.'|'|':'|'@'|'('|')' )+
 * Verify that name string is valid CDL syntax, i.e., all characters are
 * alphanumeric, '-', '_', '+', or '.'.
 * Also permit ':', '@', '(', or ')' in names for chemists currently making 
 * use of these characters, but don't document until ncgen and ncdump can 
 * also handle these characters in names.
 */
</verbatim>
</example>

<noindent></noindent> <para>netcdf-3.6.3&linebreak;
netcdf-4.0 Final  2008/08/28&linebreak;
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
/*
 * Verify that a name string is valid syntax.  The allowed name
 * syntax (in RE form) is:
 *
 * ([a-zA-Z_]|{UTF8})([^\x00-\x1F\x7F/]|{UTF8})*
 *
 * where UTF8 represents a multibyte UTF-8 encoding.  Also, no
 * trailing spaces are permitted in names.  This definition
 * must be consistent with the one in ncgen.l.  We do not allow '/'
 * because HDF5 does not permit slashes in names as slash is used as a
 * group separator.  If UTF-8 is supported, then a multi-byte UTF-8
 * character can occur anywhere within an identifier.  We later
 * normalize UTF-8 strings to NFC to facilitate matching and queries.
 */ 
</verbatim>
</example>
<!-- c End HMB documentation -->

<html endspaces=" ">
&lt;a name=&quot;make_bounds&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#make_bounds --&gt;
</html>
</subsection>
<node name="make_005fbounds_0028_0029-function" spaces=" "><nodename>make_bounds() function</nodename><nodenext spaces=" ">solar_zenith_angle function</nodenext><nodeprev spaces=" ">ID Quoting</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>make_bounds() function</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1579">make_bounds() function</indexterm></cindex>
<para>The <command>ncap2</command> custom function &textrsquo;make_bounds()&textrsquo; takes any monotonic 1D coordinate variable with regular or irregular (e.g., Gaussian) spacing and creates a bounds variable.
</para>
<para><emph>&lt;bounds_var_out&gt;=make_bounds( &lt;coordinate_var_in&gt;, &lt;dim in&gt;, &lt;string&gt;)</emph>
</para>
<table commandarg="var" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="var">1st Argument</itemformat></item>
</tableterm><tableitem><para>The name of the input coordinate variable.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="var">2nd Argument</itemformat></item>
</tableterm><tableitem><para>The second dimension of the output variable, referenced as a dimension
(i.e., the name preceded by a dollarsign) not as a string name.
The size of this dimension should always <w>be 2</w>.
If the dimension does not yet exist create it first using <code>defdim()</code>. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="var">3rd Argument</itemformat></item>
</tableterm><tableitem><para>This optional string argument will be placed in the &quot;bounds&quot; attribute
that will be created in the input coordinate variable. 
Normally this is the name of the bounds variable:
</para></tableitem></tableentry></table>
<para>Typical usage:
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;nv&quot;,2);
longitude_bounds=make_bounds(longitude,$nv,&quot;longitude_bounds&quot;);
</pre></example>

<para>Another common CF convention:
</para><example endspaces=" ">
<pre xml:space="preserve">defdim(&quot;nv&quot;,2);
climatology_bounds=make_bounds(time,$nv,&quot;climatology_bounds&quot;);
</pre></example>

</subsection>
<node name="solar_005fzenith_005fangle-function" spaces=" "><nodename>solar_zenith_angle function</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">make_bounds() function</nodeprev><nodeup spaces=" ">ncap2 netCDF Arithmetic Processor</nodeup></node>
<subsection spaces=" "><sectiontitle>solar_zenith_angle function</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1580">solar_zenith_angle function</indexterm></cindex>

<para><emph>&lt;zenith_out&gt;=solar_zenith_angle( &lt;time_in&gt;, &lt;latitude in&gt;)</emph>  
</para>
<para>This function takes two arguments, mean local solar time and latitude.
Calculation and output is done with type <code>NC_DOUBLE</code>.
The calendar attribute for &lt;time_in&gt; in is NOT read and is assumed to be
Gregorian (this is the calendar that UDUnits uses).
As part of the calculation &lt;time_in&gt; is converted to days since start of
year.
For some  input units e.g., seconds, this function may produce
gobbledygook.
The output &lt;zenith_out&gt; is in <code>degrees</code>. 
For more details of the algorithm used please examine the function
<code>solar_geometry()</code> in <code>fmc_all_cls.cc</code>.
Note that this routine does not account for the equation of time,
and so can be in error by the angular equivalent of up to about fifteen
minutes time depending on the day of year.
</para>
<example endspaces=" ">
<pre xml:space="preserve">my_time[time]=&lbrace;10.50, 11.0, 11.50, 12.0, 12.5, 13.0, 13.5, 14.0, 14.50, 15.00&rbrace;;  
my_time&arobase;units=&quot;hours since 2017-06-21&quot;;

// Assume we are at Equator
latitude=0.0;

// 32.05428, 27.61159, 24.55934, 23.45467, 24.55947, 27.61184, 32.05458, 37.39353, 43.29914, 49.55782 ;
zenith=solar_zenith_angle(my_time,latitude);
</pre></example>

<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncatted&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncatted --&gt;
</html>
</subsection>
</section>
<node name="ncatted-netCDF-Attribute-Editor" spaces=" "><nodename>ncatted netCDF Attribute Editor</nodename><nodenext spaces=" ">ncbo netCDF Binary Operator</nodenext><nodeprev spaces=" ">ncap2 netCDF Arithmetic Processor</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncatted</command> netCDF Attribute Editor</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1581">attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1582">attribute names</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1583">editing attributes</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="21" mergedindex="cp">ncatted</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted [-a <var>att_dsc</var>] [-a &dots;] [-D <var>dbg</var>]
[-H] [-h] [--hdr_pad <var>nbr</var>] [--hpss] 
[-l <var>path</var>] [-O] [-o <var>output-file</var>] [-p <var>path</var>]
[-R] [-r] [--ram_all] [-t] <var>input-file</var> [[<var>output-file</var>]]
</pre></example>
 
<noindent></noindent>
<para>DESCRIPTION
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1584"><command>ncattget</command></indexterm></cindex>
<para><command>ncatted</command> edits attributes in a netCDF file.  
If you are editing attributes then you are spending too much time in the
world of metadata, and <command>ncatted</command> was written to get you back out as
quickly and painlessly as possible.
<command>ncatted</command> can <dfn>append</dfn>, <dfn>create</dfn>, <dfn>delete</dfn>,
<dfn>modify</dfn>, and <dfn>overwrite</dfn> attributes (all explained below).  
<command>ncatted</command> allows each editing operation to be applied
to every variable in a file.
This saves time when changing attribute conventions throughout a file. 
<command>ncatted</command> is for <emph>writing</emph> attributes.
To <emph>read</emph> attribute values in plain text, use <command>ncks -m -M</command>,
or define something like <command>ncattget</command> as a shell command
(<pxref label="Filters-for-ncks"><xrefnodename>Filters for <command>ncks</command></xrefnodename></pxref>). 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1585"><code>history</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1586"><code>-h</code></indexterm></cindex>
<para>Because repeated use of <command>ncatted</command> can considerably increase the size
of the <code>history</code> global attribute (<pxref label="History-Attribute"><xrefnodename>History Attribute</xrefnodename></pxref>), the
<samp>-h</samp> switch is provided to override automatically appending the
command to the <code>history</code> global attribute in the <var>output-file</var>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1587">performance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1588">operator speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1589">speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1590">execution time</indexterm></cindex>
<para>According to the <cite>netCDF User Guide</cite>, altering metadata in
netCDF files does not incur the penalty of recopying the entire file
when the new metadata occupies less space than the old metadata.
Thus <command>ncatted</command> may run much faster (at least on netCDF3 files)
if judicious use of header padding (<pxref label="Metadata-Optimization"><xrefnodename>Metadata Optimization</xrefnodename></pxref>) was
made when producing the <var>input-file</var>.
Similarly, using the <samp>--hdr_pad</samp> option with <command>ncatted</command>
helps ensure that future metadata changes to <var>output-file</var> occur
as swiftly as possible.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1591">missing values</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1592">data, missing</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1593"><code>_FillValue</code></indexterm></cindex>
<para>When <command>ncatted</command> is used to change the <code>_FillValue</code> attribute,
it changes the associated missing data self-consistently.
If the internal floating-point representation of a missing value, 
e.g., 1.0e36, differs between two machines then netCDF files produced 
on those machines will have incompatible missing values.
This allows <command>ncatted</command> to change the missing values in files from 
different machines to a single value so that the files may then be 
concatenated, e.g., by <command>ncrcat</command>, without losing information.   
<xref label="Missing-Values"><xrefnodename>Missing Values</xrefnodename></xref>, for more information.
</para>
<para>To master <command>ncatted</command> one must understand the meaning of the
structure that describes the attribute modification, <var>att_dsc</var> 
specified by the required option <samp>-a</samp> or <samp>--attribute</samp>. 
This option is repeatable and may be used multiple time in a single
<command>ncatted</command> invocation to increase the efficiency of altering
multiple attributes.
Each <var>att_dsc</var> contains five elements.
This makes using <command>ncatted</command> somewhat complicated, though
powerful. 
The <var>att_dsc</var> fields are in the following order:&linebreak; 
</para>
<para><var>att_dsc</var> = <var>att_nm</var>, <var>var_nm</var>, <var>mode</var>, <var>att_type</var>,
<var>att_val</var>&linebreak;
</para>
<table commandarg="var" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="var">att_nm</itemformat></item>
</tableterm><tableitem><para>Attribute name. 
Example: <code>units</code>
As of <acronym><acronymword>NCO</acronymword></acronym> 4.5.1 (July, 2015), <command>ncatted</command> accepts 
regular expressions (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>) for attribute names
(it has &textldquo;always&textrdquo; accepted regular expressions for variable names). 
Regular expressions will select all matching attribute names. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="var">var_nm</itemformat></item>
</tableterm><tableitem><para>Variable name. 
Example: <code>pressure</code>, <code>'^H2O'</code>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1594">extended regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1595">regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1596">pattern matching</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1597">wildcards</indexterm></cindex>
Regular expressions (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>) are accepted and will 
select all matching variable (and/or group) names. 
The names <code>global</code> and <code>group</code> have special meaning.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="var">mode</itemformat></item>
</tableterm><tableitem><para>Edit mode abbreviation. 
Example: <code>a</code>. 
See below for complete listing of valid values of <var>mode</var>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="var">att_type</itemformat></item>
</tableterm><tableitem><para>Attribute type abbreviation. 
Example: <code>c</code>. 
See below for complete listing of valid values of <var>att_type</var>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="var">att_val</itemformat></item>
</tableterm><tableitem><para>Attribute value. 
Example: <code>pascal</code>. 
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>There should be no empty space between these five consecutive
arguments. 
The description of these arguments follows in their order of
appearance. 
</para>
<para>The value of <var>att_nm</var> is the name of the attribute to edit. 
The meaning of this should be clear to all <command>ncatted</command> users.
Both <var>att_nm</var> and <var>var_nm</var> may be specified as regular
expressions.
If <var>att_nm</var> is omitted (i.e., left blank) and <dfn>Delete</dfn> mode is 
selected, then all attributes associated with the specified variable
will be deleted. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1598">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1599">attributes, global</indexterm></cindex>
<para>The value of <var>var_nm</var> is the name of the variable containing the
attribute (named <var>att_nm</var>) that you want to edit.
There are three very important and useful exceptions to this rule.
The value of <var>var_nm</var> can also be used to direct <command>ncatted</command>
to edit global attributes, or to repeat the editing operation for every 
group or variable in a file.
<w>A value</w> of <var>var_nm</var> of <code>global</code> indicates that <var>att_nm</var>
refers to a global (i.e., root-level) attribute, rather than to a
particular variable&textrsquo;s attribute. 
This is the method <command>ncatted</command> supports for editing global
attributes.
<w>A value</w> of <var>var_nm</var> of <code>group</code> indicates that <var>att_nm</var>
refers to all groups, rather than to a particular variable&textrsquo;s or group&textrsquo;s
attribute.  
The operation will proceed to edit group metadata for every group.
Finally, if <var>var_nm</var> is left blank, then <command>ncatted</command> 
attempts to perform the editing operation on every variable in the file.
This option may be convenient to use if you decide to change the
conventions you use for describing the data.
As of <acronym><acronymword>NCO</acronymword></acronym> 4.6.0 (May, 2016), <command>ncatted</command> accepts 
the <samp>-t</samp> (or long-option equivalent <samp>--typ_mch</samp> or
<samp>--type_match</samp>) option.
This causes <command>ncatted</command> to perform the editing operation only on
variables that are the same type as the specified attribute.
</para>
<html endspaces=" ">
&lt;a name=&quot;mode&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mode --&gt;
&lt;a name=&quot;att_mode&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_mode --&gt;
&lt;a name=&quot;att_edit&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_edit --&gt;
&lt;a name=&quot;att_append&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_append --&gt;
&lt;a name=&quot;att_create&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_create --&gt;
&lt;a name=&quot;att_delete&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_delete --&gt;
&lt;a name=&quot;att_modify&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_modify --&gt;
&lt;a name=&quot;att_nappend&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_nappend --&gt;
&lt;a name=&quot;att_overwrite&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_overwrite --&gt;
&lt;a name=&quot;att_prepend&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_prepend --&gt;
</html>
<para>The value of <var>mode</var> is a single character abbreviation (<code>a</code>,
<code>c</code>, <code>d</code>, <code>m</code>, <code>n</code>, <code>o</code>, or <code>p</code>)
standing for one of seven editing modes:&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="1600">attribute, edit</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1601">attribute, append</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1602">attribute, create</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1603">attribute, delete</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1604">attribute, modify</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1605">attribute, nappend</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1606">attribute, overwrite</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1607">attribute, prepend</indexterm></cindex>
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">a </itemformat></item>
</tableterm><tableitem><para><dfn>Append</dfn>.
Append value <var>att_val</var> to current <var>var_nm</var> attribute
<var>att_nm</var> value <var>att_val</var>, if any.  
If <var>var_nm</var> does not already have an existing attribute
<var>att_nm</var>, it is created with the value <var>att_val</var>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">c</itemformat></item>
</tableterm><tableitem><para><dfn>Create</dfn>.
Create variable <var>var_nm</var> attribute <var>att_nm</var> with <var>att_val</var>
if <var>att_nm</var> does not yet exist.  
If <var>var_nm</var> already has an attribute <var>att_nm</var>, there is no
effect, so the existing attribute is preserved without change.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">d</itemformat></item>
</tableterm><tableitem><para><dfn>Delete</dfn>.
Delete current <var>var_nm</var> attribute <var>att_nm</var>.
If <var>var_nm</var> does not have an attribute <var>att_nm</var>, there is no
effect. 
If <var>att_nm</var> is omitted (left blank), then all attributes associated
with the specified variable are automatically deleted. 
When <dfn>Delete</dfn> mode is selected, the <var>att_type</var> and <var>att_val</var>
arguments are superfluous and may be left blank.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">m</itemformat></item>
</tableterm><tableitem><para><dfn>Modify</dfn>.
Change value of current <var>var_nm</var> attribute <var>att_nm</var> to value
<var>att_val</var>. 
If <var>var_nm</var> does not have an attribute <var>att_nm</var>, there is no
effect. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">n </itemformat></item>
</tableterm><tableitem><para><dfn>Nappend</dfn>.
Append value <var>att_val</var> to <var>var_nm</var> attribute <var>att_nm</var> value 
<var>att_val</var> if <var>att_nm</var> already exists.
If <var>var_nm</var> does not have an attribute <var>att_nm</var>, there is no
effect. 
In other words, if <var>att_nm</var> already exists, Nappend behaves like
Append otherwise it does nothing.
The mnenomic is &textldquo;non-create append&textrdquo;.
Nappend mode was added to <command>ncatted</command> in version 4.6.0 (May,
2016). 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">o</itemformat></item>
</tableterm><tableitem><para><dfn>Overwrite</dfn>.
Write attribute <var>att_nm</var> with value <var>att_val</var> to variable
<var>var_nm</var>, overwriting existing attribute <var>att_nm</var>, if any. 
This is the default mode.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">p </itemformat></item>
</tableterm><tableitem><para><dfn>Prepend</dfn>.
Prepend value <var>att_val</var> to <var>var_nm</var> attribute <var>att_nm</var> value 
<var>att_val</var> if <var>att_nm</var> already exists.
If <var>var_nm</var> does not have an attribute <var>att_nm</var>, there is no
effect. 
Prepend mode was added to <command>ncatted</command> in version 5.0.5 (January, 
2022). 
</para></tableitem></tableentry></table>

<html endspaces=" ">
&lt;a name=&quot;att_typ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#att_typ --&gt;
</html>
<para>The value of <var>att_type</var> is a single character abbreviation 
(<code>f</code>, <code>d</code>, <code>l</code>, <code>i</code>, <code>s</code>, <code>c</code>, 
<code>b</code>, <code>u</code>) or a short string standing for one of the twelve
primitive netCDF data types:&linebreak;  
</para><table commandarg="code" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="code">f</itemformat></item>
</tableterm><tableitem><para><dfn>Float</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_FLOAT</code>. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">d</itemformat></item>
</tableterm><tableitem><para><dfn>Double</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_DOUBLE</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">i, l</itemformat></item>
</tableterm><tableitem><para><dfn>Integer</dfn> or (its now deprecated synonym) <dfn>Long</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_INT</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">s</itemformat></item>
</tableterm><tableitem><para><dfn>Short</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_SHORT</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">c</itemformat></item>
</tableterm><tableitem><para><dfn>Char</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_CHAR</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">b</itemformat></item>
</tableterm><tableitem><para><dfn>Byte</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_BYTE</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ub</itemformat></item>
</tableterm><tableitem><para><dfn>Unsigned Byte</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_UBYTE</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">us</itemformat></item>
</tableterm><tableitem><para><dfn>Unsigned Short</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_USHORT</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">u, ui, ul</itemformat></item>
</tableterm><tableitem><para><dfn>Unsigned Int</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_UINT</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ll, int64</itemformat></item>
</tableterm><tableitem><para><dfn>Int64</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_INT64</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">ull, uint64</itemformat></item>
</tableterm><tableitem><para><dfn>Uint64</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_UINT64</code>.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="code">sng, string</itemformat></item>
</tableterm><tableitem><para><dfn>String</dfn>.
Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic
type <code>NC_STRING</code>.
Note that <command>ncatted</command> handles type <code>NC_STRING</code> attributes
correctly beginning with version 4.3.3 released in July, 2013. 
Earlier versions fail when asked to handle <code>NC_STRING</code> attributes.  
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>In <dfn>Delete</dfn> mode the specification of <var>att_type</var> is optional
(and is ignored if supplied).
</para>
<para>The value of <var>att_val</var> is what you want to change attribute
<var>att_nm</var> to contain.
The specification of <var>att_val</var> is optional in <dfn>Delete</dfn> (and is
ignored) mode. 
Attribute values for all types besides <code>NC_CHAR</code> must have an
attribute length of at least one.
Thus <var>att_val</var> may be a single value or one-dimensional array of
elements of type <code>att_type</code>.
If the <var>att_val</var> is not set or is set to empty space,
and the <var>att_type</var> is <code>NC_CHAR</code>, e.g., <code>-a units,T,o,c,&quot;&quot;</code>
or <code>-a units,T,o,c,</code>, then the corresponding attribute is set to 
have zero length.
When specifying an array of values, it is safest to enclose
<var>att_val</var> in single or double quotes, e.g., 
<code>-a levels,T,o,s,&quot;1,2,3,4&quot;</code> or   
<code>-a levels,T,o,s,'1,2,3,4'</code>.
The quotes are strictly unnecessary around <var>att_val</var> except 
when <var>att_val</var> contains characters which would confuse the calling
shell, such as spaces, commas, and wildcard characters. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1608">Perl</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1609"><acronym><acronymword>ASCII</acronymword></acronym></indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> processing of <code>NC_CHAR</code> attributes is a bit like Perl in
that it attempts to do what you want by default (but this sometimes
causes unexpected results if you want unusual data storage).
<cindex index="cp" spaces=" "><indexterm index="cp" number="1610"><code>printf()</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1611"><code>\n</code> (<acronym><acronymword>ASCII</acronymword></acronym> LF, linefeed)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1612">characters, special</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1613"><code>\t</code> (<acronym><acronymword>ASCII</acronymword></acronym> HT, horizontal tab)</indexterm></cindex>
If the <var>att_type</var> is <code>NC_CHAR</code> then the argument is interpreted as a
string and it may contain C-language escape sequences, e.g., <code>\n</code>,
which <acronym><acronymword>NCO</acronymword></acronym> will interpret before writing anything to disk.
<acronym><acronymword>NCO</acronymword></acronym> translates valid escape sequences and stores the
appropriate <acronym><acronymword>ASCII</acronymword></acronym> code instead.
Since two byte escape sequences, e.g., <code>\n</code>, represent one-byte
<acronym><acronymword>ASCII</acronymword></acronym> codes, e.g., <acronym><acronymword>ASCII</acronymword></acronym> 10 (decimal), the stored
string attribute is one byte shorter than the input string length for
each embedded escape sequence. 
The most frequently used C-language escape sequences are <code>\n</code> (for
linefeed) and <code>\t</code> (for horizontal tab).
These sequences in particular allow convenient editing of formatted text
attributes. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1614"><code>\a</code> (<acronym><acronymword>ASCII</acronymword></acronym> BEL, bell)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1615"><code>\b</code> (<acronym><acronymword>ASCII</acronymword></acronym> BS, backspace)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1616"><code>\f</code> (<acronym><acronymword>ASCII</acronymword></acronym> FF, formfeed)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1617"><code>\r</code> (<acronym><acronymword>ASCII</acronymword></acronym> CR, carriage return)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1618"><code>\v</code> (<acronym><acronymword>ASCII</acronymword></acronym> VT, vertical tab)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1619"><code>\\</code> (<acronym><acronymword>ASCII</acronymword></acronym> \, backslash)</indexterm></cindex>
The other valid <acronym><acronymword>ASCII</acronymword></acronym> codes are <code>\a</code>, <code>\b</code>, <code>\f</code>,
<code>\r</code>, <code>\v</code>, and <code>\\</code>. 
<xref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref>, for more examples of string formatting
(with the <command>ncks</command> <samp>-s</samp> option) with special characters. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1620"><code>\'</code> (protected end quote)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1621"><code>\&quot;</code> (protected double quote)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1622"><code>\?</code> (protected question mark)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1623"><code>\\</code> (protected backslash)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1624"><code>'</code> (end quote)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1625"><code>&quot;</code> (double quote)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1626"><code>?</code> (question mark)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1627"><code>\</code> (backslash)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1628">special characters</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1629"><acronym><acronymword>ASCII</acronymword></acronym></indexterm></cindex>
<para>Analogous to <code>printf</code>, other special characters are also allowed by 
<command>ncatted</command> if they are &textldquo;protected&textrdquo; by a backslash.
The characters <code>&quot;</code>, <code>'</code>, <code>?</code>, and <code>\</code> may be 
input to the shell as <code>\&quot;</code>, <code>\'</code>, <code>\?</code>, and <code>\\</code>.
<acronym><acronymword>NCO</acronymword></acronym> simply strips away the leading backslash from these
characters before editing the attribute.
No other characters require protection by a backslash.
Backslashes which precede any other character (e.g., <code>3</code>, <code>m</code>,
<code>$</code>, <code>|</code>, <code>&amp;</code>, <code>&arobase;</code>, <code>%</code>, <code>&lbrace;</code>, and
<code>&rbrace;</code>) will not be filtered and will be included in the attribute.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1630">strings</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1631">NUL-termination</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1632">NUL</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1633">C language</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1634"><code>0</code> (NUL)</indexterm></cindex>
<para>Note that the NUL character <code>\0</code> which terminates <w>C language</w>
strings is assumed and need not be explicitly specified.
<!-- comment If @code{\0} is input, it will not be translated (because it would -->
<!-- comment terminate the string in an additional location). -->
<!-- comment 20101007 Before today, \0 was not translated to NUL -->
<!-- comment 20101007 As of today,  \0 is      translated to NUL -->
If <code>\0</code> is input, it is translated to the NUL character.
However, this will make the subsequent portion of the string, if any,
invisible to <w>C standard</w> library string functions. 
And that may cause unintended consequences.
Because of these context-sensitive rules, one must use <command>ncatted</command>
with care in order to store data, rather than text strings, in an 
attribute of type <code>NC_CHAR</code>.
</para>
<para>Note that <command>ncatted</command> interprets character attributes
(i.e., attributes of type <code>NC_CHAR</code>) as strings.
<html endspaces=" ">
&lt;a name=&quot;xmp_ncatted&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncatted --&gt;
</html>
EXAMPLES
</para>
<para>Append the string <code>Data version 2.0.\n</code> to the global attribute
<code>history</code>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a history,global,a,c,'Data version 2.0\n' in.nc 
</pre></example>
<para>Note the use of embedded <w>C language</w> <code>printf()</code>-style escape 
sequences. 
</para>
<para>Change the value of the <code>long_name</code> attribute for variable <code>T</code>
from whatever it currently is to &textldquo;temperature&textrdquo;:
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a long_name,T,o,c,temperature in.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;MPAS&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#MPAS --&gt;
&lt;a name=&quot;typ_mch&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#typ_mch --&gt;
&lt;a name=&quot;type_match&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#type_match --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1635">MPAS</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1636"><code>_FillValue</code></indexterm></cindex>
<para>Many model and observational datasets use missing values that are not
annotated in the standard manner.
For example, at the time (2015&textndash;2018) of this writing,
the <acronym><acronymword>MPAS</acronymword></acronym> ocean and ice models use
<math>-9.99999979021476795361e+33</math> as the missing value, yet do not
store a <code>_FillValue</code> attribute with any variables.
To prevent arithmetic from treating these values as normal, designate
this value as the <code>_FillValue</code> attribute:
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted    -a _FillValue,,o,d,-9.99999979021476795361e+33 in.nc
ncatted -t -a _FillValue,,o,d,-9.99999979021476795361e+33 in.nc
ncatted -t -a _FillValue,,o,d,-9.99999979021476795361e+33 \
           -a _FillValue,,o,f,1.0e36 -a _FillValue,,o,i,-999 in.nc
</pre></example>
<para>The first example adds the attribute to all variables. 
The <samp>-t</samp> switch causes the second example to add the attribute only
to double precision variables.
This is often more useful, and can be used to provide distinct missing
value attributes to each numeric type, as in the third example.
</para>
<html endspaces=" ">
&lt;a name=&quot;NaNf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#NaNf --&gt;
&lt;a name=&quot;NaN&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#NaN --&gt;
&lt;a name=&quot;nan&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nan --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1637">NaN</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1638">NaNf</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1639"><acronym><acronymword>IEEE</acronymword></acronym> NaN, NaNf</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1640">Not-a-Number</indexterm></cindex>
<para><acronym><acronymword>NCO</acronymword></acronym> arithmetic operators may not work as expected on
<acronym><acronymword>IEEE</acronymword></acronym> NaN (short for Not-a-Number) and NaN-like numbers such
as positive infinity and negative infinity
<footnote><para>NaN is a special floating point value (not a string).
Arithmetic comparisons to NaN and NaN-like numbers always
return False, contrary to the behavior of all other numbers.
This behavior is difficult to intuit, yet <w><acronym><acronymword>IEEE</acronymword></acronym> 754</w>
mandates it.  
To correctly handle NaNs during arithmetic, code must use special 
math library macros (e.g., <command>isnormal()</command>) to determine whether 
any operand requires special treatment. 
If so, additional logic must be added to correctly perform the
arithmetic. 
This is in addition to the normal handling incurred to correctly
handle missing values. 
Handling field and missing values (either or both of which may be NaN) 
in binary operators thus incurs four-to-eight extra code paths.
Each code path slows down arithmetic relative to normal numbers.
This makes supporting NaN arithmetic costly and inefficient.
Hence <acronym><acronymword>NCO</acronymword></acronym> supports NaN only to the extent necessary to
replace it with a normal number.
Although using NaN for the missing value (or any value) in datasets is 
legal in netCDF, we discourage it.
We recommend avoiding NaN entirely.</para></footnote>. 
One way to work-around this problem is to change <acronym><acronymword>IEEE</acronymword></acronym> NaNs
to normal missing values. 
As of <acronym><acronymword>NCO</acronymword></acronym> 4.1.0 (March, 2012), <command>ncatted</command> works with 
NaNs (though none of <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s arithmetic operators do).
This limited support enables users to change NaN to a normal number
before performing arithmetic or propagating a NaN-tainted dataset.
First set the missing value (i.e., the value of the <code>_FillValue</code>
attribute) for the variable(s) in question to the <acronym><acronymword>IEEE</acronymword></acronym> NaN
value.  
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a _FillValue,,o,f,NaN in.nc
</pre></example>
<para>Then change the missing value from the <acronym><acronymword>IEEE</acronymword></acronym> NaN value to a
normal <acronym><acronymword>IEEE</acronymword></acronym> number, like 1.0e36 (or to whatever the original
missing value was). 
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a _FillValue,,m,f,1.0e36 in.nc
</pre></example>
<para>Some <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>MODIS</acronymword></acronym> datasets provide a real-world
example. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -O -a _FillValue,,m,d,1.0e36 -a missing_value,,m,d,1.0e36 \
        MODIS_L2N_20140304T1120.nc MODIS_L2N_20140304T1120_noNaN.nc
</pre></example>

<para>Delete all existing <code>units</code> attributes:
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a units,,d,, in.nc
</pre></example>
<noindent></noindent>
<para>The value of <var>var_nm</var> was left blank in order to select all
variables in the file.
The values of <var>att_type</var> and <var>att_val</var> were left blank because
they are superfluous in <dfn>Delete</dfn> mode. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1641"><code>global</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1642">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1643">attributes, global</indexterm></cindex>
<para>Delete all attributes associated with the <code>tpt</code> variable, and
delete all global attributes
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a ,tpt,d,, -a ,global,d,, in.nc
</pre></example>
<noindent></noindent>
<para>The value of <var>att_nm</var> was left blank in order to select all
attributes associated with the variable.
To delete all global attributes, simply replace <code>tpt</code> with
<code>global</code> in the above.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1644"><code>units</code></indexterm></cindex>
<para>Modify all existing <code>units</code> attributes to <code>meter second-1</code>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a units,,m,c,'meter second-1' in.nc
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="1645"><code>units</code></indexterm></cindex>
<para>Add a <code>units</code> attribute of <code>kilogram kilogram-1</code> to all
variables whose first three characters are <samp>H2O</samp>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a units,'^H2O',c,c,'kilogram kilogram-1' in.nc
</pre></example>

<para>Remove the <code>_FillValue</code> attribute from <code>lat</code> and <code>lon</code> variables.
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -O -a _FillValue,'[lat]|[lon]',d,, in.nc
</pre></example>

<para>Overwrite the <code>quanta</code> attribute of variable
<code>energy</code> to an array of four integers. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a quanta,energy,o,s,'010,101,111,121' in.nc
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="1646">extended regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1647">regular expressions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1648">pattern matching</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1649">wildcards</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> 3.9.6 (January, 2009), <command>ncatted</command> accepts
<dfn>extended regular expressions</dfn> as arguments for variable names,
and, since <acronym><acronymword>NCO</acronymword></acronym> 4.5.1 (July, 2015), for attribute names.
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -a isotope,'^H2O*',c,s,'18' in.nc
ncatted -a '.?_iso19115$','^H2O*',d,, in.nc
</pre></example>
<para>The first example creates <code>isotope</code> attributes for all variables
whose names contain <samp>H2O</samp>.
The second deletes all attributes whose names end in <code>_iso19115</code>
from all variables whose names contain <samp>H2O</samp>.
See <ref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></ref> for more details on using regular
expressions. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1650">groups</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> 4.3.8 (November, 2013), <command>ncatted</command> 
accepts full and partial group paths in names of attributes,
variables, dimensions, and groups.
<!-- c ncks -m -v lon ~/in_grp.nc -->
</para><example endspaces=" ">
<pre xml:space="preserve"># Overwrite units attribute of specific 'lon' variable
ncatted -O -a units,/g1/lon,o,c,'degrees_west' in_grp.nc
# Overwrite units attribute of all 'lon' variables
ncatted -O -a units,lon,o,c,'degrees_west' in_grp.nc
# Delete units attribute of all 'lon' variables
ncatted -O -a units,lon,d,, in_grp.nc
# Overwrite units attribute with new type for specific 'lon' variable
ncatted -O -a units,/g1/lon,o,sng,'degrees_west' in_grp.nc
# Add new_att attribute to all variables
ncatted -O -a new_att,,c,sng,'new variable attribute' in_grp.nc
# Add new_grp_att group attribute to all groups
ncatted -O -a new_grp_att,group,c,sng,'new group attribute' in_grp.nc
# Add new_grp_att group attribute to single group
ncatted -O -a g1_grp_att,g1,c,sng,'new group attribute' in_grp.nc
# Add new_glb_att global attribute to root group
ncatted -O -a new_glb_att,global,c,sng,'new global attribute' in_grp.nc
</pre></example>
<para>Note that regular expressions work well in conjuction with group
path support. 
In other words, the variable name (including group path component) and
the attribute names may both be extended regular expressions.
</para>
<para>Demonstrate input of C-language escape sequences (e.g., <code>\n</code>) and
other special characters (e.g., <code>\&quot;</code>) 
</para><example endspaces=" ">
<pre xml:space="preserve">ncatted -h -a special,global,o,c,
'\nDouble quote: \&quot;\nTwo consecutive double quotes: \&quot;\&quot;\n
Single quote: Beyond my shell abilities!\nBackslash: \\\n
Two consecutive backslashes: \\\\\nQuestion mark: \?\n' in.nc
</pre></example>
<para>Note that the entire attribute is protected from the shell by single
quotes. 
These outer single quotes are necessary for interactive use, but may be
omitted in batch scripts.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1651">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1652">pipes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1653">shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1654"><command>xargs</command></indexterm></cindex>
<para>Although <command>ncatted</command> accepts multiple <samp>-a <var>att_dst</var></samp>
options simultaneously, modifying lengthy commands can become
unwieldy.  
To preserve simplicity in storing/modifying multiple attribute edits, 
consider storing the options separately in a text file and
assembling them at run-time to generate and submit the correct
command.
One such method uses the <command>xargs</command> command to intermediate
between an on-disk list attributes to change and the <command>ncatted</command>
command.
For example, use an intermediate file named <file>options.txt</file>
to store one option per line thusly
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
cat &gt; opt.txt &lt;&lt; EOF
-a institution,global,m,c,\&quot;Super Cool University\&quot;
-a source,global,c,c,\&quot;My Awesome Radar\&quot;
-a contributors,global,c,c,\&quot;Enrico Fermi, Galileo Galilei, Leonardo Da Vinci\&quot;
...
EOF
</verbatim>
</example>
<para>The backslashes preserve the whitespace in the individual attributes
for correct parsing by the shell.
Simply substituting the expansion of this file through <command>xargs</command>
directly on the command line fails to work (why?).
However, a simple workaround is to use <command>xargs</command> to construct
the command string, and execute that string with <command>eval</command>:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
opt=$(cat opt.txt | xargs)
cmd=&quot;ncatted -O ${opt} in.nc out.nc&quot;
eval $cmd
</verbatim>
</example>
<para>This procedure can by modified to employ more complex option
pre-processing using other tools such as Awk, Perl, or Python.
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncbo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncbo --&gt;
&lt;a name=&quot;ncdiff&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncdiff --&gt;
&lt;a name=&quot;ncadd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncadd --&gt;
&lt;a name=&quot;ncsub&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncsub --&gt;
&lt;a name=&quot;ncsubtract&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncsubtract --&gt;
&lt;a name=&quot;ncmult&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncmult --&gt;
&lt;a name=&quot;ncmultiply&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncmultiply --&gt;
&lt;a name=&quot;ncdivide&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncdivide --&gt;
</html>
</section>
<node name="ncbo-netCDF-Binary-Operator" spaces=" "><nodename>ncbo netCDF Binary Operator</nodename><nodenext spaces=" ">ncchecker netCDF Compliance Checker</nodenext><nodeprev spaces=" ">ncatted netCDF Attribute Editor</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncbo</command> netCDF Binary Operator</sectiontitle>
<findex index="fn" spaces=" "><indexterm index="fn" number="22" mergedindex="cp">ncbo</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="23" mergedindex="cp">ncdiff</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="24" mergedindex="cp">ncadd</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="25" mergedindex="cp">ncsub</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="26" mergedindex="cp">ncsubtract</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="27" mergedindex="cp">ncmult</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="28" mergedindex="cp">ncmultiply</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="29" mergedindex="cp">ncdivide</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1655">binary operations</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1656">addition</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1657">subtraction</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1658">multiplication</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1659">adding data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1660">subtracting data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1661">multiplying data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1662">dividing data</indexterm></cindex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" "> 
<pre xml:space="preserve">ncbo [-3] [-4] [-5] [-6] [-7] [-A] [-C] [-c] [--cmp <var>cmp_sng</var>]
[--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F] [--fl_fmt <var>fl_fmt</var>]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...] [-H] [-h] [--hdr_pad <var>nbr</var>] [--hpss]
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [--no_cll_msr] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>file_3</var>] [-p <var>path</var>] [--qnt ...] [--qnt_alg <var>alg_nm</var>]
[-R] [-r] [--ram_all] [-t <var>thr_nbr</var>] [--unn] [-v <var>var</var>[,&dots;]]
[-X ...] [-x] [-y <var>op_typ</var>]
<var>file_1</var> <var>file_2</var> [<var>file_3</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncbo</command> performs binary operations on variables in <var>file_1</var>
and the corresponding variables (those with the same name) in
<var>file_2</var> and stores the results in <var>file_3</var>. 
The binary operation operates on the entire files (modulo any excluded
variables). 
<xref label="Missing-Values"><xrefnodename>Missing Values</xrefnodename></xref>, for treatment of missing values.
One of the four standard arithmetic binary operations currently
supported must be selected with the <samp>-y <var>op_typ</var></samp> switch (or
long options <samp>--op_typ</samp> or <samp>--operation</samp>).
<cindex index="cp" spaces=" "><indexterm index="cp" number="1663"><code>add</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1664"><code>subtract</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1665"><code>multiply</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1666"><code>divide</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1667"><code>+</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1668"><code>-</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1669"><code>*</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1670"><code>/</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1671"><code>-y <var>op_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1672"><code>--operation <var>op_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1673"><code>--op_typ <var>op_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1674">alternate invocations</indexterm></cindex>
The valid binary operations for <command>ncbo</command>, their definitions, 
corresponding values of the <var>op_typ</var> key, and alternate invocations
are:  
</para><table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="dfn">Addition</itemformat></item>
</tableterm><tableitem><!-- c Internal operation code: @{nco_op_add}@* -->
<para>Definition: <var>file_3</var> = <var>file_1</var> + <var>file_2</var>&linebreak;
Alternate invocation: <command>ncadd</command>&linebreak;
<var>op_typ</var> key values: <samp>add</samp>, <samp>+</samp>, <samp>addition</samp>&linebreak;
Examples: <samp>ncbo --op_typ=add 1.nc 2.nc 3.nc</samp>, <samp>ncadd 1.nc 2.nc 3.nc</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Subtraction</itemformat></item>
</tableterm><tableitem><para>Definition: <var>file_3</var> = <var>file_1</var> - <var>file_2</var>&linebreak;
Alternate invocations: <command>ncdiff</command>, <command>ncsub</command>, <command>ncsubtract</command>&linebreak;
<var>op_typ</var> key values: <samp>sbt</samp>, <samp>-</samp>, <samp>dff</samp>, <samp>diff</samp>, <samp>sub</samp>, <samp>subtract</samp>, <samp>subtraction</samp>&linebreak;
Examples: <samp>ncbo --op_typ=- 1.nc 2.nc 3.nc</samp>, <samp>ncdiff 1.nc 2.nc 3.nc</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Multiplication</itemformat></item>
</tableterm><tableitem><para>Definition: <var>file_3</var> = <var>file_1</var> * <var>file_2</var>&linebreak; 
Alternate invocations: <command>ncmult</command>, <command>ncmultiply</command>&linebreak; 
<var>op_typ</var> key values: <samp>mlt</samp>, <samp>*</samp>, <samp>mult</samp>, <samp>multiply</samp>, <samp>multiplication</samp>&linebreak;
Examples: <samp>ncbo --op_typ=mlt 1.nc 2.nc 3.nc</samp>, <samp>ncmult 1.nc 2.nc 3.nc</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Division</itemformat></item>
</tableterm><tableitem><para>Definition: <var>file_3</var> = <var>file_1</var> / <var>file_2</var>&linebreak; 
Alternate invocation: <command>ncdivide</command>&linebreak;
<var>op_typ</var> key values: <samp>dvd</samp>, <samp>/</samp>, <samp>divide</samp>, <samp>division</samp>&linebreak;
Examples: <samp>ncbo --op_typ=/ 1.nc 2.nc 3.nc</samp>, <samp>ncdivide 1.nc 2.nc 3.nc</samp>&linebreak;
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>Care should be taken when using the shortest form of key values,
i.e., <samp>+</samp>, <samp>-</samp>, <samp>*</samp>, <w>and <samp>/</samp></w>.
Some of these single characters may have special meanings to the shell
<cindex index="cp" spaces=" "><indexterm index="cp" number="1675">naked characters</indexterm></cindex>
<footnote><para><w>A naked</w> (i.e., unprotected or unquoted) <samp>*</samp> is a
wildcard character.  
<w>A naked</w> <samp>-</samp> may confuse the command line parser.
<w>A naked</w> <samp>+</samp> and <samp>/</samp> are relatively harmless.</para></footnote>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1676">Bash shell</indexterm></cindex>
Place these characters inside quotes to keep them from being interpreted 
(globbed) by the shell
<footnote><para>The widely used shell Bash correctly interprets all these
special characters even when they are not quoted. 
That is, Bash does not prevent <acronym><acronymword>NCO</acronymword></acronym> from correctly interpreting 
the intended arithmetic operation when the following arguments are given
(without quotes) to <command>ncbo</command>:
<samp>--op_typ=+</samp>, <samp>--op_typ=-</samp>, <samp>--op_typ=*</samp>,
and <samp>--op_typ=/</samp></para></footnote>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1677">globbing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1678">shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1679">quotes</indexterm></cindex>
For example, the following commands are equivalent
</para><example endspaces=" ">
<pre xml:space="preserve">ncbo --op_typ=* 1.nc 2.nc 3.nc # Dangerous (shell may try to glob)
ncbo --op_typ='*' 1.nc 2.nc 3.nc # Safe ('*' protected from shell)
ncbo --op_typ=&quot;*&quot; 1.nc 2.nc 3.nc # Safe ('*' protected from shell)
ncbo --op_typ=mlt 1.nc 2.nc 3.nc
ncbo --op_typ=mult 1.nc 2.nc 3.nc
ncbo --op_typ=multiply 1.nc 2.nc 3.nc
ncbo --op_typ=multiplication 1.nc 2.nc 3.nc
ncmult 1.nc 2.nc 3.nc # First do 'ln -s ncbo ncmult'
ncmultiply 1.nc 2.nc 3.nc # First do 'ln -s ncbo ncmultiply'
</pre></example>
<para>No particular argument or invocation form is preferred.
Users are encouraged to use the forms which are most intuitive to them.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1680"><command>alias</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1681"><command>ln -s</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1682">symbolic links</indexterm></cindex>
<para>Normally, <command>ncbo</command> will fail unless an operation type is specified
with <samp>-y</samp> (equivalent to <samp>--op_typ</samp>).
You may create exceptions to this rule to suit your particular tastes,
in conformance with your site&textrsquo;s policy on <dfn>symbolic links</dfn> to
executables (files of a different name point to the actual executable).
For many years, <command>ncdiff</command> was the main binary file operator.
As a result, many users prefer to continue invoking <command>ncdiff</command>
rather than memorizing a new command (<samp>ncbo -y <var>sbt</var></samp>) which
behaves identically to the original <command>ncdiff</command> command.
However, from a software maintenance standpoint, maintaining a distinct 
executable for each binary operation (e.g., <command>ncadd</command>) is untenable,
and a single executable, <command>ncbo</command>, is desirable.
To maintain backward compatibility, therefore, <acronym><acronymword>NCO</acronymword></acronym>
automatically creates a symbolic link from <command>ncbo</command> to
<command>ncdiff</command>.  
Thus <command>ncdiff</command> is called an <dfn>alternate invocation</dfn> of
<command>ncbo</command>. 
<command>ncbo</command> supports many additional alternate invocations which must
be manually activated.
Should users or system adminitrators decide to activate them, the
procedure is simple. 
For example, to use <samp>ncadd</samp> instead of <samp>ncbo --op_typ=add</samp>, 
simply create a symbolic link from <command>ncbo</command> to <command>ncadd</command>
<footnote><para>The command to do this is <samp>ln -s -f ncbo ncadd</samp></para></footnote>.
The alternatate invocations supported for each operation type are listed
above. 
Alternatively, users may always define <samp>ncadd</samp> as an <dfn>alias</dfn> to 
<samp>ncbo --op_typ=add</samp>
<footnote><para>The command to do this is <samp>alias ncadd='ncbo --op_typ=add'</samp></para></footnote>.
</para>
<para>It is important to maintain portability in <acronym><acronymword>NCO</acronymword></acronym> scripts.
Therefore we recommend that site-specfic invocations (e.g.,
<samp>ncadd</samp>) be used only in interactive sessions from the
command-line.
For scripts, we recommend using the full invocation (e.g., 
<samp>ncbo --op_typ=add</samp>).
This ensures portability of scripts between users and sites.
</para>
<html endspaces=" ">
&lt;a name=&quot;brd_var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#brd_var --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1683">broadcasting variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1684">rank</indexterm></cindex>
<para><command>ncbo</command> operates (e.g., adds) variables in <var>file_2</var> with the
corresponding variables (those with the same name) in <var>file_1</var> and
stores the results in <var>file_3</var>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1685">broadcasting variables</indexterm></cindex>
Variables in <var>file_1</var> or <var>file_2</var> are <dfn>broadcast</dfn> to conform
to the corresponding variable in the other input file if
necessary<footnote spaces="\n"><para>Prior to <acronym><acronymword>NCO</acronymword></acronym> version 4.3.1 (May, 2013), <command>ncbo</command>
would only broadcast variables in <var>file_2</var> to conform to
<var>file_1</var>. 
Variables in <var>file_1</var> were <emph>never</emph> broadcast to conform to the 
dimensions in <var>file_2</var>.</para></footnote>. 
Now <command>ncbo</command> is completely symmetric with respect to <var>file_1</var>
and <var>file_2</var>, i.e., 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$\rm{file}_1 - \rm{file}_2 = -(\rm{file}_2-\rm{file}_1)$.
@clear flg
</tex>
<math><var>file_1</var> - <var>file_2</var> = - (<var>file_2</var> - <var>file_1</var></math>.
<clear name="flg" line=" flg"></clear>
</para>
<para>Broadcasting a variable means creating data in non-existing dimensions
by copying data in existing dimensions.
For example, a two dimensional variable in <var>file_2</var> can be
subtracted from a four, three, or two (not one or zero)
dimensional variable (of the same name) in <code>file_1</code>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1686">anomalies</indexterm></cindex>
This functionality allows the user to compute anomalies from the mean.
In the future, we will broadcast variables in <var>file_1</var>, if necessary
to conform to their counterparts in <var>file_2</var>.
<!-- c TODO #268 -->
<cindex index="cp" spaces=" "><indexterm index="cp" number="1687">rank</indexterm></cindex>
Thus, presently, the number of dimensions, or <dfn>rank</dfn>, of any
processed variable in <var>file_1</var> must be greater than or equal to the
rank of the same variable in <var>file_2</var>. 
Of course, the size of all dimensions common to both <var>file_1</var> and
<var>file_2</var> must be equal. 
</para>
<para>When computing anomalies from the mean it is often the case that
<var>file_2</var> was created by applying an averaging operator to a file
with initially the same dimensions as <var>file_1</var> (often <var>file_1</var>
itself).  
In these cases, creating <var>file_2</var> with <command>ncra</command> rather than
<command>ncwa</command> will cause the <command>ncbo</command> operation to fail.
For concreteness say the record dimension in <code>file_1</code> is
<code>time</code>.  
If <var>file_2</var> was created by averaging <var>file_1</var> over the
<code>time</code> dimension with the <command>ncra</command> operator (rather than with
the <command>ncwa</command> operator), then <var>file_2</var> will have a <code>time</code>
dimension of <w>size 1</w> rather than having no <code>time</code> dimension at
all 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1688">degenerate dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1689"><samp>-b</samp></indexterm></cindex>
<footnote><para>This is because <command>ncra</command> collapses the record dimension
to a size <w>of 1</w> (making it a <dfn>degenerate</dfn> dimension), but does
not remove it, while, unless <samp>-b</samp> is given, <command>ncwa</command> removes
all averaged dimensions.
In other words, by default <command>ncra</command> changes variable size though
not rank, while, <command>ncwa</command> changes both variable size and rank.</para></footnote>.   
In this case the input files to <command>ncbo</command>, <var>file_1</var> and
<var>file_2</var>, will have unequally sized <code>time</code> dimensions which
causes <command>ncbo</command> to fail.
To prevent this from occurring, use <command>ncwa</command> to remove the
<code>time</code> dimension from <var>file_2</var>.
See the example below.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1690">coordinate variable</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="1691"><code>NC_CHAR</code></indexterm></cindex>
<para><command>ncbo</command> never operates on coordinate variables or variables
of type <code>NC_CHAR</code> or <code>NC_STRING</code>. 
This ensures that coordinates like (e.g., latitude and longitude) are 
physically meaningful in the output file, <var>file_3</var>. 
This behavior is hardcoded.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1692"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm></cindex>
<command>ncbo</command> applies special rules to some 
<acronym><acronymword>CF</acronymword></acronym>-defined (and/or <acronym><acronymword>NCAR CCSM</acronymword></acronym> or <acronym><acronymword>NCAR CCM</acronymword></acronym> 
fields) such as <code>ORO</code>.
See <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref> for a complete description.
Finally, we note that <command>ncflint</command> (<pxref label="ncflint-netCDF-File-Interpolator"><xrefnodename>ncflint netCDF File
Interpolator</xrefnodename></pxref>) is designed for file interpolation.
As such, it also performs file subtraction, addition, multiplication,
albeit in a more convoluted way than <command>ncbo</command>.
</para>
<html endspaces=" ">
&lt;a name=&quot;grp_brd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grp_brd --&gt;
&lt;a name=&quot;brd_grp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#brd_grp --&gt;
&lt;a name=&quot;gb&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gb --&gt;
&lt;a name=&quot;GB&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#GB --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1693">broadcasting groups</indexterm></cindex>
<para>Beginning with <acronym><acronymword>NCO</acronymword></acronym> version 4.3.1 (May, 2013), <command>ncbo</command> 
supports <dfn>group broadcasting</dfn>.
Group broadcasting means processing data based on group patterns in the
input file(s) and automatically transferring or transforming groups to
the output file. 
Consider the case where <var>file_1</var> contains multiple groups each with
the variable <var>v1</var>, while <var>file_2</var> contains <var>v1</var> only in its 
top-level (i.e., root) group.
Then <command>ncbo</command> will replicate the group structure of <var>file_1</var>
in the output file, <var>file_3</var>.
Each group in <var>file_3</var> contains the output of the corresponding
group in <var>file_1</var> operating on the data in the single group in
<var>file_2</var>. 
An example is provided below.
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncbo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncbo --&gt;
&lt;a name=&quot;xmp_ncdiff&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncdiff --&gt;
</html>
<para>EXAMPLES
</para>
<para>Say files <file>85_0112.nc</file> and <file>86_0112.nc</file> each contain 12 months
of data.
Compute the change in the monthly averages from 1985 to 1986:
</para><example endspaces=" ">
<pre xml:space="preserve">ncbo   86_0112.nc 85_0112.nc 86m85_0112.nc
ncdiff 86_0112.nc 85_0112.nc 86m85_0112.nc
ncbo --op_typ=sub 86_0112.nc 85_0112.nc 86m85_0112.nc
ncbo --op_typ='-' 86_0112.nc 85_0112.nc 86m85_0112.nc
</pre></example>
<noindent></noindent>
<para>These commands are all different ways of expressing the same thing.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1694">broadcasting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1695">rank</indexterm></cindex>
<para>The following examples demonstrate the broadcasting feature of
<command>ncbo</command>.  
Say we wish to compute the monthly anomalies of <code>T</code> from the yearly
average of <code>T</code> for the year 1985.
First we create the 1985 average from the monthly data, which is stored
with the record dimension <code>time</code>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncra 85_0112.nc 85.nc
ncwa -O -a time 85.nc 85.nc
</pre></example>
<noindent></noindent>
<para>The second command, <command>ncwa</command>, gets rid of the <code>time</code> dimension
of <w>size 1</w> that <command>ncra</command> left in <file>85.nc</file>. 
Now none of the variables in <file>85.nc</file> has a <code>time</code> dimension.
<w>A quicker</w> way to accomplish this is to use <command>ncwa</command> from the
beginning:  
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -a time 85_0112.nc 85.nc
</pre></example>
<noindent></noindent>
<para>We are now ready to use <command>ncbo</command> to compute the anomalies for 1985:
</para><example endspaces=" ">
<pre xml:space="preserve">ncdiff -v T 85_0112.nc 85.nc t_anm_85_0112.nc
</pre></example>
<noindent></noindent>
<para>Each of the 12 records in <file>t_anm_85_0112.nc</file> now contains the
monthly deviation of <code>T</code> from the annual mean of <code>T</code> for each 
gridpoint. 
</para>
<para>Say we wish to compute the monthly gridpoint anomalies from the zonal
annual mean. 
<w>A <dfn>zonal mean</dfn></w> is a quantity that has been averaged over the
longitudinal (or <var>x</var>) direction.
First we use <command>ncwa</command> to average over longitudinal direction
<code>lon</code>, creating <file>85_x.nc</file>, the zonal mean of <file>85.nc</file>. 
Then we use <command>ncbo</command> to subtract the zonal annual means from the
monthly gridpoint data:
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -a lon 85.nc 85_x.nc
ncdiff 85_0112.nc 85_x.nc tx_anm_85_0112.nc
</pre></example>
<noindent></noindent>
<para>This examples works assuming <file>85_0112.nc</file> has dimensions
<code>time</code> and <code>lon</code>, and that <file>85_x.nc</file> has no <code>time</code>
or <code>lon</code> dimension.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1696">broadcasting groups</indexterm></cindex>
<para>Group broadcasting simplifies evaluation of multiple models against
observations.
Consider the input file <file>cmip5.nc</file> which contains multiple
top-level groups <code>cesm</code>, <code>ecmwf</code>, and <code>giss</code>, each of
which contains the surface air temperature field <code>tas</code>.
We wish to compare these models to observations stored in <file>obs.nc</file> 
which contains <code>tas</code> only in its top-level (i.e., root) group.
It is often the case that many models and/or model simulations exist,
whereas only one observational dataset does.
We evaluate the models and obtain the bias (difference) between models
and observations by subtracting <file>obs.nc</file> from <file>cmip5.nc</file>.
Then <command>ncbo</command> &textldquo;broadcasts&textrdquo; (i.e., replicates) the observational
data to match the group structure of <file>cmip5.nc</file>, subtracts,
and then stores the results in the output file, <file>bias.nc</file>
which has the same group structure as <file>cmip5.nc</file>.
</para><example endspaces=" ">
<pre xml:space="preserve">% ncbo -O cmip5.nc obs.nc bias.nc
% ncks -H -v tas -d time,3 bias.nc
/cesm/tas
time[3] tas[3]=-1 
/ecmwf/tas
time[3] tas[3]=0 
/giss/tas
time[3] tas[3]=1 
</pre></example>
<noindent></noindent>

<html endspaces=" ">
&lt;a name=&quot;csn_anm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#csn_anm --&gt;
</html>
<para>As a final example, say we have five years of monthly data (i.e., 
<w>60 months</w>) stored in <file>8501_8912.nc</file> and we wish to create a
file which contains the twelve month seasonal cycle of the average
monthly anomaly from the five-year mean of this data. 
The following method is just one permutation of many which will
accomplish the same result.
First use <command>ncwa</command> to create the five-year mean: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -a time 8501_8912.nc 8589.nc
</pre></example>
<noindent></noindent>
<para>Next use <command>ncbo</command> to create a file containing the difference of
each month&textrsquo;s data from the five-year mean:
</para><example endspaces=" ">
<pre xml:space="preserve">ncbo 8501_8912.nc 8589.nc t_anm_8501_8912.nc
</pre></example>
<noindent></noindent>
<para>Now use <command>ncks</command> to group together the five January anomalies in
one file, and use <command>ncra</command> to create the average anomaly for all
five Januarys. 
These commands are embedded in a shell loop so they are repeated for all
twelve months:
<cindex index="cp" spaces=" "><indexterm index="cp" number="1697">Bash Shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1698">Bourne Shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1699">C Shell</indexterm></cindex>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for idx in {1..12}; do # Bash Shell (version 3.0+) 
  idx=`printf &quot;%02d&quot; ${idx}` # Zero-pad to preserve order
  ncks -F -d time,${idx},,12 t_anm_8501_8912.nc foo.${idx}
  ncra foo.${idx} t_anm_8589_${idx}.nc
done
for idx in 01 02 03 04 05 06 07 08 09 10 11 12; do # Bourne Shell
  ncks -F -d time,${idx},,12 t_anm_8501_8912.nc foo.${idx}
  ncra foo.${idx} t_anm_8589_${idx}.nc
done
foreach idx (01 02 03 04 05 06 07 08 09 10 11 12) # C Shell
  ncks -F -d time,${idx},,12 t_anm_8501_8912.nc foo.${idx}
  ncra foo.${idx} t_anm_8589_${idx}.nc
end
</verbatim>
</example>
<noindent></noindent>
<para>Note that <command>ncra</command> understands the <code>stride</code> argument so the
two commands inside the loop may be combined into the single command 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncra -F -d time,${idx},,12 t_anm_8501_8912.nc foo.${idx}
</verbatim>
</example>
<noindent></noindent>
<para>Finally, use <command>ncrcat</command> to concatenate the <w>12 average</w> monthly  
anomaly files into one twelve-record file which contains the entire
seasonal cycle of the monthly anomalies:
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat t_anm_8589_??.nc t_anm_8589_0112.nc
</pre></example>
<noindent></noindent>

<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncchecker&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncchecker --&gt;
</html>
</section>
<node name="ncchecker-netCDF-Compliance-Checker" spaces=" "><nodename>ncchecker netCDF Compliance Checker</nodename><nodenext spaces=" ">ncclimo netCDF Climatology Generator</nodenext><nodeprev spaces=" ">ncbo netCDF Binary Operator</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncchecker</command> netCDF Compliance Checker</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1700"><acronym><acronymword>CF</acronymword></acronym></indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="30" mergedindex="cp">ncchecker</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncchecker 
[-D <var>dbg</var>] [-i <var>drc_in</var>]
[--tests=<var>tst_lst</var>]
[-x] [-v <var>var</var>[,&dots;]] [--version]
[<var>input-files</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<html endspaces=" ">
&lt;a name=&quot;DIWG&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#DIWG --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1701"><acronym><acronymword>DIWG</acronymword></acronym></indexterm></cindex>
<para>As of version 5.2.2 (March, 2024), <acronym><acronymword>NCO</acronymword></acronym> comes with the
<command>ncchecker</command> script.
This command checks files for compliance with best practices rules and 
recommendations from various data and metadata standards bodies.
These include the Climate &amp; Forecast (<acronym><acronymword>CF</acronymword></acronym>) Metadata
Conventions and the NASA Dataset Interoperability Working Group
(<acronym><acronymword>DIWG</acronymword></acronym>) recommendations.
Only a small subset (six tests) of <acronym><acronymword>CF</acronymword></acronym> or
<acronym><acronymword>DIWG</acronymword></acronym> recommendations are currently supported.
The number of tests implemented, or, equivalently, of recommendations
checked, is expected to grow.
</para>
<para><command>ncchecker</command> reads each data file in <var>input-files</var>, in
<var>drc_in</var>, or piped through standard input.
It performs the checks requested in the <samp>--tests=<var>tst_lst</var></samp>
option, if any (otherwise it performs all tests), and writes the
results to <code>stdout</code>.
The command supports some standard <acronym><acronymword>NCO</acronymword></acronym> options, including
increasing the verbosity level with <samp>-D <var>dbg_lvl</var></samp>,
excluding variables with <samp>-x -v <var>var_lst</var></samp>, variable
subsetting with <samp>-v <var>var_lst</var></samp>, and printing the 
version with <samp>--version</samp>. 
The output contains counts of the location and number of failed tests,
or prints &textldquo;SUCCESS&textrdquo; for tests with no failures.
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncchecker&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncchecker --&gt;
</html>
<para>EXAMPLES
</para>
<example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncchecker in1.nc in2.nc # Run all tests on two files
ncchecker -v var1,var2 in1.nc # Check only two variables
ncchecker *.nc # Glob input files via wildcard
ls *.nc | ncchecker # Input files via stdin
ncchecker --dbg=2 *.nc # Debug ncchecker
ncchecker --tests=nan,mss *.nc # Select only two tests
ncchecker --tests=xtn,tm,nan,mss,chr,bnd *.nc # Change test ordering
ncchecker file:///Users/zender/in_zarr4#mode=nczarr,file # Check Zarr object(s)
</verbatim>
</example>

<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncclimo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncclimo --&gt;
&lt;a name=&quot;ncsplit&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncsplit --&gt;
&lt;a name=&quot;ncsplit&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#splitter --&gt;
</html>
</section>
<node name="ncclimo-netCDF-Climatology-Generator" spaces=" "><nodename>ncclimo netCDF Climatology Generator</nodename><nodenext spaces=" ">ncecat netCDF Ensemble Concatenator</nodenext><nodeprev spaces=" ">ncchecker netCDF Compliance Checker</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncclimo</command> netCDF Climatology Generator</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1702">climo</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1703">climatology</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="31" mergedindex="cp">ncclimo</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo [-3] [-4] [-5] [-6] [-7] 
[-a <var>wnt_md</var>] [-C <var>clm_md</var>] [-c <var>caseid</var>] [--cmp <var>cmp_sng</var>]
[-d <var>dbg_lvl</var>] [--d2f] [--dpf=<var>dpf</var>] [--dpt_fl=<var>dpt_fl</var>] [-E <var>yr_prv</var>] [-e <var>yr_end</var>]
[-f <var>fml_nm</var>] [--fl_fmt=<var>fl_fmt</var>] [--glb_avg] [--glb_stt=<var>glb_stt</var>] 
[-h <var>hst_nm</var>] [-i <var>drc_in</var>] [-j <var>job_nbr</var>] [-L <var>dfl_lvl</var>] [-l <var>lnk_flg</var>]
[-m <var>mdl_nm</var>] [--mth_end=<var>mth_end</var>] [--mth_srt=<var>mth_srt</var>]
[-n <var>nco_opt</var>] [--no_cll_msr] [--no_frm_trm] [--no_ntv_tms] [--no_stg_grd] [--no_stdin] 
[-O <var>drc_rgr</var>] [-o <var>drc_out</var>] [-P <var>prc_typ</var>] [-p <var>par_typ</var>] [--qnt=<var>qnt_prc</var>]
[-R <var>rgr_opt</var>] [-r <var>rgr_map</var>] [-S <var>yr_prv</var>] [-s <var>yr_srt</var>]
[--seasons=<var>csn_lst</var>] [--sgs_frc=<var>sgs_frc</var>] [--split] [--sum_scl=<var>sum_scl</var>]
[-t <var>thr_nbr</var>] [--tpd=<var>tpd</var>] [--uio] [-v <var>var_lst</var>] [--var_xtr=<var>var_xtr</var>] [--version] 
[--vrt_out=<var>vrt_fl</var>] [--vrt_xtr=<var>vrt_xtr</var>]
[-X <var>drc_xtn</var>] [-x <var>drc_prv</var>] [--xcl_var]
[-Y <var>rgr_xtn</var>] [-y <var>rgr_prv</var>] [--ypf=<var>ypf_max</var>]
[<var>input-files</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para>In climatology generation mode, <command>ncclimo</command> ingests &textldquo;raw&textrdquo; data
consisting of interannual sets of files, each containing sub-daily
(diurnal), daily, monthly, or yearly averages, and from these
produces climatological daily, monthly, seasonal, and/or annual
means.
Alternatively, in timeseries reshaping (aka &textldquo;splitter&textrdquo;) mode,
<command>ncclimo</command> will subset and temporally split the input raw data
timeseries into per-variable files spanning the entire period. 
<command>ncclimo</command> can optionally (call <command>ncremap</command> to) regrid
all output files in either mode.
Unlike the rest of <acronym><acronymword>NCO</acronymword></acronym>, <command>ncclimo</command> and
<command>ncremap</command> are shell scripts, not compiled binaries<footnote spaces=" \n"><para>This means that newer (including user-modified) versions of
<command>ncclimo</command> work fine without re-compiling <acronym><acronymword>NCO</acronymword></acronym>.
Re-compiling is only necessary to take advantage of new features or
fixes in the <acronym><acronymword>NCO</acronymword></acronym> binaries, not to improve <command>ncclimo</command>.
One may download and give executable permissions to the latest source 
at <url><urefurl>https://github.com/nco/nco/tree/master/data/ncclimo</urefurl></url> without
re-installing the rest of <acronym><acronymword>NCO</acronymword></acronym>.</para></footnote>. 
<html endspaces=" ">
&lt;a name=&quot;HDF5_USE_FILE_LOCKING&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#HDF5_USE_FILE_LOCKING --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1704"><code>HDF5_USE_FILE_LOCKING</code></indexterm></cindex>
As of <acronym><acronymword>NCO</acronymword></acronym> 4.9.2 (February, 2020), the <command>ncclimo</command>
and <command>ncremap</command> scripts export the environment variable
<code>HDF5_USE_FILE_LOCKING</code> with a value of <code>FALSE</code>.
This prevents failures of these operators that can occur with some
versions of the underlying HDF library that attempt to lock files
on file systems that cannot, or do not, support it.
</para>
<para>There are five (usually) required options (<samp>-c</samp>, <samp>-s</samp>,
<samp>-e</samp>, <samp>-i</samp>, and <samp>-o</samp>)) to generate climatologies, and
many more options are available to customize the processing.
Options are similar to <command>ncremap</command> options.
Standard <command>ncclimo</command> usage for climatology generation looks like
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo            -c caseid -s srt_yr -e end_yr -i drc_in -o drc_out
ncclimo -m mdl_nm  -c caseid -s srt_yr -e end_yr -i drc_in -o drc_out
ncclimo -v var_lst -c caseid -s srt_yr -e end_yr -i drc_in -o drc_out
ncclimo --case=caseid --start=srt_yr --end=end_yr --input=drc_in --output=drc_out
</pre></example>
<para>In climatology generation mode, <command>ncclimo</command> constructs the list
of input filenames from the arguments to the caseid, date, and
model-type options.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.4 (September, 2020), <command>ncclimo</command>
can produce climatologies of high-frequency input data supplied via
standard input, positional command-line options, or directory
contents, all input methods traditionally supported only in splitter
mode. 
Instead of using the <code>caseid</code> option to help generate the input
filenames as it does for normal (monthly) climos, <command>ncclimo</command>
uses the <code>caseid</code> option, when provided, to rename the output
files for high-frequency climos.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Generate diurnal climos from high-frequency CMIP6 timeseries
cd ${drc_in};ls ${caseid}*.h4.nc | ncclimo --clm_md=hfc \
  -c ${caseid} --yr_srt=2001 --yr_end=2002 --drc_out=${HOME}
</verbatim>
</example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="1705">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1706"><code>stdin</code></indexterm></cindex>
<para><command>ncclimo</command> automatically switches to timeseries reshaping mode
if it receives a list of files from <code>stdin</code>, or, alternatively,
placed as positional arguments (after the last command-line option), or
if neither of these is done and no <var>caseid</var> is specified, in which
case it assumes all <code>*.nc</code> files in <var>drc_in</var> constitute the
input file list. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Split monthly timeseries into CMIP-like timeseries
cd ${drc_in};ls ${caseid}*.h4.nc | ncclimo              -v=T \
  --ypf=1 --yr_srt=56 --yr_end=76 --drc_out=${HOME}
# Split high-frequency timeseries into CMIP-like timeseries
cd ${drc_in};ls ${caseid}*.h4.nc | ncclimo --clm_md=hfs -v=T \
  --ypf=1 --yr_srt=56 --yr_end=76 --drc_out=${HOME}
</verbatim>
</example>

<para>Options for <command>ncclimo</command> and <command>ncremap</command> come in both short
(single-letter) and long forms. 
The handful of long-option synonyms for each option allows the user 
to imbue the commands with a level of verbosity and precision that suits
her taste. 
A complete description of all options is given below, in alphabetical
order of the short option letter.
Long option synonyms are given just after the letter.
When invoked without options, <command>ncclimo</command> and <command>ncremap</command>
print a succinct table of all options and some examples.
All valid options for both operators are listed in their command
syntax above but, for brevity, options that <command>ncclimo</command> passes
straight through to <command>ncremap</command> are only fully described in the
table of <command>ncremap</command> options.
</para><table commandarg="option" spaces=" " endspaces=" ">
<beforefirstitem><html endspaces=" ">
&lt;a name=&quot;winter_mode&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#winter_mode --&gt;
&lt;a name=&quot;wnt_md&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wnt_md --&gt;
&lt;a name=&quot;dec_md&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dec_md --&gt;
&lt;a name=&quot;dcm_md&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dcm_md --&gt;
&lt;a name=&quot;december_mode&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#december_mode --&gt;
&lt;a name=&quot;djf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#djf --&gt;
&lt;a name=&quot;DJF&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#DJF --&gt;
&lt;a name=&quot;jfd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#jfd --&gt;
&lt;a name=&quot;JFD&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#JFD --&gt;
</html>
</beforefirstitem><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1707"><code>-a <var>wnt_md</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1708"><code>djf</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1709"><code>DJF</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1710"><code>JFD</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1711"><code>jfd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1712"><code>--dec_md</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1713"><code>--dcm_md</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1714"><code>--december_mode</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1715"><code>--wnt_md</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1716"><code>--winter_mode</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1717"><var>dec_md</var></indexterm></cindex>
<item spaces=" "><itemformat command="option">-a <var>dec_md</var> (<code>--dec_md</code>, <code>--dcm_md</code>, <code>--december_mode</code>, <code>--dec_mode</code>)</itemformat></item>
</tableterm><tableitem><para>Winter mode aka December mode determines the start and end months of
the climatology and the type of NH winter seasonal average.
Two valid arguments are <code>jfd</code> (default, or synonyms <code>sdd</code>
and <code>JFD</code>) and <code>djf</code> (or synonyms <code>scd</code> and
<code>DJF</code>). 
<acronym><acronymword>DJF</acronymword></acronym>-mode is the same as <acronym><acronymword>SCD</acronymword></acronym>-mode which
stands for &textldquo;Seasonally Continuous December&textrdquo;. 
The first month used is December of the year before the start year
specified with <samp>-s</samp>.
The last month is November of the end year specified with <samp>-e</samp>.
In <acronym><acronymword>DJF</acronymword></acronym>-mode the Northern Hemisphere winter seasonal
climatology will be computed with sets of the three consecutive
months December, January, and February (DJF) where the calendar
year of the December months is always one less than the calendar
year of January and February.
<acronym><acronymword>JFD</acronymword></acronym>-mode is the same as <acronym><acronymword>SDD</acronymword></acronym>-mode which stands for
&textldquo;Seasonally Discontinuous December&textrdquo;.
The first month used is January of the specified start year. 
The last month is December of the end year specified with <samp>-e</samp>.
In <acronym><acronymword>JFD</acronymword></acronym>-mode the Northern Hemisphere winter seasonal
climatology will be computed with sets of the three non-consecutive
months January, February, and December (JFD) from each calendar year. 
</para>
<html endspaces=" ">
&lt;a name=&quot;clm_md&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm_md --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1718"><code>-C <var>clm_md</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1719"><var>clm_md</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1720"><code>--clm_md</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1721"><code>--climatology_mode</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1722"><code>--mode</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1723"><code>--climatology</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-C <var>clm_md</var> (<code>--clm_md</code>, <code>--climatology_mode</code>, <code>--mode</code>, <code>--climatology</code>)</itemformat></item>
</tableterm><tableitem><para>Climatology mode.
Valid values for <var>clm_md</var> are
<code>ann</code> (or synonyms <code>annual</code>, <code>annual</code>, <code>yearly</code>, or <code>year</code>)
for annual-mode climatologies,
<code>dly</code> (or synonyms <code>daily</code>, <code>doy</code>, or <code>day</code>)
for daily-mode climatologies,
<code>hfc</code> (or synonyms <code>high_frequency_climo</code> or <code>hgh_frq_clm</code>)
for high-frequency (diurnally resolved) climos, 
<code>hfs</code> (or synonyms <code>high_frequency_splitter</code> or <code>hgh_frq_spl</code>)
for high-frequency splitting, and 
<code>mth</code> (or synonyms <code>month</code> or <code>monthly</code>)
for monthly climotologies.
The value indicates the timespan of each input file for annual and
monthly climatologies.
The default mode is <samp>mth</samp>, which means input files are monthly
averages.  
Use <samp>ann</samp> when the input files are a series of annual means 
(a common temporal resolution for ice-sheet simulations).
The value <samp>dly</samp> is used only input files whose temporal
resolution is daily or finer, and when the desired output is a
day-of-year climatology where the means are output for each
day of a <w>365 day</w> year.
Day-of-year climatologies are uncommon, yet useful for showing
daily variability.
The value <samp>hfc</samp> indicates a high-frequency climatology where
the output will be a traditional set of climatological monthly,
seasonal, or annual means similar to monthly climos, except that
each file will have the same number of timesteps-per-day as the
input data to resolve the diurnal cycle.
The value <samp>hfs</samp> indicates a high-frequency splitting operation
where an interannual input timeseries will be split into regular
size segments of a given number of years, similar to <acronym><acronymword>CMIP</acronymword></acronym>
timeseries.
</para>
<para>The climatology generator and splitter do not require that daily-mode
input files begin or end on daily boundaries.
These tools hyperslab the input files using the date information
required to performed their analysis.
This facilitates analyzing datasets with varying numbers of days per
input file.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1724"><code>stdin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1725"><command>crontab</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1726"><code>nohup</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1727">Python</indexterm></cindex>
<para>Explicitly specifying <samp>--clm_md=mth</samp> serves a secondary purpose,
namely invoking the default setting on systems that control
<code>stdin</code>.
When <command>ncclimo</command> detects that <code>stdin</code> is not attached to the
terminal (keyboard) it automatically expects a list of files on
<code>stdin</code>. 
Some environments, however, hijack <code>stdin</code> for their purposes
and thereby confuse <code>ncclimo</code> into expecting a list argument.
Users have encountered this issue when attempting to run
<command>ncclimo</command> in Python parallel environments, via inclusion in 
<command>crontab</command>, and in <command>nohup</command>-mode (whatever that is!).
In such cases, explicitly specify <samp>--clm_md=mth</samp> (or <code>ann</code> or
<code>day</code>) to persuade <command>ncclimo</command> to compute a normal
climatology. 
</para>
<html endspaces=" ">
&lt;a name=&quot;caseid&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#caseid --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1728"><code>-c <var>caseid</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1729"><var>caseid</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1730"><code>--caseid</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1731"><code>--case</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-c <var>caseid</var> (<code>--case</code>, <code>--caseid</code>, <code>--case_id</code>)</itemformat></item>
</tableterm><tableitem><para>Simulation name, or any input filename for non-<acronym><acronymword>CESM</acronymword></acronym>&textrsquo;ish files.  
The use of <var>caseid</var> is required in climate generation mode (unless
equivalent information is provided through other options), where
<var>caseid</var> is used to construct both input and output filenames.
For <acronym><acronymword>CESM</acronymword></acronym>&textrsquo;ish input files like
<file>famipc5_ne30_v0.3_00001.cam.h0.1980-01.nc</file>, 
specify <samp>-c famipc5_ne30_v0.3_00001</samp>. 
The <samp>.cam.</samp> and <samp>.h0.</samp> bits are added internally to produce
the input filenames.
Modify these via the <option>-m <var>mdl_nm</var></option> and <option>-h
<var>hst_nm</var></option> options if needed.   
</para>
<para>For input files named slightly differently than standard
<acronym><acronymword>CESM</acronymword></acronym>&textrsquo;ish names, supply the filename (excluding the path
component) as the <var>caseid</var> and then <command>ncclimo</command> will attempt
to parse that by matching to a database of regular expressions known
to be favored by various other datasets.
These expressions are all various formats of dates at the end of the
filenames, and adhere to the general convention
<var>prefix</var>[.-]<var>YYYY</var>[-]<var>MM</var>[-]<var>DD</var>[-]<var>SSSSS</var>.<var>suffix</var>.
The particular formats currently supported, as of <acronym><acronymword>NCO</acronymword></acronym> version
5.1.6 (May, 2023) are:
<var>prefix</var><code>_YYYYMM</code>.<var>suffix</var>, 
<var>prefix</var><code>.YYYY-MM</code>.<var>suffix</var>, 
<var>prefix</var><code>.YYYY-MM-01</code>.<var>suffix</var>, and
<var>prefix</var><code>.YYYY-MM-01-00000</code>.<var>suffix</var>.
For example, input files like <file>merra2_198001.nc</file> (i.e., the six
digits that precede the suffix are <var>YYYYMM</var>-format), specify
<samp>-c merra2_198001.nc</samp> and the prefix (<code>merra2</code>) will be
automatically abstracted and used to template and generate all the
filenames based on the specified <var>yr_srt</var> and <var>yr_end</var>. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncclimo -c merra2_198001.nc --start=1980 --end=1999 --drc_in=${drc}
ncclimo -c cesm_1980-01.nc --start=1980 --end=1999 --drc_in=${drc}
ncclimo -c eamxx_1980-01-00000.nc --start=1980 --end=1999 --drc_in=${drc}
</verbatim>
</example>
<para>Please tell us any common dataset filename regular expressions that you would
like added to <command>ncclimo</command>&textrsquo;s internal database.
</para>
<para>The <samp>--caseid=<var>caseid</var></samp> option is not mandatory in
the High-Frequency-Splitter (<var>clm_md</var>=<code>hfs</code>) and
High-Frequency-Climatology (<var>clm_md</var>=<code>hfc</code>) modes.
Those modes expect all input filenames to be entered from the
command-line so there is no internal need to create filenames
from the <var>caseid</var> variable.
Instead, when <var>caseid</var> is specified in a high-freqency mode,
its value is used to name the output files in a similar manner
to the <samp>-f <var>fml_nm</var></samp> option.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1732"><code>-D <var>dbg_lvl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1733"><var>dbg_lvl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1734"><code>--dbg_lvl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1735"><code>--debug_level</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-D <var>dbg_lvl</var> (<code>--dbg_lvl</code>, <code>--dbg</code>, <code>--debug</code>, <code>--debug_level</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a debugging level similar to the rest of <acronym><acronymword>NCO</acronymword></acronym>.
If <math><var>dbg_lvl</var> = 1</math>, <command>ncclimo</command> prints more extensive
diagnostics of its behavior.
If <math><var>dbg_lvl</var> = 2</math>, <command>ncclimo</command> prints the commands
it would execute at any higher or lower debugging level, but does
not execute these commands.
If <math><var>dbg_lvl</var> &gt; 2</math>, <command>ncclimo</command> prints the diagnostic
information, executes all commands, and passes-through the debugging
level to the regridder (<command>ncks</command>) for additional diagnostics.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1736"><code>d2f</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1737"><code>--d2f</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1738"><code>--d2s</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1739"><code>--dbl_flt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1740"><code>--dbl_sgl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1741"><code>--double_float</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1742"><code>ncpdq</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1743">Precision</indexterm></cindex>
<item spaces=" "><itemformat command="option">--d2f (<code>--d2f</code>, <code>--d2s</code>, <code>--dbl_flt</code>, <code>--dbl_sgl</code>, <code>--double_float</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) causes <command>ncclimo</command>
to invoke <command>ncremap</command> with the same switch, so that
<command>ncremap</command> converts all double precision non-coordinate
variables to single precision in the regridded file.
This switch has no effect on files that are not regridded.
To demote the precision in such files, use <command>ncpdq</command> to apply
the <code>dbl_flt</code> packing map to the file directly.
</para>
<html endspaces=" ">
&lt;a name=&quot;dpf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dpf --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1744"><code>--dpf=<var>dpf</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1745"><var>dpf</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1746"><code>--dpf</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1747"><code>--days-per-file</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--dpf=<var>dpf</var> (<code>--dpf</code>, <code>--days_per_file</code>)</itemformat></item>
</tableterm><tableitem><para>The number of days-per-file in files ingested by <command>ncclimo</command>.
It can sometimes be difficult for <command>ncclimo</command> to infer the
number of days-per-file in high-frequency input files, i.e., those
with 1 or more timesteps-per-day.
In such cases, users may override the inferred value by explicitly
specifying <code>--dpf=<var>dpf</var></code>.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1748"><code>--dpt_fl=<var>dpt_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1749"><var>dpt_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1750"><code>--mpas_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1751"><code>--mpas_depth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1752"><code>--depth_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1753"><command>add_depth.py</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1754">Depth</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1755"><acronym><acronymword>MPAS</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="option">--dpt_fl=<var>dpt_fl</var> (<code>--dpt_fl</code>, <code>--depth_file</code>, <code>--mpas_fl</code>, <code>--mpas_depth</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>--dpt_fl=<var>dpt_fl</var></samp> triggers the addition of a depth
coordinate to <acronym><acronymword>MPAS</acronymword></acronym> ocean datasets that will undergo
regridding.
<command>ncclimo</command> passes this option through to <command>ncremap</command>,
and this option has no effect when <command>ncclimo</command> does not invoke
<command>ncremap</command>. 
The <command>ncremap</command> documentation contains the full description of
this option.
</para>
<html endspaces=" ">
&lt;a name=&quot;end_yr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#end_yr --&gt;
&lt;a name=&quot;yr_end&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#yr_end --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1756"><code>-e <var>end_yr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1757"><var>end_yr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1758"><code>--end_yr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1759"><code>--end_year</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1760"><code>--year_end</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1761"><code>--end</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-e <var>end_yr</var> (<code>--end_yr</code>, <code>--yr_end</code>, <code>--end_year</code>, <code>--year_end</code>, <code>--end</code>)</itemformat></item>
</tableterm><tableitem><para>End year (example: 2000). 
By default, the last month is December of the specified end year.  
If <samp>-a scd</samp> is specified, the last month used is November of the
specified end year.  
</para>
<html endspaces=" ">
&lt;a name=&quot;fml_nm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fml_nm --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1762"><code>-f <var>fml_nm</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1763"><var>fml_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1764"><code>--fml_nm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1765"><code>--fml</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1766"><code>--family</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1767"><code>--family_name</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-f <var>fml_nm</var> (<code>--fml_nm</code>, <code>--fml</code>, <code>--family</code>, <code>--family_name</code>)</itemformat></item>
</tableterm><tableitem><para>Family name (nickname) of output files.
In climate generation mode, output climo file names are constructed by
default with the same <var>caseid</var> as the input files.
The <var>fml_nm</var>, if supplied, replaces <var>caseid</var> in output climo
names, which are of the form
<code><var>fml_nm</var>_XX_YYYYMM_YYYYMM.nc</code> where <var>XX</var> is the month or
seasonal abbreviation.
Use <samp>-f <var>fml_nm</var></samp> to simplify long names, avoid overlap, etc.
Example values of <var>fml_nm</var> are <samp>control</samp>, <samp>experiment</samp>,
and (for a single-variable climo) <samp>FSNT</samp>.
In timeseries reshaping mode, <var>fml_nm</var> will be used, if supplied,
as an additional string in the output filename.
For example, specifying <samp>-f control</samp> would cause
<file>T_000101_000912.nc</file> to be instead named 
<file>T_control_000101_000912.nc</file>.
</para>
<html endspaces=" ">
&lt;a name=&quot;hst_nm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hst_nm --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1768"><code>-h <var>hst_nm</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1769"><var>hst_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1770"><code>--history_name</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1771"><code>--hst_nm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1772"><code>--history</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-h <var>hst_nm</var> (<code>--hst_nm</code>, <code>--history_name</code>, <code>--history</code>)</itemformat></item>
</tableterm><tableitem><para>History volume name of file used to generate climatologies.
This referring to the <var>hst_nm</var> character sequence used to construct
input file names: <code>caseid.mdl_nm.</code><var>hst_nm</var><code>.YYYY-MM.nc</code>.
By default input climo file names are constructed from the <var>caseid</var> 
of the input files, together with the model name <var>mdl_nm</var> (specified
with <samp>-m</samp>) and the date range.
Use <samp>-h <var>hst_nm</var></samp> to specify alternative history volumes.
Examples include <samp>h0</samp> (default, works for <acronym><acronymword>CAM</acronymword></acronym>,
<acronym><acronymword>CLM/CTSM/ELM</acronymword></acronym>), <samp>h1</samp>, and <samp>h</samp> (for <acronym><acronymword>CISM</acronymword></acronym>).
</para>
<html endspaces=" ">
&lt;a name=&quot;drc_in&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drc_in --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1773"><code>-i <var>drc_in</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1774"><var>drc_in</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1775"><code>--drc_in</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1776"><code>--in_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1777"><code>--dir_in</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1778"><code>--input</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-i <var>drc_in</var> (<code>--drc_in</code>, <code>--in_drc</code>, <code>--dir_in</code>, <code>--input</code>)</itemformat></item>
</tableterm><tableitem><para>Directory containing all monthly mean files to read as input to the
climatology.
The use of <var>drc_in</var> is mandatory in climate generation mode and is 
optional in timeseries reshaping mode.
In timeseries reshaping mode, <command>ncclimo</command> uses all netCDF files
(meaning files with suffixes <code>.nc</code>, <code>.nc3</code>, <code>.nc4</code>,
<code>.nc5</code>, <code>.nc6</code>, <code>.nc7</code>,
<code>.cdf</code>, <code>.hdf</code>, <code>.he5</code>, or <code>.h5</code>) in <var>drc_in</var> to 
create the list of input files when no list is provided through
<code>stdin</code> or as positional arguments to the command-line. 
</para>
<html endspaces=" ">
&lt;a name=&quot;job_nbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#job_nbr --&gt;
&lt;a name=&quot;job_nbr_ncclimo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#job_nbr_ncclimo --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1779"><code>-j <var>job_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1780"><var>job_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1781"><code>--job_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1782"><code>--job_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1783"><code>--jobs</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-j <var>job_nbr</var> (<code>--job_nbr</code>, <code>--job_number</code>, <code>--jobs</code>)</itemformat></item>
</tableterm><tableitem><para>The <var>job_nbr</var> parameter controls the parallelism granularity of
both timeseries reshaping (aka splitting) and climatology generation.
These modes parallelize over different types of tasks, so we describe
the effects of <var>job_nbr</var> separately, first for climatologies, then
for splitting. 
However, for both modes, <var>job_nbr</var> specifies the total number of
simultaneous processes to run in parallel either on the local node for
Background parallelism, or across all the nodes for <acronym><acronymword>MPI</acronymword></acronym>
parallelism (i.e., <var>job_nbr</var> is the simultaneous total across all
nodes, it is not the simultaneous number per node).
</para>
<para>For climatology generation, <var>job_nbr</var> specifies the number of
averaging tasks to perform simultaneously on the local node for
Background parallelism, or spread across all nodes for
<acronym><acronymword>MPI</acronymword></acronym>-parallelism.
By default <command>ncclimo</command> sets <math><var>job_nbr</var> = 12</math> for
background parallelism mode.
This number ensures that monthly averages for all individual
months complete more-or-less simultaneously, so that all seasonal
averages can then be computed.
However, many nodes are too small to simultaneously average multiple
distinct months (January, February, etc.).
Hence <var>job_nbr</var> may be set to any factor of 12, i.e., 1, 2, 3, 4,
6, or 12.
For Background parallelism, setting <math><var>job_nbr</var> = 4</math> causes
four-months to be averaged at one time.
After three batches of four-months complete, the climatology generator
then moves on to seasonal averaging and regridding.
In <acronym><acronymword>MPI</acronymword></acronym>-mode, <command>ncclimo</command> defaults to 
<math><var>job_nbr</var> = <var>nd_nbr</var></math> unless the user explicitly sets
<var>job_nbr</var> to a different value. 
For the biggest jobs, when a single-month nearly exhausts the
<acronym><acronymword>RAM</acronymword></acronym> on a node, this default value
<math><var>job_nbr</var> = <var>nd_nbr</var></math> ensures that each node gets only
one job at a time. 
To override this default for <acronym><acronymword>MPI</acronymword></acronym>-parallelism, set
<math><var>job_nbr</var> &gt;= <var>nd_nbr</var></math> otherwise some nodes will be idle 
for the entire time.
If a node can handle averaging three distinct months simultaneously,
then try <math><var>job_nbr</var> = 3*<var>nd_nbr</var></math>.
Never set <math><var>job_nbr</var> &gt; 12</math> in climatology mode, since there
are at most only twelve jobs that can be performed in parallel.
</para>
<para>For splitting, <var>job_nbr</var> specifies the number of simultaneous
subsetting processes to spawn during parallel execution for both
Background and <acronym><acronymword>MPI</acronymword></acronym>-parallelism.  
In both parallelism modes <command>ncclimo</command> spawns processes in
batches of <var>job_nbr</var> jobs, then waits for those processes to
complete. 
Once a batch finishes, <command>ncclimo</command> spawns the next batch.
For Background-parallelism, all jobs are spawned to the local node.
For <acronym><acronymword>MPI</acronymword></acronym>-parallelism, all jobs are spawned in round-robin
fashion to all available nodes until <var>job_nbr</var> jobs are running.
Rinse, lather, repeat until all variables have been split.
The splitter chooses its default value of <var>job_nbr</var> based on
on the parallelism mode.
For Background parallelism, <var>job_nbr</var> defaults to the number of
variables to be split, so that not specifying <var>job_nbr</var> results 
in launching <var>var_nbr</var> simultaneous splitter tasks.
This scales well to over a hundred variables in our tests
<footnote><para>At least one known environment (the <acronym><acronymword>E3SM-Unified</acronymword></acronym>
Anaconda environment at <acronym><acronymword>NERSC</acronymword></acronym>) prevents users from spawning
scores of processes and may report <acronym><acronymword>OpenBLAS/pthread</acronymword></acronym> or
<code>RLIMIT_NPROC</code>-related errors.
A solution seems to be executing <samp>ulimit -u unlimited</samp></para></footnote>.
In practice, splitting timeseries consumes minimal memory, since
<command>ncrcat</command> (which underlies the splitter) only holds one
record (timestep) of a variable in memory <ref label="Memory-Requirements"><xrefnodename>Memory Requirements</xrefnodename></ref>.
</para>
<para>However, if splitting consumes so much <acronym><acronymword>RAM</acronymword></acronym> (e.g., because 
variables are large and/or the number of jobs is large) that a
single node can perform only one or a few subsetting jobs at a time,
then it is reasonable to use <acronym><acronymword>MPI</acronymword></acronym>-mode to split the datasets. 
For <acronym><acronymword>MPI</acronymword></acronym>-parallelism, <var>job_nbr</var> defaults to the number of 
nodes requested. 
This helps prevent users from overloading nodes with too many jobs.
Usually, however, nodes can usually subset (and then regrid, if
requested) multiple variables simultaneously.
In summary, the splitter defaults to
<math><var>job_nbr</var> = <var>var_nbr</var></math> in Background mode, and to
<math><var>job_nbr</var> = <var>node_nbr</var></math> in <acronym><acronymword>MPI</acronymword></acronym> mode. 
Subject to the availability of adequate <acronym><acronymword>RAM</acronymword></acronym>, expand the
number of jobs-per-node by increasing <var>job_nbr</var> until overall
throughput peaks.
</para>
<para>The main throughput bottleneck in timeseries reshaping mode is I/O. 
Increasing <var>job_nbr</var> may reduce throughput once the maximum I/O
bandwidth of the node is reached, due to contention for I/O
resources. 
Regridding requires math that can relieve some I/O contention and
allows for some throughput gains with increasing <var>job_nbr</var>.
One strategy that seems sensible is to set <var>job_nbr</var> equal to
the number of nodes times the number of cores per node, and increase
or decrease as necessary until throughput peaks.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1784"><code>-L</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1785"><code>--dfl_lvl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1786"><code>--dfl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1787"><code>--deflate</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-L (<code>--dfl_lvl</code>, <code>--dfl</code>, <code>--deflate</code>)</itemformat></item>
</tableterm><tableitem><para>Activate deflation (i.e., lossless compress, see <ref label="Deflation"><xrefnodename>Deflation</xrefnodename></ref>) with
the <code>-L <var>dfl_lvl</var></code> short option (or with the same argument to 
the <samp>--dfl_lvl</samp> or <samp>--deflate</samp> long options). 
Specify deflation level <var>dfl_lvl</var> on a scale from no deflation
(<var>dfl_lvl = 0</var>, the default) to maximum deflation
(<var>dfl_lvl = 9</var>).
</para>
<html endspaces=" ">
&lt;a name=&quot;lnk_flg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lnk_flg --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1788"><code>-l</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1789"><code>--lnk_flg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1790"><code>--link_flag</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1791"><code>--no_amwg_links</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1792"><code>--no_amwg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1793"><code>--amwg_links</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-l (<code>--lnk_flg</code>, <code>--link_flag</code>)</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--no_amwg_link (<code>--no_amwg_link</code>, <code>--no_amwg_links</code>, <code>--no_amwg</code>, <code>--no_AMWG_link</code>, <code>--no_AMWG_links</code>)</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--amwg_link (<code>--amwg_link</code>, <code>--amwg_links</code>, <code>--AMWG_link</code>, <code>--AMWG_links</code>)</itemformat></item>
</tableterm><tableitem><para>These options turn-on or turn-off the linking of
<acronym><acronymword>E3SM/ACME</acronymword></acronym>-climo to <acronym><acronymword>AMWG</acronymword></acronym>-climo filenames.
<acronym><acronymword>AMWG</acronymword></acronym> omits the <acronym><acronymword>YYYYMM</acronymword></acronym> components of climo filenames,
resulting in shorter names.
By default <command>ncclimo</command> symbolically links the full
<acronym><acronymword>E3SM/ACME</acronymword></acronym> filename (which is always) created to a file with
the shorter (<acronym><acronymword>AMWG</acronymword></acronym>) name whose creation is optional. 
<acronym><acronymword>AMWG</acronymword></acronym> diagnostics scripts can produce plots directly from
the linked <acronym><acronymword>AMWG</acronymword></acronym> filenames. 
The <samp>-l</samp> (and <samp>--lnk_flg</samp> and <samp>--link_flag</samp> long-option
synonmyms) are true options that require an argument of either
<samp>Yes</samp> or <samp>No</samp>.
The remaining synonyms are switches that take no arguments.
The <samp>--amwg_link</samp> switch and its synonyms cause the creation
of symbolic links with <acronym><acronymword>AMWG</acronymword></acronym> filenames.
The <samp>--no_amwg_link</samp> switch and its synonyms prevent the creation
of symbolic links with <acronym><acronymword>AMWG</acronymword></acronym> filenames.
If you do not need <acronym><acronymword>AMWG</acronymword></acronym> filenames, turn-off linking to
reduce file proliferation in the output directories.
</para>
<html endspaces=" ">
&lt;a name=&quot;mdl_nm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mdl_nm --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1794"><code>-m <var>mdl_nm</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1795"><var>mdl_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1796"><code>--model_name</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1797"><code>--mdl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1798"><code>--model</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1799"><code>--mdl_nm</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-m <var>mdl_nm</var> (<code>--mdl_nm</code>, <code>--mdl</code>, <code>--model_name</code>, <code>--model</code>)</itemformat></item>
</tableterm><tableitem><para>Model name (as embedded in monthly input filenames). 
Default is <samp>cam</samp>. Other options are <samp>clm2</samp>, <samp>ocn</samp>,
<samp>ice</samp>, <samp>cism</samp>, <samp>cice</samp>, <samp>pop</samp>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;nco_opt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco_opt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1800"><code>-n <var>nco_opt</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1801"><var>nco_opt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1802"><code>--nco_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1803"><code>--nco_options</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1804"><code>--nco</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-n <var>nco_opt</var> (<code>nco_opt</code>, <code>nco</code>, <code>nco_options</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a string of options to pass-through unaltered to
<command>ncks</command>. 
<var>nco_opt</var> defaults to <samp>--no_tmp_fl</samp>.
Note that <command>ncclimo</command> passes its <var>nco_opt</var> to
<command>ncremap</command>.
This can cause unexpected results, so use the front-end options to
<command>ncclimo</command> when possible, rather than attempting to subvert
them with <var>nco_opt</var>.
</para>
<html endspaces=" ">
&lt;a name=&quot;drc_rgr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drc_rgr --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1805"><code>-O <var>drc_rgr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1806"><var>drc_rgr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1807"><code>--drc_rgr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1808"><code>--rgr_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1809"><code>--dir_rgr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1810"><code>--regrid</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-O <var>drc_rgr</var> (<code>--drc_rgr</code>, <code>--rgr_drc</code>, <code>--dir_rgr</code>, <code>--regrid</code>)</itemformat></item>
</tableterm><tableitem><para>Directory to hold regridded climo files.
Regridded climos are placed in <var>drc_out</var> unless a separate
directory for them is specified with <samp>-O</samp> (NB: capital &textldquo;O&textrdquo;). 
</para>
<html endspaces=" ">
&lt;a name=&quot;no_cll_msr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_cll_msr --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1811"><code>--no_cll_msr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1812"><code>--no_cll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1813"><code>--no_cell_measures</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1814"><code>--no_area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1815"><code>cell_measures</code> attribute</indexterm></cindex>
<item spaces=" "><itemformat command="option">--no_cll_msr (<code>--no_cll_msr</code>, <code>--no_cll</code>, <code>--no_cell_measures</code>, <code>--no_area</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) controls whether <command>ncclimo</command>
and <command>ncremap</command> add measures variables to the extraction list
along with the primary variable and other associated variables. 
See <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref> for a detailed description.
</para>
<html endspaces=" ">
&lt;a name=&quot;no_frm_trm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_frm_trm --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1816"><code>--no_frm_trm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1817"><code>--no_frm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1818"><code>--no_formula_terms</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1819"><code>formula_terms</code> attribute</indexterm></cindex>
<item spaces=" "><itemformat command="option">--no_frm_trm (<code>--no_frm_trm</code>, <code>--no_frm</code>, <code>--no_formula_terms</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) controls whether <command>ncclimo</command>
and <command>ncremap</command> add formula variables to the extraction list along
with the primary variable and other associated variables. 
See <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref> for a detailed description.
</para>
<html endspaces=" ">
&lt;a name=&quot;hms_avg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hms_avg --&gt;
&lt;a name=&quot;rgn_avg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgn_avg --&gt;
&lt;a name=&quot;glb_avg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#glb_avg --&gt;
&lt;a name=&quot;global_average&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#global_average --&gt;
&lt;a name=&quot;regional_average&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#regional_average --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1820"><code>--glb_avg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1821"><code>--global_average</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1822"><code>--rgn_avg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1823"><code>--regional_average</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1824"><code>--hms_avg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1825"><code>--hemispheric_average</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1826">global average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1827">regional average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1828">hemispheric average</indexterm></cindex>
<item spaces=" "><itemformat command="option">--glb_avg (<code>--glb_avg</code>, <code>--global_average</code>) (deprecated)</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--rgn_avg (<code>--rgn_avg</code>, <code>--region_average</code>)</itemformat></item>
</tableterm><tableitem><para>When introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.9.1 (released December,
2019), this switch (which takes no argument) caused the splitter to
output global horizontally spatially averaged timeseries files instead of
raw, native-grid timeseries.
This switch changed behavior in <acronym><acronymword>NCO</acronymword></acronym> version 5.1.1
(released November, 2022).
It now causes the splitter to output three horizontally spatially
averaged timeseries.
First is the global average (as before), next is the northern
hemisphere average, followed by the southern hemisphere average.
The three timeseries are now saved in a two-dimensional (time
by region) array with a &textldquo;region dimension&textrdquo; named <code>rgn</code>.
The region names are stored in the variable named <code>region_name</code>.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 5.2.3 (released March, 2024), this switch
works with sub-gridscale fractions, such as are common in surface
models like <acronym><acronymword>ELM</acronymword></acronym> and <acronym><acronymword>CLM</acronymword></acronym>.
The correct weights for (<acronym><acronymword>SGS</acronymword></acronym>) fraction will automatically be
applied so long as <command>ncclimo</command> is invoked with
<samp>-P <var>prc_typ</var></samp>.
Otherwise the field containing the (<acronym><acronymword>SGS</acronymword></acronym>) fraction must be
supplied with <samp>--sgs_frc=<var>sgs_frc</var></samp>.
</para>
<para>This switch only has effect in timeseries splitting mode.
This is useful, for example, to quickly diagnose the behavior of ongoing
model simulations prior to a full-blown analysis. 
Thus the spatial mean files will be in the same location and have the same
name as the native grid timeseries would have been and had, respectively.
Note that this switch does not alter the capability of also outputting
the full regridded timeseries, if requested, at the same time.
</para>
<para>Because the switch now outputs global and regional averages, the best
practice is to invoke with <samp>--rgn_avg</samp> instead of
<samp>--glb_avg</samp>. 
<acronym><acronymword>NCO</acronymword></acronym> version 5.2.8 (released September, 2024) superseded this
switch by introducing support for more general global/regional
statistics timeseries output via the <code>--glb_stt</code>/<code>--rgn_stt</code>
options. 
</para>
<html endspaces=" ">
&lt;a name=&quot;hms_stt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hms_stt --&gt;
&lt;a name=&quot;rgn_stt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgn_stt --&gt;
&lt;a name=&quot;glb_stt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#glb_stt --&gt;
&lt;a name=&quot;global_statistic&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#global_statistic --&gt;
&lt;a name=&quot;regional_statistic&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#regional_statistic --&gt;
&lt;a name=&quot;foo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#foo --&gt;
&lt;a name=&quot;foo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#foo --&gt;
&lt;a name=&quot;foo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#foo --&gt;
&lt;a name=&quot;foo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#foo --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1829"><code>--sum_scl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1830"><code>--sum_scale</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1831"><code>--scl_fct</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1832"><code>--scale_factor</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1833"><code>--sum_scl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1834"><code>--glb_stt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1835"><code>--global_statistic</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1836"><code>--rgn_stt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1837"><code>--regional_statistic</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1838"><code>--hms_stt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1839">global statistic</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1840">regional statistic</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1841">hemispheric statistic</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1842">sum scale</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1843">scale factor</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1844"><code>--sum_scl</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--glb_stt (<code>--glb_stt</code>, <code>--global_statistic</code>)</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--rgn_stt (<code>--rgn_stt</code>, <code>--region_statistic</code>)</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>NCO</acronymword></acronym> version 5.2.8 (released September, 2024) introduced the
<code>--glb_stt</code>/<code>--rgn_stt</code> options (or long options
equivalents <code>--hms_stt</code>, <code>--regional_statistic</code>, and
<code>--global_statistic</code>) to support more general global/regional
statistics timeseries output. 
These options allow the user to choose which statistic, sums or
averages, to output with global/regional timeseries for all
variables.
Set <var>rgn_stt</var> to <code>avg</code>, <code>average</code>, or <code>mean</code>
to output timeseries of the global/regional mean statistic.
Set <var>rgn_stt</var> to <code>sum</code>, <code>total</code>, <code>ttl</code>, or
<code>integral</code> to output timeseries of the global/regional sum.
The option <samp>--rgn_stt=avg</samp> is equivalent setting the
<code>--rgn_avg</code> switch (which may eventually be deprecated).
When invoked with <samp>--rgn_stt=sum</samp> the averaged field is
multiplied by the sum of the <var>area</var> variable. 
For area-intensive fields (e.g., fluxes per unit area) this results in
the total net flux over the area.
However, the field must employ the same areal units as the <var>area</var> 
variable for this to be true. 
For example, fields given in inverse square meters would need to
employ an <var>area</var> variable in square meters.
Unfortunately, many people love non-SI units so that is rarely
the case!
For example, ELM and CLM archive <var>area</var> in a field named
<code>area</code> whose units are square kilometers, so a scale factor of
one million is needed to correct the sum for many variables.
EAM and CAM also archive <var>area</var> in a field named <code>area</code>,
though in unis of inverse steradians, which would require a
different scale factor to match the sums of area-intensive fields.
</para>
<para>That is why <command>ncclimo</command> introduced a second new option
<samp>--sum_scl=<var>sum_scl</var></samp>, in <acronym><acronymword>NCO</acronymword></acronym> version 5.2.8
(released September, 2024).
The long option equivalents are <code>--scl_fct</code>, <code>--sum_scale</code>,
and <code>--scale_factor</code>.
When <var>rgn_stt</var> is <code>sum</code>, the <var>sum_scl</var> scale factor
multiplies the integrated field value, which allows the user to
generate timeseries in the desired units for any field.
Consider these prototypical examples to generate global timeseries
of common geophysical statistics from <acronym><acronymword>ESM</acronymword></acronym> output:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Timeseries of global GPP in grams/s for ELM/CLM:
ncclimo -P elm --split --rgn_stt=sum --sum_scl=1.0e6 -v GPP ...
# Timeseries of global GPP in GT C/yr for ELM/CLM:
ncclimo -P elm --split --rgn_stt=sum --sum_scl=1.0e6*3600*24*365/1.0e12 -v GPP ...
# Timeseries of global column vapor in kg for EAM/CAM:
ncclimo -P eam --split --rgn_stt=sum --sum_scl=6.37122e6^2 -v TMQ ...
</verbatim>
</example>
<para>All three examples set <var>rgn_stt</var> to <code>sum</code> in order to
activate the <var>sum_scl</var> factor.
The first example scales (multiplies) the mean of all global
timeseries (here, <code>GPP</code> for concreteness) by one million.
This factor converts the <acronym><acronymword>ELM</acronymword></acronym> or <acronym><acronymword>CLM</acronymword></acronym> <code>area</code>
variable from square kilometers to square meters, appropriate to
to integrating fields like <code>GPP</code> whose fluxes are per square
meter.
The output timeseries of <code>GPP</code> would then be in <w>gC s-1</w>.
The second example sets the scale factor to convert the global
<code>GPP</code> statistic to units of <w>GT C yr-1</w>.
The third example shows how to convert areal sums in sterradians
(which <acronym><acronymword>EAM</acronymword></acronym> and <acronym><acronymword>CAM</acronymword></acronym> use for <code>area</code>) to
square meters.
This factor converts atmospheric variables from global mean mass per
square meter to global total mass.
The <code>--glb_stt=sum</code>/<code>--sum_scl</code> procedure is model- and
variable-specific and we are open to suggestions to make it more
useful. 
</para>
<html endspaces=" ">
&lt;a name=&quot;no_ntv_tms&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_ntv_tms --&gt;
&lt;a name=&quot;no_ntv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_ntv --&gt;
&lt;a name=&quot;no_native&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_native --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1845"><code>--no_ntv_tms</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1846"><code>--no_ntv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1847"><code>--no_native</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1848"><code>--remove_native</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--no_ntv_tms (<code>--no_ntv_tms</code>, <code>--no_ntv</code>, <code>--no_native</code>, <code>--remove_native</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) controls whether the splitter
retains native grid split files, which it does by default, or deletes them.
<command>ncclimo</command> can split model output from multi-variable native grid
files into per-variable timeseries files and regrid those onto a
so-called analysis grid. 
That is the typical format in which Model Intercomparison Projects
(<acronym><acronymword>MIP</acronymword></acronym>s) request and disseminate contributions.
When the data producer has no use for the split timeseries on the native
grid, he/she can invoke this flag to cause <command>ncclimo</command> to
delete the native grid timeseries (not the raw native grid datafiles).
This functionality is implemented by first creating the native grid 
timeseries, regridding it, and then overwriting the native grid
timeseries with the regridded timeseries.
Thus the regridded files will be in the same location and have the same
name as the native grid timeseries would have been and had, respectively.
</para>
<html endspaces=" ">
&lt;a name=&quot;no_stg_grd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_stg_grd --&gt;
&lt;a name=&quot;no_stg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_stg --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1849"><code>slat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1850"><code>slon</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1851"><code>w_stag</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1852"><code>--no_stg_grd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1853"><code>--no_stg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1854"><code>--no_stagger</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1855"><code>--no_staggered_grid</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--no_stg_grd (<code>--no_stg_grd</code>, <code>--no_stg</code>, <code>--no_stagger</code>, <code>--no_staggered_grid</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) controls whether
regridded output will contain the staggered grid coordinates 
<code>slat</code>, <code>slon</code>, and <code>w_stag</code> (<pxref label="Regridding"><xrefnodename>Regridding</xrefnodename></pxref>). 
By default the staggered grid is output for all files regridded from 
a Cap (aka <acronym><acronymword>FV</acronymword></acronym>) grid, except when the regridding is performed
as part of splitting (reshaping) into timeseries.
</para>
<html endspaces=" ">
&lt;a name=&quot;drc_out&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drc_out --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1856"><code>-o <var>drc_out</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1857"><var>drc_out</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1858"><code>--drc_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1859"><code>--out_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1860"><code>--dir_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1861"><code>--output</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-o <var>drc_out</var> (<code>--drc_out</code>, <code>--out_drc</code>, <code>--dir_out</code>, <code>--output</code>)</itemformat></item>
</tableterm><tableitem><para>Directory to hold computed (output) native grid climo files.
Regridded climos are also placed here unless a separate directory
for them is specified with <samp>-O</samp> (NB: capital &textldquo;O&textrdquo;). 
</para>
<html endspaces=" ">
&lt;a name=&quot;par_typ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#par_typ --&gt;
&lt;a name=&quot;par_typ_ncclimo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#par_typ_ncclimo --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1862"><code>-p <var>par_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1863"><var>par_typ</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1864"><code>--par_typ</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1865"><code>--par_md</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1866"><code>--parallel_type</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1867"><code>--parallel_mode</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1868"><code>--parallel</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-p <var>par_typ</var> (<code>--par_typ</code>, <code>--par_md</code>, <code>--parallel_type</code>, <code>--parallel_mode</code>, <code>--parallel</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the parallelism mode desired.
The options are serial mode (<samp>-p srl</samp>, <samp>-p serial</samp>, or <samp>-p nil</samp>), 
background mode parallelism (<samp>-p bck</samp> or <samp>-p background</samp>)),
and <acronym><acronymword>MPI</acronymword></acronym> parallelism (<samp>-p mpi</samp> or <samp>-p MPI</samp>). 
The default is background-mode parallelism.
The default <var>par_typ</var> is <samp>background</samp>, which means
<command>ncclimo</command> spawns up to twelve (one for each month) parallel
processes at a time.
See discussion below under Memory Considerations.
</para>
<html endspaces=" ">
&lt;a name=&quot;qnt_prc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#qnt_prc --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1869"><code>--qnt=<var>qnt_prc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1870"><var>ppc_prc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1871"><var>qnt_prc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1872"><code>--ppc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1873"><code>--ppc_prc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1874"><code>--qnt_prc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1875"><code>--precision</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1876"><code>--qnt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1877"><code>--quantize</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--qnt=<var>qnt_prc</var> (<code>--ppc</code>, <code>--ppc_prc</code>, <code>--precision</code>, <code>--qnt</code>, <code>--quantize</code>)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1878">Decimal Significant Digits</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1879">Number of Significant Digits</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1880">Bit-Grooming</indexterm></cindex>
<para>Specifies the precision of the Precision-Preserving Compression
algorithm (<pxref label="Precision_002dPreserving-Compression"><xrefnodename>Precision-Preserving Compression</xrefnodename></pxref>).
A positive integer is interpreted as the Number of Significant Digits
for the Bit-Grooming algorithm, and is equivalent to specifying
<samp>--qnt default=<var>qnt_prc</var></samp> to a binary operator.
A positive or negative integer preceded by a period, e.g., <samp>.-2</samp> is 
interpreted as the number of Decimal Significant Digits for the
rounding algorithm and is equivalent to specifying
<samp>--qnt default=.<var>qnt_prc</var></samp> to a binary operator.
This option applies one precision algorithm and a uniform precision
for the entire file. 
To specify variable-by-variable precision options, pass the desired
options as a quoted string directly with <samp>-n <var>nco_opt</var></samp>,
e.g., <samp>-n '--qnt FSNT,TREFHT=4 --qnt CLOUD=2'</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;rgr_opt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr_opt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1881"><code>-R <var>rgr_opt</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1882"><var>rgr_opt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1883"><code>--rgr_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1884"><code>--regrid_options</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-R <var>rgr_opt</var> (<code>rgr_opt</code>, <code>regrid_options</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a string of options to pass-through unaltered to
<command>ncks</command>. 
<var>rgr_opt</var> defaults to <samp>-O --no_tmp_fl</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;rgr_map&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr_map --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1885"><code>-r <var>rgr_map</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1886"><var>rgr_map</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1887"><code>--rgr_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1888"><code>--regrid_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1889"><code>--map</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-r <var>rgr_map</var> (<code>--rgr_map</code>, <code>--regrid_map</code>, <code>--map</code>)</itemformat></item>
</tableterm><tableitem><para>Regridding map.
Unless <samp>-r</samp> is specified <command>ncclimo</command> produces only a 
climatology on the native grid of the input datasets.
The <var>rgr_map</var> specifies how to (quickly) transform the native
grid into the desired analysis grid.
<command>ncclimo</command> will (call <command>ncremap</command> to) apply the given map
to the native grid climatology and produce a second climatology on the
analysis grid.
Options intended exclusively for the regridder may be passed as
arguments to the <samp>-R</samp> switch.
See below the discussion on regridding.
</para>
<html endspaces=" ">
&lt;a name=&quot;mth_srt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mth_srt --&gt;
&lt;a name=&quot;srt_mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#srt_mth --&gt;
&lt;a name=&quot;mth_end&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mth_end --&gt;
&lt;a name=&quot;end_mth&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#end_mth --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1890"><code>--mth_srt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1891"><code>--srt_mth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1892"><code>--start_month</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1893"><code>--month_start</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--mth_srt=<var>mth_srt</var> (<code>--mth_srt</code>, <code>--srt_mth</code>, <code>--month_start</code>, <code>--start_month</code>)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="1894"><code>--mth_end</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1895"><code>--end_mth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1896"><code>--end_month</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1897"><code>--month_end</code></indexterm></cindex>
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--mth_end=<var>mth_end</var> (<code>--mth_end</code>, <code>--end_mth</code>, <code>--month_end</code>, <code>--end_month</code>)</itemformat></item>
</tableterm><tableitem><para>Start month (example: 4), and end month (example: 11).
The starting month of monthly timeseries extracted by the splitter
defaults to January of the specified start year, and the ending
month defaults to December of the specified end year.
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.9.8</w>, released in March, 2021,
the splitter mode of <command>ncclimo</command> accepts user-specified
start and end months with the <samp>--mth_srt</samp> and <samp>--mth_end</samp>
options, respectively.
Months are input as one-based integers so January <w>is 1</w> and
December is <w>is 12</w>.
To extract 14-month timeseries from individual monthly input files one
could use, e.g., 
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo --yr_srt=1 --yr_end=2 --mth_srt=4 --mth_end=5 ...
</pre></example>
<para>Note that <code>mth_srt</code> and <code>mth_end</code> only affect the splitter,
and that they play no role in climatology generation.
</para>
<html endspaces=" ">
&lt;a name=&quot;srt_yr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#srt_yr --&gt;
&lt;a name=&quot;yr_srt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#yr_srt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1898"><code>-s <var>srt_yr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1899"><var>srt_yr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1900"><code>--srt_yr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1901"><code>--start_year</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1902"><code>--year_start</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1903"><code>--start</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-s <var>srt_yr</var> (<code>--srt_yr</code>, <code>--yr_srt</code>, <code>--start_year</code>, <code>--year_start</code>, <code>--start</code>)</itemformat></item>
</tableterm><tableitem><para>Start year (example: 1980). 
By default, the first month used is January of the specified start year. 
If <samp>-a scd</samp> is specified, the first month used will be December
of the year before the start year (to allow for contiguous
<acronym><acronymword>DJF</acronymword></acronym> climos).
</para>
<html endspaces=" ">
&lt;a name=&quot;csn_lst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#csn_lst --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1904"><code>--seasons=<var>csn_lst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1905"><var>csn_lst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1906"><code>--seasons</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1907"><code>--csn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1908"><code>--csn_lst</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--seasons=<var>csn_lst</var> (<code>--seasons</code>, <code>--csn_lst</code>, <code>--csn</code>)</itemformat></item>
</tableterm><tableitem><para>Seasons for <command>ncclimo</command> to compute in monthly climatology
generation mode. 
The list of seasons, <var>csn_lst</var>, is a comma-separated,
case-insensitive, unordered subset of the abbreviations for the eleven
(so far) defined seasons: 
<code>jfm</code>, <code>amj</code>, <code>jas</code>, <code>ond</code>, <code>on</code>, <code>fm</code>,
<code>djf</code>, <code>mam</code>, <code>jja</code>, <code>son</code>, and <code>ann</code>.
By default <code><var>csn_lst</var>=mam,jja,son,djf</code>.
Moreover, <command>ncclimo</command> automatically computes the climatological
annual mean, <code>ANN</code>, is always computed when MAM, JJA, SON, and DJF
are all requested (which is the default).
The ANN computed automatically is the time-weighted average of the four
seasons, rather than as the time-weighted average of the twelve monthly
climatologies. 
Users who need ANN but not DJF, MAM, JJA, and SON should instead
explicitly specify ANN as a season in <var>csn_lst</var>.
The ANN computed as a season is the time-weighted average of the twelve
monthly climatologies, rather than the time-weighted average of four
seasonal climatologies. 
Specifying the four seasons and ANN in <var>csn_lst</var> (e.g.,
<code><var>csn_lst</var>=mam,jja,son,djf,ann</code>) is legal though redundant
and wasteful.
It cause ANN to be computed twice, first as the average of the twelve
monthly climatologies, then as the average of the four seasons.
The special value <code><var>csn_lst</var>=none</code> turns-off computation of
seasonal (and annual) climatologies. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo --seasons=none ...            # Produce only monthly climos
ncclimo --seasons=mam,jja,son,djf ... # Monthly + MAM,JJA,SON,DJF,ANN
ncclimo --seasons=jfm,jas,ann ...     # Monthly + JFM,JAS,ANN
ncclimo --seasons=fm,on ...           # Monthly + FM,ON
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;split&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#split --&gt;
&lt;a name=&quot;splitter&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#splitter --&gt;
&lt;a name=&quot;tms_flg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tms_flg --&gt;
&lt;a name=&quot;timeseries&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#timeseries --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1909"><code>--split</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1910"><code>--splitter</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1911"><code>--tms_flg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1912"><code>--timeseries</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--split (<code>--split</code>, <code>--splitter</code>, <code>--tms_flg</code>, <code>--timeseries</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) explicitly instructs
<command>ncclimo</command> to split the input multi-variable raw datasets into 
per-variable timeseries spanning the entire period.
The <code>--split</code> switch, and its synonyms <code>--splitter</code>,
<code>--tms_flg</code>, and <code>--timeseries</code>, were introduced in
<acronym><acronymword>NCO</acronymword></acronym> version 5.0.4 (released December, 2021).
Previously, the splitter was automatically invoked whenever the input
files were provided via <code>stdin</code>, globbing, or positional
command-line arguments, with some exceptions.
That older method became ambiguous and untenable once it was decided
to also allow climos to be generated from files provided via
<code>stdin</code>, globbing, or positional command-line arguments.
Now there are three methods to invoke the splitter:
<w>1) Use</w> the <samp>--split</samp> flag:
this is the most explicit way to invoke the splitter.
<w>2) Select</w> <samp>clm_md=hfs</samp>:
the high-frequency splitter mode by definition invokes the splitter,
so a more explicit option than this is not necessary.
<w>3) Set</w> the years-per-file option, e.g., <samp>--ypf=25</samp>:
the <code>ypf_max</code> option is only useful to the splitter, and has
thus been used in many scripts.
Since this option still causes the splitter to be invoked, those
will perform as before the <acronym><acronymword>API</acronymword></acronym> change.
</para>
<para>These three splitter invocations methods are non-exclusive, i.e., more
than one can be used, and there is no harm in doing so.
While the <acronym><acronymword>API</acronymword></acronym> change in version 5.0.4 does proscribe the
former practice of passively invoking the splitter by simply piping
files to <code>stdin</code> or similar, it enables much more flexibility
for future features, including the possibility of automatically
generating timeseries filenames for the splitter, and of piping
files to <code>stdin</code> or similar for climo generation.
</para>
<html endspaces=" ">
&lt;a name=&quot;no_stdin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_stdin --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1913">Chrysalis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1914">Common Workflow Language</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1915">Azure <acronym><acronymword>CI</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1916"><acronym><acronymword>SLURM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1917"><acronym><acronymword>CWL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1918"><code>--no_stdin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1919"><code>--no_inp_std</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1920"><code>--no_standard_input</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1921"><code>--no_redirect</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--no_stdin (<code>--no_stdin</code>, <code>--no_inp_std</code>, <code>--no_redirect</code>, <code>--no_standard_input</code>)</itemformat></item>
</tableterm><tableitem><para>First introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.8.0 (released May, 2019),
this switch (which takes no argument) disables checking standard input
(aka <code>stdin</code>) for input files. 
This is useful because <command>ncclimo</command> and <command>ncremap</command> may
mistakenly expect input to be provided on <code>stdin</code> in environments
that use <code>stdin</code> for other purposes. 
Some non-interactive environments (e.g., <command>crontab</command>,
<code>nohup</code>, Azure <acronym><acronymword>CI</acronymword></acronym>, <acronym><acronymword>CWL</acronymword></acronym>), may
use standard input for their own purposes, and thus confuse
<acronym><acronymword>NCO</acronymword></acronym> into thinking that you provided the input files names
via the <code>stdin</code> mechanism. 
In such cases users may disable the automatic checks for standard
input by explicitly invoking the <samp>--no_stdin</samp> flag.
This switch is usually not required for jobs in an interactive shell.
Interactive <acronym><acronymword>SLURM</acronymword></acronym> shells can also commandeer <code>stdin</code>,
as is the case on the <code>DOE</code> machine named Chrysalis.
This behavior appears to vary depending on the <acronym><acronymword>SLURM</acronymword></acronym>
implementation.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncclimo --no_stdin -v T -s 2000 -e 2001 --ypf=10 -i in -o out
</verbatim>
</example>

</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1922"><code>-t <var>thr_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1923"><var>thr_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1924"><code>--thr_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1925"><code>--thr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1926"><code>--threads</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1927"><code>--thread_number</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-t <var>thr_nbr</var> (<code>--thr_nbr</code>, <code>--thr</code>, <code>--thread_number</code>, <code>--threads</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the number of threads used per regridding process
(<pxref label="OpenMP-Threading"><xrefnodename>OpenMP Threading</xrefnodename></pxref>).
The <acronym><acronymword>NCO</acronymword></acronym> regridder scales well to 8&textndash;16 threads.
However, regridding with the maximum number of threads can interfere
with climatology generation in parallel climatology mode (i.e., when
<math><var>par_typ</var></math> = <code>mpi</code> or <code>bck</code>). 
Hence <command>ncclimo</command> defaults to <var>thr_nbr</var>=2.
</para>
<html endspaces=" ">
&lt;a name=&quot;tpd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tpd --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1928"><code>--tpd<var>tpd_out</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1929"><code>--tpd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1930"><code>--tpd_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1931"><code>--timesteps_per_day</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1932"><var>tpd</var></indexterm></cindex>
<item spaces=" "><itemformat command="option">--tpd=<var>tpd</var> (<code>--tpd_out</code>, <code>--tpd</code>, <code>--timesteps_per_day</code>)</itemformat></item>
</tableterm><tableitem><para>Normally, the number of timesteps-per-day in files ingested by
<command>ncclimo</command>.
It can sometimes be difficult for <command>ncclimo</command> to infer the
number of timesteps-per-day in high-frequency input files, i.e., those
with 1 or more timesteps-per-day.
In such cases, users may override the inferred value by explicitly
specifying <code>--tpd=<var>tpd</var></code>.
</para>
<para>The value of <var>tpd_out</var> in daily-average climatology mode
<code>clm_md=dly</code> (which is generally not used outside of ice-sheet
models) is different, and actually refers to the number of timesteps
per day that ncclimo will output, regardless of its value in the input
files.
Hence in daily-average mode (only), we refer to this variable as
<var>tpd_out</var>.
</para>
<para>The climatology output from input files at daily or sub-daily resolution
is, by default, averaged to daily resolution, i.e., <var>tpd_out</var>=1. 
If the number of timesteps per day in each input file is <var>tpd_in</var>,
then the user may select any value of <var>tpd_out</var> that is smaller 
than and integrally divides <var>tpd_in</var>.
For example, an input timeseries with <var>tpd_in</var>=8 (i.e., 3-hourly
resolution), can be used to produce climatological output at 3, 6,
or 12-hourly resolution by setting <var>tpd_out</var> to 8, 4, or 2,
respectively. 
This option only takes effect in daily-average climatology mode.
</para>
<para>For full generality, the <code>--tpd</code> option should probably be split
into separate options <code>--tpd_in</code> and <code>--tpd_out</code>.
However, because it is unlikely that anyone will need to specify these
to different values, we leave only one option.
If this hinders you, please let us know and we will split the options.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1933"><code>-v <var>var_lst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1934"><var>var_lst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1935"><code>--var_lst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1936"><code>--var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1937"><code>--vars</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1938"><code>--variables</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1939"><code>--variable_list</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-v <var>var_lst</var> (<code>--var_lst</code>, <code>--var</code>, <code>--vars</code>, <code>--variables</code>, <code>--variable_list</code>)</itemformat></item>
</tableterm><tableitem><para>Variables to subset or to split.
Same behavior as <ref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></ref>.
The use of <var>var_lst</var> is optional in clim-generation mode.
We suggest using this feature to test whether an <command>ncclimo</command>
command, especially one that is lengthy and/or time-consuming, works as
intended on one or a few variables with, e.g., <samp>-v T,FSNT</samp> before
generating the full climatology (by omitting this option). 
Invoking this switch was required in the original splitter released in 
version 4.6.5 (March, 2017), and became optional as of version 4.6.6
(May, 2017). 
This option is recommended in timeseries reshaping mode to prevent
inadvertently copying the results of an entire model simulation. 
Regular expressions are allowed so, e.g., <samp>PREC.?</samp> extracts
the variables <samp>PRECC,PRECL,PRECSC,PRECSL</samp> if present.
Currently in reshaping mode all matches to a regular expression are
placed in the same output file.
We hope to remove this limitation in the future.
</para>
<html endspaces=" ">
&lt;a name=&quot;var_xtr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#var_xtr --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1940"><var>var_xtr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1941"><code>--var_xtr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1942"><code>--var_extra</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1943"><code>--extra_variables</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1944"><code>--variables_extra</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--var_xtr=<var>var_xtr</var> (<code>--var_xtr</code>, <code>--var_xtr</code>, <code>--var_extra</code>, <code>--variables_extra</code>, <code>--extra_variables</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>--var_xtr</samp> option causes <command>ncclimo</command> to include the extra
variables list in <var>var_xtr</var> in every timeseries split from the raw
data. 
This is useful when extra variables are desired in timeseries.
There are no limits on the extra variables&textmdash;they may be of any rank
and may be timeseries themselves.
One useful application of this option, is to ensure that the area
variable is included with each timeseries, e.g.,
<samp>--var_xtr=area</samp>. 
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1945"><code>--version</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1946"><code>--vrs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1947"><code>--config</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1948"><code>--configuration</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1949"><code>--cnf</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--version (<code>--version</code>, <code>--vrs</code>, <code>--config</code>, <code>--configuration</code>, <code>--cnf</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) causes the operator to print
its version and configuration.
This includes the copyright notice, <acronym><acronymword>URL</acronymword></acronym>s to the <acronym><acronymword>BSD</acronymword></acronym>
and <acronym><acronymword>NCO</acronymword></acronym> license, directories from which the <acronym><acronymword>NCO</acronymword></acronym>
scripts and binaries are running, and the locations of any separate 
executables that may be used by the script.
</para>
<html endspaces=" ">
&lt;a name=&quot;xcl_var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xcl_var --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1950"><code>--xcl_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1951"><code>--xcl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1952"><code>--exclude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1953"><code>--exclude_variables</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--xcl_var (<code>--xcl_var</code>, <code>--xcl</code>, <code>--exclude</code>, <code>--exclude_variables</code>)</itemformat></item>
</tableterm><tableitem><para>This flag (which takes no argument) changes <var>var_lst</var>,
as set by the <code>--var_lst</code> option, from an extraction list to an
exclusion list so that variables in <var>var_lst</var> will not be
processed, and variables not in <var>var_lst</var> will be processed.
Thus the option <samp>-v <var>var_lst</var></samp> must also be present for this
flag to take effect.
Variables explicitly specified for exclusion by
<samp>--xcl --vars=<var>var_lst</var>[,&dots;]</samp> need not be present in the
input file.
Previously, this switch has always woked in climo mode.
As of <acronym><acronymword>NCO</acronymword></acronym> version 5.2.5 (July, 2024), this switch also works
in timeseries mode.
</para>
<html endspaces=" ">
&lt;a name=&quot;ypf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ypf --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1954"><code>--ypf_max <var>ypf_max</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1955"><var>ypf_max</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1956"><code>--ypf_max</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">--ypf_max <var>ypf_max</var> (<code>--ypf</code>, <code>--years</code>, <code>--years_per_file</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the maximum number of years-per-file output by
<command>ncclimo</command>&textrsquo;s splitting operation.  
When <command>ncclimo</command> subsets and splits a collection of input files
spanning a timerseries, it places each subset variable in its own output
file. 
The maximum length, in years, of each output file is <var>ypf_max</var>,
which defaults to <var>ypf_max</var>=50.
If an input timeseries spans <w>237 years</w> and <var>ypf_max</var>=50, then
<command>ncclimo</command> will generate four output files of length <w>50 years</w>  
and one output file of length <w>37 years</w>.
Note that invoking this option <emph>causes</emph> <command>ncclimo</command> to enter
timeseries reshaping mode.
In fact, one <emph>must</emph> use <samp>--ypf</samp> to turn-on splitter mode when
the input files are specified by using the <samp>-i drc_in</samp> method.
Otherwise it would be ambiguous whether to generate a climatology from 
or to split the input files. 
</para></tableitem></tableentry></table>
<noindent></noindent>

<unnumberedsubsec spaces=" "><sectiontitle>Timeseries Reshaping mode, aka Splitting</sectiontitle>
<para>This section of the <command>ncclimo</command> documentation applies only to
resphaping mode, whereas all subsequent sections apply to climatology
generation mode. 
In splitter mode, <command>ncclimo</command> <emph>reshapes</emph> the input so that
the outputs are continuous timeseries of each variable taken from all
input files.  
As of <acronym><acronymword>NCO</acronymword></acronym> version 5.0.4 (released December, 2021), 
<command>ncclimo</command> enters splitter mode when invoked with the
<code>--split</code> switch (or its synonyms <code>--splitter</code>, 
<code>--tms_flg</code>, or <code>--timeseries</code>) or with the <code>--ypf_max</code> 
option. 
Then <command>ncclimo</command> will create per-variable timeseries from the
list of files supplied via <code>stdin</code>, or, alternatively,
placed as positional arguments (after the last command-line option), or
if neither of these is done and no <var>caseid</var> is specified, in which
case it assumes all <code>*.nc</code> files in <var>drc_in</var> constitute the
input file list. 
These examples invoke reshaping mode in the four possible ways:
</para><example endspaces=" ">
<pre xml:space="preserve"># Pipe list to stdin
cd $drc_in;ls *mdl*000[1-9]*.nc | ncclimo --split -v T,Q,RH -s 1 -e 9 -o $drc_out
# Redirect list from file to stdin
cd $drc_in;ls *mdl*000[1-9]*.nc &gt; foo;ncclimo --split -v T,Q,RH -s 1 -e 9 -o $drc_out &lt; foo
# List as positional arguments
ncclimo --split -v T,Q,RH -s 1 -e 9 -o $drc_out $drc_in/*mdl*000[1-9]*.nc
# Glob directory
ncclimo --split -v T,Q,RH -s 1 -e 9 -i $drc_in -o $drc_out
</pre></example>
<para>Assuming each input file is a monthly average comprising the variables
<var>T</var>, <var>Q</var>, and <var>RH</var>, then the output will be files
<file>T_000101_000912.nc</file>, 
<file>Q_000101_000912.nc</file>, and
<file>RH_000101_000912.nc</file>. 
When necessary, the output is split into segments each containing no
more than <var>ypf_max</var> (default 50) years of input, i.e., 
<file>T_000101_005012.nc</file>, <file>T_005101_009912.nc</file>,
<file>T_010001_014912.nc</file>, etc.
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle><acronym><acronymword>MPAS-O/SI/LI</acronymword></acronym> considerations</sectiontitle>
<para><acronym><acronymword>MPAS</acronymword></acronym> ocean and ice models currently have their own
(non-CESM&textrsquo;ish) naming convention that guarantees output files have the
same names for all simulations. 
By default <command>ncclimo</command> analyzes the &textldquo;timeSeriesStatsMonthly&textrdquo;
analysis member output (tell us if you want options for other analysis
members). 
<command>ncclimo</command> and <command>ncremap</command> recognize input files as being 
<acronym><acronymword>MPAS</acronymword></acronym>-style when invoked with <samp>-P mpas</samp> or with the
more expressive synonym  <samp>--prc_typ=mpas</samp>.
The the generic <samp>-P mpas</samp> invocation works for generating
climatologies for any <acronym><acronymword>MPAS</acronymword></acronym> model.
However, some regridder options are model-specific and therefore it is  
smarter to specify which <acronym><acronymword>MPAS</acronymword></acronym> model produced the input
data with 
<samp>-P mpasatmosphere</samp>, (or <samp>-P mpasa</samp> for short),
<samp>-P mpasocean</samp>, (or <samp>-P mpaso</samp> for short),
<samp>-P mpasseaice</samp>, (or <samp>-P mpassi</samp> for short), or
<samp>-P mali</samp>, like this: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncclimo -P mpasa  -c $case -s 1980 -e 1983 -i $drc_in -o $drc_out # MPAS-A
ncclimo -P mpaso  -c $case -s 1980 -e 1983 -i $drc_in -o $drc_out # MPAS-O
ncclimo -P mpassi -c $case -s 1980 -e 1983 -i $drc_in -o $drc_out # MPAS-SI
ncclimo -P mali   -c $case -s 1980 -e 1983 -i $drc_in -o $drc_out # MPAS-LI
</verbatim>
</example>
<para>As of June 2024 and <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.2.5</w>, <command>ncclimo</command>
updated its <acronym><acronymword>MPAS</acronymword></acronym> dataset filename construction option. 
Previously it constructed <acronym><acronymword>MPAS</acronymword></acronym> monthly datasets names like this:
<file>$mdl_nm.hist.am.timeSeriesStatsMonthly.$YYYY-$MM-01.nc</file>.
where <var>mdl_nm</var> is the canonical <acronym><acronymword>MPAS</acronymword></acronym> component name,
e.g., <code>mpaso</code>.
This yielded names consistent with <acronym><acronymword>E3SM</acronymword></acronym> v1 output like
<file>mpaso.hist.am.timeSeriesStatsMonthly.0001-02-01.nc</file>, and
<file>mpascice.hist.am.timeSeriesStatsMonthly.0001-02-01.nc</file>. 
Now <command>ncclimo</command> prepends the <var>caseid</var>, if present, to the
filename. 
This yields names consistent with <acronym><acronymword>E3SM</acronymword></acronym> v2 and v3 output like
<file>v2.LR.historical_0101.mpaso.hist.am.timeSeriesStatsMonthly.0001-02-01.nc</file>, and
<file>v2.LR.historical_0101.mpassi.hist.am.timeSeriesStatsMonthly.0001-02-01.nc</file>. 
To read <acronym><acronymword>MPAS</acronymword></acronym> filenames with other patterns, simply pipe the 
filenames to <command>ncclimo</command>: <samp>ls *mpas*hist | ncclimo ...</samp>.
</para>
<para>Raw output data from all <acronym><acronymword>MPAS</acronymword></acronym> models does not contain
missing value attributes <footnote spaces="\n"><para>We submitted pull-requests to implement the <code>_FillValue</code>
attribute in all <acronym><acronymword>MPAS</acronymword></acronym>-ocean output in July, 2020.
The status of this <acronym><acronymword>PR</acronymword></acronym> may be tracked at
<url><urefurl>https://github.com/MPAS-Dev/MPAS-Model/pull/677</urefurl></url>.
Once this <acronym><acronymword>PR</acronymword></acronym> is merged to master, we will do the same
for the <acronym><acronymword>MPAS</acronymword></acronym>-Seaice and <acronym><acronymword>MPAS</acronymword></acronym>-Landice models.</para></footnote>.
These attributes must be manually added before sending the data as
input to <command>ncclimo</command> or <command>ncremap</command>.
We recommend that simulation producers annotate all floating point
variables with the appropriate <code>_FillValue</code> prior to invoking
<command>ncclimo</command>. 
Run something like this once in the history-file directory: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for fl in `ls hist.*` ; do
  ncatted -O -t -a _FillValue,,o,d,-9.99999979021476795361e+33 ${fl}
done
</verbatim>
</example>
<para>If/when <acronym><acronymword>MPAS-O/I</acronymword></acronym> generates the <code>_FillValue</code> attributes
itself, this step can and should be skipped. 
All other <command>ncclimo</command> features like regridding (below) are invoked 
identically for <acronym><acronymword>MPAS</acronymword></acronym> as for <acronym><acronymword>CAM</acronymword></acronym>/<acronym><acronymword>CLM</acronymword></acronym> users
although under-the-hood <command>ncclimo</command> does do some special
pre-processing (dimension permutation, metadata annotation) for
<acronym><acronymword>MPAS</acronymword></acronym>.  
A five-year oEC60to30 <acronym><acronymword>MPAS-O</acronymword></acronym> climo with regridding to T62
takes less than <w>10 minutes</w> on the machine <file>rhea</file>. 
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Annual climos</sectiontitle>
<para>Not all model or observed history files are created as monthly means. 
To create a climatological annual mean from a series of annual mean
inputs, select <command>ncclimo</command>&textrsquo;s annual climatology mode with 
the <samp>-C ann</samp> option:  
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncclimo -C ann -m cism -h h -c caseid -s 1851 -e 1900 -i drc_in -o drc_out
</verbatim>
</example>
<para>The options <samp>-m mdl_nm</samp> and <samp>-h hst_nm</samp> (that default to 
<code>cam</code> and <code>h0</code>, respectively) tell <command>ncclimo</command> how to
construct the input filenames. 
The above formula names the files
<code>caseid.cism.h.1851-01-01-00000.nc</code>,
<code>caseid.cism.h.1852-01-01-00000.nc</code>, 
and so on. 
Annual climatology mode produces a single output file (or two if
regridding is selected), and in all other respects behaves the same as
monthly climatology mode.  
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Regridding Climos and Other Files</sectiontitle>
<para><command>ncclimo</command> will (optionally) regrid during climatology generation 
and produce climatology files on both native and analysis grids. 
This regridding is virtually free, because it is performed on idle
nodes/cores after monthly climatologies have been computed and while
seasonal climatologies are being computed.  
This load-balancing can save half-an-hour on ne120 datasets. 
To regrid, simply pass the desired mapfile name with <samp>-r map.nc</samp>,
e.g., <samp>-r maps/map_ne120np4_to_fv257x512_aave.20150901.nc</samp>. 
Although this should not be necessary for normal use, you may pass any
options specific to regridding with <samp>-R opt1 opt2</samp>.
</para>
<para>Specifying <samp>-O <var>drc_rgr</var></samp> (NB: uppercase <samp>O</samp>) causes
<command>ncclimo</command> to place the regridded files in the directory
<var>drc_rgr</var>.  
These files have the same names as the native grid climos from which
they were derived. 
There is no namespace conflict because they are in separate
directories. 
These files also have symbolic links to their <acronym><acronymword>AMWG</acronymword></acronym> filenames. 
If <samp>-O <var>drc_rgr</var></samp> is not specified, <command>ncclimo</command> places 
all regridded files in the native grid climo output directory,
<var>drc_out</var>, specified by <samp>-o <var>drc_out</var></samp> (NB: lowercase 
<samp>o</samp>). 
To avoid namespace conflicts when both climos are stored in the same
directory, the names of regridded files are suffixed by the destination
geometry string obtained from the mapfile, e.g., 
<file>*_climo_fv257x512_bilin.nc</file>. 
These files also have symbolic links to their <acronym><acronymword>AMWG</acronymword></acronym> filenames. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo -c amip_xpt -s 1980 -e 1983 -i drc_in -o drc_out
ncclimo -c amip_xpt -s 1980 -e 1983 -i drc_in -o drc_out -r map_fl
ncclimo -c amip_xpt -s 1980 -e 1983 -i drc_in -o drc_out -r map_fl -O drc_rgr
</pre></example>
<noindent></noindent>
<para>The above commands perform a climatology without regridding, then with
regridding (all climos stored in <var>drc_out</var>), then with regridding and
storing regridded files separately. 
Paths specified by <var>drc_in</var>, <var>drc_out</var>, and <var>drc_rgr</var> may be
relative or absolute.  
An alternative to regridding during climatology generation is to regrid
afterwards with <command>ncremap</command>, which has more special features
built-in for regridding. 
To use <command>ncremap</command> to regrid a climatology in <var>drc_out</var> and
place the results in <var>drc_rgr</var>, use something like
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -I drc_out -m map.nc -O drc_rgr
ls drc_out/*climo* | ncremap -m map.nc -O drc_rgr
</pre></example>
<para>See <ref label="ncremap-netCDF-Remapper"><xrefnodename>ncremap netCDF Remapper</xrefnodename></ref> for more details (including
<acronym><acronymword>MPAS</acronymword></acronym>!).  
</para> 
<html endspaces=" ">
&lt;a name=&quot;yr_end_prv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#yr_end_prv --&gt;
&lt;a name=&quot;yr_srt_prv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#yr_srt_prv --&gt;
&lt;a name=&quot;drc_xtn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drc_xtn --&gt;
&lt;a name=&quot;drc_prv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drc_prv --&gt;
&lt;a name=&quot;drc_rgr_xtn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drc_rgr_xtn --&gt;
&lt;a name=&quot;drc_rgr_prv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#drc_rgr_prv --&gt;
&lt;a name=&quot;clm_bnr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm_bnr --&gt;
&lt;a name=&quot;clm_xtn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm_xtn --&gt;
</html>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Extended Climatologies</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1957">incremental climatology (climo)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1958">binary climatology (climo)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1959">extended climatology (climo)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1960">previous climatology (climo)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1961">current climatology (climo)</indexterm></cindex>
<para><command>ncclimo</command> supports two methods for generating extended
climatologies: Binary and Incremental.
Both methods lengthen a climatology without requiring access to 
all the raw monthly data spanning the time period.
The binary method combines, with appropriate weighting, two previously
computed climatologies into a single climatology. 
No raw monthly data are employed.
The incremental method computes a climatology from raw monthly data
and (with appropriate weighting) combines that with a previously
computed climatology that ends the month prior to raw data.
The incremental method was introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.6.1
(released August, 2016), and the binary method was introduced in
<acronym><acronymword>NCO</acronymword></acronym> version 4.6.3 (released December, 2016).
</para>
<!-- c fxm edit to distinguish extended from binary -->
<para>Both methods, binary and incremental, compute the so-called &textldquo;extended
climo&textrdquo; as a weighted mean of two shorter climatologies,
called the &textldquo;previous&textrdquo; and &textldquo;current&textrdquo; climos.
The incremental method uses the original monthly input to compute the
curent climo, which must immediately follow in time the previous climo 
which has been pre-computed.
The binary method use pre-computed climos for both the previous and
current climos, and these climos need not be sequential nor
chronological. 
Both previous and current climos for both binary and incremental methods
may be of any length (in years); their weights will be automatically
adjusted in computing the extended climo.
</para>
<para>The use of pre-computed climos permits ongoing simulations (or lengthy
observations) to be analyzed in shorter segments combined piecemeal,
instead of requiring all raw, native-grid data to be simultaneously
accessible.
Without extended climatology capability, generating a one-hundred
year climatology requires that one-hundred years of monthly data be
available on disk. 
Disk-space requirements for large datasets may make this untenable.
Extended climo methods permits a one-hundred year climo to be
generated as the weighted mean of, say, the current ten year climatology
(weighted at 10%) combined with the pre-computed climatology of the
previous 90-years (weighted at 90%).
The 90-year climo could itself have been generated incrementally or
binary-wise, and so on. 
Climatologies occupy at most 17/(12<var>N</var>) the amount of space
of <var>N</var> years of monthly data, so the extended methods vastly
reduce disk-space requirements. 
</para>
<para>Incremental mode is selected by specifying <samp>-S</samp>, the start year
of the pre-computed, previous climo.
The argument to <samp>-S</samp>) is the previous climo start year.
That, together with the current climo end year, determines the extended
climo range.
<command>ncclimo</command> assumes that the previous climo ends the month before
the current climo begins.
In incremental mode, <command>ncclimo</command> first generates the current
climatology from the current monthly input files then weights  
that current climo with the previous climo to produce the extended
climo.
</para>
<para>Binary mode is selected by specifying both <samp>-S</samp> and <samp>-E</samp>, the 
end year of the pre-computed, previous climo.
In binary mode, the previous and current climatologies can be of any
length, and from any time-period, even overlapping.
Most users will run extended clmos the same way they run regular climos
in terms of parallelism and regridding, although that is not required.  
Both climos must treat Decembers same way (or else previous climo files
will not be found), and if subsetting (i.e., <samp>-v var_lst</samp>) is
performed, then the subset must remain the same, and if nicknames (i.e.,
<samp>-f fml_nm</samp>) are employed, then the nickname must remain the same. 
</para>
<para>As of 20161129, the <code>climatology_bounds</code> attributes of extended
climos are incorrect. 
This is a work in progress...
</para>
<para>Options:
</para><table commandarg="option" spaces=" " endspaces=" ">
<tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1962"><code>-E <var>yr_end_prv</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1963"><var>yr_end_prv</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1964"><code>--yr_end_prv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1965"><code>--prv_yr_end</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1966"><code>--previous_end</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-E <var>yr_end_prv</var> (<code>--yr_end_prv</code>, <code>--prv_yr_end</code>, <code>--previous_end</code>)</itemformat></item>
</tableterm><tableitem><para>The ending year of the previous climo. 
This argument is required to trigger binary climatologies,
and should not be used for incremental climatologies.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1967"><code>-S <var>yr_srt_prv</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1968"><var>yr_srt_prv</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1969"><code>--yr_srt_prv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1970"><code>--prv_yr_srt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1971"><code>--previous_start</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-S <var>yr_srt_prv</var> (<code>--yr_srt_prv</code>, <code>--prv_yr_srt</code>, <code>--previous_start</code>)</itemformat></item>
</tableterm><tableitem><para>The starting year of the previous climo. 
This argument is required to trigger incremental climatologies,
and is also mandatory for binary climatologies.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1972"><code>-X <var>drc_xtn</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1973"><var>drc_xtn</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1974"><code>--drc_xtn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1975"><code>--xtn_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1976"><code>--extended</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-X <var>drc_xtn</var> (<code>--drc_xtn</code>, <code>--xtn_drc</code>, <code>--extended</code>)</itemformat></item>
</tableterm><tableitem><para>Directory in which the extended native grid climo files will be stored
for an extended climatology.
Default value is <var>drc_prv</var>. 
Unless a separate directory is specified (with <samp>-Y</samp>) for the
extended climo on the analysis grid, it will be stored in <var>drc_xtn</var>,
too.  
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1977"><code>-x <var>drc_prv</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1978"><var>drc_prv</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1979"><code>--drc_prv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1980"><code>--prv_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1981"><code>--previous</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-x <var>drc_prv</var> (<code>--drc_prv</code>, <code>--prv_drc</code>, <code>--previous</code>)</itemformat></item>
</tableterm><tableitem><para>Directory in which the previous native grid climo files reside for an
incremental climatology. 
Default value is <var>drc_out</var>. 
Unless a separate directory is specified (with <samp>-y</samp>) for the
previous climo on the analysis grid, it is assumed to reside in
<var>drc_prv</var>, too. 
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1982"><code>-Y <var>drc_rgr_xtn</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1983"><var>drc_rgr_xtn</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1984"><code>--drc_rgr_xtn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1985"><code>--drc_xtn_rgr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1986"><code>--extended_regridded</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1987"><code>--regridded_extended</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-Y <var>drc_rgr_xtn</var> (<code>--drc_rgr_xtn</code>, <code>--drc_xtn_rgr</code>, <code>--extended_regridded</code>, <code>--regridded_extended</code>)</itemformat></item>
</tableterm><tableitem><para>Directory in which the extended analysis grid climo files will be
stored in an incremental climatology. 
Default value is <var>drc_xtn</var>.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="1988"><code>-y <var>drc_rgr_prv</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1989"><var>drc_rgr_prv</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1990"><code>--drc_rgr_prv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1991"><code>--drc_prv_rgr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1992"><code>--regridded_previous</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1993"><code>--previous_regridded</code></indexterm></cindex>
<item spaces=" "><itemformat command="option">-y <var>drc_rgr_prv</var> (<code>--drc_rgr_prv</code>, <code>--drc_prv_rgr</code>, <code>--regridded_previous</code>, <code>--previous_regridded</code>)</itemformat></item>
</tableterm><tableitem><para>Directory in which the previous climo on the analysis grid resides in an
incremental climatology. 
Default value is <var>drc_prv</var>.
</para></tableitem></tableentry></table>
<noindent></noindent>

<para>Incremental method climatologies can be as simple as providing a start
year for the previous climo, e.g., 
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo -v FSNT,AODVIS -c caseid -s 1980 -e 1981 -i raw -o clm -r map.nc
ncclimo -v FSNT,AODVIS -c caseid -s 1982 -e 1983 -i raw -o clm -r map.nc -S 1980
</pre></example>
<para>By default <command>ncclimo</command> stores all native and analysis grid climos
in one directory so the above &textldquo;just works&textrdquo;.
There are no namespace clashes because all climos are for distinct
years, and regridded files have a suffix based on their grid resolution.  
However, there can be only one set of <acronym><acronymword>AMWG</acronymword></acronym> filename links
due to <acronym><acronymword>AMWG</acronymword></acronym> filename convention.
Thus <acronym><acronymword>AMWG</acronymword></acronym> filename links, if any, point to the latest extended 
climo in a given directory. 
</para>
<para>Many researchers segregate (with <samp>-O <var>drc_rgr</var></samp>) native-grid
from analysis-grid climos. 
Incrementally generated climos must be consistent in this regard.
In other words, all climos contributing to an extended climo must have
their native-grid and analysis-grid files in the same (per-climo)
directory, or all climos must segregate their native from their analysis
grid files.
Do not segregate the grids in one climo, and combine them in another.
Such climos cannot be incrementally aggregated.
Thus incrementing climos can require from zero to four additional
options that specify all the previous and extended climatologies for
both native and analysis grids.
The example below constructs the current climo in <var>crr</var>,
then combines the weighted average of that with the previous climo in
<var>prv</var>, and places the resulting extended climatology in <var>xtn</var>.
Here the native and analysis climos are combined in one directory per 
climo:
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo -v FSNT,AODVIS -c caseid -s 1980 -e 1981 -i raw -o prv -r map.nc
ncclimo -v FSNT,AODVIS -c caseid -s 1982 -e 1983 -i raw -o clm -r map.nc \
        -S 1980 -x prv -X xtn
</pre></example>
<para>If the native and analysis grid climo directories are segregated, 
then those directories must be specified, too:
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo -v FSNT,AODVIS -c caseid -s 1980 -e 1981 -i raw -o prv -O rgr_prv -r map.nc
ncclimo -v FSNT,AODVIS -c caseid -s 1982 -e 1983 -i raw -o clm -O rgr -r map.nc \
        -S 1980 -x prv -X xtn -y rgr_prv -Y rgr_xtn
</pre></example>

<para><command>ncclimo</command> does not know whether a pre-computed climo is on a
native grid or an analysis grid, i.e., whether it has been regridded.
In binary mode, <command>ncclimo</command> may be pointed to two pre-computed
native grid climatologies, or to two pre-computed analysis grid
climatologies.
In other words, it is not necessary to maintain native grid
climatologies for use in creating extended climatologies.
It is sufficient to generate climatologies on the analysis grid, and
feed them to <command>ncclimo</command> in binary mode, without a mapping file:
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo -c caseid -S 1980 -E 1981 -x prv -s 1980 -e 1981 -i crr -o clm 
</pre></example>

</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Coupled Runs</sectiontitle>
<para><command>ncclimo</command> works on all <acronym><acronymword>E3SM/ACME</acronymword></acronym> and <acronym><acronymword>CESM</acronymword></acronym> models. 
It can simultaneously generate climatologies for a coupled run, where
climatologies mean both native and regridded monthly, seasonal, and
annual averages as per <acronym><acronymword>E3SM/ACME</acronymword></acronym> specifications (which mandate
the inclusion of certain helpful metadata and provenance information).
Here are template commands for a recent simulation:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
caseid=20160121.A_B2000ATMMOD.ne30_oEC.titan.a00
drc_in=/scratch/simulations/$caseid/run
drc_out=${DATA}/acme
map_atm=${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc
map_lnd=$map_atm
map_ocn=${DATA}/maps/map_oEC60to30_to_t62_bilin.20160301.nc
map_ice=$map_ocn
ncclimo -p mpi -c $caseid -m cam  -s 2 -e 5 -i $drc_in -r $map_atm -o $drc_out/atm
ncclimo        -c $caseid -m clm2 -s 2 -e 5 -i $drc_in -r $map_lnd -o $drc_out/lnd
ncclimo -p mpi -m mpaso           -s 2 -e 5 -i $drc_in -r $map_ocn -o $drc_out/ocn 
ncclimo        -m mpassi          -s 2 -e 5 -i $drc_in -r $map_ice -o $drc_out/ice
</verbatim>
</example>
<para>Atmosphere and ocean model output is typically larger than land and ice
model output.  
These commands recognize that by using different parallelization
strategies that may (<file>rhea</file> standard queue) or may not
(<file>cooley</file>, or <file>rhea</file>&textrsquo;s <code>bigmem</code> queue) be required,
depending on the fatness of the analysis nodes, as explained below. 
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Memory Considerations</sectiontitle>
<para>It is important to employ the optimal <command>ncclimo</command> parallelization
strategy for your computer hardware resources. 
Select from the three available choices with the 
<option>-p <var>par_typ</var></option> switch.
The options are serial mode (<samp>-p srl</samp>, <samp>-p serial</samp>, or <samp>-p nil</samp>), 
background mode parallelism (<samp>-p bck</samp>, or <samp>-p background</samp>),
and <acronym><acronymword>MPI</acronymword></acronym> parallelism (<samp>-p mpi</samp> or <samp>-p MPI</samp>).
The default is background-mode parallelism.
This is appropriate for lower resolution (e.g., ne30L30) simulations on
most nodes at high-performance computer centers. 
Use (or at least start with) serial mode on personal
laptops/workstations.   
Serial mode requires twelve times less <acronym><acronymword>RAM</acronymword></acronym> than the parallel
modes, and is much less likely to deadlock or cause <acronym><acronymword>OOM</acronymword></acronym>
(out-of-memory) conditions on your personal computer. 
If the available <acronym><acronymword>RAM</acronymword></acronym> (plus swap) is 
<math>&lt; 12*4*</math><code>sizeof(</code>monthly input file<code>)</code>, then try serial
mode first (12 is the optimal number of parallel processes for monthly
climos, the computational overhead is a factor of four). 
<acronym><acronymword>EAM-SE</acronymword></acronym> ne30L30 output is about <w>1 GB/month</w> so each month
requires about <w>4 GB</w> of <acronym><acronymword>RAM</acronymword></acronym>. 
<acronym><acronymword>EAM-SE</acronymword></acronym> ne30L72 output (with <acronym><acronymword>LINOZ</acronymword></acronym>) is about 
<w>10 GB/month</w> so each month requires about <w>40 GB</w> <acronym><acronymword>RAM</acronymword></acronym>. 
<acronym><acronymword>EAM-SE</acronymword></acronym> ne120 output is about <w>12 GB/month</w> so each month
requires about <w>48 GB</w> <acronym><acronymword>RAM</acronymword></acronym>. 
The computer does not actually use all this memory at one time, and many
kernels compress <acronym><acronymword>RAM</acronymword></acronym> usage to below what top reports, so the
actual physical usage is hard to pin-down, but may be a factor of
2.5&textndash;3.0 (rather than a factor of four) times the size of the input
file. 
For instance, my <w>16 GB</w> 2014 MacBookPro successfully runs an ne30L30 
climatology (that requests <w>48 GB</w> <acronym><acronymword>RAM</acronymword></acronym>) in background mode. 
However the laptop is slow and unresponsive for other uses until it
finishes (in 6&textndash;8 minutes) the climos. 
Experiment and choose the parallelization option that performs best.
</para>
<para>Serial-mode, as its name implies, uses one core at a time for climos,
and proceeds sequentially from months to seasons to annual
climatologies. 
Serial mode means that climos are performed serially, while regridding
still employs OpenMP threading (up to <w>16 cores</w>) on platforms that
support it. 
By design each month and each season is independent of the others, so
all months can be computed in parallel, then each season can be computed
in parallel (using monthly climatologies), from which annual average is
computed. 
Background parallelization mode exploits this parallelism and executes
the climos in parallel as background processes on a single node, so that
twelve cores are simultaneously employed for monthly climatologies, four
for seasonal, and one for annual. 
The optional regridding will employ, by default, up to two cores per
process. 
The <acronym><acronymword>MPI</acronymword></acronym> parallelism mode executes the climatologies on
different nodes so that up to (optimally) twelve nodes compute monthly 
climos. 
The full memory of each node is available for each individual climo. 
The optional regridding employs, by default, up to eight cores per node
in <acronym><acronymword>MPI</acronymword></acronym>-mode.
<acronym><acronymword>MPI</acronymword></acronym>-mode or serial-mode must be used to process ne30L72 and
ne120L30 climos on all but the fattest <acronym><acronymword>DOE</acronymword></acronym> nodes. 
An ne120L30 climo in background mode on <file>rhea</file> (i.e., on one <w>128
GB</w> compute node) fails due to <acronym><acronymword>OOM</acronymword></acronym>. 
(Unfortunately <acronym><acronymword>OOM</acronymword></acronym> errors do not produce useful return codes
so if your climo processes die without printing useful information, the
cause may be <acronym><acronymword>OOM</acronymword></acronym>). 
However the same climo in background-mode succeeds when executed on a
single big-memory (<w>1 TB</w>) node on <file>rhea</file> (use
<samp>-lpartition=gpu</samp>, as shown below). 
Or <acronym><acronymword>MPI</acronymword></acronym>-mode can be used for any climatology. 
The same ne120L30 climo will also finish blazingly fast in background
mode on <file>cooley</file> (i.e., on one <w>384 GB</w> compute node), so
<acronym><acronymword>MPI</acronymword></acronym>-mode is unnecessary on <file>cooley</file>. 
In general, the fatter the memory, the better the performance.  
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Single, Dedicated Nodes at <acronym><acronymword>LCF</acronymword></acronym>s</sectiontitle>
<para>The basic approach above (running the script from a standard terminal
window) that works well for small cases can be unpleasantly slow on
login nodes of <acronym><acronymword>LCF</acronymword></acronym>s and for longer or higher resolution (e.g.,
ne120) climatologies. 
As a baseline, generating a climatology of <w>5 years</w> of ne30 (~1x1
degree) <acronym><acronymword>EAM-SE</acronymword></acronym> output with <command>ncclimo</command> takes 1&textndash;2
minutes on <file>rhea</file> (at a time with little contention), and 6&textndash;8
minutes on a 2014 MacBook Pro. 
To make things a bit faster at <acronym><acronymword>LCF</acronymword></acronym>s, request a dedicated node
(this only makes sense on supercomputers or clusters with
job-schedulers).  
On <file>rhea</file> or <file>titan</file>, which use the <acronym><acronymword>PBS</acronymword></acronym> scheduler,
do this with 
</para><example endspaces=" ">
<pre xml:space="preserve"># Standard node (128 GB), PBS scheduler
qsub -I -A CLI115 -V -l nodes=1 -l walltime=00:10:00 -N ncclimo
# Bigmem node (1 TB), PBS scheduler
qsub -I -A CLI115 -V -l nodes=1 -l walltime=00:10:00 -lpartition=gpu -N ncclimo
</pre></example>
<para>The equivalent requests on <file>cooley</file> or <file>mira</file> (Cobalt
scheduler) and <file>cori</file> or <file>titan</file> (<acronym><acronymword>SLURM</acronymword></acronym> scheduler)
are:  
</para><example endspaces=" ">
<pre xml:space="preserve"># Cooley node (384 GB) with Cobalt
qsub -I -A HiRes_EarthSys --nodecount=1 --time=00:10:00 --jobname=ncclimo 
# Cori node (128 GB) with SLURM
salloc  -A acme --nodes=1 --partition=debug --time=00:10:00 --job-name=ncclimo
</pre></example>
<noindent></noindent>
<para>Flags used and their meanings:
</para><table commandarg="option" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="option">-I </itemformat></item>
</tableterm><tableitem><para>Submit in interactive mode. 
This returns a new terminal shell rather than running a program. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--time</itemformat></item>
</tableterm><tableitem><para>How long to keep this dedicated node for. 
Unless you kill the shell created by the <command>qsub</command> command, the
shell will exist for this amount of time, then die suddenly. 
In the above examples, <w>10 minutes</w> is requested. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">-l nodes=1 </itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>PBS</acronymword></acronym> syntax (e.g., on <file>rhea</file>) for nodes.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--nodecount 1 </itemformat></item>
</tableterm><tableitem><para>Cobalt syntax (e.g., on <file>cooley</file>) for nodes.
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">--nodes=1</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>SLURM</acronymword></acronym> syntax (e.g., on <file>cori</file> or <file>edison</file>) for nodes.
These scheduler-dependent variations request a quantity of nodes. 
Request <w>1 node</w> for Serial or Background-mode, and up to <w>12 nodes</w> 
for <acronym><acronymword>MPI</acronymword></acronym>-mode parallelism.
In all cases <command>ncclimo</command> will use multiple cores per node if
available. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">-V</itemformat></item>
</tableterm><tableitem><para>Export existing environmental variables into the new interactive shell.
This may not actually be needed.  
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">-q name</itemformat></item>
</tableterm><tableitem><para>Queue name.
This is needed for locations like <file>edison</file> that have multiple
queues with no default queue. 
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="option">-A </itemformat></item>
</tableterm><tableitem><para>Name of account to charge for time used. 
</para></tableitem></tableentry></table>
<para>Acquiring a dedicated node is useful for any workflow, not just creating climos.
This command returns a prompt once nodes are assigned (the prompt is
returned in your home directory so you may then have to <command>cd</command> to
the location you meant to run from). 
Then run your code with the basic <command>ncclimo</command> invocation.
The is faster because the node is exclusively dedicated to <command>ncclimo</command>.
Again, ne30L30 climos only require <w>&lt; 2</w> minutes, so the 
<w>10 minutes</w> requested in the example is excessive and conservative.  
Tune it with experience. 
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle><w>12 node</w> <acronym><acronymword>MPI</acronymword></acronym>-mode Jobs</sectiontitle>
<para>The above parallel approaches will fail when a single node lacks enough 
<acronym><acronymword>RAM</acronymword></acronym> (plus swap) to store all twelve monthly input files, plus
extra <acronym><acronymword>RAM</acronymword></acronym> for computations. 
One should employ <acronym><acronymword>MPI</acronymword></acronym> multinode parallelism <samp>-p mpi</samp>
on nodes with less <acronym><acronymword>RAM</acronymword></acronym> than
<math>12*3*</math><code>sizeof(</code>input<code>)</code>. 
The longest an ne120 climo will take is less than half an hour (~25
minutes on <file>edison</file> or <file>rhea</file>), so the simplest method to run
<acronym><acronymword>MPI</acronymword></acronym> jobs is to request 12-interactive nodes using the above
commands (though remember to add <samp>-p mpi</samp>), then execute the script
at the command line. 
</para>
<para>It is also possible, and sometimes preferable, to request
non-interactive compute nodes in a batch queue. 
Executing an <acronym><acronymword>MPI</acronymword></acronym>-mode climo (on machines with job scheduling
and, optimally, <w>12 nodes</w>) in a batch queue can be done in two
commands. 
First, write an executable file which calls the <command>ncclimo</command> script
with appropriate arguments. 
We do this below by echoing to a file, <file>ncclimo.pbs</file>.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
echo &quot;ncclimo -p mpi -c $caseid -s 1 -e 20 -i $drc_in -o $drc_out&quot; &gt; ncclimo.pbs
</verbatim>
</example>
<para>The only new argument here is <samp>-p mpi</samp> that tells <command>ncclimo</command>
to use <acronym><acronymword>MPI</acronymword></acronym> parallelism. 
Then execute this command file with a <w>12 node</w> non-interactive job: 
</para><example endspaces=" ">
<pre xml:space="preserve">qsub -A CLI115 -V -l nodes=12 -l walltime=00:30:00 -j oe -m e -N ncclimo \
     -o ncclimo.out ncclimo.pbs
</pre></example>
<para>This script adds new flags:
<samp>-j oe</samp> (combine output and error streams into standard error),
<samp>-m e</samp> (send email to the job submitter when the job ends),
<samp>-o ncclimo.out</samp> (write all output to <file>ncclimo.out</file>).
The above commands are meant for <acronym><acronymword>PBS</acronymword></acronym> schedulers like on
<file>rhea</file>.  
Equivalent commands for <file>cooley</file>/<file>mira</file> (Cobalt) and
<file>cori</file>/<file>edison</file> (<acronym><acronymword>SLURM</acronymword></acronym>) are
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Cooley (Cobalt scheduler)
/bin/rm -f ncclimo.err ncclimo.out
echo '#!/bin/bash' &gt; ncclimo.cobalt
echo &quot;ncclimo -p mpi -c $caseid -s 1 -e 20 -i $drc_in -o $drc_out&quot; &gt;&gt; ncclimo.cobalt
chmod a+x ncclimo.cobalt
qsub -A HiRes_EarthSys --nodecount=12 --time=00:30:00 --jobname ncclimo \
     --error ncclimo.err --output ncclimo.out --notify zender@uci.edu ncclimo.cobalt

# Cori/Edison (SLURM scheduler)
echo &quot;ncclimo -p mpi -c $caseid -s 1 -e 20 -i $drc_in -o $drc_out -r $map_fl&quot; \
      &gt; ncclimo.pbs
chmod a+x ncclimo.slurm
sbatch -A acme --nodes=12 --time=03:00:00 --partition=regular --job-name=ncclimo \
       --mail-type=END --error=ncclimo.err --output=ncclimo.out ncclimo.slurm
</verbatim>
</example>
<para>Notice that Cobalt and <acronym><acronymword>SLURM</acronymword></acronym> require the introductory
shebang-interpreter line (<code>#!/bin/bash</code>) which <acronym><acronymword>PBS</acronymword></acronym> does
not need.  
Set only the scheduler batch queue parameters mentioned above. 
In <acronym><acronymword>MPI</acronymword></acronym>-mode, <command>ncclimo</command> determines the appropriate
number of tasks-per-node based on the number of nodes available and
script internals (like load-balancing for regridding). 
Hence do not set a tasks-per-node parameter with scheduler configuration
parameters as this could cause conflicts.
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>What does <command>ncclimo</command> do?</sectiontitle>
<para>For monthly climatologies (e.g., <acronym><acronymword>JAN</acronymword></acronym>), <command>ncclimo</command> passes
the list of all relevant January monthly files to <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s
<command>ncra</command> command, which averages each variable in these monthly
files over their time-dimension (if it exists) or copies the value from
the first month unchanged (if no time-axis exists). 
Seasonal climos are then created by taking the average of the monthly
climo files using <command>ncra</command>. 
To account for differing numbers of days per month, the <command>ncra</command>
<samp>-w</samp> flag is used, followed by the number of days in the relevant
months. 
For example, the <acronym><acronymword>MAM</acronymword></acronym> climo is computed with 
<samp>ncra -w 31,30,31 MAR_climo.nc APR_climo.nc MAY_climo.nc MAM_climo.nc</samp> 
(details about file names and other optimization flags have been
stripped here to make the concept easier to follow). 
The annual (<acronym><acronymword>ANN</acronymword></acronym>) climo is then computed as a weighted
average of the seasonal climos.
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Assumptions, Approximations, and Algorithms (<acronym><acronymword>AAA</acronymword></acronym>) Employed: </sectiontitle>
<para>A climatology embodies many algorithmic choices, and regridding from the
native to the analysis grid involves still more choices. 
A separate method should reproduce the <command>ncclimo</command> and
<acronym><acronymword>NCO</acronymword></acronym> answers to round-off precision if it implements the same
algorithmic choices. 
For example, <command>ncclimo</command> agrees to round-off with <acronym><acronymword>AMWG</acronymword></acronym>
diagnostics when making the same (sometimes questionable) choices. 
The most important choices have to do with converting single- to
double-precision (<acronym><acronymword>SP</acronymword></acronym> and <acronym><acronymword>DP</acronymword></acronym>, respectively),
treatment of missing values, and generation/application of regridding
weights. 
For concreteness and clarity we describe the algorithmic choices made in
processing a <acronym><acronymword>EAM-SE</acronymword></acronym> monthly output into a climatological
annual mean (<acronym><acronymword>ANN</acronymword></acronym>) and then regridding that. 
Other climatologies (e.g., daily to monthly, or
annual-to-climatological) involve similar choices. 
</para>
<para><acronym><acronymword>E3SM/ACME</acronymword></acronym> (and <acronym><acronymword>CESM</acronymword></acronym>) computes fields in <acronym><acronymword>DP</acronymword></acronym> and
outputs history (not restart) files as monthly means in <acronym><acronymword>SP</acronymword></acronym>. 
The <acronym><acronymword>NCO</acronymword></acronym> climatology generator (<command>ncclimo</command>) processes
these data in four stages. 
Stage <var>N</var> accesses input only from stage <math><var>N-1</var></math>, never
from stage <math><var>N-2</var></math> or earlier. 
Thus the (on-disk) files from stage <var>N</var> determine the highest
precision achievable by stage <math><var>N+1</var></math>. 
The general principal is to perform math (addition, weighting,
normalization) in <acronym><acronymword>DP</acronymword></acronym> and output results to disk in the same
precision in which they were input from disk (usually <acronym><acronymword>SP</acronymword></acronym>). 
In <w>Stage 1</w>, <acronym><acronymword>NCO</acronymword></acronym> ingests <w>Stage 0</w> monthly means (raw
<acronym><acronymword>EAM-SE</acronymword></acronym> output), converts <acronym><acronymword>SP</acronymword></acronym> input to <acronym><acronymword>DP</acronymword></acronym>,
performs the average across all years, then converts the answer from
<acronym><acronymword>DP</acronymword></acronym> to <acronym><acronymword>SP</acronymword></acronym> for storage on-disk as the climatological
monthly mean. 
In <w>Stage 2</w>, <acronym><acronymword>NCO</acronymword></acronym> ingests <w>Stage 1</w> climatological monthly
means, converts <acronym><acronymword>SP</acronymword></acronym> input to <acronym><acronymword>DP</acronymword></acronym>, performs the average
across all months in the season (e.g., <acronym><acronymword>DJF</acronymword></acronym>), then converts the  
answer from <acronym><acronymword>DP</acronymword></acronym> to <acronym><acronymword>SP</acronymword></acronym> for storage on-disk as the
climatological seasonal mean. 
In <w>Stage 3</w>, <acronym><acronymword>NCO</acronymword></acronym> ingests <w>Stage 2</w> climatological
seasonal means, converts <acronym><acronymword>SP</acronymword></acronym> input to <acronym><acronymword>DP</acronymword></acronym>, performs
the average across all four seasons (<acronym><acronymword>DJF</acronymword></acronym>, <acronym><acronymword>MAM</acronymword></acronym>,
<acronym><acronymword>JJA</acronymword></acronym>, <acronym><acronymword>SON</acronymword></acronym>), then converts the answer from
<acronym><acronymword>DP</acronymword></acronym> to <acronym><acronymword>SP</acronymword></acronym> for storage on-disk as the climatological
annual mean.  
</para>
<para><w>Stage 2</w> weights each input month by its number of days (e.g., 31 for 
January), and <w>Stage 3</w> weights each input season by its number of days 
(e.g., 92 for <acronym><acronymword>MAM</acronymword></acronym>). 
<acronym><acronymword>E3SM/ACME</acronymword></acronym> runs <acronym><acronymword>EAM-SE</acronymword></acronym> with a 365-day calendar, so these
weights are independent of year and never change. 
The treatment of missing values in <w>Stages 1&textndash;3</w> is limited by the
lack of missing value tallies provided by <w>Stage 0</w> (model) output. 
<w>Stage 0</w> records a value as missing if it is missing for the entire
month, and present if the value is valid for one or more timesteps. 
<w>Stage 0</w> does not record the missing value tally (number of valid
timesteps) for each spatial point. 
Thus a point with a single valid timestep during a month is weighted the
same in <w>Stages 1&textndash;4</w> as a point with 100% valid timesteps during the
month. 
The absence of tallies inexorably degrades the accuracy of subsequent
statistics by an amount that varies in time and space. 
On the positive side, it reduces the output size (by a factor of two) 
and complexity of analyzing fields that contain missing values. 
Due to the ambiguous nature of missing values, it is debatable whether
they merit efforts to treat them more exactly. 
</para>
<para>The vast majority of fields undergo three promotion/demotion cycles 
between <acronym><acronymword>EAM-SE</acronymword></acronym> and <acronym><acronymword>ANN</acronymword></acronym>. 
No promotion/demotion cycles occur for history fields that
<acronym><acronymword>EAM-SE</acronymword></acronym> outputs in <acronym><acronymword>DP</acronymword></acronym> rather than <acronym><acronymword>SP</acronymword></acronym>, nor
for fields without a time dimension. 
Typically these fields are grid coordinates (e.g., longitude, latitude) 
or model constants (e.g., 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$\cod$
@clear flg
</tex>
CO2
<clear name="flg" line=" flg"></clear>
mixing ratio). 
<acronym><acronymword>NCO</acronymword></acronym> never performs any arithmetic on grid coordinates or
non-time-varying input, regardless of whether they are <acronym><acronymword>SP</acronymword></acronym> or
<acronym><acronymword>DP</acronymword></acronym>. 
Instead, <acronym><acronymword>NCO</acronymword></acronym> copies these fields directly from the first
input file.  
<w>Stage 4</w> uses a mapfile to regrid climos from the native to the
desired analysis grid. 
<acronym><acronymword>E3SM/ACME</acronymword></acronym> currently uses mapfiles generated by
<command>ESMF_RegridWeightGen</command> (<acronym><acronymword>ERWG</acronymword></acronym>) and by TempestRemap.  
</para>
<para>The algorithmic choices, approximations, and commands used to generate
mapfiles from input gridfiles are separate issues.
We mention only some of these issues here for brevity.
Input gridfiles used by <acronym><acronymword>E3SM/ACME</acronymword></acronym> until ~20150901, and by
<acronym><acronymword>CESM</acronymword></acronym> (then and currently, at least for Gaussian grids)
contained flaws that effectively reduced their precision, especially at
regional scales, and especially for Gaussian grids. 
<acronym><acronymword>E3SM/ACME</acronymword></acronym> (and <acronym><acronymword>CESM</acronymword></acronym>) mapfiles continue to approximate
grids as connected by great circles, whereas most analysis grids (and
some models) use great circles for longitude and small circles for
latitude. 
The great circle assumption may be removed in the future. 
Constraints imposed by <acronym><acronymword>ERWG</acronymword></acronym> during weight-generation ensure
that global integrals of fields undergoing conservative regridding are
exactly conserved. 
</para>
<para>Application of weights from the mapfile to regrid the native data to the
analysis grid is straightforward. 
Grid fields (e.g., latitude, longitude, area) are not regridded. 
Instead they are copied (and area is reconstructed if absent) directly
from the mapfile. 
<acronym><acronymword>NCO</acronymword></acronym> ingests all other native grid (source) fields, converts
<acronym><acronymword>SP</acronymword></acronym> to <acronym><acronymword>DP</acronymword></acronym>, and accumulates destination gridcell
values as the sum of the <acronym><acronymword>DP</acronymword></acronym> weight (from the sparse matrix in
the mapfile) times the (usually <acronym><acronymword>SP</acronymword></acronym>-promoted-to-<acronym><acronymword>DP</acronymword></acronym>)
source values. 
Fields without missing values are then stored to disk in their
original precision. 
Fields with missing values are treated (by default) with what
<acronym><acronymword>NCO</acronymword></acronym> calls the &textldquo;conservative&textrdquo; algorithm. 
This algorithm uses all valid data from the source grid on the
destination grid once and only once. 
Destination cells receive the weighted valid values of the source
cells. 
This is conservative because the global integrals of the source and
destination fields are equal. 
See <ref label="ncremap-netCDF-Remapper"><xrefnodename>ncremap netCDF Remapper</xrefnodename></ref> for more description of the
conservative and of the optional (&textldquo;renormalized&textrdquo;) algorithm. 
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncclimo&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncclimo --&gt;
</html>
<para>EXAMPLES
</para>
<html endspaces=" ">
&lt;a name=&quot;merra2&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#merra2 --&gt;
</html>
<para>How to create a climo from a collection of monthly
non-<acronym><acronymword>CESM</acronymword></acronym>&textrsquo;ish files?  
This is a two-step procedure:
First be sure the names are arranged with a <acronym><acronymword>YYYYMM</acronymword></acronym>-format date
preceding the suffix (usually <samp>.nc</samp>).
Then give <emph>any</emph> monthly input filename to <command>ncclimo</command>.
Consider the <acronym><acronymword>MERRA2</acronymword></acronym> collection, for example.
As retrieved from <acronym><acronymword>NASA</acronymword></acronym>, <acronym><acronymword>MERRA2</acronymword></acronym> files have names like
<file>svc_MERRA2_300.tavgM_2d_aer_Nx.200903.nc4</file>. 
While the sub-string <samp>200903</samp> is easy to recognize as a month in
<acronym><acronymword>YYYYMM</acronymword></acronym> format, other parts (specifically the <samp>300</samp> code)
of the filename also change with date. 
We can use Bash regular expressions to extract dates and create symbolic
links to simpler filenames with regularly patterned <acronym><acronymword>YYYYMM</acronymword></acronym>
strings like <file>merra2_200903.nc4</file>:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for fl in `ls *.nc4` ; do
# Convert svc_MERRA2_300.tavgM_2d_aer_Nx.YYYYMM.nc4 to merra2_YYYYMM.nc4
    sfx_out=`expr match &quot;${fl}&quot; '.*_Nx.\(.*.nc4\)'`
    fl_out=&quot;merra2_${sfx_out}&quot;
    ln -s ${fl} ${fl_out}
done
</verbatim>
</example>
<para>Then call <command>ncclimo</command> with any standard format filename, e.g., 
<file>merra2_200903.nc4</file>, as as the <var>caseid</var>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo -c merra2_200903.nc4 -s 1980 -e 2016 -i $drc_in -o $drc_out
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;ecmwf_ifs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ecmwf_ifs --&gt;
</html>
<para>In the default monthly climo generation mode, <command>ncclimo</command> expects 
each input file to contain one single record that is the monthly average 
of all fields.
Another example of of wrangling observed datasets into a
<acronym><acronymword>CESM</acronymword></acronym>ish format is <acronym><acronymword>ECMWF</acronymword></acronym> Integrated Forecasting
System (<acronym><acronymword>IFS</acronymword></acronym>) output that contains twelve months per file,
rather than the one month per file that <command>ncclimo</command> expects.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for yr in {1979..2016}; do
# Convert ifs_YYYY01-YYYY12.nc to ifs_YYYYMM.nc
    yyyy=`printf &quot;%04d&quot; $yr`
    for mth in {1..12}; do
        mm=`printf &quot;%02d&quot; $mth`
        ncks -O -F -d time,${mth} ifs_${yyyy}01-${yyyy}12.nc ifs_${yyyy}${mm}.nc
    done
done
</verbatim>
</example>
<para>Then call <command>ncclimo</command> with <file>ifs_197901.nc</file> as <var>caseid</var>:  
</para><example endspaces=" ">
<pre xml:space="preserve">ncclimo -c ifs_197901.nc -s 1979 -e 2016 -i $drc_in -o $drc_out
</pre></example>
<para><acronym><acronymword>ncclimo</acronymword></acronym> does not recognize all combinations imaginable of
records per file and files per year. 
However, support can be added for the most prevalent combinations 
so that <acronym><acronymword>ncclimo</acronymword></acronym>, rather than the user, does any necessary data
wrangling.
Contact us if there is a common input data format you would like
supported as a custom option.
</para>
<para>Often one wishes to create a climatology of a single variable.
The <samp>-f <var>fml_nm</var></samp> option to <command>ncclimo</command> makes this easy.
Consider a series of single-variable climos for the fields <code>FSNT</code>, 
and <code>FLNT</code>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncclimo -v FSNT -f FSNT -c amip_xpt -s 1980 -e 1983 -i drc_in -o drc_out
ncclimo -v FLNT -f FLNT -c amip_xpt -s 1980 -e 1983 -i drc_in -o drc_out
</verbatim>
</example>
<para>These climos use the <samp>-f</samp> option and so their output files will
have no namespace conflicts. 
Moreover, the climatologies can be generated in parallel.
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncecat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncecat --&gt;
</html>
</unnumberedsubsec>
</section>
<node name="ncecat-netCDF-Ensemble-Concatenator" spaces=" "><nodename>ncecat netCDF Ensemble Concatenator</nodename><nodenext spaces=" ">nces netCDF Ensemble Statistics</nodenext><nodeprev spaces=" ">ncclimo netCDF Climatology Generator</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncecat</command> netCDF Ensemble Concatenator</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1994">concatenation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1995">ensemble concatenation</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="32" mergedindex="cp">ncecat</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat [-3] [-4] [-5] [-6] [-7] [-A] [-C] [-c] [--cmp <var>cmp_sng</var>]
[--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F] [--fl_fmt <var>fl_fmt</var>]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--gag] [--glb ...]
[-H] [-h] [--hdf] [--hdr_pad <var>nbr</var>] [--hpss] 
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [-M] [--md5_digest] [--mrd] [-n <var>loop</var>]
[--no_cll_msr] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>output-file</var>] [-p <var>path</var>] [--qnt ...] [--qnt_alg <var>alg_nm</var>]
[-R] [-r] [--ram_all] [-t <var>thr_nbr</var>] [-u <var>ulm_nm</var>] [--unn]
[-v <var>var</var>[,&dots;]] [-X ...] [-x] 
[<var>input-files</var>] [<var>output-file</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncecat</command> aggregates an arbitrary number of input files into a 
single output file using using one of two methods.
<dfn>Record AGgregation</dfn> (<acronym><acronymword>RAG</acronymword></acronym>), the traditional method employed on
(flat) netCDF3 files and still the default method, stores
<var>input-files</var> as consecutive records in the <var>output-file</var>.
<dfn>Group AGgregation</dfn> (<acronym><acronymword>GAG</acronymword></acronym>) stores <var>input-files</var> as top-level
groups in the netCDF4 <var>output-file</var>.
Record Aggregation (<acronym><acronymword>RAG</acronymword></acronym>) makes numerous assumptions about the
structure of input files whereas Group Aggregation (<acronym><acronymword>GAG</acronymword></acronym>) makes
none. 
Both methods are described in detail below.
Since <command>ncecat</command> aggregates all the contents of the input files,
it can easily produce large output files so it is often helpful to invoke
subsetting simultaneously (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>).
</para>
<html endspaces=" ">
&lt;a name=&quot;rag&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rag --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1996">record aggregation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1997"><acronym><acronymword>RAG</acronymword></acronym></indexterm></cindex>
<para><acronym><acronymword>RAG</acronymword></acronym> makes each variable (except coordinate variables) in each
input file into a single record of the same variable in the output file.  
Coordinate variables are not concatenated, they are instead simply
copied from the first input file to the <var>output-file</var>.
All <var>input-files</var> must contain all extracted variables (or else
there would be &textldquo;gaps&textrdquo; in the output file).
</para>
<para>A new record dimension is the glue which binds together the input file
data.
The new record dimension is defined in the root group of the output file
so it is visible to all sub-groups.
Its name is, by default, &textldquo;record&textrdquo;.
<cindex index="cp" spaces=" "><indexterm index="cp" number="1998">unlimited dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="1999">record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2000"><samp>-u <var>ulm_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2001"><samp>--ulm_nm <var>ulm_nm</var></samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2002"><samp>--rcd_nm <var>ulm_nm</var></samp></indexterm></cindex>
This default name can be overridden with the <samp>-u <var>ulm_nm</var></samp>
short option (or the <samp>--ulm_nm</samp> or <samp>rcd_nm</samp> long options).
</para>
<para>Each extracted variable must be constant in size and rank across all
<var>input-files</var>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2003">record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2004">hyperslab</indexterm></cindex>
The only exception is that <command>ncecat</command> allows files to differ in
the record dimension size if the requested record hyperslab
(<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>) resolves to the same size for all files. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2005"><acronym><acronymword>CMIP</acronymword></acronym></indexterm></cindex>
This allows easier gluing/averaging of unequal length timeseries from 
simulation ensembles (e.g., the <acronym><acronymword>CMIP</acronymword></acronym> archive). 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2006">fixed dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2007">fix record dimension</indexterm></cindex>
<para>Classic (i.e., all netCDF3 and <code>NETCDF4_CLASSIC</code>) output files
can contain only one record dimension.
<command>ncecat</command> makes room for the new glue record dimension by
changing the pre-existing record dimension, if any, in the input files
into a fixed dimension in the output file. 
netCDF4 output files may contain any number of record dimensions, so
<command>ncecat</command> need not and does not alter the record dimensions,
if any, of the input files as it copies them to the output file. 
</para>
<html endspaces=" ">
&lt;a name=&quot;gag&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#gag --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2008">group aggregation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2009"><acronym><acronymword>GAG</acronymword></acronym></indexterm></cindex>
<para><dfn>Group AGgregation</dfn> (<acronym><acronymword>GAG</acronymword></acronym>) stores <var>input-files</var> as
top-level groups in the <var>output-file</var>.
No assumption is made about the size or shape or type of a given 
object (variable or dimension or group) in the input file.
The entire contents of the extracted portion of each input file
is placed in its own top-level group in <var>output-file</var>, which
is automatically made as a netCDF4-format file.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2010"><option>--gag</option></indexterm></cindex>
<para><acronym><acronymword>GAG</acronymword></acronym> has two methods to specify group names for the
<var>output-file</var>.    
The <samp>-G</samp> option, or its long-option equivalent <samp>--gpe</samp>,
takes as argument a group path editing description <var>gpe_dsc</var> of
where to place the results.
Each input file needs a distinct output group name to avoid namespace
conflicts in the <var>output-file</var>. 
Hence <command>ncecat</command> automatically creates unique output group names
based on either the input filenames or the <var>gpe_dsc</var> arguments.
When the user provides <var>gpe_dsc</var> (i.e., with <samp>-G</samp>), then the
output groups are formed by enumerating sequential two-digit numeric
suffixes starting with zero, and appending them to the specified group
path (<pxref label="Group-Path-Editing"><xrefnodename>Group Path Editing</xrefnodename></pxref>).
When <var>gpe_dsc</var> is not provided (i.e., user requests <acronym><acronymword>GAG</acronymword></acronym> with
<samp>--gag</samp> instead of <samp>-G</samp>), then <command>ncecat</command> forms the
output groups by stripping the input file name of any type-suffix
(e.g., <code>.nc</code>), and all but the final component of the full
filename. 
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat --gag 85.nc 86.nc 87.nc 8587.nc # Output groups 85, 86, 87
ncecat -G 85_ a.nc b.nc c.nc 8589.nc # Output groups 85_00, 85_01, 85_02
ncecat -G 85/ a.nc b.nc c.nc 8589.nc # Output groups 85/00, 85/01, 85/02
</pre></example>

<para>With both <acronym><acronymword>RAG</acronymword></acronym> and <acronym><acronymword>GAG</acronymword></acronym> the <var>output-file</var> size is
the sum of the sizes of the extracted variables in the input files. 
<xref label="Statistics-vs-Concatenation"><xrefnodename>Statistics vs Concatenation</xrefnodename></xref>, for a description of the
distinctions between the various statistics tools and concatenators. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2011">multi-file operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2012">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2013"><code>stdin</code></indexterm></cindex>
As a multi-file operator, <command>ncecat</command> will read the list of
<var>input-files</var> from <code>stdin</code> if they are not specified 
as positional arguments on the command line 
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2014"><code>-M</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2015"><code>--no_glb_mtd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2016"><code>--suppress_global_metadata</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2017"><code>history</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2018">provenance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2019">metadata, global</indexterm></cindex> 
<para>Suppress global metadata copying.
By default <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s multi-file operators copy the global metadata
from the first input file into <var>output-file</var>.  
This helps to preserve the provenance of the output data.
However, the use of metadata is burgeoning and sometimes one
encounters files with excessive amounts of extraneous metadata.
Extracting small bits of data from such files leads to output files
which are much larger than necessary due to the automatically copied
metadata.
<command>ncecat</command> supports turning off the default copying of global
metadata via the <samp>-M</samp> switch (or its long option equivalents,
<samp>--no_glb_mtd</samp> and <samp>--suppress_global_metadata</samp>). 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2020">climate model</indexterm></cindex>
<para>Consider five realizations, <file>85a.nc</file>, <file>85b.nc</file>, 
<w>&dots; <file>85e.nc</file></w> of 1985 predictions from the same climate
model. 
Then <code>ncecat 85?.nc 85_ens.nc</code> glues together the individual
realizations into the single file, <file>85_ens.nc</file>. 
If an input variable was dimensioned [<code>lat</code>,<code>lon</code>], it will
by default have dimensions [<code>record</code>,<code>lat</code>,<code>lon</code>] in
the output file. 
<w>A restriction</w> of <command>ncecat</command> is that the hyperslabs of the
processed variables must be the same from file to file.
Normally this means all the input files are the same size, and contain 
data on different realizations of the same variables.
</para>
<findex index="fn" spaces=" "><indexterm index="fn" number="33" mergedindex="cp">ncpdq</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2021">packing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2022">unpacking</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2023"><code>add_offset</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2024"><code>scale_factor</code></indexterm></cindex>
<para>Concatenating a variable packed with different scales across multiple
datasets is beyond the capabilities of <command>ncecat</command> (and
<command>ncrcat</command>, the other concatenator (<ref label="Concatenation"><xrefnodename>Concatenation</xrefnodename></ref>).
<command>ncecat</command> does not unpack data, it simply <emph>copies</emph> the data
from the <var>input-files</var>, and the metadata from the <emph>first</emph>
<var>input-file</var>, to the <var>output-file</var>. 
This means that data compressed with a packing convention must use
the identical packing parameters (e.g., <code>scale_factor</code> and
<code>add_offset</code>) for a given variable across <emph>all</emph> input files.
Otherwise the concatenated dataset will not unpack correctly.
The workaround for cases where the packing parameters differ across
<var>input-files</var> requires three steps:
First, unpack the data using <command>ncpdq</command>.
Second, concatenate the unpacked data using <command>ncecat</command>, 
Third, re-pack the result with <command>ncpdq</command>.
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncecat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncecat --&gt;
</html>
<para>EXAMPLES
</para>
<para>Consider a model experiment which generated five realizations of one
year of data, say 1985.
You can imagine that the experimenter slightly perturbs the
initial conditions of the problem before generating each new solution.  
Assume each file contains all twelve months (a seasonal cycle) of data
and we want to produce a single file containing all the seasonal
cycles. 
Here the numeric filename suffix denotes the experiment number
(<emph>not</emph> the month):
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat 85_01.nc 85_02.nc 85_03.nc 85_04.nc 85_05.nc 85.nc
ncecat 85_0[1-5].nc 85.nc
ncecat -n 5,2,1 85_01.nc 85.nc
</pre></example>
<noindent></noindent>
<para>These three commands produce identical answers.
<xref label="Specifying-Input-Files"><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions
between these methods.
The output file, <file>85.nc</file>, is five times the size as a single
<var>input-file</var>. 
It contains <w>60 months</w> of data.
</para>
<html endspaces=" ">
&lt;a name=&quot;ncecat_rnm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncecat_rnm --&gt;
</html>
<para>One often prefers that the (new) record dimension have a more
descriptive, context-based name than simply &textldquo;record&textrdquo;. 
This is easily accomplished with the <samp>-u <var>ulm_nm</var></samp> switch.
To add a new record dimension named &textldquo;time&textrdquo; to all variables
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat -u time in.nc out.nc
</pre></example>
<para>To glue together multiple files with a new record variable named
&textldquo;realization&textrdquo; 
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat -u realization 85_0[1-5].nc 85.nc
</pre></example>
<noindent></noindent>
<para>Users are more likely to understand the data processing history when
such descriptive coordinates are used. 
</para>
<html endspaces=" ">
&lt;a name=&quot;dmn_rcd_rm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dmn_rcd_rm --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2025">record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2026">fixed dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2027">fix record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2028"><code>--mk_rec_dmn <var>dim</var></code></indexterm></cindex>
<para>Consider a file with an existing record dimension named <code>time</code>. 
and suppose the user wishes to convert <code>time</code> from a record
dimension to a non-record dimension.
This may be useful, for example, when the user has another use for the
record variable.
The simplest method is to use <samp>ncks --fix_rec_dmn</samp>, and another
possibility is to use <command>ncecat</command> followed by 
<command>ncwa</command>: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2029">degenerate dimension</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat in.nc out.nc # Convert time to non-record dimension
ncwa -a record in.nc out.nc # Remove new degenerate record dimension
</pre></example>
<noindent></noindent>
<para>The second step removes the degenerate record dimension.
See <ref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></ref> and
<ref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></ref> for other methods of
of changing variable dimensionality, including the record dimension.
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;nces&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nces --&gt;
&lt;a name=&quot;ncea&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncea --&gt;
</html>
</section>
<node name="nces-netCDF-Ensemble-Statistics" spaces=" "><nodename>nces netCDF Ensemble Statistics</nodename><nodenext spaces=" ">ncflint netCDF File Interpolator</nodenext><nodeprev spaces=" ">ncecat netCDF Ensemble Concatenator</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>nces</command> netCDF Ensemble Statistics</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2030">averaging data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2031">ensemble average</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="34" mergedindex="cp">nces</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">nces [-3] [-4] [-5] [-6] [-7] [-A] [-C] [-c] [--cb <var>y1</var>,<var>y2</var>,<var>m1</var>,<var>m2</var>,<var>tpd</var>]
[--cmp <var>cmp_sng</var>] [--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...]
[-H] [-h] [--hdf] [--hdr_pad <var>nbr</var>] [--hpss] 
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [-n <var>loop</var>]
[--no_cll_msr] [--no_frm_trm] [--no_tmp_fl] [--nsm_fl|grp] [--nsm_sfx sfx]
[-O] [-o <var>output-file</var>] [-p <var>path</var>] [--qnt ...] [--qnt_alg <var>alg_nm</var>]
[-R] [-r] [--ram_all] [--rth_dbl|flt] [-t <var>thr_nbr</var>] [--unn]
[-v <var>var</var>[,&dots;]] [-w wgt] [-X ...] [-x] [-y <var>op_typ</var>]
[<var>input-files</var>] [<var>output-file</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>nces</command> performs gridpoint statistics (including, but not limited
to, averages) on variables across an arbitrary number (an
<dfn>ensemble</dfn>) of <var>input-files</var> and/or of input groups within each
file. 
Each file (or group) receives an equal weight by default.
<command>nces</command> was formerly (until <acronym><acronymword>NCO</acronymword></acronym> version 4.3.9,
released December, 2013) known as <command>ncea</command> (netCDF Ensemble
Averager)<footnote spaces="\n"><para>The old ncea command was deprecated in <acronym><acronymword>NCO</acronymword></acronym> version 4.3.9,  
released December, 2013.
<acronym><acronymword>NCO</acronymword></acronym> will attempt to maintain back-compatibility and work
as expected with invocations of <command>ncea</command> for as long as possible.
Please replace <command>ncea</command> by <command>nces</command> in all future work.</para></footnote>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2032">ensemble</indexterm></cindex>
For example, <command>nces</command> will average a set of files or groups,
weighting each file or group evenly by default. 
This is distinct from <command>ncra</command>, which performs statistics only
over the record dimension(s) (e.g., <var>time</var>), and weights each record 
in each record dimension evenly.
</para>
<para>The file or group is the logical unit of organization for the results of
many scientific studies.
Often one wishes to generate a file or group which is the statistical
product (e.g., average) of many separate files or groups. 
This may be to reduce statistical noise by combining the results of a
large number of experiments, or it may simply be a step in a procedure 
whose goal is to compute anomalies from a mean state. 
In any case, when one desires to generate a file whose statistical
properties are influenced by all the inputs, then use <command>nces</command>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2033">weights</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2034">weighted average</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.9.4</w>, released in July, 2020,
<command>nces</command> accepts user-specified weights with the <samp>-w</samp> 
(or long-option equivalent <samp>--wgt</samp>, <samp>--wgt_var</samp>,
or <samp>--weight</samp>) switch. 
The user must specify one weight per input file on the command line,
or the name of a (scalar or degenerate 1-D array) variable in each
input file that contains a single value to weight that file.
When no weight is specified, <command>nces</command> weights each file
(e.g., ensemble) in the <var>input-files</var> equally.
</para>
<para>Variables in the <var>output-file</var> are the same size as the variable
hyperslab in each input file or group, and each input file or group
must be the same size after hyperslabbing
<footnote><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.2 (released February, 2014)
<command>nces</command> allows hyperslabs in all dimensions so long as the
hyperslabs resolve to the same size. 
The fixed (i.e., non-record) dimensions should be the same size in
all ensemble members both before and after hyperslabbing, although
the hyperslabs may (and usually do) change the size of the dimensions
from the input to the output files.
Prior to this, <command>nces</command> was only guaranteed to work on hyperslabs
in the record dimension that resolved to the same size.</para></footnote>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2035">record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2036">hyperslab</indexterm></cindex>
<command>nces</command> does allow files to differ in the input record
dimension size if the requested record hyperslab (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>)
resolves to the same size for all files.  
<command>nces</command> recomputes the record dimension hyperslab limits for
each input file so that coordinate limits may be used to select equal
length timeseries from unequal length files.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2037"><acronym><acronymword>IPCC</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2038"><acronym><acronymword>AR4</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2039"><acronym><acronymword>CMIP</acronymword></acronym></indexterm></cindex>
This simplifies analysis of unequal length timeseries from simulation
ensembles (e.g., the <acronym><acronymword>CMIP3</acronymword></acronym> <acronym><acronymword>IPCC</acronymword></acronym> <acronym><acronymword>AR4</acronymword></acronym>
archive).   
</para>
<html endspaces=" ">
&lt;a name=&quot;nsm_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nsm_fl --&gt;
&lt;a name=&quot;nsm_grp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nsm_grp --&gt;
&lt;a name=&quot;nsm_sfx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nsm_sfx --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2040"><code>--nsm_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2041"><code>--nsm_grp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2042"><code>--ensemble_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2043"><code>--ensemble_group</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2044"><code>--nsm_sfx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2045"><code>--ensemble_suffix</code></indexterm></cindex>
<para><command>nces</command> works in one of two modes, file ensembles 
or group ensembles.
File ensembles are the default (equivalent to the old <command>ncea</command>) 
and may also be explicitly specified by the <samp>--nsm_fl</samp> or
<samp>--ensemble_file</samp> switches.
To perform statistics on ensembles of groups, a newer feature, use
<samp>--nsm_grp</samp> or <samp>--ensemble_group</samp>.
Members of a group ensemble are groups that share the same structure,
parent group, and nesting level. 
Members must be <dfn>leaf groups</dfn>, i.e., not contain any sub-groups.
Their contents usually have different values because they are
realizations of replicated experiments.  
In group ensemble mode <command>nces</command> computes the statistics across 
the ensemble, which may span multiple input files. 
Files may contain members of multiple, distinct ensembles. 
However, all ensembles must have at least one member in the first input 
file. 
Group ensembles behave as an unlimited dimension of datasets: 
they may contain an arbitrary and extensible number of realizations in
each file, and may be composed from multiple files. 
</para>
<para>Output statistics in group ensemble mode are stored in the parent group
by default. 
If the ensemble members are <file>/cesm/cesm_01</file> and
<file>/cesm/cesm_02</file>, then the computed statistic will be in
<file>/cesm</file> in the output file.   
The <samp>--nsm_sfx</samp> option instructs nces to instead store output in  
a new child group of the parent created by attaching the suffix
to the parent group&textrsquo;s name, e.g., <samp>--nsm_sfx='_avg'</samp> would store
results in the output group <file>/cesm/cesm_avg</file>:
</para><example endspaces=" ">
<pre xml:space="preserve">nces --nsm_grp                  mdl1.nc mdl2.nc mdl3.nc out.nc
nces --nsm_grp --nsm_sfx='_avg' mdl1.nc mdl2.nc mdl3.nc out.nc
</pre></example>

<para><xref label="Statistics-vs-Concatenation"><xrefnodename>Statistics vs Concatenation</xrefnodename></xref>, for a description of the
distinctions between the statistics tools and concatenators. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2046">multi-file operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2047">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2048"><code>stdin</code></indexterm></cindex>
As a multi-file operator, <command>nces</command> will read the list of
<var>input-files</var> from <code>stdin</code> if they are not specified 
as positional arguments on the command line 
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>).
</para>
<para>Like <command>ncra</command> and <command>ncwa</command>, <command>nces</command> treats coordinate
variables as a special case.
Coordinate variables are assumed to be the same in all ensemble members,
so <command>nces</command> simply copies the coordinate variables that appear in 
ensemble members directly to the output file.
This has the same effect as averaging the coordinate variable across the
ensemble, yet does not incur the time- or precision- penalties of
actually averaging them.
<command>ncra</command> and <command>ncwa</command> allow coordinate variables to be
processed only by the linear average operation, regardless of the
arithmetic operation type performed on the non-coordinate variables
(<pxref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></pxref>). 
Thus it can be said that the three operators (<command>ncra</command>,
<command>ncwa</command>, and <command>nces</command>) all average coordinate variables
(even though <command>nces</command> simply copies them).
All other requested arithmetic operations (e.g., maximization,
square-root, RMS) are applied only to non-coordinate variables.
In these cases the linear average of the coordinate variable will be
returned.
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncea&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncea --&gt;
&lt;a name=&quot;xmp_nces&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_nces --&gt;
</html>
<para>EXAMPLES
</para>
<para>Consider a model experiment which generated five realizations of one
year of data, say 1985.
Imagine that the experimenter slightly perturbs the initial conditions
of the problem before generating each new solution.   
Assume each file contains all twelve months (a seasonal cycle) of data
and we want to produce a single file containing the ensemble average
(mean) seasonal cycle.  
Here the numeric filename suffix denotes the realization number
(<emph>not</emph> the month):
</para><example endspaces=" ">
<pre xml:space="preserve">nces 85_01.nc 85_02.nc 85_03.nc 85_04.nc 85_05.nc 85.nc
nces 85_0[1-5].nc 85.nc
nces -n 5,2,1 85_01.nc 85.nc
</pre></example>
<noindent></noindent>
<para>These three commands produce identical answers.
<xref label="Specifying-Input-Files"><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions
between these methods.
The output file, <file>85.nc</file>, is the same size as the inputs files.
It contains 12 months of data (which might or might not be stored in the 
record dimension, depending on the input files), but each value in the
output file is the average of the five values in the input files.
</para>
<para>In the previous example, the user could have obtained the ensemble
average values in a particular spatio-temporal region by adding a 
hyperslab argument to the command, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">nces -d time,0,2 -d lat,-23.5,23.5 85_??.nc 85.nc
</pre></example>
<noindent></noindent>
<para>In this case the output file would contain only three slices of data in
the <var>time</var> dimension. 
These three slices are the average of the first three slices from the
input files.
Additionally, only data inside the tropics is included.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.3.9 (released December, 2013)
<command>nces</command> also works with groups (rather than files) as the
fundamental unit of the ensemble.
Consider two ensembles, <code>/ecmwf</code> and <code>/cesm</code> stored across
three input files <file>mdl1.nc</file>, <file>mdl2.nc</file>, and <file>mdl3.nc</file>.
Ensemble members would be leaf groups with names like <code>/ecmwf/01</code>,
<code>/ecmwf/02</code> etc. and <code>/cesm/01</code>, <code>/cesm/02</code>, etc.
These commands average both ensembles: 
</para><example endspaces=" ">
<pre xml:space="preserve">nces --nsm_grp mdl1.nc mdl2.nc mdl3.nc out.nc
nces --nsm_grp --nsm_sfx='_min' --op_typ=min -n 3,1,1 mdl1.nc out.nc
nces --nsm_grp -g cesm -v tas -d time,0,3 -n 3,1,1 mdl1.nc out.nc
</pre></example>
<example endspaces=" ">
<pre xml:space="preserve">nces --nsm_grp mdl1.nc mdl2.nc mdl3.nc out.nc
nces --nsm_grp --nsm_sfx='_min' --op_typ=min -n 3,1,1 mdl1.nc out.nc
nces --nsm_grp -g cesm -v tas -d time,0,3 -n 3,1,1 mdl1.nc out.nc
</pre></example>
<para>The first command stores averages in the output groups <file>/cesm</file> and 
<file>/ecmwf</file>, while the second stores minima in the output groups
<file>/cesm/cesm_min</file> and <file>/ecmwf/ecmwf_min</file>:
The third command demonstrates that sub-setting and hyperslabbing work
as expected.
Note that each input file may contain different numbers of members
of each ensemble, as long as all distinct ensembles contain at least one
member in the first file.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2049">weights</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2050">weighted average</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.9.4</w>, released in July, 2020,
<command>nces</command> accepts user-specified weights with the <samp>-w</samp> 
(or long-option equivalent <samp>--wgt</samp>, <samp>--wgt_var</samp>,
or <samp>--weight</samp>) switch: 
</para><example endspaces=" ">
<pre xml:space="preserve"># Construct input variables with values of 1 and 2
ncks -O -M -v one ~/nco/data/in.nc ~/1.nc
ncrename -O -v one,var ~/1.nc
ncap2 -O -s 'var=2' ~/1.nc ~/2.nc

# Three methods of weighting input files unevenly
# 1. Old-method: specify input files multiple times
# 2. New-method: specify one weight per input file
# 3. New-method: specify weight variable in each input file
nces -O ~/1.nc ~/2.nc ~/2.nc ~/out.nc # Clumsy, limited to integer weights
nces -O -w 1,2 ~/1.nc ~/2.nc ~/out.nc # Flexible, works for any weight
nces -O -w var ~/1.nc ~/2.nc ~/out.nc # Flexible, works for any weight
# All three methods produce same answer: var=(1*1+2*2)/3=5/3=1.67
ncks ~/out.nc
</pre></example>

<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncflint&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncflint --&gt;
</html>
</section>
<node name="ncflint-netCDF-File-Interpolator" spaces=" "><nodename>ncflint netCDF File Interpolator</nodename><nodenext spaces=" ">ncks netCDF Kitchen Sink</nodenext><nodeprev spaces=" ">nces netCDF Ensemble Statistics</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncflint</command> netCDF File Interpolator</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2051">interpolation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2052">adding data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2053">multiplying data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2054">addition</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="35" mergedindex="cp">ncflint</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncflint [-3] [-4] [-5] [-6] [-7] [-A] [-C] [-c]  [--cmp <var>cmp_sng</var>]
[--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [--fl_fmt <var>fl_fmt</var>]
[-F] [--fix_rec_crd] [-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...]
[-H] [-h] [--hdr_pad <var>nbr</var>] [--hpss] 
[-i <var>var</var>,<var>val3</var>] [-L <var>dfl_lvl</var>] [-l <var>path</var>] [-N]
[--no_cll_msr] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>file_3</var>] [-p <var>path</var>] [--qnt ...] [--qnt_alg <var>alg_nm</var>] 
[-R] [-r] [--ram_all] [-t <var>thr_nbr</var>] [--unn] [-v <var>var</var>[,&dots;]]
[-w <var>wgt1</var>[,<var>wgt2</var>]] [-X ...] [-x]
<var>file_1</var> <var>file_2</var> [<var>file_3</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncflint</command> creates an output file that is a linear combination of 
the input files.
This linear combination is a weighted average, a normalized weighted
average, or an interpolation of the input files.
Coordinate variables are not acted upon in any case, they are simply
copied from <var>file_1</var>.
</para>
<para>There are two conceptually distinct methods of using <command>ncflint</command>.
The first method is to specify the weight each input file contributes to 
the output file.
In this method, the value <var>val3</var> of a variable in the output file
<var>file_3</var> is determined from its values <var>val1</var> and <var>val2</var> in
the two input files according to 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$val3 = wgt1 \times val1 + wgt2 \times val2$
@clear flg
</tex>
<math><var>val3</var> = <var>wgt1</var>*<var>val1</var> + <var>wgt2</var>*<var>val2</var></math> 
<clear name="flg" line=" flg"></clear>
.
Here at least <var>wgt1</var>, and, optionally, <var>wgt2</var>, are specified on 
the command line with the <samp>-w</samp> (or <samp>--weight</samp> or
<samp>--wgt_var</samp>) switch.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2055"><code>-w <var>wgt1</var>[,<var>wgt2</var>]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2056"><code>--weight <var>wgt1</var>[,<var>wgt2</var>]</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2057"><code>--wgt_var <var>wgt1</var>[,<var>wgt2</var>]</code></indexterm></cindex>
If only <var>wgt1</var> is specified then <var>wgt2</var> is automatically
computed as <math><var>wgt2</var> = 1 &minus; <var>wgt1</var></math>.
Note that weights larger <w>than 1</w> are allowed. 
Thus it is possible to specify <math><var>wgt1</var> = 2</math> and
<math><var>wgt2</var> = -3</math>.
One can use this functionality to multiply all values in a given
file by a constant.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2058">normalization</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2059"><code>-N</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2060"><code>--nrm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2061"><code>--normalize</code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.1 (July, 2016), the <samp>-N</samp> switch
(or long-option equivalents <samp>--nrm</samp> or <samp>--normalize</samp>)
implements a variation of this method. 
This switch instructs <command>ncflint</command> to internally normalize the two
supplied (or one supplied and one inferred) weights so that 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$wgt1 = wgt1 / (wgt1 + wgt2)$ and $wgt2 = wgt2 / (wgt1 + wgt2)$
@clear flg
</tex>
<math><var>wgt1</var> = <var>wgt1</var>/(<var>wgt1</var> + <var>wgt2</var></math> and
<math><var>wgt2</var> = <var>wgt2</var>/(<var>wgt1</var> + <var>wgt2</var></math> and
<clear name="flg" line=" flg"></clear>
.
This allows the user to input integral weights, say, and to delegate 
the chore of normalizing them to <command>ncflint</command>.
Be careful that <samp>-N</samp> means what you think, since the same
switch means something quite different in <command>ncwa</command>.
</para>
<para>The second method of using <command>ncflint</command> is to specify the
interpolation option <w>with <samp>-i</samp></w> (or with the <samp>--ntp</samp> or 
<samp>--interpolate</samp> long options). 
This is the inverse of the first method in the following sense: 
When the user specifies the weights directly, <command>ncflint</command> has no
work to do besides multiplying the input values by their respective
weights and adding together the results to produce the output values.  
It makes sense to use this when the weights are known 
<emph><w>a priori</w></emph>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2062">arrival value</indexterm></cindex> 
<para>Another class of problems has the <dfn>arrival value</dfn> (i.e., <var>val3</var>)
of a particular variable <var>var</var> known <emph><w>a priori</w></emph>. 
In this case, the implied weights can always be inferred by examining
the values of <var>var</var> in the input files. 
This results in one equation in two unknowns, <var>wgt1</var> and <var>wgt2</var>:  
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$val3 = wgt1 \times val1 + wgt2 \times val2$
@clear flg
</tex>
<math><var>val3</var> = <var>wgt1</var>*<var>val1</var> + <var>wgt2</var>*<var>val2</var></math> 
<clear name="flg" line=" flg"></clear>
.
Unique determination of the weights requires imposing the additional
constraint of normalization on the weights:
<math><var>wgt1</var> + <var>wgt2</var> = 1</math>.
Thus, to use the interpolation option, the user specifies <var>var</var>
and <var>val3</var> with the <samp>-i</samp> option.
<command>ncflint</command> then computes <var>wgt1</var> and <var>wgt2</var>, and uses these
weights on all variables to generate the output file.
Although <var>var</var> may have any number of dimensions in the input
files, it must represent a single, scalar value.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="2063">degenerate dimension</indexterm></cindex>
Thus any dimensions associated with <var>var</var> must be <dfn>degenerate</dfn>,
i.e., of size one.
</para>
<para>If neither <samp>-i</samp> nor <samp>-w</samp> is specified on the command line,
<command>ncflint</command> defaults to weighting each input file equally in the
output file.
This is equivalent to specifying <samp>-w 0.5</samp> or <samp>-w 0.5,0.5</samp>.
Attempting to specify both <samp>-i</samp> and <samp>-w</samp> methods in the same
command is an error. 
</para>
<para><command>ncflint</command> does not interpolate variables of type <code>NC_CHAR</code>
and <code>NC_STRING</code>. 
This behavior is hardcoded.
</para>
<para>By default <command>ncflint</command> interpolates or multiplies record
coordinate variables (e.g., time is often stored as a record coordinate) 
not other coordinate variables (e.g., latitude and longitude). 
This is because <command>ncflint</command> is often used to time-interpolate
between existing files, but is rarely used to spatially interpolate.
Sometimes however, users wish to multiply entire files by a constant
that does not multiply any coordinate variables.
The <samp>--fix_rec_crd</samp> switch was implemented for this purpose
in <acronym><acronymword>NCO</acronymword></acronym> version 4.2.6 (March, 2013).
It prevents <command>ncflint</command> from multiplying or interpolating any
coordinate variables, including record coordinate variables. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2064">missing values</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2065"><code>_FillValue</code></indexterm></cindex>
<para>Depending on your intuition, <command>ncflint</command> may treat missing values
unexpectedly.
Consider a point where the value in one input file, say <var>val1</var>,
equals the missing value <var>mss_val_1</var> and, at the same point,
the corresponding value in the other input file <var>val2</var> is not
misssing (i.e., does not equal <var>mss_val_2</var>).
There are three plausible answers, and this creates ambiguity.
</para>
<para><w>Option one</w> is to set <math><var>val3</var> = <var>mss_val_1</var></math>.
The rationale is that <command>ncflint</command> is, at heart, an interpolator
and interpolation involving a missing value is intrinsically undefined.
<command>ncflint</command> currently implements this behavior since it is the
most conservative and least likely to lead to misinterpretation.
</para>
<para><w>Option two</w> is to output the weighted valid data point, i.e.,
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$val3 = wgt2 \times val2$
@clear flg
</tex>
<math><var>val3</var> = <var>wgt2</var>*<var>val2</var></math> 
<clear name="flg" line=" flg"></clear>
.
The rationale for this behavior is that interpolation is really a
weighted average of known points, so <command>ncflint</command> should weight the
valid point. 
</para>
<para><w>Option three</w> is to return the <emph>unweighted</emph> valid point, i.e.,
<math><var>val3</var> = <var>val2</var></math>.
This behavior would appeal to those who use <command>ncflint</command> to
estimate data using the closest available data. 
When a point is not bracketed by valid data on both sides, it is better
to return the known datum than no datum at all.
</para>
<para>The current implementation uses the first approach, <w>Option one</w>.
If you have strong opinions on this matter, let us know, since we are
willing to implement the other approaches as options if there is enough
interest. 
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncflint&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncflint --&gt;
</html>
<para>EXAMPLES
</para>
<para>Although it has other uses, the interpolation feature was designed 
to interpolate <var>file_3</var> to a time between existing files.
Consider input files <file>85.nc</file> and <file>87.nc</file> containing variables 
describing the state of a physical system at times <math><code>time</code> =
85</math> and <math><code>time</code> = 87</math>.
Assume each file contains its timestamp in the scalar variable
<code>time</code>.  
Then, to linearly interpolate to a file <file>86.nc</file> which describes
the state of the system at time at <code>time</code> = 86, we would use
</para><example endspaces=" ">
<pre xml:space="preserve">ncflint -i time,86 85.nc 87.nc 86.nc
</pre></example>

<para>Say you have observational data covering January and April 1985 in two
files named <file>85_01.nc</file> and <file>85_04.nc</file>, respectively.
Then you can estimate the values for February and March by interpolating
the existing data as follows.
Combine <file>85_01.nc</file> and <file>85_04.nc</file> in a 2:1 ratio to make
<file>85_02.nc</file>:  
</para><example endspaces=" ">
<pre xml:space="preserve">ncflint -w 0.667 85_01.nc 85_04.nc 85_02.nc
ncflint -w 0.667,0.333 85_01.nc 85_04.nc 85_02.nc
</pre></example>

<para>Multiply <file>85.nc</file> <w>by 3</w> and <w>by &minus;2</w> and add them
together to make <file>tst.nc</file>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncflint -w 3,-2 85.nc 85.nc tst.nc
</pre></example>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2066">null operation</indexterm></cindex>
<para>This is an example of a null operation, so <file>tst.nc</file> should be
identical (within machine precision) to <file>85.nc</file>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2067">multiplication</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2068">file multiplication</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2069">scaling</indexterm></cindex>
<para>Multiply all the variables except the coordinate variables in the file
<file>emissions.nc</file> by <w>by 0.8</w>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncflint --fix_rec_crd -w 0.8,0.0 emissions.nc emissions.nc scaled_emissions.nc
</pre></example>
<noindent></noindent>
<para>The use of <samp>--fix_rec_crd</samp> ensures, e.g., that the <code>time</code>
coordinate, if any, is not scaled (i.e., multiplied).
</para>
<para>Add <file>85.nc</file> to <file>86.nc</file> to obtain <file>85p86.nc</file>,
then subtract <file>86.nc</file> from <file>85.nc</file> to obtain <file>85m86.nc</file> 
</para><example endspaces=" ">
<pre xml:space="preserve">ncflint -w 1,1 85.nc 86.nc 85p86.nc
ncflint -w 1,-1 85.nc 86.nc 85m86.nc
ncdiff 85.nc 86.nc 85m86.nc
</pre></example>
<noindent></noindent>
<para>Thus <command>ncflint</command> can be used to mimic some <command>ncbo</command>
operations. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2070">broadcasting variables</indexterm></cindex>
However this is not a good idea in practice because <command>ncflint</command>
does not broadcast (<pxref label="ncbo-netCDF-Binary-Operator"><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></pxref>) conforming
variables during arithmetic. 
Thus the final two commands would produce identical results except that    
<command>ncflint</command> would fail if any variables needed to be broadcast.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2071"><code>units</code></indexterm></cindex>
<para>Rescale the dimensional units of the surface pressure <code>prs_sfc</code>
from Pascals to hectopascals (millibars)
</para><example endspaces=" ">
<pre xml:space="preserve">ncflint -C -v prs_sfc -w 0.01,0.0 in.nc in.nc out.nc
ncatted -a units,prs_sfc,o,c,millibar out.nc
</pre></example>
<noindent></noindent>

<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncks&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncks --&gt;
</html>
</section>
<node name="ncks-netCDF-Kitchen-Sink" spaces=" "><nodename>ncks netCDF Kitchen Sink</nodename><nodenext spaces=" ">ncpdq netCDF Permute Dimensions Quickly</nodenext><nodeprev spaces=" ">ncflint netCDF File Interpolator</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncks</command> netCDF Kitchen Sink</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2072">kitchen sink</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2073">printing files contents</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2074">printing variables</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="36" mergedindex="cp">ncks</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncks [-3] [-4] [-5] [-6] [-7] [-A] [-a] [--area_wgt] [-b <var>fl_bnr</var>]
[-C] [-c] [--cdl] [--chk_bnd] [--chk_chr] [--chk_map] [--chk_mss] [--chk_nan] [--chk_xtn]
[--cmp <var>cmp_sng</var>] [--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]
[-F] [--fix_rec_dmn <var>dim</var>] [--fl_fmt <var>fl_fmt</var>] [--fmt_val <var>format</var>]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...] [--grp_xtr_var_xcl]
[-H] [-h] [--hdn] [--hdr_pad <var>nbr</var>] [--hpss] [--hrz <var>fl_hrz</var>] [--jsn] [--jsn_fmt <var>lvl</var>] 
[-L <var>dfl_lvl</var>] [-l <var>path</var>]
[-M] [-m] [--map <var>map-file</var>] [--md5] [--mk_rec_dmn <var>dim</var>]
[--no_blank] [--no_cll_msr] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>output-file</var>] [-P] [-p <var>path</var>] [--prn_fl <var>print-file</var>]
[-Q] [-q] [--qnt ...] [--qnt_alg <var>alg_nm</var>]
[-R] [-r] [--rad] [--ram_all] [--rgr ...] [--rnr=wgt]
[-s <var>format</var>] [--s1d] [-u] [--unn] [-V] [-v <var>var</var>[,&dots;]] [--vrt <var>vrt-file</var>] 
[-X ...] [-x] [--xml] <var>input-file</var> [[<var>output-file</var>]]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2075"><command>ncextr</command></indexterm></cindex>
<para>The nickname &textldquo;kitchen sink&textrdquo; is a catch-all because <command>ncks</command>
combines most features of <command>ncdump</command> and <command>nccopy</command> with
extra features to extract, hyperslab, multi-slab, sub-set, and translate  
into one versatile utility. 
<command>ncks</command> extracts (a subset of the) data from <var>input-file</var>,
regrids it according to <var>map-file</var> if specified,
then writes in netCDF format to <var>output-file</var>, and 
optionally writes it in flat binary format to <file>fl_bnr</file>, and
optionally prints it to screen.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2076"><code>--trd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2077"><code>--traditional</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2078">traditional</indexterm></cindex>
<para><command>ncks</command> prints netCDF input data in <acronym><acronymword>ASCII</acronymword></acronym>,
<acronym><acronymword>CDL</acronymword></acronym>, <acronym><acronymword>JSON</acronymword></acronym>, or <acronym><acronymword>NcML/XML</acronymword></acronym> text formats to
<code>stdout</code>, like (an extended version of) <command>ncdump</command>.
By default <command>ncks</command> prints <acronym><acronymword>CDL</acronymword></acronym> format.
Option <samp>-s</samp> (or long options <samp>--sng_fmt</samp> and <samp>--string</samp>) 
permits the user to format data using C-style format strings, while
option <samp>--cdl</samp> outputs <acronym><acronymword>CDL</acronymword></acronym>,
option <samp>--jsn</samp> (or <samp>json</samp>) outputs <acronym><acronymword>JSON</acronymword></acronym>,
option <samp>--trd</samp> (or <samp>traditional</samp>) outputs &textldquo;traditional&textrdquo; format,
and option <samp>--xml</samp> (or <samp>ncml</samp>) outputs <acronym><acronymword>NcML</acronymword></acronym>. 
The &textldquo;traditional&textrdquo; tabular format is intended to be
easy to search for the data you want, one datum per screen line, with
all dimension subscripts and coordinate values (if any) preceding the
datum. 
<command>ncks</command> exposes many flexible controls over printed output,
including <acronym><acronymword>CDL</acronymword></acronym>, <acronym><acronymword>JSON</acronymword></acronym>, and <acronym><acronymword>NcML</acronymword></acronym>.
</para>
<para>Options <samp>-a</samp>, <samp>--cdl</samp>, <samp>-F</samp>, <samp>--fmt_val</samp>, <samp>-H</samp>,
<samp>--hdn</samp>, <samp>--jsn</samp>, <samp>-M</samp>, <samp>-m</samp>, <samp>-P</samp>,
<samp>--prn_fl</samp>, <samp>-Q</samp>, <samp>-q</samp>, <samp>-s</samp>, <samp>--trd</samp>,
<samp>-u</samp>, <samp>-V</samp>, and <samp>--xml</samp> (and their long option
counterparts) control the presence of data and metadata and their
formatted location and appearance when printed. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2079">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2080">attributes, global</indexterm></cindex>
<para><command>ncks</command> extracts (and optionally creates a new netCDF file
comprised of) only selected variables from the input file
(similar to the old <command>ncextr</command> specification).
Only variables and coordinates may be specifically included or
excluded&textmdash;all global attributes and any attribute associated with an
extracted variable are copied to the screen and/or output netCDF file. 
Options <samp>-c</samp>, <samp>-C</samp>, <samp>-v</samp>, and <samp>-x</samp> (and their long 
option synonyms) control which variables are extracted.
</para>
<para><command>ncks</command> extracts hyperslabs from the specified variables
(<command>ncks</command> implements the original <command>nccut</command> specification). 
Option <samp>-d</samp> controls the hyperslab specification.
Input dimensions that are not associated with any output variable do
not appear in the output netCDF.
This feature removes superfluous dimensions from netCDF files. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2081">appending data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2082">merging files</indexterm></cindex>
<para><command>ncks</command> will append variables and attributes from the
<var>input-file</var> to <var>output-file</var> if <var>output-file</var> is a
pre-existing netCDF file whose relevant dimensions conform to dimension
sizes of <var>input-file</var>. 
The append features of <command>ncks</command> are intended to provide a
rudimentary means of adding data from one netCDF file to another,
conforming, netCDF file. 
If naming conflicts exist between the two files, data in
<var>output-file</var> is usually overwritten by the corresponding data from 
<var>input-file</var>.  
Thus, when appending, the user should backup <var>output-file</var> in case 
valuable data are inadvertantly overwritten.
</para>
<para>If <var>output-file</var> exists, the user will be queried whether to
<dfn>overwrite</dfn>, <dfn>append</dfn>, or <dfn>exit</dfn> the <command>ncks</command> call
completely.  
Choosing <dfn>overwrite</dfn> destroys the existing <var>output-file</var> and
create an entirely new one from the output of the <command>ncks</command> call.  
Append has differing effects depending on the uniqueness of the
variables and attributes output by <command>ncks</command>: If a variable or
attribute extracted from <var>input-file</var> does not have a name conflict
with the members of <var>output-file</var> then it will be added to
<var>output-file</var> without overwriting any of the existing contents of
<var>output-file</var>.  
In this case the relevant dimensions must agree (conform) between the
two files; new dimensions are created in <var>output-file</var> as required. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2083">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2084">attributes, global</indexterm></cindex>
When a name conflict occurs, a global attribute from <var>input-file</var>
will overwrite the corresponding global attribute from
<var>output-file</var>.  
If the name conflict occurs for a non-record variable, then the
dimensions and type of the variable (and of its coordinate dimensions,
if any) must agree (conform) in both files. 
Then the variable values (and any coordinate dimension values)
from <var>input-file</var> will overwrite the corresponding variable values
(and coordinate dimension values, if any) in <var>output-file</var> 
<footnote spaces="\n"><para>Those familiar with netCDF mechanics might wish to know what is
happening here: <command>ncks</command> does not attempt to redefine the variable
in <var>output-file</var> to match its definition in <var>input-file</var>,
<command>ncks</command> merely copies the values of the variable and its
coordinate dimensions, if any, from <var>input-file</var> to
<var>output-file</var>. 
</para></footnote>.
</para>
<para>Since there can only be one record dimension in a file, the record
dimension must have the same name (though not necessarily the same size) in 
both files if a record dimension variable is to be appended. 
If the record dimensions are of differing sizes, the record dimension of
<var>output-file</var> will become the greater of the two record dimension
sizes, the record variable from <var>input-file</var> will overwrite any
counterpart in <var>output-file</var> and fill values will be written to any
gaps left in the rest of the record variables (I think). 
In all cases variable attributes in <var>output-file</var> are superseded by
attributes of the same name from <var>input-file</var>, and left alone if
there is no name conflict. 
</para>
<para>Some users may wish to avoid interactive <command>ncks</command> queries about
whether to overwrite existing data.
For example, batch scripts will fail if <command>ncks</command> does not receive 
responses to its queries. 
Options <samp>-O</samp> and <samp>-A</samp> are available to force overwriting
existing files, and appending existing variables, respectively. 
</para>
<unnumberedsubsec spaces=" "><sectiontitle>Options specific to <command>ncks</command></sectiontitle>

<para>The following summarizes features unique to <command>ncks</command>.  
Features common to many operators are described in 
<ref label="Shared-features"><xrefnodename>Shared features</xrefnodename></ref>. 
</para>
<table commandarg="samp" spaces=" " endspaces=" ">
<beforefirstitem>
<html endspaces=" ">
&lt;a name=&quot;abc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#abc --&gt;
&lt;a name=&quot;alphabetize&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alphabetize --&gt;
</html>
</beforefirstitem><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2085">alphabetization</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2086">sort alphabetically</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2087"><code>--abc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2088"><code>--alphabetize</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2089"><code>--no_abc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2090"><code>--no_alphabetize</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2091"><code>--no-abc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2092"><code>--no-alphabetize</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-a</itemformat></item>
</tableterm><tableitem><para>Switches <samp>-a</samp>, <samp>--abc</samp>, and <samp>--alphabetize</samp>
<emph>turn-off</emph> the default alphbetization of extracted fields in
<command>ncks</command> only.
These switches are misleadingly named and were deprecated in
<command>ncks</command> as of <acronym><acronymword>NCO</acronymword></acronym> version 4.7.1 (December, 2017).  
</para>
<para>This is the default behavior so these switches are no-ops included only
for completeness.
By default, <acronym><acronymword>NCO</acronymword></acronym> extracts, prints, and writes specified output
variables to disk in alphabetical order. 
This tends to make long output lists easier to search for particular
variables. 
Again, no option is necessary to write output in alphabetical order.
Until <acronym><acronymword>NCO</acronymword></acronym> version 4.7.1 (December, 2017), <command>ncks</command>
used the <code>-a</code>, <code>--abc</code>, or <code>--alphabetize</code> switches to
<emph>turn-off</emph> the default alphabetization.
These names were counter-intuitive and needlessly confusing.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.7.1, <command>ncks</command> uses the new switches
<code>--no_abc</code>, <code>--no-abc</code>, <code>--no_alphabetize</code>, or
<code>--no-alphabetize</code>, all of which are equivalent.
The <code>--abc</code> and <code>--alphabetize</code> switches are now no-ops,
i.e., they write the output in the unsorted order of the input.
The <code>-a</code> switch is now completely deprecated in favor of the
clearer long option switches.
</para>
<html endspaces=" ">
&lt;a name=&quot;bnr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bnr --&gt;
&lt;a name=&quot;binary&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#binary --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2093">binary format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2094"><code>-b</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2095"><code>--fl_bnr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2096"><code>--bnr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2097"><code>--binary</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-b <file>file</file></itemformat></item>
</tableterm><tableitem><para>Activate native machine binary output writing to binary file
<file>file</file>.
Also <samp>--fl_bnr</samp> and <samp>--binary-file</samp>.
Writing packed variables in binary format is not supported.
Metadata is never output to the binary file.
Examine the netCDF output file to see the variables in the binary file. 
Use the <samp>-C</samp> switch, if necessary, to avoid wanting unwanted
coordinates to the binary file:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -O -v one_dmn_rec_var -b bnr.dat -p ~/nco/data in.nc out.nc
% ls -l bnr.dat | cut -d ' ' -f 5 # 200 B contains time and one_dmn_rec_var
200
% ls -l bnr.dat
% ncks -C -O -v one_dmn_rec_var -b bnr.dat -p ~/nco/data in.nc out.nc
% ls -l bnr.dat | cut -d ' ' -f # 40 B contains one_dmn_rec_var only
40
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;cal&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cal --&gt;
&lt;a name=&quot;cln&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cln --&gt;
&lt;a name=&quot;date_format&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#date_format --&gt;
&lt;a name=&quot;dt_fmt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dt_fmt --&gt;
&lt;a name=&quot;calendar&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#calendar --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2098">calendar dates</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2099">date formats</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2100">Gregorian dates</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2101"><code>--calendar</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2102"><code>--cln_lgb</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2103"><code>--prn_lgb</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2104"><code>--dt_fmt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2105"><code>--date_format</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2106"><code>--datestamp</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--cal </itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.5 (March, 2017), <command>ncks</command> can
print human-legible calendar strings corresponding to time values with 
UDUnits-compatible date units of the form time-since-basetime, e.g.,
<samp>days since 2000-01-01</samp> and a <acronym><acronymword>CF</acronymword></acronym> calendar attribute, if
any. 
Enact this with the <samp>--calendar</samp> (also <samp>--cln</samp>,
<samp>--prn_lgb</samp>, and <samp>--datestamp</samp>) option when printing in any mode.
Invoking this option when <math><var>dbg_lvl</var> &gt;= 1</math> in <acronym><acronymword>CDL</acronymword></acronym>
mode prints both the value and the calendar string (one in comments):
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@aerosol:~$ ncks -D 1 --cal -v tm_365 ~/nco/data/in.nc
...
  variables:
    double tm_365 ;
      tm_365:units = &quot;days since 2013-01-01&quot; ; // char
      tm_365:calendar = &quot;365_day&quot; ; // char

  data:
    tm_365 = &quot;2013-03-01&quot;; // double value: 59
...
zender@aerosol:~$ ncks -D 1 -v tm_365 ~/nco/data/in.nc
...
    tm_365 = 59; // calendar format: &quot;2013-03-01&quot;
...
</verbatim>
</example>
<para>This option is similar to the <command>ncdump</command> <samp>-t</samp> option.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.8 (August, 2017), <command>ncks</command> 
<acronym><acronymword>CDL</acronymword></acronym> printing supports finer-grained control of date formats
with the <samp>--dt_fmt=<var>dt_fmt</var></samp> (or <samp>--date_format</samp>) option. 
The <var>dt_fmt</var> is an enumerated integer from 0&textndash;3.
Values <math><var>dt_fmt</var>=0</math> or 1 correspond to the short format for
dates that are the default.
The value <math><var>dt_fmt</var>=2</math> requests the &textldquo;regular&textrdquo; format for
dates, <math><var>dt_fmt</var>=3</math> requests the full <acronym><acronymword>ISO</acronymword></acronym>-8601 format
with the &textldquo;T&textrdquo; separator and the comma:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -H -m -v time_bnds -C --dt_fmt=value ~/nco/data/in.nc
# Value:    Output:
# 0,1       1964-03-13 09:08:16        # Default, short format
# 2         1964-03-13 09:08:16.000000 # Regular format
# 3         1964-03-13T09:08:16.000000 # ISO8601 'T' format
</verbatim>
</example>
<para>Note that <samp>--dt_fmt</samp> automatically implies <samp>--cal</samp>
makes that options superfluous.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.4 (September, 2020), invoking
the <samp>--dt_fmt</samp> option now applies equally well to <acronym><acronymword>JSON</acronymword></acronym>
and <acronym><acronymword>XML</acronymword></acronym> output as to <acronym><acronymword>CDL</acronymword></acronym> output:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -d time,0 -v time --cdl --dt_fmt=3 ~/nco/data/in.nc
...
time = &quot;1964-03-13T21:09:0.000000&quot; ;
...
% ncks -d time,0 -v time --json --dt_fmt=3 ~/nco/data/in.nc
...
&quot;data&quot;: [&quot;1964-03-13T21:09:0.000000&quot;]
...
% ncks -d time,0 -v time --xml --dt_fmt=3 ~/nco/data/in.nc
...
&lt;ncml:values separator=&quot;*&quot;&gt;1964-03-13T21:09:0.000000&lt;/ncml:values&gt;
...
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;chk_map&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chk_map --&gt;
&lt;a name=&quot;area_wgt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#area_wgt --&gt;
&lt;a name=&quot;frac_b_nrm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#frac_b_nrm --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2107"><code>--area_wgt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2108"><code>--chk_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2109"><code>--frac_b_nrm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2110">map-file</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--chk_map</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.0 (December, 2019), invoking
<samp>--chk_map</samp> causes <command>ncks</command> to evaluate the quality of
regridding weights in the map-file provided as <var>input-file</var>.
This option works with map-files (not grid-files) in
<acronym><acronymword>ESMF</acronymword></acronym>/<acronym><acronymword>CMIP6</acronymword></acronym>-compliant format (i.e., a sparse matrix
variable named <code>S</code> and coordinates <code>[xy][ab]_[cv]</code>.
When invoked with the additional <samp>--area_wgt</samp> option, the
evaluation statistics are area-weighted and thus exactly represent
the global-mean/min/max/mebs/rms/sdn biases expected when regridding a
globally uniform field.
This tool makes it easier to objectively assess weight-generation
algorithms, and will hopefully assist in their improvement.
Thanks to Mark Taylor of Saturday Night Live (<acronym><acronymword>SNL</acronymword></acronym>) and Paul 
Ullrich of UC Davis for this suggestion and early prototypes.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
$ ncks --chk_map map.nc            # Unweighted statistics
$ ncks --chk_map --dbg=2 map.nc    # Additional diagnostics
$ ncks --chk_map --area_wgt map.nc # Area-weighted statistics
</verbatim>
</example>

<para>The map-checker performs numerous checks and reports numerous
statistics, probably more than you care about. 
Be assured that each piece of provided information has in the past
proved useful to developers of weight-generation and regridding
algorithms.
Most of the time, users can learn whether the examined map is of
sufficient quality for their purposes by examing only a few of these
statistics.
Before defining these primary statistics, it is helpful to understand
the meaning of the weight-array <var>S</var> (stored in a map-file as the
variable <code>S</code>), and the terminology of rows and columns.
</para>
<para>A remapping (aka regridding) transforms a field on an input grid to an
an output grid while conserving to the extent possible or desired the
local and global properties of the field.
The map <var>S</var> is a matrix of <var>M</var> rows and <var>N</var> columns of
weights, where <var>M</var> is the number of gridcells (or degrees of
freedom, <acronym><acronymword>DOF</acronymword></acronym>s) in the destination grid, and <var>N</var> is the
number of gridcells (or <acronym><acronymword>DOFs</acronymword></acronym>) in the source grid. 
An individual weight <var>S</var>(<var>m</var>,<var>n</var>) represents the
fractional contribution to destination gridcell <var>m</var> by source
gridcell <var>n</var>. 
By convention the weights are normalized to sum to unity in each row 
(destination gridcell) that completely overlaps the input grid.
Thus the weights in a single row are all equivalent to the fractional
destination areas that the same destination gridcell (we will drop the
<acronym><acronymword>DOF</acronymword></acronym> terminology hereafter for conciseness) receives from
each source gridcell. 
Regardless of the values of the individual weights, it is intuitive
that their row-sum should never exceed unity because that would be
physically equivalent to an output gridcell receiving more than its
own area from the source grid.
Map-files typically store these row-sum statistics for each
destination gridcell in the <code>frac_b</code> variable described further
below. 
</para>
<para>Likewise the weights in a single column represent the fractional
destination areas that a single source gridcell contributes to  
every output gridcell.
Each output gridcell in a column may have a different area so
column-sums need not, and in general do not, sum to unity.
However, a source gridcell ought to contribute to the destination
grid a total area equal to its own area.
Thus a constraint on column-sums is that their weights, themselves
weighted by the destination gridcell area corresponding to each row,
should sum exactly to the source gridcell area.
In other words, the destination-area-weighted column-sum divided by
the source gridcell area would be unity (in a perfect first order
map) for every source gridcell that completely overlaps valid
destination gridcells.  
Map-files typically store these area-weighted-column-sum-ratio
statistics for each gridcell in the <code>frac_a</code> variable described
further below.  
</para>
<para>Storing the entire weight-matrix <b>S</b> is unnecessary because only a
relative handful of gridcells in the source grid contribute to a given 
destination gridcell, and visa versa.
Instead, map-files store only the non-zero <var>S</var>(<var>m</var>,<var>n</var>),
and encode them as a sparse-matrix.
Storing <b>S</b> as a sparse matrix rather than a full matrix reduces
overall storage sizes by a factor on the order of the ratio of the
product of the grid sizes to their sum, or about 10,000 for grids with
horizontal resolution near one degree, and more for finer resolutions.
The sparse-matrix representation is a one-dimensional array of weights 
<code>S</code>, together with two ancillary arrays, <code>row</code>
and <code>column</code>, that contain the one-dimensional row and column
indices, respectively, corresponding to the destination and source
gridcells of the associated weight.
By convention, map-files store the row and column indices using the
1-based convention in common use in the 1990s when regridding software
was all written in Fortran.
The map-checker prints cell locations with 1-based indices as well:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --chk_map map_ne30np4_to_cmip6_180x360_nco.20190601.nc
Characterization of map-file map_ne30np4_to_cmip6_180x360_nco.20190601.nc
Cell triplet elements : [Fortran (1-based) index, center latitude, center longitude]
Sparse matrix size n_s: 246659
Weight min S(190813):  5.1827201764857658e-25 from cell \
                       [33796,-45.7998,+136.437] to [15975,-45.5,+134.5]
Weight max S( 67391):  1.0000000000000000e+00 from cell \
                       [33671,-54.4442,+189.645] to [12790,-54.5,+189.5]
Ignored weights (S=0.0): 0
...
</verbatim>
</example>
<para>Here the map-file weights span twenty-five orders of magnitude.
This may seem large though in practice is typical for high-resolution
intersection grids.
The Fortran-convention index of each weight extreme is followed by 
its geographic latitude and longitude.
Reporting the locations of extrema, and of gridcells whose metrics
miss their target values by more than a specificied tolerance, are
prime map-checker features.
</para>
<para>As mentioned above, the two statistics most telling about map quality 
are the weighted column-sums <var>frac_a</var> and the row-sums <var>frac_b</var>.
The short-hand names for what these metrics quantify are
Conservation and Consistency, respectively. 
Conservation means the total fraction of an input gridcell that
contributes to the output grid.
For global input and output grids that completely tile the sphere,
the entirety of each input gridcell should contribute (i.e., map to)
the output grid.
The same concept that applies locally to conservation of a gridcell
value applies globally to the overall conservation of an input field.
Thus a perfectly conservative mapping between global grids that tile
the sphere would have <math><var>frac_a</var> = 1.0</math> for every input
gridcell, and for the mean of all input gridcells.
</para>
<para>The map-checker computes Conservation (<var>frac_a</var>) from the stored
variables <code>S</code>, <code>row</code>, <code>column</code>, <code>area_a</code>, and
<code>area_b</code> in the map-file, and then compares those values to the
<code>frac_a</code> values (if any) on-disk, and warns of any disagreements
<footnote spaces="\n"><para>As of <w>version 5.1.1</w> (November 2022), the map checker diagnoses
from the global attributes <code>map_method</code>, <code>no_conserve</code>,
or <code>noconserve</code> (in that order, if present) whether the mapping
weights are intended to be conservative (as opposed to, e.g.,
bilinear). 
Weights deemed non-conservative by design are no longer flagged with
dire <emph>WARNING</emph> messages.</para></footnote>. 
By definition, conservation is perfect to first order if the sum of
the destination-gridcell-area-weighted weights (which is an area)
equals the source gridcell area, and so their ratio (<var>frac_a</var>) is
unity.
Computing the area-weighted-column-sum-ratios and comparing those
<var>frac_a</var> to the stored <code>frac_a</code> catches any discrepancies. 
The analysis sounds an alarm when discrepancies exceed a tolerance
(currently 5.0e-16).  
More importantly, the map-checker reports the summary statistics of
the computed <var>frac_a</var> metrics and their imputed errors, including
the grid mean, minimum, maximum, mean-absolute bias, root-mean-square
bias, and standard deviation.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --chk_map map_ne30np4_to_cmip6_180x360_nco.20190601.nc
...
Conservation metrics (column-sums of area_b-weighted weights normalized by area_a) and errors---
Perfect metrics for global Grid B are avg = min = max = 1.0, mbs = rms = sdn = 0.0:
frac_a avg: 1.0000000000000000 = 1.0-0.0e+00 // Mean
frac_a min: 0.9999999999991109 = 1.0-8.9e-13 // Minimum in grid A cell [45328,+77.3747,+225]
frac_a max: 1.0000000000002398 = 1.0+2.4e-13 // Maximum in grid A cell [47582,+49.8351,+135]
frac_a mbs: 0.0000000000000096 =     9.6e-15 // Mean absolute bias from 1.0
frac_a rms: 0.0000000000000167 =     1.7e-14 // RMS relative to 1.0
frac_a sdn: 0.0000000000000167 =     1.7e-14 // Standard deviation
...
</verbatim>
</example>
<para>The values of the <code>frac_a</code> metric are generally imperfect (not
1.0) for global grids.
The bias is the deviation from the target metric shown in the second
floating-point column in each row above (e.g., 8.9e-13). 
These biases should be vanishingly small with respect to unity.
Mean biases as large as 1.0e-08 may be considered acceptable for
off-line analyses (i.e., a single regridding of raw data) though the
acceptable tolerance should be more stringent for on-line use such as
in a coupler where forward and reverse mappings may be applied tens of 
thousands of times.
The mean biases for such on-line regridding should be close to 1.0e-15
in order for tens-of-thousands of repetitions to still conserve
mass/energy to full double-precision.
</para>
<para>The minimum and maximum gridcell biases indicate the worst performing
locations of the mapping.
These are generally much (a few orders of magnitude) greater than the
mean biases.
Observe that the minimum and maximum biases in the examples above
and below occur at longitudes that are multiples of <w>45 degrees</w>.
This is characteristic of mappings to/from for cube-square grids
whose faces have edges, and thus additional complexity, at multiples
of <w>45 degrees</w>.
This illustrates how intersection grid geometry influences biases.
More complex, finer-scale structures, produce greater biases.
The Root-Mean-Square (<acronym><acronymword>RMS</acronymword></acronym>) and standard deviation metrics
characterize the distribution of biases throughout the entire
intersection grid, and are thus complementary information to the
minimum and maximum biases. 
</para>
<para>Consistency expresses the total fraction of an output gridcell that
receives contributions from the input grid. 
Thus Consistency is directly analogous to Conservation, only applied
to the output grid. 
Conservation is the extent to which the mapping preserves the local
and grid-wide integrals of input fields, while Consistency is the
extent to which the mapping correctly aligns the input and output
grids so that each destination cell receives the appropriate
proportion of the input integrals.
The mapping will produce an acceptably faithful reproduction of the
input on the output grid only if all local and global Conservation and
Consistency metrics meet the acceptable error tolerances. 
</para>
<para>The map-checker computes the Consistency (<var>frac_b</var>) as row-sums of 
the weights stored in <code>S</code> and compares these to the stored values
of <code>frac_b</code>. 
(Note how the definition of weights <var>S</var>(<var>m</var>,<var>n</var>) as the
fractional contribution to destination gridcell <var>m</var> by source
gridcell <var>n</var> makes calculation of <var>frac_b</var> almost trivial in
comparison to <var>frac_a</var>). 
Nevertheless, <code>frac_b</code> in the file may differ from the computed
row-sum for example if the map-file generator artificially limits the
stored <code>frac_b</code> value for any cell <w>to 1.0</w> for those row-sums
that <w>exceed 1.0</w>.  
The map-checker raises an alarm when discrepancies between computed
and stored <code>frac_b</code> exceed a tolerance (currently 5.0e-16).  
There are semi-valid reasons a map-generator might do this, so this
does not necessarily indicate an error.
The alarm simply informs the user that applying the weights will lead
to a slightly different Consistency than indicated by the stored
<code>frac_b</code>.
</para>
<para>As with <code>frac_a</code>, the values of <code>frac_b</code> are generally
imperfect <w>(not 1.0)</w> for global grids:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --chk_map map_ne30np4_to_cmip6_180x360_nco.20190601.nc
...
Consistency metrics (row-sums of weights) and errors---
Perfect metrics for global Grid A are avg = min = max = 1.0, mbs = rms = sdn = 0.0:
frac_b avg: 0.9999999999999999 = 1.0-1.1e-16 // Mean
frac_b min: 0.9999999999985523 = 1.0-1.4e-12 // Minimum in grid B cell [59446,+75.5,+45.5]
frac_b max: 1.0000000000004521 = 1.0+4.5e-13 // Maximum in grid B cell [63766,+87.5,+45.5]
frac_b mbs: 0.0000000000000065 =     6.5e-15 // Mean absolute bias from 1.0
frac_b rms: 0.0000000000000190 =     1.9e-14 // RMS relative to 1.0
frac_b sdn: 0.0000000000000190 =     1.9e-14 // Standard deviation
...
</verbatim>
</example>
<para>This example shows that <var>frac_b</var> has the greatest local errors
at similar boundaries (multiples of <w>45 degrees</w> longitude) as
<var>frac_a</var>. It is typical for Conservation and Consistency to
degrade in intricate areas of the intersection grid, and these
areas occur at multiples of <w>45 degrees</w> longitude for cubed-sphere 
mappings. 
</para>
<para>The map-checker will produce area-weighted metrics when invoked
with the <code>--area_wgt</code> flag, e.g.,
<samp>ncks --area_wgt in.nc</samp>.
Area-weighted statistics show the exact local and global results to
expect with real-world grids in which large consistency/conservation
errors in small gridcells may be less important than smaller errors in
larger gridcells. 
Global-weighted mean statistics will of course differ from unweighted
statistics, although the minimum and maximum do not change:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --area_wgt map_ne30np4_to_cmip6_180x360_nco.20190601.nc
...
Conservation metrics (column-sums of area_b-weighted weights normalized by area_a) and errors---
Perfect metrics for global Grid B are avg = min = max = 1.0, mbs = rms = sdn = 0.0:
frac_a avg: 1.0000000000000009 = 1.0+8.9e-16 // Area-weighted mean
frac_a min: 0.9999999999999236 = 1.0-7.6e-14 // Minimum in grid A cell [12810,+3.44654,+293.25]
frac_a max: 1.0000000000001146 = 1.0+1.1e-13 // Maximum in grid A cell [16203,-45.7267,+272.31]
frac_a mbs: 0.0000000000000067 =     6.7e-15 // Area-weighted mean absolute bias from 1.0
frac_a rms: 0.0000000000000102 =     1.0e-14 // Area-weighted RMS relative to 1.0
frac_a sdn: 0.0000000000000103 =     1.0e-14 // Standard deviation

Consistency metrics (row-sums of weights) and errors---
Perfect metrics for global Grid A are avg = min = max = 1.0, mbs = rms = sdn = 0.0:
frac_b avg: 1.0000000000000047 = 1.0+4.7e-15 // Area-weighted mean
frac_b min: 0.9999999999998442 = 1.0-1.6e-13 // Minimum in grid B cell [48415,+44.5,+174.5]
frac_b max: 1.0000000000002611 = 1.0+2.6e-13 // Maximum in grid B cell [16558,-44.5,+357.5]
frac_b mbs: 0.0000000000000065 =     6.5e-15 // Area-weighted mean absolute bias from 1.0
frac_b rms: 0.0000000000000129 =     1.3e-14 // Area-weighted RMS relative to 1.0
frac_b sdn: 0.0000000000000133 =     1.3e-14 // Standard deviation
...
</verbatim>
</example>
<para>The examples above show no outstanding differences (besides rounding) 
between the unweighted and area-weighted statistics.
The absence of degradation between the global unweighted statistics
(further up the page) and the global weighted statistics (just above)
demonstrates there are no important correlations between local weight
biases and gridcell areas.
The area-weighted mean <var>frac_b</var> statistic deserves special
mention.
Its value is the exact factor by which the mapping will shift the
global mean of a spatially uniform input field.
This metric is, therefore, first among equals when evaluating 
the quality of maps under consideration for use in time-stepping
models where global conservation (e.g., of mass or energy) is
crucial. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2111"><code>--frac_b_nrm</code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.2 (March, 2020), adding the
<samp>--frac_b_nrm</samp> flag changes the map-checker into a read-write
algorithm that first diagnoses the map-file statistics described
above and then re-writes the weights (and weight-derived statistics
<var>frac_a</var> and <var>frac_b</var>) to compensate or &textldquo;fix&textrdquo; issues
that poor-quality input grids can cause.
Input grids can and often do have regions that are not tiled by
any portion of any input gridcell.
For example, many <acronym><acronymword>FV</acronymword></acronym> ocean grids (such as <acronym><acronymword>MPAS</acronymword></acronym>)
are empty (have no gridcells) in land regions beyond the coasts.
Some <acronym><acronymword>FV</acronymword></acronym> ocean grids have gridcells everywhere and mask
(i.e., screen-out) the non-ocean gridcells by setting the mask value
to zero.
Both these designs are perfectly legal.
What is illegal, yet sometimes encountered in practice, is overlapping
gridcells on the same input grid.
Such an input grid is said to be self-overlapping.
</para>
<para>The surface topography dataset grid
<file>SCRIPgrid_1km-merge-10min_HYDRO1K-merge-nomask_c130402.nc</file>
(hereafter the <acronym><acronymword>HYDRO1K</acronymword></acronym> grid for short) used by
<acronym><acronymword>E3SM</acronymword></acronym> and <acronym><acronymword>CESM</acronymword></acronym> is self-overlapping.
Weight-generators that receive the same input location twice might
(if they do not take precaustions to idenfity the issue, which no
known weight-generators do) double-weight the self-overlapped
region(s).
In other words, self-overlapping input grids can lead
weight-generators to produce values <math><var>frac_b</var> &gt;&gt; 1.0</math>.
Applying these weights would lead to exaggerated values on the
destination grid.
</para>
<para>The best solution to this issue is to adjust the input grid to
avoid self-overlap.
However, this solution may be difficult or impractical where the
original data, producer, or algorithm are unavailable or unclear.
In such cases, the <code>--frac_b_nrm</code> flag provides a workaround. 
Please understand that <samp>ncks --frac_b_nrm map.nc</samp> is designed to
alter <file>map.nc</file> in-xsplace, so backup the original file first.
<!-- c ncks -frac_b_nrm $DATA/maps/map_hydro1k_to_ne1024np4_nco.20200301.nc > foo 2>&1 -->
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --frac_b_nrm map_hydro1k_to_ne1024np4_nco.20200301.nc
...
...
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;chk_bnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chk_bnd --&gt;
&lt;a name=&quot;check_bounds&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#check_bounds --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2112"><code>--chk_bnd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2113"><code>--check_bounds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2114"><code>bounds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2115"><acronym><acronymword>CF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2116"><acronym><acronymword>DIWG</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--chk_bnd</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 5.2.0 (February, 2022), <command>ncks</command>
can report all coordinates that lack a corresponding
<code>bounds</code> attribute.
This check complies with <acronym><acronymword>CF</acronymword></acronym> Conventions and with
<acronym><acronymword>NASA</acronymword></acronym>&textrsquo;s Dataset Interoperability Working Group 
(<uref><urefurl>https://wiki.earthdata.nasa.gov/display/ESDSWG/Dataset+Interoperability+Working+Group</urefurl><urefdesc spaces="\n">DIWG</urefdesc></uref>).
<acronym><acronymword>CF</acronymword></acronym> requires that coordinate variables that describe
a continuous (not discrete) axis contain a &textldquo;bounds&textrdquo; attribute
that points to a variable marking the edges of each gridcell
(in time, space, or other dimensions).
This option reports which coordinates lack the required
<code>bounds</code> attribute, so that a file can be easily
checked for compliance with the convention:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
$ ncks --chk_bnd in.nc
ncks: WARNING nco_chk_bnd() reports coordinate Lat does not contain &quot;bounds&quot; attribute
ncks: WARNING nco_chk_bnd() reports coordinate Lon does not contain &quot;bounds&quot; attribute
ncks: INFO nco_chk_bnd() reports total number of coordinates without &quot;bounds&quot; attribute is 2
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;chk_chr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chk_chr --&gt;
&lt;a name=&quot;check_char&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#check_char --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2117"><code>--chk_chr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2118"><code>--check_char</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2119"><code>missing_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2120"><acronym><acronymword>CF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2121"><acronym><acronymword>DIWG</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--chk_chr</itemformat></item>
</tableterm><tableitem><para>The <emph>identifiers</emph> in a netCDF file are the set of dimension,
group, variable, and attribute names it contains.
As of <acronym><acronymword>NCO</acronymword></acronym> version 5.1.8 (September, 2023), <command>ncks</command>
can report all identifiers that violate the <acronym><acronymword>CF</acronymword></acronym> Convention
that identifiers &textldquo;should begin with a letter and be composed of
letters, digits, and underscores.&textrdquo;
System or library-defined identifiers (such as <code>_FillValue</code>)
are not subject to this (user-land) rule.
<acronym><acronymword>NASA</acronymword></acronym>&textrsquo;s Dataset Interoperability Working Group 
(<uref><urefurl>https://wiki.earthdata.nasa.gov/display/ESDSWG/Dataset+Interoperability+Working+Group</urefurl><urefdesc spaces="\n">DIWG</urefdesc></uref>) supports this convention.
This option reports which identifiers do not comply with this
convention, so that a file can be easily checked for compliance with
the <acronym><acronymword>DIWG</acronymword></acronym> recommendation and the underlying <acronym><acronymword>CF</acronymword></acronym>
Convention: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
$ ncks --chk_chr ~/nco/data/in.nc
...
ncks: WARNING nco_chk_chr() reports variable att_var_spc_chr attribute name &quot;at_in_name@&quot; is not CF-compliant
ncks: WARNING nco_chk_chr() reports variable name &quot;var_nm-dash&quot; is not CF-compliant
ncks: WARNING nco_chk_chr() reports variable var_nm-dash attribute name &quot;att_nm-dash&quot; is not CF-compliant
ncks: INFO nco_chk_chr() reports total number of identifiers with CF non-compliant names is 26
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;chk_mss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chk_mss --&gt;
&lt;a name=&quot;check_missing_value&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#check_missing_value --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2122"><code>--chk_mss</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2123"><code>--check_missing_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2124"><code>missing_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2125"><acronym><acronymword>CF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2126"><acronym><acronymword>DIWG</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--chk_mss</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 5.1.8 (September, 2023), <command>ncks</command>
can report all variables and groups that contain a
<code>missing_value</code> attribute.
<acronym><acronymword>NASA</acronymword></acronym>&textrsquo;s Dataset Interoperability Working Group 
(<uref><urefurl>https://wiki.earthdata.nasa.gov/display/ESDSWG/Dataset+Interoperability+Working+Group</urefurl><urefdesc spaces="\n">DIWG</urefdesc></uref>) notes that the <code>missing_value</code> attribute has been
semi-deprecated, and recommends that it should not be used in new
Earth Science data products.
This option reports which variables (and groups) contain a
<code>missing_value</code> attribute, so that a file can be easily
checked for compliance with the <acronym><acronymword>DIWG</acronymword></acronym> recommendation:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
$ ncks --chk_mss ~/nco/data/in.nc
ncks: WARNING nco_chk_mss() reports variable fll_val_mss_val contains &quot;missing_value&quot; attribute
ncks: WARNING nco_chk_mss() reports variable one_dmn_rec_var_missing_value contains &quot;missing_value&quot; attribute
...
ncks: WARNING nco_chk_mss() reports variable rec_var_int_mss_val_flt contains &quot;missing_value&quot; attribute
ncks: INFO nco_chk_mss() reports total number of variables and/or groups with &quot;missing_value&quot; attribute is 11
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;chk_nan&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chk_nan --&gt;
&lt;a name=&quot;check_nan&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#check_nan --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2127"><code>--chk_nan</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2128"><code>--check_nan</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2129"><code>NaN</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2130"><code>NaNf</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2131"><acronym><acronymword>DIWG</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--chk_nan</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.8.0 (May, 2019), <command>ncks</command> can
locate <code>NaN</code> or <code>NaNf</code> in double- and single-precision
floating-point variables, respectively.
<acronym><acronymword>NCO</acronymword></acronym> prints the location of the first <code>NaN</code> (if any)
encountered in each variable. 
<acronym><acronymword>NASA</acronymword></acronym>&textrsquo;s Dataset Interoperability Working Group 
(<uref><urefurl>https://wiki.earthdata.nasa.gov/display/ESDSWG/Dataset+Interoperability+Working+Group</urefurl><urefdesc spaces="\n">DIWG</urefdesc></uref>) notes that the <code>missing_value</code> attribute has been
semi-deprecated, and recommends that it should not be used in new
Earth Science data products.
This option reports allows users to easily check whether all the
floating point variables in a file comply with the <acronym><acronymword>DIWG</acronymword></acronym>
recommendation: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
$ ncks --chk_nan ~/nco/data/in_4.nc
ncks: WARNING nco_chk_nan() reports variable /nan_arr has first NaNf at hyperslab element 1
ncks: WARNING nco_chk_nan() reports variable /nan_scl has first NaNf at hyperslab element 0
ncks: INFO nco_chk_nan() reports total number of floating-point variables with NaN elements is 2
</verbatim>
</example>
<para>Thanks to Matthew Thompson of <acronym><acronymword>NASA</acronymword></acronym> for originally suggesting
this feature.
</para>
<html endspaces=" ">
&lt;a name=&quot;chk_xtn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#chk_xtn --&gt;
&lt;a name=&quot;check_extension&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#check_extension --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2132"><code>--chk_xtn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2133"><code>--check_extension</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2134"><acronym><acronymword>DIWG</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--chk_xtn</itemformat></item>
</tableterm><tableitem><para>A filename <emph>extension</emph> is the suffix that follows the final
period <samp>.</samp> in a filename.
For example, the suffix of <samp>in.file.nc</samp> is <samp>nc</samp>.
<acronym><acronymword>NASA</acronymword></acronym>&textrsquo;s Dataset Interoperability Working Group 
(<uref><urefurl>https://wiki.earthdata.nasa.gov/display/ESDSWG/Dataset+Interoperability+Working+Group</urefurl><urefdesc spaces="\n">DIWG</urefdesc></uref>) recommends that &textldquo;files created with the HDF5, HDF-EOS5, or netCDF
APIs should have filename extensions \&quot;h5\&quot;, \&quot;he5\&quot;, or \&quot;nc\&quot;,
respectively.&textrdquo; 
As of <acronym><acronymword>NCO</acronymword></acronym> version 5.1.9 (November, 2023), <command>ncks</command>
can report all filenames that violate this <acronym><acronymword>DIWG</acronymword></acronym>
recommendation. 
This option reports which filenames do not comply with this
convention.
If a file appears to be mis-labeled, e.g., the extension is <samp>.h5</samp>
but the file contents match <acronym><acronymword>HDF5-EOS</acronymword></acronym> structure, that will
also be reported.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@spectral:~$ ncks --chk_xtn ~/nco/data/in.nc
zender@spectral:~$ ncks --chk_xtn ~/in.nc4
ncks: WARNING nco_chk_xtn() reports filename extension &quot;nc4&quot; is non-compliant
ncks: HINT rename file with &quot;nc&quot; rather than &quot;nc4&quot; extension
ncks: INFO nco_chk_xtn() reports total number of non-compliant filename extensions is 1
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;dmn_fix_mk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dmn_fix_mk --&gt;
&lt;a name=&quot;fix_rec_dmn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fix_rec_dmn --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2135">record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2136">fixed dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2137"><code>--fix_rec_dmn <var>dim</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2138"><code>--no_rec_dmn <var>dim</var></code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--fix_rec_dmn</itemformat></item>
</tableterm><tableitem><para>Change record dimension <var>dim</var> in the input file into a fixed
dimension in the output file. 
Also <samp>--no_rec_dmn</samp>.
Before <acronym><acronymword>NCO</acronymword></acronym> version 4.2.5 (January, 2013), the syntax for 
<code>--fix_rec_dmn</code> did not permit or require the specification of
the dimension name <var>dim</var>. 
This is because the feature only worked on netCDF3 files, which support
only one record dimension, so specifying its name was unnecessary.
netCDF4 files allow an arbitrary number of record dimensions, so the
user must specify which record dimension to fix.
The decision was made that starting with <acronym><acronymword>NCO</acronymword></acronym> version 4.2.5
(January, 2013), it is always required to specify the dimension name to
fix regardless of the netCDF file type.
This keeps the code simple, and is symmetric with the syntax for
<code>--mk_rec_dmn</code>, described next.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.0 (January, 2014), the argument
<code>all</code> may be given to <samp>--fix_rec_dmn</samp> to convert <emph>all</emph> 
record dimensions to fixed dimensions in the output file. 
Previously, <samp>--fix_rec_dmn</samp> only allowed one option, the name of a
single record dimension to be fixed. 
Now it is simple to simultaneously fix all record dimensions.
This is useful (and nearly mandatory) when flattening netCDF4 files that
have multiple record dimensions per group into netCDF3 files (which are
limited to at most one record dimension) (<pxref label="Group-Path-Editing"><xrefnodename>Group Path Editing</xrefnodename></pxref>). 
</para>
<html endspaces=" ">
&lt;a name=&quot;hdn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdn --&gt;
&lt;a name=&quot;hidden&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hidden --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2139">hidden attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2140">special attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2141"><code>--hdn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2142"><code>--hidden</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2143"><code>_SOURCE_FORMAT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2144"><code>_Format</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2145"><code>_DeflateLevel</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2146"><code>_Shuffle</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2147"><code>_Storage</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2148"><code>_ChunkSizes</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2149"><code>_Endianness</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2150"><code>_Fletcher32</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2151"><code>_NOFILL</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2152"><code>_NCProperties</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2153"><code>_IsNetcdf4</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2154"><code>_SuperblockVersion</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--hdn</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.0 (January, 2014), the <samp>--hdn</samp>
or <samp>--hidden</samp> options print hidden (aka special) attributes.
This is equivalent to <samp>ncdump -s</samp>.
Hidden attributes include: <code>_Format</code>, <code>_DeflateLevel</code>,
<code>_Shuffle</code>, <code>_Storage</code>, <code>_ChunkSizes</code>,
<code>_Endianness</code>, <code>_Fletcher32</code>, and <code>_NOFILL</code>. 
Previously <command>ncks</command> ignored all these attributes in
<acronym><acronymword>CDL</acronymword></acronym>/<acronym><acronymword>XML</acronymword></acronym> modes. 
Now it prints these attributes as appropriate in all modes. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.6 (September, 2014), <samp>--hdn</samp> 
also prints the extended file format (i.e., the format of the file
or server supplying the data) as <code>_SOURCE_FORMAT</code>.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.1 (August, 2016), <samp>--hdn</samp> 
also prints the hidden attributes <code>_NCProperties</code>,
<code>_IsNetcdf4</code>, and <code>_SuperblockVersion</code> for netCDF4 files so 
long as <acronym><acronymword>NCO</acronymword></acronym> is linked against netCDF library version 4.4.1 or
later. 
Users are referred to the
<uref><urefurl>http://www.unidata.ucar.edu/software/netcdf/docs</urefurl><urefdesc spaces=" ">Unidata netCDF Documentation</urefdesc></uref>,
or the man pages for <command>ncgen</command> or <command>ncdump</command>, for
detailed descriptions of the meanings of these hidden attributes. 
</para>
<html endspaces=" ">
&lt;a name=&quot;cdl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cdl --&gt;
&lt;a name=&quot;hdp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hdp --&gt;
&lt;a name=&quot;hncgen&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hncgen --&gt;
&lt;a name=&quot;h4_ncgen&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#h4_ncgen --&gt;
&lt;a name=&quot;ncgen-hdf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncgen-hdf --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2155"><command>hdp</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2156"><command>ncgen</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2157"><command>ncgen-hdf</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2158"><command>hncgen</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2159"><command>h4_ncgen</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2160"><command>ncdump</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2161"><code>--cdl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2162"><acronym><acronymword>CDL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2163"><acronym><acronymword>HDF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2164"><acronym><acronymword>HDF4</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--cdl </itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.3.3 (July, 2013), <command>ncks</command> can
print extracted data and metadata to screen (i.e., <code>stdout</code>) as
valid <acronym><acronymword>CDL</acronymword></acronym> (network Common data form Description Language). 
<acronym><acronymword>CDL</acronymword></acronym> is the human-readable &textldquo;lingua franca&textrdquo; of netCDF ingested by
<command>ncgen</command> and excreted by <command>ncdump</command>.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.9 (September, 2017), <command>ncks</command> 
prints <acronym><acronymword>CDL</acronymword></acronym> by default, and the &textldquo;traditional&textrdquo; mode must
be explicitly selected with <samp>--trd</samp>.
Compare <command>ncks</command> &textldquo;traditional&textrdquo; with <acronym><acronymword>CDL</acronymword></acronym> printing:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@roulee:~$ ncks --trd -v one ~/nco/data/in.nc
one: type NC_FLOAT, 0 dimensions, 1 attribute, chunked? no, compressed? no, packed? no
one size (RAM) = 1*sizeof(NC_FLOAT) = 1*4 = 4 bytes
one attribute 0: long_name, size = 3 NC_CHAR, value = one

one = 1 

zender@roulee:~$ ncks --cdl -v one ~/nco/data/in.nc
netcdf in {

  variables:
    float one ;
    one:long_name = &quot;one&quot; ;

  data:
    one = 1 ;

} // group /
</verbatim>
</example>
<para>Users should note the <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s <acronym><acronymword>CDL</acronymword></acronym> mode outputs
successively more verbose additional diagnostic information in
<acronym><acronymword>CDL</acronymword></acronym> comments as the level of debugging increases from
zero to two.
For example printing the above with <samp>-D 2</samp> yields
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@roulee:~$ ncks -D 2 --cdl -v one ~/nco/data/in.nc
netcdf in {
  // ncgen -k classic -b -o in.nc in.cdl

  variables:
    float one ; // RAM size = 1*sizeof(NC_FLOAT) = 1*4 = 4 bytes, ID = 147
      one:long_name = &quot;one&quot; ; // char

  data:
    one = 1 ; 

} // group /
</verbatim>
</example>

<para><command>ncgen</command> converts <acronym><acronymword>CDL</acronymword></acronym>-mode output into a netCDF file:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -v one ~/nco/data/in.nc &gt; ~/in.cdl
ncgen -k netCDF-4 -b -o ~/in.nc ~/in.cdl
ncks -v one ~/in.nc
</pre></example>
<para>The <acronym><acronymword>HDF4</acronymword></acronym> version of <command>ncgen</command>, often named
<command>hncgen</command>, <command>h4_ncgen</command>, or <command>ncgen-hdf</command>,
(usually) converts netCDF3 <acronym><acronymword>CDL</acronymword></acronym> into an <acronym><acronymword>HDF</acronymword></acronym> file:
</para><example endspaces=" ">
<pre xml:space="preserve">cd ~/nco/data
ncgen      -b -o hdf.hdf hdf.cdl # HDF ncgen is sometimes named...ncgen
ncgen      -b -o in.hdf  in.cdl  # Fails: Some valid netCDF CDL breaks HDF ncgen
hncgen     -b -o hdf.hdf hdf.cdl # HDF ncgen is hncgen in some RPM packages
h4_ncgen   -b -o hdf.hdf hdf.cdl # HDF ncgen is h4_ncgen in Anaconda packages
ncgen-hdf  -b -o hdf.hdf hdf.cdl # HDF ncgen is ncgen-hdf in some Debian packages
hdp dumpsds hdf.hdf              # ncdump/h5dump-equivalent for HDF4
h4_ncdump dumpsds hdf.hdf        # ncdump/h5dump-equivalent for HDF4
</pre></example>
<para>Note that <acronym><acronymword>HDF4</acronymword></acronym> does not support netCDF-style groups, so the 
above commands fail when the input file contains groups.
Only netCDF4 and <acronym><acronymword>HDF5</acronymword></acronym> support groups.
In our experience the <acronym><acronymword>HDF</acronymword></acronym> <command>ncgen</command> command, by
whatever name installed, is not robust and fails on many valid netCDF3 
<acronym><acronymword>CDL</acronymword></acronym> constructs.
The <acronym><acronymword>HDF4</acronymword></acronym> version of <command>ncgen</command> will definitely fail on
the default <acronym><acronymword>NCO</acronymword></acronym> input file <file>nco/data/in.cdl</file>.
The <acronym><acronymword>NCO</acronymword></acronym> source code distribution provides
<file>nco/data/hdf.cdl</file> that works with the <acronym><acronymword>HDF4</acronymword></acronym> version
of <command>ncgen</command>, and can be used to test <acronym><acronymword>HDF</acronymword></acronym> files.
</para>
<html endspaces=" ">
&lt;a name=&quot;dmn_rec_mk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dmn_rec_mk --&gt;
&lt;a name=&quot;mk_rec_dmn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mk_rec_dmn --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2165">record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2166">fixed dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2167">fix record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2168"><code>--mk_rec_dmn <var>dim</var></code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--mk_rec_dmn <var>dim</var></itemformat></item>
</tableterm><tableitem><para>Change existing dimension <var>dim</var> to a record dimension in the output file.
This is the most straightforward way of changing a dimension to a/the
record dimension, and works fine in most cases.
See <ref label="ncecat-netCDF-Ensemble-Concatenator"><xrefnodename>ncecat netCDF Ensemble Concatenator</xrefnodename></ref> and 
<ref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></ref> for other methods of
changing variable dimensionality, including the record dimension. 
</para>
<html endspaces=" ">
&lt;a name=&quot;H&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#H --&gt;
&lt;a name=&quot;data&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#data --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2169"><code>-H</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2170"><code>--data</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2171"><code>--hieronymus</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-H </itemformat></item>
</tableterm><tableitem><para>Toggle (turn-on or turn-off) default behavior of printing data (not
metadata) to screen or copying data to disk.
Also activated using <samp>--print</samp> or <samp>--prn</samp>.
By default <command>ncks</command> prints all metadata but no data to screen 
when no netCDF <var>output-file</var> is specified.
And if <var>output-file</var> is specified, <command>ncks</command> copies all
metadata and all data to it.
In other words, the printing/copying default is context-sensitive,
and <samp>-H</samp> toggles the default behavior.
Hence, use <samp>-H</samp> to turn-off copying data (not metadata) to an
output file. 
(It is occasionally useful to write all metadata to a file, so that
the file has allocated the required disk space to hold the data, yet
to withold writing the data itself). 
And use <samp>-H</samp> to turn-on printing data (not metadata) to screen.
Unless otherwise specified (with <code>-s</code>), each element of the data
hyperslab prints on a separate line containing the names, indices,
and, values, if any, of all of the variables dimensions.
The dimension and variable indices refer to the location of the
corresponding data element with respect to the variable as stored on
disk (i.e., not the hyperslab).
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks --trd -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0 
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1 
lat[0]=-90 lev[0]=100 lon[2]=180 three_dmn_var[2]=2 
...
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21 
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22 
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23 
</pre></example>
<para>Printing the same variable with the <samp>-F</samp> option shows the same
variable indexed with Fortran conventions
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks -F -C -v three_dmn_var in.nc
lon(1)=0 lev(1)=100 lat(1)=-90 three_dmn_var(1)=0 
lon(2)=90 lev(1)=100 lat(1)=-90 three_dmn_var(2)=1 
lon(3)=180 lev(1)=100 lat(1)=-90 three_dmn_var(3)=2 
...
</pre></example>
<para>Printing a hyperslab does not affect the variable or dimension indices
since these indices are relative to the full variable (as stored in the
input file), and the input file has not changed.
However, if the hyperslab is saved to an output file and those values
are printed, the indices will change:
<!-- c fxm: replace with new MSA output style -->
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks --trd -H -d lat,90.0 -d lev,1000.0 -v three_dmn_var in.nc out.nc
...
lat[1]=90 lev[2]=1000 lon[0]=0 three_dmn_var[20]=20 
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21 
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22 
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23 
% ncks --trd -C -v three_dmn_var out.nc
lat[0]=90 lev[0]=1000 lon[0]=0 three_dmn_var[0]=20 
lat[0]=90 lev[0]=1000 lon[1]=90 three_dmn_var[1]=21 
lat[0]=90 lev[0]=1000 lon[2]=180 three_dmn_var[2]=22 
lat[0]=90 lev[0]=1000 lon[3]=270 three_dmn_var[3]=23 
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;jsn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#jsn --&gt;
&lt;a name=&quot;json&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#json --&gt;
&lt;a name=&quot;JSON&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#JSON --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2172"><code>--jsn_fmt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2173"><code>--jsn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2174"><code>--json</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2175"><acronym><acronymword>JSN</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2176"><acronym><acronymword>JSON</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2177">JavaScript</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--jsn, --json</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.2 (November, 2016), <command>ncks</command> can
print extracted metadata and data to screen (i.e., <code>stdout</code>) as
<acronym><acronymword>JSON</acronymword></acronym>, JavaScript Object Notation, defined 
<uref><urefurl>http://www.json.org</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
<command>ncks</command> supports <acronym><acronymword>JSON</acronymword></acronym> output more completely, flexibly,
and robustly than any other tool to our knowledge.
With <command>ncks</command> one can translate entire netCDF3 and netCDF4 files
into <acronym><acronymword>JSON</acronymword></acronym>, including metadata and data, using all 
<acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s subsetting and hyperslabbing capabilities.
<acronym><acronymword>NCO</acronymword></acronym> uses a <acronym><acronymword>JSON</acronymword></acronym> format we developed ourselves,
during a year of discussion among interested researchers.
Some refer to this format as <acronym><acronymword>NCO-JSON</acronymword></acronym>, to disambiguate it from 
other <acronym><acronymword>JSON</acronymword></acronym> formats for netCDF data.
Other projects have since adopted, and some can generate, 
<acronym><acronymword>NCO-JSON</acronymword></acronym>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2178"><acronym><acronymword>ERDDAP</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2179"><acronym><acronymword>CF-JSON</acronymword></acronym></indexterm></cindex>
Projects that support <acronym><acronymword>NCO-JSON</acronymword></acronym> include <acronym><acronymword>ERDDAP</acronymword></acronym> 
(<url><urefurl>https://coastwatch.pfeg.noaa.gov/erddap/index.html</urefurl></url>, choose output
filetype <code>.ncoJson</code> from this 
<uref><urefurl>https://coastwatch.pfeg.noaa.gov/erddap/griddap/documentation.html#fileType</urefurl><urefdesc spaces=" ">table</urefdesc></uref>) 
and <acronym><acronymword>CF-JSON</acronymword></acronym> (<url><urefurl>http://cf-json.org</urefurl></url>).
</para>
<para>Behold <acronym><acronymword>JSON</acronymword></acronym> output in default mode:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@aerosol:~$ ncks --jsn -v one ~/nco/data/in.nc
{
  &quot;variables&quot;: {
    &quot;one&quot;: {
      &quot;type&quot;: &quot;float&quot;,
      &quot;attributes&quot;: {
        &quot;long_name&quot;: &quot;one&quot;
      },
      &quot;data&quot;: 1.0
    }
  }
}
</verbatim>
</example>
<para><acronym><acronymword>NCO</acronymword></acronym> converts to (using commonsense rules) and prints all
<acronym><acronymword>NC_TYPE</acronymword></acronym>s as one of three atomic types distinguishable as 
<acronym><acronymword>JSON</acronymword></acronym> values: <code>float</code>, <code>string</code>, and <code>int</code>
<footnote><para>The <acronym><acronymword>JSON</acronymword></acronym> boolean atomic type is not (yet) supported
as there is no obvious netCDF-equivalent to this type.</para></footnote>.
Floating-point types (<code>NC_FLOAT</code> and <code>NC_DOUBLE</code>)
are printed with a decimal point and at least one signficant digit
following the decimal point, e.g., <code>1.0</code> rather than <code>1.</code> or
<code>1</code>.    
Integer types (e.g., <code>NC_INT</code>, <code>NC_UINT64</code>) are printed
with no decimal point. 
String types (<code>NC_CHAR</code> and <code>NC_STRING</code>) are enclosed 
in double-quotes.
</para>
<para>The <acronym><acronymword>JSON</acronymword></acronym> specification allows many possible output formats for  
netCDF files.  
<acronym><acronymword>NCO</acronymword></acronym> developers implemented a working prototype in Octoboer,
2016 and, after discussing options with interested parties 
<uref><urefurl>https://sourceforge.net/p/nco/discussion/9829/thread/8c4d7e72</urefurl><urefdesc spaces=" ">here</urefdesc></uref>, 
finalized the emitted <acronym><acronymword>JSON</acronymword></acronym> syntax a few weeks later.
The resulting <acronym><acronymword>JSON</acronymword></acronym> backend supports three levels of
pedanticness, ordered from more concise, flexible, and human-readable to 
more verbose, restrictive, and 1-to-1 reproducible.
<acronym><acronymword>JSON</acronymword></acronym>-specific switches access these modes and other features. 
Each <acronym><acronymword>JSON</acronymword></acronym> configuration option automatically triggers 
<acronym><acronymword>JSON</acronymword></acronym> printing, so that specifying <samp>--json</samp> in addition to
a <acronym><acronymword>JSON</acronymword></acronym> configuration option is redundant and unnecessary. 
</para>
<para>Request a specific format level with the pedantic level argument to
the <samp>--jsn_fmt <var>lvl</var></samp> option.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.3 (December, 2016), the option formerly
known as <samp>--jsn_att_fmt</samp> was renamed simply <samp>--jsn_fmt</samp>.
The more general name reflects the fact that the option controls
all <acronym><acronymword>JSON</acronymword></acronym> formatting, not just attribute formatting.
As of version 4.6.3, <acronym><acronymword>NCO</acronymword></acronym> defaults to demarcate inner 
dimensions of variable data with (nested) square brackets rather than 
printing data as an unrolled single dimensional array.
An array with C-ordered dimensionality [2,3,4] prints as:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --jsn -v three_dmn_var ~/nco/data/in.nc
...
&quot;data&quot;: [[[0.0, 1.0, 2.0, 3.0], [4.0, 5.0, 6.0, 7.0], [8.0, 9.0, 10.0,11.0]], [[12.0, 13.0, 14.0, 15.0], [16.0, 17.0, 18.0, 19.0], [20.0,21.0, 22.0, 23.0]]]
...
% ncks --jsn_fmt=4 -v three_dmn_var ~/nco/data/in.nc
...
&quot;data&quot;: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0,22.0, 23.0]
...
</verbatim>
</example>
<para>One can recover the former behavior (and omit the brackets) by adding
four to the base pedantic level <var>lvl</var> (as shown above).
Besides the potential offset of four, <var>lvl</var> may take one of three 
values between 0&textndash;2: 
</para><itemize commandarg="bullet" spaces=" " endspaces=" "><itemprepend><formattingcommand command="bullet"/></itemprepend>
<listitem><prepend>&bullet;</prepend> <para><math><var>lvl</var> = 0</math> is the default mode, and is also explicitly
selectable with <samp>--jsn_fmt=0</samp>.
All values are output without the original <acronym><acronymword>NC_TYPE</acronymword></acronym> token.
This allows attributes to print as <acronym><acronymword>JSON</acronymword></acronym> name-value pairs,
rather than as more complex objects: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --jsn_fmt=0 -v att_var ~/nco/data/in_grp.nc
...
&quot;att_var&quot;: {
  &quot;shape&quot;: [&quot;time&quot;],
  &quot;type&quot;: &quot;float&quot;,
  &quot;attributes&quot;: {
    &quot;byte_att&quot;: [0, 1, 2, 127, -128, -127, -2, -1],
    &quot;char_att&quot;: &quot;Sentence one.\nSentence two.\n&quot;,
    &quot;short_att&quot;: 37,
    &quot;int_att&quot;: 73,
    &quot;long_att&quot;: 73,
    &quot;float_att&quot;: [73.0, 72.0, 71.0, 70.010, 69.0010, 68.010, 67.010],
    &quot;double_att&quot;: [73.0, 72.0, 71.0, 70.010, 69.0010, 68.010, 67.0100010]
  },
  &quot;data&quot;: [10.0, 10.10, 10.20, 10.30, 10.40101, 10.50, 10.60, 10.70, 10.80, 10.990]
...
</verbatim>
</example>

<para>This least pedantic mode produces the most easily read results, and
suffices for many (most?) purposes.  
Any downstream parser is expected to assign an appropriate type as
indicated by <acronym><acronymword>JSON</acronymword></acronym> syntax rules.
Because the original attributes&textrsquo; <code>NC_TYPE</code> are not output, 
a downstream parser may not exactly reproduce the input file datatypes. 
For example, whether the original attribute string was stored as
<code>NC_CHAR</code> or <code>NC_STRING</code> will be unknown to a downstream
parser.
Distinctions between <code>NC_FLOAT</code> and <code>NC_DOUBLE</code> are similarly
lost, as are all distinctions among the integer types.
</para>
<para>In our experience, these distinctions are immaterial for attributes,
which are intended for metadata not for large-scale storage.   
Type-distinctions can, however, significantly impact the size of
variable data, responsible for nearly all the storage required by
datasets.
For instance, storing or transferring an <code>NC_SHORT</code> field as
<code>NC_DOUBLE</code> would waste a factor of four in space or bandwidth. 
This is why <acronym><acronymword>NCO</acronymword></acronym> <emph>always</emph> prints the <code>NC_TYPE</code> 
of variable data.
Downstream parsers can (but are not required to) take advantage of the
variable&textrsquo;s <code>NC_TYPE</code> to choose the most efficient storage type. 
</para>
<para>The Shape member of the variable object is an ordered array of
dimension names such as <code>&quot;shape&quot;: [&quot;lat&quot;,&quot;lon&quot;]</code>, similar to its
use in NcML.
Each name corresponds to a previously defined Dimension object
that, taken together, define the rank, shape, and size of the
variable. 
Variables are assumed to be scalar by default.
Hence the Shape member is mandatory for arrays, and is always omitted
for scalars (by contrast, NcML requires an empty shape string to
indicate scalars).  
</para>
</listitem><listitem><prepend>&bullet;</prepend> <para><math><var>lvl</var> = 1</math> is a medium-pedantic level that prints all
attributes as objects (with explicit types) unless the attribute type
match the simplest default <acronym><acronymword>JSON</acronymword></acronym> value types.
In other words, attributes of type <code>NC_FLOAT</code>, <code>NC_CHAR</code>,
<code>NC_SHORT</code>, and <code>NC_BYTE</code> are printed as objects with an
explicit type so that parsers do not use the default type. 
Attributes of type <code>NC_DOUBLE</code>, <code>NC_STRING</code>, and <code>NC_INT</code>
are printed as <acronym><acronymword>JSON</acronymword></acronym> arrays, as in the <math><var>lvl</var> = 0</math>
above: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --jsn_fmt=1 -v att_var ~/nco/data/in.nc
...
&quot;att_var&quot;: {
  &quot;shape&quot;: [&quot;time&quot;],
  &quot;type&quot;: &quot;float&quot;,
  &quot;attributes&quot;: {
    &quot;byte_att&quot;: { &quot;type&quot;: &quot;byte&quot;, &quot;data&quot;: [0, 1, 2, 127, -128, -127, -2, -1]},
    &quot;char_att&quot;: &quot;Sentence one.\nSentence two.\n&quot;,
    &quot;short_att&quot;: { &quot;type&quot;: &quot;short&quot;, &quot;data&quot;: 37},
    &quot;int_att&quot;: 73,
    &quot;long_att&quot;: 73,
    &quot;float_att&quot;: [73.0, 72.0, 71.0, 70.010, 69.0010, 68.010, 67.010],
    &quot;double_att&quot;: { &quot;type&quot;: &quot;double&quot;, &quot;data&quot;: [73.0, 72.0, 71.0, 70.010, 69.0010, 68.010, 67.0100010]}
  },
  &quot;data&quot;: [10.0, 10.10, 10.20, 10.30, 10.40101, 10.50, 10.60, 10.70, 10.80, 10.990]
...
</verbatim>
</example>
<para>The attributes of type <code>NC_BYTE</code>, <code>NC_SHORT</code>, and
<code>NC_DOUBLE</code> are printed as <acronym><acronymword>JSON</acronymword></acronym> objects that comprise an
<code>NC_TYPE</code> and a value list, because their values could conceivably 
not be representable, or would waste space, if interpreted as
<code>NC_INT</code> or <code>NC_FLOAT</code>, respectively.
All other attributes may be naturally mapped to the type indicated by
the <acronym><acronymword>JSON</acronymword></acronym> syntax of the value, where numbers are assumed to
correspond to <code>NC_FLOAT</code> for floating-point, <code>NC_INT</code> for
integers, and <code>NC_CHAR</code> or <code>NC_STRING</code> for strings.
This minimal increase in verbosity allows a downstream parser to
re-construct the original dataset with nearly identical attributes types
to the original.
</para>
</listitem><listitem><prepend>&bullet;</prepend> <para><math><var>lvl</var> = 2</math> is the most pedantic mode, and should be used
when preserving all input types (e.g., to ensure exact reproducibility
of the input file) is important. 
This mode always prints attributes as <acronym><acronymword>JSON</acronymword></acronym> objects with a type
value so that any downstream parser can (though it need not) guarantee
exact reproduction of the original dataset:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks --jsn_fmt=2 -v att_var ~/nco/data/in.nc
...
&quot;att_var&quot;: {
  &quot;shape&quot;: [&quot;time&quot;],
  &quot;type&quot;: &quot;float&quot;,
  &quot;attributes&quot;: {
    &quot;byte_att&quot;: { &quot;type&quot;: &quot;byte&quot;, &quot;data&quot;: [0, 1, 2, 127, -128, -127, -2, -1]},
    &quot;char_att&quot;: { &quot;type&quot;: &quot;char&quot;, &quot;data&quot;: &quot;Sentence one.\nSentence two.\n&quot;},
    &quot;short_att&quot;: { &quot;type&quot;: &quot;short&quot;, &quot;data&quot;: 37},
    &quot;int_att&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;data&quot;: 73},
    &quot;long_att&quot;: { &quot;type&quot;: &quot;int&quot;, &quot;data&quot;: 73},
    &quot;float_att&quot;: { &quot;type&quot;: &quot;float&quot;, &quot;data&quot;: [73.0, 72.0, 71.0, 70.010, 69.0010, 68.010, 67.010]},
    &quot;double_att&quot;: { &quot;type&quot;: &quot;double&quot;, &quot;data&quot;: [73.0, 72.0, 71.0, 70.010, 69.0010, 68.010, 67.0100010]}
  },
  &quot;data&quot;: [10.0, 10.10, 10.20, 10.30, 10.40101, 10.50, 10.60, 10.70, 10.80, 10.990]
...
</verbatim>
</example>
</listitem></itemize>

<cindex index="cp" spaces=" "><indexterm index="cp" number="2180"><command>jsonlint</command></indexterm></cindex>
<para>That <acronym><acronymword>ncks</acronymword></acronym> produces correct translations of for all supported
datatypes may be verified by a <acronym><acronymword>JSON</acronymword></acronym> syntax checker command
like <command>jsonlint</command>. 
Please let us know how to improve <acronym><acronymword>JSON</acronymword></acronym> features for your
application.  
</para>
<html endspaces=" ">
&lt;a name=&quot;Metadata&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#Metadata --&gt;
&lt;a name=&quot;M&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#M --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2181"><code>-M</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2182"><code>--Mtd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2183"><code>--Metadata</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2184">metadata, global</indexterm></cindex> 
<item spaces=" "><itemformat command="samp">-M</itemformat></item>
</tableterm><tableitem><para>Turn-on printing to screen or turn-off copying global and group metadata.
This includes file summary information and global and group attributes.
Also <samp>--Mtd</samp> and <samp>--Metadata</samp>.
By default <command>ncks</command> prints global metadata to screen if no netCDF
output file and no variable extraction list is specified (with <samp>-v</samp>).  
Use <samp>-M</samp> to print global metadata to screen if a netCDF output is 
specified, or if a variable extraction list is specified (with <samp>-v</samp>). 
Use <samp>-M</samp> to turn-off copying of global and group metadata when
copying, subsetting, or appending to an output file.
</para>
<html endspaces=" ">
&lt;a name=&quot;prn_tbl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prn_tbl --&gt;
</html>
<para>The various combinations of printing switches can be confusing.
In an attempt to anticipate what most users want to do, <command>ncks</command>
uses context-sensitive defaults for printing.
Our goal is to minimize the use of switches required to accomplish the
common operations.
We assume that users creating a new file or overwriting (e.g., with
<samp>-O</samp>) an existing file usually wish to copy all global and
variable-specific attributes to the new file.
In contrast, we assume that users appending (e.g., with <samp>-A</samp> an
explicit variable list from one file to another usually wish to copy
only the variable-specific attributes to the output file.
The switches <samp>-H</samp>, <samp>-M</samp>, and <samp>-m</samp> switches are
implemented as toggles which reverse the default behavior.
The most confusing aspect of this is that <samp>-M</samp> inhibits copying
global metadata in overwrite mode and causes copying of global
metadata in append mode.
</para><example endspaces=" ">
<pre xml:space="preserve">ncks                 in.nc        # Print  VAs and GAs
ncks          -v one in.nc        # Print  VAs not GAs
ncks    -M    -v one in.nc        # Print  GAs only
ncks       -m -v one in.nc        # Print  VAs only
ncks    -M -m -v one in.nc        # Print  VAs and GAs
ncks -O              in.nc out.nc # Copy   VAs and GAs
ncks -O       -v one in.nc out.nc # Copy   VAs and GAs
ncks -O -M    -v one in.nc out.nc # Copy   VAs not GAs
ncks -O    -m -v one in.nc out.nc # Copy   GAs not VAs
ncks -O -M -m -v one in.nc out.nc # Copy   only data (no atts)
ncks -A              in.nc out.nc # Append VAs and GAs
ncks -A       -v one in.nc out.nc # Append VAs not GAs
ncks -A -M    -v one in.nc out.nc # Append VAs and GAs
ncks -A    -m -v one in.nc out.nc # Append only data (no atts)
ncks -A -M -m -v one in.nc out.nc # Append GAs not VAs
</pre></example>
<para>where <code>VAs</code> and <code>GAs</code> denote variable and group/global
attributes, respectively. 
</para>
<html endspaces=" ">
&lt;a name=&quot;-m&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-m --&gt;
&lt;a name=&quot;m&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#m --&gt;
&lt;a name=&quot;mtd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mtd --&gt;
&lt;a name=&quot;metadata&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#metadata --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2185"><command>ncdump</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2186"><code>-m</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2187"><code>--mtd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2188"><code>--metadata</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2189">metadata</indexterm></cindex>
<item spaces=" "><itemformat command="samp">-m</itemformat></item>
</tableterm><tableitem><para>Turn-on printing to screen or turn-off copying variable metadata.
Using <samp>-m</samp> will print variable metadata to screen (similar to
<kbd>ncdump -h</kbd>).  
This displays all metadata pertaining to each variable, one variable
at a time.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2190">chunking</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2191">compression</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2192">deflation</indexterm></cindex>
This includes information on the storage properties of the variable,
such as whether it employs chunking, compression, or packing.
Also activated using <samp>--mtd</samp> and <samp>--metadata</samp>.
The <command>ncks</command> default behavior is to print variable metadata to
screen if no netCDF output file is specified.
Use <samp>-m</samp> to print variable metadata to screen if a netCDF output is  
specified. 
Also use <samp>-m</samp> to turn-off copying of variable metadata to an output
file.
</para>
<html endspaces=" ">
&lt;a name=&quot;no_blank&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_blank --&gt;
&lt;a name=&quot;noblank&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#noblank --&gt;
&lt;a name=&quot;no-blank&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no-blank --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2193"><code>--no_blank</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2194"><code>--noblank</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2195"><code>--no-blank</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2196">blank</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2197">missing values</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--no_blank</itemformat></item>
</tableterm><tableitem><para>Print numeric representation of missing values.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.2.2 (October, 2012), <acronym><acronymword>NCO</acronymword></acronym> prints
missing values as blanks (i.e., the underscore character <samp>_</samp>) by default.
To enable the old behavior of printing the numeric representation of
missing values (e.g., <code>1.0e36</code>), use the <samp>--no_blank</samp> switch.
Also activated using <samp>--noblank</samp> or <samp>--no-blank</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;P&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#P --&gt;
&lt;a name=&quot;prn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prn --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2198"><code>-P</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2199"><code>--print</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2200"><code>--prn</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-P </itemformat></item>
</tableterm><tableitem><para>Print data, metadata, and units to screen.
The <samp>-P</samp> switch is a convenience abbreviation for 
<samp>-C -H -M -m -u</samp>.
Also activated using <samp>--print</samp> or <samp>--prn</samp>.
This set of switches is useful for exploring file contents.
</para>
<html endspaces=" ">
&lt;a name=&quot;fl_prn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_prn --&gt;
&lt;a name=&quot;prn_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prn_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2201">print file</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2202"><code>--fl_prn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2203"><code>--prn_fl</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--prn_fl <file>print-file</file></itemformat></item>
</tableterm><tableitem><para>Activate printing formatted output to file <file>print-file</file>.
Also <samp>--print_file</samp>, <samp>--fl_prn</samp>, and <samp>--file_print</samp>.
One can achieve the same result by redirecting stdout to a named file.
However, it is slightly faster to print formatted output directly to a
file than to stdout:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --fl_prn=foo.txt --jsn in.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;Q&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#Q --&gt;
&lt;a name=&quot;quiet&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#quiet --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2204"><code>-Q</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2205"><code>--quiet</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-Q</itemformat></item>
</tableterm><tableitem><para>Print quietly, meaning omit dimension names, indices, and coordinate
values when printing arrays. 
Variable (not dimension) indices are printed.
Variable names appear flush left in the output:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@roulee:~$ ncks --trd -Q -v three_dmn_rec_var -C -H ~/nco/data/in.nc              
three_dmn_rec_var[0]=1 
...
</verbatim>
</example>
<para>This helps locate specific variables in lists with many variables and 
different dimensions. 
See also the <samp>-V</samp> option, which omits all names and indices and
prints only variable values. 
</para>
<html endspaces=" ">
&lt;a name=&quot;q&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#q --&gt;
&lt;a name=&quot;quench&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#quench --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2206"><code>-q</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2207"><code>--quench</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2208">quench</indexterm></cindex>
<item spaces=" "><itemformat command="samp">-q </itemformat></item>
</tableterm><tableitem><para>Quench (turn-off) all printing to screen.
This overrides the setting of all print-related switches, equivalent to
<kbd>-H -M -m</kbd> when in single-file printing mode. 
When invoked with <code>-R</code> (<pxref label="Retaining-Retrieved-Files"><xrefnodename>Retaining Retrieved Files</xrefnodename></pxref>), <command>ncks</command>
automatically sets <code>-q</code>. 
This allows <command>ncks</command> to retrieve remote files without
automatically trying to print them.
Also <samp>--quench</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;rad&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rad --&gt;
&lt;a name=&quot;orphan&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#orphan --&gt;
&lt;a name=&quot;rph_dmn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rph_dmn --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2209"><code>--rad</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2210">orphan dimensions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2211"><code>--retain_all_dimensions</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2212"><code>--orphan_dimensions</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2213"><code>--rph_dmn</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--rad</itemformat></item>
</tableterm><tableitem><para>Retain all dimensions.
When invoked with <code>--rad</code> (Retain All Dimensions),
<command>ncks</command> copies each dimension in the input file to the output
file, regardless of whether the dimension is utilized by any variables. 
Normally <command>ncks</command> discards &textldquo;orphan dimensions&textrdquo;, i.e., dimensions
not referenced by any variables.
This switch allows users to keep non-referenced dimensions in the workflow.
When invoked in printing mode, causes orphaned dimensions to be printed
(they are not printed by default).
Also <samp>--retain_all_dimensions</samp>, <samp>--orphan_dimensions</samp>, and
<samp>--rph_dmn</samp>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;s&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#s --&gt;
&lt;a name=&quot;sng_fmt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sng_fmt --&gt;
&lt;a name=&quot;string&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#string --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2214"><code>-s</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2215"><code>--string</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2216"><code>--sng_fmt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2217"><code>printf()</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2218">C language</indexterm></cindex>
<item spaces=" "><itemformat command="samp">-s <var>format</var></itemformat></item>
</tableterm><tableitem><para>String format for text output. 
Accepts <w>C language</w> escape sequences and <code>printf()</code> formats. 
Also <samp>--string</samp>  and <samp>--sng_fmt</samp>.
This option is only intended for use with traditional (<acronym><acronymword>TRD</acronymword></acronym>)
printing, and thus automatically invokes the <samp>--trd</samp> switch.
</para>
<html endspaces=" ">
&lt;a name=&quot;fmt_val&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fmt_val --&gt;
&lt;a name=&quot;val_fmt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#val_fmt --&gt;
&lt;a name=&quot;value_format&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#value_format --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2219"><code>--value_format</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2220"><code>--fmt_val</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2221"><code>--val_fmt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2222"><code>printf()</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2223">C language</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--fmt_val <var>format</var></itemformat></item>
</tableterm><tableitem><para>Supply a <code>printf()</code>-style format for printed output, i.e., in
<acronym><acronymword>CDL</acronymword></acronym>, <acronym><acronymword>JSON</acronymword></acronym>, <acronym><acronymword>TRD</acronymword></acronym>, or <acronym><acronymword>XML</acronymword></acronym> modes. 
Also <samp>--val_fmt</samp> and <samp>--value_format</samp>.
One use for this option is to reduce the printed precision of floating
point values: 
</para><example endspaces=" ">
<pre xml:space="preserve"># Default printing of original double precision values
# 0.0,0.1,0.12,0.123,0.1234,0.12345,0.123456,0.1234567,0.12345678,0.123456789
% ncks -C -v ppc_dbl ~/nco/data/in.nc
...
ppc_dbl = 0, 0.1, 0.12, 0.123, 0.1234, 0.12345, 0.123456, 0.1234567, 0.12345678, 0.123456789 ;
...
# Restrict printing to three digits after the decimal
% ncks --fmt_val=%.3f -C -v ppc_dbl ~/nco/data/in.nc
...
ppc_dbl = 0., 0.1, 0.12, 0.123, 0.123, 0.123, 0.123, 0.123, 0.123, 0.123 ;
...
</pre></example>
<noindent></noindent>
<para>The supplied <var>format</var> only applies to floating point variable values 
(<code>NC_FLOAT</code> or <code>NC_DOUBLE</code>), and not to other types or to
attributes.
For reference, the default <code>printf()</code> <var>format</var> for
<acronym><acronymword>CDL</acronymword></acronym>, <acronym><acronymword>JSON</acronymword></acronym>, <acronym><acronymword>TRD</acronymword></acronym>, and <acronym><acronymword>XML</acronymword></acronym> modes is
<code>%#.7gf</code>, <code>%#.7g</code>,  <code>%g</code>,    and <code>%#.7g</code>,
respectively, for single-precision data, and, for double-precision data is
<code>%#.15g</code>, <code>%#.15g</code>, <code>%.12g</code>, and <code>%#.15g</code>,
respectively.
<acronym><acronymword>NCO</acronymword></acronym> introduced this feature in version 4.7.3 (March, 2018).
We would appreciate your feedback on whether and how to extend this
feature to make it more useful. 
</para>
<html endspaces=" ">
&lt;a name=&quot;hrz&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hrz --&gt;
&lt;a name=&quot;hrz_crd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hrz_crd --&gt;
&lt;a name=&quot;hrz_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hrz_fl --&gt;
&lt;a name=&quot;fl_hrz&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_hrz --&gt;
&lt;a name=&quot;s1d&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#s1d --&gt;
&lt;a name=&quot;restart&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#restart --&gt;
&lt;a name=&quot;sparse&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sparse --&gt;
&lt;a name=&quot;unpack_sparse&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#unpack_sparse --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2224">restart files</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2225">sparse format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2226"><acronym><acronymword>S1D</acronymword></acronym> format</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2227"><code>--unpack_sparse</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2228"><code>--s1d</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2229"><code>--sparse</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2230"><code>--hrz</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2231"><code>--hrz_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2232"><code>--hrz_crd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2233"><acronym><acronymword>PFT</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2234"><acronym><acronymword>MEC</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2235">multiple elevation classes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2236">elevation classes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2237">landunit</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2238">topounit</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2239">plant functional type</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--s1d, --sparse, --unpack_sparse, --hrz <file>file</file></itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.2.0</w>, released in February, 2024,
<command>ncks</command> can help analyze initial condition and restart datasets 
produced by the <acronym><acronymword>E3SM ELM</acronymword></acronym> and <acronym><acronymword>CESM CLM/CTSM</acronymword></acronym>
land-surface models. 
Whereas gridded history datasets from these <acronym><acronymword>ESM</acronymword></acronym>s use a
standard gridded data format, land-surface &quot;restart files&quot; employ a  
custom packing format that unwinds multi-dimensional data into
sparse, 1-D (<acronym><acronymword>S1D</acronymword></acronym>) arrays that are not easily
visualized.
<command>ncks</command> can convert <acronym><acronymword>S1D</acronymword></acronym> files into gridded datasets
where all dimensions are explicitly declared, rather than unrolled or 
&quot;packed&quot;.  
Invoke this conversion feature with the <code>--s1d</code> option
(or long option equivalents, <code>--sparse</code> or <code>--unpacksparse</code>) 
and, with <samp>--hrz_crd <var>fl_hrz</var></samp> (e.g.,
<samp>--hrz_crd <file>hrz.nc</file></samp>), point to the file that contains the 
horizontal coordinates (that restart files usually omit).
The output file is the fully gridded input file, with no loss
of information:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks --s1d --hrz=elmv3_history.nc elmv3_restart.nc out.nc
</verbatim>
</example>
<para>The output file contains all input variables placed on a lat-lon or 
unstructured grid, with new dimensions for Plant Funtional Type
(<acronym><acronymword>PFT</acronymword></acronym>) and multiple elevation classes (<acronym><acronymword>MEC</acronymword></acronym>s).
</para>
<html endspaces=" ">
&lt;a name=&quot;ssh&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ssh --&gt;
&lt;a name=&quot;scr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#scr --&gt;
&lt;a name=&quot;secret&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#secret --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2240"><code>--ssh</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2241"><code>--scr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2242"><code>--secret</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2243">hidden features</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--ssh, --secret</itemformat></item>
</tableterm><tableitem><para>Print summary of <command>ncks</command> hidden features.
These hidden or secret features are used mainly by developers.
They are not supported for general use and may change at any time.
This demonstrates conclusively that I cannot keep a secret.
Also <samp>--ssh</samp> and <samp>--scr</samp>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;trd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#trd --&gt;
&lt;a name=&quot;traditional&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#traditional --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2244"><code>--trd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2245"><code>--traditional</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--trd, --traditional</itemformat></item>
</tableterm><tableitem><para>From 1995&textndash;2017 <command>ncks</command> dumped the <acronym><acronymword>ASCII</acronymword></acronym> text
representation of netCDF files in what we now call &textldquo;traditional&textrdquo;
mode. 
Much of this manual contains output printed in traditional mode,
which places one value per line, with complete dimensional
information.
Traditional-mode metadata output includes lower-level information,
such as <acronym><acronymword>RAM</acronymword></acronym> usage and internal variable IDs, than
<acronym><acronymword>CDL</acronymword></acronym>.  
While this is useful for some developers and user, <acronym><acronymword>CDL</acronymword></acronym> has,
over the years, become more useful than traditional mode for most
users.  
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.9 (September, 2017) <acronym><acronymword>CDL</acronymword></acronym> became 
the default printing mode. 
Traditional printing mode is accessed via the <samp>--trd</samp> option.  
</para>
<html endspaces=" ">
&lt;a name=&quot;units&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#units --&gt;
&lt;a name=&quot;u&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#u --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2246"><code>-u</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2247"><code>--units</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-u, --units</itemformat></item>
</tableterm><tableitem><para>Toggle the printing of a variable&textrsquo;s <code>units</code> attribute, if any, 
with its values.
Also <samp>--units</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;V&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#V --&gt;
&lt;a name=&quot;val_var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#val_var --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2248"><code>-V</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2249"><code>--val_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2250"><code>--no_dmn_var_nm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2251"><code>--no_nm_prn</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-V</itemformat></item>
</tableterm><tableitem><para>Print variable values only.
Do not print variable and dimension names, indices, and coordinate
values when printing arrays. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@roulee:~$ ncks --trd -V -v three_dmn_rec_var -C -H ~/nco/data/in.nc
1
...
</verbatim>
</example>
<para>See also the <samp>-Q</samp> option, which prints variable names and indices,
but not dimension names, indices, or coordinate values when printing
arrays. 
Using <samp>-V</samp> is the same as specifying <samp>-Q --no_nm_prn</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;xml&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xml --&gt;
&lt;a name=&quot;ncml&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncml --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2252"><code>--xml</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2253"><code>--ncml</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2254"><command>ncdump</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2255"><acronym><acronymword>XML</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2256"><acronym><acronymword>NcML</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--xml, --ncml</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.3.3 (July, 2013), <command>ncks</command> can
print extracted data and metadata to screen (i.e., <code>stdout</code>) as 
<acronym><acronymword>XML</acronymword></acronym> in <acronym><acronymword>NcML</acronymword></acronym>, the netCDF Markup Language.  
<command>ncks</command> supports <acronym><acronymword>XML</acronymword></acronym> more completely than 
<samp>ncdump -x</samp>.
With <command>ncks</command> one can translate entire netCDF3 and netCDF4 files
into <acronym><acronymword>NcML</acronymword></acronym>, including metadata and data, using all 
<acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s subsetting and hyperslabbing capabilities.
Compare <command>ncks</command> &textldquo;traditional&textrdquo; with <acronym><acronymword>XML</acronymword></acronym> printing:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@roulee:~$ ncks --trd -v one ~/nco/data/in.nc
one: type NC_FLOAT, 0 dimensions, 1 attribute, chunked? no, compressed? no, packed? no
one size (RAM) = 1*sizeof(NC_FLOAT) = 1*4 = 4 bytes
one attribute 0: long_name, size = 3 NC_CHAR, value = one

one = 1 

zender@roulee:~$ ncks --xml -v one ~/nco/data/in.nc
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;netcdf xmlns=&quot;http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2&quot; location=&quot;/home/zender/nco/data/in.nc&quot;&gt;
  &lt;variable name=&quot;one&quot; type=&quot;float&quot; shape=&quot;&quot;&gt;
    &lt;attribute name=&quot;long_name&quot; separator=&quot;*&quot; value=&quot;one&quot; /&gt;
    &lt;values&gt;1.&lt;/values&gt;
  &lt;/variable&gt;
&lt;/netcdf&gt;
</verbatim>
</example>
<para><acronym><acronymword>XML</acronymword></acronym>-mode prints variable metadata and, as of 
<acronym><acronymword>NCO</acronymword></acronym> version 4.3.7 (October, 2013), variable data and, as of
<acronym><acronymword>NCO</acronymword></acronym> version 4.4.0 (January, 2014), hidden attributes.
That <acronym><acronymword>ncks</acronymword></acronym> produces correct <acronym><acronymword>NcML</acronymword></acronym> translations of
<acronym><acronymword>CDM</acronymword></acronym> files for all supported datatypes is verified by
comparison to output from Unidata&textrsquo;s <command>toolsUI</command> Java program.
Please let us know how to improve <acronym><acronymword>XML</acronymword></acronym>/<acronym><acronymword>NcML</acronymword></acronym>
features. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2257"><code>--xml_no_location</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2258"><code>--xml_spr_chr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2259"><code>--xml_spr_nmr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2260">separator</indexterm></cindex>
<para><command>ncks</command> provides additional options to configure <acronym><acronymword>NcML</acronymword></acronym>
output: <samp>--xml_no_location</samp>, <samp>--xml_spr_chr</samp>, and
<samp>--xml_spr_nmr</samp>. 
Every <acronym><acronymword>NcML</acronymword></acronym> configuration option automatically triggers
<acronym><acronymword>NcML</acronymword></acronym> printing, so that specifying <samp>--xml</samp> in addition
to a configuration option is redundant and unnecessary.
The <samp>--xml_no_location</samp> switch prevents output of the
<acronym><acronymword>NcML</acronymword></acronym> <code>location</code> element.
By default the location element is printed with a value equal to the
location of the input dataset, e.g.,
<code>location=&quot;/home/zender/in.nc&quot;</code>.
The <samp>--xml_spr_chr</samp> and <samp>--xml_spr_nmr</samp> options customize
the strings used as <acronym><acronymword>NcML</acronymword></acronym> separators for attributes and
variables of character-type and numeric-type, respectively.
Their default separators are <code>*</code> and &textldquo;<code> </code>&textrdquo; (a space):
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@roulee:~$ ncks --xml -d time,0,3 -v two_dmn_rec_var_sng in.nc
...
   &lt;values separator=&quot;*&quot;&gt;abc*bcd*cde*def&lt;/values&gt;
 ...
 zender@roulee:~$ ncks --xml_spr_chr=', ' -v two_dmn_rec_var_sng in.nc
...
&lt;values separator=&quot;, &quot;&gt;abc, bcd, cde, def, efg, fgh, ghi, hij, jkl, klm&lt;/values&gt;
...
zender@roulee:~$ ncks --xml -v one_dmn_rec_var in.nc
...
&lt;values&gt;1 2 3 4 5 6 7 8 9 10&lt;/values&gt;
...
zender@roulee:~$ ncks --xml_spr_nmr=', ' -v one_dmn_rec_var in.nc
...
&lt;values separator=&quot;, &quot;&gt;1, 2, 3, 4, 5, 6, 7, 8, 9, 10&lt;/values&gt;
...
</verbatim>
</example>
<para>Separator elements for strings are a thorny issue.
One must be sure that the separator element is not mistaken as a portion
of the string. 
<acronym><acronymword>NCO</acronymword></acronym> attempts to produce valid <acronym><acronymword>NcML</acronymword></acronym> and supplies the
<samp>--xml_spr_chr</samp> option to work around any difficulties.
<acronym><acronymword>NCO</acronymword></acronym> performs precautionary checks with
<code>strstr(<var>val</var>,<var>spr</var>)</code> to identify presence of the separator
string (<var>spr</var>) in data (<var>val</var>) and, when it detects a match,
automatically switches to a backup separator string (<code>*|*</code>). 
However limitations of <code>strstr()</code> may lead to false negatives 
when the separator string occurs in data beyond the first string in
multi-dimensional <code>NC_CHAR</code> arrays. 
Hence, results may be ambiguous to NcML parsers. 
If problems arise, use <samp>--xml_spr_chr</samp> to specify a multi-character
separator that does not appear in the string array and that does not
include an NcML formatting characters (e.g., commas, angles, quotes).
</para></tableitem></tableentry></table>

<html endspaces=" ">
&lt;a name=&quot;ncattget&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncattget --&gt;
&lt;a name=&quot;nclst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nclst --&gt;
&lt;a name=&quot;ncvarlst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncvarlst --&gt;
&lt;a name=&quot;ncvardmnlst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncvardmnlst --&gt;
&lt;a name=&quot;ncdmnlst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncdmnlst --&gt;
&lt;a name=&quot;ncdmnsz&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncdmnsz --&gt;
&lt;a name=&quot;ncgrplst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncgrplst --&gt;
&lt;a name=&quot;ncrecsz&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncrecsz --&gt;
&lt;a name=&quot;ncmax&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncmax --&gt;
&lt;a name=&quot;ncmdn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncmdn --&gt;
&lt;a name=&quot;ncavg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncavg --&gt;
&lt;a name=&quot;ncrng&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncrng --&gt;
&lt;a name=&quot;ncunits&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncunits --&gt;
&lt;a name=&quot;alias&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alias --&gt;
&lt;a name=&quot;filters&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#filters --&gt;
&lt;a name=&quot;filter&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#filter --&gt;
&lt;a name=&quot;flt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#flt --&gt;
</html>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Filters for <command>ncks</command></menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

</unnumberedsubsec>
<node name="Filters-for-ncks" spaces=" "><nodename>Filters for <command>ncks</command></nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">ncks netCDF Kitchen Sink</nodeprev><nodeup spaces=" ">ncks netCDF Kitchen Sink</nodeup></node>
<subsection spaces=" "><sectiontitle>Filters for <command>ncks</command></sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2261"><acronym><acronymword>UNIX</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2262"><command>ncattget</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2263"><command>ncavg</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2264"><command>ncdmnlst</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2265"><command>ncvardmnlst</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2266"><command>ncvardmnlatlon</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2267"><command>ncdmnsz</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2268"><command>ncgrplst</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2269"><command>nclst</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2270"><command>nclst</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2271"><command>ncmax</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2272"><command>ncmdn</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2273"><command>ncmin</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2274"><command>ncrecsz</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2275"><command>ncrng</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2276"><command>nctypget</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2277"><command>ncunits</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2278"><file>.bashrc</file></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2279">filters</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2280">alias</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2281">shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2282">Bash shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2283">Csh shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2284">Sh shell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2285"><command>bash</command></indexterm></cindex>
<para>We encourage the use of standard <acronym><acronymword>UNIX</acronymword></acronym> pipes and filters to
narrow the verbose output of <command>ncks</command> into more precise targets.
For example, to obtain an uncluttered listing of the variables in a file
try 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --trd -m in.nc | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort
</pre></example>
<para>A Bash user could alias the previous filter to the shell command
<command>ncvarlst</command> as shown below.
More complex examples could involve command line arguments.
For example, a user may frequently be interested in obtaining the value
of an attribute, e.g., for textual file examination or for passing to
another shell command.
Say the attribute is <code>purpose</code>, the variable is <code>z</code>, and the
file is <code>in.nc</code>.
In this example, <command>ncks --trd -m -v z</command> is too verbose so a robust
<command>grep</command> and <command>cut</command> filter is desirable, such as
</para><example endspaces=" ">
<pre xml:space="preserve">ncks --trd -M -m in.nc | grep -E -i &quot;^z attribute [0-9]+: purpose&quot; | cut -f 11- -d ' ' | sort
</pre></example>
<para>The filters are clearly too complex to remember on-the-fly so the entire 
procedure could be implemented as a shell command or function called,
say, <command>ncattget</command>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
function ncattget { ncks --trd -M -m ${3} | grep -E -i &quot;^${2} attribute [0-9]+: ${1}&quot; | cut -f 11- -d ' ' | sort ; }
</verbatim>
</example>
<para>The shell <command>ncattget</command> is invoked with three arugments that are,
in order, the names of the attribute, variable, and file to examine.
Global attributes are indicated by using a variable name of <code>global</code>.
This definition yields the following results
</para><example endspaces=" ">
<pre xml:space="preserve">% ncattget purpose z in.nc
Height stored with a monotonically increasing coordinate
% ncattget Purpose Z in.nc
Height stored with a monotonically increasing coordinate
% ncattget history z in.nc
% ncattget history global in.nc
History global attribute.
</pre></example>
<para>Note that case sensitivity has been turned off for the variable and
attribute names (and could be turned on by removing the <samp>-i</samp> switch
to <command>grep</command>).
Furthermore, extended regular expressions may be used for both the
variable and attribute names.
The next two commands illustrate this by searching for the values
of attribute <code>purpose</code> in all variables, and then for all
attributes of the variable <code>z</code>:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncattget purpose .+ in.nc
1-D latitude coordinate referred to by geodesic grid variables
1-D longitude coordinate referred to by geodesic grid variables
...
% ncattget .+ Z in.nc
Height
Height stored with a monotonically increasing coordinate
meter
</pre></example>

<para>Extended filters are best stored as shell commands if they are
used frequently.
Shell commands may be re-used when they are defined in shell
configuration files.
These files are usually named <file>.bashrc</file>, <file>.cshrc</file>, and
<file>.profile</file> for the Bash, Csh, and Sh shells, respectively.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2286">minimum</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2287">maximum</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2288">median</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2289">mode</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2290">range</indexterm></cindex>
<html endspaces=" ">
&lt;a name=&quot;median&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#median --&gt;
&lt;a name=&quot;mode&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mode --&gt;
&lt;a name=&quot;range&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#range --&gt;
</html>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# NB: Untested on Csh, Ksh, Sh, Zsh! Send us feedback!
# Bash shell (/bin/bash), .bashrc examples
# ncattget $att_nm $var_nm $fl_nm : What attributes does variable have?
function ncattget { ncks --trd -M -m ${3} | grep -E -i &quot;^${2} attribute [0-9]+: ${1}&quot; | cut -f 11- -d ' ' | sort ; }
# ncunits $att_val $fl_nm : Which variables have given units?
function ncunits { ncks --trd -m ${2} | grep -E -i &quot; attribute [0-9]+: units.+ ${1}&quot; | cut -f 1 -d ' ' | sort ; }
# ncavg $var_nm $fl_nm : What is mean of variable?
function ncavg { ncwa -y avg -O -C -v ${1} ${2} ~/foo.nc ; ncks --trd -H -C -v ${1} ~/foo.nc | cut -f 3- -d ' ' ; }
# ncavg $var_nm $fl_nm : What is mean of variable?
function ncavg { ncap2 -O -C -v -s &quot;foo=${1}.avg();print(foo)&quot; ${2} ~/foo.nc | cut -f 3- -d ' ' ; }
# ncdmnlst $fl_nm : What dimensions are in file?
function ncdmnlst { ncks --cdl -m ${1} | cut -d ':' -f 1 | cut -d '=' -s -f 1 ; }
# ncvardmnlst $var_nm $fl_nm : What dimensions are in a variable?
function ncvardmnlst { ncks --trd -m -v ${1} ${2} | grep -E -i &quot;^${1} dimension [0-9]+: &quot; | cut -f 4 -d ' ' | sed 's/,//' ; }
# ncvardmnlatlon $var_nm $fl_nm : Does variable contain both lat and lon dimensions?
function ncvardmnlatlon { flg=`ncks -C -v ${1} -m ${2} | grep -E -i &quot;${1}\(&quot; | grep -E &quot;lat.*lon|lon.*lat&quot;` ; [[ ! -z &quot;$flg&quot; ]] &amp;&amp; echo &quot;Yes, ${1} has both lat and lon dimensions&quot; || echo &quot;No, ${1} does not have both lat and lon dimensions&quot; }
# ncdmnsz $dmn_nm $fl_nm : What is dimension size?
function ncdmnsz { ncks --trd -m -M ${2} | grep -E -i &quot;: ${1}, size =&quot; | cut -f 7 -d ' ' | uniq ; }
# ncgrplst $fl_nm : What groups are in file?
function ncgrplst { ncks -m ${1} | grep 'group:' | cut -d ':' -f 2 | cut -d ' ' -f 2 | sort ; }
# ncvarlst $fl_nm : What variables are in file?
function ncvarlst { ncks --trd -m ${1} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort ; }
# ncmax $var_nm $fl_nm : What is maximum of variable?
function ncmax { ncwa -y max -O -C -v ${1} ${2} ~/foo.nc ; ncks --trd -H -C -v ${1} ~/foo.nc | cut -f 3- -d ' ' ; }
# ncmax $var_nm $fl_nm : What is maximum of variable?
function ncmax { ncap2 -O -C -v -s &quot;foo=${1}.max();print(foo)&quot; ${2} ~/foo.nc | cut -f 3- -d ' ' ; }
# ncmdn $var_nm $fl_nm : What is median of variable?
function ncmdn { ncap2 -O -C -v -s &quot;foo=gsl_stats_median_from_sorted_data(${1}.sort());print(foo)&quot; ${2} ~/foo.nc | cut -f 3- -d ' ' ; }
# ncmin $var_nm $fl_nm : What is minimum of variable?
function ncmin { ncap2 -O -C -v -s &quot;foo=${1}.min();print(foo)&quot; ${2} ~/foo.nc | cut -f 3- -d ' ' ; }
# ncrng $var_nm $fl_nm : What is range of variable?
function ncrng { ncap2 -O -C -v -s &quot;foo_min=${1}.min();foo_max=${1}.max();print(foo_min,\&quot;%f\&quot;);print(\&quot; to \&quot;);print(foo_max,\&quot;%f\&quot;)&quot; ${2} ~/foo.nc ; }
# ncmode $var_nm $fl_nm : What is mode of variable?
function ncmode { ncap2 -O -C -v -s &quot;foo=gsl_stats_median_from_sorted_data(${1}.sort());print(foo)&quot; ${2} ~/foo.nc | cut -f 3- -d ' ' ; }
# ncrecsz $fl_nm : What is record dimension size?
function ncrecsz { ncks --trd -M ${1} | grep -E -i &quot;^Root record dimension 0:&quot; | cut -f 10- -d ' ' ; }
# nctypget $var_nm $fl_nm : What type is variable?
function nctypget { ncks --trd -m -v ${1} ${2} | grep -E -i &quot;^${1}: type&quot; | cut -f 3 -d ' ' | cut -f 1 -d ',' ; }

# Csh shell (/bin/csh), .cshrc examples (derive others from Bash definitions):
ncattget() { ncks --trd -M -m -v ${3} | grep -E -i &quot;^${2} attribute [0-9]+: ${1}&quot; | cut -f 11- -d ' ' | sort ; }
ncdmnsz() { ncks --trd -m -M ${2} | grep -E -i &quot;: ${1}, size =&quot; | cut -f 7 -d ' ' | uniq ; }
ncvarlst() { ncks --trd -m ${1} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort ; }
ncrecsz() { ncks --trd -M ${1} | grep -E -i &quot;^Record dimension:&quot; | cut -f 8- -d ' ' ; }

# Sh shell (/bin/sh), .profile examples (derive others from Bash definitions):
ncattget() { ncks --trd -M -m ${3} | grep -E -i &quot;^${2} attribute [0-9]+: ${1}&quot; | cut -f 11- -d ' ' | sort ; }
ncdmnsz() { ncks --trd -m -M ${2} | grep -E -i &quot;: ${1}, size =&quot; | cut -f 7 -d ' ' | uniq ; }
ncvarlst() { ncks --trd -m ${1} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort ; }
ncrecsz() { ncks --trd -M ${1} | grep -E -i &quot;^Record dimension:&quot; | cut -f 8- -d ' ' ; }
</verbatim>
</example>

<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncks&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncks --&gt;
</html>
<para>EXAMPLES
</para>
<para>View all data in netCDF <file>in.nc</file>, printed with Fortran indexing
conventions: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -F in.nc
</pre></example>

<para>Copy the netCDF file <file>in.nc</file> to file <file>out.nc</file>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncks in.nc out.nc
</pre></example>
<para>Now the file <file>out.nc</file> contains all the data from <file>in.nc</file>.
There are, however, two differences between <file>in.nc</file> and
<file>out.nc</file>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2291"><code>history</code></indexterm></cindex>
First, the <code>history</code> global attribute (<pxref label="History-Attribute"><xrefnodename>History Attribute</xrefnodename></pxref>)
will contain the command used to create <file>out.nc</file>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2292">alphabetize output</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2293">sort alphabetically</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2294"><code>-a</code></indexterm></cindex>
Second, the variables in <file>out.nc</file> will be defined in alphabetical
order.
Of course the internal storage of variable in a netCDF file should be
transparent to the user, but there are cases when alphabetizing a file 
is useful (see description of <code>-a</code> switch).
</para>
<html endspaces=" ">
&lt;a name=&quot;xmp_att_glb_cpy&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_att_glb_cpy --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2295">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2296">attributes, global</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2297">subsetting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2298">exclusion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2299">extraction</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2300"><code>-v <var>var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2301"><code>--variable <var>var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2302"><code>-x</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2303"><code>--exclude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2304"><code>--xcl</code></indexterm></cindex>
<para>Copy all global attributes (and no variables) from <file>in.nc</file> to
<file>out.nc</file>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -A -x ~/nco/data/in.nc ~/out.nc
</pre></example>
<para>The <samp>-x</samp> switch tells <acronym><acronymword>NCO</acronymword></acronym> to use the complement of the
extraction list (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>). 
Since no extraction list is explicitly specified (with <samp>-v</samp>),
the default is to extract all variables.
The complement of all variables is no variables.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2305"><code>-A</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2306"><code>--apn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2307"><code>--append</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2308">appending to files</indexterm></cindex>
Without any variables to extract, the append (<samp>-A</samp>) command
(<pxref label="Appending-Variables"><xrefnodename>Appending Variables</xrefnodename></pxref>) has only to extract and copy
(i.e., append) global attributes to the output file.
</para>
<html endspaces=" ">
&lt;a name=&quot;xmp_att_glb_cpy&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_att_var_cpy --&gt;
</html>
<para>Copy/append metadata (not data) from variables in one file to
variables in a second file.
When copying/subsetting/appending files (as opposed to printing them),
the copying of data, variable metadata, and global/group metadata are
now turned OFF by <samp>-H</samp>, <samp>-m</samp>, and <samp>-M</samp>, respectively. 
This is the opposite sense in which these switches work when
<emph>printing</emph> a file. 
One can use these switches to easily replace data or metadata in one
file with data or metadata from another:
</para><example endspaces=" ">
<pre xml:space="preserve"># Extract naked (data-only) copies of two variables
ncks -h -M -m -O -C -v one,three_dmn_rec_var ~/nco/data/in.nc ~/out.nc
# Change values to be sure original values are not copied in following step
ncap2 -O -v -s 'one*=2;three_dmn_rec_var*=0' ~/nco/data/in.nc ~/in2.nc
# Append in2.nc metadata (not data!) to out.nc
ncks -A -C -H -v one,three_dmn_rec_var ~/in2.nc ~/out.nc
</pre></example>
<para>Variables in <file>out.nc</file> now contain data (not metadata) from
<file>in.nc</file> and metadata (not data) from <file>in2.nc</file>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2309"><code>-s</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2310"><code>--string</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2311"><code>--sng_fmt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2312"><code>printf()</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2313"><code>\n</code> (linefeed)</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2314"><code>\t</code> (horizontal tab)</indexterm></cindex>
<para>Print variable <code>three_dmn_var</code> from file <file>in.nc</file> with
default notations. 
Next print <code>three_dmn_var</code> as an un-annotated text column.
Then print <code>three_dmn_var</code> signed with very high precision.
Finally, print <code>three_dmn_var</code> as a comma-separated list:
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks --trd -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0 
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1 
...
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23 
% ncks --trd -s '%f\n' -C -v three_dmn_var in.nc
0.000000
1.000000
...
23.000000
% ncks --trd -s '%+16.10f\n' -C -v three_dmn_var in.nc
   +0.0000000000
   +1.0000000000
...
  +23.0000000000
% ncks --trd -s '%f, ' -C -v three_dmn_var in.nc
0.000000, 1.000000, ..., 23.000000,
</pre></example>
<noindent></noindent>
<para>Programmers will recognize these as the venerable <w>C language</w> 
<code>printf()</code> formatting strings. 
The second and third options are useful when pasting data into text
files like reports or papers.  
<xref label="ncatted-netCDF-Attribute-Editor"><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></xref>, for more details on string
formatting and special characters.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2315"><code>--no_blank</code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.2.2 (October, 2012), <acronym><acronymword>NCO</acronymword></acronym> prints
missing values as blanks (i.e., the underscore character <samp>_</samp>) by
default: 
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks --trd -C -H -v mss_val in.nc
lon[0]=0 mss_val[0]=73 
lon[1]=90 mss_val[1]=_ 
lon[2]=180 mss_val[2]=73 
lon[3]=270 mss_val[3]=_ 
% ncks -s '%+5.1f, ' -H -C -v mss_val in.nc
+73.0, _, +73.0, _, 
</pre></example>
<para>To print the numeric value of the missing value instead of a blank,
use the <samp>--no_blank</samp> option.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2316"><code>-Q</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2317"><code>--quiet</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2318"><code>-V</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2319"><code>--val_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2320"><code>--no_dmn_var_nm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2321"><code>--no_nm_prn</code></indexterm></cindex>
<para><command>ncks</command> prints in a verbose fashion by default and supplies a
number of switches to pare-down (or even spruce-up) the output.
The interplay of the <samp>-Q</samp>, <samp>-V</samp>, and (otherwise undocumented) 
<samp>--no_nm_prn</samp> switches yields most desired verbosities:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncks -v three_dmn_rec_var -C -H ~/nco/data/in.nc
time[0]=1 lat[0]=-90 lon[0]=0 three_dmn_rec_var[0]=1 
% ncks -Q -v three_dmn_rec_var -C -H ~/nco/data/in.nc              
three_dmn_rec_var[0]=1 
% ncks -V -v three_dmn_rec_var -C -H ~/nco/data/in.nc
1
% ncks -Q --no_nm_prn -v three_dmn_rec_var -C -H ~/nco/data/in.nc
1
% ncks --no_nm_prn -v three_dmn_rec_var -C -H ~/nco/data/in.nc
1 -90 0 1
</verbatim>
</example>

<para>One dimensional arrays of characters stored as netCDF variables are 
automatically printed as strings, whether or not they are
NUL-terminated, e.g.,
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -v fl_nm in.nc
</pre></example>
<noindent></noindent>
<para>The <code>%c</code> formatting code is useful for printing 
multidimensional arrays of characters representing fixed length strings
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -s '%c' -v fl_nm_arr in.nc
</pre></example>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2322"><code>core dump</code></indexterm></cindex>
<para>Using the <code>%s</code> format code on strings which are not NUL-terminated 
(and thus not technically strings) is likely to result in a core dump.
</para>
<html endspaces=" ">
&lt;a name=&quot;xmp_xtr_xcl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_xtr_xcl --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2323">subsetting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2324">exclusion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2325">extraction</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2326"><code>-x</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2327"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2328"><code>coordinates</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2329"><code>climatology</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2330"><code>bounds</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2331"><code>ancillary_variables</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2332"><code>grid_mapping</code> attribute</indexterm></cindex>
<para>Create netCDF <file>out.nc</file> containing all variables, and any associated 
coordinates, except variable <code>time</code>, from netCDF <file>in.nc</file>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -x -v time in.nc out.nc
</pre></example>
<para>As a special case of this, consider how to remove a 
variable such as <code>time_bounds</code> that is identified in a
<acronym><acronymword>CF</acronymword></acronym> Convention (<pxref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></pxref>) compliant
<code>ancillary_variables</code>, <code>bounds</code>, <code>climatology</code>, 
<code>coordinates</code>, or <code>grid_mapping</code> attribute. 
<acronym><acronymword>NCO</acronymword></acronym> subsetting assumes the user wants all ancillary variables,
axes, bounds and coordinates associated with all extracted variables 
(<pxref label="Subsetting-Coordinate-Variables"><xrefnodename>Subsetting Coordinate Variables</xrefnodename></pxref>).
Hence to exclude a <code>ancillary_variables</code>, <code>bounds</code>,
<code>climatology</code>, <code>coordinates</code>, or <code>grid_mapping</code> variable
while retaining the &textldquo;parent&textrdquo; variable (here <code>time</code>), one must use
the <samp>-C</samp> switch:  
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -C -x -v time_bounds in.nc out.nc
</pre></example>
<para>The <samp>-C</samp> switch tells the operator <emph>NOT</emph> to necessarily
include all the <acronym><acronymword>CF</acronymword></acronym> ancillary variables, axes, bounds, and
coordinates.
Hence the output file will contain <code>time</code> and not
<code>time_bounds</code>. 
</para>
<para>Extract variables <code>time</code> and <code>pressure</code> from netCDF
<file>in.nc</file>.  
If <file>out.nc</file> does not exist it will be created.
Otherwise the you will be prompted whether to append to or to
overwrite <file>out.nc</file>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -v time,pressure in.nc out.nc
ncks -C -v time,pressure in.nc out.nc
</pre></example>
<noindent></noindent>
<para>The first version of the command creates an <file>out.nc</file> which contains
<code>time</code>, <code>pressure</code>, and any coordinate variables associated
with <var>pressure</var>. 
The <file>out.nc</file> from the second version is guaranteed to contain only 
two variables <code>time</code> and <code>pressure</code>.  
</para>
<para>Create netCDF <file>out.nc</file> containing all variables from file
<file>in.nc</file>.  
Restrict the dimensions of these variables to a hyperslab. 
<!-- c Print (with @code{-H}) the hyperslabs to the screen for good measure.   -->
The specified hyperslab is: the fifth value in dimension <code>time</code>;
the 
half-open range <math><var>lat</var> &gt; 0.</math> in coordinate <code>lat</code>; the
half-open range <math><var>lon</var> &lt; 330.</math> in coordinate <code>lon</code>; the
closed interval <math>0.3 &lt; <var>band</var> &lt; 0.5</math> in coordinate <code>band</code>;
and cross-section closest to 1000.&noeos; in coordinate <code>lev</code>.  
Note that limits applied to coordinate values are specified with a
decimal point, and limits applied to dimension indices do not have a 
decimal point <xref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></xref>.
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -d time,5 -d lat,,0.0 -d lon,330.0, -d band,0.3,0.5 
-d lev,1000.0 in.nc out.nc 
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="2333">wrapped coordinates</indexterm></cindex>
<para>Assume the domain of the monotonically increasing longitude coordinate
<code>lon</code> is <math>0 &lt; <var>lon</var> &lt; 360</math>. 
Here, <code>lon</code> is an example of a wrapped coordinate.
<command>ncks</command> will extract a hyperslab which crosses the Greenwich
meridian simply by specifying the westernmost longitude as <var>min</var> and 
the easternmost longitude as <var>max</var>, as follows:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -d lon,260.0,45.0 in.nc out.nc
</pre></example>
<para>For more details <xref label="Wrapped-Coordinates"><xrefnodename>Wrapped Coordinates</xrefnodename></xref>.
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncpdq&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncpdq --&gt;
&lt;a name=&quot;ncpack&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncpack --&gt;
&lt;a name=&quot;ncunpack&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncunpack --&gt;
</html>
</subsection>
</section>
<node name="ncpdq-netCDF-Permute-Dimensions-Quickly" spaces=" "><nodename>ncpdq netCDF Permute Dimensions Quickly</nodename><nodenext spaces=" ">ncra netCDF Record Averager</nodenext><nodeprev spaces=" ">ncks netCDF Kitchen Sink</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncpdq</command> netCDF Permute Dimensions Quickly</sectiontitle>
<findex index="fn" spaces=" "><indexterm index="fn" number="37" mergedindex="cp">ncpdq</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="38" mergedindex="cp">ncpack</indexterm></findex>
<findex index="fn" spaces=" "><indexterm index="fn" number="39" mergedindex="cp">ncunpack</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2334">reshape variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2335">permute dimensions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2336">reverse dimensions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2337">re-order dimensions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2338">re-dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2339">packing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2340">unpacking</indexterm></cindex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncpdq [-3] [-4] [-5] [-6] [-7] [-A] [-a [-]<var>dim</var>[,&dots;]]
[-C] [-c] [--cmp <var>cmp_sng</var>]
[--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F] [--fl_fmt <var>fl_fmt</var>]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...]
[-H] [-h] [--hdf] [--hdr_pad <var>nbr</var>] [--hpss] 
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [-M <var>pck_map</var>] [--mrd]
[--no_cll_msr] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>output-file</var>] [-P <var>pck_plc</var>] [-p <var>path</var>]
[--qnt ...] [--qnt_alg <var>alg_nm</var>] [-R] [-r] [--ram_all] [-t <var>thr_nbr</var>]
[-U] [--unn] [-v <var>var</var>[,&dots;]] [-X ...] [-x]
<var>input-file</var> [<var>output-file</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncpdq</command> performs one (not both) of two distinct functions
per invocation: packing or dimension permutation.
Without any options, <command>ncpdq</command> will pack data with default
parameters.
The <samp>-a</samp> option tells <command>ncpdq</command> to permute dimensions
accordingly, otherwise <command>ncpdq</command> will pack data as
instructed/controlled by the <samp>-M</samp> and <samp>-P</samp> options.
<command>ncpdq</command> is optimized to perform these actions in a parallel
fashion with a minimum of time and memory.
The <dfn>pdq</dfn> may stand for &textldquo;Permute Dimensions Quickly&textrdquo;, 
&textldquo;Pack Data Quietly&textrdquo;, &textldquo;Pillory Dan Quayle&textrdquo;, or other silly uses.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2341"><code>add_offset</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2342"><code>scale_factor</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2343"><command>ncap2</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2344">packing policy</indexterm></cindex>
<unnumberedsubsec spaces=" "><sectiontitle>Packing and Unpacking Functions</sectiontitle>
<para>The <command>ncpdq</command> packing (and unpacking) algorithms are described 
in <ref label="Methods-and-functions"><xrefnodename>Methods and functions</xrefnodename></ref>, and are also implemented in
<command>ncap2</command>. 
<command>ncpdq</command> extends the functionality of these algorithms by 
providing high level control of the <dfn>packing policy</dfn> so that
users can consistently pack (and unpack) entire files with one command. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2345"><var>pck_plc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2346"><code>-P <var>pck_plc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2347"><code>--pck_plc <var>pck_plc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2348"><code>--pack_policy <var>pck_plc</var></code></indexterm></cindex>
The user specifies the desired packing policy with the <samp>-P</samp> switch
(or its long option equivalents, <samp>--pck_plc</samp> and
<samp>--pack_policy</samp>) and its <var>pck_plc</var> argument.
Four packing policies are currently implemented:&linebreak;   
</para><table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="dfn">Packing (and Re-Packing) Variables [<emph>default</emph>]</itemformat></item>
</tableterm><tableitem><para>Definition: Pack unpacked variables, re-pack packed variables&linebreak;
Alternate invocation: <code>ncpack</code>&linebreak;
<var>pck_plc</var> key values: <samp>all_new</samp>, <samp>pck_all_new_att</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Packing (and not Re-Packing) Variables</itemformat></item>
</tableterm><tableitem><para>Definition: Pack unpacked variables, copy packed variables&linebreak;
Alternate invocation: none&linebreak;
<var>pck_plc</var> key values: <samp>all_xst</samp>, <samp>pck_all_xst_att</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Re-Packing Variables</itemformat></item>
</tableterm><tableitem><para>Definition: Re-pack packed variables, copy unpacked variables&linebreak;
Alternate invocation: none&linebreak;
<var>pck_plc</var> key values: <samp>xst_new</samp>, <samp>pck_xst_new_att</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Unpacking</itemformat></item>
</tableterm><tableitem><para>Definition: Unpack packed variables, copy unpacked variables&linebreak;
Alternate invocation: <code>ncunpack</code>&linebreak;
<var>pck_plc</var> key values: <samp>upk</samp>, <samp>unpack</samp>, <samp>pck_upk</samp>&linebreak;
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>Equivalent key values are fully interchangeable.
Multiple equivalent options are provided to satisfy disparate needs
and tastes of <acronym><acronymword>NCO</acronymword></acronym> users working with scripts and from the
command line.
</para>
<para>Regardless of the packing policy selected, <command>ncpdq</command> 
no longer (as of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.4 in October, 2010)
packs coordinate variables, or the special variables, weights, 
and other grid properties described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>.
Prior <command>ncpdq</command> versions treated coordinate variables and
grid properties no differently from other variables.
However, coordinate variables are one-dimensional, so packing saves
little space on large files, and the resulting files are difficult for
humans to read. 
<command>ncpdq</command> will, of course, <emph>unpack</emph> coordinate variables and
weights, for example, in case some other, non-<acronym><acronymword>NCO</acronymword></acronym> software
packed them in the first place.
</para>
<para>Concurrently, Gaussian and area weights and other grid properties are
often used to derive fields in re-inflated (unpacked) files, so packing
such grid properties causes a considerable loss of precision in 
downstream data processing.
If users express strong wishes to pack grid properties, we will
implement new packing policies.
An immediate workaround for those needing to pack grid properties
now, is to use the <command>ncap2</command> packing functions or to rename the
grid properties prior to calling <command>ncpdq</command>. 
We welcome your feedback. 
</para>
<para>To reduce required memorization of these complex policy switches, 
<command>ncpdq</command> may also be invoked via a synonym or with switches
that imply a particular policy.
<command>ncpack</command> is a synonym for <command>ncpdq</command> and behaves the same 
in all respects.
Both <command>ncpdq</command> and <command>ncpack</command> assume a default packing
policy request of <samp>all_new</samp>.
Hence <command>ncpack</command> may be invoked without any <samp>-P</samp> switch,
unlike <command>ncpdq</command>.
Similarly, <command>ncunpack</command> is a synonym for <command>ncpdq</command> 
except that <command>ncpack</command> implicitly assumes a request to unpack, 
i.e., <samp>-P pck_upk</samp>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2349"><code>-U</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2350"><code>--unpack</code></indexterm></cindex>
Finally, the <command>ncpdq</command> <samp>-U</samp> switch (or its long option
equivalents <samp>--unpack</samp>) requires no argument.
It simply requests unpacking.
</para>
<para>Given the menagerie of synonyms, equivalent options, and implied
options, a short list of some equivalent commands is appropriate.
The following commands are equivalent for packing:
<code>ncpdq -P all_new</code>, <code>ncpdq --pck_plc=all_new</code>, and
<code>ncpack</code>.
The following commands are equivalent for unpacking:
<code>ncpdq -P upk</code>, <code>ncpdq -U</code>, <code>ncpdq --pck_plc=unpack</code>, 
and <code>ncunpack</code>.
Equivalent commands for other packing policies, e.g., <samp>all_xst</samp>, 
follow by analogy. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2351"><command>alias</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2352"><command>ln -s</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2353">symbolic links</indexterm></cindex>
Note that <command>ncpdq</command> synonyms are subject to the same constraints 
and recommendations discussed in the secion on <command>ncbo</command> synonyms
(<pxref label="ncbo-netCDF-Binary-Operator"><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></pxref>).
That is, symbolic links must exist from the synonym to <command>ncpdq</command>,
or else the user must define an <command>alias</command>.
</para>
<html endspaces=" ">
&lt;a name=&quot;pck_map&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#pck_map --&gt;
&lt;a name=&quot;hgh_sht&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hgh_sht --&gt;
&lt;a name=&quot;hgh_byt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#hgh_byt --&gt;
&lt;a name=&quot;flt_byt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#flt_byt --&gt;
&lt;a name=&quot;nxt_lsr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nxt_lsr --&gt;
&lt;a name=&quot;dbl_flt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dbl_flt --&gt;
&lt;a name=&quot;flt_dbl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#flt_dbl --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2354">packing map</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2355"><var>pck_map</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2356"><code>-M <var>pck_map</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2357"><code>--pck_map <var>pck_map</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2358"><code>--map <var>pck_map</var></code></indexterm></cindex>
<para>The <command>ncpdq</command> packing algorithms must know to which type
particular types of input variables are to be packed.
The correspondence between the input variable type and the output,
packed type, is called the <dfn>packing map</dfn>.
The user specifies the desired packing map with the <samp>-M</samp> switch
(or its long option equivalents, <samp>--pck_map</samp> and
<samp>--map</samp>) and its <var>pck_map</var> argument.
Six packing maps are currently implemented:&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="2359"><samp>hgh_sht</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2360"><samp>hgh_byt</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2361"><samp>flt_sht</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2362"><samp>flt_byt</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2363"><samp>nxt_lsr</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2364"><samp>dbl_flt</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2365"><samp>flt_dbl</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2366"><code>NC_DOUBLE</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2367"><code>NC_FLOAT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2368"><code>NC_INT64</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2369"><code>NC_UINT64</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2370"><code>NC_INT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2371"><code>NC_UINT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2372"><code>NC_SHORT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2373"><code>NC_USHORT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2374"><code>NC_CHAR</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2375"><code>NC_BYTE</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2376"><code>NC_UBYTE</code></indexterm></cindex>
</para><table commandarg="dfn" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="dfn">Pack Floating Precisions to <code>NC_SHORT</code> [<emph>default</emph>]</itemformat></item>
</tableterm><tableitem><para>Definition: Pack floating precision types to <code>NC_SHORT</code>&linebreak;
Map: Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>] to <code>NC_SHORT</code>&linebreak;
Types copied instead of packed: [<code>NC_INT64</code>,<code>NC_UINT64</code>,<code>NC_INT</code>,<code>NC_UINT</code>,<code>NC_SHORT</code>,<code>NC_USHORT</code>,<code>NC_CHAR</code>,<code>NC_BYTE</code>,<code>NC_UBYTE</code>]&linebreak;
<var>pck_map</var> key values: <samp>flt_sht</samp>, <samp>pck_map_flt_sht</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Pack Floating Precisions to <code>NC_BYTE</code></itemformat></item>
</tableterm><tableitem><para>Definition: Pack floating precision types to <code>NC_BYTE</code>&linebreak;
Map: Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>] to <code>NC_BYTE</code>&linebreak; 
Types copied instead of packed: [<code>NC_INT64</code>,<code>NC_UINT64</code>,<code>NC_INT</code>,<code>NC_UINT</code>,<code>NC_SHORT</code>,<code>NC_USHORT</code>,<code>NC_CHAR</code>,<code>NC_BYTE</code>,<code>NC_UBYTE</code>]&linebreak;
<var>pck_map</var> key values: <samp>flt_byt</samp>, <samp>pck_map_flt_byt</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Pack Higher Precisions to <code>NC_SHORT</code></itemformat></item>
</tableterm><tableitem><para>Definition: Pack higher precision types to <code>NC_SHORT</code>&linebreak;
Map: 
Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>,<code>NC_INT64</code>,<code>NC_UINT64</code>,<code>NC_INT</code>,<code>NC_UINT</code>] to <code>NC_SHORT</code>&linebreak;
Types copied instead of packed: [<code>NC_SHORT</code>,<code>NC_USHORT</code>,<code>NC_CHAR</code>,<code>NC_BYTE</code>,<code>NC_UBYTE</code>]&linebreak;
<var>pck_map</var> key values: <samp>hgh_sht</samp>, <samp>pck_map_hgh_sht</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Pack Higher Precisions to <code>NC_BYTE</code></itemformat></item>
</tableterm><tableitem><para>Definition: Pack higher precision types to <code>NC_BYTE</code>&linebreak;
Map: 
Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>,<code>NC_INT64</code>,<code>NC_UINT64</code>,<code>NC_INT</code>,<code>NC_UINT</code>,<code>NC_SHORT</code>,<code>NC_USHORT</code>] to <code>NC_BYTE</code>&linebreak;
Types copied instead of packed: [<code>NC_CHAR</code>,<code>NC_BYTE</code>,<code>NC_UBYTE</code>]&linebreak;
<var>pck_map</var> key values: <samp>hgh_byt</samp>, <samp>pck_map_hgh_byt</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Pack to Next Lesser Precision</itemformat></item>
</tableterm><tableitem><para>Definition: Pack each type to type of next lesser size&linebreak;
Map: Pack [<code>NC_DOUBLE</code>,<code>NC_INT64</code>,<code>NC_UINT64</code>] to <code>NC_INT</code>. 
Pack [<code>NC_FLOAT</code>,<code>NC_INT</code>,<code>NC_UINT</code>] to <code>NC_SHORT</code>.
Pack [<code>NC_SHORT</code>,<code>NC_USHORT</code>] to <code>NC_BYTE</code>.&linebreak;
Types copied instead of packed: [<code>NC_CHAR</code>,<code>NC_BYTE</code>,<code>NC_UBYTE</code>]&linebreak;
<var>pck_map</var> key values: <samp>nxt_lsr</samp>, <samp>pck_map_nxt_lsr</samp>&linebreak;
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Pack Doubles to Floats</itemformat></item>
</tableterm><tableitem><para>Definition: Demote (via type-conversion, <emph>not packing</emph>) double-precision variables to single-precision&linebreak;
Map: Demote <code>NC_DOUBLE</code> to <code>NC_FLOAT</code>. 
Types copied instead of packed: All except <code>NC_DOUBLE</code>&linebreak;
<var>pck_map</var> key values: <samp>dbl_flt</samp>, <samp>pck_map_dbl_flt</samp>, <samp>dbl_sgl</samp>, <samp>pck_map_dbl_sgl</samp>&linebreak;
The <code>dbl_flt</code> map was introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.7.7 (September, 2018).
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="dfn">Promote Floats to Doubles</itemformat></item>
</tableterm><tableitem><para>Definition: Promote (via type-conversion, <emph>not packing</emph>) single-precision variables to double-precision&linebreak;
Map: Promote <code>NC_FLOAT</code> to <code>NC_DOUBLE</code>.
Types copied instead of packed: All except <code>NC_FLOAT</code>&linebreak;
<var>pck_map</var> key values: <samp>flt_dbl</samp>, <samp>pck_map_flt_dbl</samp>, <samp>sgl_dbl</samp>, <samp>pck_map_sgl_dbl</samp>&linebreak;
The <code>flt_dbl</code> map was introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.9.1
(December, 2019). 
</para></tableitem></tableentry></table>
<noindent></noindent>
<para>The default <samp>all_new</samp> packing policy with the default
<samp>flt_sht</samp> packing map reduces the typical <code>NC_FLOAT</code>-dominated
file size by <w>about 50%.</w>
<samp>flt_byt</samp> packing reduces an <code>NC_DOUBLE</code>-dominated file by
<w>about 87%.</w>
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2377"><code>d2f</code></indexterm></cindex>
<para>The &textldquo;packing map&textrdquo; <samp>pck_map_dbl_flt</samp> does a pure type-conversion
(no packing is involved) from <code>NC_DOUBLE</code> to <code>NC_FLOAT</code>.
The resulting variables are not packed, they are just single-precision
floating point instead of double-precision floating point.
This operation is irreversible, and no attributes are created, modified,
or deleted for these variables.
Note that coordinate and coordinate-like variables will not be demoted
as best practices dictate maintaining coordinates in the highest
possible precision.
</para>
<para>The &textldquo;packing map&textrdquo; <samp>pck_map_flt_dbl</samp> does a pure type-conversion
(no packing is involved) from <code>NC_FLOAT</code> to <code>NC_DOUBLE</code>.
The resulting variables are not packed, they are just double-precision
floating point instead of single-precision floating point.
This operation is irreversible, and no attributes are created, modified,
or deleted for these variables.
All single-precision variables, including coordinates, are promoted. 
Note that this map can double the size of a dataset.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2378"><var>_FillValue</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2379"><code>_FillValue</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2380"><code>NUL</code></indexterm></cindex>
<para>The netCDF packing algorithm (<pxref label="Methods-and-functions"><xrefnodename>Methods and functions</xrefnodename></pxref>) is
lossy&textmdash;once packed, the exact original data cannot be recovered without
a full backup. 
Hence users should be aware of some packing caveats:
First, the interaction of packing and data equal to the
<var>_FillValue</var> is complex.
Test the <code>_FillValue</code> behavior by performing a pack/unpack cycle 
to ensure data that are missing <emph>stay</emph> missing and data that are
not misssing do not join the Air National Guard and go missing.
This may lead you to elect a new <var>_FillValue</var>.
Second, <code>ncpdq</code> actually allows packing into <code>NC_CHAR</code> (with,
e.g., <samp>flt_chr</samp>).
However, the intrinsic conversion of <code>signed char</code> to higher
precision types is tricky for values equal to zero, i.e., for
<code>NUL</code>.  
Hence packing to <code>NC_CHAR</code> is not documented or advertised.  
Pack into <code>NC_BYTE</code> (with, e.g., <samp>flt_byt</samp>) instead.
</para>
<html endspaces=" ">
&lt;a name=&quot;rvr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rvr --&gt;
</html>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Dimension Permutation</sectiontitle>
<para><command>ncpdq</command> re-shapes variables in <var>input-file</var> by re-ordering
and/or reversing dimensions specified in the dimension list.
The dimension list is a whitespace-free, comma separated list of
dimension names, optionally prefixed by negative signs, that follows the 
<samp>-a</samp> (or long options <samp>--arrange</samp>, <samp>--permute</samp>,
<samp>--re-order</samp>, or <samp>--rdr</samp>) switch.  
To re-order variables by a subset of their dimensions, specify
these dimensions in a comma-separated list following <samp>-a</samp>, e.g., 
<samp>-a lon,lat</samp>. 
To reverse a dimension, prefix its name with a negative sign in the
dimension list, e.g., <samp>-a -lat</samp>. 
Re-ordering and reversal may be performed simultaneously, e.g.,
<samp>-a lon,-lat,time,-lev</samp>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2381">record dimension</indexterm></cindex>
<para>Users may specify any permutation of dimensions, including
permutations which change the record dimension identity.
The record dimension is re-ordered like any other dimension.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2382">concatenation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2383">record dimension</indexterm></cindex>
This unique <command>ncpdq</command> capability makes it possible to concatenate
files along any dimension.
See <ref label="Concatenation"><xrefnodename>Concatenation</xrefnodename></ref> for a detailed example.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2384">record variable</indexterm></cindex>
The record dimension is always the most slowly varying dimension in a
record variable (<pxref label="C-and-Fortran-Index-Conventions"><xrefnodename>C and Fortran Index Conventions</xrefnodename></pxref>).
The specified re-ordering fails if it requires creating more than
one record dimension amongst all the output variables
<footnote><para>This limitation, imposed by the netCDF storage layer,
may be relaxed in the future with netCDF4.</para></footnote>.
</para>
<para>Two special cases of dimension re-ordering and reversal deserve special
mention. 
First, it may be desirable to completely reverse the storage order of a
variable. 
To do this, include all the variable&textrsquo;s dimensions in the dimension
re-order list in their original order, and prefix each dimension name
with the negative sign.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="2385">transpose</indexterm></cindex>
Second, it may useful to transpose a variable&textrsquo;s storage order, e.g.,
<w>from C</w> to Fortran data storage order 
(<pxref label="C-and-Fortran-Index-Conventions"><xrefnodename>C and Fortran Index Conventions</xrefnodename></pxref>).
To do this, include all the variable&textrsquo;s dimensions in the dimension
re-order list in reversed order.
Explicit examples of these two techniques appear below.
</para>
<tex endspaces=" ">
NB: fxm ncpdq documentation will evolve through Fall 2004.
I will upload updates to documentation linked to by the NCO homepage.
ncpdq is a powerful operator, and 
I am unfamiliar with the terminology needed to describe what ncpdq does.
Sequences, sets, sheesh!
I just know that it does ``The right thing'' according to my gut feelings.
Now do you feel more comfortable using it?

Let $\dmnvct(\xxx)$ represent the dimensionality of the variable $\xxx$. 
Dimensionality describes the order and sizes of dimensions.
If $\xxx$ has rank $\dmnnbr$, then we may write $\dmnvct(\xxx)$ as the
$\dmnnbr$-element vector 
$$
\dmnvct(\xxx) = [ \dmn_{1}, \dmn_{2}, \dmn_{3}, \ldots, 
\dmn_{\dmnidx-1}, \dmn_{\dmnidx}, \dmn_{\dmnidx+1}, 
\ldots, \dmn_{\dmnnbr-2}, \dmn_{\dmnnbr-1}, \dmn_{\dmnnbr} ] 
$$
where $\dmn_{\dmnidx}$ is the size of the $\dmnidx$'th dimension.

The dimension re-order list specified with @samp{-a} is the
$\rdrnbr$-element vector 
$$
\rdrvct = [ \rdr_{1}, \rdr_{2}, \rdr_{3}, \ldots, 
\rdr_{\rdridx-1}, \rdr_{\rdridx}, \rdr_{\rdridx+1}, 
\ldots, \rdr_{\rdrnbr-2}, \rdr_{\rdrnbr-1}, \rdr_{\rdrnbr} ] 
$$
There need be no relation between $\dmnnbr$ and $\rdrnbr$.
Let the $\shrnbr$-element vector $\shrvct$ be the intersection
(i.e., the ordered set of unique shared dimensions) of $\dmnvct$ and 
$\rdrvct$
Then
$$
\eqalign{{\shrvct} &amp;= \rdrvct \cap \dmnvct \cr
&amp;= [ \shr_{1}, \shr_{2}, \shr_{3}, \ldots, 
\shr_{\shridx-1}, \shr_{\shridx}, \shr_{\shridx+1}, 
\ldots, \shr_{\shrnbr-2}, \shr_{\shrnbr-1}, \shr_{\shrnbr} ]} 
$$
$\shrvct$ is empty if $\rdrvct \notin \dmnvct$.

Re-ordering (or re-shaping) a variable means mapping the input state
with dimensionality $\dmnvct(\xxx)$ to the output state with
dimensionality $\dmnvctprm(\xxxprm)$.  
In practice, mapping occurs in three logically distinct steps.
First, we tranlate the user input to a one-to-one mapping $\mpp$ 
between input and output dimensions, 
$\dmnvct \mapsto \dmnvctprm$.
This tentative map is final unless external constraints (typically
netCDF restrictions) impose themselves.   
Second, we check and, if necessary, refine the tentative mapping so that
the re-shaped variables will co-exist in the same file without violating 
netCDF-imposed storage restrictions. 
This refined map specifies the final (output) dimensionality.
Third, we translate the output dimensionality into one-dimensional  
memory offsets for each datum according to the @w{C language} convention 
for multi-dimensional array storage.
Dimension reversal changes the ordering of data, though not the
rank or dimensionality, and so is part of the third step. 

Dimensions $\rdr$ disjoint from $\dmnvct$ play no role in re-ordering.
The first step taken to re-order a variable is to determine $\shrvct$. 
$\rdrvct$ is constant for all variables, whereas $\dmnvct$, and hence
$\shrvct$, is variable-specific.
$\shrvct$ is empty if $\rdrvct \notin \dmnvct$.
This may be the case for some extracted variables.
The user may explicitly specify the one-to-one mapping of input
to output dimension order by supplying (with @samp{-a}) a re-order list
$\rdrvct$ such that $\shrnbr = \dmnnbr$. 
In this case $\dmnsubnnnprm = \shrsubnnn$.  
The degenerate case occurs when $\dmnvct = \shrvct$.
This produces the identity mapping $\dmnsubnnnprm = \dmnsubnnn$.  

The mapping of input to output dimension order is more complex
when $\shrnbr \ne \dmnnbr$. 
In this case $\dmnsubnnnprm = \dmnsubnnn$ for the $\dmnnbr-\shrnbr$
dimensions $\dmnsubnnnprm \notin \shrvct$.
For the $\shrnbr$ dimensions $\dmnsubnnnprm \in \shrvct$, 
$\dmnsubnnnprm = \shrsubsss$.  
</tex>

<!-- c fxm: discuss netCDF-imposed constraints here -->

<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncpdq&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncpdq --&gt;
</html>
<para>EXAMPLES
</para>
<para>Pack and unpack all variables in file <file>in.nc</file> and store the results
in <file>out.nc</file>:  
</para><example endspaces=" ">
<pre xml:space="preserve">ncpdq in.nc out.nc # Same as ncpack in.nc out.nc
ncpdq -P all_new -M flt_sht in.nc out.nc # Defaults
ncpdq -P all_xst in.nc out.nc
ncpdq -P upk in.nc out.nc # Same as ncunpack in.nc out.nc
ncpdq -U in.nc out.nc # Same as ncunpack in.nc out.nc
</pre></example>
<para>The first two commands pack any unpacked variable in the input file.
They also unpack and then re-pack every packed variable.
The third command only packs unpacked variables in the input file.
If a variable is already packed, the third command copies it unchanged
to the output file. 
The fourth and fifth commands unpack any packed variables.
If a variable is not packed, the third command copies it unchanged.
</para>
<para>The previous examples all utilized the default packing map.
Suppose you wish to archive all data that are currently unpacked 
into a form which only preserves 256 distinct values.
Then you could specify the packing map <var>pck_map</var> as <samp>hgh_byt</samp>
and the packing policy <var>pck_plc</var> as <samp>all_xst</samp>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncpdq -P all_xst -M hgh_byt in.nc out.nc
</pre></example>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2386">appending variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2387"><samp>-A</samp></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2388"><samp>-v</samp></indexterm></cindex>
<para>Many different packing maps may be used to construct a given file 
by performing the packing on subsets of variables (e.g., with <samp>-v</samp>) 
and using the append feature with <samp>-A</samp> (<pxref label="Appending-Variables"><xrefnodename>Appending Variables</xrefnodename></pxref>).
</para>
<para>Users may wish to unpack data packed with the <acronym><acronymword>HDF</acronymword></acronym> convention,
and then re-pack it with the netCDF convention so that all their
datasets use the same packing convention prior to intercomparison.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2389"><command>ncl_convert2nc</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2390"><acronym><acronymword>NCL</acronymword></acronym></indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve"># One-step procedure: For NCO 4.4.0+, netCDF 4.3.1+
# 1. Convert, unpack, and repack HDF file into netCDF file
ncpdq --hdf_upk -P xst_new modis.hdf modis.nc # HDF4 files
ncpdq --hdf_upk -P xst_new modis.h5  modis.nc # HDF5 files

# One-step procedure: For NCO 4.3.7--4.3.9
# 1. Convert, unpack, and repack HDF file into netCDF file
ncpdq --hdf4 --hdf_upk -P xst_new modis.hdf modis.nc # HDF4
ncpdq        --hdf_upk -P xst_new modis.h5  modis.nc # HDF5

# Two-step procedure: For NCO 4.3.6 and earlier
# 1. Convert HDF file to netCDF file
ncl_convert2nc modis.hdf
# 2. Unpack using HDF convention and repack using netCDF convention
ncpdq --hdf_upk -P xst_new modis.nc modis.nc
</pre></example>
<para><acronym><acronymword>NCO</acronymword></acronym> now
<footnote spaces="\n"><para>Prior to <acronym><acronymword>NCO</acronymword></acronym> 4.4.0 and netCDF 4.3.1 (January, 2014),
<acronym><acronymword>NCO</acronymword></acronym> requires the <samp>--hdf4</samp> switch to correctly read
HDF4 input files.
For example, 
<samp>ncpdq --hdf4 --hdf_upk -P xst_new modis.hdf modis.nc</samp>. 
That switch is now obsolete, though harmless for backwards
compatibility. 
Prior to version 4.3.7 (October, 2013), <acronym><acronymword>NCO</acronymword></acronym> lacked the
software necessary to circumvent netCDF library flaws handling
<acronym><acronymword>HDF4</acronymword></acronym> files, and thus <acronym><acronymword>NCO</acronymword></acronym> failed to convert
<acronym><acronymword>HDF4</acronymword></acronym> files to netCDF files.
In those cases, use the <command>ncl_convert2nc</command> command distributed
with <acronym><acronymword>NCL</acronymword></acronym> to convert <acronym><acronymword>HDF4</acronymword></acronym> files to netCDF.</para></footnote>
automatically detects <acronym><acronymword>HDF4</acronymword></acronym> files.  
In this case it produces an output file <file>modis.nc</file> which preserves
the <acronym><acronymword>HDF</acronymword></acronym> packing used in the input file.
The <command>ncpdq</command> command first unpacks all packed variables using the
<acronym><acronymword>HDF</acronymword></acronym> unpacking algorithm (as specified by <samp>--hdf_upk</samp>), 
and then repacks those same variables using the netCDF algorithm
(because that is the only algorithm <acronym><acronymword>NCO</acronymword></acronym> packs with).
As described above the <samp>--P xst_new</samp> packing policy only repacks
variables that are already packed. 
Not-packed variables are copied directly without loss of precision
<footnote><para><command>ncpdq</command> does not support packing data using the
<acronym><acronymword>HDF</acronymword></acronym> convention.
Although it is now straightforward to support this, we think it might
sow more confusion than it reaps. 
Let us know if you disagree and would like <acronym><acronymword>NCO</acronymword></acronym> to support
packing data with <acronym><acronymword>HDF</acronymword></acronym> algorithm.</para></footnote>.
</para>
<para>Re-order file <file>in.nc</file> so that the dimension <code>lon</code> always
precedes the dimension <code>lat</code> and store the results in
<file>out.nc</file>:  
</para><example endspaces=" ">
<pre xml:space="preserve">ncpdq -a lon,lat in.nc out.nc
ncpdq -v three_dmn_var -a lon,lat in.nc out.nc
</pre></example>
<para>The first command re-orders every variable in the input file.
The second command extracts and re-orders only the variable
<code>three_dmn_var</code>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2391">reverse dimensions</indexterm></cindex>
<para>Suppose the dimension <code>lat</code> represents latitude and monotonically 
increases increases from south to north. 
Reversing the <code>lat</code> dimension means re-ordering the data so that
latitude values decrease monotonically from north to south.
Accomplish this with
</para><example endspaces=" ">
<pre xml:space="preserve">% ncpdq -a -lat in.nc out.nc
% ncks --trd -C -v lat in.nc
lat[0]=-90
lat[1]=90
% ncks --trd -C -v lat out.nc
lat[0]=90
lat[1]=-90
</pre></example>
<para>This operation reversed the latitude dimension of all variables.
Whitespace immediately preceding the negative sign that specifies
dimension reversal may be dangerous.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2392">long options</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2393">quotes</indexterm></cindex>
Quotes and long options can help protect negative signs that should
indicate dimension reversal from being interpreted by the shell as
dashes that indicate new command line switches.
</para><example endspaces=" ">
<pre xml:space="preserve">ncpdq -a -lat in.nc out.nc # Dangerous? Whitespace before &quot;-lat&quot;
ncpdq -a '-lat' in.nc out.nc # OK. Quotes protect &quot;-&quot; in &quot;-lat&quot;
ncpdq -a lon,-lat in.nc out.nc # OK. No whitespace before &quot;-&quot;
ncpdq --rdr=-lat in.nc out.nc # Preferred. Uses &quot;=&quot; not whitespace
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="2394">transpose</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2395">reverse dimensions</indexterm></cindex>
<html endspaces=" ">
&lt;a name=&quot;ncpdq_trn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncpdq_trn --&gt;
&lt;a name=&quot;transpose&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#transpose --&gt;
</html>
<para>To create the mathematical transpose of a variable, place all its
dimensions in the dimension re-order list in reversed order.
This example creates the transpose of <code>three_dmn_var</code>: 
</para><example endspaces=" ">
<pre xml:space="preserve">% ncpdq -a lon,lev,lat -v three_dmn_var in.nc out.nc
% ncks --trd -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0 
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1 
lat[0]=-90 lev[0]=100 lon[2]=180 three_dmn_var[2]=2 
...
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21 
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22 
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23 
% ncks --trd -C -v three_dmn_var out.nc
lon[0]=0 lev[0]=100 lat[0]=-90 three_dmn_var[0]=0
lon[0]=0 lev[0]=100 lat[1]=90 three_dmn_var[1]=12
lon[0]=0 lev[1]=500 lat[0]=-90 three_dmn_var[2]=4
...
lon[3]=270 lev[1]=500 lat[1]=90 three_dmn_var[21]=19
lon[3]=270 lev[2]=1000 lat[0]=-90 three_dmn_var[22]=11
lon[3]=270 lev[2]=1000 lat[1]=90 three_dmn_var[23]=23
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="2396">reverse data</indexterm></cindex>
<para>To completely reverse the storage order of a variable, include
all its dimensions in the re-order list, each prefixed by a negative
sign. 
This example reverses the storage order of <code>three_dmn_var</code>: 
</para><example endspaces=" ">
<pre xml:space="preserve">% ncpdq -a -lat,-lev,-lon -v three_dmn_var in.nc out.nc
% ncks --trd -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0 
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1 
lat[0]=-90 lev[0]=100 lon[2]=180 three_dmn_var[2]=2 
...
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21 
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22 
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23 
% ncks --trd -C -v three_dmn_var out.nc
lat[0]=90 lev[0]=1000 lon[0]=270 three_dmn_var[0]=23
lat[0]=90 lev[0]=1000 lon[1]=180 three_dmn_var[1]=22
lat[0]=90 lev[0]=1000 lon[2]=90 three_dmn_var[2]=21
...
lat[1]=-90 lev[2]=100 lon[1]=180 three_dmn_var[21]=2
lat[1]=-90 lev[2]=100 lon[2]=90 three_dmn_var[22]=1
lat[1]=-90 lev[2]=100 lon[3]=0 three_dmn_var[23]=0
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;dmn_rcd_mk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dmn_rcd_mk --&gt;
&lt;a name=&quot;mk_rcd_dmn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mk_rcd_dmn --&gt;
</html>
<para>Creating a record dimension named, e.g., <code>time</code>, in a file which
has no existing record dimension is simple with <command>ncecat</command>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat -O -u time in.nc out.nc # Create degenerate record dimension named &quot;time&quot;
</pre></example>

<cindex index="cp" spaces=" "><indexterm index="cp" number="2397">record dimension</indexterm></cindex>
<para>Now consider a file with all dimensions, including <code>time</code>, fixed
(non-record).
Suppose the user wishes to convert <code>time</code> from a fixed dimension to  
a record dimension. 
This may be useful, for example, when the user wishes to append
additional time slices to the data.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.1 (April, 2010) the preferred method for
doing this is with <command>ncks</command>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncks -O --mk_rec_dmn time in.nc out.nc # Change &quot;time&quot; to record dimension
</pre></example>

<para>Prior to 4.0.1, the procedure to change an existing fixed dimension into
a record dimension required three separate commands,
<command>ncecat</command> followed by <command>ncpdq</command>, and then <command>ncwa</command>.
The recommended method is now to use <samp>ncks --fix_rec_dmn</samp>, yet it
is still instructive to present the original procedure, as it shows how
multiple operators can achieve the same ends by different means: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2398">degenerate dimension</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">ncecat -O in.nc out.nc # Add degenerate record dimension named &quot;record&quot;
ncpdq -O -a time,record out.nc out.nc # Switch &quot;record&quot; and &quot;time&quot;
ncwa -O -a record out.nc out.nc # Remove (degenerate) &quot;record&quot;
</pre></example>
<noindent></noindent>
<para>The first step creates a degenerate (size equals one) record dimension
named (by default) <code>record</code>. 
The second step swaps the ordering of the dimensions named <code>time</code>
and <code>record</code>.
Since <code>time</code> now occupies the position of the first (least rapidly
varying) dimension, it becomes the record dimension.
The dimension named <code>record</code> is no longer a record dimension.
The third step averages over this degenerate <code>record</code> dimension.
Averaging over a degenerate dimension does not alter the data.
The ordering of other dimensions in the file (<code>lat</code>, <code>lon</code>,
etc.) is immaterial to this procedure. 
See <ref label="ncecat-netCDF-Ensemble-Concatenator"><xrefnodename>ncecat netCDF Ensemble Concatenator</xrefnodename></ref> and 
<ref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></ref> for other methods of
changing variable dimensionality, including the record dimension. 
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncra&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncra --&gt;
</html>
</unnumberedsubsec>
</section>
<node name="ncra-netCDF-Record-Averager" spaces=" "><nodename>ncra netCDF Record Averager</nodename><nodenext spaces=" ">ncrcat netCDF Record Concatenator</nodenext><nodeprev spaces=" ">ncpdq netCDF Permute Dimensions Quickly</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncra</command> netCDF Record Averager</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2399">averaging data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2400">record average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2401">record dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2402">running average</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="40" mergedindex="cp">ncra</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncra [-3] [-4] [-5] [-6] [-7] [-A] [-C] [-c]
[--cb <var>y1</var>,<var>y2</var>,<var>m1</var>,<var>m2</var>,<var>tpd</var>] [--cmp <var>cmp_sng</var>]
[--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>][,[<var>interleave</var>]]]]]
[-F] [--fl_fmt <var>fl_fmt</var>]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...]
[-H] [-h] [--hdf] [--hdr_pad <var>nbr</var>] [--hpss] 
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [--mro] [-N] [-n <var>loop</var>] 
[--no_cll_msr] [--no_cll_mth] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>output-file</var>] [-p <var>path</var>] [--qnt ...] [--qnt_alg <var>alg_nm</var>]
[--prm_int] [--prw wgt_arr] [-R] [-r] [--ram_all] [--rec_apn] [--rth_dbl|flt]
[-t <var>thr_nbr</var>] [--unn] [-v <var>var</var>[,&dots;]] [-w wgt] [-X ...] [-x] [-y <var>op_typ</var>]
[<var>input-files</var>] [<var>output-file</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncra</command> computes statistics (including, though not limited to,
averages) of record variables across an arbitrary number of  
<var>input-files</var>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2403">degenerate dimension</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2404">record dimension</indexterm></cindex>
The record dimension is, by default, retained as a degenerate 
<w>(size 1)</w> dimension in the output variables.
<xref label="Statistics-vs-Concatenation"><xrefnodename>Statistics vs Concatenation</xrefnodename></xref>, for a description of the
distinctions between the various statistics tools and concatenators. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2405">multi-file operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2406">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2407"><code>stdin</code></indexterm></cindex>
As a multi-file operator, <command>ncra</command> will read the list of
<var>input-files</var> from <code>stdin</code> if they are not specified 
as positional arguments on the command line 
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>).
</para>
<para>Input files may vary in size, but each must have a record dimension.
The record coordinate, if any, should be monotonic (or else non-fatal
warnings may be generated). 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2408">hyperslab</indexterm></cindex>
Hyperslabs of the record dimension which include more than one file 
work correctly.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2409">stride</indexterm></cindex>
<command>ncra</command> supports the <var>stride</var> argument to the <samp>-d</samp>
hyperslab option (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>) for the record dimension only,
<var>stride</var> is not supported for non-record dimensions.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2410">operation types</indexterm></cindex>
<command>ncra</command> <emph>always averages</emph> coordinate variables (e.g., 
<code>time</code>) regardless of the arithmetic operation type performed on
non-coordinate variables (<pxref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></pxref>).
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.4.9</w>, released in May, 2015,
<command>ncra</command> accepts user-specified weights with the <samp>-w</samp> 
(or long-option equivalent <samp>--wgt</samp>, <samp>--wgt_var</samp>,
or <samp>--weight</samp>) switch. 
When no weight is specified, <command>ncra</command> weights each record (e.g.,
time slice) in the <var>input-files</var> equally.
<command>ncra</command> does not attempt to see if, say, the <code>time</code>
coordinate is irregularly spaced and thus would require a weighted
average in order to be a true time-average.
Specifying unequal weights is entirely the user&textrsquo;s responsibility.
</para>
<para>Weights specified with <samp>-w wgt</samp> may take one of two forms.
In the first form, the <samp>wgt</samp> argument is a comma-separated list of
values by which to weight each <emph>file</emph> (recall that files may have
multiple timesteps). 
In this form the number of weights specified must equal the number of
files specified in the input file list, or else the program will exit.
In the second form, the <samp>wgt</samp> argument is the name of a weighting
variable present in every input file.
The variable may be a scalar or a one-dimensional record variable.
Scalar weights are applied uniformly to the entire file (i.e., this
produces the same arithmetic result as supplying the same value
as a per-file weight option on the command-line).
One-dimensional weights apply to each corresponding record (i.e.,
per-record weights), and are suitable for dynamically changing
timesteps. 
</para>
<para>By default, any weights specified (whether by value or by variable name)
are normalized to unity by dividing each specified weight by the sum of
all the weights.
This means, for example, that, <samp>-w 0.25,0.75</samp> is equivalent to 
<samp>-w 2.0,6.0</samp> since both are equal when normalized.
This behavior simplifies specifying weights based on countable items.
For example, time-weighting monthly averages for March, April, and May
to obtain a spring seasonal average can be done with 
<samp>-w 31,30,31</samp> instead of 
<samp>-w 0.33695652173913043478,0.32608695652173913043,0.33695652173913043478</samp>. 
</para>
<para>However, sometimes one wishes to use weights in &textldquo;dot-product mode&textrdquo;,
i.e., multiply by the (non-normalized) weights.
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.5.2</w>, released in July, 2015,
<command>ncra</command> accepts the <samp>-N</samp> (or long-option equivalent
<samp>--no_nrm_by_wgt</samp>) switch that prevents automatic weight
normalization. 
When this switch is used, the weights will not be normalized (unless the
user provides them as normalized), and the numerator of the weighted
average will not be divided by the sum of the weights (which is one for
normalized weights).
</para>
<html endspaces=" ">
&lt;a name=&quot;prw&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prw --&gt;
&lt;a name=&quot;per_record_weights&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#per_record_weights --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2411"><code>--per_record_weights</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2412"><code>--prw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2413">weights</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2414">weighted average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2415">per-record-weights</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2416">record average</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.9.4</w>, released in September, 2020,
<command>ncra</command> supports the <samp>--per_record_weights</samp> (or
<samp>--prw</samp>) flag to utilize the command-line weights separately
specified by <samp>-w <var>wgt_arr</var></samp> (or <samp>--wgt <var>wgt_arr</var></samp>)
for per-record weights instead of per-file-weights, where
<var>wgt_arr</var> is a 1-D array of weights.
This is useful when computing weighted averages with cyclically
varying weights, since the weights given on the command line will be 
repeated for the length of the timeseries.
Consider, for example, a <acronym><acronymword>CMIP6</acronymword></acronym> timeseries of historical
monthly mean emissions that one wishes to convert to a timeseries of
annual-mean emissions.
One can now weight each month by its number of days via:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra --per_record_weights --mro -d time,,,12,12 --wgt \
  31,28,31,30,31,30,31,31,30,31,30,31 ~/monthly.nc ~/annual.nc
</pre></example>
<para>Note that the twelve weights will be implicitly repeated throughtout
the duration of the input file(s), which in this case may therefore
specify an interannual monthly timeseries that is reduced to a
timeseries of annual-means in the output.
</para>
<para>Bear these exceptions in mind when weighting input:
First, <command>ncra</command> only applies weights if the arithmetic operation
type is averaging (<pxref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></pxref>), i.e., for timeseries mean
and for timeseries mean absolute value.
Weights are never applied for minimization, square-roots, etc.
Second, <command>ncra</command> <emph>never weights</emph> coordinate variables (e.g., 
<code>time</code>) regardless of the weighting performed on non-coordinate
variables.
</para>
<html endspaces=" ">
&lt;a name=&quot;prm_ints&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prm_ints --&gt;
&lt;a name=&quot;promote_ints&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#promote_ints --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2417"><code>--promote_ints</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2418"><code>--prm_ints</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2419">promotion</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2420">Boolean values</indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.9.4</w>, released in September, 2020,
<command>ncra</command> supports the <samp>--promote_ints</samp> (or <samp>prm_ints</samp>) 
flags to output statistics of integer-valued input variables in
floating-point precision in the output file.
By default, arithmetic operators such as <command>ncra</command> auto-promote
integers to double-precision prior to arithmetic, then conduct the
arithmetic, then demote the values back to integers for final output.
The final stage (demotion) of this default behavior quantizes the
mantissa of the values and prevents, e.g., retaining the statisitical
means of Boolean (0 or 1-valued) input data as floating point data.
The <samp>--promote_ints</samp> flag eliminates the demotion and causes the
statistical means of integer (<code>NC_BYTE</code>, <code>NC_SHORT</code>,
<code>NC_INT</code>, <code>NC_INT64</code>) inputs to be output as
single-precision floating point (<code>NC_FLOAT</code>) variables.
This allows useful arithmetic to be performed on Boolean values stored
in the space-conserving <code>NC_BYTE</code> (single-byte) format.
</para><example endspaces=" ">
<pre xml:space="preserve">ncra --prm_ints in*.nc out.nc
</pre></example>

<ignore endspaces=" ">
@c Old, and possibly future, documentation
@html
&lt;a name=&quot;cb&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cb --&gt;
&lt;a name=&quot;c2b&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#c2b --&gt;
&lt;a name=&quot;clm_bnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm_bnd --&gt;
&lt;a name=&quot;clm2bnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm2bnd --&gt;
@end html
@cindex @code{--cb}
@cindex @code{--c2b}
@cindex @code{--clm_bnd}
@cindex @code{--clm2bnd}
As of @acronym{NCO} version 4.6.0 (May, 2016) @command{ncra} can honor 
the @acronym{CF} @code{climatology} and climatological statistics
conventions described in @ref{CF Conventions}.
This functionality only works when each input file contains only a
single record (timestep).
Currently this is opt-in with the @samp{--cb} flag (or long-option
equivalent @samp{--clm_bnd}), or with the @samp{--c2b} flag (or its
long-option equivalent @samp{--clm2bnd}) switches. 
Invoking @samp{--cb} causes @command{ncra} to:
@enumerate
@item Add a @code{climatology} attribute with value
``climatology_bounds'' the time coordinate, if necessary
@item Remove the @code{bounds} attribute from the time coordinate, if
necessary 
@item Output a variable named @code{climatology_bounds} with values that
      are minima/maxima of the input time coordinate @code{bounds}
      variable. 
@item Omit any input time coordinate @code{bounds} attribute and
      variable 
@item Ensure the @code{cell_methods} attribute for all variables is
      appropriate for climatologies within and over years.
      Climatologies within days will have incorrect units (the switch is
      currently opt-in so that incorrect units are not inadvertently generated).
      Please contact the authors if this functionality is important to you
      (The omission of climatologies within days is mainly a matter of
      trying to keep the switches and interface clean).
@end enumerate
Use the @samp{--c2b} flag (instead of @samp{--cb}) to convert the input
@code{climatology} bounds to a non-climatology @code{bounds} in the
output.  
In other words, use @samp{--c2b} when averaging sub-sampled
climatologies together to produce a continuous (non-climatologically
sub-sampled) mean. 
@example
# Use --cb to average months into a climatological month
ncra --cb 2014_01.nc 2015_01.nc 2016_01.nc clm_JAN.nc
# Use --cb to average climatological months into a climatological season
ncra --cb clm_DEC.nc clm_JAN.nc clm_FEB.nc clm_DJF.nc
# Four seasons make a complete year so use --c2b
ncra --c2b clm_DJF.nc clm_MAM.nc clm_JJA.nc clm_SON.nc clm_ANN.nc
@end example
Currently this functionality only works with climatologies within and
over years (not within or over days).
</ignore>

<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncra&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncra --&gt;
</html>
<para>EXAMPLES
</para>
<para>Average files <file>85.nc</file>, <file>86.nc</file>, <w>&dots; <file>89.nc</file></w>
along the record dimension, and store the results in <file>8589.nc</file>: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2421">globbing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2422"><code>NINTAP</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2423">Processor</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2424"><acronym><acronymword>CCM</acronymword></acronym> Processor</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">ncra 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
ncra 8[56789].nc 8589.nc
ncra -n 5,2,1 85.nc 8589.nc
</pre></example>
<para>These three methods produce identical answers.
<xref label="Specifying-Input-Files"><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions
between these methods.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2425">Fortran</indexterm></cindex>
<para>Assume the files <file>85.nc</file>, <file>86.nc</file>, <w>&dots; <file>89.nc</file></w>
each contain a record coordinate <var>time</var> of length 12 defined such
that the third record in <file>86.nc</file> contains data from March 1986,
etc. 
<acronym><acronymword>NCO</acronymword></acronym> knows how to hyperslab the record dimension across files.
Thus, to average data from December, 1985 through February, 1986:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -d time,11,13 85.nc 86.nc 87.nc 8512_8602.nc
ncra -F -d time,12,14 85.nc 86.nc 87.nc 8512_8602.nc
</pre></example>
<noindent></noindent>
<para>The file <file>87.nc</file> is superfluous, but does not cause an error.
The <samp>-F</samp> turns on the Fortran (1-based) indexing convention.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2426">stride</indexterm></cindex>
The following uses the <var>stride</var> option to average all the March
temperature data from multiple input files into a single output file
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -F -d time,3,,12 -v temperature 85.nc 86.nc 87.nc 858687_03.nc
</pre></example>
<para><xref label="Stride"><xrefnodename>Stride</xrefnodename></xref>, for a description of the <var>stride</var> argument.
</para>
<para>Assume the <var>time</var> coordinate is incrementally numbered such that
January, <w><math>1985 = 1</math></w> and December, <w><math>1989 = 60</math></w>.
Assuming <samp>??</samp> only expands to the five desired files, the following 
averages June, 1985&textndash;June, 1989: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -d time,6.,54. ??.nc 8506_8906.nc
ncra -y max -d time,6.,54. ??.nc 8506_8906.nc
</pre></example>
<para>The second example identifies the maximum instead of averaging.
<xref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></xref>, for a description of all available statistical 
operations. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2427">seasonal average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2428">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2429">subcycle</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2430">time-averaging</indexterm></cindex>
<para><command>ncra</command> includes the powerful subcycle and multi-record output
features (<pxref label="Subcycle"><xrefnodename>Subcycle</xrefnodename></pxref>). 
This example uses these features to compute and output winter
(<acronym><acronymword>DJF</acronymword></acronym>) averages for all winter seasons beginning with year
1990 and continuing to the end of the input file:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -O --mro -d time,&quot;1990-12-01&quot;,,12,3 in.nc out.nc
</pre></example>

<para>The <samp>-w wgt</samp> option weights input data <emph>per-file</emph>
when explicit numeric weights are given on the command-line, or 
<emph>per-timestep</emph> when the argument is a record variable that
resides in the file:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -w 31,31,28 dec.nc jan.nc feb.nc out.nc # Per-file weights
ncra -w delta_t in1.nc in2.nc in3.nc out.nc # Per-timestep weights
</pre></example>
<para>The first example weights the input differently per-file to produce
correctly weighted winter seasonal mean statistics.
The second example weights the input per-timestep to produce correctly 
weighted mean statistics.
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncrcat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncrcat --&gt;
</html>
</section>
<node name="ncrcat-netCDF-Record-Concatenator" spaces=" "><nodename>ncrcat netCDF Record Concatenator</nodename><nodenext spaces=" ">ncremap netCDF Remapper</nodenext><nodeprev spaces=" ">ncra netCDF Record Averager</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncrcat</command> netCDF Record Concatenator</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2431">concatenation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2432">record concatenation</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="41" mergedindex="cp">ncrcat</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat [-3] [-4] [-5] [-6] [-7] [-A] [-C] [-c] [--cmp <var>cmp_sng</var>]
[--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>][,[<var>subcycle</var>][,[<var>interleave</var>]]]]]
[-F] [--fl_fmt <var>fl_fmt</var>]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...]
[-H] [-h] [--hdr_pad <var>nbr</var>] [--hpss] 
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [--md5_digest] [-n <var>loop</var>]
[--no_tmp_fl] [--no_cll_msr] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>output-file</var>] [-p <var>path</var>] [--qnt ...] [--qnt_alg <var>alg_nm</var>]
[-R] [-r] [--ram_all] [--rec_apn] [-t <var>thr_nbr</var>]
[--unn] [-v <var>var</var>[,&dots;]] [-X ...] [-x] 
[<var>input-files</var>] [<var>output-file</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncrcat</command> concatenates record variables across an arbitrary
number of <var>input-files</var>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2433">record dimension</indexterm></cindex>
The final record dimension is by default the sum of the lengths of the 
record dimensions in the input files.
<xref label="Statistics-vs-Concatenation"><xrefnodename>Statistics vs Concatenation</xrefnodename></xref>, for a description of the
distinctions between the various statistics tools and concatenators. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2434">multi-file operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2435">standard input</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2436"><code>stdin</code></indexterm></cindex>
As a multi-file operator, <command>ncrcat</command> will read the list of
<var>input-files</var> from <code>stdin</code> if they are not specified 
as positional arguments on the command line 
(<pxref label="Large-Numbers-of-Files"><xrefnodename>Large Numbers of Files</xrefnodename></pxref>).
</para>
<para>Input files may vary in size, but each must have a record dimension.
The record coordinate, if any, should be monotonic (or else non-fatal
warnings may be generated).
<cindex index="cp" spaces=" "><indexterm index="cp" number="2437">hyperslab</indexterm></cindex>
Hyperslabs along the record dimension that span more than one file are  
handled correctly.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2438">stride</indexterm></cindex>
<command>ncra</command> supports the <var>stride</var> argument to the <samp>-d</samp>
hyperslab option for the record dimension only, <var>stride</var> is not
supported for non-record dimensions.
</para>
<findex index="fn" spaces=" "><indexterm index="fn" number="42" mergedindex="cp">ncpdq</indexterm></findex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2439">packing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2440">unpacking</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2441"><code>add_offset</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2442"><code>scale_factor</code></indexterm></cindex>
<para>Concatenating a variable packed with different scales multiple datasets  
is beyond the capabilities of <command>ncrcat</command> (and <command>ncecat</command>,
the other concatenator (<ref label="Concatenation"><xrefnodename>Concatenation</xrefnodename></ref>).
<command>ncrcat</command> does not unpack data, it simply <emph>copies</emph> the data
from the <var>input-files</var>, and the metadata from the <emph>first</emph>
<var>input-file</var>, to the <var>output-file</var>. 
This means that data compressed with a packing convention must use
the identical packing parameters (e.g., <code>scale_factor</code> and
<code>add_offset</code>) for a given variable across <emph>all</emph> input files.
Otherwise the concatenated dataset will not unpack correctly.
The workaround for cases where the packing parameters differ across
<var>input-files</var> requires three steps:
First, unpack the data using <command>ncpdq</command>.
Second, concatenate the unpacked data using <command>ncrcat</command>, 
Third, re-pack the result with <command>ncpdq</command>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2443">ARM conventions</indexterm></cindex>
<para><command>ncrcat</command> applies special rules to <acronym><acronymword>ARM</acronymword></acronym> convention time
fields (e.g., <code>time_offset</code>).
See <ref label="ARM-Conventions"><xrefnodename>ARM Conventions</xrefnodename></ref> for a complete description.
</para>
<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncrcat&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncrcat --&gt;
</html>
<para>EXAMPLES
</para>
<para>Concatenate files <file>85.nc</file>, <file>86.nc</file>, <w>&dots; <file>89.nc</file></w>
along the record dimension, and store the results in <file>8589.nc</file>: 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2444">globbing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2445"><code>NINTAP</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2446">Processor</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2447"><acronym><acronymword>CCM</acronymword></acronym> Processor</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
ncrcat 8[56789].nc 8589.nc
ncrcat -n 5,2,1 85.nc 8589.nc
</pre></example>
<noindent></noindent>
<para>These three methods produce identical answers.
<xref label="Specifying-Input-Files"><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions
between these methods.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2448">Fortran</indexterm></cindex>
<para>Assume the files <file>85.nc</file>, <file>86.nc</file>, <w>&dots; <file>89.nc</file></w>
each contain a record coordinate <var>time</var> of <w>length 12</w> defined
such that the third record in <file>86.nc</file> contains data from March
1986, etc. 
<acronym><acronymword>NCO</acronymword></acronym> knows how to hyperslab the record dimension across files. 
Thus, to concatenate data from December, 1985&textndash;February, 1986:
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat -d time,11,13 85.nc 86.nc 87.nc 8512_8602.nc
ncrcat -F -d time,12,14 85.nc 86.nc 87.nc 8512_8602.nc
</pre></example>
<noindent></noindent>
<para>The file <file>87.nc</file> is superfluous, but does not cause an error.
When <command>ncra</command> and <command>ncrcat</command> encounter a file which does 
contain any records that meet the specified hyperslab criteria, they
disregard the file and proceed to the next file without failing.
The <samp>-F</samp> turns on the Fortran (1-based) indexing convention.
<cindex index="cp" spaces=" "><indexterm index="cp" number="2449">stride</indexterm></cindex>
</para>
<para>The following uses the <var>stride</var> option to concatenate all the March 
temperature data from multiple input files into a single output file
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat -F -d time,3,,12 -v temperature 85.nc 86.nc 87.nc 858687_03.nc
</pre></example>
<para><xref label="Stride"><xrefnodename>Stride</xrefnodename></xref>, for a description of the <var>stride</var> argument.
</para>
<para>Assume the <var>time</var> coordinate is incrementally numbered such that
January, <w>1985 = 1</w> and December, <w>1989 = 60.</w>
Assuming <code>??</code> only expands to the five desired files, the following 
concatenates June, 1985&textndash;June, 1989: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncrcat -d time,6.,54. ??.nc 8506_8906.nc
</pre></example>

<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncremap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncremap --&gt;
</html>
</section>
<node name="ncremap-netCDF-Remapper" spaces=" "><nodename>ncremap netCDF Remapper</nodename><nodenext spaces=" ">ncrename netCDF Renamer</nodenext><nodeprev spaces=" ">ncrcat netCDF Record Concatenator</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncremap</command> netCDF Remapper</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2450">remap</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2451">regrid</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="43" mergedindex="cp">ncremap</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap [-3] [-4] [-5] [-6] [-7]
[-a <var>alg_typ</var>] [--a2o] [--add_fll] [--alg_lst] [--area_dgn] [--cmp <var>cmp_sng</var>]
[-D <var>dbg_lvl</var>] [-d <var>dst_fl</var>] [--d2f] [--dpt] [--dpt_fl=<var>dpt_fl</var>]
[--dt_sng=<var>dt_sng</var>] [--esmf_typ=<var>esmf_typ</var>] 
[--fl_fmt=<var>fl_fmt</var>] [-G <var>grd_sng</var>] [-g <var>grd_dst</var>]
[-I <var>drc_in</var>] [-i <var>input-file</var>] [-j <var>job_nbr</var>] [-L <var>dfl_lvl</var>]
[-M] [-m <var>map_fl</var>] [--mpi_nbr=<var>mpi_nbr</var>] [--mpi_pfx=<var>mpi_pfx</var>] [--mpt_mss] [--msh_fl=<var>msh_fl</var>]
[--msk_apl] [--msk_dst=<var>msk_dst</var>] [--msk_out=<var>msk_out</var>] [--msk_src=<var>msk_src</var>] [--mss_val=<var>mss_val</var>]
[-n <var>nco_opt</var>] [--nm_dst=<var>nm_dst</var>] [--nm_src=<var>nm_src</var>] 
[--no_add_fll] [--no_cll_msr] [--no_frm_trm] [--no_permute] [--no_stdin] [--no_stg_grd]
[-O <var>drc_out</var>] [-o <var>output-file</var>] [-P <var>prc_typ</var>] [-p <var>par_typ</var>]
[--pdq=<var>pdq_opt</var>] [--qnt=<var>qnt_opt</var>] [--preserve=<var>prs_stt</var>] [--ps_nm=<var>ps_nm</var>]
[-R <var>rgr_opt</var>] [--rgn_dst] [--rgn_src] [--rnr_thr=<var>rnr_thr</var>] 
[--rrg_bb_wesn=<var>bb_wesn</var>] [--rrg_dat_glb=<var>dat_glb</var>] [--rrg_grd_glb=<var>grd_glb</var>]
[--rrg_grd_rgn=<var>grd_rgn</var>] [--rrg_rnm_sng=<var>rnm_sng</var>]
[-s <var>grd_src</var>] [--sgs_frc=<var>sgs_frc</var>] [--sgs_msk=<var>sgs_msk</var>] [--sgs_nrm=<var>sgs_nrm</var>]
[--skl=<var>skl-file</var>] [--stdin] [-T <var>drc_tmp</var>] [-t <var>thr_nbr</var>]
[-U] [-u <var>unq_sfx</var>] [--ugrid=<var>ugrid-file</var>] [--uio]
[-V <var>rgr_var</var>] [-v <var>var_lst</var>[,&dots;]] [--version] [--vrb=<var>vrb_lvl</var>] 
[--vrt_in=<var>vrt_fl</var>] [--vrt_out=<var>vrt_fl</var>] [--vrt_nm=<var>vrt_nm</var>] [--vrt_ntp=<var>vrt_ntp</var>] [--vrt_xtr=<var>vrt_xtr</var>]
[-W <var>wgt_opt</var>] [-w <var>wgt_cmd</var>] [-x <var>xtn_lst</var>[,&dots;]] [--xcl_var]
[--xtr_nsp=<var>xtr_nsp</var>] [--xtr_xpn=<var>xtr_xpn</var>]
[<var>input-files</var>] [<var>output-file</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncremap</command> remaps the data file(s) in <var>input-file</var>, in
<var>drc_in</var>, or piped through standard input, to the horizontal grid
specified by (in descending order of precedence) <var>map_fl</var>,
<var>grd_dst</var>, or <var>dst_fl</var> and stores the result in
<var>output-file</var>(s).  
If a vertical grid <var>vrt_fl</var> is provided, <command>ncremap</command> will
(also) vertically interpolate the input file(s) to that grid.
When no <var>input-file</var> is provided, <command>ncremap</command> operates in
&textldquo;map-only&textrdquo; mode where it exits after producing an annotated map-file. 
<command>ncremap</command> was introduced to <acronym><acronymword>NCO</acronymword></acronym> in version 4.5.4
(December, 2015). 
</para>
<para><command>ncremap</command> is a &textldquo;super-operator&textrdquo; that orchestrates the
regridding features of several different programs including other
<acronym><acronymword>NCO</acronymword></acronym> operators.
Under the hood <acronym><acronymword>NCO</acronymword></acronym> applies pre-computed remapping weights or, 
when necessary, generates and infers grids, generates remapping
weights itself or calls external programs to generate the weights,
and then applies the weights (i.e., regrids).
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2452"><command>ncremap</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2453"><command>ESMF_RegridWeightGen</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2454"><command>GenerateOfflineMap</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2455"><command>GenerateOverlapMesh</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2456"><command>mbtempest</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2457"><command>mbconvert</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2458"><command>mbpart</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2459"><acronym><acronymword>ERWG</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2460"><acronym><acronymword>MOAB</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2461">TempestRemap</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2462"><acronym><acronymword>NCL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2463">Conda</indexterm></cindex>
<para>Unlike the rest of <acronym><acronymword>NCO</acronymword></acronym>, <command>ncremap</command> and
<command>ncclimo</command> are shell scripts, not compiled binaries<footnote spaces=" \n"><para>This means that newer (including user-modified) versions of
<command>ncremap</command> work fine without re-compiling <acronym><acronymword>NCO</acronymword></acronym>.
Re-compiling is only necessary to take advantage of new features or
fixes in the <acronym><acronymword>NCO</acronymword></acronym> binaries, not to improve <command>ncremap</command>.
One may download and give executable permissions to the latest source 
at <url><urefurl>https://github.com/nco/nco/tree/master/data/ncremap</urefurl></url> without
re-installing the rest of <acronym><acronymword>NCO</acronymword></acronym>.</para></footnote>. 
<html endspaces=" ">
&lt;a name=&quot;HDF5_USE_FILE_LOCKING&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#HDF5_USE_FILE_LOCKING --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2464"><code>HDF5_USE_FILE_LOCKING</code></indexterm></cindex>
As of <acronym><acronymword>NCO</acronymword></acronym> 4.9.2 (February, 2020), the <command>ncclimo</command>
and <command>ncremap</command> scripts export the environment variable
<code>HDF5_USE_FILE_LOCKING</code> with a value of <code>FALSE</code>.
This prevents failures of these operators that can occur with some
versions of the underlying HDF library that attempt to lock files
on file systems that cannot or do not support it.
<command>ncremap</command> wraps the underlying regridder (<command>ncks</command>) and
external executables to produce a friendly interface to regridding.
Without any external dependencies, <command>ncremap</command> applies weights
from a pre-exisiting map-file to a source data file to produce a
regridded dataset. 
Source and destination datasets may be on any Swath, Curvilinear,
Rectangular, or Unstructured Data (<acronym><acronymword>SCRUD</acronymword></acronym>) grid. 
<command>ncremap</command> will also use its own algorithms or, when requested,  
external programs <acronym><acronymword>ESMF</acronymword></acronym>&textrsquo;s <command>ESMF_RegridWeightGen</command>
(<acronym><acronymword>ERWG</acronymword></acronym>) or
<acronym><acronymword>MOAB</acronymword></acronym>&textrsquo;s
<command>mbconvert</command>/<command>mbpart</command>/<command>mbtempest</command>, 
TempestRemap&textrsquo;s
<command>GenerateOverlapMesh</command>/<command>GenerateOfflineMap</command>) to
generate weights and mapfiles.
In order to use the weight-generation options, either invoke an
internal <acronym><acronymword>NCO</acronymword></acronym> weight-generation algorithm (e.g.,
<samp>--alg_typ=nco</samp>), or ensure that the desired external
weight-generation package is installed and on your <code>$PATH</code>.
The recommended way to obtain <acronym><acronymword>ERWG</acronymword></acronym> is as distributed in
binary format.  
Many <acronym><acronymword>NCO</acronymword></acronym> users already have <acronym><acronymword>NCL</acronymword></acronym> on their
system(s), and <acronym><acronymword>NCL</acronymword></acronym> usually comes with <acronym><acronymword>ERWG</acronymword></acronym>. 
Since about June, 2016, the Conda <acronym><acronymword>NCO</acronymword></acronym> package will also
install <acronym><acronymword>ERWG</acronymword></acronym>
<footnote spaces="   \n"><para>Install the Conda <acronym><acronymword>NCO</acronymword></acronym> package with
<samp>conda install -c conda-forge nco</samp>.</para></footnote>. 
Then be sure the directory containing the <acronym><acronymword>ERWG</acronymword></acronym> executable is
on your <code>$PATH</code> before using <command>ncremap</command>.
As a fallback, <acronym><acronymword>ERWG</acronymword></acronym> may also be installed from source:
<url><urefurl>https://earthsystemcog.org/projects/esmf/download_last_public</urefurl></url>.
<command>ncremap</command> can also generate and utilize mapfiles created by
TempestRemap, 
<url><urefurl>https://github.com/ClimateGlobalChange/tempestremap</urefurl></url>.
Until about April, 2019, TempestRemap had to be built from source
because there were no binary distributions of it.
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.8.0</w>, released in May, 2019, the
Conda <acronym><acronymword>NCO</acronymword></acronym> package automatically installs the new
TempestRemap Conda package so building from source is not necessary. 
Please contact those projects for support on building and installing
their software, which makes <command>ncremap</command> more functional and
user-friendly.
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.0.2</w> from September, 2021,
<command>ncremap</command> users can also use the <acronym><acronymword>MOAB</acronymword></acronym> regridding
toolchain.
<acronym><acronymword>MOAB</acronymword></acronym> and <acronym><acronymword>ERWG</acronymword></acronym> perform best in an <acronym><acronymword>MPI</acronymword></acronym>
environment. 
One can easily obtain such an environment with Conda
<footnote spaces="\n"><para>Install the Conda <acronym><acronymword>MPI</acronymword></acronym> versions of the
<acronym><acronymword>ERWG</acronymword></acronym> and <acronym><acronymword>MOAB</acronymword></acronym> packages with
<samp>conda install -c conda-forge moab=5.3.0=*mpich_tempest* esmf</samp>.</para></footnote>.
Please ensure you have the latest version of <acronym><acronymword>ERWG</acronymword></acronym>,
<acronym><acronymword>MOAB</acronymword></acronym>, and/or TempestRemap before reporting any related 
problems to <acronym><acronymword>NCO</acronymword></acronym>.  
</para>
<para>As mentioned above, <command>ncremap</command> orchestrates the regridding
features of several different programs.
<command>ncremap</command> runs most quickly when it is supplied with a
pre-computed mapfile.  
However, <command>ncremap</command> will also (call other programs to) compute
mapfiles when necessary and when given sufficient grid information.
Thus it is helpful to understand when <command>ncremap</command> will and will 
not internally generate a mapfile.
Supplying input data files and a pre-computed mapfile <emph>without</emph>
any other grid information causes <command>ncremap</command> to regrid the data
files without first pausing to internally generate a mapfile.
On the other hand, supplying any grid information (i.e., using any of
the <samp>-d</samp>, <samp>-G</samp>, <samp>-g</samp>, or <samp>-s</samp> switches described
below), causes <command>ncremap</command> to internally (re-)generate the
mapfile by combining the supplied and inferred grid information.
A generated mapfile is given a default name unless a user-specified name
is supplied with <samp>-m <var>map_fl</var></samp>. 
</para>
<unnumberedsubsec spaces=" "><sectiontitle>Fields not regridded by <command>ncremap</command></sectiontitle>

<para>Most people ultimately use <command>ncremap</command> to regrid data, yet not all
data can or should be regridded in the sense of applying a sparse-matrix
of weights to an input field to produce and output field.
Certain fields (e.g., the longitude coordinate) specify the grid.
These fields must be provided in order to compute the weights that are
used to regrid. 
The regridded usually copies these fields &textldquo;as is&textrdquo; directly into
regridded files, where they describe the destination grid, and replace
or supercede the source grid information.
Other fields are extensive grid properties (e.g., the number of cells
adjacent to a given cell) that may apply only to the source (not the
destination) grid, or be too difficult to re-compute for the destination
grid. 
<command>ncremap</command> contains an internal database of fields that it will
not propagate or regrid.
First are variables with names identical to the coordinate names found
in an ever-growing collection of publicly available geoscience datasets
(<acronym><acronymword>CMIP</acronymword></acronym>, <acronym><acronymword>NASA</acronymword></acronym>, etc.):&linebreak;
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2465"><code>CO_Latitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2466"><code>CO_Longitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2467"><code>LAT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2468"><code>LON</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2469"><code>LatitudeCornerpoints</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2470"><code>Latitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2471"><code>LongitudeCornerpoints</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2472"><code>Longitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2473"><code>S1_Latitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2474"><code>S1_Longitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2475"><code>TLAT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2476"><code>TLONG</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2477"><code>TLON</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2478"><code>ULAT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2479"><code>ULONG</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2480"><code>ULON</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2481"><code>XLAT_M</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2482"><code>XLAT</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2483"><code>XLONG_M</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2484"><code>XLONG</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2485"><code>area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2486"><code>bounds_lat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2487"><code>bounds_lon</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2488"><code>global_latitude0</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2489"><code>global_longitude0</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2490"><code>gridcell_area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2491"><code>gw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2492"><code>lat_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2493"><code>lat_vertices</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2494"><code>latitude0</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2495"><code>latitude_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2496"><code>latitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2497"><code>latt_bounds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2498"><code>latu_bounds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2499"><code>lat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2500"><code>lon_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2501"><code>lon_vertices</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2502"><code>longitude0</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2503"><code>longitude_bnds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2504"><code>longitude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2505"><code>lont_bounds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2506"><code>lonu_bounds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2507"><code>lon</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2508"><code>nav_lat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2509"><code>nav_lon</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2510"><code>slat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2511"><code>slon</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2512"><code>w_stag</code></indexterm></cindex>

<para><code>area</code>, <code>gridcell_area</code>, <code>gw</code>, <code>LAT</code>, <code>lat</code>,
<code>Latitude</code>, <code>latitude</code>, <code>nav_lat</code>,
<code>global_latitude0</code>, <code>latitude0</code>, <code>slat</code>, <code>TLAT</code>,
<code>ULAT</code>, <code>XLAT</code>, <code>XLAT_M</code>, <code>CO_Latitude</code>,
<code>S1_Latitude</code>, <code>lat_bnds</code>, <code>lat_vertices</code>,
<code>latt_bounds</code>, <code>latu_bounds</code>, <code>latitude_bnds</code>,
<code>LatitudeCornerpoints</code>, <code>bounds_lat</code>, <code>LON</code>, <code>lon</code>,
<code>Longitude</code>, <code>longitude</code>, <code>nav_lon</code>,
<code>global_longitude0</code>, <code>longitude0</code>, <code>slon</code>, <code>TLON</code>,
<code>TLONG</code>, <code>ULON</code>, <code>ULONG</code>, <code>XLONG</code>, <code>XLONG_M</code>,
<code>CO_Longitude</code>, <code>S1_Longitude</code>, <code>lon_bnds</code>,
<code>lon_vertices</code>, <code>lont_bounds</code>, <code>lonu_bounds</code>,
<code>longitude_bnds</code>, <code>LongitudeCornerpoints</code>, <code>bounds_lon</code>,
and <code>w_stag</code>.
</para>
<para>Files produced by <acronym><acronymword>MPAS</acronymword></acronym> models may contain these variables that
will not be regridded:&linebreak;
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2513"><code>angleEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2514"><code>areaTriangle</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2515"><code>cellsOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2516"><code>cellsOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2517"><code>cellsOnVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2518"><code>dcEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2519"><code>dvEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2520"><code>edgeMask</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2521"><code>edgesOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2522"><code>edgesOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2523"><code>edgesOnVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2524"><code>indexToCellID</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2525"><code>indexToEdgeID</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2526"><code>indexToVertexID</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2527"><code>kiteAreasOnVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2528"><code>latCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2529"><code>latEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2530"><code>latVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2531"><code>lonCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2532"><code>lonEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2533"><code>lonVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2534"><code>maxLevelEdgeTop</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2535"><code>meshDensity</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2536"><code>nEdgesOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2537"><code>nEdgesOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2538"><code>vertexMask</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2539"><code>verticesOnCell</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2540"><code>verticesOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2541"><code>weightsOnEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2542"><code>xEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2543"><code>yEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2544"><code>zEdge</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2545"><code>xVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2546"><code>yVertex</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2547"><code>zVertex</code></indexterm></cindex>

<para><code>angleEdge</code>, <code>areaTriangle</code>, <code>cellsOnCell</code>,
<code>cellsOnEdge</code>, <code>cellsOnVertex</code>, <code>dcEdge</code>, <code>dvEdge</code>,
<code>edgeMask</code>, <code>edgesOnCell</code>, <code>edgesOnEdge</code>,
<code>edgesOnVertex</code>, <code>indexToCellID</code>, <code>indexToEdgeID</code>,
<code>indexToVertexID</code>, <code>kiteAreasOnVertex</code>, <code>latCell</code>,
<code>latEdge</code>, <code>latVertex</code>, <code>lonCell</code>, <code>lonEdge</code>,
<code>lonVertex</code>, <code>maxLevelEdgeTop</code>, <code>meshDensity</code>,
<code>nEdgesOnCell</code>, <code>nEdgesOnEdge</code>, <code>vertexMask</code>,
<code>verticesOnCell</code>, <code>verticesOnEdge</code>, <code>weightsOnEdge</code>,
<code>xEdge</code>, <code>yEdge</code>, <code>zEdge</code>, <code>xVertex</code>,
<code>yVertex</code>, and <code>zVertex</code>.
</para>
<para>Most of these fields that <command>ncremap</command> will not regrid are also
fields that <acronym><acronymword>NCO</acronymword></acronym> size-and-rank-preserving operators will not
modify, as described in <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref>. 
</para>
</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Options specific to <command>ncremap</command></sectiontitle>

<para>The following summarizes features unique to <command>ncremap</command>.  
Features common to many operators are described in 
<ref label="Shared-features"><xrefnodename>Shared features</xrefnodename></ref>. 
</para>
<table commandarg="samp" spaces=" " endspaces=" ">
<beforefirstitem>
<html endspaces=" ">
&lt;a name=&quot;tr_alg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tr_alg --&gt;
&lt;a name=&quot;alg_typ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_typ --&gt;
&lt;a name=&quot;neareststod&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#neareststod --&gt;
&lt;a name=&quot;nstod&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nstod --&gt;
&lt;a name=&quot;stod&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#stod --&gt;
&lt;a name=&quot;nearestdtos&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nearestdtos --&gt;
&lt;a name=&quot;ndtos&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ndtos --&gt;
&lt;a name=&quot;dtos&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dtos --&gt;
&lt;a name=&quot;nds&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nds --&gt;
&lt;a name=&quot;patch&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#patch --&gt;
&lt;a name=&quot;patc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#patc --&gt;
&lt;a name=&quot;pch&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#pch --&gt;
&lt;a name=&quot;bilinear&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bilinear --&gt;
&lt;a name=&quot;esmfbilin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#esmfbilin --&gt;
&lt;a name=&quot;bilin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bilin --&gt;
&lt;a name=&quot;blin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#blin --&gt;
&lt;a name=&quot;conserve&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#conserve --&gt;
&lt;a name=&quot;aave&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#aave --&gt;
&lt;a name=&quot;esmfaave&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#esmfaave --&gt;
&lt;a name=&quot;traave&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#traave --&gt;
&lt;a name=&quot;trbilin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#trbilin --&gt;
&lt;a name=&quot;trintbilin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#trintbilin --&gt;
&lt;a name=&quot;trfv2&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#trfv2 --&gt;
&lt;a name=&quot;fv2se_flx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fv2se_flx --&gt;
&lt;a name=&quot;se2fv_flx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#se2fv_flx --&gt;
&lt;a name=&quot;fv2se_stt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fv2se_stt --&gt;
&lt;a name=&quot;se2fv_stt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#se2fv_stt --&gt;
&lt;a name=&quot;fv2se_alt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fv2se_alt --&gt;
&lt;a name=&quot;se2fv_alt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#se2fv_alt --&gt;
&lt;a name=&quot;se2se&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#se2se --&gt;
&lt;a name=&quot;cs2cs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cs2cs --&gt;
&lt;a name=&quot;fv2fv&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fv2fv --&gt;
&lt;a name=&quot;fv2fv_flx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fv2fv_flx --&gt;
&lt;a name=&quot;fv2fv_stt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fv2fv_stt --&gt;
&lt;a name=&quot;rll2rll&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rll2rll --&gt;
&lt;a name=&quot;ncoaave&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncoaave --&gt;
&lt;a name=&quot;nco_con&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco_con --&gt;
&lt;a name=&quot;nco_dwe&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco_dwe --&gt;
&lt;a name=&quot;nco_idw&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco_idw --&gt;
</html>
</beforefirstitem><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2548"><code>-a <var>alg_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2549"><var>alg_typ</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2550"><code>--alg_typ</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2551"><code>--algorithm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2552"><code>--regrid_algorithm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2553"><code>dwe</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2554"><code>idw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2555"><code>neareststod</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2556"><code>nstod</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2557"><code>stod</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2558"><code>nsd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2559"><code>nearestdtos</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2560"><code>ndtos</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2561"><code>dtos</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2562"><code>nds</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2563"><code>patch</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2564"><code>patc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2565"><code>pch</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2566"><code>bilinear</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2567"><code>bilin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2568"><code>esmfbilin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2569"><code>blin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2570"><code>aave</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2571"><code>esmfaave</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2572"><code>conserve</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2573"><code>conserve2nd</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-a <var>alg_typ</var> (<code>--alg_typ</code>, <code>--algorithm</code>, <code>--regrid_algorithm</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the interpolation algorithm for weight-generation for use by
<command>ESMF_RegridWeightGen</command> (<acronym><acronymword>ERWG</acronymword></acronym>), <acronym><acronymword>MOAB</acronymword></acronym>,
<acronym><acronymword>NCO</acronymword></acronym>, and/or TempestRemap. 
<command>ncremap</command> unbundles this algorithm choice from the rest of
the weight-generator invocation syntax because users more frequently
change interpolation algorithms than other options
(that can be changed with <samp>-W <var>wgt_opt</var></samp>).
<command>ncremap</command> can invoke all seven <acronym><acronymword>ERWG</acronymword></acronym> weight
generation algorithms, one <acronym><acronymword>NCO</acronymword></acronym> algorithm, and eight
TempestRemap algorithms (with both <acronym><acronymword>TR</acronymword></acronym> and <acronym><acronymword>MOAB</acronymword></acronym>). 
</para>
<html endspaces=" ">
&lt;a name=&quot;alg_esmf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_esmf --&gt;
&lt;a name=&quot;alg_erwg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_erwg --&gt;
</html>
<para>The seven <acronym><acronymword>ERWG</acronymword></acronym> weight generation algorithms are:
<code>bilinear</code> (acceptable abbreviations are: <code>esmfbilin</code> (preferred), <code>bilin</code>, <code>blin</code>, <code>bln</code>), 
<code>conserve</code> (or <code>esmfaave</code> (preferred), <code>conservative</code>, <code>cns</code>, <code>c1</code>, or <code>aave</code>), 
<code>conserve2nd</code> (or <code>conservative2nd</code>, <code>c2</code>, or <code>c2nd</code>)
(<acronym><acronymword>NCO</acronymword></acronym> supports <code>conserve2nd</code> as of version 4.7.4 (April, 2018)), 
<code>nearestdtos</code> (or <code>nds</code> or <code>dtos</code> or <code>ndtos</code>), 
<code>neareststod</code> (or <code>nsd</code> or <code>stod</code> or <code>nstod</code>), 
and <code>patch</code> (or <code>pch</code> or <code>patc</code>). 
See <acronym><acronymword>ERWG</acronymword></acronym> documentation
<uref><urefurl>http://www.earthsystemmodeling.org/esmf_releases/public/ESMF_6_3_0rp1/ESMF_refdoc/node3.html#SECTION03020000000000000000</urefurl><urefdesc spaces=" ">here</urefdesc></uref>
for detailed descriptions of <acronym><acronymword>ERWG</acronymword></acronym> algorithms.
</para>
<html endspaces=" ">
&lt;a name=&quot;alg_nco&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_nco --&gt;
&lt;a name=&quot;idw&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#idw --&gt;
&lt;a name=&quot;dwe&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dwe --&gt;
&lt;a name=&quot;nco_idw&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco_idw --&gt;
&lt;a name=&quot;nco_dwe&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco_dwe --&gt;
&lt;a name=&quot;inverse_distance&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#inverse_distance --&gt;
&lt;a name=&quot;inverse_distance_weighted&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#inverse_distance_weighted --&gt;
&lt;a name=&quot;distance_weighted&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#distance_weighted --&gt;
&lt;a name=&quot;nearest_neighbor&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nearest_neighbor --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2574"><code>ncoaave</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2575"><code>nco_con</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2576"><code>nco_cns</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2577"><code>nco_conserve</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2578"><code>nco</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2579"><code>ncoidw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2580"><code>nco_idw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2581"><code>nco_dwe</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2582"><code>idw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2583"><code>dwe</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2584"><code>inverse_distance_weighted</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2585"><code>distance_weighted</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2586"><code>nco_nearest_neighbor</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2587"><acronym><acronymword>DWE</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2588"><acronym><acronymword>IDW</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2589">inverse-distance-weighted interpolation/extrapolation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2590">distance-weighted extrapolation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2591">nearest-neighbor extrapolation</indexterm></cindex>
<para><command>ncremap</command> implements its own internal weight-generation
algorithm as of <acronym><acronymword>NCO</acronymword></acronym> version 4.8.0 (May, 2019).
The first <acronym><acronymword>NCO</acronymword></acronym>-native algorithm is a first-order conservative
algorithm <code>ncoaave</code> that competes well in accuracy with similar
algorithms (e.g., <acronym><acronymword>ERWG</acronymword></acronym>&textrsquo;s conservative algorithm <code>esmfaave</code>).
This algorithm is built-in to <acronym><acronymword>NCO</acronymword></acronym> and requires no external
software so it is <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s default weight generation algorithm.
It works well for everyday use. 
The algorithm may also be explicitly invoked with <code>nco_con</code> (or
<code>nco_cns</code>, <code>nco_conservative</code>, or simply <code>nco</code>).
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.4 (September, 2019) <command>ncremap</command>
supports a second internal weight-generation algorithm based on
inverse-distance-weighted (<acronym><acronymword>IDW</acronymword></acronym>) interpolation/extrapolation. 
<acronym><acronymword>IDW</acronymword></acronym> is similar to the <acronym><acronymword>ERWG</acronymword></acronym> <code>nearestidavg</code>
extrapolation alorithm, and accepts the same two parameters as input:
<samp>--xtr_xpn <var>xtr_xpn</var></samp> sets the (absolute value of) the
exponent used in inverse distance weighting (default <w>is 2.0</w>), and 
<samp>--xtr_nsp <var>xtr_nsp</var></samp> sets the number of source points used
in the extrapolation (default <w>is 8</w>).
<command>ncremap</command> applies <command>NCO</command>&textrsquo;s <acronym><acronymword>IDW</acronymword></acronym> to the entire
destination grid, not just to points with missing/masked values,
whereas <acronym><acronymword>ERWG</acronymword></acronym> uses distance-weighted-extrapolation
(<acronym><acronymword>DWE</acronymword></acronym>) solely for extrapolation to missing data points. 
Thus <command>NCO</command>&textrsquo;s <acronym><acronymword>IDW</acronymword></acronym> is more often used as an
alternative to bilinear interpolation since it interpolates between
known regions and extrapolates to unknown regions.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --alg_typ=nco_idw -s src.nc -d dst.nc -m map.nc
ncremap -a nco_idw --xtr_xpn=1.0 -s src.nc -d dst.nc -m map.nc
ncremap -a nco_idw --xtr_nsp=1   -s src.nc -d dst.nc -m map.nc
</verbatim>
</example>

<ignore endspaces=" ">
It promises to free users from the bondage of spherically-connected cell edges.
We are working to make it geometrically exact for gridcells with
small-circle edges, such as the latitude circles in @acronym{RLL}
grids. 
</ignore>
<html endspaces=" ">
&lt;a name=&quot;moab&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#moab --&gt;
&lt;a name=&quot;mbtr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mbtr --&gt;
&lt;a name=&quot;MOAB&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#MOAB --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2592"><acronym><acronymword>MOAB</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2593">TempestRemap</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2594">Tempest2</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2595"><code>se2fv_flx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2596"><code>fv2se_flx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2597"><code>se2fv_stt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2598"><code>fv2se_stt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2599"><code>se2fv_alt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2600"><code>fv2se_alt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2601"><code>se2se</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2602"><code>cs2cs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2603"><code>fv2fv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2604"><code>fv2fv_flx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2605"><code>fv2fv_stt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2606"><code>rll2rll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2607"><code>mono_se2fv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2608"><code>conservative_monotone_se2fv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2609"><code>monotr_fv2se</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2610"><code>conservative_monotone_fv2se</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2611"><code>highorder_se2fv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2612"><code>accurate_conservative_nonmonotone_se2fv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2613"><code>highorder_fv2se</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2614"><code>accurate_conservative_nonmonotone_fv2se</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2615"><code>intbilin_se2fv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2616"><code>accurate_monotone_nonconservative_se2fv</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2617"><code>mono_fv2se</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2618"><code>conservative_monotone_fv2se_alt</code></indexterm></cindex>
<para><command>ncremap</command> can invoke eight preconfigured TempestRemap 
weight-generation algorithms, and one generic algorithm
(<code>tempest</code>) for which users should provide their own 
options. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.7.2 (January, 2018), <command>ncremap</command>
implemented the six <acronym><acronymword>E3SM</acronymword></acronym>-recommended TempestRemap mapping
algorithms between <acronym><acronymword>FV</acronymword></acronym> and <acronym><acronymword>SE</acronymword></acronym> flux, state, and
other variables.
<command>ncremap</command> originated some (we hope) common-sense names
for these algorithms (<code>se2fv_flx</code>, <code>se2fv_stt</code>,
<code>se2fv_alt</code>, <code>fv2se_flx</code>, <code>fv2se_stt</code>, and
<code>fv2se_alt</code>), and also allows more mathematically precise
synonyms (shown below).
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.0 (December, 2019), <command>ncremap</command> 
added two further boutique mappings (<code>fv2fv_flx</code> and
<code>fv2fv_stt</code>). 
As of <acronym><acronymword>NCO</acronymword></acronym> version 5.1.9 (November, 2023), <command>ncremap</command> 
added support for two brand new TempestRemap bilinear interpolation
algorithms for <acronym><acronymword>FV</acronymword></acronym> grids.
These are (<code>trbilin</code> for traditional bilinear interpolation,
and <code>trintbilin</code>), for integrated bilinear or barycentric
interpolation. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 5.2.0 (February, 2024), <command>ncremap</command> 
added support for <code>trfv2</code>, a new second-order conservative
algorithm.
These newer TempestRemap algorithms are briefly described at
<url><urefurl>https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/1217757434/Mapping+file+algorithms+and+naming+convention</urefurl></url>.
</para>
<para>The <samp>-a tempest</samp> algorithm can be specified with the precise
TempestRemap options as arguments to the <samp>-W</samp> (or
<samp>--wgt_opt</samp>) option.  
Support for the named algorithms requires TempestRemap version 2.0.0
or later (some option combinations fail with earlier versions).
The <acronym><acronymword>MOAB</acronymword></acronym> algorithms are identical TempestRemap algorithms
<footnote spaces="\n"><para>However, mapping weights generated by
Although <acronym><acronymword>MOAB</acronymword></acronym> and TempestRemap use the same numerical
algorithms, they are likely to produce slightly different weights
due to round-off differences. 
<acronym><acronymword>MOAB</acronymword></acronym> is heavily parallelized and computes and adds terms
together in an unpredictable order compared to the serial TempestRemap.</para></footnote>.
Use the same algorithm names to select them.
Passing the <code>--mpi_nbr</code> option to  <command>ncremap</command> causes it
to invoke the <acronym><acronymword>MOAB</acronymword></acronym> toolchain to compute weights for any
TempestRemap algorithm (otherwise the <acronym><acronymword>TR</acronymword></acronym> toolchain is
used).
</para>
<para>Generate and use the recommended weights to remap fluxes from
<acronym><acronymword>FV</acronymword></acronym> to <acronym><acronymword>FV</acronymword></acronym> grids, for example, with
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -a traave --src_grd=src.g --dst_grd=dst.nc -m map.nc
ncremap -m map.nc in.nc out.nc
</verbatim>
</example>
<para>This causes <command>ncremap</command> to automatically invoke TempestRemap with
the boutique options 
<samp>--in_type fv --in_np 1 --out_type fv --out_np 1</samp>
that are recommended by <acronym><acronymword>E3SM</acronymword></acronym> for conservative and monotone  
remapping of fluxes.
Invoke <acronym><acronymword>MOAB</acronymword></acronym> to compute these weights by adding the
<samp>--mpi_nbr=<var>mpi_nbr</var></samp> option:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --mpi_nbr=8 -a traave --src_grd=src.g --dst_grd=dst.nc -m map.nc
</verbatim>
</example>
<para>This causes <command>ncremap</command> to automatically invoke multiple
components of the <acronym><acronymword>MOAB</acronymword></acronym> toolchain:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
mbconvert -B -o PARALLEL=WRITE_PART -O PARALLEL=BCAST_DELETE \
  -O PARTITION=TRIVIAL -O PARALLEL_RESOLVE_SHARED_ENTS \
  &quot;src.g&quot; &quot;src.h5m&quot;
mbconvert -B -o PARALLEL=WRITE_PART -O PARALLEL=BCAST_DELETE \
  -O PARTITION=TRIVIAL -O PARALLEL_RESOLVE_SHARED_ENTS \
  &quot;dst.nc&quot; &quot;dst.h5m&quot;
mbpart 8 --zoltan RCB &quot;src.h5m&quot; &quot;src_8p.h5m&quot;
mbpart 8 --zoltan RCB --recompute_rcb_box --scale_sphere \
  --project_on_sphere 2 &quot;dst.h5m&quot; &quot;dst_8p.h5m&quot;
mpirun -n 8 mbtempest --type 5 --weights \
  --load &quot;src_8p.h5m&quot; --load &quot;dst_8p.h5m&quot; \
  --method fv --order 1 --method fv --order 1 \
  --file &quot;map.nc&quot;
ncatted -O --gaa &lt;command lines&gt; map.nc map.nc
</verbatim>
</example>
<para>The <acronym><acronymword>MOAB</acronymword></acronym> toolchain should produce a map-file identical, to
rounding precision, to one produced by <acronym><acronymword>TR</acronymword></acronym>.
When speed matters (i.e., large grids), and the algorithm is supported
(e.g., <code>traave</code>), invoke <acronym><acronymword>MOAB</acronymword></acronym>, otherwise invoke
<acronym><acronymword>TR</acronymword></acronym>. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2619">Galerkin methods</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2620"><code>cgll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2621"><code>dgll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2622"><code>mono</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2623"><code>--mono</code></indexterm></cindex>
<para>TempestRemap options have the following meanings:
<code>mono</code> specifies a monotone remapping, i.e., one that does not
generate any new extrema in the field variables.
<code>cgll</code> indicates the input or output are represented by a
continuous Galerkin method on Gauss-Lobatto-Legendre nodes.
This is appropriate for spectral element datasets.
(TempestRemap also supports, although <acronym><acronymword>NCO</acronymword></acronym> does not invoke,
the <code>dgll</code> option for a discontinuous Galerkin method on
Gauss-Lobatto-Legendre nodes.)
It is equivalent to, yet simpler to remember and to invoke than 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -a tempest --src_grd=se.g --dst_grd=fv.nc -m map.nc \
        -W '--in_type cgll --in_np 4 --out_type fv --mono'
</verbatim>
</example>
<para>Specifying <samp>-a tempest</samp> without additional options in the
<samp>-W</samp> clause causes TempestRemap to employ defaults.
The default configuration requires both input and output grids to be
<acronym><acronymword>FV</acronymword></acronym>, and produces a conservative, non-monotonic mapping.
The <samp>-a traave</samp> option described below may produce more desirable
results than this default for many users.
Using <samp>-a tempest</samp> alone without other options for spectral
element grids will lead to undefined and likely unintentional
results. 
In other words, <samp>-a tempest</samp> is intended to be used in
conjunction with a <samp>-W</samp> option clause to supply your own
combination of TempestRemap options that does not duplicate one of the 
boutique option collections that already has its own name.
</para>
<para>The full list of supported canonical algorithm names, their synonyms,
and boutique options passed to <command>GenerateOfflineMap</command> or to
<command>mbtempest</command> follow.
</para>
<html endspaces=" ">
&lt;a name=&quot;bug_moab&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bug_moab --&gt;
</html>
<cartouche endspaces=" ">
<para>Caveat lector:
As of September, 2021 <acronym><acronymword>MOAB</acronymword></acronym>-generated weights are only
trustworthy for the <code>traave</code> algorithm (synonym for <code>fv2fv_flx</code>). 
The options for all other algorithms are implemented as indicated
though they should be invoked for testing purposes only.
High order and spectral element maps are completely unsupported.
<acronym><acronymword>MOAB</acronymword></acronym> anticipates supporting more TempestRemap algorithms
in the future.
Always use the map-checker to test maps before use, e.g., with
<samp>ncks --chk_map map.nc</samp>.
</para></cartouche>

<html endspaces=" ">
&lt;a name=&quot;alg_tr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_tr --&gt;
&lt;a name=&quot;alg_mbtr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_mbtr --&gt;
&lt;a name=&quot;alg_moab&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_moab --&gt;
</html>
<table commandarg="asis" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>traave</code> (synonyms <code>fv2fv_flx</code>, <code>fv2fv_mono</code>, <code>conservative_monotone_fv2fv</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --in_np 1 --out_type fv --out_np 1</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --order 1 --method fv --order 1</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>trbilin</code> (no synonyms),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --out_type fv --method bilin</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --method fv --order 1 --order 1 --fvmethod bilin</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>trintbilin</code> (no synonyms),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --out_type fv --method intbilin</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --method fv --order 1 --order 1 --fvmethod intbilin</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>trfv2</code> (synonyms <code>trfvnp2</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --in_np 2 --out_type fv --out_np 1 --method normalize</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --order 2 --method fv --order 1 --fvmethod normalize</samp>
</para>
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>se2fv_flx</code> (synonyms <code>mono_se2fv</code>, <code>conservative_monotone_se2fv</code>)</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type cgll --in_np 4 --out_type fv --mono</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method cgll --order 4 --global_id GLOBAL_DOFS --method fv --monotonic 1 --global_id GLOBAL_ID</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>fv2se_flx</code> (synonyms <code>monotr_fv2se</code>, <code>conservative_monotone_fv2se</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type cgll --in_np 4 --out_type fv --mono</samp>.
For <code>fv2se_flx</code> the weights are generated with options identical to
<code>se2fv_flx</code>, and then the transpose of the resulting weight matrix
is employed.&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method cgll --order 4 --method fv --monotonic 1</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>se2fv_stt</code> (synonyms <code>highorder_se2fv</code>, <code>accurate_conservative_nonmonotone_se2fv</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type cgll --in_np 4 --out_type fv</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method cgll --order 4 --method fv</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>fv2se_stt</code> (synonyms <code>highorder_fv2se</code>, <code>accurate_conservative_nonmonotone_fv2se</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --in_np 2 --out_type cgll --out_np 4</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --order 2 --method cgll --order 4</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>se2fv_alt</code> (synonyms <code>intbilin_se2fv</code>, <code>accurate_monotone_nonconservative_se2fv</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type cgll --in_np 4 --out_type fv --method mono3 --noconserve</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method cgll --order 4 --method fv --monotonic 3 --noconserve</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>fv2se_alt</code> (synonyms <code>mono_fv2se</code>, <code>conservative_monotone_fv2se_alt</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --in_np 1 --out_type cgll --out_np 4 --mono</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --order 1 --method cgll --order 4 --monotonic 1</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>se2se</code> (synonyms <code>cs2cs</code>, <code>conservative_monotone_se2se</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type cgll --in_np 4 --out_type cgll --out_np 4 --mono</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method cgll --order 4 --method cgll --order 4 --monotonic 1</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>fv2fv</code> (synonyms <code>rll2rll</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --in_np 2 --out_type fv</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --order 2 --method fv</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>fv2fv_flx</code> (synonyms <code>traave</code> <code>fv2fv_mono</code>, <code>conservative_monotone_fv2fv</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --in_np 1 --out_type fv --out_np 1</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --order 1 --method fv --order 1</samp>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis"><code>fv2fv_stt</code> (synonyms <code>fv2fv_highorder</code>, <code>accurate_conservative_nonmonotone_fv2fv</code>),</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>TR</acronymword></acronym> options: <samp>--in_type fv --in_np 2 --out_type fv</samp>&linebreak;
<acronym><acronymword>MOAB</acronymword></acronym> options: <samp>--method fv --order 2 --method fv</samp>
</para>

</tableitem></tableentry></table>
<para>Thus these boutique options are specialized for <acronym><acronymword>SE</acronymword></acronym> grids with
fourth order resolution (<math><var>np</var> = 4</math>).
Full documentation of the <acronym><acronymword>E3SM</acronymword></acronym>-recommended boutique options
for TempestRemap is
<uref><urefurl>https://acme-climate.atlassian.net/wiki/spaces/Docs/pages/178848194/Transition+to+TempestRemap+for+Atmosphere+grids</urefurl><urefdesc spaces=" ">here</urefdesc></uref>
(may require <acronym><acronymword>E3SM</acronymword></acronym>-authorization to view).
Let us know if you would like other boutique TempestRemap option sets 
added as canonical options for <command>ncremap</command>.
</para>
<html endspaces=" ">
&lt;a name=&quot;a2o&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#a2o --&gt;
&lt;a name=&quot;atm2ocn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#atm2ocn --&gt;
&lt;a name=&quot;b2l&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#b2l --&gt;
&lt;a name=&quot;big2ltl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#big2ltl --&gt;
&lt;a name=&quot;l2s&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#l2s --&gt;
&lt;a name=&quot;lrg2sml&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#lrg2sml --&gt;
&lt;a name=&quot;allow_no_overlap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#allow_no_overlap --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2624"><command>GenerateOverlapMesh</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2625"><var>a2o</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2626"><code>--a2o</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2627"><code>--atm2ocn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2628"><code>--b2l</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2629"><code>--big2ltl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2630"><code>--l2s</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2631"><code>--lrg2sml</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2632"><code>--allow_no_overlap</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--a2o (<code>--a2o</code>, <code>--atm2ocn</code>, <code>--b2l</code>, <code>--big2ltl</code>, <code>--l2s</code>, <code>--lrg2sml</code>)</itemformat></item>
</tableterm><tableitem><para>Use one of these flags (that take no arguments) to cause TempestRemap to
generate mapping weights from a source grid that has more coverage than
the destination grid, i.e., the destination grid is a subset of the
source.
When computing the intersection of two meshes, TempestRemap uses an
algorithm (in an executable named <command>GenerateOverlapMesh</command>) that
expects the mesh with less coverage to be the first grid, and the
grid with greater coverage to be the second, regardless of the mapping
direction.
By default, <command>ncremap</command> supplies the source grid first and the
destination second, but this order causes <command>GenerateOverlapMesh</command>  
(which is agnostic about ordering for grids of equal coverage)
to fail when the source grid covers regions not in the destination grid.  
For example, a global atmosphere grid has more coverage than a global
ocean grid, so that remapping from atmosphere-to-ocean would require
invoking the <samp>--atm2ocn</samp> switch:
</para><example endspaces=" ">
<pre xml:space="preserve"># Use --a2o to generate weights for &quot;big&quot; to &quot;little&quot; remaps:
ncremap --a2o -a se2fv_flx --src_grd=atm_se_grd.nc \
              --dst_grd=ocn_fv_grd.nc -m atm2ocn.nc
# Otherwise, omit it:
ncremap       -a fv2se_flx --src_grd=ocn_fv_grd.nc \
              --dst_grd=atm_se_grd.nc -m map.nc
ncremap       -a se2fv_flx --src_grd=atm_se_grd.nc \
              --dst_grd=atm_fv_grd.nc -m map.nc
# Only necessary when generating, not applying, weights:
ncremap -m atm2ocn.nc in.nc out.nc
</pre></example>
<para>As shown in the second example above, remapping from global
ocean-to-atmosphere grids does not require (and should not invoke) this
switch. 
The third example shows that the switch is only needed when
<emph>generating</emph> weights, not when applying them. 
The switch is never needed (and is ignored) when generating weights
with <acronym><acronymword>ERWG</acronymword></acronym> (which constructs the intersection mesh with a
different algorithm than TempestRemap).
Attempting to remap a larger source grid to a subset destination grid
without using <samp>--a2o</samp> causes <command>GenerateOverlapMesh</command> to emit
an error (and a potential workaround) like this:
</para><example endspaces=" ">
<pre xml:space="preserve">....Nearest target face 130767
....ERROR: No overlapping face found
....This may be caused by mesh B being a subset of mesh A
....Try swapping order of mesh A and B, or override with \
    --allow_no_overlap
....EXCEPTION (../src/OverlapMesh.cpp, Line 1738) Exiting
</pre></example>
<para>The <samp>--a2o</samp> switch and its synonyms are available in 
version 4.7.3 (March, 2018) and later.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.9 (May, 2021), <code>ncremap</code>
automatically transmits the flag <samp>--allow_no_overlap</samp> to
<command>GenerateOverlapMesh</command> so that regional meshes that do
not completely overlap may be intersected.
This is thought to have no effect on global mappings.
Please let us know if these capabilities do not work for you.
</para>
<html endspaces=" ">
&lt;a name=&quot;add_fill_value&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#add_fill_value --&gt;
&lt;a name=&quot;add_fll&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#add_fll --&gt;
&lt;a name=&quot;fill_empty&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fill_empty --&gt;
&lt;a name=&quot;fll_mpt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fll_mpt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2633">missing value</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2634"><code>_FillValue</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2635"><code>--add_fll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2636"><code>--no_add_fll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2637"><code>--add_fill_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2638"><code>--fll_mpt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2639"><code>--no_fll_mpt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2640"><code>--fill_empty</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2641"><code>--no_fill_empty</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2642"><code>--msk_apl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2643"><code>--mask_apply</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--add_fll (<code>--add_fll</code>, <code>--add_fill_value</code>, <code>--fll_mpt</code>, <code>--fill_empty</code>)</itemformat></item>
</tableterm><tableitem><para>Introduced in <acronym><acronymword>NCO</acronymword></acronym> version 5.0.0 (released June, 2021),
this switch (which takes no argument) causes the regridder to add a
<code>_FillValue</code> attribute to fields with empty destination cells.
The corresponding <code>--no_add_fll</code> switches, introduced in
<acronym><acronymword>NCO</acronymword></acronym> version 5.1.1 (released November, 2022),
do the opposite and prevent the regridder from adding a
<code>_FillValue</code> attribute to fields with empty destination cells. 
Note that <code>--add_fll</code> adds an explicit <code>_FillValue</code> metadata
attribute to fields that lack one only if the field contains empty
destination cells (as described below).
This option, by itself, does not directly change the values contained
in empty gridcells. 
</para>
<para>There are two varieties of empty destination cells:
First are those cells with no non-zero weights from the source grids.
If all source grid contributions to the a particular cell are zero,
then no field will ever be mapped into that cell.
For example, if an ocean model source grid only contains ocean
gridcells (e.g., like <acronym><acronymword>MPAS</acronymword></acronym>-Ocean), then all continental
interior gridcells in a destination grid will be empty.
The second type of empty gridcell can occur in conjunction with
sub-gridscale (<acronym><acronymword>SGS</acronymword></acronym>) fractions.
All destination gridcells with <acronym><acronymword>SGS</acronymword></acronym> fraction equal to zero
will always be empty.
For example, sea-ice models often employ time-varying <acronym><acronymword>SGS</acronymword></acronym>
fractions that are zero everywhere except where/when sea ice is
present.
These gridcells are disjoint from continental interior gridcells
whose locations can be determined by mapping weights alone.
</para>
<para>When a contiguous geophysical field (e.g., air temperature) without a
<code>_FillValue</code> is mapped to such a destination grid, the empty
destination values are normally set to zero (because no source grid
cells contribute).
However, zero is a valid value for many geophysical fields.
Use this switch to ensure that empty destination gridcells are always 
set to <code>_FillValue</code>.
The default <code>_FillValue</code> will be used in the output file for
input fields that lack an explicit <code>_FillValue</code>.
This flag has no effect on fields that have any input values equal
to an explicitly or implicitly defined <code>_FillValue</code>.
The flag does affect fields that have valid input values everywhere
on the source grid, yet for some reason (e.g., disjoint grids or
zero sub-gridscale fractions) there are unmapped destination
gridcells. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap ...           # No renormalization/masking
ncremap --sgs_frc=sgs --add_fll ... # Mask cells missing 100% 
ncremap --rnr=0.1 ... # Mask cells missing &gt; 10% 
ncremap --rnr=0.1 --sgs_frc=sgs ... # Mask missing &gt; 10%
ncremap --rnr=0.1 --sgs_frc=sgs --add_fll ... # Mask missing &gt; 90% or sgs &lt; 10% 
ncremap -P mpas... # --add_fll implicit, mask where sgs=0.0
ncremap -P mpas... --no_add_fll # --add_fll explicitly turned-off, no masking
ncremap -P mpas... --rnr=0.1 # Mask missing &gt; 90% or sgs &lt; 10% 
ncremap -P elm...  # --add_fll not implicit, no masking
</verbatim>
</example>
<para>Note that <code>--add_fll</code> is automatically triggered by
<code>--msk_apl</code> to ensure that masked fields regridded with
TempestRemap-generated map-files have <code>_FillValue</code>s consistent 
with map-files generated by <acronym><acronymword>ESMF</acronymword></acronym> and <acronym><acronymword>NCO</acronymword></acronym>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;alg_lst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alg_lst --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2644"><code>--alg_lst=<var>alg_lst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2645"><var>alg_lst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2646"><code>--alg_lst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2647"><code>--algorithm_list</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--alg_lst=<var>alg_lst</var> (<code>--alg_lst</code>, <code>--algorithm_list</code>)</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 5.2.0 (February, 2024), <command>ncremap</command>
supports <samp>--alg_lst=<var>alg_lst</var></samp>, a comma-separated list of the
algorithms that <acronym><acronymword>MWF</acronymword></acronym>-mode uses to create map-files.
The default list is
<code>esmfaave,esmfbilin,ncoaave,ncoidw,traave,trbilin,trfv2,trintbilin</code>.
Each name in the list should be the primary name of an algorithm,
not a synonym.
For example, use <code>esmfaave,traave</code> not
<code>aave,fv2fv_flx</code> (the latter are backward-compatible synonyms
for the former). 
The algorithm list must be consistent with grid-types supplied:
<acronym><acronymword>ESMF</acronymword></acronym> algorithms work with meshes in <acronym><acronymword>ESMF</acronymword></acronym>,
<acronym><acronymword>SCRIP</acronymword></acronym>, or <acronym><acronymword>UGRID</acronymword></acronym> formats.
<acronym><acronymword>NCO</acronymword></acronym> algorithms only work with meshes in <acronym><acronymword>SCRIP</acronymword></acronym>
format.
TempestRemap algorithms work with meshes in <acronym><acronymword>ESMF</acronymword></acronym>,
<acronym><acronymword>Exodus</acronymword></acronym>, <acronym><acronymword>SCRIP</acronymword></acronym>, or <acronym><acronymword>UGRID</acronymword></acronym> formats. 
On output, <command>ncremap</command> inserts each algorithm name into the
output map-file name in this format:   
<code>map_<var>nm_src</var>_to_<var>nm_dst</var>_<var>alg_typ</var>.<var>dt_sng</var>.nc</code>.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
% ncremap -P mwf --alg_lst=esmfnstod,ncoaave,ncoidw,traave,trbilin \
  -s ocean.QU.240km.scrip.181106.nc -g ne11pg2.nc \
  --nm_src=QU240 --nm_dst=ne11pg2 --dt_sng=20240201
...
% ls map*
map_QU240_to_ne11pg2_esmfnstod.20240201.nc
map_QU240_to_ne11pg2_ncoaave.20240201.nc
map_QU240_to_ne11pg2_ncoidw.20240201.nc
map_QU240_to_ne11pg2_traave.20240201.nc
map_QU240_to_ne11pg2_trbilin.20240201.nc
map_ne11pg2_to_QU240_esmfnstod.20240201.nc
map_ne11pg2_to_QU240_ncoaave.20240201.nc
map_ne11pg2_to_QU240_ncoidw.20240201.nc
map_ne11pg2_to_QU240_traave.20240201.nc
map_ne11pg2_to_QU240_trbilin.20240201.nc
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;area_dgn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#area_dgn --&gt;
&lt;a name=&quot;dgn_area&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dgn_area --&gt;
&lt;a name=&quot;area_diagnose&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#area_diagnose --&gt;
&lt;a name=&quot;diagnose_area&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#diagnose_area --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2648">diagnose area</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2649"><code>--area_dgn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2650"><code>--dgn_area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2651"><code>--area_diagnose</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2652"><code>--diagnose_area</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--area_dgn (<code>--area_dgn</code>, <code>--area_diagnose</code>, <code>--dgn_area</code>, <code>--diagnose_area</code>)</itemformat></item>
</tableterm><tableitem><para>Introduced in <acronym><acronymword>NCO</acronymword></acronym> version 5.0.4 (released December, 2021),
this switch (which takes no argument) causes the regridder to diagnose 
(rather than copy) the area of each gridcell to an inferred grid-file.
By default, <command>ncremap</command> simply copies the area variable (whose
name defaults to <code>area</code> and can be explicitly specified with
<samp>-R '--rgr area_nm=name'</samp>) into the <code>grid_area</code> variable of
the inferred grid-file.
When <code>--area_dgn</code> is invoked, <command>ncremap</command> instead computes
the values of <code>grid_area</code> based on the cell boundaries in the
input template file.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --area_dgn -d dst.nc -g grid.nc
</verbatim>
</example>
<para>Note that <code>--area_dgn</code> has no effect on any mapping weights
subsequently generated from the grid-file because most
weight-generators base their weights on internally computed cell
areas (although <acronym><acronymword>ERWG</acronymword></acronym> has an option, <code>--user_areas</code>, to
override this behavior).
</para>
<html endspaces=" ">
&lt;a name=&quot;config&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#config --&gt;
&lt;a name=&quot;cnf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnf --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2653"><code>--version</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2654"><code>--vrs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2655"><code>--config</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2656"><code>--configuration</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2657"><code>--cnf</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--version (<code>--version</code>, <code>--vrs</code>, <code>--config</code>, <code>--configuration</code>, <code>--cnf</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) causes the operator to print
its version and configuration.
This includes the copyright notice, <acronym><acronymword>URL</acronymword></acronym>s to the <acronym><acronymword>BSD</acronymword></acronym>
and <acronym><acronymword>NCO</acronymword></acronym> license, directories from which the <acronym><acronymword>NCO</acronymword></acronym>
scripts and binaries are running, and the locations of any separate 
executables that may be used by the script.
</para>
<html endspaces=" ">
&lt;a name=&quot;d2f&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#d2f --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2658"><code>d2f</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2659"><code>--d2f</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2660"><code>--d2s</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2661"><code>--dbl_flt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2662"><code>--dbl_sgl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2663"><code>--double_float</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2664"><code>ncpdq</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2665">Precision</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--d2f (<code>--d2f</code>, <code>--d2s</code>, <code>--dbl_flt</code>, <code>--dbl_sgl</code>, <code>--double_float</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) demotes all double precision
non-coordinate variables to single precision.
Internally <command>ncremap</command> invokes <command>ncpdq</command> to apply the
<code>dbl_flt</code> packing map to an intermediate version of the input
file before regridding it.
This switch has no effect on files that are not regridded.
To demote the precision in such files, use <command>ncpdq</command> to apply 
the <code>dbl_flt</code> packing map to the file directly.
Files without any double precision fields will be unaltered.
</para>
<html endspaces=" ">
&lt;a name=&quot;dbg_lvl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dbg_lvl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2666"><code>-D <var>dbg_lvl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2667"><var>dbg_lvl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2668"><code>--dbg_lvl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2669"><code>--dbg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2670"><code>--debug</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2671"><code>--debug_level</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-D <var>dbg_lvl</var> (<code>--dbg_lvl</code>, <code>--dbg</code>, <code>--debug</code>, <code>--debug_level</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a debugging level similar to the rest of <acronym><acronymword>NCO</acronymword></acronym>.
If <math><var>dbg_lvl</var> = 1</math>, <command>ncremap</command> prints more extensive
diagnostics of its behavior.
If <math><var>dbg_lvl</var> = 2</math>, <command>ncremap</command> prints the commands
it would execute at any higher or lower debugging level, but does
not execute these commands.
If <math><var>dbg_lvl</var> &gt; 2</math>, <command>ncremap</command> prints the diagnostic
information, executes all commands, and passes-through the debugging
level to the regridder (<command>ncks</command>) for additional diagnostics.
</para>
<html endspaces=" ">
&lt;a name=&quot;devnull&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#devnull --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2672"><code>--devnull</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2673"><code>--dev_nll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2674"><code>--dvn_flg</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp"><code>--devnull=<var>dvn_flg</var></code> (<code>--devnull</code>, <code>--dev_nll</code>, <code>--dvn_flg</code>)</itemformat></item>
</tableterm><tableitem><para>The <var>dvn_flg</var> controls whether <command>ncremap</command> suppresses
regridder output or sends it to <code>/dev/null</code>.
The default value of <var>dvn_flg</var> is &textldquo;Yes&textrdquo;, so that
<command>ncremap</command> prints little output to the terminal.
Set <var>dvn_flg</var> to &textldquo;No&textrdquo; to allow the internal regridder
executables (mainly <command>ncks</command>) to send their output to the
terminal.
</para>
<html endspaces=" ">
&lt;a name=&quot;dpt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dpt --&gt;
&lt;a name=&quot;dpt_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dpt_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2675"><code>dpt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2676"><code>--dpt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2677"><code>--add_dpt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2678"><code>--depth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2679"><code>--add_depth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2680"><code>--dpt_fl=<var>dpt_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2681"><var>dpt_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2682"><code>--mpas_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2683"><code>--mpas_depth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2684"><code>--depth_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2685"><command>add_depth.py</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2686">Depth</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2687"><acronym><acronymword>MPAS</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--dpt (<code>--dpt</code>, <code>--add_dpt</code>, <code>--depth</code>, <code>--add_depth</code>)</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">--dpt_fl=<var>dpt_fl</var> (<code>--dpt_fl</code>, <code>--depth_file</code>, <code>--mpas_fl</code>, <code>--mpas_depth</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>--dpt</samp> switch (which takes no argument) and the
<samp>--dpt_fl=<var>dpt_fl</var></samp> option which automatically sets the
switch and also takes a filename argument, both control the addition
of a depth coordinate to <acronym><acronymword>MPAS</acronymword></acronym> ocean datasets.
Depth is the vertical distance below sea surface and, like pressure
in the atmosphere, is an important vertical coordinate whose explicit
values are often omitted from datasets yet may be computed from other
variables (gridbox thickness, pressure difference) and grid information.
Moreover, users are often more interested in the approximate depth,
aka reference depth, of a given ocean layer independent of its
horizontal position.
To invoke either of these options first obtain and place the
<command>add_depth.py</command> command on the executable path (i.e.,
<code>$PATH</code>), and use <command>ncremap --config</command> to verify that it is
found.
These options tell <command>ncremap</command> to invoke <command>add_depth.py</command>
which uses the <code>refBottomDepth</code> variable in the current data file
or, if specified, the <var>dpt_fl</var>, to create and add a depth
coordinate to the current file (before regridding).
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.7.9 (February, 2019), the depth
coordinate is an approximate, one-dimensional, globally uniform 
coordinate that neglects horizontal variations in depth that can occur
near strong bathymetry or under ice shelves.
Like its atmospheric counterpart in many models, the <code>lev</code>
pressure-coordinate, <code>depth</code> is useful for plotting purposes and
global studies. 
It would not be difficult to modify these options to add other depth
information based on the 3D cell-thickness field to ocean files
(please ask Charlie if interested in this).
</para>
<html endspaces=" ">
&lt;a name=&quot;dst_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dst_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2688"><code>-d <var>dst_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2689"><var>dst_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2690"><code>--dst_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2691"><code>--destination_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2692"><code>--tpl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2693"><code>--tpl_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2694"><code>--template</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2695"><code>--template_file</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-d <var>dst_fl</var> (<code>--dst_fl</code>, <code>--destination_file</code>, <code>--tpl</code>, <code>tpl_fl</code>, <code>--template_file</code>, <code>--template</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a data file to serve as a template for inferring the
destination grid. 
Currently <var>dst_fl</var> must be a data file (not a gridfile,
<acronym><acronymword>SCRIP</acronymword></acronym> or otherwise) from which <acronym><acronymword>NCO</acronymword></acronym> can
infer the destination grid. 
The more coordinate and boundary information and metadata 
the better <acronym><acronymword>NCO</acronymword></acronym> will do at inferring the grid.
If <var>dst_fl</var> has cell boundaries then <acronym><acronymword>NCO</acronymword></acronym> will use those.
If <var>dst_fl</var> has only cell-center coordinates (and no edges),
then <acronym><acronymword>NCO</acronymword></acronym> will guess-at (for rectangular grids) or interpolate
(for curvilinear grids) the edges. 
Unstructured grids must supply cell boundary information, as it cannot
be interpolated or guessed-at.
<acronym><acronymword>NCO</acronymword></acronym> only reads coordinate and grid data and metadata from
<var>dst_fl</var>. 
<var>dst_fl</var> is not modified, and may have read-only permissions.
</para>
<html endspaces=" ">
&lt;a name=&quot;dt_sng&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dt_sng --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2696"><code>--dt_sng=<var>dt_sng</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2697"><var>dt_sng</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2698"><code>--dt_sng</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2699"><code>--date_string</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--dt_sng=<var>dt_sng</var> (<code>--dt_sng</code>, <code>--date_string</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the date-string use in the full name of map-files created in
<acronym><acronymword>MWF</acronymword></acronym> mode.  
Map-file names include, by convention, a string to indicate the
approximate date (and thus algorithm versions employed) of weight
generation. 
<command>ncremap</command> uses the <var>dt_sng</var> argument to encode the date
into output map-file names of this format:  
<code>map_<var>nm_src</var>_to_<var>nm_dst</var>_<var>alg_typ</var>.<var>dt_sng</var>.nc</code>.
<acronym><acronymword>MWF</acronymword></acronym> mode defaults <var>dt_sng</var> to the current date in
<code>YYYYMMDD</code>-format. 
</para>
<html endspaces=" ">
&lt;a name=&quot;esmf_typ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#esmf_typ --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2700"><code>--esmf_typ=<var>esmf_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2701"><var>esmf_typ</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2702"><code>--esmf_typ</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2703"><code>--esmf_mth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2704"><code>--esmf_extrap_type</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2705"><code>--esmf_extrap_method</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2706">distance-weighted extrapolation</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--esmf_typ=<var>esmf_typ</var> (<code>--esmf_typ</code>, <code>--esmf_mth</code>, <code>--esmf_extrap_type</code>, <code>--esmf_extrap_method</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the extrapolation method used to compute unmapped
destination point values with the <acronym><acronymword>ERWG</acronymword></acronym> weight generator.
Valid values, their synonyms, and their meanings are
<code>neareststod</code> (synonyms <code>stod</code> and <code>nsd</code>) which
uses the nearest valid source value,
<code>nearestidavg</code> (synonyms <code>idavg</code> and <code>id</code>) which
uses an inverse distance-weighted (with an exponent of <var>xtr_xpn</var>)
average of the nearest <var>xtr_nsp</var> valid source values, and 
<code>none</code> (synonyms <code>nil</code> and <code>nowaydude</code>) which forbids 
extrapolation. 
Default is <math><var>esmf_typ</var> = <code>none</code></math>.
The arguments to options <samp>--xtr_xpn=<var>xtr_xpn</var></samp> (which
defaults to 2.0) and <samp>--xtr_nsp=<var>xtr_nsp</var></samp> (which defaults
to 8) set the parameters that control the extrapolation
<code>nearestidavg</code> algorithm.   
For more information on <acronym><acronymword>ERWG</acronymword></acronym> extrapolation, see documentation
<uref><urefurl>http://www.earthsystemmodeling.org/esmf_releases/last_built/ESMF_refdoc/node3.html#SECTION03022300000000000000</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
<acronym><acronymword>NCO</acronymword></acronym> supports this feature as of version 4.7.4 (April, 2018). 
</para>
<html endspaces=" ">
&lt;a name=&quot;xtr_nsp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xtr_nsp --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2707">extrapolation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2708"><code>--xtr_nsp=<var>xtr_nsp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2709"><var>xtr_nsp</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2710"><code>--xtr_nsp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2711"><code>--esmf_pnt_src_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2712"><code>--esmf_extrap_num_src_pnts</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--xtr_nsp=<var>xtr_nsp</var> (<code>--xtr_nsp</code>, <code>--esmf_pnt_src_nbr</code>, <code>--esmf_extrap_num_src_pnts</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the number of source points to use in extrapolating unmapped
destination point values with the <acronym><acronymword>ERWG</acronymword></acronym> weight generator.
This option is only useful in conjunction with explicitly requested
extrapolation types <math><var>esmf_typ</var> = <code>neareststod</code></math> and
<math><var>esmf_typ</var> = <code>nearestidavg</code></math>. 
Default is <math><var>xtr_nsp</var> = 8</math>.
For more information on <acronym><acronymword>ERWG</acronymword></acronym> extrapolation, see documentation
<uref><urefurl>http://www.earthsystemmodeling.org/esmf_releases/last_built/ESMF_refdoc/node3.html#SECTION03022300000000000000</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
<acronym><acronymword>NCO</acronymword></acronym> supports this feature as of version 4.7.4 (April, 2018). 
</para>
<html endspaces=" ">
&lt;a name=&quot;xtr_xpn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xtr_xpn --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2713"><code>--xtr_xpn=<var>xtr_xpn</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2714"><var>xtr_xpn</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2715"><code>--xtr_xpn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2716"><code>--esmf_pnt_src_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2717"><code>--esmf_extrap_num_src_pnts</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--xtr_xpn=<var>xtr_xpn</var> (<code>--xtr_xpn</code>, <code>--esmf_pnt_src_nbr</code>, <code>--esmf_extrap_num_src_pnts</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the number of source points to use in extrapolating unmapped
destination point values with the <acronym><acronymword>ERWG</acronymword></acronym> weight generator.
This option is only useful in conjunction with explicitly requested
extrapolation types <math><var>esmf_typ</var> = <code>neareststod</code></math> and
<math><var>esmf_typ</var> = <code>nearestidavg</code></math>. 
Default is <math><var>xtr_xpn</var> = 2.0</math>.
For more information on <acronym><acronymword>ERWG</acronymword></acronym> extrapolation, see documentation
<uref><urefurl>http://www.earthsystemmodeling.org/esmf_releases/last_built/ESMF_refdoc/node3.html#SECTION03022300000000000000</urefurl><urefdesc spaces=" ">here</urefdesc></uref>.
<acronym><acronymword>NCO</acronymword></acronym> supports this feature as of version 4.7.4 (April, 2018). 
</para>
<html endspaces=" ">
&lt;a name=&quot;grd_dst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grd_dst --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2718"><code>-g <var>grd_dst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2719"><var>grd_dst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2720"><code>--grd_dst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2721"><code>--grid_dest</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2722"><code>--dest_grid</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2723"><code>--destination_grid</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2724">infer</indexterm></cindex>
<item spaces=" "><itemformat command="samp">-g <var>grd_dst</var> (<code>--grd_dst</code>, <code>--grid_dest</code>, <code>--dest_grid</code>, <code>--destination_grid</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the destination gridfile.
An existing gridfile may be in any format accepted by the weight generator.
<acronym><acronymword>NCO</acronymword></acronym> will use <acronym><acronymword>ERWG</acronymword></acronym> or TempestRemap to combine
<var>grd_dst</var> with a source gridfile (either inferred from
<var>input-file</var>, supplied with <samp>-s <var>grd_src</var></samp>, or generated
from <samp>-G <var>grd_sng</var></samp>) to produce remapping weights. 
When <var>grd_dst</var> is used as input, it is not modified,
and may have read-only permissions.
When <var>grd_dst</var> is inferred from <var>input-file</var> or created
from <var>grd_sng</var>, it will be generated in <acronym><acronymword>SCRIP</acronymword></acronym> format. 
</para>
<html endspaces=" ">
&lt;a name=&quot;fl_fmt_ncremap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fl_fmt_ncremap --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2725"><code>--fl_fmt_ncremap</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2726"><code>--file_format_ncremap</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2727"><code>-3</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2728"><code>-4</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2729"><code>-5</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2730"><code>-6</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2731"><code>-7</code></indexterm></cindex>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.8 (August, 2017), <command>ncremap</command>
supports most of the file format options that the rest of <acronym><acronymword>NCO</acronymword></acronym>
has long supported (<pxref label="File-Formats-and-Conversion"><xrefnodename>File Formats and Conversion</xrefnodename></pxref>).
This includes short flags (e.g., <samp>-4</samp>) and key-value options (e.g., 
<samp>--fl_fmt=netcdf4</samp>) though not long-flags without values
(e.g., <samp>--netcdf4</samp>).
However, <command>ncremap</command> can only apply the full suite of file format 
options to files that it creates, i.e., regridded files.
The weight generators (<acronym><acronymword>ERWG</acronymword></acronym> and TempestRemap) are limited
in the file formats that they read and write.
Currently (August, 2017), <acronym><acronymword>ERWG</acronymword></acronym> supports <code>CLASSIC</code>,
<code>64BIT_OFFSET</code>, and <code>NETCDF4</code>, while TempestRemap
supports only <code>CLASSIC</code>.
These can of course be converted to other formats using <command>ncks</command>
(<pxref label="File-Formats-and-Conversion"><xrefnodename>File Formats and Conversion</xrefnodename></pxref>).
However, map-files <emph>produced</emph> in other non-<code>CLASSIC</code> formats
can remap significantly larger grids than <code>CLASSIC</code>-format
map-files. 
</para>
<html endspaces=" ">
&lt;a name=&quot;grd_sng&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grd_sng --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2732"><code>-G <var>grd_sng</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2733"><var>&textndash;grd_sng</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2734"><code>--grd_sng</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2735"><code>--grid_generation</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2736"><code>--grid_gen</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2737"><code>--grid_string</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-G <var>grd_sng</var> (<code>--grd_sng</code>, <code>--grid_generation</code>, <code>--grid_gen</code>, <code>--grid_string</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies, with together with other options, a source gridfile to 
create<footnote spaces=" \n"><para>As of version 4.7.6 (August, 2018)), <acronym><acronymword>NCO</acronymword></acronym>&textrsquo;s syntax for
gridfile generation is much improved and streamlined, and is the
syntax described here.
This is also called &textldquo;Manual Grid-file Generation&textrdquo;.
An earlier syntax (described at <pxref label="Grid-Generation"><xrefnodename>Grid Generation</xrefnodename></pxref>) accessed
through <command>ncks</command> options still underlies the new syntax, though 
it is less user-friendly. 
Both old and new syntax work well and produce finer rectangular
grids than any other software we know of.</para></footnote>.
<command>ncremap</command> creates the gridfile in <acronym><acronymword>SCRIP</acronymword></acronym> format by
default, and then, should the requisite options for regridding
be present, combines that with the destination grid (either
inferred from <var>input-file</var> or supplied with
<samp>-g <var>grd_dst</var></samp> and generates mapping weights.
Manual grid-file generation is not frequently used since
<command>ncremap</command> can infer many grids directly from the
<var>input-file</var>, and few users wish to keep track of <acronym><acronymword>SCRIP</acronymword></acronym>
grids when they can be easily regenerated as intermediate files.
This option also allows one to visually tune a grid by rapidly
generating candidates and inspecting the results.
</para>
<para>If a desired grid-file is unavailable, and no dataset on that grid is
available (so inferral cannot be used), then one must manually create
a new grid. 
Users create new grids for many reasons including dataset
intercomparisons, regional studies, and fine-tuned graphics.
<acronym><acronymword>NCO</acronymword></acronym> and <command>ncremap</command> support manual generation of the
most common rectangular grids as <acronym><acronymword>SCRIP</acronymword></acronym>-format grid-files.
Create a grid by supplying <command>ncremap</command> with a grid-file name and
&textldquo;grid-formula&textrdquo; (<var>grd_sng</var>) that contains, at a minimum, the
grid-resolution.
The grid-formula is a single hash-separated string of name-value pairs
each representing a grid parameter.
All parameters except grid resolution have reasonable defaults, so a
grid-formula can be as simple as <samp>latlon=180,360</samp>: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -g grd.nc -G latlon=180,360
</verbatim>
</example>
<para>The <acronym><acronymword>SCRIP</acronymword></acronym>-format grid-file <file>grd.nc</file> is a valid source
or destination grid for <command>ncremap</command> and other regridders. 
</para>
<para>Grid-file generation documentation in the <acronym><acronymword>NCO</acronymword></acronym> Users Guide at
<url><urefurl>http://nco.sf.net/nco.html#grid</urefurl></url> describes all the grid
parameters and contains many examples.
Note that the examples in this section use grid generation
<acronym><acronymword>API</acronymword></acronym> for <command>ncremap</command> version 4.7.6 (August, 2018) and 
later.
Earlier versions can use the <command>ncks</command> <acronym><acronymword>API</acronymword></acronym> explained
at <ref label="Grid-Generation"><xrefnodename>Grid Generation</xrefnodename></ref> in the Users Guide.  
</para>
<para>The most useful grid parameters (besides resolution) are latitude type
(<var>lat_typ</var>), longitude type (<var>lon_typ</var>), title (<var>ttl</var>),
and, for regional grids, the <acronym><acronymword>SNWE</acronymword></acronym> bounding box
(<var>snwe</var>).
The three supported varieties of global rectangular grids are
Uniform/equiangular (<math><var>lat_typ</var>=<code>uni</code></math>), Cap/FV
(<math><var>lat_typ</var>=<code>cap</code></math>), and Gaussian 
(<math><var>lat_typ</var>=<code>gss</code></math>).
The four supported varieties of longitude types are the first
(westernmost) gridcell centered at Greenwich
(<math><var>lon_typ</var>=<code>grn_ctr</code></math>), western edge at Greenwish
(<code>grn_wst</code>), or at the Dateline
(<math><var>lon_typ</var>=<code>180_ctr</code></math> and
<math><var>lon_typ</var>=<code>180_wst</code></math>, respectively).
Grids are global, uniform, and have their first longitude centered at 
Greenwich by default.
The grid-formula for this is <samp>lat_typ=uni#lon_typ=grn_ctr</samp>. 
Some examples (remember, this <acronym><acronymword>API</acronymword></acronym> requires <acronym><acronymword>NCO</acronymword></acronym>
4.7.6+): 
</para><example endspaces=" ">
<pre xml:space="preserve"><cindex index="cp" spaces=" "><indexterm index="cp" number="2738"><acronym><acronymword>NCEP2</acronymword></acronym> grid</indexterm></cindex>
</pre><verbatim xml:space="preserve" endspaces=" ">
ncremap -g grd.nc -G latlon=180,360                 # 1x1 Uniform grid
ncremap -g grd.nc -G latlon=180,360#lat_drc=n2s     # 1x1 Uniform grid, N-&gt;S not S-&gt;N
ncremap -g grd.nc -G latlon=180,360#lon_typ=grn_wst # 1x1 Uniform grid, Greenwich-west edge
ncremap -g grd.nc -G latlon=129,256#lat_typ=cap     # 1.4x1.4  FV grid
ncremap -g grd.nc -G latlon=94,192#lat_typ=gss      # T62 Gaussian grid
ncremap -g grd.nc -G latlon=361,576#lat_typ=cap#lon_typ=180_ctr # MERRA2 FV grid
ncremap -g grd.nc -G latlon=94,192#lat_typ=gss#lat_drc=n2s # NCEP2 T62 Gaussian grid 
</verbatim>
</example>
<para>Regional grids are a powerful tool in regional process analyses, and
can be much smaller in size than global datasets.
Regional grids are always uniform. Specify the rectangular bounding
box, i.e., the outside edges of the region, in <acronym><acronymword>SNWE</acronymword></acronym> order:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -g grd.nc -G ttl=&quot;Equi-Angular 1x1 Greenland grid&quot;#latlon=30,90#snwe=55.0,85.0,-90.0,0.0
</verbatim>
</example>
<para>The <var>grd_sng</var> argument to <samp>-G</samp> or <samp>--grd_sng</samp> must be 
a <emph>single</emph> hash-separated string of name-value pairs, e.g.,
<code>latlon=....#lat_typ=...#ttl=&quot;My title&quot;</code>.
<command>ncremap</command> will not correctly parse any other format, such
as multiple separate name-value pairs without hashes.
</para>
<html endspaces=" ">
&lt;a name=&quot;in_drc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#in_drc --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2739"><code>-I <var>in_drc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2740"><var>in_drc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2741"><code>stdin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2742"><code>--in_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2743"><code>--drc_in</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2744"><code>--dir_in</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2745"><code>--in_dir</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2746"><code>--input</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-I <var>in_drc</var> (<code>--in_drc</code>, <code>--drc_in</code>, <code>--dir_in</code>, <code>--in_dir</code>, <code>input</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the input directory, i.e., the directory which contains
the input file(s).
If <var>in_fl</var> is also specified, then the input filepath is
constructed by appending a slash and the filename to the directory:
<samp><var>in_drc</var>/<var>in_fl</var></samp>.
Specifying <var>in_drc</var> without <var>in_fl</var> causes <command>ncremap</command>
to attempt to remap every file in <var>in_drc</var> that ends with one of
these suffixes: <code>.nc</code>, <code>.nc3</code>, <code>.nc4</code>, <code>.nc5</code>,
<code>.nc6</code>, <code>.nc7</code>, <code>.cdf</code>,
<code>.hdf</code>, <code>.he5</code>, or <code>.h5</code>.
When multiple files are regridded, each output file takes the name
of the corresponding input file.
There is no namespace conflict because the input and output files are in
separate directories. 
Note that <command>ncremap</command> can instead accept a list of input files
through standard input (e.g., <samp>ls *.nc | ncremap ...</samp>) or as
positional command-line arguments (e.g., <samp>ncremap in1.nc in2.nc ...</samp>).
</para>
<html endspaces=" ">
&lt;a name=&quot;in_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#in_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2747"><code>-i <var>in_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2748"><var>in_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2749"><code>--in_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2750"><code>--in_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2751"><code>--input_file</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-i <var>in_fl</var> (<code>--in_fl</code>, <code>--in_file</code>, <code>--input_file</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the file containing data on the source grid to be remapped
to the destination grid.
When provided with the optional <var>map_fl</var>, <command>ncremap</command> 
only reads data from <var>in_fl</var> in order to regrid it.
Without the optional <var>map_fl</var> or <var>src_grd</var>, <command>ncremap</command>
will try to infer the source grid from <var>in_fl</var>, and so must read
coordinate and metatdata information from <var>in_fl</var>.  
In this case the more coordinate and boundary information and metadata,
the better <acronym><acronymword>NCO</acronymword></acronym> will do at inferring the source grid.
If <var>in_fl</var> has cell boundaries then <acronym><acronymword>NCO</acronymword></acronym> will use those. 
If <var>in_fl</var> has only cell-center coordinates (and no edges),
then <acronym><acronymword>NCO</acronymword></acronym> will guess (for rectangular grids) or interpolate
(for curvilinear grids) the edges.  
Unstructured grids must supply cell boundary information, as it cannot
be interpolated or guessed-at.
<var>in_fl</var> is not modified, and may have read-only permissions.
Note that <command>ncremap</command> can instead accept input file name(s)
through standard input (e.g., <samp>ls *.nc | ncremap ...</samp>) or as
positional command-line arguments (e.g.,
<samp>ncremap in1.nc in2.nc ...</samp>).
When one or three-or-more positional arguments are given, they are
all interpreted as input filename(s).  
Two positional arguments are interpreted as a single <var>input-file</var>
and its corresponding <var>output-file</var>.
</para>
<html endspaces=" ">
&lt;a name=&quot;job_nbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#job_nbr --&gt;
&lt;a name=&quot;job_nbr_ncremap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#job_nbr_ncremap --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2752"><code>-j <var>job_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2753"><var>job_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2754"><code>--job_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2755"><code>--job_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2756"><code>--job_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2757"><code>--jobs</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-j <var>job_nbr</var> (<code>--job_nbr</code>, <code>--job_number</code>, <code>--jobs</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the number of simultaneous regridding processes to spawn  
during parallel execution for both Background and <acronym><acronymword>MPI</acronymword></acronym> modes. 
In both parallel modes <command>ncremap</command> spawns processes in batches 
of <var>job_nbr</var> jobs, then waits for those processes to complete.
Once a batch finishes, <command>ncremap</command> spawns the next batch.
In Background mode, all jobs are spawned to the local node.
In <acronym><acronymword>MPI</acronymword></acronym> mode, all jobs are spawned in round-robin fashion
to all available nodes until <var>job_nbr</var> jobs are running.
</para>
<para>If regridding consumes so much <acronym><acronymword>RAM</acronymword></acronym> (e.g., because
variables are large and/or the number of threads is large) that a
single node can perform only one regridding job at a time, then a
reasonable value for <var>job_nbr</var> is the number of nodes,
<var>node_nbr</var>. 
Often, however, nodes can regrid multiple files simultaneously. 
It can be more efficient to spawn multiple jobs per node than to
increase the threading per job because I/O contention for write
access to a single file prevents threading from scaling indefinitely. 
</para>
<para>By default <math><var>job_nbr</var> = 2</math> in Background mode, and
<math><var>job_nbr</var> = <var>node_nbr</var></math> in <acronym><acronymword>MPI</acronymword></acronym> mode.
This helps prevent users from overloading nodes with too many jobs.
Subject to the availability of adequate <acronym><acronymword>RAM</acronymword></acronym>,
expand the number of jobs per node by increasing <var>job_nbr</var>
until, ideally, each core on the node is used. 
Remember that processes and threading are multiplicative in core use.
Four jobs each with four threads each consumes sixteen cores.
</para>
<para>As an example, consider regridding <w>100 files</w> with a single map.
Say you have a five-node cluster, and each node has <w>16 cores</w>
and can simultaneously regrid two files using eight threads each.
(One needs to test a bit to optimize these parameters.)
Then an optimal (in terms of wallclock time) invocation would
request five nodes with <w>10 simultaneous</w> jobs of eight threads.
On <acronym><acronymword>PBS</acronymword></acronym> or <acronym><acronymword>SLURM</acronymword></acronym> batch systems this would involve a
scheduler command like <samp>qsub -l nodes=5 ...</samp> or 
<samp>sbatch --nodes=5 ...</samp>, respectively, followed by 
<samp>ncremap --par_typ=mpi --job_nbr=10 --thr_nbr=8 ...</samp>.
This job will likely complete between five and ten-times faster than a  
serial-mode invocation of <command>ncremap</command> to regrid the same files.
The uncertainty range is due to unforeseeable, system-dependent
load and I/O charateristics.
Nodes that can simultaneously write to more than one file fare better
with multiple jobs per node.
Nodes with only one I/O channel to disk may be better exploited
by utilizing more threads per process.
</para>
<html endspaces=" ">
&lt;a name=&quot;map_mlt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#map_mlt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2758"><code>-M</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2759"><code>--mlt_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2760"><code>--multimap</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2761"><code>--no_multimap</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2762"><code>--nomultimap</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-M (<code>--mlt_map</code>, <code>--multimap</code>, <code>--no_multimap</code>, <code>--nomultimap</code>)</itemformat></item>
</tableterm><tableitem><para><command>ncremap</command> assumes that every input file is on a unique grid
unless a source gridfile is specified (with <samp>-s <var>grd_src</var></samp>)
or multiple-mapfile generation is explicitly turned-off (with
<samp>-M</samp>). 
The <samp>-M</samp> switch is a toggle, it requires and accepts no argument. 
Toggling <samp>-M</samp> tells <command>ncremap</command> to generate at most one
mapfile regardless of the number of input files. 
If <samp>-M</samp> is not toggled (and neither 
<samp>-m <var>map_fl</var></samp> nor <samp>-s <var>grd_src</var></samp> is invoked)   
then <command>ncremap</command> will generate a new mapfile for each input file.
Generating new mapfiles for each input file is necessary for processing
batches of data on different grids (e.g., swath-like data), and slow,
tedious, and unnecessary when batch processing data on the same grids.
</para>
<html endspaces=" ">
&lt;a name=&quot;map_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#map_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2763"><code>-m <var>map_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2764"><var>map_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2765"><code>--map_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2766"><code>--map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2767"><code>--map_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2768"><code>--rgr_map</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2769"><code>--regrid_map</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-m <var>map_fl</var> (<code>--map_fl</code>, <code>--map</code>, <code>--map_file</code>, <code>--rgr_map</code>, <code>--regrid_map</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a mapfile (i.e., weight-file) to remap the source to
destination grid. 
If <var>map_fl</var> is specified in conjunction with any of the <samp>-d</samp>,
<samp>-G</samp>, <samp>-g</samp>, or <samp>-s</samp> switches, then <command>ncremap</command>
will name the internally generated mapfile <var>map_fl</var>.
Otherwise (i.e., if none of the source-grid switches are used),
<command>ncremap</command> assumes that <var>map_fl</var> is a pre-computed mapfile. 
In that case, the <var>map_fl</var> must be in <acronym><acronymword>SCRIP</acronymword></acronym> format,
although it may have been produced by any application (usually
<acronym><acronymword>ERWG</acronymword></acronym> or TempestRemap). 
If <var>map_fl</var> has only cell-center coordinates (and no edges),
then <acronym><acronymword>NCO</acronymword></acronym> will guess-at or interpolate the edges.
If <var>map_fl</var> has cell boundaries then <acronym><acronymword>NCO</acronymword></acronym> will use those.
A pre-computed <var>map_fl</var> is not modified, and may have read-only
permissions. 
The user will be prompted to confirm if a newly generated map-file  
named <var>map_fl</var> would overwrite an existing file.
<command>ncremap</command> adds provenance information to any newly generated
map-file whose name was specified with <samp>-m <var>map_fl</var></samp>.
This provenance includes a <code>history</code> attribute that contains
the command invoking <command>ncremap</command>, and the map-generating command
invoked by <command>ncremap</command>.
</para>
<html endspaces=" ">
&lt;a name=&quot;mpi_pfx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mpi_pfx --&gt;
&lt;a name=&quot;mpi_prefix&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mpi_prefix --&gt;
&lt;a name=&quot;srun_cmd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#srun_cmd --&gt;
&lt;a name=&quot;srun_command&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#srun_command --&gt;
&lt;a name=&quot;mpi_nbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mpi_nbr --&gt;
&lt;a name=&quot;mpi_number&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mpi_number --&gt;
&lt;a name=&quot;tsk_nbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tsk_nbr --&gt;
&lt;a name=&quot;task_number&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#task_number --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2770"><code>--mpi_pfx=<var>mpi_pfx</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2771"><var>mpi_pfx</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2772"><code>--mpi_pfx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2773"><code>--mpi_prefix</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2774"><code>--srun_cmd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2775"><code>--srun_command</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp"><code>--mpi_pfx=<var>mpi_pfx</var></code> (<code>--mpi_pfx</code>, <code>--mpi_prefix</code>, <code>--srun_cmd</code>, <code>--srun_command</code>)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="2776"><code>--mpi_nbr=<var>mpi_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2777"><var>mpi_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2778"><code>--mpi_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2779"><code>--mpi_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2780"><code>--tsk_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2781"><code>--task_nbr</code></indexterm></cindex>
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp"><code>--mpi_nbr=<var>mpi_nbr</var></code> (<code>--mpi_nbr</code>, <code>--mpi_number</code>, <code>--tsk_nbr</code>, <code>--task_number</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>--mpi_pfx=<var>mpi_pfx</var></samp> option specifies an appropriate job
scheduler prefix for <acronym><acronymword>MPI</acronymword></acronym>-enabled weight-generation
executables such as <acronym><acronymword>ESMF</acronymword></acronym>&textrsquo;s <command>ESMF_RegridWeightGen</command>
and <acronym><acronymword>MOAB</acronymword></acronym>&textrsquo;s <command>mbtempest</command>.
Other weight generators (<command>ncks</command>, <command>GenerateOfflineMap</command>) 
are unaffected by this option since they are not
<acronym><acronymword>MPI</acronymword></acronym>-enabled. 
<var>mpi_pfx</var> defaults to <code>mpirun -n $&lbrace;<var>mpi_nbr</var>&rbrace;</code> on all
machines except those whose <code>$HOSTNAME</code> matches an internal
database of <acronym><acronymword>DOE</acronymword></acronym>-operated supercomputers where 
<var>mpi_pfx</var> usually defaults to <code>srun -n $&lbrace;<var>mpi_nbr</var>&rbrace;</code>
When invoking <samp>--mpi_pfx</samp>, be sure to explicitly define the
number of <acronym><acronymword>MPI</acronymword></acronym> tasks-per-node, e.g.,
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --mpi_pfx='srun -n 16' ...
ncremap --mpi_pfx='srun --mpi=pmi2 -n 4' ...
</verbatim>
</example>
<para>The separate <samp>--mpi_nbr=<var>mpi_nbr</var></samp> option specifies the
number of tasks-per-node that <acronym><acronymword>MPI</acronymword></acronym>-enabled weight generators
will request.
It preserves the default job scheduler prefix (<command>srun</command> or
<command>mpirun</command>):
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --mpi_nbr=4 ... # 16 MPI tasks-per-node for ERWG/mbtempest 
ncremap --mpi_nbr=16 ... # 4 MPI tasks-per-node for ERWG/mbtempest 
</verbatim>
</example>
<para>Thus <samp>--mpi_nbr=<var>mpi_nbr</var></samp> can be used to create
host-independent <command>ncremap</command> commands to facilitate benchmarking
the scaling of weight-generators across hosts that work with the
default value of <var>mpi_pfx</var>.
The <samp>--mpi_pfx</samp> option will prevail and <samp>--mpi_nbr</samp> will be
ignored if both are used in the same <command>ncremap</command> invocation.
Note that <samp>mpi_pfx</samp> is only used internally by <command>ncremap</command>
to exploit the <acronym><acronymword>MPI</acronymword></acronym> capabilities of select weight-generators.
It is not used to control and does not affect the distribution of
multiple <command>ncremap</command> commands among a cluster of nodes.
</para>
<html endspaces=" ">
&lt;a name=&quot;msh_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msh_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2782"><code>--msh_fl=<var>msh_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2783"><var>msh_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2784"><code>--msh_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2785"><code>--msh</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2786"><code>--mesh</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2787"><code>--mesh_file</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp"><code>--msh_fl=<var>msh_fl</var></code> (<code>--msh_fl</code>, <code>--msh</code>, <code>--mesh</code>, <code>--mesh_file</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a meshfile (aka intersection mesh, aka overlap mesh) that
stores the grid formed by the intersection of the source and 
destination grids.
If not specified then <command>ncremap</command> will name any internally
generated meshfile with a temporary name and delete the file prior
to exiting.
<acronym><acronymword>NCO</acronymword></acronym> and TempestRemap support archiving the meshfile,
and <acronym><acronymword>ERWG</acronymword></acronym> does not.
<acronym><acronymword>NCO</acronymword></acronym> stores the meshfile in <acronym><acronymword>SCRIP</acronymword></acronym> format, while
TempestRemap stores it in Exodus format (with a <samp>.g</samp> suffix).
<command>ncremap</command> adds provenance information to any newly generated
mesh-file whose name was specified with <samp>--msh_fl=<var>msh_fl</var></samp>.
This provenance includes a <code>history</code> attribute that contains
the command invoking <command>ncremap</command>, and the map-generating command
invoked by <command>ncremap</command>.
</para>
<html endspaces=" ">
&lt;a name=&quot;mpt_mss&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mpt_mss --&gt;
&lt;a name=&quot;mask_apply&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mask_apply --&gt;
&lt;a name=&quot;msk_app&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msk_app --&gt;
&lt;a name=&quot;fill_empty&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fill_empty --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2788">missing value</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2789"><code>--add_fill_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2790"><code>--add_fll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2791"><code>_FillValue</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2792"><code>--mpt_mss</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2793"><code>--mask_apply</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2794"><code>--msk_app</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--mpt_mss (<code>--mpt_mss</code>, <code>--sgs_zro_mss</code>, <code>--empty_missing</code>)</itemformat></item>
</tableterm><tableitem><para>Introduced in <acronym><acronymword>NCO</acronymword></acronym> version 5.1.9 (released November, 2023),
this switch (which takes no argument) causes the regridder to set
empty <acronym><acronymword>SGS</acronymword></acronym> gridcells to the missing value.
Note that this switch works only in limited circumstances.
First, it only applies to fields for which a valid sub-gridscale
(<acronym><acronymword>SGS</acronymword></acronym>) distribution has been supplied.
Second, it only applies to fields which have no missing values.
The primary usage of this switch is for sea-ice model datasets.
These datasets tend to be archived with a (<acronym><acronymword>SGS</acronymword></acronym>) fraction
that is non-zero only when and where sea ice is present. 
The datasets also tend to be written with valid data throughout the
ocean domain, regardless of whether sea-ice is present.
Most sea-ice fields are usually zero in open-ocean areas (where
<math><var>sgs_frc</var> = 0.0</math>), and non-zero where sea-ice exists.
The <code>--mpt_mss</code> switch causes the regridder to set the open-ocean
regions to the missing value.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Set open-ocean regions to missing values (not 0.0) in sea-ice output
ncremap --mpt_mss -P mpasseaice -m map.nc in.nc out.nc
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;msk_apl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msk_apl --&gt;
&lt;a name=&quot;mask_apply&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mask_apply --&gt;
&lt;a name=&quot;msk_app&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msk_app --&gt;
&lt;a name=&quot;fill_empty&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fill_empty --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2795">missing value</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2796"><code>--add_fill_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2797"><code>--add_fll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2798"><code>_FillValue</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2799"><code>--msk_apl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2800"><code>--mask_apply</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2801"><code>--msk_app</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--msk_apl (<code>--msk_apl</code>, <code>--mask_apply</code>, <code>--msk_app</code>)</itemformat></item>
</tableterm><tableitem><para>Introduced in <acronym><acronymword>NCO</acronymword></acronym> version 5.0.0 (released June, 2021),
this switch (which takes no argument) causes the regridder to
apply <var>msk_out</var> (i.e., <code>mask_b</code>) to variables after
regridding.
Some weight generators (e.g., TempestRemap) ignore masks and thus
produce non-zero weights for masked destination cells, and/or from
masked source cells.
This flag causes regridded files produced with such map-files to
adhere to the destination mask rules (though source mask rules may
still be violated).
This feature is especially useful in placing missing values (aka,
<code>_FillValue</code>) in destination cells that should be empty, so that 
regridded files have <code>_FillValue</code> distributions identical with
output from other weight-generators such as <acronym><acronymword>ESMF</acronymword></acronym> and
<acronym><acronymword>NCO</acronymword></acronym>. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --msk_apl           -v FLNS -m map.nc in.nc out.nc
ncremap --msk_apl --add_fll -v FLNS -m map.nc in.nc out.nc # Equivalent
</verbatim>
</example>
<para>By itself, <code>--msk_apl</code> would only mask cells based on the
<code>mask_b</code> field in the map-file.
This is conceptually independent of the actual intersection mesh.
However, <code>--msk_apl</code> automatically triggers <code>--add_fll</code>,
which also masks fields based on the computed intersection mesh
(i.e., <code>--frac_b</code>).
This combinations ensures that masked fields regridded with
TempestRemap-generated map-files have <code>_FillValue</code>s consistent
with map-files generated by <acronym><acronymword>ESMF</acronymword></acronym> and <acronym><acronymword>NCO</acronymword></acronym>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;msk_dst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msk_dst --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2802"><code>--msk_dst=<var>msk_dst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2803"><var>msk_dst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2804"><code>--msk_dst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2805"><code>--dst_msk</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2806"><code>--mask_destination</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2807"><code>--mask_dst</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--msk_dst=<var>msk_dst</var> (<code>--msk_dst</code>, <code>--dst_msk</code>, <code>--mask_destination</code>, <code>--mask_dst</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a template variable to use for the integer mask of the
destination grid when inferring grid files and/or creating
map-files (i.e., generating weights). 
Any variable on the same horizontal grid as a data file can serve as a
mask template for that grid. 
The mask will be one (i.e., gridcells will participate in regridding) 
where <var>msk_dst</var> has valid, non-zero values in the data file from which
<acronym><acronymword>NCO</acronymword></acronym> infers the destination grid.   
The mask will be zero (i.e., gridcells will not participate in
regridding) where <var>msk_nm</var> has a missing value or is zero.  
A typical example of this option would be to use Sea-surface Temperature
(<acronym><acronymword>SST</acronymword></acronym>) as a template variable for an ocean mask because
<acronym><acronymword>SST</acronymword></acronym> is often defined only over ocean, and missing values
might denote locations to which regridded quantities should never be
placed. 
The special value <math><var>msk_dst</var> = <code>none</code></math> prevents the
regridder from inferring and treating any variable (even one named,
e.g., <code>mask</code>) in a source file as a mask variable.
This guarantees that all points in the inferred destination grid will be 
unmasked.  
<var>msk_dst</var>, <var>msk_out</var>, and <var>msk_src</var> are related yet distinct:
<var>msk_dst</var> is the mask template variable in the destination file (whose grid will be inferred),
<var>msk_out</var> is the name to give the destination mask (usually <code>mask_b</code> in the map-file) in regridded data files, and 
<var>msk_src</var> is the mask template variable in the source file (whose grid will be inferred).
<var>msk_src</var> and <var>msk_dst</var> only affect inferred grid files for
the source and destination grids, respectively, whereas <var>msk_out</var>
only affects regridded files.
</para>
<html endspaces=" ">
&lt;a name=&quot;msk_out&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msk_out --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2808"><code>--msk_out=<var>msk_out</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2809"><var>msk_out</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2810"><code>--msk_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2811"><code>--out_msk</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2812"><code>--mask_destination</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2813"><code>--mask_out</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--msk_out=<var>msk_out</var> (<code>--msk_out</code>, <code>--out_msk</code>, <code>--mask_destination</code>, <code>--mask_out</code>)</itemformat></item>
</tableterm><tableitem><para>Use of this option tells <command>ncremap</command> to include a variable named 
<var>msk_out</var> in any regridded file.
The variable <var>msk_out</var> will contain the integer-valued
regridding mask on the destination grid.
The mask will be one (i.e., fields may have valid values in this
gridcell) or zero (i.e., fields will have missing values in this
gridcell). 
By default, <command>ncremap</command> does not output the destination mask to
the regridded file.
This option changes that default behavior and causes <command>ncremap</command>
to ingest the default destination mask variable contained in the
<var>map-file</var>. 
<acronym><acronymword>ERWG</acronymword></acronym> generates <acronym><acronymword>SCRIP</acronymword></acronym>-format map-files that contain
the destination mask in the variable named <code>mask_b</code>.
<acronym><acronymword>SCRIP</acronymword></acronym> generates map-files that contain the destination mask in
the variable named <code>dst_grid_imask</code>. 
The <code>msk_out</code> option works with map-files that adhere to either of
these conventions. 
Tempest generates map-files that do not typically contain the
destination mask, and so the <code>msk_out</code> option has no effect on
files that Tempest regrids.
<var>msk_dst</var>, <var>msk_out</var>, and <var>msk_src</var> are related yet distinct:
<var>msk_dst</var> is the mask template variable in the destination file (whose grid will be inferred),
<var>msk_out</var> is the name to give the destination mask (usually <code>mask_b</code> in the map-file) in regridded data files, and 
<var>msk_src</var> is the mask template variable in the source file (whose grid will be inferred).
<var>msk_src</var> and <var>msk_dst</var> only affect inferred grid files for
the source and destination grids, respectively, whereas <var>msk_out</var>
only affects regridded files.
</para>
<html endspaces=" ">
&lt;a name=&quot;msk_src&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msk_src --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2814"><code>--msk_src=<var>msk_src</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2815"><var>msk_src</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2816"><code>--msk_src</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2817"><code>--src_msk</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2818"><code>--mask_source</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2819"><code>--mask_src</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--msk_src=<var>msk_src</var> (<code>--msk_src</code>, <code>--src_msk</code>, <code>--mask_source</code>, <code>--mask_src</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a template variable to use for the integer mask of the
source grid when inferring grid files and/or creating
map-files (i.e., generating weights). 
Any variable on the same horizontal grid as a data file can serve as a
mask template for that grid. 
The mask will be one (i.e., gridcells will participate in regridding) 
where <var>msk_src</var> has valid, non-zero values in the data file from which
<acronym><acronymword>NCO</acronymword></acronym> infers the source grid.   
The mask will be zero (i.e., gridcells will not participate in
regridding) where <var>msk_nm</var> has a missing value or is zero.  
A typical example of this option would be to use Sea-surface Temperature
(SST) as a template variable for an ocean mask because SST is often
defined only over ocean, and missing values might denote locations from
which regridded quantities should emanate.
The special value <math><var>msk_src</var> = <code>none</code></math> prevents the
regridder from inferring and treating any variable (even one named,
e.g., <code>mask</code>) in a source file as a mask variable.
This guarantees that all points in the inferred source grid will be 
unmasked.  
<var>msk_dst</var>, <var>msk_out</var>, and <var>msk_src</var> are related yet distinct:
<var>msk_dst</var> is the mask template variable in the destination file (whose grid will be inferred),
<var>msk_out</var> is the name to give the destination mask (usually <code>mask_b</code> in the map-file) in regridded data files, and 
<var>msk_src</var> is the mask template variable in the source file (whose grid will be inferred).
<var>msk_src</var> and <var>msk_dst</var> only affect inferred grid files for
the source and destination grids, respectively, whereas <var>msk_out</var>
only affects regridded files.
</para>
<html endspaces=" ">
&lt;a name=&quot;--mss_val&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#--mss_val --&gt;
&lt;a name=&quot;mss_val_ncremap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mss_val_ncremap --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2820"><code>--mss_val=<var>mss_val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2821"><var>mss_val</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2822"><code>--mss_val</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2823"><code>--fll_val</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2824"><code>--missing_value</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2825"><code>--fill_value</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--mss_val=<var>mss_val</var> (<code>--mss_val</code>, <code>--fll_val</code>, <code>--missing_value</code>, <code>--fill_value</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the numeric value that indicates missing data when processing
<acronym><acronymword>MPAS</acronymword></acronym> datasets, i.e., when <samp>-P mpas</samp> is invoked.
The default missing value is <code>-9.99999979021476795361e+33</code> which is
correct for the <acronym><acronymword>MPAS</acronymword></acronym> ocean and sea-ice models.
Currently (January, 2018) the <acronym><acronymword>MPAS</acronymword></acronym> land-ice model uses
<code>-1.0e36</code> for missing values.
Hence this option is usually invoked as <samp>--mss_val=-1.0e36</samp> to
facilitate processing of <acronym><acronymword>MPAS</acronymword></acronym> land-ice datasets.
</para>
<html endspaces=" ">
&lt;a name=&quot;nco_opt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nco_opt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2826"><code>-n <var>nco_opt</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2827"><var>nco_opt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2828"><code>--nco_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2829"><code>--nco_options</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2830"><code>--nco</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-n <var>nco_opt</var> (<code>--nco_opt</code>, <code>--nco_options</code>, <code>--nco</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a string of options to pass-through unaltered to
<command>ncks</command>. 
<var>nco_opt</var> defaults to <samp>-O --no_tmp_fl</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;nm_dst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nm_dst --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2831"><code>--nm_dst=<var>nm_dst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2832"><var>nm_dst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2833"><code>--nm_dst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2834"><code>--name_dst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2835"><code>--nm_sht_dst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2836"><code>--name_short_destination</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--nm_dst=<var>nm_dst</var> (<code>--nm_dst</code>, <code>--name_dst</code>, <code>--name_short_destination</code>, <code>--nm_sht_dst</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the short name for the destination grid to use in the full
name of map-files created in <acronym><acronymword>MWF</acronymword></acronym> mode. 
Map-file names include, by convention, shortened versions of both the
source and destination grids.
<command>ncremap</command> uses the <var>nm_dst</var> argument to encode the
destination grid name into the output map-file name of this format: 
<code>map_<var>nm_src</var>_to_<var>nm_dst</var>_<var>alg_typ</var>.<var>dt_sng</var>.nc</code>.
<acronym><acronymword>MWF</acronymword></acronym> mode requires this argument, there is no default.
</para>
<html endspaces=" ">
&lt;a name=&quot;nm_src&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nm_src --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2837"><code>--nm_src=<var>nm_src</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2838"><var>nm_src</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2839"><code>--nm_src</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2840"><code>--name_src</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2841"><code>--nm_sht_src</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2842"><code>--name_short_source</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--nm_src=<var>nm_src</var> (<code>--nm_src</code>, <code>--name_src</code>, <code>--name_short_source</code>, <code>--nm_sht_src</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the short name for the source grid to use in the full
name of map-files created in <acronym><acronymword>MWF</acronymword></acronym> mode. 
Map-file names include, by convention, shortened versions of both the
source and destination grids.
<command>ncremap</command> uses the <var>nm_dst</var> argument to encode the
source grid name into the output map-file name of this format: 
<code>map_<var>nm_src</var>_to_<var>nm_dst</var>_<var>alg_typ</var>.<var>dt_sng</var>.nc</code>.
<acronym><acronymword>MWF</acronymword></acronym> mode requires this argument, there is no default.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2843"><code>--no_cll_msr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2844"><code>--no_cll</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2845"><code>--no_cell_measures</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2846"><code>--no_area</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2847"><code>cell_measures</code> attribute</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--no_cll_msr (<code>--no_cll_msr</code>, <code>--no_cll</code>, <code>--no_cell_measures</code>, <code>--no_area</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) controls whether <command>ncclimo</command>
and <command>ncremap</command> add measures variables to the extraction list
along with the primary variable and other associated variables. 
See <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref> for a detailed description.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2848"><code>--no_frm_trm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2849"><code>--no_frm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2850"><code>--no_formula_terms</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2851"><code>formula_terms</code> attribute</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--no_frm_trm (<code>--no_frm_trm</code>, <code>--no_frm</code>, <code>--no_formula_terms</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) controls whether <command>ncclimo</command>
and <command>ncremap</command> add formula variables to the extraction list along
with the primary variable and other associated variables. 
See <ref label="CF-Conventions"><xrefnodename>CF Conventions</xrefnodename></ref> for a detailed description.
</para>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2852"><code>slat</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2853"><code>slon</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2854"><code>w_stag</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2855"><code>--no_stg_grd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2856"><code>--no_stg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2857"><code>--no_stagger</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2858"><code>--no_staggered_grid</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--no_stg_grd (<code>--no_stg_grd</code>, <code>--no_stg</code>, <code>--no_stagger</code>, <code>--no_staggered_grid</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) controls whether
regridded output will contain the staggered grid coordinates 
<code>slat</code>, <code>slon</code>, and <code>w_stag</code> (<pxref label="Regridding"><xrefnodename>Regridding</xrefnodename></pxref>). 
Originally, the staggered grid was output for all files regridded from 
a Cap (aka <acronym><acronymword>FV</acronymword></acronym>) grid, except when the regridding was performed
as part of splitting (reshaping) into timeseries.
As of (roughly, I forget) <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.9.4</w>, released in
July, 2020, outputging the staggered grid information is turned-off
for all workflows and must be proactively turned-on (with
<code>--stg_grd</code>).
Thus the <code>--no_stg_grd</code> switch is obsolete and is intened
only to preserve backward-compatibility of previous workflows.
</para>
<html endspaces=" ">
&lt;a name=&quot;out_drc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#out_drc --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2859"><code>-O <var>out_drc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2860"><var>out_drc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2861"><code>--out_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2862"><code>--drc_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2863"><code>--dir_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2864"><code>--out_dir</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2865"><code>--output</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-O <var>out_drc</var> (<code>--out_drc</code>, <code>--drc_out</code>, <code>--dir_out</code>, <code>--out_dir</code>, <code>--output</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the output directory, i.e., the directory name to contain 
the output file(s).
If <var>out_fl</var> is also specified, then the output filepath is
constructed by appending a slash and the filename to the directory:
<samp><var>out_drc</var>/<var>out_fl</var></samp>.
Specifying <var>out_drc</var> without <var>out_fl</var> causes <command>ncremap</command>
to name each output file the same as the corresponding input file.
There is no namespace conflict because the input and output files will
be in separate directories.
</para>
<html endspaces=" ">
&lt;a name=&quot;out_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#out_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2866"><code>-o <var>out_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2867"><var>&textndash;out_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2868"><code>--out_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2869"><code>--output_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2870"><code>--out_file</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-o <var>out_fl</var> (<code>--out_fl</code>, <code>--output_file</code>, <code>--out_file</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the output filename, i.e., the name of the file to contain
the data from <var>in_fl</var> remapped to the destination grid.
If <var>out_fl</var> already exists it will be overwritten.
Specifying <var>out_fl</var> when there are multiple input files (i.e., from
using <samp>-I <var>in_drc</var></samp> or standard input) generates an error 
(output files will be named the same as input files).
Two positional arguments are interpreted as a single <var>input-file</var>
and its corresponding <var>output-file</var>.
</para>
<html endspaces=" ">
&lt;a name=&quot;mpas&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mpas --&gt;
&lt;a name=&quot;prc_typ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prc_typ --&gt;
&lt;a name=&quot;rrg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rrg --&gt;
&lt;a name=&quot;eamxx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#eamxx --&gt;
&lt;a name=&quot;scream&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#scream --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2871"><code>-P <var>prc_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2872"><var>prc_typ</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2873"><code>--prc_typ</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2874"><code>--prm_typ</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2875"><code>--procedure</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-P <var>prc_typ</var> (<code>--prc_typ</code>, <code>--prm_typ</code>, <code>--procedure</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the permutation mode desired.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.5.5 (February, 2016), one can tell
<command>ncremap</command> to invoke special processing procedures for different
types of input data. 
For instance, to automatically permute the dimensions in the data file
prior to regridding for a limited (though growing) number of data-file
types that encounter the <command>ncremap</command> limitation concerning
dimension ordering. 
Valid procedure types include <samp>airs</samp> for <acronym><acronymword>NASA AIRS</acronymword></acronym> satellite data, 
<samp>eam</samp> or <samp>cam</samp> for <acronym><acronymword>DOE EAM</acronymword></acronym> and <acronym><acronymword>NCAR CAM</acronymword></acronym> model data,
<samp>eamxx</samp> for <acronym><acronymword>DOE EAMxx</acronymword></acronym> (aka, <acronym><acronymword>SCREAM</acronymword></acronym>) model data,
<samp>elm</samp> or <samp>clm</samp> for <acronym><acronymword>DOE ELM</acronymword></acronym> and <acronym><acronymword>NCAR CLM</acronymword></acronym> model data,
<samp>cice</samp> for <acronym><acronymword>CICE</acronymword></acronym> ice model data (must be on 2D grids),
<samp>cism</samp> for <acronym><acronymword>NCAR CISM</acronymword></acronym> land ice model data,
<samp>mpasa</samp>, or <samp>mpasatmosphere</samp> for <acronym><acronymword>MPAS</acronymword></acronym> atmosphere model data,
<samp>mpascice</samp>, <samp>mpasseaice</samp>, or <samp>mpassi</samp> for <acronym><acronymword>MPAS</acronymword></acronym> sea-ice model data,
<samp>mpaso</samp> or <samp>mpasocean</samp> for <acronym><acronymword>MPAS</acronymword></acronym> ocean model data,
<samp>mod04</samp> for <w>Level 2</w> <acronym><acronymword>MODIS</acronymword></acronym> <acronym><acronymword>MOD04</acronymword></acronym> product,
<samp>mwf</samp> for making all weight-files for a pair of grids, 
<samp>sgs</samp> for datasets containing sub-gridscale (<acronym><acronymword>SGS</acronymword></acronym>) data
(such as <acronym><acronymword>CLM/CTSM/ELM</acronymword></acronym> land model data and
<acronym><acronymword>CICE/MPAS-Seaice</acronymword></acronym> sea-ice model data), 
and <samp>nil</samp> (for none).
The default <var>prc_typ</var> is <samp>nil</samp>, which means <command>ncremap</command> 
does not perform any special procedures prior to regridding.
The <acronym><acronymword>AIRS</acronymword></acronym> procedure calls <command>ncpdq</command> to permute dimensions
from their order in the input file to this order: 
<code>StdPressureLev,GeoTrack,GeoXTrack</code>.
The <acronym><acronymword>ELM</acronymword></acronym>, <acronym><acronymword>CLM</acronymword></acronym>, and <acronym><acronymword>CICE</acronymword></acronym> procedures set 
idiosyncratic model values and then invoke the Sub-gridscale
(<acronym><acronymword>SGS</acronymword></acronym>) procedure (see below). 
The <acronym><acronymword>MOD04</acronymword></acronym> procedure unpacks input data.
The <acronym><acronymword>EAMxx</acronymword></acronym> procedures permute input data dimensions into this
order prior to horizontal regridding:
<code>ilev,lev,dim2,ncol</code>, and cause the vertical interpolation
routine to look for surface pressure under the name <code>ps</code> instead
of <code>PS</code>.
The <acronym><acronymword>MPAS</acronymword></acronym> procedures permute input data dimensions into this
order: 
<code>Time,depth,nVertInterfaces,nVertLevels,nVertLevelsP1,nZBGCTracers,nBioLayersP1,nAlgaeIceLayers,nDisIronIceLayers,nIceLayers,maxEdges,MaxEdges2,nCategories,R3,ONE,TWO,FOUR,nEdges,nCells</code>,
and invokes renormalization.
An <acronym><acronymword>MPAS</acronymword></acronym> dataset that contains any other dimensions will fail
to regrid until/unless those dimensions are added to the
<command>ncremap</command> dimension permutation option.
&linebreak;
&linebreak;
<b><acronym><acronymword>MWF</acronymword></acronym>-mode</b>:&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="2876">Make-Weight-Files (<acronym><acronymword>MWF</acronymword></acronym>)</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2877"><acronym><acronymword>MWF</acronymword></acronym>-mode</indexterm></cindex>
As mentioned above in other options, <command>ncremap</command> includes an
<acronym><acronymword>MWF</acronymword></acronym>-mode (for &textldquo;Make All Weight Files&textrdquo;) that generates and
names, with one command and in a self-consistent manner, all
combinations of (for instance, <acronym><acronymword>E3SM</acronymword></acronym> or <acronym><acronymword>CESM</acronymword></acronym>)
global atmosphere&lt;-&gt;ocean maps with both <acronym><acronymword>ERWG</acronymword></acronym> and Tempest.
<acronym><acronymword>MWF</acronymword></acronym>-mode automates the laborious and error-prone process of
generating numerous map-files with various switches.
Its chief use occurs when developing and testing new global grid-pairs
for the <acronym><acronymword>E3SM</acronymword></acronym> atmosphere and ocean components.
Invoke <acronym><acronymword>MWF</acronymword></acronym>-mode with a number of specialized options to
control the naming of the output map-files: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -P mwf -s grd_ocn -g grd_atm --nm_src=ocn_nm \
        --nm_dst=atm_nm --dt_sng=date
</verbatim>
</example>
<para>where <var>grd_ocn</var> is the &quot;global&quot; ocean grid, <var>grd_atm</var>, is the
global atmosphere grid, <var>nm_src</var> sets the shortened name for the
source (ocean) grid as it will appear in the output map-files,
<var>nm_dst</var> sets, similarly, the shortend named for the destination
(atmosphere) grid, and <var>dt_sng</var> sets the date-stamp in the output
map-file name
<file>map_$&lbrace;<var>nm_src</var>&rbrace;_to_$&lbrace;<var>nm_dst</var>&rbrace;_$&lbrace;<var>alg_typ</var>&rbrace;.$&lbrace;<var>dt_sng</var>&rbrace;.nc</file>.
Setting <var>nm_src</var>, <var>nm_dst</var>, and <var>dt_sng</var>, is optional
though highly recommended.
For example,  
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -P mwf -s ocean.RRS.30-10km_scrip_150722.nc \
  -g t62_SCRIP.20150901.nc --nm_src=oRRS30to10 --nm_dst=T62 \
  --dt_sng=20180901 
</verbatim>
</example>
<para>produces the 10 <acronym><acronymword>ERWG</acronymword></acronym> map-files:
</para><enumerate first="1" endspaces=" ">
<listitem> <para><file>map_oRRS30to10_to_T62_aave.20180901.nc</file>
</para></listitem><listitem> <para><file>map_oRRS30to10_to_T62_blin.20180901.nc</file>
</para></listitem><listitem> <para><file>map_oRRS30to10_to_T62_ndtos.20180901.nc</file>
</para></listitem><listitem> <para><file>map_oRRS30to10_to_T62_nstod.20180901.nc</file>
</para></listitem><listitem> <para><file>map_oRRS30to10_to_T62_patc.20180901.nc</file>
</para></listitem><listitem> <para><file>map_T62_to_oRRS30to10_aave.20180901.nc</file>
</para></listitem><listitem> <para><file>map_T62_to_oRRS30to10_blin.20180901.nc</file>
</para></listitem><listitem> <para><file>map_T62_to_oRRS30to10_ndtos.20180901.nc</file>
</para></listitem><listitem> <para><file>map_T62_to_oRRS30to10_nstod.20180901.nc</file>
</para></listitem><listitem> <para><file>map_T62_to_oRRS30to10_patc.20180901.nc</file>
</para></listitem></enumerate>
<para>The ordering of source and destination grids is immaterial for
<acronym><acronymword>ERWG</acronymword></acronym> maps since <acronym><acronymword>MWF</acronymword></acronym>-mode produces all map
combinations.
However, as described above in the TempestRemap section, the Tempest
overlap-mesh generator must be called with the smaller grid preceding
the larger grid.
For this reason, always invoke <acronym><acronymword>MWF</acronymword></acronym>-mode with the smaller
grid (i.e., the ocean) as the source, otherwise some Tempest map-file
will fail to generate.
The six optimized <acronym><acronymword>SE</acronymword></acronym>&lt;-&gt;<acronym><acronymword>FV</acronymword></acronym> Tempest maps described
above in the TempestRemap section will be generated when the
destination grid has a <samp>.g</samp> suffix which <command>ncremap</command>
interprets as indicating an Exodus-format <acronym><acronymword>SE</acronymword></acronym> grid (NB: this
assumption is an implementation convenience that can be modified if
necessary).
For example,  
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -P mwf -s ocean.RRS.30-10km_scrip_150722.nc -g ne30.g \
        --nm_src=oRRS30to10 --nm_dst=ne30np4 --dt_sng=20180901
</verbatim>
</example>
<para>produces the <w>6 TempestRemap</w> map-files:
</para><enumerate first="1" endspaces=" ">
<listitem> <para><file>map_oRRS30to10_to_ne30np4_monotr.20180901.nc</file>
</para></listitem><listitem> <para><file>map_oRRS30to10_to_ne30np4_highorder.20180901.nc</file>
</para></listitem><listitem> <para><file>map_oRRS30to10_to_ne30np4_mono.20180901.nc</file>
</para></listitem><listitem> <para><file>map_ne30np4_to_oRRS30to10_mono.20180901.nc</file>
</para></listitem><listitem> <para><file>map_ne30np4_to_oRRS30to10_highorder.20180901.nc</file>
</para></listitem><listitem> <para><file>map_ne30np4_to_oRRS30to10_intbilin.20180901.nc</file>
</para></listitem></enumerate>
<para><acronym><acronymword>MWF</acronymword></acronym>-mode takes significant time to complete (~20 minutes on
my MacBookPro) for the above grids.
To accelerate this, consider installing the <acronym><acronymword>MPI</acronymword></acronym>-enabled
instead of the serial version of <acronym><acronymword>ERWG</acronymword></acronym>.
Then use the <samp>--wgt_cmd</samp> option to tell <command>ncremap</command> the
<acronym><acronymword>MPI</acronymword></acronym> configuration to invoke <acronym><acronymword>ERWG</acronymword></acronym> with, for
example:  
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap -P mwf --wgt_cmd='mpirun -np 12 ESMF_RegridWeightGen' \
  -s ocean.RRS.30-10km_scrip_150722.nc -g t62_SCRIP.20150901.nc \
  --nm_src=oRRS30to10 --nm_dst=T62 --dt_sng=20180901
</verbatim>
</example>
<para>Background and distributed node parallelism (as described above in the
the Parallelism section) of <acronym><acronymword>MWF</acronymword></acronym>-mode are possible though not
yet implemented.
Please let us know if this feature is desired. 
&linebreak;
&linebreak;
<b><acronym><acronymword>RRG</acronymword></acronym>-mode</b>:&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="2878">Regridding ReGional Data (<acronym><acronymword>RRG</acronymword></acronym>)</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="2879"><acronym><acronymword>RRG</acronymword></acronym>-mode</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2880"><code>rrg_bb_wesn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2881"><code>rrg_dat_glb</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2882"><code>rrg_grd_glb</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2883"><code>rrg_grd_rgn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2884"><code>rrg_rnm_sng</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2885"><var>bb_wesn</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2886"><var>dat_glb</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2887"><var>grd_glb</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2888"><var>grd_rgn</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2889"><var>rnm_sng</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2890"><code>--rrg_bb_wesn=<var>bb_wesn</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2891"><code>--rrg_dat_glb=<var>dat_glb</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2892"><code>--rrg_grd_glb=<var>grd_glb</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2893"><code>--rrg_grd_rgn=<var>grd_rgn</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2894"><code>--rrg_rnm_sng=<var>rnm_sng</var></code></indexterm></cindex>
<acronym><acronymword>EAM</acronymword></acronym> and <acronym><acronymword>CAM-SE</acronymword></acronym> will produce regional output if
requested to with the <code>finclNlonlat</code> namelist parameter.
Output for a single region can be higher temporal resolution than the
host global simulation.
This facilitates detailed yet economical regional process studies.
Regional output files are in a special format that we call
<acronym><acronymword>RRG</acronymword></acronym> (for &textldquo;regional regridding&textrdquo;).
An <acronym><acronymword>RRG</acronymword></acronym> file may contain any number of rectangular regions.
However, <command>ncremap</command> can process only one region per invocation
(change the argument to the <samp>--rnm_sng</samp> option, described below,
in each invocation).
The coordinates and variables for one region do not interfere with
other (possibly overlapping) regions because all variables and
dimensions are named with a per-region suffix string, e.g.,
<code>lat_128e_to_134e_9s_to_16s</code>.
<command>ncremap</command> can easily regrid <acronym><acronymword>RRG</acronymword></acronym> output from an
atmospheric <acronym><acronymword>FV</acronymword></acronym>-dycore because <command>ncremap</command> can infer
(as discussed above) the regional grid from any rectangular
<acronym><acronymword>FV</acronymword></acronym> data file.
Regridding regional <acronym><acronymword>SE</acronymword></acronym> data, however, is more complex
because <acronym><acronymword>SE</acronymword></acronym> gridcells are essentially weights without
vertices and <acronym><acronymword>SE</acronymword></acronym> weight-generators are not yet flexible
enough to output regional weights.
To summarize, regridding <acronym><acronymword>RRG</acronymword></acronym> data leads to three
<acronym><acronymword>SE</acronymword></acronym>-specific difficulties (#1&textndash;3 below) and two difficulties 
(#4&textndash;5) shared with <acronym><acronymword>FV</acronymword></acronym> <acronym><acronymword>RRG</acronymword></acronym> files: 
</para>
<enumerate first="1" endspaces=" ">
<listitem> <para><acronym><acronymword>RRG</acronymword></acronym> files contain only regional gridcell center
locations, not weights 
</para></listitem><listitem> <para>Global <acronym><acronymword>SE</acronymword></acronym> grids have well-defined weights not vertices
for each gridpoint 
</para></listitem><listitem> <para>Grid generation software (<acronym><acronymword>ESMF</acronymword></acronym> and TempestRemap) only create
global not regional <acronym><acronymword>SE</acronymword></acronym> grid files 
</para></listitem><listitem> <para>Non-standard variable names and dimension names
</para></listitem><listitem> <para>Regional files can contain multiple regions
</para></listitem></enumerate>

<para><command>ncremap</command>&textrsquo;s <acronym><acronymword>RRG</acronymword></acronym> mode resolves these issues to allow
trouble-free regridding of <acronym><acronymword>SE</acronymword></acronym> <acronym><acronymword>RRG</acronymword></acronym> files. The user
must provide two additional input arguments,
<samp>--dat_glb=<var>dat_glb</var></samp> (or synonynms <samp>--rrg_dat_glb</samp>,
<samp>--data_global</samp>, or <samp>--global_data</samp>) and
<samp>--grd_glb=<var>grd_glb</var></samp> (or synonyms <samp>--rrg_grd_glb</samp>,
<samp>--grid_global</samp>, or <samp>global_grid</samp>) that point to a global
<acronym><acronymword>SE</acronymword></acronym> dataset and grid, respectively, of the same resolution as
the model that generated the <acronym><acronymword>RRG</acronymword></acronym> datasets.
Hence a typical <acronym><acronymword>RRG</acronymword></acronym> regridding invocation is: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --dat_glb=dat_glb.nc --grd_glb=grd_glb.nc -g grd_rgn.nc \
        dat_rgn.nc dat_rgr.nc
</verbatim>
</example>
<para>Here <file>grd_rgn.nc</file> is a regional destination grid-file,
<file>dat_rgn.nc</file> is the <acronym><acronymword>RRG</acronymword></acronym> file to regrid, and
<file>dat_rgr.nc</file> is the regridded output.
Typically <file>grd_rgn.nc</file> is a uniform rectangular grid covering the
same region as the <acronym><acronymword>RRG</acronymword></acronym> file.
Generate this as described in the last example in the section that
describes Manual Grid-file Generation with the <samp>-G</samp> option.
<file>grd_glb.nc</file> is the standard dual-grid grid-file for the
<acronym><acronymword>SE</acronymword></acronym> resolution, e.g.,
<file>ne30np4_pentagons.091226.nc</file>.
<command>ncremap</command> regrids the
global data file <file>dat_glb.nc</file> to the global dual-grid in order to 
produce a intermediate global file annotated with gridcell
vertices.
Then it hyperslabs the lat/lon coordinates (and vertices) from the
regional domain to use with regridding the <acronym><acronymword>RRG</acronymword></acronym> file.
A <file>grd_glb.nc</file> file with only one 2D field suffices (and is
fastest) for producing the information needed by the <acronym><acronymword>RRG</acronymword></acronym> 
procedure.
One can prepare an optimal <file>dat_glb.nc</file> file by subsetting any 2D
variable from any full global <acronym><acronymword>SE</acronymword></acronym> output dataset with, 
e.g., <samp>ncks -v FSNT in.nc dat_glb.nc</samp>. 
</para>
<para><command>ncremap</command> <acronym><acronymword>RRG</acronymword></acronym> mode supports two additional options
to override internal parameters.
First, the per-region suffix string
may be set with <samp>--rnm_sng=rnm_sng</samp> (or synonyms
<samp>--rrg_rnm_sng</samp> or <samp>--rename_string</samp>).
<acronym><acronymword>RRG</acronymword></acronym> mode will, by default, regrid the first region it finds
in an <acronym><acronymword>RRG</acronymword></acronym> file.
Explicitly set the desired region with <var>rnm_sng</var> for files with
multiple regions, e.g., <samp>--rnm_sng=_128e_to_134e_9s_to_16s</samp>.
Second, the regional bounding-box may be explicitly set with
<samp>--bb_wesn=lon_wst,lon_est,lat_sth,lat_nrt</samp>.
The normal parsing of the bounding-box string from the suffix string
may fail in (as yet undiscovered) corner cases, and the
<samp>--bb_wesn</samp> option provides a workaround should that occur.
The bounding-box string must include the entire <acronym><acronymword>RRG</acronymword></acronym> region
(not a subset thereof), specified in WESN order.
The two override options may be used independently or together, as in:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncremap --rnm_sng='_128e_to_134e_9s_to_16s' --bb_wesn='128,134,-16,-9' \
        --dat_glb=dat_glb.nc --grd_glb=grd_glb.nc -g grd_rgn.nc \
        dat_rgn.nc dat_rgr.nc
</verbatim>
</example>

<para><acronym><acronymword>RRG</acronymword></acronym>-mode supports most normal <command>ncremap</command> options,
including input and output methods and regridding algorithms. 
However, <acronym><acronymword>RRG</acronymword></acronym>-mode is not widely used and, as of 20240529,
has not been parallelized like the rest of <command>ncremap</command>. 
&linebreak;
<html endspaces=" ">
&lt;a name=&quot;alm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#alm --&gt;
&lt;a name=&quot;cice&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cice --&gt;
&lt;a name=&quot;clm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#clm --&gt;
&lt;a name=&quot;ctsm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ctsm --&gt;
&lt;a name=&quot;elm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#elm --&gt;
&lt;a name=&quot;mpasseaice&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mpasseaice --&gt;
&lt;a name=&quot;sgs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sgs --&gt;
&lt;a name=&quot;sgs_frc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sgs_frc --&gt;
&lt;a name=&quot;sgs_msk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sgs_msk --&gt;
&lt;a name=&quot;sub-grid&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sub-grid --&gt;
&lt;a name=&quot;sub-gridscale&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sub-gridscale --&gt;
&lt;a name=&quot;subgrid&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#subgrid --&gt;
</html>
<b><acronym><acronymword>SGS</acronymword></acronym>-mode</b>:&linebreak;
<cindex index="cp" spaces=" "><indexterm index="cp" number="2895">Sub-gridscale (<acronym><acronymword>SGS</acronymword></acronym>) data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2896"><acronym><acronymword>SGS</acronymword></acronym>-mode</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2897"><var>sgs_frc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2898"><var>sgs_msk</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2899"><var>sgs_nrm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2900"><code>--sgs_frc=<var>sgs_frc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2901"><code>--sgs_msk=<var>sgs_msk</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2902"><code>--sgs_nrm=<var>sgs_nrm</var></code></indexterm></cindex>
<command>ncremap</command> has a sub-gridscale (<acronym><acronymword>SGS</acronymword></acronym>) mode that
performs the special pre-processing and weighting necessary to
to conserve fields that represent fractional spatial portions of a
gridcell, and/or fractional temporal periods of the analysis.
Spatial fields output by most geophysical models are intensive, 
and so by default the regridder attempts to conserve the integral of the
area times the field value such that the integral is equal on source and
destination grids. 
However some models (like <acronym><acronymword>ELM</acronymword></acronym>, <acronym><acronymword>CLM</acronymword></acronym>,
<acronym><acronymword>CICE</acronymword></acronym>, and <acronym><acronymword>MPAS-Seaice</acronymword></acronym>) output gridcell values
intended to apply to only a fraction <var>sgs_frc</var> (for
&textldquo;sub-gridscale fraction&textrdquo;) of the gridcell.  
The sub-gridscale (<acronym><acronymword>SGS</acronymword></acronym>) fraction usually changes spatially
with the distribution of land and ocean, and spatiotemporally with
the distribution of sea ice and possibly vegetation.
For concreteness consider a sub-grid field that represents the land
fraction.
Land fraction is less than one in gridcells that resolve coastlines or 
islands.  
<acronym><acronymword>ELM</acronymword></acronym> and <acronym><acronymword>CLM</acronymword></acronym> happily output temperature values
valid only for a small (i.e., <math><var>sgs_frc</var> &lt;&lt; 1</math>) island within
the larger gridcell.
Model architecture dictates this behavior and savvy researchers expect
it.
The goal of the <acronym><acronymword>NCO</acronymword></acronym> weight-application algorithm is to treat
<acronym><acronymword>SGS</acronymword></acronym> fields as seamlessly as possible so that those less
familiar with sub-gridscale models can easily regrid them correctly.
</para>
<para>Fortunately, models like <acronym><acronymword>ELM</acronymword></acronym> and <acronym><acronymword>CLM</acronymword></acronym> that run on
the same horizontal grid as the overlying atmosphere can use the same
mapping-file as the atmosphere, so long as the <acronym><acronymword>SGS</acronymword></acronym>
weight-application procedure is invoked.
Not invoking an <acronym><acronymword>SGS</acronymword></acronym>-aware weight application algorithm is
equivalent to assuming <math><var>sgs_frc</var> = 1</math> everywhere.
Regridding sub-grid values correctly versus incorrectly (e.g., with
and without <acronym><acronymword>SGS</acronymword></acronym>-mode) alters global-mean answers for
land-based quantities by <w>about 1%</w> for horizontal grid resolutions
of about one degree. 
The resulting biases are in intricately shaped regions (coasts, lakes,
sea-ice floes) and so are easy to overlook.
</para>
<para>To invoke <acronym><acronymword>SGS</acronymword></acronym> mode and correctly regrid sub-gridscale data, 
specify the names of the fractional area <var>sgs_frc</var> and, if
applicable, the mask variable <var>sgs_msk</var> (strictly, this is only
necessary if these names differ from their 
respective defaults <code>landfrac</code> and <code>landmask</code>).  
Trouble will ensue if <var>sgs_frc</var> is a percentage or an absolute
area rather than a fractional area (between zero and one).
<command>ncremap</command> must know the normalization factor <var>sgs_nrm</var> by
which <var>sgs_frc</var> must be <emph>divided</emph> (not multiplied) to obtain
a true, normalized fraction.
Datasets (such as those from <acronym><acronymword>CICE</acronymword></acronym>) that store <var>sgs_frc</var> 
in percent should specify the option
<samp>--sgs_nrm=100</samp> to instruct <command>ncremap</command> to normalize the
sub-grid area appropriately before regridding.
<command>ncremap</command> will re-derive <var>sgs_msk</var> based on the regridded 
values of <var>sgs_frc</var>: <math><var>sgs_msk</var> = 1</math> is assigned to
destination gridcells with <math><var>sgs_frc</var> &gt; 0.0</math>, and all others
<math><var>sgs_msk</var> = 0</math>.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.6.8 (released June, 2017), invoking any
of the options <samp>--sgs_frc</samp>, <samp>--sgs_msk</samp>, or <samp>--sgs_nrm</samp>,
automatically triggers <acronym><acronymword>SGS</acronymword></acronym>-mode, so that also invoking 
<samp>-P sgs</samp> is redundant though legal.
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.0 (released December, 2019), the values 
of the <var>sgs_frc</var> and <var>sgs_msk</var> variables should be explicitly
specified.
In previous versions they defaulted to <code>landfrac</code> and
<code>landmask</code>, respectively, when <samp>-P sgs</samp> was selected.
This behavior still exists but will likely be deprecated in a future
version. 
</para>
<para>The <code>area</code> and <var>sgs_frc</var> fields in the regridded file will be
in units of sterradians and fraction, respectively.
However, <command>ncremap</command> offers custom options to reproduce the
idiosyncratic data and metadata format of two particular models,
<acronym><acronymword>ELM</acronymword></acronym> and <acronym><acronymword>CICE</acronymword></acronym>.
When invoked with <samp>-P elm</samp> (or <samp>-P clm</samp>), a final step
converts the output <code>area</code> from sterradians to square kilometers. 
When invoked with <samp>-P cice</samp>, the final step converts the output
<code>area</code> from sterradians to square meters, and the output
<code>sgs_frc</code> from a fraction to a percent.
</para><example endspaces=" ">
<pre xml:space="preserve"># ELM/CLM: output &quot;area&quot; in [sr]
ncremap --sgs_frc=landfrac --sgs_msk=landmask in.nc out.nc
ncremap -P sgs in.nc out.nc
# ELM/CLM pedantic format: output &quot;area&quot; in [km2]
ncremap -P elm in.nc out.nc # Same as -P clm, alm, ctsm

# CICE: output &quot;area&quot; in [sr]
ncremap --sgs_frc=aice --sgs_msk=tmask --sgs_nrm=100 in.nc out.nc
# CICE pedantic format: output &quot;area&quot; in [m2], &quot;aice&quot; in [%]
ncremap -P cice in.nc out.nc

# MPAS-Seaice: both commands are equivalent
ncremap -P mpasseaice in.nc out.nc
ncremap --sgs_frc=timeMonthly_avg_iceAreaCell in.nc out.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;sgs_frc_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#sgs_frc_fl --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2903"><var>sgs_frc_fl</var></indexterm></cindex>
<para>It is sometimes convenient to store the <var>sgs_frc</var> field in
an external file from the field(s) to be regridded.
For example, <acronym><acronymword>CMIP</acronymword></acronym>-style timeseries are often written
with only one variable per file.
<acronym><acronymword>NCO</acronymword></acronym> supports this organization by accepting <var>sgs_frc</var>
arguments in the form of a filename followed by a slash and then a
variable name: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap --sgs_frc=sgs_landfrac_ne30.nc/landfrac -m map.nc in.nc out.nc
</pre></example>
<para>This feature is most useful for datasets whose <var>sgs_frc</var> field is
time-invariant, as is usually the case for land models.
This is because a single <var>sgs_frc</var> location (e.g.,
<file>r05.nc/landfrac</file>) can be used for all files of the same
resolution.
Time-varying <var>sgs_frc</var> fields (e.g., for sea-ice models) change
with the same frequency as the simulation output.
Thus fields associated with time-varying <var>sgs_frc</var> must be
regridded &textldquo;timestep-by-timestep&textrdquo;, i.e., with a separate
<command>ncremap</command> invocation for each snapshot of <var>sgs_frc</var>.
Of course, <command>ncrcat</command> can later concatenate these separate
regriddings can be recombined back into into a single, regridded
timeseries. 
</para>
<para>Files regridded using explicitly specified <acronym><acronymword>SGS</acronymword></acronym> options will
differ slightly from those regridded using the <samp>-P elm</samp> or 
<samp>-P cice</samp> options. 
The former will have an <code>area</code> field in sterradians, the generic
units used internally by the regridder. 
The latter produces model-specific <code>area</code> fields in square 
kilometers (for <acronym><acronymword>ELM</acronymword></acronym>) or square meters (for <acronym><acronymword>CICE</acronymword></acronym>),
as expected in the raw output from these two models.
To convert from angular to areal values, <acronym><acronymword>NCO</acronymword></acronym> assumes a
spherical Earth with radius <w>6,371,220 m</w> or <w>6,371,229 m</w>,
for <acronym><acronymword>ELM</acronymword></acronym> and <acronym><acronymword>CICE</acronymword></acronym>, respectively.
The ouput <var>sgs_frc</var> field is expressed as a decimal fraction in all
cases except for <samp>-P cice</samp> which stores the fraction in percent.
Thus the generic <acronym><acronymword>SGS</acronymword></acronym> and model-specific convenience options
produce equivalent results, and the latter is intended to be
indistinguishable (in terms of metadata and units) to raw model
output.  
This makes it more interoperable with many existing analysis scripts. 
</para>
<html endspaces=" ">
&lt;a name=&quot;par_typ&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#par_typ --&gt;
&lt;a name=&quot;par_typ_ncremap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#par_typ_ncremap --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2904"><code>-p <var>par_typ</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2905"><var>par_typ</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2906"><code>--par_typ</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2907"><code>--par_md</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2908"><code>--parallel_type</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2909"><code>--parallel_mode</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2910"><code>--parallel</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-p <var>par_typ</var> (<code>--par_typ</code>, <code>--par_md</code>, <code>--parallel_type</code>, <code>--parallel_mode</code>, <code>--parallel</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the desired file-level parallelism mode, either Background,
<acronym><acronymword>MPI</acronymword></acronym>, or Serial. 
File-level parallelism accelerates throughput when regridding multiple
files in one <command>ncremap</command> invocation, and has no effect when only
one file is to be regridded.
Note that the <command>ncclimo</command> and <command>ncremap</command> semantics for
selecting file-level parallelism are identical, though their defaults
differ (Background mode for <command>ncclimo</command> and Serial mode for
<command>ncremap</command>). 
Select the desired mode with the argument to
<samp>--par_typ=<var>par_typ</var></samp>.
Explicitly select Background mode with <var>par_typ</var> values of
<code>bck</code>, <code>background</code>, or <code>Background</code>.
The values <code>mpi</code> or <code>MPI</code> select <acronym><acronymword>MPI</acronymword></acronym> mode, and
the <code>srl</code>, <code>serial</code>, <code>Serial</code>, <code>nil</code>, or
<code>none</code> will select Serial mode (which disables file-level
parallelism, though still allows intra-file OpenMP parallelism). 
</para>
<para>The default file-level parallelism for <command>ncremap</command> is Serial
mode (i.e., no file-level parallelism), in which <command>ncremap</command>
processes one input file at a time.
Background and <acronym><acronymword>MPI</acronymword></acronym> modes implement true file-level
parallelism. 
Typically both these parallel modes scale well with sufficent
memory unless and until I/O contention becomes the bottleneck. 
In Background mode <command>ncremap</command> issues all commands to regrid
the input file list as <acronym><acronymword>UNIX</acronymword></acronym> background processes on the
local node. 
Nodes with mutiple cores and sufficient <acronym><acronymword>RAM</acronymword></acronym> take advantage
of this to simultaneously regrid multiple files.
In <acronym><acronymword>MPI</acronymword></acronym> mode <command>ncremap</command> issues commands to regrid
the input file list in round-robin fashion to all available compute
nodes. 
Prior to <acronym><acronymword>NCO</acronymword></acronym> version 4.9.0 (released December, 2019),
Background and <acronym><acronymword>MPI</acronymword></acronym> parallelism modes both regridded all
the input files at one time and there was no way to limit the number 
of files being simultaneously regridded.
Subsequent versions allow finer grained parallelism by introducing
the ability to limit the number of discrete workflow elements or
&textldquo;jobs&textrdquo; (i.e., file regriddings) to perform simultaneously within an
<command>ncremap</command> invocation or &textldquo;workflow&textrdquo;.
</para>
<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.9.0 (released December, 2019),
the <samp>--job_nbr=<var>job_nbr</var></samp> option specifies the maximum number
of files to regrid simultaneously on all nodes being harnessed by the
workflow.
Thus <var>job_nbr</var> is an additional parameter to fine-tune file level
parallelism (it has no effect in Serial mode).
Please see the <command>ncremap</command> <var>job_nbr</var> documentation for more
details.
</para>
<html endspaces=" ">
&lt;a name=&quot;pdq_opt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#pdq_opt --&gt;
&lt;a name=&quot;prm_opt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prm_opt --&gt;
&lt;a name=&quot;prm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prm --&gt;
&lt;a name=&quot;pdq&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#pdq --&gt;
&lt;a name=&quot;permute&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#permute --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2911"><var>pdq_opt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2912"><code>--pdq_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2913"><code>--pdq</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2914"><code>--prm_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2915"><code>--prm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2916"><code>--permute</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--pdq_opt <var>pdq_opt</var> (<code>--pdq</code>, <code>--prm_opt</code>, <code>--prm</code>, <code>--permute</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the dimension permutation option used by <command>ncpdq</command>
prior to regridding. 
Synonyms include <samp>--pdq</samp>, <samp>--prm</samp>, <samp>--prm_opt</samp>, and
<samp>--permute</samp>. 
Files to be regridded must have their horizontal spatial dimension(s) 
in the last (most-rapidly-varying) position. 
Most data files store variables with dimensions arranged in this
order, and <command>ncremap</command> internally sets the permutation option
for datasets known (via the <code>--prc_typ</code> option) to require
permutation.
Use <samp>--permute=<var>pdq_opt</var></samp> to override the internally preset
defaults.
This is useful when regridding files that contain new dimensions that 
<command>ncremap</command> has not encountered before.
For example, if a development version of an <acronym><acronymword>MPAS</acronymword></acronym> model
inserts a new dimension <code>new_dim</code> after the horizontal spatial
dimension <code>nCells</code> in some variables, that would prevent the
regridder from working because the horizontal dimension(s) must
be the last dimension(s).
The workaround is to instruct <command>ncremap</command> what the permutation
option to <command>ncpdq</command> should be in order to place the horizontal
spatial dimension(s) at the end of all variables:
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap --permute=Time,new_dim,nCells  --map=map.nc in.nc out.nc
ncremap --permute=time,new_dim,lat,lon --map=map.nc in.nc out.nc
</pre></example>
<para>The <acronym><acronymword>API</acronymword></acronym> for this option changed in <acronym><acronymword>NCO</acronymword></acronym> version
5.0.4 (released December, 2021).
Prior to this, the option argument needed to include the entire
option string to be passed to <command>ncpdq</command> <emph>including the
<samp>-a</samp></emph>, e.g., <samp>--permute='-a time,new_dim,lat,lon'</samp>.
Now <command>ncremap</command> supplies the implicit <samp>-a</samp> internally
so the user does not need to know the <command>ncpdq</command> syntax.
</para>
<html endspaces=" ">
&lt;a name=&quot;no_permute&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_permute --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2917">permute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2918"><command>ncpdq</command></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2919"><acronym><acronymword>SLURM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2920"><acronym><acronymword>CWL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2921"><code>--no_permute</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--no_permute (<code>--no_permute</code>, <code>--no_prm</code>, <code>--no_pdq</code>, <code>--no_ncpdq</code>)</itemformat></item>
</tableterm><tableitem><para>Introduced in <acronym><acronymword>NCO</acronymword></acronym> version 5.0.0 (released June, 2021),
this switch (which takes no argument) causes the regridder to skip the
default permutation of dimensions before regridding (notably
<acronym><acronymword>MPAS</acronymword></acronym>) datasets known to store data with non-horizontal
most-rapidly varying dimensions.
<command>ncremap</command> normally ensures that input fields are stored in the 
shape expected by regridder weights (horizontal dimensions last)
by permuting the dimensions with <command>ncpdq</command>.
However, permutation consumes time and generates an extra intermediate
file. 
Avoid this time penalty by using the <samp>--no_permute</samp> flag if the
input fields are known to already have trailing horizontal
dimensions. 
</para>
<html endspaces=" ">
&lt;a name=&quot;preserve&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#preserve --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2922"><code>--preserve=<var>prs_stt</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2923"><var>prs_stt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2924"><code>--preserve</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2925"><code>--prs_stt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2926"><code>--preserve_statistic</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--preserve=<var>prs_stt</var> (<code>--preserve</code>, <code>--prs_stt</code>, <code>--preserve_statistic</code>)</itemformat></item>
</tableterm><tableitem><para>This is a simple, intuitive option to specify how weight application
should treat destination gridcells that are not completely overlapped
by source gridcells with valid values.
Destination gridcells that are completely overlapped by valid source
values are unaffected.
The two statistics that can be preserved for incompletely overlapped
gridcells are the local mean and/or the global integral of the source
values. 
Hence the valid values for this option are <samp>integral</samp>
(and, as of <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.0.2</w>, released in September,
2021, its synonyms <samp>global</samp> and <samp>global_integral</samp>) and
<samp>mean</samp> (or its synonyms <samp>local</samp>, <samp>local_mean</samp>,
<samp>gridcell</samp>, <samp>gridcell_mean</samp>, <samp>natural_values</samp>).
<acronym><acronymword>NCO</acronymword></acronym> <w>version 5.1.5</w>, released in March, 2023, fixed a
longstanding problem with the implmentation of this option, which
had essentially been broken since its inception.
The option finally works as documented.
</para>
<para>Specifying <code>--preserve=<var>integral</var></code> sets the destination
gridcell equal to the sum of the valid source values times their
source weights.
This sum is <emph>not</emph> renormalized by the (valid) fractional area
covered. 
This is exactly equivalent to setting <code>--rnr=off</code>, i.e.,
no renormalization (see <ref label="Regridding"><xrefnodename>Regridding</xrefnodename></ref>).
If the weights were generated by a conservative algorithm then the
output will be conservative, and will conserve the global integral of 
the input field in all cases.
This is often desired for regridding quantities that should be
conserved, e.g., fluxes, and is the default weight application method 
in <command>ncremap</command> (except in <acronym><acronymword>MPAS</acronymword></acronym>-mode).
Specifying <code>--preserve=<var>mean</var></code> sets the destination
gridcell equal to the mean of the valid source values times
their source weights.
This is exactly equivalent to setting <code>--rnr=0.0</code>, i.e.,
renormalizing the integral value by the (valid) fractional area
covered (see <ref label="Regridding"><xrefnodename>Regridding</xrefnodename></ref>). 
This is often desired for regridding state variables, e.g.,
temperature, though it is not the default behavior and must be
explicitly requested (except in <acronym><acronymword>MPAS</acronymword></acronym>-mode).
These two types of preserved statistics, integral and mean, produce
identical output in all gridcells where there are no missing data,
i.e., where valid data completely tile the gridcell.
By extension, these two statistics produce identical global means
if valid data completely tile the sphere.
</para>
<html endspaces=" ">
&lt;a name=&quot;rgr_opt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr_opt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2927"><code>-R <var>rgr_opt</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2928"><var>rgr_opt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2929"><code>--rgr_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2930"><code>--regrid_options</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-R <var>rgr_opt</var> (<code>--rgr_opt</code>, <code>--regrid_options</code>)</itemformat></item>
</tableterm><tableitem><para><command>ncremap</command> passes <var>rgr_opt</var> directly through to the
regridder.  
This is useful to customize output grids and metadata.
One use is to rename output variables and dimensions from the defaults
provided by or derived from input data.
The default value is <samp>--rgr lat_nm_out=lat --rgr lon_nm_out=lon</samp>,
i.e., by default <command>ncremap</command> always names latitude and longitude
&textldquo;lat&textrdquo; and &textldquo;lon&textrdquo;, respectively, regardless of their input names.
Users might use this option to set different canonical axes names,
e.g., <samp>--rgr lat_nm_out=y --rgr lon_nm_out=x</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;rnr_thr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rnr_thr --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2931"><code>-r <var>rnr_thr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2932"><var>rnr_thr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2933"><code>--rnr_thr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2934"><code>--thr_rnr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2935"><code>--rnr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2936"><code>--renormalize</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2937"><code>--renormalization_threshold</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-r <var>rnr_thr</var> (<code>--rnr_thr</code>, <code>--thr_rnr</code>, <code>--rnr</code>, <code>--renormalize</code>, <code>--renormalization_threshold</code>)</itemformat></item>
</tableterm><tableitem><para>Use this option to request renormalized (see <ref label="Regridding"><xrefnodename>Regridding</xrefnodename></ref>)
weight-application and to specify the weight threshold, if any.
For example, <samp>-r 0.9</samp> tells the regridder to renormalize
with a weight threshold of 90%, so that all destination gridcells
with at least 90% of their area contributed by valid source gridcells
will be contain valid (not missing) values that are the area-weighted
mean of the valid source values.
If the weights are conservative, then the output gridcells on the
destination grid will preserve the mean of the input gridcells.
Specifying <samp>-r 0.9</samp> and <samp>--rnr_thr=0.9</samp> are equivalent.
Renormalization can be explicitly turned-off by setting <var>rnr_thr</var>
to either of the values <samp>off</samp>, or <samp>none</samp>. 
The <samp>--preserve=<var>prs_stt</var></samp> option performs the same task
as this option except it does not allow setting an arbitrary threshold
fraction.  
</para>
<html endspaces=" ">
&lt;a name=&quot;rgn_dst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgn_dst --&gt;
&lt;a name=&quot;rgn_src&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgn_src --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2938"><var>rgn_dst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2939"><code>--rgn_dst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2940"><code>--dst_rgn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2941"><code>--regional_destination</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--rgn_dst (<code>--rgn_dst</code>, <code>--dst_rgn</code>, <code>--regional_destination</code>)</itemformat></item>
</tableterm><tableitem><cindex index="cp" spaces=" "><indexterm index="cp" number="2942"><var>rgn_src</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2943"><code>--rgn_src</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2944"><code>--src_rgn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2945"><code>--regional_source</code></indexterm></cindex>
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">--rgn_src (<code>--rgn_src</code>, <code>--src_rgn</code>, <code>--regional_source</code>)</itemformat></item>
</tableterm><tableitem><para>Use these flags which take no argument to indicate that a user-supplied 
(i.e., with <samp>-s <var>grd_src</var></samp> or <samp>-g <var>grd_dst</var></samp>)
grid is regional.
The <acronym><acronymword>ERWG</acronymword></acronym> weight-generator (at least all versions
<w>before 8.0</w>) needs to be told whether the source, destination, or
both grids are regional or global in order to optimize weight
production. 
<command>ncremap</command> supplies this information to the regridder for grids
it automatically infers from data files. 
However, the regridder needs to be explicitly told if user-supplied
(i.e., with either <samp>-s <var>grd_src</var></samp> or <samp>-g <var>grd_dst</var></samp>)
grids are regional because the regridder does not examine supplied grids 
before calling <acronym><acronymword>ERWG</acronymword></acronym> which assumes, unless told otherwise,
that grids are global in extent.
The sole effect of these flags is to add the arguments
<samp>--src_regional</samp> and/or <samp>--dst_regional</samp> to <acronym><acronymword>ERWG</acronymword></acronym> 
calls.
Supplying regional grids without invoking these flags may dramatically 
increase the map-file size and time to compute.
According to <acronym><acronymword>E3SM</acronymword></acronym> <acronym><acronymword>MPAS</acronymword></acronym> documentation, <acronym><acronymword>ERWG</acronymword></acronym>
&textldquo;considers a mesh to be regional when the mesh is not a full sphere
(including if it is planar and does not cover the full sphere).
In other words, all <acronym><acronymword>MPAS-O</acronymword></acronym> and <acronym><acronymword>MPAS-LI</acronymword></acronym> grids are
regional&textrdquo; to <acronym><acronymword>ERWG</acronymword></acronym>.
</para>
<html endspaces=" ">
&lt;a name=&quot;grd_src&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#grd_src --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2946"><code>-s <var>grd_src</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2947"><var>grd_src</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2948"><code>--grd_src</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2949"><code>--grid_source</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2950"><code>--source_grid</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2951"><code>--src_grd</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-s <var>grd_src</var> (<code>--grd_src</code>, <code>--grid_source</code>, <code>--source_grid</code>, <code>--src_grd</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the source gridfile.
<acronym><acronymword>NCO</acronymword></acronym> will use <acronym><acronymword>ERWG</acronymword></acronym> or TempestRemap weight-generator 
to combine this with a destination gridfile (either inferred from
<var>dst_fl</var>, or generated by supplying a  <samp>-G <var>grd_sng</var></samp>
option) to generate remapping weights. 
<var>grd_src</var> is not modified, and may have read-only permissions.
One appropriate circumstance to specify <var>grd_src</var> is when the
<var>input-file</var>(s) do not contain sufficient information for 
<acronym><acronymword>NCO</acronymword></acronym> to infer an accurate or complete source grid.
(Unfortunately many dataset producers do not record information like
cell edges/vertices in their datasets. 
This is problematic for non-rectangular grids.)
<acronym><acronymword>NCO</acronymword></acronym> assumes that <var>grd_src</var>, when supplied, applies to 
every <var>input-file</var>.
Thus <acronym><acronymword>NCO</acronymword></acronym> will call the weight generator only once, and will
use that <var>map_fl</var> to regrid every <var>input-file</var>.
</para>
<para>Although <command>ncremap</command> usually uses the contents of a pre-existing
<var>grd_src</var> to create mapping weights, there are some situations
where <command>ncremap</command> creates the file specified by <var>grd_src</var>
(i.e., treats it as a location for storing output).
When a source grid is inferred or created from other user-specified
input, <command>ncremap</command> will store it in the location specified by
<var>grd_src</var>.
This allows users to, for example, name the grid on which an input
dataset is stored when that grid is not known <emph><w>a priori</w></emph>.
This functionality is only available for <acronym><acronymword>SCRIP</acronymword></acronym>-format grids. 
</para>
<html endspaces=" ">
&lt;a name=&quot;skl_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#skl_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2952"><code>--skl_fl=<var>skl_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2953"><var>skl_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2954"><code>--skl_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2955"><code>--skl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2956"><code>--skeleton</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2957"><code>--skeleton_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2958">skeleton</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--skl_fl=<var>skl_fl</var> (<code>--skl_fl</code>, <code>--skl</code>, <code>--skl_fl</code>)</itemformat></item>
</tableterm><tableitem><para>Normally <command>ncremap</command> only creates a <acronym><acronymword>SCRIP</acronymword></acronym>-format
gridfile named <var>grd_dst</var> when it receives the <code>grd_sng</code>
option.
The <samp>--skl</samp> option instructs <command>ncremap</command> to also produce a  
&textldquo;skeleton&textrdquo; file based on the <code>grd_sng</code> argument.
A skeleton file is a bare-bones datafile on the specified grid.
It contains the complete latitude/longitude grid and an area field.
Skeleton files are useful for validating that the grid-creation
instructions in <var>grd_sng</var> perform as expected.
</para>
<html endspaces=" ">
&lt;a name=&quot;stdin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#stdin --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2959"><acronym><acronymword>SLURM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2960"><acronym><acronymword>PBS</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2961"><code>--stdin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2962"><code>--inp_std</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2963"><code>--std_flg</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2964"><code>--redirect</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2965"><code>--standard_input</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--stdin (<code>--stdin</code>, <code>--inp_std</code>, <code>--std_flg</code>, <code>--redirect</code>, <code>--standard_input</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) explicitly indicates that 
input file lists are provided via <code>stdin</code>, i.e., standard input.
In interactive environments, <command>ncremap</command> can automatically
(i.e., without any switch) detect whether input is provided via
<code>stdin</code>.  
This switch is never required for jobs run in an interactive shell. 
However, non-interactive batch jobs (such as those submitted to the 
<acronym><acronymword>SLURM</acronymword></acronym> and <acronym><acronymword>PBS</acronymword></acronym> schedulers) make it impossible to 
unambiguously determine whether input has been provided via
<code>stdin</code>. 
Specifically, the <samp>--stdin</samp> switch <emph>must</emph> be used with
<command>ncremap</command> in non-interactive batch jobs on <acronym><acronymword>PBS</acronymword></acronym>
when the input files are piped to <code>stdin</code>, and on <acronym><acronymword>SLURM</acronymword></acronym>
when the input files are redirected from a file to <code>stdin</code>
<footnote spaces="\n"><para>Until version 5.0.4 (December, 2021) the <samp>--stdin</samp> was
also supported by <command>ncclimo</command>, and used for the same reasons
as it still is for <command>ncclimo</command>.
At that time, the <samp>--split</samp> switch superceded the <samp>--stdin</samp> 
switch in <command>ncclimo</command>, where it is now deprecated.</para></footnote>.
Using <samp>--stdin</samp> in any other context (e.g., interactive shells)
is optional.
</para>
<para>In some other non-interactive environments (e.g., <command>crontab</command>,
<code>nohup</code>, Azure <acronym><acronymword>CI</acronymword></acronym>, <acronym><acronymword>CWL</acronymword></acronym>),
<command>ncremap</command> may mistakenly expect input to be provided on
<code>stdin</code> simply because the environment is using <code>stdin</code> for
other purposes. 
In such cases users may disable checking <code>stdin</code> by explicitly
invoking the <samp>--no_stdin</samp> flag (described next), which works for
both <command>ncclimo</command> and <command>ncremap</command>. 
</para>
<html endspaces=" ">
&lt;a name=&quot;no_stdin&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#no_stdin --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2966">Chrysalis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2967">Common Workflow Language</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2968">Azure <acronym><acronymword>CI</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2969"><acronym><acronymword>SLURM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2970"><acronym><acronymword>CWL</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2971"><code>--no_stdin</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2972"><code>--no_inp_std</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2973"><code>--no_standard_input</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2974"><code>--no_redirect</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--no_stdin (<code>--no_stdin</code>, <code>--no_inp_std</code>, <code>--no_redirect</code>, <code>--no_standard_input</code>)</itemformat></item>
</tableterm><tableitem><para>First introduced in <acronym><acronymword>NCO</acronymword></acronym> version 4.8.0 (released May, 2019),
this switch (which takes no argument) disables checking standard input
(aka <code>stdin</code>) for input files. 
This is useful because <command>ncclimo</command> and <command>ncremap</command> may
mistakenly expect input to be provided on <code>stdin</code> in environments
that use <code>stdin</code> for other purposes. 
Some non-interactive environments (e.g., <command>crontab</command>,
<code>nohup</code>, Azure <acronym><acronymword>CI</acronymword></acronym>, <acronym><acronymword>CWL</acronymword></acronym>), may
use standard input for their own purposes, and thus confuse
<acronym><acronymword>NCO</acronymword></acronym> into thinking that you provided the input files names
via the <code>stdin</code> mechanism. 
In such cases users may disable the automatic checks for standard
input by explicitly invoking the <samp>--no_stdin</samp> flag.
This switch is usually not required for jobs in an interactive shell.
Interactive <acronym><acronymword>SLURM</acronymword></acronym> shells can also commandeer <code>stdin</code>,
as is the case on the <code>DOE</code> machine named Chrysalis.
This behavior appears to vary depending on the <acronym><acronymword>SLURM</acronymword></acronym>
implementation.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
srun -N 1 -n 1 ncremap --no_stdin -m map.nc in.nc out.nc
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;tmp_drc&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#tmp_drc --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2975"><code>-T <var>tmp_drc</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2976"><var>tmp_drc</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2977"><code>--tmp_drc</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2978"><code>--drc_tmp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2979"><code>--tmp_dir</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2980"><code>--dir_tmp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2981"><code>--tmp</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-T <var>tmp_drc</var> (<code>--tmp_drc</code>, <code>--drc_tmp</code>, <code>--tmp_dir</code>, <code>--dir_tmp</code>, <code>--tmp_drc</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the directory in which to place intermediate output files.
Depending on how it is invoked, <command>ncremap</command> may generate
a few or many intermediate files (grids and maps) that it will, by
default, remove upon successful completion.
These files can be large, so the option to set <var>tmp_drc</var> is offered
to ensure their location is convenient to the system.
If the user does not specify <var>tmp_drc</var>, then <command>ncremap</command> uses
the value of <code>$TMPDIR</code>, if any, or else <file>/tmp</file> if it exists,
or else it uses the current working director (<code>$PWD</code>).
</para>
<html endspaces=" ">
&lt;a name=&quot;thr_nbr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#thr_nbr --&gt;
&lt;a name=&quot;thr_nbr_ncremap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#thr_nbr_ncremap --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2982"><code>-t <var>thr_nbr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2983"><var>thr_nbr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2984"><code>--thr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2985"><code>--thr_nbr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2986"><code>--thread_number</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2987"><code>--threads</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-t <var>thr_nbr</var> (<code>--thr_nbr</code>, <code>--thr</code>, <code>--thread_number</code>, <code>--threads</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the number of threads used per regridding process
(<pxref label="OpenMP-Threading"><xrefnodename>OpenMP Threading</xrefnodename></pxref>).
<command>ncremap</command> can use OpenMP shared-memory techniques to
simultaneosly regrid multiple variables within a single file.
This shared memory parallelism is quite efficient because it
uses a single copy of the regridding weights in physical memory
to regrid multiple variable simultaneously.
Even so, simultaneously regridding multiple variables, especially at
high resolution, may be memory-limited, meaning that the insufficient
<acronym><acronymword>RAM</acronymword></acronym> can often limit the number of variables that the system
can simultaneously regrid.
By convention all variables to be regridded share the same
regridding weights stored in a map-file, so that only one copy
of the weights needs to be in memory, just as in Serial mode.
However, the per-thread (i.e., per-variable) OpenMP memory demands 
are considerable, with the memory required to regrid variables
amounting to no less than about 5&textndash;7 times (for type <code>NC_FLOAT</code>)
and 2.5&textndash;3.5 times (for type <code>NC_DOUBLE</code>) the size of the
uncompressed variable, respectively.
Memory requirements are so high because the regridder performs
all arithmetic in double precision to retain the highest accuracy,
and must allocate separate buffers to hold the input and output
(regridded) variable, a tally array to count the number of missing
values and an array to sum the of the weights contributing to each
output gridcell (the last two arrays are only necessary for variables
with a <code>_FillValue</code> attribute).
The input, output, and weight-sum arrays are always double precision,
and the tally array is composed of four-byte integers.
Given the high memory demands, one strategy to optimize <var>thr_nbr</var>
for repetitious workflows is to increase it to keep doubling it (1, 2,
4, &dots;) until throughput stops improving. 
With sufficient <acronym><acronymword>RAM</acronymword></acronym>, the <acronym><acronymword>NCO</acronymword></acronym> regridder scales well
up to 8&textndash;16 threads. 
</para>
<html endspaces=" ">
&lt;a name=&quot;upk_inp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#upk_inp --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2988"><code>-U</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2989"><code>--unpack</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2990"><code>--upk</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2991"><code>--upk_inp</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-U (<code>--unpack</code>, <code>--upk</code>, <code>--upk_inp</code>)</itemformat></item>
</tableterm><tableitem><para>This switch (which takes no argument) causes <command>ncremap</command> to
unpack (see <ref label="Packed-data"><xrefnodename>Packed data</xrefnodename></ref>) input data before regridding it.
This switch causes unpacking at the regridding stage that occurs
after map generation.
Hence this switch does not benefit grid inferral.
Grid inferral examines only the coordinate variables in a dataset.
If coordinates are packed (a terrible practice) in a file from which a
grid will be inferred, users should first manually unpack the file (this
option will not help). 
Fortunately, coordinate variables are usually not packed, even in files
with other packed data.
</para>
<para>Many institutions (like <acronym><acronymword>NASA</acronymword></acronym>) pack datasets to conserve space
before distributing them. 
This option allows one to regrid input data without having
to manually unpack it first.
Beware that <acronym><acronymword>NASA</acronymword></acronym> uses at least three different and
incompatible versions of packing in its <acronym><acronymword>L2</acronymword></acronym> datasets.
The unpacking algorithm employed by this option is the default netCDF
algorithm, which is appropriate for <acronym><acronymword>MOD04</acronymword></acronym> and is inappropriate
for <acronym><acronymword>MOD08</acronymword></acronym> and <acronym><acronymword>MOD13</acronymword></acronym>. 
See <ref label="Packed-data"><xrefnodename>Packed data</xrefnodename></ref> for more details and workarounds.
</para>
<html endspaces=" ">
&lt;a name=&quot;ugrid_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ugrid_fl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2992"><code>--ugrid_fl=<var>ugrid_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2993"><var>ugrid_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2994"><code>--ugrid_fl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2995"><code>--ugrid</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2996"><code>--ugrid_file</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2997">infer</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--ugrid_fl=<var>ugrid_fl</var> (<code>--ugrid_fl</code>, <code>--ugrid</code>, <code>--ugrid_fl</code>)</itemformat></item>
</tableterm><tableitem><para>Normally <command>ncremap</command> only infers a gridfile named <var>grd_dst</var> in 
<acronym><acronymword>SCRIP</acronymword></acronym>-format.
The <samp>ugrid_fl</samp> option instructs <command>ncremap</command> to infer both a 
<acronym><acronymword>SCRIP</acronymword></acronym>-format gridfile named <var>grd_dst</var> and a
<acronym><acronymword>UGRID</acronymword></acronym>-format gridfile named <var>ugrid_fl</var>.
This is an experimental feature and the <acronym><acronymword>UGRID</acronymword></acronym> file is
only expected to be valid for global rectangular grids. 
</para>
<html endspaces=" ">
&lt;a name=&quot;unq_sfx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#unq_sfx --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="2998"><code>-u <var>unq_sfx</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="2999"><var>unq_sfx</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3000">noclean</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3001"><code>--unq_sfx</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3002"><code>--unique_suffix</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3003"><code>--suffix</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-u <var>unq_sfx</var> (<code>--unq_sfx</code>, <code>--unique_suffix</code>, <code>--suffix</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the suffix used to label intermediate (internal) files
generated by the regridding workflow.
Unique names are required to avoid interference among parallel
invocations of <command>ncremap</command>. 
The default <var>unq_sfx</var> generated internally by <command>ncremap</command> is
<samp>.pid<var>PID</var></samp> where <var>PID</var> is the process ID.
Applications can provide their own more or less informative suffixes
using the <samp>--unq_sfx=<var>unq_sfx</var></samp> option.
The suffix should be unique so that no two simultaneously executing 
instances of <command>ncremap</command> can generate the same file.
For example, when the <command>ncclimo</command> climatology script issues a
dozen <command>ncremap</command> commands to regrid all twelve months 
simultaneously, it uses <samp>--unq_sfx=<var>mth_idx</var></samp> to encode the
climatological month index in the unique suffix.
Note that the controlling process <var>PID</var> is insufficient to
disambiguate all the similar temporary files when the input file list 
is divided into multiple concurrent jobs (controlled by the
<samp>--job_nbr=<var>job_nbr</var></samp> option).
Those files have their user-provided or internally generated
<var>unq_sfx</var> extended by <var>fl_idx</var>, their position in the input 
file list, so that their full suffix is
<samp>.pid<var>PID</var>.<var>fl_idx</var></samp>. 
Finally, a special value of <var>unq_sfx</var> is available to aid
developers: if <var>unq_sfx</var> is <samp>noclean</samp> then <command>ncremap</command>
retains (not removes) all intermediate files after completion.
</para>
<html endspaces=" ">
&lt;a name=&quot;var_lst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#var_lst --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3004"><code>-v <var>var_lst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3005"><var>var_lst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3006"><code>--var_lst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3007"><code>--var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3008"><code>--vars</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3009"><code>--variables</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3010"><code>--variable_list</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-v <var>var_lst</var> (<code>--var_lst</code>, <code>--var</code>, <code>--vars</code>, <code>--variables</code>, <code>--variable_list</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>-v</samp> option causes <command>ncremap</command> to regrid only the
variables in <var>var_lst</var>. 
It behaves like subsetting (<pxref label="Subsetting-Files"><xrefnodename>Subsetting Files</xrefnodename></pxref>) in the rest of
<acronym><acronymword>NCO</acronymword></acronym>.   
</para>
<html endspaces=" ">
&lt;a name=&quot;rgr_var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rgr_var --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3011"><code>-V <var>rgr_var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3012"><var>rgr_var</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3013"><code>--rgr_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3014"><code>--var_rgr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3015"><code>--var_cf</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3016"><code>--cf_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3017"><code>--cf_variable</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-V <var>var_rgr</var> (<code>--var_rgr</code>, <code>--rgr_var</code>, <code>--var_cf</code>, <code>--cf_var</code>, <code>cf_variable</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>-V</samp> option tells <command>ncremap</command> to use the same grid as 
<var>var_rgr</var> in the input file.
If <var>var_rgr</var> adheres to the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code>
convention described 
<uref><urefurl>http://cfconventions.org/cf-conventions/cf-conventions.html#coordinate-system</urefurl><urefdesc spaces=" ">here</urefdesc></uref>,
then <command>ncclimo</command> will infer the grid as represented by those
coordinate variables.
This option simplifies inferring grids when the grid coordinate names 
are unknown, since <command>ncclimo</command> will follow the <acronym><acronymword>CF</acronymword></acronym>
convention to learn the identity of the grid coordinates.
</para>
<para>Until <acronym><acronymword>NCO</acronymword></acronym> version 4.6.0 (May, 2016), <command>ncremap</command> would 
not follow <acronym><acronymword>CF</acronymword></acronym> conventions to identify coordinate variables.
Instead, <command>ncremap</command> used an internal database of &textldquo;usual
suspects&textrdquo; to identify latitude and longitude coordinate variables.
Now, if <var>var_rgr</var> is <acronym><acronymword>CF</acronymword></acronym>-compliant, then <command>ncremap</command>
will automatically identify the horizontal spatial dimensions. 
If <var>var_rgr</var> is supplied but is not <acronym><acronymword>CF</acronymword></acronym>-compliant, then
<command>ncremap</command> will still attempt to identify horizontal spatial
dimensions using its internal database of &textldquo;likely names&textrdquo;.
If both these automated methods fail, manually supply <command>ncremap</command>
with the names of the horizontal spatial dimensions 
</para><example endspaces=" ">
<pre xml:space="preserve"># Method used to obtain horizontal spatial coordinates:
ncremap -V var_rgr -d dst.nc -O ~/rgr in.nc # CF coordinates convention
ncremap -d dst.nc -O ~/rgr in.nc # Internal database
ncremap -R &quot;--rgr lat_nm=xq --rgr lon_nm=zj&quot; -d dst.nc -O ~/rgr in.nc # Manual
</pre></example>
<noindent></noindent>

<html endspaces=" ">
&lt;a name=&quot;vrb_lvl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrb_lvl --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3018"><code>--vrb=<var>vrb_lvl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3019"><var>vrb_lvl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3020"><code>--vrb_lvl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3021"><code>--vrb</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3022"><code>--verbosity</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3023"><code>--verbosity_level</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--vrb=<var>vrb_lvl</var> (<code>--vrb_lvl</code>, <code>--vrb</code>, <code>--verbosity</code>, <code>--verbosity_level</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a verbosity level similar to the rest of <acronym><acronymword>NCO</acronymword></acronym>.
If <math><var>vrb_lvl</var> = 0</math>, <command>ncremap</command> prints nothing except
potentially serious warnings.
If <math><var>vrb_lvl</var> = 1</math>, <command>ncremap</command> prints the basic
filenames involved in the remapping.
If <math><var>vrb_lvl</var> = 2</math>, <command>ncremap</command> prints helpful comments
about the code path taken.
If <math><var>vrb_lvl</var> &gt; 2</math>, <command>ncremap</command> prints even more detailed
information.
Note that <var>vrb_lvl</var> is distinct from <var>dbg_lvl</var> which is
passed to the regridder (<command>ncks</command>) for additional diagnostics.
</para>
<html endspaces=" ">
&lt;a name=&quot;vrt_crd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_crd --&gt;
&lt;a name=&quot;plev_nm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#plev_nm --&gt;
&lt;a name=&quot;vrt_nm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_nm --&gt;
&lt;a name=&quot;vertical_coordinate_name&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vertical_coordinate_name --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3024"><code>--vrt_crd</code></indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3025"><code>--plev_nm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3026"><code>--vertical_coordinate_name</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3027"><code>--vrt_nm=<var>vrt_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3028"><var>vrt_crd</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3029">Vertical coordinate</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3030"><acronym><acronymword>MPAS</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--vrt_nm=<var>vrt_nm</var> (<code>--vrt_nm</code>, <code>--plev_nm</code>, <code>--vrt_crd</code>, <code>--vertical_coordinate_name</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>--vrt_nm=<var>vrt_nm</var></samp> option instructs <command>ncremap</command>
to use <var>vrt_nm</var>, instead of the default <code>plev</code>, as the vertical
coordinate name for pure pressure grids.
This option first appeared in <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.8.0</w>,
released in May, 2019.
Note that the vertical coordinate may be specified in millibars 
in some important reanalyses like <acronym><acronymword>ERA5</acronymword></acronym>, whereas many
models express the vertical coordinate in Pascals.
The user must ensure that the vertical coordinate in the template
vertical grid-file is in the same units (e.g., mb or Pa) as the
vertical coordinate in the file to be vertically interpolated.
</para>
<html endspaces=" ">
&lt;a name=&quot;vrt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt --&gt;
&lt;a name=&quot;vrt_fl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_fl --&gt;
&lt;a name=&quot;vrt_grd_out&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_grd_out --&gt;
&lt;a name=&quot;vrt_out&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_out --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3031"><code>vrt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3032"><code>--vrt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3033"><code>--vrt_fl_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3034"><code>--vrt_grd_out</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3035"><code>--vrt_out=<var>vrt_fl</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3036"><var>vrt_fl</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3037">Vertical coordinate</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3038"><acronym><acronymword>MPAS</acronymword></acronym></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--vrt_out=<var>vrt_fl</var> (<code>--vrt_out</code>, <code>--vrt_fl</code>, <code>--vrt</code>, <code>--vrt_grd_out</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>--vrt_out=<var>vrt_fl</var></samp> option instructs <command>ncremap</command>
to vertically interpolate the input file to the vertical coordinate
grid contained in the file <var>vrt_fl</var>.
This option first appeared in <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.8.0</w>,
released in May, 2019.
The vertical gridfile <var>vrt_fl</var> must specify a vertical gridtype
that <command>ncremap</command> understands, currently either pure-pressure or
hybrid-coordinate pressure.
We plan to add pure-sigma coordinates in the future.
</para>
<para>Besides the vertical grid-type, the main assumptions, constraints, and
priorities for future development of vertical regridding are:
</para><enumerate first="1" endspaces=" ">
<listitem> <para>When originally released, the vertical interpolation feature
      required that the input datasets have netCDF (and thus C-based)
      dimension-ordering <emph>all other dimensions, a single vertical 
      dimension, then one or two horizontal dimensions, if any</emph> so
      that the horizontal dimension(s) vary most rapidly.
      <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.1.4</w>, released in January, 2023,
      eliminated this constraint.
      Now the regridder automatically determines whether the vertical
      or the horizontal dimensions vary most rapidly, and adjusts its
      algorithms accordingly.
</para></listitem><listitem> <para>The vertical interpolation algorithm defaults to linear in
      log(pressure) for pure pressure and for hybrid sigma-pressure
      coordinates.  
      This assumption is more natural for gases (like the atmosphere)
      than for condensed media (like oceans or Earth&textrsquo;s interior).
      To instead interpolate linearly in the vertical coordinate, use
      the <samp>ntp_mth=lin</samp> options (as of <acronym><acronymword>NCO</acronymword></acronym> 4.9.0).
      <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.1.4</w>, released in January, 2023,
      supports interpolation of data structured with a geometric
      depth/height grid (such as ocean data usually uses).
      Data on a depth/height grid defaults to linear interpolation.
</para></listitem><listitem> <para>Vertical interpolation and horizontal regridding may be invoked
      simultaneously (as of <acronym><acronymword>NCO</acronymword></acronym> 4.9.0) by the user simply by
      supplying both a (horizontal) map-file and a vertical grid-file
      to <command>ncremap</command>. 
      When this occurs, <command>ncremap</command> internally performs the
      vertical interpolation prior to the horizontal regridding.
      Exploiting this feature can have some unintended consequences.
      For example, horizontal regridding requires that the horizontal
      spatial dimension vary most rapidly, whereas vertical
      interpolation makes no such assumption.
      When the regridder needs to permute the dimension ordering of
      the input dataset in order to perform horizontal regridding,
      this step actually precedes the vertical regridding.
      This order of operations is problematic and we are working
      to address the issues in future updates.
</para></listitem><listitem> <para>The default extrapolation method uses nearest neighbor except
      for temperature and geopotential (those extrapolation methods
      are described below).
      These defaults are well-suited to extrapolate valid initial
      conditions from data on older vertical grids.
      Note that the default approximation used for geopotential is
      inaccurate in cold regions.
      As of July 2019 and <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.8.1</w>, one may
      instead set points outside the input domain to missing-values
      with the <samp>--vrt_xtr=mss_val</samp> option.
      More extrapolation options, exposed to user-access as of
      November 2022 in <acronym><acronymword>NCO</acronymword></acronym> <w>version 5.1.1</w>, are:
      linear extrapolation (<samp>--vrt_xtr=linear</samp>),
      setting <w>to 0.0</w> (<samp>--vrt_xtr=zero</samp>).
      Linear extrapolation does exactly what you think: Values outside
      the input domain are linearly extrapolated from the nearest two
      values inside the input domain.
      Zero extrapolation sets values outside the extrapoloation domain
      <w>to 0.0</w>.  
      Supporting other methods, or improving the existing
      special-case approximations for temperature or geopotential,
      will remain low priority until we are lobbied with compelling
      use-cases for other algorithms.  
</para></listitem><listitem> <para>Missing values may not always be treated correctly
      Eliminating this constraint was not originally a priority
      because atmospheric datasets often contain no missing data.
      However, now that vertical regridding can be applied to ocean
      data with a depth coordinate, we need to verify that using
      missing values to indicate bathymetry works as expected.
</para></listitem><listitem> <para>Time-varying vertical grids are only allowed for hybrid grids
      (not pure pressure grids), and these must store the time
      dimension as a record dimension.
      This constraint applies to the vertical grid only, not to the
      other fields in the dataset.
      Hence this does not preclude interpolating timeseries to/from
      time-invariant vertical grids.
      For example, time-varying hybrid grid data such as temperature
      may be interpolated to timeseries on a time-invariant pressure
      grid.
      Eliminating this constraint will not be a priority unless/until
      an important use-case is identified.  
</para></listitem><listitem> <para>Variable names for input and output vertical grids must match
      <acronym><acronymword>E3SM/CESM</acronymword></acronym>, <acronym><acronymword>ECMWF</acronymword></acronym>, <acronym><acronymword>MPAS</acronymword></acronym>, and
      <acronym><acronymword>NCEP</acronymword></acronym> implementations. 
      These names include <code>hyai</code>, <code>hyam</code>, <code>hybi</code>,
      <code>hybm</code>, <code>ilev</code>, <code>lev</code>, <code>P0</code>, and <code>PS</code>
      (for <acronym><acronymword>E3SM/CESM</acronymword></acronym> hybrid grids), <code>lev</code>,
      <code>lev_2</code>, and <code>lnsp</code> (for <acronym><acronymword>ECMWF</acronymword></acronym> hybrid grids
      only), <code>depth</code>, <code>timeMonthly_avg_zMid</code> (for
      <acronym><acronymword>MPAS</acronymword></acronym> depth grids), and <code>plev</code> and <code>level</code>
      (for pure-pressure grids with <acronym><acronymword>NCEP</acronymword></acronym> and <acronym><acronymword>ERA5</acronymword></acronym>
      conventions, respectively).
      The infrastructure to provide alternate names for any of these
      input/output variables names is straightforward, and is heavily 
      used for horizontal spatial regridding.
      Allowing this functionality will not be a priority until we are 
      presented with a compelling use-case.
</para></listitem></enumerate>

<html endspaces=" ">
&lt;a name=&quot;vrt_prs_mk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_prs_mk --&gt;
&lt;a name=&quot;vrt_prs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_prs --&gt;
&lt;a name=&quot;vrt_ncep&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_ncep --&gt;
</html>
<para>The simplest vertical grid-type, a pure-pressure grid, contains
the horizontally uniform vertical pressure levels in a one-dimensional 
coordinate array named (by default) <code>plev</code>. 
The <code>plev</code> dimension may have any number of levels and the values 
must monotonically increase or decrease.
A 17-level NCEP pressure grid, for example, is easy to create:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Construct monotonically decreasing 17-level NCEP pressure grid
ncap2 -O -v -s 'defdim(&quot;plev&quot;,17);plev[$plev]={100000,92500,85000, \
  70000,60000,50000,40000,30000,25000,20000,15000,10000,7000,5000, \
  3000,2000,1000};' vrt_prs_ncep_L17.nc
</verbatim>
</example>
<para><command>ncremap</command> will search the supplied vertical grid file for
the coordinate named <code>plev</code>, or, for any coordinate name
specified by with the <code>plev_nm_in</code> option to the regridder,
e.g., <samp>--plev_nm_in=z</samp>.
</para>
<html endspaces=" ">
&lt;a name=&quot;vrt_hyb_mk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_hyb_mk --&gt;
&lt;a name=&quot;vrt_hyb&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_hyb --&gt;
</html>
<para>Hybrid-coordinate grids are a hybrid between a sigma-coordinate
grid (where each pressure level is a fixed fraction of a
spatiotemporally varying surface pressure) and a pure-pressure grid
that is spatially invariant (as described above). 
The so-called hybrid <var>A</var> and <var>B</var> coefficients specify the
fractional weight of the pure-pressure and sigma-grids, respectively, 
at each level.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3039"><code>P0</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3040"><code>PS</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3041"><code>hyai</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3042"><code>hyam</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3043"><code>hybi</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3044"><code>hybm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3045"><code>formula_terms</code> attribute</indexterm></cindex>
The hybrid gridfile must specify <var>A</var> and <var>B</var> coefficients for 
both layer midpoints and interfaces with these standard
(as employed by <acronym><acronymword>CESM</acronymword></acronym> and <acronym><acronymword>E3SM</acronymword></acronym>) names and
dimensions: <code>hyai(ilev)</code>, <code>hybi(ilev)</code>, <code>hyam(lev)</code>, 
and <code>hybm(lev)</code>.
The reference pressure and surface pressure must be named
<code>P0</code> and <code>PS</code>, respectively.
The pressures at all midpoints and interfaces are then defined as 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
prs_mdp[time,lev, lat,lon]=hyam*P0+hybm*PS # Midlayer
prs_ntf[time,ilev,lat,lon]=hyai*P0+hybi*PS # Interface
</verbatim>
</example>
<para>The scalar reference pressure <code>P0</code> is typically <w>100000 Pa</w>
(or <w>1000 hPa</w>) while the surface pressure <code>PS</code> is a (possibly
time-varying) array with one or two spatial dimensions, and its values 
are in the same dimensional units (e.g., Pa or hPa) as <code>P0</code>.
</para>
<para>It is often useful to create a vertical grid file from existing
model or reanalysis output.
We call vertical grid files &textldquo;skinny&textrdquo; if they contain only the
vertical information.
Skinny grid-files are easy to create with <command>ncks</command>, e.g.,
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -C -v hyai,hyam,hybi,hybm,P0 in_L128.nc vrt_hyb_L128.nc
</verbatim>
</example>
<para>Such files are extremely small and portable, and represent
all the hybrid files created by the model because the vertical
grid parameters are time-invariant.
A &textldquo;fat&textrdquo; vertical grid file would also include the time-varying
grid information, i.e., the surface pressure field.
Fat grid-files are also easy to create with <command>ncks</command>, e.g.,
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncks -C -v hyai,hyam,hybi,hybm,P0,PS in_L128.nc vrt_hyb_L128.nc
</verbatim>
</example>
<para>The full (layer-midpoint) and half (layer-interface) pressure fields
<code>prs_mdp</code> and <code>prs_ntf</code>, respectively, can be reconstructed
from any fat grid-file with an <command>ncap2</command> command:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -s 'prs_mdp[time,lat,lon,lev]=P0*hyam+PS*hybm' \
      -s 'prs_ntf[time,lat,lon,ilev]=P0*hyai+PS*hybi' in.nc out.nc
</verbatim>
</example>

<para>Hybrid-coordinate grids define a pure-sigma or pure-pressure grid when
either their <var>A</var> or <var>B</var> coefficients are zero, respectively.
For example, the following creates the hybrid-coordinate
representation of a pure-pressure grid with midpoints every <w>100 hPa</w>
from <w>100 hPa</w> to <w>1000 hPa</w>:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncap2 -O -v -s 'defdim(&quot;ilev&quot;,11);defdim(&quot;lev&quot;,10);P0=100000.0; \
  hyai=array(0.05,0.1,$ilev);hyam=array(0.1,0.1,$lev); \
  hybi=0.0*hyai;hybm=0.0*hyam;' vrt_hyb_L10.nc
</verbatim>
</example>
<para><acronym><acronymword>NCO</acronymword></acronym> currently has no other means of representing pure sigma
vertical grids (as opposed to pure pressure grids).
</para>
<html endspaces=" ">
&lt;a name=&quot;vrt_hyb_ifs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_hyb_ifs --&gt;
</html>
<para>As of July 2019 and <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.8.1</w>, <acronym><acronymword>NCO</acronymword></acronym> 
supports regridding <acronym><acronymword>ECMWF</acronymword></acronym> datasets in <acronym><acronymword>IFS</acronymword></acronym> hybrid
vertical coordinate format to <acronym><acronymword>CESM</acronymword></acronym>/<acronym><acronymword>E3SM</acronymword></acronym>-format
hybrid vertical grids. 
Unfortunately there was a regression and this functionality was
broken between about 2023&textndash;2024 (the workaround is to use older
<acronym><acronymword>NCO</acronymword></acronym> versions like 4.9.0).
<acronym><acronymword>NCO</acronymword></acronym> once agains supports this functionality as of October
2024 (<acronym><acronymword>NCO</acronymword></acronym> <w>version 5.2.9</w>), though now the user must
employ the <samp>--ps_nm=lnsp</samp> option shown below.
</para>
<para>The native <acronym><acronymword>IFS</acronymword></acronym> hybrid datasets that we have seen store
pressure coordinates in terms of a slightly different formula that
employs the log of surface pressure (<code>lnsp</code>) instead of surface
pressure <code>PS</code>, that redefines <code>hyai</code> and <code>hyam</code> to be
pure-pressure offsets (rather than coefficients), and that omits
<code>P0</code>: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
prs_mdp[time,lev,  lat,lon]=hyam+hybm*exp(lnsp) # Midlayer
prs_ntf[time,lev_2,lat,lon]=hyai+hybi*exp(lnsp) # Interface
</verbatim>
</example>
<para>Note that <acronym><acronymword>ECMWF</acronymword></acronym> also alters the names of the vertical
half-layer coordinate and employs distinct dimensions (<code>nhym</code> and 
<code>nhyi</code>) for the hybrid variables <code>hyai(nhyi)</code>,
<code>hybi(nhyi)</code>, <code>hyam(nhym)</code>, and <code>hybm(nhym)</code>.
<acronym><acronymword>ECMWF</acronymword></acronym> uses the vertical coordinates <code>lev</code> and
<code>lev_2</code> for full-layer (i.e., midlayer) and  half-layer
(i.e., interface) for all other variables.
</para>
<para>To invoke <command>ncremap</command> on a hybrid coordinate dataset in
<acronym><acronymword>IFS</acronymword></acronym> format, one must specify that the surface pressure 
variable is named <code>lnsp</code>. 
No modifications to the <acronym><acronymword>IFS</acronymword></acronym> dataset are necessary.
The vertical grid file should be in <acronym><acronymword>CESM</acronymword></acronym>/<acronym><acronymword>E3SM</acronymword></acronym> format.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
zender@spectral:~$ ncks -m -C -v lnsp,hyai,hyam,hybi,hybm,lev,lev_2 ifs.nc
netcdf ecmwf_ifs_f640L137 {
  dimensions:
    lev = 137 ;
    lev_2 = 1 ;
    nhyi = 138 ;
    nhym = 137 ;

  variables:
    double hyai(nhyi) ;
      hyai:long_name = &quot;hybrid A coefficient at layer interfaces&quot; ;
      hyai:units = &quot;Pa&quot; ;
    double hyam(nhym) ;
      hyam:long_name = &quot;hybrid A coefficient at layer midpoints&quot; ;
      hyam:units = &quot;Pa&quot; ;
    double hybi(nhyi) ;
      hybi:long_name = &quot;hybrid B coefficient at layer interfaces&quot; ;
      hybi:units = &quot;1&quot; ;
    double hybm(nhym) ;
      hybm:long_name = &quot;hybrid B coefficient at layer midpoints&quot; ;
      hybm:units = &quot;1&quot; ;
    double lev(lev) ;
      lev:standard_name = &quot;hybrid_sigma_pressure&quot; ;
      lev:long_name = &quot;hybrid level at layer midpoints&quot; ;
      lev:formula = &quot;hyam hybm (mlev=hyam+hybm*aps)&quot; ;
      lev:formula_terms = &quot;ap: hyam b: hybm ps: aps&quot; ;
      lev:units = &quot;level&quot; ;
      lev:positive = &quot;down&quot; ;
    double lev_2(lev_2) ;
      lev_2:standard_name = &quot;hybrid_sigma_pressure&quot; ;
      lev_2:long_name = &quot;hybrid level at layer midpoints&quot; ;
      lev_2:formula = &quot;hyam hybm (mlev=hyam+hybm*aps)&quot; ;
      lev_2:formula_terms = &quot;ap: hyam b: hybm ps: aps&quot; ;
      lev_2:units = &quot;level&quot; ;
      lev_2:positive = &quot;down&quot; ;
    float lnsp(time,lev_2,lat,lon) ;
      lnsp:long_name = &quot;Logarithm of surface pressure&quot; ;
      lnsp:param = &quot;25.3.0&quot; ;
} // group /
zender@spectral:~$ ncks -m vrt_grd.nc
netcdf vrt_hyb_L72 {
  dimensions:
    ilev = 73 ;
    lev = 72 ;

  variables:
    double P0 ;
      P0:long_name = &quot;reference pressure&quot; ;
      P0:units = &quot;Pa&quot; ;

    double hyai(ilev) ;
      hyai:long_name = &quot;hybrid A coefficient at layer interfaces&quot; ;

    double hyam(lev) ;
      hyam:long_name = &quot;hybrid A coefficient at layer midpoints&quot; ;

    double hybi(ilev) ;
      hybi:long_name = &quot;hybrid B coefficient at layer interfaces&quot; ;

    double hybm(lev) ;
      hybm:long_name = &quot;hybrid B coefficient at layer midpoints&quot; ;
} // group /
zender@spectral:~$ ncremap --ps_nm=lnsp --vrt_grd=vrt_grd.nc ifs.nc out.nc
zender@spectral:~$ 
</verbatim>
</example>
<para>The <acronym><acronymword>IFS</acronymword></acronym> file can be horizontally regridded in the same
invocation. 
<command>ncremap</command> automagically handles all of the other details.
Currently <command>ncremap</command> can only interpolate data from (not to) an 
<acronym><acronymword>IFS</acronymword></acronym>-format hybrid vertical grid data file.
To interpolate to an <acronym><acronymword>IFS</acronymword></acronym>-format hybrid vertical grid, one
must place the destination vertical grid into a
<acronym><acronymword>CESM/E3SM</acronymword></acronym>-format hybrid vertical grid file (see above) 
that includes a <code>PS</code> surface pressure field (not <code>lnsp</code>
log-surface pressure) for the destination grid.
</para>
<para>The <code>lev</code> and <code>ilev</code> coordinates of a hybrid grid are
defined by the hybrid coefficients and reference pressure, and are
by convention stored in millibars (not Pascals) as follows:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ilev[ilev]=P0*(hyai+hybi)/100.0;
lev[lev]=P0*(hyam+hybm)/100.0;
</verbatim>
</example>

<para>A vertical hybrid grid file <var>vrt_fl</var> must contain at least
<code>hyai</code>, <code>hybi</code>, <code>hyam</code>, <code>hybm(lev)</code> and
<code>P0</code>; <code>PS</code>, <code>lev</code>, and <code>ilev</code> are optional. 
(Exceptions for <acronym><acronymword>ECMWF</acronymword></acronym> grids are noted above).
All hybrid-coordinate data files must contain <code>PS</code>.
Interpolating a pure-pressure coordinate data file to hybrid
coordinates requires, therefore, that the hybrid-coordinate
<var>vrt_fl</var> must contain <code>PS</code> and/or the input data file
must contain <code>PS</code>.
If both contain <code>PS</code> then the <code>PS</code> from the <var>vrt_fl</var>
takes precedence and will be used to construct the hybrid grid
and then copied without to the output file.
</para>
<para>In all cases <code>lev</code> and <code>ilev</code> are optional in input
hybrid-coordinate data files and vertical grid-files.  
They are diagnosed from the other parameters using the above
definitions. 
The minimal requirements&textmdash;a <code>plev</code> coordinate for a
pure-pressure grid or five parameters for a hybrid grid&textmdash;allow 
vertical gridfiles to be much smaller than horizontal gridfiles
such as <acronym><acronymword>SCRIP</acronymword></acronym> files.
Moreover, data files from <acronym><acronymword>ESM</acronymword></acronym>s or analyses (<acronym><acronymword>NCEP</acronymword></acronym>,
<acronym><acronymword>MERRA2</acronymword></acronym>, <acronym><acronymword>ERA5</acronymword></acronym>) are also valid gridfiles.
The flexibility in gridfile structure makes it easy to intercompare
data from the same or different sources.
</para>
<para><command>ncremap</command> supports vertical interpolation between all
combinations of pure-pressure and hybrid-pressure grids.
The input and output (aka source and destination) pressure grids may
monotonically increase or decrease independently of eachother (i.e.,
one may increase and the other may decrease). 
When an output pressure level is outside the input pressure range
for that column, then all variables must be extrapolated (not
interpolated) to that/those level(s).
By default <command>ncremap</command> sets all extrapolated values to the
nearest valid value.
</para>
<para>Temperature and geopotential height are exceptions to this rule.
Temperature variables (those named <code>T</code> or <code>ta</code>, anyway) are
extrapolated upwards towards space using the nearest neighbor
assumption, and downwards beneath the surface assuming a moist 
adiabatic lapse rate of 6.5 degrees centigrade per 100 millibars.
Geopotential variables (those named <code>Z3</code> or <code>zg</code>, anyway)
are extrapolated upwards and downwards using the hypsometric equation
<footnote><para><math>Z_2-Z_1=(R_d*T_v/g_0)*ln(p_1/p_2)=(R_d*T_v/g_0)*(ln(p_1)-ln(p_2))</math></para></footnote>
<!-- c Z2-Z1=(Rd*Tv/g0)*ln(p1/p2)=(Rd*Tv/g0)*(ln(p1)-ln(p2))}  -->
with constant global mean virtual temperature
<math><var>T</var> = 288</math>K.
This assumption leads to unrealistic values where T differs
significantly from the global mean surface temperature.
Using the local T itself would be a much better approximation,
yet would require a time-consuming implementation.
Please let us know if accurate surface geopotential extrapolation in
cold regions is important to you.
</para>
<para>Interpolation to and from hybrid coordinate grids works on both
midpoint and interface fields (i.e., on variables with <code>lev</code> or
<code>ilev</code> dimensions), while interpolation to and from pure-pressure
grids applies to fields with, or places output of fields on, a
<code>plev</code> dimension.  
All other fields pass through the interpolation procedure unscathed.
Input can be rectangular (aka <acronym><acronymword>RLL</acronymword></acronym>), curvilinear, or
unstructured.  
</para>
<html endspaces=" ">
&lt;a name=&quot;ps_nm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ps_nm --&gt;
&lt;a name=&quot;ps&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ps --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3046"><code>--ps_nm=<var>ps_nm</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3047"><var>ps_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3048"><code>--ps_nm</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3049"><code>PS</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3050">surface pressure</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--ps_nm=<var>ps_nm</var> (<code>--ps_nm</code>, <code>--ps_name</code>, <code>--vrt_ps</code>, <code>--ps</code>)</itemformat></item>
</tableterm><tableitem><para>It is sometimes convenient to store the <var>ps_nm</var> field in
an external file from the field(s) to be regridded.
For example, <acronym><acronymword>CMIP</acronymword></acronym>-style timeseries are often written
with only one variable per file.
<acronym><acronymword>NCO</acronymword></acronym> supports this organization by accepting <var>ps_nm</var>
arguments in the form of a filename followed by a slash and then a
variable name: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap --vrt_in=vrt.nc --ps_nm=ps in.nc out.nc # Use ps not PS
ncremap --vrt_in=vrt.nc --ps_nm=/external/file.nc/ps in.nc out.nc
</pre></example>
<para>This same functionality (of optionally embedding a filename into
the variable name) is also implemented for the <var>sgs_frc</var> variable.
</para>
<html endspaces=" ">
&lt;a name=&quot;ps_rtn&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ps_rtn --&gt;
&lt;a name=&quot;rtn_sfc_prs&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#rtn_sfc_prs --&gt;
&lt;a name=&quot;retain_surface_pressure&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#retain_surface_pressure --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3051"><code>--ps_rtn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3052"><var>ps_nm</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3053"><code>--ps_rtn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3054"><code>--retain_surface_pressure</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3055"><code>--rtn_sfc_prs</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3056">surface pressure, retaining</indexterm></cindex>
<item spaces=" "><itemformat command="samp">--ps_rtn (<code>--ps_rtn</code>, <code>--rtn_sfc_prs</code>, <code>--retain_surface_pressure</code>)</itemformat></item>
</tableterm><tableitem><para>As of <acronym><acronymword>NCO</acronymword></acronym> version 5.1.5 (March, 2023), <command>ncremap</command> 
includes a <code>--ps_rtn</code> switch (with long-option equivalents
<code>--rtn_sfc_prs</code> and <code>--retain_surface_pressure</code>) to
facilitate &textldquo;round-trip&textrdquo; vertical interpolation such as
hybrid-to-pressure followed by pressure-to-hybrid interpolation.
By default <command>ncremap</command> excludes the surface pressure field named
<var>ps_nm</var> from the output after hybrid-to-pressure interpolation. 
The <code>--ps_rtn</code> switch (which takes no argument) instructs the
regridder to retain the surface pressure field after
hybrid-to-pressure interpolation.
The surface pressure field is then available for subsequent
interpolation back to a hybrid vertical coordinate:
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap --ps_rtn --ps_nm=ps --vrt_out=ncep.nc in.nc out_ncep.nc
ncremap --ps_rtn -v T,Q,U,PS --vrt_out=ncep.nc in.nc out_ncep.nc
ncremap --vrt_out=hybrid.nc out_ncep.nc out_hybrid.nc
</pre></example>

<html endspaces=" ">
&lt;a name=&quot;vrt_ntp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_ntp --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3057"><code>--vrt_ntp=<var>vrt_ntp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3058"><var>vrt_ntp</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3059"><code>--vrt_ntp</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3060"><code>--ntp_mth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3061"><code>--interpolation_type</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3062"><code>--interpolation_method</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--vrt_ntp=<var>vrt_ntp</var> (<code>--vrt_ntp</code>, <code>--ntp_mth</code>, <code>--interpolation_type</code>, <code>--interpolation_method</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the interpolation method for destination points within the 
vertical range of the input data during vertical interpolation.
Valid values and their synonyms are
<code>lin</code> (synonyms <code>linear</code> and <code>lnr</code>), and
<code>log</code> (synonyms <code>logarithmic</code> and <code>lgr</code>).
Default is <math><var>vrt_ntp</var> = <code>log</code></math>.
The vertical interpolation algorithm defaults to linear in
log(pressure). 
Logarithmic interpolation is more natural for gases like the
atmosphere, because it is compressible, than for condensed media like
oceans or  Earth&textrsquo;s interior, which are incompressible.
To instead interpolate linearly in the vertical coordinate, use
the <samp>ntp_mth=lin</samp> option.
<acronym><acronymword>NCO</acronymword></acronym> supports this feature as of version 4.9.0 (December,
2019). 
</para>
<html endspaces=" ">
&lt;a name=&quot;vrt_xtr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#vrt_xtr --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3063"><code>--vrt_xtr=<var>vrt_xtr</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3064"><var>vrt_xtr</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3065"><code>--vrt_xtr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3066"><code>--xtr_mth</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3067"><code>--extrapolation_type</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3068"><code>--extrapolation_method</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--vrt_xtr=<var>vrt_xtr</var> (<code>--vrt_xtr</code>, <code>--xtr_mth</code>, <code>--extrapolation_type</code>, <code>--extrapolation_method</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies the extrapolation method for destination points outside the
vertical range of the input data during vertical interpolation.
Valid values and their synonyms are
<code>linear</code> (synonyms <code>lnr</code> and <code>lin</code>), 
<code>mss_val</code> (synonyms <code>msv</code> and <code>missing_value</code>), 
<code>nrs_ngh</code> (synonyms <code>nn</code> and <code>nearest_neighbor</code>), and
<code>zero</code> (synonym <code>nil</code>).
Default is <math><var>vrt_xtr</var> = <code>nrs_ngh</code></math>.
<acronym><acronymword>NCO</acronymword></acronym> supports this feature as of version 4.8.1 (July, 2019).
</para>
<html endspaces=" ">
&lt;a name=&quot;wgt_opt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wgt_opt --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3069"><code>-W <var>wgt_opt</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3070"><var>wgt_opt</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3071"><code>--wgt_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3072"><code>--weight_options</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3073"><code>--tps_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3074"><code>--tempest_options</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3075"><code>--esmf_opt</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3076"><code>--esmf_options</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-W <var>wgt_opt</var> (<code>--wgt_opt</code>, <code>--weight_options</code>, <code>--esmf_opt</code>, <code>--esmf_options</code>, <code>--tps_opt</code>, <code>--tempest_options</code>)</itemformat></item>
</tableterm><tableitem><para><command>ncremap</command> passes <var>wgt_opt</var> directly through to the 
weight-generator (currently <acronym><acronymword>ERWG</acronymword></acronym> or
TempestRemap&textrsquo;s <command>GenerateOfflineMap</command>) (and not to
<command>GenerateOverlapMesh</command>).
The user-specified contents of <var>wgt_opt</var>, if any, supercede the
default contents for the weight-generator.
The default option for <acronym><acronymword>ERWG</acronymword></acronym> is <samp>--ignore_unmapped</samp>).
<command>ncremap</command> 4.7.7 and later additionally set the <acronym><acronymword>ERWG</acronymword></acronym>
<samp>--ignore_degenerate</samp> option, though if the run-time <acronym><acronymword>ERWG</acronymword></acronym>
reports its version is 7.0 (March, 2018) or later. 
This is done to preserve backwards compatibility since, <acronym><acronymword>ERWG</acronymword></acronym>
7.1.0r and later require <samp>--ignore_degenerate</samp> to successfully
regrid some datasets (e.g., <acronym><acronymword>CICE</acronymword></acronym>) that previous <acronym><acronymword>ERWG</acronymword></acronym>
versions handle fine. 
Users of earlier versions of <command>ncremap</command> that call <acronym><acronymword>ESMF</acronymword></acronym>
7.1.0r and later can explicitly pass the base <acronym><acronymword>ERWG</acronymword></acronym> options
with <command>ncremap</command>&textrsquo;s <samp>--esmf_opt</samp> option:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Use when NCO &lt;= 4.7.6 and ERWG &gt;= 7.1.0r
ncremap --esmf_opt='--ignore_unmapped --ignore_degenerate' ...
</verbatim>
</example>

<para>The <acronym><acronymword>ERWG</acronymword></acronym> and TempestRemap documentation shows all available
options. 
For example, to cause <acronym><acronymword>ERWG</acronymword></acronym> to output to a netCDF4 file,  
pass <samp>-W &quot;--netcdf4&quot;</samp> to <command>ncremap</command>.
</para>
<para>By default, <command>ncremap</command> runs <command>GenerateOfflineMap</command> without
any options. 
To cause <command>GenerateOfflineMap</command> to use a <code>_FillValue</code> of
<math>-1</math>, pass <samp>-W '--fillvalue -1.0'</samp> to <command>ncremap</command>.
Other common options include enforcing monotonicity (which is not the
default in TempestRemap) constraints. 
To guarantee monotonicity in regridding from Finite Volume <acronym><acronymword>FV</acronymword></acronym> 
to <acronym><acronymword>FV</acronymword></acronym> maps (e.g., <acronym><acronymword>MPAS</acronymword></acronym>-to-rectangular), pass 
<samp>-W '-in_np 1'</samp> to <command>ncremap</command>.
To guarantee monotonicity in regridding from Finite Element <acronym><acronymword>FE</acronymword></acronym> 
to <acronym><acronymword>FV</acronymword></acronym> maps, pass <samp>-W '--mono'</samp>.
Common sets of specialized options recommended for TempestRemap are
collected into six boutique algorithms invokable with <samp>--alg_typ</samp>
as described above.
</para>
<html endspaces=" ">
&lt;a name=&quot;wgt_cmd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wgt_cmd --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3077"><code>-w <var>wgt_cmd</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3078"><var>wgt_cmd</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3079"><code>--wgt_cmd</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3080"><code>--wgt_gnr</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3081"><code>--weight_command</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3082"><code>--weight_generator</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-w <var>wgt_cmd</var> (<code>--wgt_cmd</code>, <code>--weight_command</code>, <code>--wgt_gnr</code>, <code>--weight_generator</code>)</itemformat></item>
</tableterm><tableitem><para>Specifies a (possibly extended) command to use to run the
weight-generator when a map-file is not provided.  
This command overrides the default executable executable for the
weight generator, which is <command>ESMF_RegridWeightGen</command> for
<acronym><acronymword>ESMF</acronymword></acronym> and <command>GenerateOfflineMap</command> for TempestRemap.
(There is currently no way to override <command>GenerateOverlapMesh</command>  
for TempestRemap). 
The <var>wgt_cmd</var> must accept the same arguments as the default
command. 
Examples include <samp>mpirun -np 24 ESMF_RegridWeightGen</samp>,
<samp>mpirun-openmpi-mp -np 16 ESMF_RegridWeightGen</samp>, and other
ways of exploiting parallelism that are system-dependent.
Specifying <var>wgt_cmd</var> and supplying (with <samp>-m</samp>) a map-file
is not permitted (since the weight-generator would not be used).
</para>
<html endspaces=" ">
&lt;a name=&quot;xcl_var&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xcl_var --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3083"><code>--xcl_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3084"><code>--xcl</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3085"><code>--exclude</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3086"><code>--exclude_variables</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">--xcl_var (<code>--xcl_var</code>, <code>--xcl</code>, <code>--exclude</code>, <code>--exclude_variables</code>)</itemformat></item>
</tableterm><tableitem><para>This flag (which takes no argument) changes <var>var_lst</var>,
as set by the <code>--var_lst</code> option, from an extraction list to an
exclusion list so that variables in <var>var_lst</var> will not be
processed, and variables not in <var>var_lst</var> will be processed.
Thus the option <samp>-v <var>var_lst</var></samp> must also be present for this
flag to take effect.
Variables explicitly specified for exclusion by
<samp>--xcl --vars=<var>var_lst</var>[,&dots;]</samp> need not be present in the
input file.
</para>
<html endspaces=" ">
&lt;a name=&quot;xtn_lst&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xtn_lst --&gt;
</html>
</tableitem></tableentry><tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3087"><code>-v <var>xtn_lst</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3088"><var>xtn_lst</var></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3089"><code>--xtn_lst</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3090"><code>--xtn_var</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3091"><code>--var_xtn</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3092"><code>--extensive</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3093"><code>--extensive_variables</code></indexterm></cindex>
<item spaces=" "><itemformat command="samp">-x <var>xtn_lst</var> (<code>--xtn_lst</code>, <code>--xtn_var</code>, <code>--var_xtn</code>, <code>--extensive</code>, <code>--extensive_variables</code>)</itemformat></item>
</tableterm><tableitem><para>The <samp>-x</samp> option causes <command>ncremap</command> to treat the variables in
<var>xtn_lst</var> as <dfn>extensive</dfn>, meaning that their value depends on
the gridcell boundaries. 
Support for extensive variables during regridding is nascent.
Currently variables marked as extensive are summed, not regridded.
We are interested in &textldquo;real-world&textrdquo; situations that require regridding
extensive variables, please contact us if you have one.
</para>
</tableitem></tableentry></table>

</unnumberedsubsec>
<unnumberedsubsec spaces=" "><sectiontitle>Limitations to <command>ncremap</command></sectiontitle>

<para><command>ncremap</command> has two significant limitations to be aware of.
First, for two-dimensional input grids the fields to be regridded must
have latitude and longitude, or, in the case of curvilinear data, the
two equivalent horizontal dimensions, as the final two dimensions in
<var>in_fl</var>.
Fields with other dimension orders (e.g., <samp>lat,lev,lon</samp>) will not
regrid properly. 
To circumvent this limitation one can employ 
<command>ncpdq</command> (<pxref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></pxref>)
to permute the dimensions before (and un-permute them after) regridding.
<command>ncremap</command> utilizes this method internally for some common
input grids.
For example,
</para><example endspaces=" ">
<pre xml:space="preserve"># AIRS Level2 vertical profiles
ncpdq -a StdPressureLev,GeoTrack,GeoXTrack AIRS_L2.hdf AIRS_L2_ncpdq.nc
ncremap -i AIRS_L2_ncpdq.nc -d dst_1x1.nc -O ~/rgr
# MPAS-O fields
ncpdq -a Time,nVertLevels,maxEdges,MaxEdges2,nEdges,nCells mpas.nc mpas_ncpdq.nc
ncremap -R &quot;--rgr col_nm=nCells&quot; -i mpas_ncpdq.nc -m mpas120_to_t62.nc -O ~/rgr
</pre></example>
<noindent></noindent>
<para>The previous two examples occur so frequently that <command>ncremap</command> has
been specially equipped to handle <acronym><acronymword>AIRS</acronymword></acronym> and <acronym><acronymword>MPAS</acronymword></acronym>
files. 
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.5.5 (February, 2016), the following
<command>ncremap</command> commands with the <samp>-P <var>prc_typ</var></samp> option
automagically perform all required permutation and renaming necessary: 
</para><example endspaces=" ">
<pre xml:space="preserve"># AIRS Level2 vertical profiles
ncremap -P airs -i AIRS_L2.nc -d dst_1x1.nc -O ~/rgr
# MPAS-O/I fields
ncremap -P mpas -i mpas.nc -m mpas120_to_t62.nc -O ~/rgr
</pre></example>
<noindent></noindent>
<para>The machinery to handle permutations and special options for other
datafiles is relatively easy to extend with new <var>prc_typ</var> options. 
If you work with common datasets that could benefit from their own
pre-processing options, contact us and we will try to implement them.  
</para>
<para>The second limitation is that to perform regridding, <command>ncremap</command>
must read weights from an on-disk mapfile, and cannot yet compute
weights itself and use them directly from <acronym><acronymword>RAM</acronymword></acronym>.  
This makes <command>ncremap</command> an &textldquo;offline regridder&textrdquo; and unnecessarily
slow compared to an &textldquo;integrated regridder&textrdquo; that computes weights and
immediately applies them in <acronym><acronymword>RAM</acronymword></acronym> without any disk-access.
In practice, the difference is most noticeable when the weights are 
easily computable &textldquo;on the fly&textrdquo;, e.g., rectangular-to-rectangular
mappings. 
Otherwise the weight-generation takes much more time than the
weight-application, at which <command>ncremap</command> is quite fast.
As of <acronym><acronymword>NCO</acronymword></acronym> <w>version 4.9.0</w>, released in December, 2019,
regridder supports generation of intersection grids and overlap
weights for all finite volume grid combinations.
However these weights are first stored in an offline mapfile, are not
usable otherwise.
</para>
<para>One side-effect of <command>ncremap</command> being an offline regridder is
that, when necessary, it can generate files to store intermediate
versions of grids, maps, and data. 
These files are named, by default, 
<file>ncremap_tmp_att.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>,
<file>ncremap_tmp_d2f.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>,
<file>ncremap_tmp_grd_dst.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>,
<file>ncremap_tmp_grd_src.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>,
<file>ncremap_tmp_gnr_out.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>,
<file>ncremap_tmp_map_*.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>,
<file>ncremap_tmp_msh_ovr_*.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>, and
<file>ncremap_tmp_pdq.nc</file><file>$&lbrace;unq_sfx&rbrace;</file>.
They are placed in <var>drc_out</var> with the output file(s).
In general, no intermediate grid or map files are generated when the
map-file is provided. 
Intermediate files are always generated when the <samp>-P <var>prm_typ</var></samp>
option is invoked. 
By default these files are automatically removed upon successful
completion of the script, unless <command>ncremap</command> was invoked by
<samp>--unq_sfx=noclean</samp> to explitly override this &textldquo;self-cleaning&textrdquo;
behavior.  
Nevertheless, early or unexpected termination of <command>ncremap</command>
will almost always leave behind a collection of these intermediate
files.
Should intermediate files proliferate and/or annoy you, locate and/or
remove all such files under the current directory with 
</para><example endspaces=" ">
<pre xml:space="preserve">find . -name 'ncremap_tmp*'
rm `find . -name 'ncremap_tmp*'`
</pre></example>
<noindent></noindent>

<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncremap&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncremap --&gt;
</html>
<para>EXAMPLES
</para>
<para>Regrid input file <file>in.nc</file> to the spatial grid in file <file>dst.nc</file>
and write the output to <file>out.nc</file>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -d dst.nc in.nc out.nc
ncremap -d dst.nc -i in.nc -o out.nc
ncremap -d dst.nc -O regrid in.nc out.nc
ncremap -d dst.nc in.nc regrid/out.nc
ncremap -d dst.nc -O regrid in.nc # output named in.nc
</pre></example>
<noindent></noindent>
<para><acronym><acronymword>NCO</acronymword></acronym> infers the destination spatial grid from <file>dst.nc</file> by
reading its coordinate variables and <acronym><acronymword>CF</acronymword></acronym> attributes.
In the first example, <command>ncremap</command> places the output in
<file>out.nc</file>.
In the second and third examples, the output file is
<file>regrid/out.nc</file>. 
In the fourth example, <command>ncremap</command> places the output in the
specified output directory.
Since no output filename is provided, the output file will be named
<file>regrid/in.nc</file>.
</para>
<para>Generate a mapfile with <command>ncremap</command> and store it for later re-use. 
A pre-computed mapfile (supplied with <samp>-m <var>map_fl</var></samp>) eliminates 
time-consuming weight-generation, and thus considerably reduces
wallclock time: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -m map.nc in.nc out.nc
ncremap -m map.nc -I drc_in -O regrid
</pre></example>

<para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.7.2 (January, 2018), <command>ncremap</command>
supports &textldquo;canonical&textrdquo; argument ordering of command line arguments most
frequently desired for one-off regridding, where a single input and
output filename are supplied as command-line positional arguments
without switches, pipes, or redirection: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -m map.nc in.nc out.nc # Requires 4.7.2+
ncremap -m map.nc -i in.nc -o out.nc
ncremap -m map.nc -o out.nc in.nc
ncremap -m map.nc -O out_dir in1.nc in2.nc
ncremap -m map.nc -o out.nc &lt; in.nc
ls in.nc | ncremap -m map.nc -o out.nc
</pre></example>
<para>These are all equivalent methods, but the canonical ordering shown in
the first example only works in <acronym><acronymword>NCO</acronymword></acronym> version 4.7.2 and later.
</para>
<para><command>ncremap</command> annotates the gridfiles and mapfiles that it creates
with helpful metadata containing the full provenance of the command.
Consequently, <command>ncremap</command> is a sensible tool for generating
mapfiles for later use. 
To generate a mapfile with the specified (non-default) name
<file>map.nc</file>, and then regrid a single file, 
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -d dst.nc -m map.nc in.nc out.nc
</pre></example>

<para>To test the remapping workflow, regrid only one or a few variables
instead of the entire file:  
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -v T,Q,FSNT -m map.nc in.nc out.nc
</pre></example>
<para>Regridding generally scales linearly with the size of data to be
regridded, so eliminating unnecessary variables produces a snappier
response.  
</para>
<para>Regrid multiple input files with a single mapfile <file>map.nc</file> 
and write the output to the <file>regrid</file> directory:
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -m map.nc -I drc_in -O regrid
ls drc_in/*.nc | ncremap -m map.nc -O regrid
</pre></example>
<noindent></noindent>
<para>The three ways <acronym><acronymword>NCO</acronymword></acronym> obtains the destination spatial grid are,
in decreasing order of precedence, 
from <var>map_fl</var> (specified with <samp>-m</samp>), 
from <var>grd_dst</var> (specified with <samp>-g</samp>), and
(inferred) from <var>dst_fl</var> (specified with <samp>-d</samp>).
In the first example all likely data files from <var>drc_in</var> are
regridded using the same specified mapfile, <var>map_fl</var> = <file>map.nc</file>.
Each output file is written to <var>drc_out</var> = <file>regrid</file> with the
same name as the corresponding input file.
The second example obtains the input file list from standard input,
and uses the mapfile and output directory as before.
</para>
<para>If multiple input files are on the same grid, yet the mapfile does not
exist in advance, one can still regrid all input files without incurring
the time-penalty of generating multiple mapfiles. 
To do so, provide the (known-in-advance) source gridfile or toggle the
<samp>-M</samp> switch: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -M -I drc_in -d dst.nc -O regrid
ls drc_in/*.nc | ncremap -M -d dst.nc -O regrid
ncremap -I drc_in -s grd_src.nc -d dst.nc -O regrid
ls drc_in/*.nc | ncremap -s grd_src.nc -d dst.nc -O regrid
ncremap -I drc_in -s grd_src.nc -g grd_dst.nc -O regrid
ls drc_in/*.nc | ncremap -s grd_src.nc -g grd_dst.nc -O regrid
</pre></example>
<noindent></noindent>
<para>The first two examples explicitly toggle the multi-map-generation switch
(with <samp>-M</samp>), so that <command>ncremap</command> refrains from generating
multiple mapfiles. 
In this case the source grid is inferred from the first input file,
the destination grid is inferred from <file>dst.nc</file>, and
<command>ncremap</command> uses <acronym><acronymword>ERWG</acronymword></acronym> to generate a single mapfile and
uses that to regrid every input file.
The next four examples are variants on this theme.
In these cases, the user provides (with <samp>-s grd_src.nc</samp>) the source  
gridfile, which will be used directly instead of being inferred.
Any of these styles works well when each input file is known in advance
to be on the same grid, e.g., model data for successive time periods in
a simulation. 
</para>
<para>The most powerful, time-consuming (yet simultaneously time-saving!)
feature of <command>ncremap</command> is its ability to regrid multiple input
files on unique grids.
Both input and output can be on any <acronym><acronymword>CRUD</acronymword></acronym> grid.
</para><example endspaces=" ">
<pre xml:space="preserve">ncremap -I drc_in -d dst.nc -O regrid
ls drc_in/*.nc | ncremap -d dst.nc -O regrid
ncremap -I drc_in -g grd_dst.nc -O regrid
ls drc_in/*.nc | ncremap -g grd_dst.nc -O regrid
</pre></example>
<noindent></noindent>
<para>There is no pre-supplied <var>map_fl</var> or <var>grd_src</var> in these
examples, so <command>ncremap</command> first infers the output grid from
<file>dst.nc</file> (first two examples), or directly uses the supplied
gridfile <file>grd_dst</file> (second two examples), and calls <acronym><acronymword>ERWG</acronymword></acronym>
to generate a new mapfile for each input file, whose grid it infers.
This is necessary when each input file is on a unique grid, e.g.,
swath-like data from satellite observations or models with time-varying
grids. 
These examples require remarkably little input, since <command>ncremap</command>
automates most of the work.
</para>
<para>Finally, <command>ncremap</command> uses the parallelization options 
<samp>-p <var>par_typ</var></samp> and <samp>-j <var>job_nbr</var></samp> to help manage
high-volume workflow. 
On a single node such as a local workstation, use Background mode
to regrid multiple files in parallel
</para><example endspaces=" ">
<pre xml:space="preserve">ls drc_in/*.nc | ncremap -p bck -d dst.nc -O regrid
ls drc_in/*.nc | ncremap -p bck -j 4 -d dst.nc -O regrid
</pre></example>
<noindent></noindent>
<para>Both examples will eventually regrid all input files.
The first example regrids two at a time because two is the default
batch size <command>ncremap</command> employs.
The second example regrids files in batches of four at a time.
Increasing <var>job_nbr</var> will increase throughput so long as the node
is not I/O-limited.
</para>
<para>Multi-node clusters can exploit inter-node parallelism in
<acronym><acronymword>MPI</acronymword></acronym>-mode:
</para><example endspaces=" ">
<pre xml:space="preserve">qsub -I -A CLI115 -V -l nodes=4 -l walltime=03:00:00 -N ncremap
ls drc_in/*.nc | ncremap -p mpi -j 4 -d dst.nc -O regrid
</pre></example>
<noindent></noindent>
<para>This example shows a typical request for four compute nodes.
After receiving the login prompt from the interactive master node,
execute the <command>ncremap</command> command with <samp>-p mpi</samp>.
<command>ncremap</command> will send regridding jobs in round-robin fashion
to all available compute nodes until all jobs finish.
It does this by internally prepending an <acronym><acronymword>MPI</acronymword></acronym> execution
command, like <samp>mpirun -H <var>node_name</var> -npernode 1 -n 1</samp>,
to the usual regridding command.
<acronym><acronymword>MPI</acronymword></acronym>-mode typically has excellent scaling because most
nodes have independent access to hard storage.
This is the easiest way to speed your cumbersome job by factors
of ten or more.
As mentioned above under Limitations, parallelism is currently only
supported when all regridding uses the same map-file.
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncrename&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncrename --&gt;
</html>
</unnumberedsubsec>
</section>
<node name="ncrename-netCDF-Renamer" spaces=" "><nodename>ncrename netCDF Renamer</nodename><nodenext spaces=" ">ncwa netCDF Weighted Averager</nodenext><nodeprev spaces=" ">ncremap netCDF Remapper</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncrename</command> netCDF Renamer</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3094">renaming variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3095">renaming groups</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3096">renaming dimensions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3097">renaming attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3098">variable names</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3099">dimension names</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3100">attribute names</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3101">group names</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="44" mergedindex="cp">ncrename</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncrename [-a <var>old_name</var>,<var>new_name</var>] [-a &dots;] [-D <var>dbg</var>] 
[-d <var>old_name</var>,<var>new_name</var>] [-d &dots;] [-g <var>old_name</var>,<var>new_name</var>] [-g &dots;] 
[--glb ...] [-H] [-h] [--hdf] [--hdr_pad <var>nbr</var>] [--hpss] 
[-l <var>path</var>] [-O] [-o <var>output-file</var>] [-p <var>path</var>] [-R] [-r] 
[-v <var>old_name</var>,<var>new_name</var>] [-v &dots;]
<var>input-file</var> [[<var>output-file</var>]]
</pre></example>
 
<noindent></noindent>
<para>DESCRIPTION
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3102"><kbd>.</kbd></indexterm></cindex>
<para><command>ncrename</command> renames netCDF dimensions, variables, attributes, and
groups. 
Each object that has a name in the list of old names is renamed using
the corresponding name in the list of new names. 
All the new names must be unique. 
Every old name must exist in the input file, unless the old name is
preceded by the period (or &textldquo;dot&textrdquo;) character <samp>.</samp>. 
The validity of <var>old_name</var> is not checked prior to the renaming. 
Thus, if <var>old_name</var> is specified without the <samp>.</samp> prefix that
indicates the presence of <var>old_name</var> is optional, and <var>old_name</var>  
is not present in <var>input-file</var>, then <command>ncrename</command> will abort.  
The <var>new_name</var> should never be prefixed by a <samp>.</samp> (or else the
period will be included as part of the new name).
As of <acronym><acronymword>NCO</acronymword></acronym> version 4.4.6 (released October, 2014), the
<var>old_name</var> and <var>new_name</var> arguments may include (or be, for
groups) partial or full group paths. 
The OPTIONS and EXAMPLES show how to select specific variables
whose attributes are to be renamed.
</para>
<html endspaces=" ">
&lt;a name=&quot;bug_nc4_rename&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bug_nc4_rename --&gt;
</html>
<cartouche endspaces=" ">
<para>Caveat lector: Unforunately from 2007&textndash;present (August, 2023) the
netCDF library (versions 4.0.0&textndash;4.9.3) contains bugs or limitations
that sometimes prevent <acronym><acronymword>NCO</acronymword></acronym> from correctly renaming coordinate
variables, dimensions, and groups in netCDF4 files. 
(To our knowledge the netCDF library calls for renaming always work
well on netCDF3 files so one workaround to many netCDF4 issues is
convert to netCDF3, rename, then convert back). 
To understand the renaming limitations associated with particular
netCDF versions, read the <command>ncrename</command> documentation below in 
its entirety. 
</para></cartouche>

<para>Although <command>ncrename</command> supports full pathnames for both
<var>old_name</var> and <var>new_name</var>, this is really &textldquo;window dressing&textrdquo;.
The full-path to <var>new_name</var> must be identical to the full-path to 
<var>old_name</var> in all classes of objects (attributes, variables,
dimensions, or groups).
In other words, <command>ncrename</command> can change only the local names
of objects, it cannot change the location of the object in the group
hierarchy within the file.
Hence using a full-path in <var>new_name</var> is redundant. 
The object name is the terminal path component of <var>new_name</var> and
this object must already exist in the group specified by the 
<var>old_name</var> path.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3103">data safety</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3104">safeguards</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3105">temporary output files</indexterm></cindex>
<para><command>ncrename</command> is an exception to the normal <acronym><acronymword>NCO</acronymword></acronym> rule that
the user will be interactively prompted before an existing file is
changed, and that a temporary copy of an output file is constructed
during the operation. 
If only <var>input-file</var> is specified, then <command>ncrename</command> changes
object names in the <var>input-file</var> in place without prompting and
without creating a temporary copy of <code>input-file</code>.
This is because the renaming operation is considered reversible if the
user makes a mistake.
The <var>new_name</var> can easily be changed back to <var>old_name</var> by using 
<command>ncrename</command> one more time.
</para>
<para>Note that renaming a dimension to the name of a dependent variable can
be used to invert the relationship between an independent coordinate
variable and a dependent variable. 
In this case, the named dependent variable must be one-dimensional and
should have no missing values. 
Such a variable will become a coordinate variable.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3106">performance</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3107">operator speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3108">speed</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3109">execution time</indexterm></cindex>
<para>According to the <cite>netCDF User Guide</cite>, renaming objects in netCDF
files does not incur the penalty of recopying the entire file when the
<var>new_name</var> is shorter than the <var>old_name</var>. 
Thus <command>ncrename</command> may run much faster (at least on netCDF3 files)
if judicious use of header padding (<pxref label="Metadata-Optimization"><xrefnodename>Metadata Optimization</xrefnodename></pxref>) was
made when producing the <var>input-file</var>.
Similarly, using the <samp>--hdr_pad</samp> option with <command>ncrename</command>
helps ensure that future metadata changes to <var>output-file</var> occur
as swifly as possible.
</para>
<noindent></noindent>
<para>OPTIONS
</para>
<table commandarg="samp" spaces=" " endspaces=" ">
<tableentry><tableterm><item spaces=" "><itemformat command="samp">-a <var>old_name</var>,<var>new_name</var></itemformat></item>
</tableterm><tableitem><para>Attribute renaming. 
The old and new names of the attribute are specified with <samp>-a</samp>
(or <samp>--attribute</samp>) by the associated <var>old_name</var> and
<var>new_name</var> values.  
<cindex index="cp" spaces=" "><indexterm index="cp" number="3110"><code>global</code> attribute</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3111">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3112">attributes, global</indexterm></cindex>
Global attributes are treated no differently than variable attributes.
This option may be specified more than once.
As mentioned above, all occurrences of the attribute of a given name
will be renamed unless the <samp>.</samp> form is used, with one exception.
To change the attribute name for a particular variable, specify 
the <var>old_name</var> in the format <var>old_var_name&arobase;old_att_name</var>.
The <samp>&arobase;</samp> symbol delimits the variable from the attribute name.
If the attribute is uniquely named (no other variables contain the
attribute) then the <var>old_var_name&arobase;old_att_name</var> syntax is
redundant. 
The <var>old_var_name</var> variable names <code>global</code> and <code>group</code>
have special significance.
They indicate that <var>old_att_nm</var> should only be renamed where it
occurs as a global (i.e., root group) metadata attribute (for
<code>global</code>), or (for <code>group</code>) as <emph>any</emph> group attribute, and
not where it occurs as a variable attribute.
The <var>var_name&arobase;att_name</var> syntax is accepted, though not required,
for the <var>new_name</var>.
</para>
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">-d <var>old_name</var>,<var>new_name</var></itemformat></item>
</tableterm><tableitem><para>Dimension renaming. 
The old and new names of the dimension are specified with <samp>-d</samp>
(or <samp>--dmn</samp>, <samp>--dimension</samp>) by the associated <var>old_name</var>
and <var>new_name</var> values.  
This option may be specified more than once.
</para> 
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">-g <var>old_name</var>,<var>new_name</var></itemformat></item>
</tableterm><tableitem><para>Group renaming. 
The old and new names of the group are specified with <samp>-g</samp>
(or <samp>--grp</samp>, <samp>--group</samp>) by the associated <var>old_name</var>
and <var>new_name</var> values.  
This option may be specified more than once.
This functionality is only available in <acronym><acronymword>NCO</acronymword></acronym> version 4.3.7
(October, 2013) or later, and only when built on netCDF library version
4.3.1-rc1 (August, 2013) or later. 
</para> 
</tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="samp">-v <var>old_name</var>,<var>new_name</var></itemformat></item>
</tableterm><tableitem><para>Variable renaming. 
The old and new names of the variable are specified with <samp>-v</samp>
(or <samp>--variable</samp>) by the associated <var>old_name</var> and
<var>new_name</var> values.  
This option may be specified more than once.
</para></tableitem></tableentry></table>

<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncrename&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncrename --&gt;
</html>
<para>EXAMPLES
</para>
<para>Rename the variable <code>p</code> to <code>pressure</code> and <code>t</code> to
<code>temperature</code> in netCDF <file>in.nc</file>. 
In this case <code>p</code> must exist in the input file (or
<command>ncrename</command> will abort), but the presence of <code>t</code> is optional:
</para><example endspaces=" ">
<pre xml:space="preserve">ncrename -v p,pressure -v .t,temperature in.nc
</pre></example>

<para>Rename the attribute <code>long_name</code> to <code>largo_nombre</code> in the
variable <code>u</code>, and no other variables in netCDF <file>in.nc</file>. 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncrename -a u@long_name,largo_nombre in.nc
</verbatim>
</example>
 
<para>Rename the group <code>g8</code> to <code>g20</code> in netCDF4 file
<file>in_grp.nc</file>:   
</para><example endspaces=" ">
<pre xml:space="preserve">ncrename -g g8,g20 in_grp.nc
</pre></example>
 
<para>Rename the variable <code>/g1/lon</code> to <code>longitude</code> in netCDF4
<file>in_grp.nc</file>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncrename -v /g1/lon,longitude in_grp.nc
ncrename -v /g1/lon,/g1/longitude in_grp.nc # Alternate
</pre></example>
 
<html endspaces=" ">
&lt;a name=&quot;ncrename_crd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncrename_crd --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3113">coordinate variables</indexterm></cindex>
<para><command>ncrename</command> does not automatically attach dimensions to variables of
the same name.
This is done to make renaming an easy way to change whether a variable
is a coordinate.
If you want to rename a coordinate variable so that it remains a
coordinate variable, you must separately rename both the dimension and
the variable: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncrename -d lon,longitude -v lon,longitude in.nc
</pre></example>
<para>Unfortunately, the netCDF4 library had a longstanding bug (all versions
until 4.3.1-rc5 released in December, 2013) that crashed <acronym><acronymword>NCO</acronymword></acronym>
when performing this operation. 
Simultaneously renaming variables and dimensions in netCDF4 files with
earlier versions of netCDF is impossible; it must instead be done in two 
separate <command>ncrename</command> invocations (e.g., first rename the
variable, then rename the dimension) to avoid triggering the libary
bug. 
</para>
<para>A related bug causes unintended side-effects with <command>ncrename</command> 
also built with all versions of the netCDF4 library until 4.3.1-rc5
released in December, 2013):
This bug caused renaming <emph>either</emph> a dimension <emph>or</emph> its
associated coordinate variable (not both, which would fail as above) in
a netCDF4 file to inadvertently rename both:
</para><example endspaces=" ">
<pre xml:space="preserve"># Demonstrate bug in netCDF4/HDF5 library prior to netCDF-4.3.1-rc5
ncks -O -h -m -M -4 -v lat_T42 ~/nco/data/in.nc ~/foo.nc
ncrename -O -v lat_T42,lat ~/foo.nc ~/foo2.nc # Also renames dimension
ncrename -O -d lat_T42,lat ~/foo.nc ~/foo2.nc # Also renames variable
</pre></example>
<para>To avoid this faulty behavior, either build <acronym><acronymword>NCO</acronymword></acronym> with netCDF
version 4.3.1-rc5 or later, or convert the file to netCDF3 first,
then rename as intended, then convert back.
Unforunately while this bug and the related coordinate renaming bug 
were fixed in 4.3.1-rc5 (released in December, 2013), a new and related
bug was discovered in October 2014.
</para>
<para>Another netCDF4 bug that causes unintended side-effects with
<command>ncrename</command> affects (at least) versions 4.3.1&textndash;4.3.2 and all 
snapshots of the netCDF4 library until January, 2015.
This bug (fixed in 4.3.3 in February, 2015) corrupts values or renamed
netCDF4 coordinate variables (i.e., variables with underlying dimensions
of the same name) and other (non-coordinate) variables that include an
underlying dimension that was renamed. 
In other words, <emph>renaming</emph> coordinate variables and dimensions
succeeds yet it corrupts the values contained by the affected array
variables. 
This bug corrupts affected variables by replacing their values with the
default <code>_FillValue</code> for that variable&textrsquo;s type: 
</para><example endspaces=" ">
<pre xml:space="preserve"># Demonstrate bug in netCDF4 libraries prior to version 4.3.3
ncks -O -4 -C -M -v lat ~/nco/data/in.nc ~/bug.nc
ncrename -O -v lat,tal ~/bug.nc ~/foo.nc # Broken until netCDF-4.3.3
ncrename -O -d lat,tal ~/bug.nc ~/foo.nc # Broken until netCDF-4.3.3
ncrename -O -d lat,tal -v lat,tal ~/bug.nc ~/foo.nc # Broken too
ncks ~/foo.nc
</pre></example>
<para>To avoid this faulty behavior, either build <acronym><acronymword>NCO</acronymword></acronym> with netCDF 
version 4.3.3 or later, or convert the file to netCDF3 first, then
rename as intended, then convert back.  
This bug does not affect renaming of groups or of attributes.
</para>
<para>Yet another netCDF4 bug that causes unintended side-effects with
<command>ncrename</command> affects only snapshots from January&textndash;February, 2015,
and released version 4.3.3 (February, 2015).
It was fixed in (and was the reason for releasing) netCDF version
4.3.3.1 (March, 2015). 
This bug causes renamed attributes of coordinate variables in netCDF4 
to files to disappear: 
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Demonstrate bug in netCDF4 library version 4.3.3
ncrename -O -h -a /g1/lon@units,new_units ~/nco/data/in_grp.nc ~/foo.nc 
ncks -v /g1/lon ~/foo.nc # Shows units and new_units are both gone
</verbatim>
</example>

<para>Clearly, renaming coordinates in netCDF4 files is non-trivial.
The penultimate chapter in this saga is a netCDF4 bug discovered in
September, 2015, and present in versions 4.3.3.1 (and possibly earlier 
versions too) and later.
As of this writing (February, 2018), this bug is still present in netCDF4
version 4.6.0.1-development. 
This bug causes <command>ncrename</command> to create corrupted output files
when attempting to rename two or more dimensions simultaneously.
The workaround is to rename the dimensions sequentially, in two separate  
<command>ncrename</command> calls.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Demonstrate bug in netCDF4 library versions 4.3.3.1--4.6.1+
ncrename -O -d lev,z -d lat,y -d lon,x ~/nco/data/in_grp.nc ~/foo.nc # Completes but file is unreadable
ncks -v one ~/foo.nc # File is unreadable (multiple dimensions with same ID?)
</verbatim>
</example>

<para>A new netCDF4 renaming bug was discovered in March, 2017.
It is present in versions 4.4.1&textndash;4.6.0 (and possibly earlier versions).
This bug was fixed in netCDF4 version 4.6.1 (Yay Ed!). 
This bug caused <command>ncrename</command> to fail to rename a variable when the
result would become a coordinate.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Demonstrate bug in netCDF4 library versions 4.4.1--4.6.0
ncrename -O -v non_coord,coord ~/nco/data/in_grp.nc ~/foo.nc # Fails (HDF error)
</verbatim>
</example>
<para>The fix is to upgrade to netCDF version 4.6.1.
The workaround is to convert to netCDF3, then rename, then convert back
to netCDF4.
</para>
<para>A potentially new netCDF4 bug was discovered in November, 2017 and is
now fixed.
It is present in versions 4.4.1.1&textndash;4.6.0 (and possibly earlier versions too).
This bug causes <command>ncrename</command> to fail to rename a variable when the
result would become a coordinate.
Oddly this issue shows that simultaneously renaming a dimension and
coordinate can succeed (in contrast to a bug described above), and that
separating that into two steps can fail.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Demonstrate bug in netCDF4 library versions 4.4.1--4.6.0
# 20171107: https://github.com/Unidata/netcdf-c/issues/597
# Create test dataset
ncks -O -C -v lon ~/nco/data/in_grp.nc ~/in_grp.nc
ncks -O -x -g g1,g2 ~/in_grp.nc ~/in_grp.nc
# Rename dimension then variable
ncrename -d lon,longitude ~/in_grp.nc # works
ncrename -v lon,longitude ~/in_grp.nc # borken &quot;HDF error&quot;
# Rename variable then dimension
ncrename -v lon,longitude ~/in_grp.nc # works
ncrename -d lon,longitude ~/in_grp.nc # borken &quot;nc4_reform_coord_var: Assertion `dim_datasetid &gt; 0' failed.&quot;
# Oddly renaming both simultaneously works:
ncrename -d lon,longitude -v lon,longitude ~/in_grp.nc # works
</verbatim>
</example>
<para>The fix is to upgrade to netCDF version 4.6.1.
The workaround is to convert to netCDF3, then rename, then convert back
to netCDF4.
</para>
<para>A new netCDF3 bug was discovered in April, 2018 and is now fixed.
It is present in netCDF versions 4.4.1&textndash;4.6.0 (and possibly earlier versions too).
This bug caused <command>ncrename</command> to fail to rename many coordinates
and dimensions simultaneously.
This bug affects netCDF3 <code>64BIT_OFFSET</code> files and possibly other
formats as well.
As such it is the first and so far only bug we have identified that
affects netCDF3 files.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
cp /glade/scratch/gus/GFDL/exp/CM3_test/pp/0001/0001.land_month_crop.AllD.nc ~/correa_in.nc   
ncrename -O -d grid_xt,lon -d grid_yt,lat -v grid_xt,lon -v grid_yt,lat \
         -v grid_xt_bnds,lon_bnds -v grid_yt_bnds,lat_bnds ~/correa_in.nc ~/correa_out.nc 
</verbatim>
</example>
<para>The fix is to upgrade to netCDF version 4.6.1.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3114">global attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3115">group attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3116">attributes, global</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3117"><code>_FillValue</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3118"><code>missing_value</code></indexterm></cindex>
<para>Create netCDF <file>out.nc</file> identical to <file>in.nc</file> except the
attribute <code>_FillValue</code> is changed to <code>missing_value</code>, 
the attribute <code>units</code> is changed to <code>CGS_units</code> (but only in
those variables which possess it), the attribute <code>hieght</code> is
changed to <code>height</code> in the variable <code>tpt</code>, and in the
variable <code>prs_sfc</code>, if it exists.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncrename -a _FillValue,missing_value -a .units,CGS_units \
  -a tpt@hieght,height -a prs_sfc@.hieght,height in.nc out.nc 
</verbatim>
</example>
<para>The presence and absence of the <samp>.</samp> and <samp>&arobase;</samp> features
cause this command to execute successfully only if a number of 
conditions are met. 
All variables <emph>must</emph> have a <code>_FillValue</code> attribute <emph>and</emph> 
<code>_FillValue</code> must also be a global attribute.
The <code>units</code> attribute, on the other hand, will be renamed to
<code>CGS_units</code> wherever it is found but need not be present in
the file at all (either as a global or a variable attribute).
The variable <code>tpt</code> must contain the <code>hieght</code> attribute.
The variable <code>prs_sfc</code> need not exist, and need not contain the
<code>hieght</code> attribute.
</para>
<para>Rename the global or group attribute <code>Convention</code> to
<code>Conventions</code>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ncrename -a Convention,Conventions  in.nc # Variable and group atts.
ncrename -a .Convention,Conventions in.nc # Variable and group atts.
ncrename -a @Convention,Conventions  in.nc # Group atts. only
ncrename -a @.Convention,Conventions in.nc # Group atts. only
ncrename -a global@Convention,Conventions   in.nc # Group atts. only
ncrename -a .global@.Convention,Conventions in.nc # Group atts. only
ncrename -a global@Convention,Conventions   in.nc # Global atts. only
ncrename -a .global@.Convention,Conventions in.nc # Global atts. only
</verbatim>
</example>
<para>The examples without the <code>&arobase;</code> character attempt to change the
attribute name in both Global or Group and variable attributes.
The examples with the <code>&arobase;</code> character attempt to change only 
global and group <code>Convention</code> attributes, and leave unchanged any
<code>Convention</code> attributes attached directly to variables.
Attributes prefixed with a period (<code>.Convention</code>) need not be
present. 
Attributes not prefixed with a period (<code>Convention</code>) must be
present. 
Variables prefixed with a period (<code>.</code> or <code>.global</code>) need not 
be present.  
Variables not prefixed with a period (<code>global</code>) must be present.  
</para>
<page></page>
<html endspaces=" ">
&lt;a name=&quot;ncwa&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ncwa --&gt;
</html>
</section>
<node name="ncwa-netCDF-Weighted-Averager" spaces=" "><nodename>ncwa netCDF Weighted Averager</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">ncrename netCDF Renamer</nodeprev><nodeup spaces=" ">Reference Manual</nodeup></node>
<section spaces=" "><sectiontitle><command>ncwa</command> netCDF Weighted Averager</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3119">averaging data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3120">weights</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3121">weighted average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3122">masked average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3123">broadcasting variables</indexterm></cindex>
<findex index="fn" spaces=" "><indexterm index="fn" number="45" mergedindex="cp">ncwa</indexterm></findex>

<noindent></noindent>
<para>SYNTAX
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa [-3] [-4] [-5] [-6] [-7] [-A] [-a <var>dim</var>[,&dots;]]
[-B <var>mask_cond</var>] [-b] [-C] [-c] [--cmp <var>cmp_sng</var>]
[--cnk_byt <var>sz_byt</var>] [--cnk_csh <var>sz_byt</var>] [--cnk_dmn <var>nm</var>,<var>sz_lmn</var>]
[--cnk_map <var>map</var>] [--cnk_min <var>sz_byt</var>] [--cnk_plc <var>plc</var>] [--cnk_scl <var>sz_lmn</var>]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F] [--fl_fmt <var>fl_fmt</var>]
[-G <var>gpe_dsc</var>] [-g <var>grp</var>[,&dots;]] [--glb ...] [-H] [-h] [--hdr_pad <var>nbr</var>] [--hpss] [-I]
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [-M <var>mask_val</var>] [-m <var>mask_var</var>] [-N] 
[--no_cll_msr] [--no_cll_mth] [--no_frm_trm] [--no_tmp_fl] 
[-O] [-o <var>output-file</var>] [-p <var>path</var>] [--qnt ...] [--qnt_alg <var>alg_nm</var>]
[-R] [-r] [--ram_all] [--rth_dbl|flt] [-T <var>mask_comp</var>] [-t <var>thr_nbr</var>]
[--unn] [-v <var>var</var>[,&dots;]] [-w <var>weight</var>] [-X ...] [-x] [-y <var>op_typ</var>]
<var>input-file</var> [<var>output-file</var>]
</pre></example>

<noindent></noindent>
<para>DESCRIPTION
</para>
<para><command>ncwa</command> performs statistics (including, but not limited to,
averages) on variables in a single file over arbitrary dimensions, with
options to specify weights, masks, and normalization.
<xref label="Statistics-vs-Concatenation"><xrefnodename>Statistics vs Concatenation</xrefnodename></xref>, for a description of the
distinctions between the various statistics tools and concatenators. 
The default behavior of <command>ncwa</command> is to arithmetically average
every numerical variable over all dimensions and to produce a scalar 
result for each. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3124">degenerate dimension</indexterm></cindex>
<para>Averaged dimensions are, by default, eliminated as dimensions.
Their corresponding coordinates, if any, are output as scalar
variables. 
The <samp>-b</samp> switch (and its long option equivalents <samp>--rdd</samp> and 
<samp>--retain-degenerate-dimensions</samp>) causes <command>ncwa</command> to retain
averaged dimensions as degenerate (<w>size 1</w>) dimensions.
This maintains the association between a dimension (or coordinate) and
variables after averaging and simplifies, for instance, later
concatenation along the degenerate dimension. 
</para>
<para>To average variables over only a subset of their dimensions, specify
these dimensions in a comma-separated list following <samp>-a</samp>, e.g.,
<samp>-a time,lat,lon</samp>. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3125">arithmetic operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3126">hyperslab</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3127"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>]]</code></indexterm></cindex>
As with all arithmetic operators, the operation may be restricted to
an arbitrary hyperslab by employing the <samp>-d</samp> option
(<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>). 
<command>ncwa</command> also handles values matching the variable&textrsquo;s
<code>_FillValue</code> attribute correctly. 
Moreover, <command>ncwa</command> understands how to manipulate user-specified
weights, masks, and normalization options.
With these options, <command>ncwa</command> can compute sophisticated averages
(and integrals) from the command line. 
</para>
<html endspaces=" ">
&lt;a name=&quot;-w&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#-w --&gt;
&lt;a name=&quot;wgt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#wgt --&gt;
</html>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3128"><code>-w <var>weight</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3129"><code>--weight <var>weight</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3130"><code>--wgt_var <var>weight</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3131"><code>-m <var>mask_var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3132"><code>--mask-variable <var>mask_var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3133"><code>--mask_variable <var>mask_var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3134"><code>--msk_nm <var>mask_var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3135"><code>--msk_var <var>mask_var</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3136"><code>-B <var>mask_cond</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3137"><code>--msk_cnd <var>mask_cond</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3138"><code>--mask_condition <var>mask_cond</var></code></indexterm></cindex>
<para><var>mask_var</var> and <var>weight</var>, if specified, are broadcast to conform
to the variables being averaged. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3139">rank</indexterm></cindex>
The rank of variables is reduced by the number of dimensions which they
are averaged over.  
Thus arrays which are one dimensional in the <var>input-file</var> and are
averaged by <command>ncwa</command> appear in the <var>output-file</var> as scalars.
This allows the user to infer which dimensions may have been averaged.
Note that that it is impossible for <command>ncwa</command> to make make a
<var>weight</var> or <var>mask_var</var> of rank <var>W</var> conform to a <var>var</var> of
rank <var>V</var> if <var>W &gt; V</var>.
This situation often arises when coordinate variables (which, by
definition, are one dimensional) are weighted and averaged.
<command>ncwa</command> assumes you know this is impossible and so <command>ncwa</command>
does not attempt to broadcast <var>weight</var> or <var>mask_var</var> to conform
to <var>var</var> in this case, nor does <command>ncwa</command> print a warning
message telling you this, because it is so common.  
Specifying <var>dbg &gt; 2</var> does cause <command>ncwa</command> to emit warnings in
these situations, however.
</para>
<para>Non-coordinate variables are always masked and weighted if specified.
Coordinate variables, however, may be treated specially.
By default, an averaged coordinate variable, e.g., <code>latitude</code>,
appears in <var>output-file</var> averaged the same way as any other variable 
containing an averaged dimension.
In other words, by default <command>ncwa</command> weights and masks
coordinate variables like all other variables.  
This design decision was intended to be helpful but for some
applications it may be preferable not to weight or mask coordinate
variables just like all other variables.   
Consider the following arguments to <command>ncwa</command>: 
<code>-a latitude -w lat_wgt -d latitude,0.,90.</code> where <code>lat_wgt</code> is
a weight in the <code>latitude</code> dimension.
Since, by default <command>ncwa</command> weights coordinate variables, the
value of <code>latitude</code> in the <var>output-file</var> depends on the weights 
in <var>lat_wgt</var> and is not likely to <w>be 45.0</w>, the midpoint latitude
of the hyperslab.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3140">coordinate variable</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3141"><code>-I</code></indexterm></cindex>
Option <samp>-I</samp> overrides this default behavior and causes
<command>ncwa</command> not to weight or mask coordinate variables
<footnote><para>The default behavior of (<samp>-I</samp>) changed on
19981201&textmdash;before this date the default was not to weight or mask
coordinate variables.</para></footnote>.
In the above case, this causes the value of <code>latitude</code> in the
<var>output-file</var> to <w>be 45.0</w>, an appealing result.
Thus, <samp>-I</samp> specifies simple arithmetic averages for the coordinate
variables. 
In the case of latitude, <samp>-I</samp> specifies that you prefer to archive
the arithmetic mean latitude of the averaged hyperslabs rather than the 
area-weighted mean latitude.
<footnote><para>If <code>lat_wgt</code> contains Gaussian weights then the value of 
<code>latitude</code> in the <var>output-file</var> will be the area-weighted
centroid of the hyperslab. 
For the example given, this is about <w>30 degrees.</w></para></footnote>.  
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3142">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3143">operation types</indexterm></cindex>
<para>As explained in <xref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></xref>, <command>ncwa</command> 
<emph>always averages</emph> coordinate variables regardless of the arithmetic
operation type performed on the non-coordinate variables. 
This is independent of the setting of the <samp>-I</samp> option.
The mathematical definition of operations involving rank reduction 
is given above (<pxref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></pxref>).
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Mask condition</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Normalization and Integration</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<html endspaces=" ">
&lt;a name=&quot;mask&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#mask --&gt;
&lt;a name=&quot;msk&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#msk --&gt;
</html>
<node name="Mask-condition" spaces=" "><nodename>Mask condition</nodename><nodenext spaces=" ">Normalization and Integration</nodenext><nodeprev spaces=" ">ncwa netCDF Weighted Averager</nodeprev><nodeup spaces=" ">ncwa netCDF Weighted Averager</nodeup></node>
<subsection spaces=" "><sectiontitle>Mask condition</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3144">mask condition</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3145">truth condition</indexterm></cindex>
<tex endspaces=" ">
Each $\xxx_{\idx}$ also has an associated masking
weight~$\mskflg_{\idx}$ whose value is~0 or~1 (false or true).
The value of~$\mskflg_{\idx}$ is always~1 unless a @var{mask\_var} is
specified (with 
@samp{-m}).
As noted above, @var{mask\_var} is broadcast, if possible, to conform 
to the variable being averaged.  
In this case, the value of~$\mskflg_{\idx}$ depends on the 
@dfn{mask condition} also known as the @dfn{truth condition}.
As expected, $\mskflg_{\idx} = 1$ when the mask condition is
@dfn{true} and $\mskflg_{\idx} = 0$ otherwise.   
</tex>

<cindex index="cp" spaces=" "><indexterm index="cp" number="3146"><code>--op_rlt <var>mask_comp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3147"><code>--mask_comparator <var>mask_comp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3148"><code>--msk_cmp_typ <var>mask_comp</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3149"><code>--msk_cnd_sng <var>mask_cond</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3150"><code>--mask_condition <var>mask_cond</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3151"><code>-B <var>mask_cond</var></code></indexterm></cindex>
<para>The mask condition has the syntax <math><var>mask_var</var></math>
<math><var>mask_comp</var></math> <math><var>mask_val</var></math>. 
The preferred method to specify the mask condition is in one string with  
the <samp>-B</samp> or <samp>--mask_condition</samp> switches.
The older method is to use the three switches <samp>-m</samp>, <samp>-T</samp>, and
<samp>-M</samp> to specify the <var>mask_var</var>, <var>mask_comp</var>, and 
<var>mask_val</var>, respectively.  
<footnote><para>The three switches <samp>-m</samp>, <samp>-T</samp>, and <samp>-M</samp> are
maintained for backward compatibility and may be deprecated in the
future.
It is safest to write scripts using <samp>--mask_condition</samp>.</para></footnote>.
The <var>mask_condition</var> string is automatically parsed into its three
constituents <var>mask_var</var>, <var>mask_comp</var>, and <var>mask_val</var>.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3152">comparator</indexterm></cindex>
<para>Here <var>mask_var</var> is the name of the masking variable (specified with 
<samp>-m</samp>, <samp>--mask-variable</samp>, <samp>--mask_variable</samp>,
<samp>--msk_nm</samp>, or <samp>--msk_var</samp>).  
The truth <var>mask_comp</var> argument (specified with <samp>-T</samp>,
<samp>--mask_comparator</samp>, <samp>--msk_cmp_typ</samp>, or <samp>--op_rlt</samp> may 
be any one of the six arithmetic comparators: <kbd>eq</kbd>, <kbd>ne</kbd>,
<kbd>gt</kbd>, <kbd>lt</kbd>, <kbd>ge</kbd>, <kbd>le</kbd>. 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
These are the Fortran-style character abbreviations for the logical 
comparisons $=$, $\neq$, $&gt;$, $&lt;$, $\ge$, $\le$. 
@clear flg
</tex>
These are the Fortran-style character abbreviations for the logical 
comparisons <math>==</math>, <math>!=</math>, <math>&gt;</math>, <math>&lt;</math>, <math>&gt;=</math>,
<math>&lt;=</math>. 
<clear name="flg" line=" flg"></clear>
The mask comparator defaults to <kbd>eq</kbd> (equality).
<cindex index="cp" spaces=" "><indexterm index="cp" number="3153"><code>--mask-value <var>mask_val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3154"><code>--mask_value <var>mask_val</var></code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3155"><code>--msk_val <var>mask_val</var></code></indexterm></cindex>
The <var>mask_val</var> argument to <samp>-M</samp> (or <samp>--mask-value</samp>, or
<samp>--msk_val</samp>) is the right hand side of the
<dfn>mask condition</dfn>.
Thus for the <var>i</var>&textrsquo;th element of the hyperslab to be averaged,
the mask condition is 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
{\it mask$_{\idx}$ mask\_comp mask\_val}.
@clear flg
</tex>
<math>mask(i)</math> <var>mask_comp</var> <var>mask_val</var>.
<clear name="flg" line=" flg"></clear>
</para>
<tex endspaces=" ">
Each~$\xxx_{\idx}$ is also associated with an additional
weight~$\wgt_{\idx}$ whose value may be user-specified.
The value of~$\wgt_{\idx}$ is identically~1 unless the user specifies a 
weighting variable @var{weight} (with @samp{-w}, @samp{--weight}, or
@samp{--wgt\_var}). 
In this case, the value of~$\wgt_{\idx}$ is determined by the
@var{weight} variable in the @var{input-file}. 
As noted above, @var{weight} is broadcast, if possible, to conform 
to the variable being averaged.  

$\tllnbr$ is the number of input elements $\xxx_{\idx}$ which actually
contribute to output element $\xxx_{\jjj}$.
$\tllnbr$ is also known as the @dfn{tally} and is defined as 
$$
\tllnbr = \sum_{\idx=1}^{\idx=\lmnnbr} \mssflg_{\idx} \mskflg_{\idx} 
$$
$\tllnbr$ is identical to the denominator of the generic averaging
expression except for the omission of the weight $\wgt_{\idx}$.
Thus $\tllnbr = \lmnnbr$ whenever no input points are missing values or
are masked.  
Whether an element contributes to the output, and thus increments
$\tllnbr$ by one, has more to do with the above two criteria (missing
value and masking) than with the numeric value of the element per se.
For example, $\xxx_{\idx}=0.0$ does contribute to $\xxx_{\jjj}$
(assuming the @code{_FillValue} attribute is not~0.0 and location
$\idx$ is not masked). 
The value $\xxx_{\idx}=0.0$ will not change the numerator of the generic 
averaging expression, but it will change the denominator (unless its
weight $\wgt_{\idx}=0.0$ as well).
</tex>

<html endspaces=" ">
&lt;a name=&quot;nrm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#nrm --&gt;
&lt;a name=&quot;ntg&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ntg --&gt;
</html>
</subsection>
<node name="Normalization-and-Integration" spaces=" "><nodename>Normalization and Integration</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Mask condition</nodeprev><nodeup spaces=" ">ncwa netCDF Weighted Averager</nodeup></node>
<subsection spaces=" "><sectiontitle>Normalization and Integration</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3156">normalization</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3157"><code>-N</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3158"><code>numerator</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3159">integration</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3160">dot product</indexterm></cindex>
<para><command>ncwa</command> has one switch which controls the normalization of the
averages appearing in the <var>output-file</var>.
Short option <samp>-N</samp> (or long options <samp>--nmr</samp> or
<samp>--numerator</samp>) prevents <command>ncwa</command> from dividing the weighted
sum of the variable (the numerator in the averaging expression) by the
weighted sum of the weights (the denominator in the averaging
expression).   
Thus <samp>-N</samp> tells <command>ncwa</command> to return just the numerator of the
arithmetic expression defining the operation (<pxref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></pxref>). 
</para>
<para>With this normalization option, <command>ncwa</command> can integrate variables.
Averages are first computed as sums, and then normalized to obtain the
average. 
The original sum (i.e., the numerator of the expression in
<ref label="Operation-Types"><xrefnodename>Operation Types</xrefnodename></ref>) is output if default normalization is turned off
(<w>with <samp>-N</samp></w>). 
This sum is the integral (not the average) over the specified 
(<w>with <samp>-a</samp></w>, or all, if none are specified) dimensions.
The weighting variable, if specified (<w>with <samp>-w</samp></w>), plays the
role of the differential increment and thus permits more sophisticated 
integrals (i.e., weighted sums) to be output.
For example, consider the variable 
<code>lev</code> where <math><var>lev</var> = [100,500,1000]</math> weighted by
the weight <code>lev_wgt</code> where <math><var>lev_wgt</var> = [10,2,1]</math>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3161">dot product</indexterm></cindex>
The vertical integral of <code>lev</code>, weighted by <code>lev_wgt</code>, 
is the dot product of <var>lev</var> and <var>lev_wgt</var>. 
That this is <w>is 3000.0</w> can be seen by inspection and verified with 
the integration command
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -N -a lev -v lev -w lev_wgt in.nc foo.nc;ncks foo.nc
</pre></example>

<ignore endspaces=" ">
fxm TODO nco702
As explained in @xref{Operation Types}, @command{ncwa} 
@emph{always averages} coordinate variables regardless of the arithmetic 
operation type performed on the non-coordinate variables. 
The single exception is shown in the above example.
The @samp{-N} switch turns off normalization so variables which are to be
averaged, including coordinate variables, are not normalized.
This is equivalent to summation or integration.
</ignore>

<ignore endspaces=" ">
@c NB: these masking features are deprecated
The second normalization option tells @command{ncwa} to multiply the
weighted average the variable (given by the averaging expression)
by the @w{tally, @var{M}}.
Thus this option is similar to integration---multiplying the mean value
of a quantity by the number of gridpoints to which it applies.

The third normalization option is equivalent to specifying the first two
options simultaneously. 
In other words this option causes @command{ncwa} to return 
@w{@var{M} times} the numerator of the generic averaging expression.  
With these normalization options, @command{ncwa} can compute
sophisticated averages (and integrals) from the command line.
</ignore>

<noindent></noindent>
<html endspaces=" ">
&lt;a name=&quot;xmp_ncwa&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#xmp_ncwa --&gt;
</html>
<para>EXAMPLES
</para>
<para>Given file <file>85_0112.nc</file>:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
netcdf 85_0112 {
dimensions:
        lat = 64 ;
        lev = 18 ;
        lon = 128 ;
        time = UNLIMITED ; // (12 currently)
variables:
        float lat(lat) ;
        float lev(lev) ;
        float lon(lon) ;
        float time(time) ;
        float scalar_var ;
        float three_dmn_var(lat, lev, lon) ;
        float two_dmn_var(lat, lev) ;
        float mask(lat, lon) ;
        float gw(lat) ;
} 
</verbatim>
</example>

<para>Average all variables in <file>in.nc</file> over all dimensions and store
results in <file>out.nc</file>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa in.nc out.nc
</pre></example>
<noindent></noindent>
<para>All variables in <file>in.nc</file> are reduced to scalars in <file>out.nc</file> 
since <command>ncwa</command> averages over all dimensions unless otherwise
specified (with <samp>-a</samp>).
</para>
<para>Store the zonal (longitudinal) mean of <file>in.nc</file> in <file>out.nc</file>:
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -a lon in.nc out1.nc
ncwa -a lon -b in.nc out2.nc
</pre></example>
<noindent></noindent>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3162">degenerate dimension</indexterm></cindex>
<para>The first command turns <code>lon</code> into a scalar and the second retains 
<code>lon</code> as a degenerate dimension in all variables.
</para><example endspaces=" ">
<pre xml:space="preserve">% ncks --trd -C -H -v lon out1.nc
lon = 135
% ncks --trd -C -H -v lon out2.nc
lon[0] = 135
</pre></example>
<para>In either case the tally is simply the size of <code>lon</code>, i.e., 180
for the <file>85_0112.nc</file> file described by the sample header above.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3163"><code>gw</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3164">Gaussian weights</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3165">climate model</indexterm></cindex>
<para>Compute the meridional (latitudinal) mean, with values weighted by
the corresponding element of <var>gw</var>
<footnote><para><code>gw</code> stands for <dfn>Gaussian weight</dfn> in many
climate models.</para></footnote>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -w gw -a lat in.nc out.nc
</pre></example>
<noindent></noindent>
<para>Here the tally is simply the size of <code>lat</code>, <w>or 64.</w>
The sum of the Gaussian weights <w>is 2.0.</w>
</para>
<para>Compute the area mean over the tropical Pacific:
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -w gw -a lat,lon -d lat,-20.,20. -d lon,120.,270. in.nc out.nc
</pre></example>
<noindent></noindent>
<para>Here the tally is 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$64 \times 128 = 8192$.
@clear flg
</tex>
64 times 128 = 8192.
<clear name="flg" line=" flg"></clear>
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3166"><code>ORO</code></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3167">climate model</indexterm></cindex>
<para>Compute the area-mean over the globe using only points for which 
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$ORO &lt; 0.5$
@clear flg
</tex>
<var>ORO</var> &lt; 0.5
<clear name="flg" line=" flg"></clear>
<footnote><para><code>ORO</code> stands for <dfn>Orography</dfn> in some climate models
and in those models <math><var>ORO</var> &lt; 0.5</math> selects ocean gridpoints.</para></footnote>: 
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -B 'ORO &lt; 0.5'      -w gw -a lat,lon in.nc out.nc
ncwa -m ORO -M 0.5 -T lt -w gw -a lat,lon in.nc out.nc
</pre></example>
<noindent></noindent>
<para>It is considerably simpler to specify the complete <var>mask_cond</var> with
the single string argument to <samp>-B</samp> than with the three separate
switches <samp>-m</samp>, <samp>-T</samp>, and <samp>-M</samp>
<footnote><para>Unfortunately the <samp>-B</samp> and <samp>--mask_condition</samp>
options are unsupported on Windows (with the <acronym><acronymword>MVS</acronymword></acronym> compiler),
which lacks a free, standard parser and lexer.</para></footnote>. 
If in doubt, enclose the <var>mask_cond</var> within quotes since some
of the comparators have special meanings to the shell.
</para>
<para>Assuming 70% of the gridpoints are maritime, then here the tally is
<set name="flg" line=" flg"></set>
<tex endspaces=" ">
$0.70 \times 8192 \approx 5734$.
@clear flg
</tex>
0.70 times 8192 = 5734.
<clear name="flg" line=" flg"></clear>
</para>
<para>Compute the global annual mean over the maritime tropical Pacific:
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -B 'ORO &lt; 0.5'      -w gw -a lat,lon,time \
  -d lat,-20.0,20.0 -d lon,120.0,270.0 in.nc out.nc
ncwa -m ORO -M 0.5 -T lt -w gw -a lat,lon,time \
  -d lat,-20.0,20.0 -d lon,120.0,270.0 in.nc out.nc
</pre></example>
<para>Further examples will use the one-switch specification of
<var>mask_cond</var>.  
</para>
<para>Determine the total area of the maritime tropical Pacific, assuming
the variable <var>area</var> contains the area of each gridcell
</para><example endspaces=" ">
<pre xml:space="preserve">ncwa -N -v area -B 'ORO &lt; 0.5' -a lat,lon \
  -d lat,-20.0,20.0 -d lon,120.0,270.0 in.nc out.nc
</pre></example>
<para>Weighting <var>area</var> (e.g., by <var>gw</var>) is not appropriate because
<var>area</var> is <emph>already</emph> area-weighted by definition.
Thus the <samp>-N</samp> switch, or, equivalently, the <samp>-y ttl</samp> switch, 
correctly integrate the cell areas into a total regional area.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3168">mask condition</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3169">truth condition</indexterm></cindex>
<para>Mask a file to contain <var>_FillValue</var> everywhere except where
<math><var>thr_min</var> &lt;= <var>msk_var</var> &lt;= <var>thr_max</var></math>:
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
# Set masking variable and its scalar thresholds
export msk_var='three_dmn_var_dbl' # Masking variable
export thr_max='20' # Maximum allowed value
export thr_min='10' # Minimum allowed value
ncecat -O in.nc out.nc # Wrap out.nc in degenerate &quot;record&quot; dimension
ncwa -O -a record -B &quot;${msk_var} &lt;= ${thr_max}&quot; out.nc out.nc
ncecat -O out.nc out.nc # Wrap out.nc in degenerate &quot;record&quot; dimension
ncwa -O -a record -B &quot;${msk_var} &gt;= ${thr_min}&quot; out.nc out.nc
</verbatim>
</example>
<para>After the first use of <command>ncwa</command>, <file>out.nc</file> contains
<var>_FillValue</var> where <code>$&lbrace;msk_var&rbrace; &gt;= $&lbrace;thr_max&rbrace;</code>.
The process is then repeated on the remaining data to filter out 
points where <code>$&lbrace;msk_var&rbrace; &lt;= $&lbrace;thr_min&rbrace;</code>.
The resulting <file>out.nc</file> contains valid data only
where <math><var>thr_min</var> &lt;= <var>msk_var</var> &lt;= <var>thr_max</var></math>.
</para>
<html endspaces=" ">
&lt;a name=&quot;ctr&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ctr --&gt;
</html>
</subsection>
</section>
</chapter>
<node name="Contributing" spaces=" "><nodename>Contributing</nodename><nodenext spaces=" ">Quick Start</nodenext><nodeprev spaces=" ">Reference Manual</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>Contributing</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3170">contributing</indexterm></cindex>
<para>We welcome contributions from anyone.
The project homepage at <uref><urefurl>https://sf.net/projects/nco</urefurl></uref>
contains more information on how to contribute. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3171">PayPal</indexterm></cindex>
<para>Financial contributions to <acronym><acronymword>NCO</acronymword></acronym> development may be made through  
<uref><urefurl>https://www.paypal.com/xclick/business=zender%40uci.edu&amp;item_name=NCO+development&amp;item_number=nco_dnt_dvl&amp;no_note=1&amp;tax=0&amp;currency_code=USD</urefurl><urefdesc spaces=" ">PayPal</urefdesc></uref>.
<acronym><acronymword>NCO</acronymword></acronym> has been shared for over <w>10 years</w> yet only two 
users have contributed any money to the developers
<footnote spaces="\n"><cindex index="cp" spaces=" "><indexterm index="cp" number="3172">chocolate</indexterm></cindex>
<para>Happy users have sent me a few gifts, though.
This includes a box of imported chocolate.
Mmm.
Appreciation and gifts are definitely better than money.
Naturally, I&textrsquo;m too lazy to split and send gifts to the other developers.
However, unlike some <acronym><acronymword>NCO</acronymword></acronym> developers, I have a steady &quot;real job&quot;.
My intent is to split monetary donations among the active developers
and to send them their shares via PayPal.</para></footnote>. 
So you could be the third!
</para>
<html endspaces=" ">
&lt;a name=&quot;dvl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#dvl --&gt;
&lt;a name=&quot;cnt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cnt --&gt;
&lt;a name=&quot;ppl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ppl --&gt;
</html>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Contributors</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Citation</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Proposals for Institutional Funding</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="Contributors" spaces=" "><nodename>Contributors</nodename><nodenext spaces=" ">Citation</nodenext><nodeprev spaces=" ">Contributing</nodeprev><nodeup spaces=" ">Contributing</nodeup></node>
<section spaces=" "><sectiontitle>Contributors</sectiontitle>
<para><acronym><acronymword>NCO</acronymword></acronym> would not exist without the dedicated efforts of the
remarkable software engineers who conceive, develop, and
maintain netCDF, UDUnits, and OPeNDAP.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3173">Russ Rew</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3174">John Caron</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3175">Glenn Davis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3176">Steve Emmerson</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3177">Ward Fisher</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3178">James Gallagher</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3179">Ed Hartnett</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3180">Dennis Heimbigner</indexterm></cindex>
Since 1995 <acronym><acronymword>NCO</acronymword></acronym> has received support from nearly the entire
staff of all these projects, including  
Russ Rew, 
John Caron,
Glenn Davis, 
Steve Emmerson, 
Ward Fisher,
James Gallagher, 
Ed Hartnett, 
and Dennis Heimbigner.
In addition to their roles in maintaining the software stack on which
<acronym><acronymword>NCO</acronymword></acronym> perches, Yertl-like, some of these gentlemen have advised
or contributed to <acronym><acronymword>NCO</acronymword></acronym> specifically. That support is
acknowledged separately below. 
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3181">contributors</indexterm></cindex>
<para>The primary contributors to <acronym><acronymword>NCO</acronymword></acronym> development have been:
</para><table commandarg="asis" spaces=" " endspaces=" ">
<tableentry><tableterm><cindex index="cp" spaces=" "><indexterm index="cp" number="3182">Charlie Zender</indexterm></cindex>
<item spaces=" "><itemformat command="asis">Charlie Zender</itemformat></item>
</tableterm><tableitem><para>All concept, design and implementation from 1995&textndash;2000.
Since then autotools, bug-squashing, <acronym><acronymword>CDL</acronymword></acronym>, chunking,
documentation, anchoring, recursion, <acronym><acronymword>GPE</acronymword></acronym>, packing,
regridding, <acronym><acronymword>CDL</acronymword></acronym>/<acronym><acronymword>XML</acronymword></acronym> backends, compression,
<acronym><acronymword>NCO</acronymword></acronym> library redesign, <command>ncap2</command> features,
<command>ncbo</command>, <command>ncpdq</command>, <acronym><acronymword>SMP</acronymword></acronym> threading and <acronym><acronymword>MPI</acronymword></acronym> parallelization,
netCDF4 integration, external funding, project management, science
research, releases. 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3183">Henry Butowsky</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Henry Butowsky</itemformat></item>
</tableterm><tableitem><para>Non-linear operations and <code>min()</code>, <code>max()</code>, <code>total()</code>
support in <command>ncra</command> and <command>ncwa</command>. 
Type conversion for arithmetic.
Migration to netCDF3 <acronym><acronymword>API</acronymword></acronym>.
<command>ncap2</command> parser, lexer, <acronym><acronymword>GSL</acronymword></acronym>-support, <w>and I/O</w>.
Multislabbing algorithm.
Variable wildcarding.
<acronym><acronymword>JSON</acronymword></acronym> backend.
Numerous hacks.
<command>ncap2</command> language.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3184">Rorik Peterson</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Rorik Peterson</itemformat></item>
</tableterm><tableitem><para>Original autotools build support. 
Long command-line options.
Original UDUnits support.
Debianization.
Numerous bug-fixes.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3185">Joe Hamman</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3186">Suizer</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Joe Hamman</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Suizer</itemformat></item>
</tableterm><tableitem><para>Python bindings (PyNCO).
<cindex index="cp" spaces=" "><indexterm index="cp" number="3187">Milan Klower</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3188">Rostislav Kouznetsov</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Milan Klower, Rostislav Kouznetsov</itemformat></item>
</tableterm><tableitem><para>Quantization by rounding 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3189">Daniel Wang</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Daniel Wang</itemformat></item>
</tableterm><tableitem><para>Script Workflow Analysis for MultiProcessing (<acronym><acronymword>SWAMP</acronymword></acronym>).
<acronym><acronymword>RPM</acronymword></acronym> support.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3190">Harry Mangalam</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Harry Mangalam</itemformat></item>
</tableterm><tableitem><para>Benchmarking.
OPeNDAP configuration.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3191">Pedro Vicente</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Pedro Vicente</itemformat></item>
</tableterm><tableitem><para>Windows Visual Studio support.
netCDF4 groups.
CMake build-engine.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3192">Jerome Mao</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Jerome Mao</itemformat></item>
</tableterm><tableitem><para>Multi-argument parsing.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3193">Joseph O&textrsquo;Rourke</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Joseph O&textrsquo;Rourke</itemformat></item>
</tableterm><tableitem><para>Routines from his book &textldquo;Computational Geometry in C&textrdquo;.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3194">Russ Rew</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Russ Rew</itemformat></item>
</tableterm><tableitem><para>Advice on <acronym><acronymword>NCO</acronymword></acronym> structural algorithms.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3195">Brian Mays</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Brian Mays</itemformat></item>
</tableterm><tableitem><para>Original packaging for Debian <acronym><acronymword>GNU</acronymword></acronym>/Linux, <command>nroff</command> man pages.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3196">George Shapovalov</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">George Shapovalov</itemformat></item>
</tableterm><tableitem><para>Packaging for Gentoo <acronym><acronymword>GNU</acronymword></acronym>/Linux.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3197">Bill Kocik</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Bill Kocik</itemformat></item>
</tableterm><tableitem><para>Memory management.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3198">Len Makin</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Len Makin</itemformat></item>
</tableterm><tableitem><para>NEC SX architecture support.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3199">Jim Edwards</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Jim Edwards</itemformat></item>
</tableterm><tableitem><para>AIX architecture support.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3200">Juliana Rew</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Juliana Rew</itemformat></item>
</tableterm><tableitem><para>Compatibility with large <acronym><acronymword>PID</acronymword></acronym>s.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3201">Karen Schuchardt</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Karen Schuchardt</itemformat></item>
</tableterm><tableitem><para>Auxiliary coordinate support.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3202">Gayathri Venkitachalam</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Gayathri Venkitachalam</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>MPI</acronymword></acronym> implementation.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3203">Scott Capps</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Scott Capps</itemformat></item>
</tableterm><tableitem><para>Large work-load testing
<cindex index="cp" spaces=" "><indexterm index="cp" number="3204">Xylar Asay-Davis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3205">Sterling Baldwin</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3206">Tony Bartoletti</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3207">Dave Blodgett</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3208">Peter Campbell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3209">Peter Caldwell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3210">Philip Cameron-Smith</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3211">Martin Dix</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3212">Mark Flanner</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3213">Ryan Forsyth</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3214">Chris Golaz</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3215">Barron Henderson</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3216">Ben Hillman</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3217">Aleksandar Jelenak</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3218">Markus Liebig</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3219">Keith Lindsay</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3220">Daniel Macks,</indexterm></cindex> 
<cindex index="cp" spaces=" "><indexterm index="cp" number="3221">Stu Muller</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3222">Daniel Neumann</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3223">Mike Page</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3224">Martin Schmidt</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3225">Lori Sentman</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3226">Michael Schulz</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3227">Rich Signell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3228">Bob Simons</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3229">Gary Strand</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3230">Qi Tang</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3231">Mark Taylor</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3232">Matthew Thompson</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3233">Adrian Tompkins</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3234">Paul Ullrich</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3235">Andrew Wittenberg</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3236">George White</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3237">Min Xu</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3238">Remik Ziemlinski</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3239">Jill Zhang</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Xylar Asay-Davis, Sterling Baldwin, Tony Bartoletti, Dave Blodgett, Peter Caldwell, Philip Cameron-Smith, Peter Campbell, Martin Dix, Mark Flanner, Ryan Forsyth, Chris Golaz, Barron Henderson, Ben Hillman, Aleksandar Jelenak, Markus Liebig, Keith Lindsay, Daniel Macks, Daniel Neumann, Mike Page, Martin Schmidt, Michael Schulz, Lori Sentman, Rich Signell, Bob Simons, Gary Strand, Mark Taylor, Matthew Thompson, Qi Tang, Adrian Tompkins, Paul Ullrich, George White, Andrew Wittenberg, Min Xu, Remik Ziemlinski, Jill Zhang</itemformat></item>
</tableterm><tableitem><para>Excellent bug reports and feature requests.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3240">Xylar Asay-Davis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3241">Filipe Fernandes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3242">Isuru Fernando</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3243">Craig MacLachlan</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3244">Hugo Oliveira</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3245">Rich Signell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3246">Kyle Wilcox</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3247">Klaus Zimmermann</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Filipe Fernandes, Isuru Fernando, Craig MacLachlan, Hugo Oliveira, Rich Signell, Kyle Wilcox, Klaus Zimmermann</itemformat></item>
</tableterm><tableitem><para>Anaconda packaging
<cindex index="cp" spaces=" "><indexterm index="cp" number="3248">Xylar Asay-Davis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3249">Daniel Baumann</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3250">Nick Bower</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3251">Luk Claes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3252">Barry deFreese</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3253">Francesco Lovergine</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3254">Bas Couwenberg</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3255">Matej Vela</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Xylar Asay-Davis, Daniel Baumann, Nick Bower, Luk Claebs, Bas Couwenberg, Barry deFreese, Francesco Lovergine, Matej Vela</itemformat></item>
</tableterm><tableitem><para>Cygwin packaging
<cindex index="cp" spaces=" "><indexterm index="cp" number="3256">Marco Atzeri</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Marco Atzeri</itemformat></item>
</tableterm><tableitem><para>Debian packaging
<cindex index="cp" spaces=" "><indexterm index="cp" number="3257">Patrice Dumas</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3258">Ed Hill</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3259">Orion Poplawski</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Patrice Dumas, Ed Hill, Orion Poplawski</itemformat></item>
</tableterm><tableitem><para>Gentoo packaging
<cindex index="cp" spaces=" "><indexterm index="cp" number="3260">Filipe Fernandes</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Filipe Fernandes</itemformat></item>
</tableterm><tableitem><para>OpenSuse packaging
<cindex index="cp" spaces=" "><indexterm index="cp" number="3261">Takeshi Enomoto</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3262">Alexander Hansen</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3263">Ian Lancaster</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3264">Alejandro Soto</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Takeshi Enomoto, Alexander Hansen, Ian Lancaster, Alejandro Soto</itemformat></item>
</tableterm><tableitem><para>Mac OS packaging
<cindex index="cp" spaces=" "><indexterm index="cp" number="3265">Eric Blake</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Eric Blake</itemformat></item>
</tableterm><tableitem><para>PyNCO Anaconda and Pip packaging, bug fixes
<cindex index="cp" spaces=" "><indexterm index="cp" number="3266">Tim Heap</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Tim Heap</itemformat></item>
</tableterm><tableitem><para>RedHat packaging
<cindex index="cp" spaces=" "><indexterm index="cp" number="3267">George Shapavalov</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3268">Patrick Kursawe</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3269">Manfred Schwarb</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">George Shapavalov, Patrick Kursawe, Manfred Schwarb</itemformat></item>
</tableterm><tableitem><para>Autoconf/M4 help
<cindex index="cp" spaces=" "><indexterm index="cp" number="3270">Gavin Burris</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3271">Kyle Wilcox</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Gavin Burris, Kyle Wilcox</itemformat></item>
</tableterm><tableitem><para>RHEL and CentOS build scripts and bug reports.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3272">Andrea Cimatoribus</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Andrea Cimatoribus</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>NCO</acronymword></acronym> Spiral Logo
<cindex index="cp" spaces=" "><indexterm index="cp" number="3273">Sha Feng</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3274">Walter Hannah</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3275">Martin Otte</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3276">Etienne Tourigny</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Sha Feng, Walter Hannah, Martin Otte, Etienne Tourigny</itemformat></item>
</tableterm><tableitem><para>Miscellaneous bug reports and fixes
<cindex index="cp" spaces=" "><indexterm index="cp" number="3277">Wenshan Wang</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Wenshan Wang</itemformat></item>
</tableterm><tableitem><para><acronym><acronymword>CMIP5</acronymword></acronym> and <acronym><acronymword>MODIS</acronymword></acronym> processing documentation, reference card
<cindex index="cp" spaces=" "><indexterm index="cp" number="3278">Thomas Hornigold</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3279">Ian McHugh</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3280">Todd Mitchell</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3281">Emily Wilbur</indexterm></cindex>
</para></tableitem></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Thomas Hornigold</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Ian McHugh</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Todd Mitchell</itemformat></item>
</tableterm></tableentry><tableentry><tableterm><item spaces=" "><itemformat command="asis">Emily Wilbur</itemformat></item>
</tableterm><tableitem><para>Acknowledgement via financial donations
</para></tableitem></tableentry></table>
<para>Please let me know if your name was omitted!
</para>
<html endspaces=" ">
&lt;a name=&quot;ctt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ctt --&gt;
</html>
</section>
<node name="Citation" spaces=" "><nodename>Citation</nodename><nodenext spaces=" ">Proposals for Institutional Funding</nodenext><nodeprev spaces=" ">Contributors</nodeprev><nodeup spaces=" ">Contributing</nodeup></node>
<section spaces=" "><sectiontitle>Citation</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3282">citation</indexterm></cindex>
<para>The recommended citations for <acronym><acronymword>NCO</acronymword></acronym> software are
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
Zender, C. S. (2008), Analysis of Self-describing Gridded Geoscience
Data with netCDF Operators (NCO), Environ. Modell. Softw., 23(10),
1338-1342, doi:10.1016/j.envsoft.2008.03.004. 

Zender, C. S. and H. J. Mangalam (2007), Scaling Properties of Common
Statistical Operators for Gridded Datasets, Int. J. High
Perform. Comput. Appl., 21(4), 485-498, doi:10.1177/1094342007083802.

Zender, C. S. (2016), Bit Grooming: Statistically accurate
precision-preserving quantization with compression, evaluated in the
netCDF Operators (NCO, v4.4.8+), Geosci. Model Dev., 9, 3199-3211,
doi:10.5194/gmd-9-3199-2016.

Zender, C. S. (Year), netCDF Operator (NCO) User Guide, 
http://nco.sf.net/nco.pdf. 
</verbatim>
</example>
<para>Use the first when referring to overall design, purpose, and 
optimization of <acronym><acronymword>NCO</acronymword></acronym>, the second for the speed and throughput
of <acronym><acronymword>NCO</acronymword></acronym>, the third for compressions, and the fourth for
specific features and/or the User Guide itself, or in a non-academic
setting. 
A complete list of <acronym><acronymword>NCO</acronymword></acronym> publications and presentations is at
<url><urefurl>http://nco.sf.net#pub</urefurl></url>.
This list links to the full papers and seminars themselves.
</para>
<html endspaces=" ">
&lt;a name=&quot;prp&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prp --&gt;
&lt;a name=&quot;prp_sei&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prp_sei --&gt;
&lt;a name=&quot;fnd&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#fnd --&gt;
</html>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Proposals for Institutional Funding</menunode><menuseparator>::  </menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

</section>
<node name="Proposals-for-Institutional-Funding" spaces=" "><nodename>Proposals for Institutional Funding</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Citation</nodeprev><nodeup spaces=" ">Contributing</nodeup></node>
<section spaces=" "><sectiontitle>Proposals for Institutional Funding</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3283">funding</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3284">proposals</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3285"><acronym><acronymword>NSF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3286">server-side processing</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3287">Distributed Data Reduction &amp; Analysis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3288">Scientific Data Operators</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3289"><acronym><acronymword>DDRA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3290">Server-Side Distributed Data Reduction &amp; Analysis</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3291"><acronym><acronymword>SSDDRA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3292"><acronym><acronymword>CCSM</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3293"><acronym><acronymword>IPCC</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3294"><acronym><acronymword>NSF</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3295"><acronym><acronymword>SDO</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3296"><acronym><acronymword>SEIII</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3297">OptIPuter</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3298">parallelism</indexterm></cindex>
<para>From 2004&textndash;2007, <acronym><acronymword>NSF</acronymword></acronym> funded a
<uref><urefurl>http://nco.sf.net#prp_sei</urefurl><urefdesc spaces=" ">project</urefdesc></uref>
to improve Distributed Data Reduction &amp; Analysis (<acronym><acronymword>DDRA</acronymword></acronym>) by
evolving <acronym><acronymword>NCO</acronymword></acronym> parallelism (OpenMP, <acronym><acronymword>MPI</acronymword></acronym>) and
Server-Side <acronym><acronymword>DDRA</acronymword></acronym> (<acronym><acronymword>SSDDRA</acronymword></acronym>) implemented through
extensions to <acronym><acronymword>OPeNDAP</acronymword></acronym> and netCDF4. 
The <acronym><acronymword>SSDDRA</acronymword></acronym> features were implemented in <acronym><acronymword>SWAMP</acronymword></acronym>,
the PhD Thesis of Daniel Wang.
<acronym><acronymword>SWAMP</acronymword></acronym> dramatically reduced bandwidth usage for <acronym><acronymword>NCO</acronymword></acronym> 
between client and server.
</para>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3299"><acronym><acronymword>NASA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3300"><acronym><acronymword>NRA</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3301"><acronym><acronymword>HDF</acronymword></acronym></indexterm></cindex>
<para>With this first <acronym><acronymword>NCO</acronymword></acronym> proposal funded, the content of the
next <acronym><acronymword>NCO</acronymword></acronym> proposal became clear.
We had long been interested in obtaining <acronym><acronymword>NASA</acronymword></acronym> support for 
<acronym><acronymword>HDF</acronymword></acronym>-specific enhancements to <acronym><acronymword>NCO</acronymword></acronym>. 
From 2012&textndash;2015 the <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>ACCESS</acronymword></acronym> program funded us to
implement support support netCDF4 group functionality. 
Thus <acronym><acronymword>NCO</acronymword></acronym> will grow and evade bit-rot for the foreseeable
future. 
</para>
<para>We are considering other interesting ideas for still more proposals.
Please contact us if you wish to be involved with any future
<acronym><acronymword>NCO</acronymword></acronym>-related proposals.  
Comments on the proposals and letters of support are also very welcome.
</para>
<html endspaces=" ">
&lt;a name=&quot;quicksrt&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#quicksrt --&gt;
</html>
</section>
</chapter>
<node name="Quick-Start" spaces=" "><nodename>Quick Start</nodename><nodenext spaces=" ">CMIP5 Example</nodenext><nodeprev spaces=" ">Contributing</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>Quick Start</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3302">Quick Start</indexterm></cindex>
<para>Simple examples in Bash shell scripts showing how to average data with
different file structures.  
Here we include monthly, seasonal and annual average with daily or
monthly data in either one file or multiple files. 
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Daily data in one file</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Monthly data in one file</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>One time point one file</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Multiple files with multiple time points</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="Daily-data-in-one-file" spaces=" "><nodename>Daily data in one file</nodename><nodenext spaces=" ">Monthly data in one file</nodenext><nodeprev spaces=" ">Quick Start</nodeprev><nodeup spaces=" ">Quick Start</nodeup></node>
<section spaces=" "><sectiontitle>Daily data in one file</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3303">daily data</indexterm></cindex>
<para>Suppose we have daily data from Jan 1st, 1990 to Dec. 31, 2005 in the
file of <file>in.nc</file> with the record dimension as <code>time</code>.
</para>
<noindent></noindent>
<para><strong>Monthly average:</strong>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3304">monthly average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3305">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3306">time-averaging</indexterm></cindex>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for yyyy in {1990..2005}; do      # Loop over years
  for moy in {1..12}; do          # Loop over months
    mm=$( printf &quot;%02d&quot; ${moy} )  # Change to 2-digit format

    # Average specific month yyyy-mm
    ncra -O -d time,&quot;${yyyy}-${mm}-01&quot;,&quot;${yyyy}-${mm}-31&quot; \
         in.nc in_${yyyy}${mm}.nc
  done
done

# Concatenate monthly files together
ncrcat -O in_??????.nc out.nc
</verbatim>
</example>

<noindent></noindent>
<para><strong>Annual average:</strong>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3307">annual average from daily data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3308">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3309">time-averaging</indexterm></cindex>
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for yyyy in {1990..2005}; do      # Loop over years
  ncra -O -d time,&quot;${yyyy}-01-01&quot;,&quot;${yyyy}-12-31&quot; in.nc in_${yyyy}.nc
done

# Concatenate annual files together
ncrcat -O in_????.nc out.nc
</verbatim>
</example>
<para>The <option>-O</option> switch means to overwrite the pre-existing files (<pxref label="Batch-Mode"><xrefnodename>Batch Mode</xrefnodename></pxref>).
The <option>-d</option> option is to specify the range of hyperslabs (<pxref label="Hyperslabs"><xrefnodename>Hyperslabs</xrefnodename></pxref>).
There are detailed instructions on <command>ncra</command> (<pxref label="ncra-netCDF-Record-Averager"><xrefnodename>ncra netCDF Record Averager</xrefnodename></pxref> and <command>ncrcat</command> (<pxref label="ncrcat-netCDF-Record-Concatenator"><xrefnodename>ncrcat netCDF Record Concatenator</xrefnodename></pxref>).
<acronym><acronymword>NCO</acronymword></acronym> supports UDUnits so that we can use readable dates as time dimension (<pxref label="UDUnits-Support"><xrefnodename>UDUnits Support</xrefnodename></pxref>).
</para>
</section>
<node name="Monthly-data-in-one-file" spaces=" "><nodename>Monthly data in one file</nodename><nodenext spaces=" ">One time point one file</nodenext><nodeprev spaces=" ">Daily data in one file</nodeprev><nodeup spaces=" ">Quick Start</nodeup></node>
<section spaces=" "><sectiontitle>Monthly data in one file</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3310">monthly data</indexterm></cindex>
<para>Inside the input file <file>in.nc</file>, the record dimension <code>time</code> is from Jan 1990 to Dec 2005.
</para>
<noindent></noindent>
<para><strong>Seasonal average (e.g., <acronym><acronymword>DJF</acronymword></acronym>):</strong>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3311">seasonal average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3312">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3313">time-averaging</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -O --mro -d time,&quot;1990-12-01&quot;,,12,3 in.nc out.nc
</pre></example>

<noindent></noindent>
<para><strong>Annual average:</strong>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3314">annual average from monthly data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3315">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3316">time-averaging</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -O --mro -d time,,,12,12 in.nc out.nc
</pre></example>
<para>Here we use the subcycle feature (i.e., the number after the fourth
comma: <samp>3</samp> in the seasonal example and the second <samp>12</samp> in
the annual example) to retrieve groups of records separated by regular
intervals (<pxref label="Subcycle"><xrefnodename>Subcycle</xrefnodename></pxref>).
The option <option>--mro</option> switches <command>ncra</command> to produce a
Multi-Record Output instead of a single-record output. 
For example, assume <var>snd</var> is a 3D array with dimensions
<code>time</code> * <code>latitude</code> * <code>longitude</code> and <code>time</code>
includes every month from Jan. 1990 to Dec. 2005, 192 months in total, 
or 16 years. 
Consider the following two command lines:
</para><example endspaces=" ">
<pre xml:space="preserve">ncra --mro -v snd -d time,&quot;1990-12-01&quot;,,12,3 in.nc out_mro.nc
ncra -v snd -d time,&quot;1990-12-01&quot;,,12,3 in.nc out_sro.nc
</pre></example>
<para>In the first output file, <file>out_mro.nc</file>, <var>snd</var> is still a 3D
array with dimensions <code>time</code> * <code>latitude</code> * <code>longitude</code>, 
but the length of <code>time</code> now is 16, meaning 16 winters.
In the second output file, <file>out_sro.nc</file>, the length of
<code>time</code> is <w>only 1</w>, which contains the average of all 16 winters.
</para>
<para>When using <samp>-d <var>dim</var>,min[,max]</samp> to specify the hyperslabs, 
you can leave it blank if you want to include the minimum or the
maximum of the data, like we did above. 
</para>
</section>
<node name="One-time-point-one-file" spaces=" "><nodename>One time point one file</nodename><nodenext spaces=" ">Multiple files with multiple time points</nodenext><nodeprev spaces=" ">Monthly data in one file</nodeprev><nodeup spaces=" ">Quick Start</nodeup></node>
<section spaces=" "><sectiontitle>One time point one file</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3317">daily data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3318">monthly data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3319">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3320">time-averaging</indexterm></cindex>
<para>This means if you have daily data of 30 days, there will be 30 data files.
Or if you have monthly data of 12 months, there will be 12 data files.
Dealing with this kind of files, you need to specify the file names in shell scripts and pass them to NCO operators.
For example, your daily data files may look like <file>snd_19900101.nc</file>, <file>snd_19900102.nc</file>, <file>snd_19900103.nc</file> ...
If you want to know the monthly average of Jan 1990, you can write like,
</para><example endspaces=" ">
<pre xml:space="preserve">ncra -O snd_199001??.nc out.nc
</pre></example>
<para>You might want to use loop if you need the average of each month.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
for moy in {1..12}; do          # Loop over months
  mm=$( printf &quot;%02d&quot; ${moy} )  # Change to 2-digit format

  ncra -O snd_????${mm}??.nc out_${mm}.nc
done
</verbatim>
</example>

</section>
<node name="Multiple-files-with-multiple-time-points" spaces=" "><nodename>Multiple files with multiple time points</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">One time point one file</nodeprev><nodeup spaces=" ">Quick Start</nodeup></node>
<section spaces=" "><sectiontitle>Multiple files with multiple time points</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3321">daily data</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3322">monthly data</indexterm></cindex>
<para>Similar as the last one, it&textrsquo;s more about shell scripts.
Suppose you have daily data with one month of them in one data file.
The monthly average is simply to apply <command>ncra</command> on the specific data file.
And for seasonal averages, you can specify the three months by shell scripts.
</para>
<html endspaces=" ">
&lt;a name=&quot;cmip5&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#cmip5 --&gt;
&lt;a name=&quot;godad&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#godad --&gt;
</html>
</section>
</chapter>
<node name="CMIP5-Example" spaces=" "><nodename>CMIP5 Example</nodename><nodenext spaces=" ">Parallel</nodenext><nodeprev spaces=" ">Quick Start</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle><acronym><acronymword>CMIP5</acronymword></acronym> Example</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3323"><acronym><acronymword>CMIP5</acronymword></acronym></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3324"><acronym><acronymword>GODAD</acronymword></acronym></indexterm></cindex>
<ignore endspaces=" ">
This @uref{http://nco.sf.net/xmp_cesm.html,Wonderful CMIP5 Documentation}
shows complete processing of the @acronym{CMIP5} dataset.
</ignore>

<para>The fifth phase of the Coupled Model Intercomparison Project 
(<uref><urefurl>http://cmip-pcmdi.llnl.gov/cmip5/index.html?submenuheader=0</urefurl><urefdesc spaces=" "><acronym><acronymword>CMIP5</acronymword></acronym></urefdesc></uref>) 
provides a multi-model framework for comparing the mechanisms and
responses of climate models from around the world.   
However, it is a tremendous workload to retrieve a single climate
statistic from all these models, each of which includes several ensemble 
members.  
Not only that, it is too often a tedious process that impedes new
research and hypothesis testing.  
Our <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>ACCESS</acronymword></acronym> 2011 project simplified and
accelerated this process.   
</para>
<para>Traditional geoscience data analysis requires users to work with
numerous flat (data in one level or namespace) files. 
In that paradigm instruments or models produce, and then repositories
archive and distribute, and then researchers request and analyze,
collections of flat files.
<acronym><acronymword>NCO</acronymword></acronym> works well with that paradigm, yet it also embodies the
necessary algorithms to transition geoscience data analysis from relying
solely on traditional (or &textldquo;flat&textrdquo;) datasets to allowing newer
hierarchical (or &textldquo;nested&textrdquo;) datasets.  
</para>
<para>Hierarchical datasets support and enable combining all datastreams that
meet user-specified criteria into a single or small number of files that
hold <emph>all</emph> the science-relevant data.
<acronym><acronymword>NCO</acronymword></acronym> (and no other software to our knowledge) exploits this
capability now.
Data and metadata may be aggregated into and analyzed in hierarchical
structures.
We call the resulting data storage, distribution, and analysis
paradigm Group-Oriented Data Analysis and Distribution
(<acronym><acronymword>GODAD</acronymword></acronym>). 
<acronym><acronymword>GODAD</acronymword></acronym> lets the scientific question organize the data, not the  
<emph>ad hoc</emph> granularity of all relevant datasets.
This chapter illustrates <acronym><acronymword>GODAD</acronymword></acronym> techniques applied to 
analysis of the <acronym><acronymword>CMIP5</acronymword></acronym> dataset.
</para>
<para>To begin, we document below a prototypical example of <acronym><acronymword>CMIP5</acronymword></acronym> 
analysis and evaluation using traditional <acronym><acronymword>NCO</acronymword></acronym> commands on
netCDF3-format model and <acronym><acronymword>HDF-EOS</acronymword></acronym> format observational
(<acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>MODIS</acronymword></acronym> satellite instrument) datasets.
These examples complement the <acronym><acronymword>NCO</acronymword></acronym> User Guide by detailing
in-depth data analysis in a frequently encountered &textldquo;real world&textrdquo;
context.   
Graphical representations of the results (<acronym><acronymword>NCL</acronymword></acronym> scripts
available upon request) are provided to illustrate physical meaning of
the analysis.
<ignore endspaces=" ">
In 2013 we added scripts which make use of new @acronym{NCO} features
that combine all the loops in the analysis into single commands by
exploiting @acronym{NCO}'s new group aggregation and arithmetic
features.   
</ignore>
Since <acronym><acronymword>NCO</acronymword></acronym> can process hierarchical datasets, i.e., datasets
stored with netCDF4 groups, we present sample scripts illustrating
group-based processing as well. 
</para>
<menu endspaces=" ">
<menuentry><menuleadingtext>* </menuleadingtext><menunode>Combine Files</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Global Distribution of Long-term Average</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Annual Average over Regions</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Monthly Cycle</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Regrid MODIS Data</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Add Coordinates to MODIS Data</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry><menuentry><menuleadingtext>* </menuleadingtext><menunode>Permute MODIS Coordinates</menunode><menuseparator>::</menuseparator><menudescription><pre xml:space="preserve">
</pre></menudescription></menuentry></menu>

<node name="Combine-Files" spaces=" "><nodename>Combine Files</nodename><nodenext spaces=" ">Global Distribution of Long-term Average</nodenext><nodeprev spaces=" ">CMIP5 Example</nodeprev><nodeup spaces=" ">CMIP5 Example</nodeup></node>
<section spaces=" "><sectiontitle>Combine Files</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3325">file combination</indexterm></cindex>
<para>Sometimes, the data of one ensemble member will be stored in several
files to reduce single file size.
It is more convenient to concatenate these files into a single
timeseries, and the following script illustrates how.
Key steps include: 
</para><enumerate first="1" endspaces=" ">
<listitem> <para>Obtain number and names (or partial names) of files in a directory
</para></listitem><listitem> <para>Concatenate files along the record dimension (usually time) using 
<command>ncrcat</command> (<pxref label="ncrcat-netCDF-Record-Concatenator"><xrefnodename>ncrcat netCDF Record Concatenator</xrefnodename></pxref>).
</para></listitem></enumerate>
<example endspaces=" ">
<verbatiminclude file="xmp/cmb_fl.sh" spaces=" ">xmp/cmb_fl.sh</verbatiminclude>
</example>

<para><acronym><acronymword>CMIP5</acronymword></acronym> model data downloaded from the Earth System Grid
Federation (<uref><urefurl>http://pcmdi9.llnl.gov/esgf-web-fe/</urefurl><urefdesc spaces=" "><acronym><acronymword>ESGF</acronymword></acronym></urefdesc></uref>) 
does not contain group features yet. 
Therefore users must aggregate flat files into hierarchical ones themselves.
The following script shows how.
Each dataset becomes a group in the output file.
There can be several levels of groups.
In this example, we employ two experiments (&textldquo;scenarios&textrdquo;) as the top-level.
The second-level comprises different models (e.g., <acronym><acronymword>CCSM4</acronymword></acronym>, <acronym><acronymword>CESM1-BGC</acronymword></acronym>).
Many models are run multiple times with slight perturbed initial
conditions to produce an ensemble of realizations.
These ensemble members comprise the third level of the hierarchy.
The script selects two variables, <var>snc</var> and <var>snd</var> (snow cover
and snow depth).
<cindex index="cp" spaces=" "><indexterm index="cp" number="3326"><option>--gag</option></indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3327">aggregation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3328">group aggregation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3329">groups, creating</indexterm></cindex>
</para><example endspaces=" ">
<verbatiminclude file="xmp/cmb_fl_grp.sh" spaces=" ">xmp/cmb_fl_grp.sh</verbatiminclude>
</example>

</section>
<node name="Global-Distribution-of-Long_002dterm-Average" spaces=" "><nodename>Global Distribution of Long-term Average</nodename><nodenext spaces=" ">Annual Average over Regions</nodenext><nodeprev spaces=" ">Combine Files</nodeprev><nodeup spaces=" ">CMIP5 Example</nodeup></node>
<section spaces=" "><sectiontitle>Global Distribution of Long-term Average</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3330">spatial distribution</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3331">long-term average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3332">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3333">time-averaging</indexterm></cindex>
<float name="fgr_003aglb" type="Figure" number="7.1" spaces=" " endspaces=" "><floattype>Figure</floattype><floatname>fgr:glb</floatname>
<image><imagefile>xmp/fgr1</imagefile><imagewidth>3.5in</imagewidth></image> 
<caption><para>Global Distribution of Long-term Average.</para></caption>
</float>
<noindent></noindent>
<para>This section illustrates how to calculate the global distribution of
long-term average (<pxref label="fgr_003aglb"><xrefnodename>fgr:glb</xrefnodename></pxref>) with either flat files or 
<uref><urefurl>http://nco.sourceforge.net/nco.html#index-groups</urefurl><urefdesc spaces=" ">group file</urefdesc></uref>.
Key steps include: 
</para><enumerate first="1" endspaces=" ">
<listitem> <para>Average ensemble members of each model using <command>nces</command> (<pxref label="nces-netCDF-Ensemble-Statistics"><xrefnodename>nces netCDF Ensemble Statistics</xrefnodename></pxref>)
</para></listitem><listitem> <para>Average the record dimension using <command>ncra</command> (<pxref label="ncra-netCDF-Record-Averager"><xrefnodename>ncra netCDF Record Averager</xrefnodename></pxref>)
</para></listitem><listitem> <para>Store results of each model as a distinct group in a single output file using <command>ncecat</command> (<pxref label="ncrcat-netCDF-Record-Concatenator"><xrefnodename>ncrcat netCDF Record Concatenator</xrefnodename></pxref>) with the <option>--gag</option> option
</para></listitem></enumerate>
<para>The first example shows how to process flat files.
</para><example endspaces=" ">
<verbatiminclude file="xmp/glb_avg.sh" spaces=" ">xmp/glb_avg.sh</verbatiminclude>
</example>

<para>With the use of <key>group</key>, the above script will be shortened to <w>ONE LINE</w>.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3334">groups, averaging</indexterm></cindex>
</para><example endspaces=" ">
<pre xml:space="preserve"># Data from cmb_fl_grp.sh
# ensemble averaging
nces -O --nsm_grp --nsm_sfx='_avg' \
sn_LImon_all-mdl_all-xpt_all-nsm_200001-200512.nc \
  sn_LImon_all-mdl_all-xpt_nsm-avg.nc
</pre></example>
<para>The input file,
<file>sn_LImon_all-mdl_all-xpt_all-nsm_200001-200512.nc</file>, produced by
<file>cmb_fl_grp.sh</file>, includes all the ensemble members as groups.
The option <samp>--nsm_grp</samp> denotes 
that we are using <uref><urefurl>http://nco.sf.net/nco.html#nsm_grp</urefurl><urefdesc spaces=" ">group ensembles mode</urefdesc></uref> of <command>nces</command>, 
instead of <uref><urefurl>http://nco.sf.net/nco.html#nsm_fl</urefurl><urefdesc spaces=" ">file ensembles mode</urefdesc></uref>, <samp>--nsm_fl</samp>.
The option <samp>--nsm_sfx='_avg'</samp> instructs <command>nces</command> 
to store the output as a new child group <file>/[model]/[model name]_avg/var</file>;
otherwise, the output will be stored directly in the parent group <file>/[model]/var</file>. 
In the final output file, <file>sn_LImon_all-mdl_all-xpt_nsm-avg_tm-avg.nc</file>, 
sub-groups with a suffix of &textlsquo;avg&textrsquo; are the long-term averages of each model.
One thing to notice is that for now, 
ensembles with only one ensemble member will be left untouched.
</para>
</section>
<node name="Annual-Average-over-Regions" spaces=" "><nodename>Annual Average over Regions</nodename><nodenext spaces=" ">Monthly Cycle</nodenext><nodeprev spaces=" ">Global Distribution of Long-term Average</nodeprev><nodeup spaces=" ">CMIP5 Example</nodeup></node>
<section spaces=" "><sectiontitle>Annual Average over Regions</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3335">annual average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3336">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3337">time-averaging</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3338">area-averaging</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3339">dimension order</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3340">anomalies</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3341">standard deviation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3342">renaming variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3343">attributes, editing</indexterm></cindex>
<cindex index="cp" spaces="	"><indexterm index="cp" number="3344">attributes, modifying</indexterm></cindex>
<cindex index="cp" spaces="	"><indexterm index="cp" number="3345">attributes, overwriting</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3346">regression</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3347">nco script file</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3348">variables, appending</indexterm></cindex>
<float name="fgr_003aanl" type="Figure" number="7.2" spaces=" " endspaces=" "><floattype>Figure</floattype><floatname>fgr:anl</floatname>
<image><imagefile>xmp/fgr2</imagefile><imagewidth>4in</imagewidth></image>
<caption><para>Annual Average over Regions.</para></caption>
</float>
<noindent></noindent>
<para>This section illustrates how to calculate the annual average over
specific regions (<pxref label="fgr_003aanl"><xrefnodename>fgr:anl</xrefnodename></pxref>).
Key steps include: 
</para><enumerate first="1" endspaces=" ">
<listitem> <para>Spatial average using <command>ncap2</command> (<pxref label="ncap2-netCDF-Arithmetic-Processor"><xrefnodename>ncap2 netCDF Arithmetic Processor</xrefnodename></pxref>) and <command>ncwa</command> (<pxref label="ncwa-netCDF-Weighted-Averager"><xrefnodename>ncwa netCDF Weighted Averager</xrefnodename></pxref>); 
</para></listitem><listitem> <para>Change dimension order using <command>ncpdq</command> (<pxref label="ncpdq-netCDF-Permute-Dimensions-Quickly"><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></pxref>);
</para></listitem><listitem> <para>Annual average using <command>ncra</command> (<pxref label="ncra-netCDF-Record-Averager"><xrefnodename>ncra netCDF Record Averager</xrefnodename></pxref>);
</para></listitem><listitem> <para>Anomaly from long-term average using <command>ncbo</command> (<pxref label="ncbo-netCDF-Binary-Operator"><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></pxref>);
</para></listitem><listitem> <para>Standard deviation using <command>ncbo</command> (<pxref label="ncbo-netCDF-Binary-Operator"><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></pxref>) and <command>nces</command> (<pxref label="nces-netCDF-Ensemble-Statistics"><xrefnodename>nces netCDF Ensemble Statistics</xrefnodename></pxref>);
</para></listitem><listitem> <para>Rename variables using <command>ncrename</command> (<pxref label="ncrename-netCDF-Renamer"><xrefnodename>ncrename netCDF Renamer</xrefnodename></pxref>);
</para></listitem><listitem> <para>Edit attributions using <command>ncatted</command> (<pxref label="ncatted-netCDF-Attribute-Editor"><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></pxref>);
</para></listitem><listitem> <para>Linear regression using <command>ncap2</command> (<pxref label="ncap2-netCDF-Arithmetic-Processor"><xrefnodename>ncap2 netCDF Arithmetic Processor</xrefnodename></pxref>);
</para></listitem><listitem> <para>Use <command>ncap2</command> (<pxref label="ncap2-netCDF-Arithmetic-Processor"><xrefnodename>ncap2 netCDF Arithmetic Processor</xrefnodename></pxref>) with nco script file (i.e., <file>.nco</file> file);
</para></listitem><listitem> <para>Move variables around using <command>ncks</command> (<pxref label="ncks-netCDF-Kitchen-Sink"><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></pxref>).
</para></listitem></enumerate>
<para><strong>Flat files example</strong>
</para><example endspaces=" ">
<verbatiminclude file="xmp/ann_avg.sh" spaces=" ">xmp/ann_avg.sh</verbatiminclude>
</example>
<para><strong>gsl_rgr.nco</strong>
</para><example endspaces=" ">
<verbatiminclude file="xmp/gsl_rgr.nco" spaces=" ">xmp/gsl_rgr.nco</verbatiminclude>
</example>

<para>With the <key>group</key> feature, 
all the loops over experiments, models and ensemble members can be omitted.
As we are working on implementing <key>group</key> feature in all <acronym><acronymword>NCO</acronymword></acronym> operators,
some functions (e.g., regression and standard deviation over ensemble members) 
may have to wait until the new versions.
<cindex index="cp" spaces=" "><indexterm index="cp" number="3349">group, spatial averaging</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3350">group, temporal averaging</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3351">group, anomaly</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3352">group, standard deviation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3353">group, aggregation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3354">group, dimension permutation</indexterm></cindex>
</para><example endspaces=" ">
<verbatiminclude file="xmp/ann_avg_grp.sh" spaces=" ">xmp/ann_avg_grp.sh</verbatiminclude>
</example>

</section>
<node name="Monthly-Cycle" spaces=" "><nodename>Monthly Cycle</nodename><nodenext spaces=" ">Regrid MODIS Data</nodenext><nodeprev spaces=" ">Annual Average over Regions</nodeprev><nodeup spaces=" ">CMIP5 Example</nodeup></node>
<section spaces=" "><sectiontitle>Monthly Cycle</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3355">monthly average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3356">average</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3357">time-averaging</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3358">anomalies</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3359">geographical weight</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3360">weighted average</indexterm></cindex>
<float name="fgr_003amon" type="Figure" number="7.3" spaces=" " endspaces=" "><floattype>Figure</floattype><floatname>fgr:mon</floatname>
<image><imagefile>xmp/fgr3</imagefile><imagewidth>4in</imagewidth></image>
<caption><para>Monthly Cycle.</para></caption>
</float>
<noindent></noindent>
<para>This script illustrates how to calculate the monthly anomaly from the
annual average (<pxref label="fgr_003amon"><xrefnodename>fgr:mon</xrefnodename></pxref>). 
In order to keep only the monthly cycle,
we will subtract the annual average of each year from the monthly data,
instead of subtracting the long-term average.
This is a little more complicated in coding since we need to loop over years. 
</para>
<para><strong>Flat files example</strong>
</para><example endspaces=" ">
<verbatiminclude file="xmp/mcc.sh" spaces=" ">xmp/mcc.sh</verbatiminclude>
</example>
<para>Using <key>group</key> feature and <uref><urefurl>http://nco.sourceforge.net/nco.html#Hyperslabs</urefurl><urefdesc spaces=" ">hyperslabs</urefdesc></uref> of <command>ncbo</command>,
the script will be shortened.
</para><example endspaces=" ">
<verbatiminclude file="xmp/mcc_grp.sh" spaces=" ">xmp/mcc_grp.sh</verbatiminclude>
</example>

</section>
<node name="Regrid-MODIS-Data" spaces=" "><nodename>Regrid MODIS Data</nodename><nodenext spaces=" ">Add Coordinates to MODIS Data</nodenext><nodeprev spaces=" ">Monthly Cycle</nodeprev><nodeup spaces=" ">CMIP5 Example</nodeup></node>
<section spaces=" "><sectiontitle>Regrid <acronym><acronymword>MODIS</acronymword></acronym> Data</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3361">regrid</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3362">MODIS</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3363">bilinear interpolation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3364">interpolation</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3365">renaming variables</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3366">renaming attributes</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3367">renaming dimensions</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3368">attributes, editing</indexterm></cindex>
<cindex index="cp" spaces="	"><indexterm index="cp" number="3369">attributes, modifying</indexterm></cindex>
<cindex index="cp" spaces="	"><indexterm index="cp" number="3370">attributes, overwriting</indexterm></cindex>
<para>In order to compare the results between <acronym><acronymword>MODIS</acronymword></acronym> and
<acronym><acronymword>CMIP5</acronymword></acronym> models, one usually regrids one or both datasets so 
that the spatial resolutions match. 
Here, the script illustrates how to regrid <acronym><acronymword>MODIS</acronymword></acronym> data.
Key steps include:
</para><enumerate first="1" endspaces=" ">
<listitem> <para>Regrid using bilinear interpolation (<pxref label="Bilinear-interpolation"><xrefnodename>Bilinear interpolation</xrefnodename></pxref>)
</para></listitem><listitem> <para>Rename variables, dimensions and attributions using <command>ncrename</command> (<pxref label="ncrename-netCDF-Renamer"><xrefnodename>ncrename netCDF Renamer</xrefnodename></pxref>).
</para></listitem></enumerate>
<para><strong>Main Script</strong>
</para><example endspaces=" ">
<verbatiminclude file="xmp/rgr.sh" spaces=" ">xmp/rgr.sh</verbatiminclude>
</example>
<para><strong>bi_interp.nco</strong>
</para><example endspaces=" ">
<verbatiminclude file="xmp/bi_interp.nco" spaces=" ">xmp/bi_interp.nco</verbatiminclude>
</example>

</section>
<node name="Add-Coordinates-to-MODIS-Data" spaces=" "><nodename>Add Coordinates to MODIS Data</nodename><nodenext spaces=" ">Permute MODIS Coordinates</nodenext><nodeprev spaces=" ">Regrid MODIS Data</nodeprev><nodeup spaces=" ">CMIP5 Example</nodeup></node>
<section spaces=" "><sectiontitle>Add Coordinates to <acronym><acronymword>MODIS</acronymword></acronym> Data</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3371">MODIS</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3372">coordinates</indexterm></cindex>
<para><strong>Main Script</strong>
</para><example endspaces=" ">
<verbatiminclude file="xmp/add_crd.sh" spaces=" ">xmp/add_crd.sh</verbatiminclude>
</example>
<para><strong>crd.nco</strong>
</para><example endspaces=" ">
<verbatiminclude file="xmp/crd.nco" spaces=" ">xmp/crd.nco</verbatiminclude>
</example>

</section>
<node name="Permute-MODIS-Coordinates" spaces=" "><nodename>Permute MODIS Coordinates</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">Add Coordinates to MODIS Data</nodeprev><nodeup spaces=" ">CMIP5 Example</nodeup></node>
<section spaces=" "><sectiontitle>Permute <acronym><acronymword>MODIS</acronymword></acronym> Coordinates</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3373">coordinates, modifying</indexterm></cindex>
<!-- c NB: 20140130: @textdegree is in TeXInfo 4.12 but Mac OS X 10.8 ships with 4.8 -->
<para><acronym><acronymword>MODIS</acronymword></acronym> orders latitude data from 90&deg;N to
-90&deg;N, and longitude from -180&deg;E to
180&deg;E.   
However, <acronym><acronymword>CMIP5</acronymword></acronym> orders latitude from -90&deg;N to
90&deg;N, and longitude from 0&deg;E to
360&deg;E.  
This script changes the <acronym><acronymword>MODIS</acronymword></acronym> coordinates to follow the
<acronym><acronymword>CMIP5</acronymword></acronym> convention.
</para><example endspaces=" ">
<verbatiminclude file="xmp/pmt_crd.sh" spaces=" ">xmp/pmt_crd.sh</verbatiminclude>
</example>

<ignore endspaces=" ">
@node Hierarchical Data Files, Parallel, CMIP5 Example, Top
section Hierarchical Data Files
@cindex hierarchical data
@cindex groups
Hierarchical Data Files support arbitrarily nested groups.
The following @acronym{NCO} operators now can work recursively through all groups:
@itemize @bullet
@item @command{ncbo} (@pxref{ncbo netCDF Binary Operator})
@item @command{ncecat} (@pxref{ncecat netCDF Ensemble Concatenator})
@item @command{ncks} (@pxref{ncks netCDF Kitchen Sink})
@item @command{ncpdq} (@pxref{ncpdq netCDF Permute Dimensions Quickly})
@item @command{ncwa} (@pxref{ncwa netCDF Weighted Averager})
@end itemize
Here is an example showing:
@enumerate
@item How to create a hierarchical data file from multiple files using @command{ncecat} (@pxref{ncecat netCDF Ensemble Concatenator}) or @command{ncks} (@pxref{ncks netCDF Kitchen Sink});
@item Hyperslabs using @command{ncks} (@pxref{ncks netCDF Kitchen Sink});
@item Spatial average and time average using @command{ncwa} (@pxref{ncwa netCDF Weighted Averager});
@item Anomaly from average using @command{ncbo} (@pxref{ncbo netCDF Binary Operator}).
@end enumerate
@example
@verbatiminclude xmp/grp.sh
@end example
</ignore>

<html endspaces=" ">
&lt;a name=&quot;parallel&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#parallel --&gt;
&lt;a name=&quot;prl&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#prl --&gt;
&lt;a name=&quot;swift&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#swift --&gt;
&lt;a name=&quot;swf&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#swf --&gt;
&lt;a name=&quot;Parallel&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#Parallel --&gt;
&lt;a name=&quot;Swift&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#Swift --&gt;
</html>
</section>
</chapter>
<node name="Parallel" spaces=" "><nodename>Parallel</nodename><nodenext spaces=" ">CCSM Example</nodenext><nodeprev spaces=" ">CMIP5 Example</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>Parallel</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3374">Parallel</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3375">Swift</indexterm></cindex>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3376"><command>parallel</command></indexterm></cindex>
<para>This section will describe <acronym><acronymword>NCO</acronymword></acronym> scripting strategies.
Many techniques can be used to exploit script-level parallelism,
including <acronym><acronymword>GNU</acronymword></acronym> Parallel and Swift.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
ls *historical*.nc | parallel ncks -O -d time,&quot;1950-01-01&quot;,&quot;2000-01-01&quot; {} 50y/{}
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;ccsm&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#ccsm --&gt;
</html>
</chapter>
<node name="CCSM-Example" spaces=" "><nodename>CCSM Example</nodename><nodenext spaces=" ">mybibnode</nodenext><nodeprev spaces=" ">Parallel</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>CCSM Example</sectiontitle>
<cindex index="cp" spaces=" "><indexterm index="cp" number="3377">CCSM</indexterm></cindex>

<para>This chapter illustrates how to use <acronym><acronymword>NCO</acronymword></acronym> to
process and analyze the results of a <acronym><acronymword>CCSM</acronymword></acronym> climate simulation.
</para><example endspaces=" ">
<verbatim xml:space="preserve" endspaces=" ">
************************************************************************
Task 0: Finding input files
x************************************************************************
The CCSM model outputs files to a local directory like:

/ptmp/zender/archive/T42x1_40

Each component model has its own subdirectory, e.g., 

/ptmp/zender/archive/T42x1_40/atm
/ptmp/zender/archive/T42x1_40/cpl
/ptmp/zender/archive/T42x1_40/ice
/ptmp/zender/archive/T42x1_40/lnd
/ptmp/zender/archive/T42x1_40/ocn

within which model output is tagged with the particular model name

/ptmp/zender/archive/T42x1_40/atm/T42x1_40.cam2.h0.0001-01.nc
/ptmp/zender/archive/T42x1_40/atm/T42x1_40.cam2.h0.0001-02.nc
/ptmp/zender/archive/T42x1_40/atm/T42x1_40.cam2.h0.0001-03.nc
...
/ptmp/zender/archive/T42x1_40/atm/T42x1_40.cam2.h0.0001-12.nc
/ptmp/zender/archive/T42x1_40/atm/T42x1_40.cam2.h0.0002-01.nc
/ptmp/zender/archive/T42x1_40/atm/T42x1_40.cam2.h0.0002-02.nc
...

or 

/ptmp/zender/archive/T42x1_40/lnd/T42x1_40.clm2.h0.0001-01.nc
/ptmp/zender/archive/T42x1_40/lnd/T42x1_40.clm2.h0.0001-02.nc
/ptmp/zender/archive/T42x1_40/lnd/T42x1_40.clm2.h0.0001-03.nc
...

************************************************************************
Task 1: Regional processing
************************************************************************
A common task in data processing is often creating seasonal cycles.
Imagine a 100-year simulation with its 1200 monthly mean files.
Our goal is to create a single file containing 12 months of data.
Each month in the output file is the mean of 100 input files.

Normally, we store the &quot;reduced&quot; data in a smaller, local directory.

caseid='T42x1_40'
#drc_in=&quot;${DATA}/archive/${caseid}/atm&quot;
drc_in=&quot;${DATA}/${caseid}&quot;
drc_out=&quot;${DATA}/${caseid}&quot;
mkdir -p ${drc_out}
cd ${drc_out}

Method 1: Assume all data in directory applies
for mth in {1..12}; do
  mm=`printf &quot;%02d&quot; $mth`
  ncra -O -D 1 -o ${drc_out}/${caseid}_clm${mm}.nc \
    ${drc_in}/${caseid}.cam2.h0.*-${mm}.nc 
done # end loop over mth

Method 2: Use shell 'globbing' to construct input filenames
for mth in {1..12}; do
  mm=`printf &quot;%02d&quot; $mth`
  ncra -O -D 1 -o ${drc_out}/${caseid}_clm${mm}.nc \
    ${drc_in}/${caseid}.cam2.h0.00??-${mm}.nc \
    ${drc_in}/${caseid}.cam2.h0.0100-${mm}.nc
done # end loop over mth

Method 3: Construct input filename list explicitly
for mth in {1..12}; do
  mm=`printf &quot;%02d&quot; $mth`
  fl_lst_in=''
  for yr in {1..100}; do
    yyyy=`printf &quot;%04d&quot; $yr`
    fl_in=${caseid}.cam2.h0.${yyyy}-${mm}.nc
    fl_lst_in=&quot;${fl_lst_in} ${caseid}.cam2.h0.${yyyy}-${mm}.nc&quot;
  done # end loop over yr
  ncra -O -D 1 -o ${drc_out}/${caseid}_clm${mm}.nc -p ${drc_in} \
    ${fl_lst_in}
done # end loop over mth

Make sure the output file averages correct input files!
ncks --trd -M prints global metadata: 

  ncks --trd -M ${drc_out}/${caseid}_clm01.nc

The input files ncra used to create the climatological monthly mean
will appear in the global attribute named 'history'.

Use ncrcat to aggregate the climatological monthly means

  ncrcat -O -D 1 \
    ${drc_out}/${caseid}_clm??.nc ${drc_out}/${caseid}_clm_0112.nc

Finally, create climatological means for reference.
The climatological time-mean:

  ncra -O -D 1 \
    ${drc_out}/${caseid}_clm_0112.nc ${drc_out}/${caseid}_clm.nc

The climatological zonal-mean:

  ncwa -O -D 1 -a lon \
    ${drc_out}/${caseid}_clm.nc ${drc_out}/${caseid}_clm_x.nc

The climatological time- and spatial-mean:

  ncwa -O -D 1 -a lon,lat,time -w gw \
    ${drc_out}/${caseid}_clm.nc ${drc_out}/${caseid}_clm_xyt.nc

This file contains only scalars, e.g., &quot;global mean temperature&quot;,
used for summarizing global results of a climate experiment.

Climatological monthly anomalies = Annual Cycle: 
Subtract climatological mean from climatological monthly means. 
Result is annual cycle, i.e., climate-mean has been removed.

  ncbo -O -D 1 -o ${drc_out}/${caseid}_clm_0112_anm.nc \
    ${drc_out}/${caseid}_clm_0112.nc ${drc_out}/${caseid}_clm_xyt.nc

************************************************************************
Task 2: Correcting monthly averages
************************************************************************
The previous step appoximates all months as being equal, so, e.g.,
February weighs slightly too much in the climatological mean.
This approximation can be removed by weighting months appropriately.
We must add the number of days per month to the monthly mean files.
First, create a shell variable dpm:

unset dpm # Days per month
declare -a dpm
dpm=(0 31 28.25 31 30 31 30 31 31 30 31 30 31) # Allows 1-based indexing

Method 1: Create dpm directly in climatological monthly means
for mth in {1..12}; do
  mm=`printf &quot;%02d&quot; ${mth}`
  ncap2 -O -s &quot;dpm=0.0*date+${dpm[${mth}]}&quot; \
    ${drc_out}/${caseid}_clm${mm}.nc ${drc_out}/${caseid}_clm${mm}.nc
done # end loop over mth

Method 2: Create dpm by aggregating small files
for mth in {1..12}; do
  mm=`printf &quot;%02d&quot; ${mth}`
  ncap2 -O -v -s &quot;dpm=${dpm[${mth}]}&quot; ~/nco/data/in.nc \
    ${drc_out}/foo_${mm}.nc
done # end loop over mth
ncecat -O -D 1 -p ${drc_out} -n 12,2,2 foo_${mm}.nc foo.nc
ncrename -O -D 1 -d record,time ${drc_out}/foo.nc
ncatted -O -h \
  -a long_name,dpm,o,c,&quot;Days per month&quot; \
  -a units,dpm,o,c,&quot;days&quot; \
  ${drc_out}/${caseid}_clm_0112.nc
ncks -A -v dpm ${drc_out}/foo.nc ${drc_out}/${caseid}_clm_0112.nc

Method 3: Create small netCDF file using ncgen
cat &gt; foo.cdl &lt;&lt; 'EOF'
netcdf foo { 
dimensions:
	time=unlimited;
variables:
	float dpm(time);
	dpm:long_name=&quot;Days per month&quot;;
	dpm:units=&quot;days&quot;;
data:
	dpm=31,28.25,31,30,31,30,31,31,30,31,30,31;
}
EOF
ncgen -b -o foo.nc foo.cdl
ncks -A -v dpm ${drc_out}/foo.nc ${drc_out}/${caseid}_clm_0112.nc

Another way to get correct monthly weighting is to average daily
output files, if available.  

************************************************************************
Task 3: Regional processing
************************************************************************
Let's say you are interested in examining the California region.
Hyperslab your dataset to isolate the appropriate latitude/longitudes.

ncks -O -D 1 -d lat,30.0,37.0 -d lon,240.0,270.0 \ 
    ${drc_out}/${caseid}_clm_0112.nc \
    ${drc_out}/${caseid}_clm_0112_Cal.nc

The dataset is now much smaller!
To examine particular metrics.

************************************************************************
Task 4: Accessing data stored remotely
************************************************************************
OPeNDAP server examples:

UCI DAP servers:
ncks --trd -M -p http://dust.ess.uci.edu/cgi-bin/dods/nph-dods/dodsdata in.nc
ncrcat -O -C -D 3 \
  -p http://dust.ess.uci.edu/cgi-bin/dods/nph-dods/dodsdata \
  -l /tmp in.nc in.nc ~/foo.nc

Unidata DAP servers:
ncks --trd -M -p http://thredds-test.ucar.edu/thredds/dodsC/testdods in.nc
ncrcat -O -C -D 3 \
  -p http://thredds-test.ucar.edu/thredds/dodsC/testdods \
  -l /tmp in.nc in.nc ~/foo.nc

NOAA DAP servers:
ncwa -O -C -a lat,lon,time -d lon,-10.,10. -d lat,-10.,10. -l /tmp -p \
http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis.dailyavgs/surface \
pres.sfc.1969.nc ~/foo.nc

LLNL PCMDI IPCC OPeNDAP Data Portal: 
ncks --trd -M -p http://username:password@esgcet.llnl.gov/cgi-bin/dap-cgi.py/ipcc4/sresa1b/ncar_ccsm3_0 pcmdi.ipcc4.ncar_ccsm3_0.sresa1b.run1.atm.mo.xml

Earth System Grid (ESG): http://www.earthsystemgrid.org

caseid='b30.025.ES01' 
CCSM3.0 1% increasing CO2 run, T42_gx1v3, 200 years starting in year 400
Atmospheric post-processed data, monthly averages, e.g.,
/data/zender/tmp/b30.025.ES01.cam2.h0.TREFHT.0400-01_cat_0449-12.nc
/data/zender/tmp/b30.025.ES01.cam2.h0.TREFHT.0400-01_cat_0599-12.nc

ESG supports password-protected FTP access by registered users
NCO uses the .netrc file, if present, for password-protected FTP access 
Syntax for accessing single file is, e.g.,
ncks -O -D 3 \
  -p ftp://climate.llnl.gov/sresa1b/atm/mo/tas/ncar_ccsm3_0/run1 \
  -l /tmp tas_A1.SRESA1B_1.CCSM.atmm.2000-01_cat_2099-12.nc ~/foo.nc 

# Average surface air temperature tas for SRESA1B scenario
# This loop is illustrative and will not work until NCO correctly
# translates '*' to FTP 'mget' all remote files
for var in 'tas'; do
for scn in 'sresa1b'; do
for mdl in 'cccma_cgcm3_1 cccma_cgcm3_1_t63 cnrm_cm3 csiro_mk3_0 \
gfdl_cm2_0 gfdl_cm2_1 giss_aom giss_model_e_h giss_model_e_r \
iap_fgoals1_0_g inmcm3_0 ipsl_cm4 miroc3_2_hires miroc3_2_medres \
miub_echo_g mpi_echam5 mri_cgcm2_3_2a ncar_ccsm3_0 ncar_pcm1 \
ukmo_hadcm3 ukmo_hadgem1'; do
for run in '1'; do
        ncks -R -O -D 3 -p ftp://climate.llnl.gov/${scn}/atm/mo/${var}/${mdl}/run${run} -l ${DATA}/${scn}/atm/mo/${var}/${mdl}/run${run} '*' ${scn}_${mdl}_${run}_${var}_${yyyymm}_${yyyymm}.nc
done # end loop over run
done # end loop over mdl
done # end loop over scn
done # end loop over var

cd sresa1b/atm/mo/tas/ukmo_hadcm3/run1/
ncks -H -m -v lat,lon,lat_bnds,lon_bnds -M tas_A1.nc | m
bds -x 096 -y 073 -m 33 -o ${DATA}/data/dst_3.75x2.5.nc # ukmo_hadcm3
ncview ${DATA}/data/dst_3.75x2.5.nc

# msk_rgn is California mask on ukmo_hadcm3 grid
# area is correct area weight on ukmo_hadcm3 grid
ncks -A -v area,msk_rgn ${DATA}/data/dst_3.75x2.5.nc \
${DATA}/sresa1b/atm/mo/tas/ukmo_hadcm3/run1/area_msk_ukmo_hadcm3.nc 

Template for standardized data:
${scn}_${mdl}_${run}_${var}_${yyyymm}_${yyyymm}.nc

e.g., raw data
${DATA}/sresa1b/atm/mo/tas/ukmo_hadcm3/run1/tas_A1.nc
becomes standardized data

Level 0: raw from IPCC site--no changes except for name 
         Make symbolic link name match raw data
Template: ${scn}_${mdl}_${run}_${var}_${yyyymm}_${yyyymm}.nc

ln -s -f tas_A1.nc sresa1b_ukmo_hadcm3_run1_tas_200101_209911.nc
area_msk_ukmo_hadcm3.nc

Level I: Add all variables (not standardized in time)
         to file containing msk_rgn and area
Template: ${scn}_${mdl}_${run}_${yyyymm}_${yyyymm}.nc

/bin/cp area_msk_ukmo_hadcm3.nc sresa1b_ukmo_hadcm3_run1_200101_209911.nc
ncks -A -v tas sresa1b_ukmo_hadcm3_run1_tas_200101_209911.nc \
               sresa1b_ukmo_hadcm3_run1_200101_209911.nc
ncks -A -v pr  sresa1b_ukmo_hadcm3_run1_pr_200101_209911.nc \
               sresa1b_ukmo_hadcm3_run1_200101_209911.nc

If already have file then:
mv sresa1b_ukmo_hadcm3_run1_200101_209911.nc foo.nc
/bin/cp area_msk_ukmo_hadcm3.nc sresa1b_ukmo_hadcm3_run1_200101_209911.nc
ncks -A -v tas,pr foo.nc sresa1b_ukmo_hadcm3_run1_200101_209911.nc

Level II: Correct # years, months
Template: ${scn}_${mdl}_${run}_${var}_${yyyymm}_${yyyymm}.nc

ncks -d time,....... file1.nc file2.nc 
ncrcat file2.nc file3.nc sresa1b_ukmo_hadcm3_run1_200001_209912.nc

Level III: Many derived products from level II, e.g., 

      A. Global mean timeseries
      ncwa -w area -a lat,lon \
           sresa1b_ukmo_hadcm3_run1_200001_209912.nc \
	   sresa1b_ukmo_hadcm3_run1_200001_209912_xy.nc

      B. Califoria average timeseries
      ncwa -m msk_rgn -w area -a lat,lon \
           sresa1b_ukmo_hadcm3_run1_200001_209912.nc \
	   sresa1b_ukmo_hadcm3_run1_200001_209912_xy_Cal.nc
</verbatim>
</example>

<html endspaces=" ">
&lt;a name=&quot;bibliography&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bibliography --&gt;
&lt;a name=&quot;bib&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#bib --&gt;
</html>
</chapter>
<node name="mybibnode" spaces=" "><nodename>mybibnode</nodename><nodenext spaces=" ">General Index</nodenext><nodeprev spaces=" ">CCSM Example</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<chapter spaces=" "><sectiontitle>References</sectiontitle>
<itemize commandarg="bullet" automaticcommandarg="on" endspaces=" "><itemprepend><formattingcommand command="bullet" automatic="on"/></itemprepend>
<beforefirstitem></beforefirstitem><listitem><prepend>&bullet;</prepend>
<anchor name="ZeM07">ZeM07</anchor><para>[ZeM07]
<!-- c %**else if -->
 Zender, C. S., and H. J. Mangalam (2007), Scaling Properties of Common Statistical Operators for Gridded Datasets, Int. J. High Perform. Comput. Appl., 21(4), 485-498, doi:10.1177/1094342007083802.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="Zen08">Zen08</anchor><para>[Zen08]
<!-- c %**else if -->
 Zender, C. S. (2008), Analysis of Self-describing Gridded Geoscience Data with netCDF Operators (NCO), Environ. Modell. Softw., 23(10), 1338-1342, doi:10.1016/j.envsoft.2008.03.004.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="WZJ07">WZJ07</anchor><para>[WZJ07]
<!-- c %**else if -->
 Wang, D. L., C. S. Zender, and S. F. Jenks (2007), DAP-enabled Server-side Data Reduction and Analysis, Proceedings of the 23rd AMS Conference on Interactive Information and Processing Systems (IIPS) for Meteorology, Oceanography, and Hydrology, Paper 3B.2, January 14-18, San Antonio, TX. American Meteorological Society, AMS Press, Boston, MA.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="ZMW06">ZMW06</anchor><para>[ZMW06]
<!-- c %**else if -->
 Zender, C. S., H. Mangalam, and D. L. Wang (2006), Improving Scaling Properties of Common Statistical Operators for Gridded Geoscience Datasets, Eos Trans. AGU, 87(52), Fall Meet. Suppl., Abstract IN53B-0827.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="ZeW07">ZeW07</anchor><para>[ZeW07]
<!-- c %**else if -->
 Zender, C. S., and D. L. Wang (2007), High performance distributed data reduction and analysis with the netCDF Operators (NCO), Proceedings of the 23rd AMS Conference on Interactive Information and Processing Systems (IIPS) for Meteorology, Oceanography, and Hydrology, Paper 3B.4, January 14-18, San Antonio, TX. American Meteorological Society, AMS Press, Boston, MA.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="WZJ06">WZJ06</anchor><para>[WZJ06]
<!-- c %**else if -->
 Wang, D. L., C. S. Zender, and S. F. Jenks (2006), Server-side netCDF Data Reduction and Analysis, Eos Trans. AGU, 87(52), Fall Meet. Suppl., Abstract IN53B-0826.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="WZJ073">WZJ073</anchor><para>[WZJ073]
<!-- c %**else if -->
 Wang, D. L., C. S. Zender, and S. F. Jenks (2007), Server-side parallel data reduction and analysis, in Advances in Grid and Pervasive Computing, Second International Conference, GPC 2007, Paris, France, May 2-4, 2007, Proceedings. IEEE Lecture Notes in Computer Science, vol. 4459, edited by C. Cerin and K.-C. Li, pp. 744-750, Springer-Verlag, Berlin/Heidelberg, doi:10.1007/978-3-540-72360-8_67.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="WZJ074">WZJ074</anchor><para>[WZJ074]
<!-- c %**else if -->
 Wang, D. L., C. S. Zender and S. F. Jenks (2007), A System for Scripted Data Analysis at Remote Data Centers, Eos Trans. AGU, 88(52), Fall Meet. Suppl., Abstract IN11B-0469.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="WZJ081">WZJ081</anchor><para>[WZJ081]
<!-- c %**else if -->
 Wang, D. L., C. S. Zender and S. F. Jenks (2008), Cluster Workflow Execution of Retargeted Data Analysis Scripts, Proceedings of the 8th IEEE Int&textrsquo;l Symposium on Cluster Computing and the Grid (IEEE CCGRID &textrsquo;08), pp. 449-458, Lyon, France, May 2008.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="WZJ091">WZJ091</anchor><para>[WZJ091]
<!-- c %**else if -->
 Wang, D. L., C. S. Zender, and S. F. Jenks (2009), Efficient Clustered Server-side Data Analysis Workflows using SWAMP, Earth Sci. Inform., 2(3), 141-155, doi:10.1007/s12145-009-0021-z.
</para></listitem><listitem><prepend>&bullet;</prepend>
<anchor name="PFT88">PFT88</anchor><para>[PFT88]
<!-- c %**else if -->
 Press, Flannery, Teukolsky, and Vetterling (1988), Numerical Recipes in C, Cambridge Univ. Press, New York, NY.
</para></listitem></itemize>

<!-- c @node Name Index, General Index, Operators, Top -->
<!-- c @unnumbered Function and Variable Index -->

<!-- c @printindex fn -->

<html endspaces=" ">
&lt;a name=&quot;index&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#index --&gt;
&lt;a name=&quot;idx&quot;&gt;&lt;/a&gt; &lt;!-- http://nco.sf.net/nco.html#idx --&gt;
</html>
</chapter>
<node name="General-Index" spaces=" "><nodename>General Index</nodename><nodenext spaces="  "></nodenext><nodeprev spaces=" ">mybibnode</nodeprev><nodeup spaces=" ">Top</nodeup></node>
<unnumbered spaces=" "><sectiontitle>General Index</sectiontitle>

<syncodeindex spaces=" " from="fn" to="cp" line="fn cp"></syncodeindex>
<printindex spaces=" " value="cp" line="cp"></printindex>

<!-- c TTFN (Ta ta for now) -->
</unnumbered>
<bye></bye>
</texinfo>
