Index: /trunk/psModules/src/astrom/pmAstrometry.c
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometry.c	(revision 5542)
+++ /trunk/psModules/src/astrom/pmAstrometry.c	(revision 5543)
@@ -8,6 +8,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-20 23:06:24 $
+*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-11-18 19:43:14 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -23,4 +23,22 @@
 #include "pmAstrometry.h"
 
+void PS_PRINT_POLY2D(psPolynomial2D *poly)
+{
+    for (psS32 x = 0 ; x < poly->nX+1 ; x++) {
+        for (psS32 y = 0 ; y < poly->nY+1 ; y++) {
+            printf("    (%.2f x^%d y^%d)\n", poly->coeff[x][y], x, y);
+        }
+    }
+}
+
+void PS_PRINT_PLANE_TRANSFORM(psPlaneTransform *pt)
+{
+    printf("---------------------- Plane Transform ----------------------\n");
+    printf("x:\n");
+    PS_PRINT_POLY2D(pt->x);
+    printf("y:\n");
+    PS_PRINT_POLY2D(pt->y);
+}
+
 /*****************************************************************************
 checkValidImageCoords(): this is a private function which simply determines if
@@ -29,4 +47,5 @@
 XXX: What about col0 and row0
 XXX: This should return a psBool.
+XXX: Macro this for speed.
  *****************************************************************************/
 static psS32 checkValidImageCoords(double x,
@@ -36,6 +55,5 @@
     PS_ASSERT_IMAGE_NON_NULL(tmpImage, 0);
 
-    if ((x < 0.0) || (x > (double)tmpImage->numCols) ||
-            (y < 0.0) || (y > (double)tmpImage->numRows)) {
+    if ((x < 0.0) || (x > (double)tmpImage->numCols) || (y < 0.0) || (y > (double)tmpImage->numRows)) {
         return (0);
     }
@@ -45,12 +63,69 @@
 
 /******************************************************************************
-XXX: Is this the correct way to free metadata?
-XXX: Is this the correct way to free database structs?
- 
- 
- 
-XXX: The memory dereferencing is not quite right with these functions.  If I
-call the alloc functions with non-NULL pointers, there will be memory leaks.
  *****************************************************************************/
+static void readoutFree(pmReadout *readout)
+{
+    if (readout != NULL) {
+        psFree(readout->image);
+        psFree(readout->mask);
+        psFree(readout->weight);
+        psFree(readout->bias);
+        psFree(readout->analysis);
+        psFree(readout->parent);
+    }
+}
+
+#define BIG_BANG 1
+static void cellFree(pmCell *cell)
+{
+    if (cell != NULL) {
+        psFree(cell->toChip);
+        psFree(cell->toFPA);
+        psFree(cell->toSky);
+        psFree(cell->concepts);
+        psFree(cell->camera);
+        psFree(cell->analysis);
+        //
+        // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
+        // in order to avoid memory reference counter problems.
+        //
+        for (psS32 i = 0 ; i < cell->readouts->n ; i++) {
+            pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i];
+            tmpReadout->parent = NULL;
+            if (BIG_BANG == 1) {
+                psFree(tmpReadout);
+            }
+        }
+        psFree(cell->readouts);
+        psFree(cell->parent);
+        psFree(cell->private);
+    }
+}
+
+static void chipFree(pmChip* chip)
+{
+    if (chip != NULL) {
+        psFree(chip->toFPA);
+        psFree(chip->fromFPA);
+        psFree(chip->concepts);
+        psFree(chip->analysis);
+        //
+        // Set the parent to NULL in all chip->cells before psFree(chip->cells)
+        // in order to avoid memory reference counter problems.
+        //
+        for (psS32 i = 0 ; i < chip->cells->n ; i++) {
+            pmCell *tmpCell = (pmCell *) chip->cells->data[i];
+            tmpCell->parent = NULL;
+            if (BIG_BANG == 1) {
+                psFree(tmpCell);
+            }
+        }
+        psFree(chip->cells);
+        psFree(chip->parent);
+        psFree(chip->private);
+    }
+}
+
+
 static void FPAFree(pmFPA *fpa)
 {
@@ -69,64 +144,11 @@
             pmChip *tmpChip = (pmChip *) fpa->chips->data[i];
             tmpChip->parent = NULL;
+            if (BIG_BANG == 1) {
+                psFree(tmpChip);
+            }
         }
         psFree(fpa->chips);
         psFree(fpa->private);
         psFree(fpa->phu);
-    }
-}
-
-static void chipFree(pmChip* chip)
-{
-    if (chip != NULL) {
-        psFree(chip->toFPA);
-        psFree(chip->fromFPA);
-        psFree(chip->concepts);
-        psFree(chip->analysis);
-        //
-        // Set the parent to NULL in all chip->cells before psFree(chip->cells)
-        // in order to avoid memory reference counter problems.
-        //
-        for (psS32 i = 0 ; i < chip->cells->n ; i++) {
-            pmCell *tmpCell = (pmCell *) chip->cells->data[i];
-            tmpCell->parent = NULL;
-        }
-        psFree(chip->cells);
-        psFree(chip->parent);
-        psFree(chip->private);
-    }
-}
-
-static void cellFree(pmCell *cell)
-{
-    if (cell != NULL) {
-        psFree(cell->toChip);
-        psFree(cell->toFPA);
-        psFree(cell->toSky);
-        psFree(cell->concepts);
-        psFree(cell->camera);
-        psFree(cell->analysis);
-        //
-        // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
-        // in order to avoid memory reference counter problems.
-        //
-        for (psS32 i = 0 ; i < cell->readouts->n ; i++) {
-            pmReadout *tmpReadout = (pmReadout *) cell->readouts->data[i];
-            tmpReadout->parent = NULL;
-        }
-        psFree(cell->readouts);
-        psFree(cell->parent);
-        psFree(cell->private);
-    }
-}
-
-static void readoutFree(pmReadout *readout)
-{
-    if (readout != NULL) {
-        psFree(readout->image);
-        psFree(readout->mask);
-        psFree(readout->weight);
-        psFree(readout->bias);
-        psFree(readout->analysis);
-        psFree(readout->parent);
     }
 }
