2
// Copyright (C) 2009 Alan W. Irwin
4
// This file is part of PLplot.
6
// PLplot is free software; you can redistribute it and/or modify
7
// it under the terms of the GNU Library General Public License as published
8
// by the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
11
// PLplot is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU Library General Public License for more details.
16
// You should have received a copy of the GNU Library General Public License
17
// along with PLplot; if not, write to the Free Software
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
// Provenance: This code was originally developed under the GPL as part of
21
// the FreeEOS project (revision 121). This code has been converted from
22
// Fortran to C with the aid of f2c and relicensed for PLplot under the LGPL
23
// with the permission of the FreeEOS copyright holder (Alan W. Irwin).
25
# define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
26
# define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
28
//int dsplint(double *xa, double *ya, double *y2a,
29
// int n, double x, double *y, double *dy, double *d2y)
30
int dsplint( double *xa, double *ya, double *y2a,
31
int n, double x, double *y )
35
static int nsave = 0, khi, klo;
40
// evaluate spline = y and its derivatives dy and d2y at x given
41
// xa, ya, y2a from dspline.
42
// Parameter adjustments
50
// if call with different n value, then redo range
65
// optimize range assuming continuous (ascending or
66
// descending x calls.
69
// x is descending so try next range.
72
// if x smaller than next range try lower limit.
82
else if ( xa[khi] <= x )
84
// x is ascending so try next range.
86
i__1 = khi, i__2 = n - 1;
87
klo = MIN( i__1, i__2 );
89
// if x larger than next range try upper limit.
100
while ( khi - klo > 1 )
102
k = ( khi + klo ) / 2;
112
h__ = xa[khi] - xa[klo];
117
a = ( xa[khi] - x ) / h__;
118
b = ( x - xa[klo] ) / h__;
119
*y = a * ya[klo] + b * ya[khi] + ( a * ( a * a - 1. ) * y2a[klo] + b * ( b *
120
b - 1. ) * y2a[khi] ) * ( h__ * h__ ) / 6.;
121
// *dy = (-ya[klo] + ya[khi] + (-(a * 3. * a - 1.) * y2a[klo] + (b * 3. * b
122
// - 1.) * y2a[khi]) * (h__ * h__) / 6.) / h__;
123
//d2y = a * y2a[klo] + b * y2a[khi];