Index: /tags/ipp-20120404/ippconfig/gpc1/ghost.model.mdc
===================================================================
--- /tags/ipp-20120404/ippconfig/gpc1/ghost.model.mdc	(revision 33851)
+++ /tags/ipp-20120404/ippconfig/gpc1/ghost.model.mdc	(revision 33852)
@@ -1,15 +1,83 @@
+# Original center models
+# GHOST.CENTER.X METADATA
+#   NORDER_X S32 3
+#   NORDER_Y S32 3
+#   VAL_X00_Y00  F64 -4.421024e+01
+#   VAL_X01_Y00  F64 1.216270e-02
+#   VAL_X02_Y00  F64 -9.721643e-08
+#   VAL_X03_Y00  F64 9.976554e-11
+#   VAL_X00_Y01  F64 -1.762476e-03
+#   VAL_X01_Y01  F64 1.247212e-07
+#   VAL_X02_Y01  F64 3.629557e-11
+#   VAL_X00_Y02  F64 -1.040174e-07
+#   VAL_X01_Y02  F64 1.074674e-10
+#   VAL_X00_Y03  F64 1.564112e-11
+#   NELEMENTS  S32 10
+# END
+
+# GHOST.CENTER.Y METADATA
+#   NORDER_X S32 3
+#   NORDER_Y S32 3
+#   VAL_X00_Y00  F64 -2.189470e+00
+#   VAL_X01_Y00  F64 -4.186514e-03
+#   VAL_X02_Y00  F64 1.131554e-07
+#   VAL_X03_Y00  F64 1.415192e-11
+#   VAL_X00_Y01  F64 1.569104e-02
+#   VAL_X01_Y01  F64 -1.782801e-07
+#   VAL_X02_Y01  F64 8.179602e-11
+#   VAL_X00_Y02  F64 2.577055e-07
+#   VAL_X01_Y02  F64 8.879423e-11
+#   VAL_X00_Y03  F64 5.767429e-11
+#   NELEMENTS  S32 10
+# END
+
+# Updated models of 2012-05-07
+# Corrected(?) parity
+# GHOST.CENTER.X METADATA
+#   NORDER_X S32 3
+#   NORDER_Y S32 3
+#   VAL_X00_Y00  F64  3.314569e+01
+#   VAL_X01_Y00  F64  1.110664e-02
+#   VAL_X02_Y00  F64 -1.904158e-07
+#   VAL_X03_Y00  F64  8.470224e-11
+#   VAL_X00_Y01  F64 -1.616877e-03
+#   VAL_X01_Y01  F64  1.646508e-07
+#   VAL_X02_Y01  F64  5.623381e-11
+#   VAL_X00_Y02  F64 -2.342888e-07
+#   VAL_X01_Y02  F64  1.023761e-10
+#   VAL_X00_Y03  F64  2.836980e-11
+#   NELEMENTS  S32 10
+# END
+
+# GHOST.CENTER.Y METADATA
+#   NORDER_X S32 3
+#   NORDER_Y S32 3
+#   VAL_X00_Y00  F64 -2.860068e+01
+#   VAL_X01_Y00  F64 -8.790076e-03
+#   VAL_X02_Y00  F64  2.456534e-07
+#   VAL_X03_Y00  F64  2.947749e-11
+#   VAL_X00_Y01  F64  1.948855e-02
+#   VAL_X01_Y01  F64 -2.639927e-07
+#   VAL_X02_Y01  F64  4.951474e-11
+#   VAL_X00_Y02  F64  4.341716e-07
+#   VAL_X01_Y02  F64  1.643046e-10
+#   VAL_X00_Y03  F64 -1.737983e-12
+#   NELEMENTS  S32 10
+# END
+
+# Switched order
 GHOST.CENTER.X METADATA
   NORDER_X S32 3
   NORDER_Y S32 3
