Index: /trunk/BNC/bnccaster.cpp
===================================================================
--- /trunk/BNC/bnccaster.cpp	(revision 348)
+++ /trunk/BNC/bnccaster.cpp	(revision 349)
@@ -114,7 +114,6 @@
 // New Observations
 ////////////////////////////////////////////////////////////////////////////
-void bncCaster::newObs(const QByteArray& staID, const QUrl& mountPoint,
-                       bool firstObs, Observation* obs,
-                       const QByteArray& format) {
+int bncCaster::newObs(const QByteArray& staID,
+                       bool firstObs, Observation* obs) {
 
   QMutexLocker locker(&_mutex);
@@ -128,16 +127,4 @@
   obs->StatID[sizeof(obs->StatID)-1] = '\0';
         
-  // Prepare RINEX Output
-  // --------------------
-  if (_rinexWriters.find(obs->StatID) == _rinexWriters.end()) {
-    _rinexWriters.insert(obs->StatID, new bncRinex(obs->StatID, 
-                                                   mountPoint, format));
-  }
-  bncRinex* rnx = _rinexWriters.find(obs->StatID).value();
-  if (_samplingRate == 0 || iSec % _samplingRate == 0) {
-    rnx->deepCopy(obs);
-  }
-  rnx->dumpEpoch(newTime);
-
   // First time, set the _lastDumpSec immediately
   // --------------------------------------------
@@ -158,5 +145,5 @@
     }
     delete obs;
-    return;
+    return 1;
   }
 
@@ -172,4 +159,6 @@
     _lastDumpSec = newTime - _waitTime;
   }
+
+  return 0;
 }
 
Index: /trunk/BNC/bnccaster.h
===================================================================
--- /trunk/BNC/bnccaster.h	(revision 348)
+++ /trunk/BNC/bnccaster.h	(revision 349)
@@ -32,5 +32,4 @@
 
 #include "RTCM/GPSDecoder.h"
-#include "bncrinex.h"
 
 class bncGetThread;
@@ -44,6 +43,5 @@
    void addGetThread(bncGetThread* getThread);
    int  numStations() const {return _staIDs.size();}
-   void newObs(const QByteArray& staID, const QUrl& mountPoint,
-               bool firstObs, Observation* obs, const QByteArray& format);
+   int  newObs(const QByteArray& staID, bool firstObs, Observation* obs);
 
  signals:
@@ -66,5 +64,4 @@
    QList<QTcpSocket*>*            _sockets;
    QList<QByteArray>              _staIDs;
-   QMap<QString, bncRinex*>       _rinexWriters;
    QList<bncGetThread*>           _threads;
    int                            _samplingRate;
Index: /trunk/BNC/bncgetthread.cpp
===================================================================
--- /trunk/BNC/bncgetthread.cpp	(revision 348)
+++ /trunk/BNC/bncgetthread.cpp	(revision 349)
@@ -49,4 +49,5 @@
 #include "bnctabledlg.h"
 #include "bncapp.h"
+#include "bncutils.h"
 
 #include "RTCM/RTCM2Decoder.h"
@@ -60,13 +61,14 @@
 bncGetThread::bncGetThread(const QUrl& mountPoint, 
                            const QByteArray& format, int iMount) {
-  _decoder    = 0;
-  _mountPoint = mountPoint;
-  _staID      = mountPoint.path().mid(1).toAscii();
-  _staID_orig = _staID;
-  _format     = format;
-  _socket     = 0;
-  _timeOut    = 20*1000;  // 20 seconds
-  _nextSleep  =  1;       //  1 second
-  _iMount     = iMount;   // index in mountpoints array
+  _decoder     = 0;
+  _mountPoint  = mountPoint;
+  _staID       = mountPoint.path().mid(1).toAscii();
+  _staID_orig  = _staID;
+  _format      = format;
+  _socket      = 0;
+  _timeOut     = 20*1000;  // 20 seconds
+  _nextSleep   =  1;       //  1 second
+  _iMount      = iMount;   // index in mountpoints array
+  _rinexWriter = 0;
 
   // Check name conflict
@@ -87,4 +89,6 @@
     }
   }
+
+  _samplingRate = settings.value("rnxSampl").toInt();
 
   if (num > 0) {
@@ -288,7 +292,47 @@
         for (list<Observation*>::iterator it = _decoder->_obsList.begin(); 
              it != _decoder->_obsList.end(); it++) {
+
+          // Check observation epoch
+          // -----------------------
+          int    week;
+          double sec;
+          currentGPSWeeks(week, sec);
+          
+          const double secPerWeek = 7.0 * 24.0 * 3600.0;
+          const double maxDt      = 600.0;            
+
+          if (week < (*it)->GPSWeek) {
+            week += 1;
+            sec  -= secPerWeek;
+          }
+          if (week > (*it)->GPSWeek) {
+            week -= 1;
+            sec  += secPerWeek;
+          }
+          double dt = fabs(sec - (*it)->GPSWeeks);
+          if (week != (*it)->GPSWeek || dt > maxDt) {
+            emit( newMessage("Wrong observation epoch") );
+            delete (*it);
+            continue;
+          }
+
           emit newObs(_staID, *it);
           bool firstObs = (it == _decoder->_obsList.begin());
-          _global_caster->newObs(_staID, _mountPoint, firstObs, *it, _format);
+          if ( _global_caster->newObs(_staID, firstObs, *it) == 0 ) {
+
+            if (_rinexWriter == 0) {
+              _rinexWriter = new bncRinex((*it)->StatID, _mountPoint, _format);
+            }
+
+            long iSec    = long(floor((*it)->GPSWeeks+0.5));
+            long newTime = (*it)->GPSWeek * 7*24*3600 + iSec;
+
+            if (_samplingRate == 0 || iSec % _samplingRate == 0) {
+              _rinexWriter->deepCopy(*it);
+            }
+            _rinexWriter->dumpEpoch(newTime);
+          }
+
+
         }
         _decoder->_obsList.clear();
Index: /trunk/BNC/bncgetthread.h
===================================================================
--- /trunk/BNC/bncgetthread.h	(revision 348)
+++ /trunk/BNC/bncgetthread.h	(revision 349)
@@ -32,4 +32,5 @@
 #include "RTCM/GPSDecoder.h"
 #include "bncconst.h"
+#include "bncrinex.h"
 
 class bncGetThread : public QThread {
@@ -68,4 +69,6 @@
    int         _nextSleep;
    int         _iMount;
+   int         _samplingRate;
+   bncRinex*   _rinexWriter;
 };
 
