Index: trunk/BNS/bns.cpp
===================================================================
--- trunk/BNS/bns.cpp	(revision 1131)
+++ trunk/BNS/bns.cpp	(revision 1197)
@@ -289,26 +289,55 @@
 void t_bns::readEpoch() {
 
-  QByteArray line = _clkSocket->readLine();
-
-  if (_echoStream) {
-    *_echoStream << line;
-    _echoStream->flush();
-  }
-
-  emit(newClkBytes(line.length()));
-
-  if (line.indexOf('*') == -1) {
+  // Read the first line (if not already read)
+  // -----------------------------------------
+  if (_clkLine.indexOf('*') == -1) {
+    _clkLine = _clkSocket->readLine();
+    if (_echoStream) {
+      *_echoStream << _clkLine;
+      _echoStream->flush();
+    }
+    emit(newClkBytes(_clkLine.length()));
+  }
+
+  if (_clkLine.indexOf('*') == -1) {
     return;
   }
 
-  QTextStream in(line);
+  QTextStream in(_clkLine);
 
   QString hlp;
-  int     GPSweek, numSat;
+  int     year, month, day, hour, min;
+  double  sec;
+  in >> hlp >> year >> month >> day >> hour >> min >> sec;
+
+  int     GPSweek;
   double  GPSweeks;
 
-  in >> hlp >> GPSweek >> GPSweeks >> numSat;
-
-  if (numSat > 0) {
+  GPSweekFromYMDhms(year, month, day, hour, min, sec, GPSweek, GPSweeks);
+
+  QStringList prns;
+
+  // Loop over all satellites
+  // ------------------------
+  QStringList lines;
+  for (;;) {
+    if (!_clkSocket->canReadLine()) {
+      return;
+    }
+    _clkLine = _clkSocket->readLine();
+    if (_echoStream) {
+      *_echoStream << _clkLine;
+      _echoStream->flush();
+    }
+    if (_clkLine[0] == '*') {
+      return;
+    }
+    if (_clkLine[0] == 'P') {
+      _clkLine.remove(0,1);
+      lines.push_back(_clkLine);
+    } 
+  }
+
+  if (lines.size() > 0) {
 
     QStringList prns;
@@ -328,6 +357,6 @@
         co.SatRefDatum       = DATUM_ITRF;
       
-        for (int ii = 1; ii <= numSat; ii++) {
-      
+        for (int ii = 0; ii < lines.size(); ii++) {
+
           QString      prn;
           ColumnVector xx(5);
@@ -335,20 +364,13 @@
       
           if (oldEph == 0 && ic == 0) {
-            line = _clkSocket->readLine();
-
-            if (_echoStream) {
-              *_echoStream << line;
-              _echoStream->flush();
-            }
-
-            QTextStream in(line);
+            QTextStream in(lines[ii].toAscii());
             in >> prn;
             prns << prn;
             if ( _ephList.contains(prn) ) {
-              in >> xx(1) >> xx(2) >> xx(3) >> xx(4) >> xx(5); xx(4) *= 1e-6;
-      
-              //// beg test (zero clock correction for Gerhard Wuebbena)
-              ////            xx(4) -= xx(5) / 299792458.0;
-              //// end test
+              in >> xx(1) >> xx(2) >> xx(3) >> xx(4);
+              xx(1) *= 1e3;
+              xx(2) *= 1e3;
+              xx(3) *= 1e3;
+              xx(4) *= 1e-6;
       
               t_ephPair* pair = _ephList[prn];
@@ -358,5 +380,5 @@
           }
           else {
-            prn = prns[ii-1];
+            prn = prns[ii];
             if ( _ephList.contains(prn) ) {
               t_ephPair* pair = _ephList[prn];
Index: trunk/BNS/bns.h
===================================================================
--- trunk/BNS/bns.h	(revision 1131)
+++ trunk/BNS/bns.h	(revision 1197)
@@ -77,4 +77,5 @@
   bnsRinex*                 _rnx;
   bnsSP3*                   _sp3;
+  QByteArray                _clkLine;
 };
 #endif
Index: trunk/BNS/bnsutils.cpp
===================================================================
--- trunk/BNS/bnsutils.cpp	(revision 1131)
+++ trunk/BNS/bnsutils.cpp	(revision 1197)
@@ -166,2 +166,44 @@
 }
 
+// 
+////////////////////////////////////////////////////////////////////////////
+double djul(int jj, int mm, double tt) {
+  int    ii, kk;
+  double  djul ;
+
+  if( mm <= 2 ) {
+    jj = jj - 1;
+    mm = mm + 12;
+  }  
+  
+  ii   = jj/100;
+  kk   = 2 - ii + ii/4;
+  djul = (365.25*jj - fmod( 365.25*jj, 1.0 )) - 679006.0;
+  djul = djul + floor( 30.6001*(mm + 1) ) + tt + kk;
+  return djul;
+} 
+
+void jdgp(double tjul, double & second, int & nweek) {
+  double      deltat;
+
+  deltat = tjul - 44244.0 ;
+
+  // current gps week
+
+  nweek = (int) floor(deltat/7.0);
+
+  // seconds past midnight of last weekend
+
+  second = (deltat - (nweek)*7.0)*86400.0;
+
+}
+
+void GPSweekFromYMDhms(int year, int month, int day, int hour, int min,
+                       double sec, int& GPSWeek, double& GPSWeeks) {
+
+  double tt = (min / 60.0 + hour) / 24.0 + day;
+  double mjd = djul(year, month, tt);
+  jdgp(mjd, GPSWeeks, GPSWeek);
+  GPSWeeks += sec;  
+}
+
Index: trunk/BNS/bnsutils.h
===================================================================
--- trunk/BNS/bnsutils.h	(revision 1131)
+++ trunk/BNS/bnsutils.h	(revision 1197)
@@ -20,4 +20,7 @@
                             int& GPSWeek, double& GPSWeeks);
 
+void GPSweekFromYMDhms(int year, int month, int day, int hour, int min,
+                       double sec, int& GPSWeek, double& GPSWeeks);
+
 void mjdFromDateAndTime(const QDateTime& dateTime, int& mjd, double& dayfrac);
 
