Ngmath Library Overview


What the ngmath library is

The ngmath library is a collection of mathematical procedures for which there are equivalent Fortran, C, and NCL entries. These procedures are generally not available in other libraries local to the NCAR Scientific Computing Division.

What the ngmath library contains

As of January, 1999 the ngmath library contains a collection of interpolators and approximators for one-dimensional, two-dimensional, and three-dimensional data. The packages are:

General background on interpolation and approximation methods

Computational interpolation and approximation methods can be divided into two basic classes: fitted function methods and weighted average methods.

The fitted function methods fit an algebraic surface to the known data and then pick the interpolated values from the fitted surface. The weighted average methods calculate interpolated values as weighted averages of known values.

Among the weighted average methods, the simplest are known as the inverse distance weighted average methods. These methods are implemented by calculating weights for all input coordinates such that the weights are inversely proportional to the distance an input coordinate is from the point where an interpolated value is desired. The sum of the weights is normalized to unity and an interpolated value is the sum of the products of the functional values and the calculated weights.

Comparative analysis of the ngmath packages

Three-dimensional problems

Only Dsgrid and Csagrid handle three-dimensional data. Csagrid will in general produce smoother results than Dsgrid (compare the plot for Csagrid example 5 to the plot for Dsgrid example 1).

Since Csagrid uses an approximation algorithm, the calculated surface will not necessarily pass through the original data points. Also, the Csagrid algorithm can become unstable in data sparse regions. The weighted average algorithm used in Dsgrid is stable in all cases and the resulting surface will pass through the original data values.

Two-dimensional problems

The four packages natgrid, csagrid, dsgrid, and fitgrid have entries for two-dimensional data.

In most all cases natgrid will be the package of choice. It implements a very stable algorithm and has parameters for adjusting the smoothness of the output surface.

The two-dimensional surface entries in Fitgrid offer user-settable parameters for specifying derivatives along the boundary of the output grid that are not available in Natgrid.

Csagrid will produce a two-dimensional surface that is an approximation and may produce results that are smoother in appearance than those produced by Fitgrid or Natgrid.

Dsgrid is not recommended for two-dimensional surfaces - Natgrid is superior in all respects.

One-dimensional problems

Only Fitgrid and Csagrid handle one-dimensional data and Fitgrid is definitely the package of choice. Fitgrid has an entry for producing an approximation that is essentially the same as that produced by Csagrid, but Fitgrid has many features not available in Csagrid, such as interpolating parametric curves, finding integrals, handling periodic functions, allowing for smoothing that varies from linear interpolation to a full cubic spline, and specifying slopes at the end points.

Accessing the ngmath library

The ngmath library is a stand-alone library. Using the Fortran and C entries in the library in no way depends upon using NCAR Graphics. However, the library is distributed only with NCAR Graphics. The NCL interface to the ngmath entries is built into the NCL executable.

If you have NCAR Graphics installed at your site, then the ngmath library will be located in $NCARG_ROOT/lib/libngmath.a . If you want to load the library directly, check your environment variable settings to see if you have $NCARG_ROOT set and, if not, consult your local system administrator to see what you should set it to. If you are using NCAR Graphics, then, for Fortran and C codes, by adding a "-l ngmath" flag to "ncargf77" or "ncargcc" the ngmath library will be loaded.

Future plans for the ngmath library

The next package to be added is FFTPACK, a locally-developed library of one-dimensional FFT solvers, including complex, real, sin, cosine, quarter-sin, and quarter-cosine transforms. Also planned is a package for drawing Bezier curves and a random data two-dimensional interpolator that allows for constrained regions with holes. Also, NCL interfaces to commercial libraries such as Linpack and IMSL will be provided as time permits.