Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c	(revision 6846)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c	(revision 6847)
@@ -392,5 +392,5 @@
 
 bool pmFPAAddSourceFromView(pmFPA *fpa,   // The FPA
-                            pmFPAview *phuView, // The view, corresponding to the PHU
+                            const pmFPAview *phuView, // The view, corresponding to the PHU
                             psMetadata *format // Format of file
                            )
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.h	(revision 6846)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.h	(revision 6847)
@@ -11,5 +11,5 @@
 
 bool pmFPAAddSourceFromView(pmFPA *fpa,   // The FPA
-                            pmFPAview *phuView, // The view, corresponding to the PHU
+                            const pmFPAview *phuView, // The view, corresponding to the PHU
                             psMetadata *format // Format of file
                            );
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6846)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c	(revision 6847)
@@ -2,4 +2,5 @@
 #include "pslib.h"
 #include "psAdditionals.h"
+#include "pmConfig.h"
 #include "pmHDU.h"
 #include "pmFPA.h"
@@ -22,4 +23,7 @@
     psFree (file->names);
 
+    psFree (file->format);
+    psFree (file->name);
+
     if (file->fits != NULL) {
         psFitsClose (file->fits);
@@ -54,4 +58,7 @@
     file->fits = NULL;
     file->names = psMetadataAlloc();
+
+    file->format = NULL;
+    file->name = NULL;
 
     file->filerule = NULL;
@@ -188,4 +195,13 @@
     if (fpa != NULL) {
         file->fpa = psMemIncrRefCounter(fpa);
+    }
+
+    // for WRITE type of data, the output format needs to be determined
+    // this is only needed if the output file is not identical in structure to the input
+    char *formatName = psMetadataLookupStr (&status, data, "FILE.FORMAT");
+    if (formatName && strcasecmp (formatName, "NONE")) {
+        psMetadata *formats = psMetadataLookupMD(&status, camera, "FORMATS"); // List of formats
+        char *formatFile = psMetadataLookupStr (&status, formats, formatName);
+        readConfig (&file->format, formatFile, formatName);
     }
 
@@ -332,4 +348,6 @@
 bool pmFPAfileWrite (pmFPAfile *file, const pmFPAview *view)
 {
+    // XXX test return false;
+
     if (file->mode != PM_FPA_MODE_WRITE)
         return false;
@@ -372,4 +390,5 @@
 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view)
 {
+    // XXX test return false;
     if (file->mode != PM_FPA_MODE_WRITE)
         return false;
@@ -389,5 +408,5 @@
     case PM_FPA_FILE_IMAGE:
         /* create a PHU for thie file, if it does not exist */
-        pmFPAfileCopyView (file->src, file->fpa, view);
+        pmFPAfileCopyStructureView (file->fpa, file->src, file->format, file->xBin, file->yBin, view);
         psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->filename, file->fpa);
         break;
@@ -698,5 +717,5 @@
 
         // set the view to the corresponding entry for this phu
-        pmFPAview *view = pmFPAAddSourceFromHeader(fpa, phu, format);
+        pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
 
         // XXX is this the correct psMD to save the filename?
@@ -786,5 +805,5 @@
 
         // set the view to the corresponding entry for this phu
-        pmFPAview *view = pmFPAAddSourceFromHeader(fpa, phu, format);
+        pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
 
         // XXX is this the correct psMD to save the filename?
@@ -803,4 +822,17 @@
 }
 # endif
+
+// create a new output pmFPAfile based on an existing FPA
+pmFPAfile *pmFPAfileFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, char *filename)
+{
+    // XXX pmFPAConstruct has many leaks (6919)
+    pmFPA *fpa = pmFPAConstruct (config->camera);
+    pmFPAfile *file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
+    file->src = src; // inherit output elements from this source pmFPA
+    file->xBin = xBin;
+    file->yBin = yBin;
+
+    return file;
+}
 
 // look for the given name on the argument list.
@@ -879,5 +911,5 @@
 
         // set the view to the corresponding entry for this phu
-        pmFPAview *view = pmFPAAddSourceFromHeader(file->fpa, phu, format);
+        pmFPAview *view = pmFPAAddSourceFromHeader (file->fpa, phu, format);
 
         // XXX is this the correct psMD to save the filename?
