Index: trunk/ppMerge/src/ppMergeMask.c
===================================================================
--- trunk/ppMerge/src/ppMergeMask.c	(revision 21244)
+++ trunk/ppMerge/src/ppMergeMask.c	(revision 21365)
@@ -6,6 +6,6 @@
  *
  *  @author IfA
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-01 21:43:05 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-06 02:44:31 $
  *  Copyright 2009 Institute for Astronomy, University of Hawaii
  */
@@ -38,9 +38,8 @@
     float smoothScale = psMetadataLookupF32(&mdok, config->arguments, "MASK.SMOOTH.SCALE"); ///< Radius to grow mask
 
-    psImageMaskType markVal;
-    psImageMaskType maskValRaw;
-    if (!pmConfigMaskSetBits (&maskValRaw, &markVal, config)) {
-	psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
-	return false;
+    psImageMaskType markVal, maskValRaw;
+    if (!pmConfigMaskSetBits(&maskValRaw, &markVal, config)) {
+        psError(PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
+        return false;
     }
 
@@ -48,23 +47,23 @@
     psImageMaskType maskValOut = pmConfigMaskGet (maskOutName, config);
     if (!maskValOut) {
-	psError (PS_ERR_UNKNOWN, true, "Undefined output mask bit value");
-	return false;
-    }
-    
-    psStats *statistics = psStatsAlloc(meanStat | stdevStat); ///< Statistics for background
+        psError (PS_ERR_UNKNOWN, true, "Undefined output mask bit value");
+        return false;
+    }
+
+    psStats *statistics = psStatsAlloc(meanStat | stdevStat); // Statistics for background
 
     psString outName = ppMergeOutputFile(config); ///< Name of output file
     pmChip *outChip = pmFPAfileThisChip(config->files, view, outName); ///< Output chip
     psFree(outName);
-    
+
     int numCells = 1;
     if (chipStats) {
-	// count the number of active cells for this chip:
-	numCells = 0;
-	for (int i = 0; i < outChip->cells->n; i++) {
-	    pmCell *cell = outChip->cells->data[i];
-	    if (!cell->process) continue;
-	    numCells ++;
-	}
+        // count the number of active cells for this chip:
+        numCells = 0;
+        for (int i = 0; i < outChip->cells->n; i++) {
+            pmCell *cell = outChip->cells->data[i];
+            if (!cell->process) continue;
+            numCells ++;
+        }
     }
 
@@ -85,7 +84,7 @@
         while ((inCell = pmFPAviewNextCell(inView, inFPA, 1))) {
 
-	    // the output FPA structure carries the information about which cells to process
-            pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); ///< Output cell
-	    if (!outCell->process) continue;
+            // the output FPA structure carries the information about which cells to process
+            pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); // Output cell
+            if (!outCell->process) continue;
 
             pmHDU *hdu = pmHDUFromCell(inCell); ///< HDU for cell
@@ -150,6 +149,6 @@
                 int y = pixel / numCols;
                 if (mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValRaw)) continue;
-		if (outMask && (outMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValOut)) continue;
-		if (!isfinite(image->data.F32[y][x])) continue;
+                if (outMask && (outMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValOut)) continue;
+                if (!isfinite(image->data.F32[y][x])) continue;
 
                 values->data.F32[valueIndex++] = image->data.F32[y][x];
@@ -165,9 +164,9 @@
                 }
 
