Index: /branches/rel10_ifa/psModules/src/astrom/Makefile.am
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/Makefile.am	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/astrom/Makefile.am	(revision 6859)
@@ -18,4 +18,5 @@
 	pmConceptsWrite.c \
 	pmConceptsStandard.c \
+	pmFPA_JPEG.c \
 	pmFPAview.c \
 	pmFPAfile.c
@@ -41,4 +42,5 @@
 	pmConceptsWrite.h \
 	pmConceptsStandard.h \
+	pmFPA_JPEG.h \
 	pmFPAview.h \
 	pmFPAfile.h
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPA.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPA.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPA.c	(revision 6859)
@@ -12,6 +12,6 @@
 * XXX: Should we implement non-linear cell->chip transforms?
 *
-*  @version $Revision: 1.1.4.7 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-04-14 03:09:32 $
+*  @version $Revision: 1.1.4.8 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-04-14 21:43:59 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -512,8 +512,8 @@
 
 /*****************************************************************************
+XXX EAM : I've added the 'exclusive' option.  if true all other chips are de-selected
+XXX EAM : a negative value is valid and, in combinations with exclusive, de-selects all chips
  *****************************************************************************/
-bool pmFPASelectChip(
-    pmFPA *fpa,
-    int chipNum)
+bool pmFPASelectChip(pmFPA *fpa, int chipNum, bool exclusive)
 {
     PS_ASSERT_PTR_NON_NULL(fpa, false);
@@ -533,16 +533,21 @@
             setCellsProcess(tmpChip, true);
         } else {
-            tmpChip->process = false;
-            setCellsProcess(tmpChip, false);
-        }
-
-    }
-
-    return true;
-}
-
-bool pmChipSelectCell(pmChip *chip,
-                      int cellNum
-                     )
+            if (exclusive) {
+                tmpChip->process = false;
+                setCellsProcess(tmpChip, false);
+            }
+        }
+
+    }
+
+    return true;
+}
+
+/*****************************************************************************
+XXX EAM : I've added the 'exclusive' option.  if true all other chips are de-selected
+XXX EAM : a negative value is valid and, in combinations with exclusive, de-selects all cells
+XXX this function should probably be re-defined to merge with 'setCellsProcess'
+ *****************************************************************************/
+bool pmChipSelectCell(pmChip *chip, int cellNum, bool exclusive)
 {
     assert(chip);
@@ -558,7 +563,12 @@
             continue;
         }
