Index: trunk/psphot/src/psphotMagnitudes.c
===================================================================
--- trunk/psphot/src/psphotMagnitudes.c	(revision 5828)
+++ trunk/psphot/src/psphotMagnitudes.c	(revision 5837)
@@ -1,5 +1,5 @@
 # include "psphot.h"
 
-// XXX EAM : the apMag should only be calculated for the brighter sources
+// 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
@@ -7,26 +7,37 @@
 
     int status;
+    bool isPSF;
     float x, y;
     float rflux;
+    float radius;
     pmModel *model;
 
-    // use the correct model (PSF vs FLT)
-    if (psf != NULL) {
-      model = source->modelPSF;
-    } else {
-      model = source->modelFLT;
+    switch (source->type) {
+      case PM_SOURCE_STAR:
+	model = source->modelPSF;
+	if (model == NULL) return NULL;
+	radius = apRadius;
+	isPSF = true;
+	break;
+
+      case PM_SOURCE_GALAXY:
+	model = source->modelFLT;
+	if (model == NULL) return NULL;
+	radius = model->radius;
+	isPSF = false;
+	break;
+	    
+      default:
+	return NULL;
     }
-    if (model == NULL) return NULL;
 
-    x = source->peak->x;
-    y = source->peak->y;
-
-    // we have already (psphotApplyPSF) defined pixels at least OUTER_RADIUS from source
-    // we need to mask pixels to measure the aperture magnitude
-    // set aperture mask circle of PSF_FIT_RADIUS 
-    psImageKeepCircle (source->mask, x, y, apRadius, "OR", PSPHOT_MASK_MARKED);
+    x = model->params->data.F32[2];
+    y = model->params->data.F32[3];
 
     // replace source flux
     pmSourceAddModel (source->pixels, source->mask, model, false, false);
+
+    // set aperture mask circle of PSF_FIT_RADIUS 
+    psImageKeepCircle (source->mask, x, y, radius, "OR", PSPHOT_MASK_MARKED);
 
     // measure object photometry
@@ -34,5 +45,5 @@
 
     // for PSFs, correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS
-    if (psf != NULL) {
+    if (isPSF && (psf != NULL)) {
       rflux   = pow (10.0, 0.4*source->fitMag);
       source->apMag  -= rflux * psf->skyBias * (M_PI * PS_SQR(apRadius));
@@ -44,29 +55,8 @@
 
     // unmask aperture
-    psImageKeepCircle (source->mask, x, y, apRadius, "AND", ~PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, radius, "AND", ~PSPHOT_MASK_MARKED);
+
+    if (!status) return NULL;
     return model;
-}
-
-pmModel *pmSourceSelectModel (pmSource *source) {
-
-    pmModel *model;
-
-    switch (source->type) {
-    
-	// use PSF model with stars
-      case PM_SOURCE_STAR:
-	model = source->modelPSF;
-	break;
-
-	// use FLT model with galaxies
-      case PM_SOURCE_GALAXY:
-	model = source->modelFLT;
-	break;
-	    
-	// skip defects and poorly fitted stars or galaxies
-      default:
-	model = NULL;
-    }
-    return (model);
 }
 
