Index: /branches/rel10_ifa/psModules/src/astrom/pmChipMosaic.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmChipMosaic.c	(revision 6742)
+++ /branches/rel10_ifa/psModules/src/astrom/pmChipMosaic.c	(revision 6743)
@@ -358,7 +358,7 @@
         }
 
-        numChips++;
-        pmChipMosaic(chip, xBinChip, yBinChip); // Mosaic of cells within the chip
-
+        if (pmChipMosaic(chip, xBinChip, yBinChip) > 0) {
+            numChips++;
+        }
     }
 
Index: /branches/rel10_ifa/psModules/src/astrom/pmConceptsStandard.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmConceptsStandard.c	(revision 6742)
+++ /branches/rel10_ifa/psModules/src/astrom/pmConceptsStandard.c	(revision 6743)
@@ -489,5 +489,5 @@
 
     // Otherwise, there's no formatting required
-    return concept;
+    return psMemIncrRefCounter(concept);
 }
 
@@ -508,5 +508,5 @@
 
     // No formatting required
-    return concept;
+    return psMemIncrRefCounter(concept);
 }
 
@@ -561,9 +561,9 @@
         if (strstr(format, "PRE2000")) {
             psError(PS_ERR_IO, true, "Don't you realise it's the twenty-first century?\n");
-            return false;
+            return NULL;
         }
         if (strstr(format, "BACKWARDS")) {
             psError(PS_ERR_IO, true, "You want it BACKWARDS?  Not right now, thanks.\n");
-            return false;
+            return NULL;
         }
 
Index: /branches/rel10_ifa/psModules/src/astrom/pmConceptsWrite.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmConceptsWrite.c	(revision 6742)
+++ /branches/rel10_ifa/psModules/src/astrom/pmConceptsWrite.c	(revision 6743)
@@ -204,7 +204,5 @@
                         psTrace(__func__, 8, "Writing %s to header %s\n", name, cameraItem->data.V);
                         writeHeader(hdu, cameraItem->data.V, formatted);
-                        continue;
-                    }
-                    if (strcasecmp(source, "VALUE") == 0) {
+                    } else if (strcasecmp(source, "VALUE") == 0) {
                         psTrace(__func__, 8, "Checking %s against camera format.\n", name);
                         if (! compareConcepts(cameraItem, formatted)) {
@@ -212,15 +210,15 @@
                                      "format, but the values don't match.\n", name);
                         }
-                        continue;
+                    } else {
+                        psLogMsg(__func__, PS_LOG_WARN, "Concept source %s isn't HEADER or VALUE --- can't "
+                                 "write\n", nameSource);
                     }
-                    psLogMsg(__func__, PS_LOG_WARN, "Concept source %s isn't HEADER or VALUE --- can't "
-                             "write\n", nameSource);
-                    continue;
-                }
-                // Assume it's specified by value
-                if (! compareConcepts(cameraItem, formatted)) {
+                } else if (! compareConcepts(cameraItem, formatted)) {
+                    // Assume it's specified by value
                     psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera "
                              "format, but the values don't match.\n", name);
                 }
+                psFree(formatted);
+                psFree(nameSource);
             }
 
@@ -232,5 +230,5 @@
 }
 
-
+// XXX: Needs the .DEPEND stuff
 bool pmConceptsWriteToDefaults(psMetadata *specs, // The concept specifications
                                pmFPA *fpa, // The FPA
@@ -266,4 +264,5 @@
                              "format, but the values don't match.\n");
                 }
+                psFree(formatted);
             }
         }
@@ -331,4 +330,6 @@
                     writeHeader(hdu, keyword, formatted);
                 }
+                psFree(formatted);
+                psFree(keywords);
             }
         }
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPA.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPA.c	(revision 6742)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPA.c	(revision 6743)
@@ -12,6 +12,6 @@
 * XXX: Should we implement non-linear cell->chip transforms?
 *
-*  @version $Revision: 1.1.4.5 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-03-28 02:16:26 $
+*  @version $Revision: 1.1.4.6 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-03-31 01:33:07 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -38,109 +38,103 @@
 static void readoutFree(pmReadout *readout)
 {
-    if (readout != NULL) {
-        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, "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);
-        psFree(readout->weight);
-        psFree(readout->analysis);
-        psFree(readout->bias);
-    }
+    }
+    psTrace(__func__, 9, "Freeing readout %lx\n", (size_t) readout);
+
+    #if PARENT_LINKS
+
+    psFree(readout->parent);
+    #endif
+
+    psFree(readout->image);
+    psFree(readout->mask);
+    psFree(readout->weight);
+    psFree(readout->analysis);
+    psFree(readout->bias);
 }
 
 static void cellFree(pmCell *cell)
 {
-    if (cell != NULL) {
-        psTrace(__func__, 9, "Removing cell %lx from chip %lx...\n", (size_t)cell, (size_t)cell->parent);
-        if (cell->parent) {
-            psArray *cells = cell->parent->cells;
-            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, "Removing cell %lx from chip %lx...\n", (size_t)cell, (size_t)cell->parent);
+    if (cell->parent) {
+        psArray *cells = cell->parent->cells;
+        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);
-        psFree(cell->analysis);
-        psFree(cell->config);
-        psFree(cell->hdu);
-    }
+    }
+    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);
+    psFree(cell->analysis);
+    psFree(cell->config);
+    psFree(cell->hdu);
 }
 
 static void chipFree(pmChip* chip)
 {
-    if (chip != NULL) {
-        psTrace(__func__, 9, "Removing chip %lx from fpa %lx...\n", (size_t)chip, (size_t)chip->parent);
-        if (chip->parent) {
-            psArray *chips = chip->parent->chips;
-            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, "Removing chip %lx from fpa %lx...\n", (size_t)chip, (size_t)chip->parent);
+    if (chip->parent) {
+        psArray *chips = chip->parent->chips;
+        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);
-    }
+    }
+    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);
 }
 