-        cell->process = (i == cellNum);
-    }
-
+        if (i == cellNum) {
+            cell->process = true;
+        } else {
+            if (exclusive) {
+                cell->process = false;
+            }
+        }
+    }
     return true;
 }
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPA.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPA.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPA.h	(revision 6859)
@@ -7,6 +7,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.1.4.7 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-04-14 03:09:32 $
+*  @version $Revision: 1.1.4.8 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-04-14 21:43:59 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -244,9 +244,11 @@
 bool pmFPASelectChip(
     pmFPA *fpa,
-    int chipNum
+    int chipNum,
+    bool exclusive
 );
 
 bool pmChipSelectCell(pmChip *chip,
-                      int cellNum
+                      int cellNum,
+                      bool exclusive
                      );
 
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPA_JPEG.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPA_JPEG.c	(revision 6859)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPA_JPEG.c	(revision 6859)
@@ -0,0 +1,163 @@
+/** @file  pmFPA_JPEG.c
+ *
+ * This file contains functions to write JPEG images.
+ *
+ *  @author EAM, IfA
+ *
+ *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+/*****************************************************************************/
+/* INCLUDE FILES                                                             */
+/*****************************************************************************/
+
+#include <pslib.h>
+# include "psImageJpeg.h"
+# include "psImageUnbin.h"
+# include "psAdditionals.h"
+
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmFPAfile.h"
+#include "pmFPAview.h"
+#include "pmFPA_JPEG.h"
+
+
+bool pmFPAviewWriteJPEG (const pmFPAview *view, pmFPAfile *file)
+{
+
+    pmFPA *fpa = file->fpa;
+
+    if (view->chip == -1) {
+        pmFPAWriteJPEG (fpa, view, file);
+        return true;
+    }
+
+    if (view->chip >= fpa->chips->n) {
+        return false;
+    }
+    pmChip *chip = fpa->chips->data[view->chip];
+
+    if (view->cell == -1) {
+        pmChipWriteJPEG (chip, view, file);
+        return true;
+    }
+
+    if (view->cell >= chip->cells->n) {
+        return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        pmCellWriteJPEG (cell, view, file);
+        return true;
+    }
+
+    if (view->readout >= cell->readouts->n) {
+        return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    pmReadoutWriteJPEG (readout, view, file);
+    return true;
+}
+
+// read in all chip-level JPEG files for this FPA
+bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+
+        pmChip *chip = fpa->chips->data[i];
+        pmChipWriteJPEG (chip, view, file);
+    }
+    return true;
+}
+
+// read in all cell-level JPEG files for this chip
+bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < chip->cells->n; i++) {
+
+        pmCell *cell = chip->cells->data[i];
+        pmCellWriteJPEG (cell, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level JPEG files for this cell
+bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < cell->readouts->n; i++) {
+
+        pmReadout *readout = cell->readouts->data[i];
+        pmReadoutWriteJPEG (readout, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level Objects files for this cell
+bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
+{
+    char *name, *mode, *word, *mapname;
+    psArray *range;
+    psImageJpegColormap *map;
+
+    switch (file->type) {
+    case PM_FPA_FILE_JPEG:
+
+        name = pmFPAfileNameFromRule (file->filerule, file, view);
+
+        mapname = pmFPAfileNameFromRule (file->filextra, file, view);
+        map = psImageJpegColormapSet (NULL, mapname);
+        if (!map) {
+            map = psImageJpegColormapSet (NULL, "-greyscale");
+        }
+
+        mode = pmFPAfileNameFromRule (file->extrule, file, view);
+        word = pmFPAfileNameFromRule (file->extxtra, file, view);
+        range = psStringSplitArray (word, ":");
+
+        // XXX we need to decide where the scale will come from in the long term
+        psImageClippedStatsInit (10000);
+
+        psStats *stats = psImageClippedStats (readout->image, NULL, 0, 0.25, 0.75);
+        float delta = stats->robustUQ - stats->robustLQ;
+        float min = stats->robustMedian - 3*delta;
+        float max = stats->robustMedian - 6*delta;
+        if (!strcasecmp (mode, "RANGE") && range) {
+            float fmin = atof(range->data[0]);
+            float fmax = atof(range->data[1]);
+            min = stats->robustMedian + fmin*delta;
+            max = stats->robustMedian + fmax*delta;
+        }
+        if (!strcasecmp (mode, "FRACTION")) {
+            float fmin = atof(range->data[0]);
+            float fmax = atof(range->data[1]);
+            min = fmin*stats->robustMedian;
+            max = fmax*stats->robustMedian;
+        }
+        psImageJpeg (map, readout->image, name, min, max);
+
+        psFree (name);
+        psFree (mode);
+        psFree (word);
+        psFree (mapname);
+        psFree (map);
+        psFree (stats);
+        psImageClippedStatsCleanup ();
+
+        return true;
+
+    default:
+        fprintf (stderr, "warning: type mismatch\n");
+        break;
+    }
+    return false;
+}
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPA_JPEG.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPA_JPEG.h	(revision 6859)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPA_JPEG.h	(revision 6859)
@@ -0,0 +1,27 @@
+/** @file  pmFPAview.h
+*
+*  @brief Tools to manipulate the FPA structure elements.
+*
+*  @ingroup AstroImage
+*
+*  @author EAM, IfA
+*
+*  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-04-14 21:43:59 $
+*
+*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
+*/
+
+#ifndef PM_FPA_JPEG_H
+#define PM_FPA_JPEG_H
+
+/// @addtogroup AstroImage
+/// @{
+
+bool pmFPAviewWriteJPEG (const pmFPAview *view, pmFPAfile *file);
+bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
+bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
+bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
+bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
+
+# endif
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6859)
@@ -11,5 +11,13 @@
 #include "pmFPARead.h"
 #include "pmFPAWrite.h"
-#include "pmFPAviewObjectsIO.h"
+#include "pmPeaks.h"
+#include "pmMoments.h"
+#include "pmModel.h"
+#include "pmSource.h"
+#include "pmSourceIO.h"
+#include "pmGrowthCurve.h"
+#include "pmPSF.h"
+#include "pmPSF_IO.h"
+#include "pmFPA_JPEG.h"
 
 static void pmFPAfileFree (pmFPAfile *file)
@@ -173,4 +181,10 @@
         if (!strcasecmp (type, "IMAGE"))     {
             file->type = PM_FPA_FILE_IMAGE;
+        }
+        if (!strcasecmp (type, "PSF"))     {
+            file->type = PM_FPA_FILE_PSF;
+        }
+        if (!strcasecmp (type, "JPEG"))     {
+            file->type = PM_FPA_FILE_JPEG;
         }
     }
@@ -294,4 +308,6 @@
     case PM_FPA_FILE_CMP:
     case PM_FPA_FILE_RAW:
+    case PM_FPA_FILE_PSF:
+    case PM_FPA_FILE_JPEG:
         psTrace ("pmFPAfile", 5, "not opening %s (type: %d)\n", file->filename, file->type);
         break;
@@ -339,4 +355,12 @@
         break;
 
+    case PM_FPA_FILE_PSF:
+        pmFPAviewReadPSFmodel (view, file);
+        psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
+        break;
+
+    case PM_FPA_FILE_JPEG:
+        break;
+
     default:
         fprintf (stderr, "warning: type mismatch\n");
@@ -378,4 +402,14 @@
         break;
 
+    case PM_FPA_FILE_PSF:
+        pmFPAviewWritePSFmodel (view, file);
+        psTrace ("pmFPAfile", 5, "wrote PSF %s (fpa: %p)\n", file->filename, file->fpa);
+        break;
+
+    case PM_FPA_FILE_JPEG:
+        pmFPAviewWriteJPEG (view, file);
+        psTrace ("pmFPAfile", 5, "wrote PSF %s (fpa: %p)\n", file->filename, file->fpa);
+        break;
+
     default:
         fprintf (stderr, "warning: type mismatch\n");
@@ -414,4 +448,6 @@
     case PM_FPA_FILE_CMP:
     case PM_FPA_FILE_CMF:
+    case PM_FPA_FILE_PSF:
+    case PM_FPA_FILE_JPEG:
         break;
 
@@ -453,4 +489,6 @@
     case PM_FPA_FILE_OBJ:
     case PM_FPA_FILE_CMP:
+    case PM_FPA_FILE_PSF:
+    case PM_FPA_FILE_JPEG:
         break;
 
@@ -775,4 +813,5 @@
     // load the given filerule (from config->camera) and associate it with the fpa
     // the output file is just a view to the file on config->files
+    // XXX the filenames placed on config->files should include the seq number
     file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
     if (!file) {
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h	(revision 6859)
@@ -7,6 +7,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.1.2.11 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-04-13 06:17:28 $
+*  @version $Revision: 1.1.2.12 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-04-14 21:43:59 $
 *
 *  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
@@ -34,4 +34,6 @@
     PM_FPA_FILE_RAW,
     PM_FPA_FILE_IMAGE,
+    PM_FPA_FILE_PSF,
+    PM_FPA_FILE_JPEG,
 } pmFPAfileType;
 
Index: /branches/rel10_ifa/psModules/src/objects/Makefile.am
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/Makefile.am	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/Makefile.am	(revision 6859)
@@ -20,8 +20,7 @@
      pmSourceIO_RAW.c \
      pmPSF.c \
+     pmPSF_IO.c \
      pmPSFtry.c \
-     pmGrowthCurve.c \
-     pmFPAviewReadObjects.c \
-     pmFPAviewWriteObjects.c
+     pmGrowthCurve.c
 
 EXTRA_DIST = \
@@ -44,5 +43,5 @@
      pmSourceIO.h \
      pmPSF.h \
+     pmPSF_IO.h \
      pmPSFtry.h \
-     pmGrowthCurve.h \
-     pmFPAviewObjectsIO.h
+     pmGrowthCurve.h
Index: anches/rel10_ifa/psModules/src/objects/pmFPAviewObjectsIO.h
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmFPAviewObjectsIO.h	(revision 6858)
+++ 	(revision )
@@ -1,27 +1,0 @@
-/** @file  pmFPAviewObjectsIO.h
- *
- *  @author EAM, IfA
- *
- *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-29 20:55:42 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- *
- */
-
-# ifndef PM_FPA_OBJECTS_IO_H
-# define PM_FPA_OBJECTS_IO_H
-
-bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file);
-bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
-bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
-bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
-bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
-
-bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file);
-bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
-bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
-bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
-bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
-
-# endif /* PM_FPA_OBJECTS_IO_H */
Index: anches/rel10_ifa/psModules/src/objects/pmFPAviewReadObjects.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmFPAviewReadObjects.c	(revision 6858)
+++ 	(revision )
@@ -1,159 +1,0 @@
-/** @file  pmSourcePhotometry.c
- *
- *  @author EAM, IfA; GLG, MHPCC
- *
- *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-29 20:55:42 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- *
- */
-
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include "pslib.h"
-#include "pmHDU.h"
-#include "pmFPA.h"
-#include "pmFPAview.h"
-#include "pmFPAfile.h"
-
-#include "pmPeaks.h"
-#include "pmMoments.h"
-#include "pmModel.h"
-#include "pmSource.h"
-
-#include "pmSourceIO.h"
-#include "pmFPAviewObjectsIO.h"
-
-// Given a FITS file pointer, read the table of object data
-bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file)
-{
-    pmFPA *fpa = file->fpa;
-
-    if (view->chip == -1) {
-        pmFPAReadObjects (fpa, view, file);
-        return true;
-    }
-
-    if (view->chip >= fpa->chips->n) {
-        return false;
-    }
-    pmChip *chip = fpa->chips->data[view->chip];
-
-    if (view->cell == -1) {
-        pmChipReadObjects (chip, view, file);
-        return true;
-    }
-
-    if (view->cell >= chip->cells->n) {
-        return false;
-    }
-    pmCell *cell = chip->cells->data[view->cell];
-
-    if (view->readout == -1) {
-        pmCellReadObjects (cell, view, file);
-        return true;
-    }
-
-    if (view->readout >= cell->readouts->n) {
-        return false;
-    }
-    pmReadout *readout = cell->readouts->data[view->readout];
-
-    pmReadoutReadObjects (readout, view, file);
-    return true;
-}
-
-// read in all chip-level Objects files for this FPA
-bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
-{
-
-    for (int i = 0; i < fpa->chips->n; i++) {
-
-        pmChip *chip = fpa->chips->data[i];
-        pmChipReadObjects (chip, view, file);
-    }
-    return true;
-}
-
-// read in all cell-level Objects files for this chip
-bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
-{
-
-    for (int i = 0; i < chip->cells->n; i++) {
-
-        pmCell *cell = chip->cells->data[i];
-        pmCellReadObjects (cell, view, file);
-    }
-    return true;
-}
-
-// read in all readout-level Objects files for this cell
-bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
-{
-
-    for (int i = 0; i < cell->readouts->n; i++) {
-
-        pmReadout *readout = cell->readouts->data[i];
-        pmReadoutReadObjects (readout, view, file);
-    }
-    return true;
-}
-
-// read in all readout-level Objects files for this cell
-bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
-{
-
-    bool status;
-    psArray *sources;
-    pmHDU *hdu;
-
-    switch (file->type) {
-    case PM_FPA_FILE_OBJ:
-        fprintf (stderr, "warning: OBJ is not supported as an input object format\n");
-        break;
-
-    case PM_FPA_FILE_SX:
-        fprintf (stderr, "warning: SX is not supported as an input object format\n");
-        break;
-
-    case PM_FPA_FILE_CMP:
-        // a SPLIT format : only one header and object table per file
-
-        // read in header, if not yet loaded
-        hdu = pmFPAviewThisHDU (view, file->fpa);
-
-        char *filename = pmFPAfileNameFromRule (file->filerule, file, view);
-        file->fits = psFitsOpen (filename, "r");
-        hdu->header = psFitsReadHeader (NULL, file->fits);
-        psFitsClose (file->fits);
-        sources  = pmSourcesReadCMP (filename, hdu->header);
-        psFree (filename);
-        break;
-
-    case PM_FPA_FILE_CMF:
-        // read in header, if not yet loaded
-        hdu = pmFPAviewThisHDU (view, file->fpa);
-        if (hdu->header == NULL) {
-            char *headname = pmFPAfileNameFromRule (file->extxtra, file, view);
-            psFitsMoveExtName (file->fits, headname);
-            hdu->header = psFitsReadHeader (NULL, file->fits);
-            psFree (headname);
-        }
-
-        char *dataname = pmFPAfileNameFromRule (file->extrule, file, view);
-        psFitsMoveExtName (file->fits, dataname);
-        sources  = pmSourcesReadCMF (file->fits, hdu->header);
-        psFree (dataname);
-        break;
-
-    default:
-        fprintf (stderr, "warning: type mismatch\n");
-        break;
-    }
-    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources);
-    return true;
-}
-
-
Index: anches/rel10_ifa/psModules/src/objects/pmFPAviewWriteObjects.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmFPAviewWriteObjects.c	(revision 6858)
+++ 	(revision )
@@ -1,218 +1,0 @@
-/** @file  pmSourcePhotometry.c
- *
- *  @author EAM, IfA; GLG, MHPCC
- *
- *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-29 20:55:42 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- *
- */
-
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include "pslib.h"
-#include "psAdditionals.h"
-#include "pmHDU.h"
-#include "pmFPA.h"
-#include "pmFPAview.h"
-#include "pmFPAfile.h"
-
-#include "pmPeaks.h"
-#include "pmMoments.h"
-#include "pmModel.h"
-#include "pmSource.h"
-
-#include "pmSourceIO.h"
-#include "pmFPAviewObjectsIO.h"
-
-// Given a FITS file pointer, read the table of object data
-bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file)
-{
-
-    pmFPA *fpa = file->fpa;
-
-    if (view->chip == -1) {
-        pmFPAWriteObjects (fpa, view, file);
-        return true;
-    }
-
-    if (view->chip >= fpa->chips->n) {
-        return false;
-    }
-    pmChip *chip = fpa->chips->data[view->chip];
-
-    if (view->cell == -1) {
-        pmChipWriteObjects (chip, view, file);
-        return true;
-    }
-
-    if (view->cell >= chip->cells->n) {
-        return false;
-    }
-    pmCell *cell = chip->cells->data[view->cell];
-
-    if (view->readout == -1) {
-        pmCellWriteObjects (cell, view, file);
-        return true;
-    }
-
-    if (view->readout >= cell->readouts->n) {
-        return false;
-    }
-    pmReadout *readout = cell->readouts->data[view->readout];
-
-    pmReadoutWriteObjects (readout, view, file);
-    return true;
-}
-
-// read in all chip-level Objects files for this FPA
-bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
-{
-
-    for (int i = 0; i < fpa->chips->n; i++) {
-
-        pmChip *chip = fpa->chips->data[i];
-        pmChipWriteObjects (chip, view, file);
-    }
-    return true;
-}
-
-// read in all cell-level Objects files for this chip
-bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
-{
-
-    for (int i = 0; i < chip->cells->n; i++) {
-
-        pmCell *cell = chip->cells->data[i];
-        pmCellWriteObjects (cell, view, file);
-    }
-    return true;
-}
-
-// read in all readout-level Objects files for this cell
-bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
-{
-
-    for (int i = 0; i < cell->readouts->n; i++) {
-
-        pmReadout *readout = cell->readouts->data[i];
-        pmReadoutWriteObjects (readout, view, file);
-    }
-    return true;
-}
-
-// read in all readout-level Objects files for this cell
-bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
-{
-
-    bool status;
-    char *filename;
-    char *dataname;
-    char *headname;
-    pmHDU *hdu;
-    pmHDU *phu;
-    psMetadata *updates;
-    psMetadata *outhead;
-
-    psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
-
-    switch (file->type) {
-    case PM_FPA_FILE_RAW:
-        filename = pmFPAfileNameFromRule (file->filerule, file, view);
-        pmSourcesWriteRAW (sources, filename);
-        psFree (filename);
-        break;
-
-    case PM_FPA_FILE_OBJ:
-        filename = pmFPAfileNameFromRule (file->filerule, file, view);
-        pmSourcesWriteOBJ (sources, filename);
-        psFree (filename);
-        break;
-
-    case PM_FPA_FILE_SX:
-        filename = pmFPAfileNameFromRule (file->filerule, file, view);
-        pmSourcesWriteSX (sources, filename);
-        psFree (filename);
-        break;
-
-    case PM_FPA_FILE_CMP:
-        // a SPLIT format : only one header and object table per file
-        hdu = pmFPAviewThisHDU (view, file->fpa);
-        filename = pmFPAfileNameFromRule (file->filerule, file, view);
-
-        // copy the header to an output header, add the output header data
-        outhead = psMetadataCopy (NULL, hdu->header);
-
-        // check/fix first line (must be SIMPLE = F)
-        psMetadataItem *item = psMetadataGet (outhead, PS_LIST_HEAD);
-        if (strcmp (item->name, "SIMPLE") && strcmp (item->name, "XTENSION")) {
-            psErrorStackPrint(stderr, "invalid header: first line is neither SIMPLE nor XTENSION\n");
-            exit(EXIT_FAILURE);
-        }
-        if (!strcmp (item->name, "XTENSION")) {
-            psMetadataRemoveIndex (outhead, PS_LIST_HEAD);
-        }
-        psMetadataAddBool (outhead, PS_LIST_HEAD, "SIMPLE", PS_META_REPLACE, "CMP file, not simple", false);
-
-        // copy over the entries saved in the
-        updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
-        psMetadataCopy (outhead, updates);
-
-        pmSourcesWriteCMP (sources, filename, outhead);
-        psFree (outhead);
-        psFree (filename);
-        break;
-
-    case PM_FPA_FILE_CMF:
-        // write a PHU?
-        // write a header?
-        // write the data
-
-        // get the current header
-        hdu = pmFPAviewThisHDU (view, file->fpa);
-
-        // if file does not yet have a PHU, write it to disk
-        if (file->phu == NULL) {
-            // get the corresponding phu
-            phu = pmFPAviewThisPHU (view, file->fpa);
-
-            // CMF always has extensions
-            outhead = psMetadataCopy (NULL, phu->header);
-            psMetadataAdd (outhead, PS_LIST_TAIL, "EXTEND", PS_DATA_BOOL | PS_META_REPLACE, "this file has extensions", true);
-            psFitsWriteHeaderNotImage (file->fits, outhead);
-            file->phu = phu->header;
-            psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
-            psFree (outhead);
-        }
-
-        // this this header block is new, write it to disk,
-        if (hdu->header != file->header) {
-            // determine name for header extension
-            headname = pmFPAfileNameFromRule (file->extxtra, file, view);
-            outhead = psMetadataCopy (NULL, hdu->header);
-            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "extension name", headname);
-            psFitsWriteHeaderNotImage (file->fits, outhead);
-            psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type);
-            file->header = hdu->header;
-            psFree (outhead);
-            psFree (headname);
-        }
-
-        // write this table to disk
-        dataname = pmFPAfileNameFromRule (file->extrule, file, view);
-        updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
-        pmSourcesWriteCMF (file->fits, sources, updates, dataname);
-        psTrace ("pmFPAfile", 5, "wrote ext data %s (type: %d)\n", file->filename, file->type);
-        psFree (dataname);
-        break;
-
-    default:
-        fprintf (stderr, "warning: type mismatch\n");
-        break;
-    }
-    return true;
-}
-
-// a MEF CMF file has: PHU, CELL-HEAD, TABLE, CELL-HEAD, TABLE, TABLE, TABLE...
Index: /branches/rel10_ifa/psModules/src/objects/pmPSF.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmPSF.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmPSF.c	(revision 6859)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.4.4.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-13 06:18:46 $
+ *  @version $Revision: 1.4.4.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -309,76 +309,2 @@
     return false;
 }
