Index: /trunk/doc/pslib/ChangeLogSDRS.tex
===================================================================
--- /trunk/doc/pslib/ChangeLogSDRS.tex	(revision 4039)
+++ /trunk/doc/pslib/ChangeLogSDRS.tex	(revision 4040)
@@ -1,3 +1,3 @@
-%%% $Id: ChangeLogSDRS.tex,v 1.103 2005-05-20 00:43:57 price Exp $
+%%% $Id: ChangeLogSDRS.tex,v 1.104 2005-05-27 00:38:08 eugene Exp $
 
 \subsection{Changes from version 00 to version 01}
@@ -613,3 +613,12 @@
 \item Renamed \code{psMaskToPixels} to \code{psPixelsFromMask} (bug 414).
 \item \code{psRegionFromString} returns \code{NaN} for any element that doesn't parse correctly (bug 416).
-\end{itemize}
+
+\item unified the single and double precision polynomials
+\item re-ordered the psPolynomial*Alloc arguments
+\item changed the psPolynomials to be defined in terms of Norder not Nterms
+\item re-ordered the psVectorFitPoly* arguments
+\item added mask \& maskValue ot psVectorFitPoly*
+\item changed the requirements on the input data vectors to psPolynomialFit and Eval
+\item added the psVectorClipFitPoly* functions
+
+\end{itemize}
Index: /trunk/doc/pslib/psLibSDRS.tex
===================================================================
--- /trunk/doc/pslib/psLibSDRS.tex	(revision 4039)
+++ /trunk/doc/pslib/psLibSDRS.tex	(revision 4040)
@@ -1,3 +1,3 @@
-%%% $Id: psLibSDRS.tex,v 1.233 2005-05-24 23:56:16 jhoblitt Exp $
+%%% $Id: psLibSDRS.tex,v 1.234 2005-05-27 00:38:08 eugene Exp $
 \documentclass[panstarrs,spec]{panstarrs}
 
@@ -2350,7 +2350,14 @@
 typedef struct {
     psPolynomialType type;              ///< Polynomial type
+    psElemType       ctype;             ///< Polynomial precision
     int n;                              ///< Number of terms
-    float *coeff;                       ///< Coefficients
-    float *coeffErr;                    ///< Error in coefficients
+    union {
+      psF32 *F32;                       ///< Coefficients
+      psF64 *F64;                       ///< Coefficients
+    } coeff;
+    union {
+      psF32 *F32;                       ///< Error in coefficients
+      psF64 *F64;                       ///< Error in coefficients
+    } coeffErr;
     char *mask;                         ///< Coefficient mask
 } psPolynomial1D;
@@ -2361,7 +2368,15 @@
 typedef struct {
     psPolynomialType type;              ///< Polynomial type
+    psElemType       ctype;             ///< Polynomial precision
     int nX, nY;                         ///< Number of terms in x and y
-    float **coeff;                      ///< Coefficients
-    float **coeffErr;                   ///< Error in coefficients
+    union {
+      psF32 **F32;                       ///< Coefficients
+      psF64 **F64;                       ///< Coefficients
+    } coeff;
+    union {
+      psF32 **F32;                       ///< Error in coefficients
+      psF64 **F64;                       ///< Error in coefficients
+    } coeffErr;
+    char *mask;                         ///< Coefficient mask
     char **mask;                        ///< Coefficients mask
 } psPolynomial2D;
@@ -2379,58 +2394,68 @@
 \end{datatype}
 
