How to build PyNIO from source code

PyNIO can only be built on UNIX systems. It has been successfully built on systems running Linux (32 or 64-bit), MacOSX (PPC or Intel), Windows/Cygwin, Suns using native compilers, IBMs running AIX (32 or 64-bit), and SGIs running IRIX.

This document covers what external software packages you need for PyNIO and how to build them, and then finally how to build PyNIO.

For information on building PyNGL from source code, see the "build PyNGL from source code" document.


Download and build non-optional external software

Once you download and install any external software to use with PyNIO, you must comply with the license of that software, regardless of PyNIO's source code license.

List of external software to install:

  • NCL

    See the full instructions for building NCL from source code. NCL is a difficult package to build, so we recommend going the binary distribution route if possible.

    If you link against a precompiled version of NCL, note that it will probably have GRIB2, HDF-EOS2, and NetCDF4 support enabled, so you will need to build these additional software packages before you build PyNIO from source code.

    Note that many of the instructions for building external software for NCL will also apply for PyNIO, so you don't need to follow these instructions twice. Don't fret if you can't get the "ncl" executable in $NCARG/ni/src/ncl to build; it is not needed by PyNIO. You basically need "libnio.a" and some include files from that directory.

    Make sure the NCARG_ROOT environment variable is set to the root directory of where this software was installed.

  • NetCDF-3 - do not install if you plan to build NetCDF-4 instead.

    Download version 3.6.3 or later. (Do not download version 4.x.x.)

    Once you have the netCDF source code, you can build and install it with:

      ./configure --prefix=/usr/local
      make all install
    

  • JPEG

    Download version 6b or later.

    Once you have the jpeg source code, you can build and install it with:

      ./configure --prefix=/usr/local
      make all install install-lib install-headers
    

  • zlib

    Download version 1.2.3 or later.

    Once you have the zlib source code, you can build and install it with:

      ./configure --prefix=/usr/local
      make all install
    

  • libpng

    Download version 1.2.27 (earlier versions had a serious bug) or later.

    Once you have the libpng source code, build and install it with:

      ./configure  --with-pic --disable-shared --prefix=/usr/local 
      make all install
    

  • HDF-4

    Download version 4.1 or later (do not download version 5.x.y). Important note: Normally the HDF include files get installed to "$prefix/include". Since this will cause some netCDF include files to get overwritten, you must use the "--includedir" option to install the HDF include files to "$prefix/include/hdf" instead.

    For versions older than 4.2r2, make sure the environment variable 'CFLAGS' has -DHAVE_NETCDF included (you can remove it after you are done with this build, but it won't hurt the other builds). For example:

      export CFLAGS="$CFLAGS -DHAVE_NETCDF"
    
    or
      setenv CFLAGS "$CFLAGS -DHAVE_NETCDF"
    
    Then, build and install HDF-4 with:
     ./configure --prefix=/usr/local --with-zlib=/usr/local \
           --with-jpeg=/usr/local --includedir=/usr/local/include/hdf 
      make all install
    
    The paths used for the "--with-zlib" and "--with-jpeg" options must be set to whatever you used above for these two software packages.

    For versions 4.2r2 and higher:

    It's not necessary to alter the 'CFLAGS' environment variable to build this version. Instead, use the --disable-netcdf option:

     ./configure --prefix=/usr/local --with-zlib=/usr/local \
           --with-jpeg=/usr/local --includedir=/usr/local/include/hdf \
           --disable-netcdf
      make all install
    
    Regardless of which version of HDF-4 you download, the paths used for the "--with-zlib" and "--with-jpeg" options must be set to whatever you used above for these two software packages. If you choose to build HDF-4 with the szip compression library, be sure to add "--with-szip=/usr/local" (or whatever location you used when building it) to the configuration process.


    Download and build optional external software, if needed

    Important note: if you are linking against a pre-built version of NCL, it may have the following packages built into its libraries, and hence the following software will not be optional.

  • GRIB2

    If you need support for reading GRIB2 files, then you will need to download and install the following packages:

  • HDF-EOS 2 software

    If you need support for reading HDF-EOS 2 files, then you will need to download and install the following packages:

  • NetCDF-4 - not needed if you don't need classic NetCDF-4 support

    This build will overwrite a NetCDF-3 installation if you have one.

    If you need support for reading/writing classic NetCDF-4 files, then you will need to download and install the following packages:


    Download the source code for PyNIO

    Accessing, downloading, and/or using PyNIO implies acceptance of the PyNIO source code license.

    To download the PyNIO source code, follow the instructions at:

    http://www.pyngl.ucar.edu/Download/
    The source code you download will be a single compressed tar file called something like "PyNIO-1.3.0b1.tar.gz". Move this file to a temporary directory where you have plenty of disk space (around 250 megabytes to hold all of the source code, object files, binaries, and so on). Then, uncompress and untar the file as follows:

      gunzip PyNIO-1.3.0b1.tar.gz
      tar -xvf PyNIO-1.3.0b1.tar
    
    The above steps will create a directory called "PyNIO-1.3.0b1".


    Set environment variables if necessary

    To build PyNIO, you must set the NCARG_ROOT environment variable to the root directory of where NCL was installed.

    Then, depending on what optional packages (GRIB2, NetCDF-4, HDFEOS) you decided to install, you will need to set some environment variables so the PyNIO installation knows about them.

    If you link against a precompiled version of NCL, note that it will probably have GRIB2, HDF-EOS2, and NetCDF4 support enabled. Thus you will need to read the next paragraph about setting certain environment variables to "1", and you will need to build the external software required from source code.

    First, you need to set one or more of the following environment variables to "1" if you build this software package and want to include it in PyNIO:

    setenv HAS_GRIB2 1
    setenv HAS_HDFEOS 1
    setenv HAS_NETCDF4 1
    
    Furthermore, to help PyNIO locate the installed software, you must set the corresponding environment variables to the root directory of that installed software:

    GRIB2_PREFIX
    HDFEOS_PREFIX
    NETCDF4_PREFIX
    
    You only need to set one of these if the paths are all the same.

    Finally, you may need to help the PyNIO installation find the location of any system Fortran libraries needed to resolve symbols between C and Fortran code. For example, "-lgfortran" is needed if you built the software with gfortran, "-lg2c" if g77 was used, and "-lf95" for g95. Use F2CLIBS to indicate the library name (don't include the "-l"), and F2CLIBS_PREFIX to point to the location. For example:

    setenv F2CLIBS gfortran
    setenv F2CLIBS_PREFIX /usr/local/lib
    


    Execute the 'setup.py' script

    Type:
    python setup.py install
    
    to build and install PyNIO. Go back to the "test software" section in the download section for information on testing PyNIO.

    If you have problems, send email to pyngl-talk (you must be a member to post). We will add a trouble-shooting guide once we see what kind of problems people have.