Index: trunk/Ohana/src/opihi/lib.data/spline.c
===================================================================
--- trunk/Ohana/src/opihi/lib.data/spline.c	(revision 41341)
+++ trunk/Ohana/src/opihi/lib.data/spline.c	(revision 42332)
@@ -2,5 +2,5 @@
 
 /* construct the natural spline for x, y in y2 */
-void spline_construct_flt (float *x, float *y, int N, float *y2) {
+void spline_construct_flt (float *x, float *y, int N, float *y2, float dyLower, float dyUpper) {
 
   int i;
@@ -67,5 +67,5 @@
 
 /* construct the natural spline for x, y in y2 */
-void spline_construct_dbl (opihi_flt *x, opihi_flt *y, int N, opihi_flt *y2) {
+void spline_construct_dbl (opihi_flt *x, opihi_flt *y, int N, opihi_flt *y2, opihi_flt dyLower, opihi_flt dyUpper) {
 
   int i;
@@ -77,5 +77,10 @@
   ALLOCATE (tmp, opihi_flt, N);
 
-  y2[0] = tmp[0] = 0.0;
+  if (isnan(dyLower)) {
+    y2[0] = tmp[0] = 0.0;
+  } else {
+    y2[0] = -0.5;
+    tmp[0]   = (3.0/(x[1]-x[0])) * ((y[1]-y[0])/(x[1]-x[0]) - dyLower);
+  }
   
   for (i = 1; i < N-1; i++) {
@@ -86,8 +91,16 @@
     tmp[i] = (6.0 * tmp[i] / (x[i+1] - x[i-1]) - dx*tmp[i-1]) / dy;
   }
+
+  if (isfinite(dyUpper)) {
+    opihi_flt qn = 0.5;
+    tmp[N-1] = (3.0/(x[N-1]-x[N-2])) * (dyUpper - (y[N-1]-y[N-2])/(x[N-1]-x[N-2]));
+    y2[N-1] = (tmp[N-1] - (qn * tmp[N-2])) / ((qn * y2[N-2]) + 1.0);
+  } else {
+    y2[N-1] = 0;
+  }
   
-  y2[N-1] = 0;
-  for (i = N-2; i >= 1; i--)
+  for (i = N-2; i >= 0; i--) {
     y2[i] = y2[i]*y2[i+1] + tmp[i];
+  }
 
   free (tmp);
