# How to build NCL and NCAR Graphics version 6.5.0 from source code

July 15, 2018

The latest version of this document can be found at http://www.ncl.ucar.edu/Download/build_from_src.shtml.

This is an all-encompassing document on:

- How to set up your environment to build NCL and NCAR Graphics from source code.
- What external software packages you need, which are optional, and how to build them.
- How to build and test NCL and NCAR Graphics.

NCL and NCAR Graphics can only be built on UNIX systems.

> We highly recommend that you install NCL via conda or using a precompiled NCL binary, rather than attempting a build from source code.
> If you tried a precompiled binary and ran into problems, you can email your problem to the ncl-install email list (you must subscribe first).

If you decide to go forth with building from source code, good luck!

Note on building NCAR Graphics only: you have the option during the build process to indicate you do not want to build NCL, effectively building just NCAR Graphics. This simplifies the build somewhat, since you can get by with not having to install most, if any, of the external software packages listed below. If you are already familiar with building NCAR Graphics from source code, then all the instructions you know from before are the same. When you run "./Configure", be sure to answer "n" when it asks if you want to build NCL.

Before you start building NCL/NCAR Graphics, look over this document to see what functionality you want to include. This will help you figure out what packages you'll need and what options they need to be built with. Check if you already have any of these packages on your system and if they were built with the correct options.

Some of the required software libraries may already be on your system. On Linux and Mac systems, you can use a command called "locate" to look for libraries.

        locate libcairo

NCL/NCAR Graphics has been successfully built on 32 and 64 bit Linux systems, Macs (32 or 64 bit) running MacOSX, and Windows running 32-bit Cygwin.

Email ncl-install if you have any problems understanding this document or building any of this software. We've included a troubleshooting section for common problems encountered when building NCL and/or NCAR Graphics.

Note that in the instructions below, "NCL" will sometimes be used to mean both NCL and NCAR Graphics. If something is for NCAR Graphics only, we try to indicate this.

## Table of Contents

- What's new in build instructions since last NCL release
- Visit the Troubleshooting section in advance
- Set up build environment for NCL
  - Compilers needed to build NCL
  - Set environment variables
  - Install X11 developer libraries and include files
- Download and build non-optional external software
  - JPEG (9b)
  - ZLIB (1.2.11)
  - cairo (1.14.12)
    - PNG (1.6.34)
    - pkg-config (0.29.2)
    - FreeType (2.9.1)
    - pixman (0.34.0)
  - NetCDF (4.6.1)
    - szip (2.1.1)
    - HDF-5 (1.10.1)
    - libcurl (7.60.0)
  - HDF-4 (4.2.13)
- Download and build optional external software
  - GRIB2
    - Jasper (1.900.1)
    - g2clib (1.6.0-patch)
  - GDAL/PROJ.4
    - PROJ.4 (5.1.0)
    - GDAL (2.2.4)
  - HDF-EOS 2 (2.20)
  - HDF-EOS 5 (1.16)
  - Triangle
  - UDUNITS-2 (2.2.26)
  - Vis5D+
- Download the source code for NCL
- Customize NCL build environment
  - Test if your system is recognized by NCL build environment
  - Get name of configuration file
  - Modify system configuration file to change default values (may not be necessary)
- Build NCL from source code
  - Run Configure script
    - Special note for Linux systems
    - Special note for MacOSX systems
    - Special note for Windows systems
  - Start the build and install process
  - Check that the installation was successful
- Set up your environment to run NCL and/or NCAR Graphics
- Test the NCL and/or NCAR Graphics installation
- Troubleshooting and known problems
- Appendix A - Modifying configuration files to recognize your system
  - Modify the "ymake" file to recognize your system
  - Set up a configuration file
  - Example configuration file
  - Modify machine-dependent routines
- Appendix B - General information on build process
  - Configuration files
  - Restarting the installation
  - ymake
  - machine-dependent support routines

## What's new in build instructions since last NCL release

The instructions for building haven't changed much since version 5.2.1. Here's what's new about the source code instructions since version 6.0.0 of NCL:

1. The graphical display model has been upgraded, and hence building cairo and some supplemental software is no longer optional.

2. The new ESMF regridding software in NCL uses an application called "ESMF_RegridWeightGen", which is part of the Earth System Modeling Framework. A serial version of this application is included when you download a precompiled NCL binary. If you want to build a parallelized version of this application, then see the Quick Start section of the ESMF User Guide.

3. There are experimental calls to OpenMP code in NCL V6.2.0 and higher; by default the code is compiled with "-fopenmp", but you can remove this option from the appropriate configuration file.

## Set up build environment for NCL

Compilers needed to build NCL

To build NCL, you need a Fortran compiler that can compile both Fortran 77 and 90, an ANSI C compiler, and a C++ compiler. In general, we recommend using the GNU (gcc, gfortran, and g++) compilers, and using version 7.x or higher. For NCL V6.5.0, NCL was built with the GNU and Intel compilers. In the past we have successfully used gcc, gfortran, g95, Intel Fortran/C, and Portland Group. You cannot use g77 as a Fortran compiler.

Set up environment variables for external software

Most of the external software packages that NCL and NCAR Graphics depend on are configured using a "configure" script. These "configure" scripts recognize a number of standard environment variables that allow you to set compilers and compile options.

Decide what compilers and compile options you want to use, and then set the following environment variables as appropriate:

Environment variable name | Description | Example
--- | --- | ---
CC | C compiler | bash/ksh: export CC=gcc csh/tcsh: setenv CC gcc
CFLAGS | C compile flags | bash/ksh: export CFLAGS='-O -ansi -std=c99 -fopenmp -fPIC' export CFLAGS='-O -m64 -ansi -std=c99 -fopenmp -fPIC' csh/tcsh: setenv CFLAGS '-O -ansi -std=c99 -fopenmp -fPIC' setenv CFLAGS '-O -m64 -std=c99 -ansi -fopenmp -fPIC'
FC | Fortran compiler | bash/ksh: export FC=gfortran csh/tcsh: setenv FC gfortran
FFLAGS | Fortran compile flags | bash/ksh: export FFLAGS='-fPIC -fopenmp' csh/tcsh: setenv FFLAGS '-fPIC -fopenmp'
F90 | Fortran 90 compiler | bash/ksh: export FC=gfortran csh/tcsh: setenv FC gfortran
F90FLAGS | Fortran 90 compile flags | bash/ksh: export F90FLAGS='-fPIC -fopenmp' export F90FLAGS='-m64 -fPIC -fopenmp' csh/tcsh: setenv F90FLAGS '-fPIC -fopenmp' setenv F90FLAGS '-m64 -fPIC -fopenmp'
CXX | C++ compiler | bash/ksh: export CXX=g++ csh/tcsh: setenv CXX g++
CXXFLAGS | C++ compile flags | bash/ksh: export CXXFLAGS='-O -ansi -std=c99 -fopenmp -fPIC' export CXXFLAGS='-O -m64 -ansi -fopenmp -fPIC' csh/tcsh: setenv CXXFLAGS '-O -ansi -std=c99 -fopenmp -fPIC' setenv CXXFLAGS '-O -m64 -ansi -std=c99 -fopenmp -fPIC'
CPPFLAGS | preprocessor compile flags | bash/ksh: export CPPFLAGS='-DNDEBUG' csh/tcsh: setenv CXXFLAGS '-DNDEBUG'