@@ -957,5 +989,4 @@
 bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view)
 {
-    // XXX how to we transmit the required binning factor?
     // pmFPAWrite takes care of all PHUs as needed
     if (view->chip == -1) {
@@ -985,21 +1016,41 @@
     return false;
 
-    // XXX disable readout write for now
-    # if (0)
-
-        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
-}
-
-// need to distinguish between a "copy structure" and a "copy data"
-// need to allow for binning when performing the "copy structure"
+    // XXX add readout / segment equivalents
+}
+
+// given an already-opened fits file, write the components corresponding
+// to the specified view
+bool pmFPAfileCopyStructureView (pmFPA *out, pmFPA *in, psMetadata *format, int xBin, int yBin, const pmFPAview *view)
+{
+    // pmFPAWrite takes care of all PHUs as needed
+    if (view->chip == -1) {
+        pmFPAAddSourceFromView (out, view, format);
+        pmFPACopyStructure (out, in, xBin, yBin);
+        return true;
+    }
+    if (view->chip >= in->chips->n) {
+        return false;
+    }
+    pmChip *inChip = in->chips->data[view->chip];
+    pmChip *outChip = out->chips->data[view->chip];
+
+    if (view->cell == -1) {
+        pmFPAAddSourceFromView (out, view, format);
+        pmChipCopyStructure (outChip, inChip, xBin, yBin);
+        return true;
+    }
+    if (view->cell >= inChip->cells->n) {
+        return false;
+    }
+    pmCell *inCell = inChip->cells->data[view->cell];
+    pmCell *outCell = outChip->cells->data[view->cell];
+
+    if (view->readout == -1) {
+        pmFPAAddSourceFromView (out, view, format);
+        pmCellCopyStructure (outCell, inCell, xBin, yBin);
+        return true;
+    }
+    return false;
+
+    // XXX add readout / segment equivalents
+}
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h	(revision 6846)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAfile.h	(revision 6847)
@@ -7,6 +7,6 @@
 *  @author EAM, IfA
 *
-*  @version $Revision: 1.1.2.10 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-04-10 20:22:42 $
+*  @version $Revision: 1.1.2.11 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-04-13 06:17:28 $
 *
 *  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
@@ -81,4 +81,5 @@
     int xBin;    // desired binning in x direction
     int yBin;    // desired binning in y direction
+    psMetadata *format;
 }
 pmFPAfile;
@@ -137,4 +138,7 @@
 pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input);
 
+// create a new output pmFPAfile based on an existing FPA
+pmFPAfile *pmFPAfileFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, char *filename);
+
 // add the specified filename info (value) to the files of the given mode using the given reference name
 bool pmFPAfileAddFileNames (psMetadata *files, char *name, char *value, int mode);
@@ -145,3 +149,5 @@
 bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view);
 
+bool pmFPAfileCopyStructureView (pmFPA *out, pmFPA *in, psMetadata *format, int xBin, int yBin, const pmFPAview *view);
+
 # endif
Index: /branches/rel10_ifa/psModules/src/config/pmConfig.c
===================================================================
--- /branches/rel10_ifa/psModules/src/config/pmConfig.c	(revision 6846)
+++ /branches/rel10_ifa/psModules/src/config/pmConfig.c	(revision 6847)
@@ -3,6 +3,6 @@
  *  @author PAP, IfA
  *
- *  @version $Revision: 1.7.4.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-08 20:13:03 $
+ *  @version $Revision: 1.7.4.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-13 06:18:22 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -63,5 +63,5 @@
  *
  */
-static bool readConfig(
+bool readConfig(
     psMetadata **config,                // Config to output
     const char *name,                   // Name of file
Index: /branches/rel10_ifa/psModules/src/config/pmConfig.h
===================================================================
--- /branches/rel10_ifa/psModules/src/config/pmConfig.h	(revision 6846)
+++ /branches/rel10_ifa/psModules/src/config/pmConfig.h	(revision 6847)
@@ -3,6 +3,6 @@
  *  @author PAP, IfA
  *
- *  @version $Revision: 1.3.4.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-08 20:13:03 $
+ *  @version $Revision: 1.3.4.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-13 06:18:22 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -52,4 +52,11 @@
     int *argc,
     char **argv);
+
+/** we need this elsewhere; make it public **/
+bool readConfig(
+    psMetadata **config,                // Config to output
+    const char *name,                   // Name of file
+    const char *description             // Description of file
+);
 
 /** pmConfigValidateCamera
