Index: /trunk/archive/pslib/include/psAstrom.h
===================================================================
--- /trunk/archive/pslib/include/psAstrom.h	(revision 752)
+++ /trunk/archive/pslib/include/psAstrom.h	(revision 753)
@@ -79,6 +79,6 @@
 
     psMetadata *md;			///< FPA-level metadata 
-    psPlaneDistortion *TPtoFP;		///< Transformation term from 
-    psPlaneDistortion *FPtoTP;		///< Transformation term from 
+    psPlaneDistort *TPtoFP;		///< Transformation term from 
+    psPlaneDistort *FPtoTP;		///< Transformation term from 
     psFixedPattern *pattern;		///< Fixed pattern residual offsets
     const psExposure *exp;		///< information about this exposure
@@ -96,6 +96,6 @@
 
     psMetadata *md;			///< Chip-level metadata
-    psPlaneCoordXform *chipToFPA;	///< Transformations from chip coordinates to FPA coordinates
-    psPlaneCoordXform *FPAtoChip;	///< Transformations from FPA coordinates to chip
+    psPlaneTransform *chipToFPA;	///< Transformations from chip coordinates to FPA coordinates
+    psPlaneTransform *FPAtoChip;	///< Transformations from FPA coordinates to chip
 
     struct psFPA *parentFPA;		///< FPA which contains this chip
@@ -110,7 +110,7 @@
     psMetadata *md;			///< Cell-level metadata
 
-    psPlaneCoordXform *cellToChip;	///< Transformations from cell coordinates to chip coordinates
-    psPlaneCoordXform *cellToFPA;	///< Transformations from cell coordinates to FPA coordinates
-    psPlaneCoordXform *cellToSky;	///< Quick and Dirty transformations from cell coordinates to sky
+    psPlaneTransform *cellToChip;	///< Transformations from cell coordinates to chip coordinates
+    psPlaneTransform *cellToFPA;	///< Transformations from cell coordinates to FPA coordinates
+    psPlaneTransform *cellToSky;	///< Quick and Dirty transformations from cell coordinates to sky
 
     struct psChip  *parentChip;		///< chip which contains this cell
@@ -134,123 +134,134 @@
 /*** Calculating and applying astrometric solutions ***/
 
+/** Return the cell in FPA which contains the given FPA coordinates */
+psCell *
+psCellInFPA(psCell *out,		///< Cell to return, or NULL
+	    const psPlane *coord,	///< Coordinate in FPA
+	    const psFPA *fpa)		///< FPA description
+;
+
+
 /** returns Chip in FPA which contains the given FPA coordinate */
 psChip *
 psChipInFPA (psChip *out,		///< Chip to return, or NULL
-	     const psPlaneCoord *coord,	///< coordinate in FPA
-	     const psFPA *fpa 		///< FPA description
-	     );
+	     const psPlane *coord,	///< coordinate in FPA
+	     const psFPA *fpa) 		///< FPA description
+;
 
 /** returns Cell in Chip which contains the given chip coordinate */
 psCell *
 psCellInChip(psCell *out,		///< Cell to return, or NULL
-	     const psPlaneCoord *coord,	///< coordinate in chip
-	     const psChip *chip	///< chip description
-	     );
-
-/** Return the cell in FPA which contains the given FPA coordinates */
-psCell *
-psCellInFPA(psCell *out,		///< Cell to return, or NULL
-	    const psPlaneCoord *coord,	///< Coordinate in FPA
-	    const psFPA *fpa		///< FPA description
-	    );
-
+	     const psPlane *coord,	///< coordinate in chip
+	     const psChip *chip)	///< chip description
+;
+
+/************ conversions low -> high ****************/
+/** converts the specified Cell coord to the coord on the parent Chip */
+psPlane *
+psCoordCelltoChip (psPlane *out,	///< Coordinates to return, or NULL
+		   const psPlane *in,	///< input Cell coordinate
+		   const psCell *cell) 	///< Cell description
+;
+
+/** converts the specified Chip coord to the coord on the parent FPA */
+psPlane *
+psCoordChiptoFPA (psPlane *out,		///< Coordinates to return, or NULL
+		  const psPlane *in,	///< input Chip coordinate
+		  const psChip *chip) 	///< Chip description
+;
+
+/** Convert focal plane coords to tangent plane coordinates */
+psPlane *
+psCoordFPAToTP(psPlane *out,		///< Coordinates to return, or NULL
+	       const psPlane *in,	///< input FPA coordinate
+	       const psFPA *fpa)	///< FPA description
+;
+
+/** Convert tangent plane coords to (RA,Dec) */
+psSphere *
+psCoordTPtoSky(psSphere *out,		///< Coordinates to return, or NULL
+	       const psPlane *in,	///< input TP coordinate
+	       const psGrommit *grommit) ///< Grommit for fast conversion
+;
+
+/** Convert Cell coords to FPA coordinates */
+psPlane *
+psCoordCellToFPA(psPlane *out,		///< Coordinates to return, or NULL
+		 const psPlane *in,	///< Input cell coordinates
+		 const psCell *cell)	///< Cell description
+;
+
+/** Convert cell and cell coordinate to (RA,Dec) */
+psSphere *
+psCoordCellToSky(psSphere *out,		///< Coordinates to return, or NULL
+		 const psPlane *in,	///< cell coordinates to transform
+		 const psCell *cell)	///< Cell to get coordinates for
+;
+
+/** Convert cell and cell coordinate to (RA,Dec) */
+psSphere *
+psCoordCellToSkyQD(psSphere *out,	///< Coordinates to return, or NULL
+		   const psPlane *in,	///< cell coordinates to transform
+		   const psCell *cell)	///< Cell to get coordinates for
+;
+
+
+/************ conversions low -> high ****************/
+/** Convert (RA,Dec) to tangent plane coords */
+psPlane *
+psCoordSkyToTP(psPlane *out,		///< Coordinates to return, or NULL
+	       const psSphere *in,	///< input Sky coordinate
+	       const psGrommit *grommit) ///< Grommit for fast conversion
+;
+
+/** Convert tangent plane coords to focal plane coordinates */
+psPlane *
+psCoordTPtoFPA(psPlane *out,		///< Coordinates to return, or NULL
+	       const psPlane *in,	///< input TP coordinate
+	       const psFPA *fpa)	///< FPA description
+;
+
+/** converts the specified FPA coord to the coord on the given Chip */
+psPlane *
+psCoordFPAtoChip (psPlane *out,		///< Coordinates to return, or NULL
+		  const psPlane *in,	///< input FPA coordinate
+		  const psChip *chip)	///< Chip of interest
+;
+
+/** converts the specified Chip coord to the coord on the given Cell */
+psPlane *
+psCoordChiptoCell (psPlane *out,	///< Coordinates to return, or NULL
+		   const psPlane *in,	///< input Chip coordinate
+		   const psCell *cell) 	///< Cell of interest
+;
 
 /** Convert (RA,Dec) to cell and cell coordinates */
-psPlaneCoord *
-psCoordSkyToCell(psPlaneCoord *out,	///< Coordinates to return, or NULL
-		 psCell *cell,		///< Cell to return
-		 const psSphereCoord *in, ///< Input coordinates
-		 const psFPA *fpa	///< FPA description
-		 );
-
-/** Convert cell and cell coordinate to (RA,Dec) */
-psSphereCoord *
-psCoordCellToSky(psSphereCoord *out,	///< Coordinates to return, or NULL
-		 const psPlaneCoord *coord, ///< cell coordinates to transform
-		 const psCell *cell	///< Cell to get coordinates for
-		 );
+psPlane *
+psCoordSkyToCell(psPlane *out,		///< Coordinates to return
+		 const psSphere *in,	///< Input coordinates
+		 const psCell *cell)	///< Cell of interest
+;
 
 /** Quick and dirty cell to (RA,Dec) --- employs cellToSky transformation */
-psSphereCoord *
-psCoordCellToSkyQuick(psSphereCoord *out, ///< Coordinates to return, or NULL
-		      const psPlaneCoord *coord,	///< cell coordinates to transform
-		      const psCell *cell ///< Cell description
-		      );
-
-/** Convert (RA,Dec) to tangent plane coords */
-psPlaneCoord *
-psCoordSkyToTP(psPlaneCoord *out,	///< Coordinates to return, or NULL
-	       const psSphereCoord *coord, ///< input Sky coordinate
-	       const psGrommit *grommit ///< Grommit for fast conversion
-	       );
-
-/** Convert tangent plane coords to focal plane coordinates */
-psPlaneCoord *
-psCoordTPtoFPA(psPlaneCoord *out,	///< Coordinates to return, or NULL
-	       const psPlaneCoord *coord, ///< input TP coordinate
-	       const psFPA *fpa	       ///< FPA description
-	       );
-
-/** converts the specified FPA coord to the coord on the given Chip */
-psPlaneCoord *
-psCoordFPAtoChip (psPlaneCoord *out,	///< Coordinates to return, or NULL
-		  const psPlaneCoord *coord, ///< input FPA coordinate
-		  const psChip *chip	///< Chip of interest
-		  ); 
-
-/** converts the specified Chip coord to the coord on the given Cell */
-psPlaneCoord *
-psCoordChiptoCell (psPlaneCoord *out,	///< Coordinates to return, or NULL
-		   const psPlaneCoord *coord, ///< input Chip coordinate
-		   const psCell *cell 	///< Cell of interest
-		   );
-
-/** converts the specified Cell coord to the coord on the parent Chip */
-psPlaneCoord *
-psCoordCelltoChip (psPlaneCoord *out,	///< Coordinates to return, or NULL
-		   const psPlaneCoord *coord, ///< input Cell coordinate
-		   const psCell *cell 	///< Cell description
-		   );
-
-/** converts the specified Chip coord to the coord on the parent FPA */
-psPlaneCoord *
-psCoordChiptoFPA (psPlaneCoord *out,		///< Coordinates to return, or NULL
-		  const psPlaneCoord *coord,	///< input Chip coordinate
-		  const psChip *chip 	///< Chip description
-		  );
-
-/** Convert focal plane coords to tangent plane coordinates */
-psPlaneCoord *
-psCoordFPAToTP(psPlaneCoord *out,		///< Coordinates to return, or NULL
-	       const psPlaneCoord *coord, ///< input FPA coordinate
-	       const psFPA *fpa		///< FPA description
-	       );
-
-/** Convert tangent plane coords to (RA,Dec) */
-psSphereCoord *
-psCoordTPtoSky(psSphereCoord *out,	///< Coordinates to return, or NULL
-	       const psPlaneCoord *coord, ///< input TP coordinate
-	       const psGrommit *grommit ///< Grommit for fast conversion
-	       );
-
-/** Convert Cell coords to FPA coordinates */
-psPlaneCoord *
-psCoordCellToFPA(psPlaneCoord *out,	///< Coordinates to return, or NULL
-		 const psPlaneCoord *coord, ///< Input cell coordinates
-		 const psCell *cell	///< Cell description
-		 );
+psSphere *
+psCoordSkyToCellQD(psPlane *out,	///< Coordinates to return
+		   const psSphere *in,	///< Input coordinates
+		   const psCell *cell)	///< Cell of interest
+;
+
+/**** other utilities ****/
 
 /** Get the airmass for a given position and sidereal time */
 float
