Index: /trunk/Ohana/src/opihi/cmd.data/imspline_apply.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/imspline_apply.c	(revision 42331)
+++ /trunk/Ohana/src/opihi/cmd.data/imspline_apply.c	(revision 42332)
@@ -77,5 +77,5 @@
       Tx1[i] = spline_apply_flt (Tyc, Ty1, Ty2, Ny, y);
     }
-    spline_construct_flt (Txc, Tx1, Nx, Tx2);
+    spline_construct_flt (Txc, Tx1, Nx, Tx2, NAN, NAN);
 
     /* apply x-dir spline to new image */
Index: /trunk/Ohana/src/opihi/cmd.data/imspline_construct.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/imspline_construct.c	(revision 42331)
+++ /trunk/Ohana/src/opihi/cmd.data/imspline_construct.c	(revision 42332)
@@ -55,5 +55,5 @@
     }
   
-    spline_construct_flt (Tx, Ty, Ny, Ty2);
+    spline_construct_flt (Tx, Ty, Ny, Ty2, NAN, NAN);
   
     /* copy derivatives to output buffer */
Index: /trunk/Ohana/src/opihi/cmd.data/spline_commands.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/spline_commands.c	(revision 42331)
+++ /trunk/Ohana/src/opihi/cmd.data/spline_commands.c	(revision 42332)
@@ -15,6 +15,19 @@
 int spline_create (int argc, char **argv) {
 
-  int i;
+  int i, N;
   Vector *xvec, *yvec;
+
+  double dyLower = NAN;
+  double dyUpper = NAN;
+  if ((N = get_argument (argc, argv, "-dyLower"))) {
+    remove_argument (N, &argc, argv);
+    dyLower = atof(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-dyUpper"))) {
+    remove_argument (N, &argc, argv);
+    dyUpper = atof(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
 
   if (argc != 4) {
@@ -43,5 +56,5 @@
   }    
 
-  spline_construct_dbl (myspline->xk, myspline->yk, myspline->Nknots, myspline->y2);
+  spline_construct_dbl (myspline->xk, myspline->yk, myspline->Nknots, myspline->y2, dyLower, dyUpper);
   return TRUE;
 }
Index: /trunk/Ohana/src/opihi/include/data.h
===================================================================
--- /trunk/Ohana/src/opihi/include/data.h	(revision 42331)
+++ /trunk/Ohana/src/opihi/include/data.h	(revision 42332)
@@ -133,7 +133,7 @@
 
 /* in spline.c */
-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);
 float spline_apply_flt (float *x, float *y, float *y2, int N, float X);
-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);
 opihi_flt spline_apply_dbl (opihi_flt *x, opihi_flt *y, opihi_flt *y2, int N, opihi_flt X);
 
Index: /trunk/Ohana/src/opihi/lib.data/spline.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.data/spline.c	(revision 42331)
+++ /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);
