Index: /trunk/ppImage/src/ppImageLoop.c
===================================================================
--- /trunk/ppImage/src/ppImageLoop.c	(revision 15215)
+++ /trunk/ppImage/src/ppImageLoop.c	(revision 15216)
@@ -4,4 +4,10 @@
 
 #include "ppImage.h"
+
+# define ESCAPE(MESSAGE) { \
+  psError(PS_ERR_UNKNOWN, false, MESSAGE); \
+  psFree (view); \
+  return false; \
+}
 
 bool ppImageLoop (pmConfig *config, ppImageOptions *options) {
@@ -23,8 +29,5 @@
 
     // files associated with the science image
-    if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-        psFree (view);
-        return false;
-    }
+    if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) ESCAPE ("load failure for FPA");
 
     while ((chip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) {
@@ -33,9 +36,5 @@
             continue;
         }
-
-        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-            psFree (view);
-            return false;
-        }
+        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) ESCAPE ("load failure for Chip");
 
         while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
@@ -44,8 +43,5 @@
                 continue;
             }
-            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-                psFree (view);
-                return false;
-            }
+            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) ESCAPE ("load failure for Cell");
 
             // Put version information into the header
@@ -59,8 +55,5 @@
             // process each of the readouts
             while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
-                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-                    psFree (view);
-                    return false;
-                }
+                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) ESCAPE ("load failure for Readout");
                 if (!readout->data_exists) {
                     continue;
@@ -68,10 +61,6 @@
 
                 // perform the detrend analysis
-                if (!ppImageDetrendReadout(config, options, view)) {
-                    psError(PS_ERR_UNKNOWN, false, "Unable to detrend readout.\n");
-                    psFree (view);
-                    return false;
-                }
-
+                if (!ppImageDetrendReadout(config, options, view)) 
+		    ESCAPE ("Unable to detrend readout");
             }
         }
@@ -79,40 +68,24 @@
         // Apply the fringe correction
         if (options->doFringe) {
-	    if (!ppImageDetrendFringeApply (config, chip, view, options)) {
-                psFree (view);
-                return false;
-            }
+	    if (!ppImageDetrendFringeApply (config, chip, view, options)) 
+		ESCAPE ("Unable to defringe");
 	}
 	
 	// measure various statistics for this image
-	if (!ppImagePixelStats (config, options, view)) {
-	    psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to measures stats for image");
-	    psFree (view);
-	    return false;
-	}
+	if (!ppImagePixelStats (config, options, view)) 
+	    ESCAPE ("Unable to measures stats for image");
 
-        if (!ppImageMosaicChip(config, options, view, "PPIMAGE.CHIP", "PPIMAGE.OUTPUT")) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to mosaic chip.\n");
-            psFree (view);
-            return false;
-        }
-        if (!ppImageRebinChip(config, view, "PPIMAGE.BIN1")) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to bin chip.\n");
-            psFree (view);
-            return false;
-        }
-        if (!ppImageRebinChip(config, view, "PPIMAGE.BIN2")) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to bin chip.\n");
-            psFree (view);
-            return false;
-        }
+        if (!ppImageMosaicChip(config, options, view, "PPIMAGE.CHIP", "PPIMAGE.OUTPUT"))
+            ESCAPE ("Unable to mosaic chip");
+
+        if (!ppImageRebinChip(config, view, "PPIMAGE.BIN1"))
+            ESCAPE ("Unable to bin chip (level 1).");
+
+        if (!ppImageRebinChip(config, view, "PPIMAGE.BIN2"))
+            ESCAPE ("Unable to bin chip (level 2).");
 
         // we perform photometry on the readouts of this chip in the output
         if (options->doPhotom) {
-            if (!ppImagePhotom(config, view)) {
-                psError(PS_ERR_UNKNOWN, false, "error running photometry.\n");
-                psFree (view);
-                return false;
-            }
+            if (!ppImagePhotom(config, view)) ESCAPE ("error running photometry.");
         }
 
@@ -123,16 +96,9 @@
                 continue;
             }
-
-            if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-                psFree(view);
-                return false;
-            }
+            if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) ESCAPE ("save failure for Cell");
         }
 
         // Close chip
