<?xml version="1.0"?>
<!DOCTYPE texinfo PUBLIC "-//GNU//DTD TexinfoML V4.11//EN" "http://www.gnu.org/software/texinfo/dtd/4.11/texinfo.dtd">
<texinfo xml:lang="en">
  <setfilename>nco.xml</setfilename><!-- Define edition, date, ... -->
  <setvalue name="nco-edition">3.9.9</setvalue>
  <setvalue name="doc-edition">3.9.9</setvalue>
  <setvalue name="copyright-years">1995&ndash;2009</setvalue>
  <setvalue name="update-year">2009</setvalue>
  <setvalue name="update-date">8 May 2009</setvalue>
  <setvalue name="update-month">May 2009</setvalue>
  <settitle><acronym><acronymword>NCO</acronymword></acronym>3.9.9 User's Guide</settitle>
<!-- Uncomment following line to produce guide in smallbook format -->
<!-- @smallbook -->
<!-- Merge function index into concept index -->
<!-- end of header -->
<!-- 20090226 Add bibliography capabilities -->
  <para>\input texinfo   
<!-- *-texinfo-*- -->
<!-- %% my-bib-macros.texi - Texinfo macros providing a crude -->
<!-- %% bibliography and citation capability. --> 
<!-- % Copyright (C) 2004  Aaron S. Hawley --> 
<!-- % Author: Aaron S. Hawley <ashawley@gnu.uvm.edu> -->
<!-- % Keywords: docs, texinfo, extensions, bib --> 
<!-- % This file is free software; you can redistribute it and/or modify -->
<!-- % it under the terms of the GNU General Public License as published by -->
<!-- % the Free Software Foundation; either version 2, or (at your option) -->
<!-- % any later version. --> 
<!-- % This file is distributed in the hope that it will be useful, -->
<!-- % but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -->
<!-- % GNU General Public License for more details. --> 
<!-- % You should have received a copy of the GNU General Public License -->
<!-- % along with GNU Emacs; see the file COPYING.  If not, write to -->
<!-- % the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -->
<!-- % Boston, MA 02111-1307, USA. --> 
<!-- %% Commentary: --> 
<!-- %%% Introduction --> 
<!-- %% Creates references to a ``Bibliography'' or ``References'' -->
<!-- %% section of a Texinfo document, using Texinfo's -->
<!-- %% macro system.  Although not as terse a way to cite systems as is -->
<!-- %% found in document systems like TeX, the format is simpler and -->
<!-- %% the rendering  is easier for non-academic readers. --> 
<!-- % --> 
<!-- %%% Usage --> 
<!-- %% References to cited works can be put in any section of a document. -->
<!-- %% The cited works must be put in either a Texinfo table (for -->
<!-- %% instance with ``@table @asis ... @end table'') or within a -->
<!-- %% Texinfo list (something like ``@enumerate ... @end enumerate'' -->
<!-- %% or ``@itemize @bullet ... @end itemize'').  They are created -->
<!-- %% with the command ``@mybibitem{REF-NAME}''.  To cite a reference -->
<!-- %% with a @mybibitem use ``@mybibcite{REF-NAME}''. --> 
<!-- %% The beginning of a document must include (using the @include -->
<!-- %% command) the file my-bib-macros.texi, which should be made -->
<!-- %% available in the current directory of the parent file.  A single -->
<!-- %% call should be made to choose to use a list or a table.  The -->
<!-- %% command to chose is called @mybibuselist{NODE}, where NODE is -->
<!-- %% the node containing the location where the references are listed. --> 
<!-- % --> 
<!-- %%% Example --> 
<!-- %% \input texinfo   @c -*-texinfo-*- -->
<!-- %% @comment %**start of header -->
<!-- %% @setfilename my-file-with-bib.info -->
<!-- %% @settitle Texinfo with a Bibliography and References -->
<!-- %% -->
<!-- %% @include my-bib-macros.texi -->
<!-- %% @mybibuselist{References} -->
<!-- %% -->
<!-- %% @comment %**end of header -->
<!-- %% -->
<!-- %% @node Top -->
<!-- %% @top Top -->
<!-- %% -->
<!-- %% @menu -->
<!-- %% * Introduction:: -->
<!-- %% * @mybibnode{}:: -->
<!-- %% -->
<!-- %% @end menu -->
<!-- %% -->
<!-- %% @node Introduction -->
<!-- %% @chapter Introduction -->
<!-- %% -->
<!-- %% The ability of a documentation format to make cross references to a -->
<!-- %% bibliography, a feature of LaTeX @mybibcite{LaTeX2e}, isn't -->
<!-- %% currently supported in Texinfo. -->
<!-- %% -->
<!-- %% @node @mybibnode{} -->
<!-- %% @chapter References -->
<!-- %% -->
<!-- %% @itemize @asis -->
<!-- %% -->
<!-- %% @mybibitem{LaTeX2e} Leslie Lamport, LaTeX User's Guide and -->
<!-- %% Reference Manual, 2nd edition, Addison-Wesley, Reading, -->
<!-- %% Massachusetts, 1994. -->
<!-- %% -->
<!-- %% @end itemize -->
<!-- %% -->
<!-- %% @bye --> 
<!-- %% --> 
<!-- %% This example produces (in Info): --> 
<!-- %%       1 Introduction -->
<!-- %%       ************** -->
<!-- %% -->
<!-- %%       The ability of a documentation format to make cross -->
<!-- %%       references to a bibliography, a feature of LaTeX (See item -->
<!-- %%       [LaTeX2e] in *Note LaTeX2e: References.), is not currently -->
<!-- %%       supported in Texinfo. -->
<!-- %% -->
<!-- %% -->
<!-- %%       2 References -->
<!-- %%       ************ -->
<!-- %% -->
<!-- %%       [LaTeX2e] Leslie Lamport, LaTeX User's Guide and Reference -->
<!-- %%       Manual, 2nd edition, Addison-Wesley, Reading, -->
<!-- %%       Massachusetts, 1994. --> 
<!-- %% and (in printed output): --> 
<!-- %%       1 Introduction -->
<!-- %%       ************** -->
<!-- %% -->
<!-- %%       The ability of a documentation format to make cross -->
<!-- %%       references to a bibliography, a feature of LaTeX (See item -->
<!-- %%       [LaTeX2e] in Chapter 2 [References], page 3.), is not -->
<!-- %%       currently supported in Texinfo. -->
<!-- %% -->
<!-- %% -->
<!-- %%       2 References -->
<!-- %%       ************ -->
<!-- %% -->
<!-- %%       [LaTeX2e] Leslie Lamport, LaTeX User's Guide and Reference -->
<!-- %%       Manual, 2nd edition, Addison-Wesley, Reading, -->
<!-- %%       Massachusetts, 1994. --> 
<!-- % --> 
<!-- %%% Notes --> 
<!-- %% The pointers to references will be functional in hypertext -->
<!-- %% documentation (info, HTML, XML and others) and properly rendered -->
<!-- %% in print documents, because they are implemented with Texinfo's -->
<!-- %% cross referencing capabilities (using @anchor and @ref).  Failures -->
<!-- %% by an author to make proper references with ``my-bib-macros'' in -->
<!-- %% their document will give cross referencing errors by Texinfo -->
<!-- %% conversion tools. --> 
<!-- %% Only one ``Reference'' section is allowed per document. --> 
<!-- %% An improvement of this system would create cross references -->
<!-- %% (with @xref) at each cited work to all the originating cross -->
<!-- %% refererences. --> 
<!-- % --> 
<!-- %% Code: --> 
<!-- % Configuration Options --> 
<!-- %% @mybibsetrefnode : Defines the name of the node to contain -->
<!-- %% references. --></para>
<!-- %% @mybibnode{} : Macro to be placed at node containing references -->
<!-- %% and calls to @mybibcite{} -->
<!-- %% @mybibusetable : Whether each @mybibitem will be put in a -->
<!-- %% table. -->
<!-- %% @mybibuselist : Whether each @mybibitem will be put in a -->
<!-- %% list. -->
<!-- %% @mybibcite{REF} : Cites the cross reference REF. -->
<!-- %% @mybibcite{REF} : Creates a cross referenced citation REF. -->
<!-- %% my-bib-macros.texi ends here -->
  <setvalue name="mybiblist">true</setvalue>
  <setvalue name="mybibrefnode">References</setvalue>
<!-- TeXInfo macros may not appear before TeXInfo @setfilename header -->
<!-- [idx] Index -->
<!-- [m s-1] Meridional wind speed -->
<!-- [m s-1] Zonal wind speed -->
<!-- TeX macros may appear anywhere after line 1 -->
<!-- install-info installs NCO info into this category -->
  <dircategory>netCDF</dircategory>
<!-- Set smallbook if printing in smallbook format -->
<!-- Example of smallbook font is actually written using smallbook -->
<!-- In bigbook, a kludge is used for TeX output -->
<!-- set smallbook -->
  <clearvalue name="smallbook"></clearvalue>
<!-- Experiment with smaller amounts of whitespace between paragraphs in the 8.5 by 11 inch format -->
<!-- Uncomment next line to remove ugly TeX warning blocks from overfull hboxes -->
  <para>This file documents <acronym><acronymword>NCO</acronymword></acronym>, a collection of utilities to manipulate and analyze netCDF files.</para>
  <para>Copyright &copyright; 1995&ndash;2009 Charlie Zender</para>
  <para>This is the first edition of the <cite>NCO User's Guide</cite>,&linebreak; and is consistent with 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, 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>
  <titlepage>
    <booktitle>NCO User's Guide</booktitle>
    <booksubtitle>A suite of netCDF operators</booksubtitle>
    <booksubtitle>Edition 3.9.9, for &lt;acronym&gt;&lt;acronymword&gt;NCO&lt;/acronymword&gt;&lt;/acronym&gt;Version 3.9.9</booksubtitle>
    <booksubtitle>May 2009</booksubtitle>
    <author>by Charlie Zender</author>
    <author>Department of Earth System Science</author>
    <author>University of California, Irvine</author>
<!-- Include Distribution inside titlepage so that headings are turned off -->
    <para>Copyright &copyright; 1995&ndash;2009 Charlie Zender.</para>
    <sp lines="2"></sp>
    <para>This is the first edition of the <cite>NCO User's Guide</cite>,&linebreak; and is consistent with version 2<!-- /@w --> of <file>texinfo.tex</file>.</para>
    <sp lines="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, 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 lines="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 lines="2"></sp>
<!-- Cover art by Robynn Rudel -->
  </titlepage>
  <node>
    <nodename>Top</nodename>
    <nodenext>Foreword</nodenext>
    <nodeprev>(dir)</nodeprev>
    <nodeup>(dir)</nodeup>
    <unnumbered>
      <title>NCO User's Guide</title>
<!-- node format: node-name, next, previous, up -->
      <para><emph>Note to readers of the NCO User's Guide in Info format</emph>: <emph>The <uref><urefurl>./nco.pdf</urefurl><urefdesc>NCO User's 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/packages/netcdf</urefurl></uref>). Each <acronym><acronymword>NCO</acronymword></acronym> operator (e.g., ncks) 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's 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 there is a mirror at <uref><urefurl>http://dust.ess.uci.edu/nco</urefurl></uref>.</para>
      <para>This documentation is for <acronym><acronymword>NCO</acronymword></acronym> version 3.9.9. It was last updated 8 May 2009. Corrections, additions, and rewrites of this documentation are very welcome.</para>
      <para>Enjoy,&linebreak; Charlie Zender</para>
      <menu>
        <menuentry>
          <menunode>Foreword</menunode>
          <menutitle>Foreword</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Summary</menunode>
          <menutitle>Summary</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Introduction</menunode>
          <menutitle>Introduction</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Strategies</menunode>
          <menutitle>Strategies</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Common features</menunode>
          <menutitle>Common features</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Operator Reference Manual</menunode>
          <menutitle>Operator Reference Manual</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Contributing</menunode>
          <menutitle>Contributing</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>CCSM Example</menunode>
          <menutitle>CCSM Example</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>mybibnode</menunode>
          <menutitle>mybibnode</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>General Index</menunode>
          <menutitle>General Index</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </unnumbered>
  </node>
  <node>
    <nodename>Foreword</nodename>
    <nodenext>Summary</nodenext>
    <nodeprev>Top</nodeprev>
    <nodeup>Top</nodeup>
    <unnumbered>
      <title>Foreword</title>
      <para><indexterm index="cp">foreword</indexterm><indexterm index="cp">Charlie Zender</indexterm><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 da Silva<!-- /@w -->, John Sheldon, and William Weibel for stimulating suggestions and correspondence. Your encouragment motivated me to complete the <cite>NCO User's Guide</cite>. So if you like <acronym><acronymword>NCO</acronymword></acronym>, send me a note! 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 lines="1"></sp>
      <para role="continues">Charlie Zender&linebreak; May 1997&linebreak; Boulder, Colorado&linebreak;</para>
      <sp lines="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>. <indexterm index="cp">open source</indexterm><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 lines="1"></sp>
      <para role="continues">Charlie Zender&linebreak; October 2000&linebreak; Irvine, California&linebreak;</para>
      <sp lines="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 lines="1"></sp>
      <para role="continues">Charlie Zender&linebreak; January 2003&linebreak; Irvine, California&linebreak;</para>
      <sp lines="2"></sp>
      <para><acronym><acronymword>NCO</acronymword></acronym> has been generously supported from 2004&ndash;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 lines="1"></sp>
      <para role="continues">Charlie Zender&linebreak; March 2008&linebreak; Grenoble, France&linebreak;</para>
    </unnumbered>
  </node>
  <node>
    <nodename>Summary</nodename>
    <nodenext>Introduction</nodenext>
    <nodeprev>Foreword</nodeprev>
    <nodeup>Top</nodeup>
    <unnumbered>
      <title>Summary</title>
      <para><indexterm index="cp">operators</indexterm><indexterm index="cp">summary</indexterm>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>
    </unnumbered>
  </node>
  <node>
    <nodename>Introduction</nodename>
    <nodenext>Strategies</nodenext>
    <nodeprev>Summary</nodeprev>
    <nodeup>Top</nodeup>
    <chapter>
      <title>Introduction</title>
      <para><indexterm index="cp">introduction</indexterm></para>
      <menu>
        <menuentry>
          <menunode>Availability</menunode>
          <menutitle>Availability</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Compatability</menunode>
          <menutitle>Compatability</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Libraries</menunode>
          <menutitle>Libraries</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>netCDF2/3/4 and HDF4/5 Support</menunode>
          <menutitle>netCDF2/3/4 and HDF4/5 Support</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Help Requests and Bug Reports</menunode>
          <menutitle>Help Requests and Bug Reports</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </chapter>
  </node>
  <node>
    <nodename>Availability</nodename>
    <nodenext>Compatability</nodenext>
    <nodeprev>Introduction</nodeprev>
    <nodeup>Introduction</nodeup>
    <section>
      <title>Availability</title>
      <para><indexterm index="cp"><acronym><acronymword>NCO</acronymword></acronym> availability</indexterm><indexterm index="cp">source code</indexterm>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>
      <para><indexterm index="cp">documentation</indexterm><indexterm index="cp">WWW documentation</indexterm><indexterm index="cp">on-line documentation</indexterm><indexterm index="cp"><acronym><acronymword>HTML</acronymword></acronym></indexterm><indexterm index="cp">&tex;info</indexterm><indexterm index="cp">Info</indexterm><indexterm index="cp"><cite>User's Guide</cite></indexterm><indexterm index="cp"><cite>NCO User's Guide</cite></indexterm>The documentation for <acronym><acronymword>NCO</acronymword></acronym> is called the <cite>NCO User's Guide</cite>. The <cite>User's Guide</cite> is available in 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.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><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>
      <para><indexterm index="cp">publications</indexterm><indexterm index="cp">presentations</indexterm>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. 
<!-- fxm query replace mybibnode with @mybibnode{} -->
<!-- The primary refereed publications are @mybibcite{ZeM06} and -->
<!-- @mybibcite{Zen07}. -->The primary refereed publications are fxm ZeM06 and fxm Zen07. These contain copyright restrictions which limit their redistribution, but they are freely available in preprint form from the <acronym><acronymword>NCO</acronymword></acronym>.</para>
      <para><indexterm index="cp"><acronym><acronymword>NCO</acronymword></acronym> homepage</indexterm>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's 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>. <indexterm index="cp">netCDF</indexterm>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/packages/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>
    </section>
  </node>
  <node>
    <nodename>Compatability</nodename>
    <nodenext>Libraries</nodenext>
    <nodeprev>Availability</nodeprev>
    <nodeup>Introduction</nodeup>
    <section>
      <title>Operating systems compatible with <acronym><acronymword>NCO</acronymword></acronym></title>
      <para><indexterm index="cp"><acronym><acronymword>OS</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>IBM</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>NEC</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>SGI</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>HP</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>DEC</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>PGI</acronymword></acronym></indexterm><indexterm index="cp">Cray</indexterm><indexterm index="cp">Digital</indexterm><indexterm index="cp">Sun</indexterm><indexterm index="cp">Intel</indexterm><indexterm index="cp">Comeau</indexterm><indexterm index="cp">Compaq</indexterm><indexterm index="cp">Macintosh</indexterm><indexterm index="cp">Microsoft</indexterm><indexterm index="cp">Windows</indexterm><indexterm index="cp">PathScale</indexterm><indexterm index="cp">QLogic</indexterm><indexterm index="cp">compatability</indexterm><indexterm index="cp">portability</indexterm><indexterm index="cp">installation</indexterm><acronym><acronymword>NCO</acronymword></acronym> has been successfully ported and tested and is known to work on the following 32- and 64-bit platforms: 
<!-- 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, <acronym><acronymword>SGI IRIX</acronymword></acronym> 5.x and 6.x, MacOS X<!-- /@w --> 10.x, <acronym><acronymword>NEC</acronymword></acronym> Super-UX 10.x, <acronym><acronymword>DEC OSF</acronymword></acronym>, Sun SunOS 4.1.x, Solaris 2.x, <acronym><acronymword>Cray UNICOS</acronymword></acronym> 8.x&ndash;10.x, and MS Windows95 and all later versions. If you port the code to a new operating system, please send me a note and any patches you required.</para>
      <para><indexterm index="cp"><acronym><acronymword>UNIX</acronymword></acronym></indexterm><indexterm index="cp">Unidata</indexterm><indexterm index="cp">UDUnits</indexterm>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 C and<!-- /@w --> Fortran interface and system calls. <acronym><acronymword>NCO</acronymword></acronym> code is tested for <acronym><acronymword>ANSI</acronymword></acronym> compliance by compiling with C compilers<!-- /@w --> including those from <indexterm index="cp"><command>CC</command></indexterm><indexterm index="cp"><command>c++</command></indexterm><indexterm index="cp"><command>cc</command></indexterm><indexterm index="cp"><command>como</command></indexterm><indexterm index="cp"><command>cxx</command></indexterm><indexterm index="cp"><command>gcc</command></indexterm><indexterm index="cp"><command>icc</command></indexterm><indexterm index="cp"><command>pgcc</command></indexterm><indexterm index="cp"><command>pgCC</command></indexterm><indexterm index="cp"><command>pathcc</command></indexterm><indexterm index="cp"><command>pathCC</command></indexterm><indexterm index="cp"><command>xlC</command></indexterm><indexterm index="cp"><command>xlc</command></indexterm><acronym><acronymword>GNU</acronymword></acronym> (<samp>gcc -std=c99 -pedantic -D_BSD_SOURCE -D_POSIX_SOURCE</samp> -Wall) <footnote><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>), <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>). <indexterm index="cp">C++</indexterm><indexterm index="cp"><acronym><acronymword>ISO</acronymword></acronym></indexterm><indexterm index="cp"><command>libnco</command></indexterm><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>), <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>). <indexterm index="cp"><file>Makefile</file></indexterm>See <file>nco/bld/Makefile</file> and <file>nco/src/nco_c++/Makefile.old</file> for more details and exact settings.</para>
      <para><indexterm index="cp"><acronym><acronymword>ANSI</acronymword></acronym></indexterm><indexterm index="cp">C89</indexterm><indexterm index="cp"><code>printf</code></indexterm>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. <indexterm index="cp">C99</indexterm>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 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> 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&period; C-based object code in late 1994. C compiler<!-- /@w --> vectorization capabilities have dramatically improved since 1994. We have accordingly replaced all Fortran subroutines with C functions<!-- /@w -->. This greatly simplifies the task of building <acronym><acronymword>NCO</acronymword></acronym> on nominally unsupported platforms. <indexterm index="cp">C language</indexterm>As of August 1999, <acronym><acronymword>NCO</acronymword></acronym> built entirely in C<!-- /@w --> by default. This allowed <acronym><acronymword>NCO</acronymword></acronym> to compile on any machine with an <acronym><acronymword>ANSI</acronymword></acronym> C compiler<!-- /@w -->. <indexterm index="cp">C99</indexterm><indexterm index="cp">C89</indexterm><indexterm index="cp"><code>restrict</code></indexterm>In August 2004, the first C99 feature, the <code>restrict</code> type qualifier, entered <acronym><acronymword>NCO</acronymword></acronym> in version 2.9.8. 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 C pre-processor<!-- /@w --> undefines the <code>restrict</code> type qualifier, e.g., by invoking the compiler with <samp>-Drestrict=''</samp>.</para></footnote>.</para>
      <para><indexterm index="cp"><acronym><acronymword>GSL</acronymword></acronym></indexterm><indexterm index="cp">ncap2</indexterm>In January 2009, <acronym><acronymword>NCO</acronymword></acronym> version 3.9.6 was the first to link to the GNU Scientific Library (<acronym><acronymword>GSL</acronymword></acronym>). <acronym><acronymword>GSL</acronymword></acronym> must be 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 (see <xref><xrefnodename>GSL special functions</xrefnodename></xref>).</para>
      <para><indexterm index="cp"><var>gamma</var></indexterm>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 &ldquo;true gamma&rdquo;). <indexterm index="cp">automagic</indexterm><acronym><acronymword>NCO</acronymword></acronym> automagically takes advantage of some <acronym><acronymword>GNU</acronymword></acronym> Compiler Collection (<acronym><acronymword>GCC</acronymword></acronym>) extensions to <acronym><acronymword>ANSI</acronymword></acronym> C<!-- /@w -->.</para>
      <para>As of July 2000 and <acronym><acronymword>NCO</acronymword></acronym> 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 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 (Dr&period; Frankenstein<!-- /@w -->?) could resurrect it. If you would like to volunteer to maintain <file>nco_fortran.F</file> please contact me.</para>
