<?xml version="1.0"?>
<!DOCTYPE texinfo PUBLIC "-//GNU//DTD TexinfoML V4.13//EN" "http://www.gnu.org/software/texinfo/dtd/4.13/texinfo.dtd">
<texinfo xml:lang="en">
  <setfilename>nco.xml</setfilename><!-- Define edition, date, ... -->
  <setvalue name="nco-edition">4.2.0</setvalue>
  <setvalue name="doc-edition">4.2.0</setvalue>
  <setvalue name="copyright-years">1995&ndash;2012</setvalue>
  <setvalue name="update-year">2012</setvalue>
  <setvalue name="update-date">19 May 2012</setvalue>
  <setvalue name="update-month">May 2012</setvalue>
  <settitle><acronym><acronymword>NCO</acronymword></acronym>4.2.0 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 -->
<!-- % csz 20100313 remove next line to prevent "\input texinfo" from -->
<!-- % appearing in printed output -->
<!-- %% \input texinfo   @c -*-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. -->
<!-- %% @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;2012 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 4.2.0, for &lt;acronym&gt;&lt;acronymword&gt;NCO&lt;/acronymword&gt;&lt;/acronym&gt;Version 4.2.0</booksubtitle>
    <booksubtitle>May 2012</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;2012 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 4.2.0. It was last updated 19 May 2012. 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> was 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>Symbolic Links</menunode>
          <menutitle>Symbolic Links</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>Symbolic Links</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<!-- /@w -->-language API 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><indexterm index="cp">Vista (Microsoft operating system)</indexterm> <acronym><acronymword>NCO</acronymword></acronym> has been successfully ported and tested on most Microsoft Windows operating systems including: 95/98/NT/2000/XP/Vista. 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>Currently, Cygwin 20.x<!-- /@w --> comes with the <acronym><acronymword>GNU</acronymword></acronym> C/C++ compilers (<command>gcc</command>, <command>g++</command>. These <acronym><acronymword>GNU</acronymword></acronym> compilers may be used to build the netCDF distribution itself.</para></footnote>, the compilation process is very similar to installing <acronym><acronymword>NCO</acronymword></acronym> on a <acronym><acronymword>UNIX</acronymword></acronym> system. <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>Symbolic Links</nodename>
    <nodenext>Libraries</nodenext>
    <nodeprev>Compatability</nodeprev>
    <nodeup>Introduction</nodeup>
    <section>
      <title>Symbolic Links</title>
      <para><indexterm index="cp">symbolic links</indexterm><acronym><acronymword>NCO</acronymword></acronym> relies on a common set of underlying algorithms. To minimize duplication of source code, multiple operators sometimes share the same underlying source. This is accomplished by symbolic links from a single underlying executable program to one or more invoked executable names. For example, <command>ncea</command> and <command>ncrcat</command> are symbolically linked to the <command>ncra</command> executable. The <command>ncra</command> executable behaves slightly differently based on its invocation name (i.e., <samp>argv[0]</samp>), which can be <command>ncea</command>, <command>ncra</command>, or <command>ncrcat</command>. Logically, these are three different operators that happen to share the same executable.</para>
      <para><indexterm index="cp">Cygwin</indexterm><indexterm index="cp">synonym</indexterm><indexterm index="cp">pseudonym</indexterm><indexterm index="cp"><code>--pseudonym</code></indexterm>For historical reasons, and to be more user friendly, multiple synonyms (or pseudonyms) may refer to the same operator invoked with different switches. For example, <command>ncdiff</command> is the same as <command>ncbo</command> and <command>ncpack</command> is the same as <command>ncpdq</command>. We implement the symbolic links and synonyms by the executing the following <acronym><acronymword>UNIX</acronymword></acronym> commands in the directory where the <acronym><acronymword>NCO</acronymword></acronym> executables are installed.</para>
      <example xml:space="preserve">ln -s -f ncbo ncdiff    # ncbo --op_typ='+'
ln -s -f ncra ncecat    # ncra --pseudonym='ncecat'
ln -s -f ncra ncrcat    # ncra --pseudonym='ncrcat'
ln -s -f ncbo ncadd     # ncbo --op_typ='+'
ln -s -f ncbo ncsubtract # ncbo --op_typ='-'
ln -s -f ncbo ncmultiply # ncbo --op_typ='*'
ln -s -f ncbo ncdivide   # ncbo --op_typ='/'
ln -s -f ncpdq ncpack    # ncpdq
ln -s -f ncpdq ncunpack  # ncpdq --unpack
# NB: Cygwin executable (and link) names have an '.exe' suffix, e.g.,
ln -s -f ncbo.exe ncdiff.exe
...</example>
      <para>The imputed command called by the link is given after the comment. As can be seen, some these links impute the passing of a command line argument to further modify the behavior of the underlying executable. For example, <command>ncdivide</command> is a pseudonym for <command>ncbo --op_typ='/'</command>.</para>
    </section>
  </node>
  <node>
    <nodename>Libraries</nodename>
    <nodenext>netCDF2/3/4 and HDF4/5 Support</nodenext>
    <nodeprev>Symbolic Links</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, released in May, 2007, added support for all netCDF4 atomic data types except <code>NC_STRING</code>. Support for <code>NC_STRING</code>, including ragged arrays of strings, was finally added in version 3.9.9, released in June, 2009. Support for additional netCDF4 features has been incremental. We add one netCDF4 feature at a time. You must build <acronym><acronymword>NCO</acronymword></acronym> with netCDF4 to obtain this support.</para>
      <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, Lempel-Ziv compression (deflation), and chunking. The new atomic data types are <code>NC_UBYTE</code>, <code>NC_USHORT</code>, <code>NC_UINT</code>, <code>NC_INT64</code>, and <code>NC_UINT64</code>. Eight-byte integer support is an especially useful improvement from netCDF3. All <acronym><acronymword>NCO</acronymword></acronym> operators support these types, e.g., <command>ncks</command> copies and prints them, <command>ncra</command> averages them, and <command>ncap2</command> processes algebraic scripts with them. <command>ncks</command> prints compression information, if any, to screen.</para>
      <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 in <command>ncks</command> and <command>ncecat</command>. <acronym><acronymword>NCO</acronymword></acronym> version 4.0.4 (September, 2010) completed support for netCDF4 chunking in the remaining operators. See <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>As of 2010, netCDF4 is still relatively new software. Problems with netCDF4 and <acronym><acronymword>HDF</acronymword></acronym> libraries are still being fixed. Binary <acronym><acronymword>NCO</acronymword></acronym> distributions shipped as <acronym><acronymword>RPM</acronymword></acronym>s use the netCDF4 library, while debs use the netCDF3 library, because of upstream requirements.</para>
      <para><indexterm index="cp"><code>NETCDF4_ROOT</code></indexterm>One must often build <acronym><acronymword>NCO</acronymword></acronym> from source to obtain netCDF4 support. Typically, one specifies the root of the netCDF4 installation directory. Do this with the <code>NETCDF4_ROOT</code> variable. Then use your preferred <acronym><acronymword>NCO</acronymword></acronym> build mechanism, e.g.,</para>
      <example 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>We carefully track the netCDF4 releases, and keep the netCDF4 atomic type support and other features working. Our long term goal is to utilize more of the extensive new netCDF4 feature set. The next major netCDF4 feature we are likely to utilize is parallel I/O. We will enable this in the <acronym><acronymword>MPI</acronymword></acronym> netCDF operators.</para>
    </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://sourceforge.net/projects/nco/forums/forum/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://sourceforge.net/projects/nco/forums/forum/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 variables</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. The length along the record dimension of the output is the sum of the lengths of the input files. Appending, on the other hand, refers to copying a variable from one file to another file which may or may not already contain the variable <footnote><para>Yes, the terminology is confusing. By all means mail me if you think of a better nomenclature. Should <acronym><acronymword>NCO</acronymword></acronym> use <dfn>paste</dfn> instead of <dfn>append</dfn>? </para></footnote>. <acronym><acronymword>NCO</acronymword></acronym> can append or concatenate just one variable, or all the variables in a file at the same time.</para>
      <para>In this sense, <command>ncks</command> can append variables from one file to another file. This capability is invoked by naming two files on the command line, <var>input-file</var> and <var>output-file</var>. When <var>output-file</var> already exists, the user is prompted whether to <dfn>overwrite</dfn>, <dfn>append/replace</dfn>, or <dfn>exit</dfn> from the command. Selecting <dfn>overwrite</dfn> tells the operator to erase the existing <var>output-file</var> and replace it with the results of the operation. Selecting <dfn>exit</dfn> causes the operator to exit&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>Rebasing Time Coordinate</menunode>
          <menutitle>Rebasing Time Coordinate</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>MD5 digests</menunode>
          <menutitle>MD5 digests</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Buffer sizes</menunode>
          <menutitle>Buffer sizes</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>ncap2</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>ncap2</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). Techniques to augment these methods to specify arbitrary numbers (e.g., thousands) and patterns of filenames are discussed separately (see <xref><xrefnodename>Large Numbers of Files</xrefnodename></xref>).</para>
      <para>To illustrate these methods, consider the simple problem of using <command>ncra</command> to average five input files, <file>85.nc</file>, <file>86.nc</file>, &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>
      <para>Users should specify <var>fl_out</var> using either but not both methods. If <var>fl_out</var> is specified twice (once with the switch and once as the last positional argument), then the positional argument takes precedence.</para>
    </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"><code>wget</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"><acronym><acronymword>HPSS</acronymword></acronym></indexterm><indexterm index="cp"><command>hsi</command></indexterm><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 a High Performance Storage System (<acronym><acronymword>HPSS</acronymword></acronym>) (such as that at <acronym><acronymword>NCAR</acronymword></acronym>, <acronym><acronymword>ECMWF</acronymword></acronym>, <acronym><acronymword>LANL</acronymword></acronym>, <acronym><acronymword>DKRZ</acronymword></acronym>, <acronym><acronymword>LLNL</acronymword></acronym>) specify the full <acronym><acronymword>HPSS</acronymword></acronym> pathname of the remote file. <acronym><acronymword>NCO</acronymword></acronym> will attempt to detect whether the local machine has direct (synchronous) <acronym><acronymword>HPSS</acronymword></acronym> access. In this case, <acronym><acronymword>NCO</acronymword></acronym> attempts to use the Hierarchical Storage Interface (<acronym><acronymword>HSI</acronymword></acronym>) command <command>hsi get</command> <footnote><para>The <command>hsi</command> command must be in the user's path in one of the following directories: <code>/usr/local/bin</code> or <code>/opt/hpss/bin</code>. Tell us if the <acronym><acronymword>HPSS</acronymword></acronym> installation at your site places the <command>hsi</command> command in a different location, and we will add that location to the list of acceptable paths to search for <command>hsi</command>. </para></footnote>.</para>
      <para>The following examples show how one might analyze files stored on remote systems. 
<!-- HPSS syntax at http://www2.cisl.ucar.edu/docs/hpss/hsi --></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 . /home/zender/nco/in.nc
ncks -l . http://motherlode.ucar.edu:8080/thredds/dodsC/testdods/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 <acronym><acronymword>HPSS</acronymword></acronym> <command>hsi get</command> command <footnote><para><acronym><acronymword>NCO</acronymword></acronym> supported the old <acronym><acronymword>NCAR</acronymword></acronym> Mass Storage System (<acronym><acronymword>MSS</acronymword></acronym>) until version 4.0.7 in April, 2011. <acronym><acronymword>NCO</acronymword></acronym> supported <acronym><acronymword>MSS</acronymword></acronym>-retrievals via a variety of mechanisms including the <command>msread</command>, <command>msrcp</command>, and <command>nrnet</command> commands invoked either automatically or with sentinels like <command>ncks -p mss:/ZENDER/nco -l . in.nc</command>. Once the <acronym><acronymword>MSS</acronymword></acronym> was decommissioned in March, 2011, support for these retrieval mechanisms was removed from <acronym><acronymword>NCO</acronymword></acronym>. </para></footnote>. The sixth command works if your local version of <acronym><acronymword>NCO</acronymword></acronym> is <acronym><acronymword>OPeNDAP</acronymword></acronym>-enabled (this is fully described in <xref><xrefnodename>OPeNDAP</xrefnodename></xref>), or if the remote file is accessible via <command>wget</command>. The above commands can be rewritten using the <samp>-p <var>input-path</var></samp> option as follows: <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 /home/zender/nco -l . in.nc # HPSS
ncks -p http://motherlode.ucar.edu:8080/thredds/dodsC/testdods \
     -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. It has no effect on locally-retrieved files, or on the output file. Often the path to a remotely retrieved file is quite different than the path on the local machine where you would like to store the file. If <samp>-l</samp> is not specified then <acronym><acronymword>NCO</acronymword></acronym> internally generates an <var>output-path</var> by simply setting <var>output-path</var> equal to <var>input-path</var> stripped of any machine names. If <samp>-l</samp> is not specified and the remote file resides on the <acronym><acronymword>NCAR</acronymword></acronym> <acronym><acronymword>HPSS</acronymword></acronym> system, then the leading character of <var>input-path</var>, <samp>/</samp>, is also stripped from <var>output-path</var>. Specifying <var>output-path</var> as <samp>-l ./</samp> tells <acronym><acronymword>NCO</acronymword></acronym> to store the remotely retrieved file and the output file in the current directory. Note that <samp>-l .</samp> is equivalent to <samp>-l ./</samp> though the latter is syntactically more clear.</para>
      <menu>
        <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 -o ~/foo.nc -C -H -v one -l /tmp \
  -p http://motherlode.ucar.edu:8080/thredds/dodsC/testdods in.nc
% 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. With minor changes to the above command, netCDF4 can be used as both the input and output file format:</para>
      <example xml:space="preserve">% ncks -4 -O -o ~/foo.nc -C -H -v one -l /tmp \
  -p http://motherlode.ucar.edu:8080/thredds/dodsC/testdods in_4.nc
% ncks -H -v one ~/foo.nc
one = 1</example>
      <para>And, of course, <acronym><acronymword>OPeNDAP</acronymword></acronym>-enabled <acronym><acronymword>NCO</acronymword></acronym> clients continue to support other, orthogonal features such as UDUnits (see <xref><xrefnodename>UDUnits Support</xrefnodename></xref>):</para>
      <example xml:space="preserve">% ncks -u -C -H -v wvl -d wvl,'0.4 micron','0.7 micron' \
  -p http://motherlode.ucar.edu:8080/thredds/dodsC/testdods in_4.nc
