Index: /trunk/psastro/src/psastroMaskUpdates.c
===================================================================
--- /trunk/psastro/src/psastroMaskUpdates.c	(revision 20959)
+++ /trunk/psastro/src/psastroMaskUpdates.c	(revision 20960)
@@ -6,5 +6,5 @@
   return false; \
 }
-  
+
 pmCell *pmCellInChip (pmChip *chip, float x, float y);
 bool pmCellCoordsForChip (float *xCell, float *yCell, pmCell *cell, float xChip, float yChip);
@@ -17,5 +17,5 @@
 void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1);
 
-// create a mask or mask regions based on the collection of reference stars that are 
+// create a mask or mask regions based on the collection of reference stars that are
 // in the vicinity of each chip
 bool psastroMaskUpdates (pmConfig *config) {
@@ -57,6 +57,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-	psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
-	return false;
+        psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
+        return false;
     }
     pmFPA *fpa = input->fpa;
@@ -64,6 +64,6 @@
     // really error-out here?  or just skip?
     if (!psastroZeroPointFromRecipe (&zeropt, &exptime, fpa, recipe)) {
-	psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
-	return false;
+        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
+        return false;
     }
 
@@ -79,6 +79,6 @@
     pmFPAfile *outMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.OUTPUT.MASK");
     if (!outMask) {
-	psError(PSASTRO_ERR_CONFIG, true, "Can't find output mask");
-	return false;
+        psError(PSASTRO_ERR_CONFIG, true, "Can't find output mask");
+        return false;
     }
     pmFPA *fpaMask = outMask->fpa;
@@ -87,11 +87,11 @@
     pmFPAfile *refMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.REFMASK");
     if (!refMask) {
-	psError(PSASTRO_ERR_CONFIG, true, "Can't find mask reference");
-	return false;
-    }
-
-    // double POSANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.POSANGLE"); 
+        psError(PSASTRO_ERR_CONFIG, true, "Can't find mask reference");
+        return false;
+    }
+
+    // double POSANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.POSANGLE");
     // psAssert (status, "POSANGLE missing");
-    double ROTANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.ROTANGLE"); 
+    double ROTANGLE = PM_RAD_DEG * psMetadataLookupF64 (&status, fpa->concepts, "FPA.ROTANGLE");
     psAssert (status, "ROTANGLE missing");
 
@@ -112,36 +112,36 @@
         psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
-	if (!chip->fromFPA) { continue; }
-
-	if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
-
-	// text region files for testing
-	FILE *f = NULL;
-	if (REFSTAR_MASK_REGIONS) {
-	  char *filename = NULL;
-	  char *chipname = psMetadataLookupStr (&status, chip->concepts, "CHIP.NAME");
-	  psStringAppend (&filename, "refstars.mask.%s.dat", chipname);
-	  FILE *f = fopen (filename, "w");
-	  if (!f) {
-	    psWarning ("cannot create refstar mask file %s\n", filename);
-	    continue;
-	  }
-	  psFree (filename);
-	}
-
-	pmChip *refChip  = pmFPAviewThisChip (view, refMask->fpa);
-
-	// load sequence for mask corresponding to this chip (XXX this is needed if the input mask is not the same format as the astrometry file
-	*viewMask = *view;
+        if (!chip->fromFPA) { continue; }
+
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
+
+        // text region files for testing
+        FILE *f = NULL;
+        if (REFSTAR_MASK_REGIONS) {
+          char *filename = NULL;
+          char *chipname = psMetadataLookupStr (&status, chip->concepts, "CHIP.NAME");
+          psStringAppend (&filename, "refstars.mask.%s.dat", chipname);
+          FILE *f = fopen (filename, "w");
+          if (!f) {
+            psWarning ("cannot create refstar mask file %s\n", filename);
+            continue;
+          }
+          psFree (filename);
+        }
+
+        pmChip *refChip  = pmFPAviewThisChip (view, refMask->fpa);
+
+        // load sequence for mask corresponding to this chip (XXX this is needed if the input mask is not the same format as the astrometry file
+        *viewMask = *view;
         while ((cell = pmFPAviewNextCell (viewMask, fpaMask, 1)) != NULL) {
             psTrace ("psastro", 4, "Mask Cell %d: %x %x\n", viewMask->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
-	    if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE;
-	    
+            if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE;
+
             while ((readout = pmFPAviewNextReadout (viewMask, fpaMask, 1)) != NULL) {
-		if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE;
+                if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_BEFORE)) ESCAPE;
                 if (! readout->data_exists) { continue; }
-	    }
-	}
+            }
+        }
 
         while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