<!-- Following section is obsolete -->
      <menu>
        <menuentry>
          <menunode>Windows Operating System</menunode>
          <menutitle>Windows Operating System</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </section>
  </node>
  <node>
    <nodename>Windows Operating System</nodename>
    <nodeprev>Compatability</nodeprev>
    <nodeup>Compatability</nodeup>
    <subsection>
      <title>Compiling <acronym><acronymword>NCO</acronymword></acronym> for Microsoft Windows <acronym><acronymword>OS</acronymword></acronym></title>
      <para><indexterm index="cp">Windows</indexterm><indexterm index="cp">Microsoft</indexterm><indexterm index="cp">XP (Microsoft operating system)</indexterm><indexterm index="cp">NT (Microsoft operating system)</indexterm> <acronym><acronymword>NCO</acronymword></acronym> has been successfully ported and tested on the Microsoft Windows (95/98/NT/2000/XP) operating systems. The switches necessary to accomplish this are included in the standard distribution of <acronym><acronymword>NCO</acronymword></acronym>. 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; <indexterm index="cp"><code>gcc</code></indexterm><indexterm index="cp"><code>g++</code></indexterm><indexterm index="cp"><code>g77</code></indexterm>Currently, Cygwin 20.x<!-- /@w --> comes with the <acronym><acronymword>GNU</acronymword></acronym> C/C++/Fortran compilers (<command>gcc</command>, <command>g++</command>, <command>g77</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. <indexterm index="cp">preprocessor tokens</indexterm><indexterm index="cp">Cygwin</indexterm><indexterm index="cp"><code>gnu-win32</code></indexterm><indexterm index="cp"><code>WIN32</code></indexterm><indexterm index="cp"><file>GNUmakefile</file></indexterm><indexterm index="cp"><file>Makefile</file></indexterm><indexterm index="cp"><code>f90</code></indexterm>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>
      <para><indexterm index="cp"><acronym><acronymword>UNIX</acronymword></acronym></indexterm><indexterm index="cp"><code>getuid</code></indexterm><indexterm index="cp"><code>gethostname</code></indexterm><indexterm index="cp"><file>&lt;arpa/nameser.h&gt;</file></indexterm><indexterm index="cp"><file>&lt;resolv.h&gt;</file></indexterm>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>). <indexterm index="cp"><code>ftp</code></indexterm><indexterm index="cp"><code>sftp</code></indexterm><indexterm index="cp"><code>rcp</code></indexterm><indexterm index="cp"><code>scp</code></indexterm><indexterm index="cp"><acronym><acronymword>SSH</acronymword></acronym></indexterm><indexterm index="cp">remote files</indexterm>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 (see <xref><xrefnodename>Remote storage</xrefnodename></xref>). 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 Cygwin 18.x<!-- /@w -->&mdash;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>
    </subsection>
  </node>
  <node>
    <nodename>Libraries</nodename>
    <nodenext>netCDF2/3/4 and HDF4/5 Support</nodenext>
    <nodeprev>Compatability</nodeprev>
    <nodeup>Introduction</nodeup>
    <section>
      <title>Libraries</title>
      <para><indexterm index="cp">libraries</indexterm><indexterm index="cp"><code>LD_LIBRARY_PATH</code></indexterm><indexterm index="cp">dynamic linking</indexterm><indexterm index="cp">static linking</indexterm>Like all executables, the <acronym><acronymword>NCO</acronymword></acronym> operators can be built using dynamic linking. <indexterm index="cp">performance</indexterm><indexterm index="cp">operator speed</indexterm><indexterm index="cp">speed</indexterm><indexterm index="cp">execution time</indexterm>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: /usr/local/bin/ncea: fatal: libsunmath.so.1: can't open file: errno=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 ncea`</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>
  <node>
    <nodename>netCDF2/3/4 and HDF4/5 Support</nodename>
    <nodenext>Help Requests and Bug Reports</nodenext>
    <nodeprev>Libraries</nodeprev>
    <nodeup>Introduction</nodeup>
    <section>
      <title>netCDF2/3/4 and HDF4/5 Support</title>
      <para><indexterm index="cp">netCDF2</indexterm><indexterm index="cp">netCDF3</indexterm>netCDF version 2<!-- /@w --> was released in 1993. <acronym><acronymword>NCO</acronymword></acronym> (specifically <command>ncks</command>) began soon after this in 1994. netCDF 3.0<!-- /@w --> was released in 1996, and we were eager to reap the performance advantages of the newer netCDF implementation. One 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 conversion of <acronym><acronymword>NCO</acronymword></acronym> to netCDF3<!-- /@w --> was completed (coincidentally on the same day netCDF 3.5<!-- /@w --> was released). <acronym><acronymword>NCO</acronymword></acronym> versions 2.0<!-- /@w --> and higher are built with the <code>-DNO_NETCDF_2</code> flag to ensure no netCDF2<!-- /@w --> interface calls are used. <indexterm index="cp"><code>NO_NETCDF_2</code></indexterm> <indexterm index="cp"><acronym><acronymword>HDF</acronymword></acronym></indexterm><indexterm index="cp">Hierarchical Data Format</indexterm><indexterm index="cp">Mike Folk</indexterm>However, the ability to compile <acronym><acronymword>NCO</acronymword></acronym> with only netCDF2<!-- /@w --> calls is worth maintaining because <acronym><acronymword>HDF</acronymword></acronym> version 4<!-- /@w --> <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.</para></footnote> (available from <uref><urefurl>http://hdf.ncsa.uiuc.edu</urefurl><urefdesc>HDF</urefdesc></uref>) supports only the netCDF2<!-- /@w --> library calls (see <uref><urefurl>http://hdf.ncsa.uiuc.edu/UG41r3_html/SDS_SD.fm12.html#47784</urefurl></uref>). Note that there are multiple versions of <acronym><acronymword>HDF</acronymword></acronym>. Currently <acronym><acronymword>HDF</acronymword></acronym> version 4.x<!-- /@w --> supports netCDF2<!-- /@w --> and thus <acronym><acronymword>NCO</acronymword></acronym> version 1.2.x<!-- /@w -->. If <acronym><acronymword>NCO</acronymword></acronym> version 1.2.x<!-- /@w --> (or earlier) is built with only 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. Does <samp>MF</samp> stands for Mike Folk? Perhaps. In any case, the <acronym><acronymword>MFHDF</acronymword></acronym> library only supports netCDF2<!-- /@w --> calls. Thus I will try to keep this capability in <acronym><acronymword>NCO</acronymword></acronym> as long as it is not too much trouble.</para></footnote>. <indexterm index="cp"><code>NETCDF2_ONLY</code></indexterm>The preprocessor token <code>NETCDF2_ONLY</code> exists in <acronym><acronymword>NCO</acronymword></acronym> version 1.2.x<!-- /@w --> to eliminate all netCDF3<!-- /@w --> calls. Only versions of <acronym><acronymword>NCO</acronymword></acronym> numbered 1.2.x and earlier have this capability. The <acronym><acronymword>NCO</acronymword></acronym> 1.2.x<!-- /@w --> branch will be maintained with bugfixes only (no new features) until <acronym><acronymword>HDF</acronymword></acronym> begins to fully support the netCDF3<!-- /@w --> interface (which is employed by <acronym><acronymword>NCO</acronymword></acronym> 2.x<!-- /@w -->). If, at compilation time, <code>NETCDF2_ONLY</code> is defined, then <acronym><acronymword>NCO</acronymword></acronym> version 1.2.x<!-- /@w --> will not use any netCDF3<!-- /@w --> calls and, if linked properly, the resulting <acronym><acronymword>NCO</acronymword></acronym> operators will work with <acronym><acronymword>HDF4</acronymword></acronym> files. <indexterm index="cp"><file>Makefile</file></indexterm>The <file>Makefile</file> supplied with <acronym><acronymword>NCO</acronymword></acronym> 1.2.x<!-- /@w --> is written to simplify building in this <acronym><acronymword>HDF</acronymword></acronym> capability. When <acronym><acronymword>NCO</acronymword></acronym> is built with <code>make HDF4=Y</code>, the <file>Makefile</file> sets all required preprocessor flags and library links to build with the <acronym><acronymword>HDF4</acronymword></acronym> libraries (which are assumed to reside under <code>/usr/local/hdf4</code>, edit the <file>Makefile</file> to suit your installation).</para>
      <para><indexterm index="cp">Unidata</indexterm><indexterm index="cp"><acronym><acronymword>NCSA</acronymword></acronym></indexterm><indexterm index="cp">netCDF4</indexterm><indexterm index="cp"><acronym><acronymword>HDF5</acronymword></acronym></indexterm><acronym><acronymword>HDF</acronymword></acronym> 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. In 2004, Unidata and <acronym><acronymword>NCSA</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 <xref><xrefnodename>Selecting Output File Format</xrefnodename></xref> for more details.</para>
      <para>HDF support for netCDF was completed with HDF5 version 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 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>
      <para><acronym><acronymword>NCO</acronymword></acronym> version 3.9.0 added support for all netCDF4 atomic data types in May, 2007. 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>
      <para><indexterm index="cp"><code>NC_UBYTE</code></indexterm><indexterm index="cp"><code>NC_USHORT</code></indexterm><indexterm index="cp"><code>NC_UINT</code></indexterm><indexterm index="cp"><code>NC_INT64</code></indexterm><indexterm index="cp"><code>NC_UINT64</code></indexterm>The main netCDF4 features that NCO currently supports are the new atomic data types and Lempel-Ziv compression. 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 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>
      <para><indexterm index="cp">deflation</indexterm><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 <xref><xrefnodename>Deflation</xrefnodename></xref> for more details.</para>
      <para><indexterm index="cp">chunking</indexterm><acronym><acronymword>NCO</acronymword></acronym> version 3.9.9 (June, 2009) added support for netCDF4 chunking. See <xref><xrefnodename>Chunking</xrefnodename></xref> for more details.</para>
      <para><indexterm index="cp"><acronym><acronymword>HDF5</acronymword></acronym></indexterm><indexterm index="cp"><code>-4</code></indexterm><indexterm index="cp"><code>-3</code></indexterm>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 <xref><xrefnodename>Selecting Output File Format</xrefnodename></xref> for more details.</para>
      <para><indexterm index="cp"><acronym><acronymword>RPM</acronymword></acronym></indexterm><indexterm index="cp">Debian</indexterm>Use appropriate caution while netCDF4 is beta software. Problems with netCDF4 and <acronym><acronymword>HDF</acronymword></acronym> libraries are still being fixed. <acronym><acronymword>NCO</acronymword></acronym> support for netCDF4 atomic types is relatively untested. Binary <acronym><acronymword>NCO</acronymword></acronym> distributions (<acronym><acronymword>RPM</acronymword></acronym>s and debs) still use netCDF3.</para>
      <para><indexterm index="cp"><code>NETCDF4_ROOT</code></indexterm>For now you must build <acronym><acronymword>NCO</acronymword></acronym> from source to get netCDF4 support. Typically, one specifies the root of the netCDF4-beta 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 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</example>
      <para>Our short term goal is to track the netCDF4-beta releases, keep the new netCDF4 atomic type support working, and iron out any problems. 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>
    </section>
  </node>
  <node>
    <nodename>Help Requests and Bug Reports</nodename>
    <nodeprev>netCDF2/3/4 and HDF4/5 Support</nodeprev>
    <nodeup>Introduction</nodeup>
    <section>
      <title>Help Requests and Bug Reports</title>
      <para><indexterm index="cp">reporting bugs</indexterm><indexterm index="cp">bugs, reporting</indexterm><indexterm index="cp">core dump</indexterm><indexterm index="cp">help</indexterm><indexterm index="cp">features, requesting</indexterm>We generally receive three categories of mail from users: help requests, bug reports, and feature requests. Notes saying the equivalent of "Hey, <acronym><acronymword>NCO</acronymword></acronym> continues to work great and it saves me more time everyday than it took to write this note" 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>&mdash;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 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>register</urefdesc></uref> your name and email address with SourceForge.net or else all of your postings will be attributed to "nobody". Once registered you may choose to "monitor" 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>, check first to see if that feature is already on the <uref><urefurl>file:./TODO</urefurl><urefdesc>TODO</urefdesc></uref> list. If it is, why not implement that feature yourself and send us the patch? If the feature is not yet on the list, then send a note to the <uref><urefurl>http://sf.net/forum/forum.php?forum_id=9829</urefurl><urefdesc>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). <indexterm index="cp">debugging</indexterm><indexterm index="cp"><code>-r</code></indexterm><indexterm index="cp"><code>-D</code></indexterm>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>). Post your help request to the <uref><urefurl>http://sf.net/forum/forum.php?forum_id=9830</urefurl><urefdesc>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. <indexterm index="cp"><code>-r</code></indexterm><indexterm index="cp"><code>--revision</code></indexterm><indexterm index="cp"><code>--version</code></indexterm><indexterm index="cp"><code>--vrs</code></indexterm><indexterm index="cp"><code>-D <var>debug-level</var></code></indexterm><indexterm index="cp"><code>--debug-level <var>debug-level</var></code></indexterm><indexterm index="cp"><code>--dbg_lvl <var>debug-level</var></code></indexterm><indexterm index="cp"><var>debug-level</var></indexterm><indexterm index="cp"><var>dbg_lvl</var></indexterm>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 publically accessible location, of the file(s). Post the full bug report to the <uref><urefurl>http://sf.net/bugs/?group_id=3331</urefurl><urefdesc>NCO Project buglist</urefdesc></uref>.</para>
      <para><indexterm index="cp">installation</indexterm><indexterm index="cp"><command>autoconf</command></indexterm><indexterm index="cp"><file>nco.configure.${GNU_TRP}.foo</file></indexterm><indexterm index="cp"><file>nco.config.log.${GNU_TRP}.foo</file></indexterm><indexterm index="cp"><file>nco.make.${GNU_TRP}.foo</file></indexterm><indexterm index="cp"><file>config.guess</file></indexterm><indexterm index="cp"><file>configure.eg</file></indexterm>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.${GNU_TRP}.foo</file>, <file>nco.configure.${GNU_TRP}.foo</file>, and <file>nco.make.${GNU_TRP}.foo</file>. The file <file>configure.eg</file> shows how to produce these files. Here <code>${GNU_TRP}</code> is the "<acronym><acronymword>GNU</acronymword></acronym> architecture triplet", 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>. <indexterm index="cp">regressions archive</indexterm>The regressions archive at <uref><urefurl>http://dust.ess.uci.edu/nco/rgr</urefurl></uref> 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>
    </section>
  </node>
  <node>
    <nodename>Strategies</nodename>
    <nodenext>Common features</nodenext>
    <nodeprev>Introduction</nodeprev>
    <nodeup>Top</nodeup>
    <chapter>
      <title>Operator Strategies</title>
      <menu>
        <menuentry>
          <menunode>Philosophy</menunode>
          <menutitle>Philosophy</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Climate Model Paradigm</menunode>
          <menutitle>Climate Model Paradigm</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Temporary Output Files</menunode>
          <menutitle>Temporary Output Files</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Appending Variables</menunode>
          <menutitle>Appending Variables</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Simple Arithmetic and Interpolation</menunode>
          <menutitle>Simple Arithmetic and Interpolation</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Averaging vs. Concatenating</menunode>
          <menutitle>Averaging vs. Concatenating</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Large Numbers of Files</menunode>
          <menutitle>Large Numbers of Files</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Large Datasets</menunode>
          <menutitle>Large Datasets</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Memory Requirements</menunode>
          <menutitle>Memory Requirements</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Performance</menunode>
          <menutitle>Performance</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </chapter>
  </node>
  <node>
    <nodename>Philosophy</nodename>
    <nodenext>Climate Model Paradigm</nodenext>
    <nodeprev>Strategies</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Philosophy</title>
      <para><indexterm index="cp">philosophy</indexterm><indexterm index="cp">climate model</indexterm> 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. <indexterm index="cp"><acronym><acronymword>NCL</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>IDL</acronymword></acronym></indexterm><indexterm index="cp">Perl</indexterm><indexterm index="cp">Yorick</indexterm>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>
      <para><indexterm index="cp">command line switches</indexterm>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 <xref><xrefnodename>Memory Requirements</xrefnodename></xref>.</para>
    </section>
  </node>
  <node>
    <nodename>Climate Model Paradigm</nodename>
    <nodenext>Temporary Output Files</nodenext>
    <nodeprev>Philosophy</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Climate Model Paradigm</title>
      <para><indexterm index="cp">climate model</indexterm><indexterm index="cp"><acronym><acronymword>NCAR</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>GCM</acronymword></acronym></indexterm> <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). Datasets produced by <acronym><acronymword>GCM</acronymword></acronym>s share many features with all 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>
    </section>
  </node>
  <node>
    <nodename>Temporary Output Files</nodename>
    <nodenext>Appending Variables</nodenext>
    <nodeprev>Climate Model Paradigm</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Temporary Output Files</title>
      <para><indexterm index="cp">data safety</indexterm><indexterm index="cp">error tolerance</indexterm><indexterm index="cp">safeguards</indexterm><indexterm index="cp">temporary output files</indexterm><acronym><acronymword>NCO</acronymword></acronym> operators are designed to be reasonably fault tolerant, so that if there is a system failure or the user aborts the operation (e.g., with <kbd>C-c</kbd>), then no data are lost. The user-specified <var>output-file</var> is only created upon successful completion of the operation <footnote><para>The <command>ncrename</command> operator is an exception to this rule. See <xref><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>. Note the construction of a temporary output file uses more disk space than just overwriting existing files &ldquo;in place&rdquo; (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>). <indexterm index="cp">performance</indexterm><indexterm index="cp">operator speed</indexterm><indexterm index="cp">speed</indexterm><indexterm index="cp">execution time</indexterm>Also, note this feature increases the execution time of the operator by approximately the time it takes to copy the <var>output-file</var>. Finally, note this feature allows the <var>output-file</var> to be the same as the <var>input-file</var> without any danger of &ldquo;overlap&rdquo;.</para>
      <para><indexterm index="cp"><code>-A</code></indexterm><indexterm index="cp"><code>-O</code></indexterm><indexterm index="cp"><code>--apn</code></indexterm><indexterm index="cp"><code>--append</code></indexterm><indexterm index="cp"><code>--ovr</code></indexterm><indexterm index="cp"><code>--overwrite</code></indexterm><indexterm index="cp">overwriting files</indexterm><indexterm index="cp">appending to files</indexterm>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>
    </section>
  </node>
  <node>
    <nodename>Appending Variables</nodename>
    <nodenext>Simple Arithmetic and Interpolation</nodenext>
    <nodeprev>Temporary Output Files</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Appending Variables</title>
      <para>Adding variables from one file to another is often desirable. <indexterm index="cp">concatenation</indexterm><indexterm index="cp">appending variables</indexterm><indexterm index="cp">merging files</indexterm><indexterm index="cp">pasting variables</indexterm>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>. <indexterm index="cp">record dimension</indexterm>In <acronym><acronymword>NCO</acronymword></acronym>, concatenation refers to splicing a variable along the record dimension. Appending, on the other hand, refers to adding variables from one file to another <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>. 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&mdash;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>, See <xref><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref>.</para>
      <para><indexterm index="cp">union of two files</indexterm><indexterm index="cp">disjoint files</indexterm>The simplest way to create the union of two files is</para>
      <example xml:space="preserve">ncks -A fl_1.nc fl_2.nc</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>
    </section>
  </node>
  <node>
    <nodename>Simple Arithmetic and Interpolation</nodename>
    <nodenext>Averaging vs. Concatenating</nodenext>
    <nodeprev>Appending Variables</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Simple Arithmetic and Interpolation</title>
      <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> (see <xref><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></xref>) does file addition, subtraction, multiplication, division, and broadcasting. <command>ncflint</command> (see <xref><xrefnodename>ncflint netCDF File Interpolator</xrefnodename></xref>) does file addition, subtraction, multiplication and interpolation. Sequences of these commands can accomplish simple but powerful operations from the command line.</para>
    </section>
  </node>
  <node>
    <nodename>Averaging vs. Concatenating</nodename>
    <nodenext>Large Numbers of Files</nodenext>
    <nodeprev>Simple Arithmetic and Interpolation</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Averagers vs&period; Concatenators</title>
      <para><indexterm index="cp">symbolic links</indexterm>The most frequently used operators of <acronym><acronymword>NCO</acronymword></acronym> are probably the averagers and concatenators. Because there are so many permutations of 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>ncea</command>, <command>ncwa</command>, <command>ncrcat</command>, and <command>ncecat</command>. These operators do share many capabilities <footnote><para>Currently <command>ncea</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, but merely have different inner loops.</para></footnote>, but each has its unique specialty. Two of these operators, <command>ncrcat</command> and <command>ncecat</command>, are for concatenating hyperslabs across files. The other two operators, <command>ncra</command> and <command>ncea</command>, are for averaging hyperslabs across 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>ncea</command> because it can only operate 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&mdash;including weighting, masking, and broadcasting.</para></footnote>. First, let's describe the concatenators, then the averagers.</para>
      <menu>
        <menuentry>
          <menunode>Concatenation</menunode>
          <menutitle>Concatenation</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Averaging</menunode>
          <menutitle>Averaging</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Interpolating</menunode>
          <menutitle>Interpolating</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </section>
  </node>
  <node>
    <nodename>Concatenation</nodename>
    <nodenext>Averaging</nodenext>
    <nodeprev>Averaging vs. Concatenating</nodeprev>
    <nodeup>Averaging vs. Concatenating</nodeup>
    <subsection>
      <title>Concatenators <command>ncrcat</command> and <command>ncecat</command></title>
      <para><indexterm index="cp"><command>ncecat</command></indexterm><indexterm index="cp"><command>ncrcat</command></indexterm> Joining independent files together along a 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>, &dots; <file>89.nc</file><!-- /@w --> each containing a year'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. See <xref><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. <indexterm index="cp">ensemble</indexterm><indexterm index="cp">climate model</indexterm>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>, &dots; <file>85e.nc</file><!-- /@w --> of 1985 predictions from the same climate model. Then <code>ncecat 85?.nc 85_ens.nc</code> glues the individual realizations together 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. 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. See <xref><xrefnodename>ncecat netCDF Ensemble Concatenator</xrefnodename></xref>, for a complete description of <command>ncecat</command>.</para>
      <para><indexterm index="cp"><command>ncpdq</command></indexterm><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>, &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 xml:space="preserve">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</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>
    </subsection>
  </node>
  <node>
    <nodename>Averaging</nodename>
    <nodenext>Interpolating</nodenext>
    <nodeprev>Concatenation</nodeprev>
    <nodeup>Averaging vs. Concatenating</nodeup>
    <subsection>
      <title>Averagers <command>ncea</command>, <command>ncra</command>, and <command>ncwa</command></title>
      <para><indexterm index="cp"><command>ncea</command></indexterm><indexterm index="cp"><command>ncra</command></indexterm><indexterm index="cp"><command>ncwa</command></indexterm> The differences between the averagers <command>ncra</command> and <command>ncea</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>ncea</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>ncea</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>ncea</command> can average both fixed-length and record variables. To conserve system memory, use <command>ncra</command> rather than <command>ncea</command> where possible (e.g., if each <var>input-file</var> is one record long). The file output from <command>ncea</command> will have the same dimensions (meaning dimension names as well as sizes) as the input hyperslabs (see <xref><xrefnodename>ncea netCDF Ensemble Averager</xrefnodename></xref>, for a complete description of <command>ncea</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 of 1<!-- /@w --> (see <xref><xrefnodename>ncra netCDF Record Averager</xrefnodename></xref>, for a complete description of <command>ncra</command>).</para>
    </subsection>
  </node>
  <node>
    <nodename>Interpolating</nodename>
    <nodeprev>Averaging</nodeprev>
    <nodeup>Averaging vs. Concatenating</nodeup>
    <subsection>
      <title>Interpolator <command>ncflint</command></title>
      <para><indexterm index="cp"><command>ncflint</command></indexterm> <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 (see <xref><xrefnodename>ncflint netCDF File Interpolator</xrefnodename></xref>). 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>
    </subsection>
  </node>
  <node>
    <nodename>Large Numbers of Files</nodename>
    <nodenext>Large Datasets</nodenext>
    <nodeprev>Averaging vs. Concatenating</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Large Numbers of Files</title>
      <para><indexterm index="cp">files, numerous input</indexterm><indexterm index="cp"><code>-n <var>loop</var></code></indexterm> Occasionally one desires to digest (i.e., concatenate or average) hundreds or thousands of input files. <indexterm index="cp">automagic</indexterm><indexterm index="cp"><acronym><acronymword>NASA EOSDIS</acronymword></acronym></indexterm>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 (see <xref><xrefnodename>Specifying Input Files</xrefnodename></xref>) 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 (see <xref><xrefnodename>History Attribute</xrefnodename></xref>). 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>, &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 from <acronym><acronymword>OS</acronymword></acronym> to <acronym><acronymword>OS</acronymword></acronym> and from shell to shell. <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>
      <para><indexterm index="cp">standard input</indexterm><indexterm index="cp"><code>stdin</code></indexterm>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 xml:space="preserve"># Pipe large numbers of filenames to stdin
/bin/ls | grep ${CASEID}_'......'.nc | ncecat -o foo.nc</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 (see <xref><xrefnodename>History Attribute</xrefnodename></xref>) does not record the name of any input files since the names were not passed on the command line. This makes determining the data provenance at a later date difficult. <indexterm index="cp"><code>nco_input_file_number</code></indexterm><indexterm index="cp"><code>nco_input_file_list</code></indexterm><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm>To remedy this situation, multi-file 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 (see <xref><xrefnodename>File List Attributes</xrefnodename></xref>). 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><indexterm index="cp">globbing</indexterm><indexterm index="cp">shell</indexterm><indexterm index="cp">extended regular expressions</indexterm><indexterm index="cp">regular expressions</indexterm><indexterm index="cp">pattern matching</indexterm><indexterm index="cp"><command>xargs</command></indexterm><indexterm index="cp"><acronym><acronymword>UNIX</acronymword></acronym></indexterm>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 can not 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> (see <xref><xrefnodename>Subsetting Variables</xrefnodename></xref>). 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 xml:space="preserve"># Use xargs to transfer filenames on the command line
/bin/ls | grep ${CASEID}_'......'.nc | xargs -x ncecat -o foo.nc</example>
      <para><indexterm index="cp">pipes</indexterm>The single quotes protect the only sensitive parts of the extended regular expression (the <command>grep</command> argument), and allow shell interpolation (the <code>${CASEID}</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. <indexterm index="cp">output file</indexterm><indexterm index="cp">input files</indexterm><indexterm index="cp"><code>-o <var>fl_out</var></code></indexterm>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>
      <para><indexterm index="cp">symbolic links</indexterm>Even when its internal limits have not been reached, the <command>xargs</command> technique may not be sophisticated enough to handle all situations. A full scripting language like Perl 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. <indexterm index="cp">Perl</indexterm>For example, the following Perl script 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>: <indexterm index="cp"><code>-n <var>loop</var></code></indexterm></para>
      <example xml:space="preserve"># Create enumerated symbolic links
/bin/ls | grep \.nc | perl -e \
'$idx=1;while(&lt;STDIN&gt;){chop;symlink $_,sprintf("%06d.nc",$idx++);}'
ncecat -n 999999,6,1 000001.nc foo.nc
# Remove symbolic links when finished
/bin/rm ??????.nc</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. <indexterm index="cp"><code>history</code></indexterm>One drawback to this method is that the <code>history</code> attribute (see <xref><xrefnodename>History Attribute</xrefnodename></xref>) 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>
  <node>
    <nodename>Large Datasets</nodename>
    <nodenext>Memory Requirements</nodenext>
    <nodeprev>Large Numbers of Files</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Large Datasets</title>
      <para><indexterm index="cp">large datasets</indexterm><indexterm index="cp">LFS</indexterm><indexterm index="cp">Large File Support</indexterm> <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 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>ncea</command> and <command>ncecat</command>. <indexterm index="cp">swap space</indexterm>If you work with a 300 MB<!-- /@w --> files on a machine with only 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 2 GB<!-- /@w --> in size. These users should familiarize themselves with <acronym><acronymword>NCO</acronymword></acronym>'s Large File Support (<acronym><acronymword>LFS</acronymword></acronym>) capabilities (see <xref><xrefnodename>Large File Support</xrefnodename></xref>). The next section will increase your familiarity with <acronym><acronymword>NCO</acronymword></acronym>'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>
      <para><indexterm index="cp">server</indexterm><indexterm index="cp"><acronym><acronymword>UNICOS</acronymword></acronym></indexterm><indexterm index="cp">Cray</indexterm>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. Certain machine architectures, e.g., Cray <acronym><acronymword>UNICOS</acronymword></acronym>, have special commands which allow one to increase the amount of interactive memory. <indexterm index="cp"><code>ilimit</code></indexterm>On Cray systems, try to increase the available memory with the <code>ilimit</code> command. <indexterm index="cp"><acronym><acronymword>GNU</acronymword></acronym>/Linux</indexterm><indexterm index="cp"><code>ulimit</code></indexterm><indexterm index="cp"><code>core dump</code></indexterm>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, try increasing the process-available memory with <code>ulimit</code>.</para>
      <para><indexterm index="cp">speed</indexterm>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 than 0<!-- /@w --> to the <samp>-D <var>debug-level</var></samp> (or <samp>--debug-level</samp>, or <samp>--dbg_lvl</samp>) switch. <indexterm index="cp"><code>-D <var>debug-level</var></code></indexterm><indexterm index="cp"><code>--debug-level <var>debug-level</var></code></indexterm><indexterm index="cp"><code>--dbg_lvl <var>debug-level</var></code></indexterm><indexterm index="cp"><var>debug-level</var></indexterm><indexterm index="cp"><var>dbg_lvl</var></indexterm><indexterm index="cp">debugging</indexterm>When the <var>debug-level</var> is nonzero, 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> between 1<!-- /@w --> and 3<!-- /@w --> for most situations, e.g., <code>ncea -D 2 85.nc 86.nc 8586.nc</code>. 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 <xref><xrefnodename>Memory Requirements</xrefnodename></xref>.</para>
    </section>
  </node>
  <node>
    <nodename>Memory Requirements</nodename>
    <nodenext>Performance</nodenext>
    <nodeprev>Large Datasets</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Memory Requirements</title>
      <para><indexterm index="cp">memory requirements</indexterm><indexterm index="cp">memory available</indexterm><indexterm index="cp">RAM</indexterm><indexterm index="cp">swap space</indexterm><indexterm index="cp">peak memory usage</indexterm> 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'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>
      <para><indexterm index="cp">threads</indexterm><indexterm index="cp">OpenMP</indexterm><indexterm index="cp">shared memory machines</indexterm>This section describes the memory <acronym><acronymword>NCO</acronymword></acronym> requires during operation. The required memory is based on the underlying algorithms. The description below is the memory usage per thread. Users with shared memory machines may use the threaded <acronym><acronymword>NCO</acronymword></acronym> operators (see <xref><xrefnodename>OpenMP Threading</xrefnodename></xref>). The peak and sustained memory usage will scale accordingly, i.e., by the number of threads. Memory consumption patterns of all operators are similar, with the exception of <command>ncap2</command>.</para>
      <menu>
        <menuentry>
          <menunode>Single and Multi-file Operators</menunode>
          <menutitle>Single and Multi-file Operators</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Memory for ncap2</menunode>
          <menutitle>Memory for ncap2</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </section>
  </node>
  <node>
    <nodename>Single and Multi-file Operators</nodename>
    <nodenext>Memory for ncap2</nodenext>
    <nodeprev>Memory Requirements</nodeprev>
    <nodeup>Memory Requirements</nodeup>
    <subsection>
      <title>Single and Multi-file Operators</title>
      <para><indexterm index="cp">multi-file operators</indexterm>The multi-file operators currently comprise the record operators, <command>ncra</command> and <command>ncrcat</command>, and the ensemble operators, <command>ncea</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, wherease 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>ncea</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 which do not appear in the output file (see <xref><xrefnodename>Subsetting Variables</xrefnodename></xref>) are never read and contribute nothing to the memory requirements.</para>
      <para><command>ncwa</command> consumes between two and seven times the memory of a 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. When invoked, the weighting and masking features contribute up to three-sevenths and two-sevenths 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).</para>
      <para><indexterm index="cp">OpenMP</indexterm><indexterm index="cp">threads</indexterm>The above memory requirements must be multiplied by the number of threads <var>thr_nbr</var> (see <xref><xrefnodename>OpenMP Threading</xrefnodename></xref>). <indexterm index="cp"><code>-t <var>thr_nbr</var></code></indexterm>If this causes problems then reduce (with <samp>-t <var>thr_nbr</var></samp>) the number of threads.</para>
    </subsection>
  </node>
  <node>
    <nodename>Memory for ncap2</nodename>
    <nodeprev>Single and Multi-file Operators</nodeprev>
    <nodeup>Memory Requirements</nodeup>
    <subsection>
      <title>Memory for <command>ncap2</command></title>
      <para><indexterm index="cp"><command>ncap2</command></indexterm><indexterm index="cp">binary operations</indexterm><indexterm index="cp">unary operations</indexterm><indexterm index="cp">memory leaks</indexterm><indexterm index="cp">left hand casting</indexterm><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 (see <xref><xrefnodename>Left hand casting</xrefnodename></xref>) 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>
      <para><indexterm index="cp">malloc()</indexterm><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 existance. 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>
  </node>
  <node>
    <nodename>Performance</nodename>
    <nodeprev>Memory Requirements</nodeprev>
    <nodeup>Strategies</nodeup>
    <section>
      <title>Performance</title>
      <para><indexterm index="cp">papers</indexterm><indexterm index="cp">overview</indexterm>An overview of <acronym><acronymword>NCO</acronymword></acronym> capabilities as of about 2006 is in Zender, C. S. (2008), &ldquo;Analysis of Self-describing Gridded Geoscience Data with netCDF Operators (NCO)&rdquo;, Environ. Modell. Softw., doi:10.1016/j.envsoft.2008.03.004. This paper is also available at <uref><urefurl>http://dust.ess.uci.edu/ppr/ppr_Zen08_ems.pdf</urefurl></uref>.</para>
      <para><indexterm index="cp">scaling</indexterm><indexterm index="cp">performance</indexterm><acronym><acronymword>NCO</acronymword></acronym> performance and scaling for arithmetic operations is described in Zender, C. S., and H. J. Mangalam (2007), &ldquo;Scaling Properties of Common Statistical Operators for Gridded Datasets&rdquo;, Int. J. High<!-- /@w --> Perform. Comput. Appl., 21(4), 485-498, doi:10.1177/1094342007083802. This paper is also available at <uref><urefurl>http://dust.ess.uci.edu/ppr/ppr_ZeM07_ijhpca.pdf</urefurl></uref>.</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">
        <item>
          <para><indexterm index="cp">buffering</indexterm>No data buffering is performed during <command>nc_get_var</command> and <command>nc_put_var</command> operations. <indexterm index="cp">performance</indexterm><indexterm index="cp">operator speed</indexterm><indexterm index="cp">speed</indexterm><indexterm index="cp">execution time</indexterm>Hyperslabs too large too hold in core memory will suffer substantial performance penalties because of this.</para>
        </item>
        <item>
          <para><indexterm index="cp">monotonic coordinates</indexterm>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>
        </item>
        <item>
          <para><indexterm index="cp"><var>C_format</var></indexterm><indexterm index="cp"><var>FORTRAN_format</var></indexterm><indexterm index="cp"><var>signedness</var></indexterm><indexterm index="cp"><var>scale_format</var></indexterm><indexterm index="cp"><var>add_offset</var></indexterm><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>
        </item>
        <item>
          <para><indexterm index="cp">Yorick</indexterm>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>
        </item>
      </enumerate>
    </section>
  </node>
  <node>
    <nodename>Common features</nodename>
    <nodenext>Operator Reference Manual</nodenext>
    <nodeprev>Strategies</nodeprev>
    <nodeup>Top</nodeup>
    <chapter>
      <title>NCO Features</title>
      <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. <indexterm index="cp">command line switches</indexterm>Command line switches for a given feature are consistent across all operators wherever possible. If no &ldquo;key switches&rdquo; are listed for a feature, then that particular feature is automatic and cannot be controlled by the user.</para>
      <menu>
        <menuentry>
          <menunode>Internationalization</menunode>
          <menutitle>Internationalization</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Metadata Optimization</menunode>
          <menutitle>Metadata Optimization</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>OpenMP Threading</menunode>
          <menutitle>OpenMP Threading</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Command Line Options</menunode>
          <menutitle>Command Line Options</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Specifying Input Files</menunode>
          <menutitle>Specifying Input Files</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Specifying Output Files</menunode>
          <menutitle>Specifying Output Files</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Remote storage</menunode>
          <menutitle>Remote storage</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Retaining Retrieved Files</menunode>
          <menutitle>Retaining Retrieved Files</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Selecting Output File Format</menunode>
          <menutitle>Selecting Output File Format</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Large File Support</menunode>
          <menutitle>Large File Support</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Subsetting Variables</menunode>
          <menutitle>Subsetting Variables</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Subsetting Coordinate Variables</menunode>
          <menutitle>Subsetting Coordinate Variables</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>C and Fortran Index Conventions</menunode>
          <menutitle>C and Fortran Index Conventions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Hyperslabs</menunode>
          <menutitle>Hyperslabs</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Stride</menunode>
          <menutitle>Stride</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Multislabs</menunode>
          <menutitle>Multislabs</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Wrapped Coordinates</menunode>
          <menutitle>Wrapped Coordinates</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Auxiliary Coordinates</menunode>
          <menutitle>Auxiliary Coordinates</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>UDUnits Support</menunode>
          <menutitle>UDUnits Support</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Missing Values</menunode>
          <menutitle>Missing Values</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Chunking</menunode>
          <menutitle>Chunking</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Deflation</menunode>
          <menutitle>Deflation</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Packed data</menunode>
          <menutitle>Packed data</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Operation Types</menunode>
          <menutitle>Operation Types</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Type Conversion</menunode>
          <menutitle>Type Conversion</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Batch Mode</menunode>
          <menutitle>Batch Mode</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>History Attribute</menunode>
          <menutitle>History Attribute</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>File List Attributes</menunode>
          <menutitle>File List Attributes</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>CF Conventions</menunode>
          <menutitle>CF Conventions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ARM Conventions</menunode>
          <menutitle>ARM Conventions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Operator Version</menunode>
          <menutitle>Operator Version</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </chapter>
  </node>
  <node>
    <nodename>Internationalization</nodename>
    <nodenext>Metadata Optimization</nodenext>
    <nodeprev>Common features</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Internationalization</title>
      <para><indexterm index="cp">Internationalization</indexterm><indexterm index="cp">I18N</indexterm></para>
      <cartouche>
        <para>Availability: All operators&linebreak;</para>
      </cartouche>
      <para><indexterm index="cp">L10N</indexterm><acronym><acronymword>NCO</acronymword></acronym> support for <dfn>internationalization</dfn> of textual input and output (e.g., Warning messages) is nascent. We hope to produce foreign language string catalogues in 2004. 
<!-- fxm: Work on this section --></para>
    </section>
  </node>
  <node>
    <nodename>Metadata Optimization</nodename>
    <nodenext>OpenMP Threading</nodenext>
    <nodeprev>Internationalization</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Metadata Optimization</title>
      <para><indexterm index="cp">metadata optimization</indexterm><indexterm index="cp">performance</indexterm><indexterm index="cp">operator speed</indexterm><indexterm index="cp">speed</indexterm><indexterm index="cp">execution time</indexterm><indexterm index="cp"><code>nc__enddef()</code></indexterm><indexterm index="cp"><code>--hdr_pad <var>hdr_pad</var></code></indexterm><indexterm index="cp"><code>--header_pad <var>hdr_pad</var></code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncatted</command>, <command>ncks</command>, <command>ncrename</command>&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. Future metadata expansions will not incur the performance penalty of copying the entire output file unless the expansion exceeds the amount of header padding exceeded. This can be beneficial when it is known that some metadata will be added at a future date.</para>
      <para>This optimization exploits the netCDF library <code>nc__enddef()</code> function, which behaves differently with different versions of netCDF. It will improve speed of future metadata expansion with <code>CLASSIC</code> and <code>64bit</code> netCDF files, but not necessarily with <code>NETCDF4</code> files, i.e., those created by the netCDF interface to the <acronym><acronymword>HDF5</acronymword></acronym> library (see <xref><xrefnodename>Selecting Output File Format</xrefnodename></xref>).</para>
    </section>
  </node>
  <node>
    <nodename>OpenMP Threading</nodename>
    <nodenext>Command Line Options</nodenext>
    <nodeprev>Metadata Optimization</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>OpenMP Threading</title>
      <para><indexterm index="cp">OpenMP</indexterm><indexterm index="cp">threads</indexterm><indexterm index="cp"><acronym><acronymword>SMP</acronymword></acronym></indexterm><indexterm index="cp">shared memory parallelism</indexterm><indexterm index="cp">parallelism</indexterm><indexterm index="cp"><code>nco_openmp_thread_number</code></indexterm><indexterm index="cp"><code>--thr_nbr <var>thr_nbr</var></code></indexterm><indexterm index="cp"><code>--threads <var>thr_nbr</var></code></indexterm><indexterm index="cp"><code>--omp_num_threads <var>thr_nbr</var></code></indexterm><indexterm index="cp"><code>-t <var>thr_nbr</var></code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</command>, <command>ncecat</command>, <command>ncflint</command>, <command>ncpdq</command>, <command>ncra</command>, <command>ncrcat</command>, <command>ncwa</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 <code>OMP_NUM_THREADS</code> environment variable, if present, or from the <acronym><acronymword>OS</acronymword></acronym>, if not.</para>
      <para><indexterm index="cp"><var>thr_nbr</var></indexterm><indexterm index="cp"><code>OMP_NUM_THREADS</code></indexterm><indexterm index="cp"><command>ncrcat</command></indexterm><indexterm index="cp"><command>ncwa</command></indexterm><indexterm index="cp"><command>ncap</command></indexterm><indexterm index="cp"><command>ncpdq</command></indexterm><indexterm index="cp">large datasets</indexterm><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>ncap</code>, <code>ncwa</code> and <code>ncpdq</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 well 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>
      <para><indexterm index="cp">debugging</indexterm><indexterm index="cp"><var>dbg_lvl</var></indexterm>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. <indexterm index="cp">benchmarks</indexterm>This information is also useful for benchmarking.</para>
    </section>
  </node>
  <node>
    <nodename>Command Line Options</nodename>
    <nodenext>Specifying Input Files</nodenext>
    <nodeprev>OpenMP Threading</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Command Line Options</title>
      <para><indexterm index="cp">command line options</indexterm></para>
      <cartouche>
        <para>Availability: All operators&linebreak;</para>
      </cartouche>
      <para><indexterm index="cp"><acronym><acronymword>POSIX</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>UNIX</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>GNU</acronymword></acronym></indexterm><indexterm index="cp">switches</indexterm><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. In the future, however, some features of <acronym><acronymword>NCO</acronymword></acronym> may 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>
      <para><indexterm index="cp">long options</indexterm>Extended options, also called long options, are implemented using the system-supplied <file>getopt.h</file> header file, if possible. <indexterm index="cp"><code>BSD</code></indexterm><indexterm index="cp"><code>getopt</code></indexterm><indexterm index="cp"><code>getopt_long</code></indexterm><indexterm index="cp"><file>getopt.h</file></indexterm>This provides the <command>getopt_long</command> function to <acronym><acronymword>NCO</acronymword></acronym> <footnote><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@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>
      <para><indexterm index="cp"><code>-D <var>debug-level</var></code></indexterm><indexterm index="cp"><code>--dbg_lvl <var>debug-level</var></code></indexterm>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>&ndash;<var>long_name</var> <var>value</var></kbd> (dash-dash-key-space-value), e.g., <samp>--dbg_lvl 2</samp> or <kbd>&ndash;<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 xml:space="preserve">ncks -D 3 in.nc        # Short option
ncks --dbg_lvl=3 in.nc # Long option, preferred form
ncks --dbg_lvl 3 in.nc # Long option, alternate form</example>
      <para role="continues">The last example is preferred for two reasons. First, <samp>--dbg_lvl</samp> is more specific and less ambiguous than <samp>-D</samp>. The long option form 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>
      <para><acronym><acronymword>GNU</acronymword></acronym> implements a superset of the <acronym><acronymword>POSIX</acronymword></acronym> standard which allows any unambiguous truncation of a valid option to be used.</para>
      <example 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, unambiguous truncation
ncks --db=3 in.nc      # Long option, unambiguous truncation
ncks --d=3 in.nc       # Long option, ambiguous truncation</example>
      <para role="continues">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 scripts which are re-usable employ some form of the long options for future maintainability.</para>
      <para>This manual generally uses the short option syntax. This is for historical reasons and to conserve space. The remainder of this manual specifies the full <var>long_name</var> of each option. Users are expected to pick the unambiguous truncation of each option name that most suits their taste.</para>
    </section>
  </node>
  <node>
    <nodename>Specifying Input Files</nodename>
    <nodenext>Specifying Output Files</nodenext>
    <nodeprev>Command Line Options</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Specifying Input Files</title>
      <para><indexterm index="cp">input files</indexterm><indexterm index="cp">globbing</indexterm><indexterm index="cp">regular expressions</indexterm><indexterm index="cp">wildcards</indexterm><indexterm index="cp"><code>NINTAP</code></indexterm><indexterm index="cp">Processor, <acronym><acronymword>CCM</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>CCM</acronymword></acronym> Processor</indexterm><indexterm index="cp"><code>-n <var>loop</var></code></indexterm><indexterm index="cp"><code>--nintap <var>loop</var></code></indexterm><indexterm index="cp"><code>-p <var>input-path</var></code></indexterm><indexterm index="cp"><code>--pth <var>input-path</var></code></indexterm><indexterm index="cp"><code>--path <var>input-path</var></code></indexterm><indexterm index="cp"><var>input-path</var></indexterm></para>
      <cartouche>
        <para>Availability (<code>-n</code>): <command>ncea</command>, <command>ncecat</command>, <command>ncra</command>, <command>ncrcat</command>&linebreak; Availability (<code>-p</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. <indexterm index="cp"><acronym><acronymword>UNIX</acronymword></acronym></indexterm>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). 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>, &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 xml:space="preserve">ncra 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
ncra 8[56789].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</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 passes valid filenames which match the expansion to <command>ncra</command>. The third 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/usrname/model</file>) to all <var>input-files</var> (but 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.</para></footnote>. <indexterm index="cp">multi-file operators</indexterm><indexterm index="cp">files, multiple</indexterm>This option is only available with the <dfn>multi-file operators</dfn>: <command>ncra</command>, <command>ncrcat</command>, <command>ncea</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> is able to decode lists of such filenames encoded using the <samp>-n</samp> option. The simpler (3-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>cdf</file>, <file>hdf</file>, or <file>hd5</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>
      <para><indexterm index="cp">wrapped filenames</indexterm><indexterm index="cp">climate model</indexterm>Recently the <samp>-n</samp> option has been extended to allow convenient specification of filenames with &ldquo;circular&rdquo; 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&ndash;July&ndash;August, and December&ndash;January&ndash;February, respectively:</para>
      <example 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</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 &ldquo;wrap&rdquo; 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 to <acronym><acronymword>NCO</acronymword></acronym>. The fourth argument to <samp>-n</samp>, if present, specifies the maximum integer value of <var>numeric_suffix</var>. In this case the maximum value is 12,<!-- /@w --> and will be formatted as <file>12</file> in the filename string. The fifth argument to <samp>-n</samp>, if present, specifies the minimum integer value of <var>numeric_suffix</var>. The default minimum filename suffix 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>
    </section>
  </node>
  <node>
    <nodename>Specifying Output Files</nodename>
    <nodenext>Remote storage</nodenext>
    <nodeprev>Specifying Input Files</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Specifying Output Files</title>
      <para><indexterm index="cp">output file</indexterm><indexterm index="cp">input files</indexterm><indexterm index="cp">positional arguments</indexterm><indexterm index="cp">command line switches</indexterm><indexterm index="cp"><code>-o <var>fl_out</var></code></indexterm><indexterm index="cp"><code>--output <var>fl_out</var></code></indexterm><indexterm index="cp"><code>--fl_out <var>fl_out</var></code></indexterm></para>
      <cartouche>
        <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. <indexterm index="cp">multi-file operators</indexterm>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. <indexterm index="cp"><command>xargs</command></indexterm><indexterm index="cp">input files</indexterm>Second, specification of a long list of input files may be difficult (see <xref><xrefnodename>Large Numbers of Files</xrefnodename></xref>). 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 very ugly 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. <indexterm index="cp">compilers</indexterm><indexterm index="cp">linkers</indexterm>Compilers and linkers are usually invoked this way.</para>
    </section>
  </node>
  <node>
    <nodename>Remote storage</nodename>
    <nodenext>Retaining Retrieved Files</nodenext>
    <nodeprev>Specifying Output Files</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Accessing Remote Files</title>
      <para><indexterm index="cp"><code>rcp</code></indexterm><indexterm index="cp"><code>scp</code></indexterm><indexterm index="cp"><file>.rhosts</file></indexterm><indexterm index="cp"><acronym><acronymword>NCAR MSS</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>MSS</acronymword></acronym></indexterm><indexterm index="cp">Mass Store System</indexterm><indexterm index="cp"><acronym><acronymword>URL</acronymword></acronym></indexterm><indexterm index="cp"><code>ftp</code></indexterm><indexterm index="cp"><code>sftp</code></indexterm><indexterm index="cp">remote files</indexterm><indexterm index="cp">synchronous file access</indexterm><indexterm index="cp">asynchronous file access</indexterm><indexterm index="cp"><code>--pth <var>input-path</var></code></indexterm><indexterm index="cp"><code>--path <var>input-path</var></code></indexterm><indexterm index="cp"><code>--lcl <var>output-path</var></code></indexterm><indexterm index="cp"><code>--local <var>output-path</var></code></indexterm><indexterm index="cp"><code>-l <var>output-path</var></code></indexterm><indexterm index="cp"><file>.netrc</file></indexterm><indexterm index="cp"><code>history</code></indexterm></para>
      <cartouche>
        <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. 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, or <acronym><acronymword>NCAR</acronymword></acronym>'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>
      <para>To access a file via an anonymous <acronym><acronymword>FTP</acronymword></acronym> server, supply the remote file's <acronym><acronymword>URL</acronymword></acronym>. <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> 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 these transactions 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 xml:space="preserve">machine dust.ess.uci.edu login zender password bushlied</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>
      <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 xml:space="preserve">sftp://machine.domain.tld:/path/to/filename</example>
      <para>Note the second colon following the top-level-domain (tld). This syntax is a hybrid between an <acronym><acronymword>FTP URL</acronymword></acronym> and a standard remote file syntax.</para>
      <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>
      <para><indexterm index="cp"><command>msrcp</command></indexterm><indexterm index="cp"><command>msread</command></indexterm><indexterm index="cp"><command>nrnet</command></indexterm>To access a file on <acronym><acronymword>NCAR</acronymword></acronym>'s <acronym><acronymword>MSS</acronymword></acronym>, specify the full <acronym><acronymword>MSS</acronymword></acronym> pathname of the remote file. <acronym><acronymword>NCO</acronymword></acronym> will attempt to detect whether the local machine has direct (synchronous) <acronym><acronymword>MSS</acronymword></acronym> access. In this case, <acronym><acronymword>NCO</acronymword></acronym> attempts to use the <acronym><acronymword>NCAR</acronymword></acronym> <command>msrcp</command> command <footnote><para>The <command>msrcp</command> command must be in the user's path and located in one of the following directories: <code>/usr/local/bin</code>, <code>/usr/bin</code>, <code>/opt/local/bin</code>, or <code>/usr/local/dcs/bin</code>. </para></footnote>, or, failing that, <code>/usr/local/bin/msread</code>. Otherwise <acronym><acronymword>NCO</acronymword></acronym> attempts to retrieve the <acronym><acronymword>MSS</acronymword></acronym> file through the (asynchronous) Masnet Interface Gateway System (<acronym><acronymword>MIGS</acronymword></acronym>) using the <command>nrnet</command> command.</para>
      <para>The following examples show how one might analyze files stored on remote systems.</para>
      <example 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
ncks -l . mss:/ZENDER/nco/in.nc
ncks -l . http://dust.ess.uci.edu/cgi-bin/dods/nph-dods/dodsdata/in.nc</example>
      <para role="continues">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 <command>msrcp</command>, <command>msread</command>, or <command>nrnet</command> commands. 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 <xref><xrefnodename>OPeNDAP</xrefnodename></xref>). The above commands can be rewritten using the <samp>-p <var>input-path</var></samp> option as follows: <indexterm index="cp"><code>-p <var>input-path</var></code></indexterm><indexterm index="cp"><var>input-path</var></indexterm><indexterm index="cp"><code>-l <var>output-path</var></code></indexterm><indexterm index="cp"><var>output-path</var></indexterm></para>
      <example 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 mss:/ZENDER/nco -l . in.nc
ncks -p http://dust.ess.uci.edu/cgi-bin/dods/nph-dods/dodsdata \
     -l . in.nc</example>
      <para role="continues">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>. <indexterm index="cp">stub</indexterm>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 and 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 the <acronym><acronymword>NCAR</acronymword></acronym> <acronym><acronymword>MSS</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 recommended as it is syntactically more clear.</para>
      <menu>
        <menuentry>
          <menunode>OPeNDAP</menunode>
          <menutitle>OPeNDAP</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </section>
  </node>
  <node>
    <nodename>OPeNDAP</nodename>
    <nodeprev>Remote storage</nodeprev>
    <nodeup>Remote storage</nodeup>
    <subsection>
      <title><acronym><acronymword>OPeNDAP</acronymword></acronym></title>
      <para><indexterm index="cp"><acronym><acronymword>DAP</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>DODS</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>HTTP</acronymword></acronym> protocol</indexterm><indexterm index="cp"><env>DODS_ROOT</env></indexterm><indexterm index="cp">Distributed Oceanographic Data System</indexterm><indexterm index="cp">oceanography</indexterm><indexterm index="cp">data access protocol</indexterm><indexterm index="cp">Open-source Project for a Network Data Access Protocol</indexterm><indexterm index="cp"><acronym><acronymword>OPeNDAP</acronymword></acronym>.</indexterm><indexterm index="cp">server</indexterm><indexterm index="cp">client-server</indexterm>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><para> <indexterm index="cp"><acronym><acronymword>NVODS</acronymword></acronym></indexterm><indexterm index="cp">National Virtual Ocean Data System</indexterm><indexterm index="cp">open source</indexterm><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. <indexterm index="cp"><file>Makefile</file></indexterm>This is described in the <acronym><acronymword>OPeNDAP</acronymword></acronym> documentation and automagically implemented in <acronym><acronymword>NCO</acronymword></acronym> build mechanisms <footnote><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 <footnote><para> The minimal set of libraries required to build <acronym><acronymword>NCO</acronymword></acronym> as <acronym><acronymword>OPeNDAP</acronymword></acronym> clients are, in link order, <file>libnc-dap.a</file>, <file>libdap.a</file>, and <file>libxml2</file> and <file>libcurl.a</file>.</para></footnote>.  in the usual locations. 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>OPeNDAP Homepage</urefdesc></uref> is voluminous. Check there and on the <uref><urefurl>http://www.unidata.ucar.edu/packages/dods/home/mailLists/</urefurl><urefdesc>DODS mail lists</urefdesc></uref>. to learn more about the extensive capabilities of <acronym><acronymword>OPeNDAP</acronymword></acronym> <footnote><para> We are most familiar with the <acronym><acronymword>OPeNDAP</acronymword></acronym> ability to enable network-transparent data access. <indexterm index="cp">constraint expressions</indexterm><indexterm index="cp">server-side processing</indexterm><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 "<acronym><acronymword>OPeNDAP</acronymword></acronym> Capabilities of Interest to <acronym><acronymword>NCO</acronymword></acronym> Users" for incorporation in the <cite>NCO User's 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 xml:space="preserve">% ncks -o ~/foo.nc -C -H -v one -l /tmp \
  -p http://dust.ess.uci.edu/cgi-bin/dods/nph-dods/dodsdata in.nc
one = 1
% ncks -H -v one ~/foo.nc
one = 1</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.</para>
      <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 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 (in Pa)<!-- /@w -->.</para>
      <example xml:space="preserve">ncwa -C -a lat,lon,time -d lon,-10.,10. -d lat,-10.,10. -l /tmp -p \
http://www.cdc.noaa.gov/cgi-bin/nph-nc/Datasets/ncep.reanalysis.dailyavgs/surface \
  pres.sfc.1969.nc ~/foo.nc</example>
      <para role="continues"><indexterm index="cp">packing</indexterm><indexterm index="cp">unpacking</indexterm>All with one command! The data in this particular input file also happen to be packed (see <xref><xrefnodename>Methods and functions</xrefnodename></xref>), although this is completely 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. <indexterm index="cp">I/O</indexterm>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>
    </subsection>
  </node>
  <node>
    <nodename>Retaining Retrieved Files</nodename>
    <nodenext>Selecting Output File Format</nodenext>
    <nodeprev>Remote storage</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Retaining Retrieved Files</title>
      <para><indexterm index="cp">file deletion</indexterm><indexterm index="cp">file removal</indexterm><indexterm index="cp">file retention</indexterm><indexterm index="cp"><code>-R</code></indexterm><indexterm index="cp"><code>--rtn</code></indexterm><indexterm index="cp"><code>--retain</code></indexterm></para>
      <cartouche>
        <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., 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 <xref><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref>, for more details.</para>
      <para><indexterm index="cp"><acronym><acronymword>FTP</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>SSH</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>msrcp</acronymword></acronym></indexterm>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. <indexterm index="cp">server</indexterm>For example, say you want to obtain a <acronym><acronymword>JPEG</acronymword></acronym> file from a weather server.</para>
      <example xml:space="preserve">ncks -R -p ftp://weather.edu/pub/pix/jpeg -l . storm.jpg</example>
      <para role="continues">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>
      <para><indexterm index="cp"><acronym><acronymword>DODS</acronymword></acronym></indexterm><indexterm index="cp">server</indexterm>If your <acronym><acronymword>NCO</acronymword></acronym> is <acronym><acronymword>DAP</acronymword></acronym>-enabled (see <xref><xrefnodename>OPeNDAP</xrefnodename></xref>), 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 xml:space="preserve">ncks -R -l . -p \
http://www.cdc.noaa.gov/cgi-bin/nph-nc/Datasets/ncep.reanalysis.dailyavgs/surface \
  pres.sfc.1969.nc</example>
      <para>Note that <acronym><acronymword>NCO</acronymword></acronym> is never the preffered way to transport files from remote machines. For large jobs, that is best handled by <acronym><acronymword>FTP</acronymword></acronym>, <acronym><acronymword>SSH</acronymword></acronym>, or <command>wget</command>. 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>
    </section>
  </node>
  <node>
    <nodename>Selecting Output File Format</nodename>
    <nodenext>Large File Support</nodenext>
    <nodeprev>Retaining Retrieved Files</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Selecting Output File Format</title>
      <para><indexterm index="cp"><acronym><acronymword>HDF</acronymword></acronym></indexterm><indexterm index="cp">netCDF2</indexterm><indexterm index="cp">netCDF3</indexterm><indexterm index="cp">netCDF4</indexterm><indexterm index="cp"><code>NETCDF4_CLASSIC</code> files</indexterm><indexterm index="cp"><code>NETCDF4</code> files</indexterm><indexterm index="cp"><code>CLASSIC</code> files</indexterm><indexterm index="cp"><code>64BIT</code> files</indexterm><indexterm index="cp"><code>--3</code></indexterm><indexterm index="cp"><code>-3</code></indexterm><indexterm index="cp"><code>-4</code></indexterm><indexterm index="cp"><code>--4</code></indexterm><indexterm index="cp"><code>--netcdf4</code></indexterm><indexterm index="cp"><code>--fl_fmt</code></indexterm><indexterm index="cp"><code>--file_format</code></indexterm><indexterm index="cp"><code>--64bit</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</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>&linebreak; Long options: <samp>--3</samp>, <samp>--4</samp>, <samp>--64bit</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 &ldquo;Availability&rdquo; 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>
      <para>netCDF supports four types of files: <code>CLASSIC</code>, <code>64BIT</code>, <code>NETCDF4</code>, and <code>NETCDF4_CLASSIC</code>, The <code>CLASSIC</code> format is the traditional 32-bit offset written by netCDF2 and netCDF3. As of 2005, most netCDF datasets are in <code>CLASSIC</code> format. The <code>64BIT</code> format was added in Fall, 2004.</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 perfectly readable by applications which use only the netCDF3 <acronym><acronymword>API</acronymword></acronym> and library. <acronym><acronymword>NCO</acronymword></acronym> must be built with netCDF4<!-- /@w --> to write files in the new <code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code> formats, and to read files in the new <code>NETCDF4</code> format. Users are advised to use the default <code>CLASSIC</code> format or the <code>NETCDF4_CLASSIC</code> format until netCDF4 is more widespread. Widespread support for <code>NETCDF4</code> format files is not expected for many years, 2009&ndash;2010, say. If performance or coolness are issues, then use <code>NETCDF4_CLASSIC</code> instead of <code>CLASSIC</code> format files.</para>
      <para>As mentioned above, all operators write use the input file format for output files unless told otherwise. Toggling the long option <samp>--64bit</samp> switch (or its <var>key</var>-<var>value</var> equivalent <samp>--fl_fmt=64bit</samp>) produces the netCDF3 64-bit offset format named <code>64BIT</code>. <acronym><acronymword>NCO</acronymword></acronym> must be built with netCDF 3.6<!-- /@w --> or higher to produce a <code>64BIT</code> file. 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., <acronym><acronymword>HDF</acronymword></acronym>). Casual users are advised to use the default (netCDF3) <code>CLASSIC</code> format until netCDF 3.6<!-- /@w --> and netCDF 4.0<!-- /@w --> are more widespread. Conversely, 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>These examples demonstrate converting a file from any netCDF format into any other netCDF format (subject to limits of the format):</para>
      <example xml:space="preserve">ncks --fl_fmt=classic in.nc foo_3c.nc # netCDF3 classic
