Index: trunk/psModules/src/camera/pmFPAConstruct.c
===================================================================
--- trunk/psModules/src/camera/pmFPAConstruct.c	(revision 16911)
+++ trunk/psModules/src/camera/pmFPAConstruct.c	(revision 16912)
@@ -415,37 +415,37 @@
     psArray *cellNames = NULL;      // Cell names
     psArray *cellTypes = NULL;      // Cell types
-    
+
     int nParsed = 0;
 
     switch (chipContents->type) {
       case PS_DATA_STRING: {
-	  nParsed = parseContent(&cellNames, &cellTypes, NULL, chipContents->data.str);
-	  break;
+          nParsed = parseContent(&cellNames, &cellTypes, NULL, chipContents->data.str);
+          break;
       }
       case PS_DATA_METADATA: {
-	  psMetadataIterator *iter = psMetadataIteratorAlloc(chipContents->data.md, PS_LIST_HEAD, NULL); // Iterator
-	  psMetadataItem *item;           // Item from iteration
-	  while ((item = psMetadataGetAndIncrement(iter))) {
-	      if (item->type != PS_DATA_STRING) {
-		  psWarning ("Item %s in camera format chip table is not of type STR.", item->name);
-		  continue;
-	      }
-	      nParsed += parseContent(&cellNames, &cellTypes, NULL, item->data.str);
-	  }
-	  psFree (iter);
-	  break;
+          psMetadataIterator *iter = psMetadataIteratorAlloc(chipContents->data.md, PS_LIST_HEAD, NULL); // Iterator
+          psMetadataItem *item;           // Item from iteration
+          while ((item = psMetadataGetAndIncrement(iter))) {
+              if (item->type != PS_DATA_STRING) {
+                  psWarning ("Item %s in camera format chip table is not of type STR.", item->name);
+                  continue;
+              }
+              nParsed += parseContent(&cellNames, &cellTypes, NULL, item->data.str);
+          }
+          psFree (iter);
+          break;
       }
       default:
-	psWarning ("Item %s in camera format chip table is not of type STR.", chipContents->name);
-	break;
+        psWarning ("Item %s in camera format chip table is not of type STR.", chipContents->name);
+        break;
     }
 
     if (nParsed == 0) {
-	psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-		"Unable to parse chip contents (within %s in camera format) as cellName:cellType",
-		CHIP_TYPES);
-	psFree(cellNames);
-	psFree(cellTypes);
-	return false;
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "Unable to parse chip contents (within %s in camera format) as cellName:cellType",
+                CHIP_TYPES);
+        psFree(cellNames);
+        psFree(cellTypes);
+        return false;
     }
 
@@ -1349,4 +1349,46 @@
 }
 
+bool pmFPAAddSourceFromFormat(pmFPA *fpa, const char *fpaname, const psMetadata *format)
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_METADATA_NON_NULL(format, false);
+
+    // Generate the correct structure
+    pmFPALevel phuLevel = pmFPAPHULevel(format); // Level at which PHU goes
+    pmFPAview *view = pmFPAviewAlloc(0);// View for current level
+    if (phuLevel == PM_FPA_LEVEL_FPA) {
+        if (!pmFPAAddSourceFromView(fpa, fpaname, view, format)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
+            psFree(view);
+            return false;
+        }
+    } else {
+        pmChip *chip;                       // Chip from FPA
+        while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
+            if (phuLevel == PM_FPA_LEVEL_CHIP) {
+                if (!pmFPAAddSourceFromView(fpa, fpaname, view, format)) {
+                    psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
+                    psFree(view);
+                    return false;
+                }
+            } else {
+                pmCell *cell;                   // Cell from chip
+                while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
+                    if (phuLevel == PM_FPA_LEVEL_CELL) {
+                        if (!pmFPAAddSourceFromView(fpa, fpaname, view, format)) {
+                            psError(PS_ERR_UNKNOWN, false, "Unable to add PHU to FPA.");
+                            psFree(view);
+                            return false;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    psFree(view);
+
+    return true;
+}
+
 bool pmFPAAddSourceFromView(pmFPA *fpa, const char *fpaname, const pmFPAview *phuView,
                             const psMetadata *format)
Index: trunk/psModules/src/camera/pmFPAConstruct.h
===================================================================
--- trunk/psModules/src/camera/pmFPAConstruct.h	(revision 16911)
+++ trunk/psModules/src/camera/pmFPAConstruct.h	(revision 16912)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-03-30 21:12:56 $
+ * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2008-03-11 01:27:05 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -23,4 +23,12 @@
 pmFPA *pmFPAConstruct(const psMetadata *camera ///< The camera configuration
                      );
+
+/// Add a source to the focal plane hierarchy, specified by a camera format
+///
+/// This is suitable for generating an output FPA given the desired format.
+bool pmFPAAddSourceFromFormat(pmFPA *fpa, ///< The FPA
+                              const char *fpaname, ///< FPA.NAME for the source
+                              const psMetadata *format ///< Format of file
+    );
 
 /// Add an (input or output) source to the focal plane hierarchy, specified by a view
