Index: trunk/Ohana/src/opihi/cmd.astro/csystem.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/csystem.c	(revision 39610)
+++ trunk/Ohana/src/opihi/cmd.astro/csystem.c	(revision 39926)
@@ -125,6 +125,6 @@
   opihi_flt *yptr = yvec[0].elements.Flt;
 
-  opihi_flt *uxptr = uxvec ? xvec[0].elements.Flt : NULL;
-  opihi_flt *uyptr = uyvec ? yvec[0].elements.Flt : NULL;
+  opihi_flt *uxptr = uxvec ? uxvec[0].elements.Flt : NULL;
+  opihi_flt *uyptr = uyvec ? uyvec[0].elements.Flt : NULL;
 
   for (i = 0; i < xvec[0].Nelements; i++, xptr++, yptr++) {
Index: trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c	(revision 39610)
+++ trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c	(revision 39926)
@@ -158,6 +158,6 @@
     // now that the mask has been updated, we need to recalculate mean epoch and positions
     // XXX make this conditional on actually masking unmasked points above
-    PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
-    PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
+    // PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
+    // PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
 
     PlxFitData sample;
@@ -218,13 +218,37 @@
   // fprintf (stderr, "%f +/- %f | %f %f\n", fit.p, fit.dp, fit.uR, fit.uD);
 
-/*
-  FILE *f = fopen ("test.pf.dat", "w");
+  Vector *dRresPMP, *dDresPMP, *dRresPLX, *dDresPLX;
+
+  // save fit residuals (with only pm removed, and pm and plx removed)
+  if ((dRresPMP = SelectVector ("dRresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPMP");
+  if ((dDresPMP = SelectVector ("dDresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPMP");
+  if ((dRresPLX = SelectVector ("dRresPLX", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPLX");
+  if ((dDresPLX = SelectVector ("dDresPLX", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPLX");
+    
+  ResetVector (dRresPMP, OPIHI_FLT, Ntotal);
+  ResetVector (dDresPMP, OPIHI_FLT, Ntotal);
+  ResetVector (dRresPLX, OPIHI_FLT, Ntotal);
+  ResetVector (dDresPLX, OPIHI_FLT, Ntotal);
+  
   for (i = 0; i < Ntotal; i++) {
-    double Xf = fit.Ro + fit.uR*fitdata.t[i] + fit.p*fitdata.pX[i];
-    double Yf = fit.Do + fit.uD*fitdata.t[i] + fit.p*fitdata.pY[i];
-    fprintf (f, "%f : %f %f : %f %f : %f : %f %f : %f %f\n", T[i], R[i], D[i], Xf, Yf, fitdata.t[i], fitdata.X[i], fitdata.Y[i], fitdata.pX[i], fitdata.pY[i]);
-  }
-  fclose (f);
-*/
+    
+    double x0, y0;
+    RD_to_XY (&x0, &y0, R[i], D[i], &coords);
+
+    double pX0, pY0;
+    ParFactor (&pX0, &pY0, R[i], D[i], T[i]);
+
+    double t0 = (T[i] - Tmean)/365.25;
+
+    double Xpmp = fit.Ro + fit.uR*t0 + fit.p*pX0;
+    double Ypmp = fit.Do + fit.uD*t0 + fit.p*pY0;
+    double Xplx = fit.Ro + fit.uR*t0;
+    double Yplx = fit.Do + fit.uD*t0;
+
+    dRresPMP->elements.Flt[i] = x0 - Xpmp;
+    dDresPMP->elements.Flt[i] = y0 - Ypmp;
+    dRresPLX->elements.Flt[i] = x0 - Xplx;
+    dDresPLX->elements.Flt[i] = y0 - Yplx;
+  }
 
   // fprintf (stderr, "Roff, Doff: %f, %f; dRo, dDo: %f, %f\n", fit.Ro, fit.Do, fit.dRo, fit.dDo);
Index: trunk/Ohana/src/opihi/cmd.astro/spex1dgas.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/spex1dgas.c	(revision 39610)
+++ trunk/Ohana/src/opihi/cmd.astro/spex1dgas.c	(revision 39926)
@@ -108,12 +108,7 @@
   IDList = NULL;
   XoList = NULL;
-  { 
-    // init random numbers
-    long A, B;
-    A = time(NULL);
-    for (B = 0; A == time(NULL); B++);
-    srand48(B);
-  }
  
+  // srand48() is called by startup.c
+
   if (argc != 11) goto usage;
 
Index: trunk/Ohana/src/opihi/cmd.astro/spex2dgas.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/spex2dgas.c	(revision 39610)
+++ trunk/Ohana/src/opihi/cmd.astro/spex2dgas.c	(revision 39926)
@@ -120,12 +120,6 @@
   float XoMax, YoMax;
 
-  { 
-    // init random numbers
-    long A, B;
-    A = time(NULL);
-    for (B = 0; A == time(NULL); B++);
-    srand48(B);
-  }
- 
+  // srand48() is called by startup.c
+
   if (argc != 9) goto usage;
 
Index: trunk/Ohana/src/opihi/cmd.astro/spexseq.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/spexseq.c	(revision 39610)
+++ trunk/Ohana/src/opihi/cmd.astro/spexseq.c	(revision 39926)
@@ -90,13 +90,7 @@
   int Nobject = 0;
 
-  { 
-    // init random numbers
-    long A, B;
-    A = time(NULL);
-    for (B = 0; A == time(NULL); B++);
-    srand48(B);
-  }
- 
   if (argc != 6) goto usage;
+
+  // srand48() is called by startup.c
 
   // XXX enforce matching lengths on the three vectors