ncks --fl_fmt=64bit in.nc foo_364.nc # netCDF3 64bit
ncks --fl_fmt=netcdf4_classic in.nc foo_4c.nc # netCDF4 classic
ncks --fl_fmt=netcdf4 in.nc foo_4.nc # netCDF4
ncks -3 in.nc foo_3c.nc # netCDF3 classic
ncks --3 in.nc foo_3c.nc # netCDF3 classic
ncks -4 in.nc foo_4.nc # netCDF4
ncks --4 in.nc foo_4.nc # netCDF4
ncks --64 in.nc foo364.nc # netCDF3 64bit</example>
      <para>Of course since most operators support these switches, the &ldquo;conversions&rdquo; 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</code> files from <code>NETCDF4_CLASSIC</code> files will always work. However, producing netCDF3 files from <code>NETCDF4</code> files will only work if the output files are not required to contain netCDF4-specific features.</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. As of October, 2005, <acronym><acronymword>NCO</acronymword></acronym> writes no netCDF4-specific data structures and so always succeeds at writing <code>NETCDF4_CLASSIC</code> files.</para>
      <para>There are at least three ways to discover the format of a netCDF file, i.e., whether it is a classic (32-bit offset) or newer 64-bit offset netCDF3 format, or is netCDF4 format. Each method returns the information using slightly different terminology that becomes easier to understand with practice.</para>
      <para>First, examine the end of the first line of global metadata output by <samp>ncks -M</samp>: <indexterm index="cp">netCDF3 classic file format</indexterm><indexterm index="cp">netCDF4 classic file format</indexterm><indexterm index="cp">netCDF4 file format</indexterm><indexterm index="cp">32-bit offset file format</indexterm><indexterm index="cp">64-bit offset file format</indexterm><indexterm index="cp"><command>ncks</command></indexterm><indexterm index="cp"><code>-M</code></indexterm></para>
      <example xml:space="preserve">% ncks -M foo_3c.nc
Opened file foo_3c.nc: dimensions = 19, variables = 261, global atts. = 4,
  id = 65536, type = NC_FORMAT_CLASSIC
% ncks -M foo_364.nc
Opened file foo_364.nc: dimensions = 19, variables = 261, global atts. = 4,
  id = 65536, type = NC_FORMAT_64BIT
% ncks -M foo_4c.nc
Opened file foo_4c.nc: dimensions = 19, variables = 261, global atts. = 4,
  id = 65536, type = NC_FORMAT_NETCDF4_CLASSIC
% ncks -M foo_4.nc
Opened file foo_4.nc: dimensions = 19, variables = 261, global atts. = 4,
  id = 65536, type = NC_FORMAT_NETCDF4</example>
      <para>This method requires a netCDF4-enabled <acronym><acronymword>NCO</acronymword></acronym> version 3.9.0+ (i.e., from 2007 or later).</para>
      <para>Second, query the file with <samp>ncdump -k</samp>: <indexterm index="cp"><command>ncdump</command></indexterm></para>
      <example xml:space="preserve">% ncdump -k foo_3.nc
classic
% ncdump -k foo_364.nc
64-bit-offset
% ncdump -k foo_4c.nc
netCDF-4 classic model
% ncdump -k foo_4.nc
netCDF-4</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: <indexterm index="cp"><command>od</command></indexterm><indexterm index="cp">octal dump</indexterm></para>
      <example xml:space="preserve">% od -An -c -N4 foo_3c.nc
   C   D   F 001
% od -An -c -N4 foo_364.nc
   C   D   F 002
% od -An -c -N4 foo_4c.nc
 211   H   D   F
% od -An -c -N4 foo_4.nc
 211   H   D   F</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 the newer netCDF4 file format.</para>
    </section>
  </node>
  <node>
    <nodename>Large File Support</nodename>
    <nodenext>Subsetting Variables</nodenext>
    <nodeprev>Selecting Output File Format</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Large File Support</title>
      <para><indexterm index="cp">LFS</indexterm><indexterm index="cp">Large File Support</indexterm></para>
      <cartouche>
        <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 2 GB<!-- /@w --> on some 32-bit operating systems with netCDF libraries earlier than version 3.6<!-- /@w -->. If desired, LFS support must be configured when both netCDF and <acronym><acronymword>NCO</acronymword></acronym> are installed. netCDF versions 3.6<!-- /@w --> and higher support 64-bit file addresses as part of the netCDF standard. We recommend that users ignore LFS support which is difficult to configure and is implemented in <acronym><acronymword>NCO</acronymword></acronym> only to support netCDF versions prior to 3.6<!-- /@w -->. This obviates the need for configuring explicit LFS support in applications (such as <acronym><acronymword>NCO</acronymword></acronym>) which now support 64-bit files directly through the netCDF interface. See <xref><xrefnodename>Selecting Output File Format</xrefnodename></xref> for instructions on accessing the different file formats, including 64-bit files, supported by the modern netCDF interface.</para>
      <para>If you are still interesting in explicit LFS support for netCDF versions prior to 3.6<!-- /@w -->, know that LFS support depends on a complex, interlocking set of operating system <footnote><para> Linux and <acronym><acronymword>AIX</acronymword></acronym> are known to support <acronym><acronymword>LFS</acronymword></acronym>.</para></footnote> and netCDF suppport issues. The netCDF LFS FAQ at <uref><urefurl>http://my.unidata.ucar.edu/content/software/netcdf/faq-lfs.html</urefurl></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 LFS at build time.</para>
    </section>
  </node>
  <node>
    <nodename>Subsetting Variables</nodename>
    <nodenext>Subsetting Coordinate Variables</nodenext>
    <nodeprev>Large File Support</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Subsetting Variables</title>
      <para><indexterm index="cp">subsetting</indexterm><indexterm index="cp">exclusion</indexterm><indexterm index="cp">extraction</indexterm><indexterm index="cp"><code>-v <var>var</var></code></indexterm><indexterm index="cp"><code>--variable <var>var</var></code></indexterm><indexterm index="cp"><code>-x</code></indexterm><indexterm index="cp"><code>--exclude</code></indexterm><indexterm index="cp"><code>--xcl</code></indexterm></para>
      <cartouche>
        <para>Availability: (<command>ncap2</command>), <command>ncbo</command>, <command>ncea</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;</para>
      </cartouche>
      <para>Subsetting variables refers to explicitly specifying variables to be included or excluded from operator actions. Subsetting is implemented with the <samp>-v <var>var</var>[,&dots;]</samp> and <samp>-x</samp> options. A list<!-- /@w --> of variables to extract is specified following the <samp>-v</samp> option, e.g., <samp>-v time,lat,lon</samp>. Not using the <samp>-v</samp> option is equivalent to specifying all variables. 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>
      <para>Variables explicitly specified for extraction with <samp>-v <var>var</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. <indexterm index="cp">memory requirements</indexterm>Remember, if averaging or concatenating large files stresses your systems memory or disk resources, then the easiest solution is often to use the <samp>-v</samp> option to retain only the most important variables (see <xref><xrefnodename>Memory Requirements</xrefnodename></xref>).</para>
      <para>Due to its special capabilities, <command>ncap2</command> interprets the <samp>-v</samp> switch differently (see <xref><xrefnodename>ncap2 netCDF Arithmetic Processor</xrefnodename></xref>). 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> switch.</para>
      <para><indexterm index="cp">extended regular expressions</indexterm><indexterm index="cp">regular expressions</indexterm><indexterm index="cp">pattern matching</indexterm><indexterm index="cp">wildcards</indexterm><indexterm index="cp"><command>egrep</command></indexterm><indexterm index="cp"><command>ncatted</command></indexterm><indexterm index="cp"><acronym><acronymword>GNU</acronymword></acronym></indexterm>As of <acronym><acronymword>NCO</acronymword></acronym> 2.8.1 (August, 2003), variable name arguments of 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>. For example, <samp>-v '^DST'</samp> selects all variables beginning with the string <samp>DST</samp>. Extended regular expressions are defined by the <acronym><acronymword>GNU</acronymword></acronym> <command>egrep</command> command. The meta-characters used to express pattern matching operations are <samp>^$+?.*[]{}|</samp>. If the regular expression pattern matches <emph>any</emph> part of a variable name then that variable is selected. This capability is called <dfn>wildcarding</dfn>, and is very useful for sub-setting large data files.</para>
      <para><indexterm index="cp"><acronym><acronymword>POSIX</acronymword></acronym></indexterm><indexterm index="cp"><code>regex</code></indexterm>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: <indexterm index="cp"><code>.</code> (wildcard character)</indexterm><indexterm index="cp"><code>$</code> (wildcard character)</indexterm><indexterm index="cp"><code>^</code> (wildcard character)</indexterm><indexterm index="cp"><code>?</code> (filename expansion)</indexterm><indexterm index="cp"><code>*</code> (filename expansion)</indexterm></para>
      <table>
        <tableitem>
          <tableterm><samp>^</samp></tableterm>
          <item>
            <para>Matches the beginning of a string</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><samp>$</samp></tableterm>
          <item>
            <para>Matches the end of a string</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><samp>.</samp></tableterm>
          <item>
            <para>Matches any single character</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">The most useful repetition and combination operators are <indexterm index="cp"><code>?</code> (wildcard character)</indexterm><indexterm index="cp"><code>*</code> (wildcard character)</indexterm><indexterm index="cp"><code>+</code> (wildcard character)</indexterm><indexterm index="cp"><code>|</code> (wildcard character)</indexterm></para>
      <table>
        <tableitem>
          <tableterm><samp>?</samp></tableterm>
          <item>
            <para>The preceding regular expression is optional and matched at most once</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><samp>*</samp></tableterm>
          <item>
            <para>The preceding regular expression will be matched zero or more times</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><samp>+</samp></tableterm>
          <item>
            <para>The preceding regular expression will be matched one or more times</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><samp>|</samp></tableterm>
          <item>
            <para>The preceding regular expression will be joined to the following regular expression. The resulting regular expression matches any string matching either subexpression.</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">To illustrate the use of these operators in extracting variables, consider a file with variables <code>Q</code>, <code>Q01</code>&ndash;<code>Q99</code>, <code>Q100</code>, <code>QAA</code>&ndash;<code>QZZ</code>, <code>Q_H2O</code>, <code>X_H2O</code>, <code>Q_CO2</code>, <code>X_CO2</code>.</para>
      <example xml:space="preserve">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</example>
      <para>Beware&mdash;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>
      <para><indexterm index="cp">globbing</indexterm><indexterm index="cp">shell</indexterm><indexterm index="cp"><command>bash</command></indexterm><indexterm index="cp"><command>csh</command></indexterm><indexterm index="cp">quotes</indexterm>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 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</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>
    </section>
  </node>
  <node>
    <nodename>Subsetting Coordinate Variables</nodename>
    <nodenext>C and Fortran Index Conventions</nodenext>
    <nodeprev>Subsetting Variables</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Subsetting Coordinate Variables</title>
      <para><indexterm index="cp">subsetting</indexterm><indexterm index="cp"><code>-C</code></indexterm><indexterm index="cp"><code>-c</code></indexterm><indexterm index="cp"><code>--no-coords</code></indexterm><indexterm index="cp"><code>--no-crd</code></indexterm><indexterm index="cp"><code>--coords</code></indexterm><indexterm index="cp"><code>--crd</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</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>--crd</samp>, <samp>--coords</samp>&linebreak;</para>
      </cartouche>
      <para>By default, coordinates variables associated with any variable appearing in the <var>input-file</var> will also appear 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 feature can be disabled with <samp>-C</samp>, which causes <acronym><acronymword>NCO</acronymword></acronym> to not automatically add coordinates to the variables appearing in the <var>output-file</var>. However, using <samp>-C</samp> does not preclude the user from including some coordinates in the output files simply by explicitly selecting the coordinates 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 variables in the <var>input-files</var> should appear in the <var>output-file</var>. Thus <samp>-c</samp> allows the user to select all the coordinate variables without having to know their names. <indexterm index="cp"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm>Both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code> convention described in <xref><xrefnodename>CF Conventions</xrefnodename></xref>.</para>
    </section>
  </node>
  <node>
    <nodename>C and Fortran Index Conventions</nodename>
    <nodenext>Hyperslabs</nodenext>
    <nodeprev>Subsetting Coordinate Variables</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>C and Fortran Index conventions</title>
      <para><indexterm index="cp">index convention</indexterm><indexterm index="cp">Fortran index convention</indexterm><indexterm index="cp">C index convention</indexterm><indexterm index="cp"><code>-F</code></indexterm><indexterm index="cp"><code>--fortran</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncbo</command>, <command>ncea</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>
      <para><indexterm index="cp">I/O</indexterm>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. In C<!-- /@w -->, indices count from 0<!-- /@w --> (rather than 1<!-- /@w -->), and dimensions are ordered from slowest (inner-most) to fastest (outer-most) varying. In Fortran, indices count from 1<!-- /@w --> (rather than 0<!-- /@w -->), and dimensions are ordered from fastest (inner-most) to slowest (outer-most) varying. <indexterm index="cp">transpose</indexterm>Hence C and<!-- /@w --> Fortran data storage conventions represent mathematical transposes of eachother. <indexterm index="cp">record variable</indexterm>Note that record variables contain the record dimension as the most slowly varying dimension. See <xref><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></xref> for techniques to re-order (including transpose) dimensions and to reverse data storage order.</para>
      <para><indexterm index="cp">record dimension</indexterm>Consider a file <file>85.nc</file> containing 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 xml:space="preserve">ncra -d time,5,7 85.nc 85_JJA.nc
