Index: branches/czw_branch/20170908/psastro/src/psastroLoadGhosts.c
===================================================================
--- branches/czw_branch/20170908/psastro/src/psastroLoadGhosts.c	(revision 40179)
+++ branches/czw_branch/20170908/psastro/src/psastroLoadGhosts.c	(revision 40181)
@@ -267,5 +267,6 @@
     pmCell *cell = NULL;
     pmReadout *readout = NULL;
-    float zeropt, exptime, MAX_MAG;
+    //    float zeropt, exptime, MAX_MAG;
+    float MAX_MAG;
     psMetadata *ghostModel = NULL;
     psVector *C_terms;
@@ -305,11 +306,11 @@
 
     char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID");
-    psMetadataItem *item = psMetadataLookup(glintItem->data.md, "GLINT.FILTER.TERM");
+    psMetadataItem *item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC");
     if (!item) {
-      psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM data missing");
+      psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC data missing");
       return false;
     }
     if (item->type != PS_DATA_METADATA_MULTI) {
-      psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM not multi");
+      psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC not multi");
       return false;
     }
@@ -318,5 +319,5 @@
     while ((refItem = psListGetAndIncrement(iter))) {
       if (refItem->type != PS_DATA_METADATA) {
-	psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM entry not metadata");
+	psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC entry not metadata");
 	return false;
       }
@@ -369,11 +370,11 @@
                     pmAstromObj *ref = refstars->data[i];
 		    psTrace("psastro.ghost",5,"Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g) TPA: (%f %f)",
-			    i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI,ref->TP->x,ref->RP->y);
+			    i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI,ref->TP->x,ref->TP->y);
                     if (ref->Mag > MAX_MAG) continue;
 		    
 		    psastroGhost *ghost = psastroGhostAlloc ();
 
-		    double R_TPA  = sqrt(pow(star->TP->y,2) + pow(star->TP->x,2));
-		    double theta0 = atan2(star->TP->y,star->TP->x);
+		    double R_TPA  = sqrt(pow(ref->TP->y,2) + pow(ref->TP->x,2));
+		    double theta0 = atan2(ref->TP->y,ref->TP->x);
 		    double star_radius_deg = R_TPA * glintPixelScale;
 		    if (star_radius_deg > 0.5) { continue; }
@@ -418,5 +419,5 @@
 			      ghost->FP->x,ghost->FP->y,
 			      ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"),
-			      rSrc,
+			      C,
 			      ghost->inner.major,ghost->inner.minor,ghost->inner.theta,
 			      ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
