Index: trunk/ppStack/src/ppStackCamera.c
===================================================================
--- trunk/ppStack/src/ppStackCamera.c	(revision 26898)
+++ trunk/ppStack/src/ppStackCamera.c	(revision 27004)
@@ -30,9 +30,9 @@
         pmFPAfileDefineFromArgs(&found, config, name, "FILENAMES");
     if (!file || !found) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to define file %s from %s", name, filename);
+        psError(psErrorCodeLast(), false, "Unable to define file %s from %s", name, filename);
         return NULL;
     }
     if (file->type != type) {
-        psError(PS_ERR_IO, true, "%s is not of type %s", name, pmFPAfileStringFromType(type));
+        psError(PS_ERR_IO, PPSTACK_ERR_CONFIG, "%s is not of type %s", name, pmFPAfileStringFromType(type));
         return NULL;
     }
@@ -53,5 +53,5 @@
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppSim
     if (!recipe) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSTACK_RECIPE);
+        psError(PPSTACK_ERR_CONFIG, false, "Unable to find recipe %s", PPSTACK_RECIPE);
         return false;
     }
@@ -67,5 +67,5 @@
                                                            "PPSTACK.INPUT.MASK"); // Input masks
         if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to define input masks from RUN metadata.");
+            psError(psErrorCodeLast(), false, "Unable to define input masks from RUN metadata.");
             psFree(runImages);
             return false;
@@ -76,5 +76,5 @@
                                                           "PPSTACK.INPUT.VARIANCE"); // Input variances
         if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to define input variances from RUN metadata.");
+            psError(psErrorCodeLast(), false, "Unable to define input variances from RUN metadata.");
             psFree(runImages);
             return false;
@@ -88,10 +88,10 @@
                                                          "PPSTACK.INPUT.SOURCES"); // Input sources
         if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to define input sources from RUN metadata.");
+            psError(psErrorCodeLast(), false, "Unable to define input sources from RUN metadata.");
             psFree(runImages);
             return false;
         }
         if (!runSrc) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to define input sources from RUN metadata.");
+            psError(PPSTACK_ERR_CONFIG, true, "Unable to define input sources from RUN metadata.");
             psFree(runImages);
             return false;
@@ -104,5 +104,5 @@
                                                          "PPSTACK.INPUT.PSF"); // Input PSFs
                 if (!status) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to define input PSFs from RUN metadata.");
+                    psError(psErrorCodeLast(), false, "Unable to define input PSFs from RUN metadata.");
                     psFree(runImages);
                     return false;
@@ -118,10 +118,11 @@
                                                                     "PPSTACK.CONV.KERNEL"); // Conv'n kernels
                 if (!status) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to define convolution kernels from RUN metadata.");
