Index: trunk/psLib/src/imageops/psImageMap.c
===================================================================
--- trunk/psLib/src/imageops/psImageMap.c	(revision 14924)
+++ trunk/psLib/src/imageops/psImageMap.c	(revision 14983)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-20 23:54:25 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-22 03:05:50 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -18,4 +18,5 @@
 
 #include <stdio.h>
+
 #include "psError.h"
 #include "psAbort.h"
@@ -26,4 +27,5 @@
 #include "psFitsImage.h"
 
+#include "psMemory.h"
 #include "psVector.h"
 #include "psImage.h"
@@ -96,22 +98,22 @@
 
     // accumulate the values for each map pixel
-    
+
     // we can do this by accumulating a vector of pixel indexes for each cell
     psArray *pixelSets = psArrayAlloc (map->map->numCols*map->map->numRows);
     for (int i = 0; i < pixelSets->n; i++) {
-	pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32);
+        pixelSets->data[i] = psVectorAllocEmpty (4, PS_TYPE_S32);
     }
     // associate each value with a cell
     for (int i = 0; i < x->n; i++) {
-	int xRuff = psImageBinningGetRuffX (map->binning, x->data.F32[i]);
-	int yRuff = psImageBinningGetRuffY (map->binning, y->data.F32[i]);
-
-	int bin = xRuff + yRuff*map->map->numCols;
-	assert (bin >= 0);
-	assert (bin < pixelSets->n);
-	
-	psVector *pixels = pixelSets->data[bin];
-	pixels->data.S32[pixels->n] = i;
-	psVectorExtend (pixels, 4, 1);
+        int xRuff = psImageBinningGetRuffX (map->binning, x->data.F32[i]);
+        int yRuff = psImageBinningGetRuffY (map->binning, y->data.F32[i]);
+
+        int bin = xRuff + yRuff*map->map->numCols;
+        assert (bin >= 0);
+        assert (bin < pixelSets->n);
+
+        psVector *pixels = pixelSets->data[bin];
+        pixels->data.S32[pixels->n] = i;
+        psVectorExtend (pixels, 4, 1);
     }
 
@@ -123,59 +125,59 @@
     int Ny = map->map->numRows;
     for (int iy = 0; iy < Ny; iy++) {
-	for (int ix = 0; ix < Nx; ix++) {
-    
-	    // pixel index for this cell
-	    psVector *pixels = pixelSets->data[ix + iy*Nx];
-
-	    // storage vectors
-	    psVector *xCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
-	    psVector *yCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
-	    psVector *fCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
-
-	    // error vector, if needed
-	    psVector *dfCell = NULL;
-	    if (df) {
-		dfCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
-	    }		
-
-	    // collect data for this cell
-	    for (int i = 0; i < pixels->n; i++) {
-		int bin = pixels->data.S32[i];
-		// convert x,y in the fine image to the ruff image
-		xCell->data.F32[i]  = psImageBinningGetRuffX (map->binning, x->data.F32[bin]);
-		yCell->data.F32[i]  = psImageBinningGetRuffY (map->binning, y->data.F32[bin]);
-		fCell->data.F32[i]  = f->data.F32[bin];
-		if (df) {
-		    dfCell->data.F32[i] = df->data.F32[bin];
-		}
-	    }
-
-	    // reset the stats to avoid contamination from the previous loop
-	    psStatsInit (map->stats);
-
-	    // get the value
-	    // XXX need to supply a mask and skip the masked pixels when calculating the centroid
-	    // this will not in general be properly weighted...
-	    if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
-		mask->data.U8[iy][ix] = 0;
-		// XXX ensure only one option is selected, or save both position and width
-		map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options); 
-
-		// calculate the mean position and save:
-		psStatsInit (meanStat);
-		psVectorStats (meanStat, xCell, NULL, NULL, 0);
-		xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 
-		psStatsInit (meanStat);
-		psVectorStats (meanStat, yCell, NULL, NULL, 0);
-		yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options); 
-	    } else {
-		mask->data.U8[iy][ix] = 1;
-	    }
-	    
-	    psFree (xCell);
-	    psFree (yCell);
-	    psFree (fCell);
-	    psFree (dfCell);
-	}
+        for (int ix = 0; ix < Nx; ix++) {
+
+            // pixel index for this cell
+            psVector *pixels = pixelSets->data[ix + iy*Nx];
+
+            // storage vectors
+            psVector *xCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
+            psVector *yCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
+            psVector *fCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
+
+            // error vector, if needed
+            psVector *dfCell = NULL;
+            if (df) {
+                dfCell = psVectorAlloc (pixels->n, PS_TYPE_F32);
+            }
+
+            // collect data for this cell
+            for (int i = 0; i < pixels->n; i++) {
+                int bin = pixels->data.S32[i];
+                // convert x,y in the fine image to the ruff image
+                xCell->data.F32[i]  = psImageBinningGetRuffX (map->binning, x->data.F32[bin]);
+                yCell->data.F32[i]  = psImageBinningGetRuffY (map->binning, y->data.F32[bin]);
+                fCell->data.F32[i]  = f->data.F32[bin];
+                if (df) {
+                    dfCell->data.F32[i] = df->data.F32[bin];
+                }
+            }
+
+            // reset the stats to avoid contamination from the previous loop
+            psStatsInit (map->stats);
+
+            // get the value
+            // XXX need to supply a mask and skip the masked pixels when calculating the centroid
+            // this will not in general be properly weighted...
+            if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
+                mask->data.U8[iy][ix] = 0;
+                // XXX ensure only one option is selected, or save both position and width
+                map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
+
+                // calculate the mean position and save:
+                psStatsInit (meanStat);
+                psVectorStats (meanStat, xCell, NULL, NULL, 0);
+                xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
+                psStatsInit (meanStat);
+                psVectorStats (meanStat, yCell, NULL, NULL, 0);
+                yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
+            } else {
+                mask->data.U8[iy][ix] = 1;
+            }
+
+            psFree (xCell);
+            psFree (yCell);
+            psFree (fCell);
+            psFree (dfCell);
+        }
     }
     psFree (pixelSets);
