NetCDF Users Guide
v1.1
|
This document is for getting and building the netCDF C library and utilities for the most recent released version.
Other libraries that depend on the netCDF C library, such as the Fortran, Python, Java, and C++ libraries, are available as separate distributions that can be optionally built and installed after the C library is successfully installed.
The netCDF-Java library is independent of the netCDF C library unless writing netCDF-4 files from Java is required.
The easiest way to get netCDF is through a package management program, such as rpm, yum, homebrew, macports, adept, and others. NetCDF is available from many different repositories, including the default Red Hat and Ubuntu repositories.
When getting netCDF from a software repository, you should get a development version that includes the netcdf.h header file. A development version will typically have a name such as "netcdf-devel" or "libnetcdf-dev".
Instructions for installing and using pre-built libraries for Windows may be found here: Installing and Using netCDF-C Libraries in Windows.
The netCDF-C source code is hosted from the Unidata GitHub repository.
Two options are available for building from source:
The latest full release may be downloaded from GitHub.
Source files are available in .tar.gz
and .zip
formats.
The developer snapshot may be cloned from GitHub directly by using the git
command.
$ git clone http://github.com/Unidata/netcdf-c netcdf-c
Note:
The developer snapshot release contains bug-fixes and new features added since the last full release, but may also contain new bugs, as it is not tested as extensively as the full release.
The netCDF-C library and utilities require third-party libraries for full functionality. (See NetCDF Library Architecture).
Important Note: When building netCDF-C library versions older than 4.4.1, use only HDF5 1.8.x versions.
Combining older netCDF-C versions with newer HDF5 1.10 versions will create superblock 3 files that are not readable by lots of older software.
See this announcement for more details.
The usual way of building netCDF requires the HDF5, zlib, and curl libraries. Versions required are at least HDF5 1.8.9, zlib 1.2.5, and curl 7.18.0 or later.
HDF5 and zlib packages are available from the HDF5 downloads site and the zlib home site. If you wish to use the remote data client code, then you will also need libcurl, which can be obtained from the curl website.
Note that for building netCDF, it is not necessary to build the HDF5 Fortran, C++, or Java API's. Only the HDF5 C library is used, even for netCDF Fortran or C++ libraries.
Optionally, you can also build netCDF-4 with the szip library (a.k.a. szlib). If building with szlib, get szip 2.0 or later. Technically, we mean that the HDF5 library is built with szip support. The netcdf build will then inherit szip support from the HDF5 library. If you intend to write files with szip compression, then we suggest that you use libaec to avoid patent problems. That library can be used as a drop-in replacement for the standard szip library. If you plan to use the standard szip library, then determine whether license restrictions on the use of szip apply to your situation. See the web page on szip compression in HDF products.
If make check
fails for either zlib
or HDF5
, the problem must be resolved before the netCDF-4 installation can continue. For HDF5 problems, see the HDF5 help services.
To build zlib from source, specify where you want to install zlib in a shell variable you will also use later (ZDIR, for example), and build it like this from the top-level zlib source directory
Next, specify where you want to install HDF5 in another shell variable, for example H5DIR, and build it from the HDF5 top-level source directory:
If you are building HDF5 with the optional szip library, include the --with-szlib=
option to specify where it was installed.
In all cases, the installation location specified with the --prefix
option must be different from the source directory where the software is being built.
Before building netCDF, you may need to add ${H5DIR}/lib
to the LD_LIBRARY_PATH
environment variable if that lib directory is not searched by default. See the netCDF FAQ for more details on using shared libraries.
Indicate where you want to install netCDF in another shell variable, for example NCDIR
. Then run the netCDF configure script, specifying where HDF5 was installed using the CPPFLAGS and LDFLAGS environment variables. For example, from the top-level netCDF source directory:
If you don't provide a --prefix
option, installation will be in /usr/local/
, in subdirectories lib/, include/, and bin/.
The installation location specified with the --prefix
option must be different from the source directory where the software is being built.
WARNING: you should be able to use parallel 'make all'. But 'make check' will probably fail if you use parallel make. This is because historically, there are inter-dependencies between test programs. It is unlikely that this will be fixed any time soon, if ever.
It is possible to build the netCDF C libraries and utilities so that only the netCDF classic and 64-bit offset formats are supported, or the remote data access client is not built. (See The netCDF File Format for more information about the netCDF format variants.
See the <ahref="http://www.opendap.org/documentation">DAP documentation and support site for more information about remote client access to data on OPeNDAP servers.)
If necessary, set the NCDIR shell variable to indicate where netCDF should be installed. Then to build a netCDF-3 library without support for the netCDF-4 formats or functions, but with remote client access, use:
To build with full support for netCDF-4 API's and format but without remote client access, use:
To build without netCDF-4 support or remote client access, use:
If you get the message that netCDF installed correctly, then you are done!
The netCDF-4 library can read HDF4 data files, if they were created with the SD (Scientific Data) API.
For this to work, you must build the HDF4 library with the configure option --disable-netcdf
to prevent it from building an HDF4 version of the netCDF-2 library that conflicts with the netCDF-2 functions that are built into the Unidata netCDF library.
Then, when building netCDF-4, use the --enable-hdf4
option to configure. The location for the HDF4 header files and library must be specified in the CPPFLAGS
and LDFLAGS
environment variables or configure options.
For HDF4 access to work, the library must be built with netCDF-4 features.
Here's an example, assuming the HDF5 library has been built and installed in H5DIR and you will build and install the HDF4 library in H4DIR (which could be the same as H5DIR). From the top-level HDF4 source directory:
Then from the top-level netCDF directory:
For parallel I/O to work, HDF5 must be installed with --enable-parallel
, and an MPI library (and related libraries) must be made available to the HDF5 configure. This can be accomplished with an mpicc wrapper script.
The following works from the top-level HDF5 source directory to buildHDF5 with parallel I/O:
If the HDF5 used by netCDF has been built with parallel I/O, then netCDF will also be built with inherited support for parallel I/O. This allows parallel I/O access to netCDF-4/HDF5 files.
(See /ref netcdf_formats for more information about the netCDF format variants.)
From the top-level netCDF-4 source directory, the following builds netCDF-4 with parallel I/O, assuming H5DIR specifies where parallel HDF5 was installed:
To enable parallel I/O support for classic netCDF files, i.e. CDF-1, 2 and 5 formats, PnetCDF library must also be installed.
First specify where you want to install PnetCDF in a shell variable, for example PNDIR, and build it from the PnetCDF top-level source directory. If you would like to build the shared library, include --enable-shared
option at the configure command line.
By default, only a static library is built.
To build netCDF-4 with PnetCDF support, from the top-level netCDF-4 source directory, configure netCDF with the "--enable-pnetcdf" option. If PnetCDF is built with static library only, add "--disable-shared" option.
For static builds of applications that use netCDF-4 you must link to all the libraries, netCDF, HDF5, zlib, szip (if used with HDF5 build), PnetCDF (if used with PnetCDF build), and curl (if the remote access client has not bee disabled). This will require -L options to your build for the locations of the libraries, and -l (lower-case L) for the names of the libraries.
For example, you might build other applications with netCDF-4 by setting the LIBS environment variable, assuming NCDIR, H5DIR, PNDIT, and ZDIR indicate where netCDF, HDF5, PnetCDF, and zlib are installed:
For shared builds, only -L${NCDIR}/lib -lnetcdf
is needed. All other libraries will be found automatically.
The pkg-config
or nc-config
utilities can be used to specify build options for software that uses netCDF.
For example, to compile and link an application named myapp.c with a netCDF-C libraries, whether shared or static, you can use
or
These options are used for autotools
-based builds.yup
Note: --disable
prefix indicates that the option is normally enabled.
Option | Description | Dependencies |
---|---|---|
–disable-doxygen | Disable generation of documentation. | doxygen |
–disable-fsync | disable fsync support | kernel fsync support |
–disable-netcdf-4 | build netcdf-3 without HDF5 and zlib | |
–disable-netcdf4 | synonym for disable-netcdf-4 | |
–enable-hdf4 | build netcdf-4 with HDF4 read capability | HDF4, HDF5 and zlib |
–enable-hdf4-file-tests | test ability to read HDF4 files | selected HDF4 files from Unidata ftp site |
–disable-parallel4 | build netcdf-4 without parallel I/O support | |
–disable-cdf5 | build netcdf-4 without support of classic CDF-5 file format | |
–enable-pnetcdf | build netcdf-4 with parallel I/O for classic files (CDF-1, 2, and 5 formats) using PnetCDF | PnetCDF |
–enable-extra-example-tests | Run extra example tests | –enable-netcdf-4,GNU sed |
–disable-filter-testing | Run filter example | –enable-shared –enable-netcdf-4 |
–enable-parallel-tests | run extra parallel IO tests | –enable-netcdf-4 or –enable-pnetcdf, parallel IO support |
–enable-logging | enable logging capability | –enable-netcdf-4 |
–disable-dap | build without DAP client support. | libcurl |
–disable-dap-remote-tests | disable dap remote tests | –enable-dap |
–enable-dap-long-tests | enable dap long tests | |
–enable-extra-tests | run some extra tests that may not pass because of known issues | |
–enable-ffio | use ffio instead of posixio (ex. on the Cray) | |
–disable-examples | don't build the netCDF examples during make check (examples are treated as extra tests by netCDF) | |
–disable-v2 | turn off the netCDF version 2 API | |
–disable-utilities | don't build netCDF utilities ncgen, ncdump, and nccopy | |
–disable-testsets | don't build or run netCDF tests | |
–enable-large-file-tests | Run tests which create very large data files | ~13 GB disk space required, but recovered when tests are complete). See option –with-temp-large to specify temporary directory |
–enable-benchmarks | Run benchmarks. This is an experimental feature. The benchmarks are extra tests, used to check netCDF performance. | sample data files from the Unidata ftp site |
–disable-extreme-numbers | don't use extreme numbers during testing, such as MAX_INT - 1 | |
–disable-shared | don't build shared libraries | |
–disable-static | don't build static libraries | |
–disable-largefile | omit support for files larger than 2GB | |
–enable-mmap | Use mmap to implement NC_DISKLESS | System-provided mmap or mremap functions |
–enable-valgrind-tests | build with valgrind-tests; static builds only | valgrind |
Starting with netCDF-C 4.3.0, we are happy to announce the inclusion of CMake support.
CMake will allow for building netCDF on a wider range of platforms, include Microsoft Windows with Visual Studio.
CMake support also provides robust unit and regression testing tools.
We will also maintain the standard autotools-based build system in parallel.
In addition to providing new build options for netCDF-C, we will also provide pre-built binary downloads for the shared versions of netCDF for use with Visual Studio.
The following packages are required to build netCDF-C using CMake.
There are four steps in the Build Process when using CMake
For users who prefer pre-built binaries, installation packages are available at Installing and Using netCDF-C Libraries in Windows
The output of the configuration step is a project file based on the appropriate configurator specified.
Common configurators include:
Option | Autotools | CMake |
---|---|---|
Specify Install Location | –prefix=PREFIX | -D"CMAKE_INSTALL_PREFIX=PREFIX" |
Enable/Disable netCDF-4 | –enable-netcdf-4 –disable-netcdf-4 | -D"ENABLE_NETCDF_4=ON" -D"ENABLE_NETCDF_4=OFF" |
Enable/Disable DAP | –enable-dap –disable-dap | -D"ENABLE_DAP=ON" -D"ENABLE_DAP=OFF" |
Enable/Disable Utilities | –enable-utilities –disable-utilities | -D"BUILD_UTILITIES=ON" -D"BUILD_UTILITIES=OFF" |
Specify shared/Static Libraries | –enable-shared –enable-static | -D"BUILD_SHARED_LIBS=ON" -D"BUILD_SHARED_LIBS=OFF" |
Enable/Disable Parallel netCDF-4 | –enable-parallel4 –disable-parallel4 | -D"ENABLE_PARALLEL4=ON" -D"ENABLE_PARALLEL4=OFF" |
Enable/Disable PnetCDF | –enable-pnetcdf –disable-pnetcdf | -D"ENABLE_PNETCDF=ON" -D"ENABLE_PNETCDF=OFF" |
Enable/Disable CDF5 | –enable-cdf5 –disable-cdf5 | -D"ENABLE_CDF5=ON" -D"ENABLE_CDF5=OFF" |
Enable/Disable Tests | –enable-testsets –disable-testsets | -D"ENABLE_TESTS=ON" -D"ENABLE_TESTS=OFF" |
Enable/Disable Parallel Tests | –enable-parallel-tests –disable-parallel-tests | -D"ENABLE_PARALLEL_TESTS=ON" -D"ENABLE_PARALLEL_TESTS=OFF" |
Specify a custom library location | Use CFLAGS and LDFLAGS | -D"CMAKE_PREFIX_PATH=/usr/custom_libs/" |
A full list of basic options can be found by invoking cmake [Source Directory] -L
. To enable a list of basic and advanced options, one would invoke cmake [Source Directory] -LA
.
The easiest configuration case would be one in which all of the dependent libraries are installed on the system path (in either Unix/Linux or Windows) and all the default options are desired. From the build directory (often, but not required to be located within the source directory):
$ cmake [Source Directory]
If you have libraries installed in a custom directory, you may need to specify the CMAKE_PREFIX_PATH variable to tell cmake where the libraries are installed. For example:
$ cmake [Source Directory] -DCMAKE_PREFIX_PATH=/usr/custom_libraries/
The compiler can be executed directly with 'make' or the appropriate command for the configurator which was used.
$ make
Building can also be executed indirectly via cmake:
$ cmake –build [Build Directory]
Testing can be executed several different ways:
$ make test
or
$ ctest
or
$ cmake –build [Build Directory] –target test
Once netCDF has been built and tested, it may be installed using the following commands:
$ make install
or
$ cmake –build [Build Directory] –target install
For further information regarding netCDF and CMake, see CMake-Related Frequently Asked Questions.