@@ -154,9 +176,9 @@
 }
 
+// XXX: Verify these default values for row0, col0, rowBins, colBins
 pmCell *pmCellAlloc(
     pmChip *chip,
     psMetadata *cameradata,
-    psString name
-)
+    psString name)
 {
     pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell));
@@ -189,6 +211,5 @@
 pmChip *pmChipAlloc(
     pmFPA *fpa,
-    psString name
-)
+    psString name)
 {
     pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip));
@@ -295,11 +316,11 @@
 
 
-// HEY
 /*****************************************************************************/
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
 /*****************************************************************************/
 
-pmCell* pmCellInFPA(const psPlane* fpaCoord,
-                    const pmFPA* FPA)
+pmCell* pmCellInFPA(
+    const psPlane* fpaCoord,
+    const pmFPA* FPA)
 {
     PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
@@ -317,5 +338,5 @@
 
     // Convert to those chip coordinates.
-    psCoordFPAToChip(&chipCoord, fpaCoord, tmpChip);
+    pmCoordFPAToChip(&chipCoord, fpaCoord, tmpChip);
 
     // Determine which cell contains those chip coordinates.
@@ -325,6 +346,7 @@
 }
 
-pmChip* pmChipInFPA(const psPlane* fpaCoord,
-                    const pmFPA* FPA)
+pmChip* pmChipInFPA(
+    const psPlane* fpaCoord,
+    const pmFPA* FPA)
 {
     PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
@@ -337,8 +359,11 @@
     pmCell *tmpCell = NULL;
 
+    //
     // Loop through every chip in this FPA.  Convert the original FPA
     // coordinates to chip coordinates for that chip.  Then, determine if any
     // cells in that chip contain those chip coordinates.
-
+    // XXX: Depending on the number of chips, and their topology, there may be
+    // a much more efficient way of doing this.
+    //
     for (psS32 i = 0; i < nChips; i++) {
         pmChip* tmpChip = chips->data[i];
@@ -359,6 +384,7 @@
 
 
-pmCell* pmCellInChip(const psPlane* chipCoord,
-                     const pmChip* chip)
+pmCell* pmCellInChip(
+    const psPlane* chipCoord,
+    const pmChip* chip)
 {
     PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);
@@ -373,8 +399,11 @@
     }
 
+    //
     // We loop over each cell in the chip.  We transform the chipCoord into
     // a cellCoord for that cell and determine if that cellCoord is valid.
     // If so, then we return that cell.
-
+    // XXX: Depending on the number of cells, and their topology, there may be
+    // a much more efficient way of doing this.
+    //
     for (psS32 i = 0; i < cells->n; i++) {
         pmCell* tmpCell = (pmCell* ) cells->data[i];
@@ -382,10 +411,10 @@
 
         psPlaneTransform *chipToCell = NULL;
-        if (1 != p_psIsProjectionLinear(tmpCell->toChip)) {
+        if (true ==  p_psIsProjectionLinear(tmpCell->toChip)) {
+            chipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);
+        } else {
             // XXX: Generate warning message.
             // XXX: Can we use the following function to derive a transform?
             // chipToCell = psPlaneTransformInvert(NULL, tmpCell->toChip, NULL, -1);
-        } else {
-            chipToCell = p_psPlaneTransformLinearInvert(tmpCell->toChip);
         }
 
@@ -405,4 +434,5 @@
                                           cellCoord.y,
                                           tmpReadout->image)) {
+                    psFree(chipToCell);
                     return (tmpCell);
                 }
