Index: /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_fitslit.c
===================================================================
--- /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_fitslit.c	(revision 40772)
+++ /branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_fitslit.c	(revision 40773)
@@ -76,2 +76,28 @@
 }
 
+void fitflux () {
+    // calculate elements of the chi-square for this row:
+
+    double R = 0.0, P = 0.0, P2 = 0.0, f = 0.0, fp = 0.0;
+    double wt = 1.0;
+
+    for (int ix = 0; ix < Nx; ix++) {
+      
+      // skip NAN / Inf pixels in either window or slit
+      if (!isfinite(Fwind[ix + iy*Nx])) continue;
+      if (!isfinite(Fprof[ix + iy*Nx])) continue;
+
+      float fxy = Fwind[ix + iy*Nx];
+      float pxy = Fprof[ix + iy*Nx];
+
+      R  += wt; 
+      P  += pxy*wt;
+      P2 += pxy*pxy*wt;
+      f  += fxy*wt;
+      fp += fxy*pxy*wt;
+    }
+
+    double det = R*P2 - P*P;
+    double S = (P2*f - P*fp) / det;
+    double F = (R*fp - P*f) / det;
+}