ncra -F -d time,6,8 85.nc 85_JJA.nc</example>
      <para>Printing variable <var>three_dmn_var</var> in file <file>in.nc</file> first with the C indexing<!-- /@w --> convention, then with Fortran indexing convention results in the following output formats:</para>
      <example xml:space="preserve">% ncks -v three_dmn_var in.nc
lat[0]=-90 lev[0]=1000 lon[0]=-180 three_dmn_var[0]=0
...
% ncks -F -v three_dmn_var in.nc
lon(1)=0 lev(1)=100 lat(1)=-90 three_dmn_var(1)=0
...</example>
    </section>
  </node>
  <node>
    <nodename>Hyperslabs</nodename>
    <nodenext>Stride</nodenext>
    <nodeprev>C and Fortran Index Conventions</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Hyperslabs</title>
      <para><indexterm index="cp">hyperslab</indexterm><indexterm index="cp">dimension limits</indexterm><indexterm index="cp">coordinate limits</indexterm><indexterm index="cp"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncbo</command>, <command>ncea</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>A <dfn>hyperslab</dfn><!-- /@w --> is a subset of a variable'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. 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. 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). 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.</para>
      <para><indexterm index="cp">stride</indexterm>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. For a given dimension, the specified limits must both be coordinate values (with decimal points) or dimension indices (no decimal points). The <var>stride</var> option, if any, must be a dimension index, not a coordinate value. See <xref><xrefnodename>Stride</xrefnodename></xref>, for more information on the <var>stride</var> option.</para>
      <para><indexterm index="cp"><code>NC_BYTE</code></indexterm><indexterm index="cp"><code>NC_CHAR</code></indexterm>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_BYTE</code> and <code>NC_CHAR</code> are computed numerically rather than lexically, so the results are unpredictable.</para>
      <para><indexterm index="cp">wrapped coordinates</indexterm>The relative magnitude of <var>min</var> and <var>max</var> indicate to the operator whether to expect a <dfn>wrapped coordinate</dfn> (see <xref><xrefnodename>Wrapped Coordinates</xrefnodename></xref>), 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>
    </section>
  </node>
  <node>
    <nodename>Stride</nodename>
    <nodenext>Multislabs</nodenext>
    <nodeprev>Hyperslabs</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Stride</title>
      <para><indexterm index="cp">stride</indexterm><indexterm index="cp"><code>-d <var>dim</var>,[<var>min</var>],[<var>max</var>],<var>stride</var></code></indexterm><indexterm index="cp"><code>--dimension <var>dim</var>,[<var>min</var>],[<var>max</var>],<var>stride</var></code></indexterm><indexterm index="cp"><code>--dmn <var>dim</var>,[<var>min</var>],[<var>max</var>],<var>stride</var></code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncbo</command>, <command>ncea</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. A <var>stride</var><!-- /@w --> of 1<!-- /@w --> picks all the elements of the hyperslab, and a <var>stride</var> 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 (see <xref><xrefnodename>Multislabs</xrefnodename></xref>). 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) element 0<!-- /@w --> or element <samp>stride-1</samp>. <acronym><acronymword>NCO</acronymword></acronym> must resolve this ambiguity and it chooses 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 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 (see <xref><xrefnodename>C and Fortran Index Conventions</xrefnodename></xref>) these data are stored in records 2, 14, &dots; 50<!-- /@w --> so the desired <var>stride</var> 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: <indexterm index="cp">Bourne Shell</indexterm><indexterm index="cp">C Shell</indexterm></para>
      <example xml:space="preserve">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.??</example>
      <para>With the <var>stride</var> option, <command>ncks</command> performs this hyperslab extraction in one operation:</para>
      <example xml:space="preserve">ncks -d time,2,,12 8501_8912.nc 8589_03.nc</example>
      <para>See <xref><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 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</example>
    </section>
  </node>
  <node>
    <nodename>Multislabs</nodename>
    <nodenext>Wrapped Coordinates</nodenext>
    <nodeprev>Stride</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Multislabs</title>
      <para><indexterm index="cp">multislab</indexterm><indexterm index="cp">multi-hyperslab</indexterm><indexterm index="cp"><acronym><acronymword>MSA</acronymword></acronym></indexterm><indexterm index="cp"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncbo</command>, <command>ncea</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;</para>
      </cartouche>
      <para>A multislab<!-- /@w --> is a union of one or more hyperslabs. One defines multislabs by chaining together hyperslab commands, i.e., <kbd>-d</kbd> options (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>). 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 <acronym><acronymword>MSA</acronymword></acronym> capabilities in April 2008. Sometimes multi-slabbing is referred to by the acronym <acronym><acronymword>MSA</acronymword></acronym>, which stands for &ldquo;Multi-Slabbing Algorithm&rdquo;.</para>
      <para>Multislabs overcome some restraints that limit hyperslabs. 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 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 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</example>
      <para role="continues">Any number of hyperslabs specifications may be chained together to specify the multislab.</para>
      <para><indexterm index="cp">stride</indexterm>Users may specify redundant ranges of indices in a multislab, e.g.,</para>
      <example xml:space="preserve">ncks -d lon,0,4 -d lon,2,9,2 in.nc out.nc</example>
      <para role="continues">This command retrieves the first five longitudes, and then every other longitude value up to the tenth. Elements 0, 2, 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. See <xref><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. <indexterm index="cp">I/O</indexterm>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>A final<!-- /@w --> example shows the real power of multislabs. 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 elements 0<!-- /@w -->, 1, and 5<!-- /@w --> of the <var>species</var> dimension of <var>Q</var>. The multislab specification might look something like</para>
      <example xml:space="preserve">ncks -d species,0,1 -d species,5 -d lon,0,4 -d lon,2,9,2 in.nc out.nc</example>
      <para role="continues">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>
    </section>
  </node>
  <node>
    <nodename>Wrapped Coordinates</nodename>
    <nodenext>Auxiliary Coordinates</nodenext>
    <nodeprev>Multislabs</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Wrapped Coordinates</title>
      <para><indexterm index="cp">wrapped coordinates</indexterm><indexterm index="cp">longitude</indexterm><indexterm index="cp"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></para>
      <cartouche>
        <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>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 180 degrees<!-- /@w --> East (or West). Continuing eastward, longitude increases to 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 360 degrees<!-- /@w -->, but represent contiguous regions on the globe. For example, the Saharan desert stretches from roughly 340 to 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 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 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</example>
      <para role="continues">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 (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>).</para>
    </section>
  </node>
  <node>
    <nodename>Auxiliary Coordinates</nodename>
    <nodenext>UDUnits Support</nodenext>
    <nodeprev>Wrapped Coordinates</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Auxiliary Coordinates</title>
      <para><indexterm index="cp"><code>-X</code></indexterm><indexterm index="cp"><code>--auxiliary</code></indexterm><indexterm index="cp"><code>standard_name</code></indexterm><indexterm index="cp"><code>coordinates</code></indexterm><indexterm index="cp"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm><indexterm index="cp"><code>-X <var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var></code></indexterm><indexterm index="cp"><code>--auxiliary <var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var></code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncbo</command>, <command>ncea</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 coordinate variable'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 over coordinate ranges. This works on datasets that associate coordinate variables to grid-mappings using the <acronym><acronymword>CF</acronymword></acronym>-convention (see <xref><xrefnodename>CF Conventions</xrefnodename></xref>) <code>coordinates</code> and <code>standard_name</code> attributes described <uref><urefurl>http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.1/cf-conventions.html#coordinate-system</urefurl><urefdesc>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 range [<var>lon_min</var>,<var>lon_max</var>,<var>lat_min</var>,<var>lat_max</var>] are included in the output hyperslab.</para>
      <para><indexterm index="cp">cell-based grids</indexterm>A cell-based 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 (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>) 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>'s are &ldquo;latitude&rdquo; and &ldquo;longitude&rdquo;, respectively. This <code>standard_name</code> attribute for latitude and longitude coordinates follows the <acronym><acronymword>CF</acronymword></acronym>-convention (see <xref><xrefnodename>CF Conventions</xrefnodename></xref>).</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 xml:space="preserve">% ncks -m -C -v gds_3dvar ~/nco/data/in.nc
gds_3dvar: # dim. = 2, NC_FLOAT, # att. = 4, ID = 38
gds_3dvar dimension 0: time, size = 10 NC_DOUBLE, dim. ID = 18 (CRD)(REC)
gds_3dvar dimension 1: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
gds_3dvar memory size is 10*8*nco_typ_lng(NC_FLOAT) = 80*4 = 320 bytes
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</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 is 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 &ldquo;latitude&rdquo;, and &ldquo;longitude&rdquo;:</para>
      <example xml:space="preserve">% ncks -m -C -v lat_gds,lon_gds ~/nco/data/in.nc
lat_gds: # dim. = 1, NC_DOUBLE, # att. = 4, ID = 34
lat_gds dimension 0: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
lat_gds memory size is 8*nco_typ_lng(NC_DOUBLE) = 8*8 = 64 bytes
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

lon_gds: # dim. = 1, NC_DOUBLE, # att. = 4, ID = 35
lon_gds dimension 0: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
lon_gds memory size is 8*nco_typ_lng(NC_DOUBLE) = 8*8 = 64 bytes
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</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 dimension (<code>gds_crd</code>, in this case) as the cell-based variables.</para>
      <para>This infrastructure allows <acronym><acronymword>NCO</acronymword></acronym> to identify, interpret, and process (e.g., hyperslab) the variables on cell-based grids as easily as it works with regular grids. To time-average all the values between zero and 180 degrees<!-- /@w --> longitude and between plus and minus 30 degress<!-- /@w --> latitude, we use</para>
      <example xml:space="preserve">ncra -O -X 0.,180.,-30.,30. -v gds_3dvar in.nc out.nc</example>
      <para><acronym><acronymword>NCO</acronymword></acronym> accepts multiple <samp>-X</samp> arguments for cell-based grids multi-slabs, just as it accepts multiple <samp>-d</samp> arguments for multi-slabs of regular coordinates.</para>
      <example xml:space="preserve">ncra -O -X 0.,180.,-30.,30. -X 270.,315.,45.,90. in.nc out.nc</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 xml:space="preserve">ncra -X 0.,180.,-30.,30. in.nc out.nc
ncra -X 0,180,-30,30 in.nc out.nc</example>
      <para>In contrast, arguments to <samp>-d</samp> require decimal places to be recognized as coordinates not indices (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>). We recommend always using decimal points with <samp>-X</samp> arguments to avoid confusion.</para>
    </section>
  </node>
  <node>
    <nodename>UDUnits Support</nodename>
    <nodenext>Missing Values</nodenext>
    <nodeprev>Auxiliary Coordinates</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>UDUnits Support</title>
      <para><indexterm index="cp">UDUnits</indexterm><indexterm index="cp">Unidata</indexterm><indexterm index="cp"><code>units</code></indexterm><indexterm index="cp">attribute, <code>units</code></indexterm><indexterm index="cp"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dimension <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm><indexterm index="cp"><code>--dmn <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncbo</command>, <command>ncea</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/packages/udunits</urefurl><urefdesc>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. <indexterm index="cp">MKS units</indexterm>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 xml:space="preserve">% ncks -C -H -v wvl -d wvl,"0.4 micron","0.7 micron" in.nc
wvl[0]=5e-07 meter</example>
      <para role="continues"><indexterm index="cp"><code>units</code></indexterm>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>"foo"</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. <indexterm index="cp">coordinate variable</indexterm>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'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>
      <para><indexterm index="cp"><code>units</code></indexterm><indexterm index="cp"><code>time</code></indexterm>The translation and dimensional innterpretation of time coordinates shows a more powerful, and probably more common, UDUnits application. In this example, the user prints all data between the eighth and ninth of December, 1999, from a variable whose time dimension is hours since the year 1900:</para>
      <example xml:space="preserve">% ncks -H -C -v time_udunits -d time_udunits,"1999-12-08 \
  12:00:0.0","1999-12-09 00:00:0.0",2 in.nc foo2.nc
time_udunits[1]=876018 hours since 1900-01-01 00:00:0.0</example>
      <para role="continues"><indexterm index="cp">stride</indexterm><indexterm index="cp">whitespace</indexterm>Here, the user invokes the stride (see <xref><xrefnodename>Stride</xrefnodename></xref>) capability to obtain every other timeslice. This is possible because the UDUnits feature is additive, not exclusive&mdash;it works in conjunction with all other hyperslabbing (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>) 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 xml:space="preserve">ncra -d time,"1939-09-09 12:00:0.0","1945-05-08 00:00:0.0" \
  in1.nc in2.nc in3.nc out.nc</example>
      <para role="continues">Note that there is no excess whitespace before or after the individual elements of the <samp>-d</samp> argument. <indexterm index="cp">shell</indexterm>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 (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>) 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>UDUnits2</urefdesc></uref> package supports non-ASCII characters and logarithmic units. We are interested in user-feedback on these features, which are relatively un-tested with <acronym><acronymword>NCO</acronymword></acronym>.</para>
      <para><indexterm index="cp">Climate and Forecast Metadata Convention</indexterm><indexterm index="cp">CF conventions</indexterm>The <uref><urefurl>http://www.unidata.ucar.edu/packages/udunits</urefurl><urefdesc>UDUnits</urefdesc></uref> package documentation describes the supported formats of time dimensions. Among the metadata conventions which adhere to these formats are the <uref><urefurl>http://www.cgd.ucar.edu/cms/eaton/cf-metadata/CF-1.0.html</urefurl><urefdesc>Climate and Forecast (CF) Conventions</urefdesc></uref> and the <uref><urefurl>http://ferret.wrc.noaa.gov/noaa_coop/coop_cdf_profile.html</urefurl><urefdesc>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: 
<!-- fxm add more formats here --></para>
      <example xml:space="preserve">-d time,"1918-11-11 11:00:0.0","1939-09-09 00:00:0.0"</example>
      <para role="continues">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 non-leading dash in a limit string indicates that a UDUnits date conversion is requested.</para>
      <para><indexterm index="cp">MKS units</indexterm><indexterm index="cp">God</indexterm>netCDF variables should always be stored with MKS (i.e., God's) units, so that application programs may assume MKS dimensions apply to all input variables. The UDUnits feature is intended to alleviate some of the <acronym><acronymword>NCO</acronymword></acronym> user's pain when handling MKS units. It connects users who think in human-friendly units (e.g., miles, millibars, days) to extract data which are always stored in God's units, MKS (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>
    </section>
  </node>
  <node>
    <nodename>Missing Values</nodename>
    <nodenext>Chunking</nodenext>
    <nodeprev>UDUnits Support</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Missing values</title>
      <para><indexterm index="cp">missing values</indexterm><indexterm index="cp">data, missing</indexterm><indexterm index="cp">averaging data</indexterm><indexterm index="cp"><code>missing_value</code></indexterm><indexterm index="cp"><code>_FillValue</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</command>, <command>ncflint</command>, <command>ncpdq</command>, <command>ncra</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. <indexterm index="cp">arithmetic operators</indexterm>The <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">
        <item>
          <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'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 NCO 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><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 <kbd>CPPFLAGS='-DNCO_MSS_VAL_SNG=missing_value'</kbd>. </para></footnote>.</para>
          <para><indexterm index="cp">ncrename</indexterm><indexterm index="cp">ncatted</indexterm>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> (see <xref><xrefnodename>ncrename netCDF Renamer</xrefnodename></xref>) to rename all <code>missing_value</code> attributes to <code>_FillValue</code>:</para>
          <example xml:space="preserve">ncrename -a .missing_value,_FillValue inout.nc</example>
          <para>Alternatively, one may use <command>ncatted</command> (see <xref><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></xref>) to add a <code>_FillValue</code> attribute to all variables</para>
          <example xml:space="preserve">ncatted -O -a _FillValue,,o,f,1.0e36 inout.nc</example>
        </item>
        <item>
          <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. <indexterm index="cp">C language</indexterm>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 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 C function<!-- /@w --> <code>strtod(<var>_FillValue</var>)</code>. <indexterm index="cp"><command>ncatted</command></indexterm>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 (see <xref><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></xref>).</para>
        </item>
        <item>
          <para>Identifying missing data during arithmetic operations.</para>
          <para><indexterm index="cp">performance</indexterm><indexterm index="cp">operator speed</indexterm><indexterm index="cp">speed</indexterm><indexterm index="cp">execution time</indexterm><indexterm index="cp">arithmetic operators</indexterm>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>
        </item>
        <item>
          <para>Treatment of any data identified as missing in arithmetic operators.</para>
          <para><indexterm index="cp"><command>ncea</command></indexterm><indexterm index="cp"><command>ncra</command></indexterm><indexterm index="cp"><command>ncwa</command></indexterm><indexterm index="cp"><command>ncbo</command></indexterm><indexterm index="cp"><command>ncflint</command></indexterm><acronym><acronymword>NCO</acronymword></acronym> averagers (<command>ncra</command>, <command>ncea</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 &ldquo;the right thing&rdquo;.</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>'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>
        </item>
      </enumerate>
    </section>
  </node>
  <node>
    <nodename>Chunking</nodename>
    <nodenext>Deflation</nodenext>
    <nodeprev>Missing Values</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Chunking</title>
      <para><indexterm index="cp"><code>--cnk_dmn</code></indexterm><indexterm index="cp"><code>--cnk_map</code></indexterm><indexterm index="cp"><code>--cnk_plc</code></indexterm><indexterm index="cp"><code>--cnk_scl</code></indexterm><indexterm index="cp"><code>--chunk_dimension</code></indexterm><indexterm index="cp"><code>--chunk_map</code></indexterm><indexterm index="cp"><code>--chunk_policy</code></indexterm><indexterm index="cp"><code>--chunk_scalar</code></indexterm><indexterm index="cp">chunking</indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</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_dmn <var>dmn_nm</var>,<var>cnk_sz</var></samp>, <samp>--chunk_dimension <var>dmn_nm</var>,<var>cnk_sz</var></samp>&linebreak;, <samp>--cnk_map <var>cnk_map</var></samp>, <samp>--chunk_map <var>cnk_map</var></samp>,&linebreak; <samp>--cnk_plc <var>cnk_plc</var></samp>, <samp>--chunk_policy <var>cnk_plc</var></samp>,&linebreak; <samp>--cnk_scl <var>cnk_sz</var></samp>, <samp>--chunk_scalar <var>cnk_sz</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 in detail <uref><urefurl>http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html</urefurl><urefdesc>here</urefdesc></uref>.</para>
      <para><indexterm index="cp">chunking policy</indexterm><indexterm index="cp">chunking map</indexterm><indexterm index="cp">chunksize</indexterm>The <acronym><acronymword>NCO</acronymword></acronym> chunking implementation is designed to be flexible. Users control three aspects of the chunking implementation. These are known as the <dfn>chunking policy</dfn>, <dfn>chunking map</dfn>, and <dfn>chunksize</dfn>. The first two are high-level mechanisms that apply to an entire file, while the third allows per-dimension specification of parameters. <indexterm index="cp">hyperslab</indexterm><indexterm index="cp">ncpdq</indexterm><indexterm index="cp">packing</indexterm>The implementation is a hybrid of the <command>ncpdq</command> packing policies (see <xref><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></xref>), and the hyperslab specifications (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>). Each aspect is intended to have a sensible default, so that most users will only need to set one switch to obtain sensible chunking. Power users can tune the three switches in tandem to obtain optimal performance.</para>
      <para>The user specifies 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. Five chunking policies are currently implemented:&linebreak; <indexterm index="cp"><samp>all</samp></indexterm><indexterm index="cp"><samp>g2d</samp></indexterm><indexterm index="cp"><samp>g3d</samp></indexterm><indexterm index="cp"><samp>xpl</samp></indexterm><indexterm index="cp"><samp>cnk_all</samp></indexterm><indexterm index="cp"><samp>cnk_g2d</samp></indexterm><indexterm index="cp"><samp>cnk_g3d</samp></indexterm><indexterm index="cp"><samp>cnk_xpl</samp></indexterm><indexterm index="cp"><samp>plc_all</samp></indexterm><indexterm index="cp"><samp>plc_g2d</samp></indexterm><indexterm index="cp"><samp>plc_g3d</samp></indexterm><indexterm index="cp"><samp>plc_xpl</samp></indexterm></para>
      <table>
        <tableitem>
          <tableterm><dfn>Chunk All Variables [<emph>default</emph>]</dfn></tableterm>
          <item>
            <para>Definition: Chunk all variables possible&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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Chunk Variables with at least Two Dimensions</dfn></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Chunk Variables with at least Three Dimensions</dfn></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Chunk Variables Containing Explicitly Chunked Dimensions</dfn></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Unchunking</dfn></tableterm>
          <item>
            <para>Definition: Unchunk all variables&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>unchunk</samp>&linebreak; Mnemonic: <emph>U</emph>n<emph>C</emph>hun<emph>K</emph>&linebreak;</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">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><indexterm index="cp">chunking map</indexterm><indexterm index="cp"><var>cnk_map</var></indexterm><indexterm index="cp"><code>-M <var>cnk_map</var></code></indexterm><indexterm index="cp"><code>--cnk_map <var>cnk_map</var></code></indexterm><indexterm index="cp"><code>--map <var>cnk_map</var></code></indexterm>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. Four chunking maps are currently implemented:&linebreak; <indexterm index="cp"><samp>dmn</samp></indexterm><indexterm index="cp"><samp>scl</samp></indexterm><indexterm index="cp"><samp>prd</samp></indexterm><indexterm index="cp"><samp>rd1</samp></indexterm><indexterm index="cp"><samp>cnk_dmn</samp></indexterm><indexterm index="cp"><samp>cnk_scl</samp></indexterm><indexterm index="cp"><samp>cnk_prd</samp></indexterm><indexterm index="cp"><samp>cnk_rd1</samp></indexterm><indexterm index="cp"><samp>map_dmn</samp></indexterm><indexterm index="cp"><samp>map_scl</samp></indexterm><indexterm index="cp"><samp>map_prd</samp></indexterm><indexterm index="cp"><samp>map_rd1</samp></indexterm></para>
      <table>
        <tableitem>
          <tableterm><dfn>Chunksize Equals Dimension Size [<emph>default</emph>]</dfn></tableterm>
          <item>
            <para>Definition: Chunksize defaults to dimension size. Explicitly specify chunksizes for particular dimensions with <samp>--cnk_dmn</samp> option.&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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Chunksize Equals Dimension Size except Record Dimension</dfn></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Chunksize Equals Scalar Size Specified</dfn></tableterm>
          <item>
            <para>Definition: Chunksize for all dimensions is set with the <samp>--cnk_scl</samp> option.&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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Chunksize Product Equals Scalar Size Specified</dfn></tableterm>
          <item>
            <para>Definition: The product of the chunksizes for each variable (approximately) equals the size specified with the <samp>--cnk_scl</samp> option. 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 the <var>R</var>th root of <var>cnk_scl</var>.&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>
          </item>
        </tableitem>
      </table>
      <para role="continues">It is possible to combine the above chunking map algorithms with user-specified per-dimension (but 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>cnk_sz</var>, which are the dimension name and its chunksize, respectively. The <samp>--cnk_dmn</samp> option may be us as many times as necessary.</para>
      <example xml:space="preserve"># Debugging
ncks -O -4 -D 4 --cnk_scl=8 ~/nco/data/in.nc ~/foo.nc
ncks -O -4 -D 4 --cnk_scl=8 /data/zender/dstmch90/dstmch90_clm.nc ~/foo.nc
ncks -O -4 -D 4 --cnk_dmn lat,64 --cnk_dmn lon,128 /data/zender/dstmch90/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,64 --cnk_dmn lon,128 /data/zender/dstmch90/dstmch90_clm.nc ~/foo.nc

# Chunk data then unchunk it back to its original state:
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

# Final, cleaner examples for manual
ncks --cnk_plc=all     in.nc out.nc # Chunk in.nc
ncks --cnk_plc=unchunk in.nc out.nc # Unchunk in.nc</example>
    </section>
  </node>
  <node>
    <nodename>Deflation</nodename>
    <nodenext>Packed data</nodenext>
    <nodeprev>Chunking</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Deflation</title>
      <para><indexterm index="cp"><code>-L</code></indexterm><indexterm index="cp"><code>--deflate</code></indexterm><indexterm index="cp"><code>--dfl_lvl</code></indexterm><indexterm index="cp">Lempel-Ziv deflation</indexterm><indexterm index="cp">compression</indexterm><indexterm index="cp">deflation</indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</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>-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 Lempel-Ziv deflation. The Lempel-Ziv algorithm is a lossless data compression technique. Activate this 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>). 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 a few percent in size.</para>
      <para>To compress an entire file using deflation, use</para>
      <example 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)</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 <xref><xrefnodename>Packed data</xrefnodename></xref>), can easily compress files by 50%. Packed data may be deflated to squeeze datasets by about 80%.</para>
      <example 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)</example>
      <para><indexterm index="cp">ncks</indexterm><command>ncks</command> prints deflation parameters, if any, to screen (see <xref><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref>).</para>
    </section>
  </node>
  <node>
    <nodename>Packed data</nodename>
    <nodenext>Operation Types</nodenext>
    <nodeprev>Deflation</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Packed data</title>
      <para><indexterm index="cp">packing</indexterm><indexterm index="cp">unpacking</indexterm><indexterm index="cp"><code>add_offset</code></indexterm><indexterm index="cp"><code>scale_factor</code></indexterm><indexterm index="cp"><code>missing_value</code></indexterm><indexterm index="cp"><code>_FillValue</code></indexterm><indexterm index="cp"><command>pack(x)</command></indexterm><indexterm index="cp"><command>unpack(x)</command></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</command>, <command>ncflint</command>, <command>ncpdq</command>, <command>ncra</command>, <command>ncwa</command>&linebreak; Short options: None&linebreak;</para>
      </cartouche>
      <para>The phrase <dfn>packed data</dfn> refers to data which are stored in the standard netCDF3 packing format which employs a lossy algorithm. See <xref><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref> for a description of deflation, a lossless compression technique available with netCDF4 only. Packed data may be deflated to save additional space.</para>

      <unnumberedsubsec>
        <title>Packing Algorithm</title>
        <para><dfn>Packing</dfn> The standard netCDF packing algorithm is lossy, and produces data with the same dynamic range as the original but which requires no more than half the space to store. 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 of <var>x</var>.<!-- /@w --></para>
        <sp lines="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 lines="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 representible. In practice, the number of discretely representible values is taken to be one less than the theoretical maximum. This leaves extra space and solves potential problems with rounding which can occur during the unpacking of the variable. Thus for <code>NC_SHORT</code>, <math>ndrv = 65536 - 1 = 65535</math>. Less often, the variable may be packed into type <code>NC_CHAR</code>, where <math>ndrv = 256 - 1 = 255</math>, or type <code>NC_INT</code> where where <math>ndrv = 4294967295 - 1 = 4294967294</math>. One useful feature of (lossy) netCDF packing algorithm is that additional, loss-less packing algorithms perform well on top of it.</para>
      </unnumberedsubsec>

      <unnumberedsubsec>
        <title>Unpacking Algorithm</title>
        <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.</para>
        <sp lines="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 lines="1"></sp>
        <para>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'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>
        <title>Default Handling of Packed Data</title>
        <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> (see <xref><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></xref>). Packing and unpacking individual variables may be done with <command>ncpdq</command> and the <command>ncap2</command> <command>pack()</command> and <command>unpack()</command> functions (see <xref><xrefnodename>Methods and functions</xrefnodename></xref>).</para>
      </unnumberedsubsec>
    </section>
  </node>
  <node>
    <nodename>Operation Types</nodename>
    <nodenext>Type Conversion</nodenext>
    <nodeprev>Packed data</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Operation Types</title>
      <para><indexterm index="cp">operation types</indexterm><indexterm index="cp"><code>avg</code></indexterm><indexterm index="cp"><code>sqravg</code></indexterm><indexterm index="cp"><code>avgsqr</code></indexterm><indexterm index="cp"><code>min</code></indexterm><indexterm index="cp"><code>max</code></indexterm><indexterm index="cp"><code>rmssdn</code></indexterm><indexterm index="cp"><code>rms</code></indexterm><indexterm index="cp"><code>ttl</code></indexterm><indexterm index="cp"><code>sqrt</code></indexterm><indexterm index="cp">average</indexterm><indexterm index="cp">mean</indexterm><indexterm index="cp">total</indexterm><indexterm index="cp">minimum</indexterm><indexterm index="cp">maximum</indexterm><indexterm index="cp">root-mean-square</indexterm><indexterm index="cp">standard deviation</indexterm><indexterm index="cp">variance</indexterm><indexterm index="cp"><code>-y <var>op_typ</var></code></indexterm><indexterm index="cp"><code>--operation <var>op_typ</var></code></indexterm><indexterm index="cp"><code>--op_typ <var>op_typ</var></code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncra</command>, <command>ncea</command>, <command>ncwa</command>&linebreak; Short options: <samp>-y</samp>&linebreak; Long options: <samp>--operation</samp>, <samp>--op_typ</samp>&linebreak;</para>
      </cartouche>
      <para role="continues">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>
        <tableitem>
          <tableterm><code>avg</code></tableterm>
          <item>
            <para>Mean value</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>sqravg</code></tableterm>
          <item>
            <para>Square of the mean</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>avgsqr</code></tableterm>
          <item>
            <para>Mean of sum of squares</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>max</code></tableterm>
          <item>
            <para>Maximium value</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>min</code></tableterm>
          <item>
            <para>Minimium value</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>rms</code></tableterm>
          <item>
            <para>Root-mean-square (normalized by <var>N</var>)</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>rmssdn</code></tableterm>
          <item>
            <para>Root-mean square (normalized by <var>N-1</var>)</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>sqrt</code></tableterm>
          <item>
            <para>Square root of the mean</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ttl</code></tableterm>
          <item>
            <para>Sum of values</para>
          </item>
        </tableitem>
      </table>
      <para role="continues"><indexterm index="cp">coordinate variable</indexterm><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, but not on coorniate 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. See <xref><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>printed manual</urefdesc></uref> for much more detailed and complete documentation of this subject.</emph></para>
      <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 (see <xref><xrefnodename>Help Requests and Bug Reports</xrefnodename></xref>).</para>
      <para role="continues">EXAMPLES</para>
      <para role="continues">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 minimium value of <code>prs_sfc</code> over all dimensions:</para>
      <example xml:space="preserve">ncwa -y min -v prs_sfc in.nc foo.nc</example>
      <para role="continues">Find the maximum value of <code>prs_sfc</code> at each time interval for each latitude:</para>
      <example xml:space="preserve">ncwa -y max -v prs_sfc -a lon in.nc foo.nc</example>
      <para role="continues">Find the root-mean-square value of the time-series of <code>prs_sfc</code> at every gridpoint:</para>
      <example 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</example>
      <para role="continues">The previous two commands give the same answer but <command>ncra</command> is preferred because it has a smaller memory footprint. <indexterm index="cp">degenerate dimension</indexterm>Also, 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>
      <para role="continues">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 maximium surface pressure at every point.</para>
      <example xml:space="preserve">ncea -y max -v prs_sfc jan.nc feb.nc march.nc out.nc</example>
      <para role="continues">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 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</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 var</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 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</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 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</example>
      <para><command>ncap2</command> supports intrinsic standard deviation functions (see <xref><xrefnodename>Operation Types</xrefnodename></xref>) which simplify the above expression to</para>
      <example xml:space="preserve">ncap2 -s 'prs_sfc_sdn=(prs_sfc-prs_sfc.avg($time)).rmssdn($time)' in.nc out.nc</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 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</example>
      <para>First the appropriately weighted (with <samp>-w gw</samp>) spatial mean values are written to the output file. This example includes the use of a weighted variable specified with <samp>-w gw</samp>. 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. The initial output file is then overwritten with the gridpoint deviations from the spatial mean. Finally the root-mean-square of the appropriately weighted spatial deviations is taken.</para>
      <para>The <command>ncap2</command> solution to the spatially-weighted standard deviation problem is</para>
      <example xml:space="preserve">ncap2 -s 'prs_sfc_sdn=(prs_sfc*gw-prs_sfc*gw.avg($lat,$lon)).rmssdn($lat,$lon)' \
      in.nc out.nc</example>
      <para>Be sure to multiply the variable by the weight prior to computing the the anomalies and the standard deviation.</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 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 foo2.nc
