OriginC: Interpolation and Gridding

XYZ Gridding by Renka Cline Method(Origin80 SR0)

#include <Origin.h>
#include <OC_nag.h>
int xyz_gridding_in_renka_cline(const vector& vx, const vector& vy, const vector& vz, 
                                const vector& vxGrid, const vector& vyGrid, matrix& mat) 
	Nag_Scat_Struct  comm;
	NagError  fail;
	fail.code = NE_NOERROR;
	fail.print = 0;

	int nSize = vx.GetSize();
        vector<int> triang(7*nSize);
        vector<double> grads(2*nSize);
        int nRows = mat.GetNumRows();
	int nCols = mat.GetNumCols();
        //nag_2d_scat_interpolant (e01sac) has been replaced by nag_2d_triang_interp (e01sjc) at Mark 25
	e01sjc(nSize, vx, vy, vz, triang, grads, &fail);
	if (fail.code != NE_NOERROR)
		printf("Error from e01sjc: %s\n", fail.message);
		return fail.code;
        //nag_2d_scat_eval (e01sbc) has been replaced by nag_2d_triang_eval (e01skc) at Mark 25	
	for(int ii=0; ii < nRows; ii++)
		for(int jj=0; jj < nCols; jj++)
			e01skc(nSize,vx, vy, vz, triang, grads, vxGrid[jj], vyGrid[ii], &mat[jj][ii], &fail);
	if (fail.code != NE_NOERROR && fail.code != NW_VALUE_EXTRAPOLATED)
		printf("Error from e01skc: %s\n", fail.message);
		return fail.code;
	return OE_NOERROR;	

1d Spline and NAG_FREE(Origin80 SR4)

#include <Origin.h>
#include <OC_nag.h> // must include this to see nag related macros and prototypes

// to run this example, you need to have 4 columns in the active
// worksheet and fill col(A) with a few rows by row number and col(B) by same
// number of rows of random values.
// This function will generate results in col(C) and col(D)
void test_e01bac(int nX = 0, int nY = 1, int nXFit = 2, int nYFit = 3)
	Worksheet wks = Project.ActiveLayer();
	// the knots in nX and nY
	Dataset aa(wks, nX);
	Dataset bb(wks, nY);
	vector vx, vy;
	vx = aa;
	vy = bb;
	Nag_Spline spline;
	int m = vx.GetSize();
	NagError fail = {0};
	e01bac(m, vx, vy, &spline, &fail);
	printf("Number of distinct knots = %d\n", m-2);
	printf("Distinct knots located at\n");
	for(int j = 3; j <m+1; j++)
		printf("%8.4f%s", spline.lamda[j], (j-3)%5==4 || j==m? "\n":" ");
	printf("\n\n   J B-spline coeff c\n\n");
	for(j=0; j <m; j++)
		printf("\n   %d  %13.4f\n", j+1, spline.c[j]);

	// put fit into col(nYFit) from x=col(nXFit)
	Dataset fitx(wks, nXFit);
	Dataset fity(wks, nYFit);
	// generate the X from original X by using each mid point, so total m-1 new points
	for(int ii = 0; ii < m - 1; ii++)
		fitx[ii] = (aa[ii] + aa[ii+1]) * 0.5;
	//now we can get the spline fit
	for(j=0; j<fity.GetSize(); j++)
		double yy = NANUM;
		NagError fail = {0};
		e02bbc(fitx[j], &yy, &spline, &fail);
		fity[j] = yy;
	//Free memory allocated by e01bac