Index: trunk/ppStack/src/ppStackSources.c
===================================================================
--- trunk/ppStack/src/ppStackSources.c	(revision 23242)
+++ trunk/ppStack/src/ppStackSources.c	(revision 23573)
@@ -9,7 +9,9 @@
 //#define TESTING                         // Enable debugging output
 
+#ifdef TESTING
 // Size of fake image; set by hand because it's trouble to get it from other places
 #define FAKE_COLS 4861
 #define FAKE_ROWS 4913
+#endif
 
 #ifdef TESTING
@@ -53,13 +55,17 @@
 
 
-float ppStackSourcesTransparency(const psArray *sourceLists, psVector *inputMask,
-                                 const pmFPAview *view, const pmConfig *config)
+bool ppStackSourcesTransparency(ppStackOptions *options, const pmFPAview *view, const pmConfig *config)
 {
-    PS_ASSERT_ARRAY_NON_NULL(sourceLists, NAN);
-    PS_ASSERT_VECTOR_NON_NULL(inputMask, NAN);
-    PS_ASSERT_VECTOR_TYPE(inputMask, PS_TYPE_U8, NAN);
-    PS_ASSERT_VECTOR_SIZE(inputMask, sourceLists->n, NAN);
-    PS_ASSERT_PTR_NON_NULL(view, NAN);
-    PS_ASSERT_PTR_NON_NULL(config, NAN);
+    PS_ASSERT_PTR_NON_NULL(options, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psArray *sourceLists = options->sourceLists; // Source lists for each input
+    psVector *inputMask = options->inputMask; // Mask for inputs
+
+    PS_ASSERT_ARRAY_NON_NULL(sourceLists, false);
+    PS_ASSERT_VECTOR_NON_NULL(inputMask, false);
+    PS_ASSERT_VECTOR_TYPE(inputMask, PS_TYPE_U8, false);
+    PS_ASSERT_VECTOR_SIZE(inputMask, sourceLists->n, false);
 
 #if defined(TESTING) && 0
@@ -100,5 +106,5 @@
     if (!airmassZP) {
         psError(PS_ERR_UNKNOWN, false, "Unable to find ZP.AIRMASS in recipe.");
-        return NAN;
+        return false;
     }
 
@@ -139,5 +145,5 @@
                     exptime, airmass, expFilter);
             psFree(zp);
-            return NAN;
+            return false;
         }
 
@@ -149,10 +155,10 @@
                         "Unable to find airmass term (ZP.AIRMASS) for filter %s", filter);
                 psFree(zp);
-                return NAN;
+                return false;
             }
         } else if (strcmp(filter, expFilter) != 0) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Filters don't match: %s vs %s", filter, expFilter);
             psFree(zp);
-            return NAN;
+            return false;
         }
 
@@ -160,4 +166,6 @@
         sumExpTime += exptime;
     }
+
+    options->sumExposure = sumExpTime;
 
     psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches
@@ -165,5 +173,5 @@
         psError(PS_ERR_UNKNOWN, false, "Unable to match sources");
         psFree(zp);
-        return NAN;
+        return false;
     }
 
@@ -177,5 +185,5 @@
     if (!trans) {
         psError(PS_ERR_UNKNOWN, false, "Unable to measure transparencies");
-        return NAN;
+        return false;
     }
 
@@ -186,5 +194,5 @@
     for (int i = 0; i < trans->n; i++) {
         if (!isfinite(trans->data.F32[i])) {
-            inputMask->data.U8[i] = PPSTACK_MASK_CAL;
+            inputMask->data.U8[i] |= PPSTACK_MASK_CAL;
         }
     }
@@ -223,4 +231,5 @@
     // m_0 = m_1 + zp_1 + trans_1 - c1 * airmass_0 - 2.5log(t_0)
     // We don't need to know the magnitude zero point for the filter, since it cancels out
+    options->norm = psVectorAlloc(num, PS_TYPE_F32);
     for (int i = 0; i < num; i++) {
         if (!isfinite(trans->data.F32[i])) {
@@ -229,4 +238,5 @@
         psArray *sources = sourceLists->data[i]; // Sources of interest
         float magCorr = airmassTerm - 2.5*log10(sumExpTime) - zp->data.F32[i] - trans->data.F32[i];
+        options->norm->data.F32[i] = magCorr;
         psLogMsg("ppStack", PS_LOG_INFO, "Applying magnitude correction to image %d: %f\n", i, magCorr);
 
@@ -248,5 +258,5 @@
             psError(PS_ERR_UNKNOWN, false, "Unable to match sources");
             psFree(zp);
-            return NAN;
+            return false;
         }
         psVector *trans = pmSourceMatchRelphot(matches, zp, iter, tol, starLimit, transIter, transRej,
@@ -259,4 +269,4 @@
 #endif
 
-    return sumExpTime;
+    return true;
 }
