Index: /trunk/psModules/src/camera/pmChipMosaic.c
===================================================================
--- /trunk/psModules/src/camera/pmChipMosaic.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmChipMosaic.c	(revision 7278)
@@ -41,4 +41,7 @@
                           )
 {
+    assert(bounds);
+    assert(chip);
+
     if (primary) {
         *bounds = psRegionSet(INFINITY, 0, INFINITY, 0);
@@ -104,4 +107,8 @@
                          )
 {
+    assert(xBinChip);
+    assert(yBinChip);
+    assert(chip);
+
     // Check that we've got the HDU in the chip or the FPA
     if ((!chip->hdu || !chip->hdu->images) && (!chip->parent->hdu || !chip->parent->hdu->images)) {
@@ -358,4 +365,9 @@
                         )
 {
+    assert(target);
+    assert(sources);
+    assert(xBin > 0 && yBin > 0);
+    assert(trimsec);
+
     bool success = true;                // Result of setting everything
     float gain       = 0.0;             // Gain
@@ -433,5 +445,4 @@
     }
 
-
     return success;
 }
@@ -446,4 +457,9 @@
                )
 {
+    assert(mosaicImage);
+    assert(mosaicMask);
+    assert(mosaicWeights);
+    assert(chip);
+
     psArray *cells = chip->cells;       // The array of cells
     int numCells = cells->n;            // Number of cells
@@ -587,4 +603,6 @@
                  )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+
     psImage *mosaicImage   = NULL;      // The mosaic image
     psImage *mosaicMask    = NULL;      // The mosaic mask
Index: /trunk/psModules/src/camera/pmFPA.c
===================================================================
--- /trunk/psModules/src/camera/pmFPA.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPA.c	(revision 7278)
@@ -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-06-01 22:43:26 $
+*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-06-02 00:55:22 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -399,5 +399,5 @@
 }
 
-bool pmChipSetFileStatus pmChip *chip, bool status)
+bool pmChipSetFileStatus(pmChip *chip, bool status)
 {
     PS_ASSERT_PTR_NON_NULL(chip, false);
Index: /trunk/psModules/src/camera/pmFPAConstruct.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAConstruct.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPAConstruct.c	(revision 7278)
@@ -21,4 +21,7 @@
                               )
 {
+    assert(format);
+    assert(cellName && strlen(cellName) > 0);
+
     bool status = true;                 // Result of MD lookup
     psMetadata *cells = psMetadataLookupMD(&status, format, "CELLS"); // The CELLS
@@ -43,4 +46,9 @@
                         )
 {
+    assert(first);
+    assert(second);
+    assert(third);
+    assert(string && strlen(string) > 0);
+
     bool allOK = true;                  // Everything was OK?
     psList *values = psStringSplit(string, " ,;", true); // List of the parts
@@ -96,4 +104,8 @@
                                  )
 {
+    assert(name && strlen(name) > 0);
+    assert(fileInfo);
+    assert(header);
+
     bool mdok = true;                   // Result of MD lookup
     psString keyword = psMetadataLookupStr(&mdok, fileInfo, name);
@@ -188,4 +200,8 @@
                              )
 {
+    assert(fileInfo);
+    assert(contents);
+    assert(header);
+
     bool mdok = true;                   // Status of MD lookup
     const char *contentHeaders = psMetadataLookupStr(&mdok, fileInfo, "CONTENT"); // Headers for content
@@ -237,4 +253,5 @@
     assert(contents && strlen(contents) > 0);
     assert(!cell || (cell && chip));    // Need both chip and cell if given a cell
+    assert(format);
 
     if (hdu && level == PM_FPA_LEVEL_FPA) {
@@ -329,4 +346,6 @@
                           )
 {
+    assert(format);
+
     bool mdok = true;                   // Status of MD lookup
     psMetadata *file = psMetadataLookupMD(&mdok, format, "FILE"); // File information
@@ -363,4 +382,6 @@
                      )
 {
+    PS_ASSERT_PTR_NON_NULL(camera, NULL);
+
     pmFPA *fpa = pmFPAAlloc(camera);    // The FPA to fill out
 
@@ -400,7 +421,7 @@
                            )
 {
-    assert(fpa);
-    assert(phuView);
-    assert(format);
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(phuView, false);
+    PS_ASSERT_PTR_NON_NULL(format, false);
 
     // Where does the PHU go?
@@ -495,7 +516,7 @@
                                    )
 {
-    assert(fpa);
-    assert(phu);
-    assert(format);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
+    PS_ASSERT_PTR_NON_NULL(phu, NULL);
+    PS_ASSERT_PTR_NON_NULL(format, NULL);
 
     bool mdok = true;                   // Status from metadata lookups
@@ -689,4 +710,6 @@
                )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa,);
