Index: trunk/psastro/src/psastroUtils.c
===================================================================
--- trunk/psastro/src/psastroUtils.c	(revision 12806)
+++ trunk/psastro/src/psastroUtils.c	(revision 20804)
@@ -20,60 +20,75 @@
 
     float pixelScaleUse = 1.0, pixelScale1 = 1.0,  pixelScale2 = 1.0,  pixelScale = 1.0;
+    psVector *oldScale = psVectorAllocEmpty (fpa->chips->n, PS_TYPE_F32);
 
     char *option = psMetadataLookupStr (NULL, recipe, "PSASTRO.COMMON.SCALE.OPTION");
     if (option == NULL) {
-	psError(PSASTRO_ERR_DATA, false, "no choice set for common scale option\n");
-	return false;
+        psError(PSASTRO_ERR_DATA, false, "no choice set for common scale option\n");
+        return false;
     }
 
     bool useExternal = true;
+    int nobj = 0;
 
     // find the min or max scale chip
     if (!strcasecmp (option, "MIN") || !strcasecmp (option, "MAX")) {
 
-	bool useMax = !strcasecmp (option, "MAX");
-	pixelScaleUse = (useMax) ? FLT_MIN : FLT_MAX;
-
-	for (int i = 0; i < fpa->chips->n; i++) {
-	    pmChip *chip = fpa->chips->data[i];
-	    if (!chip->process || !chip->file_exists) { continue; }
-	    if (!chip->toFPA) { continue; }
-
-	    pixelScale1 = hypot (chip->toFPA->x->coeff[1][0], chip->toFPA->x->coeff[0][1]);
-	    pixelScale2 = hypot (chip->toFPA->y->coeff[1][0], chip->toFPA->y->coeff[0][1]);
-	    pixelScale = 0.5*(pixelScale1 + pixelScale2);
-	    
-	    pixelScaleUse = (useMax) ? PS_MAX (pixelScale, pixelScaleUse) : PS_MIN (pixelScale, pixelScaleUse);
-	}
-	useExternal = false;
-    }
+        bool useMax = !strcasecmp (option, "MAX");
+        pixelScaleUse = (useMax) ? FLT_MIN : FLT_MAX;
+
+        for (int i = 0; i < fpa->chips->n; i++) {
+            pmChip *chip = fpa->chips->data[i];
+            if (!chip->process || !chip->file_exists) { continue; }
+            if (!chip->toFPA) { continue; }
+
+	    if (chip->cells->n == 0) { continue; }
+	    pmCell *cell = chip->cells->data[0];
+            if (!cell->process || !cell->file_exists) { continue; }
+
+	    if (cell->readouts->n == 0) { continue; }
+	    pmReadout *readout = cell->readouts->data[0];
+	    if (! readout->data_exists) { continue; }
+
+            pixelScale1 = hypot (chip->toFPA->x->coeff[1][0], chip->toFPA->x->coeff[0][1]);
+            pixelScale2 = hypot (chip->toFPA->y->coeff[1][0], chip->toFPA->y->coeff[0][1]);
+            pixelScale = 0.5*(pixelScale1 + pixelScale2);
+            oldScale->data.F32[nobj++] = pixelScale;
+            pixelScaleUse = (useMax) ? PS_MAX (pixelScale, pixelScaleUse) : PS_MIN (pixelScale, pixelScaleUse);
+        }
+        useExternal = false;
+        oldScale->n = nobj;
+    }
+
 
     // rescale each chip by the reference scale
     for (int i = 0; i < fpa->chips->n; i++) {
-	pmChip *chip = fpa->chips->data[i];
-	if (!chip->process || !chip->file_exists) { continue; }
-	if (!chip->toFPA) { continue; }
-
-	psPlaneTransform *toFPA = chip->toFPA;
-	psPlaneTransform *fromFPA = chip->fromFPA;
-	    
-	pixelScale1 = hypot (toFPA->x->coeff[1][0], toFPA->x->coeff[0][1]);
-	pixelScale2 = hypot (toFPA->y->coeff[1][0], toFPA->y->coeff[0][1]);
-
-	if (useExternal) {
-	    pixelScaleUse = getChipPixelScale (chip);
-	}
-
-	for (int i = 0; i <= toFPA->x->nX; i++) {
-	    for (int j = 0; j <= toFPA->x->nX; j++) {
-		toFPA->x->coeff[i][j] *= pixelScaleUse/pixelScale1;
-		toFPA->y->coeff[i][j] *= pixelScaleUse/pixelScale2;
-		fromFPA->x->coeff[i][j] *= pixelScale1/pixelScaleUse;
-		fromFPA->y->coeff[i][j] *= pixelScale2/pixelScaleUse;
-	    }
-	}
-
+        pmChip *chip = fpa->chips->data[i];
+        if (!chip->process || !chip->file_exists) { continue; }
+        if (!chip->toFPA) { continue; }
+
+        psPlaneTransform *toFPA = chip->toFPA;
+        psPlaneTransform *fromFPA = chip->fromFPA;
+
+        pixelScale1 = hypot (toFPA->x->coeff[1][0], toFPA->x->coeff[0][1]);
+        pixelScale2 = hypot (toFPA->y->coeff[1][0], toFPA->y->coeff[0][1]);
+
+        if (useExternal) {
+            pixelScaleUse = getChipPixelScale (chip);
+        }
+
+        for (int i = 0; i <= toFPA->x->nX; i++) {
+            for (int j = 0; j <= toFPA->x->nX; j++) {
+                toFPA->x->coeff[i][j] *= pixelScaleUse/pixelScale1;
+                toFPA->y->coeff[i][j] *= pixelScaleUse/pixelScale2;
+                fromFPA->x->coeff[i][j] *= pixelScale1/pixelScaleUse;
+                fromFPA->y->coeff[i][j] *= pixelScale2/pixelScaleUse;
+            }
+        }
     }
     psastroMosaicSetAstrom (fpa);
+    if (!useExternal) {
+        psastroVisualPlotCommonScale (fpa, oldScale);
+    }
+    psFree (oldScale);
     return true;
 }
