Index: trunk/doc/pslib/psLibSDRS.tex
===================================================================
--- trunk/doc/pslib/psLibSDRS.tex	(revision 256)
+++ trunk/doc/pslib/psLibSDRS.tex	(revision 271)
@@ -676,4 +676,5 @@
 
 \subsubsection{Coordinate frames}
+\label{sec:coordinateFrames}
 
 There are five coordinate frames that we need to worry about for the
@@ -743,5 +744,10 @@
 first-order 2D polynomials, simply specifying a translation, rotation
 and magnification; hence they are easily inverted, and there is no
-need to add reverse transformations.
+need to add reverse transformations.  We also add an additional
+transformation, which is intended to provide a ``quick and dirty''
+transform from the cell coordinates to the sky; this transformation
+not guaranteed to be as precise as the ``standard'' transformation of
+Cell $\rightarrow$ Chip $\rightarrow$ Focal Plane $\rightarrow$
+Tangent Plane $\rightarrow$ Sky, but will be faster.
 
 \begin{verbatim}
@@ -756,4 +762,5 @@
     psCoordXform *cellToChip;		///< Transformations from cell coordinates to chip coordinates
     psCoordXform *cellToFPA;		///< Transformations from cell coordinates to FPA coordinates
+    psCoordXform *cellToSky;		///< Quick and Dirty transformations from cell coordinates to sky
 
     struct psChip  *parentChip;		///< chip which contains this cell
@@ -892,24 +899,307 @@
 The fixed pattern is a correction to the general astrometric solution
 formed by summing the residuals from many observations.  The intent is
