Index: trunk/psModules/src/objects/pmSource.c
===================================================================
--- trunk/psModules/src/objects/pmSource.c	(revision 10048)
+++ trunk/psModules/src/objects/pmSource.c	(revision 10049)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-11-07 09:06:21 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-17 23:01:30 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,5 +31,5 @@
 static void sourceFree(pmSource *tmp)
 {
-    psTrace("psModules.objects", 4, "---- %s() begin ----\n", __func__);
+    psTrace(__func__, 5, "---- begin ----\n");
     psFree(tmp->peak);
     psFree(tmp->pixels);
@@ -40,5 +40,5 @@
     psFree(tmp->modelEXT);
     psFree(tmp->blends);
-    psTrace("psModules.objects", 4, "---- %s() end ----\n", __func__);
+    psTrace(__func__, 5, "---- end ----\n");
 }
 
@@ -65,5 +65,5 @@
 pmSource *pmSourceAlloc()
 {
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    psTrace(__func__, 5, "---- begin ----\n");
     static int id = 1;
     pmSource *source = (pmSource *) psAlloc(sizeof(pmSource));
@@ -90,5 +90,5 @@
     source->pixWeight = NAN;
 
-    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
+    psTrace(__func__, 5, "---- end ----\n");
     return(source);
 }
@@ -198,12 +198,12 @@
 
 /******************************************************************************
-    pmSourcePSFClump(source, metadata): Find the likely PSF clump in the
+    pmSourcePSFClump(source, recipe): Find the likely PSF clump in the
     sigma-x, sigma-y plane. return 0,0 clump in case of error.
 *****************************************************************************/
 
 // XXX EAM include a S/N cutoff in selecting the sources?
-pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *metadata)
-{
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *recipe)
+{
+    psTrace(__func__, 5, "---- begin ----\n");
 
     # define NPIX 10
@@ -215,5 +215,5 @@
 
     PS_ASSERT_PTR_NON_NULL(sources, emptyClump);
-    PS_ASSERT_PTR_NON_NULL(metadata, emptyClump);
+    PS_ASSERT_PTR_NON_NULL(recipe, emptyClump);
 
     // find the sigmaX, sigmaY clump
@@ -224,11 +224,11 @@
         bool status;
 
-        psF32 SX_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SX_MAX");
+        psF32 SX_MAX = psMetadataLookupF32 (&status, recipe, "MOMENTS_SX_MAX");
         if (!status)
             SX_MAX = 10.0;
-        psF32 SY_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_SY_MAX");
+        psF32 SY_MAX = psMetadataLookupF32 (&status, recipe, "MOMENTS_SY_MAX");
         if (!status)
             SY_MAX = 10.0;
-        psF32 AR_MAX = psMetadataLookupF32 (&status, metadata, "MOMENTS_AR_MAX");
+        psF32 AR_MAX = psMetadataLookupF32 (&status, recipe, "MOMENTS_AR_MAX");
         if (!status)
             AR_MAX =  3.0;
@@ -291,10 +291,10 @@
         stats = psImageStats (stats, splane, NULL, 0);
         peaks = pmFindImagePeaks (splane, stats[0].max / 2);
-        psTrace (".pmObjects.pmSourceRoughClass", 2, "clump threshold is %f\n", stats[0].max/2);
-
-        const bool keep_psf_clump = psMetadataLookupBool(NULL, metadata, "KEEP_PSF_CLUMP");
+        psTrace (__func__, 2, "clump threshold is %f\n", stats[0].max/2);
+
+        const bool keep_psf_clump = psMetadataLookupBool(NULL, recipe, "KEEP_PSF_CLUMP");
         if (keep_psf_clump)
         {
-            psMetadataAdd(metadata, PS_LIST_TAIL,
+            psMetadataAdd(recipe, PS_LIST_TAIL,
                           "PSF_CLUMP", PS_DATA_IMAGE, "Image of PSF coefficients", splane);
         }
@@ -323,5 +323,5 @@
         psArraySort (peaks, pmPeaksCompareDescend);
         clump = peaks->data[0];
-        psTrace (".pmObjects.pmSourceRoughClass", 2, "clump is at %d, %d (%f)\n", clump->x, clump->y, clump->counts);
+        psTrace (__func__, 2, "clump is at %d, %d (%f)\n", clump->x, clump->y, clump->counts);
 
         // define section window for clump
@@ -369,7 +369,7 @@
         psfClump.dY = stats->clippedStdev;
 
-        psTrace (".pmObjects.pmSourceRoughClass", 2, "clump  X,  Y: %f, %f\n", psfClump.X, psfClump.Y);
-        psTrace (".pmObjects.pmSourceRoughClass", 2, "clump DX, DY: %f, %f\n", psfClump.dX, psfClump.dY);
-        // these values should be pushed on the metadata somewhere
+        psTrace (__func__, 2, "clump  X,  Y: %f, %f\n", psfClump.X, psfClump.Y);
+        psTrace (__func__, 2, "clump DX, DY: %f, %f\n", psfClump.dX, psfClump.dY);
+        // these values should be pushed on the recipe somewhere
 
         psFree (stats);
@@ -379,22 +379,17 @@
     }
 
-    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
+    psTrace(__func__, 5, "---- end ----\n");
     return (psfClump);
 }
 
 /******************************************************************************
-    pmSourceRoughClass(source, metadata): make a guess at the source
+    pmSourceRoughClass(source, recipe): make a guess at the source
     classification.
- 
-    XXX: push the clump info into the metadata?
- 
     XXX: How can this function ever return FALSE?
- 
-    EAM: I moved S/N calculation to pmSourceMoments, using weight image
 *****************************************************************************/
 
-bool pmSourceRoughClass(psArray *sources, psMetadata *metadata, pmPSFClump clump)
-{
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+bool pmSourceRoughClass(psArray *sources, psMetadata *recipe, pmPSFClump clump)
+{
+    psTrace(__func__, 5, "---- begin ----");
 
     psBool rc = true;
@@ -406,5 +401,4 @@
     int Ncr      = 0;
     int Nsatstar = 0;
-    // psRegion allArray = psRegionSet (0, 0, 0, 0);
     psRegion inner;
 
@@ -412,10 +406,13 @@
     psVector *starsn = psVectorAllocEmpty (sources->n, PS_TYPE_F32);
 
-    // check return status value (do these exist?)
+    // get basic parameters, or set defaults
     bool status;
-    psF32 PSF_SN_LIM = psMetadataLookupF32 (&status, metadata, "PSF_SN_LIM");
-    psF32 PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, metadata, "PSF_CLUMP_NSIGMA");
+    float PSF_SN_LIM = psMetadataLookupF32 (&status, recipe, "PSF_SN_LIM");
+    if (!status)
+        PSF_SN_LIM = 20.0;
+    float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");
     if (!status)
         PSF_CLUMP_NSIGMA = 1.5;
+    float INNER_RADIUS = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
 
     // XXX allow clump size to be scaled relative to sigmas?
@@ -423,16 +420,15 @@
     for (psS32 i = 0 ; i < sources->n ; i++) {
 
-        pmSource *tmpSrc = (pmSource *) sources->data[i];
-
-        tmpSrc->peak->type = 0;
-
-        psF32 sigX = tmpSrc->moments->Sx;
-        psF32 sigY = tmpSrc->moments->Sy;
+        pmSource *source = (pmSource *) sources->data[i];
+
+        source->peak->type = 0;
+
+        psF32 sigX = source->moments->Sx;
+        psF32 sigY = source->moments->Sy;
 
         // XXX EAM : can we use the value of SATURATE if mask is NULL?
-        // inner = psRegionForSquare (tmpSrc->peak->x - tmpSrc->mask->col0, tmpSrc->peak->y - tmpSrc->mask->row0, 2);
-        inner = psRegionForSquare (tmpSrc->peak->x, tmpSrc->peak->y, 2);
-        inner = psRegionForImage (tmpSrc->mask, inner);
-        int Nsatpix = psImageCountPixelMask (tmpSrc->mask, inner, PM_MASK_SAT);
+        inner = psRegionForSquare (source->peak->x, source->peak->y, 2);
+        inner = psRegionForImage (source->mask, inner);
+        int Nsatpix = psImageCountPixelMask (source->mask, inner, PM_MASK_SAT);
 
         // saturated star (size consistent with PSF or larger)
@@ -441,6 +437,8 @@
         big = true;
         if ((Nsatpix > 1) && big) {
-            tmpSrc->type = PM_SOURCE_TYPE_STAR;
-            tmpSrc->mode |= PM_SOURCE_MODE_SATSTAR;
+            source->type = PM_SOURCE_TYPE_STAR;
+            source->mode |= PM_SOURCE_MODE_SATSTAR;
+            // recalculate moments here with larger box?
+            pmSourceMoments (source, INNER_RADIUS);
             Nsatstar ++;
             continue;
@@ -449,6 +447,6 @@
         // saturated object (not a star, eg bleed trails, hot pixels)
         if (Nsatpix > 1) {
-            tmpSrc->type = PM_SOURCE_TYPE_SATURATED;
-            tmpSrc->mode |= PM_SOURCE_MODE_DEFAULT;
+            source->type = PM_SOURCE_TYPE_SATURATED;
+            source->mode |= PM_SOURCE_MODE_DEFAULT;
             Nsat ++;
             continue;
@@ -460,6 +458,6 @@
         // XXX these limits are quite arbitrary
         if ((sigX < 0.05) || (sigY < 0.05)) {
-            tmpSrc->type = PM_SOURCE_TYPE_DEFECT;
-            tmpSrc->mode |= PM_SOURCE_MODE_DEFAULT;
+            source->type = PM_SOURCE_TYPE_DEFECT;
+            source->mode |= PM_SOURCE_MODE_DEFAULT;
             Ncr ++;
             continue;
@@ -468,6 +466,6 @@
         // likely unsaturated extended source (too large to be stellar)
         if ((sigX > (clump.X + 3*clump.dX)) || (sigY > (clump.Y + 3*clump.dY))) {
-            tmpSrc->type = PM_SOURCE_TYPE_EXTENDED;
-            tmpSrc->mode |= PM_SOURCE_MODE_DEFAULT;
+            source->type = PM_SOURCE_TYPE_EXTENDED;
+            source->mode |= PM_SOURCE_MODE_DEFAULT;
             Next ++;
             continue;
@@ -475,5 +473,5 @@
 
         // the rest are probable stellar objects
-        starsn->data.F32[starsn->n] = tmpSrc->moments->SN;
+        starsn->data.F32[starsn->n] = source->moments->SN;
         starsn->n ++;
         Nstar ++;
@@ -481,7 +479,7 @@
         // PSF star (within 1.5 sigma of clump center, S/N > limit)
         psF32 radius = hypot ((sigX-clump.X)/clump.dX, (sigY-clump.Y)/clump.dY);
-        if ((tmpSrc->moments->SN > PSF_SN_LIM) && (radius < PSF_CLUMP_NSIGMA)) {
-            tmpSrc->type = PM_SOURCE_TYPE_STAR;
-            tmpSrc->mode |= PM_SOURCE_MODE_PSFSTAR;
+        if ((source->moments->SN > PSF_SN_LIM) && (radius < PSF_CLUMP_NSIGMA)) {
+            source->type = PM_SOURCE_TYPE_STAR;
+            source->mode |= PM_SOURCE_MODE_PSFSTAR;
             Npsf ++;
             continue;
@@ -489,25 +487,23 @@
 
         // random type of star
-        tmpSrc->type = PM_SOURCE_TYPE_STAR;
-        tmpSrc->mode |= PM_SOURCE_MODE_DEFAULT;
-    }
-
-    {
-        psStats *stats  = NULL;
-        stats = psStatsAlloc (PS_STAT_MIN | PS_STAT_MAX);
-        stats = psVectorStats (stats, starsn, NULL, NULL, 0);
-        psLogMsg ("pmObjects", 3, "SN range: %f - %f\n", stats[0].min, stats[0].max);
-        psFree (stats);
-        psFree (starsn);
-    }
-
-    psTrace (".pmObjects.pmSourceRoughClass", 2, "Nstar:    %3d\n", Nstar);
-    psTrace (".pmObjects.pmSourceRoughClass", 2, "Npsf:     %3d\n", Npsf);
-    psTrace (".pmObjects.pmSourceRoughClass", 2, "Next:     %3d\n", Next);
-    psTrace (".pmObjects.pmSourceRoughClass", 2, "Nsatstar: %3d\n", Nsatstar);
-    psTrace (".pmObjects.pmSourceRoughClass", 2, "Nsat:     %3d\n", Nsat);
-    psTrace (".pmObjects.pmSourceRoughClass", 2, "Ncr:      %3d\n", Ncr);
-
-    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
+        source->type = PM_SOURCE_TYPE_STAR;
+        source->mode |= PM_SOURCE_MODE_DEFAULT;
+    }
+
+    psStats *stats  = NULL;
+    stats = psStatsAlloc (PS_STAT_MIN | PS_STAT_MAX);
+    stats = psVectorStats (stats, starsn, NULL, NULL, 0);
+    psLogMsg ("pmObjects", 3, "SN range: %f - %f\n", stats[0].min, stats[0].max);
+    psFree (stats);
+    psFree (starsn);
+
+    psTrace (__func__, 2, "Nstar:    %3d\n", Nstar);
+    psTrace (__func__, 2, "Npsf:     %3d\n", Npsf);
+    psTrace (__func__, 2, "Next:     %3d\n", Next);
+    psTrace (__func__, 2, "Nsatstar: %3d\n", Nsatstar);
+    psTrace (__func__, 2, "Nsat:     %3d\n", Nsat);
+    psTrace (__func__, 2, "Ncr:      %3d\n", Ncr);
+
+    psTrace(__func__, 5, "---- end ----\n");
     return(rc);
 }
@@ -535,5 +531,5 @@
                      psF32 radius)
 {
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    psTrace(__func__, 5, "---- begin ----\n");
     PS_ASSERT_PTR_NON_NULL(source, false);
     PS_ASSERT_PTR_NON_NULL(source->peak, false);
@@ -641,11 +637,10 @@
     // XXX EAM - the limit is a bit arbitrary.  make it user defined?
     if ((numPixels < 0.75*R2) || (Sum <= 0)) {
-        psTrace (".psModules.pmSourceMoments", 3, "no valid pixels for source\n");
-        psTrace("psModules.objects", 3, "---- %s(false) end ----\n", __func__);
+        psTrace (__func__, 3, "no valid pixels for source\n");
+        psTrace(__func__, 5, "---- end (false) ----\n");
         return (false);
     }
 
-    psTrace (".psModules.pmSourceMoments", 5,
-             "sky: %f  Sum: %f  X1: %f  Y1: %f  X2: %f  Y2: %f  XY: %f  Npix: %d\n",
+    psTrace (__func__, 4, "sky: %f  Sum: %f  X1: %f  Y1: %f  X2: %f  Y2: %f  XY: %f  Npix: %d\n",
              sky, Sum, X1, Y1, X2, Y2, XY, numPixels);
 
@@ -658,8 +653,7 @@
     y = Y1/Sum;
     if ((fabs(x) > radius) || (fabs(y) > radius)) {
-        psTrace (".psModules.pmSourceMoments", 3,
-                 "large centroid swing; invalid peak %d, %d\n",
+        psTrace (__func__, 3, "large centroid swing; invalid peak %d, %d\n",
                  source->peak->x, source->peak->y);
-        psTrace("psModules.objects", 3, "---- %s(false) end ----\n", __func__);
+        psTrace(__func__, 5, "---- end(false)  ----\n");
         return (false);
     }
@@ -679,10 +673,10 @@
     source->moments->Sy = sqrt(PS_MAX(Y2/Sum - PS_SQR(y), 0));
 
-    psTrace (".psModules.pmSourceMoments", 4,
+    psTrace (__func__, 4,
              "sky: %f  Sum: %f  x: %f  y: %f  Sx: %f  Sy: %f  Sxy: %f\n",
              sky, Sum, source->moments->x, source->moments->y,
              source->moments->Sx, source->moments->Sy, source->moments->Sxy);
 
-    psTrace("psModules.objects", 3, "---- %s(true) end ----\n", __func__);
+    psTrace(__func__, 5, "---- end ----\n");
     return(true);
 }