@@ -149,15 +149,15 @@
             if (!cell->process || !cell->file_exists) { continue; }
 
-	    // the input mask is a chip-mosaic image
-	    // the output mask is a chip-mosaic image
-	    // we mark the masked pixels in the chip space, BUT
-	    // we need to find the ends of the cells for the bleeds
-
-	    // we mask pixels on the input mask image (chip-mosaic)
-	    pmCell *cellMask = pmFPAviewThisCell(view, outMask->fpa);
-	    pmReadout *readoutMask = NULL;
-	    if (cellMask->readouts->n) {
-		readoutMask = cellMask->readouts->data[0];
-	    }
+            // the input mask is a chip-mosaic image
+            // the output mask is a chip-mosaic image
+            // we mark the masked pixels in the chip space, BUT
+            // we need to find the ends of the cells for the bleeds
+
+            // we mask pixels on the input mask image (chip-mosaic)
+            pmCell *cellMask = pmFPAviewThisCell(view, outMask->fpa);
+            pmReadout *readoutMask = NULL;
+            if (cellMask->readouts->n) {
+                readoutMask = cellMask->readouts->data[0];
+            }
 
             // process each of the readouts
@@ -170,107 +170,107 @@
                 if (refstars == NULL) { continue; }
 
-		// we need to generate the following masks regions:
-		// 1) circle around the saturated stars (scaled by magnitude)
-		// 2) diffraction spikes in direction ROT - ROTo
-		// 3) bleed trail in the direction of the readout
-
-		// XXX for the moment, let's just generate mana region-file objects in chip pixel space
-		for (int i = 0; i < refstars->n; i++) {
-		    pmAstromObj *ref = refstars->data[i];
-		    if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue;
-		    
-		    // XXX convert ref->Mag to instrumental mags
-
-		    // CIRCLE around the stars (scaled by magnitude)
-		    float radius = REFSTAR_MASK_SATSTAR_MAG_SLOPE * (REFSTAR_MASK_SATSTAR_MAG_MAX - ref->Mag);
-
-		    if (REFSTAR_MASK_REGIONS) {
-		      fprintf (f, "CIRCLE %f %f  %f %f\n", ref->chip->x, ref->chip->y, radius, radius);
-		    }
-
-		    // XXX for now, assume cell binning is 1x1 relative to chip
-		    if (readoutMask) {
-			psastroMaskCircle (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, radius, radius);
-		    }
-
-		    // LINE for boundaries of the saturation spikes (scaled by magnitude)
-		    float spikeLength = REFSTAR_MASK_SATSPIKE_MAG_SLOPE * (REFSTAR_MASK_SATSPIKE_MAG_MAX - ref->Mag);
-		    float spikeWidth = REFSTAR_MASK_SATSPIKE_WIDTH;
-
-		    for (float theta = 0.0; theta < 2*M_PI; theta += M_PI / 2.0) {
-			float x0, y0, x1, y1, dx, dy;
-
-			float Theta = ROTANGLE - REFSTAR_MASK_SATSTAR_POS_ZERO + theta;
-
-			if (REFSTAR_MASK_REGIONS) {
-			  // lower side 
-			  x0 = ref->chip->x + spikeWidth*sin(Theta);
-			  y0 = ref->chip->y - spikeWidth*cos(Theta);
-			  x1 = ref->chip->x + spikeLength*cos(Theta) + spikeWidth*sin(Theta);
-			  y1 = ref->chip->y + spikeLength*sin(Theta) - spikeWidth*cos(Theta);
-			  dx = x1 - x0;
-			  dy = y1 - y0;
-
-			  fprintf (f, "LINE %f %f  %f %f\n", x0, y0, dx, dy);
-
-			  // upper side 
-			  x0 = ref->chip->x - spikeWidth*sin(Theta);
-			  y0 = ref->chip->y + spikeWidth*cos(Theta);
-			  x1 = ref->chip->x + spikeLength*cos(Theta) - spikeWidth*sin(Theta);
-			  y1 = ref->chip->y + spikeLength*sin(Theta) + spikeWidth*cos(Theta);
-			  dx = x1 - x0;
-			  dy = y1 - y0;
-			  fprintf (f, "LINE %f %f  %f %f\n", x0, y0, dx, dy);
-			}
-
-			if (readoutMask) {
-			    psastroMaskBox (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta);
-			}
-		    }
-
-		    // convert x,y chip coordinates to cells in maskChip
-		    pmCell *refCell = pmCellInChip (refChip, ref->chip->x, ref->chip->y);
-
-		    // LINE for boundaries of the bleed lines
-		    if (REFSTAR_MASK_REGIONS) {
-		      fprintf (f, "LINE %f %f  %f %f\n", ref->chip->x, ref->chip->y, 0.0, -100.0);
-		    }
-
-		    if (readoutMask && refCell) {
-			float xCell = 0.0;
-			float yCell = 0.0;
-			float xEnd = 0.0;
-			float yEnd = 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, maskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd);
-		    }
-		}
+                // we need to generate the following masks regions:
+                // 1) circle around the saturated stars (scaled by magnitude)
+                // 2) diffraction spikes in direction ROT - ROTo
+                // 3) bleed trail in the direction of the readout
+
+                // XXX for the moment, let's just generate mana region-file objects in chip pixel space
+                for (int i = 0; i < refstars->n; i++) {
+                    pmAstromObj *ref = refstars->data[i];
+                    if (ref->Mag > REFSTAR_MASK_MAX_MAG) continue;
+
+                    // XXX convert ref->Mag to instrumental mags
+
+                    // CIRCLE around the stars (scaled by magnitude)
+                    float radius = REFSTAR_MASK_SATSTAR_MAG_SLOPE * (REFSTAR_MASK_SATSTAR_MAG_MAX - ref->Mag);
+
+                    if (REFSTAR_MASK_REGIONS) {
+                      fprintf (f, "CIRCLE %f %f  %f %f\n", ref->chip->x, ref->chip->y, radius, radius);
+                    }
+
+                    // XXX for now, assume cell binning is 1x1 relative to chip
+                    if (readoutMask) {
+                        psastroMaskCircle (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, radius, radius);
+                    }
+
+                    // LINE for boundaries of the saturation spikes (scaled by magnitude)
+                    float spikeLength = REFSTAR_MASK_SATSPIKE_MAG_SLOPE * (REFSTAR_MASK_SATSPIKE_MAG_MAX - ref->Mag);
+                    float spikeWidth = REFSTAR_MASK_SATSPIKE_WIDTH;
+
+                    for (float theta = 0.0; theta < 2*M_PI; theta += M_PI / 2.0) {
+                        float x0, y0, x1, y1, dx, dy;
+
+                        float Theta = theta - ROTANGLE - REFSTAR_MASK_SATSTAR_POS_ZERO;
+
+                        if (REFSTAR_MASK_REGIONS) {
+                          // lower side
+                          x0 = ref->chip->x + spikeWidth*sin(Theta);
+                          y0 = ref->chip->y - spikeWidth*cos(Theta);
+                          x1 = ref->chip->x + spikeLength*cos(Theta) + spikeWidth*sin(Theta);
+                          y1 = ref->chip->y + spikeLength*sin(Theta) - spikeWidth*cos(Theta);
+                          dx = x1 - x0;
+                          dy = y1 - y0;
+
+                          fprintf (f, "LINE %f %f  %f %f\n", x0, y0, dx, dy);
+
+                          // upper side
+                          x0 = ref->chip->x - spikeWidth*sin(Theta);
+                          y0 = ref->chip->y + spikeWidth*cos(Theta);
+                          x1 = ref->chip->x + spikeLength*cos(Theta) - spikeWidth*sin(Theta);
+                          y1 = ref->chip->y + spikeLength*sin(Theta) + spikeWidth*cos(Theta);
+                          dx = x1 - x0;
+                          dy = y1 - y0;
+                          fprintf (f, "LINE %f %f  %f %f\n", x0, y0, dx, dy);
+                        }
+
+                        if (readoutMask) {
+                            psastroMaskBox (readoutMask->mask, maskValue, ref->chip->x, ref->chip->y, spikeLength, spikeWidth, Theta);
+                        }
+                    }
+
+                    // convert x,y chip coordinates to cells in maskChip
+                    pmCell *refCell = pmCellInChip (refChip, ref->chip->x, ref->chip->y);
+
+                    // LINE for boundaries of the bleed lines
+                    if (REFSTAR_MASK_REGIONS) {
+                      fprintf (f, "LINE %f %f  %f %f\n", ref->chip->x, ref->chip->y, 0.0, -100.0);
+                    }
+
+                    if (readoutMask && refCell) {
+                        float xCell = 0.0;
+                        float yCell = 0.0;
+                        float xEnd = 0.0;
+                        float yEnd = 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, maskValue, (int) ref->chip->x-0.5*width, (int) ref->chip->y, (int) ref->chip->x+0.5*width+1, yEnd);
+                    }
+                }
             }
         }
 