% wvl[0]=5e-07 meter</example>
      <para>The next command is a more advanced example which demonstrates the real power of <acronym><acronymword>OPeNDAP</acronymword></acronym>-enabled <acronym><acronymword>NCO</acronymword></acronym> clients. The <command>ncwa</command> client requests an equatorial hyperslab from remotely stored <acronym><acronymword>NCEP reanalyses data</acronymword></acronym> of the 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.esrl.noaa.gov/psd/thredds/dodsC/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.esrl.noaa.gov/psd/thredds/dodsC/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 a few more years, 2013&ndash;2014, 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>grep -E</command></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>POSIX</acronymword></acronym> <command>grep -E</command> (aka <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 '.+' in.nc               # All variables
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 be placed in the <var>output-file</var>, even if they are not explicitly specified, e.g., with the <samp>-v</samp> switch. Thus variables with a latitude coordinate <code>lat</code> always carry the values of <code>lat</code> with them into the <var>output-file</var>. This 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>As of <acronym><acronymword>NCO</acronymword></acronym> version 3.9.6 (January, 2009) both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code> convention described in <xref><xrefnodename>CF Conventions</xrefnodename></xref>. As of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.8 (April, 2011) both <samp>-c</samp> and <samp>-C</samp> honor the <acronym><acronymword>CF</acronymword></acronym> <code>bounds</code> convention described in <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 the 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.5/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: type NC_FLOAT, 2 dimensions, 4 attributes, chunked? no, compressed? no, packed? no, ID = 41
gds_3dvar RAM size is 10*8*sizeof(NC_FLOAT) = 80*4 = 320 bytes
gds_3dvar dimension 0: time, size = 10 NC_DOUBLE, dim. ID = 20 (CRD)(REC)
gds_3dvar dimension 1: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
gds_3dvar attribute 0: long_name, size = 17 NC_CHAR, value = Geodesic variable
gds_3dvar attribute 1: units, size = 5 NC_CHAR, value = meter
gds_3dvar attribute 2: coordinates, size = 15 NC_CHAR, value = lat_gds lon_gds
gds_3dvar attribute 3: purpose, size = 64 NC_CHAR, value = Test auxiliary coordinates like those that define geodesic grids</example>
      <para>The <code>coordinates</code> attribute lists the names of the latitude and longitude coordinates, <code>lat_gds</code> and <code>lon_gds</code>, respectively. The <code>coordinates</code> attribute is recommended though optional. With it, the user can immediately identify which variables contain the latitude and longitude coordinates. Without a <code>coordinates</code> attribute it would be unclear at first glance whether a variable resides on a cell-based grid. In this example, <code>time</code> is a normal record dimension and <code>gds_crd</code> is the cell-based dimension.</para>
      <para>The cell-based grid file must contain two variables whose <code>standard_name</code> attributes are &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: type NC_DOUBLE, 1 dimensions, 4 attributes, chunked? no, compressed? no, packed? no, ID = 37
lat_gds RAM size is 8*sizeof(NC_DOUBLE) = 8*8 = 64 bytes
lat_gds dimension 0: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
lat_gds attribute 0: long_name, size = 8 NC_CHAR, value = Latitude
lat_gds attribute 1: standard_name, size = 8 NC_CHAR, value = latitude
lat_gds attribute 2: units, size = 6 NC_CHAR, value = degree
lat_gds attribute 3: purpose, size = 62 NC_CHAR, value = 1-D latitude coordinate referred to by geodesic grid variables

lon_gds: type NC_DOUBLE, 1 dimensions, 4 attributes, chunked? no, compressed? no, packed? no, ID = 38
lon_gds RAM size is 8*sizeof(NC_DOUBLE) = 8*8 = 64 bytes
lon_gds dimension 0: gds_crd, size = 8 NC_FLOAT, dim. ID = 17 (CRD)
lon_gds attribute 0: long_name, size = 9 NC_CHAR, value = Longitude
lon_gds attribute 1: standard_name, size = 9 NC_CHAR, value = longitude
lon_gds attribute 2: units, size = 6 NC_CHAR, value = degree
lon_gds attribute 3: purpose, size = 63 NC_CHAR, value = 1-D longitude coordinate referred to by geodesic grid variables</example>
      <para>In this example <code>lat_gds</code> and <code>lon_gds</code> represent the latitude or longitude, respectively, of cell-based variables. These coordinates (must) have the same single dimension (<code>gds_crd</code>, in this case) as the cell-based variables. And the coordinates must be one-dimensional&mdash;multidimensional coordinates will not work.</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 grid 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>Rebasing Time Coordinate</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 4 PM<!-- /@w --> and 7 PM<!-- /@w --> on December 8<!-- /@w -->, 1999, from a variable whose time dimension is hours since the year 1900:</para>
      <example xml:space="preserve">% ncks -u -H -C -v time_udunits -d time_udunits,"1999-12-08 \
  16:00:0.0","1999-12-08 19:00:0.0" in.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.</para>
      <para>One aspect that deserves mention is that UDUnits, and thus <acronym><acronymword>NCO</acronymword></acronym>, supports run-time definition of the location of the relevant UDUnits databases. With UDUnits version 1<!-- /@w -->, users may specify the directory which contains the UDUnits database, <file>udunits.dat</file>, via the <code>UDUNITS_PATH</code> environment variable. With UDUnits version 2<!-- /@w -->, users may specify the UDUnits database file itself, <file>udunits2.xml</file>, via the <code>UDUNITS2_XML_PATH</code> environment variable.</para>
      <example xml:space="preserve">export UDUNITS_PATH='/nonstandard/location/share/udunits' # UDUnits1
export UDUNITS2_XML_PATH='/nonstandard/location/share/udunits/udunits2.xml' # UDUnits2</example>
      <para>This run-time flexibility can enable the full functionality of pre-built binaries on machines with libraries in different locations.</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://cf-pcmdi.llnl.gov</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 role="continues">As of version 4.0.0 (January, 2010), <acronym><acronymword>NCO</acronymword></acronym> supports some calendar attributes specified by the CF conventions.</para>
      <table>
        <tableitem>
          <tableterm><strong>Supported types:  </strong></tableterm>
          <item>
 
            <para>"365_day"/"noleap", "360_day", "gregorian", "standard"</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><strong>Unsupported types:</strong></tableterm>
          <item>
            <para>"366_day"/"all_leap","proleptic_gregorian","julian","none"</para>
          </item>
        </tableitem>
      </table>
      <para>Unsupported types default to mixed Gregorian/Julian as defined by UDUnits.</para>
      <para role="continues">An Example: Consider the following netCDF variable</para>
      <example xml:space="preserve">variables:
  double lon_cal(lon_cal) ;
    lon_cal:long_name = "lon_cal" ;
    lon_cal:units = "days since 1964-2-28 0:0:0" ;
    lon_cal:calendar = "365_day" ;
data:
  lon_cal = 1,2,3,4,5,6,7,8,9,10;

So the command
"ncks -v lon_cal -d lon_cal,'1964-3-1 0:00:0.0','1964-3-4 00:00:0.0' in.nc out.nc"
Results in the hyperslab lon_cal=1,2,3,4</example>
      <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>Rebasing Time Coordinate</nodename>
    <nodenext>Missing Values</nodenext>
    <nodeprev>UDUnits Support</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Rebasing Time Coordinate</title>
      <cartouche>
        <para>Availability: <command>ncra</command>, <command>ncrcat</command> Short options: None&linebreak;</para>
      </cartouche>
      <para>Time re-basing is performed automatically when UDUnits is installed. Time rebasing is invoked when numerous files share a common time-based record coordinate, and the record coordinate is in the same time units in each file, but the date offset differs among files. For example suppose the time coordinate is in hours and each day in January is stored in its own daily file. Each daily file records the temperature variable <code>tpt(time)</code> with an (unadjusted) <code>time</code> coordinate value between 0&ndash;23 hours, and uses the <code>units</code> attribute to advance the base time:</para>
      <example xml:space="preserve">file01.nc time:units="hours since 1990-1-1"
file02.nc time:units="hours since 1990-1-2"
...
file31.nc time:units="hours since 1990-1-31"</example>
      <para role="continues"></para>
      <example xml:space="preserve">// Find mean noontime temperature in January
ncra -v tpt -d time,"1990-1-1 12:00:00","1990-1-31 23:59:59",24 \
      file??.nc noon.nc

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

// Results: time is "re-based" to the time units in "file01.nc"
time=36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
     53, 54, 55, 56, 57, 58, 59 ;

// If we repeat the above command but with only two input files...
ncrcat -v tpt -d time,"1990-1-2 12:00:00","1990-1-3 11:59:59" \
      file02.nc file03 noon.nc

// ...then the output time coordinate is based on the time units in "file02.nc"
time = 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
    29, 30, 31, 32, 33, 34, 35 ;</example>
    </section>
  </node>
  <node>
    <nodename>Missing Values</nodename>
    <nodenext>Chunking</nodenext>
    <nodeprev>Rebasing Time Coordinate</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 <acronym><acronymword>NCO</acronymword></acronym> once applied to <var>missing_value</var> it now applies to any <var>_FillValue</var>. <acronym><acronymword>NCO</acronymword></acronym> now treats any <var>missing_value</var> as normal data <footnote><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 used as many times as necessary.</para>
      <example xml:space="preserve"># Simple chunking and unchunking
ncks -O -4 --cnk_plc=all     in.nc out.nc # Chunk in.nc
ncks -O -4 --cnk_plc=unchunk in.nc out.nc # Unchunk in.nc

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

# More complex chunking procedures, with informative metadata
ncks -O -4 -D 4 --cnk_scl=8 ~/nco/data/in.nc ~/foo.nc
ncks -O -4 -D 4 --cnk_scl=8 /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,32 --cnk_dmn lon,128 /data/zender/dstmch90/dstmch90_clm_0112.nc ~/foo.nc

# Chunking works with all operators...
ncap2 -O -4 -D 4 --cnk_scl=8 -S ~/nco/data/ncap2_tst.nco ~/nco/data/in.nc ~/foo.nc
ncbo -O -4 -D 4 --cnk_scl=8 -p ~/nco/data in.nc in.nc ~/foo.nc
ncecat -O -4 -D 4 -n 12,2,1 --cnk_dmn lat,32 -p /data/zender/dstmch90 dstmch90_clm01.nc ~/foo.nc
ncflint -O -4 -D 4 --cnk_scl=8 ~/nco/data/in.nc ~/foo.nc
ncpdq -O -4 -D 4 -P all_new --cnk_scl=8 -L 5 ~/nco/data/in.nc ~/foo.nc
ncrcat -O -4 -D 4 -n 12,2,1 --cnk_dmn lat,32 -p /data/zender/dstmch90 dstmch90_clm01.nc ~/foo.nc
ncwa -O -4 -D 4 -a time --cnk_plc=g2d --cnk_map=rd1 --cnk_dmn lat,32 --cnk_dmn lon,128 /data/zender/dstmch90/dstmch90_clm_0112.nc ~/foo.nc</example>
      <para><indexterm index="cp">record dimension</indexterm>It is appropriate to conclude by informing users about an aspect of chunking that may not be expected: Record dimensions are always chunked with a chunksize of one. Hence all variables that contain the record dimension are also stored as chunked (since data must be stored with chunking either in all dimensions, or in no dimensions). Unless otherwise specified by the user, the other (fixed, non-record) dimensions of such variables are assigned default chunk sizes. The <acronym><acronymword>HDF5</acronymword></acronym> layer does all this automatically to optimize the on-disk variable/file storage geometry of record variables. Do not be surprised to learn that files created without any explicit instructions to activate chunking nevertheless contain chunked variables.</para>
    </section>
  </node>
  <node>
    <nodename>Deflation</nodename>
    <nodenext>MD5 digests</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>MD5 digests</nodename>
    <nodenext>Buffer sizes</nodenext>
    <nodeprev>Deflation</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>MD5 digests</title>
      <para><indexterm index="cp"><code>--md5_digest</code></indexterm><indexterm index="cp">integrity</indexterm><indexterm index="cp">security</indexterm><indexterm index="cp">digest</indexterm><indexterm index="cp">hash</indexterm><indexterm index="cp">MD5 digest</indexterm></para>
      <cartouche>
        <para>Availability: <command>ncecat</command>, <command>ncks</command>, <command>ncrcat</command>&linebreak; Short options: &linebreak; Long options: <samp>--md5_digest</samp>&linebreak;</para>
      </cartouche>
      <para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.1.0 (April, 2012), <acronym><acronymword>NCO</acronymword></acronym> supports data integrity verification using the <acronym><acronymword>MD5</acronymword></acronym> digest algorithm. This support is currently implemented in the multifile concantenators (<command>ncecat</command> and <command>ncrcat</command>) and <command>ncks</command>. Activate it with the <samp>--md5_digest</samp> long option.</para>
      <para>The behavior and verbosity of the <acronym><acronymword>MD5</acronymword></acronym> digest is operator-dependent. When activating <acronym><acronymword>MD5</acronymword></acronym> digests with <command>ncks</command> it is assumed that the user simply wishes to see the digest of every variable and this is done when the debugging level exceeds one. This incurs the minor overhead of performing the hash algorithm for each variable read. <acronym><acronymword>MD5</acronymword></acronym> digests may be activated in both the one- and two-filename argument forms of <command>ncks</command>, which are used for printing and sub-setting, respectively. The <acronym><acronymword>MD5</acronymword></acronym> digests are shown as a 32-character hexadecimal string in which each two characters represent one byte of the 16-byte digest:</para>
      <example xml:space="preserve">&gt; ncks -O -D 2 -C --md5 -v md5_a,md5_abc ~/nco/data/in.nc
...
ncks: INFO MD5(md5_a) = 0cc175b9c0f1b6a831c399e269772661
md5_a = 'a'
ncks: INFO MD5(md5_abc) = 900150983cd24fb0d6963f7d28e17f72
lev[0]=100 md5_abc[0--2]='abc'
&gt; ncks -O -D 2 -C -d lev,0 --md5 -v md5_a,md5_abc ~/nco/data/in.nc
...
cks: INFO MD5(md5_a) = 0cc175b9c0f1b6a831c399e269772661
md5_a = 'a'
ncks: INFO MD5(md5_abc) = 0cc175b9c0f1b6a831c399e269772661
lev[0]=100 md5_abc[0--0]='a'</example>
      <para>In fact these examples demonstrate the validity of the hash algorithm since the <acronym><acronymword>MD5</acronymword></acronym> hashes of the strings &ldquo;a&rdquo; and &ldquo;abc&rdquo; are widely known. The second example shows that the hyperslab of variable <code>md5_abc</code> (= &ldquo;abc&rdquo;) consisting of only its first letter (= &ldquo;a&rdquo;) has the same hash as the variable <code>md5_a</code> (&ldquo;a&rdquo;). This illustrates that <acronym><acronymword>MD5</acronymword></acronym> digests acts only on variable data, not on metadata.</para>
      <para>When activating <acronym><acronymword>MD5</acronymword></acronym> digests with <command>ncecat</command> or <command>ncrcat</command> it is assumed that the user wishes to verify that every variable written to disk has the same <acronym><acronymword>MD5</acronymword></acronym> digest as when it is subsequently read from disk. This incurs the major additional overhead of reading in each variable after it is written and performing the hash algorithm again on that to compare to the original hash. Moreover, it is assumed that such operations are generally done &ldquo;production mode&rdquo; where the user is not interested in actually examining the digests herself. The digests proceed silently unless the debugging level exceeds three:</para>
      <example xml:space="preserve">&gt; ncecat -O -D 4 --md5 -p ~/nco/data in.nc in.nc ~/foo.nc | grep MD5
...
ncecat: INFO MD5(wnd_spd) = bec190dd944f2ce2794a7a4abf224b28
ncecat: INFO MD5 digests of RAM and disk contents for wnd_spd agree
&gt; ncrcat -O -D 4 --md5 -p ~/nco/data in.nc in.nc ~/foo.nc | grep MD5
...
ncrcat: INFO MD5(wnd_spd) = 74699bb0a72b7f16456badb2c995f1a1
ncrcat: INFO MD5 digests of RAM and disk contents for wnd_spd agree</example>
      <para>Regardless of the debugging level, an error will be returned if the digests of the variable read from the source file and from the output file do not agree.</para>
      <para>These rules are evolving and as <acronym><acronymword>NCO</acronymword></acronym> pays more attention to data integrity. We welcome feedback and suggestions from users.</para>
    </section>
  </node>
  <node>
    <nodename>Buffer sizes</nodename>
    <nodenext>Packed data</nodenext>
    <nodeprev>MD5 digests</nodeprev>
    <nodeup>Common features</nodeup>
    <section>
      <title>Buffer sizes</title>
      <para><indexterm index="cp"><code>--bfr_sz_hnt</code></indexterm><indexterm index="cp">Buffer sizes</indexterm><indexterm index="cp">File buffers</indexterm><indexterm index="cp"><command>stat() system call</command></indexterm><indexterm index="cp">I/O block size</indexterm><indexterm index="cp">System calls</indexterm></para>
      <cartouche>
        <para>Availability: All operators&linebreak; Short options: &linebreak; Long options: <samp>--bfr_sz_hnt</samp>, <samp>--buffer_size_hint</samp>&linebreak;</para>
      </cartouche>
      <para>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.1.1 (May, 2012), <acronym><acronymword>NCO</acronymword></acronym> allows the user to request specific buffer sizes to allocate for reading and writing files. This buffer size determines how many system calls the netCDF layer must invoke to read and write files. By default, netCDF uses the preferred I/O block size returned as the <samp>st_blksize</samp> member of the <samp>stat</samp> structure returned by the <command>stat()</command> system call. Otherwise, netCDF uses twice the system pagesize. Because netCDF cannot guarantee the buffer size request will be met, the actual buffer size granted by the system is printed as an INFO statement:</para>
      <example xml:space="preserve"># Request 2 MB file buffer instead of default 8 kB buffer
&gt; ncks -O -D 3 --bfr_sz=2097152 ~/nco/data/in.nc ~/foo.nc
p...
ncks: INFO nc__open() will request file buffer size = 2097152 bytes
ncks: INFO nc__open() opened file with buffer size = 2097152 bytes
...</example>
    </section>
  </node>
  <node>
    <nodename>Packed data</nodename>
    <nodenext>Operation Types</nodenext>
    <nodeprev>Buffer sizes</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 two less than the theoretical maximum. This leaves space for a missing value and solves potential problems with rounding that may occur during the unpacking of the variable. Thus for <code>NC_SHORT</code>, <math>ndrv = 65536 - 2 = 65534</math>. Less often, the variable may be packed into type <code>NC_CHAR</code>, where <math>ndrv = 256 - 2 = 254</math>, or type <code>NC_INT</code> where where <math>ndrv = 4294967295 - 2 = 4294967293</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 foo3.nc
ncra -O -y rmssdn foo3.nc out.nc</example>
      <para>The first step assembles all the data into a single file. Though this may consume a lot of temporary disk space, it is more or less required by the <command>ncbo</command> operation in the third step.</para>
    </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. NB: As of 20120515, <command>ncap2</command> is unable to append to files that already contain the appended dimensions.</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>ncpdq</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 applies special rules to such data. <acronym><acronymword>NCO</acronymword></acronym> also 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 <uref><urefurl>http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/cf-conventions.html#coordinate-system</urefurl><urefdesc>here</urefdesc></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> applies special rules to certain variables in <acronym><acronymword>CF</acronymword></acronym> files. The special functions are not required by the <acronym><acronymword>CF</acronymword></acronym> netCDF conventions, yet experience shows that 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 (case-insensitively) whether the value of the global attribute <code>Conventions</code> (if any) equals <samp>CF-1.0</samp> or <samp>NCAR-CSM</samp> Should <code>Conventions</code> equal either of these in the (first) <var>input-file</var>, <acronym><acronymword>NCO</acronymword></acronym> will apply special rules to certain variables because of their usual meaning in <acronym><acronymword>CF</acronymword></acronym> files. <acronym><acronymword>NCO</acronymword></acronym> will not average the following variables often found in <acronym><acronymword>CF</acronymword></acronym> files: <code>ntrm</code>, <code>ntrn</code>, <code>ntrk</code>, <code>ndbase</code>, <code>nsbase</code>, <code>nbdate</code>, <code>nbsec</code>, <code>mdt</code>, <code>mhisf</code>. These variables contain scalar metadata such as the resolution of the host geophysical model and it makes no sense to change their values.</para>
      <para><indexterm index="cp">non-coordinate grid properties</indexterm>Furthermore, the <dfn>size and rank-preserving arithmetic operators</dfn> try not to operate on certain grid properties. These operators are <command>ncap2</command>, <command>ncbo</command>, <command>ncea</command>, <command>ncflint</command>, and <command>ncpdq</command> (when used for packing, not for permutation). These operators do not operate, by default, on (i.e., add, subtract, pack, etc.) the following variables: <code>ORO</code>, <code>area</code>, <code>datesec</code>, <code>date</code>, <code>gw</code>, <code>hyai</code>, <code>hyam</code>, <code>hybi</code>. <code>hybm</code>, <code>lat_bnds</code>, <code>lon_bnds</code>, <code>msk_*</code>. 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>bounds</code></indexterm><indexterm index="cp">bounds convention</indexterm>As of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.8 (April, 2011), <acronym><acronymword>NCO</acronymword></acronym> supports the <acronym><acronymword>CF</acronymword></acronym> <code>bounds</code> convention for cell boundaries described <uref><urefurl>http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/cf-conventions.html#cell-boundaries</urefurl><urefdesc>here</urefdesc></uref>. This convention allows coordinate variables (including multidimensional coordinates) to describe the boundaries of their cells. This is done by naming the variable which contains the bounds in in the <code>bounds</code> attribute. Note that coordinates of rank <math>N</math> have bounds of rank <math>N+1</math>. NCO-generated subsets of <acronym><acronymword>CF</acronymword></acronym>-compliant files with <code>bounds</code> attributes will include the coordinates specified by the <code>bounds</code> attribute, if any. Hence the subsets will themselves be <acronym><acronymword>CF</acronymword></acronym>-compliant.</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>As of <acronym><acronymword>NCO</acronymword></acronym> version 3.9.6 (January, 2009), <acronym><acronymword>NCO</acronymword></acronym> supports the <acronym><acronymword>CF</acronymword></acronym> <code>coordinates</code> convention described <uref><urefurl>http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/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] [-6] [<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 2012.</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. <indexterm index="cp">appending variables</indexterm>NB: As of 20120515, <command>ncap2</command> is unable to append to files that already contain the appended dimensions.</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>Sort methods</menunode>
          <menutitle>Sort methods</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Irregular grids</menunode>
          <menutitle>Irregular grids</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Bilinear interpolation</menunode>
          <menutitle>Bilinear interpolation</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>GSL special functions</menunode>
          <menutitle>GSL special functions</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>GSL interpolation</menunode>
          <menutitle>GSL interpolation</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>GSL least-squares fitting</menunode>
          <menutitle>GSL least-squares fitting</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>GSL statistics</menunode>
          <menutitle>GSL statistics</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>GSL random number generation</menunode>
          <menutitle>GSL random number generation</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>
      <para>The only exception to this rule of attribute propagation is in cases of left hand casting (see <xref><xrefnodename>Left hand casting</xrefnodename></xref>). The user must manually define the proper metadata for variables defined using left hand casting.</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; 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> 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>
      <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 a 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 Clipping&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 Clipping&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:</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 in <command>ncap2</command></indexterm><indexterm index="cp">defdim()</indexterm>Dimensions are defined in Output using the <code>defdim()</code> function.</para>
      <example xml:space="preserve">defdim("cnt",10);</example>
      <para>This dimension name must then be prefixed with a dollar-sign <samp>$</samp> when referred to in method arguments or left-hand-casting, e.g.,</para>
      <example xml:space="preserve">new_var[$cnt]=time;
temperature[$time,$lat,$lon]=35.5;
temp_avg=temperature.avg($time);</example>
      <para>The <code>size</code> method allows the dimension size to be used in an arithmetic expression:</para>
      <example xml:space="preserve">time_avg=time.total() / $time.size;</example>
      <para>Increase the size of a new variable by one and set new member to zero:</para>
      <example xml:space="preserve">defdim("cnt_new",$cnt.size+1);
new_var[$cnt_new]=0.0;
new_var(0:($cnt_new.size-2))=old_var;</example>
      <para role="continues"><strong>Dimension Abbreviations &linebreak;</strong> It is possible to use dimension abbreviations as method arguments:&linebreak; <code>$0</code> is the first dimension of a variable&linebreak; <code>$1</code> is the second dimension of a variable&linebreak; <code>$n</code> is the n+1 dimension of a variable&linebreak;</para>
      <example 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 dimension 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">array</indexterm><indexterm index="cp"><code>array</code> function</indexterm><indexterm index="cp">arrays</indexterm><indexterm index="cp">findgen-equivalent</indexterm><indexterm index="cp">indgen-equivalent</indexterm>Generating a regularly spaced one-dimensional array with <command>ncap2</command> is simple with the <code>array()</code> function. The syntax is</para>
      <example xml:space="preserve">output=array(val_srt,val_ncr,$dmn_nm); // One-dimensional output
output=array(val_srt,val_ncr,var_tpl);  // Multi-dimensional output
h</example>
      <para role="continues">where the arguments are the starting value <var>val_srt</var>, incremental value <var>val_ncr</var>, and, for one-dimensional output, the single dimension <code>$dmn_nm</code>, or, for multi-dimensional output, a template variable <code>var_tpl</code>, i.e., a variable with the same shape as the desired output.</para>
      <para>Once the associated dimensions have been defined, the start and increment arguments may be supplied as values, mathmatical expressions, or variables:</para>
      <example xml:space="preserve">var_out=array(1,1,$time); // 1,2,3,4,5,6,7,8,9,10
var_out=array(1+2-2,one,$time); // 1,2,3,4,5,6,7,8,9,10
var_out=array(1,2,three_dmn_rec_var); // 1,3,5,...155,157,159</example>
      <para><indexterm index="cp">hyperslabs</indexterm>Hyperslabs in <command>ncap2</command> are more limited than hyperslabs with the other <acronym><acronymword>NCO</acronymword></acronym> operators. <command>ncap2</command> does not understand the shell command-line syntax used to specify multi-slabs, wrapped co-ordinates, negative stride or coordinate value limits. However with a bit of syntactic magic they are all are possible. <command>ncap2</command> accepts (in fact, it requires) <var>N</var>-hyperslab arguments for a variable of rank <var>N</var>:</para>
      <example xml:space="preserve">var1(arg1,arg2 ... argN);</example>
      <para>where each hyperslab argument is of the form</para>
      <example xml:space="preserve">start:end:stride</example>
      <para>and the arguments for different dimensions are separated by commas. If "start" is omitted, it defaults to 0. If "end" is omitted, it defaults to dimension size minus one. If "stride" is omitted, it defaults to 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 (i.e., a cross-section). The number of hyperslab arguments MUST equal the variable's rank.</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 three dimensional 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 hyperslab arguments collapse to a single value (a cross-section has been specified), then that dimension is removed from the returned variable. If all the values collapse then a scalar variable is returned. So, for example, the following is valid:</para>
      <example xml:space="preserve">th_nw=th(0,:,:)+th(9,:,:);
// th_nw has dimensions $lon,$lat
// NB: the time dimension has become degenerate</example>
      <para>The following is invalid:</para>
      <example xml:space="preserve">th_nw=th(0,:,0:1)+th(9,:,0:1);</example>
      <para>because the <code>$lon</code> dimension now only has two elements. The above can be calculated by using a LHS cast with <code>$lon_nw</code> as replacement dim for <code>$lon</code>:</para>
      <example 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. Set all elements of the last record to zero:</para>
      <example xml:space="preserve">th(9,:,:)=0.0;</example>
      <para role="continues">Set first element of each lon element to 1.0:</para>
      <example xml:space="preserve">th(:,:,0)=1.0;</example>
      <para>One may hyperslab on both sides of an assign. For example, this sets the last record to the first record:</para>
      <example xml:space="preserve">th(9,:,:)=th(0,:,:);</example>
      <para>Say <var>th0</var> represents pressure at height=0 and <var>th1</var> represents pressure at height=1. Then it is possible to insert these hyperslabs into the records</para>
      <example xml:space="preserve">prs[$time,$height,$lat,$lon]=0.0;
prs(:,0,:,:)=th0;
prs(:,1,:,:)=th1</example>
      <para role="continues"><strong>Reverse method</strong> &linebreak; <indexterm index="cp">reverse()</indexterm>Use the <code>reverse()</code> method to reverse a dimension's elements in a variable with at least one dimension. This is equivalent to 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>Use the <code>permute()</code> method to swap the dimensions of a variable. The number and names of dimension arguments must match the dimensions in the variable. If the first dimension in the variable is of record type then this must remain the first dimension. If you want to change the record dimension then consider using <command>ncpdq</command>.</para>
      <para>Consider the variable:</para>
      <example xml:space="preserve">float three_dmn_var(lat,lev,lon);
three_dmn_var_prm=three_dmn_var.permute($lon,$lat,$lev);
// The permuted values are
three_dmn_var_prm=
  0,4,8,
  12,16,20,
  1,5,9,
  13,17,21,
  2,6,10,
  14,18,22,
  3,7,11,
  15,19,23;</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>ncap2</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 <command>ncdump</command> of the metadata for variable <var>a1</var></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 gets attributes from PO
th_min=1.0 + 2*three_dmn_var_dbl.min($time); // th_min  gets 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>ncap2</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 <acronym><acronymword>NCO</acronymword></acronym> must be compiled/linked to the netCDF4 library and the output file must be <acronym><acronymword>HDF5</acronymword></acronym>.</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>. There is no postfix for characters, use a quoted string instead.</para>
      <example xml:space="preserve">n4[$rlev]=0.1      // n4 will be of type <code>NC_DOUBLE</code>
n5[$lon_grd]=2.0   // n5 will be of type <code>NC_DOUBLE</code>
n6[$gds_crd]=2e3;  // n6 will be of type <code>NC_DOUBLE</code>
n7[$gds_crd]=2e3f;  // n7 will be of type <code>NC_FLOAT</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>, an 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 (4-byte) floating point number</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>d|D</tableterm>
          <item>
  
            <para><code>NC_DOUBLE</code>, a double-precision (8-byte) 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>, an unsigned 1-byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>us|US</tableterm>
          <item>
  
            <para><code>NC_USHORT</code>, an unsigned 2-byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>u|U|ul|UL</tableterm>
          <item>
  
            <para><code>NC_UINT</code>, an unsigned 4-byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>ll|LL</tableterm>
          <item>
  
            <para><code>NC_INT64</code>, a signed 8-byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>ull|ULL</tableterm>
          <item>
  
            <para><code>NC_UINT64</code>, an unsigned 8-byte integer</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 syntax 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>
<!-- Truth -->
      <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"># 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");
}

# 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">// netCDF4 needed for 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>ncap2</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-language style format string argument. Currently the print function cannot print <acronym><acronymword>RAM</acronymword></acronym> variables or expressions such as <code>'print(var_msk*3+4)'</code>. To print an expression, first evaluate it as a non-<acronym><acronymword>RAM</acronymword></acronym> variable (so it will be saved and can be printed), and 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, otherwise the missing value for var2 is used. If during the element-by-element operation an element from either operand is equal to the missing value then the missing value is carried through. In this way missing values 'percolate' or propagate through an expression.&linebreak; Missing values associated with Output variables are stored in memory and are written to disk after the script finishes. During script execution its possible (and legal) for the missing value of a variable to take on several different values.</para>
      <example 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>The convention within this document is that methods can be used as functions. However, functions are not and cannot be used as methods. Methods can be daisy changed together and their syntax is cleaner than functions. Method names are reserved words and CANNOT be used as variable names. The command <code>ncap2 -f</code> shows the complete list of methods available on your build.</para>
      <example xml:space="preserve">n2=sin(theta)
