Index: trunk/stac/src/stac.c
===================================================================
--- trunk/stac/src/stac.c	(revision 3435)
+++ trunk/stac/src/stac.c	(revision 3610)
@@ -27,4 +27,5 @@
     // Set trace levels
     psTraceSetLevel(".",0);
+    psTraceSetLevel(".psLib", 0);
     psTraceSetLevel("stac.checkMemory",10);
     psTraceSetLevel("stac.config",10);
@@ -38,4 +39,5 @@
     psTraceSetLevel("stac.area",10);
     psTraceSetLevel("stac.size",10);
+    psTraceSetLevel("stac.scales",7);
 
     // Set logging level
@@ -65,7 +67,14 @@
     psArray *transformed = NULL;
     psArray *transformedErrors = NULL;
-    (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, NULL, NULL, config);
+    (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, NULL, NULL, NULL, NULL,
+			config);
 
     psTrace("stac.time",1,"Transformation completed at %f seconds\n", getTime() - startTime);
+
+    psVector *scales = NULL;		// Relative scales between images
+    psVector *offsets = NULL;		// Offsets between images
+    (void)stacScales(&scales, &offsets, transformed, config);
+    // Rescale the images
+    (void)stacRescale(transformed, transformedErrors, NULL, scales, offsets);
 
     // Combine with rejection
@@ -122,7 +131,7 @@
     }
 
-    // Redo transformation with the masks
+    // Redo transformation with the masks and scales/offsets
     (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, rejectedSource,
-			combineRegion, config);
+			combineRegion, scales, offsets, config);
 
     // Combine the newly-transformed CR-free images, no rejection
@@ -139,6 +148,22 @@
     psFree(outFile);
 
+    // Save shifted images
+    if (config->saveShifts) {
+	for (int i = 0; i < transformed->n; i++) {
+	    char shiftName[MAXCHAR];	// Filename of shifted image
+	    sprintf(shiftName, "%s.shift", config->inputs->data[i]);
+	    psFits *shiftFile = psFitsAlloc(shiftName);
+	    if (!psFitsWriteImage(shiftFile, NULL, transformed->data[i], 0, NULL)) {
+		psErrorStackPrint(stderr, "Unable to write image: %s\n", shiftName);
+	    }
+	    psTrace("stac", 1, "Shifted image %d written to %s\n", i, shiftName);
+	    psFree(shiftFile);
+	}
+    }
+
     // Free everything I've used
     stacConfigFree(config);
+    psFree(scales);
+    psFree(offsets);
     psFree(combineRegion);
     psFree(regions);
