Index: trunk/psphot/src/psphotMagnitudes.c
===================================================================
--- trunk/psphot/src/psphotMagnitudes.c	(revision 5772)
+++ trunk/psphot/src/psphotMagnitudes.c	(revision 5773)
@@ -1,13 +1,20 @@
 # include "psphot.h"
 
-// XXX EAM : this aperture correction business is invalid (& wrong) for galaxies
+// XXX EAM : the apMag should only be calculated for the brighter sources
+// XXX EAM : SN limit set by user?
+// XXX EAM : masked region should be (optionally) elliptical
 pmModel *pmSourceMagnitudes (pmSource *source, pmPSF *psf, float apRadius) {
 
     int status;
     float x, y;
-    float sky, rflux, apMag, fitMag;
+    float rflux, apMag, fitMag;
+    pmModel *model;
 
     // use the correct model (PSF vs FLT)
-    pmModel *model = pmSourceSelectModel (source);
+    if (psf != NULL) {
+      model = source->modelPSF;
+    } else {
+      model = source->modelFLT;
+    }
     if (model == NULL) return NULL;
 
@@ -20,17 +27,16 @@
     psImageKeepCircle (source->mask, x, y, apRadius, "OR", PSPHOT_MASK_MARKED);
 
-    // save local sky for later
-    sky = model->params->data.F32[0];
-
     // replace source flux
     pmSourceAddModel (source->pixels, source->mask, model, false, false);
 
     // measure object photometry
-    status = pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
+    status = pmSourcePhotometry (&source->fitMag, &source->apMag, model, source->pixels, source->mask);
 
-    // correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS
-    rflux   = pow (10.0, 0.4*fitMag);
-    source->apMag  = apMag  - rflux * psf->skyBias * (M_PI * PS_SQR(apRadius));
-    source->fitMag = fitMag + psf->ApResid;
+    // for PSFs, correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS
+    if (psf != NULL) {
+      rflux   = pow (10.0, 0.4*source->fitMag);
+      source->apMag  -= rflux * psf->skyBias * (M_PI * PS_SQR(apRadius));
+      source->fitMag += psf->ApResid;
+    }
 
     // subtract object, leave local sky