n2=theta.sin()
n2=sin(theta)^2 + cos(theta)^2
n2=theta.sin().pow(2) + theta.cos()^2</example>
      <para>This statement chains methods together to convert three_dmn_var_sht to type double, average it, then convert this 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 (normalize by <var>N</var>)</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>rmssdn()</code></tableterm><indexterm index="cp">rmssdn()</indexterm>
          <item>
            <para>Root-mean square (normalize 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 <acronym><acronymword>RAM</acronymword></acronym> 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 <acronym><acronymword>RAM</acronymword></acronym> 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 <acronym><acronymword>RAM</acronymword></acronym> 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 <acronym><acronymword>NCO</acronymword></acronym> 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>,  an 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 (4-byte) 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 (8-byte) 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>, an unsigned 1-byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>ushort()</code></tableterm><indexterm index="cp">ushort()</indexterm>
          <item>
 
            <para>convert to <code>NC_USHORT</code>, an unsigned 2-byte integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>uint()</code></tableterm><indexterm index="cp">uint()</indexterm>
          <item>
 
            <para>convert to <code>NC_UINT</code>, an unsigned 4-byte integer</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 integer</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>uint64()</code></tableterm><indexterm index="cp">unit64()</indexterm>
          <item>
 
            <para>convert to <code>NC_UINT64</code>, an unsigned 8-byte integer</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>Unlike regular variables, <acronym><acronymword>RAM</acronymword></acronym> variables are never written to disk. Hence using <acronym><acronymword>RAM</acronymword></acronym> variables in place of regular variables (especially within loops) significantly increases execution speed. Variables that are frequently accessed within <code>for</code> or <code>where</code> clauses provide the greatest opportunities for optimization. To declare and define a <acronym><acronymword>RAM</acronymword></acronym> variable simply prefix the variable name with an asterisk (<code>*</code>) when the variable is declared/initialized. To delete a <acronym><acronymword>RAM</acronymword></acronym> variables (and recover their memory) use the <code>ram_delete()</code> method. To write a <acronym><acronymword>RAM</acronymword></acronym> variable to disk (like a regular variable) use <code>ram_write()</code>. <indexterm index="cp">ram_write()</indexterm><indexterm index="cp">ram_delete()</indexterm></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

// Create and increment a RAM variable from "one" in Input
*one++;
// Create RAM variables from the variables three and four in Input.
// Multiply three by 10 and add it to four.
*four+=*three*=10; // three=30, four=34</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 (the 'elsewhere' 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 in the predicate of a where is assign, i.e., 'var=expr'. This assign differs from a regular <command>ncap2</command> assign. The LHS var must already exist in Input or Output. The RHS expression must evaluate to a scalar or a variable/attribute of the same size as the LHS variable.</para>
        </item>
        <item>
          <para>Consider when both the LHS and RHS are variables: For every element where mask condition is True, the corresponding LHS variable element is re-assigned to its partner element on the RHS. In the elsewhere part the mask is logically inverted and the assign process proceeds as before.</para>
        </item>
        <item>
          <para>If the mask dimensions are a subset of the LHS variable's dimensions, then it is made to conform; if it cannot be made to conform then script execution halts.</para>
        </item>
        <item>
          <para>Missing values in the mask evaluate to False in the where code/block statement and to True in the elsewhere block/statement. LHS variable elements set to missing value are not re-assigned. For these reasons, do not explicitly reference missing values in the masking condition, e.g., <code>where(foo=foo.get_missing()) foo=1;</code> will not work as expected.</para>
        </item>
      </itemize>
      <para>Example: Consider the variables <code>float lon_2D_rct(lat,lon);</code> and <code>float var_msk(lat,lon);</code>. Suppose we wish to multiply by two the elements for which <code>var_msk</code> equals 1<!-- /@w -->:</para>
      <example xml:space="preserve">where(var_msk==1) lon_2D_rct=2*lon_2D_rct;</example>
      <para>Suppose that we have the variable <code>int RDM(time)</code> and that we want to set its values less than 8 or greater than 80 to 0<!-- /@w -->:</para>
      <example xml:space="preserve">where(RDM &lt; 8 || RDM &gt; 80) RDM=0;</example>
      <para>Consider irregularly gridded data, described using rank 2<!-- /@w --> coordinates: <code>double lat(south_north,east_west)</code>, <code>double lon(south_north,east_west)</code>, <code>double temperature(south_north,east_west)</code>. To find the average temperature in a region bounded by [<var>lat_min</var>,<var>lat_max</var>] and [<var>lon_min</var>,<var>lon_max</var>]:</para>
      <example 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; 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><command>ncap2</command> supplies <command>for()</command> loops and <command>while()</command> loops. They are completely unoptimized so use them only with <acronym><acronymword>RAM</acronymword></acronym> variables unless you want thrash your disk to death. To break out of a loop use the <command>break</command> command. To iterate to the next cycle use the <command>continue</command> command.</para>
      <example xml:space="preserve">// Set elements in variable double temp(time,lat)
// If element &lt; 0 set to 0, if element &gt; 100 set to 100
*sz_idx=$time.size;
*sz_jdx=$lat.size;

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

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

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

if(idx == sz) print("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>Sort methods</nodenext>
    <nodeprev>Loops</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Include files</title>
      <para><indexterm index="cp"><command>include</command></indexterm>The syntax of an <var>include-file</var> is:</para>
      <example xml:space="preserve">#include "script.nco"</example>
      <para>The script filename is searched relative to the run directory. It is possible to nest include files to an arbitrary depth. A handy use of inlcude files is to store often used constants. Use <acronym><acronymword>RAM</acronymword></acronym> variables if you do not want these constants written to <var>output-file</var>.</para>
      <example xml:space="preserve">// script.nco
// Sample file to #include in ncap2 script
*pi=3.1415926535; // RAM variable, not written to output
*h=6.62607095e-34; // RAM variable, not written to output
e=2.71828; // Regular (disk) variable, written to output</example>
    </subsection>
  </node>
  <node>
    <nodename>Sort methods</nodename>
    <nodenext>Irregular grids</nodenext>
    <nodeprev>Include files</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title><command>sort</command> methods</title>
      <para><indexterm index="cp"><command>sort</command></indexterm><indexterm index="cp"><command>asort</command></indexterm><indexterm index="cp"><command>dsort</command></indexterm><indexterm index="cp"><command>remap</command></indexterm><indexterm index="cp"><command>unmap</command></indexterm><indexterm index="cp"><command>invert_map</command></indexterm>In <acronym><acronymword>ncap2</acronymword></acronym> there are multiple ways to sort data. Beginning with <acronym><acronymword>NCO</acronymword></acronym> 4.1.0 (February, 2012), <acronym><acronymword>ncap2</acronymword></acronym> support six sorting functions:</para>
      <example xml:space="preserve">var_out=sort(var_in,&amp;srt_map); // Ascending sort
var_out=asort(var_in,&amp;srt_map); // Accending sort
var_out=dsort(var_in,&amp;srt_map); // Desending sort
var_out=remap(var_in,srt_map); // Apply srt_map to var_in
var_out=unmap(var_in,srt_map); // Reverse what srt_map did to var_in
dsr_map=invert_map(srt_map); // Produce "de-sort" map that inverts srt_map</example>
      <para>The first two functions, <command>sort()</command> and <command>asort()</command> sort, in ascending order, all the elements of <var>var_in</var> (which can be a variable or attribute) without regard to any dimensions. The third function, <command>dsort()</command> does the same but sorts in descending order. Remember that ascending and descending sorts are specified by <command>asort()</command> and <command>dsort()</command>, respectively.</para>
      <para>These three functions are overloaded to take a second, optional argument called the sort map <var>srt_map</var>, which should be supplied as a call-by-reference variable, i.e., preceded with an ampersand. If the sort map does not yet exist, then it will be created and returned as an integer type the same shape as the input variable.</para>
      <para>The output <var>var_out</var> of each sort function is a sorted version of the input, <var>var_in</var>. The output <var>var_out</var> of the two mapping functions the result of applying (with <command>remap()</command> or un-applying (with <command>unmap()</command>) the sort map <var>srt_map</var> to the input <var>var_in</var>. To apply the sort map with <command>remap()</command> the size of the variable must be exactly divisible by the size of the sort map.</para>
      <para>The final function <command>invert_map()</command> returns the so-called de-sorting map <var>dsr_map</var> which is inverse map of the input map <var>srt_map</var>. This gives the user access to both the forward and inverse sorting maps which can be useful in special situations.</para>
      <example xml:space="preserve">a1[$time]={10,2,3,4,6,5,7,3,4,1};
a1_sort=sort(a1);
print(a1_sort);
// 1, 2, 3, 3, 4, 4, 5, 6, 7, 10;

a2[$lon]={2,1,4,3};
a2_sort=sort(a2,&amp;a2_map);
print(a2);
// 1, 2, 3, 4
print(a2_map);
// 1, 0, 3, 2;</example>
      <para>If the map variable does not exist prior to the <command>sort()</command> call, then it will be created with the same shape as the input variable and be of type <code>NC_INT</code>. If the map variable already exists, then the only restriction is that it be of at least the same size as the input variable. To apply a map use <code>remap(var_in,srt_map)</code>.</para>
      <example xml:space="preserve">defdim("nlat",5);

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

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

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

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

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

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

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

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

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

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

// print("msk_flg = ");print(msk_flg); // For debugging...

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

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

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

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

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

/* NB: Even though we created all variables possible as RAM variables,
   the original coordinate of interest, time, is written to the ouput.
   I'm not exactly sure why. For now, delete it from the output with:
   ncks -O -x -v time ~/foo.nc ~/foo.nc
   */
EOF
ncap2 -O -v -S ~/ncap2_foo.nco ~/nco/data/in.nc ~/foo.nc
ncks -O -x -v time ~/foo.nc ~/foo.nc
ncks ~/foo.nc</example>
      <para>Here is an extended example of how to use <command>ncap2</command> features to sort multi-dimensional arrays based on the coordinate values along a single dimension.</para>
      <example xml:space="preserve">cat &gt; ~/ncap2_foo.nco &lt;&lt; 'EOF'
/* Purpose: Sort multi-dimensional array based on coordinate values
   This example sorts the variable three_dmn_rec_var(time,lat,lon)
   based on the values of the time coordinate. */

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

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

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

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

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

// Following shows how to do method one:

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

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

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

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

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

// Method two: Key difference is srt_map=$time.size-srt_map-1;
EOF
ncap2 -O -v -S ~/ncap2_foo.nco ~/nco/data/in.nc ~/foo.nc</example>
    </subsection>
  </node>
  <node>
    <nodename>Irregular grids</nodename>
    <nodenext>Bilinear interpolation</nodenext>
    <nodeprev>Sort methods</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 Weather and Research Forecast (<acronym><acronymword>WRF</acronymword></acronym>) model uses <var>R</var>=3:</para>
      <para><var>R</var>=3: lat(time,south_north,east_west), lon(time,south_north,east_west)</para>
      <para>and so supports grids that change with time.</para>
      <para>Grids with <var>R</var> &gt; 1 often use missing values to indicated empty points. For example, so-called "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>We demonstrate the <command>ncap2</command> analysis technique for irregular regions by constructing a mask for an <var>R</var>=2 grid. We wish to find, say, the mean temperature within [<var>lat_min</var>,<var>lat_max</var>] and [<var>lon_min</var>,<var>lon_max</var>]:</para>
      <example xml:space="preserve">ncap2 -s 'mask_var= (lat &gt;= lat_min &amp;&amp; lat &lt;= lat_max) &amp;&amp; \
                    (lon &gt;= lon_min &amp;&amp; lon &lt;= lon_max);' in.nc out.nc</example>
      <para>Arbitrarily shaped regions can be defined by more complex conditional statements. Once defined, masks can be applied to specific variables, and to entire files:</para>
      <example xml:space="preserve">ncap2 -s 'temperature_avg=(temperature*mask_var).avg()' in.nc out.nc
ncwa -a lat,lon -m mask_var -w area in.nc out.nc</example>
      <para>Crafting such commands on the command line is possible though unwieldy. In such cases, a script is often cleaner and allows you to document the procedure:</para>
      <example xml:space="preserve">cat &gt; ncap2.in &lt;&lt; 'EOF'
mask_var = (lat &gt;= lat_min &amp;&amp; lat &lt;= lat_max) &amp;&amp; (lon &gt;= lon_min &amp;&amp; &gt; lon &lt;= lon_max);
if(mask_var.total() &gt; 0){ // Check that mask contains some valid values
  temperature_avg=(temperature*mask_var).avg(); // Average temperature
  temperature_max=(temperature*mask_var).max(); // Maximum temperature
}
EOF
ncap2 -S ncap2.in in.nc out.nc</example>
      <para>For <acronym><acronymword>WRF</acronymword></acronym> files creating regional masks looks like</para>
      <example xml:space="preserve">mask_var = (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>Bilinear interpolation</nodename>
    <nodenext>GSL special functions</nodenext>
    <nodeprev>Irregular grids</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>Bilinear interpolation</title>
      <para role="continues">As of version 4.0.0 <acronym><acronymword>NCO</acronymword></acronym> has internal routines to perform bilinear interpolation on gridded data sets. In mathematics, bilinear interpolation is an extension of linear interpolation for interpolating functions of two variables on a regular grid. The idea is to perform linear interpolation first in one direction, and then again in the other direction.</para>
      <para>Suppose we have an irregular grid of data <code>temperature[lat,lon]</code>, with co-ordinate vars <code>lat[lat], lon[lon]</code>. We wish to find the temperature at an arbitary point [<var>X</var>,<var>Y</var>] within the grid. If we can locate lat_min,lat_max and lon_min,lon_max such that <code>lat_min &lt;= X &lt;= lat_max</code> and <code>lon_min &lt;=Y &lt;=lon_max</code> then we can interpolate in two dimensions to find the temperature at [<var>X</var>,<var>Y</var>].</para>
      <para>The general form of the <command>ncap2</command> interpolation function is</para>
      <example xml:space="preserve">var_out=bilinear_interp(grid_in,grid_out,grid_out_x,grid_out_y,grid_in_x,grid_in_y)</example>
      <para>where</para>
      <table>
        <tableitem>
          <tableterm><code>grid_in</code></tableterm>
          <item>
            <para>Input function data. Usually a two dimensional variable. It must be of size <code>grid_in_x.size()*grid_in_y.size()</code></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>grid_out</code></tableterm>
          <item>
            <para>This variable is the shape of <code>var_out</code>. Usually a two dimensional variable. It must be of size <code>grid_out_x.size()*grid_out_y.size()</code></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>grid_out_x</code></tableterm>
          <item>
            <para><var>X</var> output values</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>grid_out_y</code></tableterm>
          <item>
            <para><var>Y</var> output values</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>grid_in_x</code></tableterm>
          <item>
            <para><var>X</var> input values values. Must be montonic (increasing or decreasing).</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>grid_in_y</code></tableterm>
          <item>
            <para><var>Y</var> input values values. Must be montonic (increasing or decreasing).</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">Prior to calculations all arguments are converted to type <code>NC_DOUBLE</code>. After calculations <code>var_out</code> is converted to the input type of <code>grid_in</code>.</para>
      <para>Suppose the first part of an ncap2 script is</para>
      <example xml:space="preserve">defdim("X",4);
defdim("Y",5);

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

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

var_out=bilinear_interp(T_in,T_out,x_out,y_out,x_in,y_in);
print(var_out);
// 110, 200, 300, 400,
// 110.022, 200.04, 300.06, 400.08,
// 113.3, 206, 309, 412 ;</example>
      <para>It is possible to interpolate a single point:</para>
      <example xml:space="preserve">var_out=bilinear_interp(T_in,0.0,3.0,4.99,x_in,y_in);
print(var_out);
// 513.920594059406</example>
      <para role="continues"><strong>Wrapping and Extrapolation</strong> &linebreak; The function <code>bilinear_interp_wrap()</code> takes the same arguments as <code>bilinear_interp()</code> but performs wrapping (<var>Y</var>) and extrapolation (<var>X</var>) for points off the edge of the grid. If the given range of longitude is say (25-335) and we have a point at 20 degrees, then the endpoints of the range are used for the interpolation. This is what wrapping means. For wrapping to occur <var>Y</var> must be longitude and must be in the range (0,360) or (-180,180). There are no restrictions on the longitude (<var>X</var>) values, though typically these are in the range (-90,90). This <command>ncap2</command> script illustrates both wrapping and extrapolation of end points:</para>
      <example xml:space="preserve">defdim("lat_in",6);
defdim("lon_in",5);

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

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

defdim("lat_out",4);
defdim("lon_out",3);

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

T_out[$lat_out,$lon_out]=0.0;

T_out=bilinear_interp_wrap(T_in,T_out,lat_out,lon_out,lat_in,lon_in);
print(T_out);
// 13.4375, 49.5, 14.09375,
// 16.25, 54, 16.625,
// 19.25, 58.8, 19.325,
// 20.15, 60.24, 20.135 ;</example>
    </subsection>
  </node>
  <node>
    <nodename>GSL special functions</nodename>
    <nodenext>GSL interpolation</nodenext>
    <nodeprev>Bilinear interpolation</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>GSL special functions</title>
      <para role="continues"><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>ncap2</command> can access most <acronym><acronymword>GSL</acronymword></acronym> special functions including Airy, Bessel, error, gamma, beta, hypergeometric, and Legendre functions and elliptical integrals. <acronym><acronymword>GSL</acronymword></acronym> must be 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>ncap2</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>ncap2</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>ncap2</command> must conform to one another, i.e., they must share the same sub-set of dimensions. For example: <code>three_out=gsl_sf_bessel_Jn(n_in,three_dmn_var_dbl)</code> is valid because the variable <code>three_dmn_var_dbl</code> has a <var>lon</var> dimension, so <code>n_in</code> in can be broadcast to conform to <code>three_dmn_var_dbl</code>. However <code>time_out=gsl_sf_bessel_Jn(n_in,time)</code> is invalid.</para>
      <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>ncap2</command> call is valid. The mode argument in the function prototype controls the convergence of the algorithm. It also appears  in the Airy Function prototypes. It can be set by defining the environment variable <code>GSL_PREC_MODE</code>. If unset it defaults to the value <code>GSL_PREC_DOUBLE</code>. See the <acronym><acronymword>GSL</acronymword></acronym> manual for more details.</para>
      <example 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>ncap2</command> wrappers to the array functions are slightly different. Consider the following <acronym><acronymword>GSL</acronymword></acronym> prototype &linebreak; <code>int gsl_sf_bessel_Jn_array(int nmin, int nmax, double x, double *result_array)</code></para>
      <example 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 <var>x</var>=0.5 for <var>n</var>=1 to 4. The first three arguments are scalar values. If a non-scalar variable is supplied as an argument then only the first value is used. The final argument is the variable where the results are stored (NB: the <code>&amp;</code> indicates this is a call by reference). This final argument must be of type <code>double</code> and must be of least size <var>nmax-nmin+1</var>. If either of these conditions is not met then then the function returns an error message. The function/wrapper returns a status flag. Zero indicates success.</para>
      <para role="continues">Consider another array function &linebreak; <code>int gsl_sf_legendre_Pl_array( int lmax, double x, double *result_array);</code> <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 <var>P_l</var>(0.3) for <var>l</var>=0..9. Note that <var>|x|&lt;=1</var>, otherwise there will be a domain error. See the <acronym><acronymword>GSL</acronymword></acronym> documentation for more details.</para>
      <para role="continues">The <acronym><acronymword>GSL</acronymword></acronym> functions implemented in <acronym><acronymword>NCO</acronymword></acronym> are listed in the table below. This table is correct for <acronym><acronymword>GSL</acronymword></acronym> version 1.10. To see what functions are available on your build run the command <command>ncap2 -f |grep ^gsl</command> . To see this table along with the <acronym><acronymword>GSL</acronymword></acronym> C-function<!-- /@w --> 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>GSL interpolation</nodename>
    <nodenext>GSL least-squares fitting</nodenext>
    <nodeprev>GSL special functions</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>GSL interpolation</title>
      <para><indexterm index="cp"><acronym><acronymword>GSL</acronymword></acronym></indexterm>As of version 3.9.9 (released July, 2009), <acronym><acronymword>NCO</acronymword></acronym> has wrappers to the <acronym><acronymword>GSL</acronymword></acronym> interpolation functions.</para>
      <para role="continues">Given a set of data points (x1,y1)...(xn, yn) the <acronym><acronymword>GSL</acronymword></acronym> functions computes a continuous interpolating function <acronym><acronymword>Y(x)</acronymword></acronym> such that <acronym><acronymword>Y(xi) = yi</acronymword></acronym>. The interpolation is piecewise smooth, and its behavior at the end-points is determined by the type of interpolation used. For more information consult the <acronym><acronymword>GSL</acronymword></acronym> manual.</para>
      <para role="continues">Interpolation with <command>ncap2</command> is a two stage process. In the first stage, a <acronym><acronymword>RAM</acronymword></acronym> variable is created from the chosen interpolating function and the data set. This <acronym><acronymword>RAM</acronymword></acronym> variable holds in memory a <acronym><acronymword>GSL</acronymword></acronym> interpolation object. In the second stage, points along the interpolating function are calculated. If you have a very large data set or are interpolating many sets then consider deleting the <acronym><acronymword>RAM</acronymword></acronym> variable when it is redundant. Use the command <command>ram_delete(var_nm)</command>.</para>
      <para role="continues">A simple example</para>
      <example xml:space="preserve">x_in[$lon]={1.0,2.0,3.0,4.0};
y_in[$lon]={1.1,1.2,1.5,1.8};

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

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

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

print(y_out); // 1.10472, 1.2, 1.4, 1.42658, 1.69680002
print(y2);    // 1.12454
print(y3);    // '_'</example>
      <para role="continues">Note in the above example y3 is set to 'missing value' because 0.0 isn't within the input X range.</para>
      <para><strong><acronym><acronymword>GSL</acronymword></acronym> Interpolation Types</strong>&linebreak; All the interpolation functions have been implemented. These are:&linebreak; gsl_interp_linear() &linebreak; gsl_interp_polynomial() &linebreak; gsl_interp_cspline()&linebreak; gsl_interp_cspline_periodic()&linebreak; gsl_interp_akima() &linebreak; gsl_interp_akima_periodic() &linebreak;</para>
      <para role="continues">&linebreak; &linebreak; <strong> Evaluation of Interpolating Types </strong> &linebreak; <strong>Implemented</strong> &linebreak; gsl_spline_eval() &linebreak; <strong>Unimplemented</strong> &linebreak; gsl_spline_deriv()&linebreak; gsl_spline_deriv2()&linebreak; gsl_spline_integ()&linebreak;</para>
    </subsection>
  </node>
  <node>
    <nodename>GSL least-squares fitting</nodename>
    <nodenext>GSL statistics</nodenext>
    <nodeprev>GSL interpolation</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>GSL least-squares fitting</title>
      <para role="continues">Least Squares fitting is a method of calculating a straight line through a set of experimental data points in the XY plane. The data maybe weighted or unweighted. For more information please refer to the <acronym><acronymword>GSL</acronymword></acronym> manual.</para>
      <para role="continues">These <acronym><acronymword>GSL</acronymword></acronym> functions fall into three categories:&linebreak; <strong>A)</strong> Fitting data to Y=c0+c1*X&linebreak; <strong>B)</strong> Fitting data (through the origin) Y=c1*X&linebreak; <strong>C)</strong> Multi-parameter fitting (not yet implemented)&linebreak;</para>
      <para><strong>Section A</strong> &linebreak; &linebreak; <code>status=<strong>gsl_fit_linear</strong> (data_x,stride_x,data_y,stride_y,n,&amp;co,&amp;c1,&amp;cov00,&amp;cov01,&amp;cov11,&amp;sumsq) </code></para>
      <para role="continues"><strong>Input variables</strong>: data_x, stride_x, data_y, stride_y, n &linebreak; From the above variables an X and Y vector both of length 'n' are derived. If data_x or data_y is less than type double then it is converted to type <code>double</code>. It is up to you to do bounds checking on the input data. For example if stride_x=3 and n=8 then the size of data_x must be at least 24</para>
      <para role="continues"><strong>Output variables</strong>: c0, c1, cov00, cov01, cov11,sumsq &linebreak; The '&amp;' prefix indicates that these are call-by-reference variables. If any of the output variables don't exist prior to the call then they are created on the fly as scalar variables of type <code>double</code>. If they already exist then their existing value is overwritten. If the function call is successful then <code>status=0</code>.</para>
      <para><code>status= <strong>gsl_fit_wlinear</strong>(data_x,stride_x,data_w,stride_w,data_y,stride_y,n,&amp;co,&amp;c1,&amp;cov00,&amp;cov01,&amp;cov11,&amp;chisq) </code></para>
      <para role="continues">Similar to the above call except it creates an additional weighting vector from the variables data_w, stride_w, n</para>
      <para><code> data_y_out=<strong>gsl_fit_linear_est</strong>(data_x,c0,c1,cov00,cov01,cov11) </code></para>
      <para role="continues">This function calculates y values along the line Y=c0+c1*X &linebreak; &linebreak;</para>
      <para><strong>Section B</strong> &linebreak; &linebreak; <code>status=<strong>gsl_fit_mul</strong>(data_x,stride_x,data_y,stride_y,n,&amp;c1,&amp;cov11,&amp;sumsq) </code></para>
      <para role="continues"><strong>Input variables</strong>: data_x, stride_x, data_y, stride_y, n &linebreak; From the above variables an X and Y vector both of length 'n' are derived. If data_x or data_y is less than type <code>double</code> then it is converted to type <code>double</code>. &linebreak;</para>
      <para role="continues"><strong>Output variables</strong>: c1,cov11,sumsq &linebreak;</para>
      <para><code>status= <strong>gsl_fit_wmul</strong>(data_x,stride_x,data_w,stride_w,data_y,stride_y,n,&amp;c1,&amp;cov11,&amp;sumsq) </code></para>
      <para role="continues">Similar to the above call except it creates an additional weighting vector from the variables data_w, stride_w, n</para>
      <para><code> data_y_out=<strong>gsl_fit_mul_est</strong>(data_x,c0,c1,cov11) </code></para>
      <para role="continues">This function calculates y values along the line Y=c1*X &linebreak; &linebreak;</para>
      <para role="continues">The below example shows <strong>gsl_fit_linear()</strong> in action</para>
      <example xml:space="preserve">defdim("d1",10);
xin[d1]={1,2,3,4,5,6,7,8,9,10.0};
yin[d1]={3.1,6.2,9.1,12.2,15.1,18.2,21.3,24.0,27.0,30.0};
gsl_fit_linear(xin,1,yin,1,$d1.size,&amp;c0,&amp;c1,&amp;cov00,&amp;cov01,&amp;cov11,&amp;sumsq);
print(c0);  // 0.2
print(c1);  // 2.98545454545


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

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

print(yout);  // 3.18545454545 ,9.15636363636, ,12.1418181818 ,33.04</example>
      <para>&linebreak; &linebreak;</para>
    </subsection>
  </node>
  <node>
    <nodename>GSL statistics</nodename>
    <nodenext>GSL random number generation</nodenext>
    <nodeprev>GSL least-squares fitting</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>GSL statistics</title>
      <para role="continues">Wrappers for most of the <acronym><acronymword>GSL</acronymword></acronym> Statistical functions have been implemented. The <acronym><acronymword>GSL</acronymword></acronym> function names include a type specifier (except for type double functions). To obtain the equivalent <acronym><acronymword>NCO</acronymword></acronym> name simply remove the type specifier; then depending on the data type the appropriate <acronym><acronymword>GSL</acronymword></acronym> function  is called. The weighed statistical functions e.g <code> gsl_stats_wvariance()</code> are only defined in <acronym><acronymword>GSL</acronymword></acronym> for floating point types; so your data must of type <code>float</code> or <code>double</code> otherwise ncap2 will emit an error message. To view the implemented functions use the shell command <command>ncap2 -f|grep _stats</command></para>
      <para role="continues"><acronym><acronymword>GSL</acronymword></acronym> Functions</para>
      <example xml:space="preserve">short gsl_stats_max (short data[], size_t stride, size_t n);
double gsl_stats_int_mean (int data[], size_t stride, size_t n);
double gsl_stats_short_sd_with_fixed_mean (short data[], size_t stride, size_t n, double mean);
double gsl_stats_wmean (double w[], size_t wstride, double data[], size_t stride, size_t n);
double gsl_stats_quantile_from_sorted_data (double sorted_data[], size_t stride, size_t n, double f) ;</example>
      <para role="continues">Equivalent ncap2 wrapper functions</para>
      <example xml:space="preserve">short gsl_stats_max (var_data, data_stride, n);
double gsl_stats_mean (var_data, data_stride, n);
double gsl_stats_sd_with_fixed_mean (var_data, data_stride, n, var_mean);
double gsl_stats_wmean (var_weight, weight_stride, var_data, data_stride, n, var_mean);
double gsl_stats_quantile_from_sorted_data (var_sorted_data, data_stride, n, var_f) ;</example>
      <para role="continues"><acronym><acronymword>GSL</acronymword></acronym> has no notion of missing values or dimensionality beyond one. If your data has missing values which you want ignored in the calculations then use the <command>ncap2</command> built in aggregate functions( <xref><xrefnodename>Methods and functions</xrefnodename></xref> ). The <acronym><acronymword>GSL</acronymword></acronym> functions operate on a vector of values created from the var_data/stride/n arguments. The ncap wrappers check that there is no bounding error with regard to the size of the data and the final value in the vector.</para>
      <para>Some examples</para>
      <example xml:space="preserve">a1[time]={1,2,3,4,5,6,7,8,9,10 };

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

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

// bounding error, vector attempts to access element a1(10)
a1_sd=gsl_stats_sd(a1,5,3);
</example>
      <para role="continues">For functions with the signature <strong>func_nm(var_data,data_stride,n)</strong>, one may omit the second or third arguments. The default value for <var>stride</var> is <code>1</code>. The default value for <var>n</var> is <code>1+(data.size()-1)/stride</code>.</para>
      <example xml:space="preserve">// Following statements are equvalent
n2=gsl_stats_max(a1,1,10)
n2=gsl_stats_max(a1,1);
n2=gsl_stats_max(a1);

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

// Following statements are NOT equvalent
n4=gsl_stats_kurtosis(a1,3,2);
n4=gsl_stats_kurtosis(a1,3); //default n=4</example>
      <para>The following example illustrates some of the weighted functions. The data are randomly generated. In this case the value of the weight for each datum is either 0.0 or 1.0</para>
      <example xml:space="preserve">defdim("r1",2000);
data[r1]=1.0;

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

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

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

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

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

// print min/max of data
dmin=data.gsl_stats_min();
dmax=data.gsl_stats_max();
print(dmin);print(dmax);</example>
    </subsection>
  </node>
  <node>
    <nodename>GSL random number generation</nodename>
    <nodenext>Examples ncap2</nodenext>
    <nodeprev>GSL statistics</nodeprev>
    <nodeup>ncap2 netCDF Arithmetic Processor</nodeup>
    <subsection>
      <title>GSL random number generation</title>
      <para>The <acronym><acronymword>GSL</acronymword></acronym> library has a large number of random number generators. In addition there are a large set of functions for turning uniform random numbers into discrete or continuous probabilty distributions. The random number generator algorithms vary in terms of quality numbers output, speed of execution and maximium number output. For more information see the <acronym><acronymword>GSL</acronymword></acronym> documentation. The algorithm and seed are set via environment variables, these are picked up by the <code>ncap2</code> code.</para>
      <para role="continues"><strong>Setup</strong> &linebreak; The number algorithm is set by the environment variable <code>GSL_RNG_TYPE</code>. If this variable isn't set then the default rng algorithm is gsl_rng_19937. The seed is set with the environment variable <code>GSL_RNG_SEED</code>. The following wrapper functions in ncap2 provide information about the chosen algorithm. &linebreak;</para>
      <table>
        <tableitem>
          <tableterm><code>gsl_rng_min()</code></tableterm>
          <item>
            <para>the minimium value returned by the rng algorithm.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>gsl_rng_max()</code></tableterm>
          <item>
            <para>the maximium value returned by the rng algorithm.</para>
          </item>
        </tableitem>
      </table>
      <para role="continues"><strong>Uniformly Distributed Random Numbers</strong></para>
      <table>
        <tableitem>
          <tableterm><code>gsl_rng_get(var_in)</code></tableterm>
          <item>
            <para>This function returns var_in with integers from the chosen rng algorithm. The min and max values depend uoon the chosen rng algorthm.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>gsl_rng_uniform_int(var_in)</code></tableterm>
          <item>
            <para>This function returns var_in with random integers from 0 to n-1. The value n must be less than or equal to the maximium value of the chosen rng algorithm.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>gsl_rng_uniform(var_in)</code></tableterm>
          <item>
            <para>This function returns var_in with double precision numbers in the range [0.0,1). The range includes 0.0 and excludes 1.0.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><code>gsl_rng_uniform_pos(var_in)</code></tableterm>
          <item>
            <para>This function returns var_in with double precision numbers in the range (0.0,1), excluding both 0.0 and 1.0.</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">Below are examples of <code>gsl_rng_get()</code> and <code>gsl_rng_uniform_int()</code> in action.</para>
      <example xml:space="preserve">export GSL_RNG_TYPE=ranlux
export GSL_RNG_SEED=10
ncap2 -v -O -s 'a1[time]=0;a2=gsl_rng_get(a1);' in.nc foo.nc
// 10 random numbers from the range 0 - 16777215
// a2=9056646, 12776696, 1011656, 13354708, 5139066, 1388751, 11163902, 7730127, 15531355, 10387694 ;

ncap2 -v -O -s 'a1[time]=21;a2=gsl_rng_uniform_int(a1).sort();' in.nc foo.nc
// 10 random numbers from the range 0 - 20
a2 = 1, 1, 6, 9, 11, 13, 13, 15, 16, 19 ;
</example>
      <para role="continues">The following example produces an <code>ncap2</code> runtime error. This is because the chose rng algorithm has a maximium value greater than <code> NC_MAX_INT=2147483647 </code>; the wrapper functions to <code>gsl_rng_get()</code> and <code>gsl_rng_uniform_int()</code> return variable of type <code>NC_INT</code>. Please be aware of this when using random number distribution functions functions from the <acronym><acronymword>GSL</acronymword></acronym> library which return <code>unsigned int</code>. Examples of these are <code>gsl_ran_geometric()</code> and <code>gsl_ran_pascal()</code>.</para>
      <example xml:space="preserve">export GSL_RNG_TYPE=mt19937
ncap2 -v -O -s 'a1[time]=0;a2=gsl_rng_get(a1);' in.nc foo.nc</example>
      <para role="continues">To find the maximium value of the chosen rng algorithm use the following code snippet.</para>
      <example xml:space="preserve">ncap2 -v -O -s 'rng_max=gsl_rng_max();print(rng_max)' in.nc foo.nc</example>
      <para role="continues"><strong>Random Number Distributions</strong> &linebreak; The <acronym><acronymword>GSL</acronymword></acronym> library has a rich set of random number disribution functions. The library also provides cumulative distribution functions and inverse cumulative distribution functions sometimes referred to a quantile functions. To see whats available on your build use the shell command <code>ncap2 -f|grep -e _ran -e _cdf</code>.</para>
      <para role="continues">The following examples all return variables of type <code>NC_INT</code> &linebreak;</para>
      <example xml:space="preserve">defdim("out",15);
a1[$out]=0.5;
a2=gsl_ran_binomial(a1,30).sort();
//a2 = 10, 11, 12, 12, 13, 14, 14, 15, 15, 16, 16, 16, 16, 17, 22 ;
a3=gsl_ran_geometric(a2).sort();
//a2 = 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 4, 5 ;
a4=gsl_ran_pascal(a2,50);
//a5 = 37, 40, 40, 42, 43, 45, 46, 49, 52, 58, 60, 62, 62, 65, 67 ;</example>
      <para role="continues">The following all return variables of type <code>NC_DOUBLE</code>;</para>
      <example xml:space="preserve">defdim("b1",1000);
b1[$b1]=0.8;
b2=gsl_ran_exponential(b1);
b2_avg=b2.avg();
print(b2_avg);
// b2_avg = 0.756047976787

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

b4[$b1]=10.0;
b5[$b1]=20.0;
b6=gsl_ran_flat(b4,b5);
b6_avg=b6.avg();
print(b6_avg);
// b6_avg=15.0588129413</example>
    </subsection>
  </node>
  <node>
    <nodename>Examples ncap2</nodename>
    <nodenext>Intrinsic mathematical methods</nodenext>
    <nodeprev>GSL random number generation</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 <acronym><acronymword>NCO</acronymword></acronym> for more complete demonstrations of <command>ncap2</command> functionality (script available on-line at <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>ncap2</command> operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied.</para>
      <multitable>
        <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 <acronym><acronymword>NCO</acronymword></acronym> 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 from the netCDF library definitions and detail the naming conventions for each release. netcdf-3.5.1 &linebreak; netcdf-3.6.0-p1 &linebreak; netcdf-3.6.1 &linebreak; netcdf-3.6.2 &linebreak;</para>
      <example 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><indexterm index="cp"><command>ncattget</command></indexterm><command>ncatted</command> edits attributes in a netCDF file. If you are editing attributes then you are spending too much time in the world of metadata, and <command>ncatted</command> was written to get you back out as quickly and painlessly as possible. <command>ncatted</command> can <dfn>append</dfn>, <dfn>create</dfn>, <dfn>delete</dfn>, <dfn>modify</dfn>, and <dfn>overwrite</dfn> attributes (all explained below). <command>ncatted</command> allows each editing operation to be applied to every variable in a file. This saves time when changing attribute conventions throughout a file. <command>ncatted</command> is for <emph>writing</emph> attributes. To <emph>read</emph> attribute values in plain text, use <command>ncks -m -M</command>, or define something like <command>ncattget</command> as a shell command (see <xref><xrefnodename>Filters for <command>ncks</command></xrefnodename></xref>).</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 that describes 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} is input, it will not be translated (because it would -->
<!-- terminate the string in an additional location). -->
<!-- 20101007 Before today, \0 was not translated to NUL -->
<!-- 20101007 As of today,  \0 is      translated to NUL -->If <code>\0</code> is input, it is translated to the NUL character. However, this will make the subsequent portion of the string, if any, invisible to C standard<!-- /@w --> library string functions. And that may cause unintended consequences. Because of these context-sensitive rules, one must use <command>ncatted</command> with care in order to store data, rather than text strings, in an attribute of type <code>NC_CHAR</code>.</para>
      <para>Note that <command>ncatted</command> interprets character attributes (i.e., attributes of type <code>NC_CHAR</code>) as strings. EXAMPLES</para>
      <para role="continues">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, and delete all global attributes</para>
      <example xml:space="preserve">ncatted -a ,tpt,d,, -a ,global,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] [-6] [-A] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-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] [-6] [-A] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-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>]
