Index: trunk/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 27040)
+++ trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 27086)
@@ -104,5 +104,5 @@
     psTrace("psModules.imcombine", 3, "Extracting stamps...\n");
     if (!pmSubtractionStampsExtract(*stamps, ro1->image, ro2->image, variance, size, *region)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to extract stamps.");
+        psError(psErrorCodeLast(), false, "Unable to extract stamps.");
         return false;
     }
@@ -318,5 +318,5 @@
         while ((item = psMetadataGetAndIncrement(iter))) {
             if (item->type != PS_DATA_UNKNOWN) {
-                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unexpected type for kernel.");
+                psError(PM_ERR_PROG, true, "Unexpected type for kernel.");
                 psFree(iter);
                 psFree(kernelList);
@@ -338,5 +338,5 @@
     }
     if (psListLength(kernelList) == 0) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find kernels");
+        psError(PM_ERR_PROG, true, "Unable to find kernels");
         psFree(kernelList);
         return false;
@@ -353,5 +353,5 @@
         while ((item = psMetadataGetAndIncrement(iter))) {
             if (item->type != PS_DATA_REGION) {
-                psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unexpected type for region.");
+                psError(PM_ERR_PROG, true, "Unexpected type for region.");
                 psFree(iter);
                 psFree(kernels);
@@ -365,5 +365,5 @@
     }
     if (regions->n != kernels->n) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Differing number of kernels (%ld) and regions (%ld)",
+        psError(PM_ERR_PROG, true, "Differing number of kernels (%ld) and regions (%ld)",
                 kernels->n, regions->n);
         psFree(regions);
@@ -406,5 +406,5 @@
         if (!pmSubtractionAnalysis(outAnalysis, outHeader, kernel, region,
                                    ro1->image->numCols, ro1->image->numRows)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to generate QA data");
+            psError(psErrorCodeLast(), false, "Unable to generate QA data");
             psFree(outAnalysis);
             psFree(outHeader);
@@ -417,5 +417,5 @@
         if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, stride, maskBad, maskPoor, poorFrac,
                                    kernelError, covarFrac, region, kernel, true, useFFT)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to convolve image.");
+            psError(psErrorCodeLast(), false, "Unable to convolve image.");
             psFree(outAnalysis);
             psFree(outHeader);
@@ -555,5 +555,5 @@
             psStatsInit(bg);
             if (!psImageBackground(bg, NULL, ro1->image, ro1->mask, maskVal, rng)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
+                psError(PM_ERR_DATA, false, "Unable to measure background statistics.");
                 psFree(bg);
                 goto MATCH_ERROR;
@@ -565,5 +565,5 @@
             psStatsInit(bg);
             if (!psImageBackground(bg, NULL, ro2->image, ro2->mask, maskVal, rng)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
+                psError(PM_ERR_DATA, false, "Unable to measure background statistics.");
                 psFree(bg);
                 goto MATCH_ERROR;
@@ -640,5 +640,5 @@
                 psVector *buffer = NULL;// Buffer for stats
                 if (!psImageBackground(bgStats, &buffer, ro1->image, ro1->mask, maskVal, rng)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to measure background of image 1.");
+                    psError(PM_ERR_DATA, false, "Unable to measure background of image 1.");
                     psFree(bgStats);
                     psFree(buffer);
@@ -647,5 +647,5 @@
                 float bg1 = psStatsGetValue(bgStats, BG_STAT); // Background for image 1
                 if (!psImageBackground(bgStats, &buffer, ro2->image, ro2->mask, maskVal, rng)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to measure background of image 2.");
+                    psError(PM_ERR_DATA, false, "Unable to measure background of image 2.");
                     psFree(bgStats);
                     psFree(buffer);
@@ -667,5 +667,5 @@
                     break;
                   default:
-                    psError(PS_ERR_UNKNOWN, false, "Unable to determine subtraction order.");
+                    psError(psErrorCodeLast(), false, "Unable to determine subtraction order.");
                     goto MATCH_ERROR;
                 }
@@ -685,5 +685,5 @@
                 // generate the window function from the set of stamps
                 if (!pmSubtractionStampsGetWindow(stamps, size)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to get stamps window.");
+                    psError(psErrorCodeLast(), false, "Unable to get stamps window.");
                     goto MATCH_ERROR;
                 }
@@ -692,5 +692,5 @@
                 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n");
                 if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -698,5 +698,5 @@
                 psTrace("psModules.imcombine", 3, "Solving equation for normalization...\n");
                 if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -710,5 +710,5 @@
                 psTrace("psModules.imcombine", 3, "Calculating equation for kernels...\n");
                 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -717,5 +717,5 @@
                 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
                 if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -724,5 +724,5 @@
                 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
                 if (!deviations) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate deviations.");
                     goto MATCH_ERROR;
                 }
@@ -733,5 +733,5 @@
                 numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, rej);
                 if (numRejected < 0) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to reject stamps.");
+                    psError(psErrorCodeLast(), false, "Unable to reject stamps.");
                     psFree(deviations);
                     goto MATCH_ERROR;
@@ -747,5 +747,5 @@
                 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n");
                 if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -754,5 +754,5 @@
                 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
                 if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -765,5 +765,5 @@
                 psTrace("psModules.imcombine", 3, "Calculating equation for normalization...\n");
                 if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -772,5 +772,5 @@
                 psTrace("psModules.imcombine", 3, "Solving equation for kernels...\n");
                 if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
                     goto MATCH_ERROR;
                 }
@@ -779,5 +779,5 @@
                 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
                 if (!deviations) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
+                    psError(psErrorCodeLast(), false, "Unable to calculate deviations.");
                     goto MATCH_ERROR;
                 }
@@ -791,5 +791,5 @@
 
             if (!pmSubtractionAnalysis(analysis, header, kernels, region, numCols, numRows)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to generate QA data");
+                psError(psErrorCodeLast(), false, "Unable to generate QA data");
                 goto MATCH_ERROR;
             }
@@ -800,5 +800,5 @@
             if (!pmSubtractionConvolve(conv1, conv2, ro1, ro2, subMask, stride, maskBad, maskPoor, poorFrac,
                                        kernelError, covarFrac, region, kernels, true, useFFT)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to convolve image.");
+                psError(psErrorCodeLast(), false, "Unable to convolve image.");
                 goto MATCH_ERROR;
             }
@@ -820,9 +820,9 @@
 
     if (conv1 && !pmSubtractionBorder(conv1->image, conv1->variance, conv1->mask, size, maskBad)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image.");
+        psError(psErrorCodeLast(), false, "Unable to set border of convolved image.");
         goto MATCH_ERROR;
     }
     if (conv2 && !pmSubtractionBorder(conv2->image, conv2->variance, conv2->mask, size, maskBad)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to set border of convolved image.");
+        psError(psErrorCodeLast(), false, "Unable to set border of convolved image.");
         goto MATCH_ERROR;
     }
@@ -1023,5 +1023,5 @@
         } else {
             if (!pmSubtractionOrderStamp(ratios, mask, stamps, models, modelSums, i, bg1, bg2)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to measure PSF width for stamp %d", i);
+                psError(psErrorCodeLast(), false, "Unable to measure PSF width for stamp %d", i);
                 psFree(models);
                 psFree(modelSums);
@@ -1034,5 +1034,5 @@
 
     if (!psThreadPoolWait(true)) {
-        psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
+        psError(psErrorCodeLast(), false, "Error waiting for threads.");
         psFree(models);
         psFree(modelSums);
@@ -1047,5 +1047,5 @@
     psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);
     if (!psVectorStats(stats, ratios, NULL, mask, 0xff)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to calculate statistics for moments ratio.");
+        psError(psErrorCodeLast(), false, "Unable to calculate statistics for moments ratio.");
         psFree(mask);
         psFree(ratios);
@@ -1083,5 +1083,5 @@
     psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);
     if (!pmSubtractionCalculateEquation(stamps, kernels, SUBMODE)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+        psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
         return false;
     }
@@ -1089,5 +1089,5 @@
     psTrace("psModules.imcombine", 3, "Solving %s normalization equation...\n", description);
     if (!pmSubtractionSolveEquation(kernels, stamps, SUBMODE)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+        psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
         return false;
     }
@@ -1099,5 +1099,5 @@
     psTrace("psModules.imcombine", 3, "Calculating %s kernel coeffs equation...\n", description);
     if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+        psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
         return false;
     }
@@ -1105,5 +1105,5 @@
     psTrace("psModules.imcombine", 3, "Solving %s kernel coeffs equation...\n", description);
     if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+        psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
         return false;
     }
