Index: /trunk/archive/pslib/include/psAstrom.h
===================================================================
--- /trunk/archive/pslib/include/psAstrom.h	(revision 252)
+++ /trunk/archive/pslib/include/psAstrom.h	(revision 253)
@@ -7,16 +7,16 @@
  */
 
-/** Astrometric solution for an OTA.
+/* Astrometric transformations for a focal plane array.
  * There are five coordinate frames that we need to worry about:
- * 1. Cell frame:    x,y in pixels (raw coordinates; lower-left pixel center is 0.5,0.5 TBR)
- * 2. Chip frame:    X,Y in pixels
- * 3. FPA frame:     P,Q in microns 
+ * 1. Cell:          x,y in pixels (raw coordinates; lower-left pixel center is 0.5,0.5 TBR)
+ * 2. Chip:          X,Y in pixels
+ * 3. FPA:           P,Q in microns 
  * 4. Tangent plane: L,M in arcsec (TBR - angles or linear?) from the telescope boresight.
  * 5. Sky frame:     R,D in degrees (TBR - radians?)
  *
- * 1 <--> 2: cell.coords : a 2-D linear transformation : rotation, scaling, offset, (skew)
- * 2 <--> 3: chip.coords : a 2-D cubic (max) transform : specifies how the chips are mounted on the focal plane.
- * 3 <--> 4: fpa.distort : a 2-D quartic (?) transform : specifies the distortions in the optics
- * 4 <--> 5: fpa.SLpars  : SLALib parameters generated based on the telescope, ra, dec, time, etc from exposure info
+ * 1 <--> 2: 2 2-D polynomials: (X,Y) = f(x,y)
+ * 2 <--> 3: 2 2-D polynomials: (P.Q) = f(X,Y)
+ * 3 <--> 4: 2 4-D polynomials: (L,M) = f(P,Q,m,c) (m & c are magnitude and color of object)
+ * 4 <--> 5: SLALib transformation using exposure parameters (psExposure or psGrommit)
  */
 
@@ -67,8 +67,9 @@
     int nChips;                         ///< Number of Cells assigned
     int nAlloc;                         ///< Number of Cells available
-    psChip *chips;                      ///< Chips in the Focal Plane Array
-    psMetaData *md;                     ///< FPA-level metadata
-    psDistort *TPtoFP;                  ///< Transformation term from 
-    psDistort *FPtoTP;                  ///< Transformation term from 
+    struct psChip *chips;		///< Chips in the Focal Plane Array
+
+    psMetaDataSet *md;			///< FPA-level metadata 
+    psDistortion *TPtoFP;		///< Transformation term from 
+    psDistortion *FPtoTP;		///< Transformation term from 
     psExposure *exp;                    ///< information about this exposure
     psMatrix *dx, *dy;                  //!< Focal Plane fixed pattern residual offsets
@@ -83,11 +84,11 @@
 typedef struct {
     int nCells;                         ///< Number of Cells assigned
-    psCell *cells;                      ///< Cells in the Chip
-    psMetaData *md;                     ///< Chip-level metadata
-
+    struct psCell *cells;               ///< Cells in the Chip
+
+    psMetaDataSet *md;			///< Chip-level metadata
     psCoordXform *chipToFPA;            ///< Transformations from chip coordinates to FPA coordinates
     psCoordXform *FPAtoChip;            ///< Transformations from chip coordinates to FPA coordinates
 
-    psFPA *parentFPA;                   ///< FPA which contains this chip
+    struct psFPA *parentFPA;		///< FPA which contains this chip
 } psChip;
 
@@ -95,13 +96,14 @@
  */
 typedef struct {
-    psObjectTable *objects;             ///< objects derived from cell
+    int nImage;				///< number of images in this cell realization
     psImage *image;                     ///< imaging area of cell 
+    psDlist *objects;			///< objects derived from cell
     psImage *overscan;                  ///< bias region (subimage) of cell
-    psMetaData *md;                     ///< Cell-level metadata
+    psMetaDataSet *md;			///< Cell-level metadata
 
     psCoordXform *cellToChip;		///< Transformations from cell coordinates to chip coordinates
     psCoordXform *cellToFPA;		///< Transformations from cell coordinates to FPA coordinates
 
-    psChip  *parentChip;                ///< chip which contains this cell
+    struct psChip  *parentChip;		///< chip which contains this cell
 } psCell;
 
@@ -112,69 +114,69 @@
 /* Calculating and applying astrometric solutions */
 
