Index: /trunk/psLib/src/astro/psCoord.c
===================================================================
--- /trunk/psLib/src/astro/psCoord.c	(revision 1324)
+++ /trunk/psLib/src/astro/psCoord.c	(revision 1325)
@@ -10,6 +10,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-28 20:22:22 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-29 02:08:02 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -146,5 +146,5 @@
 }
 
-psSphereTransform *psSphereTransformEcliptictoICRS(void)
+psSphereTransform *psSphereTransformEcliptictoICRS(psTime time)
 {
     struct tm *tmTime = psTimeToTM(time);
@@ -293,5 +293,5 @@
                             psSphereOffsetUnit unit)
 {
-    psPlane *lin;
+    //    psPlane *lin;
     psProjection proj;
     psSphere *tmp;
@@ -312,6 +312,6 @@
         proj.type = PS_PROJ_TAN;
 
-        lin = psProject(position2, proj);
-        tmp = psDeproject(lin, proj);
+        //        lin = psProject(position2, proj);
+        //        tmp = psDeproject(lin, proj);
 
         // XXX: Do we need to convert units in tmp?
Index: /trunk/psLib/src/astro/psCoord.h
===================================================================
--- /trunk/psLib/src/astro/psCoord.h	(revision 1324)
+++ /trunk/psLib/src/astro/psCoord.h	(revision 1325)
@@ -10,6 +10,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-27 05:30:55 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-29 02:08:02 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,4 +24,5 @@
 #include "psList.h"
 #include "psFunctions.h"
+#include "psTime.h"
 
 typedef struct
@@ -121,6 +122,6 @@
                                  const psSphere *coord);
 
-psSphereTransform *psSphereTransformICRStoEcliptic(void);
-psSphereTransform *psSphereTransformEcliptictoICRS(void);
+psSphereTransform *psSphereTransformICRStoEcliptic(psTime time);
+psSphereTransform *psSphereTransformEcliptictoICRS(psTime time);
 psSphereTransform *psSphereTransformICRStoGalatic(void);
 psSphereTransform *psSphereTransformGalatictoICRS(void);
Index: /trunk/psLib/src/astronomy/psCCD.h
===================================================================
--- /trunk/psLib/src/astronomy/psCCD.h	(revision 1324)
+++ /trunk/psLib/src/astronomy/psCCD.h	(revision 1325)
@@ -11,6 +11,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-16 02:33:50 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-29 02:08:02 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -76,4 +76,5 @@
 
     psPlaneTransform* toChip;          ///< transformations from cell to chip coordinates
+    psPlaneTransform* fromChip;        ///< transformations from chip to cell coordinates
     psPlaneTransform* toFPA;           ///< transformations from cell to FPA coordinates
     psPlaneTransform* toSky;           ///< transformations from cell to sky coordinates
Index: /trunk/psLib/src/astronomy/psCoord.c
===================================================================
--- /trunk/psLib/src/astronomy/psCoord.c	(revision 1324)
+++ /trunk/psLib/src/astronomy/psCoord.c	(revision 1325)
@@ -10,6 +10,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-28 20:22:22 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-29 02:08:02 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -146,5 +146,5 @@
 }
 
-psSphereTransform *psSphereTransformEcliptictoICRS(void)
+psSphereTransform *psSphereTransformEcliptictoICRS(psTime time)
 {
     struct tm *tmTime = psTimeToTM(time);
@@ -293,5 +293,5 @@
                             psSphereOffsetUnit unit)
 {
-    psPlane *lin;
+    //    psPlane *lin;
     psProjection proj;
     psSphere *tmp;
@@ -312,6 +312,6 @@
         proj.type = PS_PROJ_TAN;
 
-        lin = psProject(position2, proj);
-        tmp = psDeproject(lin, proj);
+        //        lin = psProject(position2, proj);
+        //        tmp = psDeproject(lin, proj);
 
         // XXX: Do we need to convert units in tmp?
Index: /trunk/psLib/src/astronomy/psCoord.h
===================================================================
--- /trunk/psLib/src/astronomy/psCoord.h	(revision 1324)
+++ /trunk/psLib/src/astronomy/psCoord.h	(revision 1325)
@@ -10,6 +10,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-27 05:30:55 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-29 02:08:02 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,4 +24,5 @@
 #include "psList.h"
 #include "psFunctions.h"
+#include "psTime.h"
 
 typedef struct
@@ -121,6 +122,6 @@
                                  const psSphere *coord);
 