-	// output sequence for mask corresponding to this chip
-	*viewMask = *view;
+        // output sequence for mask corresponding to this chip
+        *viewMask = *view;
         while ((cell = pmFPAviewNextCell (viewMask, outMask->fpa, 1)) != NULL) {
             psTrace ("psastro", 4, "Mask Cell %d: %x %x\n", viewMask->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
-	    
+
             while ((readout = pmFPAviewNextReadout (viewMask, outMask->fpa, 1)) != NULL) {
                 if (! readout->data_exists) { continue; }
-		if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
-	    }
-	    if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
-	}
-
-	if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
-	if (REFSTAR_MASK_REGIONS) {
-	  fclose (f);
-	}
+                if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
+            }
+            if (!pmFPAfileIOChecks (config, viewMask, PM_FPA_AFTER)) ESCAPE;
+        }
+
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
+        if (REFSTAR_MASK_REGIONS) {
+          fclose (f);
+        }
     }
     if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
@@ -299,5 +299,5 @@
     int yBin = 1;
 
-    // Position on the cell 
+    // Position on the cell
     float xCell = PM_CHIP_TO_CELL(xChip, x0Cell, xParityCell, xBin);
     float yCell = PM_CHIP_TO_CELL(yChip, y0Cell, yParityCell, yBin);