-  VAL_X00_Y00  F64 -4.421024e+01
-  VAL_X01_Y00  F64 1.216270e-02
-  VAL_X02_Y00  F64 -9.721643e-08
-  VAL_X03_Y00  F64 9.976554e-11
-  VAL_X00_Y01  F64 -1.762476e-03
-  VAL_X01_Y01  F64 1.247212e-07
-  VAL_X02_Y01  F64 3.629557e-11
-  VAL_X00_Y02  F64 -1.040174e-07
-  VAL_X01_Y02  F64 1.074674e-10
-  VAL_X00_Y03  F64 1.564112e-11
+  VAL_X00_Y00  F64 -1.215661e+02
+  VAL_X01_Y00  F64  1.321875e-02
+  VAL_X02_Y00  F64 -4.017026e-09
+  VAL_X03_Y00  F64  1.148288e-10
+  VAL_X00_Y01  F64 -1.908074e-03
+  VAL_X01_Y01  F64  8.479150e-08
+  VAL_X02_Y01  F64  1.635732e-11
+  VAL_X00_Y02  F64  2.625405e-08
+  VAL_X01_Y02  F64  1.125586e-10
+  VAL_X00_Y03  F64  2.912432e-12
   NELEMENTS  S32 10
 END
@@ -18,17 +86,54 @@
   NORDER_X S32 3
   NORDER_Y S32 3
-  VAL_X00_Y00  F64 -2.189470e+00
-  VAL_X01_Y00  F64 -4.186514e-03
-  VAL_X02_Y00  F64 1.131554e-07
-  VAL_X03_Y00  F64 1.415192e-11
-  VAL_X00_Y01  F64 1.569104e-02
-  VAL_X01_Y01  F64 -1.782801e-07
-  VAL_X02_Y01  F64 8.179602e-11
-  VAL_X00_Y02  F64 2.577055e-07
-  VAL_X01_Y02  F64 8.879423e-11
-  VAL_X00_Y03  F64 5.767429e-11
+  VAL_X00_Y00  F64  2.422174e+01
+  VAL_X01_Y00  F64  4.170486e-04
+  VAL_X02_Y00  F64 -1.934260e-08
+  VAL_X03_Y00  F64 -1.173657e-12
+  VAL_X00_Y01  F64  1.189352e-02
+  VAL_X01_Y01  F64 -9.256748e-08
+  VAL_X02_Y01  F64  1.140772e-10
+  VAL_X00_Y02  F64  8.123932e-08
+  VAL_X01_Y02  F64  1.328378e-11
+  VAL_X00_Y03  F64  1.170865e-10
   NELEMENTS  S32 10
 END
 
+
+
+# These are semi-major/minor axes
+# These are my (CZW) quadratic solutions
+# GHOST.INNER.MAJOR METADATA
+#   NORDER_X S32 2
+#   VAL_X00  F64 2.2622e+01
+#   VAL_X01  F64 1.3822e-02
+#   VAL_X02  F64 -3.7005e-07
+#   NELEMENTS  S32 3
+# END
+
+# GHOST.INNER.MINOR METADATA
+#   NORDER_X S32 2
+#   VAL_X00  F64 4.9626e+01
+#   VAL_X01  F64 -2.4257e-04
+#   VAL_X02  F64 -1.2007e-07
+#   NELEMENTS  S32 3
+# END
+
+# GHOST.OUTER.MAJOR METADATA
+#   NORDER_X S32 2
+#   VAL_X00  F64 9.6490e+01
+#   VAL_X01  F64 9.4250e-03
+#   VAL_X02  F64 6.5680e-07
+#   NELEMENTS  S32 3
+# END
+
+# GHOST.OUTER.MINOR METADATA
+#   NORDER_X S32 2
+#   VAL_X00  F64 9.5450e+01
+#   VAL_X01  F64 2.8775e-03
+#   VAL_X02  F64 -3.1409e-07
+#   NELEMENTS  S32 3
+# END
+
+# These are the original linear solutions
 GHOST.INNER.MAJOR METADATA
   NORDER_X S32 1
Index: /tags/ipp-20120404/ippconfig/gpc1/ppImage.config
===================================================================
--- /tags/ipp-20120404/ippconfig/gpc1/ppImage.config	(revision 33851)
+++ /tags/ipp-20120404/ippconfig/gpc1/ppImage.config	(revision 33852)
@@ -25,5 +25,8 @@
 NOISEMAP                BOOL    FALSE          # Apply read noise map
 
-
+# Final detrending options 
+HAS.VIDEO       BOOL    FALSE           # Treat this OTA as if it has video data
+USE.VIDEO.DARK  BOOL    FALSE           # Use a video dark if we have video data?
+USE.VIDEO.MASK  BOOL    TRUE            # Use a video mask if we have video data?
 
 
Index: /tags/ipp-20120404/ippconfig/gpc1/psastro.config
===================================================================
--- /tags/ipp-20120404/ippconfig/gpc1/psastro.config	(revision 33851)
+++ /tags/ipp-20120404/ippconfig/gpc1/psastro.config	(revision 33852)
@@ -130,5 +130,5 @@
   ZEROPT   F32 24.563
   PHOTCODE STR g
