Index: trunk/psModules/src/astrom/pmFPA.c
===================================================================
--- trunk/psModules/src/astrom/pmFPA.c	(revision 6930)
+++ trunk/psModules/src/astrom/pmFPA.c	(revision 6970)
@@ -12,6 +12,6 @@
 * XXX: Should we implement non-linear cell->chip transforms?
 *
-*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-04-20 22:30:33 $
+*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-04-25 00:22:25 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -33,32 +33,17 @@
 /******************************************************************************
  *****************************************************************************/
-#define PS_FREE_HIERARCHY 1
-#define PARENT_LINKS 0
 
 static void readoutFree(pmReadout *readout)
 {
-    psTrace(__func__, 9, "Removing readout %lx from cell %lx...\n", (size_t) readout, (size_t) readout->parent);
+    psTrace(__func__, 9, "Removing readout %lx from cell %lx...\n", (size_t)readout, (size_t)readout->parent);
     if (readout->parent) {
         psArray *readouts = readout->parent->readouts;
         for (int i = 0; i < readouts->n; i++) {
             if (readouts->data[i] == readout) {
-                //                    pmReadout *tmpReadout = readouts->data[i];
                 readouts->data[i] = NULL;
-                #if PARENT_LINKS
-
-                psFree(tmpReadout);
-                #endif
-
-                break;
             }
         }
     }
     psTrace(__func__, 9, "Freeing readout %lx\n", (size_t) readout);
-
-    #if PARENT_LINKS
-
-    psFree(readout->parent);
-    #endif
-
     psFree(readout->image);
     psFree(readout->mask);
@@ -75,23 +60,11 @@
         for (int i = 0; i < cells->n; i++) {
             if (cells->data[i] == cell) {
-                //                    pmCell *tmpCell = cells->data[i];
                 cells->data[i] = NULL;
-                #if PARENT_LINKS
-
-                psFree(tmpCell);
-                #endif
-
-                break;
             }
         }
     }
     psTrace(__func__, 9, "Freeing cell %lx\n", (size_t)cell);
-
     pmCellFreeReadouts(cell);
     psFree(cell->readouts);
-    #if PARENT_LINKS
-
-    psFree(cell->parent);
-    #endif
 
     psFree(cell->concepts);
@@ -108,33 +81,16 @@
         for (int i = 0; i < chips->n; i++) {
             if (chips->data[i] == chip) {
-                //                    pmChip *tmpChip = chips->data[i];
                 chips->data[i] = NULL;
-                #if PARENT_LINKS
-
-                psFree(tmpChip);
-                #endif
-
-                break;
             }
         }
     }
     psTrace(__func__, 9, "Freeing chip %lx\n", (size_t)chip);
-
     pmChipFreeCells(chip);
     psFree(chip->cells);
-    #if PARENT_LINKS
-
-    psFree(chip->parent);
-    #endif
-
-    #if 0
-
-    psFree(chip->toFPA);
-    psFree(chip->fromFPA);
-    #endif
 
     psFree(chip->concepts);
     psFree(chip->analysis);
     psFree(chip->hdu);
+    psFree(chip->mosaic);
 }
 
@@ -143,18 +99,4 @@
 {
     psTrace(__func__, 9, "Freeing fpa %lx\n", (size_t)fpa);
-    #if 0
-
-    psFree(fpa->fromTangentPlane);
-    psFree(fpa->toTangentPlane);
-    psFree(fpa->projection);
-    #endif
-
-    psFree(fpa->concepts);
-    psFree(fpa->analysis);
-    psFree(fpa->camera);
-    //
-    // Set the parent to NULL in all fpa->chips before psFree(fpa->chips)
-    // in order to avoid memory reference counter problems.
-    //
     psArray *chips = fpa->chips;
     for (psS32 i = 0 ; i < chips->n ; i++) {
@@ -165,9 +107,9 @@
         chips->data[i] = NULL;
         tmpChip->parent = NULL;
-        if (PS_FREE_HIERARCHY == 1) {
-            psFree(tmpChip);
-        }
     }
     psFree(fpa->chips);
+    psFree(fpa->concepts);
+    psFree(fpa->analysis);
+    psFree(fpa->camera);
     psFree(fpa->hdu);
 }
@@ -189,9 +131,4 @@
         psTrace(__func__, 9, "Will now free readout %lx...\n", (size_t)tmpReadout);
         psFree(tmpReadout); // Drop the readout
-        #if PARENT_LINKS
-
-        psFree(cell); // Decrement reference counter on cell, since readout->parent isn't held any more
-        #endif
-
     }
     cell->readouts = psArrayRealloc(cell->readouts, 0);
@@ -216,9 +153,4 @@
         pmCellFreeReadouts(tmpCell);// Drop all readouts the cell holds
         psFree(tmpCell);            // Drop the cell
-        #if PARENT_LINKS
-
-        psFree(chip); // Decrement reference counter on chip, since cell->parent isn't held any more
-        #endif
-
     }
     chip->cells = psArrayRealloc(chip->cells, 0);
@@ -230,6 +162,5 @@
 {
     pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout));
-    tmpReadout->row0 = 0;
-    tmpReadout->col0 = 0;
+    psMemSetDeallocator(tmpReadout, (psFreeFunc) readoutFree);
 
     tmpReadout->image = NULL;
@@ -238,12 +169,5 @@
     tmpReadout->bias = psListAlloc(NULL);
     tmpReadout->analysis = psMetadataAlloc();
-    #if PARENT_LINKS
-
-    tmpReadout->parent = psMemIncrRefCounter(cell);
-    #else
-
     tmpReadout->parent = cell;
