Index: trunk/stac/src/stacCombine.c
===================================================================
--- trunk/stac/src/stacCombine.c	(revision 2783)
+++ trunk/stac/src/stacCombine.c	(revision 3375)
@@ -1,3 +1,4 @@
 #include <stdio.h>
+#include <assert.h>
 #include <math.h>
 #include "pslib.h"
@@ -15,5 +16,5 @@
     // Would like to use psVectorStats, but it doesn't have errors built in yet
     psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
-    (void)psVectorStats(stats, values, masks, 1);
+    (void)psVectorStats(stats, values, NULL, masks, 1);
     float mean = stats->sampleMean;
     psFree(stats);
@@ -47,5 +48,5 @@
 {
     psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
-    (void)psVectorStats(stats, values, masks, 1);
+    (void)psVectorStats(stats, values, NULL, masks, 1);
     float median = stats->sampleMedian;
     psFree(stats);
@@ -76,33 +77,16 @@
 	psImage *error = (psImage *)errors->data[i]; // The error image
 
-	if ((image->numCols != numCols) || (image->numRows != numRows)) {
-	    psError("stac.combine",
-		    "Image size mismatch on error image %d\nExpected %dx%d, got %dx%d\n",
-		    i, numCols, numRows, image->numCols, image->numRows);
-	    return false;
-	}
-	if ((error->numCols != numCols) || (error->numRows != numRows)) {
-	    psError("stac.combine",
-		    "Image size mismatch on error image %d\nExpected %dx%d, got %dx%d\n",
-		    i, numCols, numRows, error->numCols, error->numRows);
-	    return false;
-	}
+	assert(image->numCols == numCols && image->numRows == numRows);
+	assert(error->numCols == numCols && error->numRows == numRows);
     }
 
     // Check combined image
+    assert(!*combined || ((*combined)->numRows == numRows) && ((*combined)->numCols == numCols));
     if (*combined == NULL) {
 	*combined = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Combined image
-    } else if (((*combined)->numRows != numRows) || ((*combined)->numCols != numCols)) {
-	psError("stac.combine", "Size of combined image (%dx%d) does not match inputs (%dx%d)\n",
-		(*combined)->numCols, (*combined)->numRows, numCols, numRows);
-	return false;
     }
 
     // Check area of interest
-    if (region && ((region->numRows != numRows) || (region->numCols != numCols))) {
-	psError("stac.combine", "Size of area of interest (%dx%d) does not match inputs (%dx%d)\n",
-		region->numCols, region->numRows, numCols, numRows);
-	return false;
-    }
+    assert(!region || (region->numRows == numRows) && (region->numCols == numCols));
 
     psTrace("stac.combine", 1, "Combining images....\n");
@@ -117,8 +101,6 @@
 	    // Allocate the rejection masks, if required
 	    *rejected = psArrayAlloc(nImages);
-	} else if ((*rejected)->n != nImages) {
-	    psError("stac.combine", "Number of rejection masks (%d) does not match number of input"
-		    "images (%d).\n", (*rejected)->n, nImages);
-	    return NULL;
+	} else {
+	    assert((*rejected)->n != nImages);
 	}
 
@@ -208,14 +190,25 @@
     if (nReject > 0) {
 	for (int i = 0; i < nImages; i++) {
-	    char rejfile[MAXCHAR];	// Filename of rejection image
-	    sprintf(rejfile,"%s.shiftrej",config->inputs->data[i]);
-	    psImageWriteSection((psImage*)((*rejected)->data[i]),0,0,0,NULL,0,rejfile);
+	    char rejName[MAXCHAR];	// Filename of rejection image
+	    sprintf(rejName,"%s.shiftrej",config->inputs->data[i]);
+
+	    psFits *rejFile = psFitsAlloc(rejName);
+	    if (!psFitsWriteImage(rejFile, NULL, (*rejected)->data[i], 0, NULL)) {
+		psErrorStackPrint(stderr, "Unable to write image: %s\n", rejName);
+	    }
+	    psTrace("stac", 1, "Rejection image written to %s\n", rejName);
+	    psFree(rejFile);
 	}
     }
     // Write chi^2 image
     iteration++;
-    char chifile[MAXCHAR];		// Filename of chi^2 image
-    sprintf(chifile,"chi2_%d.fits",iteration);
-    psImageWriteSection(chi2,0,0,0,NULL,0,chifile);
+    char chiName[MAXCHAR];		// Filename of chi^2 image
+    sprintf(chiName,"chi2_%d.fits",iteration);
+    psFits *chiFile = psFitsAlloc(chiName);
+    if (!psFitsWriteImage(chiFile, NULL, chi2 , 0, NULL)) {
+	psErrorStackPrint(stderr, "Unable to write image: %s\n", chiName);
+    }
+    psTrace("stac", 1, "Chi^2 image written to %s\n", chiName);
+    psFree(chiFile);
     psFree(chi2);
 #endif