-psGetAirmass(const psSphereCoord *coord, ///< Position on the sky
+psGetAirmass(const psSphere *coord,	///< Position on the sky
              double siderealTime,	///< Sidereal time
-	     float height		///< Height above sea level
-             );
+	     float height)		///< Height above sea level
+;
 
 /** Get the parallactic angle for a given position and sidereal time */
 float
-psGetParallactic(const psSphereCoord *coord, ///< Position on the sky
-                 double siderealTime    ///< Sidereal time
-                 );
+psGetParallactic(const psSphere *coord, ///< Position on the sky
+                 double siderealTime)	///< Sidereal time
+;
 
 /** Estimate atmospheric refraction, along the parallactic */
@@ -259,11 +270,11 @@
 		psPhotSystem colorPlus,	///< Colour reference
 		psPhotSystem colorMinus, ///< Colour reference
-                const psExposure *exp	///< Telescope pointing information, for airmass, temp and pressure
-		);
+                const psExposure *exp)	///< Telescope pointing information, for airmass, temp and pressure
+;
 
 /** Calculate the parallax factor */
-psSphereCoord *
-psGetParallaxFactor(const psExposure *exp ///< Exposure details
-    );
+psSphere *
+psGetParallaxFactor(const psExposure *exp) ///< Exposure details
+;
 
 /*** Constructors / Destructors ******************************************************/
@@ -281,21 +292,21 @@
                 float pressure,         ///< Pressure
                 float humidity,         ///< Relative humidity
-                float exptime           ///< Exposure time
-		);
+                float exptime)		///< Exposure time
+;
 
 /** Destructor */
 void
-psExposureFree(psExposure *restrict myExp ///< Object to destroy
-	       );
+psExposureFree(psExposure *restrict myExp) ///< Object to destroy
+;
 
 /** Constructor */
 psGrommit *
-psGrommitAlloc(const psExposure *exp	///< Relevant exposure
-    );
+psGrommitAlloc(const psExposure *exp)	///< Relevant exposure
+;
 
 /** Destructor */
 void
-psGrommitFree(psGrommit *grommit	///< Grommit to destroy
-    );
+psGrommitFree(psGrommit *grommit)	///< Grommit to destroy
+;
 
 /* \} */ // End of AstroGroup Functions
@@ -304,11 +315,11 @@
 
 /*
-   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 (?)
+  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/psBitset.h
===================================================================
--- /trunk/archive/pslib/include/psBitset.h	(revision 752)
+++ /trunk/archive/pslib/include/psBitset.h	(revision 753)
@@ -19,10 +19,10 @@
 
 /** Constructor */
-psBitset *psBitsetAlloc(int n		///< Number of bits required
-    );
+psBitset *psBitsetAlloc(int n)		///< Number of bits required
+;
 
 /** Destructor */
-void psBitsetFree(psBitset *restrict myBits ///< bitset to destroy
-    );
+void psBitsetFree(psBitset *restrict myBits) ///< bitset to destroy
+;
 
 /************************************************************************************************************/
@@ -31,12 +31,12 @@
 psBitset *
 psBitsetSet(psBitset *restrict myBits,	///< Input bitset
-	     int bit			///< Bit to set
-    );
+	     int bit)			///< Bit to set
+;
 
 /** Check a bitset.  Returns true or false */
 int
 psBitsetTest(const psBitset *restrict checkBits, ///< bitset to check
-	      int bit			///< Bit to check
-    );
+	      int bit)			///< Bit to check
+;
 
 /** apply the given operator to two bitsets */
@@ -45,12 +45,12 @@
 	    const psBitset *restrict inBits1, ///< Input bitset 1
 	    char *operator,		///< bitset operator (AND, OR, XOR)
-	    const psBitset *restrict inBits2 ///< Input bitset 2
-    );
+	    const psBitset *restrict inBits2) ///< Input bitset 2
+;
 
 /** Apply unary NOT to a bitset */
 psBitset *
 psBitsetNot(psBitset *out,		///< Output bitset, or NULL
-	    psBitset *in		///< Input bitset to be NOT-ed
-    );
+	    psBitset *in)		///< Input bitset to be NOT-ed
+;
 
 /* \} */ // End of MathGroup Functions
Index: /trunk/archive/pslib/include/psDateTime.h
===================================================================
--- /trunk/archive/pslib/include/psDateTime.h	(revision 752)
+++ /trunk/archive/pslib/include/psDateTime.h	(revision 753)
@@ -1,4 +1,6 @@
 #if !defined(PS_DATE_TIME_H)
 #define PS_DATE_TIME_H
+
+#include "taia.h"
 
 /** \file psDateTime.h
@@ -19,6 +21,5 @@
     definition. */
 typedef struct {
-    long numSeconds;			///< Number of seconds from some defined epoch
-    double fracSeconds;			///< Fraction of seconds
+  struct taia t;
 } psTime;
 
@@ -52,5 +53,5 @@
 /** Convert psTime to JD */
 double
-psTimeToJD (psTime time)			///< Input psTime time
+psTimeToJD (psTime time)		///< Input psTime time
 ;
 
@@ -61,6 +62,11 @@
 
 /** Convert psTime to broken-down time (struct tm) */
-struct tm *
-psTimeToTm (psTime time)			///< Input psTime time
+struct tm *				
+psTimeToTm (psTime time)		///< Input psTime time
+;
+
+/** Convert psTime to lunation number */
+float
+psTimeToLunation (psTime time)		///< Input psTime time
 ;
 
@@ -86,12 +92,17 @@
 ;
 
-/** Convert timeval to psTime (struct timeval) */
+/** Convert timeval (struct timeval) to psTime */
 psTime *
 psTimevalToTime (struct timeval *input)	///< Input timeval time
 ;
 
-/** Convert broken-to psTime down time (struct tm) */
+/** Convert broken-down time (struct tm) to psTime */
 psTime *
-psTMtoTime (struct tm *input)		///< Input tm time
+psTMToTime (struct tm *input)		///< Input tm time
+;
+
+/** Convert lunation number to psTime */
+psTime *
+psLunationToTime (float lunation)	///< Input lunation
 ;
 
Index: /trunk/archive/pslib/include/psDlist.h
===================================================================
--- /trunk/archive/pslib/include/psDlist.h	(revision 752)
+++ /trunk/archive/pslib/include/psDlist.h	(revision 753)
@@ -86,9 +86,9 @@
 
 /** Convert doubly-linked list to a vector of (void *) */
-psVector *psDlistToArray(psDlist *dlist) ///< List to convert
+psVector *psDlistToVector(psDlist *dlist) ///< List to convert
 ;
 
 /** Convert array to a doubly-linked list */
-psDlist *psArrayToDlist(psVector *arr) ///< vecotor of (void *) to convert
+psDlist *psArrayToDlist(psVector *vector) ///< vector of (void *) to convert
 ;
 
Index: /trunk/archive/pslib/include/psError.h
===================================================================
--- /trunk/archive/pslib/include/psError.h	(revision 752)
+++ /trunk/archive/pslib/include/psError.h	(revision 753)
@@ -12,40 +12,50 @@
 
 typedef struct {
-    psErrorCode code;			// An error code
-    const char *descrip;		// the associated description
+    psErrorCode code;			///< An error code
+    const char *descrip;		///< the associated description
 } psErrorDescription;
 
 typedef struct {
-    char *name;				// category of code that caused the error
-    psErrorCode code;			// class of error (equivalent to errno)
-    char *msg;				// the message associated with the error
+    char *name;				///< category of code that caused the error
+    psErrorCode code;			///< class of error (equivalent to errno)
+    char *msg;				///< the message associated with the error
 } psErr;
-
-typedef enum {
-    PS_OLD_ERROR = 0,			///< This is an old error, and should append to the error stack
-    PS_NEW_ERROR = 1,			///< This is a new error and should clear the error stack
-} psErrorStatus;
 
 /// Prints an error message and doesn't abort; returns code
 int psError(const char *name,		///< Category of code that caused the error
 	    psErrorCode code,		///< class of error (equivalent to errno)
-	    psErrorStatus status,	///< is this a new error?
+	    int new,	                ///< is this a new error?
 	    const char *fmt,		///< Format
-	    ...				///< Extra arguments to use format
-    );
+	    ...)			///< Extra arguments to use format
+;
 
 void p_psErrorRegister(const psErrorDescription *errors, ///< register a set of errors
-		       int nerror);		       ///< number of errors
+		       int nerror)	///< number of errors
+;
 
-const psErr *psErrorGet(int which);	// return specified error (or an "error" with code PS_ERR_NONE)
-const psErr *psErrorLast(void);		// return last error (or an "error" with code PS_ERR_NONE)
+///< return specified error (or an "error" with code PS_ERR_NONE)
+const psErr *psErrorGet(int which);	
 
-void psErrorClear(void);		///< Clear the error stack
+///< return last error (or an "error" with code PS_ERR_NONE)
+const psErr *psErrorLast(void);		
 
-const char *psErrorCodeString(psErrorCode code);	///< return the string associated with the error code
-void psErrorStackPrint(FILE *fd, const char *fmt, ...);	///< print the errorstack to this file descriptor
-void psErrorVStackPrint(FILE *fd,	//< write to this file descriptor
-			const char *fmt,//< format for any header information; may be NULL
-			va_list ap);	//< arguments for format
+///< Clear the error stack
+void psErrorClear(void);		
+
+///< return the string associated with the error code
+const char *psErrorCodeString(psErrorCode code);	
+
+///< print the errorstack to this file descriptor
+void psErrorStackPrint(FILE *fd,	///< write to this file descriptor
+		       const char *fmt, ///< format for any header information; may be NULL
+		       ...)		///< arguments for format
+;	
+
+///< print the errorstack to this file descriptor (stdargs version)
+void psErrorStackPrintV(FILE *fd,	///< write to this file descriptor
+			const char *fmt,///< format for any header information; may be NULL
+			va_list ap)	///< arguments for format
+;
+
 
 #endif
Index: /trunk/archive/pslib/include/psFFT.h
===================================================================
--- /trunk/archive/pslib/include/psFFT.h	(revision 752)
+++ /trunk/archive/pslib/include/psFFT.h	(revision 753)
@@ -2,5 +2,5 @@
 #define PS_FFT_H
 
-#include <fftw3.h>
+/* #include <fftw3.h> */
 
 /** \file psFFT.h
@@ -13,4 +13,42 @@
  *  \{
  */
