Index: /trunk/psLib/src/astronomy/psAstrometry.c
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.c	(revision 2221)
+++ /trunk/psLib/src/astronomy/psAstrometry.c	(revision 2222)
@@ -8,6 +8,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-27 23:31:43 $
+ *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-27 23:49:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -36,12 +36,8 @@
                                    psImage* tmpImage)
 {
-    if (tmpImage == NULL) {
-        return(0);
-    }
-
-    if ((x < 0.0) ||
-            (x > (double)tmpImage->numCols) ||
-            (y < 0.0) ||
-            (y > (double)tmpImage->numRows)) {
+    PS_IMAGE_CHECK_NULL(tmpImage, 0);
+
+    if ((x < 0.0) || (x > (double)tmpImage->numCols) ||
+            (y < 0.0) || (y > (double)tmpImage->numRows)) {
         return (0);
     }
@@ -57,6 +53,9 @@
 static psS32 isProjectionLinear(psPlaneTransform *transform)
 {
-    int i = 0;
     PS_PTR_CHECK_NULL(transform, 0);
+    PS_PTR_CHECK_NULL(transform->x, 0);
+    PS_PTR_CHECK_NULL(transform->y, 0);
+
+    int i;
 
     for (i=2;i<(transform->x->nX);i++) {
@@ -106,4 +105,8 @@
 static psPlaneTransform *invertPlaneTransform(psPlaneTransform *transform)
 {
+    PS_PTR_CHECK_NULL(transform, 0);
+    PS_PTR_CHECK_NULL(transform->x, 0);
+    PS_PTR_CHECK_NULL(transform->y, 0);
+
     double A = transform->x->coeff[0][0];
     double B = transform->x->coeff[1][0];
@@ -113,5 +116,4 @@
     double F = transform->y->coeff[0][1];
 
-    PS_PTR_CHECK_NULL(transform, NULL);
     psPlaneTransform *out = psAlloc(sizeof(psPlaneTransform));
 
@@ -210,5 +212,4 @@
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
 /*****************************************************************************/
-
 
 /*
@@ -286,6 +287,6 @@
 {
     PS_PTR_CHECK_NULL(observatory, NULL);
+
     psExposure* exp = psAlloc(sizeof(psExposure));
-
     *(double *)&exp->ra = ra;
     *(double *)&exp->dec = dec;
@@ -345,4 +346,6 @@
                   const psExposure* exp)
 {
+    PS_INT_CHECK_NON_NEGATIVE(nChips, NULL);
+
     psFPA* newFPA = psAlloc(sizeof(psFPA));
 
@@ -386,4 +389,6 @@
                     psFPA *parentFPA)
 {
+    PS_INT_CHECK_NON_NEGATIVE(nCells, NULL);
+
     psChip* chip = psAlloc(sizeof(psChip));
 
@@ -414,4 +419,6 @@
                     psChip* parentChip)
 {
+    PS_INT_CHECK_NON_NEGATIVE(nReadouts, NULL);
+
     psCell* cell = psAlloc(sizeof(psCell));
 
@@ -443,4 +450,7 @@
                           const psImage* image)
 {
+    PS_INT_CHECK_NON_NEGATIVE(col0, NULL);
+    PS_INT_CHECK_NON_NEGATIVE(row0, NULL);
+
     psReadout* readout = psAlloc(sizeof(psReadout));
 
@@ -494,4 +504,5 @@
     PS_PTR_CHECK_NULL(fpaCoord, NULL);
     PS_PTR_CHECK_NULL(FPA, NULL);
+
     psChip* tmpChip = NULL;
     psPlane chipCoord;
@@ -519,4 +530,5 @@
     PS_PTR_CHECK_NULL(FPA, NULL);
     PS_PTR_CHECK_NULL(FPA->chips, NULL);
+
     psArray* chips = FPA->chips;
     psS32 nChips = chips->n;
@@ -530,4 +542,7 @@
     for (psS32 i = 0; i < nChips; i++) {
         psChip* tmpChip = chips->data[i];
+        PS_PTR_CHECK_NULL(tmpChip, NULL);
+        PS_PTR_CHECK_NULL(tmpChip->fromFPA, NULL);
+
         psPlaneTransformApply(&chipCoord, tmpChip->fromFPA, fpaCoord);
 
@@ -561,4 +576,6 @@
     for (psS32 i = 0; i < cells->n; i++) {
         psCell* tmpCell = (psCell* ) cells->data[i];
+        PS_PTR_CHECK_NULL(tmpCell, NULL);
+        PS_PTR_CHECK_NULL(tmpCell->fromChip, NULL);
         psArray* readouts = tmpCell->readouts;
 
@@ -566,4 +583,5 @@
             for (psS32 j = 0; j < readouts->n; j++) {
                 psReadout* tmpReadout = readouts->data[j];
+                PS_READOUT_CHECK_NULL(tmpReadout, NULL);
 
                 psPlaneTransformApply(&cellCoord,
@@ -657,4 +675,9 @@
     PS_PTR_CHECK_NULL(cellCoord, NULL);
     PS_PTR_CHECK_NULL(cell, NULL);
+    PS_PTR_CHECK_NULL(cell->toFPA, NULL);
+    PS_PTR_CHECK_NULL(cell->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent->toTangentPlane, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent->exposure, NULL);
 
     psPlane* fpaCoord = NULL;
@@ -689,4 +712,8 @@
     PS_PTR_CHECK_NULL(cellCoord, NULL);
     PS_PTR_CHECK_NULL(cell, NULL);
+    PS_PTR_CHECK_NULL(cell->toTP, NULL);
+    PS_PTR_CHECK_NULL(cell->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent->projection, NULL);
 
     psPlane *tpCoord = NULL;
@@ -700,5 +727,5 @@
 
     // Determine the tangent plane coordinates.
-    tpCoord = psPlaneTransformApply(tpCoord, cell->toTP, cellCoord);
+    tpCoord = psPlaneTransformApply(NULL, cell->toTP, cellCoord);
 
     // Save the old projection type and set the new projection type to TAN.
@@ -746,4 +773,5 @@
     PS_PTR_CHECK_NULL(tpCoord, NULL);
     PS_PTR_CHECK_NULL(fpa, NULL);
+    PS_PTR_CHECK_NULL(fpa->fromTangentPlane, NULL);
 
     return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane,
@@ -757,5 +785,5 @@
     PS_PTR_CHECK_NULL(fpaCoord, NULL);
     PS_PTR_CHECK_NULL(chip, NULL);
-    PS_PTR_CHECK_NULL(chip->parent, NULL);
+    PS_PTR_CHECK_NULL(chip->fromFPA, NULL);
 
     chipCoord = psPlaneTransformApply(chipCoord, chip->fromFPA, fpaCoord);
@@ -769,5 +797,5 @@
     PS_PTR_CHECK_NULL(chipCoord, NULL);
     PS_PTR_CHECK_NULL(cell, NULL);
-    PS_PTR_CHECK_NULL(cell->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->fromChip, NULL);
 
     cellCoord = psPlaneTransformApply(cellCoord, cell->fromChip, chipCoord);
@@ -783,4 +811,7 @@
     PS_PTR_CHECK_NULL(skyCoord, NULL);
     PS_PTR_CHECK_NULL(cell, NULL);
+    PS_PTR_CHECK_NULL(cell->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent->grommit, NULL);
 
     psChip *parChip = cell->parent;
@@ -814,4 +845,8 @@
     PS_PTR_CHECK_NULL(skyCoord, NULL);
     PS_PTR_CHECK_NULL(cell, NULL);
+    PS_PTR_CHECK_NULL(cell->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent, NULL);
+    PS_PTR_CHECK_NULL(cell->parent->parent->projection, NULL);
+    PS_PTR_CHECK_NULL(cell->toTP, NULL);
 
     psPlane *tpCoord = NULL;
