Index: trunk/psModules/src/objects/pmSourceExtendedPars.c
===================================================================
--- trunk/psModules/src/objects/pmSourceExtendedPars.c	(revision 23487)
+++ trunk/psModules/src/objects/pmSourceExtendedPars.c	(revision 25754)
@@ -17,30 +17,140 @@
 #endif
 
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
+// #include <stdio.h>
+// #include <math.h>
+// #include <string.h>
 #include <pslib.h>
-#include "pmHDU.h"
-#include "pmFPA.h"
-#include "pmFPAMaskWeight.h"
-#include "pmSpan.h"
-#include "pmFootprint.h"
-#include "pmPeaks.h"
-#include "pmMoments.h"
-#include "pmResiduals.h"
-#include "pmGrowthCurve.h"
-#include "pmTrend2D.h"
-#include "pmPSF.h"
-#include "pmModel.h"
-#include "pmSource.h"
-
+// #include "pmHDU.h"
+// #include "pmFPA.h"
+// #include "pmFPAMaskWeight.h"
+// #include "pmSpan.h"
+// #include "pmFootprint.h"
+// #include "pmPeaks.h"
+// #include "pmMoments.h"
+// #include "pmResiduals.h"
+// #include "pmGrowthCurve.h"
+// #include "pmTrend2D.h"
+// #include "pmPSF.h"
+// #include "pmModel.h"
+// #include "pmSource.h"
+#include "pmSourceExtendedPars.h"
+
+// *** pmSourceRadialProfile describes the radial profile of a source in elliptical contours, and 
+// intermediate data used to measure the profile
+static void pmSourceRadialProfileFree(pmSourceRadialProfile *profile)
+{
+    if (!profile) {
+        return;
+    }
+    psFree(profile->radii);
+    psFree(profile->fluxes);
+    psFree(profile->theta);
+    psFree(profile->isophotalRadii);
+
+    psFree(profile->radiusElliptical);
+    psFree(profile->fluxElliptical);
+
+    psFree(profile->binSB);
+    psFree(profile->binSBstdev);
+    psFree(profile->binSBerror);
+
+    psFree(profile->radialBins);
+    psFree(profile->area);
+}
+
+pmSourceRadialProfile *pmSourceRadialProfileAlloc()
+{
+    pmSourceRadialProfile *profile = (pmSourceRadialProfile *)psAlloc(sizeof(pmSourceRadialProfile));
+    psMemSetDeallocator(profile, (psFreeFunc) pmSourceRadialProfileFree);
+
+    profile->radii = NULL;
+    profile->fluxes = NULL;
+    profile->theta = NULL;
+    profile->isophotalRadii = NULL;
+
+    profile->radiusElliptical = NULL;
+    profile->fluxElliptical = NULL;
+
+    profile->binSB = NULL;
+    profile->binSBstdev = NULL;
+    profile->binSBerror = NULL;
+
+    profile->radialBins = NULL;
+    profile->area = NULL;
+
+    return profile;
+}
+
+bool psMemCheckSourceRadialProfile(psPtr ptr)
+{
+    PS_ASSERT_PTR(ptr, false);
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourceRadialProfileFree);
+}
+
+
+// *** pmSourceRadialProfileFreeVectors frees the intermediate data values
+bool pmSourceRadialProfileFreeVectors(pmSourceRadialProfile *profile) {
+
+    psFree(profile->radii);
+    psFree(profile->fluxes);
+    psFree(profile->theta);
+    psFree(profile->isophotalRadii);
+
+    psFree(profile->radiusElliptical);
+    psFree(profile->fluxElliptical);
+
+    // psFree(profile->binSB);
+    // psFree(profile->binSBstdev);
+    // psFree(profile->binSBerror);
+    
+    // psFree(profile->radialBins);
+    psFree(profile->area);
+
+    profile->radii = NULL;
+    profile->fluxes = NULL;
+    profile->theta = NULL;
+    profile->isophotalRadii = NULL;
+
+    profile->radiusElliptical = NULL;
+    profile->fluxElliptical = NULL;
+
+    // profile->binSB = NULL;
+    // profile->binSBstdev = NULL;
+    // profile->binSBerror = NULL;
+    
+    // profile->radialBins = NULL;
+    profile->area = NULL;
+
+    return true;
+}
+
+// *** pmSourceRadialProfileSortPair is a utility function for sorting a pair of vectors
+# define COMPARE_INDEX(A,B) (index->data.F32[A] < index->data.F32[B])
+# define SWAP_INDEX(TYPE,A,B) { \
+  float tmp; \
+  if (A != B) { \
+    tmp = index->data.F32[A]; \
+    index->data.F32[A] = index->data.F32[B]; \
+    index->data.F32[B] = tmp; \
+    tmp = extra->data.F32[A]; \
+    extra->data.F32[A] = extra->data.F32[B]; \
+    extra->data.F32[B] = tmp; \
+  } \
+}
+
+bool pmSourceRadialProfileSortPair (psVector *index, psVector *extra) {
+
+    // sort the vector set by the radius
+    PSSORT (index->n, COMPARE_INDEX, SWAP_INDEX, NONE);
+    return true;
+}
+
+// *** pmSourceExtendedPars describes the possible collection of extended flux measurements for a source
 static void pmSourceExtendedParsFree (pmSourceExtendedPars *pars) {
     if (!pars) return;
 
     psFree(pars->profile);
-    psFree(pars->annuli);
-    psFree(pars->isophot);
-    psFree(pars->petrosian);
-    psFree(pars->kron);
+    psFree(pars->petrosian_50);
+    psFree(pars->petrosian_80);
     return;
 }
@@ -51,8 +161,6 @@
 
     pars->profile = NULL;