+
+/**** Vector FFT & Complex functions ****/
+
+/** FFT a vector. in: psF32 or psC32, out: psC32 */
+psVector *
+psVectorFFT(const psVector *vector,	///< Vector to transform
+	   int dir) 			///< FFT direction (1: forward, -1: reverse)
+;
+
+/** Calculate power spectrum of a vector of floating-point numbers */
+psVector *
+psVectorPowerSpectrum(const psVector *vector) ///< Vector to obtain power spectrum of
+;
+
+/** Get the real part of a vector */
+psVector *
+psVectorReal(psVector *out,		///< Vector for output (or NULL)
+	     const psVector *in)	///< Vector to get the real part of
+;
+
+/** Get the imaginary part of a vector */
+psVector *
+psVectorImaginary(psVector *out,	///< Vector for output (or NULL)
+	     const psVector *in)	///< Vector to get the imaginary part of
+;
+
+/** Construct a complex vector from real & imaginary parts */
+psVector *
+psVectorComplex(psVector *out,		///< Vector for output (or NULL)
+	       const psVector *real,	///< real part of vector
+	       const psVector *imag)	///< imaginary part of vector
+;
+
+/** Get the complex conjugate of an vector of complex floating-point numbers */
+psVector *
+psVectorConjugate(psVector *out,	///< Vector for output (or NULL)
+		  const psVector *in)	///< Vector to get the complex conjugate of
+;
 
 /**** Image FFT & Complex functions ****/
@@ -52,40 +90,4 @@
 ;
 
-/**** Vector FFT & Complex functions ****/
-
-/** FFT a vector. in: psF32 or psC32, out: psC32 */
-psVector *
-psVectorFFT(const psVector *vector)	///< Vector to transform
-;
-
-/** Calculate power spectrum of a vector of floating-point numbers */
-psVector *
-psVectorPowerSpectrum(const psVector *vector) ///< Vector to obtain power spectrum of
-;
-
-/** Get the real part of a vector */
-psVector *
-psVectorReal(psVector *out,		///< Vector for output (or NULL)
-	     const psVector *in)	///< Vector to get the real part of
-;
-
-/** Get the imaginary part of a vector */
-psVector *
-psVectorImaginary(psVector *out,	///< Vector for output (or NULL)
-	     const psVector *in)	///< Vector to get the imaginary part of
-;
-
-/** Construct a complex vector from real & imaginary parts */
-psVector *
-psVectorComplex(psVector *out,		///< Vector for output (or NULL)
-	       const psVector *real,	///< real part of vector
-	       const psVector *imag)	///< imaginary part of vector
-;
-
-/** Get the complex conjugate of an vector of complex floating-point numbers */
-psVector *
-psVectorConjugate(psVector *out,	///< Vector for output (or NULL)
-		  const psVector *in)	///< Vector to get the complex conjugate of
-;
 
 /* \} */ // End of MathGroup Functions
Index: /trunk/archive/pslib/include/psFunctions.h
===================================================================
--- /trunk/archive/pslib/include/psFunctions.h	(revision 752)
+++ /trunk/archive/pslib/include/psFunctions.h	(revision 753)
@@ -14,10 +14,17 @@
 psGaussian(float x,			///< Value at which to evaluate
 	   float mean,			///< Mean for the Gaussian
-	   float stddev			///< Standard deviation for the Gaussian
-	   );
+	   float stddev,		///< Standard deviation for the Gaussian
+	   int normal)			///< normalized Gaussian?
+;
+
+psVector *
+psGaussianDev(float mean,		///< Mean for the Gaussian
+	      float stddev,		///< Standard deviation for the Gaussian
+	      int Npts)			///< Number of points generated
+;
 
 /************************************************************************************************************/
 
-/** One-dimensional polynomial */
+/** one-dimensional polynomial */
 typedef struct {
     int n;				///< Number of terms
@@ -86,5 +93,5 @@
 /** Evaluate 1D polynomial */
 float
-psEvalPolynomial1D(float x,		///< Value at which to evaluate
+psPolynomial1DEval(float x,		///< Value at which to evaluate
 		   const psPolynomial1D *restrict myPoly ///< Coefficients for the polynomial
 		   );
@@ -92,5 +99,5 @@
 /** Evaluate 2D polynomial */
 float
-psEvalPolynomial2D(float x,		///< Value x at which to evaluate
+psPolynomial2DEval(float x,		///< Value x at which to evaluate
 		   float y,		///< Value y at which to evaluate
 		   const psPolynomial2D *restrict myPoly ///< Coefficients for the polynomial
@@ -99,5 +106,5 @@
 /** Evaluate 3D polynomial */
 float
-psEvalPolynomial3D(float x,		///< Value x at which to evaluate
+psPolynomial3DEval(float x,		///< Value x at which to evaluate
 		   float y,		///< Value y at which to evaluate
 		   float z,		///< Value z at which to evaluate
@@ -107,5 +114,5 @@
 /** Evaluate 4D polynomial */
 float
-psEvalPolynomial4D(float w,		///< Value w at which to evaluate
+psPolynomial4DEval(float w,		///< Value w at which to evaluate
 		   float x,		///< Value x at which to evaluate
 		   float y,		///< Value y at which to evaluate
@@ -187,5 +194,5 @@
 /** Evaluate 1D polynomial (double precision) */
 double
-psEvalDPolynomial1D(double x,		///< Value at which to evaluate
+psDPolynomial1DEval(double x,		///< Value at which to evaluate
 		    const psDPolynomial1D *restrict myPoly ///< Coefficients for the polynomial
 		    );
@@ -193,5 +200,5 @@
 /** Evaluate 2D polynomial (double precision) */
 double
-psEvalDPolynomial2D(double x,		///< Value x at which to evaluate
+psDPolynomial2DEval(double x,		///< Value x at which to evaluate
 		    double y,		///< Value y at which to evaluate
 		    const psDPolynomial2D *restrict myPoly ///< Coefficients for the polynomial
@@ -200,5 +207,5 @@
 /** Evaluate 3D polynomial (double precision) */
 double
-psEvalDPolynomial3D(double x,		///< Value x at which to evaluate
+psDPolynomial3DEval(double x,		///< Value x at which to evaluate
 		    double y,		///< Value y at which to evaluate
 		    double z,		///< Value z at which to evaluate
@@ -208,5 +215,5 @@
 /** Evaluate 4D polynomial (double precision) */
 double
-psEvalDPolynomial4D(double w,		///< Value w at which to evaluate
+psDPolynomial4DEval(double w,		///< Value w at which to evaluate
 		    double x,		///< Value x at which to evaluate
 		    double y,		///< Value y at which to evaluate
Index: /trunk/archive/pslib/include/psImage.h
===================================================================
--- /trunk/archive/pslib/include/psImage.h	(revision 752)
+++ /trunk/archive/pslib/include/psImage.h	(revision 753)
@@ -13,17 +13,16 @@
     const int x0, y0;			///< data region relative to parent 
     union {
-	psF32 **rows;			///< Pointers to floating-point data (default)
-	psS8  **rows_S8;		///< Pointers to char data
-	psS16 **rows_S16;		///< Pointers to short-integer data
-	psS32 **rows_S32;		///< Pointers to integer data
-	psS64 **rows_S64;		///< Pointers to long-integer data
-	psU8  **rows_U8;		///< Pointers to unsigned-char data
-	psU16 **rows_U16;		///< Pointers to unsigned-short-integer data
-	psU32 **rows_U32;		///< Pointers to unsigned-integer data
-	psU64 **rows_U64;		///< Pointers to unsigned-long-integer data
-	psF32 **rows_F32;		///< Pointers to floating-point data
-	psF64 **rows_F64;		///< Pointers to double-precision data
-	psC32 **rows_C32;		///< Pointers to complex floating-point data
-    } rows;
+	psS8  **S8;			///< Pointers to char data
+	psS16 **S16;			///< Pointers to short-integer data
+	psS32 **S32;			///< Pointers to integer data
+	psS64 **S64;			///< Pointers to long-integer data
+	psU8  **U8;			///< Pointers to unsigned-char data
+	psU16 **U16;			///< Pointers to unsigned-short-integer data
+	psU32 **U32;			///< Pointers to unsigned-integer data
+	psU64 **U64;			///< Pointers to unsigned-long-integer data
+	psF32 **F32;			///< Pointers to floating-point data
+	psF64 **F64;			///< Pointers to double-precision data
+	psC32 **C32;			///< Pointers to complex floating-point data
+    } data;
     const struct psImage *parent;	///< parent, if a subimage 
     int Nchildren;			///< number of subimages 
@@ -215,20 +214,4 @@
 ;
 
-/// Read only header from image file.
-psMetadata *
-psImageReadHeader(psMetadata *output,	///< read data to this structure
-		  const char *extname, 	///< MEF extension name ("PHU" for primary header)
-		  int extnum,		///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
-		  const char *filename)	///< file to read from
-;
-
-/// Read only header from image file descriptor.
-psMetadata *
-psImageFReadHeader(psMetadata *output,	///< read data to this structure
-		   const char *extname,	///< MEF extension name ("PHU" for primary header)
-		   int extnum,		///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
-		   FILE *f)		///< file descriptor to read from
-;
-
 /*** basic pixel manipulations ***/
 /// Clip image values outside of range to given values.  Return number of clipped pixels.
@@ -260,8 +243,8 @@
 # endif
 /* image overlay operations 
-    PS_OVERLAY_EQUALS   = '=', 
-    PS_OVERLAY_ADD      = '+', 
-    PS_OVERLAY_SUBTRACT = '-', 
-    PS_OVERLAY_MULTIPLY = '*', 
-    PS_OVERLAY_DIVIDE   = '/', 
+   PS_OVERLAY_EQUALS   = '=', 
+   PS_OVERLAY_ADD      = '+', 
+   PS_OVERLAY_SUBTRACT = '-', 
+   PS_OVERLAY_MULTIPLY = '*', 
+   PS_OVERLAY_DIVIDE   = '/', 
 */
Index: /trunk/archive/pslib/include/psLib.h
===================================================================
--- /trunk/archive/pslib/include/psLib.h	(revision 752)
+++ /trunk/archive/pslib/include/psLib.h	(revision 753)
@@ -49,6 +49,6 @@
 
 /** @ingroup AstroGroup */
+# include <psDateTime.h>
 # include <psPosition.h>
-# include <psDateTime.h>
 # include <psMetadata.h>
 # include <psImage.h>
Index: /trunk/archive/pslib/include/psLogMsg.h
===================================================================
--- /trunk/archive/pslib/include/psLogMsg.h	(revision 752)
+++ /trunk/archive/pslib/include/psLogMsg.h	(revision 753)
@@ -30,8 +30,8 @@
 
 /// Logs a message from varargs
-void p_psLogVMsg(const char *name,	///< name of the log source
-		 int myLevel,		///< severity level of this log message 
-		 const char *fmt, 	///< printf-style format command
-		 va_list ap)		///< varargs argument list
+void psLogMsgV(const char *name,	///< name of the log source
+	       int myLevel,		///< severity level of this log message 
+	       const char *fmt, 	///< printf-style format command
+	       va_list ap)		///< varargs argument list
 ; 
 
Index: /trunk/archive/pslib/include/psMath.h
===================================================================
--- /trunk/archive/pslib/include/psMath.h	(revision 752)
+++ /trunk/archive/pslib/include/psMath.h	(revision 753)
@@ -11,9 +11,9 @@
     psType type;			///< data type information
     union {			       
-	int i;				///< integer value entry
-	float f;			///< float value entry
-	double d;			///< double value entry
-	complex float c;		///< complex value entry
-    } val;
+	psS32 S32;			///< integer value entry
+	psF32 F32;			///< float value entry
+	psF64 F64;			///< double value entry
+	psC32 C32;			///< complex value entry
+    } data;
 } p_psScalar;
 
@@ -28,6 +28,6 @@
 	    void *in1,			///< first input
 	    char *op,			///< operator 
-	    void *in2			///< second input
-    );
+	    void *in2)			///< second input
+;
 
 /** Perform a unary operation on two data items (psImage, psVector, psScalar). */
@@ -35,6 +35,6 @@
 psUnaryOp (void *out,			///< destination (may be NULL) 
 	   void *in,			///< input
-	   char *op			///< operator 
-    );
+	   char *op)			///< operator 
+;
 
 /** create a psType-ed structure from a constant double value. */
@@ -45,6 +45,6 @@
 p_psScalar *
 psScalarType (char *mode, 		///< type description 
-	      ...			///< value (or values) of specified types
-    );
+	      ...)			///< value (or values) of specified types
+;
 
 /* \} */ // End of MathGroup Functions
Index: /trunk/archive/pslib/include/psMatrix.h
===================================================================
--- /trunk/archive/pslib/include/psMatrix.h	(revision 752)
+++ /trunk/archive/pslib/include/psMatrix.h	(revision 753)
@@ -19,43 +19,42 @@
 psMatrixInvert(psImage *out,		///< Matrix to return, or NULL
 	       const psImage *myMatrix, ///< Matrix to be inverted
-	       float *restrict determinant ///< Determinant to return, or NULL
-    );
+	       float *restrict determinant) ///< Determinant to return, or NULL
+;
 
 /** Matrix determinant */
 float
-psMatrixDeterminant(const psImage *restrict myMatrix ///< Matrix to get determinant for
-		    );
+psMatrixDeterminant(const psImage *restrict myMatrix) ///< Matrix to get determinant for
+;
 
 /** Matrix operation: addition, subtraction, multiplication */
 psImage *
-psMatrixOp(psImage *out,		///< Matrix to return, or NULL
-	   const psImage *matrix1,	///< Matrix 1
-           const char *op,              ///< Operation to perform: "+", "-", "*"
-	   const psImage *matrix2	///< Matrix 2
-    );
+psMatrixMultiply(psImage *out,		///< Matrix to return, or NULL
+		 const psImage *in1,	///< Matrix 1
+		 const psImage *in2)	///< Matrix 2
+;
 
 /** Transpose Matrix */
 psImage *
 psMatrixTranspose(psImage *out,		///< Matrix to return, or NULL
-		  const psImage *myMatrix ///< Matrix to transpose
-		  );
+		  const psImage *in)	///< Matrix to transpose
+;
 
 /** LU Decomposition of a matrix */
 psImage *
 psMatrixLUD(psImage *out,		///< Matrix to return, or NULL
-	    psImage *myMatrix		///< Matrix to decompose
-	    );
+	    psImage *in)		///< Matrix to decompose
+;
 
 /** LU Solution.  Solves for and returns x in the equation Ax = b */
 psVector *
 psMatrixLUSolve(psVector *out,		///< Vector to return, or NULL
-		const psImage *luMatrix, ///< LU-decomposed matrix
-		const psVector *rhsVector ///< right-hand-side of the equation
-		); 
+		const psImage *LU,	///< LU-decomposed matrix
+		const psVector *RHS)	///< right-hand-side of the equation
+;
 
 /** Eigenvectors of a matrix */
 psVector *
-psMatrixEigenvectors(psImage *myMatrix	///< Matrix to get eigenvectors for
-    );
+psMatrixEigenvectors(psImage *myMatrix)	///< Matrix to get eigenvectors for
+;
 
 /***********************************************************************************************************/
@@ -66,12 +65,12 @@
 psVector *
 psMatrixToVector(psVector *out,		///< Vector to return, or NULL
-		 psImage *myMatrix	///< Matrix to convert
-    );
+		 psImage *in)		///< Matrix to convert
+;
 
 /** Convert vector to matrix. */
 psImage *
 psVectorToMatrix(psImage *out,		///< Matrix to return, or NULL
-		 psVector *myVector	///< Vector to convert
-    );
+		 psVector *in)		///< Vector to convert
+;
 
 /* \} */ // End of MathGroup Functions
Index: /trunk/archive/pslib/include/psMemory.h
===================================================================
--- /trunk/archive/pslib/include/psMemory.h	(revision 752)
+++ /trunk/archive/pslib/include/psMemory.h	(revision 753)
@@ -26,14 +26,14 @@
 
 /// prototype of a basic callback used by memory functions 
-typedef long (*psMemAllocateCB)(const psMemBlock *ptr);
+typedef long (*psMemAllocateCallback)(const psMemBlock *ptr);
 
 /// prototype of memory free callback used by memory functions 
-typedef long (*psMemFreeCB)(const psMemBlock *ptr);
+typedef long (*psMemFreeCallback)(const psMemBlock *ptr);
 
 /// prototype of a callback used in error conditions 
-typedef void (*psMemProblemCB)(const psMemBlock *ptr, const char *file, int lineno);
+typedef void (*psMemProblemCallback)(const psMemBlock *ptr, const char *file, int lineno);
 
 /// prototype of a callback used when memory runs out 
-typedef void *(*psMemExhaustedCB)(size_t size);
+typedef void *(*psMemExhaustedCallback)(size_t size);
 
 /** Functions **************************************************************/
@@ -84,17 +84,17 @@
 
 /// Set callback for problems 
-psMemProblemCB psMemProblemCBSet(psMemProblemCB func) ///< Function to run
+psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func) ///< Function to run
 ;
 
 /// Set callback for out-of-memory 
-psMemExhaustedCB psMemExhaustedCBSet(psMemExhaustedCB func) ///< Function to run
+psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func) ///< Function to run
 ;
 
 /// Set call back for when a particular memory block is allocated 
