Index: /trunk/pswarp/src/pswarp.c
===================================================================
--- /trunk/pswarp/src/pswarp.c	(revision 27095)
+++ /trunk/pswarp/src/pswarp.c	(revision 27096)
@@ -28,10 +28,5 @@
 
     psLibInit(NULL);
-
-    // model inits are needed in pmSourceIO
-    // models defined in psphot/src/models are not available in psastro
     pmModelClassInit();
-
-    // init various psphot pieces (errors, models, threads)
     psphotInit();
 
@@ -64,7 +59,7 @@
     }
 
-    psLogMsg("pswarp", 3, "complete pswarp run: %f sec\n", psTimerMark("pswarp"));
-    pswarpCleanup(config);
-    psLibFinalize();
-    exit(PS_EXIT_SUCCESS);
+    psLogMsg("pswarp", PS_LOG_INFO, "complete pswarp run: %f sec\n", psTimerMark("pswarp"));
+
+    psExit exitValue = pswarpCleanup(config);
+    exit(exitValue);
 }
Index: /trunk/pswarp/src/pswarp.h
===================================================================
--- /trunk/pswarp/src/pswarp.h	(revision 27095)
+++ /trunk/pswarp/src/pswarp.h	(revision 27096)
@@ -81,5 +81,5 @@
 bool pswarpDefine (pmConfig *config);
 bool pswarpLoop (pmConfig *config);
-void pswarpCleanup (pmConfig *config);
+psExit pswarpCleanup (pmConfig *config);
 bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config);
 bool pswarpTransformSources(pmReadout *output, pmReadout *input, pmConfig *config);
Index: /trunk/pswarp/src/pswarpArguments.c
===================================================================
--- /trunk/pswarp/src/pswarpArguments.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpArguments.c	(revision 27096)
@@ -26,6 +26,6 @@
     // load config data from default locations
     pmConfig *config = pmConfigRead(&argc, argv, PSWARP_RECIPE);
-    if (config == NULL) {
-        psError(PSWARP_ERR_CONFIG, false, "Can't read site configuration");
+    if (!config) {
+        psError(psErrorCodeLast(), false, "Can't read configuration");
         return NULL;
     }
@@ -33,5 +33,9 @@
     // save the following additional recipe values based on command-line options
     // these options override the PSWARP recipe values loaded from recipe files
-    pmConfigRecipeOptions (config, PSWARP_RECIPE);
+    if (!pmConfigRecipeOptions(config, PSWARP_RECIPE)) {
+        psError(psErrorCodeLast(), false, "Can't do something with recipes");
+        psFree(config);
+        return NULL;
+    }
 
     pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM",   "-astrom", "-astromlist");
@@ -72,5 +76,5 @@
         psThreadPoolInit (nThreads);
     }