@@ -416,7 +446,8 @@
 
 
-psPlane* psCoordCellToChip(psPlane* outCoord,
-                           const psPlane* inCoord,
-                           const pmCell* cell)
+psPlane* pmCoordCellToChip(
+    psPlane* outCoord,
+    const psPlane* inCoord,
+    const pmCell* cell)
 {
     PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
@@ -427,7 +458,8 @@
 
 
-psPlane* psCoordChipToFPA(psPlane* outCoord,
-                          const psPlane* inCoord,
-                          const pmChip* chip)
+psPlane* pmCoordChipToFPA(
+    psPlane* outCoord,
+    const psPlane* inCoord,
+    const pmChip* chip)
 {
     PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
@@ -438,45 +470,38 @@
 
 
-
-psPlane* psCoordFPAToTP(psPlane* outCoord,
-                        const psPlane* inCoord,
-                        double color,
-                        double magnitude,
-                        const pmFPA* fpa)
+psPlane* pmCoordFPAToTP(
+    psPlane* outCoord,
+    const psPlane* inCoord,
+    double color,
+    double magnitude,
+    const pmFPA* fpa)
 {
     PS_ASSERT_PTR_NON_NULL(inCoord, NULL);
     PS_ASSERT_PTR_NON_NULL(fpa, NULL);
 
-    return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord,
-                               color, magnitude));
+    return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord, color, magnitude));
 }
 
 /*****************************************************************************
 XXX: What about units for the (x,y) coords?
+ 
+XXX: This has not been tested.
  *****************************************************************************/
-psSphere* psCoordTPToSky(psSphere* outSphere,
-                         const psPlane* tpCoord,
-                         const psProjection *projection
-                        )
+psSphere* pmCoordTPToSky(
+    psSphere* outSphere,
+    const psPlane* tpCoord,
+    const psProjection *projection)
 {
     PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);
-
-    if (outSphere == NULL) {
-        outSphere = (psSphere* ) psAlloc(sizeof(psSphere));
-    }
-
-    // XXX: this was done by a SLALIB call -- needs to be reimplemented
-    psWarning("Warning!  psCoordTPToSky functionality is no longer implemented");
-    // slaAopqk(tpCoord->x, tpCoord->y, (double*)grommit,
-    //         &AOB, &ZOB, &HOB, &outSphere->r, &outSphere->d);
-
-    return (outSphere);
-}
-
-
-
-psPlane* psCoordCellToFPA(psPlane* fpaCoord,
-                          const psPlane* cellCoord,
-                          const pmCell* cell)
+    PS_ASSERT_PTR_NON_NULL(projection, NULL);
+
+    return(p_psDeproject(outSphere, tpCoord, projection));
+}
+
+
+psPlane* pmCoordCellToFPA(
+    psPlane* fpaCoord,
+    const psPlane* cellCoord,
+    const pmCell* cell)
 {
     PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
@@ -487,10 +512,12 @@
 
 
-
-psSphere* psCoordCellToSky(psSphere* skyCoord,
-                           const psPlane* cellCoord,
-                           double color,
-                           double magnitude,
-                           const pmCell* cell)
+// XXX: Should we check return codes of intermediate transforms?
+// XXX: This has not been tested.
+psSphere* pmCoordCellToSky(
+    psSphere* skyCoord,
+    const psPlane* cellCoord,
+    double color,
+    double magnitude,
+    const pmCell* cell)
 {
     PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
@@ -500,79 +527,35 @@
     PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
     PS_ASSERT_PTR_NON_NULL(cell->parent->parent->toTangentPlane, NULL);
-    //    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->exposure, NULL);
-
-    psPlane* fpaCoord = NULL;
-    psPlane* tpCoord = NULL;
+    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL);
+    psPlane fpaCoord;
+    psPlane tpCoord;
     pmFPA* parFPA = (cell->parent)->parent;
-    //    psGrommit* tmpGrommit = NULL;
 
     // Convert the input cell coordinates to FPA coordinates.
-    fpaCoord = psPlaneTransformApply(fpaCoord, cell->toFPA, cellCoord);
+    psPlaneTransformApply(&fpaCoord, cell->toFPA, cellCoord);
 
     // Convert the FPA coordinates to tangent plane Coordinates.
-    tpCoord = psPlaneDistortApply(tpCoord, parFPA->toTangentPlane,
-                                  fpaCoord, color, magnitude);
-
-    // Generate a grommit for this FPA.
-    //    tmpGrommit = psGrommitAlloc(parFPA->exposure);
+    psPlaneDistortApply(&tpCoord, parFPA->toTangentPlane, &fpaCoord, color, magnitude);
 
     // Convert the tangent plane Coordinates to sky coordinates.
-    //    skyCoord = psCoordTPToSky(skyCoord, tpCoord, tmpGrommit);
-
-    psFree(fpaCoord);
-    psFree(tpCoord);
-    //    psFree(tmpGrommit);
-
-    return(skyCoord);
-}
-
-
-psSphere* psCoordCellToSkyQuick(psSphere* outSphere,
-                                const psPlane* cellCoord,
-                                const pmCell* cell)
+    return(pmCoordTPToSky(NULL, &tpCoord, parFPA->projection));
+}
+
+
+// XXX: This has not been tested.
+// XXX: How do we get sphere coods from the cell->toSky plane transform?
+psSphere* pmCoordCellToSkyQuick(
+    psSphere* outSphere,
+    const psPlane* cellCoord,
+    const pmCell* cell)
 {
     PS_ASSERT_PTR_NON_NULL(cellCoord, NULL);
     PS_ASSERT_PTR_NON_NULL(cell, NULL);
     PS_ASSERT_PTR_NON_NULL(cell->toSky, NULL);
-    PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
-    PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
-    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL);
-
+
+    //    return(psPlaneTransformApply(outSphere, cell->toSky, cellCoord));
     psLogMsg(__func__, PS_LOG_WARN,
              "WARNING: psCoordCellToSkyQuick(): This function is not fully specified in the SDRS.  Returning NULL.\n");
     return(NULL);
