Index: /trunk/psModules/src/objects/pmSource.c
===================================================================
--- /trunk/psModules/src/objects/pmSource.c	(revision 9879)
+++ /trunk/psModules/src/objects/pmSource.c	(revision 9880)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-28 20:15:48 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-07 09:06:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -67,27 +67,29 @@
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     static int id = 1;
-    pmSource *tmp = (pmSource *) psAlloc(sizeof(pmSource));
-    *(int *)&tmp->id = id++;
-    tmp->peak = NULL;
-    tmp->pixels = NULL;
-    tmp->weight = NULL;
-    tmp->mask = NULL;
-    tmp->moments = NULL;
-    tmp->blends = NULL;
-    tmp->modelPSF = NULL;
-    tmp->modelEXT = NULL;
-    tmp->type = PM_SOURCE_TYPE_UNKNOWN;
-    tmp->mode = PM_SOURCE_MODE_DEFAULT;
-    psMemSetDeallocator(tmp, (psFreeFunc) sourceFree);
-
-    tmp->psfMag = 32.0;
-    tmp->extMag = 32.0;
-    tmp->errMag = 32.0;
-    tmp->apMag  = 32.0;
-    tmp->pixWeight = 0.0;
-    tmp->sky = tmp->skyErr = NAN;
+    pmSource *source = (pmSource *) psAlloc(sizeof(pmSource));
+    *(int *)&source->id = id++;
+    source->peak = NULL;
+    source->pixels = NULL;
+    source->weight = NULL;
+    source->mask = NULL;
+    source->moments = NULL;
+    source->blends = NULL;
+    source->modelPSF = NULL;
+    source->modelEXT = NULL;
+    source->type = PM_SOURCE_TYPE_UNKNOWN;
+    source->mode = PM_SOURCE_MODE_DEFAULT;
+    psMemSetDeallocator(source, (psFreeFunc) sourceFree);
+
+    // default values are NAN
+    source->psfMag = NAN;
+    source->extMag = NAN;
+    source->errMag = NAN;
+    source->apMag  = NAN;
+    source->sky    = NAN;
+    source->skyErr = NAN;
+    source->pixWeight = NAN;
 
     psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
-    return(tmp);
+    return(source);
 }
 
@@ -95,4 +97,39 @@
 {
     return (psMemGetDeallocator(ptr) == (psFreeFunc)sourceFree);
+}
+
+/******************************************************************************
+pmSourceCopy(): copy the pmSource structure and contents
+XXX : are we OK with incrementing the ID?
+*****************************************************************************/
+pmSource *pmSourceCopy(pmSource *in)
+{
+    // this copy is used to allow multiple fit attempts on the
+    // same object.  the pixels, weight, and mask arrays all point to
+    // the same original subarrays.  the peak and moments point at
+    // the original values.
+    pmSource *source = pmSourceAlloc ();
+    source->peak = psMemIncrRefCounter (in->peak);
+    source->pixels = psMemIncrRefCounter (in->pixels);
+    source->weight = psMemIncrRefCounter (in->weight);
+    source->mask = psMemIncrRefCounter (in->mask);
+    source->moments = psMemIncrRefCounter (in->moments);
+    source->blends = NULL;
+    source->modelPSF = NULL;
+    source->modelEXT = NULL;
+    source->type = in->type;
+    source->mode = in->mode;
+    psMemSetDeallocator(source, (psFreeFunc) sourceFree);
+
+    // default values are NAN
+    source->psfMag = NAN;
+    source->extMag = NAN;
+    source->errMag = NAN;
+    source->apMag  = NAN;
+    source->sky    = NAN;
+    source->skyErr = NAN;
+    source->pixWeight = NAN;
+
+    return(source);
 }
 
Index: /trunk/psModules/src/objects/pmSource.h
===================================================================
--- /trunk/psModules/src/objects/pmSource.h	(revision 9879)
+++ /trunk/psModules/src/objects/pmSource.h	(revision 9880)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-19 21:10:08 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-07 09:06:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -116,4 +116,9 @@
 pmSource  *pmSourceAlloc();
 
+/** pmSourceCopy()
+ *
+ */
+pmSource  *pmSourceCopy(pmSource *source);
+
 // free just the pixels for a source, keeping derived data
 void pmSourceFreePixels(pmSource *source);