@@ -148,35 +142,33 @@
 static void FPAFree(pmFPA *fpa)
 {
-    if (fpa != NULL) {
-        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++) {
-            pmChip *tmpChip = chips->data[i];
-            if (! tmpChip) {
-                continue;
-            }
-            chips->data[i] = NULL;
-            tmpChip->parent = NULL;
-            if (PS_FREE_HIERARCHY == 1) {
-                psFree(tmpChip);
-            }
-        }
-        psFree(fpa->chips);
-        psFree(fpa->hdu);
-    }
+    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++) {
+        pmChip *tmpChip = chips->data[i];
+        if (! tmpChip) {
+            continue;
+        }
+        chips->data[i] = NULL;
+        tmpChip->parent = NULL;
+        if (PS_FREE_HIERARCHY == 1) {
+            psFree(tmpChip);
+        }
+    }
+    psFree(fpa->chips);
+    psFree(fpa->hdu);
 }
 
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c	(revision 6742)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c	(revision 6743)
@@ -373,10 +373,10 @@
 
                 // Put in the extension
-                if (chip->hdu) {
-                    if (chip->hdu != hdu) {
-                        psLogMsg(__func__, PS_LOG_WARN, "Overwriting HDU in chip %s\n", chipName);
-                        psFree(chip->hdu);  // Make way!
-                    }
-                } else {
+                if (chip->hdu && chip->hdu != hdu) {
+                    psLogMsg(__func__, PS_LOG_WARN, "Overwriting HDU in chip %s\n", chipName);
+                    psFree(chip->hdu);  // Make way!
+                    chip->hdu = NULL;
+                }
+                if (!chip->hdu) {
                     chip->hdu = psMemIncrRefCounter(hdu);
                 }
@@ -437,11 +437,11 @@
 
                 // Put in the extension
-                if (cell->hdu) {
-                    if (cell->hdu != hdu) {
-                        psLogMsg(__func__, PS_LOG_WARN, "Overwriting HDU in chip %s, cell %s\n", chipName,
-                                 cellName);
-                        psFree(cell->hdu);
-                    }
-                } else {
+                if (cell->hdu && cell->hdu != hdu) {
+                    psLogMsg(__func__, PS_LOG_WARN, "Overwriting HDU in chip %s, cell %s\n", chipName,
+                             cellName);
+                    psFree(cell->hdu);
+                    cell->hdu = NULL;
+                }
+                if (! cell->hdu) {
                     cell->hdu = psMemIncrRefCounter(hdu);
                 }
Index: /branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c	(revision 6742)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c	(revision 6743)
@@ -307,6 +307,4 @@
     // Get the size of the HDU, either from existing trimsec and biassec, or generate these and try again
     int xSize = 0, ySize = 0;           // Size of HDU
-    #if 1
-
     if (!sizeHDU(&xSize, &ySize, targetCells) && !(generateTrimBias(targetCells, sourceCells) &&
             sizeHDU(&xSize, &ySize, targetCells))) {
@@ -314,17 +312,6 @@
         return false;
     }
-    #else
-    if (!sizeHDU(&xSize, &ySize, targetCells)) {
-        if (generateTrimBias(targetCells, sourceCells)) {
-            if (!sizeHDU(&xSize, &ySize, targetCells)) {
-                psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n");
-                return false;
-            }
-        } else {
-            psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n");
-            return false;
-        }
-    }
-    #endif
+    psFree(targetCells);
+    psFree(sourceCells);
 
     hdu->images = psArrayAlloc(numReadouts);
@@ -509,5 +496,5 @@
         } else {
             copyPixels(hdu->images->data[i], sourceImage, *trimsec, xFlip, yFlip);
-            targetReadout->image = psMemIncrRefCounter(psImageSubset(hdu->images->data[i], *trimsec));
+            targetReadout->image = psImageSubset(hdu->images->data[i], *trimsec);
         }
 
@@ -532,9 +519,10 @@
             } else {
                 copyPixels(hdu->images->data[i], bias, *biassec, xFlip, yFlip);
-                psImage *newBias = psMemIncrRefCounter(psImageSubset(hdu->images->data[i], *biassec));
+                psImage *newBias = psImageSubset(hdu->images->data[i], *biassec);
                 psListAdd(targetReadout->bias, PS_LIST_TAIL, newBias);
                 psFree(newBias);        // Drop reference
             }
         }
+        psFree(targetReadout);          // Drop reference
         psFree(biassecsIter);
         psFree(biasIter);
@@ -551,4 +539,5 @@
         }
     }
+    psFree(conceptsIter);
 
     // Need to update CELL.X0 and CELL.Y0 if we flipped