ncra -O -y rmssdn foo2.nc out.nc</example>
      <para>The first step assembles all the data into a single file. This may require a lot of temporary disk space, but is more or less required by the <command>ncbo</command> operation in the third step.</para>
    </section>
  </node>
  <node>
    <nodename>Type Conversion</nodename>
    <nodenext>Batch Mode</nodenext>
    <nodeprev>Operation Types</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Type Conversion</title>
      <para><indexterm index="cp">type conversion</indexterm></para>
      <cartouche>
        <para>Availability: <command>ncap2</command>, <command>ncbo</command>, <command>ncea</command>, <command>ncra</command>, <command>ncwa</command>&linebreak; Short options: None&linebreak;</para>
      </cartouche>
      <para><indexterm index="cp">promotion</indexterm><indexterm index="cp">demotion</indexterm><indexterm index="cp">automatic type conversion</indexterm><indexterm index="cp">manual type conversion</indexterm>Type conversion (often called <dfn>promotion</dfn> or <dfn>demotion</dfn>) refers to the casting of one fundamental data type to another, e.g., converting <code>NC_SHORT</code> (two bytes) to <code>NC_DOUBLE</code> (eight bytes). 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>
        <menuentry>
          <menunode>Automatic type conversion</menunode>
          <menutitle>Automatic type conversion</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Manual type conversion</menunode>
          <menutitle>Manual type conversion</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </section>
  </node>
  <node>
    <nodename>Automatic type conversion</nodename>
    <nodenext>Manual type conversion</nodenext>
    <nodeprev>Type Conversion</nodeprev>
    <nodeup>Type Conversion</nodeup>
    <subsection>
      <title>Automatic type conversion</title>
      <para>As a general rule, automatic type conversions should be avoided for at least two reasons. First, type conversions are expensive since they require creating (temporary) buffers and casting each element of a variable from the type it was stored at to some other type. Second, the dataset's creator probably 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 were made. Thus <acronym><acronymword>NCO</acronymword></acronym> tries to avoid performing automatic type conversions when performing arithmetic.</para>
      <para><indexterm index="cp">C language</indexterm><indexterm index="cp">Fortran</indexterm>Automatic type conversion during arithmetic in the languages C<!-- /@w --> and Fortran is performed only when necessary. All operands in an operation are converted to the most precise type before the operation takes place. However, following this parsimonious conversion rule dogmatically results in numerous headaches. For example, the average of the two <code>NC_SHORT</code>s <code>17000s</code> and <code>17000s</code> results in garbage since the intermediate value which holds their sum is also of type <code>NC_SHORT</code> and thus cannot represent values greater than 32,767 <footnote><para> <setvalue name="flg"></setvalue> <math>32767 = 2^15-1</math> <clearvalue name="flg"></clearvalue> </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 most pure. 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 when all the following conditions are met <footnote><para>Operators began performing type conversions before arithmetic in <acronym><acronymword>NCO</acronymword></acronym> version 1.2<!-- /@w -->, August, 2000. Previous versions never performed unnecessary type conversion for arithmetic.</para></footnote>:</para>
      <enumerate first="1">
        <item>
          <para>The operator is <command>ncea</command>, <command>ncra</command>, or <command>ncwa</command>. <command>ncbo</command> is not yet included in this list because subtraction did not benefit from type conversion. This will change in the future 
<!-- fxm TODO #265 --></para>
        </item>
        <item>
          <para>The arithmetic operation could benefit from type conversion. Operations that could benefit (e.g., from larger representable sums) include averaging, summation, or any "hard" arithmetic. Type conversion does not benefit searching for minima and maxima (<samp>-y min</samp>, or <samp>-y max</samp>).</para>
        </item>
        <item>
          <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 type converted because there is no type of higher precision to convert to. Type <code>NC_FLOAT</code> is not type converted because, in our judgement, the performance penalty of always doing so would outweigh the (extremely rare) potential benefits.</para>
        </item>
      </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>
      <para><indexterm index="cp"><code>floor</code></indexterm>Type conversions use the <code>floor</code> function to convert floating point number to integers. Type conversions do not attempt to round floating point numbers to the nearest integer. Thus the average of <code>1s</code> and <code>2s</code> is computed in double precisions arithmetic as <math>(<code>1.0d</code> + <code>1.5d</code>)/2) = <code>1.5d</code></math>. This result is converted to <code>NC_SHORT</code> and stored on disk as <math><code>floor(1.5d)</code> = <code>1s</code></math> <footnote><para> <indexterm index="cp">C language</indexterm>The actual type conversions are handled by intrinsic C-language type conversion, so the <code>floor()</code> function is not explicitly called, though the results would be the same if it were.</para></footnote>. Thus no "rounding up" is performed. The type conversion rules of C<!-- /@w --> can be stated as follows: If <var>n</var> is an integer then any floating point value <var>x</var> satisfying</para>
      <setvalue name="flg"></setvalue>
      <para><math>n &lt;= x &lt; n+1</math></para>
      <clearvalue name="flg"></clearvalue>
      <para>will have the value <var>n</var> when converted to an integer.</para>
    </subsection>
  </node>
  <node>
    <nodename>Manual type conversion</nodename>
    <nodeprev>Automatic type conversion</nodeprev>
    <nodeup>Type Conversion</nodeup>
    <subsection>
      <title>Manual type conversion</title>
      <para><indexterm index="cp"><command>ncap2</command></indexterm><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 xml:space="preserve">ncap2 -s 'tpt=short(tpt);prs=double(prs)' in.nc out.nc</example>
      <para>See <xref><xrefnodename>ncap2 netCDF Arithmetic Processor</xrefnodename></xref>, for more details.</para>
    </subsection>
  </node>
  <node>
    <nodename>Batch Mode</nodename>
    <nodenext>History Attribute</nodenext>
    <nodeprev>Type Conversion</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Batch Mode</title>
      <para><indexterm index="cp">batch mode</indexterm><indexterm index="cp">overwriting files</indexterm><indexterm index="cp">appending to files</indexterm><indexterm index="cp">force overwrite</indexterm><indexterm index="cp">force append</indexterm><indexterm index="cp"><code>-O</code></indexterm><indexterm index="cp"><code>-A</code></indexterm><indexterm index="cp"><code>--overwrite</code></indexterm><indexterm index="cp"><code>--ovr</code></indexterm><indexterm index="cp"><code>--apn</code></indexterm><indexterm index="cp"><code>--append</code></indexterm></para>
      <cartouche>
        <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.</para>
    </section>
  </node>
  <node>
    <nodename>History Attribute</nodename>
    <nodenext>File List Attributes</nodenext>
    <nodeprev>Batch Mode</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>History Attribute</title>
      <para><indexterm index="cp"><code>history</code></indexterm><indexterm index="cp">timestamp</indexterm><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm><indexterm index="cp"><code>-h</code></indexterm><indexterm index="cp"><code>--hst</code></indexterm><indexterm index="cp"><code>--history</code></indexterm></para>
      <cartouche>
        <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 foo.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> and many other netCDF operators adhere 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 "history", the first one found will be used. <code>history</code> attribute <indexterm index="cp"><command>ncatted</command></indexterm>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 (see <xref><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></xref>). Note that the <samp>-h</samp> switch also turns off writing the <code>nco_input_file_list</code> attribute for multi-file operators (see <xref><xrefnodename>File List Attributes</xrefnodename></xref>).</para>
    </section>
  </node>
  <node>
    <nodename>File List Attributes</nodename>
    <nodenext>CF Conventions</nodenext>
    <nodeprev>History Attribute</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>File List Attributes</title>
      <para><indexterm index="cp"><code>nco_input_file_list</code></indexterm><indexterm index="cp"><code>nco_input_file_number</code></indexterm><indexterm index="cp"><code>stdin</code></indexterm><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm><indexterm index="cp"><code>-H</code></indexterm><indexterm index="cp"><code>--fl_lst_in</code></indexterm><indexterm index="cp"><code>--file_list</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncea</command>, <command>ncecat</command>, <command>ncra</command>, <command>ncrcat</command>&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 (see <xref><xrefnodename>Large Numbers of Files</xrefnodename></xref>). 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 exact command by which the file was created.</para>
      <para><acronym><acronymword>NCO</acronymword></acronym> solves this dilemma by archiving input file list attributes. When the input file list to a multi-file operator is specified via <code>stdin</code>, the operator, by default, attaches two global attributes to any file 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 &ldquo;chain of evidence&rdquo; 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 (see <xref><xrefnodename>History Attribute</xrefnodename></xref>). Hence both switches allows space-conscious users to avoid storing what may amount to many thousands of filenames in a metadata attribute.</para>
    </section>
  </node>
  <node>
    <nodename>CF Conventions</nodename>
    <nodenext>ARM Conventions</nodenext>
    <nodeprev>File List Attributes</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title><acronym><acronymword>CF</acronymword></acronym> Conventions</title>
      <para><indexterm index="cp"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm><indexterm index="cp"><acronym><acronymword>CCSM</acronymword></acronym> conventions</indexterm><indexterm index="cp">UDUnits</indexterm><indexterm index="cp"><code>ORO</code></indexterm><indexterm index="cp"><code>area</code></indexterm><indexterm index="cp"><code>datesec</code></indexterm><indexterm index="cp"><code>date</code></indexterm><indexterm index="cp"><code>gw</code></indexterm><indexterm index="cp"><code>hyai</code></indexterm><indexterm index="cp"><code>hyam</code></indexterm><indexterm index="cp"><code>hybi</code></indexterm><indexterm index="cp"><code>hybm</code></indexterm><indexterm index="cp"><code>lat_bnds</code></indexterm><indexterm index="cp"><code>lon_bnds</code></indexterm><indexterm index="cp"><code>msk_*</code></indexterm></para>
      <cartouche>
        <para>Availability: <command>ncbo</command>, <command>ncea</command>, <command>ncecat</command>, <command>ncflint</command>, <command>ncra</command>, <command>ncwa</command>&linebreak; Short options: None&linebreak;</para>
      </cartouche>
      <para><acronym><acronymword>NCO</acronymword></acronym> recognizes the Climate and Forecast (<acronym><acronymword>CF</acronymword></acronym>) metadata conventions, and treats such data (often called history tapes), specially. <acronym><acronymword>NCO</acronymword></acronym> handles older <acronym><acronymword>NCAR</acronymword></acronym> model datasets, such as <acronym><acronymword>CCM</acronymword></acronym> and early <acronym><acronymword>CCSM</acronymword></acronym> datasets, with its <acronym><acronymword>CF</acronymword></acronym> rules even though the earlier data may not contain an explicit <code>Conventions</code> attribute (e.g., <samp>CF-1.0</samp>). We refer to all such data collectively as <acronym><acronymword>CF</acronymword></acronym> data. Skip this section if you never work with <acronym><acronymword>CF</acronymword></acronym> data.</para>
      <para>The <acronym><acronymword>CF</acronymword></acronym> netCDF conventions are described at <uref><urefurl>http://www.cgd.ucar.edu/cms/eaton/cf-metadata/CF-1.0.html</urefurl></uref>. Most <acronym><acronymword>CF</acronymword></acronym> netCDF conventions are transparent to <acronym><acronymword>NCO</acronymword></acronym> <footnote><para> The exception is appending/altering the attributes <code>x_op</code>, <code>y_op</code>, <code>z_op</code>, and <code>t_op</code> for variables which have been averaged across space and time dimensions. This feature is scheduled for future inclusion in <acronym><acronymword>NCO</acronymword></acronym>. </para></footnote>. There are no known pitfalls associated with using any <acronym><acronymword>NCO</acronymword></acronym> operator on files adhering to these conventions <footnote><para> The <acronym><acronymword>CF</acronymword></acronym> conventions recommend <code>time</code> be stored in the format <var>time</var> since <var>base_time</var>, e.g., the <code>units</code> attribute of <code>time</code> might be <samp>days since 1992-10-8 15:15:42.5 -6:00</samp>. A problem<!-- /@w --> with this format occurs when using <command>ncrcat</command> to concatenate multiple files together, each with a different <var>base_time</var>. That is, any <code>time</code> values from files following the first file to be concatenated should be corrected to the <var>base_time</var> offset specified in the <code>units</code> attribute of <code>time</code> from the first file. The analogous problem has been fixed in <acronym><acronymword>ARM</acronymword></acronym> files (see <xref><xrefnodename>ARM Conventions</xrefnodename></xref>) and could be fixed for <acronym><acronymword>CF</acronymword></acronym> files if there is sufficient lobbying. </para></footnote>. However, to facilitate maximum user friendliness, <acronym><acronymword>NCO</acronymword></acronym> does treat certain variables in some <acronym><acronymword>CF</acronymword></acronym> files specially. The special functions are not required by the <acronym><acronymword>CF</acronymword></acronym> netCDF conventions, but experience shows they simplify data analysis.</para>
      <para>Currently, <acronym><acronymword>NCO</acronymword></acronym> determines whether a datafile is a <acronym><acronymword>CF</acronymword></acronym> output datafile simply by checking whether value of the global attribute <code>Conventions</code> (if it exists) 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 attempt to treat certain variables specially, because of their 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>
      <para><indexterm index="cp">non-coordinate grid properties</indexterm>Furthermore, the <command>ncbo</command> operator does not operate on (i.e., add, subtract, 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>. These variables represent the Gaussian weights, the orography field, 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. The handling of <code>msk_*</code> is exceptional in that <emph>any</emph> variable name beginning with the string <code>msk_</code> is considered to be a &ldquo;mask&rdquo; and is thus preserved (not operated on arithmetically).</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>
      <para><indexterm index="cp"><code>coordinates</code></indexterm><indexterm index="cp">coordinates convention</indexterm><indexterm index="cp">coordinate variable</indexterm><indexterm index="cp">auxiliary coordinates</indexterm><indexterm index="cp">subsetting</indexterm><indexterm index="cp"><code>-C</code></indexterm><indexterm index="cp"><code>-c</code></indexterm><indexterm index="cp"><code>--no-coords</code></indexterm><indexterm index="cp"><code>--no-crd</code></indexterm><indexterm index="cp"><code>--coords</code></indexterm><indexterm index="cp"><code>--crd</code></indexterm>NCO supports the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code> convention described <uref><urefurl>http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.1/cf-conventions.html#coordinate-system</urefurl><urefdesc>here</urefdesc></uref>. This convention allows variables to specify additional coordinates (including multidimensional coordinates) in a space-separated string attribute named <code>coordinates</code>. NCO attaches any such coordinates to the extraction list along with variable and its usual (one-dimensional) coordinates, if any. These auxiliary coordinates are subject to the user-specified overrides described in <xref><xrefnodename>Subsetting Coordinate Variables</xrefnodename></xref>.</para>
    </section>
  </node>
  <node>
    <nodename>ARM Conventions</nodename>
    <nodenext>Operator Version</nodenext>
    <nodeprev>CF Conventions</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title><acronym><acronymword>ARM</acronymword></acronym> Conventions</title>
      <para><indexterm index="cp"><acronym><acronymword>ARM</acronymword></acronym> conventions</indexterm><indexterm index="cp"><code>time_offset</code></indexterm><indexterm index="cp"><code>base_time</code></indexterm><indexterm index="cp"><code>time</code></indexterm></para>
      <cartouche>
        <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 just blindly concatenated. Therefore <command>ncrcat</command> has been specially programmed to be able to chain together consecutive <acronym><acronymword>ARM</acronymword></acronym> <var>input-files</var> and produce and an <var>output-file</var> which contains the correct time information. 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. <indexterm index="cp"><code>history</code></indexterm><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm>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>
    </section>
  </node>
  <node>
    <nodename>Operator Version</nodename>
    <nodeprev>ARM Conventions</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Operator Version</title>
      <para><indexterm index="cp">version</indexterm><indexterm index="cp"><acronym><acronymword>RCS</acronymword></acronym></indexterm><indexterm index="cp"><code>-r</code></indexterm><indexterm index="cp"><code>--revision</code></indexterm><indexterm index="cp"><code>--version</code></indexterm><indexterm index="cp"><code>--vrs</code></indexterm></para>
      <cartouche>
        <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'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 "3.9.5" 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 May 11<!-- /@w -->, 2008.</para>
    </section>
  </node>
  <node>
    <nodename>Operator Reference Manual</nodename>
    <nodenext>Contributing</nodenext>
    <nodeprev>Common features</nodeprev>
    <nodeup>Top</nodeup>
    <chapter>
      <title>Operator Reference Manual</title>
      <para>This chapter presents reference pages for each of the operators individually. The operators are presented in alphabetical order. <indexterm index="cp">command line switches</indexterm>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 <xref><xrefnodename>Common features</xrefnodename></xref>, 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>
        <menuentry>
          <menunode>ncap2 netCDF Arithmetic Processor</menunode>
          <menutitle>ncap2 netCDF Arithmetic Processor</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncatted netCDF Attribute Editor</menunode>
          <menutitle>ncatted netCDF Attribute Editor</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncbo netCDF Binary Operator</menunode>
          <menutitle>ncbo netCDF Binary Operator</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncea netCDF Ensemble Averager</menunode>
          <menutitle>ncea netCDF Ensemble Averager</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncecat netCDF Ensemble Concatenator</menunode>
          <menutitle>ncecat netCDF Ensemble Concatenator</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncflint netCDF File Interpolator</menunode>
          <menutitle>ncflint netCDF File Interpolator</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncks netCDF Kitchen Sink</menunode>
          <menutitle>ncks netCDF Kitchen Sink</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncpdq netCDF Permute Dimensions Quickly</menunode>
          <menutitle>ncpdq netCDF Permute Dimensions Quickly</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncra netCDF Record Averager</menunode>
          <menutitle>ncra netCDF Record Averager</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncrcat netCDF Record Concatenator</menunode>
          <menutitle>ncrcat netCDF Record Concatenator</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncrename netCDF Renamer</menunode>
          <menutitle>ncrename netCDF Renamer</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ncwa netCDF Weighted Averager</menunode>
          <menutitle>ncwa netCDF Weighted Averager</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </chapter>
  </node>
  <node>
    <nodename>ncap2 netCDF Arithmetic Processor</nodename>
    <nodenext>ncatted netCDF Attribute Editor</nodenext>
    <nodeprev>Operator Reference Manual</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncap2</command> netCDF Arithmetic Processor</title>
      <para><indexterm index="cp">parser</indexterm><indexterm index="cp">lexer</indexterm><indexterm index="cp">arithmetic processor</indexterm><indexterm index="cp">ncap</indexterm><indexterm index="cp">ncap2</indexterm></para>
      <cartouche>
        <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>
<!-- fxm: TODO nco549 hyper-link all switches to explanatory sections? -->
<!-- Problem is that only works well in HTML mode -->
<!-- TeXInfo has no native mode for concise hyperlinks in text mode -->
<!-- Currently in TeX/PDF mode, TeXInfo opens browser to find link, -->
<!-- rather than jumping to internal link within document -->
      <para role="continues">SYNTAX</para>
      <example xml:space="preserve">ncap2 [-3] [-4] [<uref><urefurl>http://nco.sf.net/nco.html#-A</urefurl><urefreplacement>-A</urefreplacement></uref>] [-C] [-c] [-D <var>dbg</var>] [-F] [-f] [-L <var>dfl_lvl</var>]
[-l <var>path</var>] [-O] [-o <var>output-file</var>] [-p <var>path</var>] [-R] [-r]
[-s <var>algebra</var>] [-S <var>fl.nco</var>] [-t <var>thr_nbr</var>] [-v]
<var>input-file</var> [<var>output-file</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncap2</command> arithmetically processes netCDF files <footnote><para><command>ncap2</command> is the successor to <command>ncap</command> which was put into maintenance mode in November, 2006. This documentation refers to <command>ncap2</command>, which has a superset of the <command>ncap</command> functionality. Eventually <command>ncap</command> will be deprecated in favor <command>ncap2</command>. <command>ncap2</command> may be renamed <command>ncap</command> in 2008 or 2009.</para></footnote>. <indexterm index="cp">script file</indexterm><indexterm index="cp"><code>--script-file</code></indexterm><indexterm index="cp"><code>--fl_spt</code></indexterm><indexterm index="cp"><code>--script</code></indexterm><indexterm index="cp"><code>--spt</code></indexterm>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> 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. <indexterm index="cp">derived fields</indexterm>See <xref><xrefnodename>Missing Values</xrefnodename></xref>, for treatment of missing values. The results of the algebraic manipulations are called <dfn>derived fields</dfn>.</para>
      <para>Unlike the other operators, <command>ncap2</command> does not accept a list of variables to be operated on as an argument to <samp>-v</samp> (see <xref><xrefnodename>Subsetting Variables</xrefnodename></xref>). Rather, the <samp>-v</samp> switch takes no arguments and indicates that <command>ncap2</command> should output <emph>only</emph> user-defined variables. <command>ncap2</command> neither accepts nor understands the <var>-x</var> switch.</para>
<!-- @subsection Scripting Mathematical Processing with @command{ncap2} -->
      <menu>
        <menuentry>
          <menunode>Syntax of ncap2 statements</menunode>
          <menutitle>Syntax of ncap2 statements</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Expressions</menunode>
          <menutitle>Expressions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Dimensions</menunode>
          <menutitle>Dimensions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Left hand casting</menunode>
          <menutitle>Left hand casting</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Arrays and hyperslabs</menunode>
          <menutitle>Arrays and hyperslabs</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Attributes</menunode>
          <menutitle>Attributes</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Number literals</menunode>
          <menutitle>Number literals</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>if statement</menunode>
          <menutitle>if statement</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>print statement</menunode>
          <menutitle>print statement</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Missing values ncap2</menunode>
          <menutitle>Missing values ncap2</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Methods and functions</menunode>
          <menutitle>Methods and functions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>RAM variables</menunode>
          <menutitle>RAM variables</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Where statement</menunode>
          <menutitle>Where statement</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Loops</menunode>
          <menutitle>Loops</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Include files</menunode>
          <menutitle>Include files</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Irregular grids</menunode>
          <menutitle>Irregular grids</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>GSL special functions</menunode>
          <menutitle>GSL special functions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Examples ncap2</menunode>
          <menutitle>Examples ncap2</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Intrinsic mathematical methods</menunode>
          <menutitle>Intrinsic mathematical methods</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Operators precedence and associativity</menunode>
          <menutitle>Operators precedence and associativity </menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>ID Quoting</menunode>
          <menutitle>ID Quoting</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
      <para>Defining new variables in terms of existing variables is a powerful feature of <command>ncap2</command>. <indexterm index="cp">derived fields</indexterm>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>
    </section>
  </node>
  <node>
    <nodename>Syntax of ncap2 statements</nodename>
    <nodenext>Expressions</nodenext>
    <nodeprev>ncap2 netCDF Arithmetic Processor</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Syntax of <command>ncap2</command> statements</title>
      <para><indexterm index="cp">statement</indexterm><indexterm index="cp">syntax</indexterm>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. <indexterm index="cp">C language</indexterm>The syntax of statements is most like the computer language C<!-- /@w -->. The following characteristics of C<!-- /@w --> are preserved:</para>
      <table>
        <tableitem>
          <tableterm>Array syntax</tableterm><indexterm index="cp">array syntax</indexterm><indexterm index="cp"><code>[]</code> (array delimiters)</indexterm>
          <item>
            <para>Arrays elements are placed within <code>[]</code> characters;</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Array indexing</tableterm><indexterm index="cp">array indexing</indexterm>
          <item>
            <para>Arrays are 0-based;</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Array storage</tableterm><indexterm index="cp">array storage</indexterm>
          <item>
            <para>Last dimension is most rapidly varying;</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Assignment statements</tableterm><indexterm index="cp">assignment statement</indexterm><indexterm index="cp">semi-colon</indexterm><indexterm index="cp"><code>;</code> (end of statement)</indexterm>
          <item>
            <para>A semi<!-- /@w -->-colon <samp>;</samp> indicates the end of an assignment statement.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Comments</tableterm><indexterm index="cp">comments</indexterm><indexterm index="cp"><code>/*...*/</code> (comment)</indexterm><indexterm index="cp"><code>//</code> (comment)</indexterm>
          <item>
            <para>Multi-line comments are enclosed within <code>/* */</code> characters. Single line comments are preceded by <code>//</code> characters.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Nesting</tableterm><indexterm index="cp">including files</indexterm><indexterm index="cp">nesting</indexterm><indexterm index="cp"><code>#include</code></indexterm>
          <item>
            <para>Files may be nested in scripts using <code>#include <var>script</var></code>. Note that 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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Attribute syntax</tableterm><indexterm index="cp">attribute syntax</indexterm><indexterm index="cp"><code>@</code> (attribute)</indexterm>
          <item>
            <para>The at-sign <code>@</code> is used to delineate an attribute name from a variable name.</para>
          </item>
        </tableitem>
      </table>
    </subsection>
  </node>
  <node>
    <nodename>Expressions</nodename>
    <nodenext>Dimensions</nodenext>
    <nodeprev>Syntax of ncap2 statements</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <para><indexterm index="cp">expressions</indexterm></para>
    <subsection>
      <title>Expressions</title>
      <para>Expressions are the fundamental building block of <command>ncap2</command>. Expressions are composed of variables, numbers, literals, and attributes. <indexterm index="cp">C language</indexterm>The following C operators<!-- /@w --> are &ldquo;overloaded&rdquo; and work with scalars and multi-dimensional arrays:</para>
      <example 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:     = += -= /= *=</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 'op' var2</emph></para>
      <para><strong>Precision</strong></para>
      <itemize>
        <itemfunction>&bullet;</itemfunction>
        <item>
          <para>When both operands are variables, the result has the precision of the higher precision operand</para>
        </item>
        <item>
          <para>When one operand is a variable and the other an attribute, the result has the precision of the variable.</para>
        </item>
        <item>
          <para>When both operands are attributes, the result has the precision of the more precise attribute.</para>
        </item>
        <item>
          <para>The exponentiation operator &ldquo;^&rdquo; 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>
        </item>
      </itemize>
<!-- csz got to here editing -->
      <para><strong>Rank</strong></para>
      <itemize>
        <itemfunction>&bullet;</itemfunction>	
        <item>
          <para>The Rank of the result is generally equal to Rank of the operand that has the greatest number of dimensions.</para>
        </item>
        <item>
          <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>
        </item>
        <item>
          <para>Broadcasting a variable means creating data in non-existing dimensions from the data in existing dimensions.</para>
       
        </item>
        <item>
          <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>
        
        </item>
      </itemize>
      <para role="continues">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;</para>
      <para>examples:</para>
      <example xml:space="preserve">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</example>
      <para role="continues"><strong>Binary Operators</strong> &linebreak; <indexterm index="cp">binary Operators</indexterm>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 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
----------------------------
</example>
      <para>To see all operators: see <xref><xrefnodename>Operators precedence and associativity</xrefnodename></xref></para>
      <para>examples:</para>
      <example xml:space="preserve">tm1= time&gt;2 &amp;&amp; time &lt;7;  // tm1 = 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 ; type double;
tm2= time==3 || time&gt;=6; // tm2 = 0, 0, 1, 0, 0, 1, 1, 1, 1, 1 ; type double
tm3= int(!tm1);          // tm3=  1, 1, 0, 0, 0, 0, 1, 1, 1, 1 ; type int
tm4= tm1 &amp;&amp; tm2;         // tm4=  0, 0, 1, 0, 0, 1, 0, 0, 0, 0 ; type double;
tm5= !tm4;               // tm5=  1, 1, 0, 1, 1, 0, 1, 1, 1, 1 ; type double;
</example>
      <para role="continues"><strong>Regular Assign Operator</strong> &linebreak; <emph>var1 '=' exp1</emph> &linebreak; If var1 doesn't already exist in Output then var1 is written to Output with the values and dimensions from expr1. If var1 already exists in Output, then the only requirement on expr1 is that the number of elements must match the number already on disk. The type of expr1 is converted if necessary to the disk type.</para>
      <para role="continues"><strong> Other Assign Operators +=,-=,*=./= </strong> &linebreak;         <emph>var1 'ass_op' exp1 </emph>&linebreak; if exp1 is a variable and it doesn'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>
      <para role="continues">example:</para>
      <example 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</example>
      <para role="continues"><strong>Increment/ Decrement Operators &linebreak; </strong> These work in a similar fashion to their regular C counterparts. If say the variable "four" is input only then the statement "++four" effectively means -read four from input increment each element by one , then write the new values to Output;</para>
      <para>example:</para>
      <example 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.;</example>
      <para role="continues"><strong>Conditional Operator ?: </strong> &linebreak; <indexterm index="cp">conditional Operator</indexterm><emph>exp1 ? exp2 : exp3 </emph> &linebreak; The conditional operator ( or ternary Operator) is nice and succinct way of writing an if/then/else. If exp1 evaluates to true then exp2 is returned else exp3 is returned.</para>
      <para role="continues">example</para>
      <example xml:space="preserve">weight_avg= weight.avg();
weight_avg@units= (weight_avg ==1 ? "kilo" : "kilos");

PS_nw= PS - (PS.min() &gt;100000 ? 100000 : 0 );</example>
      <para role="continues"><strong>Clipping Operators</strong> <indexterm index="cp">clipping operators</indexterm></para>
      <table>
        <tableitem>
          <tableterm>&lt;&lt; Less Than Selection &linebreak;</tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>&gt;&gt; Greater Than Selection &linebreak;</tableterm>
          <item>
            <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>
          </item>
        </tableitem>
      </table>
      <para>example:&linebreak;</para>
      <example xml:space="preserve">
RDM2= RDM &gt;&gt;100.0;   RDM2=100,100,100,100,126,126,100,100,100, 100 ;  // type double
RDM2= RDM &lt;&lt;90s;     RDM3=1, 9, 36, 84, 90, 90, 84, 36, 9, 1 ;        // type int
</example>
    </subsection>
  </node>
  <node>
    <nodename>Dimensions</nodename>
    <nodenext>Left hand casting</nodenext>
    <nodeprev>Expressions</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Dimensions</title>
      <para><indexterm index="cp">dimensions<command>ncap</command></indexterm><indexterm index="cp">defdim()</indexterm>Dimensions can be defined in Output using the <code>defdim()</code> function.</para>
      <example xml:space="preserve">defdim("cnt",10);</example>
      <para>This dimension can then be subsequently referred to in method  arguments and a left hand cast by prefixing it with a dollar e.g</para>
      <example xml:space="preserve">new_var[$cnt]=time;
temperature[$time,$lat,$lon]=35.5;
temp_avg=temperature.avg($time);</example>
      <para>To refer to the dimension size in an expression use the <code>size</code> method.</para>
      <example xml:space="preserve">time_avg=time.total() / $time.size;</example>
      <para>Increase size of new var by one and set new member to zero;</para>
      <example xml:space="preserve">defdim("cnt_grw", $cnt.size+1);
new_var_grw[$cnt_grw]=0.0;
new_var_grw( 0:($cnt_grw.size-2))=new_var;</example>
      <para role="continues"><strong>Dimension Abbreviations &linebreak;</strong> Its possible to use dimension abbreviations as method arguments. &linebreak; <code>$0</code> is the first dimension of the variable &linebreak; <code>$1</code> is the second dimension of the variable &linebreak; <code>$n</code> is the n+1 dimension of the variable &linebreak;</para>
      <para role="continues">consider the variables:&linebreak;</para>
      <example 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);</example>
      <para role="continues"><strong>ID Quoting &linebreak;</strong> If the dim name contains non-regular characters use ID quoting. See see <xref><xrefnodename>ID Quoting</xrefnodename></xref></para>
      <example xml:space="preserve">defdim("a--list.A",10);
A1['$a--list.A']=30.0;</example>
      <para role="continues"><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>
    </subsection>
  </node>
  <node>
    <nodename>Left hand casting</nodename>
    <nodenext>Arrays and hyperslabs</nodenext>
    <nodeprev>Dimensions</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Left hand casting</title>
      <para role="continues"><indexterm index="cp">hybrid coordinate system</indexterm><indexterm index="cp">left hand casting</indexterm><indexterm index="cp"><acronym><acronymword>LHS</acronymword></acronym></indexterm>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 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</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>
      <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 xml:space="preserve">ncap2 -s 'prs_mdp[time,lat,lon,lev]=P0*hyam+PS*hybm' in.nc out.nc</example>
      <para>Manipulating the four fields which define the pressure in a hybrid coordinate system is easy with left hand casting.</para>
    </subsection>
  </node>
  <node>
    <nodename>Arrays and hyperslabs</nodename>
    <nodenext>Attributes</nodenext>
    <nodeprev>Left hand casting</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Arrays and hyperslabs</title>
      <para><indexterm index="cp">hyperslabs</indexterm>Hyperslabs in <command>ncap2</command> are a bit more limited than  hyperslabs with the other nco operators. There is no per-se multi-slabs, wrapped co-ordinates, negative stride or co-ordinate value limits. However with a bit of syntactic magic they are all are possible.</para>
      <example xml:space="preserve">  var1( hyper_arg1, hyper_arg2 .. hyper_argN)</example>
      <para role="continues">A hyperslab argument is specified using the following notation</para>
      <example xml:space="preserve">start:end:stride</example>
      <para role="continues">if "start" is omitted - then default = 0 &linebreak; if "end" is omitted - default = dimension size less one &linebreak; if "stride" is omitted - default = 1</para>
      <sp lines="1"></sp>
      <para role="continues">If a single value is present then it is assumed that that dimension collapses to a single value (ie a cross-section). The number of hyperslab arguments MUST be equal to the number of dimensions of the variable.</para>
      <sp lines="1"></sp>
      <para role="continues"><strong>Hyperslabs on the Right Hand Side of an assign&linebreak;</strong></para>
      <para>A simple 1D example:</para>
      <example xml:space="preserve">($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</example>
      <para>A more complex 3D example</para>
      <example xml:space="preserve">($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 ;
</example>
      <para>If any of the 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</para>
      <para>So for example: the following is valid:</para>
      <example xml:space="preserve">th_nw=th(0,:,:) +th(9,:,:);
th_nw  has dimensions $lon,$lat
nb the time dim has become degenerate</example>
      <para>The following is not valid:</para>
      <example xml:space="preserve">th_nw=th(0,:,0:1) +th(9,:,0:1);</example>
      <para>As the <emph>$lon</emph> now only has two elements. The above can be calculated by using a LHS cast with <emph>$lon_nw</emph> as replacement dim for <emph>$lon</emph>.</para>
      <example xml:space="preserve">defdim("lon_nw",2);
th_nw[$lat,$lon_nw]=th(0,:,0:1) +th(9,:,0:1);</example>
      <para role="continues"><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</para>
      <para role="continues">Sets all elements of the last record to zero.</para>
      <example xml:space="preserve">th(9,:,:)=0.0;</example>
      <para>Set first element of each lon element to 1.0.</para>
      <example xml:space="preserve">th(:,:,0)=1.0;</example>
      <para>Can hyperslab on both sides of an assign.&linebreak; Sets the last record to the same as the first record &linebreak;</para>
      <example xml:space="preserve">th(9,:,:)=th(0,:,:);</example>
      <para>th0 represents pressure at height=0 &linebreak; th1 represents pressure at height=1 &linebreak; Then its possible to hyperslab in the records &linebreak;</para>
      <example xml:space="preserve">P[$time,$height,$lat,$lon]=0.0;
P(:,0,:,:)=th0;
P(:,1,:,:)=th1</example>
      <para role="continues"><strong>Reverse method</strong> &linebreak; <indexterm index="cp">reverse()</indexterm>If you want to reverse a dimension's elements in an variable use the <code>reverse()</code> method with at least one dimension argument (this is equivalent to applying a negative stride) e.g</para>
      <example xml:space="preserve">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 }</example>
      <para role="continues"><strong>Permute method</strong> &linebreak; <indexterm index="cp">permute()</indexterm>If you want to swap about the dimensions of a variable use the the <code>permute()</code> method. 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 consider using <command>ncpdq</command> .</para>
      <para>Consider the variable:</para>
      <example xml:space="preserve">float three_dmn_var(lat,lev,lon);

three_dmn_var_pm=three_dmn_var.permute($lon,$lat,$lev);

three_dmn_var_pm=
  0,4,8,
  12,16,20,
  1,5,9,
  13,17,21,
  2,6,10,
  14,18,22,
  3,7,11,
  15,19,23;
</example>
    </subsection>
  </node>
  <node>
    <nodename>Attributes</nodename>
    <nodenext>Number literals</nodenext>
    <nodeprev>Arrays and hyperslabs</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Attributes</title>
      <para><indexterm index="cp">attributes<command>ncap</command></indexterm>Attributes are referred to by <emph>var_nm@att_nm</emph> &linebreak; All the following are valid statements</para>
      <example xml:space="preserve">global@text="Test Attributes";  /* Assign a global variable attribute */
a1[$time]=time*20;
a1@long_name="Kelvin";
a1@min=a1.min();
a1@max=a1.max();
a1@min++;
--a1@max; q
a1(0)=a1@min;
a1($time.size-1)=a1@max;
</example>
      <para role="continues">A <emph>value list</emph> can be used on the RHS of an assign... <indexterm index="cp">value list</indexterm></para>
      <example xml:space="preserve">a1@trip1={ 1,2,3 } ;
a1@triplet={ a1@min, (a1@min+a1@max)/2, a1@max };</example>
      <para>The netcdf specification allows all attribute types to have a size greater than one. The maximum is defined by <code>NC_MAX_ATTRS</code> -The following is an ncdump of the meta-data for variable a1</para>
      <example xml:space="preserve">double a1(time) ;
  a1:long_name = "Kelvin" ;
  a1:max = 199. ;
  a1:min = 21. ;
  a1:trip1 = 1, 2, 3 ;
  a1:triplet = 21., 110., 199. ;</example>
      <para>The <code>size()</code> method can be used with attributes -for example to save an attribute text string in a variable..</para>
      <example xml:space="preserve">defdim("sng_len", a1@long_name.size());
sng_arr[$sng_len]=a1@long_name;         // sng_arr now contains "Kelvin"</example>
      <para>Attributes defined in a script are stored in memory and are written to Output after script completion. To stop the attribute being  written use the ram_delete() method or use a bogus variable name</para>
      <para role="continues"><strong>Attribute Propagation &amp; Inheritance</strong> <indexterm index="cp">attribute propagation</indexterm><indexterm index="cp">attribute inheritance</indexterm></para>
      <itemize>
        <itemfunction>&bullet;</itemfunction>  
        <item>
          <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>
  
        </item>
        <item>
          <para>Attribute Inheritance: The LHS variable "inherits" attributes from an Input variable with the same name</para>
  
        </item>
        <item>
          <para>It is possible to have a regular assign statement for which both propagation and inheritance occur.</para>
        </item>
      </itemize>
      <example xml:space="preserve">prs_mdp[time,lat,lon,lev]=P0*hyam+hybm*PS;      //prs_mdp get attributes from PO
th_min=1.0 + 2*three_dmn_var_dbl.min($time);    //th_min get attributes from three_dmn_var_dbl</example>
      <para>If the attribute name contains non-regular characters use ID quoting. See see <xref><xrefnodename>ID Quoting</xrefnodename></xref></para>
      <example xml:space="preserve">'b..m1@c--lost'=23;</example>
    </subsection>
  </node>
  <node>
    <nodename>Number literals</nodename>
    <nodenext>if statement</nodenext>
    <nodeprev>Attributes</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Number literals</title>
      <para><indexterm index="cp">number literals <command>ncap</command></indexterm>The table below lists the postfix character(s) to add to a number literal for type cohesion. To use the new netcdf4 types nco must be compiled/linked to the netcdf4 library and the Output file must be hdf5.</para>
      <example xml:space="preserve">n1[$time]=1UL;   // n1 will now by type <code>NC_UINT</code>
n2[$lon]=4b;     // n2 will be of type <code>NC_BYTE</code>
n3[$lat]=5ull;   // n3 will be of type <code>NC_UINT64</code>
n3@a1=6.0d;      // attribute will be type <code>NC_DOUBLE</code>
n3@a2=-666L;     // attribute will be type <code>NC_INT</code></example>
      <para>A floating point number without a postfix will default to <code>NC_DOUBLE</code>. An integer without a postfix will default to type <code>NC_INT</code>. Thre is no postfix for characters. Use a quoted string.</para>
      <example xml:space="preserve">n4[$rlev]=.1      // n4 will be of type <code>NC_DOUBLE</code>
n5[$lon_grd]=2.   // n5 will be of type <code>NC_DOUBLE</code>
n6[$gds_crd]=2e3; // n6 will be of type <code>NC_DOUBLE</code>
n6@a1=41;         // attribute will be type <code>NC_INT</code>
n6@a2=-21;        // attribute will be type <code>NC_INT</code>
n6@units="kelvin" // attribute will be type <code>NC_CHAR</code></example>
      <table>
        <tableitem>
          <tableterm></tableterm>
          <item>
            <para><strong>netCDF3/4 Types</strong></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>b|B</tableterm>
          <item>
  
            <para><code>NC_BYTE</code>  a signed 1 byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>none</tableterm>
          <item>
  
            <para><code>NC_CHAR</code>  a ISO/ASCII character</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>s|S</tableterm>
          <item>
  
            <para><code>NC_SHORT</code> a signed 2 byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>l|L</tableterm>
          <item>
  
            <para><code>NC_INT</code>   a signed 4 byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>f|F</tableterm>
          <item>
  
            <para><code>NC_FLOAT</code> a single precision floating point number</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>d|D</tableterm>
          <item>
  
            <para><code>NC_DOUBLE</code> a double precision floating point number</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm></tableterm>
          <tableterm></tableterm>
          <item>
            <para><strong>netCDF4 Types</strong></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>ub|UB</tableterm>
          <item>
  
            <para><code>NC_UBYTE</code> a unsigned 1 byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>us|US</tableterm>
          <item>
  
            <para><code>NC_USHORT</code> a unsigned 2-byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>u|U|ul|UL</tableterm>
          <item>
  
            <para><code>NC_UINT</code> a unsigned 4-byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>ll|LL</tableterm>
          <item>
  
            <para><code>NC_INT64</code> a signed 8-byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>ull|ULL</tableterm>
          <item>
  
            <para><code>NC_UINT64</code> a unsigned 8-byte int</para>
          </item>
        </tableitem>
      </table>
    </subsection>
  </node>
  <node>
    <nodename>if statement</nodename>
    <nodenext>print statement</nodenext>
    <nodeprev>Number literals</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>if statement</title>
      <para><indexterm index="cp">if()</indexterm>The synatax of the if statement is similar to its C counterpart. The <emph>Conditional Operator (ternary operator)</emph> has also been implemented.</para>
      <example xml:space="preserve">
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;
}</example>
      <para role="continues">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. Unlike C there is no short-circuiting of an expression with the OR (||) AND (&amp;&amp;) operators. The whole expression is evaluated regardless if one of the AND/OR operands are true/false.</para>
      <example xml:space="preserve">A simple example

if(time&gt;0)
  print("All values of time are greater than zero\n");
else if( time&lt;0)
  print("All values of time are less than zero\n");
else {
  time_max=time.max();
  time_min=time.min();
  print("min value of time=");print(time_min,"%f");
  print("max value of time=");print(time_max,"%f");
}

A real 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; /* [nbr] Averaging 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; /* [nbr] Averaging block size */
    lmn_nbr_wgt=dmnsz_stl_lat; /* [nbr] Weight size */
  } // !nco_op_typ_avg
} // !fl_typ</example>
      <para role="continues"><strong>Conditional Operator &linebreak;</strong></para>
      <example xml:space="preserve">// nb you need netCDF4 to run this example
