\section{Building from sources}

This section describes how to build {\CDO} from the sources on a UNIX system.
{\CDO} uses the GNU configure and build system for compilation.
The only requirement is a working ANSI C99 compiler.

%First go to the \href{http://www.mpimet.mpg.de/cdo/download.html}{\tt download} page
%({\tt http://www.mpimet.mpg.de/\\,cdo/download.html}) to get the latest distribution,
First go to the \href{http://www.mpimet.mpg.de/cdo}{\tt download} page
({\tt http://www.mpimet.mpg.de/cdo}) to get the latest distribution,
if you do not have it yet.

To take full advantage of {\CDO} features the following additional
libraries should be installed:

\begin{itemize}
\item Unidata \href{http://www.unidata.ucar.edu/packages/netcdf}{netCDF} library
      ({\tt http://www.unidata.ucar.edu/packages/netcdf})
      version 3 or higher. \\
      This is needed to process netCDF \cite{netCDF} files with {\CDO}. 
\item HDF5 \href{http://www.hdfgroup.org/doc_resource/SZIP}{szip} library
      ({\tt http://www.hdfgroup.org/doc\_resource/SZIP})
      version 2.1 or higher. \\
      This is needed to process szip compressed GRIB \cite{GRIB} files with {\CDO}. 
\item \href{http://www.hdfgroup.org/HDF5}{HDF5} library
      ({\tt http://www.hdfgroup.org/HDF5})
      version 1.6 or higher. \\
      This is needed to import  CM-SAF \cite{CM-SAF} HDF5 files with the {\CDO}
      operator {\bf import\_cmsaf}. 
\item \href{http://trac.osgeo.org/proj}{PROJ.4} library
      ({\tt http://trac.osgeo.org/proj})
      version 4.6 or higher. \\
      This is needed to convert Sinusoidal and Lambert Azimuthal Equal Area coordinates
      to geographic coordinates, for e.g. remapping. 
\end{itemize}

%This section is divided into the following sections:
%<ul>
%<li>\ref install_src_unix  "Compiling from source on Unix"
%<li>\ref install_bin_unix  "Installing the binaries on Unix"
%<li>\ref build_tools       "Tools used to develop CDO"
%</ul>


\subsection{Compilation}

Compilation is done by performing the following steps:

\begin{enumerate}
\item Unpack the archive, if you haven't done that yet:
   
\begin{verbatim}
    gunzip cdo-$VERSION.tar.gz    # uncompress the archive
    tar xf cdo-$VERSION.tar       # unpack it
    cd cdo-$VERSION
\end{verbatim}

\item Run the configure script:
 
\begin{verbatim}
    ./configure
\end{verbatim}

Or with netCDF \cite{netCDF} support:
 
\begin{verbatim}
    ./configure --with-netcdf=<netCDF root directory>
\end{verbatim}

The netCDF-4 configuration depends on the netCDF-4 and HDF5 installation!
You have to define the location of the HDF5 installation if netCDF-4 was 
build with HDF5 support:
 
\begin{verbatim}
    ./configure --with-netcdf=<netCDF-4 root directory> \
                --with-hdf5=<HDF5 root directory>
\end{verbatim}

You have to specify also the location of the SZLIB if HDF5 was build with SZLIB support.\\

To enable szip \cite{szip} support add:
 
\begin{verbatim}
    --with-szlib=<SZLIB root directory>
\end{verbatim}

For an overview of other configuration options use

\begin{verbatim}
    ./configure --help
\end{verbatim}

\item Compile the program by running make:

\begin{verbatim}
    make
\end{verbatim}

\end{enumerate}

The program should compile without problems and the binary ({\tt cdo}) 
should be available in the {\tt src} directory of the distribution.


\subsection{Installation}

After the compilation of the source code do a {\tt make install},
possibly as root if the destination permissions require that.

\begin{verbatim}
    make install
\end{verbatim} 

The binary is installed into the directory {\tt $<$prefix$>$/bin}.
{\tt $<$prefix$>$} defaults to {\tt /usr/local} but can be changed with 
the {\tt --prefix} option of the configure script. 

Alternatively, you can also copy the binary from the {\tt src} directory
manually to some {\tt bin} directory in your search path.
