Difference between revisions of "UsingNetCDF"

From SourceWiki
Jump to navigation Jump to search
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Pragmatic Programming]]
 +
'''Using NetCDF files for your data'''
 +
=Introduction=
 +
 +
=Software Installation=
 +
 +
==On Ubuntu==
 +
 +
The Ubuntu package manager makes this very easy.  Go to '''System->Administration->Synaptic Package Manager''' (you will need to enter your password) and select the packages:
 +
 +
* '''python-scientific'''  (this provides a python interface for reading/writing NetCDF files)
 +
along with:
 +
* '''python-tk'''
 +
* '''python-matplotlib)'''  (these provide a means to view your data graphically)
 +
 +
==Compiling from Source==
 +
 +
This is not as convenient as using a package manager and is a bit messy!
 +
 +
===Compiling the NetCDF Libraries from Unidata===
 +
 +
The source code can be downloaded from Unidata:
 +
 +
<pre>
 +
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.0.tar.gz
 +
</pre>
  
 +
Now, unpack the tarball and build the libraries:
  
=Introduction=
+
<pre>
 +
tar -xzf netcdf-4.0.tar.gz
 +
cd netcdf-4.0
 +
./configure --prefix=/opt/netcdf/netcdf-4.0 --enable-shared FC=ifort CC=gcc CXX=g++ CPPFLAGS="-DpgiFortran" \
 +
FCFLAGS="-fpic" CFLAGS="-fPIC" CXXFLAGS="-fPIC"
 +
make
 +
make check
 +
make install
 +
</pre>
 +
 
 +
Note that we need to build the '''shared''' libraries.  Hence the addition of the '''-fPIC''' flags
 +
 
 +
===Installing the Python Interface===
 +
 
 +
<pre>
 +
wget http://sourcesup.cru.fr/frs/download.php/1833/Numeric-23.8.2.tar.gz
 +
tar -xzf ...
 +
cd Numeric...
 +
python setup.py install
 +
</pre>
 +
 
 +
<pre>
 +
wget http://sourcesup.cru.fr/frs/download.php/2309/ScientificPython-2.8.tar.gz
 +
cd ..
 +
tar ...
 +
</pre>
 +
 
 +
but now need to hack setup.py for:
 +
* netcdf path
 +
* problems with /usr/lib and /usr/lib64
 +
 
 +
perhaps easiest to just patch with a symbolic link:
 +
 
 +
<pre>
 +
cd /usr/lib/python2.4/site-packages
 +
ln -s /usr/lib64/python2.4/site-packages/Scientific
 +
</pre>
  
=Admin Details=
+
=An Example Session=

Latest revision as of 09:29, 24 June 2009

Using NetCDF files for your data

Introduction

Software Installation

On Ubuntu

The Ubuntu package manager makes this very easy. Go to System->Administration->Synaptic Package Manager (you will need to enter your password) and select the packages:

  • python-scientific (this provides a python interface for reading/writing NetCDF files)

along with:

  • python-tk
  • python-matplotlib) (these provide a means to view your data graphically)

Compiling from Source

This is not as convenient as using a package manager and is a bit messy!

Compiling the NetCDF Libraries from Unidata

The source code can be downloaded from Unidata:

wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.0.tar.gz

Now, unpack the tarball and build the libraries:

tar -xzf netcdf-4.0.tar.gz
cd netcdf-4.0
./configure --prefix=/opt/netcdf/netcdf-4.0 --enable-shared FC=ifort CC=gcc CXX=g++ CPPFLAGS="-DpgiFortran" \
FCFLAGS="-fpic" CFLAGS="-fPIC" CXXFLAGS="-fPIC"
make
make check
make install

Note that we need to build the shared libraries. Hence the addition of the -fPIC flags

Installing the Python Interface

wget http://sourcesup.cru.fr/frs/download.php/1833/Numeric-23.8.2.tar.gz
tar -xzf ...
cd Numeric...
python setup.py install
wget http://sourcesup.cru.fr/frs/download.php/2309/ScientificPython-2.8.tar.gz
cd ..
tar ...

but now need to hack setup.py for:

  • netcdf path
  • problems with /usr/lib and /usr/lib64

perhaps easiest to just patch with a symbolic link:

cd /usr/lib/python2.4/site-packages
ln -s /usr/lib64/python2.4/site-packages/Scientific

An Example Session