# Detailed description of the procedures

## NATGRIDS - primary gridding function

NATGRIDS is the Fortran single-precision subroutine that does an interpolation from 2D random data to an output grid. NATGRIDS is called after all of the desired values for control parameters have been set using the subroutines NNSETI, NNSETR, NNSETC.
```--------------------------------------------------------------
Argument | Type    |  Mode  | Dimension
--------------------------------------------------------------
CALL NATGRIDS (NPNTS,   | Integer | Input  |
X,       | Real    | Input  | NPNTS
Y,       | Real    | Input  | NPNTS
Z,       | Real    | Input  | NPNTS
NUMXOUT, | Integer | Input  |
NUMYOUT, | Integer | Input  |
XI,      | Real    | Input  | NUMXOUT
YI,      | Real    | Input  | NUMYOUT
ZI,      | Real    | Output | NUMXOUT x NUMYOUT
IER)     | Integer | Output |
--------------------------------------------------------------
```
NPNTS
The number of input data points. (NPNTS > 3)
X
An array containing the X coordinates of the input data points.
Y
An array containing the Y coordinates of the input data points.
Z
An array containing the functional values of the input data points. That is, Z(L) is the value of the input function at coordinate (X(L),Y(L)), for L=1,NPNTS.
NUMXOUT
The number of X values in the output grid.
NUMYOUT
The number of Y values in the output grid.
XI
An array of dimension NUMXOUT containing the X coordinates of the output data grid. The values in XI must be increasing, but need not be equally spaced.
YI
An array of dimension NUMYOUT containing the Y coordinates of the output data grid. The values in YI must be increasing, but need not be equally spaced.
ZI
A two-dimensional array of dimension NUMXOUT x NUMYOUT containing the interpolated functional values. ZI(I,J) is the interpolated value at grid point (XI(I),YI(J)).
IER
An error return value. If IER is returned as 0, then no errors were detected. If IER is non-zero, then refer to the error list in the error table for details.

## NNSETI - set INTEGER parameter values

NNSETI is used to set values for any of the control parameters that take integer values. The values set by NNSETI remain in effect until changed by subsequent calls to NNSETI.
```-----------------------------------------------------
Argument | Type      |  Mode  | Dimension
-----------------------------------------------------
CALL NNSETI (PNAM,   | Character | Input  |
IVAL)   | Integer   | Input  |
-----------------------------------------------------
```
PNAM
The name of the control parameter to be set.
IVAL
The value to be assigned to the parameter.

## NNGETI - retrieve values for INTEGER parameters

NNGETI is a called to obtain current values for any of the INTEGER valued control parameters.
```-----------------------------------------------------
Argument | Type      |  Mode  | Dimension
-----------------------------------------------------
CALL NNGETI (PNAM,   | Character | Input  |
IVAL)   | Integer   | Output |
-----------------------------------------------------
```
PNAM
The name of the control parameter whose value is to be retrieved.
IVAL
The current value assigned to the control parameter.

## NNSETR - set REAL parameter values

NNSETR is used to set values for any of the control parameters that take REAL values. The values set by NNSETR remain in effect until changed by subsequent calls to NNSETR.
```-----------------------------------------------------
Argument | Type      |  Mode  | Dimension
-----------------------------------------------------
CALL NNSETR (PNAM,   | Character | Input  |
RVAL)   | Real      | Input  |
-----------------------------------------------------
```
PNAM
The name of the control parameter to be set.
RVAL
The value to be assigned to the parameter.

## NNGETR - retrieve values for REAL parameters

NNGETR is a called to obtain current values for any of the REAL valued control parameters.
```-----------------------------------------------------
Argument | Type      |  Mode  | Dimension
-----------------------------------------------------
CALL NNGETR (PNAM,   | Character | Input  |
RVAL)   | Real      | Output |
-----------------------------------------------------
```
PNAM
The name of the control parameter whose value is to be retrieved.
RVAL
The current value assigned to the control parameter.

## NNSETC - set CHARACTER valued parameters

```-----------------------------------------------------
Argument | Type      |  Mode  | Dimension
-----------------------------------------------------
CALL NNSETC (PNAM,   | Character | Input  |
CVAL)   | Character | Input  |
-----------------------------------------------------
```
NNSETC is used to set values for any of the control parameters that take CHARACTER values. The values set by NNSETC remain in effect until changed by subsequent calls to NNSETC.
PNAM
The name of the control parameter to be set.
CVAL
The value to be assigned to the parameter.

## NNGETC - retrieve values for CHARACTER parameters

NNGETC is a called to obtain current values for any of the CHARACTER valued control parameters.
```-----------------------------------------------------
Argument | Type      |  Mode  | Dimension
-----------------------------------------------------
CALL NNGETC (PNAM,   | Character | Input  |
CVAL)   | Character | Output |
-----------------------------------------------------
```
PNAM
The name of the control parameter whose value is to be retrieved.
CVAL
The current value assigned to the control parameter. Be sure to provide enough space in the character variable to receive the value.