-psMemAllocateCB psMemAllocateCBSet(psMemAllocateCB func) ///< Function to run
+psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func) ///< Function to run
 ;
 
 /// Set call back for when a particular memory block is freed 
-psMemFreeCB psMemFreeCBSet(psMemFreeCB func) ///< Function to run
+psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func) ///< Function to run
 ;
 
Index: /trunk/archive/pslib/include/psMetadata.h
===================================================================
--- /trunk/archive/pslib/include/psMetadata.h	(revision 752)
+++ /trunk/archive/pslib/include/psMetadata.h	(revision 753)
@@ -10,6 +10,7 @@
 typedef enum {				///< type of val is:
     PS_META_ITEM_SET = 0,		///< NULL; metadata is in psMetadataType.items
-    PS_META_FLOAT,			///< float (.f)
-    PS_META_INT,			///< int (.i)
+    PS_META_S32,			///< int (.i)
+    PS_META_F32,			///< float (.f)
+    PS_META_F64,			///< float (.f)
     PS_META_STR,			///< string (.v)
     PS_META_IMG,			///< image (.v)
@@ -34,10 +35,10 @@
     psMetadataType type;		///< type of this item
     psMetadataFlags flags;		///< flags associated with this item
-    const union {
-	double d;			///< double value
-	float f;			///< floating value
-	int i;				///< integer value
-	void *v;			///< other type
-    } val;				///< value of metadata
+    union {
+	psS32 S32;			///< integer value
+	psF32 F32;			///< floating value
+	psF64 F64;			///< double value
+	void *V;			///< other type
+    } data;				///< value of metadata
     char *comment;			///< optional comment ("", not NULL)
     psDlist *restrict items;		///< list of psMetadataItems with the same name
@@ -56,29 +57,27 @@
 
 /** Constructor */
-psMetadataItem *psMetadataItemAlloc(int typeFlags, ///< type of this piece of metadata + flags
-				    const void *val, ///< value of new item N.b. a pointer even if the item
-					             ///< is of type e.g. int
+psMetadataItem *psMetadataItemAlloc(const char *name, ///< name of new item of metadata (sprintf format)
+				    int format, ///< type of this piece of metadata + flags
 				    const char *comment, ///< comment associated with item
-				    const char *name, ///< name of new item of metadata (may be in sprintf
-						      ///< format)
-				    ...	///< possible arguments for name format
-    );
-psMetadataItem *psVMetadataItemAlloc(
-    int typeFlags,			// type of this piece of metadata + flags
-    const void *data,			// value of new item
-    const char *comment,		// comment associated with item; may be NULL
-    const char *name,			// name of new item of metadata (may be an sprintf format)
-    va_list ap				// possible arguments for name format
-    );
+				    ...)	///< arguments for name and data
+;
+
+psMetadataItem *psMetadataItemAllocV(const char *name, ///< name of new item of metadata (sprintf format)
+				    int format, ///< type of this piece of metadata + flags
+				    const char *comment, ///< comment associated with item
+				    va_list ap)	///< arguments for name and data
+;
 
 /** Destructor */
-void psMetadataItemFree(psMetadataItem *ms ///< piece of metadata to destroy
-    );
+void psMetadataItemFree(psMetadataItem *ms) ///< piece of metadata to destroy
+;
+
 /** Constructor */
-psMetadata *psMetadataAlloc(void);   ///< make a new set of metadata
+psMetadata *psMetadataAlloc(void)   ///< make a new set of metadata
+;
 
 /** Destructor */
-void psMetadataFree(psMetadata *md ///< destroy a set of metadata
-    );
+void psMetadataFree(psMetadata *md) ///< destroy a set of metadata
+;
 
 /**** Utilities **********************************************************************/
@@ -86,17 +85,14 @@
 /// Add item to the end of the metadata
 psMetadataItem *psMetadataAppendItem(psMetadata *restrict md, ///< metadata to add to
-				     psMetadataItem *restrict item ///< Metatdata item to add
-    );
+				     psMetadataItem *restrict item) ///< Metatdata item to add
+;
 
 /// Add item to the end of the metadata.  Combines psMetadataItemAlloc and psMetadataAppendItem
 psMetadataItem *psMetadataAppend(psMetadata *restrict md, ///< Metadata to add to
-				 int typeFlags, ///< type of this piece of metadata + flags
-				 const void *val, ///< value of new item N.b. a pointer even if the item
-				                  ///< is of type e.g. int
+				 const char *name, ///< name of new item of metadata (sprintf format)
+				 int format, ///< type of this piece of metadata + flags
 				 const char *comment, ///< comment associated with item
-				 const char *name, ///< name of new item of metadata (may be in sprintf
-				                   ///< format)
-				 ...	///< possible arguments for name format
-    );
+				 ...)	///< possible arguments for name format
+;
 
 /// delete item from the metadata
