Index: trunk/psastro/src/psastroLoadCrosstalk.c
===================================================================
--- trunk/psastro/src/psastroLoadCrosstalk.c	(revision 26826)
+++ trunk/psastro/src/psastroLoadCrosstalk.c	(revision 33851)
@@ -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
