Index: /branches/rel10_ifa/psModules/src/astrom/Makefile.am
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/Makefile.am	(revision 6567)
+++ /branches/rel10_ifa/psModules/src/astrom/Makefile.am	(revision 6568)
@@ -12,11 +12,12 @@
 	pmConceptsRead.c \
 	pmConceptsWrite.c \
-	pmConceptsStandard.c
-#	pmFPAfile.c
-#	pmFPAview.c
+	pmConceptsStandard.c \
+	pmFPAfile.c \
+	pmFPAview.c 
+
+#	pmFPAAstrometry.c
+#	pmAstrometryObjects.c
 #	pmChipMosaic.c
 #	pmFPAWrite.c
-#	pmFPAAstrometry.c
-#	pmAstrometryObjects.c
 
 psmoduleincludedir = $(includedir)
@@ -31,9 +32,11 @@
 	pmConceptsRead.h \
 	pmConceptsWrite.h \
-	pmConceptsStandard.h
-#	pmFPAfile.c
-#	pmFPAview.c
-#	pmChipMosaic.h 
-#	pmFPAWrite.h
+	pmConceptsStandard.h \
+	pmFPAfile.h \
+	pmFPAview.h
+
 #	pmFPAAstrometry.h
 #	pmAstrometryObjects.h
+#
+#	pmChipMosaic.h 
+#	pmFPAWrite.h 
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6567)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6568)
@@ -1,8 +1,11 @@
 #include <stdio.h>
 #include "pslib.h"
+#include "pmHDU.h"
+#include "pmFPA.h"
 #include "pmFPAview.h"
 #include "pmFPAfile.h"
-
-static void pmPFAfileFree (pmFPAfile *file)
+#include "pmFPAviewObjectsIO.h"
+
+static void pmFPAfileFree (pmFPAfile *file)
 {
 
@@ -10,5 +13,11 @@
         return;
 
-    // psFree (file->element);
+    psFree (file->fits);
+    psFree (file->filerule);
+    psFree (file->filextra);
+    psFree (file->extrule);
+    psFree (file->extxtra);
+    psFree (file->filename);
+    psFree (file->extname);
     return;
 }
@@ -18,14 +27,25 @@
 
     pmFPAfile *file = psAlloc (sizeof(pmFPAfile));
-
-    // file->element = foo;
+    psMemSetDeallocator (file, (psFreeFunc) pmFPAfileFree);
+
+    file->fits = NULL;
+    file->filerule = NULL;
+    file->filextra = NULL;
+    file->extrule  = NULL;
+    file->extxtra  = NULL;
+    file->filename = NULL;
+    file->extname  = NULL;
     return (file);
 }
 
