Index: trunk/ppSkycell/src/ppSkycellLoop.c
===================================================================
--- trunk/ppSkycell/src/ppSkycellLoop.c	(revision 23996)
+++ trunk/ppSkycell/src/ppSkycellLoop.c	(revision 24000)
@@ -44,7 +44,9 @@
 
     REGION_RANGE(0, 0);                 // Lower left
+    psTrace("ppSkycell", 9, "Start: %.0f %.0f", toCoords->x, toCoords->y);
     REGION_RANGE(0, numRows);           // Upper left
     REGION_RANGE(numCols, 0);           // Lower right
     REGION_RANGE(numCols, numRows);     // Upper right
+    psTrace("ppSkycell", 9, "Stop: %.0f %.0f\n", toCoords->x, toCoords->y);
 
     return region;
@@ -185,4 +187,6 @@
     for (int i = 0; i < numProj; i++) {
         psRegion *projRegion = projRegions->data[i]; // Region for skycell projection
+        psTrace("ppSkycell", 2, "Projection %d: [%.0f:%.0f,%.0f:%.0f]\n",
+                i, projRegion->x0, projRegion->x1, projRegion->y0, projRegion->y1);
         int xSize = projRegion->x1 - projRegion->x0 + 1; // Size of unbinned image
         int ySize = projRegion->y1 - projRegion->y0 + 1; // Size of unbinned image
@@ -218,4 +222,16 @@
             psFree(view);
 
+            // Flip images; no idea why this has to be done, but apparently it does
+            {
+                psImage *rot = psImageRotate(NULL, inRO->image, M_PI, NAN, PS_INTERPOLATE_BILINEAR);
+                psFree(inRO->image);
+                inRO->image = rot;
+            }
+            if (inRO->mask) {
+                psImage *rot = psImageRotate(NULL, inRO->mask, M_PI, 0, PS_INTERPOLATE_FLAT);
+                psFree(inRO->mask);
+                inRO->mask = rot;
+            }
+
             pmReadout *bin1RO = pmReadoutAlloc(NULL), *bin2RO = pmReadoutAlloc(NULL); // Binned readouts
             if (!pmReadoutRebin(bin1RO, inRO, data->maskVal, data->bin1, data->bin1)) {
@@ -246,9 +262,34 @@
             psFree(file->fpa);
             file->fpa = NULL;
+            if (data->masksName) {
+                pmFPAfile *file = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.MASK", j);
+                psFree(file->fpa);
+            }
             pmFPAfileActivate(data->config->files, false, NULL);
-
-            psTrace("ppSkycell", 10, "Blah blah blah\n");
-        }
-
+        }
+
+        pmFPAfileActivate(data->config->files, true, "PPSKYCELL.JPEG1");
+        pmFPAfileActivate(data->config->files, true, "PPSKYCELL.JPEG2");
+        pmFPAview *view = filesIterateDown(data->config); // View to readout
+
+        pmCell *cell1 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.JPEG1"); // Rebinned cell 1
+        pmCell *cell2 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.JPEG2"); // Rebinned cell 2
+        psFree(view);
+        pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
+
+        ro1->image = image1;
+        ro2->image = image2;
+
+        ro1->data_exists = cell1->data_exists = cell1->parent->data_exists = true;
+        ro2->data_exists = cell2->data_exists = cell2->parent->data_exists = true;
+
+        pmFPAfile *file1 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.JPEG1", 0);
+        file1->save = true;
+        file1->index = i;
+        pmFPAfile *file2 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.JPEG2", 0);
+        file2->save = true;
+        file2->index = i;
+
+#if 0
         {
             psString filename = NULL;   // Filename for image
@@ -268,7 +309,6 @@
             psFitsClose(fits);
         }
-
-        psFree(image1);
-        psFree(image2);
+#endif
+
     }
 