+                    psError(psErrorCodeLast(), false,
+                            "Unable to define convolution kernels from RUN metadata.");
                     psFree(runImages);
                     return false;
                 }
                 if (!runKernel) {
-                    psError(PS_ERR_UNEXPECTED_NULL, true,
+                    psError(PPSTACK_ERR_CONFIG, true,
                             "Unable to define convolution kernels from RUN metadata.");
                     psFree(runImages);
@@ -137,5 +138,5 @@
         psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info
         if (!inputs) {
-            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find inputs.");
+            psError(PPSTACK_ERR_ARGUMENTS, false, "Unable to find inputs.");
             return false;
         }
@@ -145,5 +146,5 @@
         while ((item = psMetadataGetAndIncrement(iter))) {
             if (item->type != PS_DATA_METADATA) {
-                psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                psError(PPSTACK_ERR_ARGUMENTS, true,
                         "Component %s of the input metadata is not of type METADATA", item->name);
                 psFree(iter);
@@ -155,5 +156,5 @@
             psString image = psMetadataLookupStr(NULL, input, "IMAGE"); // Name of image
             if (!image || strlen(image) == 0) {
-                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks IMAGE of type STR", item->name);
+                psError(PPSTACK_ERR_ARGUMENTS, true, "Component %s lacks IMAGE of type STR", item->name);
                 psFree(iter);
                 return false;
@@ -169,5 +170,5 @@
                                               image, PM_FPA_FILE_IMAGE); // File for image
             if (!imageFile) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image);
+                psError(psErrorCodeLast(), false, "Unable to define file from image %d (%s)", i, image);
                 return false;
             }
@@ -175,5 +176,5 @@
             if (mask && strlen(mask) > 0 &&
                 !defineFile(config, imageFile, "PPSTACK.INPUT.MASK", mask, PM_FPA_FILE_MASK)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);
+                psError(psErrorCodeLast(), false, "Unable to define file from mask %d (%s)", i, mask);
                 return false;
             }
@@ -183,5 +184,5 @@
                 if (!defineFile(config, imageFile, "PPSTACK.INPUT.VARIANCE", variance,
                                 PM_FPA_FILE_VARIANCE)) {
-                    psError(PS_ERR_UNKNOWN, false,
+                    psError(psErrorCodeLast(), false,
                             "Unable to define file from variance %d (%s)", i, variance);
                     return false;
@@ -195,19 +196,19 @@
                     havePSFs = true;
                     if (!defineFile(config, imageFile, "PPSTACK.INPUT.PSF", psf, PM_FPA_FILE_PSF)) {
-                        psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf);
+                        psError(psErrorCodeLast(), false, "Unable to define file from psf %d (%s)", i, psf);
                         return false;
                     }
                 }
             } else if (havePSFs) {
-                psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF %d", i);
+                psError(PPSTACK_ERR_CONFIG, true, "Unable to find PSF %d", i);
                 return false;
             }
 
             if (!sources || strlen(sources) == 0) {
-                psError(PS_ERR_UNEXPECTED_NULL, true, "SOURCES not provided for file %d", i);
+                psError(PPSTACK_ERR_CONFIG, true, "SOURCES not provided for file %d", i);
                 return false;
             }
             if (!defineFile(config, imageFile, "PPSTACK.INPUT.SOURCES", sources, PM_FPA_FILE_CMF)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to define file from sources %d (%s)",
+                psError(psErrorCodeLast(), false, "Unable to define file from sources %d (%s)",
                         i, sources);
                 return false;
@@ -217,5 +218,6 @@
                 pmFPAfile *kernel = pmFPAfileDefineOutput(config, imageFile->fpa, "PPSTACK.CONV.KERNEL");
                 if (!kernel) {
-                    psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.CONV.KERNEL"));
+                    psError(psErrorCodeLast(), false,
+                            "Unable to generate output file from PPSTACK.CONV.KERNEL");
                     return false;
                 }
@@ -235,5 +237,5 @@
     pmFPA *outFPA = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the output
     if (!outFPA) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
+        psError(psErrorCodeLast(), false, "Unable to construct an FPA from camera configuration.");
         return false;
     }
@@ -241,9 +243,9 @@
     psFree(outFPA);                        // Drop reference
     if (!output) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT"));
+        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT"));
         return false;
     }
     if (output->type != PM_FPA_FILE_IMAGE) {
-        psError(PS_ERR_IO, true, "PPSTACK.OUTPUT is not of type IMAGE");
+        psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT is not of type IMAGE");
         return false;
     }
@@ -251,5 +253,5 @@
 
     if (!pmFPAAddSourceFromFormat(outFPA, "Stack", output->format)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to generate output FPA.");
+        psError(psErrorCodeLast(), false, "Unable to generate output FPA.");
         return false;
     }
@@ -258,9 +260,9 @@
     pmFPAfile *outMask = pmFPAfileDefineOutput(config, output->fpa, "PPSTACK.OUTPUT.MASK");
     if (!outMask) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT.MASK"));
+        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT.MASK"));
         return false;
     }
     if (outMask->type != PM_FPA_FILE_MASK) {
-        psError(PS_ERR_IO, true, "PPSTACK.OUTPUT.MASK is not of type MASK");
+        psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.MASK is not of type MASK");
         return false;
     }
@@ -271,9 +273,9 @@
         pmFPAfile *outVariance = pmFPAfileDefineOutput(config, output->fpa, "PPSTACK.OUTPUT.VARIANCE");
         if (!outVariance) {
-            psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT.VARIANCE"));
+            psError(psErrorCodeLast(), false, "Unable to generate output file from PPSTACK.OUTPUT.VARIANCE");
             return false;
         }
         if (outVariance->type != PM_FPA_FILE_VARIANCE) {
-            psError(PS_ERR_IO, true, "PPSTACK.OUTPUT.VARIANCE is not of type VARIANCE");
+            psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.VARIANCE is not of type VARIANCE");
             return false;
         }
@@ -284,9 +286,9 @@
         pmFPAfile *targetPSF = pmFPAfileDefineOutput(config, output->fpa, "PPSTACK.TARGET.PSF");
         if (!targetPSF) {
-            psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.TARGET.PSF"));
+            psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.TARGET.PSF"));
             return false;
         }
         if (targetPSF->type != PM_FPA_FILE_PSF) {
-            psError(PS_ERR_IO, true, "PPSTACK.TARGET.PSF is not of type PSF");
+            psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.TARGET.PSF is not of type PSF");
             return false;
         }
@@ -298,5 +300,5 @@
     pmFPA *unconvFPA = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain unconvolved output
     if (!unconvFPA) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to construct an FPA from camera configuration.");