+
     psTrace(__func__, 1, "FPA:\n");
     if (fpa->hdu) {
Index: /trunk/psModules/src/camera/pmFPACopy.c
===================================================================
--- /trunk/psModules/src/camera/pmFPACopy.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPACopy.c	(revision 7278)
@@ -24,4 +24,6 @@
                           )
 {
+    assert(source);
+
     psImage *copy = psMemIncrRefCounter(source);
     bool copied = false;                // Have the pixels been copied?
@@ -51,4 +53,8 @@
                      )
 {
+    assert(region);
+    assert(xBin > 0);
+    assert(yBin > 0);
+
     // Want to include the lower bound: 1 binned by 4 --> 0; 3 binned by 4 --> 0; 4 binned by 4 --> 1
     region->x0 = (int)(region->x0 / xBin);
@@ -62,4 +68,6 @@
                      )
 {
+    assert(cell);
+
     if (cell->hdu && cell->hdu->phu) {
         return cell->hdu;
@@ -274,4 +282,6 @@
     assert(target);
     assert(source);
+    assert(xBin > 0);
+    assert(yBin > 0);
 
     psArray *targetCells = target->cells; // The target cells
@@ -300,12 +310,14 @@
 }
 
-static int fpaCopy(pmFPA *target,            // The target FPA
-                   pmFPA *source,            // The source FPA, to be copied
-                   bool pixels,              // Copy the pixels?
-                   int xBin, int yBin        // (Relative) binning factors in x and y
-                  )
+static bool fpaCopy(pmFPA *target,            // The target FPA
+                    pmFPA *source,            // The source FPA, to be copied
+                    bool pixels,              // Copy the pixels?
+                    int xBin, int yBin        // (Relative) binning factors in x and y
+                   )
 {
     assert(target);
     assert(source);
+    assert(xBin > 0);
+    assert(yBin > 0);
 
     psArray *targetChips = target->chips; // The target chips
@@ -338,47 +350,65 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-int pmFPACopy(pmFPA *target,            // The target FPA
-              pmFPA *source             // The source FPA, to be copied
-             )
-{
+bool pmFPACopy(pmFPA *target,            // The target FPA
+               pmFPA *source             // The source FPA, to be copied
+              )
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
     return fpaCopy(target, source, true, 1, 1);
 }
 
-int pmChipCopy(pmChip *target,          // The target chip
-               pmChip *source           // The source chip, to be copied
-              )
-{
+bool pmChipCopy(pmChip *target,          // The target chip
+                pmChip *source           // The source chip, to be copied
+               )
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
     return chipCopy(target, source, true, 1, 1);
 }
 
-int pmCellCopy(pmCell *target,          // The target cell
-               pmCell *source           // The source cell, to be copied
-              )
-{
+bool pmCellCopy(pmCell *target,          // The target cell
+                pmCell *source           // The source cell, to be copied
+               )
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
     return cellCopy(target, source, true, 1, 1);
 }
 
 
-int pmFPACopyStructure(pmFPA *target,   // The target FPA
-                       pmFPA *source,   // The source FPA, to be copied
-                       int xBin, int yBin // Binning factors in x and y
-                      )
-{
-    return fpaCopy(target, source, false, xBin, yBin);
-}
-
-int pmChipCopyStructure(pmChip *target, // The target chip
-                        pmChip *source, // The source chip, to be copied
+bool pmFPACopyStructure(pmFPA *target,   // The target FPA
+                        pmFPA *source,   // The source FPA, to be copied
                         int xBin, int yBin // Binning factors in x and y
                        )
 {
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_INT_POSITIVE(xBin, false);
+    PS_ASSERT_INT_POSITIVE(yBin, false);
+    return fpaCopy(target, source, false, xBin, yBin);
+}
+
+bool pmChipCopyStructure(pmChip *target, // The target chip
+                         pmChip *source, // The source chip, to be copied
+                         int xBin, int yBin // Binning factors in x and y
+                        )
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_INT_POSITIVE(xBin, false);
+    PS_ASSERT_INT_POSITIVE(yBin, false);
     return chipCopy(target, source, false, xBin, yBin);
 }
 
-int pmCellCopyStructure(pmCell *target, // The target cell
-                        pmCell *source, // The source cell, to be copied
-                        int xBin, int yBin // Binning factors in x and y
-                       )
-{
+bool pmCellCopyStructure(pmCell *target, // The target cell
+                         pmCell *source, // The source cell, to be copied
+                         int xBin, int yBin // Binning factors in x and y
+                        )
+{
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+    PS_ASSERT_INT_POSITIVE(xBin, false);
+    PS_ASSERT_INT_POSITIVE(yBin, false);
     return cellCopy(target, source, false, xBin, yBin);
 }
Index: /trunk/psModules/src/camera/pmFPACopy.h
===================================================================
--- /trunk/psModules/src/camera/pmFPACopy.h	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPACopy.h	(revision 7278)
@@ -3,27 +3,27 @@
 
 // Copy the FPA components, including the pixels
-int pmFPACopy(pmFPA *target,            // The target FPA
-              pmFPA *source             // The source FPA, to be copied
-             );
-int pmChipCopy(pmChip *target,          // The target chip
-               pmChip *source           // The source chip, to be copied
+bool pmFPACopy(pmFPA *target,            // The target FPA
+               pmFPA *source             // The source FPA, to be copied
               );
-int pmCellCopy(pmCell *target,          // The target cell
-               pmCell *source           // The source cell, to be copied
-              );
+bool pmChipCopy(pmChip *target,          // The target chip
+                pmChip *source           // The source chip, to be copied
+               );
+bool pmCellCopy(pmCell *target,          // The target cell
+                pmCell *source           // The source cell, to be copied
+               );
 
 // Versions that copy the structure and not the pixels; they also allow binning
-int pmFPACopyStructure(pmFPA *target,   // The target FPA
-                       pmFPA *source,   // The source FPA, to be copied
-                       int xBin, int yBin     // Binning factors in x and y
-                      );
-int pmChipCopyStructure(pmChip *target, // The target chip
-                        pmChip *source, // The source chip, to be copied
-                        int xBin, int yBin   // Binning factors in x and y
+bool pmFPACopyStructure(pmFPA *target,   // The target FPA
+                        pmFPA *source,   // The source FPA, to be copied
+                        int xBin, int yBin     // Binning factors in x and y
                        );
-int pmCellCopyStructure(pmCell *target, // The target cell
-                        pmCell *source, // The source cell, to be copied
-                        int xBin, int yBin // Binning factors in x and y
-                       );
+bool pmChipCopyStructure(pmChip *target, // The target chip
+                         pmChip *source, // The source chip, to be copied
+                         int xBin, int yBin   // Binning factors in x and y
+                        );
+bool pmCellCopyStructure(pmCell *target, // The target cell
+                         pmCell *source, // The source cell, to be copied
+                         int xBin, int yBin // Binning factors in x and y
+                        );
 
 
Index: /trunk/psModules/src/camera/pmFPAHeader.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAHeader.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPAHeader.c	(revision 7278)
@@ -15,4 +15,6 @@
                         )
 {
+    assert(chip);
+
     bool status = true;                 // Status of concept reading
     status |= pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_HEADER, false, NULL);
@@ -33,4 +35,6 @@
                        )
 {
+    assert(fpa);
+
     bool status = true;                 // Status of concept reading
     status |= pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, NULL);
Index: /trunk/psModules/src/camera/pmFPARead.c
===================================================================
--- /trunk/psModules/src/camera/pmFPARead.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPARead.c	(revision 7278)
@@ -27,4 +27,9 @@
                         )
 {
+    assert(readout);
+    assert(image);
+    assert(trimsec);
+    assert(biassecs);
+
     // The image corresponding to the trim region
     if (psRegionIsBad(*trimsec)) {
@@ -85,4 +90,7 @@
                              )
 {
+    assert(fits);
+    assert(region);
+
     bool resize = false;                // Do we need to resize the image once read?
     psRegion toRead = psRegionSet(region->x0, region->x1, region->y0, region->y1); // Region to read
@@ -158,4 +166,9 @@
                       )
 {
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+    PS_ASSERT_INT_NONNEGATIVE(z, false);
+    PS_ASSERT_INT_NONNEGATIVE(numScans, false);
+
     // Get the HDU and read the header
     pmCell *cell = readout->parent;     // The parent cell
@@ -298,4 +311,7 @@
                )
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
     pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
     if (!hdu) {
@@ -345,4 +361,7 @@
                )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
     bool success = false;               // Were we able to read at least one HDU?
     psArray *cells = chip->cells;       // Array of cells
@@ -366,4 +385,7 @@
               )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
     bool success = false;               // Were we able to read at least one HDU?
     psArray *chips = fpa->chips;        // Array of chips
Index: /trunk/psModules/src/camera/pmFPAUtils.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAUtils.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPAUtils.c	(revision 7278)
@@ -9,5 +9,11 @@
                  )
 {
-    psArray *chips = fpa->chips;    // Array of chips
+    PS_ASSERT_PTR_NON_NULL(fpa, -1);
+    PS_ASSERT_PTR_NON_NULL(name, -1);
+    if (strlen(name) == 0) {
+        return -1;
+    }
+
+    psArray *chips = fpa->chips;        // Array of chips
     for (int i = 0; i < chips->n; i++) {
         pmChip *chip = chips->data[i]; // The chip of interest
@@ -27,4 +33,10 @@
                   )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, -1);
+    PS_ASSERT_PTR_NON_NULL(name, -1);
+    if (strlen(name) == 0) {
+        return -1;
+    }
+
     psArray *cells = chip->cells;    // Array of cells
     for (int i = 0; i < cells->n; i++) {
Index: /trunk/psModules/src/camera/pmFPAWrite.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAWrite.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPAWrite.c	(revision 7278)
@@ -16,4 +16,7 @@
                        )
 {
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
     pmHDU *hdu = pmHDUFromReadout(readout); // The HDU to which to write
     if (!hdu) {
@@ -87,4 +90,7 @@
                 )
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
     pmHDU *hdu = cell->hdu;             // The HDU
     if (!hdu) {
@@ -118,4 +124,7 @@
                 )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
     pmHDU *hdu = chip->hdu;             // The HDU
     if (!hdu) {
@@ -156,4 +165,7 @@
                )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
     pmHDU *hdu = fpa->hdu;              // The HDU
     if (!hdu) {
Index: /trunk/psModules/src/camera/pmFPA_JPEG.c
===================================================================
--- /trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 7278)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-01 01:55:43 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:22 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,6 +28,8 @@
 
 
-bool pmFPAviewWriteJPEG (const pmFPAview *view, pmFPAfile *file)
+bool pmFPAviewWriteJPEG(const pmFPAview *view, pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
 
     pmFPA *fpa = file->fpa;
@@ -70,4 +72,7 @@
 bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
 
     for (int i = 0; i < fpa->chips->n; i++) {
@@ -82,4 +87,7 @@
 bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
 
     for (int i = 0; i < chip->cells->n; i++) {
@@ -94,4 +102,7 @@
 bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
 
     for (int i = 0; i < cell->readouts->n; i++) {
@@ -106,4 +117,8 @@
 bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+
     char *name, *mode, *word, *mapname;
     psArray *range;
Index: /trunk/psModules/src/camera/pmFPAfile.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfile.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPAfile.c	(revision 7278)
@@ -22,9 +22,9 @@
 #include "pmFPA_JPEG.h"
 
-static void pmFPAfileFree (pmFPAfile *file)
-{
-
-    if (file == NULL)
+static void pmFPAfileFree(pmFPAfile *file)
+{
+    if (!file) {
         return;
+    }
 
     psFree (file->fpa);
@@ -54,9 +54,8 @@
 }
 
-pmFPAfile *pmFPAfileAlloc ()
-{
-
-    pmFPAfile *file = psAlloc (sizeof(pmFPAfile));
-    psMemSetDeallocator (file, (psFreeFunc) pmFPAfileFree);
+pmFPAfile *pmFPAfileAlloc()
+{
+    pmFPAfile *file = psAlloc(sizeof(pmFPAfile));
+    psMemSetDeallocator(file, (psFreeFunc) pmFPAfileFree);
 
     file->phu = NULL;
@@ -83,9 +82,14 @@
     file->state = PM_FPA_STATE_CLOSED;
 
-    return (file);
-}
-
-pmFPAfile *pmFPAfileDefine (psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name)
-{
+    return file;
+}
+
+pmFPAfile *pmFPAfileDefine(psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name)
+{
+    PS_ASSERT_PTR_NON_NULL(files, NULL);
+    PS_ASSERT_PTR_NON_NULL(camera, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
+    PS_ASSERT_PTR_NON_NULL(name, NULL);
+    PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
 
     bool status;
@@ -243,4 +247,6 @@
 bool pmFPAfileOpen (pmFPAfile *file, const pmFPAview *view)
 {
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
 
     bool status;
@@ -325,6 +331,9 @@
 }
 
-bool pmFPAfileRead (pmFPAfile *file, const pmFPAview *view)
-{
+bool pmFPAfileRead(pmFPAfile *file, const pmFPAview *view)
+{
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     if (file->state & PM_FPA_STATE_INACTIVE)
         return false;
@@ -378,6 +387,8 @@
 }
 
-bool pmFPAfileWrite (pmFPAfile *file, const pmFPAview *view)
-{
+bool pmFPAfileWrite(pmFPAfile *file, const pmFPAview *view)
+{
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
 
     if (file->state & PM_FPA_STATE_INACTIVE) {
@@ -436,4 +447,7 @@
 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view)
 {
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     if (file->state & PM_FPA_STATE_INACTIVE) {
         return false;
@@ -478,4 +492,7 @@
 bool pmFPAfileClose (pmFPAfile *file, const pmFPAview *view)
 {
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     if (file->state & PM_FPA_STATE_INACTIVE) {
         return false;
@@ -524,5 +541,7 @@
 bool pmFPAfileActivate (psMetadata *files, bool state, char *name)
 {
-    if (name == NULL) {
+    PS_ASSERT_PTR_NON_NULL(files, false);
+
+    if (!name) {
         psMetadataItem *item = NULL;
         psMetadataIterator *iter = psMetadataIteratorAlloc (files, PS_LIST_HEAD, NULL);
@@ -555,4 +574,7 @@
 bool pmFPAfileIOChecks (psMetadata *files, const pmFPAview *view, pmFPAfilePlace place)
 {
+    PS_ASSERT_PTR_NON_NULL(files, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     // recipe override values (command-line options):
     psMetadataItem *item = NULL;
@@ -577,6 +599,10 @@
 pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type)
 {
-    pmReadout *readout = pmReadoutAlloc (NULL);
-    readout->image = psImageAlloc (Nx, Ny, type);
+    PS_ASSERT_PTR_NON_NULL(files, false);
+    PS_ASSERT_PTR_NON_NULL(name, false);
+    PS_ASSERT_INT_POSITIVE(strlen(name), false);
+
+    pmReadout *readout = pmReadoutAlloc(NULL);
+    readout->image = psImageAlloc(Nx, Ny, type);
 
     // I want an image from the
@@ -585,13 +611,17 @@
 
     file->readout = readout;
-    psMetadataAddPtr (files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
-    psFree (file);
+    psMetadataAddPtr(files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
+    psFree(file);
     // we free this copy of file, but 'files' still has a copy
 
-    return (readout);
-}
-
-bool pmFPAfileDropInternal (psMetadata *files, char *name)
-{
+    return readout;
+}
+
+bool pmFPAfileDropInternal(psMetadata *files, char *name)
+{
+    PS_ASSERT_PTR_NON_NULL(files, false);
+    PS_ASSERT_PTR_NON_NULL(name, false);
+    PS_ASSERT_INT_POSITIVE(strlen(name), false);
+
     bool status;
 
@@ -610,4 +640,9 @@
 pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name)
 {
+    PS_ASSERT_PTR_NON_NULL(files, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(name, false);
+    PS_ASSERT_INT_POSITIVE(strlen(name), false);
+
     bool status;
 
@@ -629,4 +664,7 @@
 bool pmFPAviewReadFitsImage (const pmFPAview *view, pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+
     bool status;
     pmFPA *fpa = file->fpa;
@@ -680,4 +718,6 @@
 bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file)
 {
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
 
     pmFPA *fpa = file->fpa;
@@ -748,4 +788,10 @@
 pmFPAfile *pmFPAfileFromArgs (bool *found, pmConfig *config, char *filename, char *argname)
 {
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
+    PS_ASSERT_INT_POSITIVE(strlen(filename), false);
+    PS_ASSERT_PTR_NON_NULL(argname, false);
+    PS_ASSERT_INT_POSITIVE(strlen(argname), false);
+
     bool status;
     pmFPA *fpa = NULL;
@@ -755,13 +801,16 @@
     psMetadata *format = NULL;
 
-    if (*found)
-        return NULL;
+    if (*found) {
+        return NULL;
+    }
 
     // we search the argument data for the named fileset (argname)
     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
-    if (!status)
-        return NULL;
-    if (infiles->n < 1)
-        return NULL;
+    if (!status) {
+        return NULL;
+    }
+    if (infiles->n < 1) {
+        return NULL;
+    }
 
     // determine the current format from the header
@@ -836,4 +885,10 @@
 pmFPAfile *pmFPAfileSetFromArgs (bool *found, pmConfig *config, char *filename, char *argname)
 {
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
+    PS_ASSERT_INT_POSITIVE(strlen(filename), false);
+    PS_ASSERT_PTR_NON_NULL(argname, false);
+    PS_ASSERT_INT_POSITIVE(strlen(argname), false);
+
     bool status;
     pmFPA *fpa = NULL;
@@ -848,8 +903,10 @@
     // we search the argument data for the named fileset (argname)
     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
-    if (!status)
-        return NULL;
-    if (infiles->n < 1)
-        return NULL;
+    if (!status) {
+        return NULL;
+    }
+    if (infiles->n < 1) {
+        return NULL;
+    }
 
     // determine the current format from the header
@@ -914,4 +971,9 @@
 pmFPAfile *pmFPAfileFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, char *filename)
 {
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(src, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
+    PS_ASSERT_INT_POSITIVE(strlen(filename), false);
+
     // XXX pmFPAConstruct has many leaks (6919)
     pmFPA *fpa = pmFPAConstruct (config->camera);
@@ -928,4 +990,9 @@
 pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input)
 {
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(filename, false);
+    PS_ASSERT_INT_POSITIVE(strlen(filename), false);
+    PS_ASSERT_PTR_NON_NULL(input, false);
+
     psFits *fits = NULL;
     pmFPAfile *file = NULL;
@@ -934,6 +1001,7 @@
     psArray *infiles = NULL;
 
-    if (*found)
-        return NULL;
+    if (*found) {
+        return NULL;
+    }
 
     // a camera config is needed (as source of file rule)
@@ -951,6 +1019,7 @@
 
     // image names come from the file->name list?
-    if (!strcasecmp (file->filerule, "@FILES"))
+    if (!strcasecmp (file->filerule, "@FILES")) {
         psAbort ("pmFPAfileFromConfig", "programming error");
+    }
 
     // image needs to come from the detrend database
@@ -964,6 +1033,7 @@
         infiles->data[0] = psStringCopy (file->filerule);
     }
-    if (infiles == NULL)
-        return NULL;
+    if (infiles == NULL) {
+        return NULL;
+    }
     if (infiles->n < 1) {
         psFree (infiles);
@@ -1018,4 +1088,9 @@
 bool pmFPAfileAddFileNames (psMetadata *files, char *name, char *value, int mode)
 {
+    PS_ASSERT_PTR_NON_NULL(files, false);
+    PS_ASSERT_PTR_NON_NULL(name, false);
+    PS_ASSERT_INT_POSITIVE(strlen(name), false);
+    PS_ASSERT_PTR_NON_NULL(value, false);
+    PS_ASSERT_INT_POSITIVE(strlen(value), false);
 
     // add the output names to the output-type files
@@ -1036,4 +1111,8 @@
 char *pmFPAfileNameFromRule (char *rule, pmFPAfile *file, const pmFPAview *view)
 {
+    PS_ASSERT_PTR_NON_NULL(rule, NULL);
+    PS_ASSERT_INT_POSITIVE(strlen(rule), NULL);
+    PS_ASSERT_PTR_NON_NULL(file, NULL);
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
 
     char *newName = NULL;     // destination for resulting name
@@ -1078,4 +1157,8 @@
 bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view)
 {
+    PS_ASSERT_PTR_NON_NULL(out, false);
+    PS_ASSERT_PTR_NON_NULL(in, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     // pmFPAWrite takes care of all PHUs as needed
     if (view->chip == -1) {
@@ -1112,4 +1195,9 @@
 bool pmFPAfileCopyStructureView (pmFPA *out, pmFPA *in, psMetadata *format, int xBin, int yBin, const pmFPAview *view)
 {
+    PS_ASSERT_PTR_NON_NULL(out, false);
+    PS_ASSERT_PTR_NON_NULL(in, false);
+    PS_ASSERT_PTR_NON_NULL(format, false);
+    PS_ASSERT_PTR_NON_NULL(view, false);
+
     // pmFPAWrite takes care of all PHUs as needed
     if (view->chip == -1) {
Index: /trunk/psModules/src/camera/pmFPAview.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAview.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmFPAview.c	(revision 7278)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-01 01:55:43 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:22 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -19,15 +19,14 @@
 #include "pmFPAview.h"
 
-static void pmFPAviewFree (pmFPAview *view)
-{
-    if (view == NULL)
-        return;
+static void pmFPAviewFree(pmFPAview *view)
+{
+    // No reason to keep this function, apart from the fact that it allows us to type the memBlock
     return;
 }
 
-pmFPAview *pmFPAviewAlloc (int nRows)
-{
-    pmFPAview *view = psAlloc (sizeof(pmFPAview));
-    psMemSetDeallocator (view, (psFreeFunc) pmFPAviewFree);
+pmFPAview *pmFPAviewAlloc(int nRows)
+{
+    pmFPAview *view = psAlloc(sizeof(pmFPAview));
+    psMemSetDeallocator(view, (psFreeFunc) pmFPAviewFree);
 
     view->chip    = -1;
@@ -36,9 +35,10 @@
     view->iRows   =  0;
     view->nRows   = nRows;
-    return (view);
-}
-
-pmFPAdepth pmFPAviewDepth (const pmFPAview *view)
-{
+    return view;
+}
+
+pmFPAdepth pmFPAviewDepth(const pmFPAview *view)
+{
+    PS_ASSERT_PTR_NON_NULL(view, PM_FPA_DEPTH_NONE);
 
     if (view->chip < 0) {
@@ -54,6 +54,8 @@
 }
 
-pmChip *pmFPAviewThisChip (const pmFPAview *view, pmFPA *fpa)
-{
+pmChip *pmFPAviewThisChip(const pmFPAview *view, pmFPA *fpa)
+{
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
 
     if (view->chip < 0) {
@@ -69,6 +71,9 @@
 }
 
-pmChip *pmFPAviewNextChip (pmFPAview *view, pmFPA *fpa, int nStep)
-{
+pmChip *pmFPAviewNextChip(pmFPAview *view, pmFPA *fpa, int nStep)
+{
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
+
     view->cell = -1;
     view->readout = -1;
@@ -100,6 +105,8 @@
 }
 
-pmCell *pmFPAviewThisCell (const pmFPAview *view, pmFPA *fpa)
-{
+pmCell *pmFPAviewThisCell(const pmFPAview *view, pmFPA *fpa)
+{
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
 
     if (view->cell < 0) {
@@ -108,7 +115,5 @@
 
     pmChip *chip = pmFPAviewThisChip (view, fpa);
-    if (chip == NULL) {
-        return NULL;
-    }
+    PS_ASSERT_PTR_NON_NULL(chip, NULL);
 
     if (view->cell >= chip->cells->n) {
@@ -122,9 +127,9 @@
 pmCell *pmFPAviewNextCell (pmFPAview *view, pmFPA *fpa, int nStep)
 {
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
 
     pmChip *chip = pmFPAviewThisChip (view, fpa);
-    if (chip == NULL) {
-        return NULL;
-    }
+    PS_ASSERT_PTR_NON_NULL(chip, NULL);
 
     view->readout = -1;
@@ -158,4 +163,6 @@
 pmReadout *pmFPAviewThisReadout (const pmFPAview *view, pmFPA *fpa)
 {
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
 
     if (view->readout < 0) {
@@ -164,7 +171,5 @@
 
     pmCell *cell = pmFPAviewThisCell (view, fpa);
-    if (cell == NULL) {
-        return NULL;
-    }
+    PS_ASSERT_PTR_NON_NULL(cell, NULL);
 
     if (view->readout >= cell->readouts->n) {
@@ -178,9 +183,9 @@
 pmReadout *pmFPAviewNextReadout (pmFPAview *view, pmFPA *fpa, int nStep)
 {
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
 
     pmCell *cell = pmFPAviewThisCell (view, fpa);
-    if (cell == NULL) {
-        return NULL;
-    }
+    PS_ASSERT_PTR_NON_NULL(cell, NULL);
 
     view->iRows = 0;
@@ -211,6 +216,9 @@
 }
 
-pmHDU *pmFPAviewThisHDU (const pmFPAview *view, pmFPA *fpa)
-{
+pmHDU *pmFPAviewThisHDU(const pmFPAview *view, pmFPA *fpa)
+{
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
+
     // the HDU is attached to a cell, chip or fpa
     // if this view has a -1 for the level which contains the hdu,
@@ -229,6 +237,9 @@
 }
 
-pmHDU *pmFPAviewThisPHU (const pmFPAview *view, pmFPA *fpa)
-{
+pmHDU *pmFPAviewThisPHU(const pmFPAview *view, pmFPA *fpa)
+{
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
+
     // select the HDU which corresponds to the PHU containing this view
 
Index: /trunk/psModules/src/camera/pmHDU.c
===================================================================
--- /trunk/psModules/src/camera/pmHDU.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmHDU.c	(revision 7278)
@@ -61,5 +61,5 @@
     psMemSetDeallocator(hdu, (psFreeFunc)hduFree);
 
-    if (! extname || strlen(extname) == 0) {
+    if (!extname || strlen(extname) == 0) {
         hdu->phu = true;
         hdu->extname = psStringCopy("PHU");
@@ -86,6 +86,6 @@
                     )
 {
-    assert(hdu);
-    assert(fits);
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
 
     // Move to the appropriate extension
@@ -113,6 +113,6 @@
               )
 {
-    assert(hdu);
-    assert(fits);
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
 
     // Read the header; includes the move
@@ -159,6 +159,6 @@
                )
 {
-    assert(hdu);
-    assert(fits);
+    PS_ASSERT_PTR_NON_NULL(hdu, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
 
     psTrace(__func__, 7, "Writing HDU %s\n", hdu->extname);
Index: /trunk/psModules/src/camera/pmHDUGenerate.c
===================================================================
--- /trunk/psModules/src/camera/pmHDUGenerate.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmHDUGenerate.c	(revision 7278)
@@ -437,4 +437,6 @@
                          )
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+
     // Get the HDU and a list of cells below it
     pmHDU *hdu = pmHDUFromCell(cell); // The HDU in the cell
@@ -487,4 +489,6 @@
                          )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+
     // Get the HDU and a list of cells below it
     pmHDU *hdu = pmHDUFromChip(chip);   // The HDU in the chip
@@ -536,4 +540,6 @@
                         )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+
     // Get the HDU and a list of cells below it
     pmHDU *hdu = pmHDUFromFPA(fpa);     // The HDU in the FPA
Index: /trunk/psModules/src/camera/pmHDUUtils.c
===================================================================
--- /trunk/psModules/src/camera/pmHDUUtils.c	(revision 7277)
+++ /trunk/psModules/src/camera/pmHDUUtils.c	(revision 7278)
@@ -8,4 +8,5 @@
                    )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
     return fpa->hdu;
 }
@@ -14,4 +15,6 @@
                     )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, NULL);
+
     pmHDU *hdu = chip->hdu;             // The HDU information
     if (!hdu) {
@@ -25,4 +28,6 @@
                     )
 {
+    PS_ASSERT_PTR_NON_NULL(cell, NULL);
+
     pmHDU *hdu = cell->hdu;             // The HDU information
     if (!hdu) {
@@ -33,9 +38,10 @@
 }
 
-pmHDU *pmHDUFromReadout (pmReadout *readout)
+pmHDU *pmHDUFromReadout(pmReadout *readout)
 {
+    PS_ASSERT_PTR_NON_NULL(readout, NULL);
 
     pmCell *cell = readout->parent; // cell containing this readout;
-    pmHDU *hdu = pmHDUFromCell (cell);
+    pmHDU *hdu = pmHDUFromCell(cell);
     return hdu;
 }
@@ -64,4 +70,6 @@
                )
 {
+    PS_ASSERT_PTR_NON_NULL(hdu,);
+
     if (hdu->phu) {
         psTrace(__func__, level, "HDU: %s (PHU)\n", hdu->extname);
Index: /trunk/psModules/src/concepts/pmConcepts.c
===================================================================
--- /trunk/psModules/src/concepts/pmConcepts.c	(revision 7277)
+++ /trunk/psModules/src/concepts/pmConcepts.c	(revision 7278)
@@ -44,5 +44,6 @@
                       )
 {
-    assert(blank);
+    PS_ASSERT_PTR_NON_NULL(blank, false);
+
     if (!conceptsInitialised) {
         pmConceptsInit();
@@ -80,4 +81,7 @@
                          )
 {
+    assert(specs);
+    assert(target);
+
     if (!conceptsInitialised) {
         pmConceptsInit();
@@ -119,4 +123,8 @@
                         )
 {
+    assert(specs);
+    assert(read);
+    assert(target);
+
     if (!conceptsInitialised) {
         pmConceptsInit();
@@ -156,4 +164,7 @@
                          )
 {
+    assert(specs);
+    assert(concepts);
+
     if (!conceptsInitialised) {
         pmConceptsInit();
@@ -180,4 +191,5 @@
                        )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
     psTrace("psModule.concepts", 5, "Blanking FPA concepts: %x %x\n", conceptsFPA, fpa->concepts);
     return conceptsBlank(&conceptsFPA, fpa->concepts);
@@ -191,4 +203,5 @@
                       )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
     psTrace("psModule.concepts", 5, "Reading FPA concepts: %x %x\n", conceptsFPA, fpa->concepts);
     return conceptsRead(&conceptsFPA, fpa, NULL, NULL, &fpa->conceptsRead, source, db, fpa->concepts);
@@ -201,4 +214,5 @@
                        )
 {
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
     psTrace("psModule.concepts", 5, "Writing FPA concepts: %x %x\n", conceptsFPA, fpa->concepts);
     return conceptsWrite(&conceptsFPA, fpa, NULL, NULL, source, db, fpa->concepts);
@@ -209,4 +223,5 @@
                         )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
     psTrace("psModule.concepts", 5, "Blanking chip concepts: %x %x\n", conceptsChip, chip->concepts);
     return conceptsBlank(&conceptsChip, chip->concepts);
@@ -220,4 +235,5 @@
                        )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
     psTrace("psModule.concepts", 5, "Reading chip concepts: %x %x\n", conceptsChip, chip->concepts);
     pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
@@ -235,4 +251,5 @@
                         )
 {
+    PS_ASSERT_PTR_NON_NULL(chip, false);
     psTrace("psModule.concepts", 5, "Writing chip concepts: %x %x\n", conceptsChip, chip->concepts);
     pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
@@ -246,4 +263,5 @@
                         )
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
     psTrace("psModule.concepts", 5, "Blanking cell concepts: %x %x\n", conceptsCell, cell->concepts);
     return conceptsBlank(&conceptsCell, cell->concepts);
@@ -257,4 +275,5 @@
                        )
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
     psTrace("psModule.concepts", 5, "Reading cell concepts: %x %x\n", conceptsCell, cell->concepts);
     pmChip *chip = cell->parent;        // Chip to which the cell belongs
@@ -274,4 +293,5 @@
                         )
 {
+    PS_ASSERT_PTR_NON_NULL(cell, false);
     psTrace("psModule.concepts", 5, "Writing cell concepts: %x %x\n", conceptsCell, cell->concepts);
     pmChip *chip = cell->parent;        // Chip to which the cell belongs
@@ -336,6 +356,6 @@
         {
             psMetadataItem *fpaRa = psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN);
-            pmConceptRegister(fpaRa, (pmConceptParseFunc)pmConceptParse_FPA_Coords,
-                              (pmConceptFormatFunc)pmConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA);
+            pmConceptRegister(fpaRa, (pmConceptParseFunc)p_pmConceptParse_FPA_Coords,
+                              (pmConceptFormatFunc)p_pmConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA);
             psFree(fpaRa);
         }
@@ -344,6 +364,6 @@
         {
             psMetadataItem *fpaDec = psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN);
-            pmConceptRegister(fpaDec, (pmConceptParseFunc)pmConceptParse_FPA_Coords,
-                              (pmConceptFormatFunc)pmConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA);
+            pmConceptRegister(fpaDec, (pmConceptParseFunc)p_pmConceptParse_FPA_Coords,
+                              (pmConceptFormatFunc)p_pmConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA);
             psFree(fpaDec);
         }
@@ -446,6 +466,6 @@
                                           "Trim section", trimsec);
             psFree(trimsec);
-            pmConceptRegister(cellTrimsec, (pmConceptParseFunc)pmConceptParse_CELL_TRIMSEC,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_TRIMSEC, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellTrimsec, (pmConceptParseFunc)p_pmConceptParse_CELL_TRIMSEC,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_TRIMSEC, PM_FPA_LEVEL_CELL);
             psFree(cellTrimsec);
         }
@@ -457,6 +477,6 @@
                                           "Bias sections", biassecs);
             psFree(biassecs);
-            pmConceptRegister(cellBiassec, (pmConceptParseFunc)pmConceptParse_CELL_BIASSEC,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_BIASSEC, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellBiassec, (pmConceptParseFunc)p_pmConceptParse_CELL_BIASSEC,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_BIASSEC, PM_FPA_LEVEL_CELL);
             psFree(cellBiassec);
         }
@@ -465,6 +485,6 @@
         {
             psMetadataItem *cellXbin = psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0);
-            pmConceptRegister(cellXbin, (pmConceptParseFunc)pmConceptParse_CELL_Binning,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_XBIN, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellXbin, (pmConceptParseFunc)p_pmConceptParse_CELL_Binning,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_XBIN, PM_FPA_LEVEL_CELL);
             psFree(cellXbin);
         }
@@ -473,6 +493,6 @@
         {
             psMetadataItem *cellYbin = psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0);
-            pmConceptRegister(cellYbin, (pmConceptParseFunc)pmConceptParse_CELL_Binning,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_YBIN, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellYbin, (pmConceptParseFunc)p_pmConceptParse_CELL_Binning,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_YBIN, PM_FPA_LEVEL_CELL);
             psFree(cellYbin);
         }
@@ -481,6 +501,6 @@
         {
             psMetadataItem *cellTimesys = psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1);
-            pmConceptRegister(cellTimesys, (pmConceptParseFunc)pmConceptParse_CELL_TIMESYS,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_TIMESYS, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellTimesys, (pmConceptParseFunc)p_pmConceptParse_CELL_TIMESYS,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_TIMESYS, PM_FPA_LEVEL_CELL);
             psFree(cellTimesys);
         }
@@ -495,6 +515,6 @@
                                        "Time of exposure", time);
             psFree(time);
-            pmConceptRegister(cellTime, (pmConceptParseFunc)pmConceptParse_CELL_TIME,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_TIME, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellTime, (pmConceptParseFunc)p_pmConceptParse_CELL_TIME,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_TIME, PM_FPA_LEVEL_CELL);
             psFree(cellTime);
         }
@@ -503,6 +523,6 @@
         {
             psMetadataItem *cellX0 = psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0);
-            pmConceptRegister(cellX0, (pmConceptParseFunc)pmConceptParse_CELL_Positions,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellX0, (pmConceptParseFunc)p_pmConceptParse_CELL_Positions,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL);
             psFree(cellX0);
         }
@@ -511,6 +531,6 @@
         {
             psMetadataItem *cellY0 = psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0);
-            pmConceptRegister(cellY0, (pmConceptParseFunc)pmConceptParse_CELL_Positions,
-                              (pmConceptFormatFunc)pmConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL);
+            pmConceptRegister(cellY0, (pmConceptParseFunc)p_pmConceptParse_CELL_Positions,
+                              (pmConceptFormatFunc)p_pmConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL);
             psFree(cellY0);
         }
@@ -534,4 +554,7 @@
                       )
 {
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    PS_ASSERT_PTR_NON_NULL(source, false);
+
     // Copy FPA concepts
     target->concepts = psMetadataCopy(target->concepts, source->concepts);
Index: /trunk/psModules/src/concepts/pmConceptsRead.c
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsRead.c	(revision 7277)
+++ /trunk/psModules/src/concepts/pmConceptsRead.c	(revision 7278)
@@ -1,3 +1,4 @@
 #include <stdio.h>
+#include <assert.h>
 
 #include "pslib.h"
@@ -21,4 +22,7 @@
                                  )
 {
+    assert(concept);
+    assert(pattern);
+
     switch (pattern->type) {
     case PS_DATA_STRING: {
@@ -53,39 +57,43 @@
                         )
 {
-    if (concept) {
-        psMetadataItem *parsed = NULL;  // The parsed concept
-        if (spec->parse) {
-            parsed = spec->parse(concept, spec->blank, cameraFormat, fpa, chip, cell);
-        } else {
-            parsed = parsePlain(concept, spec->blank);
-        }
-
-        // Plug the parsed concept into a new psMetadataItem, so each "concept" has its own version that can
-        // be altered without affecting the others.  Also, so that we maintain the template name and comment.
-        psMetadataItem *cleaned = NULL;     // Item that's been cleaned up --- correct name and comment
-        switch (spec->blank->type) {
-        case PS_DATA_STRING:
-            cleaned = psMetadataItemAllocStr(spec->blank->name, spec->blank->comment, parsed->data.V);
-            break;
-        case PS_DATA_S32:
-            cleaned = psMetadataItemAllocS32(spec->blank->name, spec->blank->comment, parsed->data.S32);
-            break;
-        case PS_DATA_F32:
-            cleaned = psMetadataItemAllocF32(spec->blank->name, spec->blank->comment, parsed->data.F32);
-            break;
-        case PS_DATA_F64:
-            cleaned = psMetadataItemAllocF64(spec->blank->name, spec->blank->comment, parsed->data.F64);
-            break;
-        default:
-            cleaned = psMetadataItemAlloc(spec->blank->name, parsed->type, spec->blank->comment,
-                                          parsed->data.V);
-        }
-        psFree(parsed);
-        psMetadataAddItem(target, cleaned, PS_LIST_TAIL, PS_META_REPLACE);
-        psFree(cleaned);                 // Drop reference
-        return true;
-    }
-
-    return false;
+    assert(spec);
+    assert(cameraFormat);
+    assert(target);
+
+    if (!concept) {
+        return false;
+    }
+
+    psMetadataItem *parsed = NULL;  // The parsed concept
+    if (spec->parse) {
+        parsed = spec->parse(concept, spec->blank, cameraFormat, fpa, chip, cell);
+    } else {
+        parsed = parsePlain(concept, spec->blank);
+    }
+
+    // Plug the parsed concept into a new psMetadataItem, so each "concept" has its own version that can
+    // be altered without affecting the others.  Also, so that we maintain the template name and comment.
+    psMetadataItem *cleaned = NULL;     // Item that's been cleaned up --- correct name and comment
+    switch (spec->blank->type) {
+    case PS_DATA_STRING:
+        cleaned = psMetadataItemAllocStr(spec->blank->name, spec->blank->comment, parsed->data.V);
+        break;
+    case PS_DATA_S32:
+        cleaned = psMetadataItemAllocS32(spec->blank->name, spec->blank->comment, parsed->data.S32);
+        break;
+    case PS_DATA_F32:
+        cleaned = psMetadataItemAllocF32(spec->blank->name, spec->blank->comment, parsed->data.F32);
+        break;
+    case PS_DATA_F64:
+        cleaned = psMetadataItemAllocF64(spec->blank->name, spec->blank->comment, parsed->data.F64);
+        break;
+    default:
+        cleaned = psMetadataItemAlloc(spec->blank->name, parsed->type, spec->blank->comment,
+                                      parsed->data.V);
+    }
+    psFree(parsed);
+    psMetadataAddItem(target, cleaned, PS_LIST_TAIL, PS_META_REPLACE);
+    psFree(cleaned);                 // Drop reference
+    return true;
 }
 
@@ -100,45 +108,48 @@
                              )
 {
-    if (cell) {
-        pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
-        if (! hdu) {
-            return false;
-        }
-        psMetadata *cameraFormat = hdu->format; // The camera format
-        psMetadata *cellConfig = cell->config; // The camera configuration for this cell
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-            psMetadataItem *conceptItem = psMetadataLookup(cellConfig, name); // The concept, or NULL
-            psMetadataItem *value = NULL; // The value of the concept
-            if (conceptItem) {
-                if (conceptItem->type == PS_DATA_STRING) {
-                    // Check the SOURCE
-                    psString nameSource = NULL; // String with the concept name and ".SOURCE" added
-                    psStringAppend(&nameSource, "%s.SOURCE", name);
-                    bool mdok = true;       // Status of MD lookup
-                    psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
-                    psFree(nameSource);
-                    if (mdok && strlen(source) > 0 && strcasecmp(source, "VALUE") == 0) {
-                        value = conceptItem;
-                        conceptParse(spec, value, cameraFormat, target, NULL, NULL, cell);
-                    } else if (source && (strlen(source) == 0 || strcasecmp(source, "HEADER") != 0)) {
-                        // We leave "HEADER" to pmConceptsReadFromHeader
-                        psError(PS_ERR_IO, true, "%s isn't HEADER or VALUE --- can't read %s\n", source,
-                                name);
-                        continue;
-                    }
-                } else {
-                    // Another type --- should be OK
-                    conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell);
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(target, false);
+    if (!cell) {
+        return false;
+    }
+
+    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
+    if (! hdu) {
+        return false;
+    }
+    psMetadata *cameraFormat = hdu->format; // The camera format
+    psMetadata *cellConfig = cell->config; // The camera configuration for this cell
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+        psMetadataItem *conceptItem = psMetadataLookup(cellConfig, name); // The concept, or NULL
+        psMetadataItem *value = NULL; // The value of the concept
+        if (conceptItem) {
+            if (conceptItem->type == PS_DATA_STRING) {
+                // Check the SOURCE
+                psString nameSource = NULL; // String with the concept name and ".SOURCE" added
+                psStringAppend(&nameSource, "%s.SOURCE", name);
+                bool mdok = true;       // Status of MD lookup
+                psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
+                psFree(nameSource);
+                if (mdok && strlen(source) > 0 && strcasecmp(source, "VALUE") == 0) {
+                    value = conceptItem;
+                    conceptParse(spec, value, cameraFormat, target, NULL, NULL, cell);
+                } else if (source && (strlen(source) == 0 || strcasecmp(source, "HEADER") != 0)) {
+                    // We leave "HEADER" to pmConceptsReadFromHeader
+                    psError(PS_ERR_IO, true, "%s isn't HEADER or VALUE --- can't read %s\n", source,
+                            name);
+                    continue;
                 }
+            } else {
+                // Another type --- should be OK
+                conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell);
             }
         }
-        psFree(specsIter);
-        return true;
-    }
-    return false;
+    }
+    psFree(specsIter);
+    return true;
 }
 
@@ -151,4 +162,7 @@
                                )
 {
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(target, false);
+
     pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
     if (!hdu) {
@@ -158,19 +172,17 @@
     bool mdok = true;                   // Status of MD lookup
     psMetadata *defaults = psMetadataLookupMD(&mdok, cameraFormat, "DEFAULTS"); // The DEFAULTS spec
-    if (mdok && defaults) {
-        pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
-        psMetadata *cameraFormat = hdu->format; // The camera format
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-            psMetadataItem *conceptItem = psMetadataLookup(defaults, name); // The concept, or NULL
-            conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell);
-        }
-        psFree(specsIter);
-        return true;
-    }
-    return false;
+    if (!mdok || !defaults) {
+        return false;
+    }
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+        psMetadataItem *conceptItem = psMetadataLookup(defaults, name); // The concept, or NULL
+        conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell);
+    }
+    psFree(specsIter);
+    return true;
 }
 
@@ -183,4 +195,7 @@
                              )
 {
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(target, false);
+
     pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
     if (!hdu) {
@@ -190,57 +205,58 @@
     bool mdok = true;                   // Status of MD lookup
     psMetadata *transSpec = psMetadataLookupMD(&mdok, cameraFormat, "TRANSLATION"); // The TRANSLATION spec
-    if (mdok && transSpec) {
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-            psMetadataItem *headerItem = NULL; // The value of the concept from the header
-            // First check the cell configuration
-            if (cell && cell->config) {
-                psMetadataItem *conceptItem = psMetadataLookup(cell->config, name); // The concept, or NULL
-                if (conceptItem) {
-                    // Check the SOURCE
-                    psString nameSource = NULL; // String with the concept name and ".SOURCE" added
-                    psStringAppend(&nameSource, "%s.SOURCE", name);
-                    psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
-                    psFree(nameSource);
-                    if (mdok && strlen(source) && strcasecmp(source, "HEADER") == 0) {
-                        headerItem = psMetadataLookup(hdu->header, conceptItem->data.V);
+    if (!mdok || !transSpec) {
+        return false;
+    }
+
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+        psMetadataItem *headerItem = NULL; // The value of the concept from the header
+        // First check the cell configuration
+        if (cell && cell->config) {
+            psMetadataItem *conceptItem = psMetadataLookup(cell->config, name); // The concept, or NULL
+            if (conceptItem) {
+                // Check the SOURCE
+                psString nameSource = NULL; // String with the concept name and ".SOURCE" added
+                psStringAppend(&nameSource, "%s.SOURCE", name);
+                psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
+                psFree(nameSource);
+                if (mdok && strlen(source) && strcasecmp(source, "HEADER") == 0) {
+                    headerItem = psMetadataLookup(hdu->header, conceptItem->data.V);
+                }
+                // Leave the error handling to pmConceptsFromCamera, which should already have been called
+            }
+        }
+        if (! headerItem) {
+            psString keywords = psMetadataLookupStr(&mdok, transSpec, name); // The FITS keywords
+            if (mdok && strlen(keywords) > 0) {
+                // In case there are multiple headers
+                psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords
+                if (keys->n == 1) {
+                    // Only one key --- proceed as usual
+                    headerItem = psMetadataLookup(hdu->header, keywords);
+                } else {
+                    psListIterator *keysIter = psListIteratorAlloc(keys, PS_LIST_HEAD, false); // Iterator
+                    psString key = NULL; // Item from iteration
+                    psList *values = psListAlloc(NULL); // List containing the values
+                    while ((key = psListGetAndIncrement(keysIter))) {
+                        psMetadataItem *value = psMetadataLookup(hdu->header, key);
+                        psListAdd(values, PS_LIST_TAIL, value);
                     }
-                    // Leave the error handling to pmConceptsFromCamera, which should already have been called
+                    psFree(keysIter);
+                    headerItem = psMetadataItemAlloc(name, PS_DATA_LIST, specItem->comment, values);
+                    psFree(values);
                 }
+                psFree(keys);
             }
-            if (! headerItem) {
-                psString keywords = psMetadataLookupStr(&mdok, transSpec, name); // The FITS keywords
-                if (mdok && strlen(keywords) > 0) {
-                    // In case there are multiple headers
-                    psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords
-                    if (keys->n == 1) {
-                        // Only one key --- proceed as usual
-                        headerItem = psMetadataLookup(hdu->header, keywords);
-                    } else {
-                        psListIterator *keysIter = psListIteratorAlloc(keys, PS_LIST_HEAD, false); // Iterator
-                        psString key = NULL; // Item from iteration
-                        psList *values = psListAlloc(NULL); // List containing the values
-                        while ((key = psListGetAndIncrement(keysIter))) {
-                            psMetadataItem *value = psMetadataLookup(hdu->header, key);
-                            psListAdd(values, PS_LIST_TAIL, value);
-                        }
-                        psFree(keysIter);
-                        headerItem = psMetadataItemAlloc(name, PS_DATA_LIST, specItem->comment, values);
-                        psFree(values);
-                    }
-                    psFree(keys);
-                }
-            }
-
-            // This will also clean up the name
-            conceptParse(spec, headerItem, cameraFormat, target, fpa, chip, cell);
         }
-        psFree(specsIter);
-        return true;
-    }
-    return false;
+
+        // This will also clean up the name
+        conceptParse(spec, headerItem, cameraFormat, target, fpa, chip, cell);
+    }
+    psFree(specsIter);
+    return true;
 }
 
@@ -255,5 +271,9 @@
                                )
 {
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(target, false);
+
     #ifdef OMIT_PSDB
+
     return false;
     #else
@@ -266,343 +286,104 @@
     bool mdok = true;                   // Status of MD lookup
     psMetadata *dbSpec = psMetadataLookupMD(&mdok, cameraFormat, "DATABSE"); // The DATABASE spec
-    if (mdok && dbSpec) {
-        pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
-        psMetadata *cameraFormat = hdu->format; // The camera format
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-
-            psMetadata *dbLookup = psMetadataLookupMD(&mdok, dbSpec, name);
-            if (mdok && dbLookup) {
-                const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE"); // Table name
-                // Names of the "where" columns
-                const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL");
-                // Values of the "where" columns
-                const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS");
-
-                // Now, need to get the "given"s
-                if (strlen(givenCols) > 0 || strlen(givenPS) > 0) {
-                    psList *cols = psStringSplit(givenCols, ",;", true); // List of column names
-                    psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns
-                    psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
-                    if (cols->n != values->n) {
+    if (!mdok || !dbSpec) {
+        return false;
+    }
+
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+
+        psMetadata *dbLookup = psMetadataLookupMD(&mdok, dbSpec, name);
+        if (mdok && dbLookup) {
+            const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE"); // Table name
+            // Names of the "where" columns
+            const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL");
+            // Values of the "where" columns
+            const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS");
+
+            // Now, need to get the "given"s
+            if (strlen(givenCols) > 0 || strlen(givenPS) > 0) {
+                psList *cols = psStringSplit(givenCols, ",;", true); // List of column names
+                psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns
+                psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
+                if (cols->n != values->n) {
+                    psLogMsg(__func__, PS_LOG_WARN,
+                             "The GIVENDBCOL and GIVENPS entries for %s do not have "
+                             "the same number of entries --- ignored.\n", name);
+                } else {
+                    // Iterators for the lists
+                    psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
+                    psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
+                    char *column = NULL;    // Name of the column
+                    while ((column = psListGetAndIncrement(colsIter))) {
+                        char *dependName = psListGetAndIncrement(valuesIter); // Name for the value
+                        if (!strlen(column) || !strlen(name)) {
+                            psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
+                                     " empty --- ignored.\n", name);
+                        } else {
+                            // Search for the value name
+                            psMetadataItem *item = NULL; // The value
+                            if (!item && cell) {
+                                item = psMetadataLookup(cell->concepts, dependName);
+                            }
+                            if (!item && chip) {
+                                item = psMetadataLookup(chip->concepts, dependName);
+                            }
+                            if (!item && fpa) {
+                                item = psMetadataLookup(fpa->concepts, dependName);
+                            }
+                            if (! item) {
+                                psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB"
+                                         " lookup on %s --- ignored.\n", dependName, name);
+                            } else {
+                                // We need to create a new psMetadataItem.  I don't think we can't
+                                // simply hack the existing one, since that could conceivably cause
+                                // memory leaks
+                                psMetadataItem *newItem = psMetadataItemAlloc(name, item->type,
+                                                          item->comment,
+                                                          item->data.V);
+                                psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);
+                                psFree(newItem);
+                            }
+                        }
+                        psFree(dependName);
+                        psFree(column);
+                    } // Iterating through the columns
+                    psFree(colsIter);
+                    psFree(valuesIter);
+
+                    psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result
+                    // Note that we use limit=2 in order to test if there are multiple rows returned
+
+                    psMetadataItem *conceptItem = NULL; // The final result of the DB lookup
+                    if (dbResult->n == 0) {
                         psLogMsg(__func__, PS_LOG_WARN,
-                                 "The GIVENDBCOL and GIVENPS entries for %s do not have "
-                                 "the same number of entries --- ignored.\n", name);
+                                 "Unable to find any rows in DB for %s --- ignored\n", name);
                     } else {
-                        // Iterators for the lists
-                        psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
-                        psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
-                        char *column = NULL;    // Name of the column
-                        while ((column = psListGetAndIncrement(colsIter))) {
-                            char *dependName = psListGetAndIncrement(valuesIter); // Name for the value
-                            if (!strlen(column) || !strlen(name)) {
-                                psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
-                                         " empty --- ignored.\n", name);
-                            } else {
-                                // Search for the value name
-                                psMetadataItem *item = NULL; // The value
-                                if (!item && cell) {
-                                    item = psMetadataLookup(cell->concepts, dependName);
-                                }
-                                if (!item && chip) {
-                                    item = psMetadataLookup(chip->concepts, dependName);
-                                }
-                                if (!item && fpa) {
-                                    item = psMetadataLookup(fpa->concepts, dependName);
-                                }
-                                if (! item) {
-                                    psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB"
-                                             " lookup on %s --- ignored.\n", dependName, name);
-                                } else {
-                                    // We need to create a new psMetadataItem.  I don't think we can't
-                                    // simply hack the existing one, since that could conceivably cause
-                                    // memory leaks
-                                    psMetadataItem *newItem = psMetadataItemAlloc(name, item->type,
-                                                              item->comment,
-                                                              item->data.V);
-                                    psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);
-                                    psFree(newItem);
-                                }
-                            }
-                            psFree(dependName);
-                            psFree(column);
-                        } // Iterating through the columns
-                        psFree(colsIter);
-                        psFree(valuesIter);
-
-                        psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result
-                        // Note that we use limit=2 in order to test if there are multiple rows returned
-
-                        psMetadataItem *conceptItem = NULL; // The final result of the DB lookup
-                        if (dbResult->n == 0) {
+                        if (dbResult-> n > 1) {
                             psLogMsg(__func__, PS_LOG_WARN,
-                                     "Unable to find any rows in DB for %s --- ignored\n", name);
-                        } else {
-                            if (dbResult-> n > 1) {
-                                psLogMsg(__func__, PS_LOG_WARN,
-                                         "Multiple rows returned in DB lookup for %s --- "
-                                         " using the first one only.\n", name);
-                            }
-                            conceptItem = (psMetadataItem*)dbResult->data[0];
+                                     "Multiple rows returned in DB lookup for %s --- "
+                                     " using the first one only.\n", name);
                         }
-
-                        // Now we have the result
-                        conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell);
-
+                        conceptItem = (psMetadataItem*)dbResult->data[0];
                     }
-                    psFree(cols);
-                    psFree(values);
+
+                    // Now we have the result
+                    conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell);
+
                 }
-            } // Doing the "given"s.
-
-        } // Iterating through the concept specifications
-        psFree(specsIter);
-
-        return true;
-    }
-    return false;
+                psFree(cols);
+                psFree(values);
+            }
+        } // Doing the "given"s.
+
+    } // Iterating through the concept specifications
+    psFree(specsIter);
+
+    return true;
     #endif
 }
 
 
-
-
-#ifdef OLD
-
-psMetadataItem *pmConceptReadFromCamera(pmCell *cell, // The cell
-                                        const char *concept // Name of concept
-                                       )
-{
-    if (cell) {
-        psMetadata *camera = cell->config; // Camera configuration
-        psMetadataItem *item = psMetadataLookup(camera, concept);
-        return item;
-    }
-    return NULL;
-}
-
-psMetadataItem *pmConceptReadFromHeader(pmFPA *fpa, // The FPA that contains the chip
-                                        pmChip *chip, // The chip that contains the cell
-                                        pmCell *cell, // The cell
-                                        const char *concept // Name of concept
-                                       )
-{
-    bool mdStatus = true;               // Status of MD lookup
-    psMetadata *translation = psMetadataLookupMD(&mdStatus, fpa->camera, "TRANSLATION"); // FITS translation
-    if (! mdStatus) {
-        psError(PS_ERR_IO, false, "Unable to find TRANSLATION in camera configuration.\n");
-        return NULL;
-    }
-
-    // Look for how to translate the concept into a FITS header name
-    const char *keyword = psMetadataLookupStr(&mdStatus, translation, concept);
-    if (mdStatus && strlen(keyword) > 0) {
-        // We have a FITS header to look up --- search each level
-        if (cell && cell->hdu) {
-            psMetadataItem *cellItem = psMetadataLookup(cell->hdu->header, keyword);
-            if (cellItem) {
-                // XXX: Need to clean up before returning
-                return cellItem;
-            }
-        }
-
-        if (chip && chip->hdu) {
-            psMetadataItem *chipItem = psMetadataLookup(chip->hdu->header, keyword);
-            if (chipItem) {
-                // XXX: Need to clean up before returning
-                return chipItem;
-            }
-        }
-
-        if (fpa->hdu) {
-            psMetadataItem *fpaItem = psMetadataLookup(fpa->hdu->header, keyword);
-            if (fpaItem) {
-                // XXX: Need to clean up before returning
-                return fpaItem;
-            }
-        }
-    }
-
-    // No header value
-    return NULL;
-}
-
-
-// Look for a default
-psMetadataItem *pmConceptReadFromDefault(pmFPA *fpa, // The FPA that contains the chip
-        pmChip *chip, // The chip that contains the cell
-        pmCell *cell, // The cell
-        const char *concept // Name of concept
-                                        )
-{
-    bool mdOK = true;                   // Status of MD lookup
-    psMetadata *defaults = psMetadataLookupMD(&mdOK, fpa->camera, "DEFAULTS");
-    if (! mdOK) {
-        psError(PS_ERR_IO, false, "Unable to find DEFAULTS in camera configuration.\n");
-        return NULL;
-    }
-
-    psMetadataItem *defItem = psMetadataLookup(defaults, concept);
-    if (defItem) {
-        if (defItem->type == PS_DATA_METADATA) {
-            // A dependent default
-            psTrace(__func__, 7, "Evaluating dependent default....\n");
-            psMetadata *dependents = defItem->data.V; // The list of dependents
-            // Find out what it depends on
-            psString dependName = psStringCopy(concept);
-            psStringAppend(&dependName, ".DEPEND");
-            psString dependsOn = psMetadataLookupStr(&mdOK, defaults, dependName);
-            if (! mdOK) {
-                psError(PS_ERR_IO, false, "Unable to find %s in camera configuration for dependent default"
-                        " --- ignored\n", dependName);
-                // XXX: Need to clean up before returning
-                return NULL;
-            }
-            psFree(dependName);
-            // Find the value of the dependent concept
-            psMetadataItem *depItem = pmConceptReadFromHeader(fpa, chip, cell, dependsOn);
-            if (! depItem) {
-                psError(PS_ERR_IO, true, "Unable to find value for %s (required for %s)\n", dependsOn,
-                        concept);
-                return NULL;
-            }
-            if (depItem->type != PS_DATA_STRING) {
-                psError(PS_ERR_IO, true, "Value of %s is not of type string, as required for dependency"
-                        " --- ignored.\n", dependsOn);
-            }
-
-            defItem = psMetadataLookup(dependents, depItem->data.V);    // This is now what we were after
-        }
-    }
-
-    // XXX: Need to clean up before returning
-    return defItem;                     // defItem is either NULL or points to what was desired
-}
-
-
-// Look for a database lookup
-// XXX: Not tested
-psMetadataItem *pmConceptReadFromDB(pmFPA *fpa, // The FPA that contains the chip
-                                    pmChip *chip, // The chip that contains the cell
-                                    pmCell *cell, // The cell
-                                    psDB *db, // DB handle
-                                    const char *concept // Name of concept
-                                   )
-{
-    if (! db) {
-        // No database initialised
-        return NULL;
-    }
-
-    bool mdStatus = true;               // Status of MD lookup
-    psMetadata *database = psMetadataLookupMD(&mdStatus, fpa->camera, "DATABASE");
-    if (! mdStatus) {
-        // No error, because not everyone needs to use the DB
-        return NULL;
-    }
-
-    psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, database, concept);
-    if (dbLookup) {
-        const char *tableName = psMetadataLookupStr(&mdStatus, dbLookup, "TABLE"); // Name of the table
-        // const char *colName = psMetadataLookupStr(&mdStatus, dbLookup, "COLUMN"); // Name of the column
-        const char *givenCols = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENDBCOL"); // Name of "where"
-        // columns
-        const char *givenPS = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENPS"); // Values for "where"
-        // columns
-
-        // Now, need to get the "given"s
-        if (strlen(givenCols) || strlen(givenPS)) {
-            psList *cols = psStringSplit(givenCols, ",;", true); // List of column names
-            psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns
-            psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
-            if (cols->n != values->n) {
-                psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "
-                         "the same number of entries --- ignored.\n", concept);
-            } else {
-                // Iterators for the lists
-                psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
-                psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
-                char *column = NULL;    // Name of the column
-                while ((column = psListGetAndIncrement(colsIter))) {
-                    char *name = psListGetAndIncrement(valuesIter); // Name for the value
-                    if (!strlen(column) || !strlen(name)) {
-                        psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
-                                 " empty --- ignored.\n", concept);
-                    } else {
-                        // Search for the value name
-                        psMetadataItem *item = pmConceptReadFromHeader(fpa, chip, cell, name);
-                        if (! item) {
-                            item = pmConceptReadFromDefault(fpa, chip, cell, name);
-                        }
-                        if (! item) {
-                            psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "
-                                     " lookup on %s --- ignored.\n", name, concept);
-                        } else {
-                            // We need to create a new psMetadataItem.  I don't think we can't simply hack
-                            // the existing one, since that could conceivably cause memory leaks
-                            psMetadataItem *newItem = psMetadataItemAlloc(concept, item->type,
-                                                      item->comment, item->data.V);
-                            psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);
-                            psFree(newItem);
-                        }
-                    }
-                    psFree(name);
-                    psFree(column);
-                } // Iterating through the columns
-                psFree(colsIter);
-                psFree(valuesIter);
-
-                psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result
-                // Note that we use limit=2 in order to test if there are multiple rows returned
-
-                psMetadataItem *result = NULL; // The final result of the DB lookup
-                if (dbResult->n == 0) {
-                    psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- ignored\n",
-                             concept);
-                } else {
-                    if (dbResult-> n > 1) {
-                        psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s --- "
-                                 " using the first one only.\n", concept);
-                    }
-                    result = (psMetadataItem*)dbResult->data[0];
-                }
-                // XXX: Need to clean up before returning
-                return result;
-            }
-            psFree(cols);
-            psFree(values);
-        }
-    } // Doing the "given"s.
-
-    psAbort(__func__, "Shouldn't ever get here.\n");
-    return NULL;
-}
-
-
-// Concept lookup
-psMetadataItem *pmConceptRead(pmFPA *fpa, // The FPA
-                              pmChip *chip,// The chip
-                              pmCell *cell, // The cell
-                              psDB *db, // DB handle
-                              const char *name // Concept name
-                             )
-{
-    // Try headers, database, defaults in order
-    psMetadataItem *item = pmConceptReadFromCamera(cell, name);
-    if (! item) {
-        item = pmConceptReadFromHeader(fpa, chip, cell, name);
-    }
-    if (! item) {
-        item = pmConceptReadFromDB(fpa, chip, cell, db, name);
-    }
-    if (! item) {
-        item = pmConceptReadFromDefault(fpa, chip, cell, name);
-    }
-    return item; // item is either NULL, or points to what was desired
-}
-
-
-#endif
Index: /trunk/psModules/src/concepts/pmConceptsStandard.c
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 7277)
+++ /trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 7278)
@@ -9,4 +9,7 @@
 #include "pmConceptsStandard.h"
 
+// The functions in this file are intended to be called solely within the psModules concepts code.  For this
+// reason, they use "assert" instead of the PS_ASSERT_WHATEVER functions --- if there's a problem, then
+// there's a BIG problem that affects all of the code.
 
 #define COMPARE_REGIONS(a,b) (((a)->x0 == (b)->x0 && \
@@ -38,5 +41,10 @@
 
 // FPA.RA and FPA.DEC
-psMetadataItem *pmConceptParse_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptParse_FPA_Coords(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -102,8 +110,11 @@
 
 // FPA.RA and FPA.DEC
-psMetadataItem *pmConceptFormat_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat)
-{
-    assert(concept);
-    assert(pattern);
+psMetadataItem *p_pmConceptFormat_FPA_Coords(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
+{
+    assert(concept);
     assert(cameraFormat);
 
@@ -112,7 +123,9 @@
     // How to interpret the coordinates
     bool mdok = true;                   // Status of MD lookup
-    psMetadata *formats = psMetadataLookupMD(&mdok, cameraFormat, "FORMATS");
+    psMetadata *formats = psMetadataLookupMD(&mdok,
+                          cameraFormat,
+                          "FORMATS");
     if (mdok && formats) {
-        psString format = psMetadataLookupStr(&mdok, formats, pattern->name);
+        psString format = psMetadataLookupStr(&mdok,formats, concept->name);
         if (mdok && strlen(format) > 0) {
             if (strcasecmp(format, "HOURS") == 0) {
@@ -123,11 +136,11 @@
                 // No action required
             } else {
-                coords /= defaultCoordScaling(pattern);
+                coords /= defaultCoordScaling(concept);
             }
         } else {
-            coords /= defaultCoordScaling(pattern);
+            coords /= defaultCoordScaling(concept);
         }
     } else {
-        coords /= defaultCoordScaling(pattern);
+        coords /= defaultCoordScaling(concept);
     }
 
@@ -140,5 +153,5 @@
     psString coordString = NULL;        // String with the coordinates in sexagesimal format
     psStringAppend(&coordString, "%d:%d:%.2f", big, medium, small);
-    psMetadataItem *coordItem = psMetadataItemAllocStr(pattern->name, pattern->comment, coordString);
+    psMetadataItem *coordItem = psMetadataItemAllocStr(concept->name, concept->comment, coordString);
     psFree(coordString);
 
@@ -147,5 +160,10 @@
 
 
-psMetadataItem *pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -167,5 +185,10 @@
 }
 
-psMetadataItem *pmConceptParse_CELL_BIASSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptParse_CELL_BIASSEC(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -218,5 +241,10 @@
 
 // CELL.XBIN and CELL.YBIN
-psMetadataItem *pmConceptParse_CELL_Binning(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptParse_CELL_Binning(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -249,5 +277,10 @@
 
 
-psMetadataItem *pmConceptParse_CELL_TIMESYS(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptParse_CELL_TIMESYS(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -274,5 +307,10 @@
 
 
-psMetadataItem *pmConceptParse_CELL_TIME(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptParse_CELL_TIME(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -466,5 +504,10 @@
 }
 
-psMetadataItem *pmConceptParse_CELL_Positions(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptParse_CELL_Positions(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -489,5 +532,9 @@
 
 
-psMetadataItem *pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -501,5 +548,9 @@
 }
 
-psMetadataItem *pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     // Return a metadata item containing a list of metadata items of region strings
@@ -523,5 +574,9 @@
 // This function actually does both CELL.XBIN and CELL.YBIN if CELL.XBIN and CELL.YBIN are specified by the
 // same header.
-psMetadataItem *pmConceptFormat_CELL_XBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptFormat_CELL_XBIN(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -546,5 +601,9 @@
 
 // Only need to format if both if CELL.XBIN and CELL.YBIN are not specified by the same header.
-psMetadataItem *pmConceptFormat_CELL_YBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptFormat_CELL_YBIN(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
@@ -565,5 +624,9 @@
 
 
-psMetadataItem *pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     psString sys = NULL;            // String to store
@@ -590,5 +653,9 @@
 }
 
-psMetadataItem *pmConceptFormat_CELL_TIME(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptFormat_CELL_TIME(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     psTime *time = concept->data.V;     // The time
@@ -699,5 +766,9 @@
 }
 
-psMetadataItem *pmConceptFormat_CELL_Positions(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell)
+psMetadataItem *p_pmConceptFormat_CELL_Positions(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell)
 {
     assert(concept);
Index: /trunk/psModules/src/concepts/pmConceptsStandard.h
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsStandard.h	(revision 7277)
+++ /trunk/psModules/src/concepts/pmConceptsStandard.h	(revision 7278)
@@ -5,20 +5,88 @@
 #include "pmFPA.h"
 
+// Functions to parse and format the standard concepts
 
-psMetadataItem *pmConceptParse_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat);
-psMetadataItem *pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptParse_CELL_BIASSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptParse_CELL_Binning(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptParse_CELL_TIMESYS(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptParse_CELL_TIME(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptParse_CELL_Positions(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_CELL_XBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_CELL_YBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_CELL_TIME(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
-psMetadataItem *pmConceptFormat_CELL_Positions(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell);
+psMetadataItem *p_pmConceptParse_FPA_Coords(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_FPA_Coords(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptParse_CELL_BIASSEC(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptParse_CELL_Binning(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptParse_CELL_TIMESYS(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptParse_CELL_TIME(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptParse_CELL_Positions(psMetadataItem *concept,
+        psMetadataItem *pattern,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_XBIN(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_YBIN(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_TIME(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
+psMetadataItem *p_pmConceptFormat_CELL_Positions(psMetadataItem *concept,
+        psMetadata *cameraFormat,
+        pmFPA *fpa,
+        pmChip *chip,
+        pmCell *cell);
 
 #endif
Index: /trunk/psModules/src/concepts/pmConceptsWrite.c
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsWrite.c	(revision 7277)
+++ /trunk/psModules/src/concepts/pmConceptsWrite.c	(revision 7278)
@@ -1,3 +1,4 @@
 #include <stdio.h>
+#include <assert.h>
 #include <strings.h>
 #include "pslib.h"
@@ -110,4 +111,7 @@
                                     )
 {
+    assert(spec);
+    assert(cameraFormat);
+
     if (concept) {
         psMetadataItem *formatted = NULL;  // The formatted concept
@@ -129,4 +133,8 @@
                              )
 {
+    assert(hdu);
+    assert(keyword && strlen(keyword) > 0);
+    assert(item);
+
     if (!hdu->header) {
         return false;
@@ -166,4 +174,8 @@
                        )
 {
+    assert(hdu);
+    assert(keywords);
+    assert(item);
+
     bool status = true;                 // Status of writing headers, to be returned
     if (item->type == PS_DATA_LIST) {
@@ -204,63 +216,66 @@
                             )
 {
-    if (cell) {
-        pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
-        if (!hdu) {
-            return false;
-        }
-        psMetadata *cameraFormat = hdu->format; // The camera format
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-            psMetadataItem *cameraItem = psMetadataLookup(cell->config, name); // The concept from the camera,
-            // or NULL
-            if (cameraItem) {
-                // Grab the concept
-                psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The concept
-                // Formatted version
-                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, NULL, NULL, cell);
-                if (!formatted) {
-                    continue;
-                }
-                psString nameSource = NULL; // String with the concept name and ".SOURCE" added
-                psStringAppend(&nameSource, "%s.SOURCE", name);
-                bool mdok = true;       // Status of MD lookup
-                psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
-                if (mdok && strlen(source) > 0) {
-                    psTrace(__func__, 8, "%s is %s\n", nameSource, source);
-                    if (strcasecmp(source, "HEADER") == 0) {
-                        if (cameraItem->type != PS_DATA_STRING) {
-                            psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by header, but is not "
-                                     "of type STR --- ignored.\n", conceptItem->name);
-                            continue;
-                        }
-                        psTrace(__func__, 8, "Writing %s to header %s\n", name, cameraItem->data.V);
-                        writeHeader(hdu, cameraItem->data.V, formatted);
-                    } else if (strcasecmp(source, "VALUE") == 0) {
-                        psTrace(__func__, 8, "Checking %s against camera format.\n", name);
-                        if (! compareConcepts(formatted, cameraItem)) {
-                            psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera "
-                                     "format, but the values don't match.\n", name);
-                        }
-                    } else {
-                        psLogMsg(__func__, PS_LOG_WARN, "Concept source %s isn't HEADER or VALUE --- can't "
-                                 "write\n", nameSource);
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(concepts, false);
+    if (!cell) {
+        return false;
+    }
+
+    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
+    if (!hdu) {
+        return false;
+    }
+    psMetadata *cameraFormat = hdu->format; // The camera format
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+        psMetadataItem *cameraItem = psMetadataLookup(cell->config, name); // The concept from the camera,
+        // or NULL
+        if (cameraItem) {
+            // Grab the concept
+            psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The concept
+            // Formatted version
+            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, NULL, NULL, cell);
+            if (!formatted) {
+                continue;
+            }
+            psString nameSource = NULL; // String with the concept name and ".SOURCE" added
+            psStringAppend(&nameSource, "%s.SOURCE", name);
+            bool mdok = true;       // Status of MD lookup
+            psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
+            if (mdok && strlen(source) > 0) {
+                psTrace(__func__, 8, "%s is %s\n", nameSource, source);
+                if (strcasecmp(source, "HEADER") == 0) {
+                    if (cameraItem->type != PS_DATA_STRING) {
+                        psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by header, but is not "
+                                 "of type STR --- ignored.\n", conceptItem->name);
+                        continue;
                     }
-                } else if (! compareConcepts(formatted, cameraItem)) {
-                    // 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);
-            }
-
-        }
-        psFree(specsIter);
-        return true;
-    }
-    return false;
+                    psTrace(__func__, 8, "Writing %s to header %s\n", name, cameraItem->data.V);
+                    writeHeader(hdu, cameraItem->data.V, formatted);
+                } else if (strcasecmp(source, "VALUE") == 0) {
+                    psTrace(__func__, 8, "Checking %s against camera format.\n", name);
+                    if (! compareConcepts(formatted, cameraItem)) {
+                        psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera "
+                                 "format, but the values don't match.\n", name);
+                    }
+                } else {
+                    psLogMsg(__func__, PS_LOG_WARN, "Concept source %s isn't HEADER or VALUE --- can't "
+                             "write\n", nameSource);
+                }
+            } else if (! compareConcepts(formatted, cameraItem)) {
+                // 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);
+        }
+
+    }
+    psFree(specsIter);
+    return true;
 }
 
@@ -272,4 +287,7 @@
                               )
 {
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(concepts, false);
+
     pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
     if (!hdu) {
@@ -279,51 +297,50 @@
     bool mdok = true;                   // Status of MD lookup
     psMetadata *defaults = psMetadataLookupMD(&mdok, cameraFormat, "DEFAULTS"); // The DEFAULTS spec
-    if (mdok && defaults) {
-        pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
-        psMetadata *cameraFormat = hdu->format; // The camera format
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-            psMetadataItem *defaultItem = psMetadataLookup(defaults, name); // The item from the DEFAULTS
-            if (defaultItem) {
-                psMetadataItem *conceptItem = NULL; // The item from the concepts
-                if (defaultItem->type == PS_DATA_METADATA) {
-                    // It's a menu --- need to look up the .DEPEND
-                    psString dependName = NULL; // The concept name with ".DEPEND" on the end
-                    psStringAppend(&dependName, ".DEPEND");
-                    psString dependKey = psMetadataLookupStr(&mdok, defaults, dependName); // The keyword
-                    psFree(dependName);
-                    if (!mdok || !dependKey || strlen(dependKey) == 0) {
-                        psLogMsg(__func__, PS_LOG_WARN, "Can't find %s in the DEFAULTS for %s --- ignored.\n",
-                                 dependName, name);
-                        continue;
-                    }
-                    psString dependValue = psMetadataLookupStr(&mdok, concepts, dependName); // The value
-                    if (!mdok || !dependKey || strlen(dependKey) == 0) {
-                        psLogMsg(__func__, PS_LOG_WARN, "Concept %s specified by %s isn't of type STR -- "
-                                 "ignored.\n", name, dependName);
-                        continue;
-                    }
-                    conceptItem = psMetadataLookup(defaultItem->data.V, dependValue);
-                } else {
-                    conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
-                }
-                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
-                if (!formatted) {
+    if (!mdok || !defaults) {
+        return false;
+    }
+
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+        psMetadataItem *defaultItem = psMetadataLookup(defaults, name); // The item from the DEFAULTS
+        if (defaultItem) {
+            psMetadataItem *conceptItem = NULL; // The item from the concepts
+            if (defaultItem->type == PS_DATA_METADATA) {
+                // It's a menu --- need to look up the .DEPEND
+                psString dependName = NULL; // The concept name with ".DEPEND" on the end
+                psStringAppend(&dependName, ".DEPEND");
+                psString dependKey = psMetadataLookupStr(&mdok, defaults, dependName); // The keyword
+                psFree(dependName);
+                if (!mdok || !dependKey || strlen(dependKey) == 0) {
+                    psLogMsg(__func__, PS_LOG_WARN, "Can't find %s in the DEFAULTS for %s --- ignored.\n",
+                             dependName, name);
                     continue;
                 }
-                if (! compareConcepts(formatted, defaultItem)) {
-                    psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by the DEFAULTS in the camera "
-                             "format, but the values don't match.\n", name);
-                }
-                psFree(formatted);
-            }
-        }
-        psFree(specsIter);
-        return true;
-    }
-    return false;
+                psString dependValue = psMetadataLookupStr(&mdok, concepts, dependName); // The value
+                if (!mdok || !dependKey || strlen(dependKey) == 0) {
+                    psLogMsg(__func__, PS_LOG_WARN, "Concept %s specified by %s isn't of type STR -- "
+                             "ignored.\n", name, dependName);
+                    continue;
+                }
+                conceptItem = psMetadataLookup(defaultItem->data.V, dependValue);
+            } else {
+                conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
+            }
+            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
+            if (!formatted) {
+                continue;
+            }
+            if (! compareConcepts(formatted, defaultItem)) {
+                psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by the DEFAULTS in the camera "
+                         "format, but the values don't match.\n", name);
+            }
+            psFree(formatted);
+        }
+    }
+    psFree(specsIter);
+    return true;
 }
 
@@ -336,4 +353,7 @@
                             )
 {
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(concepts, false);
+
     pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
     if (!hdu) {
@@ -343,54 +363,53 @@
     bool mdok = true;                   // Status of MD lookup
     psMetadata *translation = psMetadataLookupMD(&mdok, cameraFormat, "TRANSLATION"); // The TRANSLATION spec
-    if (mdok && translation) {
-        pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
-        psMetadata *cameraFormat = hdu->format; // The camera format
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-            psMetadataItem *headerItem = psMetadataLookup(translation, name); // The item from the TRANSLATION
-            if (headerItem) {
-                if (headerItem->type != PS_DATA_STRING) {
-                    psLogMsg(__func__, PS_LOG_WARN, "TRANSLATION keyword for concept %s isn't of type STR ---"
-                             " ignored.", name);
-                    continue;
-                }
-                psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
-                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
-                if (!formatted) {
-                    continue;
-                }
-                psList *keywords = psStringSplit(headerItem->data.V, " ,;", true); // List of header keywords
-                if (formatted->type == PS_DATA_LIST) {
-                    psList *values = formatted->data.V; // The values for the headers
-                    if (values->n != keywords->n) {
-                        psLogMsg(__func__, PS_LOG_WARN, "Number of headers specified does not match number "
-                                 "of values for concept %s.\n", name);
+    if (!mdok || !translation) {
+        return false;
+    }
+
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+        psMetadataItem *headerItem = psMetadataLookup(translation, name); // The item from the TRANSLATION
+        if (headerItem) {
+            if (headerItem->type != PS_DATA_STRING) {
+                psLogMsg(__func__, PS_LOG_WARN, "TRANSLATION keyword for concept %s isn't of type STR ---"
+                         " ignored.", name);
+                continue;
+            }
+            psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
+            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
+            if (!formatted) {
+                continue;
+            }
+            psList *keywords = psStringSplit(headerItem->data.V, " ,;", true); // List of header keywords
+            if (formatted->type == PS_DATA_LIST) {
+                psList *values = formatted->data.V; // The values for the headers
+                if (values->n != keywords->n) {
+                    psLogMsg(__func__, PS_LOG_WARN, "Number of headers specified does not match number "
+                             "of values for concept %s.\n", name);
+                }
+                psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator
+                psListIterator *keywordsIter = psListIteratorAlloc(keywords, PS_LIST_HEAD, false);
+                psMetadataItem *valuesItem = NULL; // Item from list
+                while ((valuesItem = psListGetAndIncrement(valuesIter))) {
+                    psString keyword = psListGetAndIncrement(keywordsIter); // Keyword from the list
+                    if (strlen(keyword) > 0) {
+                        writeHeader(hdu, keyword, formatted);
                     }
-                    psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator
-                    psListIterator *keywordsIter = psListIteratorAlloc(keywords, PS_LIST_HEAD, false);
-                    psMetadataItem *valuesItem = NULL; // Item from list
-                    while ((valuesItem = psListGetAndIncrement(valuesIter))) {
-                        psString keyword = psListGetAndIncrement(keywordsIter); // Keyword from the list
-                        if (strlen(keyword) > 0) {
-                            writeHeader(hdu, keyword, formatted);
-                        }
-                    }
-                    psFree(valuesIter);
-                    psFree(keywordsIter);
-                } else {
-                    psString keyword = psListGet(keywords, PS_LIST_HEAD); // The keyword
-                    writeHeader(hdu, keyword, formatted);
-                }
-                psFree(formatted);
-                psFree(keywords);
-            }
-        }
-        psFree(specsIter);
-        return true;
-    }
-    return false;
+                }
+                psFree(valuesIter);
+                psFree(keywordsIter);
+            } else {
+                psString keyword = psListGet(keywords, PS_LIST_HEAD); // The keyword
+                writeHeader(hdu, keyword, formatted);
+            }
+            psFree(formatted);
+            psFree(keywords);
+        }
+    }
+    psFree(specsIter);
+    return true;
 }
 
@@ -404,4 +423,11 @@
                               )
 {
+    PS_ASSERT_PTR_NON_NULL(specs, false);
+    PS_ASSERT_PTR_NON_NULL(concepts, false);
+
+    if (!db) {
+        return false;
+    }
+
     #ifdef OMIT_PSDB
     return false;
@@ -415,419 +441,111 @@
     bool mdok = true;                   // Status of MD lookup
     psMetadata *database = psMetadataLookupMD(&mdok, cameraFormat, "DATABASE"); // The DATABASE spec
-    if (mdok && database) {
-        pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
-        psMetadata *cameraFormat = hdu->format; // The camera format
-        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
-        psMetadataItem *specItem = NULL;    // Item from the specs metadata
-        while ((specItem = psMetadataGetAndIncrement(specsIter))) {
-            pmConceptSpec *spec = specItem->data.V; // The specification
-            psString name = specItem->name; // The concept name
-
-            psMetadataItem *dbItem = psMetadataLookup(database, name); // The item from the DATABASE
-            if (dbItem) {
-                if (dbItem->type != PS_DATA_METADATA) {
-                    psLogMsg(__func__, PS_LOG_WARN, "DATABASE keyword for concept %s isn't of type METADATA "
-                             "--- ignored.\n", name);
-                    continue;
-                }
-
-                psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
-                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
-                if (!formatted) {
-                    continue;
-                }
-
-                psMetadata *dbLookup = dbItem->data.V; // How to look up the value of interest
-                // Name of the table
-                const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE");
-                // Name of "where" columns
-                const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL");
-                // Values for "where" columns
-                const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS");
-
-                // Now, need to get the "given"s
-                if (strlen(givenCols) || strlen(givenPS)) {
-                    psList *cols = psStringSplit(givenCols, ",;", true); // List of column names
-                    psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns
-                    psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
-                    if (cols->n != values->n) {
-                        psLogMsg(__func__, PS_LOG_WARN,
-                                 "The GIVENDBCOL and GIVENPS entries for %s do not have "
-                                 "the same number of entries --- ignored.\n", name);
+    if (!mdok || !database) {
+        return false;
+    }
+    psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *specItem = NULL;    // Item from the specs metadata
+    while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        pmConceptSpec *spec = specItem->data.V; // The specification
+        psString name = specItem->name; // The concept name
+
+        psMetadataItem *dbItem = psMetadataLookup(database, name); // The item from the DATABASE
+        if (dbItem) {
+            if (dbItem->type != PS_DATA_METADATA) {
+                psLogMsg(__func__, PS_LOG_WARN, "DATABASE keyword for concept %s isn't of type METADATA "
+                         "--- ignored.\n", name);
+                continue;
+            }
+
+            psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
+            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
+            if (!formatted) {
+                continue;
+            }
+
+            psMetadata *dbLookup = dbItem->data.V; // How to look up the value of interest
+            // Name of the table
+            const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE");
+            // Name of "where" columns
+            const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL");
+            // Values for "where" columns
+            const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS");
+
+            // Now, need to get the "given"s
+            if (strlen(givenCols) || strlen(givenPS)) {
+                psList *cols = psStringSplit(givenCols, ",;", true); // List of column names
+                psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns
+                psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
+                if (cols->n != values->n) {
+                    psLogMsg(__func__, PS_LOG_WARN,
+                             "The GIVENDBCOL and GIVENPS entries for %s do not have "
+                             "the same number of entries --- ignored.\n", name);
+                } else {
+                    // Iterators for the lists
+                    psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
+                    psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
+                    char *column = NULL;    // Name of the column
+                    while ((column = psListGetAndIncrement(colsIter))) {
+                        char *dependName = psListGetAndIncrement(valuesIter); // Name for the value
+                        if (!strlen(column) || !strlen(name)) {
+                            psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
+                                     " empty --- ignored.\n", name);
+                        } else {
+                            // Search for the value name
+                            psMetadataItem *item = NULL; // The value
+                            if (!item && cell) {
+                                item = psMetadataLookup(cell->concepts, dependName);
+                            }
+                            if (!item && chip) {
+                                item = psMetadataLookup(chip->concepts, dependName);
+                            }
+                            if (!item && fpa) {
+                                item = psMetadataLookup(fpa->concepts, dependName);
+                            }
+                            if (! item) {
+                                psLogMsg(__func__, PS_LOG_ERROR,
+                                         "Unable to find the value name %s for DB "
+                                         " lookup on %s --- ignored.\n", dependName, name);
+                            } else {
+                                // We need to create a new psMetadataItem.  I don't think we can't simply
+                                // hack the existing one, since that could conceivably cause memory leaks
+                                psMetadataAddItem(selection, formatted, PS_LIST_TAIL, PS_META_REPLACE);
+                                psFree(formatted);
+                            }
+                        }
+                        psFree(dependName);
+                        psFree(column);
+                    } // Iterating through the columns
+                    psFree(colsIter);
+                    psFree(valuesIter);
+
+                    // Check first to make sure we're only going to touch one row
+                    psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result
+                    // Note that we use limit=2 in order to test if there are multiple rows returned
+                    if (! dbResult || dbResult->n == 0) {
+                        psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- "
+                                 "ignored\n", name);
+                        return false;
                     } else {
-                        // Iterators for the lists
-                        psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
-                        psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
-                        char *column = NULL;    // Name of the column
-                        while ((column = psListGetAndIncrement(colsIter))) {
-                            char *dependName = psListGetAndIncrement(valuesIter); // Name for the value
-                            if (!strlen(column) || !strlen(name)) {
-                                psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
-                                         " empty --- ignored.\n", name);
-                            } else {
-                                // Search for the value name
-                                psMetadataItem *item = NULL; // The value
-                                if (!item && cell) {
-                                    item = psMetadataLookup(cell->concepts, dependName);
-                                }
-                                if (!item && chip) {
-                                    item = psMetadataLookup(chip->concepts, dependName);
-                                }
-                                if (!item && fpa) {
-                                    item = psMetadataLookup(fpa->concepts, dependName);
-                                }
-                                if (! item) {
-                                    psLogMsg(__func__, PS_LOG_ERROR,
-                                             "Unable to find the value name %s for DB "
-                                             " lookup on %s --- ignored.\n", dependName, name);
-                                } else {
-                                    // We need to create a new psMetadataItem.  I don't think we can't simply
-                                    // hack the existing one, since that could conceivably cause memory leaks
-                                    psMetadataAddItem(selection, formatted, PS_LIST_TAIL, PS_META_REPLACE);
-                                    psFree(formatted);
-                                }
-                            }
-                            psFree(dependName);
-                            psFree(column);
-                        } // Iterating through the columns
-                        psFree(colsIter);
-                        psFree(valuesIter);
-
-                        // Check first to make sure we're only going to touch one row
-                        psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result
-                        // Note that we use limit=2 in order to test if there are multiple rows returned
-                        if (! dbResult || dbResult->n == 0) {
-                            psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- "
-                                     "ignored\n", name);
-                            return false;
-                        } else {
-                            if (dbResult->n > 1) {
-                                psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s "
-                                         "--- ignored.\n", name);
-                            }
-                            // Update the DB
-                            psMetadata *update = psMetadataAlloc();
-                            psMetadataAddItem(update, conceptItem, PS_LIST_HEAD, 0);
-                            psDBUpdateRows(db, tableName, selection, update);
-                            psFree(update);
-                            return true;
+                        if (dbResult->n > 1) {
+                            psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s "
+                                     "--- ignored.\n", name);
                         }
+                        // Update the DB
+                        psMetadata *update = psMetadataAlloc();
+                        psMetadataAddItem(update, conceptItem, PS_LIST_HEAD, 0);
+                        psDBUpdateRows(db, tableName, selection, update);
+                        psFree(update);
+                        return true;
                     }
-                    psFree(cols);
-                    psFree(values);
-                } // Doing the "given"s.
-            }
-        }
-        psFree(specsIter);
-        return true;
-    }
-    return false;
+                }
+                psFree(cols);
+                psFree(values);
+            } // Doing the "given"s.
+        }
+    }
+    psFree(specsIter);
+    return true;
     #endif
 }
 
-
-
-
-#if 0
-
-// Well, not really "write", but check to make sure it's there and matches
-bool pmConceptWriteToCamera(pmCell *cell, // The cell
-                            psMetadataItem *concept // Concept
-                           )
-{
-    if (! cell->config) {
-        return false;
-    }
-    if (cell) {
-        psMetadataItem *item = psMetadataLookup(cell->config, concept->name); // Info we want
-        return compareConcepts(item, concept);
-    }
-
-    return false;
-}
-
-// Write the concept to the header in the appropriate location
-bool pmConceptWriteToHeader(pmFPA *fpa, // The FPA that contains the chip
-                            pmChip *chip, // The chip that contains the cell
-                            pmCell *cell, // The cell
-                            psMetadataItem *concept // Concept
-                           )
-{
-    bool mdok = true;                   // Status of MD lookup
-    bool status = false;                // Status of setting header
-    if (! fpa->camera) {
-        return false;
-    }
-    psMetadata *translation = psMetadataLookupMD(&mdok, fpa->camera, "TRANSLATION"); // FITS translation
-    if (! mdok) {
-        psError(PS_ERR_IO, false, "Unable to find TRANSLATION in camera configuration.\n");
-        return false;
-    }
-
-    // Look for how to translate the concept into a FITS header name
-    const char *keyword = psMetadataLookupStr(&mdok, translation, concept->name);
-    if (mdok && strlen(keyword) > 0) {
-        psTrace(__func__, 6, "It's in keyword %s\n", keyword);
-        psMetadataItem *headerItem = NULL; // Item to add to header
-        // XXX: Need to expand range of types
-        switch (concept->type) {
-        case PS_DATA_STRING:
-            headerItem = psMetadataItemAllocStr(keyword, concept->comment, concept->data.V);
-            break;
-        case PS_DATA_S32:
-            headerItem = psMetadataItemAllocS32(keyword, concept->comment, concept->data.S32);
-            break;
-        case PS_DATA_F32:
-            headerItem = psMetadataItemAllocF32(keyword, concept->comment, concept->data.F32);
-            break;
-        case PS_DATA_F64:
-            headerItem = psMetadataItemAllocF64(keyword, concept->comment, concept->data.F64);
-            break;
-        default:
-            headerItem = psMetadataItemAlloc(keyword, concept->type, concept->comment,
-                                             concept->data.V); // Item for the header
-        }
-
-        // We have a FITS header to look up --- search each level
-        if (cell && cell->hdu) {
-            psTrace(__func__, 7, "Adding to the cell level header...\n");
-            psMetadataAddItem(cell->hdu->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
-            status = true;
-        } else if (chip && chip->hdu) {
-            psTrace(__func__, 7, "Adding to the chip level header...\n");
-            psMetadataAddItem(chip->hdu->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
-            status = true;
-        } else if (fpa->hdu) {
-            psTrace(__func__, 7, "Adding to the FPA level header...\n");
-            psMetadataAddItem(fpa->hdu->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);
-            status = true;
-        }
-        psFree(headerItem);
-    }
-
-    // No header value
-    return status;
-}
-
-
-// Well, not really "write", but check to see if it's there, and matches
-bool pmConceptWriteToDefault(pmFPA *fpa, // The FPA that contains the chip
-                             pmChip *chip, // The chip that contains the cell
-                             pmCell *cell, // The cell
-                             psMetadataItem *concept // Concept
-                            )
-{
-    bool mdOK = true;                   // Status of MD lookup
-    if (! fpa->camera) {
-        return false;
-    }
-    psMetadata *defaults = psMetadataLookupMD(&mdOK, fpa->camera, "DEFAULTS");
-    if (! mdOK || ! defaults) {
-        psError(PS_ERR_IO, false, "Unable to find DEFAULTS in camera configuration.\n");
-        return false;
-    }
-
-    psMetadataItem *defItem = psMetadataLookup(defaults, concept->name);
-    bool status = false;                // Result of checking the database
-    if (defItem) {
-        if (defItem->type == PS_DATA_METADATA) {
-            // A dependent default
-            psTrace(__func__, 7, "Evaluating dependent default....\n");
-            psMetadata *dependents = defItem->data.V; // The list of dependents
-            // Find out what it depends on
-            psString dependName = psStringCopy(concept->name);
-            psStringAppend(&dependName, ".DEPEND");
-            psString dependsOn = psMetadataLookupStr(&mdOK, defaults, dependName);
-            if (! mdOK) {
-                psError(PS_ERR_IO, false, "Unable to find %s in camera configuration for dependent default"
-                        " --- ignored\n", dependName);
-                // XXX: Need to clean up before returning
-                return false;
-            }
-            psFree(dependName);
-            // Find the value of the dependent concept
-            psMetadataItem *depItem = pmConceptReadFromHeader(fpa, chip, cell, dependsOn);
-            if (! depItem) {
-                psError(PS_ERR_IO, true, "Unable to find value for %s (required for %s)\n", dependsOn,
-                        concept->name);
-                return false;
-            }
-            if (depItem->type != PS_DATA_STRING) {
-                psError(PS_ERR_IO, true, "Value of %s is not of type string, as required for dependency"
-                        " --- ignored.\n", dependsOn);
-            }
-
-            defItem = psMetadataLookup(dependents, depItem->data.V); // This is now what we were after
-        }
-
-        status = compareConcepts(defItem, concept);
-        if (! status) {
-            psError(PS_ERR_IO, true, "Concept %s is specified by default in the camera configuration, "
-                    "but doesn't match the actual value.\n", concept->name);
-        }
-    }
-
-    // XXX: Need to clean up before returning
-    return status;
-}
-
-
-// XXX: Not tested at all
-// XXX I WOULD NOT TRUST THIS FUNCTION IN THE SLIGHTEST YET! --- PAP
-bool pmConceptWriteToDB(pmFPA *fpa, // The FPA that contains the chip
-                        pmChip *chip, // The chip that contains the cell
-                        pmCell *cell, // The cell
-                        psDB *db,    // DB handle
-                        psMetadataItem *concept // Concept
-                       )
-{
-    if (! db) {
-        // No database initialised
-        return false;
-    }
-
-    bool mdStatus = true;               // Status of MD lookup
-    if (! fpa->camera) {
-        return false;
-    }
-    psMetadata *database = psMetadataLookupMD(&mdStatus, fpa->camera, "DATABASE");
-    if (! mdStatus) {
-        // No error, because not everyone needs to use the DB
-        return NULL;
-    }
-
-    psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, database, concept->name);
-    if (dbLookup) {
-        const char *tableName = psMetadataLookupStr(&mdStatus, dbLookup, "TABLE"); // Name of the table
-        //        const char *colName = psMetadataLookupStr(&mdStatus, dbLookup, "COLUMN"); // Name of the column
-        const char *givenCols = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENDBCOL"); // Name of "where"
-        // columns
-        const char *givenPS = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENPS"); // Values for "where"
-        // columns
-
-        // Now, need to get the "given"s
-        if (strlen(givenCols) || strlen(givenPS)) {
-            psList *cols = psStringSplit(givenCols, ",;", true); // List of column names
-            psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns
-            psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
-            if (cols->n != values->n) {
-                psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "
-                         "the same number of entries --- ignored.\n", concept);
-            } else {
-                // Iterators for the lists
-                psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
-                psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
-                char *column = NULL;    // Name of the column
-                while ((column = psListGetAndIncrement(colsIter))) {
-                    char *name = psListGetAndIncrement(valuesIter); // Name for the value
-                    if (!strlen(column) || !strlen(name)) {
-                        psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
-                                 " empty --- ignored.\n", concept);
-                    } else {
-                        // Search for the value name
-                        psMetadataItem *item = pmConceptReadFromHeader(fpa, chip, cell, name);
-                        if (! item) {
-                            item = pmConceptReadFromDefault(fpa, chip, cell, name);
-                        }
-                        if (! item) {
-                            psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "
-                                     " lookup on %s --- ignored.\n", name, concept);
-                        } else {
-                            // We need to create a new psMetadataItem.  I don't think we can't simply hack
-                            // the existing one, since that could conceivably cause memory leaks
-                            psMetadataItem *newItem = psMetadataItemAlloc(concept->name, item->type,
-                                                      item->comment, item->data.V);
-                            psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);
-                            psFree(newItem);
-                        }
-                    }
-                    psFree(name);
-                    psFree(column);
-                } // Iterating through the columns
-                psFree(colsIter);
-                psFree(valuesIter);
-
-                // Check first to make sure we're only going to touch one row
-                psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result
-                // Note that we use limit=2 in order to test if there are multiple rows returned
-                if (! dbResult || dbResult->n == 0) {
-                    psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- ignored\n",
-                             concept->name);
-                    return false;
-                } else {
-                    if (dbResult->n > 1) {
-                        psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s --- "
-                                 " ignored.\n", concept->name);
-                    }
-                    // Update the DB
-                    psMetadata *update = psMetadataAlloc();
-                    psMetadataAddItem(update, concept, PS_LIST_HEAD, 0);
-                    psDBUpdateRows(db, tableName, selection, update);
-                    psFree(update);
-                    return true;
-                }
-            }
-            psFree(cols);
-            psFree(values);
-        }
-    } // Doing the "given"s.
-
-    psAbort(__func__, "Shouldn't ever get here?\n");
-    return false;
-}
-
-
-// Concept write from item
-bool pmConceptWriteItem(pmFPA *fpa,     // The FPA
-                        pmChip *chip,   // The chip
-                        pmCell *cell,   // The cell
-                        psDB *db,       // DB handle
-                        psMetadataItem *concept // Concept item
-                       )
-{
-    if (! fpa->camera) {
-        return false;
-    }
-
-    // Try headers, database, defaults in order
-    psTrace(__func__, 3, "Trying to set concept %s...\n", concept->name);
-    bool status = pmConceptWriteToCamera(cell, concept); // Status for return
-    if (! status) {
-        psTrace(__func__, 5, "Trying header....\n");
-        status = pmConceptWriteToHeader(fpa, chip, cell, concept);
-    }
-    if (! status) {
-        psTrace(__func__, 5, "Trying database....\n");
-        status = pmConceptWriteToDB(fpa, chip, cell, db, concept);
-    }
-    if (! status) {
-        psTrace(__func__, 5, "Checking defaults....\n");
-        status = pmConceptWriteToDefault(fpa, chip, cell, concept);
-    }
-
-    if (! status) {
-        psError(PS_ERR_IO, true, "Unable to set %s (%s).\n", concept->name, concept->comment);
-    }
-
-    return status;
-}
-
-
-// Concept write
-bool pmConceptWrite(pmFPA *fpa, // The FPA
-                    pmChip *chip,// The chip
-                    pmCell *cell,    // The cell
-                    psDB *db, // DB handle
-                    psMetadata *concepts, // Concepts MD from which to set
-                    const char *name // Name of the concept
-                   )
-{
-    psMetadataItem *concept = psMetadataLookup(concepts, name);
-    if (! concept) {
-        psError(PS_ERR_IO, true, "No such concept as %s\n", name);
-        return false;
-    }
-    return pmConceptWriteItem(fpa, chip, cell, db, concept);
-}
-
-#endif
Index: /trunk/psModules/src/config/pmConfig.c
===================================================================
--- /trunk/psModules/src/config/pmConfig.c	(revision 7277)
+++ /trunk/psModules/src/config/pmConfig.c	(revision 7278)
@@ -3,6 +3,6 @@
  *  @author PAP, IfA
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-23 23:37:23 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:22 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -69,4 +69,8 @@
     const char *description)            // Description of file
 {
+    assert(config);
+    assert(name && strlen(name) > 0);
+    assert(description && strlen(description) > 0);
+
     char *realName = NULL;
     unsigned int numBadLines = 0;
@@ -303,5 +307,6 @@
         }
         if (logFD == STDIN_FILENO) {
-            psLogMsg(__func__, PS_LOG_WARN, "Only STDERR and STDOUT currently supported as a log destination.\n");
+            psLogMsg(__func__, PS_LOG_WARN, "Only STDERR and STDOUT currently supported as a log "
+                     "destination.\n");
             logFD = STDERR_FILENO;
         }
@@ -352,4 +357,7 @@
     const psMetadata *header)
 {
+    PS_ASSERT_PTR_NON_NULL(cameraFormat, false);
+    PS_ASSERT_PTR_NON_NULL(header, false);
+
     // Read the rule for that camera format
     bool mdStatus = true;
@@ -395,4 +403,5 @@
     assert(camera);
     assert(header);
+    assert(cameraName && strlen(cameraName) > 0);
 
     bool result = false;                // Did we find the first match?
@@ -449,4 +458,7 @@
 )
 {
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(header, NULL);
+
     psMetadata *format = NULL;          // The winning format
     bool mdok = false;                  // Metadata lookup status
@@ -562,9 +574,12 @@
 )
 {
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config->site, NULL);
+
     #ifdef OMIT_PSDB
+
     return NULL;
     #else
 
-    PS_ASSERT_PTR_NON_NULL(config->site, NULL);
     psBool mdStatus01 = false;
     psBool mdStatus02 = false;
@@ -590,4 +605,7 @@
                           )
 {
+    PS_ASSERT_PTR_NON_NULL(header, false);
+    PS_ASSERT_PTR_NON_NULL(format, false);
+
     bool mdok = true;                   // Status of MD lookup
     psMetadata *rules = psMetadataLookupMD(&mdok, format, "RULE"); // How to identify this format
@@ -613,4 +631,11 @@
 psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list)
 {
+    PS_ASSERT_PTR_NON_NULL(argc, NULL);
+    PS_ASSERT_INT_NONNEGATIVE(*argc, NULL);
+    PS_ASSERT_PTR_NON_NULL(argv, NULL);
+    PS_ASSERT_PTR_NON_NULL(file, NULL);
+    PS_ASSERT_INT_POSITIVE(strlen(file), NULL);
+    PS_ASSERT_PTR_NON_NULL(list, NULL);
+    PS_ASSERT_INT_POSITIVE(strlen(list), NULL);
 
     int Narg;
@@ -670,4 +695,14 @@
 bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list)
 {
+    PS_ASSERT_PTR_NON_NULL(metadata, false);
+    PS_ASSERT_PTR_NON_NULL(argc, false);
+    PS_ASSERT_INT_NONNEGATIVE(*argc, NULL);
+    PS_ASSERT_PTR_NON_NULL(argv, false);
+    PS_ASSERT_PTR_NON_NULL(name, false);
+    PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    PS_ASSERT_INT_POSITIVE(strlen(file), NULL);
+    PS_ASSERT_PTR_NON_NULL(list, false);
+    PS_ASSERT_INT_POSITIVE(strlen(list), NULL);
 
     psArray *files = pmConfigFileSets (argc, argv, file, list);
Index: /trunk/psModules/src/detrend/pmFlatField.c
===================================================================
--- /trunk/psModules/src/detrend/pmFlatField.c	(revision 7277)
+++ /trunk/psModules/src/detrend/pmFlatField.c	(revision 7278)
@@ -1,8 +1,2 @@
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
-// one that was being worked on.
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
 /** @file  pmFlatField.c
  *
@@ -24,6 +18,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-17 18:10:08 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:23 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -46,6 +40,15 @@
 bool pmFlatField(pmReadout *in, const pmReadout *flat)
 {
-    int i = 0;
-    int j = 0;
+    PS_ASSERT_PTR_NON_NULL(in, false);
+    PS_ASSERT_PTR_NON_NULL(in->image, false);
+    PS_ASSERT_IMAGE_NON_EMPTY(in->image, false);
+    PS_ASSERT_PTR_NON_NULL(flat, false);
+    PS_ASSERT_PTR_NON_NULL(flat->image, false);
+    PS_ASSERT_IMAGE_NON_EMPTY(flat->image, false);
+    if (in->mask) {
+        PS_ASSERT_IMAGE_TYPE(in->mask, PS_TYPE_U8, false);
+    }
+    PS_ASSERT_IMAGE_TYPE(flat->image, in->image->type.type, false);
+
     int totOffCol = 0;
     int totOffRow = 0;
@@ -147,39 +150,33 @@
 
     // Macro for all PS types
-    #define PM_FLAT_DIVISION(TYPE)                                                                           \
-case PS_TYPE_##TYPE:                                                                                         \
-    /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */  \
-    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
-        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
-            if(flatImage->data.TYPE[j][i] <= 0.0) {                                                          \
-                /* Negative or zero flat pixels shall be masked in input image as  PM_MASK_FLAT */           \
-                if (inMask) {                                                                                \
-                    inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT;                                    \
-                }                                                                                            \
-                flatImage->data.TYPE[j][i] = 0.0;                                                            \
-            }                                                                                                \
-        }                                                                                                    \
-    }                                                                                                        \
-    for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
-        for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
-            if(inMask && !inMask->data.PS_TYPE_MASK_DATA[j][i]) {                                            \
-                /* Module shall divide the input image by the flat-fielded image */                          \
-                inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i];                                      \
-            }                                                                                                \
-        }                                                                                                    \
-    }                                                                                                        \
+    #define FLAT_DIVISION_CASE(TYPE) \
+case PS_TYPE_##TYPE: \
+    for (long j = totOffRow; j < inImage->numRows; j++) { \
+        for (long i = totOffCol; i < inImage->numCols; i++) { \
+            if (flatImage->data.TYPE[j][i] <= 0.0) { \
+                if (inMask) { \
+                    inMask->data.U8[j][i] |= PM_MASK_FLAT; \
+                } \
+                flatImage->data.TYPE[j][i] = 0.0; \
+            } else { \
+                if (!inMask || !inMask->data.U8[j][i]) { \
+                    inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \
+                } \
+            } \
+        } \
+    } \
     break;
 
     switch(inType) {
-        PM_FLAT_DIVISION(U8);
-        PM_FLAT_DIVISION(U16);
-        PM_FLAT_DIVISION(U32);
-        PM_FLAT_DIVISION(U64);
-        PM_FLAT_DIVISION(S8);
-        PM_FLAT_DIVISION(S16);
-        PM_FLAT_DIVISION(S32);
-        PM_FLAT_DIVISION(S64);
-        PM_FLAT_DIVISION(F32);
-        PM_FLAT_DIVISION(F64);
+        FLAT_DIVISION_CASE(U8);
+        FLAT_DIVISION_CASE(U16);
+        FLAT_DIVISION_CASE(U32);
+        FLAT_DIVISION_CASE(U64);
+        FLAT_DIVISION_CASE(S8);
+        FLAT_DIVISION_CASE(S16);
+        FLAT_DIVISION_CASE(S32);
+        FLAT_DIVISION_CASE(S64);
+        FLAT_DIVISION_CASE(F32);
+        FLAT_DIVISION_CASE(F64);
     default:
         psError( PS_ERR_BAD_PARAMETER_TYPE, true,
Index: /trunk/psModules/src/detrend/pmFlatField.h
===================================================================
--- /trunk/psModules/src/detrend/pmFlatField.h	(revision 7277)
+++ /trunk/psModules/src/detrend/pmFlatField.h	(revision 7278)
@@ -1,8 +1,2 @@
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
-// one that was being worked on.
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
 /** @file  pmFlatField.h
  *
@@ -24,6 +18,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-17 18:01:05 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:23 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
Index: /trunk/psModules/src/detrend/pmFlatNormalize.c
===================================================================
--- /trunk/psModules/src/detrend/pmFlatNormalize.c	(revision 7277)
+++ /trunk/psModules/src/detrend/pmFlatNormalize.c	(revision 7278)
@@ -15,4 +15,7 @@
                          )
 {
+    PS_ASSERT_PTR_NON_NULL(chipGains, NULL);
+    PS_ASSERT_PTR_NON_NULL(fluxLevels, NULL);
+
     int numSources = fluxLevels->numRows; // Number of integrations
     int numChips = fluxLevels->numCols; // Number of chips with which each integration is made
Index: /trunk/psModules/src/detrend/pmFringeStats.c
===================================================================
--- /trunk/psModules/src/detrend/pmFringeStats.c	(revision 7277)
+++ /trunk/psModules/src/detrend/pmFringeStats.c	(revision 7278)
@@ -3,6 +3,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-17 00:55:35 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:23 $
  *
  *  Copyright 2004 IfA
@@ -61,4 +61,7 @@
 bool pmFringeRegionsCreatePoints(pmFringeRegions *fringe, const psImage *image)
 {
+    PS_ASSERT_PTR_NON_NULL(fringe, false);
+    PS_ASSERT_PTR_NON_NULL(image, false);
+    PS_ASSERT_IMAGE_NON_EMPTY(image, false);
 
     double frnd;
@@ -106,4 +109,6 @@
 pmFringeStats *pmFringeStatsAlloc(pmFringeRegions *regions)
 {
+    PS_ASSERT_PTR_NON_NULL(regions, false);
+
     pmFringeStats *stats = psAlloc(sizeof(pmFringeStats));
     (void)psMemSetDeallocator(stats, (psFreeFunc)fringeStatsFree);
@@ -120,4 +125,9 @@
 pmFringeStats *pmFringeStatsMeasure(pmFringeRegions *fringe, pmReadout *readout, psMaskType maskVal)
 {
+    PS_ASSERT_PTR_NON_NULL(fringe, NULL);
+    PS_ASSERT_PTR_NON_NULL(readout, NULL);
+    PS_ASSERT_PTR_NON_NULL(readout->image, NULL);
+    PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL);
+
     if (!fringe->x || !fringe->y) {
         // create the fringe vectors for this image
@@ -364,4 +374,9 @@
                                     unsigned int nIter, float keepFrac)
 {
+    PS_ASSERT_PTR_NON_NULL(science, NULL);
+    PS_ASSERT_PTR_NON_NULL(fringes, NULL);
+    PS_ASSERT_INT_POSITIVE(fringes->n, NULL);
+    PS_ASSERT_INT_POSITIVE(nIter, NULL);
+
     pmFringeRegions *regions = science->regions; // The fringe regions
     int numRegions = regions->nRequested; // Number of regions
@@ -439,4 +454,13 @@
                          unsigned int nIter, float keepFrac)
 {
+    PS_ASSERT_PTR_NON_NULL(readout, NULL);
+    PS_ASSERT_PTR_NON_NULL(readout->image, NULL);
+    PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL);
+    PS_ASSERT_PTR_NON_NULL(fringes, NULL);
+    PS_ASSERT_PTR_NON_NULL(fringeImages, NULL);
+    PS_ASSERT_PTR_NON_NULL(fringeStats, NULL);
+    PS_ASSERT_INT_EQUAL(fringeImages->n, fringeStats->n, NULL);
+    PS_ASSERT_INT_POSITIVE(nIter, NULL);
+
     // measure the fringe stats for the science frame and solve for the scales
     pmFringeStats *scienceStats = pmFringeStatsMeasure(fringes, readout, maskVal);
Index: /trunk/psModules/src/detrend/pmSubtractBias.c
===================================================================
--- /trunk/psModules/src/detrend/pmSubtractBias.c	(revision 7277)
+++ /trunk/psModules/src/detrend/pmSubtractBias.c	(revision 7278)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-01 01:56:29 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:23 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -146,24 +146,4 @@
 
 
-#if 0
-/******************************************************************************
-ImageSubtractScalar(): subtract a scalar from the input image.
- 
-XXX: Use a psLib function for this.
- 
-XXX: This should
- *****************************************************************************/
-static psImage *ImageSubtractScalar(psImage *image,
-                                    psF32 scalar)
-{
-    for (psS32 i=0;i<image->numRows;i++) {
-        for (psS32 j=0;j<image->numCols;j++) {
-            image->data.F32[i][j]-= scalar;
-        }
-    }
-    return(image);
-}
-#endif
-
 /******************************************************************************
 GenNewStatOptions(): this routine will take as input the options member of the
@@ -175,4 +155,6 @@
 static psStatsOptions GenNewStatOptions(const psStats *stat)
 {
+    assert(stat);
+
     psS32 numOptions = 0;
     psStatsOptions opt = 0;
@@ -210,116 +192,10 @@
     if (numOptions != 1) {
         psLogMsg(__func__, PS_LOG_WARN,
-                 "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options have been specified\n");
-    }
-    return(opt);
-}
-
-
-
-#if 0
-/******************************************************************************
-ScaleOverscanVector(): this routine takes as input an arbitrary vector,
-creates a new vector of length n, and fills the new vector with the
-interpolated values of the old vector.  The type of interpolation is:
-    PM_FIT_POLYNOMIAL: fit a polynomial to the entire input vector data.
-    PM_FIT_SPLINE: fit splines to the input vector data.
-XXX: Doesn't it make more sense to do polynomial interpolation on a few
-elements of the input vector, rather than fit a polynomial to the entire
-vector?
- *****************************************************************************/
-static psVector *ScaleOverscanVector(psVector *overscanVector,
-                                     psS32 n,
-                                     void *fitSpec,
-                                     pmFit fit)
-{
-    psTrace(".psModule.pmSubtracBias.ScaleOverscanVector", 4,
-            "---- ScaleOverscanVector() begin (%d -> %d) ----\n", overscanVector->n, n);
-    //    PS_VECTOR_PRINT_F32(overscanVector);
-
-    if (NULL == overscanVector) {
-        return(overscanVector);
-    }
-
-    // Allocate the new vector.
-    psVector *newVec = psVectorAlloc(n, PS_TYPE_F32);
-
-    //
-    // If the new vector is the same size as the old, simply copy the data.
-    //
-    if (n == overscanVector->n) {
-        for (psS32 i = 0 ; i < n ; i++) {
-            newVec->data.F32[i] = overscanVector->data.F32[i];
-        }
-        return(newVec);
-    }
-    psPolynomial1D *myPoly;
-    psSpline1D *mySpline;
-    psF32 x;
-    psS32 i;
-    if (fit == PM_FIT_POLYNOMIAL) {
-        // Fit a polynomial to the old overscan vector.
-        myPoly = (psPolynomial1D *) fitSpec;
-        PS_ASSERT_POLY_NON_NULL(myPoly, NULL);
-        myPoly = psVectorFitPolynomial1D(myPoly, NULL, 0, overscanVector, NULL, NULL);
-        if (myPoly == NULL) {
-            psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector()(1): Could not fit a polynomial to the psVector.\n");
-            return(NULL);
-        }
-
-        // For each element of the new vector, convert the x-ordinate to that
-        // of the old vector, use the fitted polynomial to determine the
-        // interpolated value at that point, and set the new vector.
-        for (i=0;i<n;i++) {
-            x = ((psF32) i) * ((psF32) overscanVector->n) / ((psF32) n);
-            newVec->data.F32[i] = psPolynomial1DEval(myPoly, x);
-        }
-    } else if (fit == PM_FIT_SPLINE) {
-        psS32 mustFreeSpline = 0;
-        // Fit a spline to the old overscan vector.
-        mySpline = (psSpline1D *) fitSpec;
-        // XXX: Does it make any sense to have a psSpline argument?
-        if (mySpline == NULL) {
-            mustFreeSpline = 1;
-        }
-
-        //
-        // NOTE: Since the X arg in the psVectorFitSpline1D() function is NULL,
-        // splines endpoints will be from 0.0 to overscanVector->n-1.  Must scale
-        // properly when doing the spline eval.
-        //
-        //        mySpline = psVectorFitSpline1D(mySpline, NULL, overscanVector, NULL);
-        mySpline = psVectorFitSpline1D(NULL, overscanVector);
-        if (mySpline == NULL) {
-            psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector()(2): Could not fit a spline to the psVector.\n");
-            return(NULL);
-        }
-        //        PS_PRINT_SPLINE(mySpline);
-
-        // For each element of the new vector, convert the x-ordinate to that
-        // of the old vector, use the fitted polynomial to determine the
-        // interpolated value at that point, and set the new vector.
-        for (i=0;i<n;i++) {
-            // Scale to [0 : overscanVector->n - 1]
-            x = ((psF32) i) * ((psF32) (overscanVector->n-1)) / ((psF32) n);
-            newVec->data.F32[i] = psSpline1DEval(mySpline, x);
-        }
-        if (mustFreeSpline ==1) {
-            psFree(mySpline);
-        }
-        //        PS_VECTOR_PRINT_F32(newVec);
-
-
-    } else {
-        psError(PS_ERR_UNKNOWN, true, "unknown fit type.  Returning NULL.\n");
-        psFree(newVec);
-        return(NULL);
-    }
-
-    psTrace(".psModule.pmSubtracBias.ScaleOverscanVector", 4,
-            "---- ScaleOverscanVector() exit ----\n");
-    return(newVec);
-}
-
-#endif
+                 "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options "
+                 "have been specified\n");
+    }
+    return opt;
+}
+
 
 // Produce an overscan vector from an array of pixels
@@ -329,4 +205,8 @@
                                )
 {
+    assert(overscanOpts);
+    assert(pixels);
+    assert(myStats);
+
     // Reduce the overscans
     psVector *reduced = psVectorAlloc(pixels->n, PS_TYPE_F32); // Overscan for each row
@@ -416,7 +296,16 @@
     psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4,
             "---- pmSubtractBias() begin ----\n");
-    PS_ASSERT_READOUT_NON_NULL(in, NULL);
-    PS_ASSERT_READOUT_NON_EMPTY(in, NULL);
-    PS_ASSERT_READOUT_TYPE(in, PS_TYPE_F32, NULL);
+    PS_ASSERT_PTR_NON_NULL(in, NULL);
+    PS_ASSERT_IMAGE_NON_NULL(in->image, NULL);
+    PS_ASSERT_IMAGE_TYPE(in->image, PS_TYPE_F32, NULL);
+    PS_ASSERT_PTR_NON_NULL(overscanOpts, NULL);
+    if (bias) {
+        PS_ASSERT_IMAGE_NON_NULL(bias->image, NULL);
+        PS_ASSERT_IMAGE_TYPE(bias->image, PS_TYPE_F32, NULL);
+    }
+    if (dark) {
+        PS_ASSERT_IMAGE_NON_NULL(dark->image, NULL);
+        PS_ASSERT_IMAGE_TYPE(dark->image, PS_TYPE_F32, NULL);
+    }
 
     psImage *image = in->image;         // The input image
Index: /trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7277)
+++ /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7278)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-01 03:39:15 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-02 00:55:23 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -30,4 +30,6 @@
                             )
 {
+    assert(stats);
+
     switch (option) {
     case PS_STAT_SAMPLE_MEAN:
@@ -96,25 +98,19 @@
     if (zero) {
         PS_ASSERT_VECTOR_TYPE(zero, PS_TYPE_F32, false);
-        if (zero->n != inputs->n) {
-            psError(PS_ERR_UNKNOWN, true, "Zero vector has incorrect size (%d vs %d).\n",
-                    zero->n, inputs->n);
-            return false;
-        }
+        PS_ASSERT_VECTOR_SIZE(zero, inputs->n, false);
     }
     if (scale) {
         PS_ASSERT_VECTOR_TYPE(scale, PS_TYPE_F32, false);
-        if (scale->n != inputs->n) {
-            psError(PS_ERR_UNKNOWN, true, "Scale vector has incorrect size (%d vs %d).\n",
-                    scale->n, inputs->n);
-            return false;
-        }
-    }
-    assert(params->fracLow >= 0.0 && params->fracLow < 1.0);
-    assert(params->fracHigh >= 0.0 && params->fracHigh < 1.0);
-    assert(params->combine == PS_STAT_SAMPLE_MEAN ||
-           params->combine == PS_STAT_SAMPLE_MEDIAN ||
-           params->combine == PS_STAT_ROBUST_MEDIAN ||
-           params->combine == PS_STAT_FITTED_MEAN ||
-           params->combine == PS_STAT_CLIPPED_MEAN);
+        PS_ASSERT_VECTOR_SIZE(scale, inputs->n, false);
+    }
+    PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracLow, 0.0, 1.0, false);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracHigh, 0.0, 1.0, false);
+    if (params->combine != PS_STAT_SAMPLE_MEAN && params->combine != PS_STAT_SAMPLE_MEDIAN &&
+            params->combine != PS_STAT_ROBUST_MEDIAN && params->combine != PS_STAT_FITTED_MEAN &&
+            params->combine != PS_STAT_CLIPPED_MEAN) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Combination method is not SAMPLE_MEAN, SAMPLE_MEDIAN, "
+                "ROBUST_MEDIAN, FITTED_MEAN or CLIPPED_MEAN.\n");
+        return false;
+    }
 
     psStats *stats = psStatsAlloc(params->combine); // The statistics to use in the combination