-  GHOST_MAX_MAG                   F32 -20.0
+  GHOST_MAX_MAG                   F32 -18.0
 END
 PHOTCODE.DATA METADATA
Index: /tags/ipp-20120404/ippconfig/recipes/filerules-mef.mdc
===================================================================
--- /tags/ipp-20120404/ippconfig/recipes/filerules-mef.mdc	(revision 33851)
+++ /tags/ipp-20120404/ippconfig/recipes/filerules-mef.mdc	(revision 33852)
@@ -59,6 +59,8 @@
 PPIMAGE.INPUT.SRC       INPUT    @FILES        CHIP       CMF
 PPIMAGE.MASK            INPUT    @DETDB        CHIP       MASK
+PPIMAGE.VIDEOMASK       INPUT    @DETDB        CHIP       MASK
 PPIMAGE.BIAS            INPUT    @DETDB        CHIP       IMAGE
 PPIMAGE.DARK            INPUT    @DETDB        CHIP       DARK
+PPIMAGE.VIDEODARK       INPUT    @DETDB        CHIP       DARK
 PPIMAGE.FLAT            INPUT    @DETDB        CHIP       IMAGE
 PPIMAGE.FRINGE          INPUT    @DETDB        CHIP       FRINGE
Index: /tags/ipp-20120404/ippconfig/recipes/filerules-simple.mdc
===================================================================
--- /tags/ipp-20120404/ippconfig/recipes/filerules-simple.mdc	(revision 33851)
+++ /tags/ipp-20120404/ippconfig/recipes/filerules-simple.mdc	(revision 33852)
@@ -23,6 +23,8 @@
 PPIMAGE.INPUT.SRC         INPUT    @FILES        READOUT    CMF       
 PPIMAGE.MASK              INPUT    @DETDB        CHIP       MASK
+PPIMAGE.VIDEOMASK         INPUT    @DETDB        CHIP       MASK
 PPIMAGE.BIAS              INPUT    @DETDB        CHIP       IMAGE     
 PPIMAGE.DARK              INPUT    @DETDB        CHIP       DARK     
+PPIMAGE.VIDEODARK         INPUT    @DETDB        CHIP       DARK
 PPIMAGE.FLAT              INPUT    @DETDB        CHIP       IMAGE     
 PPIMAGE.FRINGE            INPUT    @DETDB        CHIP       FRINGE
Index: /tags/ipp-20120404/ippconfig/recipes/filerules-split.mdc
===================================================================
--- /tags/ipp-20120404/ippconfig/recipes/filerules-split.mdc	(revision 33851)
+++ /tags/ipp-20120404/ippconfig/recipes/filerules-split.mdc	(revision 33852)
@@ -36,4 +36,5 @@
 PPIMAGE.INPUT             INPUT    @FILES        CHIP       IMAGE
 PPIMAGE.INPUT.MASK        INPUT    @FILES        CHIP       MASK
+PPIMAGE.VIDEOMASK         INPUT    @DETDB        CHIP       MASK
 PPIMAGE.INPUT.VARIANCE    INPUT    @FILES        CHIP       VARIANCE
 PPIMAGE.INPUT.PSF         INPUT    @FILES        CHIP       PSF
@@ -43,4 +44,5 @@
 PPIMAGE.NOISEMAP          INPUT    @DETDB        CHIP       IMAGE
 PPIMAGE.DARK              INPUT    @DETDB        CHIP       DARK
+PPIMAGE.VIDEODARK         INPUT    @DETDB        CHIP       DARK
 PPIMAGE.FLAT              INPUT    @DETDB        CHIP       IMAGE
 PPIMAGE.FRINGE            INPUT    @DETDB        CHIP       FRINGE
Index: /tags/ipp-20120404/ippconfig/recipes/ppImage.config
===================================================================
--- /tags/ipp-20120404/ippconfig/recipes/ppImage.config	(revision 33851)
+++ /tags/ipp-20120404/ippconfig/recipes/ppImage.config	(revision 33852)
@@ -153,4 +153,9 @@
 
 GAIN.OVERRIDE	BOOL	FALSE		# Override a non-finite gain?
