Index: trunk/ppImage/src/ppImageLoop.c
===================================================================
--- trunk/ppImage/src/ppImageLoop.c	(revision 15137)
+++ 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);
