NCL Home > Documentation > Functions > Interpolation, Ngmath routines

dspnt2

Interpolates 2D data at specified points.

Prototype

```	function dspnt2 (
x  [*] : numeric,
y  [*] : numeric,
z      : numeric,
xo [*] : numeric,
yo [*] : numeric
)

return_val  :  float or double
```

Arguments

x

A 1D array of length npts containing the X coordinates of the points where interpolation is desired.

y

A 1D array of length npts containing the Y coordinates of the points where interpolation is desired.

z

An array of any dimensionality (last dimension must be npts) containing the functional values of the input data points. Element z(...,i) is the value of the input function at coordinate (x(i), y(i)) for i = 0, npts - 1).

xo

A 1D array of length m containing the X coordinates of the output data grid. The values in xo may be in any order and m can be equal to one.

yo

A 1D array of length m containing the Y coordinates of the output data grid. The values in yo may be in any order and m can be equal to one.

Return value

Returns a floating point array dimensioned as N x m, where N represents all but the last dimension of z. The return value type is double if z is of type double.

Description

This function performs interpolation from sets of 2D data at specified points.

This function must allocate its output array in advance.

This function is part of the Dsgrid package which implements a simple inverse distance weighted interpolation algorithm. No missing values are allowed.

Examples

Example 1

Interpolate zi values to the output xo/yo grid.

```begin

NUM = 171
NX  =  21
NY  =  21

RAND_MAX = 32767.0

xi = new((/NUM/), float)
yi = new((/NUM/), float)
zi = new((/NUM/), float)

xminin = -0.2
yminin = -0.2
xmaxin =  1.2
ymaxin =  1.2
xminot =  0.0
yminot =  0.0
xmaxot =  1.0
ymaxot =  1.0

xeye =  1.3
yeye = -1.8
zeye =  3.6
;
; Create random data in three space and define a function.
;
rand1 = new((/NUM/), float)
rand2 = new((/NUM/), float)
srand(1)
do i = 0, NUM - 1
rand1(i) = rand()
rand2(i) = rand()
end do
xi = xminin + (xmaxin - xminin) * (rand1 / RAND_MAX)
yi = yminin + (ymaxin - yminin) * (rand2 / RAND_MAX)
zi = (xi - 0.25) * (xi - 0.25) + (yi - 0.50) * (yi - 0.50)

;
; Create the output grid.
;
ii = fspan(0.0, NX - 1, NX)
xo = xminot + ( ii / (NX-1)) * (xmaxot - xminot)
yo = yminot + ( ii / (NY-1)) * (ymaxot - yminot)

;
; Create 2D versions of xo and yo.
;
xo2d   = onedtond(xo, (/NY, NX/))
yo2d   = onedtond(yo, (/NX, NY/))
xo2d!0 = "y"
xo2d!1 = "x"
xo2d   = xo2d(x|:, y|:)                      ; Reorder to NX x NY

xo1d = ndtooned(xo2d)                        ; Convert to 1D
yo1d = ndtooned(yo2d)

output_1d = dspnt2(xi, yi, zi, xo1d, yo1d)   ; Interpolate using dspnt2.
output_2d = onedtond(output_1d, (/NX, NY/))   ; Convert to NX x NY
end
```