[-n <var>loop</var>] [-O] [-o <var>output-file</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>input-files</var>] [<var>output-file</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncea</command> performs gridpoint averages of variables across an arbitrary number (an <dfn>ensemble</dfn>) of <var>input-files</var>, with each file receiving an equal weight in the average. <indexterm index="cp">ensemble</indexterm><command>ncea</command> averages entire files, and weights each file evenly. This is distinct from <command>ncra</command>, which only averages over the record dimension (e.g., <var>time</var>), and weights each record in the record dimension evenly,</para>
      <para>Variables in the <var>output-file</var> are the same size as the variable in each of the <var>input-files</var>, and all <var>input-files</var> must be the same size. <indexterm index="cp">record dimension</indexterm><indexterm index="cp">hyperslab</indexterm>The only exception is that <command>ncea</command> allows files to differ in the record dimension size if the requested record hyperslab (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>) resolves to the same size for all files. <command>ncea</command> recomputes the record dimension hyperslab limits for each input file so that coordinate limits may be used to select equal length timeseries from unequal length files. <indexterm index="cp">IPCC</indexterm><indexterm index="cp">AR4</indexterm><indexterm index="cp">CMIP</indexterm>This simplifies analysis of unequal length timeseries from simulation ensembles (e.g., the CMIP IPCC AR4 archive).</para>
      <para><indexterm index="cp">operation types</indexterm><command>ncea</command> <emph>always averages</emph> coordinate variables regardless of the arithmetic operation type performed on the non-coordinate variables. (see <xref><xrefnodename>Operation Types</xrefnodename></xref>). <indexterm index="cp">record dimension</indexterm>All dimensions, including the record dimension, are treated identically and preserved in the <var>output-file</var>.</para>
      <para>See <xref><xrefnodename>Averaging vs. Concatenating</xrefnodename></xref>, for a description of the distinctions between the various averagers and concatenators. <indexterm index="cp">multi-file operators</indexterm><indexterm index="cp">standard input</indexterm><indexterm index="cp"><code>stdin</code></indexterm>As a multi-file operator, <command>ncea</command> will read the list of <var>input-files</var> from <code>stdin</code> if they are not specified as positional arguments on the command line (see <xref><xrefnodename>Large Numbers of Files</xrefnodename></xref>).</para>
      <para>The file is the logical unit of organization for the results of many scientific studies. Often one wishes to generate a file which is the gridpoint average of many separate files. This may be to reduce statistical noise by combining the results of a large number of experiments, or it may simply be a step in a procedure whose goal is to compute anomalies from a mean state. In any case, when one desires to generate a file whose properties are the mean of all the input files, then <command>ncea</command> is the operator to use.</para>
      <para><command>ncea</command> only allows coordinate variables to be processed by the linear average, minimum, and maximum operations. <command>ncea</command> will return the linear average of coordinates unless extrema are explicitly requested. Other requested operations (e.g., square-root, RMS) are applied only to non-coordinate variables. In these cases the linear average of the coordinate variable will be returned.</para>
      <para role="continues">EXAMPLES</para>
      <para>Consider a model experiment which generated five realizations of one year of data, say 1985. You can imagine that the experimenter slightly perturbs the initial conditions of the problem before generating each new solution. Assume each file contains all twelve months (a seasonal cycle) of data and we want to produce a single file containing the ensemble average (mean) seasonal cycle. Here the numeric filename suffix denotes the experiment number (<emph>not</emph> the month):</para>
      <example xml:space="preserve">ncea 85_01.nc 85_02.nc 85_03.nc 85_04.nc 85_05.nc 85.nc
ncea 85_0[1-5].nc 85.nc
ncea -n 5,2,1 85_01.nc 85.nc</example>
      <para role="continues">These three commands produce identical answers. See <xref><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions between these methods. The output file, <file>85.nc</file>, is the same size as the inputs files. It contains 12 months of data (which might or might not be stored in the record dimension, depending on the input files), but each value in the output file is the average of the five values in the input files.</para>
      <para>In the previous example, the user could have obtained the ensemble average values in a particular spatio-temporal region by adding a hyperslab argument to the command, e.g.,</para>
      <example xml:space="preserve">ncea -d time,0,2 -d lat,-23.5,23.5 85_??.nc 85.nc</example>
      <para role="continues">In this case the output file would contain only three slices of data in the <var>time</var> dimension. These three slices are the average of the first three slices from the input files. Additionally, only data inside the tropics is included.</para>
    </section>
  </node>
  <node>
    <nodename>ncecat netCDF Ensemble Concatenator</nodename>
    <nodenext>ncflint netCDF File Interpolator</nodenext>
    <nodeprev>ncea netCDF Ensemble Averager</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncecat</command> netCDF Ensemble Concatenator</title>
      <para><indexterm index="cp">concatenation</indexterm><indexterm index="cp">ensemble concatenation</indexterm><indexterm index="cp">ncecat</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncecat [-3] [-4] [-6] [-A] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-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>]
[-M] [--md5_digest] [-n <var>loop</var>] [-O] [-o <var>output-file</var>] [-p <var>path</var>] [-R] [-r]
[-t <var>thr_nbr</var>] [-u <var>ulm_nm</var>] [-v <var>var</var>[,&dots;]] [-X ...] [-x]
[<var>input-files</var>] [<var>output-file</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncecat</command> concatenates an arbitrary number of input files into a single output file. The <var>input-files</var> are stored consecutively as records in <var>output-file</var>. Each variable (except coordinate variables) in each input file becomes one record in the same variable in the output file. Coordinate variables are not concatenated, they are instead simply copied from the first input file to the <var>output-file</var>. All <var>input-files</var> must contain all extracted variables (or else there would be "gaps" in the output file).</para>
      <para>A new record dimension is the glue which binds the input file data together. The new record dimension name is, by default, &ldquo;record&rdquo;. <indexterm index="cp">unlimited dimension</indexterm><indexterm index="cp">record dimension</indexterm><indexterm index="cp"><samp>-u <var>ulm_nm</var></samp></indexterm><indexterm index="cp"><samp>--ulm_nm <var>ulm_nm</var></samp></indexterm><indexterm index="cp"><samp>--rcd_nm <var>ulm_nm</var></samp></indexterm>Its name can be specified with the <samp>-u <var>ulm_nm</var></samp> short option (or the <samp>--ulm_nm</samp> or <samp>rcd_nm</samp> long options).</para>
      <para>Each extracted variable must be constant in size and rank across all <var>input-files</var>. <indexterm index="cp">record dimension</indexterm><indexterm index="cp">hyperslab</indexterm>The only exception is that <command>ncecat</command> allows files to differ in the record dimension size if the requested record hyperslab (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>) resolves to the same size for all files. <indexterm index="cp">IPCC</indexterm>This allows easier gluing/averaging of unequal length timeseries from simulation ensembles (e.g., the IPCC AR4 archive).</para>
      <para>Thus, the <var>output-file</var> size is the sum of the sizes of the extracted variables in the input files. See <xref><xrefnodename>Averaging vs. Concatenating</xrefnodename></xref>, for a description of the distinctions between the various averagers and concatenators. <indexterm index="cp">multi-file operators</indexterm><indexterm index="cp">standard input</indexterm><indexterm index="cp"><code>stdin</code></indexterm>As a multi-file operator, <command>ncecat</command> will read the list of <var>input-files</var> from <code>stdin</code> if they are not specified as positional arguments on the command line (see <xref><xrefnodename>Large Numbers of Files</xrefnodename></xref>).</para>
      <para><indexterm index="cp"><code>-M</code></indexterm><indexterm index="cp"><code>--glb_mtd_spr</code></indexterm><indexterm index="cp">metadata, global</indexterm>Turn off global metadata copying. By default all <acronym><acronymword>NCO</acronymword></acronym> operators copy the global metadata of the first input file into <var>output-file</var>. This helps preserve the provenance of the output data. However, the use of metadata is burgeoning and is not uncommon to encounter files with excessive amounts of extraneous metadata. Extracting small bits of data from such files leads to output files which are much larger than necessary due to the automatically copied metadata. <command>ncecat</command> supports turning off the default copying of global metadata via the <samp>-M</samp> switch (or its long option equivalents, <samp>--glb_mtd_spr</samp> and <samp>--global_metadata_suppress</samp>).</para>
      <para><indexterm index="cp">climate model</indexterm>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 by default 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.</para>
      <para><indexterm index="cp">ncpdq</indexterm><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>Concatenating a variable packed with different scales across multiple datasets is beyond the capabilities of <command>ncecat</command> (and <command>ncrcat</command>, the other concatenator (<xref><xrefnodename>Concatenation</xrefnodename></xref>). <command>ncecat</command> does not unpack data, it simply <emph>copies</emph> the data from the <var>input-files</var>, and the metadata from the <emph>first</emph> <var>input-file</var>, to the <var>output-file</var>. This means that data compressed with a packing convention must use the identical packing parameters (e.g., <code>scale_factor</code> and <code>add_offset</code>) for a given variable across <emph>all</emph> input files. Otherwise the concatenated dataset will not unpack correctly. The workaround for cases where the packing parameters differ across <var>input-files</var> requires three steps: First, unpack the data using <command>ncpdq</command>. Second, concatenate the unpacked data using <command>ncecat</command>, Third, re-pack the result with <command>ncpdq</command>.</para>
      <para role="continues">EXAMPLES</para>
      <para>Consider a model experiment which generated five realizations of one year of data, say 1985. You can imagine that the experimenter slightly perturbs the initial conditions of the problem before generating each new solution. Assume each file contains all twelve months (a seasonal cycle) of data and we want to produce a single file containing all the seasonal cycles. Here the numeric filename suffix denotes the experiment number (<emph>not</emph> the month):</para>
      <example xml:space="preserve">ncecat 85_01.nc 85_02.nc 85_03.nc 85_04.nc 85_05.nc 85.nc
ncecat 85_0[1-5].nc 85.nc
ncecat -n 5,2,1 85_01.nc 85.nc</example>
      <para role="continues">These three commands produce identical answers. See <xref><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions between these methods. The output file, <file>85.nc</file>, is five times the size as a single <var>input-file</var>. It contains 60 months<!-- /@w --> of data.</para>
      <para>One often prefers that the (new) record dimension have a more descriptive, context-based name than simply &ldquo;record&rdquo;. This is easily accomplished with the <samp>-u <var>ulm_nm</var></samp> switch:</para>
      <example xml:space="preserve">ncecat -u realization 85_0[1-5].nc 85.nc</example>
      <para role="continues">Users are more likely to understand the data processing history when such descriptive coordinates are used.</para>
      <para><indexterm index="cp">record dimension</indexterm>Consider a file with an existing record dimension named <code>time</code>. and suppose the user wishes to convert <code>time</code> from a record dimension to a non-record dimension. This may be useful, for example, when the user has another use for the record variable. The procedure is to use <command>ncecat</command> followed by <command>ncwa</command>: <indexterm index="cp">degenerate dimension</indexterm></para>
      <example xml:space="preserve">ncecat in.nc out.nc # Convert time to non-record dimension
ncwa -a record in.nc out.nc # Remove new degenerate record dimension</example>
      <para role="continues">The second step removes the degenerate record dimension. See <xref><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></xref> and <xref><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref> for other methods of of changing variable dimensionality, including the record dimension.</para>
    </section>
  </node>
  <node>
    <nodename>ncflint netCDF File Interpolator</nodename>
    <nodenext>ncks netCDF Kitchen Sink</nodenext>
    <nodeprev>ncecat netCDF Ensemble Concatenator</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncflint</command> netCDF File Interpolator</title>
      <para><indexterm index="cp">interpolation</indexterm><indexterm index="cp">adding data</indexterm><indexterm index="cp">multiplying data</indexterm><indexterm index="cp">addition</indexterm><indexterm index="cp">ncflint</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncflint [-3] [-4] [-6] [-A] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F] [-h] [-i <var>var</var>,<var>val3</var>]
[-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;]] [-w <var>wgt1</var>[,<var>wgt2</var>]] [-X ...] [-x]
<var>file_1</var> <var>file_2</var> [<var>file_3</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncflint</command> creates an output file that is a linear combination of the input files. This linear combination is a weighted average, a normalized weighted average, or an interpolation of the input files. Coordinate variables are not acted upon in any case, they are simply copied from <var>file_1</var>.</para>
      <para>There are two conceptually distinct methods of using <command>ncflint</command>. The first method is to specify the weight each input file contributes to the output file. In this method, the value <var>val3</var> of a variable in the output file <var>file_3</var> is determined from its values <var>val1</var> and <var>val2</var> in the two input files according to</para>
      <setvalue name="flg"></setvalue>
      <para><math><var>val3</var> = <var>wgt1</var>*<var>val1</var> + <var>wgt2</var>*<var>val2</var></math></para>
      <clearvalue name="flg"></clearvalue>
      <para>. Here at least <var>wgt1</var>, and, optionally, <var>wgt2</var>, are specified on the command line with the <samp>-w</samp> (or <samp>--weight</samp> or <samp>--wgt_var</samp>) switch. <indexterm index="cp"><code>-w <var>wgt1</var>[,<var>wgt2</var>]</code></indexterm><indexterm index="cp"><code>--weight <var>wgt1</var>[,<var>wgt2</var>]</code></indexterm><indexterm index="cp"><code>--wgt_var <var>wgt1</var>[,<var>wgt2</var>]</code></indexterm>If only <var>wgt1</var> is specified then <var>wgt2</var> is automatically computed as <math><var>wgt2</var> = 1 &minus; <var>wgt1</var></math>. Note that weights larger than 1<!-- /@w --> are allowed. Thus it is possible to specify <math><var>wgt1</var> = 2</math> and <math><var>wgt2</var> = -3</math>. One can use this functionality to multiply all the values in a given file by a constant.</para>
      <para>The second method of using <command>ncflint</command> is to specify the interpolation option with <samp>-i</samp><!-- /@w --> (or with the <samp>--ntp</samp> or <samp>--interpolate</samp> long options). This is really the inverse of the first method in the following sense. When the user specifies the weights directly, <command>ncflint</command> has no work to do besides multiplying the input values by their respective weights and adding the results together to produce the output values. It makes sense to use this when the weights are known <emph>a priori<!-- /@w --></emph>.</para>
      <para><indexterm index="cp">arrival value</indexterm>Another class of problems has the <dfn>arrival value</dfn> (i.e., <var>val3</var>) of a particular variable <var>var</var> known <emph>a priori<!-- /@w --></emph>. In this case, the implied weights can always be inferred by examining the values of <var>var</var> in the input files. This results in one equation in two unknowns, <var>wgt1</var> and <var>wgt2</var>:</para>
      <setvalue name="flg"></setvalue>
      <para><math><var>val3</var> = <var>wgt1</var>*<var>val1</var> + <var>wgt2</var>*<var>val2</var></math></para>
      <clearvalue name="flg"></clearvalue>
      <para>. Unique determination of the weights requires imposing the additional constraint of normalization on the weights: <math><var>wgt1</var> + <var>wgt2</var> = 1</math>. Thus, to use the interpolation option, the user specifies <var>var</var> and <var>val3</var> with the <samp>-i</samp> option. <command>ncflint</command> then computes <var>wgt1</var> and <var>wgt2</var>, and uses these weights on all variables to generate the output file. Although <var>var</var> may have any number of dimensions in the input files, it must represent a single, scalar value. <indexterm index="cp">degenerate dimension</indexterm>Thus any dimensions associated with <var>var</var> must be <dfn>degenerate</dfn>, i.e., of size one.</para>
      <para>If neither <samp>-i</samp> nor <samp>-w</samp> is specified on the command line, <command>ncflint</command> defaults to weighting each input file equally in the output file. This is equivalent to specifying <samp>-w 0.5</samp> or <samp>-w 0.5,0.5</samp>. Attempting to specify both <samp>-i</samp> and <samp>-w</samp> methods in the same command is an error.</para>
      <para><command>ncflint</command> does not interpolate variables of type <code>NC_CHAR</code> and <code>NC_BYTE</code>. This behavior is hardcoded.</para>
      <para><indexterm index="cp">missing values</indexterm><indexterm index="cp"><code>_FillValue</code></indexterm>Depending on your intuition, <command>ncflint</command> may treat missing values unexpectedly. Consider a point where the value in one input file, say <var>val1</var>, equals the missing value <var>mss_val_1</var> and, at the same point, the corresponding value in the other input file <var>val2</var> is not misssing (i.e., does not equal <var>mss_val_2</var>). There are three plausible answers, and this creates ambiguity.</para>
      <para>Option one<!-- /@w --> is to set <math><var>val3</var> = <var>mss_val_1</var></math>. The rationale is that <command>ncflint</command> is, at heart, an interpolator and interpolation involving a missing value is intrinsically undefined. <command>ncflint</command> currently implements this behavior since it is the most conservative and least likely to lead to misinterpretation.</para>
      <para>Option two<!-- /@w --> is to output the weighted valid data point, i.e.,</para>
      <setvalue name="flg"></setvalue>
      <para><math><var>val3</var> = <var>wgt2</var>*<var>val2</var></math></para>
      <clearvalue name="flg"></clearvalue>
      <para>. The rationale for this behavior is that interpolation is really a weighted average of known points, so <command>ncflint</command> should weight the valid point.</para>
      <para>Option three<!-- /@w --> is to return the <emph>unweighted</emph> valid point, i.e., <math><var>val3</var> = <var>val2</var></math>. This behavior would appeal to those who use <command>ncflint</command> to estimate data using the closest available data. When a point is not bracketed by valid data on both sides, it is better to return the known datum than no datum at all.</para>
      <para>The current implementation uses the first approach, Option one<!-- /@w -->. If you have strong opinions on this matter, let us know, since we are willing to implement the other approaches as options if there is enough interest.</para>
      <para role="continues">EXAMPLES</para>
      <para>Although it has other uses, the interpolation feature was designed to interpolate <var>file_3</var> to a time between existing files. Consider input files <file>85.nc</file> and <file>87.nc</file> containing variables describing the state of a physical system at times <math><code>time</code> = 85</math> and <math><code>time</code> = 87</math>. Assume each file contains its timestamp in the scalar variable <code>time</code>. Then, to linearly interpolate to a file <file>86.nc</file> which describes the state of the system at time at <code>time</code> = 86, we would use</para>
      <example xml:space="preserve">ncflint -i time,86 85.nc 87.nc 86.nc</example>
      <para>Say you have observational data covering January and April 1985 in two files named <file>85_01.nc</file> and <file>85_04.nc</file>, respectively. Then you can estimate the values for February and March by interpolating the existing data as follows. Combine <file>85_01.nc</file> and <file>85_04.nc</file> in a 2:1 ratio to make <file>85_02.nc</file>:</para>
      <example xml:space="preserve">ncflint -w 0.667 85_01.nc 85_04.nc 85_02.nc
ncflint -w 0.667,0.333 85_01.nc 85_04.nc 85_02.nc</example>
      <para>Multiply <file>85.nc</file> by 3<!-- /@w --> and by &minus;2<!-- /@w --> and add them together to make <file>tst.nc</file>:</para>
      <example xml:space="preserve">ncflint -w 3,-2 85.nc 85.nc tst.nc</example>
      <para role="continues"><indexterm index="cp">null operation</indexterm>This is an example of a null operation, so <file>tst.nc</file> should be identical (within machine precision) to <file>85.nc</file>.</para>
      <para>Add <file>85.nc</file> to <file>86.nc</file> to obtain <file>85p86.nc</file>, then subtract <file>86.nc</file> from <file>85.nc</file> to obtain <file>85m86.nc</file></para>
      <example xml:space="preserve">ncflint -w 1,1 85.nc 86.nc 85p86.nc
ncflint -w 1,-1 85.nc 86.nc 85m86.nc
ncdiff 85.nc 86.nc 85m86.nc</example>
      <para role="continues">Thus <command>ncflint</command> can be used to mimic some <command>ncbo</command> operations. <indexterm index="cp">broadcasting variables</indexterm>However this is not a good idea in practice because <command>ncflint</command> does not broadcast (see <xref><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></xref>) conforming variables during arithmetic. Thus the final two commands would produce identical results except that <command>ncflint</command> would fail if any variables needed to be broadcast.</para>
      <para><indexterm index="cp"><code>units</code></indexterm>Rescale the dimensional units of the surface pressure <code>prs_sfc</code> from Pascals to hectopascals (millibars)</para>
      <example xml:space="preserve">ncflint -C -v prs_sfc -w 0.01,0.0 in.nc in.nc out.nc
ncatted -a units,prs_sfc,o,c,millibar out.nc</example>
      <para role="continues"></para>
    </section>
  </node>
  <node>
    <nodename>ncks netCDF Kitchen Sink</nodename>
    <nodenext>ncpdq netCDF Permute Dimensions Quickly</nodenext>
    <nodeprev>ncflint netCDF File Interpolator</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncks</command> netCDF Kitchen Sink</title>
      <para><indexterm index="cp">kitchen sink</indexterm><indexterm index="cp">printing files contents</indexterm><indexterm index="cp">printing variables</indexterm><indexterm index="cp">ncks</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncks [-3] [-4] [-6] [-A] [-a] [-B] [-b <var>binary-file</var>] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [--fix_rec_dmn]
[-F] [-H] [-h] [--hdr_pad <var>nbr</var>] [-L <var>dfl_lvl</var>] [-l <var>path</var>]
[-M] [-m] [--mk_rec_dmn <var>dim</var>] [--md5_digest]
[-O] [-o <var>output-file</var>] [-P] [-p <var>path</var>] [-Q] [-q] [-R] [-r]
[-s <var>format</var>] [-u] [-v <var>var</var>[,&dots;]] [-X ...] [-x]
<var>input-file</var> [[<var>output-file</var>]]</example>
      <para role="continues">DESCRIPTION</para>
      <para><indexterm index="cp"><command>ncextr</command></indexterm><command>ncks</command> combines selected features of <command>ncdump</command>, <command>ncextr</command>, and the nccut and ncpaste specifications into one versatile utility. <command>ncks</command> extracts a subset of the data from <var>input-file</var> and prints it as <acronym><acronymword>ASCII</acronymword></acronym> text to <file>stdout</file>, writes it in flat binary format to <file>binary-file</file>, and writes (or pastes) it in netCDF format to <var>output-file</var>.</para>
      <para><command>ncks</command> will print netCDF data in <acronym><acronymword>ASCII</acronymword></acronym> format to <code>stdout</code>, like <command>ncdump</command>, but with these differences: <command>ncks</command> prints data in a tabular format intended to be easy to search for the data you want, one datum per screen line, with all dimension subscripts and coordinate values (if any) preceding the datum. Option <samp>-s</samp> (or long options <samp>--sng_fmt</samp> and <samp>--string</samp>) lets the user format the data using C-style format strings.</para>
      <para>Options <samp>-a</samp>, <samp>-F</samp> , <samp>-H</samp>, <samp>-M</samp>, <samp>-m</samp>, <samp>-P</samp>, <samp>-Q</samp>, <samp>-q</samp>, <samp>-s</samp>, and <samp>-u</samp> (and their long option counterparts) control the formatted appearance of the data.</para>
      <para><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm><command>ncks</command> extracts (and optionally creates a new netCDF file comprised of) only selected variables from the input file (similar to the old <command>ncextr</command> specification). Only variables and coordinates may be specifically included or excluded&mdash;all global attributes and any attribute associated with an extracted variable are copied to the screen and/or output netCDF file. Options <samp>-c</samp>, <samp>-C</samp>, <samp>-v</samp>, and <samp>-x</samp> (and their long option synonyms) control which variables are extracted.</para>
      <para><command>ncks</command> extracts hyperslabs from the specified variables (<command>ncks</command> implements the original <command>nccut</command> specification). Option <samp>-d</samp> controls the hyperslab specification. Input dimensions that are not associated with any output variable do not appear in the output netCDF. This feature removes superfluous dimensions from netCDF files.</para>
      <para><indexterm index="cp">appending data</indexterm><indexterm index="cp">merging files</indexterm><command>ncks</command> will append variables and attributes from the <var>input-file</var> to <var>output-file</var> if <var>output-file</var> is a pre-existing netCDF file whose relevant dimensions conform to dimension sizes of <var>input-file</var>. The append features of <command>ncks</command> are intended to provide a rudimentary means of adding data from one netCDF file to another, conforming, netCDF file. If naming conflicts exist between the two files, data in <var>output-file</var> is usually overwritten by the corresponding data from <var>input-file</var>. Thus, when appending, the user should backup <var>output-file</var> in case valuable data are inadvertantly overwritten.</para>
      <para>If <var>output-file</var> exists, the user will be queried whether to <dfn>overwrite</dfn>, <dfn>append</dfn>, or <dfn>exit</dfn> the <command>ncks</command> call completely. Choosing <dfn>overwrite</dfn> destroys the existing <var>output-file</var> and create an entirely new one from the output of the <command>ncks</command> call. Append has differing effects depending on the uniqueness of the variables and attributes output by <command>ncks</command>: If a variable or attribute extracted from <var>input-file</var> does not have a name conflict with the members of <var>output-file</var> then it will be added to <var>output-file</var> without overwriting any of the existing contents of <var>output-file</var>. In this case the relevant dimensions must agree (conform) between the two files; new dimensions are created in <var>output-file</var> as required. <indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm>When a name conflict occurs, a global attribute from <var>input-file</var> will overwrite the corresponding global attribute from <var>output-file</var>. If the name conflict occurs for a non-record variable, then the dimensions and type of the variable (and of its coordinate dimensions, if any) must agree (conform) in both files. Then the variable values (and any coordinate dimension values) from <var>input-file</var> will overwrite the corresponding variable values (and coordinate dimension values, if any) in <var>output-file</var> <footnote><para> Those familiar with netCDF mechanics might wish to know what is happening here: <command>ncks</command> does not attempt to redefine the variable in <var>output-file</var> to match its definition in <var>input-file</var>, <command>ncks</command> merely copies the values of the variable and its coordinate dimensions, if any, from <var>input-file</var> to <var>output-file</var>. </para></footnote>.</para>
      <para>Since there can only be one record dimension in a file, the record dimension must have the same name (but not necessarily the same size) in both files if a record dimension variable is to be appended. If the record dimensions are of differing sizes, the record dimension of <var>output-file</var> will become the greater of the two record dimension sizes, the record variable from <var>input-file</var> will overwrite any counterpart in <var>output-file</var> and fill values will be written to any gaps left in the rest of the record variables (I think). In all cases variable attributes in <var>output-file</var> are superseded by attributes of the same name from <var>input-file</var>, and left alone if there is no name conflict.</para>
      <para>Some users may wish to avoid interactive <command>ncks</command> queries about whether to overwrite existing data. For example, batch scripts will fail if <command>ncks</command> does not receive responses to its queries. Options <samp>-O</samp> and <samp>-A</samp> are available to force overwriting existing files and variables, respectively.</para>

      <unnumberedsubsec>
        <title>Options specific to <command>ncks</command></title>
        <para>The following list provides a short summary of the features unique to <command>ncks</command>. Features common to many operators are described in <xref><xrefnodename>Common features</xrefnodename></xref>.</para>
        <table><indexterm index="cp">alphabetization</indexterm><indexterm index="cp">sort alphabetically</indexterm><indexterm index="cp"><code>-a</code></indexterm><indexterm index="cp"><code>--abc</code></indexterm><indexterm index="cp"><code>--alphabetize</code></indexterm>
          <tableitem>
            <tableterm><samp>-a</samp></tableterm>
            <item>
              <para>Do not alphabetize extracted fields. By default, the specified output variables are extracted, printed, and written to disk in alphabetical order. This tends to make long output lists easier to search for particular variables. Specifying <code>-a</code> results in the variables being extracted, printed, and written to disk in the order in which they were saved in the input file. Thus <code>-a</code> retains the original ordering of the variables. Also <samp>--abc</samp> and <samp>--alphabetize</samp>.</para>
              <para><indexterm index="cp">binary format</indexterm><indexterm index="cp"><code>-B</code></indexterm><indexterm index="cp"><code>--bnr</code></indexterm><indexterm index="cp"><code>--binary</code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-B <file>file</file></samp></tableterm>
            <item>
              <para>Activate native machine binary output writing to the default binary file, <file>ncks.bnr</file>. pThe <code>-B</code> switch is redundant when the <code>-b</code> <file>file</file><!-- /@w --> option is specified, and native binary output will be directed to the binary file <file>file</file>. Also <samp>--bnr</samp> and <samp>--binary</samp>. Writing packed variables in binary format is not supported.</para>
              <para><indexterm index="cp"><code>-b</code></indexterm><indexterm index="cp"><code>--fl_bnr</code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-b <file>file</file></samp></tableterm>
            <item>
              <para>Activate native machine binary output writing to binary file <file>file</file>. Also <samp>--fl_bnr</samp> and <samp>--binary-file</samp>. Writing packed variables in binary format is not supported.</para>
              <para><indexterm index="cp">stride</indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]]</samp></tableterm>
            <item>
              <para>Add <dfn>stride</dfn> argument to hyperslabber. For a complete description of the <var>stride</var> argument, See <xref><xrefnodename>Stride</xrefnodename></xref>.</para>
              <para><indexterm index="cp">record dimension</indexterm><indexterm index="cp">fixed dimension</indexterm><indexterm index="cp"><code>--fix_rec_dmn</code></indexterm><indexterm index="cp"><code>--no_rec_dmn</code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>--fix_rec_dmn</samp></tableterm>
            <item>
              <para>Change all record dimensions in the input file into fixed dimensions in the output file. Also <samp>--no_rec_dmn</samp>.</para>
              <para><indexterm index="cp">record dimension</indexterm><indexterm index="cp">fixed dimension</indexterm><indexterm index="cp"><code>--mk_rec_dmn <var>dim</var></code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>--mk_rec_dmn <var>dim</var></samp></tableterm>
            <item>
              <para>Change existing dimension <var>dim</var> to a record dimension in the output file. See <xref><xrefnodename>ncecat netCDF Ensemble Concatenator</xrefnodename></xref> and <xref><xrefnodename>ncpdq netCDF Permute Dimensions Quickly</xrefnodename></xref> for other methods of changing variable dimensionality, including the record dimension.</para>
              <para><indexterm index="cp"><code>-H</code></indexterm><indexterm index="cp"><code>--data</code></indexterm><indexterm index="cp"><code>--hieronymus</code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-H</samp></tableterm>
            <item>
              <para>Print data to screen. Also activated using <samp>--print</samp> or <samp>--prn</samp>. By default <command>ncks</command> prints all metadata and data to screen if no netCDF output file is specified. Use <samp>-H</samp> to print data to screen if a netCDF output is specified, or to restrict printing to data (no metadata) when no netCDF output is specified. Unless otherwise specified (with <code>-s</code>), each element of the data hyperslab prints on a separate line containing the names, indices, and, values, if any, of all of the variables dimensions. The dimension and variable indices refer to the location of the corresponding data element with respect to the variable as stored on disk (i.e., not the hyperslab).</para>
              <example xml:space="preserve">% ncks -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1