-psSphereTransform *psSphereTransformICRStoEcliptic(void);
-psSphereTransform *psSphereTransformEcliptictoICRS(void);
+psSphereTransform *psSphereTransformICRStoEcliptic(psTime time);
+psSphereTransform *psSphereTransformEcliptictoICRS(psTime time);
 psSphereTransform *psSphereTransformICRStoGalatic(void);
 psSphereTransform *psSphereTransformGalatictoICRS(void);
Index: /trunk/psLib/src/astronomy/psCoord2.c
===================================================================
--- /trunk/psLib/src/astronomy/psCoord2.c	(revision 1324)
+++ /trunk/psLib/src/astronomy/psCoord2.c	(revision 1325)
@@ -1,2 +1,3 @@
+// This file contains
 
 #include "psType.h"
@@ -53,4 +54,7 @@
 
     for (tmpChip = FPA->chips; tmpChip != NULL; tmpChip++) {
+        tmpCoord = psPlaneTransformApply(out, tmpChip->fromFPA, coord);
+
+
         //XXX     if (this is the correct chip)
         return(tmpChip);
@@ -58,4 +62,30 @@
 }
 
+#define PS_CHECK_VALID_IMAGE_COORDS(X, Y, IMAGE) \
+
+p_psCheckValidImageCoords(double x, double y, tmpImage)
+{
+    if ((x < 0.0) ||
+            (x > (double) tmpImage->numCols) ||
+            (y < 0.0) ||
+            (y > (double) tmpImage->numRows)) {
+        return(0);
+    }
+    return(1);
+}
+
+
+/*****************************************************************************
+XXX: We assume that readouts have valid coordinates from the range
+(0,numRows or numCols) in each dimension, and that they are square with the
+x/y axis.
+ 
+XXX: We assume that if a cell has more than one readout, all readouts have
+the same coordinates.
+ 
+XXX: if we find no cell with has this coordinate, we return NULL.
+ 
+XXX: must deallocate memory.
+ *****************************************************************************/
 psCell *psCellinChip(psCell *out,
                      const psPlane *coord,
@@ -63,9 +93,18 @@
 {
     psCell *tmpCell = NULL;
+    psReadout *tmpReadout = NULL;
+    psPlane *tmpCoord = NULL;
 
     for (tmpCell = chip->cells; tmpCell != NULL; tmpCell++) {
-        //XXX        if (this is the correct cell)
-        return(tmpCcell);
+        if (tmpCell->readouts != NULL) {
+            tmpReadout = tmpCell->readouts;
+            tmpCoord = psPlaneTransformApply(out, tmpCell->fromChip, coord);
+            if (p_psCheckValidImageCoords(tmpCoord->x, tmpCoord->y,
+                                          tmpReadout->image)) {
+                return(tmpCell);
+            }
+        }
     }
+    return(NULL);
 }
 
@@ -74,5 +113,5 @@
                            const psCell *cell)
 {
-    return(psPlaneTransformApply(psPlane *out, cell->toChip, in));
+    return(psPlaneTransformApply(out, cell->toChip, in));
 }
 
@@ -81,5 +120,5 @@
                           const psChip *chip)
 {
-    return(psPlaneTransformApply(psPlane *out, chip->toFPA, in));
+    return(psPlaneTransformApply(out, chip->toFPA, in));
 }
 
@@ -88,5 +127,5 @@
                         const psFPA *fpa)
 {
-    return(psPlaneTransformApply(psPlane *out, fpa->toTangentPlane, in));
+    return(psPlaneTransformApply(out, fpa->toTangentPlane, in));
 }
 