-
-psMetadata *pmPSFtoMD (psMetadata *metadata, pmPSF *psf)
-{
-
-    if (metadata == NULL) {
-        metadata = psMetadataAlloc ();
-    }
-
-    char *modelName = pmModelGetType (psf->type);
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName);
-
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_POISSON_ERRORS", PS_DATA_BOOL, "Poisson errors for fits", psf->poissonErrors);
-
-    int nPar = pmModelParameterCount (psf->type)    ;
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
-
-    for (int i = 0; i < nPar - 4; i++) {
-        psPolynomial2D *poly = psf->params->data[i];
-        psPolynomial2DtoMD (metadata, poly, "PSF_PAR%02d", i);
-    }
-    psPolynomial4DtoMD (metadata, psf->ApTrend, "APTREND");
-
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_AP_RESID", PS_DATA_F32, "aperture residual", psf->ApResid);
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_dAP_RESID", PS_DATA_F32, "aperture residual scatter", psf->dApResid);
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_SKY_BIAS", PS_DATA_F32, "sky bias level", psf->skyBias);
-
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_CHISQ", PS_DATA_F32, "chi-square for fit", psf->chisq);
-    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_NSTARS", PS_DATA_S32, "number of stars used to measure PSF", psf->nPSFstars);
-
-    return metadata;
-}
-
-pmPSF *pmPSFfromMD (psMetadata *metadata)
-{
-
-    bool status;
-    char keyword[80];
-
-    char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME");
-    pmModelType type = pmModelSetType (modelName);
-
-    bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS");
-    if (!status)
-        poissonErrors = true;
-
-    pmPSF *psf = pmPSFAlloc (type, poissonErrors);
-
-    int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR");
-    if (nPar != pmModelParameterCount (psf->type))
-        psAbort ("read PSF" , "mismatch model par count");
-
-    for (int i = 0; i < nPar - 4; i++) {
-        sprintf (keyword, "PSF_PAR%02d", i);
-        psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
-        psPolynomial2D *poly = psPolynomial2DfromMD (folder);
-        psFree (psf->params->data[i]);
-        psf->params->data[i] = poly;
-    }
-    sprintf (keyword, "APTREND");
-    psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
-    psPolynomial4D *poly = psPolynomial4DfromMD (folder);
-    psFree (psf->ApTrend);
-    psf->ApTrend = poly;
-
-    psf->ApResid = psMetadataLookupF32 (&status, metadata, "PSF_AP_RESID");
-    psf->dApResid = psMetadataLookupF32 (&status, metadata, "PSF_dAP_RESID");
-    psf->skyBias = psMetadataLookupF32 (&status, metadata, "PSF_SKY_BIAS");
-
-    psf->chisq = psMetadataLookupF32 (&status, metadata, "PSF_CHISQ");
-    psf->nPSFstars = psMetadataLookupS32 (&status, metadata, "PSF_NSTARS");
-
-    psFree (metadata);
-    return (psf);
-}
Index: /branches/rel10_ifa/psModules/src/objects/pmPSF.h
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmPSF.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmPSF.h	(revision 6859)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.22.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-13 06:18:46 $
+ *  @version $Revision: 1.1.22.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -103,6 +103,4 @@
 
 bool pmPSF_MaskApTrend (pmPSF *psf, pmPSF_ApTrendOptions option);
