Index: /trunk/psastro/src/pmFPAReadSMP.c
===================================================================
--- /trunk/psastro/src/pmFPAReadSMP.c	(revision 6523)
+++ /trunk/psastro/src/pmFPAReadSMP.c	(revision 6523)
@@ -0,0 +1,134 @@
+
+typedef struct {
+    float x;
+    float y;
+    float fitMag;
+    float apMag;
+    float galMag;
+    float dMag;
+    float sky;
+    float Sx;
+    float Sy;
+    float Theta;
+} pmStar;
+
+// Given a FITS file pointer, read the table of object data 
+bool pmFPAviewReadSMP (pmFPAview *view, pmFPAfile *file) {
+
+    pmFPA *fpa = view->fpa;
+
+    if (view->chip == -1) {
+	pmFPARead (fpa, view, file);
+	return true;
+    }
+
+    if (view->chip >= fpa->chips->n) {
+	return false;
+    }
+    pmChip *chip = fpa->chips->data[view->chip];
+
+    if (view->cell == -1) {
+	pmChipRead (chip, view, file);
+	return true;
+    }
+		
+    if (view->cell >= chip->cells->n) {
+	return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+	pmCellRead (cell, view, file);
+	return true;
+    }
+		
+    if (view->readout >= cell->readouts->n) {
+	return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    pmReadoutReadSMP (readout, view, file);
+    return true;
+}
+
+// read in all chip-level SMP files for this FPA
+pmFPAReadSMP (pmFPA *fpa, pmFPAview *view, pmFPAfile *file) {
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+
+	pmChip *chip = fpa->data[i];
+	pmChipReadSMP (chip, view, file);
+    }
+    return true;
+}
+
+// read in all cell-level SMP files for this chip
+pmChipReadSMP (pmChip *chip, pmFPAview *view, pmFPAfile *file) {
+
+    for (int i = 0; i < chip->cells->n; i++) {
+
+	pmCell *cell = chip->data[i];
+	pmCellReadSMP (cell, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level SMP files for this cell
+pmCellReadSMP (pmCell *cell, pmFPAview *view, pmFPAfile *file) {
+
+    for (int i = 0; i < cell->readouts->n; i++) {
+
+	pmReadout *readout = cell->data[i];
+	pmReadoutReadSMP (readout, view, file);
+    }
+    return true;
+}
+
+// read in a readout from the fits file 
+pmReadoutReadSMP (pmReadout *readout, pmFPAview *view, pmFPAfile *file) {
+
+    psFits *fits = file->fits;
+
+    // there is one SMP header per cell and one SMP table per readout
+    psMetadata *header = pmReadoutGetHeader (readout);
+    if (header == NULL) {
+	// determine the extname for the HEAD
+	headname = pmConfigNameFromRule (file->extextra, camera, view);
+	psFitsMoveExtName(fits, headname);
+	psMetadata *header = psFitsReadHeader (NULL, fits);
+    }
+
+    // determine the extname for the HEAD
+    dataname = pmConfigNameFromRule (file->extname, camera, view);
+
+    // find config information for output header
+    float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT");
+
+    psFitsMoveExtName(fits, dataname);
+    psArray *table = psFitsReadTable (fits);
+
+    // validate a single row of the table (must match SMP)
+
+    psArray *sources = psArrayAlloc (table->n);
+
+    // convert the table to the pmSource entries
+    for (int i = 0; i < table->n; i++) {
+	pmStar *source = pmSourceAlloc ();
+	
+	psMetadata *row = table->data[i];
+
+	source->x      = psMetadataLookupF32 (&status, row, "X_PIX");
+	source->y      = psMetadataLookupF32 (&status, row, "Y_PIX");
+	source->fitMag = psMetadataLookupF32 (&status, row, "MAG_RAW") - ZERO_POINT;
+	source->galMag = psMetadataLookupF32 (&status, row, "MAG_GAL") - ZERO_POINT;
+	source->apMag  = psMetadataLookupF32 (&status, row, "MAG_AP")  - ZERO_POINT;
+	source->dMag   = psMetadataLookupF32 (&status, row, "MAG_ERR");
+	source->sky    = psMetadataLookupF32 (&status, row, "LOG_SKY");
+	source->sx     = psMetadataLookupF32 (&status, row, "FWHM_X"); 
+	source->sy     = psMetadataLookupF32 (&status, row, "FWHM_Y");
+	source->theta  = psMetadataLookupF32 (&status, row, "THETA");
+
+	sources->data[i] = source;
+    }
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources);
+}
