Skip to content
Shawfeng Dong edited this page Nov 6, 2016 · 2 revisions

NetCDF (Network Common Data Form) is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data[1].

Table of Contents

Building NetCDF

The source codes for netCDF-C, netCDF-Fortran & netCDF-C++ can be downloaded from https://www.unidata.ucar.edu/downloads/netcdf/index.jsp. The netCDF-C library and utilities require the following third-party libraries for full functionality[2]:

  • HDF5 1.8.9 or later (for netCDF-4 support)
  • zlib 1.2.5 or later (for netCDF-4 compression)
  • curl 7.18.0 or later (for DAP remote access client support)
They are all present on Hyades. There are a few HDF5 libraries on Hyades. Among those, we use the one (in standard system location /usr) provided by the hdf5-1.8.12-1.with.szip.encoder.el6.x86_64 RPM package to build NetCDF.

With GCC

netCDF-C 4.3.0:

$ cd /scratch
$ tar xvfz netcdf-4.3.0.tar.gz
$ cd netcdf-4.3.0
$ ./configure --prefix=/pfs/sw/serial/gcc/netcdf-4.3.0
$ make
$ make install

netCDF-Fortran 4.2:

$ cd /scratch
$ tar xvfz netcdf-fortran-4.2.tar.gz
$ cd netcdf-fortran-4.2
$ export LD_LIBRARY_PATH=/pfs/sw/serial/gcc/netcdf-4.3.0/lib:$LD_LIBRARY_PATH
$ CPPFLAGS=-I/pfs/sw/serial/gcc/netcdf-4.3.0/include \
  LDFLAGS=-L/pfs/sw/serial/gcc/netcdf-4.3.0/lib \
  ./configure --prefix=/pfs/sw/serial/gcc/netcdf-4.3.0
$ make
$ make install

With Intel Compilers

netCDF-C 4.3.1.1:

$ cd /scratch
$ rm -rf netcdf-4.3.1.1
$ tar xvfz netcdf-4.3.1.1.tar.gz
$ cd netcdf-4.3.1.1
$ CC=icc ./configure --prefix=/pfs/sw/serial/gcc/netcdf-4.3.0
$ make
$ make install

netCDF-Fortran 4.2:

$ cd /scratch
$ rm -rf netcdf-fortran-4.2
$ tar xvfz netcdf-fortran-4.2.tar.gz
$ cd netcdf-fortran-4.2
$ export LD_LIBRARY_PATH=/pfs/sw/serial/intel/netcdf-4.3.1.1/lib:$LD_LIBRARY_PATH
$ CC=icc FC=ifort F77=ifort \
  CPPFLAGS=-I/pfs/sw/serial/intel/netcdf-4.3.1.1/include \
  LDFLAGS=-L/pfs/sw/serial/intel/netcdf-4.3.1.1/lib \
  ./configure --prefix=/pfs/sw/serial/intel/netcdf-4.3.1.1
$ make
$ make install

With PGI Compilers

We must first load the pgi module:

$ module load pgi

netCDF-C 4.3.1.1:

$ cd /scratch
$ rm -rf netcdf-4.3.1.1
$ tar xvfz netcdf-4.3.1.1.tar.gz
$ cd netcdf-4.3.1.1

The command

