Index: trunk/psModules/src/imcombine/pmSubtractionIO.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionIO.c	(revision 26893)
+++ trunk/psModules/src/imcombine/pmSubtractionIO.c	(revision 27086)
@@ -3,4 +3,5 @@
 #include <string.h>
 
+#include "pmErrorCodes.h"
 #include "pmHDU.h"
 #include "pmHDUUtils.h"
@@ -66,5 +67,5 @@
     }
     if (regions->n == 0) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "No subtraction regions found.");
+        psError(PM_ERR_PROG, true, "No subtraction regions found.");
         psFree(regions);
         return false;
@@ -87,5 +88,5 @@
 
     if (regions->n != kernels->n) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Number of regions (%ld) and kernels (%ld) don't match.\n",
+        psError(PM_ERR_PROG, true, "Number of regions (%ld) and kernels (%ld) don't match.\n",
                 regions->n, kernels->n);
         psFree(regions);
@@ -165,5 +166,5 @@
 
     if (!psFitsWriteTable(fits, header, rows, EXTNAME_KERNEL)) {
-        psError(PS_ERR_IO, false, "Unable to write subtraction kernel to FITS table.");
+        psError(psErrorCodeLast(), false, "Unable to write subtraction kernel to FITS table.");
         psFree(header);
         psFree(rows);
@@ -175,5 +176,5 @@
 
     if (image && !psFitsWriteImage(fits, header, image, 0, EXTNAME_IMAGE)) {
-        psError(PS_ERR_IO, false, "Unable to write subtraction kernel image.");
+        psError(psErrorCodeLast(), false, "Unable to write subtraction kernel image.");
         psFree(header);
         psFree(rows);
@@ -201,5 +202,5 @@
         thisView->readout = i;
         if (!pmReadoutWriteSubtractionKernels(readout, file->fits)) {
-            psError(PS_ERR_IO, false, "Failed to write %dth readout", i);
+            psError(psErrorCodeLast(), false, "Failed to write %dth readout", i);
             psFree(thisView);
             return false;
@@ -224,5 +225,5 @@
         thisView->cell = i;
         if (!pmCellWriteSubtractionKernels(cell, thisView, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write %dth cell", i);
+            psError(psErrorCodeLast(), false, "Failed to write %dth cell", i);
             psFree(thisView);
             return false;
@@ -247,5 +248,5 @@
         thisView->chip = i;
         if (!pmChipWriteSubtractionKernels(chip, thisView, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write %dth chip", i);
+            psError(psErrorCodeLast(), false, "Failed to write %dth chip", i);
             psFree(thisView);
             return false;
@@ -265,5 +266,5 @@
 
     if (!psFitsMoveExtName(fits, EXTNAME_KERNEL)) {
-        psError(PS_ERR_IO, false, "Unable to move to subtraction kernel table.");
+        psError(psErrorCodeLast(), false, "Unable to move to subtraction kernel table.");
         return false;
     }
@@ -271,5 +272,5 @@
     psArray *table = psFitsReadTable(fits); // Table of interest
     if (!table) {
-        psError(PS_ERR_IO, false, "Unable to read FITS table");
+        psError(psErrorCodeLast(), false, "Unable to read FITS table");
         return false;
     }
@@ -282,5 +283,5 @@
         TARGET = psMetadataLookup##SUFFIX(&mdok, row, NAME); \
         if (!mdok) { \
-            psError(PS_ERR_UNKNOWN, false, "Unable to find column %s in subtraction kernel table.", NAME); \
+            psError(PM_ERR_PROG, false, "Unable to find column %s in subtraction kernel table.", NAME); \
             psFree(table); \
             return false; \
@@ -325,5 +326,5 @@
             kernels->solution1 = psMemIncrRefCounter(psMetadataLookupPtr(&mdok, row, NAME_SOL1));
             if (!mdok) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to find column %s in subtraction kernel table.",
+                psError(PM_ERR_PROG, false, "Unable to find column %s in subtraction kernel table.",
                         NAME_SOL1);
                 psFree(kernels);
@@ -335,5 +336,5 @@
             kernels->solution1 = psMemIncrRefCounter(psMetadataLookupPtr(&mdok, row, NAME_SOL1));
             if (!mdok) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to find column %s in subtraction kernel table.",
+                psError(PM_ERR_PROG, false, "Unable to find column %s in subtraction kernel table.",
                         NAME_SOL1);
                 psFree(kernels);
@@ -343,5 +344,5 @@
             kernels->solution2 = psMemIncrRefCounter(psMetadataLookupPtr(&mdok, row, NAME_SOL2));
             if (!mdok) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to find column %s in subtraction kernel table.",
+                psError(PM_ERR_PROG, false, "Unable to find column %s in subtraction kernel table.",
                         NAME_SOL2);
                 psFree(kernels);
@@ -379,5 +380,9 @@
         pmReadout *readout = cell->readouts->data[i];
         thisView->readout = i;
-        pmReadoutReadSubtractionKernels(readout, file->fits);
+        if (!pmReadoutReadSubtractionKernels(readout, file->fits)) {
+            psError(psErrorCodeLast(), false, "Unable to read subtraction kernels from cell");
+            psFree(thisView);
+            return false;
+        }
         if (!readout->data_exists) {
             continue;
@@ -410,6 +415,10 @@
         pmCell *cell = chip->cells->data[i];
         thisView->cell = i;
-        pmCellReadSubtractionKernels(cell, thisView, file, config);
-        if (!cell->data_exists) {
+        if (!pmCellReadSubtractionKernels(cell, thisView, file, config)) {
+            psError(psErrorCodeLast(), false, "Unable to read subtraction kernels from cell");
+            psFree(thisView);
+            return false;
+        }
+         if (!cell->data_exists) {
             continue;
         }
@@ -419,5 +428,5 @@
 
     if (!pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_HEADER, true, true, NULL)) {
-        psError(PS_ERR_IO, false, "Failed to read concepts for chip.\n");
+        psError(psErrorCodeLast(), false, "Failed to read concepts for chip.\n");
         return false;
     }
@@ -440,10 +449,14 @@
         pmChip *chip = fpa->chips->data[i];
         thisView->chip = i;
-        pmChipReadSubtractionKernels(chip, thisView, file, config);
+        if (!pmChipReadSubtractionKernels(chip, thisView, file, config)) {
+            psError(psErrorCodeLast(), false, "Unable to read subtraction kernels from chip");
+            psFree(thisView);
+            return false;
+        }
     }
     psFree(thisView);
 
     if (!pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
-        psError(PS_ERR_IO, false, "Failed to read concepts for fpa.\n");
+        psError(psErrorCodeLast(), false, "Failed to read concepts for fpa.\n");
         return false;
     }
@@ -464,5 +477,5 @@
     if (view->chip == -1) {
         if (!pmFPAWriteSubtractionKernels(fpa, view, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write subtraction kernels from fpa");
+            psError(psErrorCodeLast(), false, "Failed to write subtraction kernels from fpa");
             psFree(fpa);
             return false;
@@ -473,5 +486,5 @@
 
     if (view->chip >= fpa->chips->n) {
-        psError(PS_ERR_UNKNOWN, false, "Writing chip == %d (>= chips->n == %ld)", view->chip, fpa->chips->n);
+        psError(PM_ERR_PROG, true, "Writing chip == %d (>= chips->n == %ld)", view->chip, fpa->chips->n);
         psFree(fpa);
         return false;
@@ -481,5 +494,5 @@
     if (view->cell == -1) {
         if (!pmChipWriteSubtractionKernels(chip, view, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write objects from chip");
+            psError(psErrorCodeLast(), false, "Failed to write objects from chip");
             psFree(fpa);
             return false;
@@ -490,5 +503,5 @@
 
     if (view->cell >= chip->cells->n) {
-        psError(PS_ERR_UNKNOWN, false, "Writing cell == %d (>= cells->n == %ld)",
+        psError(PM_ERR_PROG, true, "Writing cell == %d (>= cells->n == %ld)",
                 view->cell, chip->cells->n);
         psFree(fpa);
@@ -499,5 +512,5 @@
     if (view->readout == -1) {
         if (!pmCellWriteSubtractionKernels(cell, view, file, config)) {
-            psError(PS_ERR_IO, false, "Failed to write objects from cell");
+            psError(psErrorCodeLast(), false, "Failed to write objects from cell");
             psFree(fpa);
             return false;
@@ -508,5 +521,5 @@
 
     if (view->readout >= cell->readouts->n) {
-        psError(PS_ERR_UNKNOWN, false, "Writing readout == %d (>= readouts->n == %ld)",
+        psError(PM_ERR_PROG, true, "Writing readout == %d (>= readouts->n == %ld)",
                 view->readout, cell->readouts->n);
         psFree(fpa);
@@ -516,5 +529,5 @@
 
     if (!pmReadoutWriteSubtractionKernels(readout, file->fits)) {
-        psError(PS_ERR_IO, false, "Failed to write objects from readout %d", view->readout);
+        psError(psErrorCodeLast(), false, "Failed to write objects from readout %d", view->readout);
         psFree(fpa);
         return false;