+
+# Final detrending options 
+HAS.VIDEO       BOOL    FALSE           # Treat this OTA as if it has video data
+USE.VIDEO.DARK  BOOL    FALSE           # Use a video dark if we have video data?
+USE.VIDEO.MASK  BOOL    FALSE           # Use a video mask if we have video data?
 
 DETREND.CONSTRAINTS  METADATA
Index: /tags/ipp-20120404/ppImage/src/ppImage.h
===================================================================
--- /tags/ipp-20120404/ppImage/src/ppImage.h	(revision 33851)
+++ /tags/ipp-20120404/ppImage/src/ppImage.h	(revision 33852)
@@ -57,4 +57,8 @@
     bool addNoise;                      // Add noise to degrade MD image to 3pi
 
+  bool hasVideo;                      // Determine if this OTA has a video cell
+  bool useVideoDark;                  // Should we use a video dark if we can?
+  bool useVideoMask;                  // Should we use a video mask if we can?
+  
     // output files requested
     bool BaseFITS;
Index: /tags/ipp-20120404/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- /tags/ipp-20120404/ppImage/src/ppImageDetrendReadout.c	(revision 33851)
+++ /tags/ipp-20120404/ppImage/src/ppImageDetrendReadout.c	(revision 33852)
@@ -35,5 +35,18 @@
       }
     }
