Index: /trunk/psModules/src/detrend/pmFringeStats.c
===================================================================
--- /trunk/psModules/src/detrend/pmFringeStats.c	(revision 9950)
+++ /trunk/psModules/src/detrend/pmFringeStats.c	(revision 9951)
@@ -519,7 +519,7 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-bool pmFringesWriteFits(psFits *fits, psMetadata *header, const psArray *fringes, const char *extname)
-{
-    PS_ASSERT_PTR_NON_NULL(fits, false);
+bool pmFringesFormat(pmCell *cell, psMetadata *header, const psArray *fringes)
+{
+    PS_ASSERT_PTR_NON_NULL(cell, false);
     PS_ASSERT_ARRAY_NON_NULL(fringes, false);
 
@@ -568,4 +568,8 @@
     psMetadataAddS32(scalars, PS_LIST_TAIL, "PSFRNGNY", PS_META_REPLACE, "Large-scale smoothing in y",
                      regions->nY);
+    psMetadataAdd(cell->analysis, PS_LIST_TAIL, "FRINGE.HEADER", PS_DATA_METADATA,
+                  "Header for fringe data", scalars);
+    psFree(scalars);
+
 
     psArray *table = psArrayAlloc(numRows); // The table
@@ -600,53 +604,44 @@
     }
 
-    bool success;                       // Success of operation
-    if (!(success = psFitsWriteTable(fits, scalars, table, extname))) {
-        psError(PS_ERR_IO, false, "Unable to write fringe data to extension %s\n", extname);
-    }
-    psFree(scalars);
-    psFree(table);
-
-    return success;
-}
-
-
-psArray *pmFringesReadFits(psMetadata *header, psFits *fits, const char *extname)
-{
-    PS_ASSERT_PTR_NON_NULL(fits, NULL);
-
-    if (extname && strlen(extname) > 0 && !psFitsMoveExtName(fits, extname)) {
-        psError(PS_ERR_IO, false, "Unable to move to extension %s\n", extname);
+    psMetadataAdd(cell->analysis, PS_LIST_TAIL, "FRINGE", PS_DATA_ARRAY, "Fringe data", table);
+
+    return true;
+}
+
+
+psArray *pmFringesParse(pmCell *cell)
+{
+    PS_ASSERT_PTR_NON_NULL(cell, NULL);
+
+    bool mdok;                          // Status of MD lookup
+    psMetadata *header = psMetadataLookupMetadata(&mdok, cell->analysis, "FRINGE.HEADER"); // Header
+    if (!mdok || !header) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to find header for fringe data.\n");
         return NULL;
     }
 
-    psMetadata *headerCopy = psMemIncrRefCounter(header); // Copy of the header, or NULL
-    headerCopy = psFitsReadHeader(headerCopy, fits); // The FITS header
-    if (!headerCopy) {
-        psError(PS_ERR_IO, false, "Unable to read header for extension %s\n", extname);
-        psFree(headerCopy);
+    psArray *table = psMetadataLookupPtr(NULL, cell->analysis, "FRINGE"); // FITS table
+    if (!table) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to find table for fringe data.\n");
         return NULL;
     }
+
 
     // Read the scalars from the header
     #define READ_FRINGES_SCALAR(SCALAR, NAME) \
-    int SCALAR = psMetadataLookupS32(&mdok, headerCopy, NAME); \
+    int SCALAR = psMetadataLookupS32(&mdok, header, NAME); \
     if (!mdok || SCALAR <= 0) { \
-        psError(PS_ERR_IO, true, "Unable to find " NAME " in header of extension %s\n", extname); \
-        psFree(headerCopy); \
+        psError(PS_ERR_IO, true, "Unable to find " NAME " in fringe header.\n"); \
         return NULL; \
     }
 
     // Need to retrieve the scalars: dX, dY, nX, nY
-    bool mdok = true;                   // Status of MD lookup
-    READ_SCALAR(dX, "PSFRNGDX");
-    READ_SCALAR(dY, "PSFRNGDY");
-    READ_SCALAR(nX, "PSFRNGNX");
-    READ_SCALAR(nY, "PSFRNGNY");
-    psFree(headerCopy);
+    READ_FRINGES_SCALAR(dX, "PSFRNGDX");
+    READ_FRINGES_SCALAR(dY, "PSFRNGDY");
+    READ_FRINGES_SCALAR(nX, "PSFRNGNX");
+    READ_FRINGES_SCALAR(nY, "PSFRNGNY");
 
     // Now the vectors: x, y, mask, f, df
-    psArray *table = psFitsReadTable(fits); // The table
     long numRows = table->n;            // Number of rows
-
     pmFringeRegions *regions = pmFringeRegionsAlloc(numRows, dX, dY, nX, nY); // The fringe regions
     psVector *x = psVectorAlloc(numRows, PS_TYPE_F32); // x position
@@ -664,5 +659,5 @@
         VECTOR->data.TYPE[i] = psMetadataLookup##TYPE(&mdok, row, NAME); \
         if (!mdok) { \
-            psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " .\n"); \
+            psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " for row %ld.\n", i); \
             goto READ_FRINGES_DONE; \
         } \
