Index: /trunk/BNS/bns.cpp
===================================================================
--- /trunk/BNS/bns.cpp	(revision 803)
+++ /trunk/BNS/bns.cpp	(revision 804)
@@ -240,10 +240,14 @@
                     vv(1), vv(2), vv(3));
 
-  ColumnVector dx = xx - xB;
-  dx(4) *= 299792458.0; 
+  ColumnVector dx   = xx.Rows(1,3) - xB.Rows(1,3);
+  double       dClk = (xx(4) - xB(4)) * 299792458.0; 
+  ColumnVector rsw(3);
+
+  XYZ_to_RSW(xB, vv, dx, rsw);
 
   cout.setf(ios::showpoint | ios::fixed);
   cout << GPSweek << " " 
        << setprecision(1) << GPSweeks << " " << ep->prn.toAscii().data()
-       << setw(8) << setprecision(3) << dx.t();
-}
+       << setw(8) << setprecision(3) << dClk
+       << setw(8) << setprecision(3) << rsw.t();
+}
Index: /trunk/BNS/bns.pro
===================================================================
--- /trunk/BNS/bns.pro	(revision 803)
+++ /trunk/BNS/bns.pro	(revision 804)
@@ -2,6 +2,6 @@
 # Switch to debug configuration
 # -----------------------------
-CONFIG -= release
-CONFIG += debug
+### CONFIG -= release
+### CONFIG += debug
 
 RESOURCES += bns.qrc
Index: /trunk/BNS/bnsutils.cpp
===================================================================
--- /trunk/BNS/bnsutils.cpp	(revision 803)
+++ /trunk/BNS/bnsutils.cpp	(revision 804)
@@ -94,10 +94,11 @@
 }
 
-//  
+// Satellite Position computed using broadcast ephemeris
 ////////////////////////////////////////////////////////////////////////////
-void satellitePosition(double GPSweeks, const gpsEph* ep, 
+void satellitePosition(int GPSweek, double GPSweeks, const gpsEph* ep, 
                        double& X, double& Y, double& Z, double& dt,
                        double& vX, double& vY, double& vZ) {
 
+  const static double secPerWeek = 7 * 86400.0;
   const static double omegaEarth = 7292115.1467e-11;
   const static double gmWGS      = 398.6005e12;
@@ -112,4 +113,7 @@
   double n0 = sqrt(gmWGS/(a0*a0*a0));
   double tk = GPSweeks - ep->TOE;
+  if (GPSweek != ep->GPSweek) {  
+    tk += (GPSweek - ep->GPSweek) * secPerWeek;
+  }
   double n  = n0 + ep->Delta_n;
   double M  = ep->M0 + n*tk;
@@ -141,4 +145,7 @@
   
   double tc = GPSweeks - ep->TOC;
+  if (GPSweek != ep->GPSweek) {  
+    tc += (GPSweek - ep->GPSweek) * secPerWeek;
+  }
   dt = ep->clock_bias + ep->clock_drift*tc + ep->clock_driftrate*tc*tc 
        - 4.442807633e-10 * ep->e * sqrt(a0) *sin(E);
@@ -168,2 +175,15 @@
   vZ  = sini    *doty  + yp*cosi      *doti;
 }
+
+// Transformation xyz --> radial, along track, out-of-plane
+////////////////////////////////////////////////////////////////////////////
+void XYZ_to_RSW(const ColumnVector& rr, const ColumnVector& vv,
+                const ColumnVector& xyz, ColumnVector& rsw) {
+
+  ColumnVector cross = crossproduct(rr, vv);
+
+  rsw.ReSize(3);
+  rsw(1) = DotProduct(xyz, rr)    / rr.norm_Frobenius();
+  rsw(2) = DotProduct(xyz, vv)    / vv.norm_Frobenius();
+  rsw(3) = DotProduct(xyz, cross) / cross.norm_Frobenius();
+}
Index: /trunk/BNS/bnsutils.h
===================================================================
--- /trunk/BNS/bnsutils.h	(revision 803)
+++ /trunk/BNS/bnsutils.h	(revision 804)
@@ -2,4 +2,6 @@
 #ifndef BNSUTILS_H
 #define BNSUTILS_H
+
+#include <newmat.h>
 
 #include <QString>
@@ -17,6 +19,9 @@
 void currentGPSWeeks(int& week, double& sec);
 
-void satellitePosition(double GPSweeks, const gpsEph* ep, 
+void satellitePosition(int GPSweek, double GPSweeks, const gpsEph* ep, 
                        double& X, double& Y, double& Z, double&,
                        double& vX, double& vY, double& vZ);
+
+void XYZ_to_RSW(const ColumnVector& rr, const ColumnVector& vv,
+                const ColumnVector& xyz, ColumnVector& rsw);
 #endif
