Index: trunk/psastro/src/psastroMaskUpdates.c
===================================================================
--- trunk/psastro/src/psastroMaskUpdates.c	(revision 33851)
+++ trunk/psastro/src/psastroMaskUpdates.c	(revision 40490)
@@ -129,5 +129,8 @@
     
     bool REFSTAR_MASK_BLEED                = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED");
-
+    bool REFSTAR_MASK_BLEED_ORIENTATION_X  = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED_ORIENTATION_X");
+    bool REFSTAR_MASK_BLEED_ORIENTATION_Y  = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_BLEED_ORIENTATION_Y");
+
+    
     double REFSTAR_MASK_MAX_MAG            = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_MAX_MAG");
     double REFSTAR_MASK_SATSTAR_MAG_SLOPE  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_SATSTAR_MAG_SLOPE");
@@ -143,4 +146,9 @@
     double REFSTAR_MASK_BLEED_MAG_SLOPE    = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE");
 
+    double REFSTAR_MASK_BLEED_MAG_MAX_X    = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_MAX_X");
+    double REFSTAR_MASK_BLEED_MAG_SLOPE_X  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE_X");
+    double REFSTAR_MASK_BLEED_MAG_MAX_Y    = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_MAX_Y");
+    double REFSTAR_MASK_BLEED_MAG_SLOPE_Y  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_BLEED_MAG_SLOPE_Y");
+
     double REFSTAR_MASK_CROSSTALK_MAG_MAX  = psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_MAX");
     double REFSTAR_MASK_CROSSTALK_MAG_SLOPE= psMetadataLookupF32 (&status, recipe, "REFSTAR_MASK_CROSSTALK_MAG_SLOPE");
@@ -180,4 +188,6 @@
     }
 
+    psTrace("psastro.masks",2,"Configuration loaded for masking.");
+    
     // recipe values are given in instrumental magnitudes
     // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
@@ -187,6 +197,12 @@
     REFSTAR_MASK_SATSPIKE_MAG_MAX += MagOffset;
     REFSTAR_MASK_BLEED_MAG_MAX += MagOffset;
+    REFSTAR_MASK_BLEED_MAG_MAX_X += MagOffset;
+    REFSTAR_MASK_BLEED_MAG_MAX_Y += MagOffset;
+    
     GHOST_MAX_MAG += MagOffset;
 
+    psTrace("psastro.masks",2,"Magnitudes: max_mag: %f satstar: %f satspike: %f bleed: %f ghost %f\n",
+	    REFSTAR_MASK_MAX_MAG,REFSTAR_MASK_SATSTAR_MAG_MAX,REFSTAR_MASK_SATSPIKE_MAG_MAX,REFSTAR_MASK_BLEED_MAG_MAX,GHOST_MAX_MAG);
+    
     // select the output mask image :: we mosaic to chip mosaic format
     pmFPAfile *outMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.OUTPUT.MASK");
@@ -287,4 +303,5 @@
                 if (!refstars) continue;
 
+		psTrace("psastro.masks",2,"In Readout loop.");
                 // we need to generate the following masks regions:
                 // 1) circle around the saturated stars (scaled by magnitude)
@@ -301,5 +318,6 @@
                         }
                     }
-
+		    psTrace("psastro.masks",4,"In refstar loop: %d/%ld %f %f\n",
+			    i,refstars->n,ref->Mag,REFSTAR_MASK_MAX_MAG);
                     if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue;
 
@@ -334,5 +352,7 @@
 
                         // The length should also be a function of the image background level
-
+			psTrace("psastro.masks",4,"Masking: Radius: %f Theta: %f Length: %f Width: %f\n",
+				radius,Theta,spikeLength,spikeWidth);
+			psTrace("psastro.masks",4,"Also: %f %f %f %f\n",ref->chip->x,ref->chip->y,ROTANGLE,REFSTAR_MASK_SATSTAR_POS_ZERO);
                         psastroMaskBox (readoutMask->mask, spikeMaskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta);
                     }
@@ -349,15 +369,33 @@
                             float xCell = 0.0;
                             float yCell = 0.0;
-                            float xEnd = 0.0;
-                            float yEnd = 0.0;
+			    float xStart = 0.0;
+			    float xEnd   = 0.0;
+			    float yStart = 0.0;
+			    float yEnd   = 0.0;
+			    //                            float xEnd = 0.0;
+			    //                            float yEnd = 0.0;
+			    float width = 0.0;
+			    float length = 0.0;
                             // find coordinate of star on cell
                             pmCellCoordsForChip (&xCell, &yCell, refCell, ref->chip->x, ref->chip->y);
                             // find coordinate of end-point on chip
 
-                            int ySize = psMetadataLookupS32(NULL, refCell->concepts, "CELL.YSIZE");
-                            pmChipCoordsForCell (&xEnd, &yEnd, refCell, xCell, ySize);
-
-                            float width = REFSTAR_MASK_BLEED_MAG_SLOPE*(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);
-                            psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd);
+			    if (REFSTAR_MASK_BLEED_ORIENTATION_X) {
+			      length = pow(10,REFSTAR_MASK_BLEED_MAG_SLOPE_X*(REFSTAR_MASK_BLEED_MAG_MAX_X - ref->Mag));
+			      width  = REFSTAR_MASK_BLEED_MAG_SLOPE  *(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);
+
+			      pmChipCoordsForCell (&xStart, &yStart, refCell, xCell - length, yCell - 0.5 * width);
+			      pmChipCoordsForCell (&xEnd, &yEnd,     refCell, xCell + length, yCell + 0.5 * width);
+			      psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) xStart, (int) yStart, (int) xEnd, (int) yEnd + 1);
+			    }
+			    if (REFSTAR_MASK_BLEED_ORIENTATION_Y) {
+			      length = pow(10,REFSTAR_MASK_BLEED_MAG_SLOPE_Y*(REFSTAR_MASK_BLEED_MAG_MAX_Y - ref->Mag));
+			      width  = REFSTAR_MASK_BLEED_MAG_SLOPE  *(REFSTAR_MASK_BLEED_MAG_MAX - ref->Mag);
+
+			      pmChipCoordsForCell (&xStart, &yStart, refCell, xCell - 0.5 * width, yCell - length);
+			      pmChipCoordsForCell (&xEnd, &yEnd,     refCell, xCell + 0.5 * width, yCell + length);
+			      psastroMaskRectangle (readoutMask->mask, spikeMaskValue, (int) xStart, (int) yStart, (int) xEnd + 1, (int) yEnd);
+			    }
+			    
                         }
                     }
@@ -392,5 +430,21 @@
                     }
                 }
-
+		// Because it's very GPC1-specific, handle alternate glint types here
+		psArray *hsc_glints = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.GLINTS.HSC");
+		if (hsc_glints) {
+		  for (int i = 0; i < hsc_glints->n; i++) {
+		    // Contains (start_x, start_y, length, width, theta)
+		    psVector *glint = hsc_glints->data[i];
+
+		    psTrace("psastro.masks", 4, "Masking glint %d on chip %s with params (%f,%f,%f,%f,%f)\n",
+			    i, psMetadataLookupStr(&status,readout->parent->parent->concepts,"CHIP.NAME"),
+			    glint->data.F32[0], glint->data.F32[1],
+			    glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
+
+		    psastroMaskBox (readoutMask->mask, glintMaskValue, glint->data.F32[0], glint->data.F32[1],
+				    glint->data.F32[2], glint->data.F32[3], glint->data.F32[4]);
+		  }
+		}
+		
                 // Select the crosstalk artifact regions for this readout, and mask a circular region
                 // corresponding to the source star