@@ -674,5 +669,5 @@
         psMetadataItem *item = psMetadataLookup(row, NAME); \
         if (!item) { \
-            psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " .\n"); \
+            psError(PS_ERR_IO, true, "Unable to find " #DESCRIPTION " for row %ld.\n", i); \
             goto READ_FRINGES_DONE; \
         } \
@@ -684,10 +679,9 @@
             ARRAY->data[i] = vector; \
         } else { \
-            psError(PS_ERR_IO, true, "Found " #DESCRIPTION ", but it's of an unsupported type (%x).\n", \
-                    item->type); \
+            psError(PS_ERR_IO, true, "Found " #DESCRIPTION " for row %ld, but it's of an " \
+                    "unsupported type (%x).\n", i, item->type); \
             goto READ_FRINGES_DONE; \
         } \
     }
-
 
     // Translate the table into vectors
@@ -719,5 +713,4 @@
 
 READ_FRINGES_DONE:
-    psFree(table);
     psFree(regions);
     psFree(f);
Index: /trunk/psModules/src/detrend/pmFringeStats.h
===================================================================
--- /trunk/psModules/src/detrend/pmFringeStats.h	(revision 9950)
+++ /trunk/psModules/src/detrend/pmFringeStats.h	(revision 9951)
@@ -8,6 +8,6 @@
 /// @author Paul Price, IfA
 ///
-/// @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2006-11-04 02:34:30 $
+/// @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2006-11-13 22:19:52 $
 ///
 /// Copyright 2004-2006 Institute for Astronomy, University of Hawaii
@@ -78,6 +78,4 @@
                                         );
 
-
-
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // pmFringeStats
@@ -147,24 +145,21 @@
 /// Write an array of fringes measurements to a FITS table.
 ///
-/// Writes an array of fringe measurements for the same FPA component as a FITS table.  The array of fringe
-/// statistics must all use the same fringe regions (or there is no point in storing them all together).  The
-/// header is supplemented with scalar values dX, dY, nX and nY (as PSFRNGDX, PSFRNGDY, PSFRNGNX, PSFRNGNY)
-/// from the fringe regions, while the fringe coordinates and mask are written as a FITS table (as x, y,
-/// mask, f, df; f and df are vectors).
-bool pmFringesWriteFits(psFits *fits,    ///< FITS file to which to write
-                        psMetadata *header, ///< Header, or NULL
-                        const psArray *fringes, ///< Array of pmFringeStats, all for the same pmFringeRegion
-                        const char *extname ///< Extension name for table
+/// Writes an array of fringe measurements for a cell as a FITS table in the analysis metadata.  The array of
+/// fringe statistics must all use the same fringe regions (or there is no point in storing them all
+/// together).  The header is supplemented with scalar values dX, dY, nX and nY (as PSFRNGDX, PSFRNGDY,
+/// PSFRNGNX, PSFRNGNY) from the fringe regions, while the fringe coordinates and mask are written as a FITS
+/// table (as x, y, mask, f, df; f and df are vectors).
+bool pmFringesFormat(pmCell *cell,   ///< Cell for which to write
+                     psMetadata *header, ///< Header, or NULL
+                     const psArray *fringes ///< Array of pmFringeStats, all for the same pmFringeRegion
+                    );
+
+/// Parses an array of fringes measurements from a FITS table.
+///
+/// The fringes for the cell are read from the FITS table in the analysis metadata.  The table provides the
+/// region and the (possibly multiple) fringe statistics for that region.  The current extension is used if
+/// the extension name is not provided.
+psArray *pmFringesParse(pmCell *cell ///< Cell for which to read fringes
                        );
-
-/// Reads an array of fringes measurements from a FITS table.
-///
-/// The fringes are read from the FITS file, at the given extension name.  The table provides the region and
-/// the (possibly multiple) fringe statistics for that region.  The current extension is used if the extension
-/// name is not provided.
-psArray *pmFringesReadFits(psMetadata *header, ///< Header to read, or NULL
-                           psFits *fits,///< FITS file from which to read
-                           const char *extname ///< Extension name to read, or NULL
-                          );
 
 