lat[0]=-90 lev[0]=100 lon[2]=180 three_dmn_var[2]=2
...
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23</example>
              <para>Printing the same variable with the <samp>-F</samp> option shows the same variable indexed with Fortran conventions</para>
              <example xml:space="preserve">% ncks -F -C -v three_dmn_var in.nc
lon(1)=0 lev(1)=100 lat(1)=-90 three_dmn_var(1)=0
lon(2)=90 lev(1)=100 lat(1)=-90 three_dmn_var(2)=1
lon(3)=180 lev(1)=100 lat(1)=-90 three_dmn_var(3)=2
...</example>
              <para>Printing a hyperslab does not affect the variable or dimension indices since these indices are relative to the full variable (as stored in the input file), and the input file has not changed. However, if the hyperslab is saved to an output file and those values are printed, the indices will change: 
<!-- fxm: replace with new MSA output style --></para>
              <example xml:space="preserve">% ncks -H -d lat,90.0 -d lev,1000.0 -v three_dmn_var in.nc out.nc
...
lat[1]=90 lev[2]=1000 lon[0]=0 three_dmn_var[20]=20
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23
% ncks -C -v three_dmn_var out.nc
lat[0]=90 lev[0]=1000 lon[0]=0 three_dmn_var[0]=20
lat[0]=90 lev[0]=1000 lon[1]=90 three_dmn_var[1]=21
lat[0]=90 lev[0]=1000 lon[2]=180 three_dmn_var[2]=22
lat[0]=90 lev[0]=1000 lon[3]=270 three_dmn_var[3]=23</example>
              <para><indexterm index="cp"><code>-M</code></indexterm><indexterm index="cp"><code>--Mtd</code></indexterm><indexterm index="cp"><code>--Metadata</code></indexterm><indexterm index="cp">metadata, global</indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-M</samp></tableterm>
            <item>
              <para>Print to screen the global metadata describing the file. This includes file summary information and global attributes. Also <samp>--Mtd</samp> and <samp>--Metadata</samp>. By default <command>ncks</command> prints global metadata to screen if no netCDF output file and no variable extraction list is specified (with <samp>-v</samp>). Use <samp>-M</samp> to print global metadata to screen if a netCDF output is specified, or if a variable extraction list is specified (with <samp>-v</samp>).</para>
              <para>The various combinations of printing switches can be confusing. In an attempt to anticipate what most users want to do, <command>ncks</command> uses context-sensitive defaults for printing. Our goal is to minimize the use of switches required to accomplish the common operations. We assume that users creating a new file or overwriting (e.g., with <samp>-O</samp>) an existing file usually wish to copy all global and variable-specific attributes to the new file. In contrast, we assume that users appending (e.g., with <samp>-A</samp> an explicit variable list from one file to another usually wish to copy only the variable-specific attributes to the output file. The switches <samp>-H</samp>, <samp>-M</samp>, and <samp>-m</samp> switches are implemented as toggles which reverse the default behavior. The most confusing aspect of this is that <samp>-M</samp> inhibits copying global metadata in overwrite mode and causes copying of global metadata in append mode.</para>
              <example xml:space="preserve">ncks -O              in.nc out.nc # Copy   VAs and GAs
ncks -O       -v one in.nc out.nc # Copy   VAs and GAs
ncks -O -M    -v one in.nc out.nc # Copy   VAs not GAs
ncks -O    -m -v one in.nc out.nc # Copy   GAs not VAs
ncks -O -M -m -v one in.nc out.nc # Copy   only data (no atts)
ncks -A              in.nc out.nc # Append VAs and GAs
ncks -A       -v one in.nc out.nc # Append VAs not GAs
ncks -A -M    -v one in.nc out.nc # Append VAs and GAs
ncks -A    -m -v one in.nc out.nc # Append only data (no atts)
ncks -A -M -m -v one in.nc out.nc # Append GAs not VAs</example>
              <para>where <code>VAs</code> and <code>GAs</code> denote variable and global attributes, respectively.</para>
              <para><indexterm index="cp"><command>ncdump</command></indexterm><indexterm index="cp"><code>-m</code></indexterm><indexterm index="cp"><code>--mtd</code></indexterm><indexterm index="cp"><code>--metadata</code></indexterm><indexterm index="cp">metadata</indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-m</samp></tableterm>
            <item>
              <para>Print variable metadata to screen (similar to <kbd>ncdump -h</kbd>). This displays all metadata pertaining to each variable, one variable at a time. <indexterm index="cp">chunking</indexterm><indexterm index="cp">compression</indexterm><indexterm index="cp">deflation</indexterm>This includes information on the storage properties of the variable, such as whether it employs chunking, compression, or packing. Also activated using <samp>--mtd</samp> and <samp>--metadata</samp>. The <command>ncks</command> default behavior is to print variable metadata to screen if no netCDF output file is specified. Use <samp>-m</samp> to print variable metadata to screen if a netCDF output is specified.</para>
              <para><indexterm index="cp"><code>-P</code></indexterm><indexterm index="cp"><code>--print</code></indexterm><indexterm index="cp"><code>--prn</code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-P</samp></tableterm>
            <item>
              <para>Print data, metadata, and units to screen. The <samp>-P</samp> switch is a convenience abbreviation for <samp>-C -H -M -m -u</samp>. Also activated using <samp>--print</samp> or <samp>--prn</samp>. This set of switches is useful for exploring file contents.</para>
              <para><indexterm index="cp"><code>-Q</code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-Q</samp></tableterm>
            <item>
              <para>Toggle printing of dimension indices and coordinate values when printing arrays. Each variable's name appears flush left in the output. This helps locate specific variables in lists with many variables and different dimensions.</para>
              <para><indexterm index="cp"><code>-q</code></indexterm><indexterm index="cp"><code>--quiet</code></indexterm><indexterm index="cp">quiet</indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-q</samp></tableterm>
            <item>
              <para>Turn off all printing to screen. This overrides the setting of all print-related switches, equivalent to <kbd>-H -M -m</kbd> when in single-file printing mode. When invoked with <code>-R</code> (see <xref><xrefnodename>Retaining Retrieved Files</xrefnodename></xref>), <command>ncks</command> automatically sets <code>-q</code>. This allows <command>ncks</command> to retrieve remote files without automatically trying to print them. Also <samp>--quiet</samp>.</para>
              <para><indexterm index="cp"><code>-s</code></indexterm><indexterm index="cp"><code>--string</code></indexterm><indexterm index="cp"><code>--sng_fmt</code></indexterm><indexterm index="cp"><code>printf()</code></indexterm><indexterm index="cp">C language</indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-s <var>format</var></samp></tableterm>
            <item>
              <para>String format for text output. Accepts C language<!-- /@w --> escape sequences and <code>printf()</code> formats. Also <samp>--string</samp>  and <samp>--sng_fmt</samp>.</para>
              <para><indexterm index="cp"><code>-u</code></indexterm><indexterm index="cp"><code>--units</code></indexterm></para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><samp>-u</samp></tableterm>
            <item>
              <para>Toggle the printing of a variable's <code>units</code> attribute, if any, with its values. Also <samp>--units</samp>.</para>
            </item>
          </tableitem>
        </table>
        <menu>
          <menuentry>
            <menunode>Filters for &lt;command&gt;ncks&lt;/command&gt;</menunode>
            <menutitle>Filters for <command>ncks</command></menutitle>
            <menucomment></menucomment>
          </menuentry>
        </menu>
      </unnumberedsubsec>
    </section>
  </node>
  <node>
    <nodename>Filters for <command>ncks</command></nodename>
    <nodeprev>ncks netCDF Kitchen Sink</nodeprev>
    <nodeup>ncks netCDF Kitchen Sink</nodeup>
    <subsection>
      <title>Filters for <command>ncks</command></title>
      <para><indexterm index="cp"><acronym><acronymword>UNIX</acronymword></acronym></indexterm><indexterm index="cp"><command>ncattget</command></indexterm><indexterm index="cp"><command>nclist</command></indexterm><indexterm index="cp"><file>.bashrc</file></indexterm><indexterm index="cp">filters</indexterm><indexterm index="cp">alias</indexterm><indexterm index="cp">shell</indexterm><indexterm index="cp">Bash shell</indexterm><indexterm index="cp">Csh shell</indexterm><indexterm index="cp">Sh shell</indexterm><indexterm index="cp"><command>bash</command></indexterm>We encourage the use of standard <acronym><acronymword>UNIX</acronymword></acronym> pipes and filters to narrow the verbose output of <command>ncks</command> into more precise targets. For example, to obtain an uncluttered listing of the variables in a file try</para>
      <example xml:space="preserve">ncks -m in.nc | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort</example>
      <para>A Bash user could alias the previous filter to the shell command <command>nclist</command> as shown below. More complex examples could involve command line arguments. For example, a user may frequently be interested in obtaining the value of an attribute, e.g., for textual file examination or for passing to another shell command. Say the attribute is <code>purpose</code>, the variable is <code>z</code>, and the file is <code>in.nc</code>. In this example, <command>ncks -m -v z</command> is too verbose so a robust <command>grep</command> and <command>cut</command> filter is desirable, such as</para>
      <example xml:space="preserve">ncks -M -m in.nc | grep -E -i "z attribute [0-9]+: purpose" | cut -f 11- -d ' ' | sort</example>
      <para>The filters are clearly too complex to remember on-the-fly so the entire procedure could be implemented as a shell command or function called, say, <command>ncattget</command></para>
      <example xml:space="preserve">function ncattget { ncks -M -m ${3} | grep -E -i "^${2} attribute [0-9]+: ${1}" | cut -f 11- -d ' ' | sort ; }</example>
      <para>The shell <command>ncattget</command> is invoked with three arugments that are, in order, the names of the attribute, variable, and file to examine. Global attributes are indicated by using a variable name of <code>global</code>. This definition yields the following results</para>
      <example xml:space="preserve">% ncattget purpose z in.nc
Height stored with a monotonically increasing coordinate
% ncattget Purpose Z in.nc
Height stored with a monotonically increasing coordinate
% ncattget history z in.nc
% ncattget history global in.nc
History global attribute.</example>
      <para>Note that case sensitivity has been turned off for the variable and attribute names (and could be turned on by removing the <samp>-i</samp> switch to <command>grep</command>). Furthermore, extended regular expressions may be used for both the variable and attribute names. The next two commands illustrate this by searching for the values of <code>purpose</code> in all variables, and then for all attributes of the variable <code>z</code>:</para>
      <example xml:space="preserve">% ncattget purpose .+ in.nc
1-D latitude coordinate referred to by geodesic grid variables
1-D longitude coordinate referred to by geodesic grid variables
...
% ncattget .+ Z in.nc
Height
Height stored with a monotonically increasing coordinate
meter</example>
      <para>Extended filters are best stored as shell commands if they are used frequently. Shell commands may be re-used when they are defined in shell configuration files. These files are usually named <file>.bashrc</file>, <file>.cshrc</file>, and <file>.profile</file> for the Bash, Csh, and Sh shells, respectively.</para>
      <example xml:space="preserve"># NB: Untested on Csh, Ksh, Sh, Zsh! Send us feedback!
# Bash shell (/bin/bash) users place these in .bashrc
function nclist { ncks -m ${1} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort ; }
function ncattget { ncks -M -m ${3} | grep -E -i "^${2} attribute [0-9]+: ${1}" | cut -f 11- -d ' ' | sort ; }
# Csh shell (/bin/csh) users place these in .cshrc
nclist() { ncks -m ${1} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort ; }
ncattget() { ncks -M -m ${3} | grep -E -i "^${2} attribute [0-9]+: ${1}" | cut -f 11- -d ' ' | sort ; }
# Sh shell (/bin/sh) users place these in .profile
nclist() { ncks -m ${1} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort ; }
ncattget() { ncks -M -m ${3} | grep -E -i "^${2} attribute [0-9]+: ${1}" | cut -f 11- -d ' ' | sort ; }</example>
      <para role="continues">EXAMPLES</para>
      <para>View all data in netCDF <file>in.nc</file>, printed with Fortran indexing conventions:</para>
      <example xml:space="preserve">ncks -F in.nc</example>
      <para>Copy the netCDF file <file>in.nc</file> to file <file>out.nc</file>.</para>
      <example xml:space="preserve">ncks in.nc out.nc</example>
      <para>Now the file <file>out.nc</file> contains all the data from <file>in.nc</file>. There are, however, two differences between <file>in.nc</file> and <file>out.nc</file>. <indexterm index="cp"><code>history</code></indexterm>First, the <code>history</code> global attribute (see <xref><xrefnodename>History Attribute</xrefnodename></xref>) will contain the command used to create <file>out.nc</file>. <indexterm index="cp">alphabetize output</indexterm><indexterm index="cp">sort alphabetically</indexterm><indexterm index="cp"><code>-a</code></indexterm>Second, the variables in <file>out.nc</file> will be defined in alphabetical order. Of course the internal storage of variable in a netCDF file should be transparent to the user, but there are cases when alphabetizing a file is useful (see description of <code>-a</code> switch).</para>
      <para><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm><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>Copy all global attributes (and no variables) from <file>in.nc</file> to <file>out.nc</file>:</para>
      <example xml:space="preserve">ncks -A -x ~/nco/data/in.nc ~/out.nc</example>
      <para>The <samp>-x</samp> switch tells <acronym><acronymword>NCO</acronymword></acronym> to use the complement of the extraction list (see <xref><xrefnodename>Subsetting Variables</xrefnodename></xref>). Since no extraction list is explicitly specified (with <samp>-v</samp>), the default is to extract all variables. The complement of all variables is no variables. <indexterm index="cp"><code>-A</code></indexterm><indexterm index="cp"><code>--apn</code></indexterm><indexterm index="cp"><code>--append</code></indexterm><indexterm index="cp">appending to files</indexterm>Without any variables to extract, the append (<samp>-A</samp>) command (see <xref><xrefnodename>Appending Variables</xrefnodename></xref>) has only to extract and copy (i.e., append) global attributes to the output file.</para>
      <para><indexterm index="cp"><code>printf()</code></indexterm><indexterm index="cp"><code>\n</code> (linefeed)</indexterm><indexterm index="cp"><code>\t</code> (horizontal tab)</indexterm>Print variable <code>three_dmn_var</code> from file <file>in.nc</file> with default notations. Next print <code>three_dmn_var</code> as an un-annotated text column. Then print <code>three_dmn_var</code> signed with very high precision. Finally, print <code>three_dmn_var</code> as a comma-separated list.</para>
      <example xml:space="preserve">% ncks -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1
...
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23
% ncks -s '%f\n' -C -v three_dmn_var in.nc
0.000000
1.000000
...
23.000000
% ncks -s '%+16.10f\n' -C -v three_dmn_var in.nc
   +0.0000000000
   +1.0000000000
...
  +23.0000000000
% ncks -s '%f, ' -C -v three_dmn_var in.nc
0.000000, 1.000000, ..., 23.000000,</example>
      <para role="continues">The second and third options are useful when pasting data into text files like reports or papers. See <xref><xrefnodename>ncatted netCDF Attribute Editor</xrefnodename></xref>, for more details on string formatting and special characters.</para>
      <para>One dimensional arrays of characters stored as netCDF variables are automatically printed as strings, whether or not they are NUL-terminated, e.g.,</para>
      <example xml:space="preserve">ncks -v fl_nm in.nc</example>
      <para role="continues">The <code>%c</code> formatting code is useful for printing multidimensional arrays of characters representing fixed length strings</para>
      <example xml:space="preserve">ncks -s '%c' -v fl_nm_arr in.nc</example>
      <para role="continues"><indexterm index="cp"><code>core dump</code></indexterm>Using the <code>%s</code> format code on strings which are not NUL-terminated (and thus not technically strings) is likely to result in a core dump.</para>
      <para><indexterm index="cp">subsetting</indexterm><indexterm index="cp">exclusion</indexterm><indexterm index="cp">extraction</indexterm>Create netCDF <file>out.nc</file> containing all variables, and any associated coordinates, except variable <code>time</code>, from netCDF <file>in.nc</file>:</para>
      <example xml:space="preserve">ncks -x -v time in.nc out.nc</example>
      <para>Extract variables <code>time</code> and <code>pressure</code> from netCDF <file>in.nc</file>. If <file>out.nc</file> does not exist it will be created. Otherwise the you will be prompted whether to append to or to overwrite <file>out.nc</file>:</para>
      <example xml:space="preserve">ncks -v time,pressure in.nc out.nc
ncks -C -v time,pressure in.nc out.nc</example>
      <para role="continues">The first version of the command creates an <file>out.nc</file> which contains <code>time</code>, <code>pressure</code>, and any coordinate variables associated with <var>pressure</var>. The <file>out.nc</file> from the second version is guaranteed to contain only two variables <code>time</code> and <code>pressure</code>.</para>
      <para>Create netCDF <file>out.nc</file> containing all variables from file <file>in.nc</file>. Restrict the dimensions of these variables to a hyperslab. Print (with <code>-H</code>) the hyperslabs to the screen for good measure. The specified hyperslab is: the fifth value in dimension <code>time</code>; the half-open range <math><var>lat</var> &gt; 0.</math> in coordinate <code>lat</code>; the half-open range <math><var>lon</var> &lt; 330.</math> in coordinate <code>lon</code>; the closed interval <math>0.3 &lt; <var>band</var> &lt; 0.5</math> in coordinate <code>band</code>; and cross-section closest to 1000&period; in coordinate <code>lev</code>. Note that limits applied to coordinate values are specified with a decimal point, and limits applied to dimension indices do not have a decimal point See <xref><xrefnodename>Hyperslabs</xrefnodename></xref>.</para>
      <example xml:space="preserve">ncks -H -d time,5 -d lat,,0.0 -d lon,330.0, -d band,0.3,0.5
-d lev,1000.0 in.nc out.nc</example>
      <para><indexterm index="cp">wrapped coordinates</indexterm>Assume the domain of the monotonically increasing longitude coordinate <code>lon</code> is <math>0 &lt; <var>lon</var> &lt; 360</math>. Here, <code>lon</code> is an example of a wrapped coordinate. <command>ncks</command> will extract a hyperslab which crosses the Greenwich meridian simply by specifying the westernmost longitude as <var>min</var> and the easternmost longitude as <var>max</var>, as follows:</para>
      <example xml:space="preserve">ncks -d lon,260.0,45.0 in.nc out.nc</example>
      <para>For more details See <xref><xrefnodename>Wrapped Coordinates</xrefnodename></xref>.</para>
    </subsection>
  </node>
  <node>
    <nodename>ncpdq netCDF Permute Dimensions Quickly</nodename>
    <nodenext>ncra netCDF Record Averager</nodenext>
    <nodeprev>ncks netCDF Kitchen Sink</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncpdq</command> netCDF Permute Dimensions Quickly</title>
      <para><indexterm index="cp">ncpdq</indexterm><indexterm index="cp">ncpack</indexterm><indexterm index="cp">ncunpack</indexterm><indexterm index="cp">reshape variables</indexterm><indexterm index="cp">permute dimensions</indexterm><indexterm index="cp">reverse dimensions</indexterm><indexterm index="cp">re-order dimensions</indexterm><indexterm index="cp">re-dimension</indexterm><indexterm index="cp">packing</indexterm><indexterm index="cp">unpacking</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncpdq [-3] [-4] [-6] [-A] [-a [-]<var>dim</var>[,&dots;]] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-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>]