@@ -306,17 +306,17 @@
     for (int i = 0; i < chip->cells->n; i++) {
 
-	pmCell *cell = chip->cells->data[i];
-	psRegion *region = pmCellExtent (cell);
-
-	if (x < region->x0) goto skip;
-	if (x > region->x1) goto skip;
-	if (y < region->y0) goto skip;
-	if (y > region->y1) goto skip;
-
-	psFree (region);
-	return cell;
+        pmCell *cell = chip->cells->data[i];
+        psRegion *region = pmCellExtent (cell);
+
+        if (x < region->x0) goto skip;
+        if (x > region->x1) goto skip;
+        if (y < region->y0) goto skip;
+        if (y > region->y1) goto skip;
+
+        psFree (region);
+        return cell;
 
     skip:
-	psFree (region);
+        psFree (region);
     }
     return NULL;
@@ -337,5 +337,5 @@
     int yBin = 1;
 
-    // Position on the cell 
+    // Position on the cell
     // ((pos)*(binning)*(cellParity) + (cell0))
     // XXX this is probably totally wrong now....
@@ -361,10 +361,10 @@
     int yBin = 1;
 
-    // Position on the cell 
+    // Position on the cell
     // ((pos)*(binning)*(cellParity) + (cell0))
     // XXX this is probably totally wrong now....
     // ((pos) - (cell0))*(cellParity)/(binning))
-    *xChip = xCell*xBin*xParityCell + x0Cell; 
-    *yChip = yCell*yBin*yParityCell + y0Cell; 
+    *xChip = xCell*xBin*xParityCell + x0Cell;
+    *yChip = yCell*yBin*yParityCell + y0Cell;
 
     return true;