-
-    /*
-        if (cell->toSky) {
-            // XXX: Should we use toTP or toSky?
-            psLogMsg(__func__, PS_LOG_WARN,
-                     "WARNING: psCoordCellToSkyQuick(): The cell->toSky transform is ignored.  The cell->toTP transform is being used.");
-        }
-     
-        psPlane *tpCoord = NULL;
-        pmChip *chip = cell->parent;
-        pmFPA *FPA = chip->parent;
-        psProjectionType oldProjectionType;
-     
-        if (outSphere == NULL) {
-            outSphere = (psSphere* ) psAlloc(sizeof(psSphere));
-        }
-     
-        // Determine the tangent plane coordinates.
-        tpCoord = psPlaneTransformApply(NULL, cell->toTP, cellCoord);
-     
-        // Save the old projection type and set the new projection type to TAN.
-        oldProjectionType = FPA->projection->type;
-        FPA->projection->type = PS_PROJ_TAN;
-     
-        // Deproject the tangent plane coordinates a sphere.
-        outSphere = psDeproject(tpCoord, FPA->projection);
-     
-        // Restore old projection type.  Free memory.
-        FPA->projection->type = oldProjectionType;
-        psFree(tpCoord);
-     
-        return (outSphere);
-    */
 }
 
@@ -580,31 +563,25 @@
 /*****************************************************************************
 XXX: What about units for the (x,y) coords?
+ 
+XXX: This has not been tested.
  *****************************************************************************/
-psPlane* psCoordSkyToTP(psPlane* tpCoord,
-                        const psSphere* in,
-                        const psProjection *projection)
+psPlane* pmCoordSkyToTP(
+    psPlane* tpCoord,
+    const psSphere* in,
+    const psProjection *projection)
 {
     PS_ASSERT_PTR_NON_NULL(in, NULL);
-    //    PS_ASSERT_PTR_NON_NULL(grommit, NULL);
-
-    // char* type = "RA";
-
-    if (tpCoord == NULL) {
-        tpCoord = (psPlane* ) psAlloc(sizeof(psPlane));
-    }
-
-    // XXX: this was done by a SLALIB call -- needs to be reimplemented
-    psWarning("Warning!  psCoordSkyToTP functionality is no longer implemented");
-    // slaOapqk(type, in->r, in->d, (double*)grommit, &tpCoord->x, &tpCoord->y);
-
-    return(tpCoord);
-}
-
-
-psPlane* psCoordTPToFPA(psPlane* fpaCoord,
-                        const psPlane* tpCoord,
-                        double color,
-                        double magnitude,
-                        const pmFPA* fpa)
+    PS_ASSERT_PTR_NON_NULL(projection, NULL);
+
+    return(p_psProject(tpCoord, in, projection));
+}
+
+
+psPlane* pmCoordTPToFPA(
+    psPlane* fpaCoord,
+    const psPlane* tpCoord,
+    double color,
+    double magnitude,
+    const pmFPA* fpa)
 {
     PS_ASSERT_PTR_NON_NULL(tpCoord, NULL);
@@ -612,12 +589,12 @@
     PS_ASSERT_PTR_NON_NULL(fpa->fromTangentPlane, NULL);
 
-    return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane,
-                                tpCoord, color, magnitude));
-}
-
-
-psPlane* psCoordFPAToChip(psPlane* chipCoord,
-                          const psPlane* fpaCoord,
-                          const pmChip* chip)
+    return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane, tpCoord, color, magnitude));
+}
+
+
+psPlane* pmCoordFPAToChip(
+    psPlane* chipCoord,
+    const psPlane* fpaCoord,
+    const pmChip* chip)
 {
     PS_ASSERT_PTR_NON_NULL(fpaCoord, NULL);
@@ -629,8 +606,8 @@
 }
 
-
-psPlane* psCoordChipToCell(psPlane* cellCoord,
-                           const psPlane* chipCoord,
-                           const pmCell* cell)
+psPlane* pmCoordChipToCell(
+    psPlane* cellCoord,
+    const psPlane* chipCoord,
+    const pmCell* cell)
 {
     PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);
