Index: /trunk/psphot/src/psphotApResid.c
===================================================================
--- /trunk/psphot/src/psphotApResid.c	(revision 9567)
+++ /trunk/psphot/src/psphotApResid.c	(revision 9568)
@@ -1,4 +1,5 @@
 # include "psphot.h"
-static char DEFAULT_OPTION[] = "SKYBIAS";
+
+static pmPSFApTrendOptions DEFAULT_OPTION = PM_PSF_APTREND_SKYBIAS;
 
 // measure the aperture residual statistics
@@ -93,7 +94,13 @@
     }
 
-    // APTREND options are defined by the if ... else if ... else if ... else block below
-    char *ApTrendOption = psMetadataLookupPtr (&status, recipe, "APTREND");
-    if (!status) ApTrendOption = DEFAULT_OPTION;
+    // APTREND options : NONE SKYBIAS XY_LIN XY_QUAD SKY_XY_LIN FULL 
+    // APTREND options are used in the switch block below
+    pmPSFApTrendOptions ApTrendOption = DEFAULT_OPTION;
+    char *optionName = psMetadataLookupPtr (&status, recipe, "APTREND");
+    if (status) ApTrendOption = pmPSFApTrendOptionFromName (optionName);
+    if (ApTrendOption == PM_PSF_APTREND_ERROR) {
+	psError(PSPHOT_ERR_APERTURE, true, "invalid aperture residual trend %s", optionName);
+	return false;
+    }
 
     // 3hi/1lo sigma clipping on the rflux vs metric fit
@@ -103,19 +110,20 @@
 
     // no correction
-    if (!strcasecmp (ApTrendOption, "NONE")) { 
+    switch (ApTrendOption) {
+      case PM_PSF_APTREND_NONE:
 	// remove ApTrend fit from pmPSFtry
 	psf->ApTrend->coeff[0][0][0][0] = 0;
-    } else if (!strcasecmp (ApTrendOption, "CONSTANT")) { // constant only
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-	if (psf->ApTrend == NULL) {
-	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
-	    return false;
-	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	break;
+      case PM_PSF_APTREND_CONSTANT:
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+	if (psf->ApTrend == NULL) {
+	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
+	    return false;
+	}
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -123,17 +131,17 @@
 	    return false;
 	}
-    } else if (!strcasecmp (ApTrendOption, "SKYBIAS")) { // constant and skybias only
-	// first clip out objects which are too far from the median 
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-	if (psf->ApTrend == NULL) {
-	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
-	    return false;
-	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
+	break;
+      case PM_PSF_APTREND_SKYBIAS:
+	// first clip out objects which are too far from the median 
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+	if (psf->ApTrend == NULL) {
+	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
+	    return false;
+	}
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -141,17 +149,17 @@
 	    return false;
 	}
-    } else if (!strcasecmp (ApTrendOption, "SKYSAT")) {
-	// first clip out objects which are too far from the median 
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-	if (psf->ApTrend == NULL) {
-	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
-	    return false;
-	}
-
-	// apply the fit
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
+	break;
+      case PM_PSF_APTREND_SKYSAT:
+	// first clip out objects which are too far from the median 
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+	if (psf->ApTrend == NULL) {
+	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
+	    return false;
+	}
+	// apply the fit
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -159,8 +167,7 @@
 	    return false;
 	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYSAT);
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -168,17 +175,17 @@
 	    return false;
 	}
-    } else if (!strcasecmp (ApTrendOption, "XY_LIN")) {	// constant and linear X,Y only
-	// first clip out objects which are too far from the median 
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-	if (psf->ApTrend == NULL) {
-	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
-	    return false;
-	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_XY_LIN);
+	break;
+      case PM_PSF_APTREND_XY_LIN:
+	// first clip out objects which are too far from the median 
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+	if (psf->ApTrend == NULL) {
+	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
+	    return false;
+	}
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_LIN);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -186,17 +193,17 @@
 	    return false;
 	}
-    } else if (!strcasecmp (ApTrendOption, "XY_QUAD")) { // constant and quadratic X,Y only
-	// first clip out objects which are too far from the median 
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-	if (psf->ApTrend == NULL) {
-	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
-	    return false;
-	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_XY_QUAD);
+	break;
+      case PM_PSF_APTREND_XY_QUAD:
+	// first clip out objects which are too far from the median 
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+	if (psf->ApTrend == NULL) {
+	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
+	    return false;
+	}
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_XY_QUAD);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -204,17 +211,17 @@
 	    return false;
 	}
-    } else if (!strcasecmp (ApTrendOption, "SKY_XY_LIN")) { // constant and sky, linear X,Y only
-	// first clip out objects which are too far from the median 
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-	if (psf->ApTrend == NULL) {
-	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
-	    return false;
-	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKY_XY_LIN);
+	break;
+      case PM_PSF_APTREND_SKY_XY_LIN:
+	// first clip out objects which are too far from the median 
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+	if (psf->ApTrend == NULL) {
+	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
+	    return false;
+	}
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKY_XY_LIN);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -222,17 +229,17 @@
 	    return false;
 	}
-    } else if (!strcasecmp (ApTrendOption, "SKYSAT_XY_LIN")) { // constant and sky, linear X,Y only
-	// first clip out objects which are too far from the median 
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
-	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
-	if (psf->ApTrend == NULL) {
-	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
-	    return false;
-	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
+	break;
+      case PM_PSF_APTREND_SKYSAT_XY_LIN:
+	// first clip out objects which are too far from the median 
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
+	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
+	if (psf->ApTrend == NULL) {
+	    psError(PSPHOT_ERR_PHOTOM, false, "clipping, fitting nothing");
+	    return false;
+	}
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -240,8 +247,7 @@
 	    return false;
 	}
-
-	// apply the fit
-	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYSAT_XY_LIN);
+	// apply the fit
+	stats->clipIter = 3;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYSAT_XY_LIN);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -249,8 +255,9 @@
 	    return false;
 	}
-    } else if (!strcasecmp (ApTrendOption, "ALL")) {
-	// first clip out objects which are too far from the median 
-	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_CONSTANT);
+	break;
+      case PM_PSF_APTREND_ALL:
+	// first clip out objects which are too far from the median 
+	stats->clipIter = 2;
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_CONSTANT);
 	psf->ApTrend  = psVectorClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -258,8 +265,7 @@
 	    return false;
 	}
-
 	// fit just SkyBias and clip out objects which are too far from the median 
 	stats->clipIter = 2;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_SKYBIAS);
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_SKYBIAS);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -267,8 +273,7 @@
 	    return false;
 	}
-
 	// finally, fit x, y, SkyBias and clip out objects which are too far from the median 
 	stats->clipIter = 3;
-	pmPSF_MaskApTrend (psf->ApTrend, PM_PSF_ALL);
+	pmPSFMaskApTrend (psf->ApTrend, PM_PSF_APTREND_ALL);
 	psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
 	if (psf->ApTrend == NULL) {
@@ -276,6 +281,7 @@
 	    return false;
 	}
-    } else {
-	psError(PSPHOT_ERR_PHOTOM, true, "Unknown APTREND value: %s", ApTrendOption);
+	break;
+      default:
+	psError(PSPHOT_ERR_PHOTOM, true, "Unknown APTREND value: %s", optionName);
 	return false;
     }