+        psError(psErrorCodeLast(), false, "Unable to construct an FPA from camera configuration.");
         return false;
     }
@@ -304,9 +306,9 @@
     psFree(unconvFPA);                  // Drop reference
     if (!unConv) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.UNCONV"));
+        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.UNCONV"));
         return false;
     }
     if (unConv->type != PM_FPA_FILE_IMAGE) {
-        psError(PS_ERR_IO, true, "PPSTACK.UNCONV is not of type IMAGE");
+        psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.UNCONV is not of type IMAGE");
         return false;
     }
@@ -314,5 +316,5 @@
 
     if (!pmFPAAddSourceFromFormat(unconvFPA, "Stack", unConv->format)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to generate output FPA.");
+        psError(psErrorCodeLast(), false, "Unable to generate output FPA.");
         return false;
     }
@@ -321,9 +323,9 @@
     pmFPAfile *unconvMask = pmFPAfileDefineOutput(config, unconvFPA, "PPSTACK.UNCONV.MASK");
     if (!unconvMask) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.UNCONV.MASK"));
+        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.UNCONV.MASK"));
         return false;
     }
     if (unconvMask->type != PM_FPA_FILE_MASK) {
-        psError(PS_ERR_IO, true, "PPSTACK.UNCONV.MASK is not of type MASK");
+        psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.UNCONV.MASK is not of type MASK");
         return false;
     }
@@ -334,9 +336,9 @@
         pmFPAfile *unconvVariance = pmFPAfileDefineOutput(config, unconvFPA, "PPSTACK.UNCONV.VARIANCE");
         if (!unconvVariance) {
-            psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.UNCONV.VARIANCE"));
+            psError(psErrorCodeLast(), false, "Unable to generate output file from PPSTACK.UNCONV.VARIANCE");
             return false;
         }
         if (unconvVariance->type != PM_FPA_FILE_VARIANCE) {
-            psError(PS_ERR_IO, true, "PPSTACK.UNCONV.VARIANCE is not of type VARIANCE");
+            psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.UNCONV.VARIANCE is not of type VARIANCE");
             return false;
         }
@@ -348,9 +350,9 @@
     pmFPAfile *jpeg1 = pmFPAfileDefineOutput(config, NULL, "PPSTACK.OUTPUT.JPEG1");
     if (!jpeg1) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT.JPEG1"));
+        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT.JPEG1"));
         return false;
     }
     if (jpeg1->type != PM_FPA_FILE_JPEG) {
-        psError(PS_ERR_IO, true, "PPSTACK.OUTPUT.JPEG1 is not of type JPEG");
+        psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.JPEG1 is not of type JPEG");
         return false;
     }
@@ -358,9 +360,9 @@
     pmFPAfile *jpeg2 = pmFPAfileDefineOutput(config, NULL, "PPSTACK.OUTPUT.JPEG2");
     if (!jpeg2) {
-        psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT.JPEG2"));
+        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.OUTPUT.JPEG2"));
         return false;
     }
     if (jpeg2->type != PM_FPA_FILE_JPEG) {
-        psError(PS_ERR_IO, true, "PPSTACK.OUTPUT.JPEG2 is not of type JPEG");
+        psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.OUTPUT.JPEG2 is not of type JPEG");
         return false;
     }
@@ -377,13 +379,13 @@
         pmFPAfile *psphotInput = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT");
         if (!psphotInput) {
-            psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.INPUT"));
-            return false;
-        }
-	// specify the number of psphot input images
-	psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
+            psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.INPUT"));
+            return false;
+        }
+        // specify the number of psphot input images
+        psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", 1);
 
         // Define associated psphot input/output files
         if (!psphotDefineFiles(config, psphotInput)) {
-            psError(PSPHOT_ERR_CONFIG, false,
+            psError(psErrorCodeLast(), false,
                     "Trouble defining the additional input/output files for psphot");
             return false;
@@ -393,9 +395,9 @@
         pmFPAfile *outPSF = pmFPAfileDefineOutputFromFile(config, output, "PSPHOT.PSF.SAVE");
         if (!outPSF) {
-            psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.PSF.SAVE"));
+            psError(psErrorCodeLast(), false, _("Unable to generate output file from PSPHOT.PSF.SAVE"));
             return false;
         }
         if (outPSF->type != PM_FPA_FILE_PSF) {
-            psError(PS_ERR_IO, true, "PSPHOT.PSF.SAVE is not of type PSF");
+            psError(PPSTACK_ERR_CONFIG, true, "PSPHOT.PSF.SAVE is not of type PSF");
             return false;
         }
