Index: trunk/archive/scripts/src/papFocalPlane.c
===================================================================
--- trunk/archive/scripts/src/papFocalPlane.c	(revision 4386)
+++ trunk/archive/scripts/src/papFocalPlane.c	(revision 4694)
@@ -254,23 +254,12 @@
 }
 
-psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell
-			       const char *chipName, // The name of the chip
-			       const char *cellName, // The name of the cell
+psMetadataItem *psCellGetValue(papCell *cell, // The cell
 			       const char *valueName // Name of value
 			       )
 {
-    psTrace(__func__, 3, "Trying to retrieve %s for %s:%s...\n", valueName, chipName, cellName);
-
-    bool mdStatus = true;		// Status of MD lookup
-    papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
-    if (!mdStatus) {
-	psError(PS_ERR_IO, false, "Unable to find chip named %s\n", chipName);
-	return NULL;
-    }
-    papCell *cell = psMetadataLookupCell(&mdStatus, chip->cells, cellName); // The cell
-    if (!mdStatus) {
-	psError(PS_ERR_IO, false, "Unable to find cell named %s in chip %s\n", cellName, chipName);
-	return NULL;
-    }
+    psTrace(__func__, 3, "Trying to retrieve %s...\n", valueName);
+
+    papChip *chip = cell->parent;	// The chip
+    papFPA *fpa = chip->parent;		// The FPA
 
     // Try cache, headers, database, defaults in order
@@ -293,17 +282,14 @@
 }
 
-float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell
-			const char *chipName, // The name of the chip
-			const char *cellName, // The name of the cell
+float psCellGetValueF32(papCell *cell, // The cell
 			const char *valueName // Name of value
 			)
 {
     float value = NAN;			// Result
-    psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
-    if (! item) {
-	psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
+    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
+    if (! item) {
+	psError(PS_ERR_IO, true, "Unable to find value %s in cell.\n", valueName);
     } else if (item->type != PS_META_F32) {
-	psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not F32.\n", valueName, chipName,
-		cellName);
+	psError(PS_ERR_IO, true, "Metadata item type for %s is not F32.\n", valueName);
     } else {
 	value = item->data.F32;
@@ -313,17 +299,14 @@
 }
 
-int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell
-		      const char *chipName, // The name of the chip
-		      const char *cellName, // The name of the cell
+int psCellGetValueS32(papCell *cell, // The cell
 		      const char *valueName // Name of value
     )
 {
     int value = 0;			// Result
-    psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
-    if (! item) {
-	psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
+    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
+    if (! item) {
+	psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName);
     } else if (item->type != PS_META_S32) {
-	psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not S32.\n", valueName, chipName,
-		cellName);
+	psError(PS_ERR_IO, true, "Metadata item type for %s is not S32.\n", valueName);
     } else {
 	value = item->data.S32;
@@ -334,17 +317,14 @@
 
 
-double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell
-			 const char *chipName, // The name of the chip
-			 const char *cellName, // The name of the cell
+double psCellGetValueF64(papCell *cell, // The cell
 			 const char *valueName // Name of value
 			 )
 {
     double value = NAN;			// Result
-    psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
-    if (! item) {
-	psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
+    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
+    if (! item) {
+	psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName);
     } else if (item->type != PS_META_F64) {
-	psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not F64.\n", valueName, chipName,
-		cellName);
+	psError(PS_ERR_IO, true, "Metadata item type for %s is not F64.\n", valueName);
     } else {
 	value = item->data.F64;
@@ -355,17 +335,14 @@
 
 
-psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell
-			      const char *chipName, // The name of the chip
-			      const char *cellName, // The name of the cell
+psString psCellGetValueString(papCell *cell, // The cell
 			      const char *valueName // Name of value
     )
 {
     psString value = NULL;		// Result
-    psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
-    if (! item) {
-	psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
+    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
+    if (! item) {
+	psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName);
     } else if (item->type != PS_META_STR) {
-	psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not STR.\n", valueName, chipName,
-		cellName);
+	psError(PS_ERR_IO, true, "Metadata item type for %s is not STR.\n", valueName);
     } else {
 	value = item->data.V;
@@ -394,6 +371,7 @@
     fpa->camera = psMemIncrRefCounter((psPtr)camera);
     fpa->db = db;
-    fpa->chips = psMetadataAlloc();
-
+    fpa->chips = psArrayAlloc(0);
+
+    fpa->extname = NULL;
     fpa->pixels = NULL;
     fpa->header = NULL;
@@ -418,5 +396,5 @@
 
 papChip *papChipAlloc(papFPA *fpa,	// FPA to which the chip belongs
-		      const char *name	// Name of the chip
+		      psString name	// Chip name
     )
 {
@@ -424,6 +402,6 @@
     psMemSetDeallocator(chip, (psFreeFcn)p_papChipFree);
 
-    // Push onto the FPA
-    psMetadataAdd(fpa->chips, PS_LIST_TAIL, name, PS_META_CHIP, "Chip added on allocation", chip);
+    // Push onto the array of chips
+    fpa->chips = psArrayAdd(fpa->chips, 0, chip);
 
     // Fill in the components
@@ -435,11 +413,12 @@
 
     chip->values = psMetadataAlloc();
-    chip->cells = psMetadataAlloc();
-
+    chip->parent = psMemIncrRefCounter(fpa);
+    chip->cells = psArrayAlloc(0);
+
+    chip->extname = NULL;
     chip->pixels = NULL;
     chip->header = NULL;
 
-    psMetadataAdd(chip->values, PS_LIST_TAIL, "CHIP.NAME", PS_META_STR, "Name of the chip",
-		  psStringCopy(name));
+    psMetadataAddStr(chip->values, PS_LIST_HEAD, "CHIP.NAME", "Chip name added at papChipAlloc", name);
 
     return chip;
@@ -453,4 +432,5 @@
     psFree(chip->values);
     psFree(chip->cells);
+    psFree(chip->parent);
 
     psFree(chip->pixels);
@@ -459,6 +439,5 @@
 
 papCell *papCellAlloc(papChip *chip,	// Chip to which the cell belongs
-		      const char *name,	// Name of the cell
-		      int nReadouts	// Number of readouts contained
+		      psString name	// Name of cell
     )
 {
@@ -466,6 +445,6 @@
     psMemSetDeallocator(cell, (psFreeFcn)p_papCellFree);
 
-    // Push onto the chip
-    psMetadataAdd(chip->cells, PS_LIST_TAIL, name, PS_META_CELL, "Cell added on allocation", cell);
+    // Push onto the array of chips
+    chip->cells = psArrayAdd(chip->cells, 0, cell);
 
     // Fill in components
@@ -480,11 +459,12 @@
 
     cell->values = psMetadataAlloc();
-    cell->readouts = psArrayAlloc(nReadouts);
-
+    cell->readouts = psArrayAlloc(0);
+    cell->parent = psMemIncrRefCounter(chip);
+
+    cell->extname = NULL;
     cell->pixels = NULL;
     cell->header = NULL;
 
-    psMetadataAdd(cell->values, PS_LIST_TAIL, "CELL.NAME", PS_META_STR, "Name of the cell",
-		  psStringCopy(name));
+    psMetadataAddStr(cell->values, PS_LIST_HEAD, "CELL.NAME", "Cell name added at papCellAlloc", name);
 
     return cell;
@@ -501,4 +481,5 @@
     psFree(cell->values);
     psFree(cell->readouts);
+    psFree(cell->parent);
 
     psFree(cell->pixels);