## NNGETASPECTS - get aspect values, if calculated

NNGETASPECTS is called to retrieve an aspect, in single precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.
```-----------------------------------------------------------
Argument | Type      |  Mode  | Dimension
-----------------------------------------------------------
CALL NNGETASPECTS (I,      | Integer   | Input  |
J,      | Integer   | Input  |
ASPECT, | Real      | Output |
IER)    | Integer   | Output |
-----------------------------------------------------------
```
I
A subscript indexing the first dimensioned variable in the output grid of the most recent call to NATGRIDS.
J
A subscript indexing the second dimensioned variable in the output grid in the most recent call to NATGRIDS.
ASPECT
The aspect at the grid point Z(I,J), where Z is the output grid in the most recent call to NATGRIDS.
IER
An error return value. If IER is returned as 0, then no errors were detected. If IER is non-zero, then refer to the error list in the error table for details.

## NNGETSLOPES - get slope values, if calculated

NNGETSLOPES is called to retrieve a slope, in single precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.
```----------------------------------------------------------
Argument | Type      |  Mode  | Dimension
----------------------------------------------------------
CALL NNGETSLOPES (I,      | Integer   | Input  |
J,      | Integer   | Input  |
SLOPE,  | Real      | Output |
IER)    | Integer   | Output |
----------------------------------------------------------
```
I
A subscript indexing the first dimensioned variable in the output grid of the most recent call to NATGRIDS.
J
A subscript indexing the second dimensioned variable in the output grid in the most recent call to NATGRIDS.
SLOPE
The slope at the grid point Z(I,J), where Z is the output grid in the most recent call to NATGRIDS.
IER
An error return value. If IER is returned as 0, then no errors were detected. If IER is non-zero, then refer to the error list in the error table for details.

## NNPNTINITS - initiate single-point mode

This subroutine calculates all natural neighbor relationships in an input data array and sets some internal parameters so that NNPNTS can be called to interpolate at individual points.
```----------------------------------------------------------
Argument | Type      |  Mode  | Dimension
----------------------------------------------------------
CALL NNPNTINITS (NPNTS,   | Integer   | Input  |
X,       | Real      | Input  | NPNTS
Y,       | Real      | Input  | NPNTS
Z)       | Real      | Input  | NPNTS
----------------------------------------------------------
```
NPNTS
The number of input data points. (NPNTS > 3)
X
An array of dimension NPNTS containing the X coordinates of the input data points.
Y
An array of dimension NPNTS containing the Y coordinates of the input data points.
Z
An array of dimension NPNTS containing the functional values of the input data points. That is, Z(L) is the value of the input function at coordinate (X(L),Y(L)), for L=1,NPNTS.

## NNPNTS - interpolate at a single point

This subroutine is called to interpolate at a specified point. Before calling this subroutine, NNPNTINITS must be called.
```-------------------------------------------------------
Argument | Type      |  Mode  | Dimension
-------------------------------------------------------
CALL NNPNTS (X,       | Real      | Input  |
Y,       | Real      | Input  |
Z)       | Real      | Output |
-------------------------------------------------------
```
X
The X coordinate of the point where interpolation is desired.
Y
The Y coordinate of the point where interpolation is desired.
Z
The interpolated functional value at the point (X,Y).

## NNPNTEND - terminate single-point mode

This subroutine is called to terminate interpolation at single points. It is called after having made previous calls to NNPNTINITS and NNPNTS.
```--------------------------------------------
Argument | Type |  Mode  | Dimension
--------------------------------------------
CALL NNPNTEND () | N/A  |  N/A   | N/A
--------------------------------------------
```

## NNGETWTS - retrieve weights and neighbors

This subroutine is called to retrieve natural neighbors and weights for the function values at those neighbors. This subroutine can be called only after a call to NNPNTS and before a call to NNPNTSEND.
```---------------------------------------------------------
Argument | Type      |  Mode  | Dimension
---------------------------------------------------------
CALL NNGETWTS (NUMW,    | Integer   | Output |
NBRS,    | Integer   | Output | See below
WTS,     | Real      | Output | See below
XE,      | Real      | Output | 3
YE,      | Real      | Output | 3
ZE)      | Real      | Output | 3
---------------------------------------------------------
```
NUMW
The number of natural neighbors involved in the most recent NNPNTS call.
NBRS
An array of indices of the natural neighbors of the coordinate in the most recent NNPNTS call. These indices are into the original input data for NNPNTINITS. For example, if I is an index returned in NBRS, then (X(I),Y(I)) (where the X and Y arrays referred to here are the ones used as arguments to NNPNTINITS) is a neighbor of the input coordinate involved in the most recent NNPNTS call. You should probably dimension this array to be the same as the size of your original input data arrays, plus 3 (see below for the plus 3).
WTS
The weights used for the input data at the neighbors. For example, if NBRS(N) = M then WTS(N) would be the weight applied to the original function value F(M). The sum of WTS(L) for L=1,NUMW should be unity.
XE,YE,ZE
These are three additional values to be added to the input dataset. The way that Natgrid handles extrapolation is to enclose the coordinates of the original dataset within a large triangle, and function values at the vertices of this triangle are determined by fitting a plane to the original data by least sum of squared distances. So, it is possible that one of these three additional points may be indexed in the list of natural neighbors returned.
See Example 10.

