\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,
First go to the \href{http://code.zmaw.de/projects/cdo}{\tt download} page
({\tt http://code.zmaw.de/projects/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 The ECMWF \href{http://www.ecmwf.int/products/data/software/grib_api.html}{GRIB\_API}
      ({\tt http://www.ecmwf.int/products/data/software/grib\_api.html})
      version 1.9.5 or higher.
      This library is needed to process GRIB2 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}

{\CDO} is a multi-threaded application. Therefor all the above
libraries should be compiled thread safe. Using non-threadsafe
libraries could cause unexpected errors.

%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}

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

\item The GRIB2 configuration depends on the GRIB\_API installation!
Here is an example GRIB2 configuration with a JASPER enabled GRIB\_API version:
 
\begin{verbatim}
./configure --with-grib_api=<GRIB_API root directory> \
            --with-jasper=<JASPER root directory>
\end{verbatim}

%%You have to specify also the location of the SZLIB if HDF5 was build with SZLIB support.\\
%%
%%\item To enable szip \cite{szip} support add:
%% 
%%\begin{verbatim}
%%    --with-szlib=<SZLIB root directory>
%%\end{verbatim}

\end{itemize}

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.
