Index: trunk/Ohana/src/addstar/Makefile
===================================================================
--- trunk/Ohana/src/addstar/Makefile	(revision 15997)
+++ trunk/Ohana/src/addstar/Makefile	(revision 16040)
@@ -68,5 +68,4 @@
 $(SRC)/ReadStarsTEXT.$(ARCH).o \
 $(SRC)/FilterStars.$(ARCH).o \
-$(SRC)/sort_lists.$(ARCH).o \
 $(SRC)/ImageOptions.$(ARCH).o \
 $(SRC)/GetFileMode.$(ARCH).o \
@@ -114,5 +113,4 @@
 $(SRC)/opening_angle.$(ARCH).o \
 $(SRC)/replace_match.$(ARCH).o \
-$(SRC)/sort_lists.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o
 
@@ -151,5 +149,4 @@
 $(SRC)/SkyRegionUtils.$(ARCH).o \
 $(SRC)/SkyListForStars.$(ARCH).o \
-$(SRC)/sort_lists.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
@@ -194,5 +191,4 @@
 $(SRC)/find_matches_refstars.$(ARCH).o \
 $(SRC)/args_load2mass.$(ARCH).o \
-$(SRC)/sort_lists.$(ARCH).o \
 $(SRC)/replace_match.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o \
Index: trunk/Ohana/src/addstar/src/SEDops.c
===================================================================
--- trunk/Ohana/src/addstar/src/SEDops.c	(revision 15997)
+++ trunk/Ohana/src/addstar/src/SEDops.c	(revision 16040)
@@ -57,6 +57,7 @@
 SEDtableRow **sort_SEDtable (SEDtableRow *raw, int N) {
 
-  int l,j,ir,i;
-  SEDtableRow **value, *temp;
+  int i;
+
+  SEDtableRow **value;
   
   if (N <= 0) return (NULL);
@@ -66,33 +67,12 @@
     value[i] = &raw[i];
   }
-  if (N < 2) return (value);
-
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      temp = value[l];
-    }
-    else {
-      temp = value[ir];
-      value[ir] = value[0];
-      if (--ir == 0) {
-	value[0] = temp;
-	return (value);
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && value[j][0].color < value[j+1][0].color) ++j;
-      if (temp[0].color < value[j][0].color) {
-	value[i] = value[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    value[i] = temp;
-  }
+
+# define SWAPFUNC(A,B){ SEDtableRow *temp = value[A]; value[A] = value[B]; value[B] = temp; }
+# define COMPARE(A,B)(value[A][0].color < value[B][0].color)
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
 
   return (value);
Index: trunk/Ohana/src/addstar/src/SkyListForStars.c
===================================================================
--- trunk/Ohana/src/addstar/src/SkyListForStars.c	(revision 15997)
+++ trunk/Ohana/src/addstar/src/SkyListForStars.c	(revision 16040)
@@ -15,5 +15,5 @@
   list[0].ownElements = FALSE; // free these elements when freeing the list
 
-  sort_stars (stars, Nstars); /* sort by RA */
+  sort_stars_ra (stars, Nstars); /* sort by RA */
   for (i = 0; i < Nstars; i++) {
     if (stars[i].found) continue;
Index: trunk/Ohana/src/addstar/src/calibrate.c
===================================================================
--- trunk/Ohana/src/addstar/src/calibrate.c	(revision 15997)
+++ trunk/Ohana/src/addstar/src/calibrate.c	(revision 16040)
@@ -188,5 +188,5 @@
     return;
   }
-  fsort2 (Dmag, dDmag, Nkeep);
+  fsortpair (Dmag, dDmag, Nkeep);
 
   /* take sort list of Dmag, find median */
Index: trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches.c	(revision 15997)
+++ trunk/Ohana/src/addstar/src/find_matches.c	(revision 16040)
@@ -5,6 +5,6 @@
   int i, j, n, N, J, status, Nstars;
   double RADIUS, RADIUS2;
-  float *X1, *Y1, *X2, *Y2;
-  float dX, dY, dR;
+  double *X1, *Y1, *X2, *Y2;
+  double dX, dY, dR;
   int *N1, *N2,  *next_meas;
   int Nave, NAVE, Nmeas, NMEAS, Nmatch;
@@ -21,12 +21,12 @@
 
   /** allocate local arrays (stars) **/
-  ALLOCATE (X1, float, NstarsIn);
-  ALLOCATE (Y1, float, NstarsIn);
+  ALLOCATE (X1, double, NstarsIn);
+  ALLOCATE (Y1, double, NstarsIn);
   ALLOCATE (N1, int,   NstarsIn);
 
   /** allocate local arrays (catalog) **/
   NAVE = Nave = catalog[0].Naverage;
-  ALLOCATE (X2, float, NAVE);
-  ALLOCATE (Y2, float, NAVE);
+  ALLOCATE (X2, double, NAVE);
+  ALLOCATE (Y2, double, NAVE);
   ALLOCATE (N2, int,   NAVE);
   ALLOCATE (catalog[0].found, int, NAVE);
@@ -60,5 +60,5 @@
   Nstars = 0;
   for (i = 0; i < NstarsIn; i++) {
-    status = fRD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
+    status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
     if (!status) continue;
     N1[Nstars] = i;
@@ -76,13 +76,13 @@
     return (0);
   }
-  if (Nstars > 1) sort_lists (X1, Y1, N1, Nstars);
+  if (Nstars > 1) sort_coords_index (X1, Y1, N1, Nstars);
   
   /* build spatial index (RA sort) */
   for (i = 0; i < Nave; i++) {
-    fRD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
+    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
     N2[i] = i;
     catalog[0].found[N2[i]] = -1;
   }
-  if (Nave > 1) sort_lists (X2, Y2, N2, Nave);
+  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
 
   /* set up pointers for linked list of measure */
Index: trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 15997)
+++ trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 16040)
@@ -5,6 +5,6 @@
   int i, j, n, N, J, Jmin, status, Nstars;
   double RADIUS, RADIUS2, Rmin;