@@ -125,4 +121,21 @@
 			 const char *prefix	   ///< print this at the beginning of each line
     );
+
+/// Read only header from image file.
+psMetadata *
+psMetadataReadHeader(psMetadata *out,	///< read data to this structure
+		     const char *ext,	///< MEF extension name ("PHU" for primary header)
+		     int extnum,	///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+		     const char *file)	///< file to read from
+;
+
+/// Read only header from image file descriptor.
+psMetadata *
+psMetadataFReadHeader(psMetadata *out,	///< read data to this structure
+		      const char *ext,	///< MEF extension name ("PHU" for primary header)
+		      int extnum,	///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+		      FILE *f)		///< file descriptor to read from
+;
+
 /* \} */ // End of AstroGroup Functions
 #endif
Index: /trunk/archive/pslib/include/psMinimize.h
===================================================================
--- /trunk/archive/pslib/include/psMinimize.h	(revision 752)
+++ /trunk/archive/pslib/include/psMinimize.h	(revision 753)
@@ -15,6 +15,6 @@
 psVector *
 psMinimize(psVector *restrict initialGuess, ///< Initial guess and answer
-	   float (*myFunction)(const psVector *restrict), ///< Function to minimize
-	   float (*myFuncDeriv)(const psVector *restrict), ///< Derivatives of function, or NULL
+	   float (*myFunction)(const psVector *restrict, const psVector *restrict), ///< Function to minimize
+	   float (*myFuncDeriv)(const psVector *restrict, const psVector *restrict), ///< Derivatives of function, or NULL
 	   const psVector *restrict paramMask) ///< 1 = fit for parameter, 0 = hold parameter constant
 ;
@@ -24,10 +24,10 @@
 psVector *
 psMinimizeChi2(psVector *restrict initialGuess,	///< Initial guess and answer
-	       float (*evalModel)(const psVector *restrict,
-				  const psVector *restrict), ///< Model to fit; (domain and params)
+	       float (*evalModel)(const psVector *restrict, const psVector *restrict), ///< Model to fit; (domain and params)
 	       const psVector *restrict domain, ///< The domain values for the corresponding measurements
 	       const psVector *restrict data, ///< Data to fit
 	       const psVector *restrict errors, ///< Errors in the data
-	       const psVector *restrict paramMask) ///< 1 = fit for parameter, 0 = hold parameter constant
+	       const psVector *restrict paramMask, ///< 1 = fit for parameter, 0 = hold parameter constant
+	       float ChiSq)		///< calculated chisq of fit
 ;
 
@@ -35,7 +35,7 @@
 psPolynomial1D *
 psVectorFitPolynomial(psPolynomial1D myPoly, ///< Polynomial to fit
-		     const psVector *restrict x, ///< Ordinates (or NULL to just use the indices)
-		     const psVector *restrict y, ///< Coordinates
-		     const psVector *restrict yErr) ///< Errors in coordinates, or NULL
+ 		      const psVector *restrict x, ///< Ordinates (or NULL to just use the indices)
+		      const psVector *restrict y, ///< Coordinates
+		      const psVector *restrict yErr) ///< Errors in coordinates, or NULL
 ;
 
Index: /trunk/archive/pslib/include/psPosition.h
===================================================================
--- /trunk/archive/pslib/include/psPosition.h	(revision 752)
+++ /trunk/archive/pslib/include/psPosition.h	(revision 753)
@@ -8,4 +8,14 @@
 
 /** Structures *********************/
+
+/** projection types */
+typedef enum {                          ///< type of val is:
+    PS_PROJ_TAN,                        ///< Tangent projection
+    PS_PROJ_SIN,                        ///< Sine projection
+    PS_PROJ_AIT,                        ///< Aitoff projection
+    PS_PROJ_PAR,                        ///< Par projection
+    PS_PROJ_GLS,                        ///< GLS projection
+    PS_PROJ_NTYPE                       ///< Number of types; must be last
+} psProjectionType;
 
 /** A point in 2-D space, with errors. */
@@ -15,5 +25,5 @@
     double xErr;			///< Error in x position
     double yErr;			///< Error in y position
-} psPlaneCoord;
+} psPlane;
 
 /** A point on the surface of a sphere, with errors */
@@ -23,5 +33,5 @@
     double rErr;			///< Error in RA
     double dErr;			///< Error in Dec
-} psSphereCoord;
+} psSphere;
 
 /** A polynomial transformation between coordinate frames.  This may be a linear relationship, or may
@@ -31,5 +41,5 @@
     psDPolynomial2D *x;
     psDPolynomial2D *y;
-} psPlaneCoordXform;
+} psPlaneTransform;
 
 /** The optical distortion terms.  The lowest two terms are the x and y axis of the target system.  The higher
@@ -39,5 +49,22 @@
     psDPolynomial4D *x;
     psDPolynomial4D *y;
-} psPlaneDistortion;
+} psPlaneDistort;
+
+/** General spherical transformation */
+typedef struct {
+  double sinNPlon;                       ///< sin of North Pole longitude
+  double cosNPlon;                       ///< cos of North Pole longitude
+  double sinNPlat;                       ///< sin of North Pole lattitude
+  double cosNPlat;                       ///< cos of North Pole lattitude
+  double sinZP;	                         ///< sin of First PT of Ares lon
+  double cosZP;	                         ///< cos of First PT of Ares lon
+} psSphereTransform;
+
+/** Spherical <-> Linear projections */
+typedef struct {
+    double R, D;                         ///< coordinates of projection center
+    double Xs, Ys;                       ///< plate-scale in X and Y directions
+    psProjectionType type;               ///< projection type
+} psProjection;
 
 /** Functions **************************************************************/
@@ -47,111 +74,131 @@
 
 /** apply the coordinate transformation to the given coordinate */
-psPlaneCoord *psPlaneCoordXformApply (psPlaneCoord *out, ///< Output coordinates, or NULL
-				      const psPlaneCoordXform *frame, ///< coordinate transformation
-				      const psPlaneCoord *coords ///< input coordiate
-    );
+psPlane *psPlaneTransformApply (psPlane *out, ///< Output coordinates, or NULL
+				const psPlaneTransform *frame, ///< coordinate transformation
+				const psPlane *coords) ///< input coordiate
+;
 
 /** apply the optical distortion to the given coordinate, magnitude, color */
-psPlaneCoord *psPlaneDistortionApply (psPlaneCoord *out, ///< Output coordinates, or NULL
-				      const psPlaneDistortion *pattern, ///< optical distortion pattern
-				      const psPlaneCoord *coords, ///< input coordinate
-				      float mag, ///< magnitude of object
-				      float color ///< color of object
-    );
+psPlane *psPlaneDistortApply (psPlane *out, ///< Output coordinates, or NULL
+			      const psPlaneDistort *pattern, ///< optical distortion pattern
+			      const psPlane *coords, ///< input coordinate
+			      float mag, ///< magnitude of object
+			      float color) ///< color of object
+;
+
+/* Celestial coordinate conversions */
+
+/** Constructor */
+psSphereTransform *
+psSphereTransformAlloc(double pole1, ///< First location of pole
+		       double pole2, ///< Second location of pole
+		       double rotation) ///< Rotation between systems
+;
+
+/** Destructor */
+void psSphereTransformFree(psSphereTransform *trans) ///< Transform to destroy
+;
+
+/** Apply general spherical transformation */
+psSphere *
+psSphereTransformApply(const psSphere *coord, ///< Coordinates to convert
+		       const psSphereTransform *sys) ///< System to use to convert
+;
+
+/** Return transformation structure to convert ICRS to Ecliptic */
+psSphereTransform *psSphereTransformItoE(void);
+
+/** Return transformation structure to convert Ecliptic to ICRS */
+psSphereTransform *psSphereTransformEtoI(void);
+
+/** Return transformation structure to convert ICRS to Galactic */
+psSphereTransform *psSphereTransformItoG(void);
+
+/** Return transformation structure to convert Galactic to ICRS */
+psSphereTransform *psSphereTransformGtoI(void);
+
+/***********************************************************************************************************/
+
+
+/** Project spherical system onto a plane */
+psPlane *
+psCoordProject(const psSphere *coord, ///< Spherical coordinates to project
+	       const psProjection *projection)	///< Projection to use
+;
+
+/** Deproject plane onto spherical system */
+psSphere *
+psCoordDeproject(const psPlane *coord, ///< Plane coordinates to deproject
+		 const psProjection *projection)	///< Projection to use
+;
 
 /** Get offset (RA,Dec) on the sky between two positions position1 and position2 may not be identical */
-psSphereCoord *
-psSphereCoordGetOffset(const psSphereCoord *restrict position1, ///< Position 1
-		       const psSphereCoord *restrict position2, ///< Position 2
-		       const char *type		///< Type of offset: Linear, Spherical/Arcsec,
-						///< Spherical/Degreees etc
-    );
+psSphere *
+psSphereGetOffset(const psSphere *restrict position1, ///< Position 1
+		  const psSphere *restrict position2, ///< Position 2
+		  const char *type)	///< Type of offset: Spherical/Arcsec, Spherical/Degreees etc
+;
 
 /** Apply an offset to a position */
-psSphereCoord *
-psSphereCoordApplyOffset(const psSphereCoord *restrict position, ///< Position
-			 const psSphereCoord *restrict offset, ///< Offset
-			 const char *type		///< Type of offset: Linear, Spherical/Arcsec,
-							///< Spherical/Degreees etc
-    );
+psSphere *
+psSphereApplyOffset(const psSphere *restrict position, ///< Position
+		    const psSphere *restrict offset, ///< Offset
+		    const char *type)	///< Type of offset: Spherical/Arcsec, Spherical/Degreees etc
+;
 
 /* Positions of well-known objects */
 
 /** Get Sun Position */