$ CC=pgcc ./configure --prefix=/pfs/sw/serial/pgi/netcdf-4.3.1.1
will fail with the following error:
checking how to run the C preprocessor... /opt/pgi/linux86-64/14.10/bin/pgprepro
configure: error: in `/scratch/netcdf-4.3.1.1':
configure: error: C preprocessor "/opt/pgi/linux86-64/14.10/bin/pgprepro" fails sanity check

We must specify CPP:

$ CC=pgcc CPP="pgcc -E" \
  ./configure --prefix=/pfs/sw/serial/pgi/netcdf-4.3.1.1

$ make
$ make install

netCDF-Fortran 4.2:

$ cd /scratch
$ rm -rf netcdf-fortran-4.2
$ tar xvfz netcdf-fortran-4.2.tar.gz
$ cd netcdf-fortran-4.2

Instead of specifying CPPFLAGS and LDFLAGS as when using GCC or Intel compilers[3], here we just load the netcdf/s_pgi_4.3.1.1:

$ module load netcdf/s_pgi_4.3.1.1

$ CC=pgcc CPP="pgcc -E" \
  FC=pgf90 F77=pgf77 \
  ./configure --prefix=/pfs/sw/serial/pgi/netcdf-4.3.1.1
$ make
$ make install

netCDF C++ 4.2.1:

$ cd /scratch
$ wget https://github.com/Unidata/netcdf-cxx4/archive/v4.2.1.tar.gz
$ mv v4.2.1 netcdf-cxx4-4.2.1.tar.gz
$ tar xvfz netcdf-cxx4-4.2.1.tar.gz
$ cd netcdf-cxx4-4.2.1

$ module load netcdf/s_pgi_4.3.1.1

The command

$ CC=pgcc CPP="pgcc -E" CXX=pgCC \
  ./configure --prefix=/pfs/sw/serial/pgi/netcdf-4.3.1.1
will fail with the following error:
configure: error: NetCDF must be built with netCDF-4 enabled.

The error, however, is misleading; because NetCDF is built with netCDF-4 enabled:

$ nc-config --has-nc4
yes

A quick Google search will turn up many similar errors, dating at least back to 2012[4]. The solution offered by the netCDF support team doesn't work! A quick inspection of the configuration log suggests that there is a bug in the Autoconf[5] test, which fails to correctly determine whether netCDF-4 is enabled or not. My workaround is to replace the following line in configure:

nc_build_v4=$ac_cv_func_nc_def_opaque
with
nc_build_v4=yes
then I can successfully build netcdf-cxx4-4.2.1:
$ CC=pgcc CPP="pgcc -E" CXX=pgCC \
  ./configure --prefix=/pfs/sw/serial/pgi/netcdf-4.3.1.1
$ make
$ make install

Python netCDF4 module

We've also installed netcdf4-python[6][7], the Python interface to the netCDF C library, on Hyades.

$ module load python
$ export NETCDF4_DIR=/pfs/sw/serial/intel/netcdf-4.3.1.1
$ pip install netCDF4

Using NetCDF

To facilitate the usage of netCDF libraries, we've create a few module files for them.

To list all available netCDF modules, run:

$ module avail netcdf

netcdf/s_gcc_4.3.0              netcdf/s_intel_4.3.1.1(default) netcdf/s_pgi_4.3.1.1

To display information about, e.g., the netcdf/s_pgi_4.3.1.1 module and list the environment changes it makes, run:

$ module display netcdf/s_pgi_4.3.1.1
-------------------------------------------------------------------
/pfs/sw/modulefiles/netcdf/s_pgi_4.3.1.1:

module-whatis	 Set up environment for netcdf compiled with PGI compilers 
prepend-path	 PATH /pfs/sw/serial/pgi/netcdf-4.3.1.1/bin 
prepend-path	 CPATH /pfs/sw/serial/pgi/netcdf-4.3.1.1/include 
prepend-path	 LIBRARY_PATH /pfs/sw/serial/pgi/netcdf-4.3.1.1/lib 
prepend-path	 LD_LIBRARY_PATH /pfs/sw/serial/pgi/netcdf-4.3.1.1/lib 
prepend-path	 MANPATH /pfs/sw/serial/pgi/netcdf-4.3.1.1/share/man 
-------------------------------------------------------------------

To load the netcdf/s_pgi_4.3.1.1 module, run:

$ module load netcdf/s_pgi_4.3.1.1
Then you can simply use the option -lnetcdf to link with the netCDF-C library built with the PGI compilers. You don't need specify the include path with -I/pfs/sw/serial/pgi/netcdf-4.3.1.1/include, nor the library path with -L/pfs/sw/serial/pgi/netcdf-4.3.1.1/lib.

Ncview

Ncview is a visual browser for netCDF format files.

To install Ncview, first build udunits (a C-based package for the programatic handling of units of physical quantities) 2.1.24; then build Ncview 2.1.4:

$ cd /scratch
$ tar xvfz ncview-2.1.4.tar.gz 
$ ./configure \
  --prefix=/pfs/sw/serial/gcc/ncview-2.1.4 \
  --with-nc-config=/pfs/sw/serial/gcc/netcdf-4.3.0/bin/nc-config \
  --with-udunits2_incdir=/pfs/sw/serial/gcc/udunits-2.1.24/include \
  --with-udunits2_libdir=/pfs/sw/serial/gcc/udunits-2.1.24/lib

$ make
$ make install

To use Ncview, first load its module:

$ module load ncview

References

  1. ^ NetCDF Documentation
  2. ^ Building netCDF-C
  3. ^ Building the netCDF-4.2 and later Fortran libraries
  4. ^ Failure to configure NetCDF-4.2 CXX libraries
  5. ^ Autoconf manual
  6. ^ netcdf4-python
  7. ^ netcdf4-python documentation
Clone this wiki locally