Index: /trunk/stac/src/stac.c
===================================================================
--- /trunk/stac/src/stac.c	(revision 7541)
+++ /trunk/stac/src/stac.c	(revision 7542)
@@ -153,4 +153,11 @@
     (void)stacScales(&scales, &offsets, transformed, config->starFile, config->starMapFile, config->xMapDiff,
                      config->yMapDiff, config->aper);
+
+#ifdef TESTING
+    for (int i = 0; i < scales->n; i++) {
+        psTrace("stac", 3, "Image %d: scale %f, offset %f\n", i, scales->data.F32[i], offsets->data.F32[i]);
+    }
+#endif
+
     // Rescale the images
     (void)stacRescale(transformed, transformedErrors, NULL, scales, offsets);
@@ -242,9 +249,5 @@
     // Get regions of interest in the output frame
     psImage *combineRegion = psImageAlloc(config->outnx, config->outny, PS_TYPE_U8);
-    for (int y = 0; y < config->outny; y++) {
-        for (int x = 0; x < config->outnx; x++) {
-            combineRegion->data.U8[y][x] = 0;
-        }
-    }
+    psImageInit(combineRegion, 0);
     for (int i = 0; i < inputs->n; i++) {
         psImage *region = stacAreaOfInterest(rejectedSource->data[i], maps->data[i], config->outnx,
@@ -268,4 +271,28 @@
     (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, masks,
                         combineRegion, scales, offsets, config->outnx, config->outny);
+
+#ifdef TESTING
+    // Write transformed images out to check
+    for (int i = 0; i < inputs->n; i++) {
+        char shiftName[MAXCHAR];        // Filename of shift image
+        char errName[MAXCHAR];          // Filename of error image
+        sprintf(shiftName,"%s.shift2", (char*)config->inputs->data[i]);
+        sprintf(errName,"%s.shifterr2",(char*)config->inputs->data[i]);
+        psFits *shiftFile = psFitsOpen(shiftName, "w");
+        psFits *errFile = psFitsOpen(errName, "w");
+        psImage *trans = transformed->data[i]; // Transformed image
+        psImage *transErr = transformedErrors->data[i]; // Transformed error image
+        if (!psFitsWriteImage(shiftFile, NULL, trans, 0, NULL)) {
+            psErrorStackPrint(stderr, "Unable to write image: %s\n", shiftName);
+        }
+        psTrace("stac", 1, "Shifted image written to %s\n", shiftName);
+        if (!psFitsWriteImage(errFile, NULL, transErr, 0, NULL)) {
+            psErrorStackPrint(stderr, "Unable to write image: %s\n", errName);
+        }
+        psTrace("stac", 1, "Shifted error image written to %s\n", errName);
+        psFitsClose(shiftFile);
+        psFitsClose(errFile);
+    }
+#endif
 
     // Combine the newly-transformed CR-free images, no rejection