## NATGRIDD - primary gridding function

NATGRIDD is the Fortran double-precision subroutine that does an interpolation from 2D random data to an output grid. NATGRIDD is called after all of the desired values for control parameters have been set using the subroutines NNSETI, NNSETRD, NNSETC.
```------------------------------------------------------------------------
Argument | Type              |  Mode  | Dimension
------------------------------------------------------------------------
CALL NATGRIDD (NPNTS,   | Integer           | Input  |
X,       | Double precision  | Input  | NPNTS
Y,       | Double precision  | Input  | NPNTS
Z,       | Double precision  | Input  | NPNTS
NUMXOUT, | Integer           | Input  |
NUMYOUT, | Integer           | Input  |
XI,      | Double precision  | Input  | NUMXOUT
YI,      | Double precision  | Input  | NUMYOUT
ZI,      | Double precision  | Output | NUMXOUT x NUMYOUT
IER)     | Integer           | Output |
------------------------------------------------------------------------
```
NPNTS
The number of input data points. (NPNTS > 3)
X
An array of dimension NPNTS containing the X coordinates of the input data points.
Y
An array of dimension NPNTS containing the Y coordinates of the input data points.
Z
An array of dimension NPNTS containing the functional values of the input data points. That is, Z(L) is the value of the input function at coordinate (X(L),Y(L)), for L=1,NPNTS.
NUMXOUT
The number of X values in the output grid.
NUMYOUT
The number of Y values in the output grid.
XI
An array of dimension NUMXOUT containing the X coordinates of the output data grid. The values in XI must be increasing, but need not be equally spaced.
YI
An array of dimension NUMYOUT containing the Y coordinates of the output data grid. The values in YI must be increasing, but need not be equally spaced.
ZI
A two-dimensional array of dimension NUMXOUT x NUMYOUT containing the interpolated functional values. ZI(I,J) is the interpolated value at grid point (XI(I),YI(J)).
IER
An error return value. If IER is returned as 0, then no errors were detected. If IER is non-zero, then refer to the error list in the error table for details.

## NNSETRD - set DOUBLE PRECISION parameter values

NNSETRD is used to set values for any of the control parameters that take DOUBLE PRECISION values. The values set by NNSETRD remain in effect until changed by subsequent calls to NNSETRD.
```-------------------------------------------------------------
Argument | Type             |  Mode  | Dimension
-------------------------------------------------------------
CALL NNSETRD (PNAM,   | Character        | Input  |
RVAL)   | Double precision | Input  |
-------------------------------------------------------------
```
PNAM
The name of the control parameter to be set.
RVAL
The value to be assigned to the parameter.

## NNGETRD - retrieve values for DOUBLE PRECISION parameters

NNGETRD is a called to obtain current values for any of the DOUBLE PRECISION valued control parameters.
```-------------------------------------------------------------
Argument | Type             |  Mode  | Dimension
-------------------------------------------------------------
CALL NNGETRD (PNAM,   | Character        | Input  |
RVAL)   | Double precision | Output |
-------------------------------------------------------------
```
PNAM
The name of the control parameter whose value is to be retrieved.
RVAL
The current value assigned to the control parameter.

## NNGETASPECTD - get aspect values, if calculated

NNGETASPECTD is called to retrieve an aspect, in double precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.
```------------------------------------------------------------------
Argument | Type             |  Mode  | Dimension
------------------------------------------------------------------
CALL NNGETASPECTD (I,      | Integer          | Input  |
J,      | Integer          | Input  |
ASPECT, | Double precision | Output |
IER)    | Integer          | Output |
------------------------------------------------------------------
```
I
A subscript indexing the first dimensioned variable in the output grid of the most recent call to NATGRIDD.
J
A subscript indexing the second dimensioned variable in the output grid in the most recent call to NATGRIDD.
ASPECT
The aspect at the grid point Z(I,J), where Z is the output grid in the most recent call to NATGRIDD.
IER
An error return value. If IER is returned as 0, then no errors were detected. If IER is non-zero, then refer to the error list in the error table for details.

## NNGETSLOPED - get slope values, if calculated

