Index: /trunk/psLib/src/astronomy/psAstrometry.c
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.c	(revision 1333)
+++ /trunk/psLib/src/astronomy/psAstrometry.c	(revision 1333)
@@ -0,0 +1,291 @@
+// This file contains
+
+#include "psType.h"
+#include "psImage.h"
+#include "psArray.h"
+#include "psList.h"
+#include "psFunctions.h"
+
+psGrommit *psGrommitAlloc(const psExposure *exp)
+{
+    double *slaGrommit = (double *) psAlloc(14 * sizeof(double));
+    psGrommit *grommit = (psGrommit *) psAlloc(sizeof(psGrommit));
+    /*
+        extern void sla_aoppa(double date,
+                              double dut,
+                              double elongm,
+                              double phim,
+                              double him,
+                              double xp,
+                              double yp,
+                              double tdk,
+                              double pmb,
+                              double rh,
+                              double wl,
+                              double tlr,
+                              double *AOPRMS);
+     
+        sla_aoppa(date, deltaUT, meanLongitude, meanLatitude, height, xp, yp,
+                  exp->temperature, exp->pressure, exp->humidity, wavelength,
+                  tlr);
+    */
+    grommit->latitude = exp->dec;              // XXX Is this correct?
+    grommit->sinLat = sin(grommit->latitude);
+    grommit->cosLat = cos(grommit->latitude);
+    grommit->abberationMag = 0.0;
+    grommit->height = 0.0;
+    grommit->temperature = exp->temperature;
+    grommit->pressure = exp->pressure;
+    grommit->humidity = exp->humidity;
+    grommit->wavelength = 0.0;
+    grommit->lapseRate = 0.0;
+    grommit->refractA = 0.0;
+    grommit->refractB = 0.0;
+    grommit->longitudeOffset = ra;             // XXX Is this correct?
+    grommit->siderealTime = 0.0;
+
+    psFree(slaGrommit);
+    return(grommit);
+}
+
+void p_psGrommitFree(psGrommit *grommit)
+{
+    psFree(grommit);
+}
+
+psCell *psCellinFPA(psCell *out,
+                    const psPlane *coord,
+                    const psFPA *FPA)
+{
+    psChip *tmpChip = NULL;
+    psCell *tmpCell = NULL;
+
+    tmpChip = psChipinFPA(tmpChip, coord, FPA);
+    tmpCell = psCellinChip(tmpCell, coord, tmpChip);
+    return(tmpCell);
+}
+
+
+p_psCheckValidChipCoords(double x, double y, psChil *tmpChip)
+{
+    return(0);
+}
+
+psChip *psChipinFPA(psChip *out,
+                    const psPlane *coord,
+                    const psFPA *FPA)
+{
+    psFPA *tmpChip = NULL;
+
+    for (tmpChip = FPA->chips; tmpChip != NULL; tmpChip++) {
+        tmpCoord = psPlaneTransformApply(out, tmpChip->fromFPA, coord);
+        if (p_psCheckValidChipCoords(tmpCoord->x, tmpCoord->y,
+                                     tmpChip)) {
+            psFree(tmpCoord);
+            return(tmpChip);
+        }
+        psFree(tmpCoord);
+    }
+    psFree(tmpCoord);
+    return(NULL);
+}
+
+p_psCheckValidImageCoords(double x, double y, psImage *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,
+                     const psChip *chip)
+{
+    psCell *tmpCell = NULL;
+    psReadout *tmpReadout = NULL;
+    psPlane *tmpCoord = NULL;
+
+    for (tmpCell = chip->cells; tmpCell != NULL; tmpCell++) {
+        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);
+}
+
+psPlane *psCoordCelltoChip(psPlane *out,
+                           const psPlane *in,
+                           const psCell *cell)
+{
+    return(psPlaneTransformApply(out, cell->toChip, in));
+}
+
+psPlane *psCoordChipToFPA(psPlane *out,
+                          const psPlane *in,
+                          const psChip *chip)
+{
+    return(psPlaneTransformApply(out, chip->toFPA, in));
+}
+
+psPlane *psCoordFPAtoTP(psPlane *out,
+                        const psPlane *in,
+                        const psFPA *fpa)
+{
+    return(psPlaneTransformApply(out, fpa->toTangentPlane, in));
+}
+
+// XXX: must wrap SLA_QAPQK here.
+psSphere *psCoordTPtoSky(psSphere *out,
+                         const psPlane *in,
+                         const psGrommit *grommit)
+{
+    /*
+        double RAP;
+        double DAP;
+     
+        extern void sla_OAPQK(TYPE, OB1, OB2, AOPRMS, RAP, DAP);
+        sla_OAPQK(TYPE, OB1, OB2, *grommit, &RAP, &DAP);
+    */
+
+    return(out);
+}
+
+
+psPlane *psCoordCellToFPA(psPlane *out,
+                          const psPlane *in,
+                          const psCell *cell)
+{
+    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)
+{
+    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);
+       }
+
+       // XXX: must wrap SLA_AOPQK here.
+       psPlane *psCoordSkytoTP(psPlane *out,
+                               const psSphere *in,
+                               const psGrommit *grommit)
+       {
+           extern void sla_AOPQK (RAP, DAP, AOPRMS, AOB, ZOB, HOB, DOB, ROB);
+           double AOB;
+           double ZOB;
+           double HOB;
+           double DOB;
+           double ROB;
+
+           if (out == NULL) {
+               out = (psPlane *) psAlloc(sizeof(psPlane));
+           }
+
+           sla_AOPQK(psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &ROB);
+           out->x = XXX;
+           out->y = XXX;
+           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);
+       }
+
+
Index: /trunk/psLib/src/astronomy/psAstrometry.h
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.h	(revision 1333)
+++ /trunk/psLib/src/astronomy/psAstrometry.h	(revision 1333)
@@ -0,0 +1,124 @@
+/** @file  psCoord2.h
+ *
+ *  @brief Contains basic coordinate transformation definitions and operations
+ *
+ *  This file defines the basic types for astronomical coordinate 
+ *  transformation
+ *
+ *  @ingroup AstroImage
+ *
+ *  @author George Gusciora, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-29 04:22:26 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+# ifndef PS_COORD2_H
+# define PS_COORD2_H
+
+#include "psType.h"
+#include "psImage.h"
+#include "psArray.h"
+#include "psList.h"
+#include "psFunctions.h"
+
+typedef struct
+{
+    const double latitude;             ///<
+    const double sinLat, cosLat;       ///<
+    const double abberationMag;        ///<
+    const double height;               ///<
+    const double temperature;          ///<
+    const double pressure;             ///<
+    const double humidity;             ///<
+    const double wavelength;           ///<
+    const double lapseRate;            ///<
+    const double refractA, refractB;   ///<
+    const double longitudeOffset;      ///<
+    const double siderealTime;         ///<
+}
+psGrommit;
+
+typedef struct
+{
+    int nX, nY;               ///<
+    double x0, y0;            ///<
+    double xScale, yScale;    ///<
+    double **x, **y;          ///<
+}
+psFixedPattern;
+
+psGrommit *psGrommitAlloc(const psExposure *exp);
+
+void p_psGrommitFree(psGrommit *grommit);
+
+psCell *psCellinFPA(psCell *out,
+                    const psPlane *coord,
+                    const psFPA *FPA);
+
+psChip *psChipinFPA(psChip *out,
+                    const psPlane *coord,
+                    const psFPA *FPA);
+
+psCell *psCellinChip(psCell *out,
+                     const psPlane *coord,
+                     const psChip *chip);
+
+
+
+
+psPlane *psCoordCelltoChip(psPlane *out,
+                           const psPlane *in,
+                           const psCell *cell);
+
+psPlane *psCoordChipToFPA(psPlane *out,
+                          const psPlane *in,
+                          const psChip *chip);
+
+psPlane *psCoordFPAtoTP(psPlane *out,
+                        const psPlane *in,
+                        const psFPA *fpa);
+
+psSphere *psCoordTPtoSky(psSphere *out,
+                         const psPlane *in,
+                         const psGrommit *grommit);
+
+psPlane *psCoordCellToFPA(psPlane *out,
+                          const psPlane *in,
+                          const psCell *cell);
+
+psSphere *psCoordCelltoSky(psSphere *out,
+                           const psPlane *in,
+                           const psCell *cell);
+
+psSphere *psCoordCelltoSkyQuick(psSphere *out,
+                                const psPlane *in,
+                                const psCell *cell);
+
+psPlane *psCoordSkytoTP(psPlane *out,
+                        const psSphere *in,
+                        const psGrommit *grommit);
+
+psPlane *psCoordTPtoFPA(psPlane *out,
+                        const psPlane *in,
+                        const psFPA *fpa);
+
+psPlane *psCoordFPAtoChip(psPlane *out,
+                          const psPlane *in,
+                          const psChip *chip);
+
+psPlane *psCoordChiptoCell(psPlane *out,
+                           const psPlane *in,
+                           const psCell *cell);
+
+psPlane *psCoordSkytoCell(psPlane *out,
+                          const psSphere *in,
+                          const psCell *cell);
+
+psPlane *psCoordSkytoCellQuick(psPlane *out,
+                               const psSphere *in,
+                               const psCell *cell);
+
+#endif
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 1332)
+++ /trunk/psLib/src/math/psStats.c	(revision 1333)
@@ -1988,5 +1988,4 @@
         psFree(inF32);
     }
-
     return(stats);
 }