-
+    // Check to see if we're in a chip that contains video
+    bool hasVideo = false;
+    {
+      if (psMetadataLookupStr(NULL,input->parent->parent->hdu->header,"CELLMODE")) {
+	psWarning("VIDEO: %d %d %d\n",(int) options->hasVideo,(int) options->useVideoDark, (int) options->useVideoMask);
+	char *Vptr = strchr(psMetadataLookupStr(NULL,input->parent->parent->hdu->header,"CELLMODE"),'V');
+	if (Vptr) {
+	  hasVideo = true;
+	  psWarning("VIDEO: %d %d %d\n",(int) options->hasVideo,(int) options->useVideoDark, (int) options->useVideoMask);
+	}
+      }
+    }
+
+    
     // Masking on the basis of pixel value needs to be done before anything else, so the values are pristine.
     if (options->doMaskBuild) {
@@ -44,6 +57,12 @@
     // apply the externally supplied mask to the input->mask pixels
     if (options->doMask) {
-        pmReadout *mask = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.MASK");
-        pmMaskBadPixels(input, mask, options->maskValue);
+      pmReadout *mask;
+      if ((options->useVideoMask)&&(hasVideo)) {
+        mask = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.VIDEOMASK");
+      }
+      else {
+	mask = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.MASK");
+      }
+      pmMaskBadPixels(input, mask, options->maskValue);
     }
     if (options->doMaskBurntool) {
@@ -80,9 +99,19 @@
         psMetadata *recipe = psMetadataLookupPtr (&mdok, config->recipes, RECIPE_NAME);
         assert(mdok && recipe);
-        if (psMetadataLookupBool(&mdok, recipe, "OLDDARK")) {
+
+	if ((options->useVideoDark)&&(hasVideo)) {
+	  if (psMetadataLookupBool(&mdok, recipe, "OLDDARK")) {
+            oldDark = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.VIDEODARK");
+	  } else {
+            dark = pmFPAfileThisCell(config->files, detview, "PPIMAGE.VIDEODARK");
+	  }
+	}
+	else {
+	  if (psMetadataLookupBool(&mdok, recipe, "OLDDARK")) {
             oldDark = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.DARK");
-        } else {
+	  } else {
             dark = pmFPAfileThisCell(config->files, detview, "PPIMAGE.DARK");
-        }
+	  }
+	}
     }
 
Index: /tags/ipp-20120404/ppImage/src/ppImageOptions.c
===================================================================
--- /tags/ipp-20120404/ppImage/src/ppImageOptions.c	(revision 33851)
+++ /tags/ipp-20120404/ppImage/src/ppImageOptions.c	(revision 33852)
@@ -45,5 +45,7 @@
     options->doMaskStats     = false;   // Calculate mask fractions
     options->addNoise        = false;  //Degrade an MD image to a 3pi image
-
+    options->hasVideo        = false;   // Determine if this OTA has a video cell
+    options->useVideoDark    = false;   // Use video dark if we can?
+    options->useVideoMask    = false;   // Use video mask if we can?
     // output files requested
     options->BaseFITS        = false;   // create output image
@@ -362,4 +364,12 @@
     options->fringeKeep = psMetadataLookupF32(NULL, recipe, "FRINGE.KEEP");
 
+    // Video cell options
+    if (psMetadataLookup(recipe, "USE.VIDEO.DARK")) {
+      options->useVideoDark = psMetadataLookupBool(NULL,recipe,"USE.VIDEO.DARK");
+    }
+    if (psMetadataLookup(recipe, "USE.VIDEO.MASK")) {
+      options->useVideoMask = psMetadataLookupBool(NULL,recipe,"USE.VIDEO.MASK");
+    }
+
     // Pattern correction
     if (psMetadataLookup(format, "PATTERN.ROW.ORDER")) {
@@ -418,5 +428,5 @@
       options->patternContinuityEdgeWidth = psMetadataLookupS32(NULL, recipe, "PATTERN.CONTINUITY.WIDTH");
     }
-    
+
 
     // Remnance options
Index: /tags/ipp-20120404/ppImage/src/ppImageParseCamera.c
===================================================================
--- /tags/ipp-20120404/ppImage/src/ppImageParseCamera.c	(revision 33851)
+++ /tags/ipp-20120404/ppImage/src/ppImageParseCamera.c	(revision 33852)
@@ -22,4 +22,28 @@
     ppImageOptions *options = ppImageOptionsParse(config);
 
+    // parse the header to extract out whether this OTA has video cells.
+    // CZW: 2012-05-01 I'm somewhat ashamed of what needs to be done to get to the header. There has to be a simpler way, right?
+/*     pmFPAview *view = pmFPAviewAlloc(0);// View for level of interest */
+/*     pmChip *chip;                       // Chip from FPA */
+/*     while ((chip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) { */
+/*       if (!chip->process || !chip->file_exists) { */
+/* 	continue; */
+/*       } */
+/* /\*       if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { *\/ */
+/* /\* 	continue; *\/ */
+/* /\*       } *\/ */
+/*       psWarning("VIDEO: %d %d %d\n",(int) options->hasVideo,(int) options->useVideoDark, (int) options->useVideoMask); */
+/*       if (psMetadataLookupStr(NULL,chip->hdu->header,"CELLMODE")) { */
+/* 	psWarning("VIDEO: %d %d %d\n",(int) options->hasVideo,(int) options->useVideoDark, (int) options->useVideoMask); */
+/* 	char *Vptr = strchr(psMetadataLookupStr(NULL,chip->hdu->header,"CELLMODE"),'V'); */
+/* 	if (Vptr) { */
+/* 	  options->hasVideo = true; */
+/* 	  psWarning("VIDEO: %d %d %d\n",(int) options->hasVideo,(int) options->useVideoDark, (int) options->useVideoMask); */
+/* 	} */
+/*       } */
+/*     } */
+/*     pmFPAviewReset(view); */
+/*     psFree(view); */
+    
     // the following are defined from the argument list, if given,
     // otherwise they revert to the config information
@@ -42,18 +66,38 @@
     }
     if (options->doDark) {
-        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.DARK", "DARK",
-                               PM_FPA_FILE_DARK, PM_DETREND_TYPE_DARK)) {
+      // Always load the regular Dark
+      if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.DARK", "DARK",
+			     PM_FPA_FILE_DARK, PM_DETREND_TYPE_DARK)) {
+	psError(PS_ERR_IO, false, "Can't find a dark image source");
+	psFree(options);
+	return NULL;
+      }
+      // Sometimes load the video dark if we need it.
+      if (options->useVideoDark) {
+        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.VIDEODARK", "DARK",
+                               PM_FPA_FILE_DARK, PM_DETREND_TYPE_VIDEODARK)) {
             psError(PS_ERR_IO, false, "Can't find a dark image source");
             psFree(options);
             return NULL;
         }