th_nw=(three_dmn_var_sht &gt;= 0 ? three_dmn_var_sht.uint(): three_dmn_var_sht.int() );
</example>
    </subsection>
  </node>
  <node>
    <nodename>print statement</nodename>
    <nodenext>Missing values ncap2</nodenext>
    <nodeprev>if statement</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>print statement</title>
      <para><indexterm index="cp">print()<command>ncap</command></indexterm></para>
      <example xml:space="preserve">print( variable_name/attribute name/string, format string);</example>
      <para role="continues">The print function takes a variable name or attribute name or a quoted string and prints the contents in a in a similar fashion to <code>ncks -H </code>. There is also an optional C style format string argument. Currently the print function can't print RAM variables or expressions e.g <code>'print(var_msk*3+4)'</code> is invalid. So if you want to print an expression first assign a variable with the expression; then print the variable.</para>
      <para role="continues">examples</para>
      <example xml:space="preserve">print(lon);
lon[0]=0
lon[1]=90
lon[2]=180
lon[3]=270

print(lon_2D_rrg,"%3.2f,");
0.00,0.00,180.00,0.00,180.00,0.00,180.00,0.00,

print(mss_val_fst@_FillValue);
mss_val_fst@_FillValue, size = 1 NC_FLOAT, value = -999

print("This function \t is monotonic\n");
This function is 	  monotonic
</example>
    </subsection>
  </node>
  <node>
    <nodename>Missing values ncap2</nodename>
    <nodenext>Methods and functions</nodenext>
    <nodeprev>print statement</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Missing values ncap2</title>
      <para><indexterm index="cp">missing values ncap2</indexterm>Missing values operate slightly differently in <command>ncap2</command> Consider the expression where op is any of the following operators (excluding '=')</para>
      <example xml:space="preserve">Arithmetic operators ( * / % + - ^ )
Binary Operators     ( &gt;, &gt;= &lt;, &lt;= ==, !=,==,||,&amp;&amp;, &gt;&gt;,&lt;&lt; )
Assign Operators     ( +=,-=,/=, *= )

var1 'op' var2
</example>
      <para role="continues">if var1 has a missing value then this is the value used in the operation else 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 'percolate' 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 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;</example>
      <para>The following methods are used to edit the missing value associated with a variable. They only work on variables in Output.</para>
      <table>
        <tableitem>
          <tableterm><code>set_miss(expr)</code></tableterm><indexterm index="cp">set_miss()</indexterm>
          <item>
 
            <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</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>change_miss(expr)</code></tableterm><indexterm index="cp">change_miss()</indexterm>
          <item>
 
            <para>Changes the missing value elements of the variable to the new missing value (nb an expensive function).</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>get_miss()</code></tableterm><indexterm index="cp">get_miss()</indexterm>
          <item>
 
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>delete_miss()</code></tableterm><indexterm index="cp">delete_miss()</indexterm>
          <item>
 
            <para>Deletes the missing value associated with a variable.</para>
          </item>
        </tableitem>
      </table>
      <example xml:space="preserve">
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 only elements divisible by 3 */
where ( three_dmn_var_dbl%3 == 0 )
     new=three_dmn_var_dbl;
elsewhere
     new=new.get_miss();

</example>
    </subsection>
  </node>
  <node>
    <nodename>Methods and functions</nodename>
    <nodenext>RAM variables</nodenext>
    <nodeprev>Missing values ncap2</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Methods and functions</title>
      <para>Within this document when I refer to a method I mean a method that can also be  a function. If I refer to something as function then this function cannot be a method. The nice thing with methods is that they can be daisy changed together and their synatax is cleaner than functions. The method names are reserved words and CANNOT be used as variable names. To see the complete list of methods available on you build use the command <code>ncap2 -f</code>.</para>
      <example xml:space="preserve">n2=sin(theta) or n2=theta.sin()

n2=sin(theta)^2 +cos(theta)^2 or  n2=theta.sin().pow(2) + theta.cos()^2</example>
      <para>The below statement converts three_dmn_var_sht to type double, finds the average, then converts this average back to type short.</para>
      <example xml:space="preserve">three_avg=three_dmn_var_sht.double().avg().short();</example>
      <sp lines="1"></sp>
      <para role="continues"><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>
        <tableitem>
          <tableterm><code>avg()</code></tableterm><indexterm index="cp">avg()</indexterm>
          <item>
            <para role="continues">Mean value</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>sqravg()</code></tableterm><indexterm index="cp">sqravg()</indexterm>
          <item>
            <para>Square of the mean</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>avgsqr()</code></tableterm>
          <item>
            <para>Mean of sum of squares</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>max()</code></tableterm><indexterm index="cp">max()</indexterm>
          <item>
            <para>Maximum value</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>min()</code></tableterm><indexterm index="cp">min()</indexterm>
          <item>
            <para>Minimum value</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>rms()</code></tableterm>
          <item>
            <para>Root-mean-square (normalized by <var>N</var>)</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>rmssdn()</code></tableterm><indexterm index="cp">rmssdn()</indexterm>
          <item>
            <para>Root-mean square (normalized by <var>N-1</var>)</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ttl() or total()</code></tableterm><indexterm index="cp">ttl()</indexterm>
          <item>
            <para>Sum of values</para>
          </item>
        </tableitem>
      </table>
      <example xml:space="preserve">// Average a variable over time
four_time_avg=four_dmn_rec_var($time);</example>
      <sp lines="1"></sp>
      <para role="continues"><strong> Packing Methods &linebreak; </strong> For more information see see <xref><xrefnodename>Packed data</xrefnodename></xref> and see <xref><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></xref> &linebreak;</para>
      <table>
        <tableitem>
          <tableterm><code>pack() &amp; pack_short()</code></tableterm><indexterm index="cp">pack()</indexterm>
          <item>
            <para>The default packing algorithm is applied and variable is packed to <code>NC_SHORT</code></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>pack_byte()</code></tableterm><indexterm index="cp">pack_byte()</indexterm>
          <item>
            <para>Variable is packed to <code>NC_BYTE</code></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>pack_short()</code></tableterm><indexterm index="cp">pack_short()</indexterm>
          <item>
            <para>Variable is packed to <code>NC_SHORT</code></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>pack_int()</code></tableterm><indexterm index="cp">pack_int()</indexterm>
          <item>
            <para>Variable is packed to <code>NC_INT</code></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>unpack()</code></tableterm><indexterm index="cp">unpack()</indexterm>
          <item>
            <para>The standard unpacking algorithm is applied.</para>
          </item>
        </tableitem>
      </table>
      <para role="continues"><strong>Basic Methods &linebreak;</strong> These methods work with variables and attributes. They have no arguments</para>
      <table>
        <tableitem>
          <tableterm><code>size()</code></tableterm><indexterm index="cp">size()</indexterm>
          <item>
            <para>Total number of elements</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ndims()</code></tableterm><indexterm index="cp">ndims()</indexterm>
          <item>
            <para>Number of dimensions in variable</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>type()</code></tableterm><indexterm index="cp">type()</indexterm>
          <item>
            <para>Returns the netcdf type (see previous section)</para>
          </item>
        </tableitem>
      </table>
      <sp lines="1"></sp>
      <para role="continues"><strong>Utility Methods &linebreak;</strong> These functions are used to manipulate missing values and RAM variables. see <xref><xrefnodename>Missing values ncap2</xrefnodename></xref></para>
      <table>
        <tableitem>
          <tableterm><code>set_miss(expr)</code></tableterm>
          <item>
 
            <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</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>change_miss(expr)</code></tableterm>
          <item>
 
            <para>Changes the missing value elements of the variable to the new missing value (n.b. an expensive function).</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>get_miss()</code></tableterm>
          <item>
 
            <para>Returns the missing value of a variable in Input or Output</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>delete_miss()</code></tableterm>
          <item>
 
            <para>Deletes the missing value associated with a variable.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ram_write()</code></tableterm>
          <item>
 
            <para>Writes a RAM variable to disk i.e. converts it to a regular disk type variable</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ram_delete()</code></tableterm>
          <item>
 
            <para>Deletes a RAM variable or an attribute</para>
          </item>
        </tableitem>
      </table>
      <sp lines="1"></sp>
      <para role="continues"><strong>PDQ Methods &linebreak;</strong> See see <xref><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></xref></para>
      <table>
        <tableitem>
          <tableterm><code>reverse(dim args)</code></tableterm>
          <item>
 
            <para>Reverses the dimension ordering of elements in a variable.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>permute(dim args)</code></tableterm>
          <item>
 
            <para>Re-shapes variables by re-ordering the dimensions. All the dims of the variable must be specified in the arguments. A limitation of this permute (unlike ncpdq) is that the record dimension cannot be re-assigned.</para>
          </item>
        </tableitem>
      </table>
      <para>// Swap dimensions about and reorder along lon</para>
      <example 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</example>
      <sp lines="1"></sp>
      <para role="continues"><strong>Type Conversion Methods &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 (see <xref><xrefnodename>Type Conversion</xrefnodename></xref>). You can only use the new netcdf4 types if you have compiled/links nco with the netcdf4 library and the Output file is hdf5.</para>
      <table>
        <tableitem>
          <tableterm><code></code></tableterm>
          <item>
            <para role="continues"><strong>netCDF3/4 Types</strong></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>byte()</code></tableterm><indexterm index="cp">byte()</indexterm>
          <item>
 
            <para>convert to <code>NC_BYTE</code>  a signed 1 byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>char()</code></tableterm><indexterm index="cp">char()</indexterm>
          <item>
 
            <para>convert to <code>NC_CHAR</code>  a ISO/ASCII character</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>short()</code></tableterm><indexterm index="cp">sshort()</indexterm>
          <item>
 
            <para>convert to <code>NC_SHORT</code> a signed 2 byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>int()</code></tableterm><indexterm index="cp">int()</indexterm>
          <item>
 
            <para>convert to <code>NC_INT</code>   a signed 4 byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>float()</code></tableterm><indexterm index="cp">float()</indexterm>
          <item>
 
            <para>convert to <code>NC_FLOAT</code> a single precision floating point number</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>double()</code></tableterm><indexterm index="cp">double()</indexterm>
          <item>
 
            <para>convert to <code>NC_DOUBLE</code> a double precision floating point number</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code></code></tableterm>
          <tableterm><code></code></tableterm>
          <item>
            <para><strong>netCDF4 Types</strong></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ubyte()</code></tableterm><indexterm index="cp">ubyte()</indexterm>
          <item>
 
            <para>convert to <code>NC_UBYTE</code> a unsigned 1 byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ushort()</code></tableterm><indexterm index="cp">ushort()</indexterm>
          <item>
 
            <para>convert to <code>NC_USHORT</code> a unsigned 2-byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>uint()</code></tableterm><indexterm index="cp">uint()</indexterm>
          <item>
 
            <para>convert to <code>NC_UINT</code> a unsigned 4-byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>int64()</code></tableterm><indexterm index="cp">int64()</indexterm>
          <item>
 
            <para>convert to <code>NC_INT64</code> a signed 8-byte int</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>uint64()</code></tableterm><indexterm index="cp">unit64()</indexterm>
          <item>
 
            <para>convert to <code>NC_UINT64</code> a unsigned 8-byte int *</para>
          </item>
        </tableitem>
      </table>
      <para role="continues"><strong>Intrinsic Mathematical Methods &linebreak;</strong> The list of mathematical methods is system dependant. For the full list see <xref><xrefnodename>Intrinsic mathematical methods</xrefnodename></xref></para>
      <para>All the mathematical methods take a single operand ,with the exception of <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>. If the operand is type <emph>double</emph> then the result will be type <emph>double</emph>. Like the other methods, you are free to use the mathematical methods as functions.</para>
      <example 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</example>
    </subsection>
  </node>
  <node>
    <nodename>RAM variables</nodename>
    <nodenext>Where statement</nodenext>
    <nodeprev>Methods and functions</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>RAM variables</title>
      <para>RAM variables are used in place of regular variables to speed things up. For example in a loop or where a variable is very frequently referenced. To declare and define a RAM variable simply prefix the variable name with * when the variable is declared/initialized.&linebreak; <indexterm index="cp">ram_write()</indexterm><indexterm index="cp">ram_delete()</indexterm>To delete a RAM variable (recover some memory) use  the ram_delete() method. To convert a RAM variable to a regular disk variable in output use ram_write() method.&linebreak;</para>
      <para>The following is valid:</para>
      <example 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
</example>
      <para>Other Assigns</para>
      <example xml:space="preserve">// Create a RAM variable from the variable "one" in Input and increment its elements
*one++;

// Create a RAM variable from the variable three in Input and multiply its contents by 10
// Create a RAM variable from the variable four in Input and then add the variable "three" to
// its contents.
*four+=*three*=10;   // three=30, four=34
</example>
    </subsection>
  </node>
  <node>
    <nodename>Where statement</nodename>
    <nodenext>Loops</nodenext>
    <nodeprev>RAM variables</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Where statement</title>
      <para><indexterm index="cp">where()</indexterm>A <code>where()</code> combines the definition and application of a mask all in one go and can lead to succinct code. The full syntax of a <code>where()</code> statement is as follows:</para>
      <example xml:space="preserve">// Single assign (nb the else block is optional)
where (mask)
   var1=expr1;
elsewhere
   var1=expr2;


// Multiple assigns
where( mask) {
    var1=expr1;
    var2=expr2;
    ...
    } elsewhere {
    var1=expr3
    var2=expr4
    var3=expr5;
    ...
    }
</example>
      <itemize>
        <itemfunction>&bullet;</itemfunction>
        <item>
          <para>The only expression allowed within a where is the assign 'var=expr'. This is different from a regular <command>ncap2</command> assign. The LHS var must already exist in Input or Output. The expression on the RHS must evaluate to a scalar or a variable/attribute of the same size as the LHS variable.</para>
        </item>
        <item>
          <para>Taking the general case of a variable on the LHS side and RHS. For every element of the mask which is True , the corresponding LHS variable element  is re-assigned with its partner element on the RHS. In the elsewhere part the mask is logically inverted and the assign process continues</para>
        </item>
        <item>
          <para>if the mask dimensions are a subset of the LHS variable's dimensions , then it is made to conform; if it  can't be made to conform then script execution halts.</para>
        </item>
        <item>
          <para>Missing values in the mask evaluate to False in the  first code/block statement and True in the elsewhere block/statement. LHS variable elements set to missing value are not re-assigned</para>
        </item>
      </itemize>
      <para>example:</para>
      <para>Consider the variables:&linebreak; <code>float lon_2D_rct(lat,lon);&linebreak;</code> <code>float var_msk(lat,lon);&linebreak;</code> Suppose we want to multiply by two the elements for which var_msk is equal to 1;</para>
      <example xml:space="preserve">where(var_msk==1)
  lon_2D_rct=2*lon_2D_rct;</example>
      <para>Another example &linebreak; Suppose we have the variable&linebreak; <code>int RDM(time);</code> &linebreak; And we want to set the values less than 8 or greater than 80 to 0.</para>
      <example xml:space="preserve">where(RDM &lt;8 || RDM &gt;80)
  RDM=0;</example>
      <para role="continues">A more complex example.&linebreak; Consider the situation where we have irregularly gridded data, described using rank 2 variables:&linebreak;</para>
      <para role="continues"><code> double lat(south_north,east_west)&linebreak; double lon(south_north,east_west)&linebreak; double temperature(south_north,east west)&linebreak; </code></para>
      <para role="continues">To find the average temperature in a region [lat_min,lat_max] and [lon_min,lon_max]:</para>
      <example xml:space="preserve">
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; &gt; lon &lt;= lon_max)
  temperature_msk=temperature;