-pmFile *pmFPAfileDefine (pmFPAview *view, psMetadata *camera, char *name)
-{
+// XXX is a file allowed to be both READ and WRITE?
+pmFPAfile *pmFPAfileDefine (pmFPAview *view, psMetadata *camera, char *name)
+{
+
+    bool status;
+    char *depth;
 
     // select the name from the camera config data
-    psMetadata *data = psMetadataLookup (&status, camera, name);
+    psMetadata *data = psMetadataLookupPtr (&status, camera, name);
     if (data == NULL) {
         return false;
@@ -39,5 +59,5 @@
 
     file->openDepth = PM_FPA_DEPTH_NONE;
-    char *depth = psMetadataLookupStr (&status, data, "OPEN.DEPTH");
+    depth = psMetadataLookupStr (&status, data, "OPEN.DEPTH");
     if (depth != NULL) {
         if (!strcasecmp (depth, "FPA"))     {
@@ -56,5 +76,5 @@
 
     file->readDepth = PM_FPA_DEPTH_NONE;
-    char *depth = psMetadataLookupStr (&status, data, "READ.DEPTH");
+    depth = psMetadataLookupStr (&status, data, "READ.DEPTH");
     if (depth != NULL) {
         if (!strcasecmp (depth, "FPA"))     {
@@ -73,19 +93,25 @@
 
     file->writeDepth = PM_FPA_DEPTH_NONE;
-    char *depth = psMetadataLookupStr (&status, data, "WRITE.DEPTH");
+    depth = psMetadataLookupStr (&status, data, "WRITE.DEPTH");
     if (depth != NULL) {
         if (!strcasecmp (depth, "FPA"))     {
-            file->readDepth = PM_FPA_DEPTH_FPA;
+            file->writeDepth = PM_FPA_DEPTH_FPA;
         }
         if (!strcasecmp (depth, "CHIP"))    {
-            file->readDepth = PM_FPA_DEPTH_CHIP;
+            file->writeDepth = PM_FPA_DEPTH_CHIP;
         }
         if (!strcasecmp (depth, "CELL"))    {
-            file->readDepth = PM_FPA_DEPTH_CELL;
+            file->writeDepth = PM_FPA_DEPTH_CELL;
         }
         if (!strcasecmp (depth, "READOUT")) {
-            file->readDepth = PM_FPA_DEPTH_READOUT;
-        }
-    }
+            file->writeDepth = PM_FPA_DEPTH_READOUT;
+        }
+    }
+
+    if ((file->readDepth != PM_FPA_DEPTH_NONE) && (file->writeDepth != PM_FPA_DEPTH_NONE)) {
+        psLogMsg (__func__, 3, "warning: file %s is set to both read and write; write is ignored\n", name);
+        file->writeDepth = PM_FPA_DEPTH_NONE;
+    }
+
     return (file);
 }
@@ -94,6 +120,9 @@
 {
 
+    bool status;
+    char *extra;
+
     // is current depth == open depth?
-    depth = pmFPAviewDepth (view);
+    pmFPAdepth depth = pmFPAviewDepth (view);
     if (file->openDepth != depth) {
         return false;
@@ -101,69 +130,88 @@
 
     // determine the file name
-    file->filename = pmConfigNameFromRule (file->filerule, view);
+    file->filename = pmFPAviewNameFromRule (file->filerule, view);
 
     // indirect filenames
     if (!strcasecmp (file->filename, "@FPAIO")) {
-        extra = pmConfigNameFromRule (file->filextra, view);
-        file->filename = psMetadataLookupStr (&status, fpi->IO, extra);
+        extra = pmFPAviewNameFromRule (file->filextra, view);
+        file->filename = psMetadataLookupStr (&status, view->IO, extra);
     }
     if (!strcasecmp (file->filename, "@DETDB")) {
-        extra = pmConfigNameFromRule (file->filextra, camera, view);
-        file->filename = pmDetrendSelect (extra);
-    }
-
-    if (file->mode == READ) {
+        extra = pmFPAviewNameFromRule (file->filextra, view);
+        // file->filename = pmDetrendSelect (extra);
+    }
+
+    if (file->readDepth != PM_FPA_DEPTH_NONE) {
         file->fits = psFitsOpen (file->filename, "r");
-    } else {
+    } else if (file->writeDepth != PM_FPA_DEPTH_NONE) {
         file->fits = psFitsOpen (file->filename, "w");
     }
-}
-
-bool pmFPAfileRead (pmFPAfile *file, pmFPAview *view, psMetadata *camera)
+    return true;
+}
+
+bool pmFPAfileRead (pmFPAfile *file, pmFPAview *view)
 {
 
     // is current depth == open depth?
-    depth = pmFPAviewDepth (view);
+    pmFPAdepth depth = pmFPAviewDepth (view);
     if (file->readDepth != depth) {
         return false;
     }
 
-    if (file->mode != READ) {
-        return false;
-    }
-
-    if (file->type == FITS) {
-        // read all selected elements for this view?
-        pmFPAviewReadFitsImage (view, file->fits, phu?, database?);
-    }
-
-    if (file->type == SMP) {
-        // read all selected elements for this view?
-        pmFPAviewReadSMP (view->fpa, file->fits, phu?, database?);
-    }
-}
-
-bool pmFPAfileWrite (pmFPAfile *file, pmFPAview *view, psMetadata *camera)
+    if (file->readDepth == PM_FPA_DEPTH_NONE) {
+        return false;
+    }
+
+    switch (file->type) {
+    case PM_FPA_FILE_IMAGE:
+        pmFPAviewReadFitsImage (view, file->fits);
+        break;
+
+    case PM_FPA_FILE_SX:
+    case PM_FPA_FILE_OBJ:
+    case PM_FPA_FILE_CMP:
+    case PM_FPA_FILE_CMF:
+        pmFPAviewReadObjects (view, file);
+        break;
+
+    default:
+        fprintf (stderr, "warning: type mismatch\n");
+        return false;
+    }
+    return true;
+}
+
+bool pmFPAfileWrite (pmFPAfile *file, pmFPAview *view)
 {
 
     // is current depth == open depth?
-    depth = pmFPAviewDepth (view);
+    pmFPAdepth depth = pmFPAviewDepth (view);
     if (file->writeDepth != depth) {
         return false;
     }
 
-    if (file->mode != WRITE) {
-        return false;
-    }
-
-    if (file->type == FITS) {
-        // read all selected elements for this view?
-        pmFPAviewWriteFitsImage (view, file->fits, phu?, database?);
-    }
-
-    if (file->type == SMP) {
-        // read all selected elements for this view?
-        pmFPAviewWriteSMP (view->fpa, file->fits, phu?, database?);
-    }
+    if (file->writeDepth == PM_FPA_DEPTH_NONE) {
+        return false;
+    }
+
+    switch (file->type) {
+    case PM_FPA_FILE_IMAGE:
+        psLogMsg (__func__, 3, "write image disabled\n");
+        // XXX disabled for now
+        // XXX pmFPAviewWriteFitsImage (view, file->fits);
+        break;
+
+    case PM_FPA_FILE_SX:
+    case PM_FPA_FILE_OBJ:
+    case PM_FPA_FILE_CMP:
+    case PM_FPA_FILE_CMF:
+        pmFPAviewWriteObjects (view, file);
+        break;
+
+    default:
+        fprintf (stderr, "warning: type mismatch\n");
+        return false;
+    }
+    return true;
 }
 
@@ -179,5 +227,5 @@
 
         pmFPAfileOpen (file, view, camera);
-        pmFPAfileRead (file, view, camera);
+        pmFPAfileRead (file, view);
     }
     psFree (iter);
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h	(revision 6567)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h	(revision 6568)
@@ -7,6 +7,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-03-09 03:24:49 $
+*  @version $Revision: 1.1.2.4 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-09 20:56:39 $
 *
 *  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
@@ -40,5 +40,4 @@
     char *extname;
 
-    int mode;
     pmFPAfileType type;
 }
@@ -48,8 +47,7 @@
 pmFPAfile *pmFPAfileDefine (pmFPAview *view, psMetadata *camera, char *name);
 bool pmFPAfileOpen (pmFPAfile *file, pmFPAview *view, psMetadata *camera);
-bool pmFPAfileRead (pmFPAfile *file, pmFPAview *view, psMetadata *camera);
-bool pmFPAfileWrite (pmFPAfile *file, pmFPAview *view, psMetadata *camera);
+bool pmFPAfileRead (pmFPAfile *file, pmFPAview *view);
+bool pmFPAfileWrite (pmFPAfile *file, pmFPAview *view);
 bool pmFPAfileIOCheck (pmFPAview *view, psMetadata *camera);
-bool pmFPAviewReadFitsImage (pmFPAview *view, psFits *fits);
 
 # endif
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAview.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAview.c	(revision 6567)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAview.c	(revision 6568)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-09 03:24:49 $
+ *  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-09 20:56:39 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,28 +20,4 @@
 #include "pmFPAWrite.h"
 
-bool pmChipRead(pmChip *fpa,              // FPA to read into
-                psFits *fits,            // FITS file from which to read
-                psMetadata *phu,         // Primary header
-                psDB *db                 // Database handle, for concept ingest
-               );
-
-bool pmCellRead(pmCell *fpa,              // FPA to read into
-                psFits *fits,            // FITS file from which to read
-                psMetadata *phu,         // Primary header
-                psDB *db                 // Database handle, for concept ingest
-               );
-
-bool pmReadoutRead(pmReadout *fpa,              // FPA to read into
-                   psFits *fits,            // FITS file from which to read
-                   psMetadata *phu,         // Primary header
-                   psDB *db                 // Database handle, for concept ingest
-                  );
-
-bool pmReadoutReadSegment(pmReadout *fpa,              // FPA to read into
-                          psFits *fits,            // FITS file from which to read
-                          int n, int i,
-                          psMetadata *phu,         // Primary header
-                          psDB *db);
-
 static void pmFPAviewFree (pmFPAview *view)
 {
@@ -308,5 +284,5 @@
 
     if (view->chip == -1) {
-        pmFPARead (fpa, fits, NULL, NULL);
+        pmFPARead (fpa, fits, NULL);
         return true;
     }
@@ -318,5 +294,5 @@
 
     if (view->cell == -1) {
-        pmChipRead (chip, fits, NULL, NULL);
+        pmChipRead (chip, fits, NULL);
         return true;
     }
@@ -328,18 +304,72 @@
 
     if (view->readout == -1) {
-        pmCellRead (cell, fits, NULL, NULL);
-        return true;
-    }
-
-    if (view->readout >= cell->readouts->n) {
-        return false;
-    }
+        pmCellRead (cell, fits, NULL);
+        return true;
+    }
+
+    // XXX pmReadoutRead, pmReadoutReadSegement disabled for now
+    return false;
+
+    # if (0)
+
+        if (view->readout >= cell->readouts->n) {
+            return false;
+        }
     pmReadout *readout = cell->readouts->data[view->readout];
 
     if (view->nRows == 0) {
-        pmReadoutRead (readout, fits, NULL, NULL);
+        pmReadoutRead (readout, fits, NULL);
     } else {
         pmReadoutReadSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
     }
     return true;
-}
+    # endif
+}
+
+// XXX image writes disabled for now
+# if (0)
+    // given an already-opened fits file, write the components corresponding
+    // to the specified view
+    bool pmFPAviewWriteFitsImage (pmFPAview *view, psFits *fits)
+{
+
+    pmFPA *fpa = view->fpa;
+
+    if (view->chip == -1) {
+        pmFPAWrite (fpa, fits, NULL, NULL);
+        return true;
+    }
+
+    if (view->chip >= fpa->chips->n) {
+        return false;
+    }
+    pmChip *chip = fpa->chips->data[view->chip];
+
+    if (view->cell == -1) {
+        pmChipWrite (chip, fits, NULL, NULL);
+        return true;
+    }
+
+    if (view->cell >= chip->cells->n) {
+        return false;
+    }
+    pmCell *cell = chip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        pmCellWrite (cell, fits, NULL, NULL);
+        return true;
+    }
+
+    if (view->readout >= cell->readouts->n) {
+        return false;
+    }
+    pmReadout *readout = cell->readouts->data[view->readout];
+
+    if (view->nRows == 0) {
+        pmReadoutWrite (readout, fits, NULL, NULL);
+    } else {
+        pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
+    }
+    return true;
+}
+# endif
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAview.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAview.h	(revision 6567)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAview.h	(revision 6568)
@@ -7,6 +7,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-03-09 03:24:49 $
+*  @version $Revision: 1.1.2.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-09 20:56:39 $
 *
 *  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