Install X11 developer libraries and include files

In order to build some of the X applications that are part of NCL (like idt), you must have some of the X11 developer's libraries installed on your system. At a minimum, you should have the following libraries (and associated include files) installed on your system: X11, Xaw, Xext, Xm, Xmu, Xt.

These libraries are usually installed as part of an X developer's package, and will reside in a directory like /usr/lib, /usr/lib64, /usr/X11R6/lib, or /usr/X11R6/lib64.

For Linux systems, you can get these libraries using a command like one of the following:

       sudo apt-get install x11-dev
       sudo apt-get install xorg-dev
       sudo apt-get install libx11-dev
       yum install libx11-devel

## Download and build non-optional external software

The software listed below is not optional if you plan to build NCL. If you are building NCAR Graphics only, then read the blurb next to each software package name to see if it is needed.

> Once you download and install any external software to use with NCL, you must comply with the license of that software, regardless of what NCL's license is.

Note: it makes things easier if you install all of the external software needed (with the exception of the X11 libraries and X11 include files) to the same parent directory. This will be important later when you have to tell the NCL build system where all the external software has been installed.

We will use /usr/local in all of our examples below for installing external software. You may need to be "root" in order to have permission to install software to /usr/local. If you don't have the "root" password, then you may want to use a directory other than /usr/local, like a directory under your home directory.

You may not need to install all of this software from source code! If you are on a Linux system, you might be able to use "yum" or "apt-get" to download the desired software. On Macs, you might be able to use MacPorts. Under Cygwin, the "setup.exe" program can be used.

Each package is listed below, along with the version we used to build NCL V6.5.0 on our own systems. In most cases you don't need to have the exact version of the software we used, but it's a good idea to match them as much as possible. We've included the "wget" command we used for the retrieving the source code, where applicable.

- JPEG (9b) - not needed if you are only doing an NCAR Graphics build.

  Download version 9b

          wget http://www.ijg.org/files/jpegsr9b.zip

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

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

  You may additionally need do this to install the libraries and include files:

        make install-lib
        make install-headers

- zlib (1.2.11) - not optional, but mostly likely already available on your system

  Download version 1.2.11 or later.

          wget https://zlib.net/zlib-1.2.11.tar.gz

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

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

  cairo software

  Cairo and its supplemental packages may already be on your system (Linux, MacOSX, and Cygwin), so check this before you start building them.

  You can also install many of these packages on Linux systems using a package installer like yum apt-get, or YaST, and on a Mac system using MacPorts. The package(s) to install have names like "libcairo-devel", "libpixman-devel", etc. It is very likely that once you install "libcairo-devel", the other packages will get installed automatically, so check for this before you install all the packages.

  PNG library (1.6.34) - required

  Download version 1.6.x (not 1.4.x or 1.5.x). Version 1.2 will work as well, but we don't recommend this version.

          wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.34.tar.gz

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

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

  - pkg-config (0.29) - Download version 0.29 or later.

            wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.tar.gz

    Once you have the pkg-config source code, you can build and install it with:

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

    Make sure that the location of pkg-config is on your search path and library path. For example, if you installed pkg-config to "/usr/local", then you also need to do the following:

    From tcsh or csh:

          setenv PKG_CONFIG_PATH /usr/local/lib/pkgconfig
          set path=(/usr/local/bin $path)

    From ksh or bash:

          export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
          export PATH=/usr/local/bin:$PATH

    [On a Mac, use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH.]

  - FreeType (2.9.1) - Download version 2.9 or later.

          wget https://sourceforge.net/projects/freetype/files/freetype2/2.9.1/freetype-2.9.1.tar.gz

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

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

  - pixman (0.34.0) - Download version 0.34.x or later.

            wget https://www.cairographics.org/releases/LATEST-pixman-0.34.0

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

    Macs:

          ./configure --prefix=/usr/local --disable-openmp --disable-arm-iwmmxt \
                --disable-dependency-tracking
          make all install

    Linux, MacOS, others:

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

  - cairo (1.14.12) - Download version 1.14.12 or later. Older versions have known bugs.

            wget http://cairographics.org/releases/cairo-1.14.12.tar.xz

    You can't build cairo until you have installed FreeType, pixman, and pkg-config.

    Make sure the "pkg-config" you built is on your search path. For example, if you installed it to /usr/local, then /usr/local/bin needs to be in your search path.

    From tcsh or csh:

          setenv PATH /usr/local/bin:$PATH
          which pkg-config

    From ksh or bash:

          export PATH=/usr/local/bin:$PATH
          which pkg-config

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

          ./configure --prefix=/usr/local --enable-quartz-font=no --enable-quartz=no \
               --enable-shared=no --enable-static=yes
          make all install

- NetCDF - do not install if you are only doing an NCAR Graphics build.

  Download version 4.6.1.

  Note that NetCDF classic (sometimes referred to as NetCDF-3) and NetCDF-4 are different file formats. NetCDF software version 4.x supports both NetCDF-3 and NetCDF-4 file formats, but as noted below, you may have to set some flags in order to get support for both. NetCDF-4 files are actually written as HDF5 under the hood.

  Classic NetCDF-4 is another supported format, which looks like NetCDF-3 files to the user, but they allow for compression for potentially smaller files. Classic NetCDF-4 files cannot be read by programs that only support NetCDF-3.

  NetCDF versions 4.1.x and later support OPenDAP, and this is built in by default. NetCDF 4.1.x also includes the UDUNITS-2 software, but the stand-alone UDUNITS-2 library is more up-to-date so we recommend this over the one that comes with NetCDF. See instructions on building and installing UDUNITS-2.

  This software can be built different ways: with or without "classic" NetCDF-4 support, and with or without OPeNDAP support. Classic NetCDF-4 support gives you file compression capabilities. Full NetCDF-4 support gives you groups, unlimited dimensions, file compression, and compound structures. OPeNDAP support allows you to read NetCDF files served on the web by OPeNDAP servers. We recommend building with at least classic NetCDF-4 support turned on. The instructions below show methods for building classic NetCDF-4 without OPenDAP support, and classic NetCDF-4 with OPenDAP support.

  The NetCDF website has up-to-date intructions for building this software, so we recommend you visit their Getting and building NetCDF page. In particular, you can look at these two methods for building NetCDF:

  1. Building netCDF-4 and the Remote Data Client from source
  2. Building netCDF with Classic Library Only

  The above links include information about where to get the additional software required. We've provided these links below for convenience:

  - zlib - see instructions above.

  - szip - Download version 2.1 or later. (Click on "External Libraries Used By HDF5".)

    The szip 2.x software is available from same page where you download HDF-5. Use this version, rather than the one on the official szip page.

          ./configure --prefix=/usr/local --enable-netcdf-4  --disable-shared
          make all install

  - HDF-5 (1.10.1) - Download version 1.10.x or later.

            wget https://support.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.10.1.tar.gz

          ./configure --with-zlib=/usr/local --with-szlib=/usr/local --prefix=/usr/local
          make all install >& make-output

  - libcurl (7.60.0)

            wget https://curl.haxx.se/download/curl-7.60.0.tar.gz

    Download version 7.60.x or later. Once you have the source code, you can build and install it with:

          ./configure --prefix=/usr/local --with-zlib=/usr/local --with-pic
          make all install >& make-output

