Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h	(revision 12049)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h	(revision 12050)
@@ -4,14 +4,13 @@
 # include <signal.h>
 
-/* # define GRID_V1 */
-# define GRID_V2
-
-# if (0)
 typedef struct {
-  double xmin, xmax, ymin, ymax;
-  int style, ptype, ltype, etype, color;
-  double lweight, size;
-} Graphdata;
-# endif
+  double Ro, dRo;
+  double Do, dDo;
+  
+  double uR, duR;
+  double uD, duD;
+
+  double p, dp;
+} PMfit;
 
 typedef struct {
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPM.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPM.c	(revision 12049)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPM.c	(revision 12050)
@@ -2,15 +2,16 @@
 
 /* do we want an init function which does the alloc and a clear function to free? */
-
 FitPM (double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts) {
 
+  PFfit *fit;
   double **A, **B;
 
-  ALLOCATE (A, double *, 5);
-  ALLOCATE (B, double *, 5);
-  for (i = 0; i < 5; i++) {
-    ALLOCATE (A[i], double, 5);
+  /* do I need to do this as 2 2x2 matrix equations? */
+  ALLOCATE (A, double *, 4);
+  ALLOCATE (B, double *, 4);
+  for (i = 0; i < 4; i++) {
+    ALLOCATE (A[i], double, 4);
     ALLOCATE (B[i], double, 1);
-    bzero (A[i], 5*sizeof(double));
+    bzero (A[i], 4*sizeof(double));
     bzero (B[i], 1*sizeof(double));
   }
@@ -30,16 +31,4 @@
     Ty2 += SQ(T[i])*wy;
     
-    PR += pR[i]*wx;
-    PD += pD[i]*wy;
-    
-    PRT += pR[i]*T[i]*wx;
-    PDT += pD[i]*T[i]*wy;
-    
-    PRX += pR[i]*X[i]*wx;
-    PDY += pD[i]*Y[i]*wy;
-    
-    PR2 += SQ(pR[i])*wx;
-    PD2 += SQ(pD[i])*wy;
-
     Xs += X[i]*wx;
     Ys += Y[i]*wy;
@@ -51,23 +40,13 @@
   A[0][0] = Wx;
   A[0][1] = Tx;
-  A[0][4] = PR;
 
   A[1][0] = Tx;
   A[1][1] = Tx2;
-  A[1][4] = PRT;
 
   A[2][2] = Wy;
   A[2][3] = Ty;
-  A[2][4] = PD;
 
   A[3][2] = Ty;
   A[3][3] = Ty2;
-  A[3][4] = PDT;
-
-  A[4][0] = PR;
-  A[4][1] = PRT;
-  A[4][2] = PD;
-  A[4][3] = PDT;
-  A[4][4] = PR2 + PD2;
 
   B[0][0] = Xs;
@@ -75,21 +54,22 @@
   B[2][0] = Ys;
   B[3][0] = YT;
-  B[4][0] = PRX + PDY;
 
-  dgaussj (A, 5, B, 1);
+  dgaussj (A, 4, B, 1);
 
-  Ro = B[0];
-  uR = B[1];
-  Do = B[2];
-  uD = B[3];
-  p  = B[4];
+  ALLOCATE (fit, PMfit, 1);
+
+  fit[0].Ro = B[0];
+  fit[0].uR = B[1];
+  fit[0].Do = B[2];
+  fit[0].uD = B[3];
+  fit[0].p  = 0.0;
   
-  dRo = sqrt(A[0][0]);
-  duR = sqrt(A[1][1]);
-  dDo = sqrt(A[2][2]);
-  duD = sqrt(A[3][3]);
-  dp  = sqrt(A[4][4]);
+  fit[0].dRo = sqrt(A[0][0]);
+  fit[0].duR = sqrt(A[1][1]);
+  fit[0].dDo = sqrt(A[2][2]);
+  fit[0].duD = sqrt(A[3][3]);
+  fit[0].dp  = 0.0;
   
-  for (i = 0; i < 5; i++) {
+  for (i = 0; i < 4; i++) {
     free (A[i]);
     free (B[i]);
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPMandPar.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPMandPar.c	(revision 12050)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/FitPMandPar.c	(revision 12050)
@@ -0,0 +1,104 @@
+# include "relastro.h"
+
+/* do we want an init function which does the alloc and a clear function to free? */
+
+FitPM (double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, int Npts) {
+
+  PFfit *fit;
+  double **A, **B;
+
+  ALLOCATE (A, double *, 5);
+  ALLOCATE (B, double *, 5);
+  for (i = 0; i < 5; i++) {
+    ALLOCATE (A[i], double, 5);
+    ALLOCATE (B[i], double, 1);
+    bzero (A[i], 5*sizeof(double));
+    bzero (B[i], 1*sizeof(double));
+  }
+
+  for (i = 0; i < Npts; i++) {
+    /* handle case where dX or dY = 0.0 */
+    wx = 1.0 / SQ(dX[i]);
+    wy = 1.0 / SQ(dY[i]);
+
+    Wx += wx;
+    Wy += wy;
+
+    Tx += T[i]*wx;
+    Ty += T[i]*wy;
+    
+    Tx2 += SQ(T[i])*wx;
+    Ty2 += SQ(T[i])*wy;
+    
+    PR += pR[i]*wx;
+    PD += pD[i]*wy;
+    
+    PRT += pR[i]*T[i]*wx;
+    PDT += pD[i]*T[i]*wy;
+    
+    PRX += pR[i]*X[i]*wx;
+    PDY += pD[i]*Y[i]*wy;
+    
+    PR2 += SQ(pR[i])*wx;
+    PD2 += SQ(pD[i])*wy;
+
+    Xs += X[i]*wx;
+    Ys += Y[i]*wy;
+
+    XT += X[i]*T[i]*wx;
+    YT += Y[i]*T[i]*wy;
+  }
+
+  A[0][0] = Wx;
+  A[0][1] = Tx;
+  A[0][4] = PR;
+
+  A[1][0] = Tx;
+  A[1][1] = Tx2;
+  A[1][4] = PRT;
+
+  A[2][2] = Wy;
+  A[2][3] = Ty;
+  A[2][4] = PD;
+
+  A[3][2] = Ty;
+  A[3][3] = Ty2;
+  A[3][4] = PDT;
+
+  A[4][0] = PR;
+  A[4][1] = PRT;
+  A[4][2] = PD;
+  A[4][3] = PDT;
+  A[4][4] = PR2 + PD2;
+
+  B[0][0] = Xs;
+  B[1][0] = XT;
+  B[2][0] = Ys;
+  B[3][0] = YT;
+  B[4][0] = PRX + PDY;
+
+  dgaussj (A, 5, B, 1);
+
+  ALLOCATE (fit, PMfit, 1);
+
+  fit[0].Ro = B[0];
+  fit[0].uR = B[1];
+  fit[0].Do = B[2];
+  fit[0].uD = B[3];
+  fit[0].p  = B[4];
+  
+  fit[0].dRo = sqrt(A[0][0]);
+  fit[0].duR = sqrt(A[1][1]);
+  fit[0].dDo = sqrt(A[2][2]);
+  fit[0].duD = sqrt(A[3][3]);
+  fit[0].dp  = sqrt(A[4][4]);
+  
+  for (i = 0; i < 5; i++) {
+    free (A[i]);
+    free (B[i]);
+  }
+  free (A);
+  free (B);
+
+  return (fit);
+}
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateObjects.c	(revision 12049)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/UpdateObjects.c	(revision 12050)
@@ -86,4 +86,8 @@
       }
 
+      if (FitProperMotion) {
+	  fit = FitPMandPar (listX, dlistX, listY, dlistY, listT, pR, pD, N);
+      }
+
       if (AverageCoords) {
 	  liststats (listR, dlistR, N, &statsR);
