Index: /trunk/psModules/src/camera/pmFPAMosaic.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAMosaic.c	(revision 12653)
+++ /trunk/psModules/src/camera/pmFPAMosaic.c	(revision 12654)
@@ -510,34 +510,34 @@
         int yTargetBase = (y0->data.S32[i] - yMin) / yBinTarget; // The base y position in the target frame
 
-	// in the first case, we are just copy a section pixel-by-pixel
-        if ((xBinSource->data.S32[i] == xBinTarget) && 
-	    (yBinSource->data.S32[i] == yBinTarget) && 
-	    (xFlip->data.U8[i] == 0) && 
-	    (yFlip->data.U8[i] == 0)) {
+        // in the first case, we are just copy a section pixel-by-pixel
+        if ((xBinSource->data.S32[i] == xBinTarget) &&
+            (yBinSource->data.S32[i] == yBinTarget) &&
+            (xFlip->data.U8[i] == 0) &&
+            (yFlip->data.U8[i] == 0)) {
             // Let someone else do the hard work
             psImageOverlaySection(mosaic, image, xTargetBase, yTargetBase, "+");
-	    continue;
-        } 
-	
-	// in the second case, there's a difference with the parities, but we don't have to
-	// worry about binning
-	if (xBinSource->data.S32[i] == xBinTarget && yBinSource->data.S32[i] == yBinTarget) {
+            continue;
+        }
+
+        // in the second case, there's a difference with the parities, but we don't have to
+        // worry about binning
+        if (xBinSource->data.S32[i] == xBinTarget && yBinSource->data.S32[i] == yBinTarget) {
             switch (type) {
                 COPY_WITH_PARITY_DIFFERENCE(F32);
                 COPY_WITH_PARITY_DIFFERENCE(U8);
-	      default:
+              default:
                 psAbort("Should never get here.\n");
             }
-	    continue;
-        } 
-	
-	// In the third case, the images are flipped and have different binnnig.
-	// We have to do all of the hard work ourselves
-	switch (type) {
-	    FILL_IN(F32);
-	    FILL_IN(U8);
-	  default:
-	    psAbort("Should never get here.\n");
-	}
+            continue;
+        }
+
+        // In the third case, the images are flipped and have different binnnig.
+        // We have to do all of the hard work ourselves
+        switch (type) {
+            FILL_IN(F32);
+            FILL_IN(U8);
+          default:
+            psAbort("Should never get here.\n");
+        }
     } // Iterating over images
 
@@ -1048,5 +1048,5 @@
         }
         chipRegion = psRegionAlloc(0, 0, 0, 0); // We've cut and paste, so there's no valid trimsec
-	*chipRegion = psRegionForImage (mosaicImage, *chipRegion);
+        *chipRegion = psRegionForImage (mosaicImage, *chipRegion);
     }
     psTrace("psModules.camera", 1, "xBin,yBin: %d,%d\n", xBin, yBin);
@@ -1054,5 +1054,5 @@
     // Set the concepts for the target cell
     psList *sourceCells = psArrayToList(source->cells); // List of cells
-    pmConceptsAverageCells(targetCell, sourceCells, chipRegion, NULL);
+    pmConceptsAverageCells(targetCell, sourceCells, chipRegion, NULL, false);
     {
         psMetadataItem *item = psMetadataLookup(targetCell->concepts, "CELL.X0");
@@ -1182,5 +1182,5 @@
         }
     }
