Index: /trunk/psLib/src/astronomy/psAstrometry.c
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.c	(revision 1529)
+++ /trunk/psLib/src/astronomy/psAstrometry.c	(revision 1530)
@@ -8,6 +8,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-13 00:01:57 $
+*  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-13 22:41:24 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -97,10 +97,10 @@
 }
 
-psCell* psCellInFPA(psCell* outCell,
-                    const psPlane* fpaCoord,
+psCell* psCellInFPA(const psPlane* fpaCoord,
                     const psFPA* FPA)
 {
     psChip* tmpChip = NULL;
     psPlane* chipCoord = NULL;
+    psCell* outCell = NULL;
 
     if (fpaCoord == NULL) {
@@ -112,5 +112,5 @@
 
     // Determine which chip contains the fpaCoords.
-    tmpChip = psChipInFPA(tmpChip, fpaCoord, FPA);
+    tmpChip = psChipInFPA(fpaCoord, FPA);
 
     // Convert to those chip coordinates.
@@ -118,5 +118,5 @@
 
     // Determine which cell contains those chip coordinates.
-    outCell = psCellInChip(outCell, chipCoord, tmpChip);
+    outCell = psCellInChip(chipCoord, tmpChip);
 
     psFree(tmpChip);
@@ -144,9 +144,5 @@
 }
 
-/*****************************************************************************
-XXX: Should we return the result in "out"?
- *****************************************************************************/
-psChip* psChipInFPA(psChip* out,
-                    const psPlane* fpaCoord,
+psChip* psChipInFPA(const psPlane* fpaCoord,
                     const psFPA* FPA)
 {
@@ -172,5 +168,5 @@
                                           fpaCoord);
 
-        tmpCell = psCellInChip(tmpCell, chipCoord, tmpChip);
+        tmpCell = psCellInChip(chipCoord, tmpChip);
         if (tmpCell != NULL) {
             psFree(chipCoord);
@@ -183,9 +179,5 @@
 }
 
-/*****************************************************************************
-XXX: Should we return the result in "out"?
- *****************************************************************************/
-psCell* psCellInChip(psCell* outCell,
-                     const psPlane* chipCoord,
+psCell* psCellInChip(const psPlane* chipCoord,
                      const psChip* chip)
 {
@@ -277,5 +269,5 @@
 
     return(psPlaneDistortApply(outCoord, fpa->toTangentPlane, inCoord,
-                               magnitude, color));
+                               color, magnitude));
 }
 
@@ -344,5 +336,5 @@
     // Convert the FPA coordinates to tangent plane Coordinates.
     tpCoord = psPlaneDistortApply(tpCoord, parFPA->toTangentPlane,
-                                  fpaCoord, magnitude, color);
+                                  fpaCoord, color, magnitude);
 
     // Generate a grommit for this FPA.
@@ -359,8 +351,4 @@
 }
 
-/*****************************************************************************
-XXX: After I deproject the tangent plane to a sphere, do I have to do a
-spherical transformation to get it to the sky?
- *****************************************************************************/
 psSphere* psCoordCellToSkyQuick(psSphere* outSphere,
                                 const psPlane* cellCoord,
@@ -437,5 +425,5 @@
 
     return (psPlaneDistortApply(fpaCoord, fpa->fromTangentPlane,
-                                tpCoord, magnitude, color));
+                                tpCoord, color, magnitude));
 }
 
@@ -456,5 +444,6 @@
     }
 
-    psChip *newChip = psChipInFPA(newChip, fpaCoord, FPA);
+    // Determine which chip contains these FPA coordinates.
+    psChip *newChip = psChipInFPA(fpaCoord, FPA);
     if (newChip == NULL) {
         return(NULL);
@@ -482,5 +471,6 @@
     }
 
-    psCell *newCell = psCellInChip(newCell, chipCoord, chip);
+    // Determine which cell contains these FPA coordinates.
+    psCell *newCell = psCellInChip(chipCoord, chip);
     if (newCell == NULL) {
         return(NULL);
@@ -492,4 +482,7 @@
 }
 