NNGETSLOPED is called to retrieve a slope, in double precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.
```-----------------------------------------------------------------
Argument | Type             |  Mode  | Dimension
-----------------------------------------------------------------
CALL NNGETSLOPED (I,      | Integer          | Input  |
J,      | Integer          | Input  |
SLOPE,  | Double precision | Output |
IER)    | Integer          | Output |
-----------------------------------------------------------------
```
I
A subscript indexing the first dimensioned variable in the output grid of the most recent call to NATGRIDD.
J
A subscript indexing the second dimensioned variable in the output grid in the most recent call to NATGRIDD.
SLOPE
The slope at the grid point Z(I,J), where Z is the output grid in the most recent call to NATGRIDD.
IER
An error return value. If IER is returned as 0, then no errors were detected. If IER is non-zero, then refer to the error list in the error table for details.

## NNPNTINITD - initiate single-point mode

This subroutine calculates all natural neighbor relationships in an input data array and sets some internal parameters so that NNPNTD can be called to interpolate at individual points.
```-----------------------------------------------------------------
Argument | Type             |  Mode  | Dimension
-----------------------------------------------------------------
CALL NNPNTINITD (NPNTS,   | Integer          | Input  |
X,       | Double precision | Input  | NPNTS
Y,       | Double precision | Input  | NPNTS
Z)       | Double precision | Input  | NPNTS
-----------------------------------------------------------------
```
NPNTS
The number of input data points. (NPNTS > 3)
X
An array of dimension NPNTS containing the X coordinates of the input data points.
Y
An array of dimension NPNTS containing the Y coordinates of the input data points.
Z
An array of dimension NPNTS containing the functional values of the input data points. That is, Z(L) is the value of the input function at coordinate (X(L),Y(L)), for L=1,NPNTS.

## NNPNTD - interpolate at a single point

This subroutine is called to interpolate at a specified point. Before calling this subroutine, NNPNTINITD must be called.
```--------------------------------------------------------
Argument | Type             |  Mode  | Dimension
--------------------------------------------------------
CALL NNPNTD (X,  | Double precision | Input  |
Y,  | Double precision | Input  |
Z)  | Double precision | Output |
--------------------------------------------------------
```
X
The X coordinate of the point where interpolation is desired.
Y
The Y coordinate of the point where interpolation is desired.
Z
The interpolated functional value at the point (X,Y).

## NNPNTENDD - terminate single-point mode

This subroutine is called to terminate interpolation at single points. It is called after having made previous calls to NNPNTINITD and NNPNTD.
```---------------------------------------------
Argument   | Type |  Mode  | Dimension
---------------------------------------------
CALL NNPNTENDD ()  | N/A  |  N/A   | N/A
---------------------------------------------
```

## NNGETWTSD - retrieve weights and neighbors

This subroutine is called to retrieve natural neighbors and weights for the function values at those neighbors. This subroutine can be called only after a call to NNPNTSD and before a call to NNPNTSENDD.
```---------------------------------------------------------
Argument | Type      |  Mode  | Dimension
---------------------------------------------------------
CALL NNGETWTSD (NUMW,    | Integer   | Output |
NBRS,    | Integer   | Output | See below
WTS,     | Double    | Output | See below
XE,      | Double    | Output | 3
YE,      | Double    | Output | 3
ZE)      | Double    | Output | 3
---------------------------------------------------------
```
NUMW
The number of natural neighbors involved in the most recent NNPNTS call.
NBRS
An array of indices of the natural neighbors of the coordinate in the most recent NNPNTD call. These indices are into the original input data for NNPNTINITD. For example, if I is an index returned in NBRS, then (X(I),Y(I)) (where the X and Y arrays referred to here are the ones used as arguments to NNPNTINITD) is a neighbor of the input coordinate involved in the most recent NNPNTD call. You should probably dimension this array to be the same as the size of your original input data arrays, plus 3 (see below for the plus 3).
WTS
The weights used for the input data at the neighbors. For example, if NBRS(N) = M then WTS(N) would be the weight applied to the original function value F(M). The sum of WTS(L) for L=1,NUMW should be unity.
XE,YE,ZE
These are three additional values to be added to the input dataset. The way that Natgrid handles extrapolation is to enclose the coordinates of the original dataset within a large triangle, and function values at the vertices of this triangle are determined by fitting a plane to the original data by least sum of squared distances. So, it is possible that one of these three additional points may be indexed in the list of natural neighbors returned.
See Example 10.

## c_natgrids - Primary gridding function

c_natgrids is the C single-precision function that does an interpolation from 2D random data to an output grid. c_natgrids is called after all of the desired values for control parameters have been set using the procedures c_nnseti, c_nnsetr, c_nnsetc.

Function prototype:

```  float *c_natgrids(int, float [], float [], float [],
int, int, float [], float [], int *);
```
Return value:

c_natgrids returns a pointer to a linear array of data that is the interpolated grid stored in row-major order. That is, if out is declared as

```float *out;
```
and we set:
```  out = c_natgrids(npnts, x, y, z, numxout, numyout, xo, yo, &ier);
```
then out[i*numyout+j] is the interpolated function value at coordinate point (xo[i],yo[j]) for 0 <= i < numxout and 0 <= j < numyout. The space for out is allocated internal to c_natgrids and is numxout*numyout floats in size.

Argument description:

```-------------------------------------------------
Argument | Type     |  Size
-------------------------------------------------
float *c_natgrids (npnts,   | int      |
x,       | float [] | npnts
y,       | float [] | npnts
z,       | float [] | npnts
numxout, | int      |
numyout, | int      |
xi,      | float [] | numxout
yi,      | float [] | numyout
ier      | int *    |
);
-------------------------------------------------
```
npnts
The number of input data points. (npnts > 3)
x
An array of size npnts containing the X coordinates of the input data points.
y
An array of size npnts containing the Y coordinates of the input data points.
z
An array of size npnts containing the functional values of the input data points. That is, z[n] is the value of the input function at coordinate (x[n],y[n]), for 0 <= n < npnts.
numxout
The number of X values in the output grid.
numyout
The number of Y values in the output grid.
xi
An array of size numxout containing the X coordinates of the output data grid. The values in xi must be increasing, but need not be equally spaced.
yi
An array of size numyout containing the Y coordinates of the output data grid. The values in yi must be increasing, but need not be equally spaced.
ier
An error return value. If *ier is returned as 0, then no errors were detected. If *ier is non-zero, then refer to the error list in the error table for details.

## c_nnseti - Set int valued parameters

c_nnseti is used to set values for any of the control parameters that take int values. The values set by c_nnseti remain in effect until changed by subsequent calls to c_nnseti.

Function prototype:

```  void c_nnseti(char *, int);
```
Argument description:
```-------------------------------------------
Argument | Type    |  Size
-------------------------------------------
void c_nnseti (pnam,   | char *  |
ival);  | int     |
-------------------------------------------
```
pnam
The name of the control parameter to be assigned an int value.
ival
The value to be assigned to the control parameter whose name is pointed to by pnam.

## c_nngeti - Retrieve an int valued parameter

c_nngeti is a called to obtain current values for any of the int valued control parameters.

Function prototype:

```  void c_nngeti(char *, int);
```
Argument description:
```-------------------------------------------
Argument | Type    |  Size
-------------------------------------------
void c_nngeti (pnam,   | char *  |
ival);  | int  *  |
-------------------------------------------
```
pnam
The name of the control parameter whose value is to be retrieved.
ival
*ival will be the value currently assigned to the control parameter whose name is pointed to by pnam.

## c_nnsetr - Set float valued parameters

c_nnsetr is used to set values for any of the control parameters that take float values. The values set by c_nnsetr remain in effect until changed by subsequent calls to c_nnsetr.

Function prototype:

```  void c_nnsetr(char *, float);
```
Argument description:
```-------------------------------------------
Argument | Type    |  Size
-------------------------------------------
void c_nnsetr (pnam,   | char *  |
fval);  | float   |
-------------------------------------------
```
pnam
The name of the control parameter to be assigned a float value.
fval
The value to be assigned to the control parameter whose name is pointed to by pnam.

## c_nngetr - Retrieve a float valued parameter

c_nngetr is a called to obtain current values for any of the float valued control parameters.

Function prototype:

```  void c_nngetr(char *, float *);
```
Argument description:
```-------------------------------------------
Argument | Type    |  Size
-------------------------------------------
void c_nngetr (pnam,   | char *  |
fval);  | float * |
-------------------------------------------
```
pnam
The name of the control parameter whose value is to be retrieved.
fval
*fval will be the value currently assigned to the control parameter whose name is pointed to by pnam.

## c_nnsetc - Set char valued parameters

c_nnsetc is used to set values for any of the control parameters that take string values. The values set by c_nnsetc remain in effect until changed by subsequent calls to c_nnsetc.

Function prototype:

```  void c_nnsetc(char *, char *);
```
Argument description:
```-------------------------------------------
Argument | Type    |  Size
-------------------------------------------
void c_nnsetc (pnam,   | char *  |
cval);  | char *  |
-------------------------------------------
```
pnam
The name of the control parameter to be assigned a char value.
cval
The value to be assigned to the control parameter whose name is pointed to by pnam.

## c_nngetc - Retrieve a char valued parameter

c_nngetc is a called to obtain current values for any of the string valued control parameters.

Function prototype:

```  void c_nngetc(char *, char *);
```
Argument description:
```-------------------------------------------
Argument | Type    |  Size
-------------------------------------------
void c_nngetc (pnam,   | char *  |
cval);  | char *  |
-------------------------------------------
```
pnam
The name of the control parameter whose value is to be retrieved.
cval
cval will point to a string containing the returned value. The user is required to reserve enough space to store the string.

## c_nngetaspects - Retrieve aspect values, if calculated

c_nngetaspects is called to retrieve an aspect, in single precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.

Function prototype:

```  void c_nngetaspects(int, int, float *, int *);
```
Argument description:
```-----------------------------------------------
Argument | Type    |  Size
-----------------------------------------------
void c_nngetaspects (row,    | int     |
column, | int     |
aspect, | float * |
ier);   | int *   |
-----------------------------------------------
```
row
A subscript indexing the first dimensioned variable in the 2D grid array returned from the most recent call to c_natgrids.
column
A subscript indexing the second dimensioned variable in the 2D grid array returned from the most recent call to c_natgrids.
aspect
*aspect is the aspect at the grid point z[i,j], where z is the output grid in the most recent call to c_natgrids.
ier
*ier is an error return value. If *ier is 0, then no errors were detected. If *ier is non-zero, then refer to the error list in the error table for details.

## c_nngetslopes - Retrieve slope values, if calculated

c_nngetslopes is called to retrieve a slope, in single precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.

Function prototype:

```  void c_nngetslopes(int, int, float *, int *);
```
Argument description:
```-----------------------------------------------
Argument | Type    |  Size
-----------------------------------------------
void c_nngetslopes  (row,    | int     |
column, | int     |
slope,  | float * |
ier);   | int *   |
-----------------------------------------------
```
row
A subscript indexing the first dimensioned variable in the 2D grid array returned from the most recent call to c_natgrids.
column
A subscript indexing the second dimensioned variable in the 2D grid array returned from the most recent call to c_natgrids.
slope
*slope is the slope at the grid point z[i,j], where z is the output grid in the most recent call to c_natgrids.
ier
*ier is an error return value. If *ier is 0, then no errors were detected. If *ier is non-zero, then refer to the error list in the error table for details.

## c_nnpntinits - Enter single-point mode

This function calculates all natural neighbor relationships in an input data array and sets some internal parameters so that c_nnpnts can be called to interpolate at individual points.

Function prototype:

```  void c_nnpntinits(int, float [], float [], float []);
```
Argument description:
```-----------------------------------------------
Argument | Type     |  Size
-----------------------------------------------
void c_nnpntinits (npnts,  | int      |
x,      | float [] | npnts
y,      | float [] | npnts
z);     | float [] | npnts
-----------------------------------------------
```
npnts
The number of input data points. (npnts > 3)
x
An array of size npnts containing the X coordinates of the input data points.
y
An array of size npnts containing the Y coordinates of the input data points.
z
An array of size npnts containing the functional values of the input data points. That is, z[n] is the value of the input function at coordinate (x[n],y[n]), for 0 <= n < npnts.

## c_nnpnts - Interpolate at a single point

This function is called to interpolate at a specified point. Before calling this function, c_nnpntinits must be called.

Function prototype:

```  void c_nnpnts(float, float, float *);
```
Argument description:
```-----------------------------------------------
Argument | Type     |  Size
-----------------------------------------------
void c_nnpnts (x,      | float    |
y,      | float    |
z);     | float *  |
-----------------------------------------------
```
x
The X coordinate of the point where interpolation is desired.
y
The Y coordinate of the point where interpolation is desired.
z
*z is the interpolated functional value at the point (X,Y).

## c_nnpntend - Exit single-point mode

This function is called to terminate interpolation at single points. It is called after having made previous calls to c_nnpntinits and c_nnpnts.

Function prototype:

```  void c_nnpntend();
```
Argument description:
```-----------------------------------------------
Argument | Type     |  Size
-----------------------------------------------
void c_nnpntend ();      | N/A      |  N/A
-----------------------------------------------
```

## c_nngetwts - retrieve weights and neighbors

This function is called to retrieve natural neighbors and weights for the function values at those neighbors. This function can be called only after a call to c_nnpnts and before a call to c_nnpntend.

Function prototype:

```  void c_nngetwts(int *, int *, float *, float *, float *, float *);
```
Argument description:
```--------------------------------------------------
Argument | Type     |  Size
--------------------------------------------------
void c_nngetwts (numw,      | int *    |
nbrs,      | int *    | See below
wts,       | float *  | See below
xe,        | float *  | 3
ye,        | float *  | 3
ze)        | float *  | 3
--------------------------------------------------
```
*numw
The number of natural neighbors involved in the most recent c_nnpnts call.
nbrs
An array of indices of the natural neighbors involved in the most recent c_nnpnts call. These indices are into the original input data for c_nnpnts. nbrs should point to enough space as the size of your original input data arrays, plus 3 (see below for the plus 3).
wts
The weights used for the input data at the neighbors. For example, if nbrs[n] = m, then wts[n] would be the weight applied to the original function value f[m]. The sum of wts[l] for l=0,numw-1 should be unity. wts should point to enough space as the size of your original input data arrays, plus 3 (see below for the plus 3).
xe,ye,ze
These are three additional values to be added to the input dataset. The way that Natgrid handles extrapolation is to enclose the coordinates of the original dataset within a large triangle, and function values at the vertices of this triangle are determined by fitting a plane to the original data by least sum of squared distances. So, it is possible that one of these three additional points may be indexed in the list of natural neighbors returned.