-    #endif
-
     if (cell != NULL) {
         cell->readouts = psArrayAdd(cell->readouts, 1, (psPtr) tmpReadout);
@@ -254,49 +178,40 @@
     tmpReadout->data_exists = false;       // data yet read in
 
-    psMemSetDeallocator(tmpReadout, (psFreeFunc) readoutFree);
+    tmpReadout->row0 = 0;
+    tmpReadout->col0 = 0;
+
     return(tmpReadout);
 }
 
-// XXX: Verify these default values for row0, col0.
-// PAP: These values may disappear in the future in favour of values in the "concepts"?
 pmCell *pmCellAlloc(
     pmChip *chip,
-    const char *name)
+    const char *name
+)
 {
     pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell));
-
-    tmpCell->concepts = psMetadataAlloc();
-    tmpCell->conceptsRead = PM_CONCEPT_SOURCE_NONE;
-    psBool rc = psMetadataAddStr(tmpCell->concepts, PS_LIST_HEAD, "CELL.NAME", 0, NULL, name);
-    if (rc == false) {
-        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CELL.NAME to metadata.\n");
-    }
+    psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree);
+
     tmpCell->config = NULL;
     tmpCell->analysis = psMetadataAlloc();
     tmpCell->readouts = psArrayAlloc(0);
-    #if PARENT_LINKS
-
-    tmpCell->parent = psMemIncrRefCounter(chip);
-    #else
-
     tmpCell->parent = chip;
-    #endif
-
     if (chip != NULL) {
         chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
     }
+    tmpCell->hdu = NULL;
     tmpCell->process = true;            // All cells are processed by default
     tmpCell->file_exists = false;       // Not yet identified
     tmpCell->data_exists = false;       // Not yet read in
-    tmpCell->hdu = NULL;
-
+
+    tmpCell->concepts = psMetadataAlloc();
+    tmpCell->conceptsRead = PM_CONCEPT_SOURCE_NONE;
+    if (!psMetadataAddStr(tmpCell->concepts, PS_LIST_HEAD, "CELL.NAME", 0, NULL, name)) {
+        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CELL.NAME to metadata.\n");
+    }
     pmConceptsBlankCell(tmpCell);
 
-    psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree);
     return(tmpCell);
 }
 
-// XXX: Verify these default values for row0, col0.
-// PAP: row0, col0 may disappear in the future in favour of storing values in the "concepts".
 pmChip *pmChipAlloc(
     pmFPA *fpa,
@@ -304,40 +219,25 @@
 {
     pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip));
-
-    #if 0
-
-    tmpChip->col0 = 0;
-    tmpChip->row0 = 0;
-    tmpChip->toFPA = NULL;
-    tmpChip->fromFPA = NULL;
-    #endif
-
-    tmpChip->concepts = psMetadataAlloc();
-    tmpChip->conceptsRead = PM_CONCEPT_SOURCE_NONE;
-    psBool rc = psMetadataAddStr(tmpChip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, NULL, name);
-    if (rc == false) {
-        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CHIP.NAME to metadata.\n");
-    }
+    psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
+
     tmpChip->analysis = psMetadataAlloc();
     tmpChip->cells = psArrayAlloc(0);
-    #if PARENT_LINKS
-
-    tmpChip->parent = psMemIncrRefCounter(fpa);
-    #else
-
     tmpChip->parent = fpa;
-    #endif
-
     if (fpa != NULL) {
         fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
     }
+    tmpChip->hdu = NULL;
+    tmpChip->mosaic = NULL;
     tmpChip->process = true;            // Work on all chips, by default
     tmpChip->file_exists = false;       // Not yet identified
     tmpChip->data_exists = false;       // Not yet read in
-    tmpChip->hdu = NULL;
-
+
+    if (!psMetadataAddStr(tmpChip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, NULL, name)) {
+        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CHIP.NAME %s to concepts.\n", name);
+    }
+    tmpChip->concepts = psMetadataAlloc();
+    tmpChip->conceptsRead = PM_CONCEPT_SOURCE_NONE;
     pmConceptsBlankChip(tmpChip);
 
-    psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
     return(tmpChip);
 }
@@ -346,14 +246,6 @@
 {
     pmFPA *tmpFPA = (pmFPA *) psAlloc(sizeof(pmFPA));
-
-    #if 0
-
-    tmpFPA->fromTangentPlane = NULL;
-    tmpFPA->toTangentPlane = NULL;
-    tmpFPA->projection = NULL;
-    #endif
-
-    tmpFPA->concepts = psMetadataAlloc();
-    tmpFPA->conceptsRead = PM_CONCEPT_SOURCE_NONE;
+    psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
+
     tmpFPA->analysis = NULL;
     tmpFPA->camera = psMemIncrRefCounter((psPtr)camera);
@@ -361,7 +253,8 @@
     tmpFPA->hdu = NULL;
 
+    tmpFPA->concepts = psMetadataAlloc();
+    tmpFPA->conceptsRead = PM_CONCEPT_SOURCE_NONE;
     pmConceptsBlankFPA(tmpFPA);
 
-    psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
     return(tmpFPA);
 }
@@ -369,5 +262,5 @@
 static psBool cellCheckParents(pmCell *cell)
 {
-    if (cell == NULL) {
+    if (!cell) {
         return(true);
     }
@@ -387,5 +280,5 @@
 static psBool chipCheckParents(pmChip *chip)
 {
-    if (chip == NULL) {
+    if (!chip) {
         return(true);
     }
@@ -407,5 +300,5 @@
 psBool pmFPACheckParents(pmFPA *fpa)
 {
-    if (fpa == NULL) {
+    if (!fpa) {
         return(true);
     }
