Index: trunk/psLib/src/astronomy/psAstrometry.c
===================================================================
--- trunk/psLib/src/astronomy/psAstrometry.c	(revision 1406)
+++ trunk/psLib/src/astronomy/psAstrometry.c	(revision 1407)
@@ -1,2 +1,3 @@
+
 /** @file  psAstrometry.c
 *
@@ -8,6 +9,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-06 22:34:05 $
+*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-07 00:06:06 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,27 +21,27 @@
 #include "psMemory.h"
 
-static void grommitFree( psGrommit *grommit );
-static int checkValidChipCoords( double x, double y, psChip *tmpChip );
-static int checkValidImageCoords( double x, double y, psImage *tmpImage );
-
-psExposure* psExposureAlloc( double ra, double dec, double hourAngle,
-                             double zenith, double azimuth, double localTime, float date,
-                             float rotAngle, float temperature, float pressure, float humidity,
-                             float exposureTime )
-{
-    psExposure * exp = psAlloc( sizeof( psExposure ) );
-
-    *( double* ) & exp->ra = ra;
-    *( double* ) & exp->dec = dec;
-    *( double* ) & exp->hourAngle = hourAngle;
-    *( double* ) & exp->zenith = zenith;
-    *( double* ) & exp->azimuth = azimuth;
-    *( double* ) & exp->localTime = localTime;
-    *( float* ) & exp->date = date;
-    *( float* ) & exp->rotAngle = rotAngle;
-    *( float* ) & exp->temperature = temperature;
-    *( float* ) & exp->pressure = pressure;
-    *( float* ) & exp->humidity = humidity;
-    *( float* ) & exp->exposureTime = exposureTime;
+static void grommitFree(psGrommit * grommit);
+static int checkValidChipCoords(double x, double y, psChip * tmpChip);
+static int checkValidImageCoords(double x, double y, psImage * tmpImage);
+
+psExposure *psExposureAlloc(double ra, double dec, double hourAngle,
+                            double zenith, double azimuth, double localTime, float date,
+                            float rotAngle, float temperature, float pressure, float humidity,
+                            float exposureTime)
+{
+    psExposure *exp = psAlloc(sizeof(psExposure));
+
+    *(double *)&exp->ra = ra;
+    *(double *)&exp->dec = dec;
+    *(double *)&exp->hourAngle = hourAngle;
+    *(double *)&exp->zenith = zenith;
+    *(double *)&exp->azimuth = azimuth;
+    *(double *)&exp->localTime = localTime;
+    *(float *)&exp->date = date;
+    *(float *)&exp->rotAngle = rotAngle;
+    *(float *)&exp->temperature = temperature;
+    *(float *)&exp->pressure = pressure;
+    *(float *)&exp->humidity = humidity;
+    *(float *)&exp->exposureTime = exposureTime;
 
     return exp;
@@ -48,103 +49,82 @@
 }
 
-psGrommit* psGrommitAlloc( const psExposure *exp )
-{
-    double * slaGrommit = ( double * ) psAlloc( 14 * sizeof( double ) );
-    psGrommit *grommit = ( psGrommit * ) psAlloc( sizeof( psGrommit ) );
+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);
-    */
-    *( double* ) & grommit->latitude = exp->dec;              // XXX Is this correct?
-    *( double* ) & grommit->sinLat = sin( grommit->latitude );
-    *( double* ) & grommit->cosLat = cos( grommit->latitude );
-    *( double* ) & grommit->abberationMag = 0.0;
-    *( double* ) & grommit->height = 0.0;
-    *( double* ) & grommit->temperature = exp->temperature;
-    *( double* ) & grommit->pressure = exp->pressure;
-    *( double* ) & grommit->humidity = exp->humidity;
-    *( double* ) & grommit->wavelength = 0.0;
-    *( double* ) & grommit->lapseRate = 0.0;
-    *( double* ) & grommit->refractA = 0.0;
-    *( double* ) & grommit->refractB = 0.0;
-    *( double* ) & grommit->longitudeOffset = exp->ra;             // XXX Is this correct?
-    *( double* ) & 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;
+     * 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); */
+    *(double *)&grommit->latitude = exp->dec;   // XXX Is this correct?
+    *(double *)&grommit->sinLat = sin(grommit->latitude);
+    *(double *)&grommit->cosLat = cos(grommit->latitude);
+    *(double *)&grommit->abberationMag = 0.0;
+    *(double *)&grommit->height = 0.0;
+    *(double *)&grommit->temperature = exp->temperature;
+    *(double *)&grommit->pressure = exp->pressure;
+    *(double *)&grommit->humidity = exp->humidity;
+    *(double *)&grommit->wavelength = 0.0;
+    *(double *)&grommit->lapseRate = 0.0;
+    *(double *)&grommit->refractA = 0.0;
+    *(double *)&grommit->refractB = 0.0;
+    *(double *)&grommit->longitudeOffset = exp->ra;     // XXX Is this correct?
+    *(double *)&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 );
-}
-
-
-int checkValidChipCoords( double x, double y, psChip *tmpChip )
-{
-    return ( 0 );
-}
-
-psChip *psChipinFPA( psChip *out,
-                     const psPlane *coord,
-                     const psFPA *FPA )
-{
-    psArray * chips = FPA->chips;
+    tmpChip = psChipinFPA(tmpChip, coord, FPA);
+    tmpCell = psCellinChip(tmpCell, coord, tmpChip);
+    return (tmpCell);
+}
+
+int checkValidChipCoords(double x, double y, psChip * tmpChip)
+{
+    return (0);
+}
+
+psChip *psChipinFPA(psChip * out, const psPlane * coord, const psFPA * FPA)
+{
+    psArray *chips = FPA->chips;
     int nChips = chips->n;
-    psPlane* tmpCoord = NULL;
-
-    for ( int i = 0; i < nChips; i++ ) {
-        psChip* tmpChip = chips->data[ i ];
-        tmpCoord = psPlaneTransformApply( tmpCoord, tmpChip->fromFPA, coord );
-        if ( checkValidChipCoords( tmpCoord->x, tmpCoord->y,
-                                   tmpChip ) ) {
-            psFree( tmpCoord );
+    psPlane *tmpCoord = NULL;
+
+    for (int i = 0; i < nChips; i++) {
+        psChip *tmpChip = chips->data[i];
+
+        tmpCoord = psPlaneTransformApply(tmpCoord, tmpChip->fromFPA, coord);
+        if (checkValidChipCoords(tmpCoord->x, tmpCoord->y, tmpChip)) {
+            psFree(tmpCoord);
             // XXX: George, you didn't use the out parameter!
-            return ( tmpChip );
+            return (tmpChip);
         }
-        psFree( tmpCoord );
-    }
-    psFree( tmpCoord );
-    return ( NULL );
-}
-
-int checkValidImageCoords( 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 );
-}
-
+        psFree(tmpCoord);
+    }
+    psFree(tmpCoord);
+    return (NULL);
+}
+
+int checkValidImageCoords(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);
+}
 
 /*****************************************************************************
@@ -160,12 +140,10 @@
 XXX: must deallocate memory.
  *****************************************************************************/
