Index: trunk/ppSkycell/src/ppSkycell.h
===================================================================
--- trunk/ppSkycell/src/ppSkycell.h	(revision 28043)
+++ trunk/ppSkycell/src/ppSkycell.h	(revision 28375)
@@ -16,4 +16,5 @@
     int bin1, bin2;                     // Binning factors
     pmConfig *config;                   // Configuration
+  bool doFits;                          // hold whether to do fits as well.
 } ppSkycellData;
 
Index: trunk/ppSkycell/src/ppSkycellCamera.c
===================================================================
--- trunk/ppSkycell/src/ppSkycellCamera.c	(revision 28043)
+++ trunk/ppSkycell/src/ppSkycellCamera.c	(revision 28375)
@@ -103,4 +103,12 @@
         return false;
     }
+    if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.BIN1")) {
+        psError(psErrorCodeLast(), false, "Unable to define output.");
+        return false;
+    }
+    if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.BIN2")) {
+        psError(psErrorCodeLast(), false, "Unable to define output.");
+        return false;
+    }
 
     // Now the camera has been determined, we can read the recipe
@@ -116,4 +124,6 @@
     data->bin2 = psMetadataLookupS32(NULL, recipe, "BIN2");
 
+    data->doFits = psMetadataLookupBool(NULL, recipe, "MAKEFITS");
+    
     if (data->bin1 <= 0 || data->bin2 <= 0) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find legitimate values for BIN1 and BIN2");
Index: trunk/ppSkycell/src/ppSkycellLoop.c
===================================================================
--- trunk/ppSkycell/src/ppSkycellLoop.c	(revision 28043)
+++ trunk/ppSkycell/src/ppSkycellLoop.c	(revision 28375)
@@ -284,9 +284,15 @@
         pmFPAfileActivate(data->config->files, true, "PPSKYCELL.JPEG1");
         pmFPAfileActivate(data->config->files, true, "PPSKYCELL.JPEG2");
+	if (data->doFits) {
+	  pmFPAfileActivate(data->config->files, true, "PPSKYCELL.BIN1");
+	  pmFPAfileActivate(data->config->files, true, "PPSKYCELL.BIN2");
+	}
+	
         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
 
@@ -298,11 +304,48 @@
         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;
+        file1->fileIndex = i;
         pmFPAfile *file2 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.JPEG2", 0);
         file2->save = true;
-        file2->index = i;
+        file2->fileIndex = i;
+
+	if (data->doFits) {
+	  pmCell *Fcell1 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN1"); // Rebinned cell 1
+	  pmCell *Fcell2 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN2"); // Rebinned cell 2
+
+	  // This is a hack to get a functioning header created so the fits images can be written out.
+	  psMetadataAddS32(Fcell1->concepts,PS_LIST_TAIL,"CELL.XPARITY", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell1->concepts,PS_LIST_TAIL,"CELL.YPARITY", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell1->concepts,PS_LIST_TAIL,"CELL.READDIR", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell2->concepts,PS_LIST_TAIL,"CELL.XPARITY", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell2->concepts,PS_LIST_TAIL,"CELL.YPARITY", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell2->concepts,PS_LIST_TAIL,"CELL.READDIR", PS_META_REPLACE,"",1);
+
+	  psMetadataAddS32(Fcell1->parent->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell1->parent->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell2->parent->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1);
+	  psMetadataAddS32(Fcell2->parent->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1);
+
+	  pmReadout *Fro1 = pmReadoutAlloc(Fcell1), *Fro2 = pmReadoutAlloc(Fcell2); // Binned readouts
+	  
+	  Fro1->image = image1;
+	  Fro2->image = image2;
+	  Fro1->mask = mask1;
+	  Fro2->mask = mask2;
+	  
+	  Fro1->data_exists = Fcell1->data_exists = Fcell1->parent->data_exists = true;
+	  Fro2->data_exists = Fcell2->data_exists = Fcell2->parent->data_exists = true;
+	  
+	  pmFPAfile *fits1 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.BIN1", 0);
+	  fits1->save = true;
+	  fits1->fileIndex = i;
+	  pmFPAfile *fits2 = pmFPAfileSelectSingle(data->config->files, "PPSKYCELL.BIN2", 0);
+	  fits2->save = true;
+	  fits2->fileIndex = i;
+	}
+
+        psFree(view);
 #if 0
         {