+      }
     }
     if (options->doMask) {
-        if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.MASK", "MASK",
-                               PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
+      // Always load the regular mask
+      if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.MASK", "MASK",
+			     PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
+	psError(PS_ERR_IO, false, "Can't find a mask image source");
+	psFree(options);
+	return NULL;
+      }
+
+      if (options->useVideoMask) {
+	if (!ppImageDefineFile(config, input->fpa, "PPIMAGE.VIDEOMASK", "MASK",
+                               PM_FPA_FILE_MASK, PM_DETREND_TYPE_VIDEOMASK)) {
             psError(PS_ERR_IO, false, "Can't find a mask image source");
             psFree(options);
             return NULL;
         }
+      }
     }
     if (options->doShutter) {
Index: /tags/ipp-20120404/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- /tags/ipp-20120404/psModules/src/detrend/pmDetrendDB.c	(revision 33851)
+++ /tags/ipp-20120404/psModules/src/detrend/pmDetrendDB.c	(revision 33852)
@@ -107,4 +107,6 @@
         DETREND_STRING_CASE(ASTROM);
         DETREND_STRING_CASE(NOISEMAP);
+	DETREND_STRING_CASE(VIDEOMASK);
+	DETREND_STRING_CASE(VIDEODARK);
 	DETREND_STRING_CASE(LINEARITY);
     default:
Index: /tags/ipp-20120404/psModules/src/detrend/pmDetrendDB.h
===================================================================
--- /tags/ipp-20120404/psModules/src/detrend/pmDetrendDB.h	(revision 33851)
+++ /tags/ipp-20120404/psModules/src/detrend/pmDetrendDB.h	(revision 33852)
@@ -36,4 +36,6 @@
     PM_DETREND_TYPE_ASTROM,
     PM_DETREND_TYPE_NOISEMAP,
+    PM_DETREND_TYPE_VIDEOMASK,
+    PM_DETREND_TYPE_VIDEODARK,
     PM_DETREND_TYPE_LINEARITY,
 } pmDetrendType;
Index: /tags/ipp-20120404/psastro/src/psastroLoadCrosstalk.c
===================================================================
--- /tags/ipp-20120404/psastro/src/psastroLoadCrosstalk.c	(revision 33851)
+++ /tags/ipp-20120404/psastro/src/psastroLoadCrosstalk.c	(revision 33852)
@@ -53,5 +53,5 @@
   pmFPAview *viewMask = pmFPAviewAlloc (0);
 
-  float zeropt, exptime, MAX_MAG;
+  float zeropt, exptime, MAX_MAG, SPIKE_MAX_MAG;
 
   psLogMsg ("psastro", PS_LOG_INFO, "determine crosstalk positions");
@@ -105,4 +105,8 @@
   MAX_MAG += MagOffset;
 
+  // Get the spike maximum, as well
+  SPIKE_MAX_MAG = psMetadataLookupF32(&status, recipe, "REFSTAR_MASK_BLEED_MAG_MAX");
+  SPIKE_MAX_MAG += MagOffset;
+  
   psTrace("psastro.crosstalk",2,"%f %f %f %f\n",zeropt,exptime,MAX_MAG,MagOffset);
 
@@ -259,5 +263,5 @@
 
             pmAstromObj *crosstalk = pmAstromObjAlloc();
-
+	    
             crosstalk->Mag = ref->Mag - MagOffset;
             crosstalk->chip->x = x_t_chip;
@@ -274,8 +278,92 @@
             }
             psArrayAdd(crosstalks,100,crosstalk);
-
+	    
             psFree(targetChipName);
             psFree(targetCellName);
             psFree(crosstalk);