-psCell *psCellinChip( psCell *out,
-                      const psPlane *coord,
-                      const psChip *chip )
-{
-    psPlane * tmpCoord = NULL;
-    psArray* cells;
-
-    if ( chip == NULL ) {
+psCell *psCellinChip(psCell * out, const psPlane * coord, const psChip * chip)
+{
+    psPlane *tmpCoord = NULL;
+    psArray *cells;
+
+    if (chip == NULL) {
         return NULL;
     }
@@ -173,120 +151,101 @@
     cells = chip->cells;
 
-    if ( cells == NULL ) {
+    if (cells == NULL) {
         return NULL;
     }
 
-    for ( int i = 0; i < cells->n; i++ ) {
-        psCell* tmpCell = ( psCell* ) cells->data[ i ];
-        psArray* readouts = tmpCell->readouts;
-        if ( readouts != NULL ) {
-            for ( int j = 0; j < readouts->n; j++ ) {
-                psReadout* tmpReadout = readouts->data[ j ];
-                tmpCoord = psPlaneTransformApply( tmpCoord, tmpCell->fromChip, coord );
-                if ( checkValidImageCoords( tmpCoord->x, tmpCoord->y,
-                                            tmpReadout->image ) ) {
-                    return ( tmpCell );
+    for (int i = 0; i < cells->n; i++) {
+        psCell *tmpCell = (psCell *) cells->data[i];
+        psArray *readouts = tmpCell->readouts;
+
+        if (readouts != NULL) {
+            for (int j = 0; j < readouts->n; j++) {
+                psReadout *tmpReadout = readouts->data[j];
+
+                tmpCoord = psPlaneTransformApply(tmpCoord, tmpCell->fromChip, coord);
+                if (checkValidImageCoords(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 (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)
 {
     // XXX: This code doesn't work; fpa->toTangentPlane is of the wrong type.
     // return(psPlaneTransformApply(out, fpa->toTangentPlane, in));
-    return ( NULL );
+    return (NULL);
 }
 
 // XXX: must wrap SLA_QAPQK here.
-psSphere *psCoordTPtoSky( psSphere *out,
-                          const psPlane *in,
-                          const psGrommit *grommit )
+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 ) );
-}
-
+     * 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;
+psSphere *psCoordCelltoSky(psSphere * out, const psPlane * in, const psCell * cell)
+{
+    psPlane *tmp1 = NULL;
     psPlane *tmp2 = NULL;
-    psFPA *parFPA = ( cell->parent ) ->parent;
+    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
+    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.
 
-    psFree( tmp1 );
-
-    return ( out );
+    psFree(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 );
+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;
@@ -295,60 +254,45 @@
     double ROB;
 
-    if ( out == NULL ) {
-        out = ( psPlane * ) psAlloc( sizeof( psPlane ) );
-    }
-
-    sla_AOPQK( psSphere->r, psSphere->d, *grommit, &AOB, &ZOB, &HOB, &DOB, &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 );
-}
-
-
-
-
+    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);
+}