-/** returns Cell in Chip which contains the given point */
-int
+/** returns Chip in FPA which contains the given FPA coordinate */
+psChip *
+psChipInFPA (psFPA *fpa, 		///< FPA description
+	     psCoord *coord		///< coordinate in FPA
+	     );
+
+/** returns Cell in Chip which contains the given chip coordinate */
+psCell *
 psCellInChip (psChip *chip, 		///< chip description
-	      psCoords *coords		///< coordinate to find
+	      psCoord *coord		///< coordinate in chip
 	      );
 
-/** returns the Cell coords for the specified Cell corresponding to the given Chip coords */
-psCoords
-psChipCoordsOnCell (psCell *cell, 	///< source cell for coordinate
-		    psCoords *coords	///< coordinate of interest
-		    );
-
-/** returns the Cell coords for the specified Cell corresponding to the given Chip coords */
-psCoords
-psCellCoordsInChip (psChip *chip, 	///< 
-		    int cell, 		///< 
-		    psCoords *coords	///< 
-		    );
-
-/** returns Chip in FPA which contains the given point */
-int
-psChipInFPA (psFPA *fpa, 		///< 
-	     psCoords *coords		///< 
-	     );
-
-/** returns the Chip coords for the specified Chip corresponding to the given FPA coords */
-psCoords
-psFPACoordsOnChip (psChip *chip, 	///< 
-		   psCoords *coords	///< 
+/** Convert (RA,Dec) to tangent plane coords */
+psCoord *
+psCoordSkyToTP(psExposure *exp,		//!< Exposure description
+	       psCoord *coord		//!< input Sky coordinate
+	       );
+
+/** Convert tangent plane coords to focal plane coordinates */
+psCoord *
+psCoordTPtoFPA(psFPA *fpa,		//!< FPA description
+	       psCoord *coord		//!< input TP coordinate
+	       );
+
+/** converts the specified FPA coord to the coord on the given Chip */
+psCoord *
+psCoordFPAtoChip (psFPA *fpa, 		///< FPA description
+		  psChip *chip,		///< Chip of interest
+		  psCoord *coord	///< input FPA coordinate
+		  ); 
+
+/** converts the specified Chip coord to the coord on the given Cell */
+psCoord *
+psCoordChiptoCell (psChip *chip,	///< Chip description
+		   psCell *cell, 	///< Cell of interest
+		   psCoord *coord	///< input Chip coordinate
 		   );
 
-/** returns the Chip coords for the specified Chip corresponding to the given FPA coords */
-psCoords
-psChipCoordsInFPA (psFPA *fpa, 		///< 
-		   int chip, 		///< 
-		   psCoords *coords	///< 
+/** converts the specified Cell coord to the coord on the parent Chip */
+psCoord *
+psCoordCelltoChip (psCell *cell, 	///< Cell description
+		   psCoord *coord	///< input Cell coordinate
 		   );
 
-/** Convert (RA,Dec) to (cell#,x,y) */
-psCoords *
-psSkyToFPA(psFPA *fpa,			//!< OTA details
-	   psCoords *coords		//!< Position on the sky
-           );
-
-/** Convert (cell#,x,y) to (RA,Dec) */
-psCoords *
-psFPAToSky(psFPA *fpa,			//!< OTA details
-	   psCoords *coords		//!< Position on the sky
-           );
-
-/** Convert (RA,Dec) to (cell#,x,y) */
-psCoords *
-psSkyToTP(psExposure *exp,		//!< OTA details
-	  psCoords *coords		//!< Position on the sky
-	  );
-
-/** Convert (RA,Dec) to (cell#,x,y) */
-psCoords *
-psTPtoSky(psExposure *exp,		//!< OTA details
-	  psCoords *coords		//!< Position on the sky
-	  );
+/** converts the specified Chip coord to the coord on the parent FPA */
+psCoord *
+psCoordChiptoFPA (psChip *chip, 	///< Chip description
+		  psCoord *coord	///< input Chip coordinate
+		  );
+
+/** Convert focal plane coords to tangent plane coordinates */
+psCoord *
+psCoordFPAToTP(psFPA *fpa,			//!< FPA description
+	       psCoord *coord		//!< input FPA coordinate
+	       );
+
+/** Convert tangent plane coords to (RA,Dec) */
+psCoord *
+psCoordTPtoSky(psExposure *exp,		//!< Exposure description
+	       psCoord *coord		//!< input TP coordinate
+	       );
 
 /** Get the airmass for a given position and sidereal time */
 float
-psGetAirmass(psCoords *coords,		//!< Position on the sky
+psGetAirmass(psCoord *coord,		//!< Position on the sky
              double siderealTime        //!< Sidereal time
              );
@@ -182,5 +184,5 @@
 /** Get the parallactic angle for a given position and sidereal time */
 float
-psGetParallactic(psCoords *coords,	//!< Position on the sky
+psGetParallactic(psCoord *coord,	//!< Position on the sky
                  double siderealTime    //!< Sidereal time
                  );
@@ -189,16 +191,8 @@
 float
 psGetRefraction(float colour,           //!< Colour of object
-                psColourRef colourRef,  //!< Colour reference
+		psPhotSystem colorPlus,	// 
+		psPhotSystem colorMinus, ///< Colour reference
                 psExposure *exp         //!< Telescope pointing information, for airmass, temp and pressure
 		);
-
-/** Fit astrometric solution to list of (chip#,x,y) and (RA,Dec) */
-int
-psFitAstrom(psOTADescription *restrict ota, //!< Initial guess for coefficients
-            const psOTAPosArray *restrict detector, //!< Positions on OTA (chip#,x,y)
-            const psSkyPosArray *restrict sky, //!< Positions on the sky (RA,Dec)
-            const psExposure *exp       //!< Telescope pointing information, for airmass, parallactic angle
-                                        //!< which may help set the astrometric solution
-            );
 
 /*** Constructors / Destructors ******************************************************/
@@ -223,4 +217,15 @@
 psExposureFree(psExposure *restrict myExp //!< Object to destroy
 	       );
-
 #endif
+
+/*
+   example images:
+
+   GPC:          1 Chip per file, 1 Cell per extension 
+   Megacam:      1 FPA per file, 1 Chip per extension, 2 Cell per extension (DSEC) 
+   CFH12K (MEF): 1 FPA per file, 1 Chip per extension, 1 Cell per extension
+   CFHT-IR:      1 FPA per file, 1 Chip per extension, 4 Cell per extension (NAXIS = 3)
+   WIRCAM:       1 FPA per file, 1 Chip per extension, 1 Cell per extension (?)
+   
+
+*/
Index: /trunk/archive/pslib/include/psImage.h
===================================================================
--- /trunk/archive/pslib/include/psImage.h	(revision 252)
+++ /trunk/archive/pslib/include/psImage.h	(revision 253)
@@ -16,13 +16,15 @@
     int nx, ny;				///< size of image 
     int x0, y0;				///< data region relative to parent 
-    psF32 **rows;		        ///< == rows_f32 
-    psS8  **rows_s8;			///< pointers to psS8 data 
-    psS16 **rows_s16;			///< pointers to psS16 data 
-    psS32 **rows_s32;			///< pointers to psS32 data 
-    psU8  **rows_u8;			///< pointers to psU8 data 
-    psU16 **rows_u16;			///< pointers to psU16 data 
-    psU32 **rows_u32;			///< pointers to psU32 data 
-    psF32 **rows_f32;			///< pointers to psF32 data 
-    psF64 **rows_f64;			///< pointers to psF64 data 
+    union {
+	psF32 **rows;		        ///< == rows_f32 
+	psS8  **rows_s8;			///< pointers to psS8 data 
+	psS16 **rows_s16;			///< pointers to psS16 data 
+	psS32 **rows_s32;			///< pointers to psS32 data 
+	psU8  **rows_u8;			///< pointers to psU8 data 
+	psU16 **rows_u16;			///< pointers to psU16 data 
+	psU32 **rows_u32;			///< pointers to psU32 data 
+	psF32 **rows_f32;			///< pointers to psF32 data 
+	psF64 **rows_f64;			///< pointers to psF64 data 
+    } rows;
     struct psImage *parent;		///< parent, if a subimage 
     struct psImage *children;		///< children of this region 
Index: /trunk/archive/pslib/include/psLib.h
===================================================================
--- /trunk/archive/pslib/include/psLib.h	(revision 252)
+++ /trunk/archive/pslib/include/psLib.h	(revision 253)
@@ -39,5 +39,5 @@
 # include <psPhotom.h>
 # include <psAstrom.h>
-# include <psObject.h>
+/* # include <psObject.h> */
 
 # endif
Index: /trunk/archive/pslib/include/psMath.h
===================================================================
--- /trunk/archive/pslib/include/psMath.h	(revision 252)
+++ /trunk/archive/pslib/include/psMath.h	(revision 253)
@@ -15,5 +15,5 @@
 	double d;			///< double value entry
 	complex float c;		///< complex value entry
-    }
+    } val;
 } p_psScalar;
 
@@ -30,13 +30,13 @@
 psUnaryOp (void *out,			///< destination (may be NULL) 
 	   void *in,			///< input
-	   char *operator,		///< operator 
+	   char *operator		///< operator 
 );
 
 /** create a psType-ed structure from a constant double value. */
-p_ps_Scalar *
+p_psScalar *
 psScalar (double value);
 
 /** create a psType-ed structure from a specified type  */
-p_ps_Scalar *
+p_psScalar *
 psScalarType (char *mode, 		///< type description 
 	      ...			///< value (or values) of specified types
Index: /trunk/archive/pslib/include/psPhotom.h
===================================================================
--- /trunk/archive/pslib/include/psPhotom.h	(revision 252)
+++ /trunk/archive/pslib/include/psPhotom.h	(revision 253)
@@ -8,8 +8,8 @@
 
 /** photometry system transformation types */
-enum {
+typedef enum {
     PS_PHOT_SYS,
-    PS_PHOT_REF,
-} psPhotTransformType
+    PS_PHOT_REF
+} psPhotTransformType;
 
 /** photometry system definition */
@@ -27,6 +27,6 @@
     psPhotSystem dst;
     psPhotSystem colorPlus, colorMinus;	///< Colour reference
-    psPolynomial2D colorAirmasTerm;
-    psPhotTranformType type;
+    psPolynomial2D transform;
+    psPhotTransformType type;
 } psPhotTransform;
 
Index: /trunk/archive/pslib/include/psPosition.h
===================================================================
--- /trunk/archive/pslib/include/psPosition.h	(revision 252)
+++ /trunk/archive/pslib/include/psPosition.h	(revision 253)
@@ -7,33 +7,40 @@
  */
 
-/*************************************************/
+/** A point in 2-D space, with errors.
+ */
 typedef struct {
     union {
 	double x;				//!< x position
 	double r;				//!< x position
-    }
+    } x;
     union {
 	double xErr;				//!< Error in x position
 	double rErr;				//!< Error in x position
-    }
+    } dx;
     union {
 	double y;				//!< y position
 	double d;				//!< y position
-    }
+    } y;
     union {
 	double yErr;				//!< Error in y position
 	double dErr;				//!< Error in y position
-    }
+    } dy;
 } psCoord;
 