-        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-            psFree(view);
-            return false;
-        }
+        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) ESCAPE ("save failure for Chip");
     }
 
@@ -140,15 +106,11 @@
     // it would require us to NOT free PPIMAGE.CHIP until here
     // ppImageMosaicFPA (config, "PPIMAGE.OUTPUT.FPA", "PPIMAGE.CHIP");
-    ppImageMosaicFPA(config, options, "PPIMAGE.OUTPUT.FPA1", "PPIMAGE.BIN1");
-    ppImageMosaicFPA(config, options, "PPIMAGE.OUTPUT.FPA2", "PPIMAGE.BIN2");
+    if (!ppImageMosaicFPA(config, options, "PPIMAGE.OUTPUT.FPA1", "PPIMAGE.BIN1")) ESCAPE ("failure in FPA Mosaic (level 1)");
+    if (!ppImageMosaicFPA(config, options, "PPIMAGE.OUTPUT.FPA2", "PPIMAGE.BIN2")) ESCAPE ("failure in FPA Mosaic (level 2)");
 
     // we perform astrometry on all chips after sources have been detected
     // this also performs the psastro file IO
     if (options->doAstromChip || options->doAstromMosaic) {
-        if (!ppImageAstrom(config)) {
-            psError(PS_ERR_UNKNOWN, false, "error running astrometry.\n");
-            psFree(view);
-            return false;
-        }
+        if (!ppImageAstrom(config)) ESCAPE ("error running astrometry.");
     }
 
@@ -158,22 +120,11 @@
 
     // Write out summary statistics
-    if (!ppImageMetadataStats (config, options)) {
-	psError(PS_ERR_UNKNOWN, false, "Unable to write statistics file.\n");
-	psFree (view);
-	return false;
-    }
+    if (!ppImageMetadataStats (config, options)) ESCAPE ("Unable to write statistics file.");
 
     // Write out summary statistics
-    if (!ppImageStatsOutput (config, options)) {
-	psError(PS_ERR_UNKNOWN, false, "Unable to write statistics file.\n");
-	psFree (view);
-	return false;
-    }
+    if (!ppImageStatsOutput (config, options)) ESCAPE ("Unable to write statistics file.");
 
     // Output and Close FPA
-    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-        psFree(view);
-        return false;
-    }
+    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) ESCAPE ("save failure for FPA");
 
     psFree(view);
Index: /trunk/psastro/src/psastroDataLoad.c
===================================================================
--- /trunk/psastro/src/psastroDataLoad.c	(revision 15215)
+++ /trunk/psastro/src/psastroDataLoad.c	(revision 15216)
@@ -5,4 +5,10 @@
 // into the correct fpa structure locations (readout.analysis:PSPHOT.SOURCES)
 
+# define ESCAPE { \
+  psError(PS_ERR_UNKNOWN, false, "Failure in psastroDataSave"); \
+  psFree (view); \
+  return false; \
+}
+  
 // all of the different astrometry analysis modes use the same data load loop
 bool psastroDataLoad (pmConfig *config) {
@@ -33,30 +39,31 @@
 
     // files associated with the science image
-    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
 
     while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
         psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
-	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
 
 	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
             psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
-	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+	    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
 
 	    // process each of the readouts
 	    while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
-		pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-		if (! readout->data_exists) { continue; }
+		if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
+		if (!readout->data_exists) { continue; }
 
-		psastroConvertReadout (readout, recipe);
+		if (!psastroConvertReadout (readout, recipe)) ESCAPE;
 
-		pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+		if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
 	    }
-	    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
 	}
-	pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
     }
-    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
+
     psFree (view);
     return true;
Index: /trunk/psastro/src/psastroDataSave.c
===================================================================
--- /trunk/psastro/src/psastroDataSave.c	(revision 15215)
+++ /trunk/psastro/src/psastroDataSave.c	(revision 15216)
@@ -2,4 +2,10 @@
 // XXX leak free 2006.04.27
 