-		float mean = psStatsGetValue(statistics, meanStat);
-		float stdev = psStatsGetValue(statistics, stdevStat);
-
-		// this function increments the count for each suspect pixel in each input plane
-		// maskValRaw is used to test for valid input pixels
+                float mean = psStatsGetValue(statistics, meanStat);
+                float stdev = psStatsGetValue(statistics, stdevStat);
+
+                // this function increments the count for each suspect pixel in each input plane
+                // maskValRaw is used to test for valid input pixels
                 if (!pmMaskFlagSuspectPixels(outRO, readout, mean, stdev, maskSuspect, maskValRaw)) {
                     psError(PS_ERR_UNKNOWN, false, "Unable to find suspect values in file %d", i);
@@ -197,8 +196,7 @@
             inView->cell = -1;
             while ((inCell = pmFPAviewNextCell(inView, inFPA, 1))) {
-
-		// the output FPA structure carries the information about which cells to process
-		pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); ///< Output cell
-		if (!outCell->process) continue;
+                // the output FPA structure carries the information about which cells to process
+                pmCell *outCell = pmFPAfileThisCell(config->files, inView, "PPMERGE.OUTPUT.MASK"); // Output cell
+                if (!outCell->process) continue;
 
                 pmHDU *hdu = pmHDUFromCell(inCell); ///< HDU for cell
@@ -210,8 +208,8 @@
                 pmReadout *outRO = pmFPAfileThisReadout(config->files, inView, "PPMERGE.OUTPUT.MASK");
 
-		float mean = psStatsGetValue(statistics, meanStat);
-		float stdev = psStatsGetValue(statistics, stdevStat);
-
-		if (!pmMaskFlagSuspectPixels(outRO, readout, mean, stdev, maskSuspect, maskValRaw)) {
+                float mean = psStatsGetValue(statistics, meanStat);
+                float stdev = psStatsGetValue(statistics, stdevStat);
+
+                if (!pmMaskFlagSuspectPixels(outRO, readout, mean, stdev, maskSuspect, maskValRaw)) {
                     psError(PS_ERR_UNKNOWN, false, "Unable to find suspect values in file %d", i);
                     goto MERGE_MASK_ERROR;
@@ -243,6 +241,6 @@
     while ((outCell = pmFPAviewNextCell(outView, outFPA, 1))) {
 
-	// skip inactive cells
-	if (!outCell->process) continue;
+        // skip inactive cells
+        if (!outCell->process) continue;
 
         pmHDU *hdu = pmHDUFromCell(outCell); ///< HDU for cell
@@ -254,12 +252,12 @@
         pmReadout *outRO = outCell->readouts->data[0]; ///< Output readout
 
-	if (smoothSuspect) {
-	    // XXX test output of suspect pixel image
-	    psImage *suspects = psMetadataLookupPtr(NULL, outRO->analysis, PM_MASK_ANALYSIS_SUSPECT); ///< Suspect img
-	    assert (suspects);
-	    psImageSmooth (suspects, smoothScale, 3); ///< extend smoothing region to 3-sigma
-	}
-
-	// set the bad pixels to the value 'maskVal'
+        if (smoothSuspect) {
+            // XXX test output of suspect pixel image
+            psImage *suspects = psMetadataLookupPtr(NULL, outRO->analysis, PM_MASK_ANALYSIS_SUSPECT); // Suspect img
+            assert (suspects);
+            psImageSmooth (suspects, smoothScale, 3); // extend smoothing region to 3-sigma
+        }
+
+        // set the bad pixels to the value 'maskVal'
         if (!pmMaskIdentifyBadPixels(outRO, maskValOut, maskBad, maskMode)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to mask bad pixels");
@@ -352,9 +350,9 @@
     assert(config);
 
-    bool mdok;                          ///< Status of MD lookup
-    int numFiles = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); ///< Number of inputs
-    bool haveMasks = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.MASKS"); ///< Do we have masks?
-    bool haveWeights = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.WEIGHTS"); ///< Do we have weights?
-    int iter = psMetadataLookupS32(NULL, config->arguments, "ITER"); ///< Number of rejection iterations
+    bool mdok;                          // Status of MD lookup
+    int numFiles = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs
+    bool haveMasks = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.MASKS"); // Do we have masks?
+    bool haveVariances = psMetadataLookupBool(&mdok, config->arguments, "INPUTS.VARIANCES"); // Got variances?
+    int iter = psMetadataLookupS32(NULL, config->arguments, "ITER"); // Number of rejection iterations
 
     PS_ASSERT_INT_POSITIVE(iter, false);
@@ -375,7 +373,7 @@
         psFree(masks);
     }
-    if (haveWeights) {
-        psArray *weights = ppMergeFileDataLevel(config, "PPMERGE.INPUT.WEIGHT", PM_FPA_LEVEL_READOUT);
-        psFree(weights);
+    if (haveVariances) {
+        psArray *variances = ppMergeFileDataLevel(config, "PPMERGE.INPUT.VARIANCE", PM_FPA_LEVEL_READOUT);
+        psFree(variances);
     }
 
@@ -417,21 +415,21 @@
         }
 
-	if (outChip->data_exists) {
-	    psList *inChips = psListAlloc(NULL);
-	    for (int i=0; i < numFiles; i++) {
-		pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); ///< Input file
-		pmChip *chip = pmFPAviewThisChip(view, file->fpa);
-		psListAdd(inChips, PS_LIST_TAIL, chip);
-	    }
-
-	    // XXX I need to call pmConfigMaskWriteHeader for the PHU somewhere, after it is created!
-
-	    if (!pmConceptsAverageChips(outChip, inChips, true)) {
-		psError(PS_ERR_UNKNOWN, false, "Unable to average Chip concepts.");
-		psFree(inChips);
-		goto PPMERGE_MASK_ERROR;
-	    }
-	    psFree(inChips);
-	}
+        if (outChip->data_exists) {
+            psList *inChips = psListAlloc(NULL);
+            for (int i=0; i < numFiles; i++) {
+                pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); // Input file
+                pmChip *chip = pmFPAviewThisChip(view, file->fpa);
+                psListAdd(inChips, PS_LIST_TAIL, chip);
+            }
+
+            // XXX I need to call pmConfigMaskWriteHeader for the PHU somewhere, after it is created!
+
+            if (!pmConceptsAverageChips(outChip, inChips, true)) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to average Chip concepts.");
+                psFree(inChips);
+                goto PPMERGE_MASK_ERROR;
+            }
+            psFree(inChips);
+        }
         if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
             goto PPMERGE_MASK_ERROR;
