Index: /branches/eam_branches/psphot.20100506/src/psphotRadialApertures.c
===================================================================
--- /branches/eam_branches/psphot.20100506/src/psphotRadialApertures.c	(revision 27951)
+++ /branches/eam_branches/psphot.20100506/src/psphotRadialApertures.c	(revision 27952)
@@ -1,3 +1,5 @@
 # include "psphotInternal.h"
+
+bool psphotRadialAperturesSortFlux (psVector *radius, psVector *pixFlux, psVector *pixVar);
 
 // for now, let's store the detections on the readout->analysis for each readout
@@ -154,4 +156,5 @@
 	}
     }
+    psphotRadialAperturesSortFlux(radius, pixFlux, pixVar);
 
     psVector *flux    = psVectorAllocEmpty(radMax->n, PS_TYPE_F32); // surface brightness of radial bin
@@ -207,2 +210,27 @@
     return true;
 }
+
+// *** pmSourceRadialProfileSortPair is a utility function for sorting a pair of vectors
+# define COMPARE_VECT(A,B) (radius->data.F32[A] < radius->data.F32[B])
+# define SWAP_VECT(TYPE,A,B) { \
+  float tmp; \
+  if (A != B) { \
+    tmp = radius->data.F32[A]; \
+    radius->data.F32[A] = radius->data.F32[B];	\
+    radius->data.F32[B] = tmp; \
+    tmp = pixFlux->data.F32[A]; \
+    pixFlux->data.F32[A] = pixFlux->data.F32[B]; \
+    pixFlux->data.F32[B] = tmp; \
+    tmp = pixVar->data.F32[A]; \
+    pixVar->data.F32[A] = pixVar->data.F32[B]; \
+    pixVar->data.F32[B] = tmp; \
+  } \
+}
+
+bool psphotRadialAperturesSortFlux (psVector *radius, psVector *pixFlux, psVector *pixVar) {
+
+    // sort the vector set by the radius
+    PSSORT (radius->n, COMPARE_VECT, SWAP_VECT, NONE);
+    return true;
+}
+
