Index: /trunk/psphot/src/psphotApResid.c
===================================================================
--- /trunk/psphot/src/psphotApResid.c	(revision 7325)
+++ /trunk/psphot/src/psphotApResid.c	(revision 7326)
@@ -98,9 +98,9 @@
     if (!strcasecmp (ApTrendOption, "CONSTANT")) {
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
@@ -110,10 +110,10 @@
 	// first clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_SKYBIAS);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
@@ -122,15 +122,15 @@
 	// first clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_SKYBIAS);
-	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_SKYSAT);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 2;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
+	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYSAT);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
@@ -140,10 +140,10 @@
 	// first clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_XY_LIN);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_XY_LIN);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
@@ -153,10 +153,10 @@
 	// first clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_XY_QUAD);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_XY_QUAD);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
@@ -166,10 +166,10 @@
 	// first clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_SKY_XY_LIN);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKY_XY_LIN);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
@@ -179,15 +179,15 @@
 	// first clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_SKYBIAS);
-	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_SKYSAT_XY_LIN);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
+	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYSAT_XY_LIN);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
@@ -196,15 +196,15 @@
 	// first clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_CONSTANT);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
 	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 
 	// fit just SkyBias and clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf, PM_PSF_SKYBIAS);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 
 	// finally, fit x, y, SkyBias and clip out objects which are too far from the median 
 	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf, PM_PSF_ALL);
+	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_ALL);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
     }