+
+	    // Determine if we need to add a spike mask.
+/* 	    psWarning("BLAH: %g %g %g\n",ref->Mag,MagOffset,SPIKE_MAX_MAG); */
+	    if (ref->Mag < SPIKE_MAX_MAG) {
+	      if ((X == 2)&&(! ((U == 3)||(U == 5)||(U == 6)))) {
+		psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
+		continue;
+	      }
+	      if ((X == 3)&&(! ((U == 3)))) {
+		psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
+		continue;
+	      }
+	      if ((X == 4)&&(! ((U == 3)))) {
+		psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
+		continue;
+	      }
+	      if ((X == 5)&&(! ((U == 3)||(U == 5)||(U == 6)))) {
+		psTrace ("psastro.crosstalk",2,"Cell (%d%d) on chip (%d%d) not a known crosstalk source.",U,V,X,Y);
+		continue;
+	      }
+	      
+	      Xt = X;
+	      Yt = Y;
+	      Vt = V;
+	      
+	      for (Ut = 0; Ut < 8; Ut++) {
+
+		psString targetChipName = NULL;
+		psStringAppend(&targetChipName,"XY%d%d",Xt,Yt);
+		psString targetCellName = NULL;
+		psStringAppend(&targetCellName,"xy%d%d",Ut,Vt);
+		
+		psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]",
+			 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,
+			 targetChipName,targetCellName);
+/* 		psWarning ("CT bleed ct @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f [%s %s]", */
+/* 			 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell, */
+/* 			 targetChipName,targetCellName); */
+		
+		pmCell *CTtargetCell = getCellByName (CTsourceChip,targetCellName);
+		if (!CTtargetCell) continue;
+		
+		pmChipCoordsForCell(&x_t_chip,&y_t_chip,CTtargetCell,x_t_cell,y_t_cell);
+
+		psTrace ("psastro.crosstalk",2,"CTsource @ OTA%d%dxy%d%d@%f,%f CTtarget OTA%d%dxy%d%d@%f,%f ChipLoc: (%f,%f)",
+			 X,Y,U,V,x_cell,y_cell,Xt,Yt,Ut,Vt,x_t_cell,y_t_cell,x_t_chip,y_t_chip);
+		
+		// Hunt down the readout for the target, and save the chip position and magnitude of source star.
+		pmChip *targetChip = getChipByName(fpa,targetChipName);
+		if (!targetChip) continue;
+		if (!targetChip->cells) continue;
+		if (!targetChip->cells->n) continue;
+		
+		pmCell *targetCell = targetChip->cells->data[0];
+		if (!targetCell) continue;
+		if (!targetCell->readouts) continue;
+		if (!targetCell->readouts->n) continue;
+		pmReadout *targetReadout = targetCell->readouts->data[0];
+		if (!targetReadout) continue;
+		
+		pmAstromObj *crosstalk = pmAstromObjAlloc();
+		
+		crosstalk->Mag = ref->Mag;
+		crosstalk->chip->x = x_t_chip;
+		crosstalk->chip->y = y_t_chip;
+		
+		psArray *crosstalks = psMetadataLookupPtr (&status, targetReadout->analysis, "PSASTRO.CROSSTALKS.SPIKES");
+		if (crosstalks == NULL) {
+		  crosstalks = psArrayAllocEmpty(100);
+		  if (!psMetadataAdd(targetReadout->analysis,PS_LIST_TAIL,"PSASTRO.CROSSTALKS.SPIKES", PS_DATA_ARRAY, "crosstalk locations", crosstalks)) {
+		    psError(PSASTRO_ERR_CONFIG, false, "failure to add crosstalks to readout");
+		    goto escape;
+		  }
+		  psFree(crosstalks);
+		}
+		psArrayAdd(crosstalks,100,crosstalk);
+		
+		psFree(targetChipName);
+		psFree(targetCellName);
+		psFree(crosstalk);
+	      }
+	    } // End satspike crosstalks
+
+	    
           } // refstars
         } // readout
Index: /tags/ipp-20120404/psastro/src/psastroLoadGhosts.c
===================================================================
--- /tags/ipp-20120404/psastro/src/psastroLoadGhosts.c	(revision 33851)
+++ /tags/ipp-20120404/psastro/src/psastroLoadGhosts.c	(revision 33852)
@@ -128,4 +128,5 @@
                 for (int i = 0; i < refstars->n; i++) {
                     pmAstromObj *ref = refstars->data[i];
+		    psTrace("psastro.ghost",5,"Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g)",i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI);
                     if (ref->Mag > MAX_MAG) continue;
 
@@ -163,11 +164,46 @@
 		    pmChip *ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, -ghost->srcFP->x, -ghost->srcFP->y);
 		    // fprintf (stderr, "raw chip position: %f, %f ", ghost->chip->x, ghost->chip->y);
-
+		    float ref_chip_x = ghost->chip->x;
+		    float ref_chip_y = ghost->chip->y;
 		    ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
 		    // fprintf (stderr, "-> model chip position: %f, %f\n", ghost->chip->x, ghost->chip->y);
 