-We also define double-precision versions of the polynomials:
-
-\begin{datatype}
-/** Double-precision one-dimensional polynomial */
-typedef struct {
-    psPolynomialType type;              ///< Polynomial type
-    int n;                              ///< Number of terms
-    double *coeff;                      ///< Coefficients
-    double *coeffErr;                   ///< Error in coefficients
-    char *mask;                         ///< Coefficient mask
-} psDPolynomial1D;
-\end{datatype}
-
-\begin{datatype}
-/** Double-precision two-dimensional polynomial */
-typedef struct {
-    psPolynomialType type;              ///< Polynomial type
-    int nX, nY;                         ///< Number of terms in x and y
-    double **coeff;                     ///< Coefficients
-    double **coeffErr;                  ///< Error in coefficients
-    char **mask;                        ///< Coefficients mask
-} psDPolynomial2D;
-\end{datatype}
-
-etc.  In what follows, we only show the version for double-precision
-two-dimensionals; the others may be inferred following the standard
-naming convention exampled above.
-
-The constructor is:
-\begin{prototype}
-psDPolynomial2D *psDPolynomial2DAlloc(int nX, int nY, psPolynomialType type);
-\end{prototype}
-where \code{nX} and \code{nY} are the number of terms in x and y
-respectively.  The coefficients, errors and masks are set initially to
-zero.
+The element \code{ctype} defines the data type for the coefficients
+(allowed values of \code{PS_TYPE_F32} and \code{PS_TYPE_F64}).
+
+The constructors are:
+\begin{prototype}
+psPolynomial1D *psPolynomial1DAlloc(psPolynomialType type, 
+                                    psElemType ctype, 
+                                    int nX);
+psPolynomial2D *psPolynomial2DAlloc(psPolynomialType type, 
+                                    psElemType ctype, 
+                                    int nX, int nY);
+psPolynomial3D *psPolynomial3DAlloc(psPolynomialType type, 
+                                    psElemType ctype, 
+                                    int nX, int nY, int nZ);
+psPolynomial4D *psPolynomial4DAlloc(psPolynomialType type, 
+                                    psElemType ctype, 
+                                    int nX, int nY, int nZ, int nT);
+\end{prototype}
+where \code{nX}, \code{nY}, etc specify the polynomial order in the
+given dimension.  The coefficients, errors and masks are set initially
+to zero.
 
 To evaluate the polynomials at specific coordinates, we define:
 \begin{prototype}
-double psDPolynomial2DEval(const psDPolynomial2D *myPoly, double x, double y);
+psF64 psPolynomial2DEval(const psPolynomial2D *myPoly, 
+                         psF64 x);
+psF64 psPolynomial2DEval(const psPolynomial2D *myPoly, 
+			 psF64 x, 
+			 psF64 y);                
+psF64 psPolynomial2DEval(const psPolynomial2D *myPoly, 
+			 psF64 x, 
+			 psF64 y, 
+			 psF64 z);                 
+psF64 psPolynomial2DEval(const psPolynomial2D *myPoly, 
+			 psF64 x, 
+			 psF64 y, 
+			 psF64 z, 
+			 psF64 t);
 \end{prototype}
 
 In the event that several evaluations are required, we also define:
 \begin{prototype}
-psVector *psDPolynomial2DEvalVector(const psDPolynomial2D *myPoly, const psVector *x, const psVector *y);
-\end{prototype}
-If the \code{x} and \code{y} vectors do not match the precision of the
-polynomial, the function shall generate a warning, and convert the
-vectors to the appropriate precision.  In the event that the \code{x}
-and \code{y} vectors are of differing sizes, the function shall
-generate a warning, truncate the longer vector to the size of the
-shorter, and continue.  The precision of the output \code{psVector}
-shall match that of the polynomial.  In evaluation, those coefficients
-that have the corresponding \code{mask} element non-zero shall not be
-evaluated.
+psVector *psPolynomial2DEvalVector(const psPolynomial2D *myPoly, 
+                                   const psVector *x);
+psVector *psPolynomial2DEvalVector(const psPolynomial2D *myPoly, 
+                                   const psVector *x, 
+                                   const psVector *y);
+psVector *psPolynomial2DEvalVector(const psPolynomial2D *myPoly, 
+                                   const psVector *x, 
+                                   const psVector *y, 
+                                   const psVector *z);
+psVector *psPolynomial2DEvalVector(const psPolynomial2D *myPoly, 
+                                   const psVector *x, 
+                                   const psVector *y, 
+                                   const psVector *z, 
+                                   const psVector *t);
+\end{prototype}
+The function shall accept input vectors of any type, converting to
+\code{psF64} as needed.  In the event that the \code{x} and \code{y}
+vectors are of differing sizes, the function shall generate a warning,
+truncate the longer vector to the size of the shorter, and continuing.
+The precision of the output \code{psVector} shall be \code{psF64}.  In
+evaluation, those coefficients that have the corresponding \code{mask}
+element non-zero shall not be evaluated.
 
 \subsubsection{Splines}
@@ -2691,16 +2716,98 @@
 
 \begin{prototype}