[-M <var>pck_map</var>] [-O] [-o <var>output-file</var>] [-P <var>pck_plc</var>] [-p <var>path</var>]
[-R] [-r] [-t <var>thr_nbr</var>] [-U] [-v <var>var</var>[,&dots;]] [-X ...] [-x]
<var>input-file</var> [<var>output-file</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncpdq</command> performs one of two distinct functions, packing or dimension permutation, but not both, when invoked. <command>ncpdq</command> is optimized to perform these actions in a parallel fashion with a minimum of time and memory. The <dfn>pdq</dfn> may stand for &ldquo;Permute Dimensions Quickly&rdquo;, &ldquo;Pack Data Quietly&rdquo;, &ldquo;Pillory Dan Quayle&rdquo;, or other silly uses.</para>
      <para><indexterm index="cp"><code>add_offset</code></indexterm><indexterm index="cp"><code>scale_factor</code></indexterm><indexterm index="cp"><command>ncap2</command></indexterm><indexterm index="cp">packing policy</indexterm></para>
      <unnumberedsubsec>
        <title>Packing and Unpacking Functions</title>
        <para>The <command>ncpdq</command> packing (and unpacking) algorithms are described in <xref><xrefnodename>Methods and functions</xrefnodename></xref>, and are also implemented in <command>ncap2</command>. <command>ncpdq</command> extends the functionality of these algorithms by providing high level control of the <dfn>packing policy</dfn> so that users can consistently pack (and unpack) entire files with one command. <indexterm index="cp"><var>pck_plc</var></indexterm><indexterm index="cp"><code>-P <var>pck_plc</var></code></indexterm><indexterm index="cp"><code>--pck_plc <var>pck_plc</var></code></indexterm><indexterm index="cp"><code>--pack_policy <var>pck_plc</var></code></indexterm>The user specifies the desired packing policy with the <samp>-P</samp> switch (or its long option equivalents, <samp>--pck_plc</samp> and <samp>--pack_policy</samp>) and its <var>pck_plc</var> argument. Four packing policies are currently implemented:&linebreak;</para>
        <table>
          <tableitem>
            <tableterm><dfn>Packing (and Re-Packing) Variables [<emph>default</emph>]</dfn></tableterm>
            <item>
              <para>Definition: Pack unpacked variables, re-pack packed variables&linebreak; Alternate invocation: <code>ncpack</code>&linebreak; <var>pck_plc</var> key values: <samp>all_new</samp>, <samp>pck_all_new_att</samp>&linebreak;</para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><dfn>Packing (and not Re-Packing) Variables</dfn></tableterm>
            <item>
              <para>Definition: Pack unpacked variables, copy packed variables&linebreak; Alternate invocation: none&linebreak; <var>pck_plc</var> key values: <samp>all_xst</samp>, <samp>pck_all_xst_att</samp>&linebreak;</para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><dfn>Re-Packing Variables</dfn></tableterm>
            <item>
              <para>Definition: Re-pack packed variables, copy unpacked variables&linebreak; Alternate invocation: none&linebreak; <var>pck_plc</var> key values: <samp>xst_new</samp>, <samp>pck_xst_new_att</samp>&linebreak;</para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><dfn>Unpacking</dfn></tableterm>
            <item>
              <para>Definition: Unpack packed variables, copy unpacked variables&linebreak; Alternate invocation: <code>ncunpack</code>&linebreak; <var>pck_plc</var> key values: <samp>upk</samp>, <samp>unpack</samp>, <samp>pck_upk</samp>&linebreak;</para>
            </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>Regardless of the packing policy selected, <command>ncpdq</command> no longer (as of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.4 in October, 2010) packs coordinate variables, or the special variables, weights, and other grid properties described in <xref><xrefnodename>CF Conventions</xrefnodename></xref>. Prior <command>ncpdq</command> versions treated coordinate variables and grid properties no differently from other variables. However, coordinate variables are one-dimensional, so packing saves little space on large files, and the resulting files are difficult for humans to read. Concurrently, Gaussian and area weights and other grid properties are often used to derive fields in re-inflated (unpacked) files, so packing such grid properties causes a considerable loss of precision in downstream data processing. If users express strong wishes to pack grid properties, we will implement new packing policies. An immediate workaround for those needing to pack grid properties now, is to use the <command>ncap2</command> packing functions or to rename the grid properties prior to calling <command>ncpdq</command>. We welcome your feedback.</para>
        <para>To reduce required memorization of these complex policy switches, <command>ncpdq</command> may also be invoked via a synonym or with switches that imply a particular policy. <command>ncpack</command> is a synonym for <command>ncpdq</command> and behaves the same in all respects. Both <command>ncpdq</command> and <command>ncpack</command> assume a default packing policy request of <samp>all_new</samp>. Hence <command>ncpack</command> may be invoked without any <samp>-P</samp> switch, unlike <command>ncpdq</command>. Similarly, <command>ncunpack</command> is a synonym for <command>ncpdq</command> except that <command>ncpack</command> implicitly assumes a request to unpack, i.e., <samp>-P pck_upk</samp>. <indexterm index="cp"><code>-U</code></indexterm><indexterm index="cp"><code>--upk</code></indexterm><indexterm index="cp"><code>--unpack</code></indexterm>Finally, the <command>ncpdq</command> <samp>-U</samp> switch (or its long option equivalents, <samp>--upk</samp> and <samp>--unpack</samp>) requires no argument. It simply requests unpacking.</para>
        <para>Given the menagerie of synonyms, equivalent options, and implied options, a short list of some equivalent commands is appropriate. The following commands are equivalent for packing: <code>ncpdq -P all_new</code>, <code>ncpdq --pck_plc=all_new</code>, and <code>ncpack</code>. The following commands are equivalent for unpacking: <code>ncpdq -P upk</code>, <code>ncpdq -U</code>, <code>ncpdq --pck_plc=unpack</code>, and <code>ncunpack</code>. Equivalent commands for other packing policies, e.g., <samp>all_xst</samp>, follow by analogy. <indexterm index="cp"><command>alias</command></indexterm><indexterm index="cp"><command>ln -s</command></indexterm><indexterm index="cp">symbolic links</indexterm>Note that <command>ncpdq</command> synonyms are subject to the same constraints and recommendations discussed in the secion on <command>ncbo</command> synonyms (see <xref><xrefnodename>ncbo netCDF Binary Operator</xrefnodename></xref>). That is, symbolic links must exist from the synonym to <command>ncpdq</command>, or else the user must define an <command>alias</command>.</para>
        <para><indexterm index="cp">packing map</indexterm><indexterm index="cp"><var>pck_map</var></indexterm><indexterm index="cp"><code>-M <var>pck_map</var></code></indexterm><indexterm index="cp"><code>--pck_map <var>pck_map</var></code></indexterm><indexterm index="cp"><code>--map <var>pck_map</var></code></indexterm>The <command>ncpdq</command> packing algorithms must know to which type particular types of input variables are to be packed. The correspondence between the input variable type and the output, packed type, is called the <dfn>packing map</dfn>. The user specifies the desired packing map with the <samp>-M</samp> switch (or its long option equivalents, <samp>--pck_map</samp> and <samp>--map</samp>) and its <var>pck_map</var> argument. Five packing maps are currently implemented:&linebreak; <indexterm index="cp"><samp>hgh_sht</samp></indexterm><indexterm index="cp"><samp>hgh_byt</samp></indexterm><indexterm index="cp"><samp>flt_sht</samp></indexterm><indexterm index="cp"><samp>flt_byt</samp></indexterm><indexterm index="cp"><samp>nxt_lsr</samp></indexterm><indexterm index="cp"><code>NC_DOUBLE</code></indexterm><indexterm index="cp"><code>NC_FLOAT</code></indexterm><indexterm index="cp"><code>NC_INT</code></indexterm><indexterm index="cp"><code>NC_SHORT</code></indexterm><indexterm index="cp"><code>NC_CHAR</code></indexterm><indexterm index="cp"><code>NC_BYTE</code></indexterm></para>
        <table>
          <tableitem>
            <tableterm><dfn>Pack Floating Precisions to <code>NC_SHORT</code> [<emph>default</emph>]</dfn></tableterm>
            <item>
              <para>Definition: Pack floating precision types to <code>NC_SHORT</code>&linebreak; Map: Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>] to <code>NC_SHORT</code>&linebreak; Types copied instead of packed: [<code>NC_INT</code>,<code>NC_SHORT</code>,<code>NC_CHAR</code>,<code>NC_BYTE</code>]&linebreak; <var>pck_map</var> key values: <samp>flt_sht</samp>, <samp>pck_map_flt_sht</samp>&linebreak;</para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><dfn>Pack Floating Precisions to <code>NC_BYTE</code></dfn></tableterm>
            <item>
              <para>Definition: Pack floating precision types to <code>NC_BYTE</code>&linebreak; Map: Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>] to <code>NC_BYTE</code>&linebreak; Types copied instead of packed: [<code>NC_INT</code>,<code>NC_SHORT</code>,<code>NC_CHAR</code>,<code>NC_BYTE</code>]&linebreak; <var>pck_map</var> key values: <samp>flt_byt</samp>, <samp>pck_map_flt_byt</samp>&linebreak;</para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><dfn>Pack Higher Precisions to <code>NC_SHORT</code></dfn></tableterm>
            <item>
              <para>Definition: Pack higher precision types to <code>NC_SHORT</code>&linebreak; Map: Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>,<code>NC_INT</code>] to <code>NC_SHORT</code>&linebreak; Types copied instead of packed: [<code>NC_SHORT</code>,<code>NC_CHAR</code>,<code>NC_BYTE</code>]&linebreak; <var>pck_map</var> key values: <samp>hgh_sht</samp>, <samp>pck_map_hgh_sht</samp>&linebreak;</para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><dfn>Pack Higher Precisions to <code>NC_BYTE</code></dfn></tableterm>
            <item>
              <para>Definition: Pack higher precision types to <code>NC_BYTE</code>&linebreak; Map: Pack [<code>NC_DOUBLE</code>,<code>NC_FLOAT</code>,<code>NC_INT</code>,<code>NC_SHORT</code>] to <code>NC_BYTE</code>&linebreak; Types copied instead of packed: [<code>NC_CHAR</code>,<code>NC_BYTE</code>]&linebreak; <var>pck_map</var> key values: <samp>hgh_byt</samp>, <samp>pck_map_hgh_byt</samp>&linebreak;</para>
            </item>
          </tableitem>
          <tableitem>
            <tableterm><dfn>Pack to Next Lesser Precision</dfn></tableterm>
            <item>
              <para>Definition: Pack each type to type of next lesser size&linebreak; Map: Pack <code>NC_DOUBLE</code> to <code>NC_INT</code>. Pack [<code>NC_FLOAT</code>,<code>NC_INT</code>] to <code>NC_SHORT</code>. Pack <code>NC_SHORT</code> to <code>NC_BYTE</code>.&linebreak; Types copied instead of packed: [<code>NC_CHAR</code>,<code>NC_BYTE</code>]&linebreak; <var>pck_map</var> key values: <samp>nxt_lsr</samp>, <samp>pck_map_nxt_lsr</samp>&linebreak;</para>
            </item>
          </tableitem>
        </table>
        <para role="continues">The default <samp>all_new</samp> packing policy with the default <samp>flt_sht</samp> packing map reduces the typical <code>NC_FLOAT</code>-dominated file size by about 50%.<!-- /@w --> <samp>flt_byt</samp> packing reduces an <code>NC_DOUBLE</code>-dominated file by about 87%.<!-- /@w --></para>
        <para><indexterm index="cp"><var>_FillValue</var></indexterm><indexterm index="cp"><code>_FillValue</code></indexterm><indexterm index="cp"><code>NUL</code></indexterm>The netCDF packing algorithm (see <xref><xrefnodename>Methods and functions</xrefnodename></xref>) is lossy&mdash;once packed, the exact original data cannot be recovered without a full backup. Hence users should be aware of some packing caveats: First, the interaction of packing and data equal to the <var>_FillValue</var> is complex. Test the <code>_FillValue</code> behavior by performing a pack/unpack cycle to ensure data that are missing <emph>stay</emph> missing and data that are not misssing do not join the Air National Guard and go missing. This may lead you to elect a new <var>_FillValue</var>. Second, <code>ncpdq</code> actually allows packing into <code>NC_CHAR</code> (with, e.g., <samp>flt_chr</samp>). However, the intrinsic conversion of <code>signed char</code> to higher precision types is tricky for values equal to zero, i.e., for <code>NUL</code>. Hence packing to <code>NC_CHAR</code> is not documented or advertised. Pack into <code>NC_BYTE</code> (with, e.g., <samp>flt_byt</samp>) instead.</para>
      </unnumberedsubsec>

      <unnumberedsubsec>
        <title>Dimension Permutation</title>
        <para><command>ncpdq</command> re-shapes variables in <var>input-file</var> by re-ordering and/or reversing dimensions specified in the dimension list. The dimension list is a whitespace-free, comma separated list of dimension names, optionally prefixed by negative signs, that follows the <samp>-a</samp> (or long options <samp>--arrange</samp>, <samp>--permute</samp>, <samp>--re-order</samp>, or <samp>--rdr</samp>) switch. To re-order variables by a subset of their dimensions, specify these dimensions in a comma-separated list following <samp>-a</samp>, e.g., <samp>-a lon,lat</samp>. To reverse a dimension, prefix its name with a negative sign in the dimension list, e.g., <samp>-a -lat</samp>. Re-ordering and reversal may be performed simultaneously, e.g., <samp>-a lon,-lat,time,-lev</samp>.</para>
        <para><indexterm index="cp">record dimension</indexterm>Users may specify any permutation of dimensions, including permutations which change the record dimension identity. The record dimension is re-ordered like any other dimension. <indexterm index="cp">concatenation</indexterm><indexterm index="cp">record dimension</indexterm>This unique <command>ncpdq</command> capability makes it possible to concatenate files along any dimension. See <xref><xrefnodename>Concatenation</xrefnodename></xref> for a detailed example. <indexterm index="cp">record variable</indexterm>The record dimension is always the most slowly varying dimension in a record variable (see <xref><xrefnodename>C and Fortran Index Conventions</xrefnodename></xref>). The specified re-ordering fails if it requires creating more than one record dimension amongst all the output variables <footnote><para>This limitation, imposed by the netCDF storage layer, may be relaxed in the future with netCDF4.</para></footnote>.</para>
        <para>Two special cases of dimension re-ordering and reversal deserve special mention. First, it may be desirable to completely reverse the storage order of a variable. To do this, include all the variable's dimensions in the dimension re-order list in their original order, and prefix each dimension name with the negative sign. <indexterm index="cp">transpose</indexterm>Second, it may useful to transpose a variable's storage order, e.g., from C<!-- /@w --> to Fortran data storage order (see <xref><xrefnodename>C and Fortran Index Conventions</xrefnodename></xref>). To do this, include all the variable's dimensions in the dimension re-order list in reversed order. Explicit examples of these two techniques appear below.</para>
<!-- fxm: discuss netCDF-imposed constraints here -->
        <para role="continues">EXAMPLES</para>
        <para>Pack and unpack all variables in file <file>in.nc</file> and store the results in <file>out.nc</file>:</para>
        <example xml:space="preserve">ncpdq in.nc out.nc # Same as ncpack in.nc out.nc
ncpdq -P all_new -M flt_sht in.nc out.nc # Defaults
ncpdq -P all_xst in.nc out.nc
ncpdq -P upk in.nc out.nc # Same as ncunpack in.nc out.nc
ncpdq -U in.nc out.nc # Same as ncunpack in.nc out.nc</example>
        <para>The first two commands pack any unpacked variable in the input file. They also unpack and then re-pack every packed variable. The third command only packs unpacked variables in the input file. If a variable is already packed, the third command copies it unchanged to the output file. The fourth and fifth commands unpack any packed variables. If a variable is not packed, the third command copies it unchanged.</para>
        <para>The previous examples all utilized the default packing map. Suppose you wish to archive all data that are currently unpacked into a form which only preserves 256 distinct values. Then you could specify the packing map <var>pck_map</var> as <samp>hgh_byt</samp> and the packing policy <var>pck_plc</var> as <samp>all_xst</samp>:</para>
        <example xml:space="preserve">ncpdq -P all_xst -M hgh_byt in.nc out.nc</example>
        <para><indexterm index="cp">appending variables</indexterm><indexterm index="cp"><samp>-A</samp></indexterm><indexterm index="cp"><samp>-v</samp></indexterm>Many different packing maps may be used to construct a given file by performing the packing on subsets of variables (e.g., with <samp>-v</samp>) and using the append feature with <samp>-A</samp> (see <xref><xrefnodename>Appending Variables</xrefnodename></xref>).</para>
        <para>Re-order file <file>in.nc</file> so that the dimension <code>lon</code> always precedes the dimension <code>lat</code> and store the results in <file>out.nc</file>:</para>
        <example xml:space="preserve">ncpdq -a lon,lat in.nc out.nc
ncpdq -v three_dmn_var -a lon,lat in.nc out.nc</example>
        <para>The first command re-orders every variable in the input file. The second command extracts and re-orders only the variable <code>three_dmn_var</code>.</para>
        <para><indexterm index="cp">reverse dimensions</indexterm>Suppose the dimension <code>lat</code> represents latitude and monotonically increases increases from south to north. Reversing the <code>lat</code> dimension means re-ordering the data so that latitude values decrease monotonically from north to south. Accomplish this with</para>
        <example xml:space="preserve">% ncpdq -a -lat in.nc out.nc
% ncks -C -v lat in.nc
lat[0]=-90
lat[1]=90
% ncks -C -v lat out.nc
lat[0]=90
lat[1]=-90</example>
        <para>This operation reversed the latitude dimension of all variables. Whitespace immediately preceding the negative sign that specifies dimension reversal may be dangerous. <indexterm index="cp">long options</indexterm><indexterm index="cp">quotes</indexterm>Quotes and long options can help protect negative signs that should indicate dimension reversal from being interpreted by the shell as dashes that indicate new command line switches.</para>
        <example xml:space="preserve">ncpdq -a -lat in.nc out.nc # Dangerous? Whitespace before "-lat"
ncpdq -a '-lat' in.nc out.nc # OK. Quotes protect "-" in "-lat"
ncpdq -a lon,-lat in.nc out.nc # OK. No whitespace before "-"
ncpdq --rdr=-lat in.nc out.nc # Preferred. Uses "=" not whitespace</example>
        <para><indexterm index="cp">reverse dimensions</indexterm>To create the mathematical transpose of a variable, place all its dimensions in the dimension re-order list in reversed order. This example creates the transpose of <code>three_dmn_var</code>:</para>
        <example xml:space="preserve">% ncpdq -a lon,lev,lat -v three_dmn_var in.nc out.nc
% ncks -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1
lat[0]=-90 lev[0]=100 lon[2]=180 three_dmn_var[2]=2
...
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23
% ncks -C -v three_dmn_var out.nc
lon[0]=0 lev[0]=100 lat[0]=-90 three_dmn_var[0]=0
lon[0]=0 lev[0]=100 lat[1]=90 three_dmn_var[1]=12
lon[0]=0 lev[1]=500 lat[0]=-90 three_dmn_var[2]=4
...
lon[3]=270 lev[1]=500 lat[1]=90 three_dmn_var[21]=19
lon[3]=270 lev[2]=1000 lat[0]=-90 three_dmn_var[22]=11
lon[3]=270 lev[2]=1000 lat[1]=90 three_dmn_var[23]=23</example>
        <para><indexterm index="cp">reverse data</indexterm>To completely reverse the storage order of a variable, include all its dimensions in the re-order list, each prefixed by a negative sign. This example reverses the storage order of <code>three_dmn_var</code>:</para>
        <example xml:space="preserve">% ncpdq -a -lat,-lev,-lon -v three_dmn_var in.nc out.nc
% ncks -C -v three_dmn_var in.nc
lat[0]=-90 lev[0]=100 lon[0]=0 three_dmn_var[0]=0
lat[0]=-90 lev[0]=100 lon[1]=90 three_dmn_var[1]=1
lat[0]=-90 lev[0]=100 lon[2]=180 three_dmn_var[2]=2
...
lat[1]=90 lev[2]=1000 lon[1]=90 three_dmn_var[21]=21
lat[1]=90 lev[2]=1000 lon[2]=180 three_dmn_var[22]=22
lat[1]=90 lev[2]=1000 lon[3]=270 three_dmn_var[23]=23
% ncks -C -v three_dmn_var out.nc
lat[0]=90 lev[0]=1000 lon[0]=270 three_dmn_var[0]=23
lat[0]=90 lev[0]=1000 lon[1]=180 three_dmn_var[1]=22
lat[0]=90 lev[0]=1000 lon[2]=90 three_dmn_var[2]=21
...
lat[1]=-90 lev[2]=100 lon[1]=180 three_dmn_var[21]=2
lat[1]=-90 lev[2]=100 lon[2]=90 three_dmn_var[22]=1
lat[1]=-90 lev[2]=100 lon[3]=0 three_dmn_var[23]=0</example>
        <para>Creating a record dimension named, e.g., <code>time</code>, in a file which has no existing record dimension is simple with <command>ncecat</command>:</para>
        <example xml:space="preserve">ncecat -O -u time in.nc out.nc # Create degenerate record dimension named "time"</example>
        <para><indexterm index="cp">record dimension</indexterm>Now consider a file with all dimensions, including <code>time</code>, fixed (non-record). Suppose the user wishes to convert <code>time</code> from a fixed dimension to a record dimension. This may be useful, for example, when the user wishes to append additional time slices to the data. As of <acronym><acronymword>NCO</acronymword></acronym> version 4.0.1 (April, 2010) the preferred method for doing this is with <command>ncks</command>:</para>
        <example xml:space="preserve">ncks -O --mk_rec_dmn time in.nc out.nc # Change "time" to record dimension</example>
        <para>Prior to 4.0.1, the procedure to change an existing fixed dimension into a record dimension required three separate commands, <command>ncecat</command> followed by <command>ncpdq</command>, and then <command>ncwa</command>. It is still instructive to present the original procedure, as it shows how multiple operators can achieve the same ends by different means: <indexterm index="cp">degenerate dimension</indexterm></para>
        <example xml:space="preserve">ncecat -O in.nc out.nc # Add degenerate record dimension named "record"
ncpdq -O -a time,record out.nc out.nc # Switch "record" and "time"
ncwa -O -a record out.nc out.nc # Remove (degenerate) "record"</example>
        <para role="continues">The first step creates a degenerate (size equals one) record dimension named (by default) <code>record</code>. The second step swaps the ordering of the dimensions named <code>time</code> and <code>record</code>. Since <code>time</code> now occupies the position of the first (least rapidly varying) dimension, it becomes the record dimension. The dimension named <code>record</code> is no longer a record dimension. The third step averages over this degenerate <code>record</code> dimension. Averaging over a degenerate dimension does not alter the data. The ordering of other dimensions in the file (<code>lat</code>, <code>lon</code>, etc.) is immaterial to this procedure. See <xref><xrefnodename>ncecat netCDF Ensemble Concatenator</xrefnodename></xref> and <xref><xrefnodename>ncks netCDF Kitchen Sink</xrefnodename></xref> for other methods of changing variable dimensionality, including the record dimension.</para>
      </unnumberedsubsec>
    </section>
  </node>
  <node>
    <nodename>ncra netCDF Record Averager</nodename>
    <nodenext>ncrcat netCDF Record Concatenator</nodenext>
    <nodeprev>ncpdq netCDF Permute Dimensions Quickly</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncra</command> netCDF Record Averager</title>
      <para><indexterm index="cp">averaging data</indexterm><indexterm index="cp">record average</indexterm><indexterm index="cp">record dimension</indexterm><indexterm index="cp">running average</indexterm><indexterm index="cp">ncra</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncra [-3] [-4] [-6] [-A] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-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>]