-    pars->annuli = NULL;
-    pars->isophot = NULL;
-    pars->petrosian = NULL;
-    pars->kron = NULL;
+    pars->petrosian_50 = NULL;
+    pars->petrosian_80 = NULL;
 
     return pars;
@@ -66,135 +174,27 @@
 
 
-static void pmSourceRadialProfileFree (pmSourceRadialProfile *profile) {
-    if (!profile) return;
-
-    psFree(profile->radius);
-    psFree(profile->flux);
-    psFree(profile->variance);
+// *** pmSourceExtendedFlux describes the flux within an elliptical aperture of some kind 
+static void pmSourceExtendedFluxFree (pmSourceExtendedFlux *flux) {
+    if (!flux) return;
     return;
 }
 
-pmSourceRadialProfile *pmSourceRadialProfileAlloc (void) {
-
-    pmSourceRadialProfile *profile = (pmSourceRadialProfile *) psAlloc(sizeof(pmSourceRadialProfile));
-    psMemSetDeallocator(profile, (psFreeFunc) pmSourceRadialProfileFree);
-
-    profile->radius = NULL;
-    profile->flux = NULL;
-    profile->variance = NULL;
-
-    return profile;
-}
-
-bool psMemCheckSourceRadialProfile(psPtr ptr)
+pmSourceExtendedFlux *pmSourceExtendedFluxAlloc (void) {
+
+    pmSourceExtendedFlux *flux = (pmSourceExtendedFlux *) psAlloc(sizeof(pmSourceExtendedFlux));
+    psMemSetDeallocator(flux, (psFreeFunc) pmSourceExtendedFluxFree);
+
+    flux->flux = 0.0;
+    flux->fluxErr = 0.0;
+    flux->radius = 0.0;
+    flux->radiusErr = 0.0;
+
+    return flux;
+}
+
+
+bool psMemCheckSourceExtendedFlux(psPtr ptr)
 {
     PS_ASSERT_PTR(ptr, false);
-    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourceRadialProfileFree);
-}
-
-
-static void pmSourceIsophotalValuesFree (pmSourceIsophotalValues *isophot) {
-    if (!isophot) return;
-    return;
-}
-
-pmSourceIsophotalValues *pmSourceIsophotalValuesAlloc (void) {
-
-    pmSourceIsophotalValues *isophot = (pmSourceIsophotalValues *) psAlloc(sizeof(pmSourceIsophotalValues));
-    psMemSetDeallocator(isophot, (psFreeFunc) pmSourceIsophotalValuesFree);
-
-    isophot->mag = 0.0;
-    isophot->magErr = 0.0;
-    isophot->rad = 0.0;
-    isophot->radErr = 0.0;
-
-    return isophot;
-}
-
-
-bool psMemCheckSourceIsophotalValues(psPtr ptr)
-{
-    PS_ASSERT_PTR(ptr, false);
-    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourceIsophotalValuesFree);
-}
-
-
-static void pmSourcePetrosianValuesFree (pmSourcePetrosianValues *petrosian) {
-    if (!petrosian) return;
-    return;
-}
-
-pmSourcePetrosianValues *pmSourcePetrosianValuesAlloc (void) {
-
-    pmSourcePetrosianValues *petrosian = (pmSourcePetrosianValues *) psAlloc(sizeof(pmSourcePetrosianValues));
-    psMemSetDeallocator(petrosian, (psFreeFunc) pmSourcePetrosianValuesFree);
-
-    petrosian->mag = 0.0;
-    petrosian->magErr = 0.0;
-    petrosian->rad = 0.0;
-    petrosian->radErr = 0.0;
-
-    return petrosian;
-}
-
-
-bool psMemCheckSourcePetrosianValues(psPtr ptr)
-{
-    PS_ASSERT_PTR(ptr, false);
-    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourcePetrosianValuesFree);
-}
-
-static void pmSourceKronValuesFree (pmSourceKronValues *kron) {
-    if (!kron) return;
-    return;
-}
-
-pmSourceKronValues *pmSourceKronValuesAlloc (void) {
-
-    pmSourceKronValues *kron = (pmSourceKronValues *) psAlloc(sizeof(pmSourceKronValues));
-    psMemSetDeallocator(kron, (psFreeFunc) pmSourceKronValuesFree);
-
-    kron->mag = 0.0;
-    kron->magErr = 0.0;
-    kron->rad = 0.0;
-    kron->radErr = 0.0;
-
-    return kron;
-}
-
-
-bool psMemCheckSourceKronValues(psPtr ptr)
-{
-    PS_ASSERT_PTR(ptr, false);
-    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourceKronValuesFree);
-}
-
-
-static void pmSourceAnnuliFree (pmSourceAnnuli *annuli) {
-    if (!annuli) return;
-
-    psFree (annuli->flux);
-    psFree (annuli->fluxErr);
-    psFree (annuli->fluxVar);
-
-    return;
-}
-
-pmSourceAnnuli *pmSourceAnnuliAlloc (void) {
-
-    pmSourceAnnuli *annuli = (pmSourceAnnuli *) psAlloc(sizeof(pmSourceAnnuli));
-    psMemSetDeallocator(annuli, (psFreeFunc) pmSourceAnnuliFree);
-
-    annuli->flux = NULL;
-    annuli->fluxErr = NULL;
-    annuli->fluxVar = NULL;
-
-    return annuli;
-}
-
-
-bool psMemCheckSourceAnnuli(psPtr ptr)
-{
-    PS_ASSERT_PTR(ptr, false);
-    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourceAnnuliFree);
-}
+    return ( psMemGetDeallocator(ptr) == (psFreeFunc) pmSourceExtendedFluxFree);
+}
