Index: trunk/psastro/src/psastroUtils.c
===================================================================
--- trunk/psastro/src/psastroUtils.c	(revision 5505)
+++ trunk/psastro/src/psastroUtils.c	(revision 5509)
@@ -69,19 +69,34 @@
 }
 
-psArray *psastroSelectBrightStars (psMetadata *config, psArray *stars) {
-
-    stars = psArraySort (stars, psastroSortByMag);
+psArray *psastroSelectBrightStars (pmFPA *inFPA, psMetadata *config) {
+
+    pmFPA *sbFPA = pmFPACopy (fpa);
 
     // add exclusions for objects on some basis?
     int MAX_NSTARS = pmMetadataLookupS32 (&status, config, "MAX_NSTARS");
 
-    nSubset = PS_MIN (MAX_NSTARS, stars->n);
-
-    psArray *subset = psArrayAlloc (nSubset);
-
-    for (int i = 0; i < nSubset; i++) {
-	subset->data[i] = stars->data[i];
-    }
-
+    for (int i = 0; i < inFPA->chips->n; i++) {
+	pmChip *inChip = inFPA->chips->data[i];
+	pmChip *sbChip = sbFPA->chips->data[i];
+	for (int j = 0; j < Ncells; j++) {
+	    pmCell *inCell = inChip->cells->data[j];
+o	    pmCell *sbCell = sbChip->cells->data[j];
+	    for (int k = 0; k < Nreadouts; k++) {
+		pmReadout *inReadout = inCell->readouts->data[k];
+		pmReadout *sbReadout = sbCell->readouts->data[k];
+
+		inReadout->stars = psArraySort (inReadout->stars, psastroSortByMag);
+
+		nSubset = PS_MIN (MAX_NSTARS, stars->n);
+
+		psArray *subset = psArrayAlloc (nSubset);
+
+		for (int i = 0; i < nSubset; i++) {
+		    subset->data[i] = inReadout->stars->data[i];
+		}
+		sbReadout->stars = subset;
+	    }
+	}
+    }
     return (subset);
 }
@@ -133,2 +148,94 @@
 }
 
+pmFPA *pmFPACopy (pmFPA *inFPA) {
+
+    pmFPA *fpa = pmFPAAlloc ();
+
+    fpa->toSky   = psMemCopy (inFPA->toSky);
+    fpa->toTPA   = psMemCopy (inFPA->toTPA);
+    fpa->fromTPA = psMemCopy (inFPA->fromTPA);
+
+    fpa->chips = psArrayAlloc (inFPA->chips->n);
+    for (int i = 0; i < inFPA->chips->n; i++) {
+
+	pmChip *inChip = inFPA->chips->data[i];
+
+	pmChip *chip = pmChipAlloc ();
+	chip->fpa = fpa; // assign parent fpa (view only; don't free)
+
+	chip->toFPA = psMemCopy (inChip->toFPA);
+	chip->fromFPA = psMemCopy (inChip->fromFPA);
+
+	chip->cells = psArrayAlloc (inChip->cells->n);
+	for (int j = 0; j < Ncells; j++) {
+
+	    pmCell *inCell = inChip->cells->data[j];
+
+	    pmCell *cell = pmCellAlloc ();
+	    cell->chip = chip;      // assign parent chip (view only; don't free)
+
+	    cell->header = psMemCopy (inCell->header);
+	    cell->toChip = psMemCopy (inCell->toChip);
+
+	    cell->readouts = psArrayAlloc (inCell);
+	    for (int k = 0; k < Nreadouts; k++) {
+
+		pmReadout *inReadout = inCell->readouts->data[k];
+
+		pmReadout *readout = pmReadoutAlloc ();
+
+		*readout = *inReadout;
+		readout->stars = NULL;
+		
+		cell->readouts->data[k] = readout;
+	    }
+	    chip->cells->data[j] = cell;
+	}
+	fpa->chips->data[i] = chip;
+    }
+    return (fpa);
+}
+
+bool psastroProjectRawstars (pmFPA *fpa) {
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+	pmChip *chip = fpa->chips->data[i];
+	for (int j = 0; j < chip->cells->n; j++) {
+	    pmCell *cell = chip->cells->data[j];
+	    for (int k = 0; k < cell->readouts->n; k++) {
+		pmReadout *readout = cell->readouts->data[k];
+		for (int m = 0; m < readout->stars->n; m++) {
+		    pmAstromObj *star = readout->data[m];
+		    // apply readout offsets
+		    // apply cell PlaneTransform
+		    // apply chip PlaneTransform
+		    psPlaneTransformApply (star-> 
+
+	    }
+	    chip->cells->data[j] = cell;
+	}
+	fpa->chips->data[i] = chip;
+    }
+    return (fpa);
+}
+ 
+bool psastroChipAstrom (psArray *refstars, pmFPA *subset) {
+
+    // do this loop over the readouts 
+
+    // find initial offset / rotation
+    stat = pmAstromGridMatch (subset, refstars, config);
+
+    pmAstromModifyFPA (fpa, stat);
+
+    // use fit result to re-project rawstars
+    psastroProjectRawstars (fpa, subset);
+    psastroProjectRefstars (fpa, refstars);
+    
+    // use small radius to match stars
+    match = pmAstromRadiusMatch (rawstars, refstars, options);
+
+    // fit astrometric terms
+    output = pmAstromMatchedListFit (fpa, subset, refstars, match, options);
+}
+
