Index: /trunk/psphot/Makefile
===================================================================
--- /trunk/psphot/Makefile	(revision 5606)
+++ /trunk/psphot/Makefile	(revision 5607)
@@ -12,9 +12,10 @@
 IPSLIB  :=      $(shell pslib-config --cflags)
 
-INCS	= 	$(IPSLIB)
-# LIBS	= 	-lpsmodule $(LPSLIB)
-LIBS	= 	$(LPSLIB)
+LPSMOD  :=      $(shell psmodule-config --libs)
+IPSMOD  :=      $(shell psmodule-config --cflags)
+
+INCS	= 	$(IPSLIB) $(IPSMOD)
+LIBS	= 	$(LPSLIB) $(LPSMOD)
 CFLAGS	=	$(INCS) -std=c99 -Wall -Werror -g
-# CFLAGS	=	$(INCS) -std=c99 -g
 LFLAGS	=	$(LIBS) 
 
@@ -32,15 +33,16 @@
 $(SRC)/psphotSubtractPSF.$(ARCH).o \
 $(SRC)/psphotSortBySN.$(ARCH).o    \
-$(SRC)/psphotDefinePixels.$(ARCH).o \
+$(SRC)/psphotDefinePixels.$(ARCH).o\
 $(SRC)/psphotMagnitudes.$(ARCH).o  \
-$(SRC)/psLibUtils.$(ARCH).o	   \
 $(SRC)/psLine.$(ARCH).o		   \
-$(SRC)/psEllipse.$(ARCH).o         \
 $(SRC)/psModulesUtils.$(ARCH).o	   \
 $(SRC)/pmPeaksSigmaLimit.$(ARCH).o \
+$(SRC)/psImageData.$(ARCH).o
+
+PSMODULES = \
+$(SRC)/psEllipse.$(ARCH).o         \
 $(SRC)/pmPSF.$(ARCH).o             \
 $(SRC)/pmPSFtry.$(ARCH).o          \
-$(SRC)/psImageData.$(ARCH).o	   \
-$(SRC)/pmModelGroup.$(ARCH).o       \
+$(SRC)/pmModelGroup.$(ARCH).o      \
 $(SRC)/pmObjects_EAM.$(ARCH).o
 
@@ -65,6 +67,7 @@
 
 psphot: $(BIN)/psphot.$(ARCH)
+# $(BIN)/psphot.$(ARCH) : $(PSPHOT) $(PSMODULES)
 $(BIN)/psphot.$(ARCH) : $(PSPHOT)
-$(PSPHOT): $(SRC)/psphot.h
+$(PSPHOT) $(PSMODULES): $(SRC)/psphot.h
 
 fitsource: $(BIN)/fitsource.$(ARCH)
Index: /trunk/psphot/doc/notes.txt
===================================================================
--- /trunk/psphot/doc/notes.txt	(revision 5606)
+++ /trunk/psphot/doc/notes.txt	(revision 5607)
@@ -1,4 +1,47 @@
 
 Notes on psphot
+
+2005.11.25
+
+  I've updated psphot to work with the current psLib v8, though a
+  number of psLib fixes were needed.  These are pushed under
+  psLib:eam_rel8_b2.  The psphot code which works with that version of
+  psLib is tagged psphot_dev_04.
+
+  I'm working on converting psphot to work with the current release of
+  psModules, which basically includes all of the object functions. 
+
+  - change comments are relative to psModules (vs psphot versions)
+
+  psEllipse.c : OK
+  psEllipse.h : OK
+  pmModelGroup.c : OK (missing TGAUSS entry)
+  pmModelGroup.h : OK (adds many comments)
+
+  pmPSFtry.c : a bunch of formatting weirdness (try-> got line breaks
+	       added pmPSFtryMetric_Alt
+	       fixed up usage of psVectorClipFitPolynomial1D  
+	       fixed up usage of psPolynomial..Alloc  
+
+  pmPSFtry.h : OK (Added extensive comments)
+
+  pmPSF.c : fixed up usage of psPolynomial..Alloc
+
+  pmPSF.h : OK (Added extensive comments)
+
+  pmObjects.c : cleaned up some formatting,
+		fixed usage of psImageCountPixelMask
+
+  pmObjects.h : added apMag and fitMag to pmSource
+		dropped PS_MODEL_name defines
+
+  psLibUtils.[ch] should be dropped from psModules
+  psModulesUtils.[ch] should be dropped from psModules
+
+  Makefile.am : dropped psModulesUtils.[ch], psLibUtils.[ch]
+
+  - I have successfully tested psphot with the psModules.v8 code
+    (eam_rel8_b1 tag).  I only needed to make a few modes in the
+    psModules code.  
 
 2005.11.16
Index: /trunk/psphot/doc/versions.txt
===================================================================
--- /trunk/psphot/doc/versions.txt	(revision 5606)
+++ /trunk/psphot/doc/versions.txt	(revision 5607)
@@ -1,4 +1,9 @@
 
 2005.11.25
+
+  psphot_dev_05 should be compiled against psLib tag eam_rel8_b2 and
+  psModules tag eam_rel8_b1.  this version removes all _EAM versions
+  of psLib and psModules code.  It now uses the psModules version of
+  the object code.
 
   psphot_dev_04 should be compiled against psLib tag eam_rel8_b2 this
Index: /trunk/psphot/src/pmObjects_EAM.c
===================================================================
--- /trunk/psphot/src/pmObjects_EAM.c	(revision 5606)
+++ /trunk/psphot/src/pmObjects_EAM.c	(revision 5607)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-11-25 23:13:43 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-11-26 03:00:41 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -723,5 +723,7 @@
     for (psS32 row = 0; row < source->pixels->numRows ; row++) {
         for (psS32 col = 0; col < source->pixels->numCols ; col++) {
-            if ((source->mask != NULL) && (source->mask->data.U8[row][col])) continue;
+            if ((source->mask != NULL) && (source->mask->data.U8[row][col])) {
+		continue;
+	    }
 
 	    psF32 xDiff = col + source->pixels->col0 - xPeak;
@@ -730,5 +732,7 @@
 	    // XXX EAM : calculate xDiff, yDiff up front;
 	    //           radius is just a function of (xDiff, yDiff)
-	    if (!VALID_RADIUS(xDiff, yDiff, R2)) continue;
+	    if (!VALID_RADIUS(xDiff, yDiff, R2)) {
+		continue;
+	    }
 
 	    psF32 pDiff = source->pixels->data.F32[row][col] - sky;
@@ -736,5 +740,7 @@
 	    // XXX EAM : check for valid S/N in pixel
 	    // XXX EAM : should this limit be user-defined?
-	    if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1) continue;
+	    if (pDiff / sqrt(source->weight->data.F32[row][col]) < 1) {
+		continue;
+	    }
 	    
 	    Sum += pDiff;
@@ -1031,5 +1037,4 @@
 
 	// XXX EAM : can we use the value of SATURATE if mask is NULL?
-	// allArray = psRegionSet (0, 0, 0, 0);
 	int Nsatpix = psImageCountPixelMask (tmpSrc->mask, allArray, PSPHOT_MASK_SATURATED);
 
@@ -1670,13 +1675,4 @@
 	}
     } 
-    # if (0)
-    else {
-	// try keeping the moments sky -- unsuccessful
-	for (int i = 1; i < paramMask->n; i++) {
-	    paramMask->data.U8[i] = 0;
-	}
-	paramMask->data.U8[0] = 1;
-    }
-    # endif
 
 
@@ -1814,12 +1810,2 @@
     return(p_pmSourceAddOrSubModel(image, mask, model, center, 1));
 }
-
-
-// XXX: Put this is psConstants.h
-#define PS_VECTOR_CHECK_SIZE(VEC1, N, RVAL) \
-if (VEC1->n != N) { \
-    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
-            "psVector %s has size %d, should be %d.", \
-            #VEC1, VEC1->n, N); \
-    return(RVAL); \
-}
Index: /trunk/psphot/src/pmObjects_EAM.h
===================================================================
--- /trunk/psphot/src/pmObjects_EAM.h	(revision 5606)
+++ /trunk/psphot/src/pmObjects_EAM.h	(revision 5607)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-21 06:52:23 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-11-26 03:00:41 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -22,6 +22,7 @@
 #include<math.h>
 #include "pslib.h"
-#include "psLibUtils.h"
-// #include "pmModelGroup.h"
+#include "psEllipse.h"
+
+# define psMemCopy(A)(psMemIncrRefCounter((A)))
 
 // defined mask values for mask image pixels.
Index: /trunk/psphot/src/pmPSFtry.c
===================================================================
--- /trunk/psphot/src/pmPSFtry.c	(revision 5606)
+++ /trunk/psphot/src/pmPSFtry.c	(revision 5607)
@@ -16,14 +16,14 @@
 static void pmPSFtryFree (pmPSFtry *test) {
 
-  if (test == NULL) return;
-
-  psFree (test->psf);
-  psFree (test->sources);
-  psFree (test->modelFLT);
-  psFree (test->modelPSF);
-  psFree (test->metric);
-  psFree (test->fitMag);
-  psFree (test->mask);
-  return;
+    if (test == NULL) return;
+
+    psFree (test->psf);
+    psFree (test->sources);
+    psFree (test->modelFLT);
+    psFree (test->modelPSF);
+    psFree (test->metric);
+    psFree (test->fitMag);
+    psFree (test->mask);
+    return;
 }
 
@@ -95,7 +95,7 @@
 	// exclude the poor fits
 	if (!status) {
-	  try->mask->data.U8[i] = PSFTRY_MASK_FLT_FAIL;
-	  psFree (model);
-	  continue;
+	    try->mask->data.U8[i] = PSFTRY_MASK_FLT_FAIL;
+	    psFree (model);
+	    continue;
 	}
 	try->modelFLT->data[i] = model;
@@ -136,5 +136,4 @@
 
 	// otherwise, save the resulting model
-	// pmModelSkyOffset (modelPSF, x, y, RADIUS);
 	try->modelPSF->data[i] = modelPSF;
 
@@ -171,177 +170,169 @@
 bool pmPSFtryMetric (pmPSFtry *try, float RADIUS) {
 
-  float dBin;
-  int   nKeep, nSkip;
-
-  // the measured (aperture - fit) magnitudes (dA == try->metric)
-  //   depend on both the true ap-fit (dAo) and the bias in the sky measurement:
-  //     dA = dAo + dsky/flux
-  //   where flux is the flux of the star
-  // we fit this trend to find the infinite flux aperture correction (dAo),
-  //   the nominal sky bias (dsky), and the error on dAo
-  // the values of dA are contaminated by stars with close neighbors in the aperture
-  //   we use an outlier rejection to avoid this bias
-
-  FILE *f;
-  f = fopen ("apresid.dat", "w");
-  if (f == NULL) psAbort ("pmPSFtry", "can't open output file");
-
-  // rflux = ten(0.4*fitMag);
-  psVector *rflux = psVectorAlloc (try->sources->n, PS_TYPE_F64);
-  for (int i = 0; i < try->sources->n; i++) {
-    if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue;
-    rflux->data.F64[i] = pow(10.0, 0.4*try->fitMag->data.F64[i]);
-    fprintf (f, "%3d %8.4f %12.5e %8.4f\n", i, try->fitMag->data.F64[i], rflux->data.F64[i], try->metric->data.F64[i]);
-  }
-  fclose (f);
-
-  // XXX EAM : try 3hi/1lo sigma clipping on the rflux v dap fit
-
-  // find min and max of (1/flux):
-  psStats *stats = psStatsAlloc (PS_STAT_MIN | PS_STAT_MAX);
-  psVectorStats (stats, rflux, NULL, try->mask, PSFTRY_MASK_ALL);
+    float dBin;
+    int   nKeep, nSkip;
+
+    // the measured (aperture - fit) magnitudes (dA == try->metric)
+    //   depend on both the true ap-fit (dAo) and the bias in the sky measurement:
+    //     dA = dAo + dsky/flux
+    //   where flux is the flux of the star
+    // we fit this trend to find the infinite flux aperture correction (dAo),
+    //   the nominal sky bias (dsky), and the error on dAo
+    // the values of dA are contaminated by stars with close neighbors in the aperture
+    //   we use an outlier rejection to avoid this bias
+
+    // rflux = ten(0.4*fitMag);
+    psVector *rflux = psVectorAlloc (try->sources->n, PS_TYPE_F64);
+    for (int i = 0; i < try->sources->n; i++) {
+	if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue;
+	rflux->data.F64[i] = pow(10.0, 0.4*try->fitMag->data.F64[i]);
+    }
+
+    // find min and max of (1/flux):
+    psStats *stats = psStatsAlloc (PS_STAT_MIN | PS_STAT_MAX);
+    psVectorStats (stats, rflux, NULL, try->mask, PSFTRY_MASK_ALL);
   
-  // build binned versions of rflux, metric
-  dBin = (stats->max - stats->min) / 10.0;
-  psVector *rfBin = psVectorCreate (NULL, stats->min, stats->max, dBin, PS_TYPE_F64);
-  psVector *daBin = psVectorAlloc (rfBin->n, PS_TYPE_F64);
-  psVector *maskB = psVectorAlloc (rfBin->n, PS_TYPE_U8);
-  psFree (stats);
-
-  psTrace ("psphot.metricmodel", 3, "rflux max: %g, min: %g, delta: %g\n", stats->max, stats->min, dBin);
-
-  // group data in daBin bins, measure lower 50% mean
-  for (int i = 0; i < daBin->n; i++) {
-
-    psVector *tmp = psVectorAlloc (try->sources->n, PS_TYPE_F64);
-    tmp->n = 0;
-
-    // accumulate data within bin range
-    for (int j = 0; j < try->sources->n; j++) {
-      // masked for: bad model fit, outlier in parameters
-      if (try->mask->data.U8[j] & PSFTRY_MASK_ALL) continue;
+    // build binned versions of rflux, metric
+    dBin = (stats->max - stats->min) / 10.0;
+    psVector *rfBin = psVectorCreate (NULL, stats->min, stats->max, dBin, PS_TYPE_F64);
+    psVector *daBin = psVectorAlloc (rfBin->n, PS_TYPE_F64);
+    psVector *maskB = psVectorAlloc (rfBin->n, PS_TYPE_U8);
+    psFree (stats);
+
+    psTrace ("psphot.metricmodel", 3, "rflux max: %g, min: %g, delta: %g\n", stats->max, stats->min, dBin);
+
+    // group data in daBin bins, measure lower 50% mean
+    for (int i = 0; i < daBin->n; i++) {
+
+	psVector *tmp = psVectorAlloc (try->sources->n, PS_TYPE_F64);
+	tmp->n = 0;
+
+	// accumulate data within bin range
+	for (int j = 0; j < try->sources->n; j++) {
+	    // masked for: bad model fit, outlier in parameters
+	    if (try->mask->data.U8[j] & PSFTRY_MASK_ALL) continue;
     
-      // skip points with extreme dA values
-      if (fabs(try->metric->data.F64[j]) > 0.5) continue;
-
-      // skip points outside of this bin
-      if (rflux->data.F64[j] < rfBin->data.F64[i] - 0.5*dBin) continue;
-      if (rflux->data.F64[j] > rfBin->data.F64[i] + 0.5*dBin) continue;
-
-      tmp->data.F64[tmp->n] = try->metric->data.F64[j];
-      tmp->n ++;
-    }
-
-    // is this a valid point?
-    maskB->data.U8[i] = 0;
-    if (tmp->n < 2) {
-      maskB->data.U8[i] = 1;
-      psFree (tmp);
-      continue;
-    } 
-
-    // dA values are contaminated with low outliers 
-    // measure statistics only on upper 50% of points
-    // this would be easier if we could sort in reverse:
-
-    psVectorSort (tmp, tmp);
-    nKeep = 0.5*tmp->n;
-    nSkip = tmp->n - nKeep;
-
-    psVector *tmp2 = psVectorAlloc (nKeep, PS_TYPE_F64);
-    for (int j = 0; j < tmp2->n; j++) {
-      tmp2->data.F64[j] = tmp->data.F64[j + nSkip];
-    }
-
-    stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
-    psVectorStats (stats, tmp2, NULL, NULL, 0);
-    psTrace ("psphot.metricmodel", 4, "rfBin %d (%g): %d pts, %g\n", i, rfBin->data.F64[i], tmp->n, stats->sampleMedian);
-
-    daBin->data.F64[i] = stats->sampleMedian;
-
+	    // skip points with extreme dA values
+	    if (fabs(try->metric->data.F64[j]) > 0.5) continue;
+
+	    // skip points outside of this bin
+	    if (rflux->data.F64[j] < rfBin->data.F64[i] - 0.5*dBin) continue;
+	    if (rflux->data.F64[j] > rfBin->data.F64[i] + 0.5*dBin) continue;
+
+	    tmp->data.F64[tmp->n] = try->metric->data.F64[j];
+	    tmp->n ++;
+	}
+
+	// is this a valid point?
+	maskB->data.U8[i] = 0;
+	if (tmp->n < 2) {
+	    maskB->data.U8[i] = 1;
+	    psFree (tmp);
+	    continue;
+	} 
+
+	// dA values are contaminated with low outliers 
+	// measure statistics only on upper 50% of points
+	// this would be easier if we could sort in reverse:
+
+	psVectorSort (tmp, tmp);
+	nKeep = 0.5*tmp->n;
+	nSkip = tmp->n - nKeep;
+
+	psVector *tmp2 = psVectorAlloc (nKeep, PS_TYPE_F64);
+	for (int j = 0; j < tmp2->n; j++) {
+	    tmp2->data.F64[j] = tmp->data.F64[j + nSkip];
+	}
+
+	stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
+	psVectorStats (stats, tmp2, NULL, NULL, 0);
+	psTrace ("psphot.metricmodel", 4, "rfBin %d (%g): %d pts, %g\n", i, rfBin->data.F64[i], tmp->n, stats->sampleMedian);
+
+	daBin->data.F64[i] = stats->sampleMedian;
+
+	psFree (stats);
+	psFree (tmp);
+	psFree (tmp2);
+    }
+
+    // linear clipped fit to rfBin, daBin
+    psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD);
+    psStats *fitstat = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
+    poly = psVectorClipFitPolynomial1D (poly, fitstat, maskB, 1, daBin, NULL, rfBin);
+
+    psVector *daBinFit = psPolynomial1DEvalVector (poly, rfBin);
+    psVector *daResid  = (psVector *) psBinaryOp (NULL, (void *) daBin, "-", (void *) daBinFit);
+
+    stats = psStatsAlloc (PS_STAT_CLIPPED_STDEV);
+    stats = psVectorStats (stats, daResid, NULL, maskB, 1);
+
+    try->psf->ApResid = poly->coeff[0];
+    try->psf->dApResid = stats->clippedStdev;
+    try->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
+
+    psFree (rflux);
+    psFree (rfBin);
+    psFree (daBin);
+    psFree (maskB);
+    psFree (daBinFit);
+    psFree (daResid);
+    psFree (poly);
     psFree (stats);
-    psFree (tmp);
-    psFree (tmp2);
-  }
-
-  // linear clipped fit to rfBin, daBin
-  psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD);
-  psStats *fitstat = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
-  poly = psVectorClipFitPolynomial1D (poly, fitstat, maskB, 1, daBin, NULL, rfBin);
-
-  psVector *daBinFit = psPolynomial1DEvalVector (poly, rfBin);
-  psVector *daResid  = (psVector *) psBinaryOp (NULL, (void *) daBin, "-", (void *) daBinFit);
-
-  stats = psStatsAlloc (PS_STAT_CLIPPED_STDEV);
-  stats = psVectorStats (stats, daResid, NULL, maskB, 1);
-
-  try->psf->ApResid = poly->coeff[0];
-  try->psf->dApResid = stats->clippedStdev;
-  try->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
-
-  psFree (rflux);
-  psFree (rfBin);
-  psFree (daBin);
-  psFree (maskB);
-  psFree (daBinFit);
-  psFree (daResid);
-  psFree (poly);
-  psFree (stats);
-  psFree (fitstat);
-
-  return true;
+    psFree (fitstat);
+
+    return true;
 }
 
 bool pmPSFtryMetric_Alt (pmPSFtry *try, float RADIUS) {
 
-  // the measured (aperture - fit) magnitudes (dA == try->metric)
-  //   depend on both the true ap-fit (dAo) and the bias in the sky measurement:
-  //     dA = dAo + dsky/flux
-  //   where flux is the flux of the star
-  // we fit this trend to find the infinite flux aperture correction (dAo),
-  //   the nominal sky bias (dsky), and the error on dAo
-  // the values of dA are contaminated by stars with close neighbors in the aperture
-  //   we use an outlier rejection to avoid this bias
-
-  // rflux = ten(0.4*fitMag);
-  psVector *rflux = psVectorAlloc (try->sources->n, PS_TYPE_F64);
-  for (int i = 0; i < try->sources->n; i++) {
-    if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue;
-    rflux->data.F64[i] = pow(10.0, 0.4*try->fitMag->data.F64[i]);
-  }
-
-  // XXX EAM : try 3hi/1lo sigma clipping on the rflux vs metric fit
-  psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
-
-  // XXX EAM 
-  stats->min = 1.0;
-  stats->max = 3.0;
-  stats->clipIter = 3;
-
-  // linear clipped fit to rfBin, daBin
-  psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD);
-  poly = psVectorClipFitPolynomial1D (poly, stats, try->mask, PSFTRY_MASK_ALL, try->metric, NULL, rflux);
-  fprintf (stderr, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
-
-  try->psf->ApResid = poly->coeff[0];
-  try->psf->dApResid = stats->sampleStdev;
-  try->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
-
-  FILE *f;
-  f = fopen ("apresid.dat", "w");
-  if (f == NULL) psAbort ("pmPSFtry", "can't open output file");
-
-  for (int i = 0; i < try->sources->n; i++) {
-    fprintf (f, "%3d %8.4f %12.5e %8.4f %3d\n", i, try->fitMag->data.F64[i], rflux->data.F64[i], try->metric->data.F64[i], try->mask->data.U8[i]);
-  }
-  fclose (f);
-
-  psFree (rflux);
-  psFree (poly);
-  psFree (stats);
-
-  // psFree (daFit);
-  // psFree (daResid);
-
-  return true;
-}
+    // the measured (aperture - fit) magnitudes (dA == try->metric)
+    //   depend on both the true ap-fit (dAo) and the bias in the sky measurement:
+    //     dA = dAo + dsky/flux
+    //   where flux is the flux of the star
+    // we fit this trend to find the infinite flux aperture correction (dAo),
+    //   the nominal sky bias (dsky), and the error on dAo
+    // the values of dA are contaminated by stars with close neighbors in the aperture
+    //   we use an outlier rejection to avoid this bias
+
+    // rflux = ten(0.4*fitMag);
+    psVector *rflux = psVectorAlloc (try->sources->n, PS_TYPE_F64);
+    for (int i = 0; i < try->sources->n; i++) {
+	if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue;
+	rflux->data.F64[i] = pow(10.0, 0.4*try->fitMag->data.F64[i]);
+    }
+
+    // XXX EAM : try 3hi/1lo sigma clipping on the rflux vs metric fit
+    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
+
+    // XXX EAM 
+    stats->min = 1.0;
+    stats->max = 3.0;
+    stats->clipIter = 3;
+
+    // linear clipped fit to rfBin, daBin
+    psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD);
+    poly = psVectorClipFitPolynomial1D (poly, stats, try->mask, PSFTRY_MASK_ALL, try->metric, NULL, rflux);
+    fprintf (stderr, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
+
+    try->psf->ApResid = poly->coeff[0];
+    try->psf->dApResid = stats->sampleStdev;
+    try->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
+
+    FILE *f;
+    f = fopen ("apresid.dat", "w");
+    if (f == NULL) psAbort ("pmPSFtry", "can't open output file");
+
+    for (int i = 0; i < try->sources->n; i++) {
+	fprintf (f, "%3d %8.4f %12.5e %8.4f %3d\n", i, try->fitMag->data.F64[i], rflux->data.F64[i], try->metric->data.F64[i], try->mask->data.U8[i]);
+    }
+    fclose (f);
+
+    psFree (rflux);
+    psFree (poly);
+    psFree (stats);
+
+    // psFree (daFit);
+    // psFree (daResid);
+
+    return true;
+}
Index: /trunk/psphot/src/psLibUtils.c
===================================================================
--- /trunk/psphot/src/psLibUtils.c	(revision 5606)
+++ /trunk/psphot/src/psLibUtils.c	(revision 5607)
@@ -64,19 +64,2 @@
     return (TRUE);
 }
-
-// XXX EAM a utility function
-bool p_psVectorPrintRow (int fd, psVector *a, char *name)
-{
-
-    char line[1024];
-
-    sprintf (line, "vector: %s\n", name);
-    write (fd, line, strlen(line));
-
-    for (int i = 0; i < a[0].n; i++) {
-        sprintf (line, "%f  ", p_psVectorGetElementF64(a, i));
-	write (fd, line, strlen(line));
-    }
-    write (fd, "\n", 1);
-    return (true);
-}
Index: /trunk/psphot/src/psLibUtils.h
===================================================================
--- /trunk/psphot/src/psLibUtils.h	(revision 5606)
+++ /trunk/psphot/src/psLibUtils.h	(revision 5607)
@@ -2,7 +2,4 @@
 # ifndef PS_LIB_UTILS
 # define PS_LIB_UTILS
-
-// XXX EAM : psEllipse needs to be be included in psLib
-# include "psEllipse.h"
 
 // structure to carry a dynamic string
@@ -13,40 +10,4 @@
 } psLine;
 
-# define psMemCopy(A)(psMemIncrRefCounter((A)))
-
-// XXX EAM : my version using varience instead of stdev
-bool psMinimizeGaussNewtonDelta_EAM (psVector *delta,
-				     const psVector *params,
-				     const psVector *paramMask,
-				     const psArray  *x,
-				     const psVector *y,
-				     const psVector *yErr,
-				     psMinimizeLMChi2Func func);
-
-// minimize : using varience vs sigma and parameter limits
-psBool 	     p_psMinLM_GuessABP_EAM (psImage  *Alpha, psVector *Beta, psVector *Params, const psImage  *alpha, const psVector *beta, const psVector *params, const psVector *paramMask, const psVector *beta_lim, const psVector *params_min, const psVector *params_max, psF64 lambda);
-psBool 	     psMinimizeLMChi2_EAM(psMinimization *min, psImage *covar, psVector *params, const psVector *paramMask, const psArray *x, const psVector *y, const psVector *yErr, psMinimizeLMChi2Func func);
-psF64        p_psMinLM_dLinear (const psVector *Beta, const psVector *beta, psF64 lambda);
-
-int          psImageCountPixelMask_EAM (psImage *mask, psU8 value); // added to SDRS
-
-// psLib extra utilities
-# if (0) // added to psLib v8
-int	     psArgumentGet (int argc, char **argv, char *arg); // added to SDRS
-int	     psArgumentRemove (int N, int *argc, char **argv); // added to SDRS
-bool 	     psTimerClear (char *name);   // added to SDRS 
-psVector    *psVectorCreate (double lower, double upper, double delta, psElemType type); // added to SDRS
-# endif
-
-bool 	     psTimerStart (char *name);   // added to SDRS
-psF64 	     psTimerMark (char *name);    // added to SDRS
-void 	     psTimerFree ();              // added to SDRS (as psTimerStop)
-psS32 	     psLogArguments (int *argc, char **argv);   // added to SDRS (part of psArgumentVerbosity)
-psS32 	     psTraceArguments (int *argc, char **argv); // added to SDRS (part of psArgumentVerbosity)
-
-// basic image functions
-bool         psImageInit (psImage *image,...); // added to SDRS (v.15)
-void	     psImageSmooth_EAM (psImage *image, float sigma, float Nsigma); // added to SDRS (v.15)
-
 // psLine functions -- keep out for now?
 psLine      *psLineAlloc (int Nline);
@@ -54,24 +15,3 @@
 bool	     psLineAdd (psLine *line, char *format, ...);
 
-// not included in the .h file -- these are fairly lame, keep out?
-bool p_psVectorPrint (int fd, psVector *a, char *name);
-bool p_psVectorPrintRow (int fd, psVector *a, char *name);
-
-// polynomial functions -- all in SDRS, not done for v.15
-// XXX the pslib 0.7.0 polynomials are *still* nTerm, not nOrder!!!
-psPolynomial1D *Polynomial1DAlloc_EAM(psPolynomialType type, psS32 nOrder);
-void	        Polynomial1DDump_EAM(psPolynomial1D *poly);
-psF64		Polynomial1DEval_EAM(const psPolynomial1D* myPoly, psF64 x);
-psVector       *Polynomial1DEvalVector_EAM(const psPolynomial1D *myPoly, const psVector *x);
-psPolynomial1D *VectorFitPolynomial1D_EAM(psPolynomial1D* myPoly, psVector* mask, psMaskType maskValue, const psVector* y, const psVector* yErr, const psVector* x);
-psPolynomial1D *VectorClipFitPolynomial1D_EAM(psPolynomial1D* poly, psStats *stats, psVector* mask, psMaskType maskValue, const psVector* z, const psVector* zErr, const psVector* x);
-
-psPolynomial2D *Polynomial2DAlloc_EAM(psPolynomialType type, psS32 nXorder, psS32 nYorder);
-void	        Polynomial2DDump_EAM(psPolynomial2D *poly);
-psF64	        Polynomial2DEval_EAM(const psPolynomial2D* myPoly, psF64 x, psF64 y);
-psVector       *Polynomial2DEvalVector_EAM(const psPolynomial2D *myPoly, const psVector *x,const psVector *y);
-psVector       *Polynomial2DEvalVectorD_EAM(const psPolynomial2D *myPoly, const psVector *x,const psVector *y);
-psPolynomial2D *VectorFitPolynomial2D_EAM(psPolynomial2D* myPoly, psVector* mask, psMaskType maskValue, const psVector* z, const psVector* zErr, const psVector* x, const psVector* y);
-psPolynomial2D *VectorClipFitPolynomial2D_EAM(psPolynomial2D* poly, psStats *stats, psVector* mask, psMaskType maskValue, const psVector* z, const psVector* zErr, const psVector* x, const psVector* y);
-
 # endif
Index: /trunk/psphot/src/psphotArguments.c
===================================================================
--- /trunk/psphot/src/psphotArguments.c	(revision 5606)
+++ /trunk/psphot/src/psphotArguments.c	(revision 5607)
@@ -12,6 +12,5 @@
   fprintf (stderr, "starting... %s\n", psLibVersion());
   psLogSetFormat ("M");
-  psLogArguments (argc, argv);
-  psTraceArguments (argc, argv);
+  psArgumentVerbosity (argc, argv);
 
   // optional mask image - add to config