@@ -1113,5 +1113,5 @@
     psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
     if (!deviations) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
+        psError(psErrorCodeLast(), false, "Unable to calculate deviations.");
         return false;
     }
@@ -1120,5 +1120,5 @@
     long numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, rej);
     if (numRejected < 0) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to reject stamps.");
+        psError(psErrorCodeLast(), false, "Unable to reject stamps.");
         psFree(deviations);
         return false;
@@ -1130,5 +1130,5 @@
         psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);
         if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_ALL)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+            psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
             return false;
         }
@@ -1136,5 +1136,5 @@
         psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description);
         if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_ALL)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+            psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
             return false;
         }
@@ -1147,5 +1147,5 @@
         psTrace("psModules.imcombine", 3, "Calculating %s normalization equation...\n", description);
         if (!pmSubtractionCalculateEquation(stamps, kernels, PM_SUBTRACTION_EQUATION_KERNELS)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+            psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
             return false;
         }
@@ -1153,5 +1153,5 @@
         psTrace("psModules.imcombine", 3, "Resolving %s equation...\n", description);
         if (!pmSubtractionSolveEquation(kernels, stamps, PM_SUBTRACTION_EQUATION_KERNELS)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation.");
+            psError(psErrorCodeLast(), false, "Unable to calculate least-squares equation.");
             return false;
         }
@@ -1161,5 +1161,5 @@
         psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations
         if (!deviations) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations.");
+            psError(psErrorCodeLast(), false, "Unable to calculate deviations.");
             return false;
         }
@@ -1167,5 +1167,5 @@
         long numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, NAN);
         if (numRejected < 0) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to reject stamps.");
+            psError(psErrorCodeLast(), false, "Unable to reject stamps.");
             psFree(deviations);
             return false;
@@ -1191,5 +1191,5 @@
 
     if (!subtractionModeTest(stamps1, kernels1, "convolve 1", subMask1, rej)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to test subtraction with convolution of image 1");
+        psError(psErrorCodeLast(), false, "Unable to test subtraction with convolution of image 1");
         psFree(stamps1);
         psFree(kernels1);
@@ -1206,5 +1206,5 @@
 
     if (!subtractionModeTest(stamps2, kernels2, "convolve 2", subMask2, rej)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to test subtraction with convolution of image 2");
+        psError(psErrorCodeLast(), false, "Unable to test subtraction with convolution of image 2");
         psFree(stamps2);
         psFree(kernels2);
