2.1.18.13 ocmath_modified_shepard_interpolant


Description

This subroutine generates a two-dimensional surface interpolating a set of scattered data points, using a modification of Shepard's method.

Syntax

int ocmath_modified_shepard_interpolant( int npts, double * x, double * y, double * f, ocmath_ModShepard_Struct * comm, ocmath_ModShepard_Opt * optional )

Parameters

npts
[input]number of nodes and associated data values.
npts should be larger than or equal to 6
x
[input] array of length n containing the cartesian x coordinates of the nodes
y
[input] array of length n containing the cartesian y coordinates of the nodes
f
[output]array of length n containing the data values in one-to-one correspondence with the nodes.
comm
[output] the structure contains the result and the option of the interpolation.
optional
[input] the user specified option.
optional->nq: the number of points involved in the calculation of the quadratic function.
Constraint: 5 <= nq <= min(40, m-1)
optional->nw: the number of points involved in the calculation of the weight function.
Constraint: 1 <= nw <= min(40, m-1)
When optional == NULL, the default value for nq and nw are:
optional->nq = 13;
optional->nw = 19;

Return

Err_Intp_No_Error: No error occur;

Err_Intp_Mem_Fail: Fails to allocate memory;

Err_Intp_Method: Invalid input for interpolation method

Err_Intp_Invalid_Point: Not enough points or all points collinear

Err_Intp_Duplicate_Point: Duplicate points founded

Examples

EX1

#include <wks2mat.h>
void ocmath_modified_shepard_interpolant_ex1()
{
    double x[9] = { 0.,1.,1.,0.,.25,.5,.75,.5, 1. };
    double y[9] = { 0.,0.,1.,1.,.5,.3,.5,.7 , 0.5};
    double z[9] = { 0, 1, 2, 1, 0.5, 0.59, 1, 0.99, 1.25};
    double px[5] = { .1,.3,.5,.7,.9 };
    double py[5] = { .2,.4,.6,.8, .4 };
    
    int n = 9;

    ocmath_ModShepard_Opt optional;
    ocmath_ModShepard_Struct comm;

    optional.nq = 5;
    optional.nw = 7;
    
    ocmath_modified_shepard_interpolant(n, x, y, z,&comm, &optional);

    int m = 5;
    double pf[5];
    ocmath_modified_shepard_eval(&comm, m, px, py, pf);

    for(int i=0; i<m; i++)
        printf("%g\t%g\t%g\n\n", px[i], py[i], pf[i]);

    ocmath_modshepard_struct_free(&comm);
}

EX2

//assume there are x, y, z data in the first three columns of active worksheet
//this example will create a new matrix storing gridding data
#include <wks2mat.h>
void ocmath_modified_shepard_interpolant_ex2()
{
    Worksheet    wks = Project.ActiveLayer();
    if(!wks)
    {
        out_str("found no active worksheet");
        return;
    }
    Dataset    dsX(wks, 0);
    Dataset    dsY(wks, 1);
    Dataset dsZ(wks, 2);
    int npts = dsX.GetSize();
    vector vX = dsX;
    vector vY = dsY;
    vector vZ = dsZ;
    
    ocmath_ModShepard_Opt optional;
    ocmath_ModShepard_Struct comm;

    optional.nq = 5;
    optional.nw = 7;
    
    ocmath_modified_shepard_interpolant(npts, vX, vY, vZ, &comm, &optional);
    
    //set X and Y of the gridding
    double dXMin, dXMax, dYMin, dYMax;
    vX.GetMinMax(dXMin, dXMax);
    vY.GetMinMax(dYMin, dYMax);
    
    //perform random matrix conversion using Kriging algorithm
    int nRows = 100;
    int nCols = 50;
    matrix    mZ(nRows, nCols);
    vector    vEvalX(nRows * nCols);
    vector    vEvalY(nRows * nCols);
    ocmath_mat_to_regular_xyz(NULL, nRows, nCols, dXMin, dXMax, dYMin, dYMax, vEvalX, vEvalY, NULL, true);
    ocmath_modified_shepard_eval(&comm, nRows * nCols, vEvalX, vEvalY, mZ);    
    ocmath_modshepard_struct_free(&comm);
        
    //create Matrix storing the result
    MatrixLayer    mResultLayer;
    mResultLayer.Create();
    Matrix    matResult(mResultLayer);
    matResult = mZ;
    MatrixObject mo = mResultLayer.MatrixObjects(0);
    mo.SetXY(dXMin, dYMin, dXMax, dYMax);//set X and Y range of Matrix
}

Remark

See Also

ocmath_modshepard_struct_free

Header to Include

wks2mat.h

Reference