-    pmConceptsAverageCells(targetCell, sourceCells, fpaRegion, NULL);
+    pmConceptsAverageCells(targetCell, sourceCells, fpaRegion, NULL, false);
     {
         psMetadataItem *item = psMetadataLookup(targetCell->concepts, "CELL.X0");
Index: /trunk/psModules/src/concepts/pmConceptsAverage.c
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsAverage.c	(revision 12653)
+++ /trunk/psModules/src/concepts/pmConceptsAverage.c	(revision 12654)
@@ -22,5 +22,5 @@
 // Set a variety of concepts in a cell by averaging over several
 // XXX does not properly set XSIZE, YSIZE
-bool pmConceptsAverageCells(pmCell *target, psList *sources, psRegion *trimsec, psRegion *biassec)
+bool pmConceptsAverageCells(pmCell *target, psList *sources, psRegion *trimsec, psRegion *biassec, bool same)
 {
     PS_ASSERT_PTR_NON_NULL(target, false);
@@ -61,6 +61,10 @@
             xBin    = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN");
             yBin    = psMetadataLookupS32(NULL, cell->concepts, "CELL.YBIN");
-            x0      = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0");
-            y0      = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0");
+
+            if (same) {
+                // Only makes sense to update these if they are the same cell
+                x0  = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0");
+                y0  = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0");
+            }
         } else {
             if (timeSys != psMetadataLookupS32(NULL, cell->concepts, "CELL.TIMESYS")) {
@@ -84,13 +88,15 @@
                 success = false;
             }
-            if (x0 != psMetadataLookupS32(NULL, cell->concepts, "CELL.X0")) {
-                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing CELL.X0 in use: %d vs %d\n",
-                        x0, psMetadataLookupS32(NULL, cell->concepts, "CELL.X0"));
-                success = false;
-            }
-            if (y0 != psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0")) {
-                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing CELL.Y0 in use: %d vs %d\n",
-                        y0, psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0"));
-                success = false;
+            if (same) {
+                if (x0 != psMetadataLookupS32(NULL, cell->concepts, "CELL.X0")) {
+                    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing CELL.X0 in use: %d vs %d\n",
+                            x0, psMetadataLookupS32(NULL, cell->concepts, "CELL.X0"));
+                    success = false;
+                }
+                if (y0 != psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0")) {
+                    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing CELL.Y0 in use: %d vs %d\n",
+                            y0, psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0"));
+                    success = false;
+                }
             }
         }
@@ -123,6 +129,8 @@
     MD_UPDATE(target->concepts, "CELL.XBIN", S32, xBin);
     MD_UPDATE(target->concepts, "CELL.YBIN", S32, yBin);
-    MD_UPDATE(target->concepts, "CELL.X0", S32, x0);
-    MD_UPDATE(target->concepts, "CELL.Y0", S32, y0);
+    if (same) {
+        MD_UPDATE(target->concepts, "CELL.X0", S32, x0);
+        MD_UPDATE(target->concepts, "CELL.Y0", S32, y0);
+    }
 
     // CELL.TIME needs special care
Index: /trunk/psModules/src/concepts/pmConceptsAverage.h
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsAverage.h	(revision 12653)
+++ /trunk/psModules/src/concepts/pmConceptsAverage.h	(revision 12654)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:14 $
+ * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-03-28 23:45:31 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -31,11 +31,15 @@
 /// - CELL.READDIR
 /// - CELL.TIMESYS
+/// - CELL.X0, CELL.Y0
 /// And for others, it takes the "worst" possible value:
 /// - CELL.SATURATION
 /// - CELL.BAD
+/// These concepts are only handled if the cells are all the same cell (mosaicking vs stacking):
+/// - CELL.X0, CELL.Y0
 bool pmConceptsAverageCells(pmCell *target,///< Target cell
                             psList *sources, ///< List of source cells
                             psRegion *trimsec, ///< The new trim section
-                            psRegion *biassec ///< The new bias section
+                            psRegion *biassec, ///< The new bias section
+                            bool same   ///< Are the cells the same cell from different chips?
                            );
 
Index: /trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 12653)
+++ /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 12654)
@@ -398,5 +398,5 @@
         psListAdd(inputCells, PS_LIST_TAIL, readout->parent);
     }
-    bool success = pmConceptsAverageCells(output->parent, inputCells, NULL, NULL);
+    bool success = pmConceptsAverageCells(output->parent, inputCells, NULL, NULL, true);
     psFree(inputCells);
 