+/*****************************************************************************
+XXX: Should we do anything to determine which cell contains the coordinates?
+ *****************************************************************************/
 psPlane* psCoordSkyToCell(psPlane* cellCoord,
                           const psSphere* skyCoord,
@@ -570,7 +563,28 @@
 simply inverts the supplied psPlaneTransform transform.  It assumes that
 "transform" is linear.
+ 
+This program assumes that the inverse of the following linear equations:
+        X2 = A + (B * X1) + (C * Y1);
+        Y2 = D + (E * X1) + (F * Y1);
+is
+        Y1 = (Y2 - ((E/B) * X2) - D + ((E*A)/B)) / (F - ((C*E)/B));
+        X1 = (Y2 - ((F/C) * X2) - D + ((F*A)/C)) / (E - ((F*B)/C));
+or
+ X1 = (-D + ((F*A)/C)) / (E - ((F*B)/C)) +
+      (X2 * -((F/C) / (E - ((F*B)/C)))) +
+             (Y2 * (1.0 / (E - ((F*B)/C))));
+        Y1 = (-D + ((E*A)/B))/(F - ((C*E)/B)) +
+             (X2 * -((E/B) / (F - ((C*E)/B)))) +
+             (Y2 * (1.0 / (F - ((C*E)/B))));
  *****************************************************************************/
-psPlaneTransform *p_psInvertPlaneDistortTransform(psPlaneTransform *transform)
-{
+psPlaneTransform *p_psInvertPlaneTransform(psPlaneTransform *transform)
+{
+    double A = transform->x->coeff[0][0];
+    double B = transform->x->coeff[1][0];
+    double C = transform->x->coeff[0][1];
+    double D = transform->y->coeff[0][0];
+    double E = transform->y->coeff[1][0];
+    double F = transform->y->coeff[0][1];
+
     if (transform == NULL) {
         psAbort(__func__, "input parameter transform is NULL.");
@@ -578,8 +592,17 @@
     psPlaneTransform *out = psAlloc(sizeof(psPlaneTransform));
 
-    // XXX: figure it out
+    out->x->coeff[0][0] = -D + ((F*A)/C) / (E - ((F*B)/C));
+    out->x->coeff[1][0] = -(F/C) / (E - ((F*B)/C));
+    out->x->coeff[0][1] =  1.0 / (E - ((F*B)/C));
+    out->y->coeff[0][0] = -D + ((E*A)/B) / (F - ((C*E)/B));
+    out->y->coeff[1][0] = -(E/B) / (F - ((C*E)/B));
+    out->y->coeff[0][1] =  1.0 / (F - ((C*E)/B));
+
     return(out);
 }
 
+/*****************************************************************************
+XXX: Should we do anything to determine which cell contains the coordinates?
+ *****************************************************************************/
 psPlane* psCoordSkyToCellQuick(psPlane* cellCoord,
                                const psSphere* skyCoord,
@@ -614,5 +637,5 @@
     }
 
-    TPtoCell = p_psInvertPlaneDistortTransform(cell->toTP);
+    TPtoCell = p_psInvertPlaneTransform(cell->toTP);
     cellCoord = psPlaneTransformApply(cellCoord, TPtoCell, tpCoord);
 
Index: /trunk/psLib/src/astronomy/psAstrometry.h
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.h	(revision 1529)
+++ /trunk/psLib/src/astronomy/psAstrometry.h	(revision 1530)
@@ -8,6 +8,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-12 05:36:53 $
+*  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-13 22:41:24 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -258,5 +258,4 @@
  */
 psCell* psCellInFPA(
-    psCell* out,                       ///< a cell struct to recycle. If NULL, a new struct is created
     const psPlane* coord,              ///< the coordinate in FPA plane
     const psFPA* FPA                   ///< the FPA to search for the cell
@@ -268,5 +267,4 @@
  */
 psChip* psChipInFPA(
-    psChip* out,                       ///< a chip struct to recycle. If NULL, a new struct is created
     const psPlane* coord,              ///< the coordinate in FPA plane
     const psFPA* FPA                   ///< the FPA to search for the cell
@@ -278,5 +276,4 @@
  */
 psCell* psCellInChip(
-    psCell* out,                       ///< a cell struct to recycle. If NULL, a new struct is created
     const psPlane* coord,              ///< the coordinate in Chip plane
     const psChip* chip                 ///< the chip to search for the cell