elsewhere
  temperature_msk=temperature@_FillValue;

temp_avg=temperature_msk.avg();
temp_max=temperature.max();
</example>
    </subsection>
  </node>
  <node>
    <nodename>Loops</nodename>
    <nodenext>Include files</nodenext>
    <nodeprev>Where statement</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Loops</title>
      <para><indexterm index="cp">while()</indexterm><indexterm index="cp">for()</indexterm>In <command>ncap</command> there are for() loops and while() loops. They are currently completely unoptimized So use them with  RAM variables unless you want thrash your disk to death. To break out of a loop use "break" command. To iterate to the next cycle use the "continue" command.</para>
      <example xml:space="preserve">// Follwing sets 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;

// See if values of of a co-ordinate variable double lat(lat) are 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("lat co-ordinate is monotonic\n");
   else
     print("lat co-ordinate is NOT monotonic\n");

// 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("Total of odd elements ");print(sum);print("\n");
</example>
    </subsection>
  </node>
  <node>
    <nodename>Include files</nodename>
    <nodenext>Irregular grids</nodenext>
    <nodeprev>Loops</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Include files</title>
      <para><indexterm index="cp">include ncap</indexterm>The synatax of an include file is:</para>
      <example xml:space="preserve">#include "script"</example>
      <para role="continues">The script filename is searched relative to the run directory. Its possible to nest include files to an arbitrary depth. A handy use of inlcude files is to store often used constants. Use RAM variables of you don't want these constants written to Output.</para>
      <example xml:space="preserve">*pi=3.1415926535;
*h=6.62607095e-34;
e=2.71828;</example>
    </subsection>
  </node>
  <node>
    <nodename>Irregular grids</nodename>
    <nodenext>GSL special functions</nodenext>
    <nodeprev>Include files</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Irregular Grids</title>
      <para><indexterm index="cp">irregular grids</indexterm><indexterm index="cp">rectangular grids</indexterm><indexterm index="cp">non-rectangular grids</indexterm><indexterm index="cp">non-standard grids</indexterm><indexterm index="cp">mask</indexterm>