-psMetadata *pmPSFtoMD (psMetadata *metadata, pmPSF *psf);
-pmPSF *pmPSFfromMD (psMetadata *metadata);
 
 # endif
Index: /branches/rel10_ifa/psModules/src/objects/pmPSF_IO.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmPSF_IO.c	(revision 6859)
+++ /branches/rel10_ifa/psModules/src/objects/pmPSF_IO.c	(revision 6859)
@@ -0,0 +1,312 @@
+/** @file  pmPSF_IO.c
+ *
+ * This file contains functions to read and write PSF models using the psMetadata Config file
+ * format.
+ *
+ *  @author EAM, IfA
+ *
+ *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+/*****************************************************************************/
+/* INCLUDE FILES                                                             */
+/*****************************************************************************/
+
+#include <pslib.h>
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmFPAfile.h"
+#include "pmFPAfile.h"
+
+#include "pmPeaks.h"
+#include "pmMoments.h"
+#include "pmGrowthCurve.h"
+#include "pmModel.h"
+#include "pmPSF.h"
+#include "pmPSF_IO.h"
+#include "pmSource.h"
+#include "pmModelGroup.h"
+#include "pmSourceIO.h"
+
+psMetadata *pmPSFtoMD (psMetadata *metadata, pmPSF *psf)
+{
+
+    if (metadata == NULL) {
+        metadata = psMetadataAlloc ();
+    }
+
+    char *modelName = pmModelGetType (psf->type);
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NAME", PS_DATA_STRING, "PSF model name", modelName);
+
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_POISSON_ERRORS", PS_DATA_BOOL, "Poisson errors for fits", psf->poissonErrors);
+
+    int nPar = pmModelParameterCount (psf->type)    ;
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_MODEL_NPAR", PS_DATA_S32, "PSF model parameter count", nPar);
+
+    for (int i = 0; i < nPar - 4; i++) {
+        psPolynomial2D *poly = psf->params->data[i];
+        psPolynomial2DtoMD (metadata, poly, "PSF_PAR%02d", i);
+    }
+    psPolynomial4DtoMD (metadata, psf->ApTrend, "APTREND");
+
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_AP_RESID", PS_DATA_F32, "aperture residual", psf->ApResid);
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_dAP_RESID", PS_DATA_F32, "aperture residual scatter", psf->dApResid);
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_SKY_BIAS", PS_DATA_F32, "sky bias level", psf->skyBias);
+
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_CHISQ", PS_DATA_F32, "chi-square for fit", psf->chisq);
+    psMetadataAdd (metadata, PS_LIST_TAIL, "PSF_NSTARS", PS_DATA_S32, "number of stars used to measure PSF", psf->nPSFstars);
+
+    return metadata;
+}
+
+pmPSF *pmPSFfromMD (psMetadata *metadata)
+{
+
+    bool status;
+    char keyword[80];
+
+    char *modelName = psMetadataLookupPtr (&status, metadata, "PSF_MODEL_NAME");
+    pmModelType type = pmModelSetType (modelName);
+
+    bool poissonErrors = psMetadataLookupPtr (&status, metadata, "PSF_POISSON_ERRORS");
+    if (!status)
+        poissonErrors = true;
+
+    pmPSF *psf = pmPSFAlloc (type, poissonErrors);
+
+    int nPar = psMetadataLookupS32 (&status, metadata, "PSF_MODEL_NPAR");
+    if (nPar != pmModelParameterCount (psf->type))
+        psAbort ("read PSF" , "mismatch model par count");
+
+    for (int i = 0; i < nPar - 4; i++) {
+        sprintf (keyword, "PSF_PAR%02d", i);
+        psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
+        psPolynomial2D *poly = psPolynomial2DfromMD (folder);
+        psFree (psf->params->data[i]);
+        psf->params->data[i] = poly;
+    }
+    sprintf (keyword, "APTREND");
+    psMetadata *folder = psMetadataLookupPtr (&status, metadata, keyword);
+    psPolynomial4D *poly = psPolynomial4DfromMD (folder);
+    psFree (psf->ApTrend);
+    psf->ApTrend = poly;
+
+    psf->ApResid = psMetadataLookupF32 (&status, metadata, "PSF_AP_RESID");
+    psf->dApResid = psMetadataLookupF32 (&status, metadata, "PSF_dAP_RESID");
+    psf->skyBias = psMetadataLookupF32 (&status, metadata, "PSF_SKY_BIAS");
+
+    psf->chisq = psMetadataLookupF32 (&status, metadata, "PSF_CHISQ");
+    psf->nPSFstars = psMetadataLookupS32 (&status, metadata, "PSF_NSTARS");
+
+    psFree (metadata);
+    return (psf);
+}
+
+bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file)
+{
+
+    pmFPA *fpa = file->fpa;
+
+    if (view->chip == -1) {
+        pmFPAWritePSFmodel (fpa, view, file);
+        return true;
+    }
+
+    if (view->chip >= fpa->chips->n) {
+        return false;
+    }
+    pmChip *chip = fpa->chips->data[view->chip];
+
+    if (view->cell == -1) {
+        pmChipWritePSFmodel (chip, view, file);
+        return true;
+    }
+
+    if (view->cell >= chip->cells->n) {
+        return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        pmCellWritePSFmodel (cell, view, file);
+        return true;
+    }
+
+    if (view->readout >= cell->readouts->n) {
+        return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    pmReadoutWritePSFmodel (readout, view, file);
+    return true;
+}
+
+// read in all chip-level PSFmodel files for this FPA
+bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+
+        pmChip *chip = fpa->chips->data[i];
+        pmChipWritePSFmodel (chip, view, file);
+    }
+    return true;
+}
+
+// read in all cell-level PSFmodel files for this chip
+bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < chip->cells->n; i++) {
+
+        pmCell *cell = chip->cells->data[i];
+        pmCellWritePSFmodel (cell, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level PSFmodel files for this cell
+bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < cell->readouts->n; i++) {
+
+        pmReadout *readout = cell->readouts->data[i];
+        pmReadoutWritePSFmodel (readout, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level Objects files for this cell
+bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
+{
+    bool status;
+    char *filename;
+
+    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
+
+    switch (file->type) {
+    case PM_FPA_FILE_PSF:
+        filename = pmFPAfileNameFromRule (file->filerule, file, view);
+        psMetadata *psfData = pmPSFtoMD (NULL, psf);
+        psMetadataConfigWrite (psfData, filename);
+        psFree (psfData);
+        psFree (filename);
+        return true;
+
+    default:
+        fprintf (stderr, "warning: type mismatch\n");
+        break;
+    }
+    return false;
+}
+
+
+
+bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file)
+{
+
+    pmFPA *fpa = file->fpa;
+
+    if (view->chip == -1) {
+        pmFPAReadPSFmodel (fpa, view, file);
+        return true;
+    }
+
+    if (view->chip >= fpa->chips->n) {
+        return false;
+    }
+    pmChip *chip = fpa->chips->data[view->chip];
+
+    if (view->cell == -1) {
+        pmChipReadPSFmodel (chip, view, file);
+        return true;
+    }
+
+    if (view->cell >= chip->cells->n) {
+        return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        pmCellReadPSFmodel (cell, view, file);
+        return true;
+    }
+
+    if (view->readout >= cell->readouts->n) {
+        return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    pmReadoutReadPSFmodel (readout, view, file);
+    return true;
+}
+
+// read in all chip-level PSFmodel files for this FPA
+bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+
+        pmChip *chip = fpa->chips->data[i];
+        pmChipReadPSFmodel (chip, view, file);
+    }
+    return true;
+}
+
+// read in all cell-level PSFmodel files for this chip
+bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < chip->cells->n; i++) {
+
+        pmCell *cell = chip->cells->data[i];
+        pmCellReadPSFmodel (cell, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level PSFmodel files for this cell
+bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < cell->readouts->n; i++) {
+
+        pmReadout *readout = cell->readouts->data[i];
+        pmReadoutReadPSFmodel (readout, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level Objects files for this cell
+bool pmReadoutReadPSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
+{
+
+    int Nfail;
+    char *filename;
+
+    switch (file->type) {
+    case PM_FPA_FILE_PSF:
+        filename = pmFPAfileNameFromRule (file->filerule, file, view);
+
+        psMetadata *psfData = psMetadataConfigParse (NULL, &Nfail, filename, FALSE);
+        pmPSF *psf = pmPSFfromMD (psfData);
+        psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf);
+
+        psFree (psf);
+        psFree (psfData);
+        psFree (filename);
+
+        return true;
+
+    default:
+        fprintf (stderr, "warning: type mismatch\n");
+        break;
+    }
+    return false;
+}
+
Index: /branches/rel10_ifa/psModules/src/objects/pmPSF_IO.h
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmPSF_IO.h	(revision 6859)
+++ /branches/rel10_ifa/psModules/src/objects/pmPSF_IO.h	(revision 6859)
@@ -0,0 +1,32 @@
+/** @file  pmPSF.h
+ *
+ * This file contains typedefs for the Point-Spread Function and prototypes
+ * for functions that calculate the PSF.
+ *
+ *  @author EAM, IfA
+ *
+ *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ *
+ */
+
+# ifndef PM_PSF_IO_H
+# define PM_PSF_IO_H
+
+psMetadata *pmPSFtoMD (psMetadata *metadata, pmPSF *psf);
+pmPSF *pmPSFfromMD (psMetadata *metadata);
+bool pmFPAviewWritePSFmodel (const pmFPAview *view, pmFPAfile *file);
+bool pmFPAWritePSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
+bool pmChipWritePSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
+bool pmCellWritePSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
+bool pmReadoutWritePSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
+
+bool pmFPAviewReadPSFmodel (const pmFPAview *view, pmFPAfile *file);
+bool pmFPAReadPSFmodel (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
+bool pmChipReadPSFmodel (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
+bool pmCellReadPSFmodel (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
+bool pmReadoutReadPSFmodel (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
+
+# endif
Index: /branches/rel10_ifa/psModules/src/objects/pmSource.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSource.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSource.c	(revision 6859)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-09 03:14:23 $
+ *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -57,4 +57,10 @@
     tmp->mode = PM_SOURCE_MODE_DEFAULT;
     psMemSetDeallocator(tmp, (psFreeFunc) sourceFree);
+
+    tmp->psfMag = 32.0;
+    tmp->extMag = 32.0;
+    tmp->errMag = 32.0;
+    tmp->apMag  = 32.0;
+    tmp->pixWeight = 0.0;
 
     psTrace(__func__, 3, "---- %s() end ----\n", __func__);
Index: /branches/rel10_ifa/psModules/src/objects/pmSource.h
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSource.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSource.h	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-09 03:14:23 $
+ *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -85,4 +85,5 @@
     float errMag;
     float apMag;
+    float pixWeight;   // model-weighted coverage of valid pixels
     psRegion region;   // area on image covered by selected pixels
 }
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO.c	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-28 02:14:56 $
+ *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -14,6 +14,10 @@
 #include <string.h>
 #include "pslib.h"
+#include "psAdditionals.h"
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+
 #include "pmPeaks.h"
 #include "pmMoments.h"
@@ -53,2 +57,322 @@
 }
 
+// Given a FITS file pointer, read the table of object data
+bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file)
+{
+
+    pmFPA *fpa = file->fpa;
+
+    if (view->chip == -1) {
+        pmFPAWriteObjects (fpa, view, file);
+        return true;
+    }
+
+    if (view->chip >= fpa->chips->n) {
+        return false;
+    }
+    pmChip *chip = fpa->chips->data[view->chip];
+
+    if (view->cell == -1) {
+        pmChipWriteObjects (chip, view, file);
+        return true;
+    }
+
+    if (view->cell >= chip->cells->n) {
+        return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        pmCellWriteObjects (cell, view, file);
+        return true;
+    }
+
+    if (view->readout >= cell->readouts->n) {
+        return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    pmReadoutWriteObjects (readout, view, file);
+    return true;
+}
+
+// read in all chip-level Objects files for this FPA
+bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+
+        pmChip *chip = fpa->chips->data[i];
+        pmChipWriteObjects (chip, view, file);
+    }
+    return true;
+}
+
+// read in all cell-level Objects files for this chip
+bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < chip->cells->n; i++) {
+
+        pmCell *cell = chip->cells->data[i];
+        pmCellWriteObjects (cell, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level Objects files for this cell
+bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < cell->readouts->n; i++) {
+
+        pmReadout *readout = cell->readouts->data[i];
+        pmReadoutWriteObjects (readout, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level Objects files for this cell
+bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
+{
+
+    bool status;
+    char *filename;
+    char *dataname;
+    char *headname;
+    pmHDU *hdu;
+    pmHDU *phu;
+    psMetadata *updates;
+    psMetadata *outhead;
+
+    psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
+
+    switch (file->type) {
+    case PM_FPA_FILE_RAW:
+        filename = pmFPAfileNameFromRule (file->filerule, file, view);
+        pmSourcesWriteRAW (sources, filename);
+        psFree (filename);
+        break;
+
+    case PM_FPA_FILE_OBJ:
+        filename = pmFPAfileNameFromRule (file->filerule, file, view);
+        pmSourcesWriteOBJ (sources, filename);
+        psFree (filename);
+        break;
+
+    case PM_FPA_FILE_SX:
+        filename = pmFPAfileNameFromRule (file->filerule, file, view);
+        pmSourcesWriteSX (sources, filename);
+        psFree (filename);
+        break;
+
+    case PM_FPA_FILE_CMP:
+        // a SPLIT format : only one header and object table per file
+        hdu = pmFPAviewThisHDU (view, file->fpa);
+        filename = pmFPAfileNameFromRule (file->filerule, file, view);
+
+        // copy the header to an output header, add the output header data
+        outhead = psMetadataCopy (NULL, hdu->header);
+
+        // check/fix first line (must be SIMPLE = F)
+        psMetadataItem *item = psMetadataGet (outhead, PS_LIST_HEAD);
+        if (strcmp (item->name, "SIMPLE") && strcmp (item->name, "XTENSION")) {
+            psErrorStackPrint(stderr, "invalid header: first line is neither SIMPLE nor XTENSION\n");
+            exit(EXIT_FAILURE);
+        }
+        if (!strcmp (item->name, "XTENSION")) {
+            psMetadataRemoveIndex (outhead, PS_LIST_HEAD);
+        }
+        psMetadataAddBool (outhead, PS_LIST_HEAD, "SIMPLE", PS_META_REPLACE, "CMP file, not simple", false);
+
+        // copy over the entries saved in the
+        updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
+        psMetadataCopy (outhead, updates);
+
+        pmSourcesWriteCMP (sources, filename, outhead);
+        psFree (outhead);
+        psFree (filename);
+        break;
+
+    case PM_FPA_FILE_CMF:
+        // write a PHU?
+        // write a header?
+        // write the data
+
+        // get the current header
+        hdu = pmFPAviewThisHDU (view, file->fpa);
+
+        // if file does not yet have a PHU, write it to disk
+        if (file->phu == NULL) {
+            // get the corresponding phu
+            phu = pmFPAviewThisPHU (view, file->fpa);
+
+            // CMF always has extensions
+            outhead = psMetadataCopy (NULL, phu->header);
+            psMetadataAdd (outhead, PS_LIST_TAIL, "EXTEND", PS_DATA_BOOL | PS_META_REPLACE, "this file has extensions", true);
+            psFitsWriteHeaderNotImage (file->fits, outhead);
+            file->phu = phu->header;
+            psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
+            psFree (outhead);
+        }
+
+        // this this header block is new, write it to disk,
+        if (hdu->header != file->header) {
+            // determine name for header extension
+            headname = pmFPAfileNameFromRule (file->extxtra, file, view);
+            outhead = psMetadataCopy (NULL, hdu->header);
+            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "extension name", headname);
+            psFitsWriteHeaderNotImage (file->fits, outhead);
+            psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type);
+            file->header = hdu->header;
+            psFree (outhead);
+            psFree (headname);
+        }
+
+        // write this table to disk
+        dataname = pmFPAfileNameFromRule (file->extrule, file, view);
+        updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
+        pmSourcesWriteCMF (file->fits, sources, updates, dataname);
+        psTrace ("pmFPAfile", 5, "wrote ext data %s (type: %d)\n", file->filename, file->type);
+        psFree (dataname);
+        break;
+
+    default:
+        fprintf (stderr, "warning: type mismatch\n");
+        break;
+    }
+    return true;
+}
+// a MEF CMF file has: PHU, CELL-HEAD, TABLE, CELL-HEAD, TABLE, TABLE, TABLE...
+
+// Given a FITS file pointer, read the table of object data
+bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file)
+{
+    pmFPA *fpa = file->fpa;
+
+    if (view->chip == -1) {
+        pmFPAReadObjects (fpa, view, file);
+        return true;
+    }
+
+    if (view->chip >= fpa->chips->n) {
+        return false;
+    }
+    pmChip *chip = fpa->chips->data[view->chip];
+
+    if (view->cell == -1) {
+        pmChipReadObjects (chip, view, file);
+        return true;
+    }
+
+    if (view->cell >= chip->cells->n) {
+        return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        pmCellReadObjects (cell, view, file);
+        return true;
+    }
+
+    if (view->readout >= cell->readouts->n) {
+        return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    pmReadoutReadObjects (readout, view, file);
+    return true;
+}
+
+// read in all chip-level Objects files for this FPA
+bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < fpa->chips->n; i++) {
+
+        pmChip *chip = fpa->chips->data[i];
+        pmChipReadObjects (chip, view, file);
+    }
+    return true;
+}
+
+// read in all cell-level Objects files for this chip
+bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < chip->cells->n; i++) {
+
+        pmCell *cell = chip->cells->data[i];
+        pmCellReadObjects (cell, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level Objects files for this cell
+bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
+{
+
+    for (int i = 0; i < cell->readouts->n; i++) {
+
+        pmReadout *readout = cell->readouts->data[i];
+        pmReadoutReadObjects (readout, view, file);
+    }
+    return true;
+}
+
+// read in all readout-level Objects files for this cell
+bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
+{
+
+    bool status;
+    psArray *sources;
+    pmHDU *hdu;
+
+    switch (file->type) {
+    case PM_FPA_FILE_OBJ:
+        fprintf (stderr, "warning: OBJ is not supported as an input object format\n");
+        break;
+
+    case PM_FPA_FILE_SX:
+        fprintf (stderr, "warning: SX is not supported as an input object format\n");
+        break;
+
+    case PM_FPA_FILE_CMP:
+        // a SPLIT format : only one header and object table per file
+
+        // read in header, if not yet loaded
+        hdu = pmFPAviewThisHDU (view, file->fpa);
+
+        char *filename = pmFPAfileNameFromRule (file->filerule, file, view);
+        file->fits = psFitsOpen (filename, "r");
+        hdu->header = psFitsReadHeader (NULL, file->fits);
+        psFitsClose (file->fits);
+        sources  = pmSourcesReadCMP (filename, hdu->header);
+        psFree (filename);
+        break;
+
+    case PM_FPA_FILE_CMF:
+        // read in header, if not yet loaded
+        hdu = pmFPAviewThisHDU (view, file->fpa);
+        if (hdu->header == NULL) {
+            char *headname = pmFPAfileNameFromRule (file->extxtra, file, view);
+            psFitsMoveExtName (file->fits, headname);
+            hdu->header = psFitsReadHeader (NULL, file->fits);
+            psFree (headname);
+        }
+
+        char *dataname = pmFPAfileNameFromRule (file->extrule, file, view);
+        psFitsMoveExtName (file->fits, dataname);
+        sources  = pmSourcesReadCMF (file->fits, hdu->header);
+        psFree (dataname);
+        break;
+
+    default:
+        fprintf (stderr, "warning: type mismatch\n");
+        break;
+    }
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "psphot sources", sources);
+    return true;
+}
+
+
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO.h
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO.h	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-28 02:14:56 $
+ *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -30,3 +30,15 @@
 bool pmPeaksWriteText (psArray *peaks, char *filename);
 
+bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file);
+bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
+bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
+bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
+bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
+
+bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file);
+bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file);
+bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file);
+bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file);
+bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file);
+
 # endif /* PM_SOURCE_IO_H */
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMF.c	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-29 20:55:42 $
+ *  @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -17,4 +17,7 @@
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+
 #include "pmPeaks.h"
 #include "pmMoments.h"