-psPolynomial1D *psVectorFitPolynomial1D(psPolynomial1D *myPoly, const psVector *x, const psVector *y,
-                                        const psVector *yErr);
-\end{prototype}
-\code{psVectorFitPolynomial1d} returns the polynomial that best fits the
-observations.  The input parameters are a polynomial that specifies
-the fit order, \code{myPoly}, which will be altered and returned with
-the best-fit coefficients; and the observations, \code{x}, \code{y}
-and \code{yErr}.  The independent variable list, \code{x} may be
-\code{NULL}, in which case the vector index is used.  The dependent
-variable error, \code{yErr} may be null, in which case the solution is
-determined in the assumption that all data errors are equal.  This
-function must be valid only for types \code{psF32}, \code{psF64}.
+psPolynomial1D *psVectorFitPolynomial1D(psPolynomial1D *myPoly, 
+					const psVector *mask, 
+					unsigned int    maskValue
+					const psVector *f,
+                                        const psVector *fErr
+                                        const psVector *x);
+psPolynomial2D *psVectorFitPolynomial2D(psPolynomial1D *myPoly, 
+					const psVector *mask, 
+					unsigned int    maskValue
+					const psVector *f,
+                                        const psVector *fErr
+                                        const psVector *x, 
+                                        const psVector *y);
+psPolynomial3D *psVectorFitPolynomial3D(psPolynomial1D *myPoly, 
+					const psVector *mask, 
+					unsigned int    maskValue
+					const psVector *f,
+                                        const psVector *fErr
+                                        const psVector *x, 
+                                        const psVector *y, 
+                                        const psVector *z);
+psPolynomial4D *psVectorFitPolynomial4D(psPolynomial1D *myPoly, 
+					const psVector *mask, 
+					unsigned int    maskValue
+					const psVector *f,
+                                        const psVector *fErr
+                                        const psVector *x, 
+                                        const psVector *y, 
+                                        const psVector *z, 
+                                        const psVector *t);
+\end{prototype}
+These functions return the polynomial that best fits the input data.
+The provided polynomial, \code{myPoly}, specifies the fit order, and
+will be returnd with the best-fit coefficients.  The dependent
+variable and its error (\code{f, fErr}) are provided along with the
+appropriate number of independent variables (\code{x}, \code{y}, etc).
+In the special case of 1D fitting, the independent variable list,
+\code{x} may be \code{NULL}, in which case the vector index is used.
+The dependent variable error, \code{yErr} may be null, in which case
+the solution is determined in the assumption that all data errors are
+equal.  This function must be valid only for input data types of
+\code{psF32}, \code{psF64}. The \code{mask} and \code{maskValue}
+entries may be used to specify an input data set to ignore.  All of
+the input vectors must be the same length.
+
+\begin{prototype}
+psPolynomial1D *psVectorClipFitPolynomial1D(psPolynomial1D *myPoly, 
+  				        psStats        	   *stats,
+					const psVector 	   *mask, 
+					unsigned int   	    maskValue
+					const psVector 	   *f,
+                                        const psVector 	   *fErr
+                                        const psVector 	   *x);
+psPolynomial2D *psVectorClipFitPolynomial2D(psPolynomial1D *myPoly, 
+  				        psStats        	   *stats,
+					const psVector 	   *mask, 
+					unsigned int   	    maskValue
+					const psVector 	   *f,
+                                        const psVector 	   *fErr
+                                        const psVector 	   *x, 
+                                        const psVector 	   *y);
+psPolynomial3D *psVectorClipFitPolynomial3D(psPolynomial1D *myPoly, 
+  				        psStats        	   *stats,
+					const psVector 	   *mask, 
+					unsigned int   	    maskValue
+					const psVector 	   *f,
+                                        const psVector 	   *fErr
+                                        const psVector 	   *x, 
+                                        const psVector 	   *y, 
+                                        const psVector 	   *z);
+psPolynomial4D *psVectorClipFitPolynomial4D(psPolynomial1D *myPoly, 
+  				        psStats        	   *stats,
+					const psVector 	   *mask, 
+					unsigned int   	    maskValue
+					const psVector 	   *f,
+                                        const psVector 	   *fErr
+                                        const psVector 	   *x, 
+                                        const psVector 	   *y, 
+                                        const psVector 	   *z, 
+                                        const psVector 	   *t);
+\end{prototype}
+These functions replicate the capability of the vector fitting
+functions, but also include an iterative clipping stage.  The clipping
+parameters are defined by the \code{stats} entry, to which are also
+returned the clipped statistics for the final residuals.  Thus, if N
+clipping iterations are requested, the function performs the fit,
+constructs the residuals, measures the residual scatter, and masks the
+outlier vector elements.  This cycle is repeated N times, though on
+the last iteration, no additional masking is performed.  The provided
+mask must be respected, and any additionally masked elements are also
+masked with the same mask vector, which must be provided.  The
+elements masked by this routine are given the mask value of 1 and may
+thus be distinguished from input masked elements if they use a
+different mask value.
 
 \begin{prototype}