@@ -193,8 +195,8 @@
     map->nGood = mask->numCols * mask->numRows - map->nBad - map->nPoor;
     if (map->nBad > badFrac * mask->numCols * mask->numRows) {
-	psFree (xCoord);
-	psFree (yCoord);
-	psFree (mask);
-	return false;
+        psFree (xCoord);
+        psFree (yCoord);
+        psFree (mask);
+        return false;
     }
 
@@ -222,42 +224,42 @@
 // using the points given, generate a map with maximum resolution that yields only good and ok pixels
 bool psImageMapGenerateScale (psImageMap *map, psVector *x, psVector *y, psVector *f, psVector *df, float badFrac) {
-    
+
     int nXruff, nYruff;
-	
+
     while (!psImageMapGenerate (map, x, y, f, df, badFrac)) {
-	// if we failed to build an acceptable map, decrease nXruff, nYruff as appropriate, and
-	// try again...  try to keep the aspect ratio.
-
-	// if both axes are at 1, give up
-	if ((map->binning->nXruff == 1) && (map->binning->nYruff == 1)) {
-	    return false;
-	}
-
-	// if one axis is at 1, decrement the other
-	if (map->binning->nXruff == 1) {
-	    nXruff = map->binning->nXruff;
-	    nYruff = map->binning->nYruff - 1;
-	    psImageMapModifyScale (map, nXruff, nYruff);
-	    continue;
-	}
-	if (map->binning->nYruff == 1) {
-	    nYruff = map->binning->nYruff;
-	    nXruff = map->binning->nXruff - 1;
-	    psImageMapModifyScale (map, nXruff, nYruff);
-	    continue;
-	}
-
-	// otherwise, decrement the larger axis, and set the smaller based
-	// on the aspect ratio
-	float aRatio = map->binning->nXruff / map->binning->nYruff;
-	if (map->binning->nXruff > map->binning->nYruff) {
-	    nXruff = map->binning->nXruff - 1;
-	    nYruff = (int)(0.5 + (nXruff / aRatio));
-	} else {
-	    nYruff = map->binning->nYruff - 1;
-	    nXruff = (int)(0.5 + (nYruff * aRatio));
-	}
-
-	psImageMapModifyScale (map, nXruff, nYruff);
+        // if we failed to build an acceptable map, decrease nXruff, nYruff as appropriate, and
+        // try again...  try to keep the aspect ratio.
+
+        // if both axes are at 1, give up
+        if ((map->binning->nXruff == 1) && (map->binning->nYruff == 1)) {
+            return false;
+        }
+
+        // if one axis is at 1, decrement the other
+        if (map->binning->nXruff == 1) {
+            nXruff = map->binning->nXruff;
+            nYruff = map->binning->nYruff - 1;
+            psImageMapModifyScale (map, nXruff, nYruff);
+            continue;
+        }
+        if (map->binning->nYruff == 1) {
+            nYruff = map->binning->nYruff;
+            nXruff = map->binning->nXruff - 1;
+            psImageMapModifyScale (map, nXruff, nYruff);
+            continue;
+        }
+
+        // otherwise, decrement the larger axis, and set the smaller based
+        // on the aspect ratio
+        float aRatio = map->binning->nXruff / map->binning->nYruff;
+        if (map->binning->nXruff > map->binning->nYruff) {
+            nXruff = map->binning->nXruff - 1;
+            nYruff = (int)(0.5 + (nXruff / aRatio));
+        } else {
+            nYruff = map->binning->nYruff - 1;
+            nXruff = (int)(0.5 + (nYruff * aRatio));
+        }
+
+        psImageMapModifyScale (map, nXruff, nYruff);
     }
     return true;
@@ -271,5 +273,5 @@
     result = psImageUnbinPixel_V2(x, y, map->map, map->binning);
 
-    return result; 
+    return result;
 }
 
@@ -284,7 +286,7 @@
 
     for (int i = 0; i < x->n; i++) {
-	result->data.F32[i] = psImageUnbinPixel_V2(x->data.F32[i], y->data.F32[i], map->map, map->binning);
-    }
-
-    return result; 
-}
+        result->data.F32[i] = psImageUnbinPixel_V2(x->data.F32[i], y->data.F32[i], map->map, map->binning);
+    }
+
+    return result;
+}