## c_nnpntend - Exit single-point mode

This function is called to terminate interpolation at single points. It is called after having made previous calls to c_nnpntinits and c_nnpnts.

Function prototype:

```  void c_nnpntend();
```
Argument description:
```-----------------------------------------------
Argument | Type     |  Size
-----------------------------------------------
void c_nnpntend ();      | N/A      |  N/A
-----------------------------------------------
```

## c_natgridd - Primary gridding function

c_natgridd is the C double-precision function that does an interpolation from 2D random data to an output grid. c_natgrids is called after all of the desired values for control parameters have been set using the function c_nnseti, c_nnsetrd, c_nnsetc.

Function prototype:

```  double *c_natgridd(int, double [], double [], double [],
int, int, double [], double [], int *);
```
Return value:

c_natgridd returns a pointer to a linear array of data that is the interpolated grid stored in row-major order. That is, if out is declared as

```double *out;
```
and we set:
```  out = c_natgridd(numin, x, y, z, numxout, numyout, xo, yo, &ier);
```
then out[i*numyout+j] is the interpolated function value at coordinate point (xo[i],yo[j]) for 0 <= i < numxout and 0 <= j < numyout. The space for out is allocated internal to c_natgridd and is numxout*numyout double-precision values in size.

Argument description:

```-------------------------------------------------
Argument | Type      |  Size
-------------------------------------------------
double *c_natgridd (npnts,  | int       |
x,       | double [] | npnts
y,       | double [] | npnts
z,       | double [] | npnts
numxout, | int       |
numyout, | int       |
xi,      | double [] | numxout
yi,      | double [] | numyout
ier      | int *     |
);        |           |
-------------------------------------------------
```
npnts
The number of input data points. (npnts > 3)
x
An array of size npnts containing the X coordinates of the input data points.
y
An array of size npnts containing the Y coordinates of the input data points.
z
An array of size npnts containing the functional values of the input data points. That is, z[n] is the value of the input function at coordinate (x[n],y[n]), for 0 <= n < npnts.
numxout
The number of X values in the output grid.
numyout
The number of Y values in the output grid.
xi
An array of size numxout containing the X coordinates of the output data grid. The values in xi must be increasing, but need not be equally spaced.
yi
An array of size numyout containing the Y coordinates of the output data grid. The values in yi must be increasing, but need not be equally spaced.
ier
An error return value. If *ier is returned as 0, then no errors were detected. If *ier is non-zero, then refer to the error list in the error table for details.

## c_nnsetrd - Set double-precision parameter values

c_nnsetrd is used to set values for any of the control parameters that take double-precision values. The values set by c_nnsetrd remain in effect until changed by subsequent calls to c_nnsetrd.

Function prototype:

```  void c_nnsetrd(char *, double);
```
Argument description:
```-------------------------------------------
Argument | Type    |  Size
-------------------------------------------
void c_nnsetrd (pnam,   | char *  |
dval);  | double  |
-------------------------------------------
```
pnam
The name of the control parameter to be assigned a float value.
dval
The value to be assigned to the control parameter whose name is pointed to by pnam.

## c_nngetrd - Retrieve a double-precision parameter value

c_nngetrd is a called to obtain current values for any of the double-precision control parameters.

Function prototype:

```  void c_nngetrd(char *, double *);
```
Argument description:
```-------------------------------------------
Argument | Type     |  Size
-------------------------------------------
void c_nngetrd (pnam,   | char *   |
dval);  | double * |
-------------------------------------------
```
pnam
The name of the control parameter whose value is to be retrieved.
dval
*dval is the value currently assigned to the control parameter whose name is pointed to by pnam.

## c_nngetaspectd - Retrieve aspect values, if calculated

c_nngetaspectd is called to retrieve an aspect, in double precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.

Function prototype:

```  void c_nngetaspectd(int, int, double *, int *);
```
Argument description:
```-----------------------------------------------
Argument | Type     |  Size
-----------------------------------------------
void c_nngetaspectd (row,    | int      |
column, | int      |
aspect, | double * |
ier);   | int *    |
-----------------------------------------------
```
row
A subscript indexing the first dimensioned variable in the 2D grid array returned from the most recent call to c_natgrids.
column
A subscript indexing the second dimensioned variable in the 2D grid array returned from the most recent call to c_natgrids.
aspect
*aspect is the aspect at the grid point z[i,j], where z is the output grid in the most recent call to c_natgridd.
ier
*ier is an error return value. If *ier is 0, then no errors were detected. If *ier is non-zero, then refer to the error list in the error table for details.

## c_nngetsloped - Retrieve slope values, if calculated

c_nngetsloped is called to retrieve a slope, in double precision, at a specified coordinate value. For further details, see the module on computing aspects and slopes.

Function prototype:

```  void c_nngetsloped(int, int, double *, int *);
```
Argument description:
```----------------------------------------------
Argument | Type     |  Size
----------------------------------------------
void c_nngetsloped (row,    | int      |
column, | int      |
slope,  | double * |
ier);   | int *    |
----------------------------------------------
```
row
A subscript indexing the first dimensioned variable in the output grid of the most recent call to c_natgridd.
column
A subscript indexing the second dimensioned variable in the output grid of the most recent call to c_natgridd.
slope
*slope is the slope at the grid point z[i,j], where z is the output grid in the most recent call to c_natgridd.
ier
*ier is an error return value. If *ier is 0, then no errors were detected. If *ier is non-zero, then refer to the error list in the error table for details.

## c_nnpntinitd - Enter single-point mode

This function calculates all natural neighbor relationships in an input data array and sets some internal parameters so that c_nnpntd can be called to interpolate at individual points.

Function prototype:

```  void c_nnpntinitd(int, double [], double [], double []);
```
Argument description:
```-----------------------------------------------
Argument | Type      |  Size
-----------------------------------------------
void c_nnpntinitd (npnts,  | int       |
x,      | double [] | npnts
y,      | double [] | npnts
z);     | double [] | npnts
-----------------------------------------------
```
npnts
The number of input data points. (npnts > 3)
x
An array of size npnts containing the X coordinates of the input data points.
y
An array of size npnts containing the Y coordinates of the input data points.
z
An array of size npnts containing the functional values of the input data points. That is, z[n] is the value of the input function at coordinate (x[n],y[n]), for 0 <= n < npnts.

## c_nnpntd - Interpolate at a single point

This function is called to interpolate at a specified point. Before calling this function, c_nnpntinitd must be called.

Function prototype:

```  void c_nnpntd(double, double, double *);
```
Argument description:
```-------------------------------------------
Argument | Type      |  Size
-------------------------------------------
void c_nnpntd (x,      | double    |
y,      | double    |
z);     | double *  |
-------------------------------------------
```
x
The X coordinate of the point where interpolation is desired.
y
The Y coordinate of the point where interpolation is desired.
z
*z is the interpolated functional value at the point (X,Y).

## c_nnpntendd - Exit single-point mode

This function is called to terminate interpolation at single points. It is called after having made previous calls to c_nnpntinitd and c_nnpntd.

Function prototype:

```  void c_nnpntendd();
```
Argument description:
```-----------------------------------------------
Argument | Type     |  Size
-----------------------------------------------
void c_nnpntendd ()       | N/A      |  N/A
-----------------------------------------------
```

## c_nngetwtsd - retrieve weights and neighbors

This function is called to retrieve natural neighbors and weights for the function values at those neighbors. This function can be called only after a call to c_nnpnts and before a call to c_nnpntend.

Function prototype:

```  void c_nngetwtsd(int *, int *, float *, float *, float *, float *);
```
Argument description:
```--------------------------------------------------
Argument | Type     |  Size
--------------------------------------------------
void c_nngetwtsd (numw,      | int *    |
nbrs,      | int *    | See below
wts,       | double * | See below
xe,        | double * | 3
ye,        | double * | 3
ze)        | double * | 3
--------------------------------------------------
```
*numw
The number of natural neighbors involved in the most recent c_nnpnts call.
nbrs
An array of indices of the natural neighbors involved in the most recent c_nnpnts call. These indices are into the original input data for c_nnpnts. nbrs should point to enough space as the size of your original input data arrays, plus 3 (see below for the plus 3).
wts
The weights used for the input data at the neighbors. For example, if nbrs[n] = m, then wts[n] would be the weight applied to the original function value f[m]. The sum of wts[l] for l=0,numw-1 should be unity. wts should point to enough space as the size of your original input data arrays, plus 3 (see below for the plus 3).
xe,ye,ze
These are three additional values to be added to the input dataset. The way that Natgrid handles extrapolation is to enclose the coordinates of the original dataset within a large triangle, and function values at the vertices of this triangle are determined by fitting a plane to the original data by least sum of squared distances. So, it is possible that one of these three additional points may be indexed in the list of natural neighbors returned.

home | contents | defs | params | procedures | exmpls | index