Index: /trunk/archive/pslib/include/psAstrom.h
===================================================================
--- /trunk/archive/pslib/include/psAstrom.h	(revision 149)
+++ /trunk/archive/pslib/include/psAstrom.h	(revision 149)
@@ -0,0 +1,218 @@
+#if !defined(PS_ASTROM_H)
+#define PS_ASTROM_H
+
+/* Include array declaration macros */
+#include "psArray.h"
+/* Include standard array definitions */
+#include "psStdArrays.h"
+/* Include position definitions */
+#include "psPosition.h"
+/* Include colour definitions */
+#include "psColour.h"
+
+
+/***********************************************************************************************************/
+
+/* Astrometric coefficients */
+typedef struct {
+    int xyOrder;		        // Spatial (x,y) order of polynomial
+    int colourOrder;		        // Order of polynomial in colour
+    int magOrder;		        // Order of polynomial in magnitude
+    int xyColourOrder;		        // Spatial (x,y) order of polynomial in colour times x and y
+    int xyMagOrder;		        // Spatial (x,y) order of polynomial in magnitude times x and y
+    enum psColourRef colourRef;	        // Colour reference
+    psDoubleArray *restrict coeff;	// Coefficients of astrometric solution
+    psDoubleArray *restrict coeffErr;	// Error in coefficients
+} psAstromCoeffs;
+
+/* Constructor */
+psAstromCoeffs *
+psAstromCoeffsNew(int xyOrder,		// Spatial (x,y) order of polynomial
+		  int colourOrder,	// Order of polynomial in colour
+		  int magOrder,		// Order of polynomial in magnitude
+		  int xyColourOrder,	// Spatial (x,y) order of polynomial in colour times x and y
+		  int xyMagOrder,	// Spatial (x,y) order of polynomial in magnitude times x and y
+		  enum psColourRef colourRef // Colour reference
+    );
+
+/* Destructor */
+void
+psAstromCoeffsDel(psAstromCoeffs *restrict myAstromCoeffs // Object to destroy
+    );
+
+/***********************************************************************************************************/
+
+/* Telescope pointing information for an exposure */
+typedef struct {
+    // Telescope longitude, latitude and height are stored separately, since they don't change with pointing
+    double ra, dec;			// Telescope boresight
+    double ha;				// Hour angle
+    double zd;				// Zenith distance
+    double az;				// Azimuth
+    float rotAngle;			// Rotator position angle
+    float temp;				// Temperature
+    float pressure;			// Pressure
+    /* Derived quantities */
+    float parallactic;			// Parallactic angle
+    float airmass;	                // Airmass, calculated from zenith distance
+} psTelPointing;
+
+/* Constructor */
+psTelPointing *
+psTelPointingNew(double ra, double dec,	// Telescope boresight
+		 double ha,		// Hour angle
+		 double zd,		// Zenith distance
+		 double az,		// Azimuth
+		 float rotAngle,	// Rotator position angle
+		 float temp,		// Temperature
+		 float pressure		// Pressure
+    );
+
+/* Destructor */
+void
+psTelPointingDel(psTelPointing *restrict myTelPointing // Object to destroy
+    );
+
+
+/***********************************************************************************************************/
+
+/* Cell details: specifies how the cell is mounted on its parent OTA   */
+typedef struct {
+    psOTAPos position;			// Position of cell in its OTA.  Specifies the position of the
+					// (imaginary) pixel (0,0)
+    float rotation;			// Rotation of cell in its OTA.  Specified from +x through +y
+    int xSize, ySize;			// Number of pixels in x and y
+    float scale;			// Relative pixel scales, if CCD pitch varies. Specify a positive
+					// scale for a left-handed coordinate system, negative for right. If
+					// NULL, then every chip has identical scale, and system is
+					// left-handed.
+} psCellDescription;
+
+/* Constructor */
+psCellDescription *
+psCellDescriptionNew(void);
+
+/* Destructor */
+void
+psCellDescriptionDel(psCellDescription *restrict myCell // Cell description to destroy
+    );
+
+/***********************************************************************************************************/
+
+/* Array of cell descriptions */
+PS_DECLARE_ARRAY_TYPE(psCellDescription);
+PS_CREATE_ARRAY_TYPE(psCellDescription);
+
+/***********************************************************************************************************/
+
+/* OTA details: specifies how the OTA is mounted on the focal plane */
+typedef struct {
+    psOTAPos position;			// Position of OTA on the focal plane.  Specifies the position of the
+					// bottom left-hand corner.
+    float rotation;			// Rotation of OTA on the focal plane.  Specified from +x through +y
+    psCellDescriptionArray *restrict cells; // Cell descriptions
+    psOTAAstrom *astrom;		// OTA astrometry
+} psOTADescription;
+
+/* Constructor */
+psOTADescription *
+psOTADescriptionNew(void);
+
+/* Destructor */
+void
+psOTADescriptionDel(psOTADescription *restrict myOTA // OTA description to destroy
+    );
+
+/***********************************************************************************************************/
+
+/* Astrometric solution for an OTA */
+/* There are four coordinate frames that we need to worry about:
+ * 1. Chip frame: chip# plus x,y in pixels
+ * 2. Focal plane frame: X,Y in microns
+ * 3. Tangent plane: xi,eta in arcsec from the telescope boresight.
+ * 4. Sky frame: RA,Dec
+ *
+ * 1 <--> 2: OTA description (parent of this struct) specifies how the chips are mounted on the focal plane.
+ * 2 <--> 3: The astrometric solution corrects for distortions in the optics so we can go from what the
+ * telescope sees on the focal plane to what it really should be like (i.e. the tangent plane).
+ * 3 <--> 4: SLALib converts between the tangent plane and the celestial sphere using a set of numbers one
+ * must calculate for each tangent point.
+ *
+ * Coordinate frames 2 and 3 are hidden from the user because all they care about is going between frames 1
+ * and 4.
+ */
+typedef struct {
+    /* Focal plane to and from tangent plane */
+    psAstromCoeffs *restrict tpToFP;	// General astrometric solution for tangent plane to focal plane
+    psAstromCoeffs *restrict fpToTP;	// General astrometric solution for focal plane to tangent plane
+    psMatrix *pattern;		        // Fixed pattern distortions for focal plane to tangent plane (simply
+					// * -1 for the reverse); MAY NEED TO BE REVISED UPON IMPLEMENTATION
+    /* Tangent plane to and from the celestial sphere */
+    psDoubleArray *restrict tp;		// Data needed to convert from the sky to the tangent plane and back;
+					// produced by and used by SLALib (a.k.a. "Wallace's Grommit")
+    /* Characterisation of the solution */
+    float rmsX, rmsY;		        // Dispersion in astrometric solution
+    float chi2;				// chi^2 of astrometric solution
+} psOTAAstrom;
+
+/* Constructor */
+psAstrom *
+psAstromNew(const psTelPointing *telescope	// Telescope pointing, used to initialise the tp data.
+    );
+
+/* Destructor */
+void
+psAstromDel(psAstrom *restrict myAstrom	// Object to destroy
+    );
+
+/***********************************************************************************************************/
+
+/* Calculating and applying astrometric solutions */
+
+/* Convert (RA,Dec) to (cell#,x,y) */
+psOTAPos *
+psSkyToOTA(const psSkyPos *restrict position, // Position on the sky
+	   const psOTADescription *restrict ota // OTA details
+    );
+
+/* Convert (cell#,x,y) to (RA,Dec) */
+psSkyPos *
+psOTAToSky(const psOTAPos *restrict position, // Position on the detector
+	   const psOTADescription *restrict ota // OTA details
+    );
+
+/* Fit astrometric solution to list of (chip#,x,y) and (RA,Dec) */
+int
+psFitAstrom(psOTADescription *restrict ota, // psAstrom struct containing initial guess for coefficients
+	    const psOTAPosArray *restrict detector, // Positions on OTA (chip#,x,y)
+	    const psSkyPosArray *restrict sky, // Positions on the sky (RA,Dec)
+	    const psTelPointing *telescope // Telescope pointing information, for airmass, parallactic angle
+					   // which may help set the astrometric solution
+	    );
+
+/***********************************************************************************************************/
+
+/* Functions needed for astrometry, and will likely be useful elsewhere */
+
+/* Get the airmass for a given position and sidereal time */
+float
+psGetAirmass(const psSkyPos *restrict position, // Position on the sky
+	     float siderealTime	// Sidereal time
+	     );
+
+/* Get the parallactic angle for a given position and sidereal time */
+float
+psGetParallactic(const psSkyPos *restrict position, // Position on the sky
+		 real siderealTime	// Sidereal time
+		 );
+
+/* Estimate atmospheric refraction, along the parallactic */
+float
+psGetRefraction(float colour,		// Colour of object
+		enum psColourRef colourRef; // Colour reference
+		psTelPointing telescope	// Telescope pointing information, for airmass, temp and pressure
+    );
+
+/***********************************************************************************************************/
+
+#endif
Index: /trunk/archive/pslib/include/psBitMask.h
===================================================================
--- /trunk/archive/pslib/include/psBitMask.h	(revision 149)
+++ /trunk/archive/pslib/include/psBitMask.h	(revision 149)
@@ -0,0 +1,37 @@
+#if !defined (PS_BIT_MASK_H)
+#define PS_BIT_MASK_H
+
+/* Type for a big bitmask */
+/* Set to long int for now */
+typedef long int psBitMask;
+
+
+/* Set a bit mask */
+psBitMask *
+psSetBitMask(psBitMask *outMask,	// Output bit mask or NULL
+	     const psBitMask *myMask,	// Input bit mask
+	     int bit			// Bit to set
+    );
+
+/* Check a bit mask.  Returns true or false */
+int
+psCheckBitMask(const psBitMask *checkMask, // Bit mask to check
+	       int bit			// Bit to check
+    );
+
+/* OR two bit masks */
+psBitMask *
+psOrBitMasks(psBitMask *outMask,	// Output bit mask or NULL
+	     const psBitMask *restrict inMask1,	// Input bit mask 1
+	     const psBitMask *restrict inMask2 // Input bit mask 2
+    );
+
+/* AND two bit masks */
+psBitMask *
+psAndBitMasks(psBitMask *outMask,	// Output bit mask or NULL
+	     const psBitMask *restrict inMask1,	// Input bit mask 1
+	     const psBitMask *restrict inMask2 // Input bit mask 2
+    );
+
+
+#endif
Index: /trunk/archive/pslib/include/psColour.h
===================================================================
--- /trunk/archive/pslib/include/psColour.h	(revision 149)
+++ /trunk/archive/pslib/include/psColour.h	(revision 149)
@@ -0,0 +1,21 @@
+#if !defined(PS_COLOUR_H)
+#define PS_COLOUR_H
+
+/* Colour References */
+
+/*
+ * Reference colours are roughly appropriate for a G5V star.  I get, with an arbitrary zero point, on the AB
+ * system the following rough magnitudes: g = 1.36 mag, r = 0.84 mag, i = 0.72 mag, z = 0.69 mag, y = 0.69
+ * mag, w = 0.80 mag
+ */
+enum {
+    PS_COLOUR_NO_INFO,			// No colour information
+    PS_COLOUR_G_MINUS_R,		// Reference is g-r = 0.5 mag
+    PS_COLOUR_R_MINUS_I,		// Reference is r-i = 0.1 mag
+    PS_COLOUR_I_MINUS_Z,		// Reference is i-z = 0.0 mag
+    PS_COLOUR_Z_MINUS_Y,		// Reference is z-y = 0.0 mag
+    PS_COLOUR_R_MINUS_W			// Reference is r-w = 0.0 mag
+} psColourRef;
+
+
+#endif
Index: /trunk/archive/pslib/include/psComplexArrays.h
===================================================================
--- /trunk/archive/pslib/include/psComplexArrays.h	(revision 149)
+++ /trunk/archive/pslib/include/psComplexArrays.h	(revision 149)
@@ -0,0 +1,37 @@
+#if !defined(PS_COMPLEX_ARRAYS_H)
+#define PS_COMPLEX_ARRAYS_H
+
+#include "psStdArrays.h"
+
+/* Complex number arrays */
+
+/* Multiplication of two complex number arrays */
+/* Purposely leave these NOT restrict-ed, so that the multiplication may be done in-place */
+psComplexArray *
+psComplexMultiply(psComplexArray *out, // Output array to be returned; may be NULL
+		  const psComplexArray *complex1, // Input complex array 1
+		  const psComplexArray *complex2 // Input complex array 2
+		  );
+
+/* Division of two complex number arrays */
+/* Purposely leave these NOT restrict-ed, so that the division may be done in-place */
+psComplexArray *
+psComplexDivide(psComplexArray *out,	// Output array to be returned; may be NULL
+		const psComplexArray *complex1, // Input complex array 1
+		const psComplexArray *complex2 // Input complex array 2
+		);
+
+/* Complex conjugates for a complex number array */
+/* Purposely leave these NOT restrict-ed, so that the operation may be done in-place */
+psComplexArray *
+psComplexConjugate(psComplexArray *out,	// Output array to be returned; may be NULL
+		   const psComplexArray *myComplexNumbers // Input complex number array
+		   );
+
+/* Moduli for a complex number array */
+psFloatArray *
+psComplexModulus(const psComplex *restrict myComplexNumbers // Input complex number array
+		 );
+
+
+#endif
Index: /trunk/archive/pslib/include/psDataAPIs.h
===================================================================
--- /trunk/archive/pslib/include/psDataAPIs.h	(revision 149)
+++ /trunk/archive/pslib/include/psDataAPIs.h	(revision 149)
@@ -0,0 +1,25 @@
+#if !defined(PS_STATS_H)
+#define PS_STATS_H
+
+/* Include standard arrays */
+#include "psStdArrays.h"
+
+/***********************************************************************************************************/
+
+/* Do Statistics on an array.  Returns a status value. */
+int
+psArrayStats(const psFloatArray *restrict myArray, // Array to be analysed
+	     const psIntArray *restrict maskArray, // Ignore elements where (maskArray & maskVal) != 0
+						   // May be NULL
+	     unsigned int maskVal,	// Only mask elements with one of these bits set in maskArray
+	     int numIter,	        // Number of clipping iterations (0 not to clip)
+	     float numSD,		// Number of s.d. to clip at
+	     float *restrict mean,	// Mean of array (or NULL)
+	     float *restrict sd,	// Standard deviation (or NULL)
+	     float *restrict med	// Median (or NULL)
+	     );
+
+/***********************************************************************************************************/
+
+
+#endif
Index: /trunk/archive/pslib/include/psDateTime.h
===================================================================
--- /trunk/archive/pslib/include/psDateTime.h	(revision 149)
+++ /trunk/archive/pslib/include/psDateTime.h	(revision 149)
@@ -0,0 +1,21 @@
+#if !defined(PS_DATE_TIME_H)
+#define PS_DATE_TIME_H
+
+/* Dates and Times */
+
+/* Get current MJD, for a timestamp */
+float
+psGetMJD(void);
+
+/* Convert MJD to Human-readable date/time string */
+char *
+psMJDToTime(float mjd			// Input MJD
+	    );
+
+/* Get Sidereal time */
+float
+psGetSidereal(float mjd,		// MJD
+	      float longitude		// Longitude
+	      );
+
+#endif
Index: /trunk/archive/pslib/include/psFFT.h
===================================================================
--- /trunk/archive/pslib/include/psFFT.h	(revision 149)
+++ /trunk/archive/pslib/include/psFFT.h	(revision 149)
@@ -0,0 +1,29 @@
+#if !defined(PS_FFT_H)
+#define PS_FFT_H
+
+#include "psStdArrays.h"
+
+/* Fourier Transform functions */
+
+/* Return Fourier Transform of an array */
+psComplexArray *
+psRealFFT(psComplexArray *restrict out,	// Output array to be returned; may be NULL
+	  const psFloatArray *restrict myArray // Input array
+	  );
+
+/* Return [inverse?] Fourier Transform of a complex array */
+/* May NOT be done in-place (restrict-ed) */
+psComplexArray *
+psComplexFFT(psComplexArray *restrict out, // Output array to be returned; may be NULL
+	     const psComplexArray *restrict myArray, // Input array
+	     int sign			// +1 or -1 to indicate direction of FT
+	     );
+
+/* Return Power spectrum of a array */
+psFloatArray *
+psPowerSpec(psFloatArray *restrict out,	// Output array to be returned
+	    const psFloatArray *restrict myArray // Input array
+	    );
+
+
+#endif
Index: /trunk/archive/pslib/include/psFilter.h
===================================================================
--- /trunk/archive/pslib/include/psFilter.h	(revision 149)
+++ /trunk/archive/pslib/include/psFilter.h	(revision 149)
@@ -0,0 +1,13 @@
+#if !defined(PS_FILTER_H)
+#define PS_FILTER_H
+
+enum {
+    PS_FILTER_G,			// g band
+    PS_FILTER_R,			// r band
+    PS_FILTER_I,			// i band
+    PS_FILTER_Z,			// z band
+    PS_FILTER_Y,			// y band
+    PS_FILTER_W				// w band
+} psFilter;
+
+#endif
Index: /trunk/archive/pslib/include/psFunctions.h
===================================================================
--- /trunk/archive/pslib/include/psFunctions.h	(revision 149)
+++ /trunk/archive/pslib/include/psFunctions.h	(revision 149)
@@ -0,0 +1,31 @@
+#if !defined(PS_FUNCTIONS_H)
+#define PS_FUNCTIONS_H
+
+#include "psStdArrays.h"
+
+/* Standard Functions */
+
+/* Gaussian */
+/* Note that this is not a Gaussian deviate */
+float
+psGaussian(float x,			// Value at which to evaluate
+	   float mean,			// Mean for the Gaussian
+	   float stddev			// Standard deviation for the Gaussian
+	   );
+
+/* Polynomial: one dimension */
+float
+psPolynomial1d(float x,			// Value at which to evaluate
+	       const psFloatArray *restrict coeffs // Coefficients for the polynomial
+	       );
+
+/* Polynomial: two dimensions */
+float
+psPolynomial2d(float x,			// Value x at which to evaluate
+	       float y,			// Value y at which to evaluate
+	       int orderx,		// Polynomial order in x
+	       int ordery,		// Polynomial order in y
+	       const psFloatArray *coeffs // Coefficients for the polynomial
+	       );
+
+#endif
Index: /trunk/archive/pslib/include/psMatrix.h
===================================================================
--- /trunk/archive/pslib/include/psMatrix.h	(revision 149)
+++ /trunk/archive/pslib/include/psMatrix.h	(revision 149)
@@ -0,0 +1,46 @@
+#if !defined(PS_MATRIX_H)
+#define PS_MATRIX_H
+
+/* A matrix */
+typedef struct {
+    int xSize, ySize;			// Dimensions in x and y
+    float *restrict *restrict value;	// Values in matrix
+} psMatrix;
+
+/* Constructor */
+psMatrix *
+psMatrixNew(int Xdimen,			// x dimension of new matrix
+	    int Ydimen			// y dimension of new matrix
+	    );
+
+/* Destructor */
+void
+psMatrixDel(psMatrix *restrict myMatrix	// Matrix to destroy
+	    );
+
+/***********************************************************************************************************/
+
+/* Linear Algebra */
+
+/* Invert matrix */
+/* Not using restrict, to allow inversion to be done in-place */
+psMatrix *
+psInvertMatrix(psMatrix *out,		// Matrix to return, or NULL
+	       const psMatrix *myMatrix, // Matrix to be inverted
+	       float *restrict determinant // Determinant to return, or NULL
+	       );
+
+/* Matrix determinant */
+float
+psDeterminant(const psMatrix *restrict myMatrix // Matrix to get determinant for
+	      );
+
+/* Matrix Multiplication */
+/* Not using restrict, to allow matrix1 == matrix2, and to do multiplication in-place */
+psMatrix
+psMatrixMultiply(psMatrix *out,		// Matrix to return, or NULL
+		 const psMatrix *matrix1, // Matrix 1
+		 const psMatrix *matrix2 // Matrix 2
+		 );
+
+#endif
Index: /trunk/archive/pslib/include/psMinimise.h
===================================================================
--- /trunk/archive/pslib/include/psMinimise.h	(revision 149)
+++ /trunk/archive/pslib/include/psMinimise.h	(revision 149)
@@ -0,0 +1,34 @@
+#if !defined(PS_MINIMISE_H)
+#define PS_MINIMISE_H
+
+#include "psStdArrays.h"
+
+
+/* Minimisation */
+
+/* Minimise a particular function */
+psFloatArray *
+psMinimise(float (*myFunction)(const psFloatArray *restrict),	// Function to minimise
+	   psFloatArray *restrict initialGuess // Initial guess
+	   );
+
+
+/* Minimise chi^2 for input data */
+psFloatArray *
+psMinimiseChi2(float (*evalModel)(const psFloatArray *restrict,
+				  const psFloatArray *restrict), // Model to fit; receives domain and
+								   // parameters
+	       const psFloatArray *restrict domain, // The domain values for the corresponding measurements
+	       const psFloatArray *restrict data, // Data to fit
+	       const psFloatArray *restrict errors, // Errors in the data
+	       psFloatArray *restrict initialGuess, // Initial guess
+	       const psIntArray *restrict guessMask // 1 = fit for parameter, 0 = hold parameter constant
+	       );
+
+/* Derive a polynomial that goes through the points --- can be done analytically */
+psFloatArray *
+psGetArrayPolynomial(const psFloatArray *restrict ord, // Ordinates (or NULL to just use the indices)
+		     const psFloatArray *restrict coord // Coordinates
+    );
+
+#endif
Index: /trunk/archive/pslib/include/psObjects.h
===================================================================
--- /trunk/archive/pslib/include/psObjects.h	(revision 149)
+++ /trunk/archive/pslib/include/psObjects.h	(revision 149)
@@ -0,0 +1,174 @@
+#if !defined(PS_OBJECTS_H)
+#define PS_OBJECTS_H
+
+/* Include array declaration macros */
+#include "psArray.h"
+/* Standard array definitions */
+#include "psStdArrays.h"
+/* Positions */
+#include "psPosition.h"
+/* Colour definitions */
+#include "psColour.h"
+/* Astrometry */
+#include "psAstrom.h"
+/* Bit masks */
+#include "psBitMask.h"
+/* Image definitions */
+#include "psImages.h"
+
+
+/***********************************************************************************************************/
+
+/* Object definition, to handle both objects we detect, and catalogues */
+typedef struct {
+    psOTAPos *otaPos;			// Centre position on OTA, with associated error
+    psSkyPos *skyPos;			// Position on the sky, with associated error
+    float mag, magErr;			// Magnitude and associated error
+    float isoMag, isoMagErr;		// Isophotal magnitude and associated error
+    float fwhm, fwhmErr;		// FWHM and associated error
+    float ellipA, ellipB;		// Elliptical semi-major (A) and semi-minor (B) axes
+    float ellipAngle;			// Ellipse position angle
+    float sky, skyErr;			// Local sky level, and associated error
+    float colour, colourErr;		// Colour and associated error, if known
+    enum psColourRef colourRef;		// Colour reference
+    psBitMask *quality;			// Bit mask for quality information
+} psObject;
+
+/* Constructor */
+psObject *
+psObjectNew(void);
+
+/* Destructor */
+void
+psObjectDel(psObject *restrict myObject);
+
+/***********************************************************************************************************/
+
+/* An assembly of objects */
+PS_DECLARE_ARRAY_TYPE(psObject);
+PS_CREATE_ARRAY_TYPE(psObject);
+
+/***********************************************************************************************************/
+
+/* Associates objects on an image with the image */
+typedef struct {
+    const psImage *image;		// Image that produced the objects, which has metadata we need
+    psObjectArray *objects;		// The objects
+} psImageObjects;
+
+/* Constructor */
+psImageObjects *
+psImageObjectsNew(const psImage *image,	// Image that produced the objects, which has metadata we need
+		  psObjectArray *objects // The objects
+		  );
+
+/* Destructor */
+void
+psImageObjectsDel(psImageObjects *restrict myImageObjects // Object to destroy
+		  );
+
+/***********************************************************************************************************/
+
+/* Objects from a catalogue */
+typedef struct {
+    enum psCatalogue catalogue;		// Source catalogue from which objects come
+    psObjectArray *object;		// The objects
+} psCatalogueObjects;
+
+/* Constructor */
+psCatalogueObjects *
+psCatalogueObjectsNew(enum psCatalogue *catalogue, // Source catalogue
+		      psObjectArray *objects // The objects
+		      );
+
+/* Destructor */
+void
+psCatalogueObjectsDel(psCatalogeObjects *restrict myCatalogueObjects // Object to destroy
+		      );
+
+/***********************************************************************************************************/
+
+/* A "super" object --- an object with multiple detections in different images */
+typedef struct {
+    const psImageArray *images;		// Images that provided the different measurements
+    const psObjectArray *objects;	// Individual object measurements
+
+    /* Derived quantities */
+    psSkyPos *meanSkyPos;		// Mean position on the sky
+    double pmRA, pmDec;			// Proper motion in RA and Dec
+    double pmRAErr, pmDecErr;		// Errors in proper motion
+    float posChi2;			// chi^2 for position
+} psSuperObject;
+
+/* Constructor */
+psSuperObject *
+psSuperObjectNew(const psImageArray *images, // The images with the measurements
+		 const psObjectArray *objects // Object measurements
+		 );
+
+/* Destructor */
+void
+psSuperObjectDel(psSuperObject *restrict mySuperObject // Object to destroy
+		 );
+
+
+/***********************************************************************************************************/
+
+/* Correlation */
+
+
+/* Correlate two OTA object arrays */
+/*
+ * Returns an array with the indices of the object in the second bunch that matched the corresponding object
+ * in the first bunch, or -1 if none that match.
+ */
+psIntArray *
+psCorrelateObjects(const psObjectArray *restrict myObjects1, // First bunch of objects
+		   const psObjectArray *restrict myObjects2, // Second bunch of objects
+		   const psOTADescription *myOTA1, // OTA description for first bunch of objects, or NULL for
+						   // sky
+		   const psOTADescription *myOTA2 // OTA description for second bunch of objects, or NULL for
+						  // sky
+		   );
+
+
+/* Get matched lists from a correlated index array */
+/* Returns a status number, and matched1 and matched2 are manipulated to contain matches */
+int
+psGetCorrelatedMatches(const psIntArray matches, // Index array specifying matches */
+		       const psObjectArray *restrict myObjects1, // First bunch of objects
+		       const psObjectArray *restrict myObjects2, // Second bunch of objects
+		       psObjectArray *matched1, // Matched objects in first bunch
+		       psObjectArray *matched2 // Matched objects in second bunch
+		       );
+
+/***********************************************************************************************************/
+
+/* Object selection */
+
+/* Get objects within a particular magnitude range */
+psObjectArray *
+psSelectObjectMag(psObjectArray *restrict myArray, // Bunch of objects to select from
+		  float magLower,	// Lower bound for magnitude
+		  float magUpper	// Upper bound for magnitude
+		  );
+
+/* Get objects within a radius on the sky */
+psObjectArray *
+psSelectObjectSkyDist(psObjectArray *restrict myArray, // Bunch of objects to select from
+		      psSkyPos *skyPos,	// Position on the sky
+		      float radius,	// Radius of search
+		      int circleOrSquare // Circle = 1, Square = 2
+		      );
+
+/* Get objects within a particular colour range */
+psObjectArray *
+psSelectObjectColour(psObjectArray *restrict myArray, // Bunch of objects to select from
+		     float magLower,	// Lower bound for colour
+		     float magUpper,	// Upper bound for colour
+		     enum psColourRef colourRef	// Only select those with this colour reference
+		     );
+
+
+#endif
+
Index: /trunk/archive/pslib/include/psPosition.h
===================================================================
--- /trunk/archive/pslib/include/psPosition.h	(revision 149)
+++ /trunk/archive/pslib/include/psPosition.h	(revision 149)
@@ -0,0 +1,187 @@
+#if !defined(PS_POSITION_H)
+#define PS_POSITION_H
+
+/* Include array declaration macros */
+#include "psArray.h"
+
+/***********************************************************************************************************/
+
+/* Magic values for errors */
+enum {
+    PS_NO_VALUE = -111.0,		// Corresponding value not yet measured
+    PS_NO_ERROR = -222.0		// Corresponding value has no error
+};
+
+/***********************************************************************************************************/
+
+/* Planets */
+enum {
+    PS_MERCURY = 1,
+    PS_VENUS = 2,
+    PS_MARS = 4,
+    PS_JUPITER = 5,
+    PS_SATURN = 6,
+    PS_URANUS = 7,
+    PS_NEPTUNE = 8,
+    PS_PLUTO = 9
+} psPlanetNum;
+
+/* Catalogues */
+enum {
+    PS_PANSTARRS,			// Pan-STARRS object catalogue
+    PS_USNO,				// USNO-B1 catalogue
+    PS_2MASS,				// 2MASS catalogue
+    PS_TYCHO,				// Tycho catalogue
+    UCAC2 = 4				// UCAC2 catalogue
+} psCatalogue;
+
+/***********************************************************************************************************/
+
+/* A position on a detector */
+typedef struct {
+    int chip;				// Chip number
+    float x;				// x position
+    float xErr;				// Error in x position
+    float y;				// y position
+    float yErr;				// Error in y position
+} psOTAPos;
+
+/* Constructor */
+psOTAPos *
+psOTAPosNew(void);
+
+/* Destructor */
+void
+psOTAPosDel(psOTAPos *restrict myOTAPos	// Object to destroy
+    );
+
+/***********************************************************************************************************/
+
+/* An array of detector positions */
+PS_DECLARE_ARRAY_TYPE(psOTAPos);
+PS_CREATE_ARRAY_TYPE(psOTAPos);
+
+/***********************************************************************************************************/
+
+/* A simple RA/Dec position on the sky, default system is ICRS. */
+/* Double precision needed for milli-arcsec */
+typedef struct {
+    double ra;				// Right Ascension
+    double raErr;			// Error in RA
+    double dec;				// Declination
+    double decErr;			// Error in Dec
+} psSkyPos;
+
+/* Constructor */
+psSkyPos *
+psSkyPosNew(void);
+
+/* Destructor */
+void
+psSkyPosDel(psSkyPos *restrict mySkyPos	// Object to destroy
+    );
+
+/***********************************************************************************************************/
+
+/* An array of sky positions */
+PS_DECLARE_ARRAY_TYPE(psSkyPos);
+PS_CREATE_ARRAY_TYPE(psSkyPos);
+
+/***********************************************************************************************************/
+
+/* Latitude and Longitude. */
+/* Double precision needed for milli-arcsec */
+typedef struct {
+    double lat;				// Latitude
+    double latErr;			// Error in Latitude
+    double lng;			        // Longitude (can't use "long")
+    double lngErr;			// Error in Longitude
+} psLatLong;
+
+/* Constructor */
+psLatLong *
+psLatLongNew(void);
+
+/* Destructor */
+void
+psLatLongDel(psLatLong *restrict myLatLong // Object to destroy
+    );
+
+/***********************************************************************************************************/
+
+/* Offsets */
+
+/* Get offset (RA,Dec) on the sky between two positions */
+/* position1 and position2 may not be identical */
+psSkyPos *
+psGetOffset(const psSkyPos *restrict position1, // Position 1
+	    const psSkyPos *restrict position2 // Position 2
+	    );
+
+/* Apply an offset to a position */
+psSkyPos *
+psApplyOffset(const psSkyPos *restrict position, // Position
+	      const psSkyPos *restrict offset // Offset
+	      );
+
+/***********************************************************************************************************/
+
+/* Positions of well-known objects */
+
+/* Get Sun Position */
+psSkyPos *
+psGetSunPos(float mjd			// MJD to get position for
+	    );
+
+/* Get Moon position */
+psSkyPos *
+psGetMoonPos(float mjd,			// MJD to get position for
+	     double latitude,		// Latitude for apparent position
+	     double longitude		// Longitude for apparent position
+	     );
+
+/* Get Moon phase */
+float
+psGetMoonPhase(float mjd		// MJD to get phase for
+	       );
+
+/* Get Planet positions */
+psSkyPos *
+psGetPlanetPos(enum psPlanetNum myPlanetNum, // Number for planet
+	       float mjd		// MJD to get position for
+	       );
+
+/* Get star list from catalogue */
+psObjectArray *
+psReadStarCatalogue(double ra,		// RA of centre of search
+		    double dec,		// Declination of centre of search
+		    float radius,	// Radius of search for stars in catalogue
+		    float mjd,		// The epoch (in MJD) for which to get positions
+		    enum psCatalogue myCatalogue // The catalogue to use
+    );
+
+/***********************************************************************************************************/
+
+/* Celestial coordinate conversions */
+
+/* Convert ICRS to Ecliptic */
+psLatLong *
+psCoordinatesItoE(const psSkyPos *restrict coordinates // ICRS coordinates to convert
+		  );
+
+/* Convert Ecliptic to ICRS */
+psSkyPos *
+psCoordinatesEtoI(const psLatLong *restrict coordinates // Ecliptic coordinates to convert
+		  );
+
+/* Convert ICRS to Galactic */
+psLatLong *
+psCoordinatesItoG(const psSkyPos *restrict coordinates // ICRS coordinates to convert
+		  );
+
+/* Convert Galactic to ICRS */
+psSkyPos *
+psCoordinatesGtoI(const psLatLong *restrict coordinates // Galactic coordinates to convert
+		  );
+
+/***********************************************************************************************************/
Index: /trunk/archive/pslib/include/psSort.h
===================================================================
--- /trunk/archive/pslib/include/psSort.h	(revision 149)
+++ /trunk/archive/pslib/include/psSort.h	(revision 149)
@@ -0,0 +1,22 @@
+#if !defined(PS_SORT_H)
+#define PS_SORT_H
+
+#include "psStdArrays.h"
+
+/* Sorting */
+
+/* Sort an array */
+/* Inputs not restrict-ed to allow sort in place */
+psFloatArray *
+psSort(psFloatArray *out,		// Sorted array to return. May be NULL
+       const psFloatArray *myArray	// Array to sort
+       );
+
+/* Sort an array, along with some other stuff */
+/* Returns an index array */
+psIntArray *
+psCoSort(psIntArray *restrict out;	// Output index array (may be NULL)
+	 const psFloatArray *restrict myArray // Array to sort
+	 );
+
+#endif
Index: /trunk/archive/pslib/include/psStats.h
===================================================================
--- /trunk/archive/pslib/include/psStats.h	(revision 149)
+++ /trunk/archive/pslib/include/psStats.h	(revision 149)
@@ -0,0 +1,59 @@
+#if !defined(PS_STATS_H)
+#define PS_STATS_H
+
+/* Include standard arrays */
+#include "psStdArrays.h"
+
+/* Do Statistics on an array.  Returns a status value. */
+int
+psArrayStats(const psFloatArray *restrict myArray, // Array to be analysed
+	     const psIntArray *restrict maskArray, // Ignore elements where (maskArray & maskVal) != 0
+						   // May be NULL
+	     unsigned int maskVal,	// Only mask elements with one of these bits set in maskArray
+	     int numIter,	        // Number of clipping iterations (0 not to clip)
+	     float numSD,		// Number of s.d. to clip at
+	     float *restrict mean,	// Mean of array (or NULL)
+	     float *restrict sd,	// Standard deviation (or NULL)
+	     float *restrict med	// Median (or NULL)
+	     );
+
+/***********************************************************************************************************/
+
+/* Histograms */
+typedef struct {
+    const psFloatArray *restrict lower, *restrict upper; // Lower and upper bounds for the bins
+    psIntArray *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
+} psHistogram;
+
+
+/* Constructor */
+psHistogram *
+psHistogramNew(float lower,		// Lower limit for the bins
+	       float upper,		// Upper limit for the bins
+	       float size		// Size of the bins
+    );
+
+/* Generic constructor */
+psHistogram *
+psHistogramNewGeneric(const psFloatArray *restrict lower, // Lower bounds for the bins
+		      const psFloatArray *restrict upper, // Upper bounds for the bins
+		      float minVal,	// Minimum value
+		      float maxVal	// Maximum value
+    );
+
+/* Destructor */
+void
+psHistogramDel(psHistogram *restrict myHist // Histogram to destroy
+    );
+
+
+/* Calculate a histogram */
+psHistogram *
+psGetArrayHistogram(psHistogram *restrict myHist, // Histogram data
+		    const psFloatArray *restrict myArray // Array to analyse
+    );
+
+#endif
+
Index: /trunk/archive/pslib/include/psStdArrays.h
===================================================================
--- /trunk/archive/pslib/include/psStdArrays.h	(revision 149)
+++ /trunk/archive/pslib/include/psStdArrays.h	(revision 149)
@@ -0,0 +1,29 @@
+#if !defined(PS_TYPES_H)
+#define PS_TYPES_H
+
+#include "psArray.h"
+
+/* ps- typedefs so that array names comply with the standard naming convention */
+/* These should not be used generally. */
+typedef float psFloat;
+typedef int psInt;
+typedef complex float psComplex;
+typedef double psDouble;
+
+/* An array of real numbers */
+PS_DECLARE_ARRAY_TYPE(psFloat);
+PS_CREATE_ARRAY_TYPE(psFloat);
+
+/* An array of complex numbers */
+PS_DECLARE_ARRAY_TYPE(psComplex);
+PS_CREATE_ARRAY_TYPE(psComplex);
+
+/* An array of integers */
+PS_DECLARE_ARRAY_TYPE(psInt);
+PS_CREATE_ARRAY_TYPE(psInt);
+
+/* An array of double-precision real numbers */
+PS_DECLARE_ARRAY_TYPE(psDouble);
+PS_CREATE_ARRAY_TYPE(psDouble);
+
+#endif
