PGI Guide to NetCDF

This guide is intended to help build and test the network Common Data Format libraries using the PGI 2010 compilers.

Version Information

This guide was created for the 4.0.1 release of netCDF and PGI 2010 release. This information is for both x64 processors running 64-bit Windows and x86 processors running 32-bit Windows.

Application Notes

Information about netCDF can be found at the netCDF FAQ page.

(From the webpage) "NetCDF (network Common Data Form) is an interface for array-oriented data access and a freely-distributed collection of software libraries for C, Fortran, C++, Java, and perl that provide implementations of the interface. The netCDF software was developed by Glenn Davis, Russ Rew, Steve Emmerson, John Caron, and Harvey Davies at the Unidata Program Center in Boulder, Colorado, and augmented by contributions from other netCDF users. The netCDF libraries define a machine-independent format for representing scientific data. Together, the interface, libraries, and format support the creation, access, and sharing of scientific data."

Obtaining the Source Code

netCDF source code can be downloaded from anonymous FTP found at the netCDF FTP site or on the web at the netCDF FAQ page. The 4.0 release notes contain information about this release.



Building netCDF and Testing

  1. Download the source code to a DOS directory. Trying to build in a Cygwin directory or in a shared directory can complicate the process. Untar the netCDF package.

    tar -xvzf netcdf-4.0.1.tar.gz
    cd netcdf-4.0.1
  2. Edit the file libsrc/v2i.c and on line 12 add:

    #include "nc.h"
  3. Edit the file configure and change line 15973 from:

     *pgCC\ [1-5]* | *pgcpp\ [1-5]*)


     *pgCC\ [1-5].* | *pgcpp\ [1-5].*)

    These changes will allow the match for the PGI 2010 release 10.0 and above compilers to fall through to the lower stanza.

  4. Set up your environment:

    setenv AR pgar
    setenv NM pgnm
    setenv CC pgcc
    setenv CXX pgcpp
    setenv CFLAGS  "-O2 -V -Msignextend"
    setenv FC pgf90
    setenv LD pgf90
    setenv F90 pgf90
    setenv FFLAGS "-O2"
    setenv CPPFLAGS "-DpgiFortran -D_MSC_VER"
    setenv PGI_OBJSUFFIX "o"
  5. Download the files getopt.c and getopt.h from Add the two files to both ncdump and ncgen directories. The two files are also available from this web site as part of a netCDF zip archive.

  6. Edit ncdump/ncdump.c, ncdump/dumplib.c and ncgen/genlib.c and replace all instances of snprintf with _snprintf.

  7. Edit ncdump/ and add getopt.c and getopt.h to the line starting with ncdump_SOURCES.

  8. Edit ncdump/ and add getopt.$(OBJEXT) to the line starting with am_ncdump_OBJECTS.

  9. Edit ncgen/ and add getopt.c and getopt.h to the line starting with ncgen_SOURCES.

  10. Edit ncgen/ and add getopt.$(OBJEXT) to the line starting with am_ncgen_OBJECTS.

  11. Configure the source code:

    ./configure --enable-shared --prefix=C:/dos/path/to/install/directory
  12. Build the code:

    make >& make.log
  13. Test the build:

    make test >& make_test.log

    Note that some of the ncgen tests fail but the libraries are complete and installable.

  14. Finally, install the results:

    make install

Note the example above uses the csh command "setenv" to set the environment variables. Please change this to match your shell's method of setting environment variables.

The exact optimizations you use should be adjusted depending upon how you compile the applications that will use the netCDF library. If your application is 32-bits and is compiled with -Mcache_align or the aggregate flag -fastsse which contains -Mcache_align, then you must add -Mcache_align or -fastsse to the CFLAGS and FFLAGS. Failure to do so may result in a segmentation violation cause by mismatched data alignment.

Known Issues


The NetCDF build scripts use -bind_at_load which can cause PGI compilers to react poorly. To work around this problem, create or edit a siterc file with these contents:

switch -bind_at_load is replace(-bind_at_load) positional(linker);

Place (or find) the file in $PGI/linux86/2010/bin/siterc and $PGI/linux86-64/2010/bin/siterc or in $PGI/osx86/2010/bin/siterc and $PGI/osx86-64/2010/bin/siterc

Click me