@@ -76,5 +79,6 @@
         psMetadataAdd (row, PS_LIST_TAIL, "THETA",   PS_DATA_F32, "", axes.theta);
         psMetadataAdd (row, PS_LIST_TAIL, "DOPHOT",  PS_DATA_U8,  "", type);
-        psMetadataAdd (row, PS_LIST_TAIL, "DUMMY",   PS_DATA_STRING, "", "123");
+        psMetadataAdd (row, PS_LIST_TAIL, "WEIGHT",  PS_DATA_U8,  "", PS_MIN (255, PS_MAX(0, 255*source->pixWeight)));
+        psMetadataAdd (row, PS_LIST_TAIL, "DUMMY",   PS_DATA_STRING, "", "12");
 
         psArrayAdd (table, 100, row);
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-29 20:55:42 $
+ *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,7 @@
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+
 #include "pmPeaks.h"
 #include "pmMoments.h"
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_OBJ.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_OBJ.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_OBJ.c	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-09 04:25:03 $
+ *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,7 @@
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+
 #include "pmPeaks.h"
 #include "pmMoments.h"
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_RAW.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_RAW.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_RAW.c	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-13 06:18:46 $
+ *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,7 @@
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+
 #include "pmPeaks.h"
 #include "pmMoments.h"
@@ -91,5 +94,5 @@
             fprintf (f, "%9.6f ", dPAR[j]);
         }