-  float *X1, *Y1, *X2, *Y2;
-  float dX, dY, dR;
+  double *X1, *Y1, *X2, *Y2;
+  double dX, dY, dR;
   int *N1, *N2,  *next_meas, *next_miss;
   int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
@@ -21,12 +21,12 @@
 
   /** allocate local arrays (stars) **/
-  ALLOCATE (X1, float, NstarsIn);
-  ALLOCATE (Y1, float, NstarsIn);
+  ALLOCATE (X1, double, NstarsIn);
+  ALLOCATE (Y1, double, NstarsIn);
   ALLOCATE (N1, int,   NstarsIn);
 
   /** allocate local arrays (catalog) **/
   NAVE = Nave = catalog[0].Naverage;
-  ALLOCATE (X2, float, NAVE);
-  ALLOCATE (Y2, float, NAVE);
+  ALLOCATE (X2, double, NAVE);
+  ALLOCATE (Y2, double, NAVE);
   ALLOCATE (N2, int,   NAVE);
   ALLOCATE (catalog[0].found, int, NAVE);
@@ -61,5 +61,5 @@
   Nstars = 0;
   for (i = 0; i < NstarsIn; i++) {
-    status = fRD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
+    status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
     if (!status) continue;
     N1[Nstars] = i;
@@ -77,13 +77,13 @@
     return (0);
   }
-  if (Nstars > 1) sort_lists (X1, Y1, N1, Nstars);
+  if (Nstars > 1) sort_coords_index (X1, Y1, N1, Nstars);
 
   /* build spatial index (RA sort) */
   for (i = 0; i < Nave; i++) {
-    fRD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
+    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
     N2[i] = i;
     catalog[0].found[N2[i]] = -1;
   }
-  if (Nave > 1) sort_lists (X2, Y2, N2, Nave);
+  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
 
   /* set up pointers for linked list of measure, missing */
Index: trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 15997)
+++ trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 16040)
@@ -5,6 +5,6 @@
   int i, j, k, n, m, N, J;
   double RADIUS, RADIUS2;
-  float *X1, *Y1, *X2, *Y2;
-  float dX, dY, dR;
+  double *X1, *Y1, *X2, *Y2;
+  double dX, dY, dR;
   int *N1, *N2,  *next, *next_miss, last, last_miss;
   int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
@@ -18,6 +18,6 @@
 
   /** allocate local arrays (stars) **/
-  ALLOCATE (X1, float, Nstars);
-  ALLOCATE (Y1, float, Nstars);
+  ALLOCATE (X1, double, Nstars);
+  ALLOCATE (Y1, double, Nstars);
   ALLOCATE (N1, int,   Nstars);
 