@@ -376,17 +376,17 @@
     // XXX need to worry about row0, col0
     for (int ix = -dX; ix <= +dX; ix++) {
-	int jx = ix + x0;
-	if (jx < 0) continue;
-	if (jx >= mask->numCols) continue;
-	for (int iy = -dY; iy <= +dY; iy++) {
-	    int jy = iy + y0;
-	    if (jy < 0) continue;
-	    if (jy >= mask->numRows) continue;
-
-	    double r2 = PS_SQR(ix/dX) + PS_SQR(iy/dY);
-	    if (r2 > 1.0) continue;
-	    
-	    mask->data.U8[jy][jx] |= value;
-	}
+        int jx = ix + x0;
+        if (jx < 0) continue;
+        if (jx >= mask->numCols) continue;
+        for (int iy = -dY; iy <= +dY; iy++) {
+            int jy = iy + y0;
+            if (jy < 0) continue;
+            if (jy >= mask->numRows) continue;
+
+            double r2 = PS_SQR(ix/dX) + PS_SQR(iy/dY);
+            if (r2 > 1.0) continue;
+
+            mask->data.U8[jy][jx] |= value;
+        }
     }
     return true;
@@ -415,5 +415,5 @@
 
   /* rather than draw the line from float positions, we find the closest
-     integer end-points and draw the line between those pixels */ 
+     integer end-points and draw the line between those pixels */
 
   X1 = ROUND(x1);
@@ -449,31 +449,31 @@
     e = 0;
     for (X = X1; X <= X2; X++) {
-	if (X > 0) {
-	    if (swapcoords) {
-		if (X >= mask->numRows) continue;
-		for (int y = Y - dW; y <= Y + dW; y++) {
-		    if (y < 0) continue;
-		    if (y >= mask->numCols) continue;
-		    mask->data.U8[X][y] |= value;
-		}
-	    } else {
-		if (X >= mask->numCols) continue;
-		for (int y = Y - dW; y <= Y + dW; y++) {
-		    if (y < 0) continue;
-		    if (y >= mask->numRows) continue;
-		    mask->data.U8[y][X] |= value;
-		}
-	    }
-	}
-	e += dY;
-	e2 = 2 * e;
-	if (e2 > dX) {
-	    Y++;
-	    e -= dX;
-	} 
-	if (e2 < -dX) {
-	    Y--;
-	    e += dX;
-	}
+        if (X > 0) {
+            if (swapcoords) {
+                if (X >= mask->numRows) continue;
+                for (int y = Y - dW; y <= Y + dW; y++) {
+                    if (y < 0) continue;
+                    if (y >= mask->numCols) continue;
+                    mask->data.U8[X][y] |= value;
+                }
+            } else {
+                if (X >= mask->numCols) continue;
+                for (int y = Y - dW; y <= Y + dW; y++) {
+                    if (y < 0) continue;
+                    if (y >= mask->numRows) continue;
+                    mask->data.U8[y][X] |= value;
+                }
+            }
+        }
+        e += dY;
+        e2 = 2 * e;
+        if (e2 > dX) {
+            Y++;
+            e -= dX;
+        }
+        if (e2 < -dX) {
+            Y--;
+            e += dX;
+        }
     }
     return;
@@ -481,5 +481,5 @@
 
 void psastroMaskRectangle (psImage *mask, char value, int x0, int y0, int x1, int y1) {
-    
+
     int xs = PS_MAX (0, PS_MIN (mask->numCols, PS_MIN (x0, x1)));
     int xe = PS_MAX (0, PS_MIN (mask->numCols, PS_MAX (x0, x1)));
@@ -488,8 +488,8 @@
 
     for (int iy = ys; iy < ye; iy++) {
-	for (int ix = xs; ix < xe; ix++) {
-	    mask->data.U8[iy][ix] |= value;
-	}
-    }
-}
-
+        for (int ix = xs; ix < xe; ix++) {
+            mask->data.U8[iy][ix] |= value;
+        }
+    }
+}
+