-        fprintf (f, ": %8.4f %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4d %2d\n",
+        fprintf (f, ": %8.4f %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4.2f %4d %2d\n",
                  source[0].apMag, source[0].type, source[0].mode,
                  log10(model[0].chisq/model[0].nDOF),
@@ -97,4 +100,5 @@
                  source[0].moments->SN,
                  model[0].radiusTMP,
+                 source[0].pixWeight,
                  model[0].nDOF,
                  model[0].nIter);
@@ -147,5 +151,5 @@
             fprintf (f, "%9.6f ", dPAR[j]);
         }
-        fprintf (f, ": %7.4f  %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4d %2d\n",
+        fprintf (f, ": %7.4f  %2d %#5x %7.3f %7.3f  %7.1f %7.2f %4.2f %4d %2d\n",
                  source->apMag,
                  source[0].type, source[0].mode,
@@ -154,4 +158,5 @@
                  source[0].moments->SN,
                  model[0].radiusTMP,
+                 source[0].pixWeight,
                  model[0].nDOF,
                  model[0].nIter);
Index: /branches/rel10_ifa/psModules/src/objects/pmSourceIO_SX.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourceIO_SX.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourceIO_SX.c	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-29 20:55:42 $
+ *  @version $Revision: 1.1.2.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,7 @@
 #include "pmHDU.h"
 #include "pmFPA.h"
+#include "pmFPAview.h"
+#include "pmFPAfile.h"
+
 #include "pmPeaks.h"
 #include "pmMoments.h"
Index: /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-01 02:47:20 $
+ *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -25,4 +25,6 @@
 #include "pmSourcePhotometry.h"
 
+# define DO_SKY 0
+
 static float AP_MIN_SN = 0.0;
 
@@ -105,4 +107,7 @@
     status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
 
+    // measure the weight of included pixels
+    status = pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->mask);
+
     // measure object aperture photometry
     if (SN > AP_MIN_SN) {
@@ -169,5 +174,4 @@
 }
 
