Index: /trunk/psModules/src/detrend/pmShutterCorrection.c
===================================================================
--- /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 8885)
+++ /trunk/psModules/src/detrend/pmShutterCorrection.c	(revision 8886)
@@ -61,4 +61,5 @@
 
 #include "pmShutterCorrection.h"
+#include "psVectorBracket.h"
 
 static void pmShutterCorrParsFree (pmShutterCorrPars *pars)
@@ -89,6 +90,7 @@
 
     pmShutterCorrPars *pars = pmShutterCorrParsAlloc ();
-
-    N = exptime->n;
+    psPolynomial1D *line = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1);
+
+    int N = exptime->n;
     // ASSERT (N >> 5)
 
@@ -111,7 +113,6 @@
 
     // fit a line and extrapolate the fit to 0.0
-    psPolynomial1D *line = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1);
-    line = psVectorFitPolynomial1D (line, NULL, 0, tmpY, NULL, tmpX);
-    ratio = psPolynomial1DEval (line, 0.0) / pars->scale;
+    psVectorFitPolynomial1D (line, NULL, 0, tmpY, NULL, tmpX);
+    float ratio = psPolynomial1DEval (line, 0.0) / pars->scale;
 
     // XXX we need a sanity check:
@@ -122,8 +123,8 @@
 
     // find two points bracketing the value counts = A (1 + dTk/dTo) / 2 = pars->scale (1 + ratio) / 2
-    value = pars->scale * (1 + ratio) / 2.0;
-
-    Nm = psVectorBracket (exptime, value, (ratio < 1.0));
-    Np = (Nm == N - 1) ? Nm - 1 : Nm + 1;
+    float value = pars->scale * (1 + ratio) / 2.0;
+
+    int Nm = psVectorBracket (exptime, value, (ratio < 1.0));
+    int Np = (Nm == N - 1) ? Nm - 1 : Nm + 1;
 
     tmpX->data.F64[0] = counts->data.F64[Nm];
@@ -133,5 +134,4 @@
 
     // fit a line and extrapolate the fit to counts = A (1 + dTk/dTo) : exptime = dTo
-    psPolynomial1D *line = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1);
     line = psVectorFitPolynomial1D (line, NULL, 0, tmpY, NULL, tmpX);
     pars->offref = psPolynomial1DEval (line, value);
@@ -154,5 +154,5 @@
 
     for (int i = 0; i < exptime->n; i++) {
-        value = 1.0 / (exptime->data.F32[i] + offref);
+        float value = 1.0 / (exptime->data.F32[i] + offref);
         x->data.F32[i] = exptime->data.F32[i] * value;
         y->data.F32[i] = value;
@@ -171,5 +171,5 @@
     pmShutterCorrPars *pars = pmShutterCorrParsAlloc ();
 
-    pars->offref = guess->offref;
+    pars->offref = offref;
     pars->scale  = line->coeff[1][0];
     pars->offset = line->coeff[0][1] / line->coeff[1][0];
@@ -235,5 +235,5 @@
     }
 
-    fitStatus = psMinimizeLMChi2(myMin, covar, params, constrain, x, y, yErr, pmShutterCorrectionModel);
+    psMinimizeLMChi2(myMin, covar, params, constrain, x, y, yErr, pmShutterCorrectionModel);
 
     pmShutterCorrPars *pars = pmShutterCorrParsAlloc ();
Index: /trunk/psModules/src/objects/Makefile.am
===================================================================
--- /trunk/psModules/src/objects/Makefile.am	(revision 8885)
+++ /trunk/psModules/src/objects/Makefile.am	(revision 8886)
@@ -22,5 +22,6 @@
      pmPSF_IO.c \
      pmPSFtry.c \
-     pmGrowthCurve.c
+     pmGrowthCurve.c \
+     psVectorBracket.c
 
 EXTRA_DIST = \
@@ -45,5 +46,6 @@
      pmPSF_IO.h \
      pmPSFtry.h \
-     pmGrowthCurve.h
+     pmGrowthCurve.h \
+     psVectorBracket.h
 
 CLEANFILES = *~
Index: /trunk/psModules/src/objects/pmGrowthCurve.c
===================================================================
--- /trunk/psModules/src/objects/pmGrowthCurve.c	(revision 8885)
+++ /trunk/psModules/src/objects/pmGrowthCurve.c	(revision 8886)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-09-15 09:49:01 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-09-22 21:35:34 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,5 @@
 #include <pslib.h>
 #include "pmGrowthCurve.h"
+#include "psVectorBracket.h"
 
 static void pmGrowthCurveFree (pmGrowthCurve *growth)
@@ -57,79 +58,2 @@
 }
 
-// return the last entry below or first entry above key value
-int psVectorBracket (psVector *index, psF32 key, bool above)
-{
-
-    int N;
-    int Nlo = 0;
-    int Nhi = index->n;
-
-    if (above) {
-        while (Nhi - Nlo > 10) {
-            N = 0.5*(Nlo + Nhi);
-            if (index->data.F32[N] > key) {
-                Nhi = N;
-            } else {
-                Nlo = N - 1;
-            }
-        }
-        // at this point, index[Nhi] > key >= index[Nlo]
-        N = Nlo;
-        while ((index->data.F32[N] <= key) && (N < Nhi)) {
-            N++;
-        }
-        return (N);
-    }
-    while (Nhi - Nlo > 10) {
-        N = 0.5*(Nlo + Nhi);
-        if (index->data.F32[N] < key) {
-            Nlo = N;
-        } else {
-            Nhi = N + 1;
-        }
-    }
-    // at this point, index[Nhi] >= key > index[Nlo]
-    N = Nhi;
-    while ((index->data.F32[N] >= key) && (N > Nlo)) {
-        N--;
-    }
-    return (N);
-}
-
-// search for the bins bounding key in index, interpolate the corresponding values
-psF32 psVectorInterpolate (psVector *index, psVector *value, psF32 key)
-{
-
-    int n0 = 0;
-    int n1 = 0;
-
-    // extrapolate at ends
-    if (key < index->data.F32[0]) {
-        n0 = 0;
-        n1 = 1;
-    }
-
-    // extrapolate at ends
-    if (key > index->data.F32[index->n-1]) {
-        n0 = index->n-2;
-        n1 = index->n-1;
-    }
-
-    if (n1 == 0) {
-        n0 = psVectorBracket (index, key, FALSE);
-        n1 = n0 + 1;
-    }
-
-    if (n0 == index->n-1) {
-        n1 = n0;
-        n0 = n1 - 1;
-    }
-
-    float dy = value->data.F32[n1] - value->data.F32[n0];
-    float dx = index->data.F32[n1] - index->data.F32[n0];
-    float dX = key - index->data.F32[n0];
-    float dY = dX * (dy/dx);
-    float result = value->data.F32[n0] + dY;
-    return result;
-}
-
Index: /trunk/psModules/src/psmodules.h
===================================================================
--- /trunk/psModules/src/psmodules.h	(revision 8885)
+++ /trunk/psModules/src/psmodules.h	(revision 8886)
@@ -44,4 +44,5 @@
 #include <pmSubtractBias.h>
 #include <pmDetrendDB.h>
+#include <pmShutterCorrection.h>
 // #include <pmSubtractSky.h>
 
@@ -70,4 +71,5 @@
 #include <pmModelGroup.h>
 #include <pmSourcePhotometry.h>
+#include <psVectorBracket.h>
 
 #endif
