The ngmath library is a collection of mathematical procedures
for which there are equivalent Fortran, C, and
NCL entries.
As of July, 1999 the ngmath library contains a collection of
interpolators
and approximators
for one-dimensional,
two-dimensional, and three-dimensional data. The packages are:
- natgrid -- a two-dimensional
random data interpolation package based on Dave Watson's package
nngridr.
- dsgrid -- a three-dimensional
random data interpolator based on a simple
inverse distance
weighting algorithm.
- fitgrid -- an interpolation
package for one-dimensional and two-dimensional gridded data
based on
Alan
Cline's package Fitpack, an early version of which is available
from netlib. Fitpack
uses splines under tension to interpolate in one and two dimensions.
- csagrid -- an approximation
package for one-dimensional, two-dimensional, and three-dimensional
random data based on
David
Fulker's package Splpack. Csagrid uses cubic splines to
calculate its approximation function.
- cssgrid
-- an interpolation
package for random data on the surface of a sphere. Cssgrid
uses cubic splines to calculate its interpolation function.
Cssgrid is based on the work of
Robert Renka.
- shgrid
-- an interpolation
package for random data in 3-space. Shgrid
uses a modified Shepard's algorithm to calculate its
interpolation function.
Shgrid is based on the work of
Robert Renka.
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.
Shgrid, Dsgrid and Csagrid handle three-dimensional data.
For interpolation, Shgrid is probably the package of
choice. Shgrid uses a least-squares fit of biquadratics
to construct its interpolation function.
The interpolation function calculated by Shgrid will pass
through the original data points.
Csagrid uses a least squares fit of cubic splines to calculate
an approximation surface; the calculated surface
will not necessarily pass through the original data points.
The Csagrid algorithm can become unstable in
data sparse regions.
Dsgrid uses a weighted average algorithm and is stable in all cases,
but the resultant interpolation function is not usually smooth
and the execution time is very slow. Dsgrid is probably best used
when Csagrid and Shgrid fail, and for comparative purposes.
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.
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.
Only Cssgrid is designed specifically for interpolating data
on the surface of a sphere. Cssgrid uses cubic splines to calculate
an interpolation function.
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.
We hope to some day add interfaces to the
FFTPACK5
software, which contains 1D, 2D, and multiple fast Fourier
subroutines, for transforming real and complex data, real even and odd
wave data, and real even and odd quarter-wave data.