Index: /trunk/BNC/RTCM3/RTCM3coDecoder.cpp
===================================================================
--- /trunk/BNC/RTCM3/RTCM3coDecoder.cpp	(revision 1833)
+++ /trunk/BNC/RTCM3/RTCM3coDecoder.cpp	(revision 1834)
@@ -47,4 +47,5 @@
 #include "bncapp.h"
 #include "bncsettings.h"
+#include "rtcm3torinex.h"
 
 using namespace std;
@@ -163,21 +164,38 @@
         }
         else {
-          double GPSdaysec = fmod(_GPSweeks, 86400.0);
-          int    weekDay   = int((_GPSweeks - GPSdaysec) / 86400.0);
-          if      (GPSdaysec > _co.GLONASSEpochTime + 3600.0) {
+
+          // Guess GPS week and sec using system time
+          // ----------------------------------------
+          int week;
+          double sec;
+          currentGPSWeeks(week, sec); 
+          int weekDay      = int(sec/86400.0); 
+          int GPSDaySecHlp = int(sec) - weekDay * 86400;
+
+          // cout << "week, sec " << week << " " << sec << endl;
+
+          // Second of day (GPS time) from Glonass Epoch
+          // -------------------------------------------
+          QDate date = dateAndTimeFromGPSweek(week, sec).date();
+          int leapSecond = gnumleap(date.year(), date.month(), date.day());
+          int GPSDaySec  = _co.GLONASSEpochTime + 3 * 3600 + leapSecond;
+
+          // cout << "GlonassEpoch, leapSecond, GPSDaySec "
+          //      << _co.GLONASSEpochTime << " " << leapSecond << " "
+          //      << GPSDaySec << endl;
+
+          // Handle the difference between system clock and correction epoch
+          // ---------------------------------------------------------------
+          if      (GPSDaySec < GPSDaySecHlp - 3600) {
             weekDay += 1;
-            if (weekDay > 6) {
-              weekDay = 0;
-              GPSweek += 1;
-            }
           }
-          else if (GPSdaysec < _co.GLONASSEpochTime - 3600.0) {
+          else if (GPSDaySec > GPSDaySecHlp + 3600) {
             weekDay -= 1;
-            if (weekDay < 0) {
-              weekDay = 6;
-              GPSweek -= 1;
-            }
-          }
-          _GPSweeks = weekDay * 86400.0 + _co.GLONASSEpochTime;
+          } 
+
+          _GPSweeks = weekDay * 86400.0 + GPSDaySec;
+                      
+          // cout << "weekDay, _GPSweeks " << weekDay << " " 
+          //      << _GPSweeks << endl;
         }
 
Index: /trunk/BNC/RTCM3/rtcm3torinex.c
===================================================================
--- /trunk/BNC/RTCM3/rtcm3torinex.c	(revision 1833)
+++ /trunk/BNC/RTCM3/rtcm3torinex.c	(revision 1834)
@@ -1,5 +1,5 @@
 /*
   Converter for RTCM3 data to RINEX.
-  $Id: rtcm3torinex.c,v 1.23 2009/04/30 11:40:45 mervart Exp $
+  $Id: rtcm3torinex.c,v 1.24 2009/05/04 10:38:37 mervart Exp $
   Copyright (C) 2005-2008 by Dirk Stöcker <stoecker@alberding.eu>
 
@@ -55,5 +55,5 @@
 
 /* CVS revision and version */
-static char revisionstr[] = "$Revision: 1.23 $";
+static char revisionstr[] = "$Revision: 1.24 $";
 
 #ifndef COMPILEDATE
@@ -238,5 +238,5 @@
 }
 
-static int gnumleap(int year, int month, int day)
+int gnumleap(int year, int month, int day)
 {
   int ls = 0;
@@ -1689,5 +1689,5 @@
 
 #ifndef NO_RTCM3_MAIN
-static char datestr[]     = "$Date: 2009/04/30 11:40:45 $";
+static char datestr[]     = "$Date: 2009/05/04 10:38:37 $";
 
 /* The string, which is send as agent in HTTP request */
Index: /trunk/BNC/RTCM3/rtcm3torinex.h
===================================================================
--- /trunk/BNC/RTCM3/rtcm3torinex.h	(revision 1833)
+++ /trunk/BNC/RTCM3/rtcm3torinex.h	(revision 1834)
@@ -4,5 +4,5 @@
 /*
   Converter for RTCM3 data to RINEX.
-  $Id: rtcm3torinex.h,v 1.15 2008/11/26 12:17:13 weber Exp $
+  $Id: rtcm3torinex.h,v 1.16 2008/12/08 10:50:42 mervart Exp $
   Copyright (C) 2005-2006 by Dirk Stöcker <stoecker@alberding.eu>
 
@@ -232,4 +232,5 @@
 #endif /* PRINTFARG */
 
+int gnumleap(int year, int month, int day);
 void HandleHeader(struct RTCM3ParserData *Parser);
 int RTCM3Parser(struct RTCM3ParserData *handle);