-psSphereCoord *
-psGetSunPos(float mjd			///< MJD to get position for
-    );
-
-/** Get Moon position */
-psSphereCoord *
-psGetMoonPos(float mjd,			///< MJD to get position for
-	     double latitude,		///< Latitude for apparent position
-	     double longitude		///< Longitude for apparent position
-    );
+psSphere *
+psSunGetPos(psTime time)		///< MJD to get position for
+;
+
+/** Get Sun Rise time */
+psSphere *
+psSunGetRise(psTime *twi15,		///< corresponding 15 deg twilight
+	     psTime *twi18,		///< corresponding 18 deg twilight
+	     psTime time)		///< get rise closest to this time
+;
+
+/** Get Sun Set time */
+psSphere *
+psSunGetSet(psTime *twi15,		///< corresponding 15 deg twilight
+	    psTime *twi18,		///< corresponding 18 deg twilight
+	    psTime time)		///< get set closest to this time
+;
+
+/** Get Length of closest night */
+float
+psNightLength(psTime time)		///< MJD to get position for
+;
+
+/** Get Moon Position */
+psSphere *
+psMoonGetPos(psTime time)		///< MJD to get position for
+;
+
+/** Get Moon Rise time */
+psSphere *
+psMoonGetRise(psTime time)		///< get rise closest to this time
+;
+
+/** Get Moon Set time */
+psSphere *
+psMoonGetSet(psTime time)		///< get set closest to this time
+;
 
 /** Get Moon phase */
 float
-psGetMoonPhase(float mjd		///< MJD to get phase for
-    );
+psMoonGetPhase(psTime time)		///< MJD to get phase for
+;
 
 /** Get Planet positions */
-psSphereCoord *
-psGetSolarSystemPos(const char *solarSystemObject, ///< Named S.S. object
-		    float mjd		///< MJD to get position for
-    );
+psSphere *
+psPlanetGetPos(const char *solarSystemObject, ///< Named S.S. object
+	       psTime time)		///< MJD to get position for
+;
 
 /***********************************************************************************************************/
 
-/* Celestial coordinate conversions */
-
-/** General spherical transformation */
-typedef struct {
-    double sin1, sin2, sin3, cos1, cos2, cos3; ///< Sines and cosines for transformation
-} psSphereCoordTransformation;
-
-/** Constructor */
-psSphereCoordTransformation *
-psSphereCoordTransformationAlloc(double pole1, ///< First location of pole
-				 double pole2, ///< Second location of pole
-				 double rotation ///< Rotation between systems
-    );
-
-/** Destructor */
-void psSphereCoordTranformationFree(psSphereCoordTransformation *trans ///< Transformation to destroy
-    );
-
-/** Apply general spherical transformation */
-psSphereCoord *
-psSphereCoordTransform(const psSphereCoord *coord, ///< Coordinates to convert
-		       const psSphereCoordTransformation *sys ///< System to use to convert
-    );
-
-/** Return transformation structure to convert ICRS to Ecliptic */
-psSphereCoordTransformation *psSphereCoordTransformationItoE(void);
-
-/** Return transformation structure to convert Ecliptic to ICRS */
-psSphereCoordTransformation *psSphereCoordTransformationEtoI(void);
-
-/** Return transformation structure to convert ICRS to Galactic */
-psSphereCoordTransformation *psSphereCoordTransformationItoG(void);
-
-/** Return transformation structure to convert Galactic to ICRS */
-psSphereCoordTransformation *psSphereCoordTransformationGtoI(void);
-
-/***********************************************************************************************************/
-
-
-/** Project spherical system onto a plane */
-psPlaneCoord *
-psCoordProject(const psSphereCoord *coord, ///< Spherical coordinates to project
-	       const char *projection	///< Projection to use
-    );
-
-/** Deproject plane onto spherical system */
-psSphereCoord *
-psCoordDeproject(const psPlaneCoord *coord, ///< Plane coordinates to deproject
-		 const char *projection	///< Projection to use
-    );
-
 /* \} */ // End of AstroGroup Functions
 
Index: /trunk/archive/pslib/include/psStats.h
===================================================================
--- /trunk/archive/pslib/include/psStats.h	(revision 752)
+++ /trunk/archive/pslib/include/psStats.h	(revision 753)
@@ -12,49 +12,44 @@
     PS_STAT_SAMPLE_MEDIAN         = 0x000002,
     PS_STAT_SAMPLE_STDEV          = 0x000004,
-    PS_STAT_SAMPLE_UQ 		  = 0x000008, 
-    PS_STAT_SAMPLE_LQ 		  = 0x000010,
-    PS_STAT_ROBUST_MEAN           = 0x000020,
-    PS_STAT_ROBUST_MEAN_NVALUES   = 0x000040,
-    PS_STAT_ROBUST_MEDIAN         = 0x000080,
-    PS_STAT_ROBUST_MEDIAN_NVALUES = 0x000100,
-    PS_STAT_ROBUST_MODE           = 0x000200,
-    PS_STAT_ROBUST_MODE_NVALUES   = 0x000400,
-    PS_STAT_ROBUST_STDEV          = 0x000800,
-    PS_STAT_ROBUST_UQ 		  = 0x001000, 
-    PS_STAT_ROBUST_LQ 		  = 0x002000,
-    PS_STAT_CLIPPED_MEAN          = 0x004000,
-    PS_STAT_CLIPPED_MEAN_NVALUES  = 0x008000,
-    PS_STAT_CLIPPED_MEAN_NSIGMA   = 0x010000,
-    PS_STAT_CLIPPED_STDEV         = 0x020000,
-    PS_STAT_MAX     		  = 0x040000,     
-    PS_STAT_MIN     		  = 0x080000,
-    PS_STAT_NVALUES 		  = 0x100000
+    PS_STAT_SAMPLE_QUARTILE       = 0x000008, 
+    PS_STAT_ROBUST_MEAN           = 0x000010,
+    PS_STAT_ROBUST_MEDIAN         = 0x000020,
+    PS_STAT_ROBUST_MODE           = 0x000040,
+    PS_STAT_ROBUST_STDEV          = 0x000080,
+    PS_STAT_ROBUST_QUARTILE       = 0x000100, 
+    PS_STAT_CLIPPED_MEAN          = 0x000200,
+    PS_STAT_CLIPPED_STDEV         = 0x000400,
+    PS_STAT_MAX                   = 0x000800,     
+    PS_STAT_MIN                   = 0x001000,
+    PS_STAT_USE_RANGE             = 0x002000,
+    PS_STAT_USE_BINSIZE           = 0x004000,
+    PS_STAT_ROBUST_FOR_SAMPLE     = 0x008000
 } psStatsOptions;    			  
 
 /** generic statistics structure */
 typedef struct {
-    double sampleMean;			///< formal mean of sample
-    double sampleMedian;		///< formal median of sample
-    double sampleStdev;			///< standard deviation of sample
-    double sampleUQ;			///< upper quartile of sample
-    double sampleLQ;			///< lower quartile of sample
-    double robustMean;			///< robust mean of data
-    int    robustMeanNvalues;		///< number of measurements used for robust mean
-    double robustMedian;		///< robust median of data
-    int    robustMedianNvalues;		///< number of measurements used for robust median
-    double robustMode;			///< Robust mode of data
-    int    robustModeNvalues;		///< Number of measurements used for robust mode
-    double robustStdev;			///< robust standard deviation of data
-    double robustUQ;			///< robust upper quartile
-    double robustLQ;			///< robust lower quartile
-    double clippedMean;			///< Nsigma clipped mean
-    int    clippedMeanNvalues;		///< number of data points used for clipped mean
-    double clippedStdev;		///< standard deviation after clipping
-    double clipSigma;			///< Nsigma used for clipping; user input
-    int    clipIter;			///< Number of clipping iterations; user input
-    double min;				///< minimum data value in data
-    double max;				///< maximum data value in data
-    int    nValues;			///< number of data values in data
-    psStatsOptions options;		///< bitmask of calculated values
+    double sampleMean;                  ///< formal mean of sample
+    double sampleMedian;                ///< formal median of sample
+    double sampleStdev;                 ///< standard deviation of sample
+    double sampleUQ;                    ///< upper quartile of sample
+    double sampleLQ;                    ///< lower quartile of sample
+    double sampleLimit;                 ///< Number of datapoints to 
+    double robustMean;                  ///< robust mean of data
+    double robustMedian;                ///< robust median of data
+    double robustMode;                  ///< Robust mode of data
+    double robustStdev;                 ///< robust standard deviation of data
+    double robustUQ;                    ///< robust upper quartile
+    double robustLQ;                    ///< robust lower quartile
+    int    robustN50;                   ///< Number of points UQ-LQ
+    int    robustNfit;                  ///< Number of points in Gauss. fit
+    double clippedMean;                 ///< Nsigma clipped mean
+    double clippedStdev;                ///< standard deviation after clipping
+    int    clippedNvalues;              ///< number of data points used for clipped mean
+    double clipSigma;                   ///< Nsigma used for clipping; user input
+    int    clipIter;                    ///< Number of clipping iterations; user input
+    double min;                         ///< minimum data value in data; input range
+    double max;                         ///< maximum data value in data; input range
+    double binsize;		        ///< binsize for robust fit (input/output)
+    psStatsOptions options;             ///< bitmask of calculated values
 } psStats;
 
@@ -85,5 +80,4 @@
     const psVector *restrict bounds;	///< Bounds for the bins
     psVector *nums;			///< Number in each of the bins
-    const float minVal, maxVal;		///< Minimum and maximum values
     int minNum, maxNum;			///< Number below the minimum and above the maximum
     int uniform;			///< Is it a uniform distribution?
@@ -99,7 +93,5 @@
 /** Generic constructor \ingroup MathGroup */
 psHistogram *
-psHistogramAllocGeneric(const psVector *restrict bounds, ///< Bounds for the bins
-			float minVal,	///< Minimum value
-			float maxVal)	///< Maximum value
+psHistogramAllocGeneric(const psVector *restrict bounds) ///< Bounds for the bins
 ;
 
@@ -112,5 +104,5 @@
 /** Calculate a histogram \ingroup MathGroup **/
 psHistogram *
-psVectorHistogram(psHistogram *restrict myHist, ///< Histogram data
+psHistogramVector(psHistogram *restrict myHist, ///< Histogram data
 		  const psVector *restrict myArray) ///< Array to analyse
 ;
Index: /trunk/archive/pslib/include/psVector.h
===================================================================
--- /trunk/archive/pslib/include/psVector.h	(revision 752)
+++ /trunk/archive/pslib/include/psVector.h	(revision 753)
@@ -11,20 +11,19 @@
     psType type; 			///< vector data type and dimension
     const int n;			///< size of vector 
-    const int nalloc;			///< data region relative to parent 
+    const int nalloc;			///< allocated data block
     union {
-	psF32 *arr;			///< Pointers to floating-point data (default)
-	psS8  *arr_S8;			///< Pointers to short-integer data
-	psS16 *arr_S16;			///< Pointers to short-integer data
-	psS32 *arr_S32;			///< Pointers to integer data
-	psS64 *arr_S64;			///< Pointers to long-integer data
-	psU8  *arr_U18;			///< Pointers to unsigned-short-integer data
-	psU16 *arr_U16;			///< Pointers to unsigned-short-integer data
-	psU32 *arr_U32;			///< Pointers to unsigned-integer data
-	psU64 *arr_U64;			///< Pointers to unsigned-long-integer data
-	psF32 *arr_F32;			///< Pointers to floating-point data
-	psF64 *arr_F64;		        ///< Pointers to double-precision data
-	psF32 *arr_C32;			///< Pointers to complex floating-point data
-	void **arr_v;
-    } arr;
+	psS8  *S8;			///< Pointers to short-integer data
+	psS16 *S16;			///< Pointers to short-integer data
+	psS32 *S32;			///< Pointers to integer data
+	psS64 *S64;			///< Pointers to long-integer data
+	psU8  *U18;			///< Pointers to unsigned-short-integer data
+	psU16 *U16;			///< Pointers to unsigned-short-integer data
+	psU32 *U32;			///< Pointers to unsigned-integer data
+	psU64 *U64;			///< Pointers to unsigned-long-integer data
+	psF32 *F32;			///< Pointers to floating-point data
+	psF64 *F64;		        ///< Pointers to double-precision data
+	psF32 *C32;			///< Pointers to complex floating-point data
+	void **V;
+    } data;
 } psVector;
 