@@ -74,3 +74,6 @@
 bool pmFPAviewReadFitsImage (pmFPAview *view, psFits *fits);
 
+// write the components for the specified view
+bool pmFPAviewWriteFitsImage (pmFPAview *view, psFits *fits);
+
 # endif
Index: /branches/rel10_ifa/psModules/src/objects/Makefile.am
===================================================================
--- /branches/rel10_ifa/psModules/src/objects/Makefile.am	(revision 6567)
+++ /branches/rel10_ifa/psModules/src/objects/Makefile.am	(revision 6568)
@@ -3,25 +3,25 @@
 libpsmoduleobjects_la_CPPFLAGS = $(SRCINC) $(PSMODULE_CFLAGS) -I../pslib/
 libpsmoduleobjects_la_LDFLAGS  = -release $(PACKAGE_VERSION)
-libpsmoduleobjects_la_SOURCES  = 
-#     pmPeaks.c \
-#     pmMoments.c \
-#     pmModel.c \
-#     pmModelGroup.c \
-#     pmSource.c \
-#     pmSourceSky.c \
-#     pmSourceContour.c \
-#     pmSourceFitModel.c \
-#     pmSourceFitSet.c \
-#     pmSourcePhotometry.c \
-#     pmSourceIO.c \
-#     pmSourceIO_CMF.c \
-#     pmSourceIO_CMP.c \
-#     pmSourceIO_OBJ.c \
-#     pmSourceIO_SX.c \
-#     pmPSF.c \
-#     pmPSFtry.c \
-#     pmGrowthCurve.c \
-#     pmFPAviewReadObjects.c \
-#     pmFPAviewWriteObjects.c
+libpsmoduleobjects_la_SOURCES  = \
+     pmPeaks.c \
+     pmMoments.c \
+     pmModel.c \
+     pmModelGroup.c \
+     pmSource.c \
+     pmSourceSky.c \
+     pmSourceContour.c \
+     pmSourceFitModel.c \
+     pmSourceFitSet.c \
+     pmSourcePhotometry.c \
+     pmSourceIO.c \
+     pmSourceIO_CMF.c \
+     pmSourceIO_CMP.c \
+     pmSourceIO_OBJ.c \
+     pmSourceIO_SX.c \
+     pmPSF.c \
+     pmPSFtry.c \
+     pmGrowthCurve.c \
+     pmFPAviewReadObjects.c \
+     pmFPAviewWriteObjects.c
 
 EXTRA_DIST = \
@@ -32,17 +32,17 @@
 
 psmoduleincludedir = $(includedir)
-psmoduleinclude_HEADERS =
-#     pmPeaks.h \
-#     pmMoments.h \
-#     pmModel.h \
-#     pmModelGroup.h \
-#     pmSource.h \
-#     pmSourceSky.h \
-#     pmSourceContour.h \
-#     pmSourceFitModel.h \
-#     pmSourceFitSet.h \
-#     pmSourcePhotometry.h \
-#     pmSourceIO.h \
-#     pmPSF.h \
-#     pmPSFtry.h \
-#     pmGrowthCurve.h
+psmoduleinclude_HEADERS = \
+     pmPeaks.h \
+     pmMoments.h \
+     pmModel.h \
+     pmModelGroup.h \
+     pmSource.h \
+     pmSourceSky.h \
+     pmSourceContour.h \
+     pmSourceFitModel.h \
+     pmSourceFitSet.h \
+     pmSourcePhotometry.h \
+     pmSourceIO.h \
+     pmPSF.h \
+     pmPSFtry.h \
+     pmGrowthCurve.h
