[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[no subject]



I have tried several things, including changing the size of the look up
tables but that has very little influence on the results. The same for
changing the type of the tables from double to float.

Any suggestions (also pointers to books on this subject) are welcome,


Jaap


The code (based on an old -- freeware -- pascal version of numerical recipies):

double getval_short(TBL *tab, double xval)
{
	unsigned long index,mid,lo,up,n;
	int ascnd;
	double top,bott,rico;

	/* first check high and low points */	
	if (xval <= tab->x[0])
		return tab->y[0];
	else if (xval >= tab->x[(tab->points) - 1])
		return tab->y[(tab->points) - 1];

	/* Find position in array: x[index] < xval < x[index +1]*/
	n = tab->points;
	lo = -1; up = n;

	ascnd = (tab->x[n - 1] >= tab->x[0]);
	while (up - lo > 1){
		mid = (up + lo) >> 1;
		if (xval >= tab->x[mid] == ascnd)
			lo = mid;
		else
			up = mid;
	}
	if ( xval == tab->x[0])  index = 0;
	else if (xval == tab->x[n-1]) index =  n - 2;
	else index = lo;

	/* linear interpolation */
	top = (tab->y[index + 1] - tab->y[index]);
	bott = (tab->x[index + 1] - tab->x[index]);
	rico =  top/bott;
	return (rico * (xval - tab->x[index])) + tab->y[index];
}

-- 
--------------------------------------------------------------
Jaap Schellekens                E-mail:         schj@geo.vu.nl
Hydro(geo)logy Dept.            Fax:            ++31 20 6462457
Inst. of Earth Sc.              Voice:          ++31 20 4447287
Vrije Universiteit
De Boelelaan 1085               use finger schj@flow.geo.vu.nl
                                for extra information
1081 HV Amsterdam NL            See also:   http://flow.geo.vu.nl



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []