Index: /trunk/psastro/src/psastroAstromGuess.c
===================================================================
--- /trunk/psastro/src/psastroAstromGuess.c	(revision 8045)
+++ /trunk/psastro/src/psastroAstromGuess.c	(revision 8046)
@@ -4,5 +4,5 @@
 // XXX WCS keywords in the headers corresponding to the chips.
 // XXX this function is both converting the header WCS astrometry terms to the fpa terms
-//     and applying the astrometry to the detected objects.  
+//     and applying the astrometry to the detected objects.
 bool psastroAstromGuess (pmConfig *config) {
 
@@ -10,6 +10,6 @@
     bool status = false;
     bool isMosaic = false;
-    double RAmin, RAmax, RAminSky, RAmaxSky;
-    double DECmin, DECmax;
+    double RAmin = NAN, RAmax = NAN, RAminSky = NAN, RAmaxSky = NAN;
+    double DECmin = NAN, DECmax = NAN;
 
     pmChip *chip = NULL;
@@ -23,6 +23,6 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-	psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-	exit(EXIT_FAILURE);
+        psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
+        exit(EXIT_FAILURE);
     }
 
@@ -30,6 +30,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-	psErrorStackPrint(stderr, "Can't find input data!\n");
-	exit(EXIT_FAILURE);
+        psErrorStackPrint(stderr, "Can't find input data!\n");
+        exit(EXIT_FAILURE);
     }
 
@@ -44,71 +44,71 @@
         psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
-	
+
         // read WCS data from the corresponding header
         pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
 
-	pmAstromReadWCS (fpa, chip, hdu->header, plateScale, isMosaic);
-	if (newFPA) {
-	    newFPA = false;
-	    RAminSky = fpa->projection->R - M_PI;
-	    RAmaxSky = fpa->projection->R + M_PI;
-	    RAmin = RAmax = fpa->projection->R;
-	    DECmin = DECmax = fpa->projection->D;
-	}
+        pmAstromReadWCS (fpa, chip, hdu->header, plateScale, isMosaic);
+        if (newFPA) {
+            newFPA = false;
+            RAminSky = fpa->projection->R - M_PI;
+            RAmaxSky = fpa->projection->R + M_PI;
+            RAmin = RAmax = fpa->projection->R;
+            DECmin = DECmax = fpa->projection->D;
+        }
 
-	// apply the new WCS guess data to all of the data in the readouts
-	// XXX should this go into a different function? this would separate WCS interpretation from application
-	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
+        // apply the new WCS guess data to all of the data in the readouts
+        // XXX should this go into a different function? this would separate WCS interpretation from application
+        while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
             psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
-	    // process each of the readouts
-	    while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
-		if (! readout->data_exists) { continue; }
+            // process each of the readouts
+            while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) {
+                if (! readout->data_exists) { continue; }
 
-		psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
-		if (rawstars == NULL) { continue; }
+                psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");
+                if (rawstars == NULL) { continue; }
 
-		for (int i = 0; i < rawstars->n; i++) {
-		    pmAstromObj *raw = rawstars->data[i];
-	
-		    psPlaneTransformApply (raw->FP, chip->toFPA, raw->chip);
-		    psPlaneDistortApply (raw->TP, fpa->toTangentPlane, raw->FP, 0.0, 0.0);
-		    p_psDeproject (raw->sky, raw->TP, fpa->projection);
+                for (int i = 0; i < rawstars->n; i++) {
+                    pmAstromObj *raw = rawstars->data[i];
 
-		    if (i < 0) {
-			fprintf (stderr, "up: %f,%f -> %f,%f -> %f,%f -> %f,%f\n", 
-				 raw->chip->x, raw->chip->y, 
-				 raw->FP->x, raw->FP->y, 
-				 raw->TP->x, raw->TP->y, 
-				 raw->sky->r, raw->sky->d);
+                    psPlaneTransformApply (raw->FP, chip->toFPA, raw->chip);
+                    psPlaneDistortApply (raw->TP, fpa->toTangentPlane, raw->FP, 0.0, 0.0);
+                    p_psDeproject (raw->sky, raw->TP, fpa->projection);
 
-			psPlane *fp = psPlaneAlloc();
-			psPlane *tp = psPlaneAlloc();
-			psPlane *ch = psPlaneAlloc();
+                    if (i < 0) {
+                        fprintf (stderr, "up: %f,%f -> %f,%f -> %f,%f -> %f,%f\n",
+                                 raw->chip->x, raw->chip->y,
+                                 raw->FP->x, raw->FP->y,
+                                 raw->TP->x, raw->TP->y,
+                                 raw->sky->r, raw->sky->d);
 
-			p_psProject (tp, raw->sky, fpa->projection);
-			psPlaneDistortApply (fp, fpa->fromTangentPlane, tp, 0.0, 0.0);
-			psPlaneTransformApply (ch, chip->fromFPA, fp);
+                        psPlane *fp = psPlaneAlloc();
+                        psPlane *tp = psPlaneAlloc();
+                        psPlane *ch = psPlaneAlloc();
 
-			fprintf (stderr, "dn: %f,%f <- %f,%f <- %f,%f <- %f,%f\n", 
-				 ch->x, ch->y, 
-				 fp->x, fp->y, 
-				 tp->x, tp->y, 
-				 raw->sky->r, raw->sky->d);
-		    }
+                        p_psProject (tp, raw->sky, fpa->projection);
+                        psPlaneDistortApply (fp, fpa->fromTangentPlane, tp, 0.0, 0.0);
+                        psPlaneTransformApply (ch, chip->fromFPA, fp);
 
-		    // rationalize ra to sky range centered on boresite
-		    while (raw->sky->r < RAminSky) raw->sky->r += M_PI;
-		    while (raw->sky->r > RAmaxSky) raw->sky->r -= M_PI;
+                        fprintf (stderr, "dn: %f,%f <- %f,%f <- %f,%f <- %f,%f\n",
+                                 ch->x, ch->y,
+                                 fp->x, fp->y,
+                                 tp->x, tp->y,
+                                 raw->sky->r, raw->sky->d);
+                    }
 
-		    RAmin = PS_MIN (raw->sky->r, RAmin);
-		    RAmax = PS_MAX (raw->sky->r, RAmax);
+                    // rationalize ra to sky range centered on boresite
+                    while (raw->sky->r < RAminSky) raw->sky->r += M_PI;
+                    while (raw->sky->r > RAmaxSky) raw->sky->r -= M_PI;
 
-		    DECmin = PS_MIN (raw->sky->d, DECmin);
-		    DECmax = PS_MAX (raw->sky->d, DECmax);
-		}
-	    }
-	}
+                    RAmin = PS_MIN (raw->sky->r, RAmin);
+                    RAmax = PS_MAX (raw->sky->r, RAmax);
+
+                    DECmin = PS_MIN (raw->sky->d, DECmin);
+                    DECmax = PS_MAX (raw->sky->d, DECmax);
+                }
+            }
+        }
     }
 
@@ -119,5 +119,5 @@
     psMetadataAdd (recipe, PS_LIST_TAIL, "DEC_MIN", PS_DATA_F32 | PS_META_REPLACE, "", DECmin);
     psMetadataAdd (recipe, PS_LIST_TAIL, "DEC_MAX", PS_DATA_F32 | PS_META_REPLACE, "", DECmax);
-    
+
     psFree (view);
     return true;
Index: /trunk/psphot/src/psphotChoosePSF.c
===================================================================
--- /trunk/psphot/src/psphotChoosePSF.c	(revision 8045)
+++ /trunk/psphot/src/psphotChoosePSF.c	(revision 8046)
@@ -2,11 +2,11 @@
 
 // try PSF models and select best option
-pmPSF *psphotChoosePSF (pmReadout *readout, psArray *sources, psMetadata *recipe) { 
+pmPSF *psphotChoosePSF (pmReadout *readout, psArray *sources, psMetadata *recipe) {
 
-    bool       	    status;
-    char       	   *modelName;
-    pmPSF 	   *psf = NULL;
-    pmPSFtry 	   *try = NULL;
-    psArray    	   *stars = NULL;
+    bool            status;
+    char           *modelName;
+    pmPSF          *psf = NULL;
+    pmPSFtry       *try = NULL;
+    psArray        *stars = NULL;
 
     psTimerStart ("psphot");
@@ -32,6 +32,6 @@
     // select the candidate PSF stars (pointers to original sources)
     for (int i = 0; (i < sources->n) && (stars->n < NSTARS); i++) {
-	pmSource *source = sources->data[i];
-	if (source->mode & PM_SOURCE_MODE_PSFSTAR) psArrayAdd (stars, 200, source);
+        pmSource *source = sources->data[i];
+        if (source->mode & PM_SOURCE_MODE_PSFSTAR) psArrayAdd (stars, 200, source);
     }
     psLogMsg ("psphot.pspsf", 4, "selected candidate %d PSF objects\n", stars->n);
@@ -47,9 +47,9 @@
 
     if (mdi->type == PS_DATA_STRING) {
-	list = psListAlloc(NULL);
-	psListAdd (list, PS_LIST_HEAD, mdi);
+        list = psListAlloc(NULL);
+        psListAdd (list, PS_LIST_HEAD, mdi);
     } else {
-	if (mdi->type != PS_DATA_METADATA_MULTI) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
-	list = psMemIncrRefCounter(mdi->data.list);
+        if (mdi->type != PS_DATA_METADATA_MULTI) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
+        list = psMemIncrRefCounter(mdi->data.list);
     }
 
@@ -59,9 +59,9 @@
 
     // try each model option listed in config
-    psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE); 
-    for (int i = 0; i < models->n; i++) { 
-	psMetadataItem *item = psListGetAndIncrement (iter);
-	modelName = item->data.V;
-	models->data[i] = pmPSFtryModel (stars, modelName, RADIUS, POISSON_ERRORS);
+    psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE);
+    for (int i = 0; i < models->n; i++) {
+        psMetadataItem *item = psListGetAndIncrement (iter);
+        modelName = item->data.V;
+        models->data[i] = pmPSFtryModel (stars, modelName, RADIUS, POISSON_ERRORS);
     }
     psFree (iter);
@@ -75,12 +75,12 @@
     float bestM = try->psf->dApResid;
     for (int i = 1; i < models->n; i++) {
-	try = models->data[i];
-	float M = try->psf->dApResid;
-	if (M < bestM) {
-	    bestM = M;
-	    bestN = i;
-	}
+        try = models->data[i];
+        float M = try->psf->dApResid;
+        if (M < bestM) {
+            bestM = M;
+            bestN = i;
+        }
     }
-    
+
     // use the best model:
     try = models->data[bestN];
@@ -88,8 +88,8 @@
     // unset the PSFSTAR flag for stars not used for PSF model
     for (int i = 0; i < try->sources->n; i++) {
-	pmSource *source = try->sources->data[i];
-	if (try->mask->data.U8[i] & PSFTRY_MASK_EXT_FAIL) {
-	    source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
-	}
+        pmSource *source = try->sources->data[i];
+        if (try->mask->data.U8[i] & PSFTRY_MASK_EXT_FAIL) {
+            source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
+        }
     }
 
@@ -130,5 +130,5 @@
     // get the model full-width at half-max
     psF64 FWHM_X = 2*modelRadiusFunc (modelPSF->params, 0.5);
-    
+
     shape.sx  = modelPSF->params->data.F32[4];
     shape.sy  = modelPSF->params->data.F32[5];
@@ -141,5 +141,5 @@
     psMetadataAdd (recipe, PS_LIST_TAIL, "FWHM_Y", PS_DATA_F32 | PS_META_REPLACE, "PSF FWHM Minor axis", FWHM_Y);
     psMetadataAdd (recipe, PS_LIST_TAIL, "ANGLE",  PS_DATA_F32 | PS_META_REPLACE, "PSF angle",           axes.theta);
-    
+
     psFree (modelEXT);
     psFree (modelPSF);
@@ -150,31 +150,28 @@
 bool psphotMomentsStats (pmReadout *readout, psMetadata *recipe, psArray *sources) {
 
-    // without the PSF model, we can only rely on the source->moments 
+    // without the PSF model, we can only rely on the source->moments
     // as a measure of the FWHM values
 
-    double FWHM_X, FWHM_Y, FWHM_T;
-    int FWHM_N;
+    double FWHM_X = 0.0, FWHM_Y = 0.0, FWHM_T = 0.0;
+    int FWHM_N = 0;
 
     psEllipseMoments moments;
     psEllipseAxes axes;
 
-    FWHM_N = 0;
-    FWHM_X = FWHM_Y = 0.0;
+    for (int i = 0; i < sources->n; i++) {
+        pmSource *source = sources->data[i];
+        if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
 
-    for (int i = 0; i < sources->n; i++) {
-	pmSource *source = sources->data[i];
-	if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
-	
-	// moments->Sx,Sy are roughly sigma_x,y
-	moments.x2 = PS_SQR(source->moments->Sx);
-	moments.y2 = PS_SQR(source->moments->Sy);
-	moments.xy = source->moments->Sxy;
+        // moments->Sx,Sy are roughly sigma_x,y
+        moments.x2 = PS_SQR(source->moments->Sx);
+        moments.y2 = PS_SQR(source->moments->Sy);
+        moments.xy = source->moments->Sxy;
 
-	axes = psEllipseMomentsToAxes (moments);
+        axes = psEllipseMomentsToAxes (moments);
 
-	FWHM_X += axes.major * 2.35;
-	FWHM_Y += axes.minor * 2.35;
-	FWHM_T += axes.theta;
-	FWHM_N ++;
+        FWHM_X += axes.major * 2.35;
+        FWHM_Y += axes.minor * 2.35;
+        FWHM_T += axes.theta;
+        FWHM_N ++;
     }
 
@@ -186,5 +183,5 @@
     psMetadataAdd (recipe, PS_LIST_TAIL, "FWHM_Y", PS_DATA_F32 | PS_META_REPLACE, "PSF FWHM Minor axis", FWHM_Y);
     psMetadataAdd (recipe, PS_LIST_TAIL, "ANGLE",  PS_DATA_F32 | PS_META_REPLACE, "PSF angle",           FWHM_T);
-    
+
     return true;
 }