@@ -25,6 +25,6 @@
   Nave = catalog[0].Naverage;
   NAVE = Nave + 1000;
-  ALLOCATE (X2, float, NAVE);
-  ALLOCATE (Y2, float, NAVE);
+  ALLOCATE (X2, double, NAVE);
+  ALLOCATE (Y2, double, NAVE);
   ALLOCATE (N2, int, NAVE);
   ALLOCATE (catalog[0].found, int, NAVE);
@@ -59,15 +59,15 @@
   
   for (i = 0; i < Nstars; i++) {
-    fRD_to_XY (&X1[i], &Y1[i], stars[i][0].R, stars[i][0].D, &tcoords);
+    RD_to_XY (&X1[i], &Y1[i], stars[i][0].R, stars[i][0].D, &tcoords);
     N1[i] = i;
   }
-  if (Nstars > 1) sort_lists (X1, Y1, N1, Nstars);
+  if (Nstars > 1) sort_coords_index (X1, Y1, N1, Nstars);
   
   for (i = 0; i < Nave; i++) {
-    fRD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
+    RD_to_XY (&X2[i], &Y2[i], catalog[0].average[i].R, catalog[0].average[i].D, &tcoords);
     N2[i] = i;
     catalog[0].found[N2[i]] = -1;
   }
-  if (Nave > 1) sort_lists (X2, Y2, N2, Nave);
+  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
 
   /* set up pointers for linked list of measurements */
Index: trunk/Ohana/src/addstar/src/sort_lists.c
===================================================================
--- trunk/Ohana/src/addstar/src/sort_lists.c	(revision 15997)
+++ 	(revision )
@@ -1,186 +1,0 @@
-# include "addstar.h"
-
-void sort_stars (Stars *stars, int N) {
-
-  int l,j,ir,i;
-  Stars tmp;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tmp = stars[l];
-    }
-    else {
-      tmp = stars[ir];
-      stars[ir] = stars[0];
-      if (--ir == 0) {
-	stars[0] = tmp;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && stars[j].R < stars[j+1].R) j++;
-      if (tmp.R < stars[j].R) {
-	stars[i] = stars[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    stars[i] = tmp;
-  }
-}
-
-void sort_regions (SkyRegion *region, int N) {
-
-  int l,j,ir,i;
-  SkyRegion tmp;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tmp = region[l];
-    } else {
-      tmp = region[ir];
-      region[ir] = region[0];
-      if (--ir == 0) {
-	region[0] = tmp;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && region[j].Dmin < region[j+1].Dmin) j++;
-      if (tmp.Dmin < region[j].Dmin) {
-	region[i] = region[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    region[i] = tmp;
-  }
-}
-
-void sort_lists (float *X, float *Y, int *S, int N) {
-
-  int l,j,ir,i;
-  double tX, tY, tS;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-      tY = Y[l];
-      tS = S[l];
-    } else {
-      tX = X[ir];
-      X[ir] = X[0];
-      tY = Y[ir];
-      Y[ir] = Y[0];
-      tS = S[ir];
-      S[ir] = S[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	Y[0] = tY;
-	S[0] = tS;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	Y[i] = Y[j];
-	S[i] = S[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-    Y[i] = tY;
-    S[i] = tS;
-  }
-}
-
-void fsort (float *X, int N) {
-
-  int l,j,ir,i;
-  float tX;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-    } else {
-      tX = X[ir];
-      X[ir] = X[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-  }
-}
-
-void fsort2 (float *X, float *Y, int N) {
-
-  int l,j,ir,i;
-  float tX, tY;
-  
-  l = N >> 1;
-  ir = N - 1;
-  for (;;) {
-    if (l > 0) {
-      l--;
-      tX = X[l];
-      tY = Y[l];
-    }
-    else {
-      tX = X[ir];
-      tY = Y[ir];
-      X[ir] = X[0];
-      Y[ir] = Y[0];
-      if (--ir == 0) {
-	X[0] = tX;
-	Y[0] = tY;
-	return;
-      }
-    }
-    i = l;
-    j = (l << 1) + 1;
-    while (j <= ir) {
-      if (j < ir && X[j] < X[j+1]) j++;
-      if (tX < X[j]) {
-	X[i] = X[j];
-	Y[i] = Y[j];
-	j += (i=j) + 1;
-      }
-      else j = ir + 1;
-    }
-    X[i] = tX;
-    Y[i] = tY;
-  }
-}
