Index: trunk/ppStack/src/ppStackMatch.c
===================================================================
--- trunk/ppStack/src/ppStackMatch.c	(revision 26898)
+++ trunk/ppStack/src/ppStackMatch.c	(revision 27004)
@@ -31,10 +31,10 @@
     psFree(resolved);
     if (!fits) {
-        psError(PS_ERR_IO, false, "Unable to open previously produced image: %s", name);
+        psError(PPSTACK_ERR_IO, false, "Unable to open previously produced image: %s", name);
         return false;
     }
     psImage *image = psFitsReadImage(fits, psRegionSet(0,0,0,0), 0); // Image of interest
     if (!image) {
-        psError(PS_ERR_IO, false, "Unable to read previously produced image: %s", name);
+        psError(PPSTACK_ERR_IO, false, "Unable to read previously produced image: %s", name);
         psFitsClose(fits);
         return false;
@@ -150,5 +150,5 @@
     psImage *unbinned = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Unbinned background model
     if (!psImageUnbin(unbinned, binned, binning)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to unbin background model");
+        psError(PPSTACK_ERR_DATA, false, "Unable to unbin background model");
         psFree(unbinned);
         return NULL;
@@ -177,15 +177,15 @@
     int num = psMetadataLookupS32(&mdok, recipe, "RENORM.NUM");
     if (!mdok) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.NUM is not set in the recipe");
+        psError(PPSTACK_ERR_CONFIG, true, "RENORM.NUM is not set in the recipe");
         return false;
     }
     float minValid = psMetadataLookupF32(&mdok, recipe, "RENORM.MIN");
     if (!mdok) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.MIN is not set in the recipe");
+        psError(PPSTACK_ERR_CONFIG, true, "RENORM.MIN is not set in the recipe");
         return false;
     }
     float maxValid = psMetadataLookupF32(&mdok, recipe, "RENORM.MAX");
     if (!mdok) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.MAX is not set in the recipe");
+        psError(PPSTACK_ERR_CONFIG, true, "RENORM.MAX is not set in the recipe");
         return false;
     }
@@ -229,5 +229,5 @@
 
     if (!pmReadoutMaskNonfinite(readout, maskVal)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in readout.");
+        psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels in readout.");
         return false;
     }
@@ -256,5 +256,5 @@
             psFree(resolved);
             if (!fits || !pmReadoutReadSubtractionKernels(conv, fits)) {
-                psError(PS_ERR_IO, false, "Unable to read previously produced kernel");
+                psError(PPSTACK_ERR_IO, false, "Unable to read previously produced kernel");
                 psFitsClose(fits);
                 return false;
@@ -265,5 +265,5 @@
                 !readImage(&readout->mask, options->convMasks->data[index], config) ||
                 !readImage(&readout->variance, options->convVariances->data[index], config)) {
-                psError(PS_ERR_IO, false, "Unable to read previously produced image.");
+                psError(PPSTACK_ERR_IO, false, "Unable to read previously produced image.");
                 return false;
             }
@@ -326,5 +326,5 @@
             float scaleMax = psMetadataLookupF32(NULL, ppsub, "SCALE.MAX"); // Maximum for scaling
             if (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax)) {
-                psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                psError(PPSTACK_ERR_CONFIG, false,
                         "Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in PPSUB recipe.",
                         scaleRef, scaleMin, scaleMax);
@@ -346,5 +346,5 @@
             psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
             if (!psImageBackground(bg, NULL, readout->image, readout->mask, maskVal | maskBad, rng)) {
-                psError(PS_ERR_UNKNOWN, false, "Can't measure background for image.");
+                psError(PPSTACK_ERR_DATA, false, "Can't measure background for image.");
                 psFree(fake);
                 psFree(optWidths);
@@ -366,5 +366,5 @@
                                           stampSources, SOURCE_MASK, NULL, NULL, options->psf,
                                           minFlux, footprint + size, false, true)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF.");
+                psError(PPSTACK_ERR_DATA, false, "Unable to generate fake image with target PSF.");
                 psFree(fake);
                 psFree(optWidths);
@@ -417,5 +417,5 @@
                                                stride, kernelError, covarFrac, maskVal, maskBad, maskPoor,
                                                poorFrac, badFrac)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to convolve images.");
+                    psError(psErrorCodeLast(), false, "Unable to convolve images.");
                     psFree(fake);
                     psFree(optWidths);
@@ -433,5 +433,5 @@
                                                        options->inputSeeing->data.F32[index],
                                                        options->targetSeeing, scaleRef, scaleMin, scaleMax)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to scale kernel parameters");
+                    psError(psErrorCodeLast(), false, "Unable to scale kernel parameters");
                     psFree(fake);
                     psFree(optWidths);
@@ -451,5 +451,5 @@
                                         sysError, skyErr, kernelError, covarFrac, maskVal, maskBad, maskPoor,
                                         poorFrac, badFrac, PM_SUBTRACTION_MODE_2)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
+                    psError(psErrorCodeLast(), false, "Unable to match images.");
                     psFree(fake);
                     psFree(optWidths);
@@ -464,4 +464,5 @@
                 psFree(widthsCopy);
             }
+
 
 #ifdef TESTING
@@ -628,5 +629,5 @@
     // Measure the variance level for the weighting
     if (!psImageBackground(bg, NULL, readout->variance, readout->mask, maskVal | maskBad, rng)) {
-        psError(PS_ERR_UNKNOWN, false, "Can't measure mean variance for image.");
+        psError(PPSTACK_ERR_DATA, false, "Can't measure mean variance for image.");
         psFree(rng);
         psFree(bg);