+/** A polynomial transformation between coordinate frames.  This may be a linear relationship, or may
+ * represent a higher-order transformation.
+ */
+typedef struct {
+    psDPolynomial2D *x;
+    psDPolynomial2D *y;
+} psCoordXform;
+
+/** The optical distortion terms.  The lowest two terms are the x and y axis of the target system.  The higher
+ * two terms represent magnitude and color terms.
+ */
 typedef struct {
     psDPolynomial4D *x;
     psDPolynomial4D *y;
 } psDistortion;
-
-typedef struct {
-    psDPolynomial2D *x;
-    psDPolynomial2D *y;
-} psCoordXform;
 
 psCoord *psCoordXformApply (psCoordXform *frame, psCoord *coords);
@@ -46,14 +53,14 @@
 
 /** Get offset (RA,Dec) on the sky between two positions position1 and position2 may not be identical */
-psCoords *
-psGetOffset(const psCoords *restrict position1, //!< Position 1
-	    const psCoords *restrict position2, //!< Position 2
+psCoord *
+psGetOffset(const psCoord *restrict position1, //!< Position 1
+	    const psCoord *restrict position2, //!< Position 2
 	    char *system
 	    );
 
 /** Apply an offset to a position */
-psCoords *
-psApplyOffset(const psCoords *restrict position, //!< Position
-	      const psCoords *restrict offset, //!< Offset
+psCoord *
+psApplyOffset(const psCoord *restrict position, //!< Position
+	      const psCoord *restrict offset, //!< Offset
 	      char *system
     );
@@ -64,10 +71,10 @@
 
 /** Get Sun Position */
-psCoords *
+psCoord *
 psGetSunPos(float mjd			//!< MJD to get position for
 	    );
 
 /** Get Moon position */
-psCoords *
+psCoord *
 psGetMoonPos(float mjd,			//!< MJD to get position for
 	     double latitude,		//!< Latitude for apparent position
@@ -81,5 +88,5 @@
 
 /** Get Planet positions */
-psCoords *
+psCoord *
 psGetSolarSystemPos(char *solarSystemObject, //!< Named S.S. object
 		    float mjd		//!< MJD to get position for
Index: /trunk/archive/pslib/include/psSort.h
===================================================================
--- /trunk/archive/pslib/include/psSort.h	(revision 252)
+++ /trunk/archive/pslib/include/psSort.h	(revision 253)
@@ -15,5 +15,5 @@
 /** Sort an array, along with some other stuff.  Returns an index array */
 psIntArray *
-psSortIndex(psIntArray *restrict out;	//!< Output index array (may be NULL)
+psSortIndex(psIntArray *restrict out,	//!< Output index array (may be NULL)
 	    const psFloatArray *restrict myArray //!< Array to sort
     );