-# define DO_SKY 0
 // return source aperture magnitude
 bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask)
@@ -202,40 +206,82 @@
 }
 
-# if (0)
-    // XXX split into ap, psf, ext mags?
-    bool pmSourcePhotometry (float *fitMag, float *apMag, pmModel *model, psImage *image, psImage *mask)
-{
-
-    float obsSum = 0;
-    float fitSum = 0;
-    float sky = model->params->data.F32[0];
-
-    *fitMag = 99.0;
-    *obsMag = 99.0;
-
-    // measure fitMag
-    pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
-    fitSum = modelFluxFunc (model->params);
-    if (fitSum <= 0)
-        return false;
-    if (!isfinite(fitSum))
-        return false;
-    *fitMag = -2.5*log10(fitSum);
-
-    // measure apMag
-    for (int ix = 0; ix < image->numCols; ix++) {
-        for (int iy = 0; iy < image->numRows; iy++) {
-            if (mask->data.U8[iy][ix])
-                continue;
-            obsSum += image->data.F32[iy][ix] - sky;
-        }
-    }
-    if (obsSum <= 0)
-        return false;
-    *obsMag = -2.5*log10(obsSum);
-
+// return source aperture magnitude
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask)
+{
+    float modelSum = 0;
+    float validSum = 0;
+    float sky = 0;
+    float value;
+
+    int Xo, Yo, dP;
+    int dX, DX, NX;
+    int dY, DY, NY;
+
+    *pixWeight = 0.0;
+
+    if (model == NULL)
+        return false;
+
+    // we only care about the value of the object model, not the local sky
+    if (DO_SKY) {
+        sky = model->params->data.F32[0];
+    } else {
+        sky = 0;
+    }
+
+    // the model function returns the source flux at a position
+    pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
+    psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
+    psVector *params = model->params;
+
+    Xo = params->data.F32[2];
+    Yo = params->data.F32[3];
+
+    dX = Xo - image->col0;
+    dP = image->numCols - dX;
+    DX = PS_MAX(dX, dP);
+    NX = image->numCols;
+
+    dY = Yo - image->row0;
+    dP = image->numRows - dY;
+    DY = PS_MAX(dY, dP);
+    NY = image->numRows;
+
+    // measure modelSum and validSum
+    // XXX this does not work for sources near the edge: we need to measure for
+    // a full square region
+    for (int ix = -DX; ix < DX + 1; ix++) {
+        int mx = ix + dX;
+        for (int iy = -DY; iy < DY + 1; iy++) {
+            int my = iy + dY;
+
+            coord->data.F32[0] = (psF32) (ix + Xo);
+            coord->data.F32[1] = (psF32) (iy + Yo);
+
+            // for the full model, add all points
+            value = modelFunc (NULL, params, coord) - sky;
+            modelSum += value;
+
+            // include count only the unmasked pixels within the image area
+            if (mx < 0)
+                continue;
+            if (my < 0)
+                continue;
+            if (mx >= NX)
+                continue;
+            if (my >= NY)
+                continue;
+            if (mask->data.U8[my][mx])
+                continue;
+
+            validSum += value;
+        }
+    }
+    if (validSum <= 0)
+        return false;
+
+    *pixWeight = validSum / modelSum;
     return (true);
 }
