# title: demo of spline using apache math library.
# label: spline demo
# Note this appears to yield a result different than IDL's result.

from org.apache.commons.math.analysis.interpolation import SplineInterpolator

setLayoutOverplot(2)

x= dataset( [ 2., 3., 4., 5., 6., 7. ] )
y= dataset( [ 1,  3,  4,  3,  5,  3, ] )
#y= (x-3)**2
plot( 0, x, y, title='Original Data' )

si= SplineInterpolator()
psf= si.interpolate( x, y )

xx= findgen(100)/20 + 2.
yy= fltarr(100)
for i in range(100):
   yy[i]= psf.value(xx[i].value())

plot( 1, xx, yy, title='Spline Interpolation' )

bind( dom.plots[0].xaxis, 'range', dom.plots[1].xaxis, 'range' ) 
bind( dom.plots[0].yaxis, 'range', dom.plots[1].yaxis, 'range' ) 
