Index: /trunk/psModules/src/astrom/pmFPA.c
===================================================================
--- /trunk/psModules/src/astrom/pmFPA.c	(revision 7005)
+++ /trunk/psModules/src/astrom/pmFPA.c	(revision 7006)
@@ -12,6 +12,6 @@
 * XXX: Should we implement non-linear cell->chip transforms?
 *
-*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-04-26 00:27:14 $
+*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-04-30 22:04:46 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -36,6 +36,7 @@
 static void readoutFree(pmReadout *readout)
 {
-    psTrace(__func__, 9, "Removing readout %lx from cell %lx...\n", (size_t)readout, (size_t)readout->parent);
+    // if this readout has a parent, drop that instance
     if (readout->parent) {
+        psTrace(__func__, 9, "Removing readout %lx from cell %lx...\n", (size_t)readout, (size_t)readout->parent);
         psArray *readouts = readout->parent->readouts;
         for (int i = 0; i < readouts->n; i++) {
@@ -55,6 +56,8 @@
 static void cellFree(pmCell *cell)
 {
-    psTrace(__func__, 9, "Removing cell %lx from chip %lx...\n", (size_t)cell, (size_t)cell->parent);
+
+    // if this cell has a parent, drop that instance
     if (cell->parent) {
+        psTrace(__func__, 9, "Removing cell %lx from chip %lx...\n", (size_t)cell, (size_t)cell->parent);
         psArray *cells = cell->parent->cells;
         for (int i = 0; i < cells->n; i++) {
@@ -76,6 +79,7 @@
 static void chipFree(pmChip* chip)
 {
-    psTrace(__func__, 9, "Removing chip %lx from fpa %lx...\n", (size_t)chip, (size_t)chip->parent);
+    // if this chip has a parent, drop that instance
     if (chip->parent) {
+        psTrace(__func__, 9, "Removing chip %lx from fpa %lx...\n", (size_t)chip, (size_t)chip->parent);
         psArray *chips = chip->parent->chips;
         for (int i = 0; i < chips->n; i++) {
@@ -85,4 +89,5 @@
         }
     }
+
     psTrace(__func__, 9, "Freeing chip %lx\n", (size_t)chip);
     pmChipFreeCells(chip);
@@ -93,4 +98,10 @@
     psFree(chip->hdu);
     psFree(chip->mosaic);
+
+    # if FPA_ASTROM
+
+    psFree(chip->toFPA);
+    psFree(chip->fromFPA);
+    # endif
 }
 
@@ -99,11 +110,12 @@
 {
     psTrace(__func__, 9, "Freeing fpa %lx\n", (size_t)fpa);
+
+    // NULL the parent pointers
     psArray *chips = fpa->chips;
-    for (psS32 i = 0 ; i < chips->n ; i++) {
+    for (int i = 0 ; i < chips->n ; i++) {
         pmChip *tmpChip = chips->data[i];
         if (! tmpChip) {
             continue;
         }
-        chips->data[i] = NULL;
         tmpChip->parent = NULL;
     }
@@ -113,4 +125,11 @@
     psFree(fpa->camera);
     psFree(fpa->hdu);
+
+    # if FPA_ASTROM
+
+    psFree(fpa->fromTangentPlane);
+    psFree(fpa->toTangentPlane);
+    psFree(fpa->projection);
+    # endif
 }
 
@@ -127,8 +146,6 @@
             continue;
         }
-        readouts->data[i] = NULL;
         tmpReadout->parent = NULL;
         psTrace(__func__, 9, "Will now free readout %lx...\n", (size_t)tmpReadout);
-        psFree(tmpReadout); // Drop the readout
     }
     cell->readouts = psArrayRealloc(cell->readouts, 0);
@@ -149,8 +166,6 @@
             continue;
         }
-        cells->data[i] = NULL;
         tmpCell->parent = NULL;
         pmCellFreeReadouts(tmpCell);// Drop all readouts the cell holds
-        psFree(tmpCell);            // Drop the cell
     }
     chip->cells = psArrayRealloc(chip->cells, 0);
@@ -221,9 +236,17 @@
     psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
 
-    tmpChip->analysis = psMetadataAlloc();
+    # if FPA_ASTROM
+
+    tmpChip->col0 = 0;
+tmpChip->row0 = 0;
+tmpChip->toFPA = NULL;
+tmpChip->fromFPA = NULL;
+# endif
+
+tmpChip->analysis = psMetadataAlloc();
     tmpChip->cells = psArrayAlloc(0);
     tmpChip->parent = fpa;
     if (fpa != NULL) {
-        fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
+        psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
     }
     tmpChip->hdu = NULL;
@@ -239,5 +262,4 @@
     }
     pmConceptsBlankChip(tmpChip);
-
     return(tmpChip);
 }
@@ -248,6 +270,13 @@
     psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
 
-    tmpFPA->analysis = NULL;
-    tmpFPA->camera = psMemIncrRefCounter((psPtr)camera);
+    # if FPA_ASTROM
+
+    tmpFPA->fromTangentPlane = NULL;
+tmpFPA->toTangentPlane = NULL;
+tmpFPA->projection = NULL;
+# endif
+
+tmpFPA->analysis = NULL;
+tmpFPA->camera = psMemIncrRefCounter((psPtr)camera);
     tmpFPA->chips = psArrayAlloc(0);
     tmpFPA->hdu = NULL;
