Index: /trunk/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometryObjects.c	(revision 7943)
+++ /trunk/psModules/src/astrom/pmAstrometryObjects.c	(revision 7944)
@@ -8,6 +8,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-07-18 15:36:32 $
+*  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-07-20 13:02:19 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -114,141 +114,116 @@
     return (matches);
 }
-/******************************************************************************
-pmAstromRadiusMatch(st1, st2, config)
- ******************************************************************************/
-psArray *pmAstromRadiusMatch(
-    const psArray *st1,
-    const psArray *st2,
-    const psMetadata *config)
-{
-    PS_ASSERT_PTR_NON_NULL(st1, NULL);
-    PS_ASSERT_PTR_NON_NULL(st2, NULL);
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    assert(st1->n == 0 || pmIsAstromObj(st1->data[0]));
-    assert(st2->n == 0 || pmIsAstromObj(st2->data[0]));
-
-    bool status = false;
-    double RADIUS = psMetadataLookupF32 (&status, config, "PSASTRO.MATCH.RADIUS");
-    if (!status) {
-        psError(PS_ERR_IO, false, "Failed to lookup matching radius");
-        return NULL;
-    }
+
+/************************************************************************************************************/
+
+#define MAKE_ASTROM_RADIUS(FUNC, MEMBER) \
+psArray *FUNC( \
+               const psArray *st1, \
+               const psArray *st2, \
+               const psMetadata *config) \
+{ \
+    PS_ASSERT_PTR_NON_NULL(st1, NULL); \
+    PS_ASSERT_PTR_NON_NULL(st2, NULL); \
+    PS_ASSERT_PTR_NON_NULL(config, NULL); \
+    \
+    assert(st1->n == 0 || pmIsAstromObj(st1->data[0])); \
+    assert(st2->n == 0 || pmIsAstromObj(st2->data[0])); \
+    \
+    bool status = false; \
+    double RADIUS = psMetadataLookupF32 (&status, config, "PSASTRO.MATCH.RADIUS"); \
+    if (!status) { \
+        psError(PS_ERR_IO, false, "Failed to lookup matching radius"); \
+        return NULL; \
+    } \
     /*
-     * sort both lists by Focal Plane X coord; st1 first
-     */
+     * sort both lists by X coord; 
+    st1 first
+    */ \
     psVector *x1 = psVectorAlloc(st1->n, PS_TYPE_F64);
+    \
     x1->n = x1->nalloc;
-    for (int i = 0; i < st1->n; i++) {
-        x1->data.F64[i] = ((pmAstromObj *)st1->data[i])->FP->x;
-    }
+    \
+    for (int i = 0; i < st1->n; i++)
+    {
+        \
+        x1->data.F64[i] = ((pmAstromObj *)st1->data[i])->MEMBER->x;
+        \
+    } \
     const psVector *sorted1 = psVectorSortIndex(NULL, x1);
+    \
     assert (sorted1->type.type == PS_TYPE_S32);
-
+    \
+    \
     psVector *y1 = psVectorAlloc(st1->n, PS_TYPE_F64);
+    \
     y1->n = y1->nalloc;
-    for (int i = 0; i < st1->n; i++) {
-        x1->data.F64[i] = ((pmAstromObj *)st1->data[sorted1->data.S32[i]])->FP->x;
-        y1->data.F64[i] = ((pmAstromObj *)st1->data[sorted1->data.S32[i]])->FP->y;
-    }
-
-    // now st2
+    \
+    for (int i = 0; i < st1->n; i++)
+    {
+        \
+        x1->data.F64[i] = ((pmAstromObj *)st1->data[sorted1->data.S32[i]])->MEMBER->x;
+        \
+        y1->data.F64[i] = ((pmAstromObj *)st1->data[sorted1->data.S32[i]])->MEMBER->y;
+        \
+    } \
+    \
+    /* now st2 */ \
     psVector *x2 = psVectorAlloc(st2->n, PS_TYPE_F64);
+    \
     x2->n = x2->nalloc;
-    for (int i = 0; i < st2->n; i++) {
-        x2->data.F64[i] = ((pmAstromObj *)st2->data[i])->FP->x;
-    }
+    \
+    for (int i = 0; i < st2->n; i++)
+    {
+        \
+        x2->data.F64[i] = ((pmAstromObj *)st2->data[i])->MEMBER->x;
+        \
+    } \
     const psVector *sorted2 = psVectorSortIndex(NULL, x2);
-
+    \
+    \
     psVector *y2 = psVectorAlloc(st2->n, PS_TYPE_F64);
+    \
     y2->n = y2->nalloc;
-    for (int i = 0; i < st2->n; i++) {
-        x2->data.F64[i] = ((pmAstromObj *)st2->data[sorted2->data.S32[i]])->FP->x;
-        y2->data.F64[i] = ((pmAstromObj *)st2->data[sorted2->data.S32[i]])->FP->y;
-    }
+    \
+    for (int i = 0; i < st2->n; i++)
+    {
+        \
+        x2->data.F64[i] = ((pmAstromObj *)st2->data[sorted2->data.S32[i]])->MEMBER->x;
+        \
+        y2->data.F64[i] = ((pmAstromObj *)st2->data[sorted2->data.S32[i]])->MEMBER->y;
+        \
+    } \
     /*
      * Do the work
-     */
+     */ \
     psArray *matches = match_lists(x1, y1, x2, y2, sorted1, sorted2, RADIUS);
-
+    \
+    \
     psFree(sorted1);
+    \
     psFree(sorted2);
+    \
     psFree(x1);
+    \
     psFree(y1);
+    \
     psFree(x2);
+    \
     psFree(y2);
-
+    \
+    \
     psLogMsg (__func__, 3, "radius match: %d pairs (radius: %f)\n", matches->n, RADIUS);
+    \
     return (matches);
-}
-
-/******************************************************************************
-pmAstromRadiusMatchChip(st1, st2, config) : match objects on the chip
- ******************************************************************************/
-psArray *pmAstromRadiusMatchChip(
-    const psArray *st1,
-    const psArray *st2,
-    const psMetadata *config)
-{
-    PS_ASSERT_PTR_NON_NULL(st1, NULL);
-    PS_ASSERT_PTR_NON_NULL(st2, NULL);
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    assert(st1->n == 0 || pmIsAstromObj(st1->data[0]));
-    assert(st2->n == 0 || pmIsAstromObj(st2->data[0]));
-
-    bool status = false;
-    double RADIUS = psMetadataLookupF32 (&status, config, "PSASTRO.MATCH.RADIUS");
-    if (!status) {
-        psError(PS_ERR_IO, false, "Failed to lookup matching radius");
-        return NULL;
-    }
-    /*
-     * sort both lists by chip X coord; st1 first
-     */
-    psVector *x1 = psVectorAlloc(st1->n, PS_TYPE_F64);
-    x1->n = x1->nalloc;
-    for (int i = 0; i < st1->n; i++) {
-        x1->data.F64[i] = ((pmAstromObj *)st1->data[i])->FP->x;
-    }
-    const psVector *sorted1 = psVectorSortIndex(NULL, x1);
-    assert (sorted1->type.type == PS_TYPE_S32);
-
-    psVector *y1 = psVectorAlloc(st1->n, PS_TYPE_F64);
-    y1->n = y1->nalloc;
-    for (int i = 0; i < st1->n; i++) {
-        x1->data.F64[i] = ((pmAstromObj *)st1->data[sorted1->data.S32[i]])->chip->x;
-        y1->data.F64[i] = ((pmAstromObj *)st1->data[sorted1->data.S32[i]])->chip->y;
-    }
-
-    // now st2
-    psVector *x2 = psVectorAlloc(st2->n, PS_TYPE_F64);
-    x2->n = x2->nalloc;
-    for (int i = 0; i < st2->n; i++) {
-        x2->data.F64[i] = ((pmAstromObj *)st2->data[i])->FP->x;
-    }
-    const psVector *sorted2 = psVectorSortIndex(NULL, x2);
-
-    psVector *y2 = psVectorAlloc(st2->n, PS_TYPE_F64);
-    y2->n = y2->nalloc;
-    for (int i = 0; i < st2->n; i++) {
-        x2->data.F64[i] = ((pmAstromObj *)st2->data[sorted2->data.S32[i]])->chip->x;
-        y2->data.F64[i] = ((pmAstromObj *)st2->data[sorted2->data.S32[i]])->chip->y;
-    }
-    /*
-     * Do the work
-     */
-    psArray *matches = match_lists(x1, y1, x2, y2, sorted1, sorted2, RADIUS);
-
-    psFree(sorted1);
-    psFree(sorted2);
-    psFree(x1);
-    psFree(y1);
-    psFree(x2);
-    psFree(y2);
-
-    psLogMsg (__func__, 3, "radius match: %d pairs (radius: %f)\n", matches->n, RADIUS);
-    return (matches);
-}
+    \
+}
+
+/******************************************************************************/
+/*
+ * Match two lists of pmAstromObjs, based on the FP, TP, or chip coordinates
+ */
+MAKE_ASTROM_RADIUS(pmAstromRadiusMatch, FP)
+MAKE_ASTROM_RADIUS(pmAstromRadiusMatchTP, TP)
+MAKE_ASTROM_RADIUS(pmAstromRadiusMatchChip, chip)
 
 /******************************************************************************
