Index: /trunk/BNC/bnccaster.cpp
===================================================================
--- /trunk/BNC/bnccaster.cpp	(revision 159)
+++ /trunk/BNC/bnccaster.cpp	(revision 160)
@@ -83,4 +83,17 @@
   long newTime = obs->GPSWeek * 7*24*3600 + obs->GPSWeeks;
 
+  // Rename the Station
+  // ------------------
+  strncpy(obs->StatID, staID.constData(),sizeof(obs->StatID));
+        
+  // Prepare RINEX Output
+  // --------------------
+  if (_rinexWriters.find(obs->StatID) == _rinexWriters.end()) {
+    _rinexWriters.insert(obs->StatID, new bncRinex(obs->StatID));
+  }
+  bncRinex* rnx = _rinexWriters.find(obs->StatID).value();
+  rnx->deepCopy(obs);
+  rnx->dumpEpoch(newTime);
+
   // First time, set the _lastDumpSec immediately
   // --------------------------------------------
@@ -98,7 +111,6 @@
   }
 
-  // Rename the station and save the observation
-  // -------------------------------------------
-  strncpy(obs->StatID, staID.constData(),sizeof(obs->StatID));
+  // Save the observation
+  // --------------------
   _epochs->insert(newTime, obs);
 
@@ -196,12 +208,4 @@
           }
         }
-        
-        // Prepare RINEX Output
-        // --------------------
-        if (_rinexWriters.find(obs->StatID) == _rinexWriters.end()) {
-          _rinexWriters.insert(obs->StatID, new bncRinex(obs->StatID));
-        }
-        bncRinex* rnx = _rinexWriters.find(obs->StatID).value();
-        rnx->deepCopy(obs);
       }
 
@@ -210,12 +214,4 @@
       first = false;
     }
-
-    // Write RINEX Files
-    // -----------------
-    QMapIterator<QString, bncRinex*> ir(_rinexWriters);
-    while (ir.hasNext()) {
-      bncRinex* rnx = ir.next().value();
-      rnx->dumpEpoch();
-    }
-  }
-}
+  }
+}
Index: /trunk/BNC/bncrinex.cpp
===================================================================
--- /trunk/BNC/bncrinex.cpp	(revision 159)
+++ /trunk/BNC/bncrinex.cpp	(revision 160)
@@ -260,9 +260,21 @@
 // Write One Epoch into the RINEX File
 ////////////////////////////////////////////////////////////////////////////
-void bncRinex::dumpEpoch() {
+void bncRinex::dumpEpoch(long maxTime) {
+
+  // Select observations older than maxTime
+  // --------------------------------------
+  QList<Observation*> dumpList;
+  QMutableListIterator<Observation*> mIt(_obs);
+  while (mIt.hasNext()) {
+    Observation* ob = mIt.next();
+    if (ob->GPSWeek * 7*24*3600 + ob->GPSWeeks < maxTime) {
+      dumpList.push_back(ob);
+      mIt.remove();
+    }
+  }
 
   // Easy Return
   // -----------
-  if (_obs.isEmpty()) {
+  if (dumpList.isEmpty()) {
     return;
   }
@@ -270,5 +282,5 @@
   // Time of Epoch
   // -------------
-  Observation* firstObs = *_obs.begin();
+  Observation* firstObs = *dumpList.begin();
 
   QDateTime datTim = dateAndTimeFromGPSweek( firstObs->GPSWeek,
@@ -290,7 +302,7 @@
 
   _out << datTim.toString(" yy MM dd hh mm ss.zzz0000").toAscii().data()
-       << "  " << 0 << setw(3)  << _obs.size();
-
-  QListIterator<Observation*> it(_obs); int iSat = 0;
+       << "  " << 0 << setw(3)  << dumpList.size();
+
+  QListIterator<Observation*> it(dumpList); int iSat = 0;
   while (it.hasNext()) {
     iSat++;
@@ -320,5 +332,4 @@
 
   _out.flush();
-  _obs.clear();
 }
 
Index: /trunk/BNC/bncrinex.h
===================================================================
--- /trunk/BNC/bncrinex.h	(revision 159)
+++ /trunk/BNC/bncrinex.h	(revision 160)
@@ -17,5 +17,5 @@
    ~bncRinex();
    void deepCopy(const Observation* obs);
-   void dumpEpoch();
+   void dumpEpoch(long maxTime);
 
  private:
