Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6864)
@@ -245,5 +245,5 @@
     bool status;
     char *extra;
-    char *mode;
+    char *mode = NULL;
     char *readMode = "r";
     char *writeMode = "w";
Index: /branches/rel10_ifa/psModules/src/objects/models/pmModel_QGAUSS.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 6864)
@@ -123,10 +123,10 @@
     // the area needs to be multiplied by the integral of f(z)
     norm = 0.0;
-    for (z = 0.005; z < 50; z += 0.01) {
+    for (z = 0.05; z < 50; z += 0.1) {
         f = 1.0 / (1 + PAR[7]*z + pow(z, 2.25));
         // test: f = 1.0 / (1 + PAR[7]*z + PS_SQR(z));
         norm += f;
     }
-    norm *= 0.01;
+    norm *= 0.1;
 
     psF64 Flux = PAR[1] * Area * norm;
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO.c	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO.c	(revision 6864)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-14 21:43:59 $
+ *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-17 17:10:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -326,5 +326,5 @@
 
     bool status;
-    psArray *sources;
+    psArray *sources = NULL;
     pmHDU *hdu;
 
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c	(revision 6864)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-14 21:43:59 $
+ *  @version $Revision: 1.1.2.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-17 17:10:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -89,4 +89,5 @@
     psMetadataAdd (header, PS_LIST_HEAD, "EXTNAME", PS_DATA_STRING | PS_META_REPLACE, "extension name", extname);
 
+    // XXX this is broken : does not write the existing header elements except EXTNAME
     psFitsWriteTable (fits, header, table);
     psTrace ("pmFPAfile", 5, "wrote ext data %s\n", extname);
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c	(revision 6864)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-14 21:43:59 $
+ *  @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-17 17:10:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -37,5 +37,5 @@
     psMetadataItem *mdi;
     psF32 *PAR, *dPAR;
-    float dmag, lsky;
+    float lsky = 0;
     bool status;
     psEllipseShape shape;
@@ -99,5 +99,5 @@
         psLineAdd (line, "%6.1f ",  PAR[3]);
         psLineAdd (line, "%6.3f ",  PS_MIN (99.0, source->psfMag + ZERO_POINT));
-        psLineAdd (line, "%03d ",   PS_MIN (999, (int)(1000*dmag)));
+        psLineAdd (line, "%03d ",   PS_MIN (999, (int)(1000*source->errMag)));
         psLineAdd (line, "%2d ",    type);
         psLineAdd (line, "%3.1f ",  lsky);
@@ -249,25 +249,2 @@
     return (sources);
 }
-
-# if (0)
-    PAR = model->params->data.F32;
-dPAR = model->dparams->data.F32;
-
-dmag = dPAR[1] / PAR[1];
-type = pmSourceDophotType (source);
-lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]);
-
-psLineInit (line);
-psLineAdd (line, "%6.1f ", PAR[2]);
-psLineAdd (line, "%6.1f ", PAR[3]);
-psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->fitMag + ZERO_POINT));
-psLineAdd (line, "%03d ",  PS_MIN (999, (int)(1000*dmag)));
-psLineAdd (line, "%2d ",   type);
-psLineAdd (line, "%3.1f ", lsky);
-psLineAdd (line, "%6.3f ", 99.999); // should be 'Mgal
-psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->apMag + ZERO_POINT));
-psLineAdd (line, "%6.2f ", PAR[4]); // should be 'FHWM x'
-psLineAdd (line, "%6.2f ", PAR[5]); // should be 'FHWM y'
-psLineAdd (line, "%5.1f\n", 0); // should be theta
-
-# endif
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_RAW.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_RAW.c	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_RAW.c	(revision 6864)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-14 21:43:59 $
+ *  @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-17 17:10:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -130,5 +130,6 @@
         if (source->type != PM_SOURCE_TYPE_EXTENDED)
             continue;
-        model = pmSourceMagnitudes (source, NULL, false, false);
+
+        model = source->modelEXT;
         if (model == NULL)
             continue;
Index: /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c	(revision 6864)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-14 21:43:59 $
+ *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-17 17:10:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -56,9 +56,8 @@
 
 // XXX EAM : masked region should be (optionally) elliptical
-// XXX curve of growth is corrected to
-pmModel *pmSourceMagnitudes (pmSource *source, pmPSF *psf, bool growthCorr, bool apTrendCorr)
-{
-
-    int status;
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode)
+{
+
+    int status = false;
     bool isPSF;
     float x, y;
@@ -67,9 +66,14 @@
     pmModel *model;
 
+    source->psfMag = 99.0;
+    source->extMag = 99.0;
+    source->errMag = 99.0;
+    source->apMag  = 99.0;
+
     switch (source->type) {
     case PM_SOURCE_TYPE_STAR:
         model = source->modelPSF;
         if (model == NULL)
-            return NULL;
+            return false;
         isPSF = true;
         break;
@@ -78,10 +82,10 @@
         model = source->modelEXT;
         if (model == NULL)
-            return NULL;
+            return false;
         isPSF = false;
         break;
 
     default:
-        return NULL;
+        return false;
     }
 
@@ -96,4 +100,16 @@
     y = model->params->data.F32[3];
 
+    // measure object model photometry
+    status = pmSourcePhotometryModel (&source->psfMag, source->modelPSF);
+    status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
+    // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
+    if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf) {
+        // convert to the equivalent 2D model?
+        source->psfMag += psPolynomial4DEval (psf->ApTrend, x, y, 0.0, 0.0);
+    }
+
+    if (SN < AP_MIN_SN)
+        return false;
+
     // replace source flux
     // XXX test to see if source has been subtracted?
@@ -103,31 +119,20 @@
     psImageKeepCircle (source->mask, x, y, model->radiusTMP, "OR", PM_SOURCE_MASK_MARKED);
 
-    // measure object model photometry
-    status = pmSourcePhotometryModel (&source->psfMag, source->modelPSF);
-    status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
-
     // measure the weight of included pixels
-    status = pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->mask);
+    if (mode & PM_SOURCE_PHOT_WEIGHT) {
+        pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->mask);
+    }
 
     // measure object aperture photometry
-    if (SN > AP_MIN_SN) {
-        status = pmSourcePhotometryAper  (&source->apMag, model, source->pixels, source->mask);
-    } else {
-        source->apMag = 99.0;
-    }
+    status = pmSourcePhotometryAper  (&source->apMag, model, source->pixels, source->mask);
 
     // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
-    if (isPSF && (psf != NULL)) {
-        if (SN > AP_MIN_SN) {
-            if ((psf->growth != NULL) && growthCorr) {
-                source->apMag += pmGrowthCurveCorrect (psf->growth, model->radiusTMP);
-            }
-            if (apTrendCorr) {
-                rflux   = pow (10.0, 0.4*source->psfMag);
-                source->apMag  -= PS_SQR(model->radiusTMP)*rflux * psf->skyBias + psf->skySat / rflux;
-            }
-        }
-        if (apTrendCorr) {
-            source->psfMag += psPolynomial4DEval (psf->ApTrend, x, y, 0.0, 0.0);
+    if (status && isPSF && psf) {
+        if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
+            source->apMag += pmGrowthCurveCorrect (psf->growth, model->radiusTMP);
+        }
+        if (mode & PM_SOURCE_PHOT_APCORR) {
+            rflux   = pow (10.0, 0.4*source->psfMag);
+            source->apMag  -= PS_SQR(model->radiusTMP)*rflux * psf->skyBias + psf->skySat / rflux;
         }
     }
@@ -139,7 +144,5 @@
     pmModelSub (source->pixels, source->mask, model, false, false);
 
-    if (!status)
-        return NULL;
-    return model;
+    return status;
 }
 
Index: /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h	(revision 6863)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h	(revision 6864)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-14 21:43:59 $
+ *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-17 17:10:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -25,4 +25,12 @@
  *
  */
+
+typedef enum {
+    PM_SOURCE_PHOT_NONE   = 0x0000,
+    PM_SOURCE_PHOT_GROWTH = 0x0001,
+    PM_SOURCE_PHOT_APCORR = 0x0002,
+    PM_SOURCE_PHOT_WEIGHT = 0x0004,
+} pmSourcePhotometryMode;
+
 bool pmSourcePhotometryModel(
     float *fitMag,                      ///< integrated fit magnitude
@@ -37,5 +45,6 @@
 );
 
-pmModel *pmSourceMagnitudes (pmSource *source, pmPSF *psf, bool growthCorr, bool apTrendCorr);
+bool pmSourceMagnitudesInit (psMetadata *config);
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode);
 float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj);
 float pmSourceCrossWeight (pmSource *Mi, pmSource *Mj);