[-n <var>loop</var>] [-O] [-o <var>output-file</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>input-files</var>] [<var>output-file</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncra</command> averages record variables across an arbitrary number of <var>input-files</var>. <indexterm index="cp">degenerate dimension</indexterm><indexterm index="cp">record dimension</indexterm>The record dimension is, by default, retained as a degenerate (size 1)<!-- /@w --> dimension in the output variables. See <xref><xrefnodename>Averaging vs. Concatenating</xrefnodename></xref>, for a description of the distinctions between the various averagers and concatenators. <indexterm index="cp">multi-file operators</indexterm><indexterm index="cp">standard input</indexterm><indexterm index="cp"><code>stdin</code></indexterm>As a multi-file operator, <command>ncra</command> will read the list of <var>input-files</var> from <code>stdin</code> if they are not specified as positional arguments on the command line (see <xref><xrefnodename>Large Numbers of Files</xrefnodename></xref>).</para>
      <para>Input files may vary in size, but each must have a record dimension. The record coordinate, if any, should be monotonic (or else non-fatal warnings may be generated). <indexterm index="cp">hyperslab</indexterm>Hyperslabs of the record dimension which include more than one file work correctly. <indexterm index="cp">stride</indexterm><command>ncra</command> supports the <var>stride</var> argument to the <samp>-d</samp> hyperslab option (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>) for the record dimension only, <var>stride</var> is not supported for non-record dimensions.</para>
      <para><command>ncra</command> weights each record (e.g., time slice) in the <var>input-files</var> equally. <command>ncra</command> does not attempt to see if, say, the <code>time</code> coordinate is irregularly spaced and thus would require a weighted average in order to be a true time average. <indexterm index="cp">operation types</indexterm><command>ncra</command> <emph>always averages</emph> coordinate variables regardless of the arithmetic operation type performed on the non-coordinate variables. (see <xref><xrefnodename>Operation Types</xrefnodename></xref>).</para>
      <para role="continues">EXAMPLES</para>
      <para>Average files <file>85.nc</file>, <file>86.nc</file>, &dots; <file>89.nc</file><!-- /@w --> along the record dimension, and store the results in <file>8589.nc</file>: <indexterm index="cp">globbing</indexterm><indexterm index="cp"><code>NINTAP</code></indexterm><indexterm index="cp">Processor</indexterm><indexterm index="cp"><acronym><acronymword>CCM</acronymword></acronym> Processor</indexterm></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 -n 5,2,1 85.nc 8589.nc</example>
      <para>These three methods produce identical answers. See <xref><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions between these methods.</para>
      <para><indexterm index="cp">Fortran</indexterm>Assume the files <file>85.nc</file>, <file>86.nc</file>, &dots; <file>89.nc</file><!-- /@w --> each contain a record coordinate <var>time</var> of length 12 defined such that the third record in <file>86.nc</file> contains data from March 1986, etc. <acronym><acronymword>NCO</acronymword></acronym> knows how to hyperslab the record dimension across files. Thus, to average data from December, 1985 through February, 1986:</para>
      <example xml:space="preserve">ncra -d time,11,13 85.nc 86.nc 87.nc 8512_8602.nc
ncra -F -d time,12,14 85.nc 86.nc 87.nc 8512_8602.nc</example>
      <para role="continues">The file <file>87.nc</file> is superfluous, but does not cause an error. The <samp>-F</samp> turns on the Fortran (1-based) indexing convention. <indexterm index="cp">stride</indexterm>The following uses the <var>stride</var> option to average all the March temperature data from multiple input files into a single output file</para>
      <example xml:space="preserve">ncra -F -d time,3,,12 -v temperature 85.nc 86.nc 87.nc 858687_03.nc</example>
      <para>See <xref><xrefnodename>Stride</xrefnodename></xref>, for a description of the <var>stride</var> argument.</para>
      <para>Assume the <var>time</var> coordinate is incrementally numbered such that January, <math>1985 = 1</math><!-- /@w --> and December, <math>1989 = 60</math><!-- /@w -->. Assuming <samp>??</samp> only expands to the five desired files, the following averages June, 1985&ndash;June, 1989:</para>
      <example xml:space="preserve">ncra -d time,6.,54. ??.nc 8506_8906.nc</example>
    </section>
  </node>
  <node>
    <nodename>ncrcat netCDF Record Concatenator</nodename>
    <nodenext>ncrename netCDF Renamer</nodenext>
    <nodeprev>ncra netCDF Record Averager</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncrcat</command> netCDF Record Concatenator</title>
      <para><indexterm index="cp">concatenation</indexterm><indexterm index="cp">record concatenation</indexterm><indexterm index="cp">ncrcat</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncrcat [-3] [-4] [-6] [-A] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-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>]