@@ -101,91 +140,103 @@
                           const psCell *cell)
 {
-    return(psPlaneTransformApply(psPlane *out, cell->toFPA, in));
-}
-
+    return(psPlaneTransformApply(out, cell->toFPA, in));
+}
+
+
+// XXX: This implementation requires a new psGrommit be created for each
+// transformation, as well as a few psPlane structs.  Can this be implemented
+// better?
 psSphere *psCoordCelltoSky(psSphere *out,
                            const psPlane *in,
                            const psCell *cell)
 {
-    if (out == NULL) {
-        out = (psSphere *) psAlloc(sizeof(psSphere));
-    }
-
-    return(out);
-}
-
-psSphere *psCoordCelltoSkyQuick(psSphere *out,
-                                const psPlane *in,
-                                const psCell *cell)
-{
-    if (out == NULL) {
-        out = (psSphere *) psAlloc(sizeof(psSphere));
-    }
-
-    return(out);
-}
-
-psPlane *psCoordSkytoTP(psPlane *out,
-                        const psSphere *in,
-                        const psGrommit *grommit)
-{
-    if (out == NULL) {
-        out = (psPlane *) psAlloc(sizeof(psPlane));
-    }
-
-    return(out);
-}
-
-psPlane *psCoordTPtoFPA(psPlane *out,
-                        const psPlane *in,
-                        const psFPA *fpa)
-{
-    return(psPlaneTransformApply(psPlane *out, fpa->fromTangentPlane, in));
-}
-
-psPlane *psCoordFPAtoChip(psPlane *out,
-                          const psPlane *in,
-                          const psChip *chip)
-{
-
-    if (out == NULL) {
-        out = (psPlane *) psAlloc(sizeof(psPlane));
-    }
-
-    return(out);
-}
-
-psPlane *psCoordChiptoCell(psPlane *out,
-                           const psPlane *in,
-                           const psCell *cell)
-{
-    if (out == NULL) {
-        out = (psPlane *) psAlloc(sizeof(psPlane));
-    }
-
-    return(out);
-}
-
-psPlane *psCoordSkytoCell(psPlane *out,
-                          const psSphere *in,
-                          const psCell *cell)
-{
-    if (out == NULL) {
-        out = (psPlane *) psAlloc(sizeof(psPlane));
-    }
-
-    return(out);
-}
-
-psPlane *psCoordSkytoCellQuick(psPlane *out,
+    psPlane *tmp1 = NULL;
+    psPlane *tmp2 = NULL;
+    psFPA *parFPA = (cell->parent)->parent;
+    psGrommit *tmpGrommit = NULL;
+
+    tmp1 = psPlaneTransformApply(tmp1, cell->toFPA, in)
+           tmp2 = psPlaneTransformApply(tmp2, parFPA->toTangentPlane, tmp1)
+                  tmpGrommit = psGrommitAlloc(parFPA->exposure)
+                               tmp3 = psCoordTPtoSky(out, tmp2, psGrommit);
+
+    psFree(tmp1);
+    psFree(tmp2);
+    psFree(tmpGrommit);
+
+    return(psCoordTPtoSky(out, tmp2, psGrommit);
+       }
+
+       psSphere *psCoordCelltoSkyQuick(psSphere *out,
+                                       const psPlane *in,
+                                       const psCell *cell)
+       {
+           psPlane *tmp1 = NULL;
+
+           tmp1 = psPlaneTransformApply(tmp1, cell->toSky, in);
+
+           //XXX: Do something to convert the linear coords in tmp1 to spherical
+           // coords in out.
+
+           free(tmp1)
+
+           return(out);
+       }
+
+       psPlane *psCoordSkytoTP(psPlane *out,
                                const psSphere *in,
-                               const psCell *cell)
-{
-    if (out == NULL) {
-        out = (psPlane *) psAlloc(sizeof(psPlane));
-    }
-
-    return(out);
-}
-
-
+                               const psGrommit *grommit)
+       {
+           if (out == NULL) {
+               out = (psPlane *) psAlloc(sizeof(psPlane));
+           }
+
+           return(out);
+       }
+
+       psPlane *psCoordTPtoFPA(psPlane *out,
+                               const psPlane *in,
+                               const psFPA *fpa)
+       {
+           return(psPlaneTransformApply(out, fpa->fromTangentPlane, in));
+       }
+
+       psPlane *psCoordFPAtoChip(psPlane *out,
+                                 const psPlane *in,
+                                 const psChip *chip)
+       {
+           return(psPlaneTransformApply(out, chip->fromFPA, in));
+       }
+
+
+       psPlane *psCoordChiptoCell(psPlane *out,
+                                  const psPlane *in,
+                                  const psCell *cell)
+       {
+           return(psPlaneTransformApply(out, cell->fromChip, in));
+       }
+
+       psPlane *psCoordSkytoCell(psPlane *out,
+                                 const psSphere *in,
+                                 const psCell *cell)
+       {
+           out = psCoordSkytoTP(out, in, tmpGrommit);
+           out = psCoordTPtoFPA(out, out, whichFPA);
+           out = psCoordFPAtoChip(out, out, whichChip);
+           out = psCoordChiptoCell(out, out, whichCell);
+
+           return(out);
+       }
+
+       psPlane *psCoordSkytoCellQuick(psPlane *out,
+                                      const psSphere *in,
+                                      const psCell *cell)
+       {
+           if (out == NULL) {
+               out = (psPlane *) psAlloc(sizeof(psPlane));
+           }
+
+           return(out);
+       }
+
+