-# endif
 
 float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj)
Index: /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.h	(revision 6859)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-01 02:47:20 $
+ *  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-14 21:43:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -40,4 +40,5 @@
 float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj);
 float pmSourceCrossWeight (pmSource *Mi, pmSource *Mj);
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask);
 
 # endif /* PM_SOURCE_PHOTOMETRY_H */
Index: /branches/rel10_ifa/psModules/src/pslib/psAdditionals.c
===================================================================
--- /branches/rel10_ifa/psModules/src/pslib/psAdditionals.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/pslib/psAdditionals.c	(revision 6859)
@@ -143,4 +143,7 @@
 {
     psList *values = psListAlloc(NULL); // The list of values to return
+    if (string == NULL)
+        return values;  // NULL string is not an error, just an empty list
+
     unsigned int length = strlen(string); // The length of the string
     unsigned int numSplitters = strlen(splitters); // Number of characters that might split
@@ -176,4 +179,13 @@
 }
 
+psArray *psStringSplitArray (const char *string, const char *splitters)
+{
+
+    psList *list = psStringSplit (string, splitters);
+    psArray *array = psListToArray (list);
+    psFree (list);
+    return array;
+}
+
 #ifndef whitespace
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
Index: /branches/rel10_ifa/psModules/src/pslib/psAdditionals.h
===================================================================
--- /branches/rel10_ifa/psModules/src/pslib/psAdditionals.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/pslib/psAdditionals.h	(revision 6859)
@@ -30,4 +30,9 @@
                      );
 
+// Split string on given characters
+psArray *psStringSplitArray(const char *string, // String to split
+                            const char *splitters // Characters on which to split
+                           );
+
 // strip whitespace from head and tail of string
 int psStringStrip (char *string);
Index: /branches/rel10_ifa/psModules/src/pslib/psImageUnbin.c
===================================================================
--- /branches/rel10_ifa/psModules/src/pslib/psImageUnbin.c	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/pslib/psImageUnbin.c	(revision 6859)
@@ -179,5 +179,5 @@
 }
 
-double psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax)
+psStats *psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax)
 {
     double value;
@@ -185,6 +185,7 @@
     int ny = image->numRows;
 
+    psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_QUARTILE);
     if (nx*ny <= 0)
-        return 0.0;
+        return stats;
 
     int Nsubset = PS_MIN (MAX_SAMPLE_PIXELS, nx*ny);
@@ -203,5 +204,5 @@
         int iy = pixel / nx;
 
-        if (mask->data.U8[iy][ix] & maskValue)
+        if (mask && mask->data.U8[iy][ix] & maskValue)
             continue;
 
@@ -226,8 +227,11 @@
     value = value / npts;
 
+    stats->robustMedian = value;
+    stats->robustUQ = values->data.F32[imax];
+    stats->robustLQ = values->data.F32[imin];
+
+    psFree (values);
+    return stats;
     // XXX correct for selection bias??
-
-    psFree (values);
-    return value;
 }
 
Index: /branches/rel10_ifa/psModules/src/pslib/psImageUnbin.h
===================================================================
--- /branches/rel10_ifa/psModules/src/pslib/psImageUnbin.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/pslib/psImageUnbin.h	(revision 6859)
@@ -11,5 +11,5 @@
 
 // my temporary image stats function; seems to be much faster than psLib???
-double psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax);
+psStats *psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax);
 
 // my temporary sort which is based on N.R.; seems to be faster than psLib sort???
Index: /branches/rel10_ifa/psModules/src/psmodules.h
===================================================================
--- /branches/rel10_ifa/psModules/src/psmodules.h	(revision 6858)
+++ /branches/rel10_ifa/psModules/src/psmodules.h	(revision 6859)
@@ -35,4 +35,6 @@
 #include <pmFPARead.h>
 #include <pmFPAWrite.h>
+#include <pmFPA_JPEG.h>
+
 #include <pmReadout.h>
 // #include <pmChipMosaic.h>
@@ -66,8 +68,8 @@
 # include <pmGrowthCurve.h>
 # include <pmPSF.h>
+# include <pmPSF_IO.h>
 # include <pmPSFtry.h>
 # include <pmModelGroup.h>
 # include <pmSourcePhotometry.h>
-# include <pmFPAviewObjectsIO.h>
 
 #endif