+# define ESCAPE { \
+  psError(PS_ERR_UNKNOWN, false, "Failure in psastroDataSave"); \
+  psFree (view); \
+  return false; \
+}
+  
 // this loop saves the photometry/astrometry data files
 bool psastroDataSave (pmConfig *config) {
@@ -30,32 +36,32 @@
 
     // open/load files as needed
-    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
 
     while ((chip = pmFPAviewNextChip (view, output->fpa, 1)) != NULL) {
         psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
-	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
 
 	while ((cell = pmFPAviewNextCell (view, output->fpa, 1)) != NULL) {
             psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
-	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+	    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
 
 	    // process each of the readouts
 	    while ((readout = pmFPAviewNextReadout (view, output->fpa, 1)) != NULL) {
-		pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-		if (! readout->data_exists) { continue; }
+		if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
+		if (!readout->data_exists) { continue; }
 
-		pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+		if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
 	    }
-	    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
 	}
-	pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
     }
-    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
 
     // activate all files except PSASTRO.OUTPUT
-    pmFPAfileActivate (config->files, true, NULL);
-    pmFPAfileActivate (config->files, false, "PSASTRO.OUTPUT");
+    if (!pmFPAfileActivate (config->files, true, NULL)) ESCAPE;
+    if (!pmFPAfileActivate (config->files, false, "PSASTRO.OUTPUT")) ESCAPE;
 
     psFree (view);
Index: /trunk/psphot/src/psphotImageLoop.c
===================================================================
--- /trunk/psphot/src/psphotImageLoop.c	(revision 15215)
+++ /trunk/psphot/src/psphotImageLoop.c	(revision 15216)
@@ -1,3 +1,9 @@
 # include "psphotStandAlone.h"
+
+# define ESCAPE(MESSAGE) { \
+  psError(PSPHOT_ERR_DATA, false, MESSAGE); \
+  psFree (view); \
+  return false; \
+}
 
 bool psphotImageLoop (pmConfig *config) {
@@ -22,9 +28,5 @@
     
     // files associated with the science image
-    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
-	psError(PSPHOT_ERR_DATA, false, "failed IO for fpa in psphot\n");
-	psFree(view);
-	return false;
-    }
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot.");
 
     // for psphot, we force data to be read at the chip level 
@@ -38,15 +40,8 @@
 	pmFPAfileActivate (config->files, true, "PSPHOT.MASK");
 	pmFPAfileActivate (config->files, true, "PSPHOT.WEIGHT");
-	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
-            psError(PSPHOT_ERR_DATA, false, "failed IO for chip %d in psphot\n", view->chip);
-	    psFree (view);
-	    return false;
-	}
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot.");
 
 	// mosaic the cells of a chip into a single contiguous (trimmed) chip
-        if (!psphotMosaicChip(config, view, "PSPHOT.INPUT", "PSPHOT.LOAD")) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to mosaic chip.\n");
-            return false;
-        }
+        if (!psphotMosaicChip(config, view, "PSPHOT.INPUT", "PSPHOT.LOAD")) ESCAPE ("Unable to mosaic chip.");
 
 	// try to load other supporting data (PSF, SRC, etc).
@@ -56,9 +51,6 @@
 	pmFPAfileActivate (config->files, false, "PSPHOT.MASK");
 	pmFPAfileActivate (config->files, false, "PSPHOT.WEIGHT");
-	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
-            psError(PSPHOT_ERR_DATA, false, "failed IO for chip %d in psphot\n", view->chip);
-	    psFree (view);
-	    return false;
-	}
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot.");
+
 	// re-activate files so they will be closed and freed below
 	pmFPAfileActivate (config->files, true, NULL);
@@ -83,21 +75,13 @@
 
 	// save output which is saved at the chip level
-	if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
-            psError(PSPHOT_ERR_DATA, false, "failed IO for chip %d in psphot\n", view->chip);
-	    psFree (view);
-	    return false;
-	}
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot.");
     }
     // save output which is saved at the fpa level
-    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
-	psError(PSPHOT_ERR_DATA, false, "failed IO for fpa in psphot\n");
-	psFree (view);
-	return false;
-    }
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed ouput for FPA in psphot.");
+
+    // fail if we failed to handle an error
+    if (psErrorCodeLast() != PS_ERR_NONE) psAbort ("failed to handle an error!");
 
     psFree (view);
-
-    // fail if we failed to handle an error
-    if (psErrorCodeLast() != PS_ERR_NONE) return false;
     return true;
 }