+		    if (ghostChip) {
+		      psTrace("psastro.ghost",5,"   in ghost: %d/%ld: ref: (%f,%f) or (%f,%f,%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)",
+			      i,refstars->n,
+			      ref->FP->x,ref->FP->y,
+			      ref_chip_x,ref_chip_y,psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"),
+			      ghost->FP->x,ghost->FP->y,
+			      ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"),
+			      rSrc,
+			      ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
+			      ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
+/* 		      psWarning("   GHOST_DATA: %d/%ld: ref: (%f,%f) or (%f,%f,%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)", */
+/* 			      i,refstars->n, */
+/* 			      ref->FP->x,ref->FP->y, */
+/* 			      ref_chip_x,ref_chip_y,psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"), */
+/* 			      ghost->FP->x,ghost->FP->y, */
+/* 			      ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"), */
+/* 			      rSrc, */
+/* 			      ghost->inner.major,ghost->inner.minor,ghost->inner.theta, */
+/* 			      ghost->outer.major,ghost->outer.minor,ghost->outer.theta); */
+		    }
+		    else {
+		      psTrace("psastro.ghost",5,"   in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)",
+			      i,refstars->n,
+			      ref->FP->x,ref->FP->y,
+			      ghost->FP->x,ghost->FP->y,
+			      ghost->chip->x,ghost->chip->y,"NONE",
+			      ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
+			      ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
+		    }		      
+		      
+
+			    
 		    if (!ghostChip) goto skip;
 		    if (!ghostChip->cells) goto skip;
 		    if (!ghostChip->cells->n) goto skip;
+
+		    
 		    pmCell *ghostCell = ghostChip->cells->data[0];
 		    if (!ghostCell) goto skip;
@@ -190,4 +226,5 @@
 
 		skip:
+		    
 		    psFree (ghost);
                 }
Index: /tags/ipp-20120404/psastro/src/psastroMaskUpdates.c
===================================================================
--- /tags/ipp-20120404/psastro/src/psastroMaskUpdates.c	(revision 33851)
+++ /tags/ipp-20120404/psastro/src/psastroMaskUpdates.c	(revision 33852)
@@ -406,4 +406,31 @@
                     // XXX for now, assume cell binning is 1x1 relative to chip
                     psastroMaskCircle (readoutMask->mask, crosstalkMaskValue, ref->chip->x, ref->chip->y, radius, radius);
+                  }
+                }
+		// Crosstalk Bleeds
+                psArray *bleedcrosstalks = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.CROSSTALKS.SPIKES");
+                if (bleedcrosstalks) {
+                  for (int i = 0; i < bleedcrosstalks->n; i++) {
+                    pmAstromObj *ref = bleedcrosstalks->data[i];
+                    float width = REFSTAR_MASK_BLEED_MAG_SLOPE * (REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);
+                    psTrace("psastro.crosstalk",2,"Masking spike on Chip %s @ (%f,%f) Magnitude: %f Radius %f\n",
+                            psMetadataLookupStr(&status,readout->parent->parent->concepts,"CHIP.NAME"),
+                            ref->chip->x,ref->chip->y,ref->Mag,width);
+                    // XXX for now, assume cell binning is 1x1 relative to chip
+		    pmCell *refCell = pmCellInChip(refChip,ref->chip->x,ref->chip->y);
+		    if (refCell) {
+		      float xCell = 0.0;
+		      float yCell = 0.0;
+		      pmCellCoordsForChip (&xCell, &yCell, refCell, ref->chip->x, ref->chip->y);
+		      int ySize = psMetadataLookupS32(NULL,refCell->concepts,"CELL.YSIZE");
+/* 		      psWarning("Masking CTspike on Chip %s @ (%f,%f) Magnitude: %f (%f %f) Radius %f Z: %d %d %d %d\n", */
+/* 				psMetadataLookupStr(&status,readout->parent->parent->concepts,"CHIP.NAME"), */
+/* 				ref->chip->x,ref->chip->y,ref->Mag,REFSTAR_MASK_BLEED_MAG_SLOPE,REFSTAR_MASK_BLEED_MAG_MAX,width, */
+/* 				(int) (ref->chip->x - 0.5 * width),   (int) (ref->chip->y - yCell), */
+/* 				(int) (ref->chip->x+0.5 * width + 1), (int) (ref->chip->y + (ySize - yCell))); */
+		      psastroMaskRectangle (readoutMask->mask, crosstalkMaskValue,
+					    (int) (ref->chip->x - 0.5 * width),   (int) (ref->chip->y - yCell),
+					    (int) (ref->chip->x+0.5 * width + 1), (int) (ref->chip->y + (ySize - yCell)));
+		    }
                   }
                 }
Index: /tags/ipp-20120404/psastro/src/psastroMaskUtils.c
===================================================================
--- /tags/ipp-20120404/psastro/src/psastroMaskUtils.c	(revision 33851)
+++ /tags/ipp-20120404/psastro/src/psastroMaskUtils.c	(revision 33852)
@@ -135,5 +135,5 @@
 	// XXX optimize this
 	float A = 1.0;
-	float B = shape.sxy*y*PS_SQR(shape.sx);
+	float B = 2.0 * shape.sxy*y*PS_SQR(shape.sx);
 	float C = PS_SQR(y*shape.sx/shape.sy) - PS_SQR(shape.sx);
 