- HDF-4 - (4.2.13) if you want to build NCAR Graphics only, then HDF-4 is optional, unless you need HDF support in ctrans, ictrans, and idt.

  Download version 4.2.x or later. (HDF version 5.x.y is a different software package).

          wget https://support.hdfgroup.org/ftp/HDF/HDF_Current/src/hdf-4.2.13.tar

  Note: As of NCL V6.2.0, you no longer need to install the HDF include files to a special directory (in older versions you had to use a special "--includedir" option).

  Build and install HDF-4 with:

       ./configure --prefix=/usr/local --with-zlib=/usr/local \
             --with-jpeg=/usr/local --disable-netcdf
        make all install

  Note: if you are having problems with "make", one user reported that he used "gmake" instead.

  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

Again, as with the above section, it makes things easier if you install all of the external software needed to the same parent directory. We will use /usr/local in all of our examples below for installing external software.

GRIB2 software - not needed if you are only doing an NCAR Graphics build.

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

- Jasper (1.900.1) - Download version 1.900 or later.

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

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

- libpng - see instructions above.

- g2clib - normally you would download this software from http://www.nco.ncep.noaa.gov/pmb/codes/GRIB2/, but there were a few bugs we had to fix. Download the g2clib-1.6.0-patch.tar.gz file instead.

          wget http://www.ncl.ucar.edu/Download/files/g2clib-1.6.0-patch.tar.gz

  Once you have this modified g2clib source code, make changes to "makefile" to:

  1. change the compiler (CC line) and flags (CFLAGS lines)
  2. make sure the DEFS line has both "-DUSE_JPEG2000" and "-DUSE_PNG"
  3. if on a 64-bit system (x86_64, ia64, etc), make sure the DEFS line also has "-D__64BIT__" (that's two underscores before and after)
  4. add the appropriate location of the Jasper/libpng include files to the "INC" line

  Now type:

        make all
        mv libgrib2c.a /usr/local/lib
        cp grib2.h /usr/local/include

GDAL/PROJ.4 software - not needed if you are only doing an NCAR Graphics build.

If you need support for reading shapefile, mapinfo, TIGER, etc, file formats, then you will need to download and install the following two packages.

- PROJ.4 (5.1.0) - Cartographic Projections Library - Download version 5.x or later.

          wget http://download.osgeo.org/proj/proj-5.1.0.tar.gz

  Once you have the PROJ.4 source code, you can build and install it with:

        ./configure --prefix=/usr/local --enable-static=yes --enable-shared=no
        make all install

- GDAL (2.2.4) - Geospatial Data Abstraction Library - Download version 2.2.x or later.

          wget http://download.osgeo.org/gdal/2.2.4/gdal-2.2.4.tar.gz

  Important note about GDAL: this software contains its own versions of the GRIB2 library (g2clib) and the HDF4/HDF5 libraries. It's important that you do NOT compile these versions of the libraries, but rather the ones as instructed elsewhere on this page. To turn off the build of these libraries inside of the GDAL software requires including several "--without-xxxx" options:

        ./configure --with-static-proj4=/usr/local --prefix=/usr/local --without-pam
            --with-png=/usr/local --with-gif=internal --with-libtiff=internal
            --with-geotiff=internal --with-jpeg=/usr/local --with-libz=/usr/local
            --with-sqlite3=no --with-expat=no --with-curl=no --without-ld-shared
            --with-hdf4=no --with-hdf5=no --with-pg=no --without-grib --disable-shared
            --with-freexl=no --with-geos=no --with-openjpeg=no --with-mysql=no
            --with-ecw=no --with-fgdb=no --with-odbc=no --with-xml2=no --with-ogdi=no
            --with-pcraster=no --with-xerces=no

        make all install

HDF-EOS 2 software - not needed if you are only doing an NCAR Graphics build.

        wget ftp://edhs1.gsfc.nasa.gov/edhs/hdfeos/latest_release/HDF-EOS2.20v1.00.tar.Z

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

- HDF-EOS 2 (2.20) - Download version 2.20 or later.

  Once you have the HDF-EOS 2 source code, you can build and install it with:

          ./configure CC=/usr/local/bin/h4cc --with-hdf4=/usr/local --with-zlib=/usr/local --with-jpeg=/usr/local --prefix=/usr/local

HDF-EOS 5 software - not needed if you are only doing an NCAR Graphics build.

        wget ftp://edhs1.gsfc.nasa.gov/edhs/hdfeos5/latest_release/HDF-EOS5.1.16.tar.Z

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

- szip - see instructions above.

- HDF5 - see instructions above.

- HDF-EOS 5 (1.16) - Download version 1.16 or later.

  Once you have the HDF-EOS 5 source code, you can build and install it with:

        ./configure CC=/usr/local/bin/h5cc --with-hdf5=/usr/local --with-zlib=/usr/local
             --with-szlib=/usr/local --prefix=/usr/local
        make all install

  Note that if you have settings in your CFLAGS, you can include these by enclosing them with '':

        ./configure CC=/usr/local/bin/h5cc --with-hdf5=/usr/local --with-zlib=/usr/local
             --with-szlib=/usr/local --prefix=/usr/local
        make all install

  You may also have to hand-copy two include files:

        cp include/HE5_GctpFunc.h include/HE5_HdfEosDef.h /usr/local/include/.

Triangle software - not needed if you are only doing an NCAR Graphics build.

If you need to use the Triangle code (for generating triangular meshes that you can contour), then you will need to download the source code, and copy over only the files "triangle.c" and "triangle.h" to the $NCL/ni/src/lib/hlu directory in the NCL source tree (you may not have downloaded the NCL source code yet, so wait until you get to this part to copy over the two files).

Note that Triangle has a more restrictive license than NCL's license which disallows you from selling any source code or product that contains Triangle. If you build NCL with Triangle included, you will be bound by Triangle's license.

UDUNITS-2 (2.2.26) - not needed if you are only doing an NCAR Graphics build.

Download the Udunits 2.x (not 1.x!) source code.

        wget ftp://ftp.unidata.ucar.edu/pub/udunits/udunits-2.2.26.tar.gz

If you need the conversion functions ut_calendar and ut_inv_calendar, then you need to install UDUNITS-2.

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

      setenv PERL ""                    # export PERL=""
      ./configure --prefix=/usr/local
      make all install >& make-output

Setting the PERL environment variable to an empty string prevents the perl interface from being built, which is not needed for NCL.

Vis5D+ software (1.3.0-beta) - not needed if you are only doing an NCAR Graphics build.

If you need to use any of the v5d_xxx functions (see the "V" section of the NCL function list), then you need to install Vis5d+.

Download the vis5d+ source code. We used 1.3.0-beta. Once you have the source code, you can build and install it with:

      ./configure --prefix=/usr/local --with-netcdf=/usr/local/lib/libnetcdf.a
      make all install >& make-output

## Download the source code for NCL

Accessing, downloading, and/or using NCL implies acceptance of NCL source code license, which is based on the OSI Apache License, Version 2.0 license.

To download the NCL source code, follow the instructions at the URL:

> http://www.ncl.ucar.edu/Download/

The NCL source code you download will be a single compressed tar file (we'll call it "ncl_ncarg-6.5.0.tar.gz"). Move the "ncl_ncarg-6.5.0.tar.gz" file to a temporary directory where you have plenty of disk space (around 850 megabytes to hold all of the source code, object files, binaries, and so on). Then, uncompress and untar the file as follows:

      tar -zxvf ncl_ncarg-6.5.0.tar.gz

The above steps will create a directory called "ncl_ncarg-6.5.0". For convenience, we'll use the notation $NCARG to mean the top level of the NCL/NCAR Graphics source tree. Set the environment variable NCARG to the full path of this directory. For example, if you untarred the files from the directory /usr/local/src, then you would do one of the following: From tcsh or csh:

      setenv NCARG /usr/local/src/ncl_ncarg-6.5.0

From ksh or bash:

      export NCARG=/usr/local/src/ncl_ncarg-6.5.0

sh:

      NCARG=/usr/local/src/ncl_ncarg-6.5.0
      export NCARG

Be sure to see the troubleshooting section below for any known problems or tips.

## Customize NCL build environment

- Test if your system is recognized by NCL build environment

  Before you try to build NCL, you need to quickly check if your system will be recognized by the NCL build environment. Type:

        cd $NCARG/config
        make -f Makefile.ini
        ./ymake -config `pwd`

  (Note that the ticks around "pwd" are back ticks.)

  If no output is echoed to the screen, then this means your system is recognized by the NCL build environment. Go to the very next section, "Get name of configuration file."

  If, however, you get a message:

      ymake: system unknown

  then go to Appendix A for information on modifying some files in the $NCARG/config directory so they recognize your system. Then you can come back to this section.

- Get name of configuration file

  If no output is echoed to the screen from the "ymake" command in the previous section, then this most likely means that the NCL build environment recognizes your system. Just to be certain, you can check the name of the configuration file that the NCL build is going to use by typing (in the same directory):

        grep SYSTEM_INCLUDE Makefile

  This should echo something like:

      SYSTEM_INCLUDE          = "Darwin"

  which means "Darwin" is the name of the configuration file it will use in the $NCARG/config directory.

- Modify system configuration file to change default values

  Now that you have the name of the configuration file that's going to be used in the "$NCARG/config" directory, you may need to edit this file and make changes to it. The "README" in the same directory has a description of some available configuration files that you can copy from.

  When modifying your configuration file, pay particular attention to how the following macros are being set:

  CCompiler | The C compiler
  FCompiler | The Fortran compiler
  CcOptions | C compiler options (besides the optimize flag)
  FcOptions | Fortran compiler options (besides the optimize flag)
  COptimizeFlag | C optimize flag(s) (the default is "-O")
  FOptimizeFlag | Fortran optimize flag(s) (the default is "-O")
  ExtraSysLibraries | Extra system libraries that might be needed to get executables to link
  CtoFLibraries | Extra Fortran libraries that might be needed to get executables to link ("-lgfortran" is one example, if you are using the gfortran Fortran compiler)
  NgCallF | The macro for handling how Fortran routine names are named in the library.

  and change or add them as desired.

  If you don't see these macros being defined in your system configuration file, then that means that the default value, which is defined in the $NCARG/config/Template file, is being used. To change the default, just add it to your system configuration file with the new value.

  For example, on LINUX systems, the default C and Fortran compilers are "gcc" and "gfortran". If you want to change this to "icc" and "ifort", then modify the file $NCARG/config/LINUX, and add the line:

      #define CCompiler  icc
      #define FCompiler  ifort

  along with the other macro definitions.

## Build NCL from source code

In order to build NCL from source, you must have a Fortran compiler that can compile both Fortran 77 and 90 code, and an ANSI C compiler.

Here are the general steps for building NCL from source:

1. Run Configure script
2. Start the build and install process
3. Check that the installation was successful
4. Set up your environment to use NCL
5. Test the NCL and/or NCAR Graphics installation

## Run Configure script

Before you build and install NCL, you need to run a script called "Configure" to answer several questions about where you want the software installed, what optional software you want to include, and the location of the optional software.

Enter the following commands to run this script:

      cd $NCARG
      ./Configure  -v

If Configure doesn't recognize your system, it will quit right away with an error message. Otherwise, it will start asking you several questions.

If it quits with an error message that indicates it doesn't recognize your system, then read and follow the instructions in the section on Test if your system is recognized by the NCL build environment before running Configure again.

If Configure does recognize your system, then answer all of the questions about where you want the software installed, whether you want support for HDF4-EOS, HDF5-EOS, cairo, etc, and so on.

One of the final questions is to list the paths to your local libraries and include files. It's important to include the paths to the external software you want support for, like cairo, HDF-EOS5, GRIB2, etc.

Be sure to include the path to the freetype include files, which will be in a directory like "/usr/local/include/freetype2".

Once you have finished running Configure, you should get a message indicating that the configuration process is complete, and that you can start building and installing the software. First verify that you have the correct compilers, options, and paths by typing:

        make Info

If everything looks okay, then you can skip the next few sections and go directly to "Start the build and install process."

If the installation paths look wrong, then rerun Configure and reenter the installation paths.

If something else looks wrong, like the name of the compilers or the compiler options listed, then go back to the section "Modify system configuration file to change default values", or read the next few sections on notes for specific systems.

Special note for Linux systems

The default configuration file for Linux is "LINUX". You need to edit this file for i386, i686, x86_64, and ia64 systems. There are several LINUX.xxxx sample configuration files to help you modify this file for your purpose. Also, see the "README" file in the "config" directory for more information.

If you are using the "gcc" and "gfortran" compilers to build NCL, then you will need to include something like:

    #define CtoFLibraries   -lgfortran

in the $NCARG/config/LINUX file. You may also need to indicate the path to the gfortran library with the -L option:

    #define CtoFLibraries -L/usr/local/lib -lgfortran

"/usr/local/lib" is just an example. You will need to find "libgfortran.so" or "libgfortran.a" on your system and use this path.

If you are using "gcc" and "g95" to compile NCL, then you need to do the same thing, except use "-lf95" in place of "-lgfortran". Ditto for if you are using the Intel compilers "icc" and "ifort", you may need "-lifcore".

Special note for MacOSX systems

The default file for an Intel MacOSX system is "Darwin_Intel". If "uname -m" reports "i386" or "x86_64" on your system, then this is the file you want to modify.

The default configuration file for a PPC MacOSX system is "Darwin". If "uname -m" reports "Power Macintosh", then this is the file you want to modify.

There are are other Darwin.xxxx and Darwin_Intel.xxxx sample configuration files. You can use any one of these to help you modify Darwin or Darwin_Intel for your purpose.

If you have an Intel Mac running MacOS 10.6 or later, then your Mac is probably 64-bit, and you need to copy the "Darwin_Intel.64" file to "Darwin_Intel" and modify it as necessary.

To build NCL on an MacOSX system, you must first install a few supplemental packages:

1. MacOSX Developer Tools (Xcode)

   This is usually available on one of the installer CDs that came with your Mac. Or, if you have a "/Developers/Tools" directory, cd to that directory and search for a PDF file that will contain instructions on how to install the Developer's Tools.

   If you don't have the directory or the CD, you can get this software from the http://connect.apple.com site. (You may need to create an account with them first.) Once you are logged in, click on "Download Software", and then "Mac OS X". You should then see a link for downloading the Developer's Tools.

2. MacPorts

   MacPorts supplies a program called "port", which is a highly useful application for easily downloading software for Macs. (See next section on how to install gfortran.)

3. GNU fortran compiler (gfortran)

   If you don't have a Fortran compiler, then you can try using the MacPorts command "port" to get one. Type something like:

           port install gfortran

   If this fails, you can use the "list" command to see what gfortran packages are available:

           port list gfortran

   If "port" doesn't work, then you can download and install precompiled MacOSX compilers from the HPC website, the gcc/gfortran binaries wiki or the g95 website.

4. X11 server

   An X11 server will enable you to display NCL graphical output to your screen. We recommend that you use Apple's X11 server, which should already be installed on your Mac, or may be available on one of your installation CDs.

NCL will build on a MacOSX system using the GNU compilers. It may build using different compilers, but we've only lately used gcc and gfortran.

Be sure to see the "Running NCL under MacOSX" document for more notes.

Special note for Windows systems

Before you can build any software on a Windows system running Cygwin, you need to install a number of software packages via the "setup-x86.exe" X/Cygwin program. See the "Installing NCL under Windows/Cygwin/X" page for a full description of what you need and how to download it.

## Start the build and install process

Once you've run "Configure", and "make Info" gives you the correct information, you can initiate the build and install process by typing:

        cd $NCARG
        make Everything  >&  make-output  &

Be patient; this can take from thirty minutes to a few hours depending on your machine and its current load. During the installation, you may examine the contents of the make-output file with the command:

        tail  -f  make-output

If you encounter errors during the build process, you can restart without losing any of the work already accomplished. Refer to the section "Restarting the installation" for details about recovering from errors that occur during installation.

## Check that the installation was successful

To test that your build of NCL was successful, test the list of files installed on your system against the master list of NCL/NCAR Graphics files. If you just built and installed NCAR Graphics, then check your files against this smaller list of NCAR Graphics files.

If it looks like not all the files were installed, then take a look at the make-output file, and check for words like "fatal" or "error". Don't worry too much about warnings, unless they are followed by errors.

If you find an error, try to determine the nature of the error, make any necessary adjustments, and either start the build from scratch or from where it left off.

If the nature of the error appears to be something like an option not being included on every compile line, then you need to change the system configuration file in $NCARG/config, add the necessary option(s), and restart the build from scratch (using a different output file):

        cd $NCARG
        make Everything >& make-output.2

If the nature of the error is such that you just need to tweak a particular file or Makefile somewhere in the NCL/NCARG Graphics source tree, then cd to the problem directory, make the change, and then type the following to recompile the local change (to make sure your change was successful) and start the build from where it left off:

        make me
        make includes depend all install
        cd $NCARG
        make all install >>& make-output

See Appendix B for more information on editing configuration files and restarting the installation.

## Set up your environment to use NCL and/or NCAR Graphics

Once the build process is complete, you need to do the following before you can start using NCL or NCAR Graphics:

1. Set the environment variable NCARG_ROOT to the parent directory of where you installed everything.
2. Make sure "$NCARG_ROOT/bin" is on your search path.
3. Make sure "$NCARG_ROOT/man" is on your man path.
4. Copy a .hluresfile to your home directory (NCL only).

Here's an example (using csh) that assumes you installed everything to the parent directory /usr/local:

        setenv   NCARG_ROOT   /usr/local

        setenv   PATH      $NCARG_ROOT/bin:$PATH

        setenv   MANPATH   $NCARG_ROOT/man:$MANPATH

Here's an example for bash or ksh:

        export NCARG_ROOT=/usr/local

        export PATH=$NCARG_ROOT/bin:$PATH

        export MANPATH=$NCARG_ROOT/man:$MANPATH

## Test the NCL and/or NCAR Graphics installation

You can quickly test if NCL is installed properly by typing "ncl" with the "-V" option to get the version, and then running a quick program:

        ncl -V
        ng4ex gsun01n

The ng4ex command will copy an NCL script called gsun01n.ncl into your current working directory, and run it with NCL. An X11 window should pop up with an XY plot drawn on it. Click on this plot with your left mouse button to keep advancing to the next frame.

Once this file is in your directory, you can also run it yourself with:

        ncl gsun01n.ncl

If "ncl" seems to be working, then this indicates that your build of NCAR Graphics was at least mostly successful, since NCL depends on the NCAR Graphics libraries.

To test NCAR Graphics only, there's an extensive suite of examples available. You should refer to the NCAR Graphics Fundamentals. It will show you how to run examples and test programs, and how to view the resulting graphics. Using the ncargex and ctrans programs is the easiest way to test the installation and become familiar with the use of NCAR Graphics.

For a quick test, try the following:

        ncargex cpex08
        ctrans -d X11 cpex08.ncgm

The first command will copy a file called cpex08.f into your current working directory, compile, link, and execute it, and create a graphics file called cpex08.ncgm. The second command will display the graphic on an X11 window on your screen. You must have your DISPLAY environment variable set correctly for this command to work. Left-click on the X11 window to make the graphic go away.

# Troubleshooting and known problems

This section is for people trying to build NCL/NCAR Graphics from source code. Many of these instructions apply to older versions of the source code, and may not be needed for versions 5.1.x and higher.

1. We've had problems building some of the supplemental code (the fontcaps, for one) for NCL using the Intel icc/ifort compilers, and had to use gcc/gfortran instead.

   If you still want to try the icc/ifort compilers, and "icc" can't find the "ifcore" library, then you may need to include a "-L" option that includes the path to this library in your configuration file in $NCARG/config.

   For example, if you are on a LINUX system and "libifcore.{a.so}" is in /opt/intel/fc/10.1.013/lib, then edit $NCARG/config/LINUX and change the CtoFLibraries line to have:

       #define CtoFLibraries   -lm -L/opt/intel/fc/10.1.013/lib -lifcore

2. If you get the following errors when building the code in the $NCARG/ni/src/ncl directory:

       cp lex.yy.c scanner.c
       gcc -ansi  -g  -I../../.././include -I/Users/fredclare/include -I/
       Users/fredclare/include/hdf -I/usr/X11R6/include -I/sw/include -I/usr/
       X11R6/include/X11  -DDarwin -DMAJOR=9       -DSYSV -D_POSIX_SOURCE -
       D_XOPEN_SOURCE -DByteSwapped -DNeedFuncProto    -c -o scanner.o scanner.c
       lex.yy.c: In function ~Qyy_get_next_buffer~R:
       lex.yy.c:2099: error: ~Qyy_current_buffer~R undeclared (first use in this
       function)
       lex.yy.c:2099: error: (Each undeclared identifier is reported only once
       lex.yy.c:2099: error: for each function it appears in.)
       make: *** [scanner.o] Error 1

   then your problem may be with flex. You can try our version of flex. Download the flex.tar.gz file, and then do the following to build a new flex:

          gzcat flex.tar.gz | tar -xf -
          cd flex-2.5.3
          ./configure

   This should create a "flex" executable. Move this executable to somewhere that's on your search path already (like maybe $NCARG_ROOT/bin). Make sure that you are getting this flex and not the system one by typing:

           rehash
           which flex

   A user reported that he had trouble compiling flex with "gcc -O2", but that it worked with the Intel "icc" compiler, using "icc -O0 -g". He didn't try "gcc -O0", which you may want to try if flex is core dumping.

   Now, you can test if the "ncl" executable will build:

          cd $NCARG/ni/src/ncl
          make clean includes depend all install

   If the file "ncl" builds, then you can start your build from where it left off with:

          cd $NCARG
          make all install >>& make-output &

   Of course, you can send the output from "make" to whatever file you like.

3. If you get the following errors when you try to compile a Fortran or C NCAR Graphics program:

        /usr/local/ncarg/lib/libncarg_gks.a(gziqwk.o): In function `gziqwk_':
        gziqwk.f:(.text+0x187): undefined reference to `ggkwdr_'
        /usr/local/ncarg/lib/libncarg_gks.a(gztowk.o): In function `gztowk_':
        gztowk.f:(.text+0x295): undefined reference to `ggkwdr_'
        gztowk.f:(.text+0x7d7): undefined reference to `ggkwdr_'
        gztowk.f:(.text+0xc30): undefined reference to `ggkwdr_'

   then try this:

          cd $NCARG/ncarg2d/src/libncarg_gks
          rm awi/ggkwdr_stub.o
          make all install

4. If you are seeing errors in your compilation that mention "conflicting types for wchar_t", then add:

        -D__UNIXOS2__

   (those are two double underscores on the front and the end) to the "StdDefines" line in your configuration file in $NCARG/config (most likely the LINUX or one of the Darwin files in that directory), and rerun "make Everything".

# Appendix A - Modify configuration files to recognize your system

You only need to read this section if $NCARG/ymake did not recognize your system. (We'll refer to this as an unsupported system.) If the Configure script recognized your system, then skip to the section "Modify system configuration file to change default values".

The three steps you'll need to follow before building NCL on an unsupported system are:

1. Modify the "ymake" file to recognize your system.
2. Set up a configuration file.
3. Modify machine-dependent routines (if necessary).

Once you've completed these three steps, then you need to run the Configure script again as described in the "Run Configure script" section.

1. Modify the "ymake" file to recognize your system

For the first step, modify the file $NCARG/config/ymake and go to the lines that read:

        #   Figure out what kind of system we are on. We need to know the OS
        #   and the machine architecture.

Notice that the UNIX command "uname" is used to determine the architecture type and operating system name. Once you figure out what the various options that uname reports on your system, add your machine architecture and operating system names to the case statements that follow in the same manner as the other systems are done. You also need to come up with a name for your configuration file. This is the value you'll give to the "sysincs" variable. An example will be provided below after step 2.

2. Set up a configuration file

For the second step, cd to $NCARG/config and prepare a configuration file for your system that has the same name you used for the "sysincs" variable in the ymake file. Use one of the existing configuration files as a foundation (for example, "Sun4Solaris"). You will notice several macros being defined in the configuration file. You only need to define a macro if you want it to be something different than what is defined in the "Template" file. The Template file is where all the default values are set. For example, the default Fortran compiler is set to "f77" in the Template file. If your Fortran compiler is called "gfortran", then you would add the following line to your configuration file:

        #define    FCompiler       gfortran

To see what other macros are available and what the default values are set to, see the Template file. In particular, you may need to change the following macros:

        CCompiler
        FCompiler
        ExtraSysLibraries
        CcOptions
        FcOptions
        NgCallF

Example on how to modify ymake file and set up configuration file

As an example for the first two steps, suppose you are trying to build a configuration file for a Koblinsky Systems Inc. SlothStation running ChaOS version 5.4. Assume that the command "uname -s" returns "ChaOS" and that "uname -m" returns "Sloth999". Modify the file $NCARG/config/ymake and add:

        case  ChaOS:

right after the first occurrence of the statement:

        switch ("$foo")

You should now see something like:

        switch ("$foo")
        case  ChaOS:
        case  SunOS:
        case  AIX:
        ...

Then, after the first occurrence of the statement:

        switch("$opsys")

add the lines:

        case  ChaOS:
            set  os      = $opsys
            set  arch    = $mach
            set  sysincs = Sloth
            set  vendor  = Koblinsky
        breaksw

and after the second occurrence add:

        case  ChaOS:

where appropriate to get the correct major and minor operating system version numbers defined.

Let's further assume that this system is similar to a Sun workstation running Solaris, so use the Sun4Solaris configuration file as a foundation:

        cd  $NCARG/config
        cp  Sun4Solaris  Sloth

The file name "Sloth" is used because this is the value we gave to the "sysincs" variable above. Make any obvious changes to the file "Sloth". As mentioned above, you may need to change the following macros:

        CCompiler
        FCompiler
        ExtraSysLibraries
        CcOptions
        FcOptions
        NgCallF

Of particular note is the "NgCallF" macro. First, a little background: the NCL code is predominantly Fortran code, but the Fortran code relies on a number of C support routines. Since not all systems support the same calling conventions (for example, some systems require an underscore after a Fortran routine name, while others require the name to be in uppercase), the installation system is programmed to apply the macro "NgCallF" to all Fortran-called C code.

The default value of this macro handles the case where an underscore is appended after the Fortran routine name, so you won't need to define this macro if this is the behavior of your compiler. If, however, your compiler does not append an underscore (the IBM xlf/xlf90 compilers are two such examples), then you need to set this macro as follows:

        NgCallF  reg

If your compiler converts the Fortran routine name to uppercase (this is the case with old Cray and the Absoft ProFortran compilers), then you need to set the macro to:

        NgCallF  caps

3. Modify machine-dependent routines

There are some machine dependent routines that you may need to modify to indicate things like the standard input/output units, the number of bits per integer, the smallest positive magnitude, and so on. All of these machine-dependent requirements have been isolated in several subroutines and it may be necessary to modify these subroutines before building the software.

The routines in question are:

        GBYTES  ISHIFT
        G01MIO  I1MACH
        IAND    R1MACH
        IOR     SBYTES

These routines are referred to as "low-level support routines" in the remainder of this section. Complete functional descriptions for these routines appear in the section "Machine-dependent support routines". Examples of implementations of all of these subroutines except G01MIO are given in the directory:

> $NCARG/common/src/libncarg_c

A Fortran implementation of the support routine G01MIO is contained in the directory:

> $NCARG/ncarg2d/src/libncarg_gks/bwi

G01MIO is the basic I/O routine for NCAR's GKS package, and it is not used anywhere else but in that package.

The subroutines in the above two directories are examples only. These examples may help you, and some may actually run on your machine, but care must be taken to ensure that the implemented routines satisfy the functional descriptions as given in the "Machine-dependent support routines" section. Some of the examples given are coded in C.

There is source code for creating an executable for testing implementations of the low-level routines in the directory:

> $NCARG/ncarg2d/src/bin/impltest

The source in this directory may require changes only when moving to a machine with a word size other than 32 or 64.

This directory contains a program called "tlocal" that can be used to test the implementations of IOR, IAND, ISHIFT, GBYTES, and SBYTES. Read the prologue documentation in the code for tlocal for implementation instructions. Success or failure messages will be issued to Fortran unit 6. There are no tests for I1MACH and R1MACH, but the success of the tlocal test depends on proper implementation of I1MACH and R1MACH. Constants for I1MACH and R1MACH for a large number of computers appear in the comment cards of I1MACH and R1MACH. If constants for your host computer appear there, simply uncomment the appropriate cards for your implementation of I1MACH and R1MACH. Otherwise be very careful to implement I1MACH and R1MACH correctly since there is no test for them. The support routine G01MIO is used only by NCAR's GKS package, and no test for it is provided in tlocal.

Since many of the low-level support routines are executed frequently throughout the package, efficient versions are desirable. There are portable Fortran versions of GBYTES and SBYTES in the directory:

> $NCARG/common/src/libncarg_c

but they run very slowly. GBYTES and SBYTES are used primarily in the NCGM translator; machine-language versions of these routines could greatly speed up the translator. Machine-language versions of IAND, IOR, and ISHIFT are also desirable.

# Appendix B - General information on build process

This section contains general information on building NCL that you may find useful. It includes information on:

- configuration files
- how to restart the installation if it bombs
- the ymake system
- machine-dependent support routines

### Configuration files

Configuration files contain make macros. At installation time, these macros are used by ymake to construct all of the Makefiles for building NCL and NCAR Graphics. Any change you make in your configuration file will cause a change in your Makefile(s), if you run something like "make Everything", "make Makefiles", or "make me" to regenerate the Makefile(s). Refer to the "ymake" section for more information.

Configuration files reside in the directory $NCARG/config. They have names like "LINUX" and "Darwin_Intel" to indicate the machine on which they operate. For example, If you are on any kind of system running LINUX, you should make changes to the file $NCARG/config/LINUX. See the "README" file in this directory for more information about the various configuration files.

A few of the macros are quite likely to change from system to system, but most are not. The Configure script allows the installer to make some of these minor changes to the configuration file without editing it. You must be running csh in order to run Configure.

### Restarting the installation

The standard build process is initiated by telling make to build the "Everything" target, which results in a series of actions. First, a hierarchy of Makefiles is constructed, based on your system configuration. Next, all old object code is removed, dependencies are created, and then compilation, the most time-consuming step, begins. Finally, libraries and executables are built and then installed. This can take from thirty minutes to a few hours. If you encounter an error along the way, it is very important that you avoid wasting the work that has already been done. There are other targets besides "Everything". The following targets may be used to gracefully restart the installation process:

        Everything = (Makefiles, clean, all, install)
        All        = (Makefiles, all, install)
        all        = (compile and build libraries)
        install    = (move objects to destinations)
        clean      = (remove object files, core dumps, etc.)

If a compilation fails halfway through the install process and you have already created the Makefiles, cleaned out old object code, and compiled a large number of files, you may first correct the problem and then restart the install process. To correct the problem, you need to first look carefully at the error message in the make-output file. By looking at the last several lines of the make-output file, you should be able to determine which directory the make stopped in. For example, let's say see the following in your make-output file:

    ...
    Making ./ncarview/src/lib/libncarg_ras
    cc -Xc  -O  -I../../../.././include -I/usr/openwin/include -I/usr/dt/include   -DBuildRasterHDF -DSUN -DBuildRasterHPPCL -DBuildRasterNrif -DBuildRasterSun  -DBuildRasterXWD  -DBuildRasterAVS -DBuildRasterSGI  -DBuildRasterAbekas  -DBuildRasterBinary -DBuildRasterYUV  -DNGTMPDIR='"tmp"' -Dsun4 -DSUN -DSYSV -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__ -DNeedFuncProto   -c  raster.c
    cc -Xc  -O  -I../../../.././include -I/usr/openwin/include -I/usr/dt/include   -DBuildRasterHDF -DSUN -DBuildRasterHPPCL -DBuildRasterNrif -DBuildRasterSun  -DBuildRasterXWD  -DBuildRasterAVS -DBuildRasterSGI  -DBuildRasterAbekas  -DBuildRasterBinary -DBuildRasterYUV  -DNGTMPDIR='"tmp"' -Dsun4 -DSUN -DSYSV -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__ -DNeedFuncProto   -c  hdf.c
    "hdf.c", line 44: cannot find include file: <hdf/hdf.h>
    "hdf.c", line 45: cannot find include file: <hdf/dfgr.h>
    "hdf.c", line 192: cannot recover from previous errors
    cc: acomp failed for hdf.c
    *** Error code 2
    make: Fatal error: Command failed for target `hdf.o'

You can see from the:

        Making ./ncarview/src/lib/libncarg_ras

line that the make bombed in the directory "ncarview/src/lib/libncarg_ras". The error message here indicates that it can't find the HDF include files. To fix this problem, then, you would need to do one of three things:

1. Install HDF on your system (see the section "Download the source code or binaries for HDF"), and then also follow step #2.
2. If HDF is already installed on your system, run "Configure" and include the paths to HDF when it asks for local library and include directory search paths.
3. Run "Configure" and answer no to the question: "Build HDF support into raster library?".

In most cases, the fix just involves modifying source files and recompiling. If this is the case, then after you fix the source file(s), you can restart the install process by typing:

        cd $NCARG
        make all install >& make-output &

In our example above with the HDF software, the fix involved something that would affect the Makefiles. In this case, then, you need to regenerate the Makefiles. To do this, type:

        cd $NCARG
        make All >& make-output &

### ymake

A utility named "ymake" is used by this package to generate the Makefile hierarchy.

A file named yMakefile exists in each directory and is converted to a regular Makefile using the C preprocessor and a collection of general and system-specific macros. The ymake system resides in $NCARG/config. This allows the redundant information in each Makefile to be isolated, in addition to providing Makefile conditionals. The C preprocessor knows what system it is running on. (The same technique is being employed in other systems, including MIT's X Window System.) If you need to change a Makefile, implement the changes in the yMakefile and then type:

        make me

If you completely destroy a Makefile, you can usually recover by typing:

> $NCARG/config/ymkmf

There is more information about ymake in the ymake man page which resides in the directory $NCARG/config.

### Machine-dependent support routines

Following are functional descriptions of the required locally-implemented support routines. A test suite is distributed for this package so that an implementor may verify that the implementations are correct. The routine G01MIO is needed only if the NCAR GKS package is being implemented.

FUNCTION I1MACH(I)

This function is used to set up 16 machine constants.

> I1MACH(1) = the standard input unit
> I1MACH(2) = the standard output unit
> I1MACH(3) = the standard punch unit
> I1MACH(4) = the standard error message unit
> I1MACH(5) = the number of bits per integer storage unit
> I1MACH(6) = the number of characters per integer storage unit

Assume that integers are represented in the S-digit, base-A form:

> SIGN*(X(S-1)*A**(S-1)+...+X(1)*A+X(0))

in which 0 .LT. X(I) .LT. A for I=0,...,S-1.

> I1MACH(7) = A, the base
> I1MACH(8) = S, the number of base-A digits
> I1MACH(9) = A**S-1, the largest magnitude

Assume that floating-point numbers are represented in the T-digit, base-B form:

> SIGN*(B**E)*((X(1)/B+...+(X(T)/B**T))

in which 0 .LT. X(1), and EMIN .LE. E .LE. EMAX.

> I1MACH(10) = B, the base

Single-precision constants

> I1MACH(11) = T, the number of base-B digits
> I1MACH(12) = EMIN, the smallest exponent E
> I1MACH(13) = EMAX, the largest exponent E

Double-precision constants

> I1MACH(14) = T, the number of base-B digits
> I1MACH(15) = EMIN, the smallest exponent E
> I1MACH(16) = EMAX, the largest exponent E

FUNCTION R1MACH(I)

This function sets five single-precision machine constants:

> R1MACH(1) = B**(EMIN-1), the smallest positive magnitude
> R1MACH(2) = B**EMAX*(1-B**(-T)), the largest magnitude
> R1MACH(3) = B**(-T), the smallest relative spacing
> R1MACH(4) = B**(1-T), the largest relative spacing
> R1MACH(5) = LOG10(B)

FUNCTION ISHIFT(IWORD,N)

IWORD is shifted by N bits. If N > 0, a left circular shift is performed (all bits are shifted left N bits, and the bits that are shifted out of the word to the left are shifted back into the word at the right). If N < 0, a right end-off shift is performed (all bits are shifted right by N bits, and the bits that are shifted out of the right of the word are lost)-if the leftmost bit is 0, then the vacated positions are filled with zeros; if the leftmost bit is 1, then the vacated positions are undefined. The implementor may assume that IABS(N) .LE. word_length.

FUNCTION IAND(K1,K2)

The bit-by-bit logical product of K1 and K2. If K3 = IAND(K1,K2), then the nth bit of K3 is 0 if the nth bit of either K1 or K2 is 0; otherwise the nth bit of K3 is 1. FUNCTION IOR(K1,K2) The bit-by-bit logical sum of K1 and K2. If K3 = IOR(K1,K2), then the nth bit of K3 is 0 if and only if the nth bit of both K1 and K2 is 0.

SUBROUTINE G01MIO(IOP,IUNIT,FNAME,IBUFF,LENGTH,IERROR)

This output routine is the central one for the metafile generator. A Fortran implementation of this subroutine is in the directory:

> $NCARG/ncarg2d/src/libncarg_gks/bwi

Input arguments

IOP
  Indicates type of operation desired: IOP = 1 means OPEN workstation for output on IABS(IUNIT). IOP = 2 means CLOSE workstation for output on IABS(IUNIT). IOP = 3 means write IBUF to IABS(IUNIT). IOP = 4 means read IABS(IUNIT) into IBUF. IOP = 5 means position the record pointer to the beginning of the file. IOP = 6 means position the record pointer to the beginning of the previous record.
IUNIT
  IABS(IUNIT) is the Fortran logical unit number on which IOP is to occur.
FNAME
  The filename to be used for the open operation.
IBUFF
  Buffer containing data for a read or write operation.
LENGTH
  Length of data in IBUFF, in integer words.

Output arguments

IERROR
  Error indicator that equals 0 if no errors.

SUBROUTINE GBYTES(NPACK,ISAM,IBIT,NBITS,NSKIP,ITER)

This subroutine is used to unpack bit chunks from NPACK into the ISAM array. A portable Fortran version of this routine is distributed, but the Fortran version is inefficient and should be replaced with a more efficient implementation.

NPACK
  Address of first word of the array to be unpacked. For the purposes of this subroutine, NPACK is viewed as a bit stream.
ISAM
  Array to receive the unpacked bit chunks. They will be right justified with zero-fill in this array. ISAM should be dimensioned for ITER.
IBIT
  A bit-count offset to be used before the first bit chunk is unpacked. For example, if IBIT=3, and NBITS=5, then 3 bits in NPACK will be skipped and the next 5 bits will be unpacked into ISAM(1).
NBITS
  The number of bits in each bit chunk to be unpacked. An error condition occurs if NBITS is larger than the number of bits-per-word on the machine.
NSKIP
  The number of bits to skip between each bit chunk to be unpacked. Bits are skipped only after the first bit chunk has been unpacked.
ITER
  The number of bit chunks to be unpacked.

For example:

           CALL GBYTES(NPB,ISB,3,6,9,2)

In this call, three bits would be skipped at the beginning of NPB; the next six bits would be unpacked into ISB(1) and right-justified with zero-fill; nine bits would be skipped in NPB, and then the next six bits of NPB would be unpacked into ISB(2) and right-justified with zero-fill.

SUBROUTINE SBYTES(NPACK,ISAM,IBIT,NBITS,NSKIP,ITER)

This subroutine is the reverse of GBYTES as described above. NPACK-Address of first word of array to be packed. ISAM-Array to be packed into NPACK. The rightmost NBITS bits of each word will be packed. ISAM should be dimensioned for at least ITER. IBIT-A bit-count offset to be used before the first bits are packed into NPACK. For example, if IBIT=3, and NBITS=5, 3 bits in NPACK will be skipped before the rightmost 5 bits of ISAM(1) are packed into it. NBITS-The number of bits in each word of ISAM to be unpacked. An error condition occurs if NBITS exceeds the word size on the machine. NSKIP-The number of bits to skip between each bit chunk packed. ITER-The number of bit chunks to be packed.

For example:

           CALL SBYTES(NPC,ISB,45,6,3,2)

In this call, 45 bits would be skipped at the beginning of NPC; the rightmost 6 bits of ISB(1) would be packed into NPC; 3 bits would be skipped in NPC, and the rightmost 6 bits of ISB(2) would be packed into NPC.