Index: /trunk/archive/pslib/src/Metadata/metadata.c
===================================================================
--- /trunk/archive/pslib/src/Metadata/metadata.c	(revision 752)
+++ /trunk/archive/pslib/src/Metadata/metadata.c	(revision 753)
@@ -47,31 +47,27 @@
  */
 psMetadataItem *psMetadataItemAlloc(
-    int typeFlags,			// type of this piece of metadata + flags
-    const void *data,			// value of new item
+    const char *name,			// name of new item of metadata (may be an sprintf format)
+    int format,				// type of this piece of metadata + flags
     const char *comment,		// comment associated with item; may be NULL
+    ...)				// data + possible arguments for name format
+{
+    va_list ap;
+    va_start(ap, comment);
+
+    psMetadataItem *mi = psMetadataItemAllocV(name, format, comment, ap);
+
+    va_end(ap);
+
+    return mi;
+}
+
+psMetadataItem *psMetadataItemAllocV(
     const char *name,			// name of new item of metadata (may be an sprintf format)
-    ...					// possible arguments for name format
-    )
-{
-    va_list ap;
-    va_start(ap, name);
-
-    psMetadataItem *mi = psVMetadataItemAlloc(typeFlags, data, comment, name, ap);
-
-    va_end(ap);
-
-    return mi;
-}
-
-psMetadataItem *psVMetadataItemAlloc(
-    int typeFlags,			// type of this piece of metadata + flags
-    const void *data,			// value of new item
+    int format,				// type of this piece of metadata + flags
     const char *comment,		// comment associated with item; may be NULL
-    const char *name,			// name of new item of metadata (may be an sprintf format)
-    va_list ap				// possible arguments for name format
-    )
-{
-    const psMetadataType type = typeFlags & PS_META_TYPE_MASK; // the type part of typeFlags
-    psMetadataFlags flags = typeFlags & ~PS_META_TYPE_MASK;    // the flags part of typeFlags
+    va_list ap)				// possible arguments for name format
+{
+    const psMetadataType type = format & PS_META_TYPE_MASK; // the type part of format
+    psMetadataFlags flags = format & ~PS_META_TYPE_MASK;    // the flags part of format
     static int id = 0;			// unique ID for an item of metadata
     psMetadataItem *ms = psAlloc(sizeof(psMetadataItem));
@@ -94,35 +90,22 @@
     ms->items = NULL;
 
-    assert (name != NULL);
-    if (strchr(name, '%') != NULL) {
-	static char tmp[201];		// should be enough; we won't overflow even if it isn't
-
-	if(vsnprintf(tmp, sizeof(tmp), name, ap) > sizeof(tmp) - 1) {
-	    psTrace("metadata.name", 1, "Keyword \"%s\" was truncated to \"%s\" upon expansion\n", name, tmp);
-	}
-
-	name = tmp;	    
-    }
-    ms->name = psStringCopy(name);
-
-    ms->comment = psStringCopy(comment == NULL ? "" : comment);
-
     assert (type >= 0 && type < PS_META_NTYPE);
     switch (type) {
       case PS_META_ITEM_SET:
-	*(void **)&ms->val.v = NULL;
+	ms->data.V = NULL;
 	ms->items = psDlistAlloc(NULL);
 	break;
 
-      case PS_META_FLOAT:
-	*(float *)&ms->val.f = *(float *)data;
-	break;
-	
-      case PS_META_INT:
-	*(int *)&ms->val.i = *(int *)data;
+      case PS_META_F32:			// psF32 promoted to psF64 through ...
+      case PS_META_F64:
+	ms->data.F64 = va_arg (ap, psF64);
+	break;
+	
+      case PS_META_S32:
+	ms->data.S32 = va_arg (ap, psS32);
 	break;
 	
       case PS_META_STR:
-	*(void **)&ms->val.v = psStringCopy(data);
+	ms->data.V = psStringCopy(va_arg(ap, char *));
 	break;
 	
@@ -132,5 +115,5 @@
       case PS_META_ASTROM:
       case PS_META_UNKNOWN:
-	*(void **)&ms->val.v = (void *)data;
+	ms->data.V = va_arg(ap, void *);
 	break;
 
@@ -139,4 +122,18 @@
 	break;				// NOTREACHED
     }
+
+    assert (name != NULL);
+    if (strchr(name, '%') != NULL) {
+	static char tmp[201];		// should be enough; we won't overflow even if it isn't
+
+	if(vsnprintf(tmp, sizeof(tmp), name, ap) > sizeof(tmp) - 1) {
+	    psTrace("metadata.name", 1, "Keyword \"%s\" was truncated to \"%s\" upon expansion\n", name, tmp);
+	}
+
+	name = tmp;	    
+    }
+    ms->name = psStringCopy(name);
+
+    ms->comment = psStringCopy(comment == NULL ? "" : comment);
 
     return ms;
@@ -159,10 +156,11 @@
 	break;
 	
-      case PS_META_FLOAT:
-      case PS_META_INT:
+      case PS_META_F32:
+      case PS_META_F64:
+      case PS_META_S32:
 	break;				// nothing to do
 	
       case PS_META_STR:
-	psFree(ms->val.v);
+	psFree(ms->data.V);
 	break;
 	
@@ -198,5 +196,5 @@
 	psMetadataItem *head = meta;
 	if (head == NULL) {		// this is the first item of this name
-	    head = psMetadataAppend(ms, PS_META_ITEM_SET, NULL, NULL, item->name);
+	    head = psMetadataAppend(ms, item->name, PS_META_ITEM_SET, NULL);
 	}	    
 
@@ -224,5 +222,5 @@
 	return item;
     } else if (meta != NULL) {
-	psError(__func__, PS_ERR_UNKNOWN, PS_NEW_ERROR,
+	psError(__func__, PS_ERR_UNKNOWN, 1,
 		"Key \"%s\" is already present in the metaDataSet 0x%x", item->name, ms);
 	psMetadataItemFree(item);
@@ -242,17 +240,13 @@
  */
 psMetadataItem *psMetadataAppend(psMetadata *restrict md, ///< Metadata to add to
-				 int typeFlags, ///< type of this piece of metadata + flags
-				 const void *val, ///< value of new item N.b. a pointer even if the item
-				                  ///< is of type e.g. int
-				 const char *comment, ///< comment associated with item
-				 const char *name, ///< name of new item of metadata (may be in sprintf
-				                   ///< format)
-				 ...		   ///< possible arguments for name format
-    )
+    const char *name,			///< name of new item of metadata
+    int format,				///< type of this piece of metadata + flags
+    const char *comment,		///< comment associated with item
+    ...)				///< possible arguments for name format
 {
     va_list ap;
-    va_start(ap, name);
-
-    psMetadataItem *mi = psVMetadataItemAlloc(typeFlags, val, comment, name, ap);
+    va_start(ap, comment);
+
+    psMetadataItem *mi = psMetadataItemAllocV(name, format, comment, ap);
 
     va_end(ap);
@@ -363,14 +357,15 @@
 	break;
 	
-      case PS_META_FLOAT:
-	fprintf(fd, "%g\n", ms->val.f);
-	break;
-	
-      case PS_META_INT:
-	fprintf(fd, "%d\n", ms->val.i);
+      case PS_META_F64:
+      case PS_META_F32:
+	fprintf(fd, "%g\n", ms->data.F32);
+	break;
+	
+      case PS_META_S32:
+	fprintf(fd, "%d\n", ms->data.S32);
 	break;
 	
       case PS_META_STR:
-	fprintf(fd, "%s\n", (char *)ms->val.v);
+	fprintf(fd, "%s\n", (char *)ms->data.V);
 	break;
 	
Index: /trunk/archive/pslib/src/Utils/Makefile
===================================================================
--- /trunk/archive/pslib/src/Utils/Makefile	(revision 752)
+++ /trunk/archive/pslib/src/Utils/Makefile	(revision 753)
@@ -2,5 +2,5 @@
 CFLAGS = -Wall -g -I$(PSLIB_DIR)/include -I$(FFTW_DIR)/include
 DYLIB = dylib
-DYLIB_LDFLAGS = "-undefined suppress -flat_namespace -dynamiclib";
+DYLIB_LDFLAGS = -undefined suppress -flat_namespace -dynamiclib -shared
 
 PSLIB_DIR = ../..
Index: /trunk/archive/pslib/src/Utils/dlist.c
===================================================================
--- /trunk/archive/pslib/src/Utils/dlist.c	(revision 752)
+++ /trunk/archive/pslib/src/Utils/dlist.c	(revision 753)
@@ -317,6 +317,5 @@
     psDlistElem *ptr = dlist->head;
     for (int i = 0, n = dlist->n; i < n; i++) {
-	arr->arr.arr_v[i] = ptr->data;
-
+	arr->data.V[i] = ptr->data;
 	ptr->data = NULL;
 	ptr = ptr->next;
@@ -339,6 +338,6 @@
     for (int i = 0, n = arr->n; i < n; i++) {
 	psDlistAppend(list,
-		      psMemDecrRefCounter(arr->arr.arr_v[i])); // it\'s already Incr
-	arr->arr.arr_v[i] = NULL;
+		      psMemDecrRefCounter(arr->data.V[i])); // it\'s already Incr
+	arr->data.V[i] = NULL;
     }
 
Index: /trunk/archive/pslib/src/Utils/error.c
===================================================================
--- /trunk/archive/pslib/src/Utils/error.c	(revision 752)
+++ /trunk/archive/pslib/src/Utils/error.c	(revision 753)
@@ -76,8 +76,8 @@
 int psError(const char *name,		// category of code that caused the error
 	    psErrorCode code,		// code of error (equivalent to errno)
-	    psErrorStatus status,	// is this a new error?
+	    int new,			// is this a new error?
 	    const char *fmt, ...)	// format and possible extra arguments
 {
-    if (code == PS_ERR_NONE || status == PS_NEW_ERROR) { // free old error stack
+    if (code == PS_ERR_NONE || new) { // free old error stack
 	errStack *eptr = errorStack;
 
@@ -99,5 +99,5 @@
 	
 	va_start(ap, fmt);
-	p_psLogVMsg(name, PS_LOG_ERROR, fmt, ap);
+	psLogMsgV(name, PS_LOG_ERROR, fmt, ap);
 	va_end(ap);
     }
@@ -210,5 +210,5 @@
     }
 
-    psErrorVStackPrint(fd, fmt, ap);
+    psErrorStackPrintV(fd, fmt, ap);
 
     if (fmt != NULL) {
@@ -217,5 +217,5 @@
 }
 
-void psErrorVStackPrint(FILE *fd,	// write to this file descriptor
+void psErrorStackPrintV(FILE *fd,	// write to this file descriptor
 			const char *fmt,// format for any header information; may be NULL
 			va_list ap)	// arguments for format
Index: /trunk/archive/pslib/src/Utils/logmsg.c
===================================================================
--- /trunk/archive/pslib/src/Utils/logmsg.c	(revision 752)
+++ /trunk/archive/pslib/src/Utils/logmsg.c	(revision 753)
@@ -110,5 +110,5 @@
 #endif
 
-void p_psLogVMsg(const char *name, int level, const char *fmt, va_list ap)
+void psLogMsgV(const char *name, int level, const char *fmt, va_list ap)
 {
     static int first = 1;
@@ -224,5 +224,5 @@
     va_start(ap, fmt);
 
-    p_psLogVMsg(name, level, fmt, ap);
+    psLogVMsg(name, level, fmt, ap);
     va_end(ap);
 }
Index: /trunk/archive/pslib/src/Utils/memory.c
===================================================================
--- /trunk/archive/pslib/src/Utils/memory.c	(revision 752)
+++ /trunk/archive/pslib/src/Utils/memory.c	(revision 753)
@@ -48,15 +48,15 @@
  * First the I-can't-get-the-memory callback
  */
-static void *memExhaustedCB0(size_t size)
+static void *memExhaustedCallback0(size_t size)
 {
     return NULL;
 }
-static psMemExhaustedCB memExhaustedCB = memExhaustedCB0;
-
-psMemExhaustedCB psMemExhaustedCBSet(psMemExhaustedCB func)
-{
-    psMemExhaustedCB old = memExhaustedCB;
-
-    memExhaustedCB = (func != NULL) ? func : memExhaustedCB0;
+static psMemExhaustedCallback memExhaustedCallback = memExhaustedCallback0;
+
+psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func)
+{
+    psMemExhaustedCallback old = memExhaustedCallback;
+
+    memExhaustedCallback = (func != NULL) ? func : memExhaustedCallback0;
 
     return old;
@@ -65,5 +65,5 @@
  * then the I-have-detected-a-problem callback
  */
-static void memProblemCB0(const psMemBlock *ptr,
+static void memProblemCallback0(const psMemBlock *ptr,
 			  const char *file, int lineno)
 {
@@ -76,9 +76,9 @@
 	fprintf(stderr, "\n");
     } else if (ptr->refCounter <= 0) {
-	psError(__func__, PS_ERR_BADFREE, PS_NEW_ERROR,
+	psError(__func__, PS_ERR_BADFREE, 1,
 		"Block %ld allocated at %s:%d freed more than once at %s:%d\n",
 		ptr->id, ptr->file, ptr->lineno, file, lineno);
     } else if (ptr->refCounter > 1) {
-	psError(__func__,  PS_ERR_BADFREE, PS_NEW_ERROR,
+	psError(__func__,  PS_ERR_BADFREE, 1,
 		"Block %ld allocated at %s:%d freed while still referenced at %s:%d\n",
 		ptr->id, ptr->file, ptr->lineno, file, lineno);
@@ -89,11 +89,11 @@
     }
 }
-static psMemProblemCB memProblemCB = memProblemCB0;
-
-psMemProblemCB psMemProblemCBSet(psMemProblemCB func)
-{
-    psMemProblemCB old = memProblemCB;
-
-    memProblemCB = (func != NULL) ? func : memProblemCB0;
+static psMemProblemCallback memProblemCallback = memProblemCallback0;
+
+psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func)
+{
+    psMemProblemCallback old = memProblemCallback;
+
+    memProblemCallback = (func != NULL) ? func : memProblemCallback0;
 
     return old;
@@ -129,5 +129,5 @@
  * isn't resignalled)
  */
-static long memAllocateCB0(const psMemBlock *ptr)
+static long memAllocateCallback0(const psMemBlock *ptr)
 {
     static int incr = 0;		// "p_psMemAllocateID += incr"
@@ -138,5 +138,5 @@
 }
 
-static long memFreeCB0(const psMemBlock *ptr)
+static long memFreeCallback0(const psMemBlock *ptr)
 {
     static int incr = 0;		// "p_psMemFreeID += incr"
@@ -150,21 +150,21 @@
  * The default callbacks, and the routines to change them
  */
-static psMemAllocateCB memAllocateCB = memAllocateCB0;
-static psMemFreeCB memFreeCB = memFreeCB0;
-
-psMemAllocateCB psMemAllocateCBSet(psMemAllocateCB func)
-{
-    psMemAllocateCB old = memAllocateCB;
-
-    memAllocateCB = (func != NULL) ? func : memAllocateCB0;
-
-    return old;
-}
-
-psMemFreeCB psMemFreeCBSet(psMemFreeCB func)
-{
-    psMemFreeCB old = memFreeCB;
-
-    memFreeCB = (func != NULL) ? func : memFreeCB0;
+static psMemAllocateCallback memAllocateCallback = memAllocateCallback0;
+static psMemFreeCallback memFreeCallback = memFreeCallback0;
+
+psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func)
+{
+    psMemAllocateCallback old = memAllocateCallback;
+
+    memAllocateCallback = (func != NULL) ? func : memAllocateCallback0;
+
+    return old;
+}
+
+psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func)
+{
+    psMemFreeCallback old = memFreeCallback;
+
+    memFreeCallback = (func != NULL) ? func : memFreeCallback0;
 
     return old;
@@ -194,5 +194,5 @@
     if (m == NULL) {
 	if (!quiet) {
-	    psError(__func__,  PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR,
+	    psError(__func__,  PS_ERR_MEMORY_CORRUPTION, 1,
 		    "psMemCheckCorruption: NULL memory block\n");
 	}
@@ -202,5 +202,5 @@
     if (!ALIGNED(m)) {
 	if (!quiet) {
-	    psError(__func__,  PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR,
+	    psError(__func__,  PS_ERR_MEMORY_CORRUPTION, 1,
 		    "psMemCheckCorruption: non-aligned memory block\n");
 	}
@@ -210,5 +210,5 @@
     if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
 	if (!quiet) {
-	    psError(__func__, PS_ERR_MEMORY_CORRUPTION, PS_NEW_ERROR,
+	    psError(__func__, PS_ERR_MEMORY_CORRUPTION, 1,
 		    "psMemCheckCorruption: memory block %ld is corrupted\n", m->id);
 	}
@@ -232,5 +232,5 @@
 		nbad++;
 
-		memProblemCB(memBlocks[i], "(psMemCheckCorruption)", 0);
+		memProblemCallback(memBlocks[i], "(psMemCheckCorruption)", 0);
 		
 		if (abort_on_error) {
@@ -251,5 +251,5 @@
 
     if (ptr == NULL) {
-	ptr = memExhaustedCB(size);
+	ptr = memExhaustedCallback(size);
 	if (ptr == NULL) {
 	    psAbort(__func__, "Failed to allocate %ld bytes at %s:%d",
@@ -270,5 +270,5 @@
     
     if (ptr->id == p_psMemAllocateID && p_psMemAllocateID > 0) {
-	p_psMemAllocateID += memAllocateCB(ptr);	
+	p_psMemAllocateID += memAllocateCallback(ptr);	
     }
     /*
@@ -310,12 +310,12 @@
      */
     if (ptr->id == p_psMemFreeID && p_psMemFreeID > 0) {
-	p_psMemFreeID += memFreeCB(ptr);	
+	p_psMemFreeID += memFreeCallback(ptr);	
     }
 
     if (bad_memblock(ptr, 0)) {
-	memProblemCB(ptr, file, lineno); // we may not own this block; don't free it
+	memProblemCallback(ptr, file, lineno); // we may not own this block; don't free it
     } else {
 	if (ptr->refCounter != 1) {
-	    memProblemCB(ptr, file, lineno);
+	    memProblemCallback(ptr, file, lineno);
 	}
 	ptr->refCounter--;
@@ -396,5 +396,5 @@
 
     if (bad_memblock(ptr, 0)) {
-	memProblemCB(ptr, "(psMemGetRefCounter)", -1);
+	memProblemCallback(ptr, "(psMemGetRefCounter)", -1);
     }
 
@@ -411,5 +411,5 @@
 
     if (bad_memblock(ptr, 0)) {
-	memProblemCB(ptr, "(psMemIncrRefCounter)", -1);
+	memProblemCallback(ptr, "(psMemIncrRefCounter)", -1);
     }
 
@@ -428,5 +428,5 @@
 
     if (bad_memblock(ptr, 0)) {
-	memProblemCB(ptr, "(psMemDecrRefCounter)", -1);
+	memProblemCallback(ptr, "(psMemDecrRefCounter)", -1);
     }
 
Index: /trunk/archive/pslib/src/Utils/misc.c
===================================================================
--- /trunk/archive/pslib/src/Utils/misc.c	(revision 752)
+++ /trunk/archive/pslib/src/Utils/misc.c	(revision 753)
@@ -29,5 +29,5 @@
 
     va_start(ap, fmt);
-    p_psLogVMsg(name, PS_LOG_ABORT, fmt, ap);
+    psLogMsgV(name, PS_LOG_ABORT, fmt, ap);
     va_end(ap);
     
Index: /trunk/archive/pslib/src/Utils/vector.c
===================================================================
--- /trunk/archive/pslib/src/Utils/vector.c	(revision 752)
+++ /trunk/archive/pslib/src/Utils/vector.c	(revision 753)
@@ -16,5 +16,5 @@
 
    *(int *)&vec->n = *(int *)&vec->nalloc = nalloc;
-   vec->arr.arr_v = psAlloc(nalloc*sizeof(void **));
+   vec->data.V = psAlloc(nalloc*sizeof(void **));
 
    return vec;
@@ -34,12 +34,12 @@
 
    if (elemFree != NULL && vec->nalloc > 0) {
-      assert (vec->arr.arr != NULL);	/* choose any member of the union */
+      assert (vec->data.V != NULL);	/* choose any member of the union */
       const int n = vec->nalloc;
       for (int i = 0; i < n; i++) {
-	 elemFree(vec->arr.arr_v[i]);
+	 elemFree(vec->data.V[i]);
       }
    }
 
-   psFree(vec->arr.arr_v);
+   psFree(vec->data.V);
    psFree(vec);
 }
