Index: trunk/stac/src/stac.c
===================================================================
--- trunk/stac/src/stac.c	(revision 3666)
+++ trunk/stac/src/stac.c	(revision 3667)
@@ -71,5 +71,5 @@
 	sprintf(errName,"%s.err",config->inputs->data[i]);
 	psFits *errorFile = psFitsAlloc(errName);
-	if (!psFitsWriteImage(errorFile, NULL, error, 0, NULL)) {
+	if (!psFitsWriteImage(errorFile, NULL, errors->data[i], 0, NULL)) {
 	    psErrorStackPrint(stderr, "Unable to write image: %s\n", errName);
 	}
@@ -91,15 +91,15 @@
 	char shiftName[MAXCHAR];	// Filename of shift image
 	char errName[MAXCHAR];		// Filename of error image
-	sprintf(shiftName,"%s.shift1",config->inputs->data[n],numTransforms);
-	sprintf(errName,"%s.shifterr1",config->inputs->data[n],numTransforms);
-	psTrace("stac.transform.test", 6,
-		"Output files have size: %dx%d\n",outImage->numCols,outImage->numRows);
+	sprintf(shiftName,"%s.shift1",config->inputs->data[i]);
+	sprintf(errName,"%s.shifterr1",config->inputs->data[i]);
 	psFits *shiftFile = psFitsAlloc(shiftName);
 	psFits *errFile = psFitsAlloc(errName);
-	if (!psFitsWriteImage(shiftFile, NULL, outImage, 0, NULL)) {
+	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, outError, 0, NULL)) {
+	if (!psFitsWriteImage(errFile, NULL, transErr, 0, NULL)) {
 	    psErrorStackPrint(stderr, "Unable to write image: %s\n", errName);
 	}
@@ -137,10 +137,10 @@
 #ifdef TESTING
     // Write rejection images out to check
-    for (int i = 0; i < nImages; i++) {
+    for (int i = 0; i < rejected->n; i++) {
 	char rejName[MAXCHAR];	// Filename of rejection image
-	sprintf(rejName,"%s.shiftrej",config->inputs->data[i]);
+	sprintf(rejName, "%s.shiftrej", config->inputs->data[i]);
 	
 	psFits *rejFile = psFitsAlloc(rejName);
-	if (!psFitsWriteImage(rejFile, NULL, (*rejected)->data[i], 0, NULL)) {
+	if (!psFitsWriteImage(rejFile, NULL, rejected->data[i], 0, NULL)) {
 	    psErrorStackPrint(stderr, "Unable to write image: %s\n", rejName);
 	}
@@ -151,5 +151,5 @@
     // Write out pre-combined image
     char preName[MAXCHAR];		// Filename of precombined image
-    sprintf(preName,"%s.pre",config->output);
+    sprintf(preName, "%s.pre", config->output);
     psFits *preFile = psFitsAlloc(preName);
     if (!psFitsWriteImage(preFile, NULL, combined, 0, NULL)) {