@@ -648,9 +625,10 @@
 
 
-psPlane* psCoordSkyToCell(psPlane* cellCoord,
-                          const psSphere* skyCoord,
-                          float color,
-                          float magnitude,
-                          const pmCell* cell)
+psPlane* pmCoordSkyToCell(
+    psPlane* cellCoord,
+    const psSphere* skyCoord,
+    float color,
+    float magnitude,
+    const pmCell* cell)
 {
     PS_ASSERT_PTR_NON_NULL(skyCoord, NULL);
@@ -658,20 +636,18 @@
     PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
     PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
-    //    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->grommit, NULL);
-
     pmChip *parChip = cell->parent;
     pmFPA *parFPA = parChip->parent;
 
     // Convert the skyCoords to tangent plane coords.
-    psPlane *tpCoord = psCoordSkyToTP(NULL, skyCoord, parFPA->projection);
+    psPlane *tpCoord = pmCoordSkyToTP(NULL, skyCoord, parFPA->projection);
 
     // Convert the tangent plane coords to FPA coords.
-    psPlane *fpaCoord = psCoordTPToFPA(NULL, tpCoord, color, magnitude, parFPA);
+    psPlane *fpaCoord = pmCoordTPToFPA(NULL, tpCoord, color, magnitude, parFPA);
 
     // Convert the FPA coords to chip coords.
-    psPlane *chipCoord = psCoordFPAToChip(NULL, fpaCoord, parChip);
+    psPlane *chipCoord = pmCoordFPAToChip(NULL, fpaCoord, parChip);
 
     // Convert the chip coords to cell coords.
-    cellCoord = psCoordChipToCell(cellCoord, chipCoord, cell);
+    cellCoord = pmCoordChipToCell(cellCoord, chipCoord, cell);
 
     psFree(tpCoord);
@@ -683,225 +659,24 @@
 
 
-psPlane* psCoordSkyToCellQuick(psPlane* cellCoord,
-                               const psSphere* skyCoord,
-                               const pmCell* cell)
+/*****************************************************************************
+XXX: What about units for the (x,y) coords?
+ 
+XXX: This has not been tested.
+ 
+XXX: How do we get sphere coods from the cell->toSky plane transform?
+ *****************************************************************************/
+psPlane* pmCoordSkyToCellQuick(
+    psPlane* cellCoord,
+    const psSphere* skyCoord,
+    const pmCell* cell)
 {
     PS_ASSERT_PTR_NON_NULL(skyCoord, NULL);
     PS_ASSERT_PTR_NON_NULL(cell, NULL);
-    PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
-    PS_ASSERT_PTR_NON_NULL(cell->parent->parent, NULL);
-    PS_ASSERT_PTR_NON_NULL(cell->parent->parent->projection, NULL);
-
-
+    PS_ASSERT_PTR_NON_NULL(cell->toSky, NULL);
+
+    //    return(p_psProject(cellCoord, skyCoord, cell->toSky));
     psLogMsg(__func__, PS_LOG_WARN,
-             "WARNING: psCoordSkyToCellQuick(): This function is not fully specified in the SDRS.  Returning NULL.\n");
+             "WARNING: psCoordCellToSkyQuick(): This function is not fully specified in the SDRS.  Returning NULL.\n");
     return(NULL);
-    /*
-     
-        if (cell->toSky) {
-            // XXX: Should we use toTP or toSky?
-            psLogMsg(__func__, PS_LOG_WARN,
-                     "WARNING: psCoordSkyToCellQuick: The cell->toSky transform is ignored.  The cell->toTP transform is being used.");
-        }
-     
-        psPlane *tpCoord = NULL;
-        pmChip *whichChip = cell->parent;
-        pmFPA  *whichFPA = whichChip->parent;
-        psProjectionType oldProjectionType;
-        psPlaneTransform *TPtoCell = NULL;
-     
-        // Save the old projection type and set the new projection type to TAN.
-        oldProjectionType = whichFPA->projection->type;
-        whichFPA->projection->type = PS_PROJ_TAN;
-     
-        if (cellCoord == NULL) {
-            cellCoord = (psPlane* ) psAlloc(sizeof(psPlane));
-        }
-     
-        tpCoord = psProject(skyCoord, whichFPA->projection);
-     
-        // generate an error if cell->toTP is not linear.
-        if (0 == p_psIsProjectionLinear(cell->toTP)) {
-            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                    PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM,
-                    "cell to tangent plane");
-        }
-     
-        TPtoCell = p_psPlaneTransformLinearInvert(cell->toTP);
-        cellCoord = psPlaneTransformApply(cellCoord, TPtoCell, tpCoord);
-     
-        // Restore old projection type.  Free memory.
-        whichFPA->projection->type = oldProjectionType;
-        psFree(tpCoord);
-        return (cellCoord);
-    */
-}
-
-/*
-psMetadataItem* psMetadataLookup(
-    const psMetadata * md,             ///< Metadata collection to lookup meta!
-    const char * key                   ///< Name of metadata key.
-);
-*/
-
-// XXX: How should we handle errors?  What if psMetadataLookup() is NULL?
-psMetadataItem *pmReadoutGetConcept(pmReadout *readout, const char *concept)
-{
-    //    return(psMetadataLookup(readout->concepts, concept));
-    return(NULL);
-}
-
-psMetadataItem *pmCellGetConcept(pmCell *cell, const char *concept)
-{
-    return(psMetadataLookup(cell->concepts, concept));
-}
-
-psMetadataItem *pmChipGetConcept(pmChip *chip, const char *concept)
-{
-    return(psMetadataLookup(chip->concepts, concept));
-}
-
-psMetadataItem *pmFPAGetConcept(pmFPA *fpa, const char *concept)
-{
-    return(psMetadataLookup(fpa->concepts, concept));
-}
-
-
-float pmFPAGetAirmass(pmFPA *fpa) // FPA.AIRMASS
-{
-    psMetadataItem *tmp = pmFPAGetConcept(fpa, "FPA.AIRMASS");
-    return((float) tmp->data.F32);
-}
-
-psString pmFPAGetFilter(pmFPA *fpa) // FPA.FILTER
-{
-    psMetadataItem *tmp = pmFPAGetConcept(fpa, "FPA.FILTER");
-    return((psString) tmp->data.V);
-}
-
-float pmFPAGetPosAngle(pmFPA *fpa) // FPA.POSANGLE
-{
-    psMetadataItem *tmp = pmFPAGetConcept(fpa, "FPA.POSANGLE");
-    return((float) tmp->data.F32);
-}
-
-double pmFPAGetRA(pmFPA *fpa) // FPA.RA
-{
-    psMetadataItem *tmp = pmFPAGetConcept(fpa, "FPA.RA");
-    return((float) tmp->data.F32);
-}
-
-double pmFPAGetDec(pmFPA *fpa) // FPA.DEC
-{
-    psMetadataItem *tmp = pmFPAGetConcept(fpa, "FPA.DEC");
-    return((float) tmp->data.F32);
-}
-
-psString pmFPAGetRADecSys(pmFPA *fpa) // FPA.RADECSYS
-{
-    psMetadataItem *tmp = pmFPAGetConcept(fpa, "FPA.RADECSYS");
-    return((psString) tmp->data.V);
-}
-
-psString pmFPAGetName(pmFPA *fpa) // FPA.NAME
-{
-    psMetadataItem *tmp = pmFPAGetConcept(fpa, "FPA.NAME");
-    return((psString) tmp->data.V);
-}
-
-psString pmChipGetName(pmChip *chip) // CHIP.NAME
-{
-    psMetadataItem *tmp = pmChipGetConcept(chip, "CHIP.NAME");
-    return((psString) tmp->data.V);
-}
-
-psString pmCellGetName(pmCell *cell) // CELL.NAME
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.NAME");
-    return((psString) tmp->data.V);
-}
-
-psTime *pmCellGetTime(pmCell *cell) // CELL.TIME
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.TIME");
-    return((psTime *) tmp->data.V);
-}
-
-psList *pmCellGetBiasSec(pmCell *cell) // CELL.BIASSEC
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.BIASSEC");
-    return((psList *) tmp->data.list);
-}
-
-psRegion pmCellGetTrimSec(pmCell *cell) // CELL.TRIMSEC
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.TRIMSEC");
-    return((psRegion) *((psRegion *) (tmp->data.V)));
-}
-
-float pmCellGetGain(pmCell *cell) // CELL.GAIN
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.GAIN");
-    return((float) tmp->data.F32);
-}
-
-float pmCellGetReadNoise(pmCell *cell) // CELL.READNOISE
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.READNOISE");
-    return((float) tmp->data.F32);
-}
-
-float pmCellGetSaturation(pmCell *cell) // CELL.SATURATION
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.SATURATION");
-    return((float) tmp->data.F32);
-}
-
-float pmCellGetBad(pmCell *cell) // CELL.BAD
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.BAD");
-    return((float) tmp->data.F32);
-}
-
-
-psPixelCoord pmCellGetBin(pmCell *cell) // CELL.BIN
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.BIN");
-    return((psPixelCoord)  *((psPixelCoord *) (tmp->data.V)));
-}
-
-psPixelCoord pmCellGetParity(pmCell *cell) // CELL.PARITY
-{
-    psMetadataItem *tmp = pmCellGetConcept(cell, "CELL.PARITY");
-    return((psPixelCoord)  *((psPixelCoord *) (tmp->data.V)));
-}
-
-float pmReadoutGetExposure(pmReadout *readout) // READOUT.EXPOSURE
-{
-    psMetadataItem *tmp = pmReadoutGetConcept(readout, "READOUT.EXPOSURE");
-    return((float) tmp->data.F32);
-}
-
-float pmReadoutGetDarkTime(pmReadout *readout) // READOUT.DARKTIME
-{
-    psMetadataItem *tmp = pmReadoutGetConcept(readout, "READOUT.DARKTIME");
-    return((float) tmp->data.F32);
-}
-
-
-
-
-/*
-typedef struct
-{
-    float x0;
-}
-psJunk;
- 
-psJunk *pmCellTmp(pmCell *cell) // CELL.TRIMSEC
-{
-    psMetadataItem *tmp;
-    return((psJunk *) tmp->data.V);
-}
- 
-*/
+}
+//This code will
Index: /trunk/psModules/src/astrom/pmAstrometry.h
===================================================================
--- /trunk/psModules/src/astrom/pmAstrometry.h	(revision 5542)
+++ /trunk/psModules/src/astrom/pmAstrometry.h	(revision 5543)
@@ -8,6 +8,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-10-20 23:06:24 $
+*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-11-18 19:43:14 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -274,5 +274,5 @@
  *  @return psPlane*    the resulting chip coordinate
  */
