Index: /trunk/psModules/src/camera/pmFPARead.c
===================================================================
--- /trunk/psModules/src/camera/pmFPARead.c	(revision 7203)
+++ /trunk/psModules/src/camera/pmFPARead.c	(revision 7204)
@@ -118,5 +118,8 @@
     }
 
+    psTrace(__func__, 5, "Reading section [%.0f:%.0f,%.0f:%.0f]\n",
+            toRead.x0, toRead.x1, toRead.y0, toRead.y1);
     psImage *image = psFitsReadImage(fits, toRead, z); // Desired pixels
+    psTrace(__func__, 7, "Image is %dx%d\n", image->numCols, image->numRows);
 
     // XXX: We only support F32 for now
@@ -129,4 +132,6 @@
     if (resize) {
         // For some reason, the region of interest is smaller than the number of pixels we want.
+        psTrace(__func__, 5, "Resizing image to %.0fx%.0f\n",
+                fullSize.x1 - fullSize.x0, fullSize.y1 - fullSize.y0);
         psImage *temp = psImageAlloc(fullSize.x1 - fullSize.x0, fullSize.y1 - fullSize.y0, image->type.type);
         psImageInit(temp, bad);
@@ -232,4 +237,11 @@
     }
 
+    int maxSize;                        // Number of cols,rows in image
+    if (readdir == 1) {
+        maxSize = PS_MIN(naxis2, trimsec->y1);
+    } else {
+        maxSize = PS_MIN(naxis1, trimsec->x1);
+    }
+
     // Read the FITS image
     int offset = 0;                     // The offset from the start of the image to where we are now
@@ -245,20 +257,22 @@
         }
     }
-    if ((readdir == 1 && offset >= naxis2) || (readdir == 2 && offset > naxis1)) {
-        // We've read everything there is
-        return false;
-    }
-    int upper = offset + numScans;      // The upper limit for the pixel read
-    if (readdir == 1 && upper > naxis2) {
-        upper = naxis2;
-    } else if (readdir == 2 && upper > naxis1) {
-        upper = naxis1;
-    }
-
-    // Blow away existing data
+
+    // Blow away existing data.
+    // Do this before returning, so that we're not returning data from a previous read
     psFree(readout->image);
+    readout->image = NULL;
     while (readout->bias->n > 0) {
         psListRemove(readout->bias, PS_LIST_HEAD);
     }
+
+    if (offset >= maxSize) {
+        // We've read everything there is
+        psTrace(__func__, 7, "Read everything.\n");
+        psFree(readout->image);
+        return false;
+    }
+    int upper = PS_MIN(offset + numScans, maxSize); // The upper limit for the pixel read
+    psTrace(__func__, 7, "offset=%d, upper = %d, image is %dx%d, trimsec [%.0f:%.0f,%.0f:%.0f]\n",
+            offset, upper, naxis1, naxis2, trimsec->x0, trimsec->x1, trimsec->y0, trimsec->y1);
 
     // Get the new the trim section
Index: /trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7203)
+++ /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7204)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-24 05:08:52 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-05-25 04:06:28 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -179,4 +179,6 @@
         minInputCols = PS_MIN(minInputCols, readout->col0);
         maxInputCols = PS_MAX(maxInputCols, readout->col0 + readout->image->numCols);
+        psTrace(__func__, 7, "Readout %d: offset %d,%d; size %dx%d\n", i,
+                readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);
         // Bounds of input image
         rowLower->data.U32[i] = readout->row0;
@@ -192,7 +194,8 @@
     // If there's existing images, we need to extend them
     long minOutputRows = (output->image || output->mask || output->weight) ?
-                         PS_MIN(minInputRows, output->row0) : minInputRows; // Smallest row value, considering the output
+                         PS_MIN(minInputRows, output->row0) : minInputRows;  // Smallest output row value
     long minOutputCols = (output->image || output->mask || output->weight) ?
-                         PS_MIN(minInputCols, output->col0) : minInputCols; // Smallest column value, considering the output
+                         PS_MIN(minInputCols, output->col0) : minInputCols; // Smallest output column value
+    psTrace(__func__, 7, "Output minimum: %d,%d\n", minOutputCols, minOutputRows);
 
     // Update the origin
@@ -267,4 +270,8 @@
     psMaskType maskVal = params->maskVal; // The mask value
 
+    psTrace(__func__, 3, "Iterating %d --> %d, %d --> %d\n",
+            minInputCols - output->col0, maxInputCols - output->col0,
+            minInputRows - output->row0, maxInputRows - output->row0);
+
     for (int i = minInputRows; i < maxInputRows; i++) {
         for (int j = minInputCols; j < maxInputCols; j++) {
