Index: trunk/pois/src/poisCalculateDeviations.c
===================================================================
--- trunk/pois/src/poisCalculateDeviations.c	(revision 5717)
+++ trunk/pois/src/poisCalculateDeviations.c	(revision 5742)
@@ -6,12 +6,12 @@
 #define MAXCHAR 80
 
-psVector *poisCalculateDeviations(psVector *deviations,	// Output array of deviations, or NULL
-				  psArray *stamps, // Array of stamps
-				  psImage *refImage, // Reference image
-				  psImage *inImage, // Input image
-				  psImage *mask, // Mask image
-				  psArray *kernelParams, // Array of kernel parameters
-				  psVector *solution, // Solution vector
-				  poisConfig *config // Configuration
+psVector *poisCalculateDeviations(psVector *deviations, // Output array of deviations, or NULL
+                                  psArray *stamps, // Array of stamps
+                                  psImage *refImage, // Reference image
+                                  psImage *inImage, // Input image
+                                  psImage *mask, // Mask image
+                                  psArray *kernelParams, // Array of kernel parameters
+                                  psVector *solution, // Solution vector
+                                  poisConfig *config // Configuration
     )
 {
@@ -32,63 +32,63 @@
 
     if (!deviations) {
-	deviations = psVectorAlloc(stamps->n, PS_TYPE_F32);
+        deviations = psVectorAlloc(stamps->n, PS_TYPE_F32);
     }
 
-    int footprint = config->footprint;	// Size of stamp footprint
+    int footprint = config->footprint;  // Size of stamp footprint
     int xSize = footprint + config->xKernel; // (Half) size of subimage in x
     int ySize = footprint + config->yKernel; // (Half) size of subimage in y
-    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);	// Statistics
+    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); // Statistics
 
     psImage *subStamp = psImageAlloc(2 * xSize, 2 * ySize, PS_TYPE_F32); // Subtraction of stamp
     for (int s = 0; s < stamps->n; s++) {
-	poisStamp *stamp = stamps->data[s]; // The coordinates of the stamp of interest
-	int x = stamp->x;		// Stamp x coord
-	int y = stamp->y;		// Stamp y coord
-	if (stamp->status == POIS_STAMP_USED) {
-	    psRegion stampRegion = {x - xSize, x + xSize, y - ySize, y + ySize};
-	    psImage *refStamp = psImageSubset(refImage, stampRegion);
-	    psImage *inStamp = psImageSubset(inImage, stampRegion);
-	    psImage *maskStamp = psImageSubset(mask, stampRegion);
-	    psImage *convRefStamp = poisConvolveImage(refStamp, maskStamp, solution, kernelParams, config);
-	    // Calculate chi^2
-	    (void)psBinaryOp(subStamp, inStamp, "-", convRefStamp);
-	    (void)psBinaryOp(subStamp, subStamp, "*", subStamp);
-	    (void)psBinaryOp(subStamp, subStamp, "/", inStamp);
-	    psRegion stampTrim = { config->xKernel, config->xKernel + 2 * footprint, config->yKernel,
-				   config->yKernel + 2 * footprint };
-	    psImage *subStampTrim = psImageSubset(subStamp, stampTrim);
-	    psImage *maskStampTrim = psImageSubset(maskStamp, stampTrim);
-	    // Copy image to workaround bug 305
-	    psImage *tempImage = psImageCopy(NULL, subStampTrim, PS_TYPE_F32);
-	    psImage *tempMask = psImageCopy(NULL, maskStampTrim, PS_TYPE_U8);
-	    
-	    (void)psImageStats(stats, tempImage, tempMask, POIS_MASK_BAD | POIS_MASK_NEAR_BAD);
-	    
-	    psFree(tempImage);
-	    psFree(tempMask);
-	    
-	    deviations->data.F32[s] = sqrtf(stats->sampleMean / 2.0);
-	    psTrace("pois.calculateDeviations", 5, "Deviation of stamp %d (%d,%d) is %f\n", s, x, y,
-		    deviations->data.F32[s]);
-	    
+        poisStamp *stamp = stamps->data[s]; // The coordinates of the stamp of interest
+        int x = stamp->x;               // Stamp x coord
+        int y = stamp->y;               // Stamp y coord
+        if (stamp->status == POIS_STAMP_USED) {
+            psRegion stampRegion = {x - xSize, x + xSize, y - ySize, y + ySize};
+            psImage *refStamp = psImageSubset(refImage, stampRegion);
+            psImage *inStamp = psImageSubset(inImage, stampRegion);
+            psImage *maskStamp = psImageSubset(mask, stampRegion);
+            psImage *convRefStamp = poisConvolveImage(refStamp, maskStamp, solution, kernelParams, config);
+            // Calculate chi^2
+            (void)psBinaryOp(subStamp, inStamp, "-", convRefStamp);
+            (void)psBinaryOp(subStamp, subStamp, "*", subStamp);
+            (void)psBinaryOp(subStamp, subStamp, "/", inStamp);
+            psRegion stampTrim = { config->xKernel, config->xKernel + 2 * footprint, config->yKernel,
+                                   config->yKernel + 2 * footprint };
+            psImage *subStampTrim = psImageSubset(subStamp, stampTrim);
+            psImage *maskStampTrim = psImageSubset(maskStamp, stampTrim);
+            // Copy image to workaround bug 305
+            psImage *tempImage = psImageCopy(NULL, subStampTrim, PS_TYPE_F32);
+            psImage *tempMask = psImageCopy(NULL, maskStampTrim, PS_TYPE_U8);
+
+            (void)psImageStats(stats, tempImage, tempMask, POIS_MASK_BAD | POIS_MASK_NEAR_BAD);
+
+            psFree(tempImage);
+            psFree(tempMask);
+
+            deviations->data.F32[s] = sqrtf(stats->sampleMean / 2.0);
+            psTrace("pois.calculateDeviations", 5, "Deviation of stamp %d (%d,%d) is %f\n", s, x, y,
+                    deviations->data.F32[s]);
+
 #ifdef TESTING
-	    char stampName[MAXCHAR];		// File name for stamp
-	    snprintf(stampName, MAXCHAR, "stamp%d.fits", s);
-	    psFits *stampFile = psFitsAlloc(stampName);
-	    if (!psFitsWriteImage(stampFile, NULL, subStampTrim, 0)) {
-		psErrorStackPrint(stderr, "Unable to write stamp: %s\n", stampName);
-	    }
-	    psFree(stampFile);
+            char stampName[MAXCHAR];            // File name for stamp
+            snprintf(stampName, MAXCHAR, "stamp%d.fits", s);
+            psFits *stampFile = psFitsOpen(stampName, "w");
+            if (!psFitsWriteImage(stampFile, NULL, subStampTrim, 0)) {
+                psErrorStackPrint(stderr, "Unable to write stamp: %s\n", stampName);
+            }
+            psFitsClose(stampFile);
 #endif
 
 #if 0
-	    psFree(convRefStamp);
-	    psFree(maskStampTrim);
-	    psFree(subStampTrim);
-	    psFree(maskStamp);
-	    psFree(refStamp);
-	    psFree(inStamp);
+            psFree(convRefStamp);
+            psFree(maskStampTrim);
+            psFree(subStampTrim);
+            psFree(maskStamp);
+            psFree(refStamp);
+            psFree(inStamp);
 #endif
-	}
+        }
     }
 