-    pswarpSetThreads ();
+    pswarpSetThreads();
 
     if ((N = psArgumentGet(argc, argv, "-dumpconfig"))) {
@@ -160,5 +164,5 @@
     bool PSF = psMetadataLookupBool(&status, recipe, "PSF"); ///< Generate a PSF model?
     if (!status) {
-	PSF = true;
+        PSF = true;
         psWarning("PSF is not set in the %s recipe --- defaulting to TRUE.", PSWARP_RECIPE);
     }
Index: /trunk/pswarp/src/pswarpCleanup.c
===================================================================
--- /trunk/pswarp/src/pswarpCleanup.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpCleanup.c	(revision 27096)
@@ -13,18 +13,57 @@
 # include "pswarp.h"
 
-void pswarpCleanup (pmConfig *config) {
+psExit pswarpCleanup (pmConfig *config)
+{
+    psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
+    psErrorCode errorCode = psErrorCodeLast(); // Error code
+    if (errorCode != PS_ERR_NONE) {
+        psErrorStackPrint(stderr, "Unable to perform warp.");
+        switch (errorCode) {
+          case PSWARP_ERR_UNKNOWN:
+          case PS_ERR_UNKNOWN:
+            exitValue = PS_EXIT_UNKNOWN_ERROR;
+            break;
+          case PS_ERR_IO:
+          case PS_ERR_DB_CLIENT:
+          case PS_ERR_DB_SERVER:
+          case PS_ERR_BAD_FITS:
+          case PS_ERR_OS_CALL_FAILED:
+          case PSWARP_ERR_IO:
+            exitValue = PS_EXIT_SYS_ERROR;
+            break;
+          case PS_ERR_BAD_PARAMETER_VALUE:
+          case PS_ERR_BAD_PARAMETER_TYPE:
+          case PS_ERR_BAD_PARAMETER_NULL:
+          case PS_ERR_BAD_PARAMETER_SIZE:
+          case PSWARP_ERR_ARGUMENTS:
+          case PSWARP_ERR_CONFIG:
+            exitValue = PS_EXIT_CONFIG_ERROR;
+            break;
+          case PSWARP_ERR_DATA:
+          case PSWARP_ERR_NO_OVERLAP:
+            exitValue = PS_EXIT_DATA_ERROR;
+            break;
+          case PS_ERR_UNEXPECTED_NULL:
+          case PS_ERR_PROGRAMMING:
+          case PSWARP_ERR_NOT_IMPLEMENTED:
+          default:
+            // It's a programming error if we're not dealing with the error correctly
+            exitValue = PS_EXIT_PROG_ERROR;
+            break;
+        }
+    }
 
-    psFree (config);
+    psThreadPoolFinalize();
+    psMemCheckCorruption(stderr, true);
 
-    psTimerStop ();
-    psMemCheckCorruption(stderr, true);
-    pmModelClassCleanup ();
-    psTimeFinalize ();
-    psThreadPoolFinalize ();
-    pmConceptsDone ();
-    pmConfigDone ();
-    // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "pswarp");
-    fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "pswarp");
+    psFree(config);
 
-    return;
+    psTimerStop();
+    pmVisualClose();
+    pmModelClassCleanup();
+    pmConceptsDone();
+    pmConfigDone();
+    psLibFinalize();
+
+    return exitValue;
 }
Index: /trunk/pswarp/src/pswarpDefine.c
===================================================================
--- /trunk/pswarp/src/pswarpDefine.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpDefine.c	(revision 27096)
@@ -49,5 +49,5 @@
     {
         if (!pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read headers for skycell.");
+            psError(psErrorCodeLast(), false, "Unable to read headers for skycell.");
             psFree(view);
             return false;
@@ -59,5 +59,5 @@
         pmHDU *hdu = pmHDUFromCell(source); ///< HDU for source
         if (!hdu || !hdu->header) {
-            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find header for sky cell.");
+            psError(PM_ERR_PROG, false, "Unable to find header for sky cell.");
             psFree(view);
             return false;
@@ -65,6 +65,6 @@
         int numCols = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); ///< Number of columns
         int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); ///< Number of rows
-	if ((numCols == 0) || (numRows == 0)) {
-            psError(PS_ERR_UNKNOWN, false, "skycell has invalid dimensions %d x %d", numCols, numRows);
+        if ((numCols == 0) || (numRows == 0)) {
+            psError(PSWARP_ERR_DATA, false, "skycell has invalid dimensions %d x %d", numCols, numRows);
             psFree(view);
             return false;
@@ -77,5 +77,5 @@
         psFree(readout);                // Drop reference
 
-	bool status = false;
+        bool status = false;
         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XBIN");
         psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YBIN");
@@ -106,10 +106,10 @@
     if (bilevelAstrometry) {
         if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for skycell.");
+            psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for skycell.");
             psFree(view);
             return false;
         }
         if (!pmAstromReadBilevelChip(outputChip, hdu->header)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for skycell.");
+            psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for skycell.");
             psFree(view);
             return false;
@@ -118,5 +118,5 @@
         // we use a default FPA pixel scale of 1.0
         if (!pmAstromReadWCS(output->fpa, outputChip, hdu->header, 1.0)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for skycell.");
+            psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for skycell.");
             psFree(view);
             return false;
Index: /trunk/pswarp/src/pswarpDefineSkycell.c
===================================================================
--- /trunk/pswarp/src/pswarpDefineSkycell.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpDefineSkycell.c	(revision 27096)
@@ -47,5 +47,5 @@
     }
     if (infiles->n != 1) {
-        psError(PS_ERR_IO, false, "Found n == %ld files in %s in arguments\n", infiles->n, argname);
+        psError(PSWARP_ERR_CONFIG, false, "Found n == %ld files in %s in arguments\n", infiles->n, argname);
         return false;
     }
@@ -54,5 +54,5 @@
     psString realName = pmConfigConvertFilename (infiles->data[0], config, false, false);
     if (!realName) {
-        psError(PS_ERR_IO, false, "Failed to convert file name %s\n", (char *) infiles->data[0]);
+        psError(psErrorCodeLast(), false, "Failed to convert file name %s\n", (char *) infiles->data[0]);
         return false;
     }
@@ -61,5 +61,5 @@
     fits = psFitsOpen (realName, "r");
     if (!fits) {
-        psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
+        psError(psErrorCodeLast(), false, "Failed to open file %s\n", realName);
         psFree (realName);
         return false;
@@ -67,5 +67,5 @@
     phu = psFitsReadHeader (NULL, fits);
     if (!phu) {
-        psError(PS_ERR_IO, false, "Failed to read file header %s\n", realName);
+        psError(psErrorCodeLast(), false, "Failed to read file header %s\n", realName);
         psFree (realName);
         return false;
@@ -87,5 +87,5 @@
     format = pmConfigCameraFormatFromHeader (NULL, NULL, NULL, skyConfig, phu, false);
     if (!format) {
-        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
+        psError(psErrorCodeLast(), false, "Failed to read CCD format from %s\n", realName);
         psFree(phu);
         psFree (realName);
@@ -100,5 +100,5 @@
     fpa = pmFPAConstruct (skyConfig->camera, skyConfig->cameraName);
     if (!fpa) {
-        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
+        psError(psErrorCodeLast(), false, "Failed to construct FPA from %s", realName);
         psFree (realName);
         return false;
@@ -110,5 +110,5 @@
     file = pmFPAfileDefineInput (skyConfig, fpa, NULL, filename);
     if (!file) {
-        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
+        psError(psErrorCodeLast(), false, "file %s not defined\n", filename);
         psFree(phu);
         psFree(fpa);
@@ -126,5 +126,5 @@
     file->fileLevel = pmFPAPHULevel(format);
     if (file->fileLevel == PM_FPA_LEVEL_NONE) {
-        psError(PS_ERR_IO, true, "Unable to determine file level for %s\n", file->name);
+        psError(PSWARP_ERR_CONFIG, true, "Unable to determine file level for %s\n", file->name);
         psFree(phu);
         psFree(fpa);
@@ -137,5 +137,5 @@
     pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
     if (!view) {
-        psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
+        psError(psErrorCodeLast(), false, "Unable to determine source for %s", file->name);
         psFree(phu);
         psFree (fpa);
Index: /trunk/pswarp/src/pswarpHeadersLoad.c
===================================================================
--- /trunk/pswarp/src/pswarpHeadersLoad.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpHeadersLoad.c	(revision 27096)
@@ -74,5 +74,5 @@
     if (bilevelAstrometry) {
         if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input.");
+            psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input.");
             psFree(view);
             return false;
@@ -92,5 +92,5 @@
         if (bilevelAstrometry) {
             if (!pmAstromReadBilevelChip (chip, hdu->header)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for input.");
+                psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input.");
                 psFree(view);
                 return false;
@@ -99,5 +99,5 @@
             // we use a default FPA pixel scale of 1.0
             if (!pmAstromReadWCS(input->fpa, chip, hdu->header, 1.0)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input.");
+                psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input.");
                 psFree(view);
                 return false;
Index: /trunk/pswarp/src/pswarpLoop.c
===================================================================
--- /trunk/pswarp/src/pswarpLoop.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpLoop.c	(revision 27096)
@@ -84,10 +84,10 @@
     psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE);
     if (!recipe) {
-        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
+        psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
         return false;
     }
 
     if (!pswarpSetMaskBits(config)) {
-        psError(PS_ERR_IO, false, "failed to set mask bits");
+        psError(psErrorCodeLast(), false, "failed to set mask bits");
         return NULL;
     }
@@ -111,5 +111,5 @@
 
     if (astrom->camera != input->camera) {
-        psError(PS_ERR_UNKNOWN, true, "Input camera and astrometry camera do not match.");
+        psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match.");
         return false;
     }
@@ -211,5 +211,5 @@
     if (bilevelAstrometry) {
         if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");
+            psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA.");
             psFree(view);
             psFree(stats);
@@ -237,5 +237,5 @@
         if (bilevelAstrometry) {
             if (!pmAstromReadBilevelChip (chip, hdu->header)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for input FPA.");
+                psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA.");
                 psFree(view);
                 psFree(stats);
@@ -245,5 +245,5 @@
             // we use a default FPA pixel scale of 1.0
             if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input FPA.");
+                psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA.");
                 psFree(view);
                 psFree(stats);
@@ -312,5 +312,5 @@
 
     if (!pswarpPixelsLit(output, stats, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to calculate pixel regions.");
+        psError(psErrorCodeLast(), false, "Unable to calculate pixel regions.");
         psFree(cells);
         psFree(view);
@@ -349,5 +349,5 @@
 
     if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to average cell concepts.");
+        psError(psErrorCodeLast(), false, "Unable to average cell concepts.");
         psFree(stats);
         psFree(cells);
@@ -361,5 +361,5 @@
 
     if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA concepts from input to output.");
+        psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");
         psFree(stats);
         psFree(view);
@@ -388,5 +388,5 @@
         pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU
         if (!skyHDU) {
-            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find skycell HDU.");
+            psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU.");
             psFree(view);
             return false;
@@ -398,5 +398,5 @@
 
     if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to generate WCS header.");
+        psError(psErrorCodeLast(), false, "Unable to generate WCS header.");
         psFree(stats);
         return false;
@@ -428,5 +428,5 @@
         psArray *sources = psphotLoadPSFSources (config, view);
         if (!sources) {
-            psError(PS_ERR_UNKNOWN, false, "No sources supplied to measure PSF");
+            psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");
             return false;
         }
Index: /trunk/pswarp/src/pswarpParseCamera.c
===================================================================
--- /trunk/pswarp/src/pswarpParseCamera.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpParseCamera.c	(revision 27096)
@@ -31,5 +31,5 @@
     }
     if (!status) {
-        psError(PSWARP_ERR_CONFIG, false, "Failed to load file definition for %s", filerule);
+        psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
         return false;
     }
@@ -38,5 +38,5 @@
         file = pmFPAfileDefineFromRun(&status, bind, config, filerule); // File to return
         if (!status) {
-            psError(PSWARP_ERR_CONFIG, false, "Failed to load file definition for %s", filerule);
+            psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
             return NULL;
         }
@@ -65,5 +65,5 @@
     pmFPAfile *input = defineInputFile(config, NULL, "PSWARP.INPUT", "INPUT", PM_FPA_FILE_IMAGE);
     if (!input) {
-        psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.INPUT");
+        psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.INPUT");
         return false;
     }
@@ -89,5 +89,5 @@
     bool status = pswarpDefineSkycell(&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");
     if (!status) {
-        psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.SKYCELL");
+        psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.SKYCELL");
         return false;
     }
@@ -97,5 +97,5 @@
     pmFPAfile *output = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT");
     if (!output) {
-        psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT");
+        psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT");
         return false;
     }
@@ -104,5 +104,5 @@
     pmFPAfile *outMask = pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.MASK");
     if (!outMask) {
-        psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.MASK");
+        psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.MASK");
         return false;
     }
@@ -112,5 +112,5 @@
         pmFPAfile *outVariance = pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.VARIANCE");
         if (!outVariance) {
-            psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.VARIANCE");
+            psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.VARIANCE");
             return false;
         }
@@ -121,5 +121,5 @@
         pmFPAfile *outSources = pmFPAfileDefineSkycell(config, output->fpa, "PSWARP.OUTPUT.SOURCES");
         if (!outSources) {
-            psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.SOURCES");
+            psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.SOURCES");
             return false;
         }
@@ -129,5 +129,5 @@
     psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE);
     if (!recipe) {
-        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
+        psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
         return false;
     }
@@ -139,14 +139,14 @@
         pmFPAfile *psphotInput = pmFPAfileDefineSkycell(config, NULL, "PSPHOT.INPUT");
         if (!psphotInput) {
-            psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.INPUT"));
+            psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.INPUT"));
             return false;
         }
         psphotInput->src = psMemIncrRefCounter(output->fpa);
-	// specify the number of psphot input images
-	psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
+        // specify the number of psphot input images
+        psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
 
         pmFPAfile *psphotInSources = pmFPAfileDefineSkycell(config, output->fpa, "PSPHOT.INPUT.CMF");
         if (!psphotInSources) {
-            psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.INPUT.CMF"));
+            psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.INPUT.CMF"));
             return false;
         }
@@ -155,5 +155,5 @@
         psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE); // Recipe
         if (!psphotRecipe) {
-            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find %s recipe.", PSPHOT_RECIPE);
+            psError(PSWARP_ERR_CONFIG, false, "Unable to find %s recipe.", PSPHOT_RECIPE);
             return false;
         }
@@ -162,5 +162,5 @@
         // Define associated psphot input/output files
         if (!psphotDefineFiles(config, psphotInput)) {
-            psError(PSPHOT_ERR_CONFIG, false,
+            psError(PSWARP_ERR_CONFIG, false,
                     "Unable to define the additional input/output files for psphot");
             return false;
@@ -183,5 +183,5 @@
                 int chipNum = atoi(chips->data[i]);
                 if (! pmFPASelectChip(input->fpa, chipNum, false)) {
-                    psError(PSWARP_ERR_CONFIG, true, "Chip number %d doesn't exist in camera.\n", chipNum);
+                    psError(PSWARP_ERR_ARGUMENTS, true, "Chip number %d doesn't exist in camera.\n", chipNum);
                     return false;
                 }
Index: /trunk/pswarp/src/pswarpSetMaskBits.c
===================================================================
--- /trunk/pswarp/src/pswarpSetMaskBits.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpSetMaskBits.c	(revision 27096)
@@ -28,5 +28,5 @@
     // this function sets the required single-image mask bits
     if (!pmConfigMaskSetBits (&maskIn, &markIn, config)) {
-        psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
+        psError (psErrorCodeLast(), false, "Unable to define the mask bit values");
         return false;
     }
@@ -64,5 +64,5 @@
     }
     if (!markOut) {
-        psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
+        psError(PSWARP_ERR_CONFIG, true, "Unable to define the MARK bit mask: all bits taken!");
         return false;
     }
@@ -71,5 +71,5 @@
     psMetadata *warpRecipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
     if (!warpRecipe) {
-        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
+        psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
         return false;
     }
@@ -85,5 +85,5 @@
     psMetadata *psphotRecipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
     if (!psphotRecipe) {
-        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSPHOT_RECIPE);
+        psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSPHOT_RECIPE);
         return false;
     }
Index: /trunk/pswarp/src/pswarpSetThreads.c
===================================================================
--- /trunk/pswarp/src/pswarpSetThreads.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpSetThreads.c	(revision 27096)
@@ -19,13 +19,10 @@
 {
     pswarpTransformTileArgs *args = job->args->data[0];
-    bool status = pswarpTransformTile (args);
-    return status;
+    return pswarpTransformTile(args);
 }
 
-bool pswarpSetThreads(void) {
-
-    psThreadTask *task = NULL;
-
-    task = psThreadTaskAlloc("PSWARP_TRANSFORM_TILE", 1);
+bool pswarpSetThreads(void)
+{
+    psThreadTask *task = psThreadTaskAlloc("PSWARP_TRANSFORM_TILE", 1);
     task->function = &pswarpThread_pswarpTransformTile;
     psThreadTaskAdd(task);
Index: /trunk/pswarp/src/pswarpTransformReadout.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformReadout.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpTransformReadout.c	(revision 27096)
@@ -89,5 +89,5 @@
 
     if (!pmReadoutMaskNonfinite(input, pmConfigMaskGet("SAT", config))) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in input.");
+        psError(psErrorCodeLast(), false, "Unable to mask non-finite pixels in input.");
         return false;
     }
@@ -129,5 +129,5 @@
             psArrayAdd(job->args, 1, args);
             if (!psThreadJobAddPending(job)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to warp image.");
+                psError(psErrorCodeLast(), false, "Unable to warp image.");
                 return false;
             }
@@ -140,5 +140,5 @@
     // wait here for the threaded jobs to finish
     if (!psThreadPoolWait (false)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
+        psError(psErrorCodeLast(), false, "Unable to interpolate image.");
         return false;
     }
@@ -185,5 +185,5 @@
     if (goodPixels > 0) {
         if (!pswarpTransformSources(output, input, config)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
+            psError(psErrorCodeLast(), false, "Unable to interpolate image.");
             return false;
         }
Index: /trunk/pswarp/src/pswarpTransformSources.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformSources.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpTransformSources.c	(revision 27096)
@@ -45,6 +45,6 @@
     psArray *outSources = outDetections->allSources;
     if (!outSources) {
-	outDetections->allSources = psArrayAllocEmpty(SOURCE_ARRAY_BUFFER);
-	outSources = outDetections->allSources;
+        outDetections->allSources = psArrayAllocEmpty(SOURCE_ARRAY_BUFFER);
+        outSources = outDetections->allSources;
     }
 
@@ -61,5 +61,5 @@
         int xGrid, yGrid;           ///< Grid coordinates for local map
         if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to get grid coordinates for source at %f,%f\n",
+            psError(psErrorCodeLast(), false, "Unable to get grid coordinates for source at %f,%f\n",
                     xIn, yIn);
             psFree(outDetections);
@@ -76,5 +76,5 @@
         double xOut, yOut;          ///< Output coordinates
         if (!pswarpMapApply(&xOut, &yOut, map, xIn + 0.5, yIn + 0.5)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to transform coordinates for source at %f,%f\n",
+            psError(psErrorCodeLast(), false, "Unable to transform coordinates for source at %f,%f\n",
                     xIn, yIn);
             psFree(outDetections);
@@ -111,8 +111,8 @@
 
         new->modelPSF = pmModelAlloc(source->modelPSF->type);
-	new->modelPSF->params->data.F32[PM_PAR_I0]=
-	  (isfinite(new->psfMag) ? pow(10.0, -0.4*new->psfMag) : NAN);
-	new->modelPSF->dparams->data.F32[PM_PAR_I0]=
-	  (isfinite(new->psfMag) ? new->errMag*pow(10.0, -0.4*new->psfMag) : NAN);
+        new->modelPSF->params->data.F32[PM_PAR_I0]=
+          (isfinite(new->psfMag) ? pow(10.0, -0.4*new->psfMag) : NAN);
+        new->modelPSF->dparams->data.F32[PM_PAR_I0]=
+          (isfinite(new->psfMag) ? new->errMag*pow(10.0, -0.4*new->psfMag) : NAN);
 
 #if 0
Index: /trunk/pswarp/src/pswarpTransformTile.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformTile.c	(revision 27095)
+++ /trunk/pswarp/src/pswarpTransformTile.c	(revision 27096)
@@ -98,5 +98,5 @@
             psImageMaskType maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; // Value of mask
             if (!psImageInterpolate(&imageValue, &varValue, &maskValue, xIn, yIn, args->interp)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
+                psError(psErrorCodeLast(), false, "Unable to interpolate image.");
                 return false;
             }