[--md5_digest] [-n <var>loop</var>] [-O] [-o <var>output-file</var>] [-p <var>path</var>] [-R] [-r]
[-t <var>thr_nbr</var>] [-v <var>var</var>[,&dots;]] [-X ...] [-x]
[<var>input-files</var>] [<var>output-file</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncrcat</command> concatenates record variables across an arbitrary number of <var>input-files</var>. <indexterm index="cp">record dimension</indexterm>The final record dimension is by default the sum of the lengths of the record dimensions in the input files. See <xref><xrefnodename>Averaging vs. Concatenating</xrefnodename></xref>, for a description of the distinctions between the various averagers and concatenators. <indexterm index="cp">multi-file operators</indexterm><indexterm index="cp">standard input</indexterm><indexterm index="cp"><code>stdin</code></indexterm>As a multi-file operator, <command>ncrcat</command> will read the list of <var>input-files</var> from <code>stdin</code> if they are not specified as positional arguments on the command line (see <xref><xrefnodename>Large Numbers of Files</xrefnodename></xref>).</para>
      <para>Input files may vary in size, but each must have a record dimension. The record coordinate, if any, should be monotonic (or else non-fatal warnings may be generated). <indexterm index="cp">hyperslab</indexterm>Hyperslabs along the record dimension that span more than one file are handled correctly. <indexterm index="cp">stride</indexterm><command>ncra</command> supports the <var>stride</var> argument to the <samp>-d</samp> hyperslab option for the record dimension only, <var>stride</var> is not supported for non-record dimensions.</para>
      <para><indexterm index="cp">ncpdq</indexterm><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>Concatenating a variable packed with different scales multiple datasets is beyond the capabilities of <command>ncrcat</command> (and <command>ncecat</command>, the other concatenator (<xref><xrefnodename>Concatenation</xrefnodename></xref>). <command>ncrcat</command> does not unpack data, it simply <emph>copies</emph> the data from the <var>input-files</var>, and the metadata from the <emph>first</emph> <var>input-file</var>, to the <var>output-file</var>. This means that data compressed with a packing convention must use the identical packing parameters (e.g., <code>scale_factor</code> and <code>add_offset</code>) for a given variable across <emph>all</emph> input files. Otherwise the concatenated dataset will not unpack correctly. The workaround for cases where the packing parameters differ across <var>input-files</var> requires three steps: First, unpack the data using <command>ncpdq</command>. Second, concatenate the unpacked data using <command>ncrcat</command>, Third, re-pack the result with <command>ncpdq</command>.</para>
      <para><indexterm index="cp">ARM conventions</indexterm><command>ncrcat</command> applies special rules to <acronym><acronymword>ARM</acronymword></acronym> convention time fields (e.g., <code>time_offset</code>). See <xref><xrefnodename>ARM Conventions</xrefnodename></xref> for a complete description.</para>
      <para role="continues">EXAMPLES</para>
      <para>Concatenate files <file>85.nc</file>, <file>86.nc</file>, &dots; <file>89.nc</file><!-- /@w --> along the record dimension, and store the results in <file>8589.nc</file>: <indexterm index="cp">globbing</indexterm><indexterm index="cp"><code>NINTAP</code></indexterm><indexterm index="cp">Processor</indexterm><indexterm index="cp"><acronym><acronymword>CCM</acronymword></acronym> Processor</indexterm></para>
      <example xml:space="preserve">ncrcat 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
ncrcat 8[56789].nc 8589.nc
ncrcat -n 5,2,1 85.nc 8589.nc</example>
      <para role="continues">These three methods produce identical answers. See <xref><xrefnodename>Specifying Input Files</xrefnodename></xref>, for an explanation of the distinctions between these methods.</para>
      <para><indexterm index="cp">Fortran</indexterm>Assume the files <file>85.nc</file>, <file>86.nc</file>, &dots; <file>89.nc</file><!-- /@w --> each contain a record coordinate <var>time</var> of length 12<!-- /@w --> defined such that the third record in <file>86.nc</file> contains data from March 1986, etc. <acronym><acronymword>NCO</acronymword></acronym> knows how to hyperslab the record dimension across files. Thus, to concatenate data from December, 1985&ndash;February, 1986:</para>
      <example xml:space="preserve">ncrcat -d time,11,13 85.nc 86.nc 87.nc 8512_8602.nc
ncrcat -F -d time,12,14 85.nc 86.nc 87.nc 8512_8602.nc</example>
      <para role="continues">The file <file>87.nc</file> is superfluous, but does not cause an error. When <command>ncra</command> and <command>ncrcat</command> encounter a file which does contain any records that meet the specified hyperslab criteria, they disregard the file and proceed to the next file without failing. The <samp>-F</samp> turns on the Fortran (1-based) indexing convention. <indexterm index="cp">stride</indexterm> The following uses the <var>stride</var> option to concatenate all the March temperature data from multiple input files into a single output file</para>
      <example xml:space="preserve">ncrcat -F -d time,3,,12 -v temperature 85.nc 86.nc 87.nc 858687_03.nc</example>
      <para>See <xref><xrefnodename>Stride</xrefnodename></xref>, for a description of the <var>stride</var> argument.</para>
      <para>Assume the <var>time</var> coordinate is incrementally numbered such that January, 1985 = 1<!-- /@w --> and December, 1989 = 60.<!-- /@w --> Assuming <code>??</code> only expands to the five desired files, the following concatenates June, 1985&ndash;June, 1989:</para>
      <example xml:space="preserve">ncrcat -d time,6.,54. ??.nc 8506_8906.nc</example>
    </section>
  </node>
  <node>
    <nodename>ncrename netCDF Renamer</nodename>
    <nodenext>ncwa netCDF Weighted Averager</nodenext>
    <nodeprev>ncrcat netCDF Record Concatenator</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncrename</command> netCDF Renamer</title>
      <para><indexterm index="cp">renaming variables</indexterm><indexterm index="cp">renaming dimensions</indexterm><indexterm index="cp">renaming attributes</indexterm><indexterm index="cp">variable names</indexterm><indexterm index="cp">dimension names</indexterm><indexterm index="cp">attribute names</indexterm><indexterm index="cp">ncrename</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncrename [-a <var>old_name</var>,<var>new_name</var>] [-a &dots;] [-D <var>dbg</var>]
[-d <var>old_name</var>,<var>new_name</var>] [-d &dots;] [-h] [--hdr_pad <var>nbr</var>] [-l <var>path</var>]
[-O] [-o <var>output-file</var>] [-p <var>path</var>] [-R] [-r]
[-v <var>old_name</var>,<var>new_name</var>] [-v &dots;]
<var>input-file</var> [[<var>output-file</var>]]</example>
      <para role="continues">DESCRIPTION</para>
      <para><indexterm index="cp"><kbd>.</kbd></indexterm><command>ncrename</command> renames dimensions, variables, and attributes in a netCDF file. Each object that has a name in the list of old names is renamed using the corresponding name in the list of new names. All the new names must be unique. Every old name must exist in the input file, unless the old name is preceded by the period (or &ldquo;dot&rdquo;) character <samp>.</samp>. The validity of <var>old_name</var> is not checked prior to the renaming. Thus, if <var>old_name</var> is specified without the the <samp>.</samp> prefix and is not present in <var>input-file</var>, <command>ncrename</command> will abort. The <var>new_name</var> should never be prefixed by a <samp>.</samp> (or else the period will be included as part of the new name). The OPTIONS and EXAMPLES show how to select specific variables whose attributes are to be renamed.</para>
      <para><indexterm index="cp">data safety</indexterm><indexterm index="cp">safeguards</indexterm><indexterm index="cp">temporary output files</indexterm><command>ncrename</command> is the exception to the normal rules that the user will be interactively prompted before an existing file is changed, and that a temporary copy of an output file is constructed during the operation. If only <var>input-file</var> is specified, then <command>ncrename</command> will change the names of the <var>input-file</var> in place without prompting and without creating a temporary copy of <code>input-file</code>. This is because the renaming operation is considered reversible if the user makes a mistake. The <var>new_name</var> can easily be changed back to <var>old_name</var> by using <command>ncrename</command> one more time.</para>
      <para>Note that renaming a dimension to the name of a dependent variable can be used to invert the relationship between an independent coordinate variable and a dependent variable. In this case, the named dependent variable must be one-dimensional and should have no missing values. Such a variable will become a coordinate variable.</para>
      <para><indexterm index="cp">performance</indexterm><indexterm index="cp">operator speed</indexterm><indexterm index="cp">speed</indexterm><indexterm index="cp">execution time</indexterm>According to the <cite>netCDF User's Guide</cite>, renaming properties in netCDF files does not incur the penalty of recopying the entire file when the <var>new_name</var> is shorter than the <var>old_name</var>.</para>
      <para role="continues">OPTIONS</para>
      <table>
        <tableitem>
          <tableterm><samp>-a <var>old_name</var>,<var>new_name</var></samp></tableterm>
          <item>
            <para>Attribute renaming. The old and new names of the attribute are specified with <samp>-a</samp> (or <samp>--attribute</samp>) by the associated <var>old_name</var> and <var>new_name</var> values. <indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm>Global attributes are treated no differently than variable attributes. This option may be specified more than once. As mentioned above, all occurrences of the attribute of a given name will be renamed unless the <samp>.</samp> form is used, with one exception. To change the attribute name for a particular variable, specify the <var>old_name</var> in the format <var>old_var_name@old_att_name</var>. The <samp>@</samp> symbol delimits the variable and attribute names. If the attribute is uniquely named (no other variables contain the attribute) then the <var>old_var_name@old_att_name</var> syntax is redundant. The <var>var_name@att_name</var> syntax is accepted, but not required, for the <var>new_name</var>.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><samp>-d <var>old_name</var>,<var>new_name</var></samp></tableterm>
          <item>
            <para>Dimension renaming. The old and new names of the dimension are specified with <samp>-d</samp> (or <samp>--dmn</samp>, <samp>--dimension</samp>) by the associated <var>old_name</var> and <var>new_name</var> values. This option may be specified more than once.</para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm><samp>-v <var>old_name</var>,<var>new_name</var></samp></tableterm>
          <item>
            <para>Variable renaming. The old and new names of the variable are specified with <samp>-v</samp> (or <samp>--variable</samp>) by the associated <var>old_name</var> and <var>new_name</var> values. This option may be specified more than once.</para>
          </item>
        </tableitem>
      </table>
      <para role="continues">EXAMPLES</para>
      <para>Rename the variable <code>p</code> to <code>pressure</code> and <code>t</code> to <code>temperature</code> in netCDF <file>in.nc</file>. In this case <code>p</code> must exist in the input file (or <command>ncrename</command> will abort), but the presence of <code>t</code> is optional:</para>
      <example xml:space="preserve">ncrename -v p,pressure -v .t,temperature in.nc</example>
      <para>Rename the attribute <code>long_name</code> to <code>largo_nombre</code> in the variable <code>u</code>, and no other variables in netCDF <file>in.nc</file>.</para>
      <example xml:space="preserve">ncrename -a u:long_name,largo_nombre in.nc</example>
      <para><indexterm index="cp">coordinate variables</indexterm><command>ncrename</command> does not automatically attach dimensions to variables of the same name. If you want to rename a coordinate variable so that it remains a coordinate variable, you must separately rename both the dimension and the variable:</para>
      <example xml:space="preserve">ncrename -d lon,longitude -v lon,longitude in.nc</example>
      <para><indexterm index="cp">global attributes</indexterm><indexterm index="cp">attributes, global</indexterm><indexterm index="cp"><code>_FillValue</code></indexterm><indexterm index="cp"><code>missing_value</code></indexterm>Create netCDF <file>out.nc</file> identical to <file>in.nc</file> except the attribute <code>_FillValue</code> is changed to <code>missing_value</code>, the attribute <code>units</code> is changed to <code>CGS_units</code> (but only in those variables which possess it), the attribute <code>hieght</code> is changed to <code>height</code> in the variable <code>tpt</code>, and in the variable <code>prs_sfc</code>, if it exists.</para>
      <example xml:space="preserve">ncrename -a _FillValue,missing_value -a .units,CGS_units \
  -a tpt@hieght,height -a prs_sfc@.hieght,height in.nc out.nc</example>
      <para>The presence and absence of the <samp>.</samp> and <samp>@</samp> features cause this command to execute successfully only if a number of conditions are met. All variables <emph>must</emph> have a <code>_FillValue</code> attribute <emph>and</emph> <code>_FillValue</code> must also be a global attribute. The <code>units</code> attribute, on the other hand, will be renamed to <code>CGS_units</code> wherever it is found but need not be present in the file at all (either as a global or a variable attribute). The variable <code>tpt</code> must contain the <code>hieght</code> attribute. The variable <code>prs_sfc</code> need not exist, and need not contain the <code>hieght</code> attribute.</para>
    </section>
  </node>
  <node>
    <nodename>ncwa netCDF Weighted Averager</nodename>
    <nodeprev>ncrename netCDF Renamer</nodeprev>
    <nodeup>Operator Reference Manual</nodeup>
    <section>
      <title><command>ncwa</command> netCDF Weighted Averager</title>
      <para><indexterm index="cp">averaging data</indexterm><indexterm index="cp">weighted average</indexterm><indexterm index="cp">masked average</indexterm><indexterm index="cp">broadcasting variables</indexterm><indexterm index="cp">ncwa</indexterm> SYNTAX</para>
      <example xml:space="preserve">ncwa [-3] [-4] [-6] [-A] [-a <var>dim</var>[,&dots;]] [-B <var>mask_cond</var>] [-b] [-C] [-c]
[--cnk_dmn nm,sz] [--cnk_map map] [--cnk_plc plc] [--cnk_scl sz]
[-D <var>dbg</var>] [-d <var>dim</var>,[<var>min</var>][,[<var>max</var>][,[<var>stride</var>]]] [-F] [-h] [-I] [-L <var>dfl_lvl</var>] [-l <var>path</var>]
[-M <var>mask_val</var>] [-m <var>mask_var</var>] [-N] [-O]
[-o <var>output-file</var>] [-p <var>path</var>] [-R] [-r] [-T <var>mask_comp</var>]
[-t <var>thr_nbr</var>] [-v <var>var</var>[,&dots;]] [-w <var>weight</var>] [-X ...] [-x] [-y <var>op_typ</var>]
<var>input-file</var> [<var>output-file</var>]</example>
      <para role="continues">DESCRIPTION</para>
      <para><command>ncwa</command> averages variables in a single file over arbitrary dimensions, with options to specify weights, masks, and normalization. See <xref><xrefnodename>Averaging vs. Concatenating</xrefnodename></xref>, for a description of the distinctions between the various averagers and concatenators. The default behavior of <command>ncwa</command> is to arithmetically average every numerical variable over all dimensions and to produce a scalar result for each.</para>
      <para><indexterm index="cp">degenerate dimension</indexterm>Averaged dimensions are, by default, eliminated as dimensions. Their corresponding coordinates, if any, are output as scalars. The <samp>-b</samp> switch (and its long option equivalents <samp>--rdd</samp> and <samp>--retain-degenerate-dimensions</samp>) causes <command>ncwa</command> to retain averaged dimensions as degenerate (size 1<!-- /@w -->) dimensions. This maintains the association between a dimension (or coordinate) and variables after averaging and simplifies, for instance, later concatenation along the degenerate dimension.</para>
      <para>To average variables over only a subset of their dimensions, specify these dimensions in a comma-separated list following <samp>-a</samp>, e.g., <samp>-a time,lat,lon</samp>. <indexterm index="cp">arithmetic operators</indexterm><indexterm index="cp">hyperslab</indexterm><indexterm index="cp"><code>-d <var>dim</var>,[<var>min</var>][,[<var>max</var>]]</code></indexterm>As with all arithmetic operators, the operation may be restricted to an arbitrary hypserslab by employing the <samp>-d</samp> option (see <xref><xrefnodename>Hyperslabs</xrefnodename></xref>). <command>ncwa</command> also handles values matching the variable's <code>_FillValue</code> attribute correctly. Moreover, <command>ncwa</command> understands how to manipulate user-specified weights, masks, and normalization options. With these options, <command>ncwa</command> can compute sophisticated averages (and integrals) from the command line.</para>
      <para><indexterm index="cp"><code>-w <var>weight</var></code></indexterm><indexterm index="cp"><code>--weight <var>weight</var></code></indexterm><indexterm index="cp"><code>--wgt_var <var>weight</var></code></indexterm><indexterm index="cp"><code>-m <var>mask_var</var></code></indexterm><indexterm index="cp"><code>--mask-variable <var>mask_var</var></code></indexterm><indexterm index="cp"><code>--mask_variable <var>mask_var</var></code></indexterm><indexterm index="cp"><code>--msk_nm <var>mask_var</var></code></indexterm><indexterm index="cp"><code>--msk_var <var>mask_var</var></code></indexterm><indexterm index="cp"><code>-B <var>mask_cond</var></code></indexterm><indexterm index="cp"><code>--msk_cnd <var>mask_cond</var></code></indexterm><indexterm index="cp"><code>--mask_condition <var>mask_cond</var></code></indexterm><var>mask_var</var> and <var>weight</var>, if specified, are broadcast to conform to the variables being averaged. <indexterm index="cp">rank</indexterm>The rank of variables is reduced by the number of dimensions which they are averaged over. Thus arrays which are one dimensional in the <var>input-file</var> and are averaged by <command>ncwa</command> appear in the <var>output-file</var> as scalars. This allows the user to infer which dimensions may have been averaged. Note that that it is impossible for <command>ncwa</command> to make make a <var>weight</var> or <var>mask_var</var> of rank <var>W</var> conform to a <var>var</var> of rank <var>V</var> if <var>W &gt; V</var>. This situation often arises when coordinate variables (which, by definition, are one dimensional) are weighted and averaged. <command>ncwa</command> assumes you know this is impossible and so <command>ncwa</command> does not attempt to broadcast <var>weight</var> or <var>mask_var</var> to conform to <var>var</var> in this case, nor does <command>ncwa</command> print a warning message telling you this, because it is so common. Specifying <var>dbg &gt; 2</var> does cause <command>ncwa</command> to emit warnings in these situations, however.</para>
      <para>Non-coordinate variables are always masked and weighted if specified. Coordinate variables, however, may be treated specially. By default, an averaged coordinate variable, e.g., <code>latitude</code>, appears in <var>output-file</var> averaged the same way as any other variable containing an averaged dimension. In other words, by default <command>ncwa</command> weights and masks coordinate variables like all other variables. This design decision was intended to be helpful but for some applications it may be preferable not to weight or mask coordinate variables just like all other variables. Consider the following arguments to <command>ncwa</command>: <code>-a latitude -w lat_wgt -d latitude,0.,90.</code> where <code>lat_wgt</code> is a weight in the <code>latitude</code> dimension. Since, by default <command>ncwa</command> weights coordinate variables, the value of <code>latitude</code> in the <var>output-file</var> depends on the weights in <var>lat_wgt</var> and is not likely to be 45.0<!-- /@w -->, the midpoint latitude of the hyperslab. <indexterm index="cp">coordinate variable</indexterm><indexterm index="cp"><code>-I</code></indexterm>Option <samp>-I</samp> overrides this default behavior and causes <command>ncwa</command> not to weight or mask coordinate variables <footnote><para>The default behavior of (<samp>-I</samp>) changed on 1998/12/01&mdash;before this date the default was not to weight or mask coordinate variables.</para></footnote>. In the above case, this causes the value of <code>latitude</code> in the <var>output-file</var> to be 45.0<!-- /@w -->, an appealing result. Thus, <samp>-I</samp> specifies simple arithmetic averages for the coordinate variables. In the case of latitude, <samp>-I</samp> specifies that you prefer to archive the arithmetic mean latitude of the averaged hyperslabs rather than the area-weighted mean latitude. <footnote><para>If <code>lat_wgt</code> contains Gaussian weights then the value of <code>latitude</code> in the <var>output-file</var> will be the area-weighted centroid of the hyperslab. For the example given, this is about 30 degrees.<!-- /@w --></para></footnote>.</para>
      <para><indexterm index="cp">average</indexterm><indexterm index="cp">operation types</indexterm>As explained in See <xref><xrefnodename>Operation Types</xrefnodename></xref>, <command>ncwa</command> <emph>always averages</emph> coordinate variables regardless of the arithmetic operation type performed on the non-coordinate variables. This is independent of the setting of the <samp>-I</samp> option. The mathematical definition of operations involving rank reduction is given above (see <xref><xrefnodename>Operation Types</xrefnodename></xref>).</para>
      <menu>
        <menuentry>
          <menunode>Mask condition</menunode>
          <menutitle>Mask condition</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Normalization and Integration</menunode>
          <menutitle>Normalization and Integration</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </section>
  </node>
  <node>
    <nodename>Mask condition</nodename>
    <nodenext>Normalization and Integration</nodenext>
    <nodeprev>ncwa netCDF Weighted Averager</nodeprev>
    <nodeup>ncwa netCDF Weighted Averager</nodeup>
    <subsection>
      <title>Mask condition</title>
      <para><indexterm index="cp">mask condition</indexterm><indexterm index="cp">truth condition</indexterm> <indexterm index="cp"><code>--op_rlt <var>mask_comp</var></code></indexterm><indexterm index="cp"><code>--mask_comparator <var>mask_comp</var></code></indexterm><indexterm index="cp"><code>--msk_cmp_typ <var>mask_comp</var></code></indexterm><indexterm index="cp"><code>--msk_cnd_sng <var>mask_cond</var></code></indexterm><indexterm index="cp"><code>--mask_condition <var>mask_cond</var></code></indexterm><indexterm index="cp"><code>-B <var>mask_cond</var></code></indexterm>The mask condition has the syntax <math><var>mask_var</var></math> <math><var>mask_comp</var></math> <math><var>mask_val</var></math>. The preferred method to specify the mask condition is in one string with the <samp>-B</samp> or <samp>--mask_condition</samp> switches. The older method is to use the three switches <samp>-m</samp>, <samp>-T</samp>, and <samp>-M</samp> to specify the <var>mask_var</var>, <var>mask_comp</var>, and <var>mask_val</var>, respectively. <footnote><para>The three switches <samp>-m</samp>, <samp>-T</samp>, and <samp>-M</samp> are maintained for backward compatibility and may be deprecated in the future. It is safest to write scripts using <samp>--mask_condition</samp>.</para></footnote>. The <var>mask_condition</var> string is automatically parsed into its three constituents <var>mask_var</var>, <var>mask_comp</var>, and <var>mask_val</var>.</para>
      <para><indexterm index="cp">comparator</indexterm>Here <var>mask_var</var> is the name of the masking variable (specified with <samp>-m</samp>, <samp>--mask-variable</samp>, <samp>--mask_variable</samp>, <samp>--msk_nm</samp>, or <samp>--msk_var</samp>). The truth <var>mask_comp</var> argument (specified with <samp>-T</samp>, <samp>--mask_comparator</samp>, <samp>--msk_cmp_typ</samp>, or <samp>--op_rlt</samp> may be any one of the six arithmetic comparators: <kbd>eq</kbd>, <kbd>ne</kbd>, <kbd>gt</kbd>, <kbd>lt</kbd>, <kbd>ge</kbd>, <kbd>le</kbd>.</para>
      <setvalue name="flg"></setvalue>
      <para>These are the Fortran-style character abbreviations for the logical comparisons <math>==</math>, <math>!=</math>, <math>&gt;</math>, <math>&lt;</math>, <math>&gt;=</math>, <math>&lt;=</math>.</para>
      <clearvalue name="flg"></clearvalue>
      <para>The mask comparator defaults to <kbd>eq</kbd> (equality). <indexterm index="cp"><code>--mask-value <var>mask_val</var></code></indexterm><indexterm index="cp"><code>--mask_value <var>mask_val</var></code></indexterm><indexterm index="cp"><code>--msk_val <var>mask_val</var></code></indexterm>The <var>mask_val</var> argument to <samp>-M</samp> (or <samp>--mask-value</samp>, or <samp>--msk_val</samp>) is the right hand side of the <dfn>mask condition</dfn>. Thus for the <var>i</var>'th element of the hyperslab to be averaged, the mask condition is</para>
      <setvalue name="flg"></setvalue>
      <para><math>mask(i)</math> <var>mask_comp</var> <var>mask_val</var>.</para>
      <clearvalue name="flg"></clearvalue>
    </subsection>
  </node>
  <node>
    <nodename>Normalization and Integration</nodename>
    <nodeprev>Mask condition</nodeprev>
    <nodeup>ncwa netCDF Weighted Averager</nodeup>
    <subsection>
      <title>Normalization and Integration</title>
      <para><indexterm index="cp">normalization</indexterm><indexterm index="cp"><code>-N</code></indexterm><indexterm index="cp"><code>numerator</code></indexterm><indexterm index="cp">integration</indexterm><indexterm index="cp">dot product</indexterm><command>ncwa</command> has one switch which controls the normalization of the averages appearing in the <var>output-file</var>. Short option <samp>-N</samp> (or long options <samp>--nmr</samp> or <samp>--numerator</samp>) prevents <command>ncwa</command> from dividing the weighted sum of the variable (the numerator in the averaging expression) by the weighted sum of the weights (the denominator in the averaging expression). Thus <samp>-N</samp> tells <command>ncwa</command> to return just the numerator of the arithmetic expression defining the operation (see <xref><xrefnodename>Operation Types</xrefnodename></xref>).</para>
      <para>With this normalization option, <command>ncwa</command> can integrate variables. Averages are first computed as sums, and then normalized to obtain the average. The original sum (i.e., the numerator of the expression in <xref><xrefnodename>Operation Types</xrefnodename></xref>) is output if default normalization is turned off (with <samp>-N</samp><!-- /@w -->). This sum is the integral (not the average) over the specified (with <samp>-a</samp><!-- /@w -->, or all, if none are specified) dimensions. The weighting variable, if specified (with <samp>-w</samp><!-- /@w -->), plays the role of the differential increment and thus permits more sophisticated integrals (i.e., weighted sums) to be output. For example, consider the variable <code>lev</code> where <math><var>lev</var> = [100,500,1000]</math> weighted by the weight <code>lev_wgt</code> where <math><var>lev_wgt</var> = [10,2,1]</math>. <indexterm index="cp">dot product</indexterm>The vertical integral of <code>lev</code>, weighted by <code>lev_wgt</code>, is the dot product of <var>lev</var> and <var>lev_wgt</var>. That this is is 3000.0<!-- /@w --> can be seen by inspection and verified with the integration command</para>
      <example xml:space="preserve">ncwa -N -a lev -v lev -w lev_wgt in.nc foo.nc;ncks foo.nc</example>
      <para role="continues">EXAMPLES</para>
      <para>Given file <file>85_0112.nc</file>:</para>
      <example xml:space="preserve">netcdf 85_0112 {
dimensions:
        lat = 64 ;
        lev = 18 ;
        lon = 128 ;
        time = UNLIMITED ; // (12 currently)
variables:
        float lat(lat) ;
        float lev(lev) ;
        float lon(lon) ;
        float time(time) ;
        float scalar_var ;
        float three_dmn_var(lat, lev, lon) ;
        float two_dmn_var(lat, lev) ;
        float mask(lat, lon) ;
        float gw(lat) ;
}</example>
      <para>Average all variables in <file>in.nc</file> over all dimensions and store results in <file>out.nc</file>:</para>
      <example xml:space="preserve">ncwa in.nc out.nc</example>
      <para role="continues">All variables in <file>in.nc</file> are reduced to scalars in <file>out.nc</file> since <command>ncwa</command> averages over all dimensions unless otherwise specified (with <samp>-a</samp>).</para>
      <para>Store the zonal (longitudinal) mean of <file>in.nc</file> in <file>out.nc</file>:</para>
      <example xml:space="preserve">ncwa -a lon in.nc out1.nc
ncwa -a lon -b in.nc out2.nc</example>
      <para role="continues"><indexterm index="cp">degenerate dimension</indexterm>The first command turns <code>lon</code> into a scalar and the second retains <code>lon</code> as a degenerate dimension in all variables.</para>
      <example xml:space="preserve">% ncks -C -H -v lon out1.nc
lon = 135
% ncks -C -H -v lon out2.nc
lon[0] = 135</example>
      <para>In either case the tally is simply the size of <code>lon</code>, i.e., 180 for the <file>85_0112.nc</file> file described by the sample header above.</para>
      <para><indexterm index="cp"><code>gw</code></indexterm><indexterm index="cp">Gaussian weights</indexterm><indexterm index="cp">climate model</indexterm>Compute the meridional (latitudinal) mean, with values weighted by the corresponding element of <var>gw</var> <footnote><para><code>gw</code> stands for <dfn>Gaussian weight</dfn> in many climate models.</para></footnote>:</para>
      <example xml:space="preserve">ncwa -w gw -a lat in.nc out.nc</example>
      <para role="continues">Here the tally is simply the size of <code>lat</code>, or 64.<!-- /@w --> The sum of the Gaussian weights is 2.0.<!-- /@w --></para>
      <para>Compute the area mean over the tropical Pacific:</para>
      <example xml:space="preserve">ncwa -w gw -a lat,lon -d lat,-20.,20. -d lon,120.,270. in.nc out.nc</example>
      <para role="continues">Here the tally is</para>
      <setvalue name="flg"></setvalue>
      <para>64 times 128 = 8192.</para>
      <clearvalue name="flg"></clearvalue>
      <para><indexterm index="cp"><code>ORO</code></indexterm><indexterm index="cp">climate model</indexterm>Compute the area-mean over the globe using only points for which</para>
      <setvalue name="flg"></setvalue>
      <para><var>ORO</var> &lt; 0.5</para>
      <clearvalue name="flg"></clearvalue>
      <para><footnote><para><code>ORO</code> stands for <dfn>Orography</dfn> in some climate models and in those models <math><var>ORO</var> &lt; 0.5</math> selects ocean gridpoints.</para></footnote>:</para>
      <example xml:space="preserve">ncwa -B 'ORO &lt; 0.5'      -w gw -a lat,lon in.nc out.nc
ncwa -m ORO -M 0.5 -T lt -w gw -a lat,lon in.nc out.nc</example>
      <para role="continues">It is considerably simpler to specify the complete <var>mask_cond</var> with the single string argument to <samp>-B</samp> than with the three separate switches <samp>-m</samp>, <samp>-T</samp>, and <samp>-M</samp>. If in doubt, enclose the <var>mask_cond</var> within quotes since some of the comparators have special meanings to the shell.</para>
      <para>Assuming 70% of the gridpoints are maritime, then here the tally is</para>
      <setvalue name="flg"></setvalue>
      <para>0.70 times 8192 = 5734.</para>
      <clearvalue name="flg"></clearvalue>
      <para>Compute the global annual mean over the maritime tropical Pacific:</para>
      <example xml:space="preserve">ncwa -B 'ORO &lt; 0.5'      -w gw -a lat,lon,time \
  -d lat,-20.0,20.0 -d lon,120.0,270.0 in.nc out.nc
ncwa -m ORO -M 0.5 -T lt -w gw -a lat,lon,time \
  -d lat,-20.0,20.0 -d lon,120.0,270.0 in.nc out.nc</example>
      <para>Further examples will use the one-switch specification of <var>mask_cond</var>.</para>
      <para>Determine the total area of the maritime tropical Pacific, assuming the variable <var>area</var> contains the area of each gridcell</para>
      <example xml:space="preserve">ncwa -N -v area -B 'ORO &lt; 0.5' -a lat,lon \
  -d lat,-20.0,20.0 -d lon,120.0,270.0 in.nc out.nc</example>
      <para>Weighting <var>area</var> (e.g., by <var>gw</var>) is not appropriate because <var>area</var> is <emph>already</emph> area-weighted by definition. Thus the <samp>-N</samp> switch, or, equivalently, the <samp>-y ttl</samp> switch, correctly integrate the cell areas into a total regional area.</para>
      <para><indexterm index="cp">mask condition</indexterm><indexterm index="cp">truth condition</indexterm>Mask a file to contain <var>_FillValue</var> everywhere except where <math><var>thr_min</var> &lt;= <var>msk_var</var> &lt;= <var>thr_max</var></math>:</para>
      <example xml:space="preserve"># Set masking variable and its scalar thresholds
export msk_var='three_dmn_var_dbl' # Masking variable
export thr_max='20' # Maximum allowed value
export thr_min='10' # Minimum allowed value
ncecat -O in.nc out.nc # Wrap out.nc in degenerate "record" dimension
ncwa -O -a record -B "${msk_var} &lt;= ${thr_max}" out.nc out.nc
ncecat -O out.nc out.nc # Wrap out.nc in degenerate "record" dimension
ncwa -O -a record -B "${msk_var} &gt;= ${thr_min}" out.nc out.nc</example>
      <para>After the first use of <command>ncwa</command>, <file>out.nc</file> contains <var>_FillValue</var> where <code>${msk_var} &gt;= ${thr_max}</code>. The process is then repeated on the remaining data to filter out points where <code>${msk_var} &lt;= ${thr_min}</code>. The resulting <file>out.nc</file> contains valid data only where <math><var>thr_min</var> &lt;= <var>msk_var</var> &lt;= <var>thr_max</var></math>.</para>
    </subsection>
  </node>
  <node>
    <nodename>Contributing</nodename>
    <nodenext>CCSM Example</nodenext>
    <nodeprev>Operator Reference Manual</nodeprev>
    <nodeup>Top</nodeup>
    <chapter>
      <title>Contributing</title>
      <para><indexterm index="cp">contributing</indexterm>We welcome contributions from anyone. The project homepage at <uref><urefurl>https://sf.net/projects/nco</urefurl></uref> contains more information on how to contribute.</para>
      <para><indexterm index="cp">PayPal</indexterm>Financial contributions to <acronym><acronymword>NCO</acronymword></acronym> development may be made through <uref><urefurl>https://www.paypal.com/xclick/business=zender%40uci.edu&amp;item_name=NCO+development&amp;item_number=nco_dnt_dvl&amp;no_note=1&amp;tax=0&amp;currency_code=USD</urefurl><urefdesc>PayPal</urefdesc></uref>. <acronym><acronymword>NCO</acronymword></acronym> has been shared for over 10 years<!-- /@w --> yet only two users have contributed any money to the developers <footnote><para> <indexterm index="cp">chocolate</indexterm>Happy users have sent me a few gifts, though. This includes a box of imported chocolate. Mmm. Appreciation and gifts are definitely better than money. Naturally, I'm too lazy to split and send gifts to the other developers. However, unlike some <acronym><acronymword>NCO</acronymword></acronym> developers, I have a steady "real job". My intent is to split monetary donations among the active developers and to send them their shares via PayPal.</para></footnote>. So you could be the third!</para>
      <menu>
        <menuentry>
          <menunode>Contributors</menunode>
          <menutitle>Contributors</menutitle>
          <menucomment></menucomment>
        </menuentry>
        <menuentry>
          <menunode>Proposals for Institutional Funding</menunode>
          <menutitle>Proposals for Institutional Funding</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </chapter>
  </node>
  <node>
    <nodename>Contributors</nodename>
    <nodenext>Proposals for Institutional Funding</nodenext>
    <nodeprev>Contributing</nodeprev>
    <nodeup>Contributing</nodeup>
    <section>
      <title>Contributors</title>
      <para><indexterm index="cp">contributors</indexterm>The primary contributors to <acronym><acronymword>NCO</acronymword></acronym> development have been:</para>
      <table><indexterm index="cp">Charlie Zender</indexterm>
        <tableitem>
          <tableterm>Charlie Zender</tableterm>
          <item>
            <para>Concept, design and implementation of operators from 1995-2000. Since then autotools, bug-squashing, chunking, documentation, packing, <acronym><acronymword>NCO</acronymword></acronym> library redesign, <command>ncap2</command> features, <command>ncbo</command>, <command>ncpdq</command>, SMP threading and MPI parallelization, netCDF4 integration, external funding, project management, science research, releases. <indexterm index="cp">Henry Butowsky</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Henry Butowsky</tableterm>
          <item>
            <para>Non-linear operations and <code>min()</code>, <code>max()</code>, <code>total()</code> support in <command>ncra</command> and <command>ncwa</command>. Type conversion for arithmetic. Migration to netCDF3 API. <command>ncap2</command> parser, lexer, and I/O<!-- /@w -->. Multislabbing algorithm. Variable wildcarding. Various hacks. <command>ncap2</command> language. <indexterm index="cp">Rorik Peterson</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Rorik Peterson</tableterm>
          <item>
            <para>Original autotool build support. Long command-line options. Original UDUnits support. Debianization. Numerous bug-fixes. <indexterm index="cp">Daniel Wang</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Daniel Wang</tableterm>
          <item>
            <para>Script Workflow Analysis for MultiProcessing (SWAMP). RPM support. <indexterm index="cp">Harry Mangalam</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Harry Mangalam</tableterm>
          <item>
            <para>Benchmarking. OPeNDAP configuration. <indexterm index="cp">Brian Mays</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Brian Mays</tableterm>
          <item>
            <para>Original packaging for Debian GNU/Linux, <command>nroff</command> man pages. <indexterm index="cp">George Shapovalov</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>George Shapovalov</tableterm>
          <item>
            <para>Packaging for Gentoo GNU/Linux. <indexterm index="cp">Bill Kocik</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Bill Kocik</tableterm>
          <item>
            <para>Memory management. <indexterm index="cp">Len Makin</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Len Makin</tableterm>
          <item>
            <para>NEC SX architecture support. <indexterm index="cp">Jim Edwards</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Jim Edwards</tableterm>
          <item>
            <para>AIX architecture support. <indexterm index="cp">Juliana Rew</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Juliana Rew</tableterm>
          <item>
            <para>Compatibility with large PIDs. <indexterm index="cp">Karen Schuchardt</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Karen Schuchardt</tableterm>
          <item>
            <para>Auxiliary coordinate support. <indexterm index="cp">Gayathri Venkitachalam</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Gayathri Venkitachalam</tableterm>
          <item>
            <para><acronym><acronymword>MPI</acronymword></acronym> implementation. <indexterm index="cp">Scott Capps</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Scott Capps</tableterm>
          <item>
            <para>Large work-load testing <indexterm index="cp">Mark Flanner</indexterm><indexterm index="cp">Keith Lindsay</indexterm><indexterm index="cp">Martin Dix</indexterm><indexterm index="cp">Mike Page</indexterm><indexterm index="cp">Martin Schmidt</indexterm><indexterm index="cp">Michael Schulz</indexterm><indexterm index="cp">Remik Ziemlinski</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Martin Dix, Mark Flanner, Keith Lindsay, Mike Page, Martin Schmidt, Michael Schulz, Remik Ziemlinski</tableterm>
          <item>
            <para>Excellent bug reports and feature requests. <indexterm index="cp">Markus Liebig</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Markus Liebig</tableterm>
          <item>
            <para>Proof-read the ncap documentation <indexterm index="cp">Daniel Baumann</indexterm><indexterm index="cp">Barry deFreese</indexterm><indexterm index="cp">Francesco Lovergine</indexterm><indexterm index="cp">Matej Vela</indexterm><indexterm index="cp">Luk Claes</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Daniel Baumann, Barry deFreese, Francesco Lovergine, Matej Vela, Luk Claes</tableterm>
          <item>
            <para>Debian packaging <indexterm index="cp">Patrice Dumas</indexterm><indexterm index="cp">Ed Hill</indexterm><indexterm index="cp">Orion Powlawski</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Patrice Dumas, Ed Hill, Orion Poplawski</tableterm>
          <item>
            <para>RedHat packaging <indexterm index="cp">George Shapavalov</indexterm><indexterm index="cp">Patrick Kursawe</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>George Shapavalov, Patrick Kursawe</tableterm>
          <item>
            <para>Gentoo packaging <indexterm index="cp">Filipe Fernandes</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Filipe Fernandes</tableterm>
          <item>
            <para>OpenSuse packaging <indexterm index="cp">Alexander Hansen</indexterm><indexterm index="cp">Takeshi Enomoto</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Takeshi Enomoto, Alexander Hansen</tableterm>
          <item>
            <para>Mac OS packaging <indexterm index="cp">Eric Blake</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Eric Blake</tableterm>
          <item>
            <para>Autoconf/M4 help <indexterm index="cp">Gavin Burris</indexterm><indexterm index="cp">Kyle Wilcox</indexterm></para>
          </item>
        </tableitem>
        <tableitem>
          <tableterm>Gavin Burris, Kyle Wilcox</tableterm>
          <item>
            <para>RHEL and CentOS build scripts and bug reports.</para>
          </item>
        </tableitem>
      </table>
      <para>Please let me know if your name was omitted!</para>
      <menu>
        <menuentry>
          <menunode>Proposals for Institutional Funding</menunode>
          <menutitle>Proposals for Institutional Funding</menutitle>
          <menucomment></menucomment>
        </menuentry>
      </menu>
    </section>
  </node>
  <node>
    <nodename>Proposals for Institutional Funding</nodename>
    <nodeprev>Contributors</nodeprev>
    <nodeup>Contributing</nodeup>
    <section>
      <title>Proposals for Institutional Funding</title>
      <para><indexterm index="cp">funding</indexterm><indexterm index="cp">proposals</indexterm><indexterm index="cp"><acronym><acronymword>NSF</acronymword></acronym></indexterm><indexterm index="cp">server-side processing</indexterm><indexterm index="cp">Distributed Data Reduction &amp; Analysis</indexterm><indexterm index="cp">Scientific Data Operators</indexterm><indexterm index="cp"><acronym><acronymword>DDRA</acronymword></acronym></indexterm><indexterm index="cp">Server-Side Distributed Data Reduction &amp; Analysis</indexterm><indexterm index="cp"><acronym><acronymword>SSDDRA</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>CCSM</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>IPCC</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>NSF</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>SDO</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>SEIII</acronymword></acronym></indexterm><indexterm index="cp">OptIPuter</indexterm><acronym><acronymword>NSF</acronymword></acronym> has funded a <uref><urefurl>http://nco.sf.net#prp_sei</urefurl><urefdesc>project</urefdesc></uref> to improve Distributed Data Reduction &amp; Analysis (<acronym><acronymword>DDRA</acronymword></acronym>) by evolving <acronym><acronymword>NCO</acronymword></acronym> into a suite of Scientific Data Operators called <acronym><acronymword>SDO</acronymword></acronym>. <indexterm index="cp">parallelism</indexterm>The two main components of this project are <acronym><acronymword>NCO</acronymword></acronym> parallelism (OpenMP, <acronym><acronymword>MPI</acronymword></acronym>) and Server-Side <acronym><acronymword>DDRA</acronymword></acronym> (<acronym><acronymword>SSDDRA</acronymword></acronym>) implemented through extensions to <acronym><acronymword>OPeNDAP</acronymword></acronym> and netCDF4. This project will dramatically reduce bandwidth usage for <acronym><acronymword>NCO</acronymword></acronym> <acronym><acronymword>DDRA</acronymword></acronym>.</para>
      <para><indexterm index="cp"><acronym><acronymword>NASA</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>NRA</acronymword></acronym></indexterm><indexterm index="cp"><acronym><acronymword>HDF</acronymword></acronym></indexterm>With this first <acronym><acronymword>NCO</acronymword></acronym> proposal funded, the content of the next <acronym><acronymword>NCO</acronymword></acronym> proposal is clear. We are interested in obtaining <acronym><acronymword>NASA</acronymword></acronym> support for <acronym><acronymword>HDF</acronymword></acronym>-specific enhancements to <acronym><acronymword>NCO</acronymword></acronym>. We plan to submit a proposal to the next suitable <acronym><acronymword>NASA</acronymword></acronym> <acronym><acronymword>NRA</acronymword></acronym> or <acronym><acronymword>NSF</acronymword></acronym> opportunity.</para>
      <para>We are considering a lot of interesting ideas for still more proposals. Please contact us if you wish to be involved with any future <acronym><acronymword>NCO</acronymword></acronym>-related proposals. Comments on the proposals and letters of support are also very welcome.</para>
    </section>
  </node>
  <node>
    <nodename>CCSM Example</nodename>
    <nodenext>mybibnode</nodenext>
    <nodeprev>Contributing</nodeprev>
    <nodeup>Top</nodeup>
    <chapter>
      <title>CCSM Example</title>
      <para><indexterm index="cp">CCSM</indexterm> This chapter illustrates how to use <acronym><acronymword>NCO</acronymword></acronym> to process and analyze the results of a <acronym><acronymword>CCSM</acronymword></acronym> climate simulation.</para>
      <example xml:space="preserve">************************************************************************
Task 0: Finding input files
************************************************************************
The CCSM model outputs files to a local directory like:

/ptmp/zender/archive/T42x1_40

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

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

within which model output is tagged with the particular model name

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

or

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

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

Normally, we store the "reduced" data in a smaller, local directory.

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

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

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

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

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

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

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

Use ncrcat to aggregate the climatological monthly means

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

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

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

The climatological zonal-mean:

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

The climatological time- and spatial-mean:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      B. Califoria average timeseries
      ncwa -m msk_rgn -w area -a lat,lon \
           sresa1b_ukmo_hadcm3_run1_200001_209912.nc \
	   sresa1b_ukmo_hadcm3_run1_200001_209912_xy_Cal.nc</example>
    </chapter>
  </node>
  <node>
    <nodename>mybibnode</nodename>
    <nodenext>General Index</nodenext>
    <nodeprev>CCSM Example</nodeprev>
    <nodeup>Top</nodeup>
    <chapter>
      <title>References</title>
      <itemize>
        <itemfunction></itemfunction>
        <item>
          <para><anchor name="ZeM07"></anchor>[ZeM07] 
<!-- %**else if --> Zender, C. S., and H. J. Mangalam (2007), Scaling Properties of Common Statistical Operators for Gridded Datasets, Int. J. High Perform. Comput. Appl., 21(4), 485-498, doi:10.1177/1094342007083802.</para>
        </item>
        <item>
          <para><anchor name="Zen08"></anchor>[Zen08] 
<!-- %**else if --> Zender, C. S. (2008), Analysis of Self-describing Gridded Geoscience Data with netCDF Operators (NCO), Environ. Modell. Softw., 23(10), 1338-1342, doi:10.1016/j.envsoft.2008.03.004.</para>
        </item>
        <item>
          <para><anchor name="WZJ07"></anchor>[WZJ07] 
<!-- %**else if --> Wang, D. L., C. S. Zender, and S. F. Jenks (2007), DAP-enabled Server-side Data Reduction and Analysis, Proceedings of the 23rd AMS Conference on Interactive Information and Processing Systems (IIPS) for Meteorology, Oceanography, and Hydrology, Paper 3B.2, January 14-18, San Antonio, TX. American Meteorological Society, AMS Press, Boston, MA.</para>
        </item>
        <item>
          <para><anchor name="ZMW06"></anchor>[ZMW06] 
<!-- %**else if --> Zender, C. S., H. Mangalam, and D. L. Wang (2006), Improving Scaling Properties of Common Statistical Operators for Gridded Geoscience Datasets, Eos Trans. AGU, 87(52), Fall Meet. Suppl., Abstract IN53B-0827.</para>
        </item>
        <item>
          <para><anchor name="ZeW07"></anchor>[ZeW07] 
<!-- %**else if --> Zender, C. S., and D. L. Wang (2007), High performance distributed data reduction and analysis with the netCDF Operators (NCO), Proceedings of the 23rd AMS Conference on Interactive Information and Processing Systems (IIPS) for Meteorology, Oceanography, and Hydrology, Paper 3B.4, January 14-18, San Antonio, TX. American Meteorological Society, AMS Press, Boston, MA.</para>
        </item>
        <item>
          <para><anchor name="WZJ06"></anchor>[WZJ06] 
<!-- %**else if --> Wang, D. L., C. S. Zender, and S. F. Jenks (2006), Server-side netCDF Data Reduction and Analysis, Eos Trans. AGU, 87(52), Fall Meet. Suppl., Abstract IN53B-0826.</para>
        </item>
        <item>
          <para><anchor name="WZJ073"></anchor>[WZJ073] 
<!-- %**else if --> Wang, D. L., C. S. Zender, and S. F. Jenks (2007), Server-side parallel data reduction and analysis, in Advances in Grid and Pervasive Computing, Second International Conference, GPC 2007, Paris, France, May 2-4, 2007, Proceedings. IEEE Lecture Notes in Computer Science, vol. 4459, edited by C. Cerin and K.-C. Li, pp. 744-750, Springer-Verlag, Berlin/Heidelberg, doi:10.1007/978-3-540-72360-8_67.</para>
        </item>
        <item>
          <para><anchor name="WZJ074"></anchor>[WZJ074] 
<!-- %**else if --> Wang, D. L., C. S. Zender and S. F. Jenks (2007), A System for Scripted Data Analysis at Remote Data Centers, Eos Trans. AGU, 88(52), Fall Meet. Suppl., Abstract IN11B-0469.</para>
        </item>
        <item>
          <para><anchor name="WZJ081"></anchor>[WZJ081] 
<!-- %**else if --> Wang, D. L., C. S. Zender and S. F. Jenks (2008), Cluster Workflow Execution of Retargeted Data Analysis Scripts, Proceedings of the 8th IEEE Int'l Symposium on Cluster Computing and the Grid (IEEE CCGRID '08), pp. 449-458, Lyon, France, May 2008.</para>
        </item>
        <item>
          <para><anchor name="WZJ091"></anchor>[WZJ091] 
<!-- %**else if --> Wang, D. L., C. S. Zender, and S. F. Jenks (2009), Efficient Clustered Server-side Data Analysis Workflows using SWAMP, Earth Sci. Inform., 2(3), 141-155, doi:10.1007/s12145-009-0021-z.</para>
        </item>
      </itemize>
<!-- @node Name Index, General Index, Operators, Top -->
<!-- @unnumbered Function and Variable Index -->
<!-- @printindex fn -->
    </chapter>
  </node>
  <node>
    <nodename>General Index</nodename>
    <nodeprev>mybibnode</nodeprev>
    <nodeup>Top</nodeup>
    <unnumbered>
      <title>General Index</title>
      <printindex>cp</printindex>
<!-- Print table of contents -->
      <contents></contents>
<!-- TTFN (Ta ta for now) -->
    </unnumbered>
  </node>
</texinfo>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-indent-step:1
sgml-indent-data:nil
End:
-->