-to correct for higher-order distortions in the camera system
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+to correct for higher-order distortions in the camera system on a
+coarse grid (larger than individual pixels, but smaller than a single
+cell).  Hence, in addition to the offsets, we need to specify the size
+and scale of the grid in $x$ and $y$, as well as the origin of the
+grid.
+
+\begin{verbatim}
+/** The fixed pattern residual offsets.  These are specified via a coarse grid of x and y offsets. */
+typedef struct {
+    int nX, nY;				//!< Number of elements in x and y
+    double x0, y0;			//!< Position of the lower-left corner of the grid on the focal plane
+    double xScale, yScale;		//!< Scale of the grid
+    double **x, **y;			//!< The grid of offsets in x and y
+} psFixedPattern;
+\end{verbatim}
+
+
+\subsubsection{Constructors and Destructors}
+
+Each of the above structures needs an appropriate constructor and
+destructor.  Other than \code{psExposure}, which contains significant
+non-pointer types, the constructors should not take any arguments, and
+the destructors should only take the structure to be destroyed.
+The constructor for \code{psExposure} is specified below.
+
+\begin{verbatim}
+/** Constructor */
+psExposure *
+psExposureAlloc(double ra, double dec,  //!< Telescope boresight
+                double ha,              //!< Hour angle
+                double zd,              //!< Zenith distance
+                double az,              //!< Azimuth
+                double lst,             //!< Local Sidereal Time
+                float mjd,              //!< MJD
+                float rotAngle,         //!< Rotator position angle
+                float temp,             //!< Temperature
+                float pressure,         //!< Pressure
+                float humidity,         //!< Relative humidity
+                float exptime           //!< Exposure time
+		);
+\end{verbatim}
+
+
+\subsubsection{Finding}
+
+We require functions to return the structure containing given coordinates.
+For example, we want the chip that corresponds to the focal plane coordinates
+$(p,q) = (-1.234,+5.678)$.
+
+
+\begin{verbatim}
+/** returns Chip in FPA which contains the given FPA coordinate */
+psChip *
+psChipInFPA (psFPA *fpa, 		///< FPA description
+	     psCoord *coord		///< coordinate in FPA
+	     );
+\end{verbatim}
+
+\begin{verbatim}
+/** returns Cell in Chip which contains the given chip coordinate */
+psCell *
+psCellInChip (psChip *chip, 		///< chip description
+	      psCoord *coord		///< coordinate in chip
+	      );
+\end{verbatim}
+
+Usually we will want to go directly from the FPA to the Cell, so we
+also specify the following function, which performs the above two
+functions in order.
+
+\begin{verbatim}
+/** Return the cell in FPA which contains the given FPA coordinates */
+psCell *
+psCellInFPA(psCell *out,		//!< Cell to return, or NULL
+	    psFPA *fpa,			//!< FPA description
+	    psCoord *coord		//!< Coordinate in FPA
+	    );
+\end{verbatim}
+
+
+
+\subsubsection{Conversion Functions}
+
+We require functions to convert between the various coordinate frames
+(Section~\ref{sec:coordinateFrames}).  The heirarchy of the coordinate
+frames and the transformations between each are shown in
+Figure~\ref{fig:coco}.  The functions that employ the transformations
+are shown in Figure~\ref{fig:cocoFunc}.  In addition to
+transformations between each adjoining coordinate frame in the
+heirarchy, we also require higher-level functions to convert between
+the Cell and Sky coordinate frames; these will simply perform the
+intermediate steps.
+
+\begin{figure}
+\psfig{file=coordinateFrames.ps,width=9in,angle=-90}
+\caption{The coordinate systems in the \PS{} IPP, and the relation
+between each by transformations contained in the appropriate
+structures.}
+\label{fig:coco}
+\end{figure}
+
+\begin{figure}
+\psfig{file=coordinateConv.ps,width=9in,angle=-90}
+\caption{Conversion between coordinate systems by PSLib.}
+\label{fig:cocoFunc}
+\end{figure}
+
+The function prototypes are:
+
+\begin{verbatim}
+/** returns Chip in FPA which contains the given FPA coordinate */
+psChip *
+psChipInFPA (psChip *out,		//!< Chip to return, or NULL
+	     psFPA *fpa, 		///< FPA description
+	     psCoord *coord		///< coordinate in FPA
+	     );
+\end{verbatim}
+
+\begin{verbatim}
+/** returns Cell in Chip which contains the given chip coordinate */
+psCell *
+psCellInChip(psCell *out,		//!< Cell to return, or NULL
+	     psChip *chip, 		///< chip description
+	     psCoord *coord		///< coordinate in chip
+	     );
+\end{verbatim}
+
+\begin{verbatim}
+/** Return the cell in FPA which contains the given FPA coordinates */
+psCell *
+psCellInFPA(psCell *out,		//!< Cell to return, or NULL
+	    psFPA *fpa,			//!< FPA description
+	    psCoord *coord		//!< Coordinate in FPA
+	    );
+\end{verbatim}
+
+\begin{verbatim}
+/** Convert (RA,Dec) to cell and cell coordinates */
+psCoord *
+psCoordSkyToCell(psCoord *out,		//!< Coordinates to return, or NULL
+		 psCell *cell,		//!< Cell to return
+		 const psFPA *fpa	//!< FPA description
+		 );
+\end{verbatim}
+
+\begin{verbatim}
+/** Convert cell and cell coordinate to (RA,Dec) */
+psCoord *
+psCoordCellToSky(psCoord *out,		//!< Coordinates to return, or NULL
+		 const psCell *cell,	//!< Cell to get coordinates for
+		 psCoord *coord		//!< cell coordinates to transform
+		 );
+\end{verbatim}
+
+\begin{verbatim}
+/** Quick and dirty cell to (RA,Dec) --- employs cellToSky transformation */
+psCoord *
+psCoordCellToSkyQuick(psCoord *out,	//!< Coordinates to return, or NULL
+		      const psCell *cell, //!< Cell description
+		      psCoord *coord	//!< cell coordinates to transform
+		      );
+\end{verbatim}
+
+\begin{verbatim}
+/** Convert (RA,Dec) to tangent plane coords */
+psCoord *
+psCoordSkyToTP(psCoord *out,		//!< Coordinates to return, or NULL
+	       psexposure *exp,		//!< Exposure description
+	       psCoord *coord		//!< input Sky coordinate
+	       );
+\end{verbatim}
+
+\begin{verbatim}
+/** Convert tangent plane coords to focal plane coordinates */
+psCoord *
+psCoordTPtoFPA(psCoord *out,		//!< Coordinates to return, or NULL
+	       const psFPA *fpa,	//!< FPA description
+	       psCoord *coord		//!< input TP coordinate
+	       );
+\end{verbatim}
+
+\begin{verbatim}
+/** converts the specified FPA coord to the coord on the given Chip */
+psCoord *
+psCoordFPAtoChip (psCoord *out,		//!< Coordinates to return, or NULL
+		  psFPA *fpa, 		///< FPA description
+		  psChip *chip,		///< Chip of interest
+		  psCoord *coord	///< input FPA coordinate
+		  ); 
+\end{verbatim}
+
+\begin{verbatim}
+/** converts the specified Chip coord to the coord on the given Cell */
+psCoord *
+psCoordChiptoCell (psCoord *out,	//!< Coordinates to return, or NULL
+		   psChip *chip,	///< Chip description
+		   psCell *cell, 	///< Cell of interest
+		   psCoord *coord	///< input Chip coordinate
+		   );
+
+\begin{verbatim}
+/** converts the specified Cell coord to the coord on the parent Chip */
+psCoord *
+psCoordCelltoChip (psCoord *out,	//!< Coordinates to return, or NULL
+		   psCell *cell, 	///< Cell description
+		   psCoord *coord	///< input Cell coordinate
+		   );
+\end{verbatim}
+
+\begin{verbatim}
+/** converts the specified Chip coord to the coord on the parent FPA */
+psCoord *
+psCoordChiptoFPA (psCoord *out,		//!< Coordinates to return, or NULL
+		  psChip *chip, 	///< Chip description
+		  psCoord *coord	///< input Chip coordinate
+		  );
+\end{verbatim}
+
+\begin{verbatim}
+/** Convert focal plane coords to tangent plane coordinates */
+psCoord *
+psCoordFPAToTP(psCoord *out,		//!< Coordinates to return, or NULL
+	       psFPA *fpa,		//!< FPA description
+	       psCoord *coord		//!< input FPA coordinate
+	       );
+\end{verbatim}
+
+\begin{verbatim}
+/** Convert tangent plane coords to (RA,Dec) */
+psCoord *
+psCoordTPtoSky(psCoord *out,		//!< Coordinates to return, or NULL
+	       psExposure *exp,		//!< Exposure description
+	       psCoord *coord		//!< input TP coordinate
+	       );
+\end{verbatim}
+
+\begin{verbatim}
+/** Convert Cell coords to FPA coordinates */
+psCoord *
+psCoordCellToFPA(psCoord *out,		//!< Coordinates to return, or NULL
+		 psCell *cell,		//!< Cell description
+		 psCoord *coord		//!< Input cell coordinates
+		 );
+\end{verbatim}
+
+\subsubsection{Additional functions}
+
+We require additional functions to perform general functions which
+will be useful for astrometry.  Given coordinates on the sky, we
+need to get the airmass, the parallactic angle, and an estimate of
+the atmospheric refraction.
+
+\begin{verbatim}
+/** Get the airmass for a given position and sidereal time */
+float
+psGetAirmass(const psCoord *coord,	//!< Position on the sky
+             double siderealTime,	//!< Sidereal time
+	     float height		//!< Height above sea level
+             );
+\end{verbatim}
+
+\begin{verbatim}
+/** Get the parallactic angle for a given position and sidereal time */
+float
+psGetParallactic(const psCoord *coord,	//!< Position on the sky
+                 double siderealTime    //!< Sidereal time
+                 );
+\end{verbatim}
+
+\begin{verbatim}
+/** Estimate atmospheric refraction, along the parallactic */
+float
+psGetRefraction(float colour,           //!< Colour of object
+		psPhotSystem colorPlus,	///< Colour reference
+		psPhotSystem colorMinus, ///< Colour reference
+                const psExposure *exp	//!< Telescope pointing information, for airmass, temp and pressure
+		);
+\end{verbatim}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subsection{Dates and times}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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