<!-- fxm need to edit rrg sxn beginning here --><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: rectangularity, regularity, and fxm.</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 (4 degrees<!-- /@w -->) are constant as are the (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>Wrapped coordinates (see <xref><xrefnodename>Wrapped Coordinates</xrefnodename></xref>), such as longitude, are independent of these grid properties (regularity, rectangularity).</para>
      <para><indexterm index="cp">wrapped coordinates</indexterm>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 WRF (Weather and Research Forecast) 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 "staggered grids" 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>Let's demonstrate the recommended <command>ncap2</command> analysis technique by constructing a region 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 xml:space="preserve">ncap2 -s 'mask= (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</example>
      <para>Once you have a mask, you can use it on specific variables:</para>
      <example xml:space="preserve">ncap2 -s 'temperature_avg=(temperature*mask).avg()' in.nc out.nc</example>
      <para>and you can apply it to entire files:</para>
      <example xml:space="preserve">ncwa -a lat,lon -m mask -w area in.nc out.nc</example>
      <para>You can put this altogether on the command line or in a script, e.g., cleaner.</para>
      <example xml:space="preserve">cat &gt; ncap2.in &lt;&lt; EOF
mask = (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.total() &gt; 0){ // Check that mask contains some valid values
  temperature_avg=(temperature*mask).avg(); // Average temperature
  temperature_max=(temperature*mask).max(); // Maximum temperature
}
EOF
ncap2 -S ncap2.in in.nc out.nc</example>
      <para>For the WRF file creating the mask looks like</para>
      <example xml:space="preserve">mask = (XLAT &gt;= lat_min &amp;&amp; XLAT &lt;= lat_max) &amp;&amp; (XLONG &gt;= lon_min &amp;&amp; &gt; XLONG &lt;= lon_max);</example>
      <para>In practice with WRF it's a bit more complicated because you must use the global metadata to determine the grid staggering and offsets to translate XLAT and XLONG into real latitudes and longitudes and missing points. The WRF grid documentation should describe this.</para>
      <para>A few notes: Irregular regions are the union of arrays lat/lon_min/max's. The mask procedure is identical for all <var>R</var>. 
<!-- fxm need to edit rrg sxn down to here --></para>
    </subsection>
  </node>
  <node>
    <nodename>GSL special functions</nodename>
    <nodenext>Examples ncap2</nodenext>
    <nodeprev>Irregular grids</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title><acronym><acronymword>GSL</acronymword></acronym> special functions</title>
      <para><indexterm index="cp"><acronym><acronymword>GSL</acronymword></acronym></indexterm>As of version 3.9.6 (released January, 2009), <acronym><acronymword>NCO</acronymword></acronym> can link to the GNU Scientific Library (<acronym><acronymword>GSL</acronymword></acronym>). <command>ncap</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 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>
      <para role="continues">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><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>
      <para><indexterm index="cp">gamma function</indexterm><indexterm index="cp"><var>gsl_sf_gamma</var></indexterm>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>ncap</command> script would be:</para>
      <example xml:space="preserve">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</example>
      <para role="continues">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>
      <para><indexterm index="cp">Bessel function</indexterm><indexterm index="cp"><var>gsl_sf_bessel_Jn</var></indexterm>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 role="continues">An <command>ncap</command> script would be</para>
      <example xml:space="preserve">lon_out=gsl_sf_bessel_Jn(2,lon_in);
lon_out=0.11490, 0.0012, 0.00498, 0.011165</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 xml:space="preserve">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</example>
      <para role="continues">Arguments to <acronym><acronymword>GSL</acronymword></acronym> wrapper functions in <command>ncap</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>
      <para><indexterm index="cp">Elliptic integrals</indexterm>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 xml:space="preserve">three_out=gsl_sf_ellint_RD(0.5,time,three_dmn_var_dbl);</example>
      <para role="continues">The three arguments are all conformable so the above <command>ncap</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 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</example>
      <para role="continues">The <command>ncap</command> wrappers to the array functions are slightly different. Lets consider the following gsl prototype &linebreak; <code>int gsl_sf_bessel_Jn_array(int nmin, int nmax, double x, double *result_array)</code></para>
      <example 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 ;
</example>
      <para role="continues">This calculates the bessel function of x=0.5 for n=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 go ( note the '&amp;' this indicates a call by reference). This final argument must be of type <code>double</code> and must be of least size (nmax-nmin+1). If either of these conditions are not met then then the function will blow out with an error message. The function/wrapper returns a status flag. Zero indicates success.</para>
      <para role="continues">Lets look at another array function &linebreak; <code>int gsl_sf_legendre_Pl_array( int lmax, double x, double *result_array);</code></para>
      <para><indexterm index="cp">Legendre polynomial</indexterm><indexterm index="cp">gsl_sf_legendre_Pl</indexterm></para>
      <example xml:space="preserve">a1=time.double();
x=0.3;
status=gsl_sf_legendre_Pl_array(a1.size()-1, x,&amp;a1);
print(status);</example>
      <para role="continues">This call calculates P_l(0.3) for l=0..9. Note |x|&lt;=1, otherwise there will be a domain error. See the <acronym><acronymword>GSL</acronymword></acronym> documentation for more details.</para>
      <para role="continues">Below is table detailing what GSL functions have been implemented. 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> C function prototypes look at the spreadsheet <strong>doc/nco_gsl.ods</strong>. &linebreak; &linebreak;</para>
      <multitable>
        <columnfraction>35</columnfraction>
        <columnfraction>5</columnfraction>
        <columnfraction>60</columnfraction>
        <tbody>
          <row>
            <entry><strong>GSL NAME</strong></entry>
            <entry><strong>I</strong></entry>
            <entry><strong>NCAP FUNCTION CALL</strong></entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Ai_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Ai(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Bi_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Bi(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Ai_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Ai_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Bi_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Bi_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Ai_deriv_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Ai_deriv(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Bi_deriv_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Bi_deriv(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Ai_deriv_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Ai_deriv_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_Bi_deriv_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_Bi_deriv_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_zero_Ai_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_zero_Ai(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_zero_Bi_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_zero_Bi(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_zero_Ai_deriv_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_zero_Ai_deriv(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_airy_zero_Bi_deriv_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_airy_zero_Bi_deriv(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_J0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_J0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_J1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_J1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Jn_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Jn(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Jn_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_Jn_array(int,int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Y0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Y0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Y1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Y1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Yn_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Yn(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Yn_array</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Yn_array</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_I0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_I0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_I1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_I1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_In_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_In(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_In_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_In_array(int,int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_I0_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_I0_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_I1_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_I1_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_In_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_In_scaled(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_In_scaled_array</entry>
            <entry>Y</entry>
            <entry>staus=gsl_sf_bessel_In_scaled_array(int,int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_K0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_K0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_K1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_K1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Kn_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Kn(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Kn_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_Kn_array(int,int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_K0_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_K0_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_K1_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_K1_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Kn_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Kn_scaled(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Kn_scaled_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_Kn_scaled_array(int,int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_j0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_J0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_j1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_J1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_j2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_j2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_jl_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_jl(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_jl_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_jl_array(int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_jl_steed_array</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_jl_steed_array</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_y0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Y0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_y1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Y1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_y2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_y2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_yl_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_yl(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_yl_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_yl_array(int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_i0_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_I0_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_i1_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_I1_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_i2_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_i2_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_il_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_il_scaled(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_il_scaled_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_il_scaled_array(int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_k0_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_K0_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_k1_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_K1_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_k2_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_k2_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_kl_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_kl_scaled(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_kl_scaled_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_bessel_kl_scaled_array(int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Jnu_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Jnu(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Ynu_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Ynu(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_sequence_Jnu_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_bessel_sequence_Jnu</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Inu_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Inu_scaled(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Inu_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Inu(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Knu_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Knu_scaled(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_Knu_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_Knu(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_lnKnu_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_lnKnu(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_zero_J0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_zero_J0(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_zero_J1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_bessel_zero_J1(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_bessel_zero_Jnu_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_bessel_zero_Jnu</entry>
          </row>
          <row>
            <entry>gsl_sf_clausen_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_clausen(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hydrogenicR_1_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_hydrogenicR_1</entry>
          </row>
          <row>
            <entry>gsl_sf_hydrogenicR_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_hydrogenicR</entry>
          </row>
          <row>
            <entry>gsl_sf_coulomb_wave_FG_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_coulomb_wave_FG</entry>
          </row>
          <row>
            <entry>gsl_sf_coulomb_wave_F_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_coulomb_wave_F_array</entry>
          </row>
          <row>
            <entry>gsl_sf_coulomb_wave_FG_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_coulomb_wave_FG_array</entry>
          </row>
          <row>
            <entry>gsl_sf_coulomb_wave_FGp_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_coulomb_wave_FGp_array</entry>
          </row>
          <row>
            <entry>gsl_sf_coulomb_wave_sphF_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_coulomb_wave_sphF_array</entry>
          </row>
          <row>
            <entry>gsl_sf_coulomb_CL_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_coulomb_CL</entry>
          </row>
          <row>
            <entry>gsl_sf_coulomb_CL_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_coulomb_CL_array</entry>
          </row>
          <row>
            <entry>gsl_sf_coupling_3j_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_coupling_3j</entry>
          </row>
          <row>
            <entry>gsl_sf_coupling_6j_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_coupling_6j</entry>
          </row>
          <row>
            <entry>gsl_sf_coupling_RacahW_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_coupling_RacahW</entry>
          </row>
          <row>
            <entry>gsl_sf_coupling_9j_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_coupling_9j</entry>
          </row>
          <row>
            <entry>gsl_sf_coupling_6j_INCORRECT_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_coupling_6j_INCORRECT</entry>
          </row>
          <row>
            <entry>gsl_sf_dawson_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_dawson(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_debye_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_debye_1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_debye_2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_debye_2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_debye_3_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_debye_3(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_debye_4_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_debye_4(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_debye_5_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_debye_5(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_debye_6_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_debye_6(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_dilog_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_dilog</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_dilog_xy_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_dilog_xy_e</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_dilog_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_dilog</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_spence_xy_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_spence_xy_e</entry>
          </row>
          <row>
            <entry>gsl_sf_multiply_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_multiply</entry>
          </row>
          <row>
            <entry>gsl_sf_multiply_err_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_multiply_err</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_Kcomp_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_Kcomp(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_Ecomp_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_Ecomp(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_Pcomp_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_Pcomp(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_Dcomp_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_Dcomp(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_F_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_F(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_E_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_E(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_P_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_P(dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_D_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_D(dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_RC_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_RC(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_RD_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_RD(dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_RF_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_RF(dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_ellint_RJ_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_ellint_RJ(dbl_expr,dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_elljac_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_elljac</entry>
          </row>
          <row>
            <entry>gsl_sf_erfc_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_erfc(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_log_erfc_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_log_erfc(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_erf_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_erf(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_erf_Z_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_erf_Z(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_erf_Q_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_erf_Q(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hazard_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hazard(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_exp(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_e10_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_exp_e10</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_mult_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_exp_mult(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_mult_e10_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_exp_mult_e10</entry>
          </row>
          <row>
            <entry>gsl_sf_expm1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expm1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exprel_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_exprel(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exprel_2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_exprel_2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exprel_n_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_exprel_n(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_err_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_exp_err(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_err_e10_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_exp_err_e10</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_mult_err_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_exp_mult_err</entry>
          </row>
          <row>
            <entry>gsl_sf_exp_mult_err_e10_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_exp_mult_err_e10</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_E1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_E1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_E2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_E2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_En_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_En(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_E1_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_E1_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_E2_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_E2_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_En_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_En_scaled(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_Ei_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_Ei(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_Ei_scaled_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_Ei_scaled(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_Shi_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_Shi(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_Chi_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_Chi(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_expint_3_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_expint_3(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_Si_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_Si(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_Ci_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_Ci(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_atanint_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_atanint(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_m1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_m1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_int(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_mhalf_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_mhalf(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_half_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_half(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_3half_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_3half(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fermi_dirac_inc_0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fermi_dirac_inc_0(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lngamma_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_lngamma(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lngamma_sgn_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_lngamma_sgn</entry>
          </row>
          <row>
            <entry>gsl_sf_gamma_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gamma(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gammastar_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gammastar(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gammainv_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gammainv(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lngamma_complex_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_lngamma_complex</entry>
          </row>
          <row>
            <entry>gsl_sf_taylorcoeff_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_taylorcoeff(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_fact_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_fact(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_doublefact_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_doublefact(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lnfact_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_lnfact(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lndoublefact_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_lndoublefact(uint_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lnchoose_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_lnchoose</entry>
          </row>
          <row>
            <entry>gsl_sf_choose_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_choose</entry>
          </row>
          <row>
            <entry>gsl_sf_lnpoch_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_lnpoch(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lnpoch_sgn_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_lnpoch_sgn</entry>
          </row>
          <row>
            <entry>gsl_sf_poch_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_poch(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_pochrel_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_pochrel(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gamma_inc_Q_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gamma_inc_Q(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gamma_inc_P_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gamma_inc_P(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gamma_inc_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gamma_inc(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lnbeta_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_lnbeta(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lnbeta_sgn_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_lnbeta_sgn</entry>
          </row>
          <row>
            <entry>gsl_sf_beta_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_beta(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_beta_inc_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_beta_inc</entry>
          </row>
          <row>
            <entry>gsl_sf_gegenpoly_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gegenpoly_1(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gegenpoly_2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gegenpoly_2(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gegenpoly_3_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gegenpoly_3(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_gegenpoly_n_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_gegenpoly_n</entry>
          </row>
          <row>
            <entry>gsl_sf_gegenpoly_array</entry>
            <entry>Y</entry>
            <entry>gsl_sf_gegenpoly_array</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_0F1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_0F1(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_1F1_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_1F1_int(int_expr,int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_1F1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_1F1(dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_U_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_U_int(int_expr,int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_U_int_e10_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_hyperg_U_int_e10</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_U_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_U(dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_U_e10_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_hyperg_U_e10</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_2F1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_2F1(dbl_expr,dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_2F1_conj_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_2F1_conj(dbl_expr,dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_2F1_renorm_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_2F1_renorm(dbl_expr,dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_2F1_conj_renorm_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_2F1_conj_renorm(dbl_expr,dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hyperg_2F0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hyperg_2F0(dbl_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_laguerre_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_laguerre_1(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_laguerre_2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_laguerre_2(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_laguerre_3_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_laguerre_3(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_laguerre_n_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_laguerre_n(int_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lambert_W0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_lambert_W0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_lambert_Wm1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_lambert_Wm1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Pl_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_Pl(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Pl_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_legendre_Pl_array(int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Pl_deriv_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_legendre_Pl_deriv_array</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_P1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_P1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_P2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_P2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_P3_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_P3(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Q0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_Q0(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Q1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_Q1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Ql_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_Ql(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Plm_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_Plm(int_expr,int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Plm_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_legendre_Plm_array(int,int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_Plm_deriv_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_legendre_Plm_deriv_array</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_sphPlm_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_sphPlm(int_expr,int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_sphPlm_array</entry>
            <entry>Y</entry>
            <entry>status=gsl_sf_legendre_sphPlm_array(int,int,double,&amp;var_out)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_sphPlm_deriv_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_legendre_sphPlm_deriv_array</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_array_size</entry>
            <entry>N</entry>
            <entry>gsl_sf_legendre_array_size</entry>
          </row>
          <row>
            <entry>gsl_sf_conicalP_half_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_conicalP_half(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_conicalP_mhalf_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_conicalP_mhalf(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_conicalP_0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_conicalP_0(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_conicalP_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_conicalP_1(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_conicalP_sph_reg_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_conicalP_sph_reg(int_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_conicalP_cyl_reg_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_conicalP_cyl_reg(int_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_H3d_0_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_H3d_0(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_H3d_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_H3d_1(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_H3d_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_legendre_H3d(int_expr,dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_H3d_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_legendre_H3d_array</entry>
          </row>
          <row>
            <entry>gsl_sf_legendre_array_size</entry>
            <entry>N</entry>
            <entry>gsl_sf_legendre_array_size</entry>
          </row>
          <row>
            <entry>gsl_sf_log_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_log(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_log_abs_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_log_abs(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_log_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_log</entry>
          </row>
          <row>
            <entry>gsl_sf_log_1plusx_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_log_1plusx(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_log_1plusx_mx_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_log_1plusx_mx(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_a_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_a_array</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_b_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_b_array</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_a</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_a</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_b</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_b</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_a_coeff</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_a_coeff</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_b_coeff</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_b_coeff</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_ce</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_ce</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_se</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_se</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_ce_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_ce_array</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_se_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_se_array</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_Mc</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_Mc</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_Ms</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_Ms</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_Mc_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_Mc_array</entry>
          </row>
          <row>
            <entry>gsl_sf_mathieu_Ms_array</entry>
            <entry>N</entry>
            <entry>gsl_sf_mathieu_Ms_array</entry>
          </row>
          <row>
            <entry>gsl_sf_pow_int_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_pow_int</entry>
          </row>
          <row>
            <entry>gsl_sf_psi_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_psi_int(int_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_psi_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_psi(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_psi_1piy_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_psi_1piy(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_psi_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_psi</entry>
          </row>
          <row>
            <entry>gsl_sf_psi_1_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_psi_1_int(int_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_psi_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_psi_1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_psi_n_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_psi_n(int_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_synchrotron_1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_synchrotron_1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_synchrotron_2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_synchrotron_2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_transport_2_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_transport_2(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_transport_3_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_transport_3(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_transport_4_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_transport_4(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_transport_5_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_transport_5(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_sin_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_sin</entry>
          </row>
          <row>
            <entry>gsl_sf_cos_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_cos</entry>
          </row>
          <row>
            <entry>gsl_sf_hypot_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_hypot</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_sin_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_sin</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_cos_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_cos</entry>
          </row>
          <row>
            <entry>gsl_sf_complex_logsin_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_complex_logsin</entry>
          </row>
          <row>
            <entry>gsl_sf_sinc_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_sinc</entry>
          </row>
          <row>
            <entry>gsl_sf_lnsinh_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_lnsinh</entry>
          </row>
          <row>
            <entry>gsl_sf_lncosh_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_lncosh</entry>
          </row>
          <row>
            <entry>gsl_sf_polar_to_rect</entry>
            <entry>N</entry>
            <entry>gsl_sf_polar_to_rect</entry>
          </row>
          <row>
            <entry>gsl_sf_rect_to_polar</entry>
            <entry>N</entry>
            <entry>gsl_sf_rect_to_polar</entry>
          </row>
          <row>
            <entry>gsl_sf_sin_err_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_sin_err</entry>
          </row>
          <row>
            <entry>gsl_sf_cos_err_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_cos_err</entry>
          </row>
          <row>
            <entry>gsl_sf_angle_restrict_symm_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_angle_restrict_symm</entry>
          </row>
          <row>
            <entry>gsl_sf_angle_restrict_pos_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_angle_restrict_pos</entry>
          </row>
          <row>
            <entry>gsl_sf_angle_restrict_symm_err_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_angle_restrict_symm_err</entry>
          </row>
          <row>
            <entry>gsl_sf_angle_restrict_pos_err_e</entry>
            <entry>N</entry>
            <entry>gsl_sf_angle_restrict_pos_err</entry>
          </row>
          <row>
            <entry>gsl_sf_zeta_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_zeta_int(int_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_zeta_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_zeta(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_zetam1_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_zetam1(dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_zetam1_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_zetam1_int(int_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_hzeta_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_hzeta(dbl_expr,dbl_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_eta_int_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_eta_int(int_expr)</entry>
          </row>
          <row>
            <entry>gsl_sf_eta_e</entry>
            <entry>Y</entry>
            <entry>gsl_sf_eta(dbl_expr)</entry>
          </row>
        </tbody>
      </multitable>
    </subsection>
  </node>
  <node>
    <nodename>Examples ncap2</nodename>
    <nodenext>Intrinsic mathematical methods</nodenext>
    <nodeprev>GSL special functions</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Examples ncap2</title>
      <para>See the <file>ncap.in</file> and <file>ncap2.in</file> scripts released with NCO for more complete demonstrations of <command>ncap</command> and <command>ncap2</command> functionality, respectively (these scripts are available on-line at <uref><urefurl>http://nco.sf.net/ncap.in</urefurl></uref> and <uref><urefurl>http://nco.sf.net/ncap2.in</urefurl></uref>).</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 xml:space="preserve">ncap2 -s 'one@new=2*att_var@double_att' in.nc out.nc</example>
      <para>Average variables of mixed types (result is of type <code>double</code>):</para>
      <example xml:space="preserve">ncap2 -s 'average=(var_float+var_double+var_int)/3' in.nc out.nc</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 together 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 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</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>
      <para><indexterm index="cp">growing dimensions</indexterm><indexterm index="cp">dimensions, growing</indexterm><command>ncap2</command> may be used to &ldquo;grow&rdquo; 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 xml:space="preserve">defdim("new_lat",$lat.size+1); // Define new dimension sizes
defdim("new_lon",$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</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 xml:space="preserve">ncap2 -v -S grow.nco in.nc out.nc</example>
      <para><indexterm index="cp">flags</indexterm>Imagine you wish to create a binary flag based on the value of an array. The flag should have value 1.0<!-- /@w --> where the array exceeds 1.0<!-- /@w -->, and 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 xml:space="preserve">ncap2 -s 'ORO_flg=(ORO &gt; 1.0)' in.nc out.nc</example>
      <para>Suppose your task is to change all values of <code>ORO</code> which equal 2.0<!-- /@w --> to the new value 3.0<!-- /@w -->:</para>
      <example xml:space="preserve">ncap2 -s 'ORO_msk=(ORO==2.0);ORO=ORO_msk*3.0+!ORO_msk*ORO' in.nc out.nc</example>
      <para><indexterm index="cp">mask</indexterm>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> equals 2.0<!-- /@w --> &linebreak; Using the <code>where</code> statement the above code simplifies to :</para>
      <example xml:space="preserve">ncap2 -s 'where(ORO==2.0) ORO=3.0;' in.nc foo.nc</example>
      <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. <indexterm index="cp">covariance</indexterm>
<!-- 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</para>
      <setvalue name="flg"></setvalue>
      <para><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></para>
      <clearvalue name="flg"></clearvalue>
      <para>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. <indexterm index="cp">eddy covariance</indexterm>Sometimes this is called the <dfn>eddy covariance</dfn>. We will store the covariance in the variable <code>uprmvprm</code>.</para>
      <example 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</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 xml:space="preserve">ncap2 -O -s 'uprmvprm=(u-uavg)*(v-vavg)' foo.nc foo.nc # Covariance</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 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</example>
      <para>We have not seen a simpler method to script and execute powerful arithmetic than <command>ncap2</command>.</para>
      <para><indexterm index="cp">globbing</indexterm><indexterm index="cp">shell</indexterm><indexterm index="cp">quotes</indexterm><indexterm index="cp">extended regular expressions</indexterm><indexterm index="cp">regular expressions</indexterm><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 (see <xref><xrefnodename>Subsetting Variables</xrefnodename></xref>). 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 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 # Fails ($time = '')
ncap2 -s "uavg=u.avg($time)"  in.nc foo.nc # Fails ($time = '')</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 (see <xref><xrefnodename>CCSM Example</xrefnodename></xref>). In such cases it may be necessary to use the shell backslash character <samp>\</samp> to protect the <command>ncap2</command> meta-character.</para>
      <para><indexterm index="cp">appending data</indexterm><indexterm index="cp">time-averaging</indexterm><indexterm index="cp">ncks</indexterm><indexterm index="cp">ncwa</indexterm><indexterm index="cp">ncra</indexterm><indexterm index="cp">degenerate dimension</indexterm><indexterm index="cp"><samp>-b</samp></indexterm>Whether a degenerate record dimension is desirable or undesirable depends on the application. Often a degenerate <var>time</var> dimension is useful, e.g., for concatentating, but 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 (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. <indexterm index="cp"><code>-C</code></indexterm>Equally important is the <samp>-C</samp> argument (see <xref><xrefnodename>Subsetting Coordinate Variables</xrefnodename></xref>) 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>
    </subsection>
  </node>
  <node>
    <nodename>Intrinsic mathematical methods</nodename>
    <nodenext>Operators precedence and associativity</nodenext>
    <nodeprev>Examples ncap2</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Intrinsic mathematical methods</title>
      <para><command>ncap2</command> supports the standard mathematical functions supplied with most operating systems. <indexterm index="cp">addition</indexterm><indexterm index="cp">subtraction</indexterm><indexterm index="cp">multiplication</indexterm><indexterm index="cp">division</indexterm><indexterm index="cp">exponentiation</indexterm><indexterm index="cp">power</indexterm><indexterm index="cp">modulus</indexterm><indexterm index="cp"><code>+</code> (addition)</indexterm><indexterm index="cp"><code>-</code> (subtraction)</indexterm><indexterm index="cp"><code>*</code> (multiplication)</indexterm><indexterm index="cp"><code>/</code> (division)</indexterm><indexterm index="cp"><code>^</code> (power)</indexterm><indexterm index="cp"><code>%</code> (modulus)</indexterm>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: <indexterm index="cp"><var>abs</var></indexterm><indexterm index="cp"><var>acosh</var></indexterm><indexterm index="cp"><var>acos</var></indexterm><indexterm index="cp"><var>asinh</var></indexterm><indexterm index="cp"><var>asin</var></indexterm><indexterm index="cp"><var>atanh</var></indexterm><indexterm index="cp"><var>atan</var></indexterm><indexterm index="cp"><var>ceil</var></indexterm><indexterm index="cp"><var>cosh</var></indexterm><indexterm index="cp"><var>cos</var></indexterm><indexterm index="cp"><var>erfc</var></indexterm><indexterm index="cp"><var>erf</var></indexterm><indexterm index="cp"><var>exp</var></indexterm><indexterm index="cp"><var>floor</var></indexterm><indexterm index="cp"><var>gamma</var></indexterm><indexterm index="cp"><var>ln</var></indexterm><indexterm index="cp"><var>log10</var></indexterm><indexterm index="cp"><var>log</var></indexterm><indexterm index="cp"><var>nearbyint</var></indexterm><indexterm index="cp"><var>pow</var></indexterm><indexterm index="cp"><var>rint</var></indexterm><indexterm index="cp"><var>round</var></indexterm><indexterm index="cp"><var>sinh</var></indexterm><indexterm index="cp"><var>sin</var></indexterm><indexterm index="cp"><var>sqrt</var></indexterm><indexterm index="cp"><var>tanh</var></indexterm><indexterm index="cp"><var>tan</var></indexterm><indexterm index="cp"><var>trunc</var></indexterm><indexterm index="cp">mathematical functions</indexterm><indexterm index="cp">nearest integer function (inexact)</indexterm><indexterm index="cp">nearest integer function (exact)</indexterm><indexterm index="cp">rounding functions</indexterm><indexterm index="cp">truncation function</indexterm><indexterm index="cp">absolute value</indexterm><indexterm index="cp">arccosine function</indexterm><indexterm index="cp">arcsine function</indexterm><indexterm index="cp">arctangent function</indexterm><indexterm index="cp">ceiling function</indexterm><indexterm index="cp">complementary error function</indexterm><indexterm index="cp">cosine function</indexterm><indexterm index="cp">error function</indexterm><indexterm index="cp">exponentiation function</indexterm><indexterm index="cp">floor function</indexterm><indexterm index="cp">gamma function</indexterm><indexterm index="cp">hyperbolic arccosine function</indexterm><indexterm index="cp">hyperbolic arcsine function</indexterm><indexterm index="cp">hyperbolic arctangent function</indexterm><indexterm index="cp">hyperbolic cosine function</indexterm><indexterm index="cp">hyperbolic sine function</indexterm><indexterm index="cp">hyperbolic tangent</indexterm><indexterm index="cp">logarithm, base 10</indexterm><indexterm index="cp">logarithm, natural</indexterm><indexterm index="cp">power function</indexterm><indexterm index="cp">sine function</indexterm><indexterm index="cp">square root function</indexterm></para>
      <table>
        <tableitem>
          <tableterm><code>abs(x)</code></tableterm>
          <item>
            <para><dfn>Absolute value</dfn> Absolute value of <var>x</var>. Example: <math>abs(-1) = 1</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>acos(x)</code></tableterm>
          <item>
            <para><dfn>Arc-cosine</dfn> Arc-cosine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>acos(1.0) = 0.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>acosh(x)</code></tableterm>
          <item>
            <para><dfn>Hyperbolic arc-cosine</dfn> Hyperbolic arc-cosine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>acosh(1.0) = 0.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>asin(x)</code></tableterm>
          <item>
            <para><dfn>Arc-sine</dfn> Arc-sine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>asin(1.0) = 1.57079632679489661922</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>asinh(x)</code></tableterm>
          <item>
            <para><dfn>Hyperbolic arc-sine</dfn> Hyperbolic arc-sine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>asinh(1.0) = 0.88137358702</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>atan(x)</code></tableterm>
          <item>
            <para><dfn>Arc-tangent</dfn> Arc-tangent of <var>x</var> where <var>x</var> is specified in radians between <math>-pi/2</math> and <math>pi/2</math>. Example: <math>atan(1.0) = 0.78539816339744830961</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>atan2(y,x)</code></tableterm>
          <item>
            <para><dfn>Arc-tangent2</dfn> Arc-tangent of <var>y/x</var> <math>:Example atan2(1,3) =  0.321689857</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>atanh(x)</code></tableterm>
          <item>
            <para><dfn>Hyperbolic arc-tangent</dfn> Hyperbolic arc-tangent of <var>x</var> where <var>x</var> is specified in radians between <math>-pi/2</math> and <math>pi/2</math>. Example: <math>atanh(3.14159265358979323844) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ceil(x)</code></tableterm>
          <item>
            <para><dfn>Ceil</dfn> Ceiling of <var>x</var>. Smallest integral value not less than argument. Example: <math>ceil(0.1) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>cos(x)</code></tableterm>
          <item>
            <para><dfn>Cosine</dfn> Cosine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>cos(0.0) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>cosh(x)</code></tableterm>
          <item>
            <para><dfn>Hyperbolic cosine</dfn> Hyperbolic cosine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>cosh(0.0) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>erf(x)</code></tableterm>
          <item>
            <para><dfn>Error function</dfn> Error function of <var>x</var> where <var>x</var> is specified between <math>-1</math> and <math>1</math>. Example: <math>erf(1.0) = 0.842701</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>erfc(x)</code></tableterm>
          <item>
            <para><dfn>Complementary error function</dfn> Complementary error function of <var>x</var> where <var>x</var> is specified between <math>-1</math> and <math>1</math>. Example: <math>erfc(1.0) = 0.15729920705</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>exp(x)</code></tableterm>
          <item>
            <para><dfn>Exponential</dfn> Exponential of <var>x</var>, <math>e^x</math>. Example: <math>exp(1.0) = 2.71828182845904523536</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>floor(x)</code></tableterm>
          <item>
            <para><dfn>Floor</dfn> Floor of <var>x</var>. Largest integral value not greater than argument. Example: <math>floor(1.9) = 1</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>gamma(x)</code></tableterm>
          <item>
            <para><dfn>Gamma function</dfn> Gamma function of <var>x</var>, <math>Gamma(x)</math>. The well-known and loved continuous factorial function. Example: <math>gamma(0.5) = sqrt(pi)</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>gamma_inc_P(x)</code></tableterm>
          <item>
            <para><dfn>Incomplete Gamma function</dfn> Incomplete Gamma function of parameter <var>a</var> and variable <var>x</var>, <math>gamma_inc_P(a,x)</math>. One of the four incomplete gamma functions. Example: <math>gamma_inc_P(1,1) = 1-1/e</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ln(x)</code></tableterm>
          <item>
            <para><dfn>Natural Logarithm</dfn> Natural logarithm of <var>x</var>, <math>ln(x)</math>. Example: <math>ln(2.71828182845904523536) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>log(x)</code></tableterm>
          <item>
            <para><dfn>Natural Logarithm</dfn> Exact synonym for <code>ln(x)</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>log10(x)</code></tableterm>
          <item>
            <para><dfn>Base 10 Logarithm</dfn> Base 10<!-- /@w --> logarithm of <var>x</var>, <math>log10(x)</math>. Example: <math>log(10.0) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>nearbyint(x)</code></tableterm>
          <item>
            <para><dfn>Round inexactly</dfn> Nearest integer to <var>x</var> is returned in floating point format. <indexterm index="cp">inexact conversion</indexterm>No exceptions are raised for <dfn>inexact conversions</dfn>. Example: <math>nearbyint(0.1) = 0.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>pow(x,y)</code></tableterm>
          <item>
            <para><dfn>Power</dfn> <indexterm index="cp">promotion</indexterm><indexterm index="cp">automatic type conversion</indexterm>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 C language<!-- /@w --> <code>pow</code> function, integer arguments are promoted (see <xref><xrefnodename>Type Conversion</xrefnodename></xref>) to type <code>NC_FLOAT</code> before evaluation. Example: <math>pow(2,3) = 8</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>rint(x)</code></tableterm>
          <item>
            <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: <math>rint(0.1) = 0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>round(x)</code></tableterm>
          <item>
            <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 IEEE rounding direction. Example: <math>round(0.5) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>sin(x)</code></tableterm>
          <item>
            <para><dfn>Sine</dfn> Sine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>sin(1.57079632679489661922) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>sinh(x)</code></tableterm>
          <item>
            <para><dfn>Hyperbolic sine</dfn> Hyperbolic sine of <var>x</var> where <var>x</var> is specified in radians. Example: <math>sinh(1.0) = 1.1752</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>sqrt(x)</code></tableterm>
          <item>
            <para><dfn>Square Root</dfn> Square Root of <var>x</var>, <math>sqrt(x)</math>. Example: <math>sqrt(4.0) = 2.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>tan(x)</code></tableterm>
          <item>
            <para><dfn>Tangent</dfn> Tangent of <var>x</var> where <var>x</var> is specified in radians. Example: <math>tan(0.78539816339744830961) = 1.0</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>tanh(x)</code></tableterm>
          <item>
            <para><dfn>Hyperbolic tangent</dfn> Hyperbolic tangent of <var>x</var> where <var>x</var> is specified in radians. Example: <math>tanh(1.0) = 0.761594155956</math></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>trunc(x)</code></tableterm>
          <item>
            <para><dfn>Truncate</dfn> Nearest integer to <var>x</var> is returned in floating point format. Round halfway cases toward zero, regardless of current IEEE rounding direction. Example: <math>trunc(0.5) = 0.0</math></para>
          </item>
        </tableitem>
      </table>
      <para role="continues">The complete list of mathematical functions supported is platform-specific. Functions mandated by ANSI C<!-- /@w --> are <emph>guaranteed</emph> to be present and are indicated with an asterisk 
<!-- fxm No they're not, not yet --><indexterm index="cp"><code>ANSI C</code></indexterm><indexterm index="cp"><code>float</code></indexterm><indexterm index="cp">precision</indexterm><indexterm index="cp">quadruple precision</indexterm><indexterm index="cp">single precision</indexterm><indexterm index="cp">double precision</indexterm><indexterm index="cp"><code>long double</code></indexterm><indexterm index="cp"><code>NC_DOUBLE</code></indexterm><footnote><para> 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. <indexterm index="cp"><code>-f</code></indexterm><indexterm index="cp"><code>--prn_fnc_tbl</code></indexterm><indexterm index="cp"><code>--fnc_tbl</code></indexterm>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. <indexterm index="cp">Linux</indexterm><footnote><para>Linux supports more of these intrinsic functions than other OSs.</para></footnote></para>
      <para role="continues"></para>
<!-- Begin HMB documentation -->
    </subsection>
  </node>
  <node>
    <nodename>Operators precedence and associativity</nodename>
    <nodenext>ID Quoting</nodenext>
    <nodeprev>Intrinsic mathematical methods</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Operators precedence and associativity</title>
      <para>This page lists the <command>ncap</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>
        <columnfraction>18</columnfraction>
        <columnfraction>62</columnfraction>
        <columnfraction>20</columnfraction>
        <thead>
          <row>
            <entry>Operator</entry>
            <entry>Description</entry>
            <entry>Associativity</entry>
          </row>
        </thead>
        <tbody>
          <row>
            <entry><code>++ --</code></entry>
            <entry>Postfix Increment/Decrement</entry>
            <entry>Right to Left</entry>
          </row>
          <row>
            <entry><code>()</code></entry>
            <entry>Parentheses (function call)</entry>
          </row>
          <row>
            <entry><code>.</code></entry>
            <entry>Method call</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>++ --</code></entry>
            <entry>Prefix Increment/Decrement</entry>
            <entry>Right to Left</entry>
          </row>
          <row>
            <entry><code>+ -</code></entry>
            <entry>Unary  Plus/Minus</entry>
          </row>
          <row>
            <entry><code>!</code></entry>
            <entry>Logical Not</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>^</code></entry>
            <entry>Power of Operator</entry>
            <entry>Right to Left</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>* / %</code></entry>
            <entry>Multiply/Divide/Modulus</entry>
            <entry>Left To Right</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>+ -</code></entry>
            <entry>Addition/Subtraction</entry>
            <entry>Left To Right</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>&gt;&gt; &lt;&lt;</code></entry>
            <entry>Fortran style array clipping</entry>
            <entry>Left to Right</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>&lt; &lt;=</code></entry>
            <entry>Less than/Less than or equal to</entry>
            <entry>Left to Right</entry>
          </row>
          <row>
            <entry><code>&gt; &gt;=</code></entry>
            <entry>Greater than/Greater than or equal to</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>== !=</code></entry>
            <entry>Equal to/Not equal to</entry>
            <entry>Left to Right</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>&amp;&amp;</code></entry>
            <entry>Logical AND</entry>
            <entry>Left to Right</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>||</code></entry>
            <entry>Logical OR</entry>
            <entry>Left to Right</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>?:</code></entry>
            <entry>Ternary Operator</entry>
            <entry>Right to Left</entry>
          </row>
          <row>
            <entry></entry>
          </row>
          <row>
            <entry><code>=</code></entry>
            <entry>Assignment</entry>
            <entry>Right to Left</entry>
          </row>
          <row>
            <entry><code>+= -=</code></entry>
            <entry>Addition/subtraction assignment</entry>
          </row>
          <row>
            <entry><code>*= /=</code></entry>
            <entry>Multiplication/division assignment</entry>
          </row>
        </tbody>
      </multitable>
    </subsection>
  </node>
  <node>
    <nodename>ID Quoting</nodename>
    <nodeprev>Operators precedence and associativity</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>ID Quoting</title>
      <para><indexterm index="cp">ID Quoting</indexterm>In this section when I refer to a name I mean a variable name, attribute name or a dimension name The allowed characters in a valid netCDF name vary from release to release. (See end section). If you want to use metacharacters in a name or use a method name as a variable name then the name has to be quoted wherever it occurs.</para>
      <para role="continues">The default nco name is specified by the regular expressions:</para>
      <example xml:space="preserve">DGT:     ('0'..'9');
LPH:     ( 'a'..'z' | 'A'..'Z' | '_' );
name:    (LPH)(LPH|DGT)+</example>
      <para role="continues">The first character of a valid name must be alphabetic or the underscore. Any subsequent characters must be alphanumeric or underscore. ( e.g a1,_23, hell_is_666 )</para>
      <para role="continues">The valid characters in a quoted name are specified by the regular expressions:</para>
      <example xml:space="preserve">LPHDGT:  ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9');
name:    (LPHDGT|'-'|'+'|'.'|'('|')'|':' )+  ;</example>
      <para role="continues">Quote a variable: &linebreak; 'avg' , '10_+10','set_miss' '+-90field' , '&ndash;test'=10.0d&linebreak; &linebreak; Quote a attribute: &linebreak; 'three@10', 'set_mss@+10', '666@hell', 't1@+units'="kelvin" &linebreak; &linebreak; Quote a dimension: &linebreak; '$10', '$t1&ndash;', '$&ndash;odd', c1['$10','$t1&ndash;']=23.0d &linebreak;</para>
      <sp lines="1"></sp>
      <para>The following comments are lifted directly from the netcdf libraries and detail the naming conventions for each release.</para>
      <para role="continues">netcdf-3.5.1 &linebreak; netcdf-3.6.0-p1 &linebreak; netcdf-3.6.1 &linebreak; netcdf-3.6.2 &linebreak;</para>
      <example xml:space="preserve">/*
 * ( [a-zA-Z]|[0-9]|'_'|'-'|'+'|'.'|'|':'|'@'|'('|')' )+
 * Verify that a name string is valid
 * CDL syntax, eg, all the 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.
 */</example>
      <para role="continues">netcdf-3.6.3 &linebreak; netcdf-4.0 Final  2008/08/28 &linebreak;</para>
      <example xml:space="preserve">/*
 * 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.
 */</example>
<!-- End HMB documentation -->
    </subsection>
  </node>
  <node>
    <nodename>ncatted netCDF Attribute Editor</nodename>
    <nodenext>ncbo netCDF Binary Operator</nodenext>
    <nodeprev>ncap2 netCDF Arithmetic Processor</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncatted</command> netCDF Attribute Editor</title>
      <para><indexterm index="cp">attributes</indexterm><indexterm index="cp">attribute names</indexterm><indexterm index="cp">editing attributes</indexterm><indexterm index="cp">ncatted</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncatted [-a <var>att_dsc</var>] [-a &dots;] [-D <var>dbg</var>] [-h] [--hdr_pad <var>nbr</var>]
[-l <var>path</var>] [-O] [-o <var>output-file</var>] [-p <var>path</var>] [-R] [-r]
<var>input-file</var> [[<var>output-file</var>]]</example>
      <para role="continues">DESCRIPTION</para>
      <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). Furthermore, <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. Note that <command>ncatted</command> interprets character attributes (i.e., attributes of type <code>NC_CHAR</code>) as strings.</para>
      <para><indexterm index="cp"><code>history</code></indexterm><indexterm index="cp"><code>-h</code></indexterm>Because repeated use of <command>ncatted</command> can considerably increase the size of the <code>history</code> global attribute (see <xref><xrefnodename>History Attribute</xrefnodename></xref>), 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>
      <para><indexterm index="cp">missing values</indexterm><indexterm index="cp">data, missing</indexterm><indexterm index="cp"><code>_FillValue</code></indexterm>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 together, e.g., by <command>ncrcat</command>, without losing any information. See <xref><xrefnodename>Missing Values</xrefnodename></xref>, for more information.</para>
      <para>The key to mastering <command>ncatted</command> is understanding the meaning of the structure describing the attribute modification, <var>att_dsc</var> specified by the required option <samp>-a</samp> or <samp>--attribute</samp>. Each <var>att_dsc</var> contains five elements, which makes using <command>ncatted</command> somewhat complicated, but powerful. The <var>att_dsc</var> argument structure contains five arguments 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>
        <tableitem>
          <tableterm><var>att_nm</var></tableterm>
          <item>
            <para>Attribute name. Example: <code>units</code></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><var>var_nm</var></tableterm>
          <item>
            <para>Variable name. <indexterm index="cp">extended regular expressions</indexterm><indexterm index="cp">regular expressions</indexterm><indexterm index="cp">pattern matching</indexterm><indexterm index="cp">wildcards</indexterm>Regular expressions (see <xref><xrefnodename>Subsetting Variables</xrefnodename></xref>) are accepted and will select any matching variable names. Example: <code>pressure</code>, <code>'^H2O'</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><var>mode</var></tableterm>
          <item>
            <para>Edit mode abbreviation. Example: <code>a</code>. See below for complete listing of valid values of <var>mode</var>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><var>att_type</var></tableterm>
          <item>
            <para>Attribute type abbreviation. Example: <code>c</code>. See below for complete listing of valid values of <var>att_type</var>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><var>att_val</var></tableterm>
          <item>
            <para>Attribute value. Example: <code>pascal</code>.</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">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 you want to edit. This meaning of this should be clear to all users of the <command>ncatted</command> operator. 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>
      <para><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm>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 variable in a file. A value<!-- /@w --> of <var>var_nm</var> of &ldquo;global&rdquo; indicates that <var>att_nm</var> refers to a global attribute, rather than a particular variable's attribute. This is the method <command>ncatted</command> supports for editing global attributes. If <var>var_nm</var> is left blank, on the other hand, 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. Finally, as mentioned above, <var>var_nm</var> may be specified as a regular expression.</para>
      <para>The value of <var>mode</var> is a single character abbreviation (<code>a</code>, <code>c</code>, <code>d</code>, <code>m</code>, or <code>o</code>) standing for one of five editing modes:&linebreak; <indexterm index="cp">attributes, appending</indexterm><indexterm index="cp">attributes, creating</indexterm><indexterm index="cp">attributes, deleting</indexterm><indexterm index="cp">attributes, modifying</indexterm><indexterm index="cp">attributes, editing</indexterm><indexterm index="cp">attributes, overwriting</indexterm></para>
      <table>
        <tableitem>
          <tableterm><code>a</code></tableterm>
          <item>
            <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 have an attribute <var>att_nm</var>, there is no effect.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>c</code></tableterm>
          <item>
            <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.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>d</code></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>m</code></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>o</code></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
      </table>
      <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>
        <tableitem>
          <tableterm><code>f</code></tableterm>
          <item>
            <para><dfn>Float</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_FLOAT</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>d</code></tableterm>
          <item>
            <para><dfn>Double</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_DOUBLE</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>i, l</code></tableterm>
          <item>
            <para><dfn>Integer</dfn> or <dfn>Long</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_INT</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>s</code></tableterm>
          <item>
            <para><dfn>Short</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_SHORT</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>c</code></tableterm>
          <item>
            <para><dfn>Char</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_CHAR</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>b</code></tableterm>
          <item>
            <para><dfn>Byte</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_BYTE</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ub</code></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>us</code></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>u, ui, ul</code></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ll, int64</code></tableterm>
          <item>
            <para><dfn>Int64</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_INT64</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ull, uint64</code></tableterm>
          <item>
            <para><dfn>Uint64</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_UINT64</code>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>sng</code></tableterm>
          <item>
            <para><dfn>String</dfn>. Value(s) specified in <var>att_val</var> will be stored as netCDF intrinsic type <code>NC_STRING</code>.</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">The specification of <var>att_type</var> is optional (and is ignored) in <dfn>Delete</dfn> mode.</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,""</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,"1,2,3,4"</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>
      <para><indexterm index="cp">Perl</indexterm><indexterm index="cp"><acronym><acronymword>ASCII</acronymword></acronym></indexterm><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). <indexterm index="cp"><code>printf()</code></indexterm><indexterm index="cp"><code>\n</code> (<acronym><acronymword>ASCII</acronymword></acronym> LF, linefeed)</indexterm><indexterm index="cp">characters, special</indexterm><indexterm index="cp"><code>\t</code> (<acronym><acronymword>ASCII</acronymword></acronym> HT, horizontal tab)</indexterm>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. <indexterm index="cp"><code>\a</code> (<acronym><acronymword>ASCII</acronymword></acronym> BEL, bell)</indexterm><indexterm index="cp"><code>\b</code> (<acronym><acronymword>ASCII</acronymword></acronym> BS, backspace)</indexterm><indexterm index="cp"><code>\f</code> (<acronym><acronymword>ASCII</acronymword></acronym> FF, formfeed)</indexterm><indexterm index="cp"><code>\r</code> (<acronym><acronymword>ASCII</acronymword></acronym> CR, carriage return)</indexterm><indexterm index="cp"><code>\v</code> (<acronym><acronymword>ASCII</acronymword></acronym> VT, vertical tab)</indexterm><indexterm index="cp"><code>\\</code> (<acronym><acronymword>ASCII</acronymword></acronym> \, backslash)</indexterm>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>. See <xref><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>
      <para><indexterm index="cp"><code>\'</code> (protected end quote)</indexterm><indexterm index="cp"><code>\"</code> (protected double quote)</indexterm><indexterm index="cp"><code>\?</code> (protected question mark)</indexterm><indexterm index="cp"><code>\\</code> (protected backslash)</indexterm><indexterm index="cp"><code>'</code> (end quote)</indexterm><indexterm index="cp"><code>"</code> (double quote)</indexterm><indexterm index="cp"><code>?</code> (question mark)</indexterm><indexterm index="cp"><code>\</code> (backslash)</indexterm><indexterm index="cp">special characters</indexterm><indexterm index="cp"><acronym><acronymword>ASCII</acronymword></acronym></indexterm>Analogous to <code>printf</code>, other special characters are also allowed by <command>ncatted</command> if they are "protected" by a backslash. The characters <code>"</code>, <code>'</code>, <code>?</code>, and <code>\</code> may be input to the shell as <code>\"</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>@</code>, <code>%</code>, <code>{</code>, and <code>}</code>) will not be filtered and will be included in the attribute.</para>
      <para><indexterm index="cp">strings</indexterm><indexterm index="cp">NUL-termination</indexterm><indexterm index="cp">NUL</indexterm><indexterm index="cp">C language</indexterm><indexterm index="cp"><code>0</code> (NUL)</indexterm>Note that the NUL character <code>\0</code> which terminates C language<!-- /@w --> strings is assumed and need not be explicitly specified. If <code>\0</code> is input, it will not be translated (because it would terminate the string in an additional location). Because of these context-sensitive rules, if wish to use an attribute of type <code>NC_CHAR</code> to store data, rather than text strings, you should use <command>ncatted</command> with care.</para>
      <para role="continues">EXAMPLES</para>
      <para>Append the string "Data version 2.0.\n" to the global attribute <code>history</code>:</para>
      <example xml:space="preserve">ncatted -a history,global,a,c,"Data version 2.0\n" in.nc</example>
      <para>Note the use of embedded 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 "temperature":</para>
      <example xml:space="preserve">ncatted -a long_name,T,o,c,temperature in.nc</example>
      <para>Delete all existing <code>units</code> attributes:</para>
      <example xml:space="preserve">ncatted -a units,,d,, in.nc</example>
      <para role="continues">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>
      <para><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm>Delete all attributes associated with the <code>tpt</code> variable:</para>
      <example xml:space="preserve">ncatted -a ,tpt,d,, in.nc</example>
      <para role="continues">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>
      <para><indexterm index="cp"><code>units</code></indexterm>Modify all existing <code>units</code> attributes to "meter second-1":</para>
      <example xml:space="preserve">ncatted -a units,,m,c,"meter second-1" in.nc</example>
      <para><indexterm index="cp"><code>units</code></indexterm>Add a <code>units</code> attribute of "kilogram kilogram-1" to all variables whose first three characters are <samp>H2O</samp>:</para>
      <example xml:space="preserve">ncatted -a units,'^H2O',c,c,"kilogram kilogram-1" in.nc</example>
      <para>Overwrite the <code>quanta</code> attribute of variable <code>energy</code> to an array of four integers.</para>
      <example xml:space="preserve">ncatted -O -a quanta,energy,o,s,"010,101,111,121" in.nc</example>
      <para><indexterm index="cp">extended regular expressions</indexterm><indexterm index="cp">regular expressions</indexterm><indexterm index="cp">pattern matching</indexterm><indexterm index="cp">wildcards</indexterm>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>. Create <code>isotope</code> attributes for all variables containing <samp>H2O</samp> in their names.</para>
      <example xml:space="preserve">ncatted -O -a isotope,'^H2O*',c,s,"18" in.nc</example>
      <para>See <xref><xrefnodename>Subsetting Variables</xrefnodename></xref> for more details.</para>
      <para>Demonstrate input of C-language escape sequences (e.g., <code>\n</code>) and other special characters (e.g., <code>\"</code>)</para>
      <example xml:space="preserve">ncatted -h -a special,global,o,c,
'\nDouble quote: \"\nTwo consecutive double quotes: \"\"\n
Single quote: Beyond my shell abilities!\nBackslash: \\\n
Two consecutive backslashes: \\\\\nQuestion mark: \?\n' in.nc</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>
    </section>
  </node>
  <node>
    <nodename>ncbo netCDF Binary Operator</nodename>
    <nodenext>ncea netCDF Ensemble Averager</nodenext>
    <nodeprev>ncatted netCDF Attribute Editor</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncbo</command> netCDF Binary Operator</title>
      <para><indexterm index="cp">ncbo</indexterm><indexterm index="cp">ncdiff</indexterm><indexterm index="cp">ncadd</indexterm><indexterm index="cp">ncsub</indexterm><indexterm index="cp">ncsubtract</indexterm><indexterm index="cp">ncmult</indexterm><indexterm index="cp">ncmultiply</indexterm><indexterm index="cp">ncdivide</indexterm><indexterm index="cp">binary operations</indexterm><indexterm index="cp">addition</indexterm><indexterm index="cp">subtraction</indexterm><indexterm index="cp">multiplication</indexterm><indexterm index="cp">adding data</indexterm><indexterm index="cp">subtracting data</indexterm><indexterm index="cp">multiplying data</indexterm><indexterm index="cp">dividing data</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncbo [-3] [-4] [-A] [-C] [-c] [-D <var>dbg</var>]
[-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F] [-h]
[-L <var>dfl_lvl</var>] [-l <var>path</var>] [-O] [-o <var>file_3</var>] [-p <var>path</var>] [-R] [-r]
[-t <var>thr_nbr</var>] [-v <var>var</var>[,&dots;]] [-X ...] [-x] [-y <var>op_typ</var>]
<var>file_1</var> <var>file_2</var> [<var>file_3</var>]</example>
      <para role="continues">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). See <xref><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>). <indexterm index="cp"><code>add</code></indexterm><indexterm index="cp"><code>subtract</code></indexterm><indexterm index="cp"><code>multiply</code></indexterm><indexterm index="cp"><code>divide</code></indexterm><indexterm index="cp"><code>+</code></indexterm><indexterm index="cp"><code>-</code></indexterm><indexterm index="cp"><code>*</code></indexterm><indexterm index="cp"><code>/</code></indexterm><indexterm index="cp"><code>-y <var>op_typ</var></code></indexterm><indexterm index="cp"><code>--operation <var>op_typ</var></code></indexterm><indexterm index="cp"><code>--op_typ <var>op_typ</var></code></indexterm><indexterm index="cp">alternate invocations</indexterm>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>
        <tableitem>
          <tableterm><dfn>Addition</dfn></tableterm>
<!-- Internal operation code: @{nco_op_add}@* -->
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Subtraction</dfn></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Multiplication</dfn></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><dfn>Division</dfn></tableterm>
          <item>
            <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>
          </item>
        </tableitem>
      </table>
      <para role="continues">Care should be taken when using the shortest form of key values, i.e., <samp>+</samp>, <samp>-</samp>, <samp>*</samp>, and <samp>/</samp><!-- /@w -->. Some of these single characters may have special meanings to the shell <indexterm index="cp">naked characters</indexterm><footnote><para>A naked<!-- /@w --> (i.e., unprotected or unquoted) <samp>*</samp> is a wildcard character. A naked<!-- /@w --> <samp>-</samp> may confuse the command line parser. A naked<!-- /@w --> <samp>+</samp> and <samp>/</samp> are relatively harmless.</para></footnote>. <indexterm index="cp">Bash shell</indexterm>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>. <indexterm index="cp">globbing</indexterm><indexterm index="cp">shell</indexterm><indexterm index="cp">quotes</indexterm>For example, the following commands are equivalent</para>
      <example 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="*" 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'</example>
      <para>No particular argument or invocation form is preferred. Users are encouraged to use the forms which are most intuitive to them.</para>
      <para><indexterm index="cp"><command>alias</command></indexterm><indexterm index="cp"><command>ln -s</command></indexterm><indexterm index="cp">symbolic links</indexterm>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'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>
      <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>. <indexterm index="cp">broadcasting variables</indexterm>Variables in <var>file_2</var> are <dfn>broadcast</dfn> to conform to the corresponding variable in <var>file_1</var> if necessary, but the reverse is not true. Broadcasting a variable means creating data in non-existing dimensions from the data in existing dimensions. For example, a two dimensional variable in <var>file_2</var> can be subtracted from a four, three, or two (but not one or zero) dimensional variable (of the same name) in <code>file_1</code>. <indexterm index="cp">anomalies</indexterm>This functionality allows the user to compute anomalies from the mean. Note that variables in <var>file_1</var> are <emph>not</emph> broadcast to conform to the dimensions in <var>file_2</var>. In the future, we will broadcast variables in <var>file_1</var>, if necessary to conform to their counterparts in <var>file_2</var>. 
<!-- TODO #268 --><indexterm index="cp">rank</indexterm>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>. Furthermore, 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> were 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 size 1<!-- /@w --> rather than having no <code>time</code> dimension at all <indexterm index="cp">degenerate dimension</indexterm><indexterm index="cp"><samp>-b</samp></indexterm><footnote><para>This is because <command>ncra</command> collapses the record dimension to a size 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 but 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 occuring, use <command>ncwa</command> to remove the <code>time</code> dimension from <var>file_2</var>. See the example below.</para>
      <para><indexterm index="cp">coordinate variable</indexterm><indexterm index="cp"><code>NC_BYTE</code></indexterm><indexterm index="cp"><code>NC_CHAR</code></indexterm><command>ncbo</command> never operates on coordinate variables or variables of type <code>NC_CHAR</code> or <code>NC_BYTE</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. <indexterm index="cp"><acronym><acronymword>CF</acronymword></acronym> conventions</indexterm><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 <xref><xrefnodename>CF Conventions</xrefnodename></xref> for a complete description. Finally, we note that <command>ncflint</command> (see <xref><xrefnodename>ncflint netCDF File Interpolator</xrefnodename></xref>) 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>
      <para role="continues">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 xml:space="preserve">ncbo -op_typ=sub 86_0112.nc 85_0112.nc 86m85_0112.nc
ncdiff 86_0112.nc 85_0112.nc 86m85_0112.nc</example>
      <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 xml:space="preserve">ncra 85_0112.nc 85.nc
ncwa -O -a time 85.nc 85.nc</example>
      <para role="continues">The second command, <command>ncwa</command>, gets rid of the <code>time</code> dimension of 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. A quicker<!-- /@w --> way to accomplish this is to use <command>ncwa</command> from the beginning:</para>
      <example xml:space="preserve">ncwa -a time 85_0112.nc 85.nc</example>
      <para role="continues">We are now ready to use <command>ncbo</command> to compute the anomalies for 1985:</para>
      <example xml:space="preserve">ncdiff -v T 85_0112.nc 85.nc t_anm_85_0112.nc</example>
      <para role="continues">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. 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 xml:space="preserve">ncwa -a lon 85.nc 85_x.nc
ncdiff 85_0112.nc 85_x.nc tx_anm_85_0112.nc</example>
      <para role="continues">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>
      <para>As a final example, say we have five years of monthly data (i.e., 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 xml:space="preserve">ncwa -a time 8501_8912.nc 8589.nc</example>
      <para role="continues">Next use <command>ncbo</command> to create a file containing the difference of each month's data from the five-year mean:</para>
      <example xml:space="preserve">ncbo 8501_8912.nc 8589.nc t_anm_8501_8912.nc</example>
      <para role="continues">Now use <command>ncks</command> to group the five January anomalies together 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: <indexterm index="cp">Bash Shell</indexterm><indexterm index="cp">Bourne Shell</indexterm><indexterm index="cp">C Shell</indexterm></para>
      <example xml:space="preserve">for idx in {1..12}; do # Bash Shell (version 3.0+)
  idx=`printf "%02d" ${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</example>
      <para role="continues">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 xml:space="preserve">ncra -F -d time,${idx},,12 t_anm_8501_8912.nc foo.${idx}</example>
      <para role="continues">Finally, use <command>ncrcat</command> to concatenate the 12 average<!-- /@w --> monthly anomaly files into one twelve-record file which contains the entire seasonal cycle of the monthly anomalies:</para>
      <example xml:space="preserve">ncrcat t_anm_8589_??.nc t_anm_8589_0112.nc</example>
      <para role="continues"></para>
    </section>
  </node>
  <node>
    <nodename>ncea netCDF Ensemble Averager</nodename>
    <nodenext>ncecat netCDF Ensemble Concatenator</nodenext>
    <nodeprev>ncbo netCDF Binary Operator</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncea</command> netCDF Ensemble Averager</title>
      <para><indexterm index="cp">averaging data</indexterm><indexterm index="cp">ensemble average</indexterm><indexterm index="cp">ncea</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncea [-3] [-4] [-A] [-C] [-c] [-D <var>dbg</var>]
[-d <var>dim</var>,[<var>min</var>][,