-psPlane* psCoordCellToChip(
+psPlane* pmCoordCellToChip(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the coordinate within Cell
@@ -285,5 +285,5 @@
  *  @return psPlane*    the resulting FPA coordinate
  */
-psPlane* psCoordChipToFPA(
+psPlane* pmCoordChipToFPA(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the coordinate within Chip
@@ -296,5 +296,5 @@
  *  @return psPlane*    the resulting Tangent Plane coordinate
  */
-psPlane* psCoordFPAToTP(
+psPlane* pmCoordFPAToTP(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the coordinate within FPA
@@ -309,5 +309,5 @@
  *  @return psSphere*    the resulting Sky coordinate
  */
-psSphere* psCoordTPToSky(
+psSphere* pmCoordTPToSky(
     psSphere* out,                     ///< a sphere struct to recycle. If NULL, a new struct is created
     const psPlane* in,                ///< the coordinate within Tangent Plane
@@ -319,5 +319,5 @@
  *  @return psPlane*    the resulting FPA coordinate
  */
-psPlane* psCoordCellToFPA(
+psPlane* pmCoordCellToFPA(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the coordinate within cell
@@ -330,5 +330,5 @@
  *  @return psSphere*    the resulting Sky coordinate
  */
-psSphere* psCoordCellToSky(
+psSphere* pmCoordCellToSky(
     psSphere* out,                     ///< a sphere struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the coordinate within cell
@@ -344,5 +344,5 @@
  *  @return psSphere*    the resulting Sky coordinate
  */
-psSphere* psCoordCellToSkyQuick(
+psSphere* pmCoordCellToSkyQuick(
     psSphere* out,                     ///< a sphere struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the coordinate within cell
@@ -355,5 +355,5 @@
  *  @return psPlane*    the resulting Tangent Plane coordinate
  */
-psPlane* psCoordSkyToTP(
+psPlane* pmCoordSkyToTP(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psSphere* in,                ///< the sky coordinate
@@ -365,5 +365,5 @@
  *  @return psPlane*    the resulting FPA coordinate
  */
-psPlane* psCoordTPToFPA(
+psPlane* pmCoordTPToFPA(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the coordinate within tangent plane
@@ -378,5 +378,5 @@
  *  @return psPlane*    the resulting chip coordinate
  */
-psPlane* psCoordFPAToChip(
+psPlane* pmCoordFPAToChip(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the FPA coordinate
@@ -389,5 +389,5 @@
  *  @return psPlane*    the resulting cell coordinate
  */
-psPlane* psCoordChipToCell(
+psPlane* pmCoordChipToCell(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psPlane* in,                 ///< the Chip coordinate
@@ -400,5 +400,5 @@
  *  @return psPlane*    the resulting cell coordinate
  */
-psPlane* psCoordSkyToCell(
+psPlane* pmCoordSkyToCell(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psSphere* in,                ///< the Sky coordinate
@@ -414,5 +414,5 @@
  *  @return psPlane*    the resulting cell coordinate
  */
-psPlane* psCoordSkyToCellQuick(
+psPlane* pmCoordSkyToCellQuick(
     psPlane* out,                      ///< a plane struct to recycle. If NULL, a new struct is created
     const psSphere* in,                ///< the Sky coordinate
@@ -420,40 +420,3 @@
 );
 
-
-psMetadataItem *pmCellGetConcept(pmCell *cell, const char *concept);
-psMetadataItem *pmChipGetConcept(pmChip *chip, const char *concept);
-psMetadataItem *pmFPAGetConcept(pmFPA *fpa, const char *concept);
-
-/**
- * 
- *  We next specify a series of specific functions for concept lookups. These
- *  will generally be what the user utilises, so the goal is to provide a simple
- *  interface providing a single type back, so the user doesnt have to go to the
- *  trouble of checking types, etc. These functions should employ the above three
- *  general lookup functions and deal with the result appropriately.
- *
- */
-float pmFPAGetAirmass(pmFPA *fpa); // FPA.AIRMASS
-psString pmFPAGetFilter(pmFPA *fpa); // FPA.FILTER
-float pmFPAGetPosAngle(pmFPA *fpa); // FPA.POSANGLE
-double pmFPAGetRA(pmFPA *fpa); // FPA.RA
-double pmFPAGetDec(pmFPA *fpa); // FPA.DEC
-psString pmFPAGetRADecSys(pmFPA *fpa); // FPA.RADECSYS
-psString pmFPAGetName(pmFPA *fpa); // FPA.NAME
-psString pmChipGetName(pmChip *chip); // CHIP.NAME
-psString pmCellGetName(pmCell *cell); // CELL.NAME
-psTime *pmCellGetTime(pmCell *cell); // CELL.TIME
-psList *pmCellGetBiasSec(pmCell *cell); // CELL.BIASSEC
-psRegion pmCellGetTrimSec(pmCell *cell); // CELL.TRIMSEC
-float pmCellGetGain(pmCell *cell); // CELL.GAIN
-float pmCellGetReadNoise(pmCell *cell); // CELL.READNOISE
-float pmCellGetSaturation(pmCell *cell); // CELL.SATURATION
-float pmCellGetBad(pmCell *cell); // CELL.BAD
-psPixelCoord pmCellGetBin(pmCell *cell); // CELL.BIN
-psPixelCoord pmCellGetParity(pmCell *cell); // CELL.PARITY
-float pmReadoutGetExposure(pmReadout *readout); // READOUT.EXPOSURE
-float pmReadoutGetDarkTime(pmReadout *readout); // READOUT.DARKTIME
-
-
-
 #endif // #ifndef PS_ASTROMETRY_H
Index: /trunk/psModules/src/detrend/pmFlatField.c
===================================================================
--- /trunk/psModules/src/detrend/pmFlatField.c	(revision 5542)
+++ /trunk/psModules/src/detrend/pmFlatField.c	(revision 5543)
@@ -18,6 +18,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-11-15 20:09:03 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-11-18 19:43:14 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -38,4 +38,9 @@
 #include "pmSubtractBias.h"
 
+// XXX: This should be removed when the autoconf stuff handles psConstants.h correctly.
+#define PS_WARN_PTR_NON_NULL(NAME) \
+if ((NAME) == NULL) { \
+    psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
+} \
 
 bool pmFlatField(
Index: /trunk/psModules/src/detrend/pmMaskBadPixels.c
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 5542)
+++ /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 5543)
@@ -19,6 +19,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-11-15 20:09:03 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-11-18 19:43:14 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -36,4 +36,11 @@
 #include "pmMaskBadPixelsErrors.h"
 #include "pmSubtractBias.h"
+
+//XXX: REmove, autoconf is broken.
+#define PS_WARN_PTR_NON_NULL(NAME) \
+if ((NAME) == NULL) { \
+    psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
+} \
+
 
 /******************************************************************************
@@ -41,5 +48,5 @@
 input image mask and a pixel location, then sets (logical or) all pixels with
 parameter radius if that pixel to maskVal parameter.
- *****************************************************************************/
+*****************************************************************************/
 psBool GrowPixel(
     psImage *inMask,
Index: /trunk/psModules/src/detrend/pmNonLinear.c
===================================================================
--- /trunk/psModules/src/detrend/pmNonLinear.c	(revision 5542)
+++ /trunk/psModules/src/detrend/pmNonLinear.c	(revision 5543)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-11-15 20:09:03 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-11-18 19:43:14 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,10 +24,16 @@
 #include "pmSubtractBias.h"
 
+// XXX: Remove, autoconf must be
+#define PS_WARN_PTR_NON_NULL(NAME) \
+if ((NAME) == NULL) { \
+    psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
+} \
 /******************************************************************************
 pmNonLinearityLookup(): This routine will take an pmReadout image as input
 and a 1-D polynomial.  For each pixel in the input image, the polynomial will
-be evaluated at that pixels value, and the image pixel will then be set to
+be evaluated at that pixels value, and the image pixel will then be set 
+to
 that value.
- *****************************************************************************/
+*****************************************************************************/
 
 pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout,
Index: /trunk/psModules/test/astrom/Makefile.am
===================================================================
--- /trunk/psModules/test/astrom/Makefile.am	(revision 5542)
+++ /trunk/psModules/test/astrom/Makefile.am	(revision 5543)
@@ -6,7 +6,9 @@
 
 TESTS = \
-    tst_pmAstrometry
+    tst_pmAstrometry \
+    tst_pmAstrometry01
 
 tst_pmAstrometry_SOURCES = tst_pmAstrometry.c
+tst_pmAstrometry01_SOURCES = tst_pmAstrometry01.c
 
 check_PROGRAMS = $(TESTS)
Index: /trunk/psModules/test/astrom/tst_pmAstrometry.c
===================================================================
--- /trunk/psModules/test/astrom/tst_pmAstrometry.c	(revision 5542)
+++ /trunk/psModules/test/astrom/tst_pmAstrometry.c	(revision 5543)
@@ -6,6 +6,10 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-20 23:06:24 $
+ * XXX: Significant work needed: must test the variout coordinate transformation function.
+ *
+ *
+ *
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-11-18 19:43:14 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -172,5 +176,5 @@
 
     psFree(fpa);
-    psFree(chip);
+    //    psFree(chip);
     psFree(camera);
 
@@ -267,6 +271,6 @@
 
     psFree(fpa);
-    psFree(chip);
-    psFree(cell);
+    //    psFree(chip);
+    //    psFree(cell);
     psFree(camera);
 
@@ -353,10 +357,9 @@
 
     psFree(fpa);
-    psFree(chip);
-    psFree(cell);
-    psFree(readout);
+    //    psFree(chip);
+    //    psFree(cell);
+    //    psFree(readout);
     psFree(camera);
 
     return 0;
 }
-
