Index: /trunk/BNC/src/RTCM/RTCM2Decoder.cpp
===================================================================
--- /trunk/BNC/src/RTCM/RTCM2Decoder.cpp	(revision 6442)
+++ /trunk/BNC/src/RTCM/RTCM2Decoder.cpp	(revision 6443)
@@ -55,5 +55,5 @@
 // 
 
-RTCM2Decoder::RTCM2Decoder(const std::string& ID) : bncEphUser(true) {
+RTCM2Decoder::RTCM2Decoder(const std::string& ID) : _ephUser(true) {
   _ID = ID;
 }
@@ -352,9 +352,11 @@
 
       // Select corresponding ephemerides
-      if      (ephLast(prn) && ephLast(prn)->IOD() == IODcorr) {
-        eph = ephLast(prn);
-      }
-      else if (ephPrev(prn) && ephPrev(prn)->IOD() == IODcorr) {
-        eph = ephPrev(prn);
+      const t_eph* ephLast = _ephUser.ephLast(prn);
+      const t_eph* ephPrev = _ephUser.ephPrev(prn);
+      if      (ephLast && ephLast->IOD() == IODcorr) {
+        eph = ephLast;
+      }
+      else if (ephPrev && ephPrev->IOD() == IODcorr) {
+        eph = ephPrev;
       }
 
Index: /trunk/BNC/src/RTCM/RTCM2Decoder.h
===================================================================
--- /trunk/BNC/src/RTCM/RTCM2Decoder.h	(revision 6442)
+++ /trunk/BNC/src/RTCM/RTCM2Decoder.h	(revision 6443)
@@ -36,5 +36,5 @@
 #include "bncephuser.h"
 
-class RTCM2Decoder: public bncEphUser, public GPSDecoder {
+class RTCM2Decoder: public GPSDecoder {
 
   public:
@@ -57,18 +57,19 @@
     void translateCorr2Obs(std::vector<std::string>& errmsg);
 
-    std::string            _ID;
-
-    std::string            _buffer;
-    rtcm2::RTCM2packet     _PP;
+    QMutex             _mutex;
+    std::string        _ID;
+    std::string        _buffer;
+    rtcm2::RTCM2packet _PP;
 
     // for messages 18, 19 decoding
-    rtcm2::RTCM2_Obs       _ObsBlock;
+    rtcm2::RTCM2_Obs   _ObsBlock;
 
     // for messages 20, 21 decoding
-    rtcm2::RTCM2_03           _msg03;
-    rtcm2::RTCM2_22           _msg22;
-    rtcm2::RTCM2_23           _msg23;
-    rtcm2::RTCM2_24           _msg24;
-    rtcm2::RTCM2_2021         _msg2021;
+    rtcm2::RTCM2_03    _msg03;
+    rtcm2::RTCM2_22    _msg22;
+    rtcm2::RTCM2_23    _msg23;
+    rtcm2::RTCM2_24    _msg24;
+    rtcm2::RTCM2_2021  _msg2021;
+    bncEphUser         _ephUser;        
 };
 
Index: /trunk/BNC/src/bncephuser.cpp
===================================================================
--- /trunk/BNC/src/bncephuser.cpp	(revision 6442)
+++ /trunk/BNC/src/bncephuser.cpp	(revision 6443)
@@ -67,8 +67,11 @@
 ////////////////////////////////////////////////////////////////////////////
 bncEphUser::~bncEphUser() {
-  QMapIterator<QString, t_ephPair*> it(_eph);
+  QMapIterator<QString, deque<t_eph*> > it(_eph);
   while (it.hasNext()) {
     it.next();
-    delete it.value();
+    const deque<t_eph*>& qq = it.value();
+    for (unsigned ii = 0; ii < qq.size(); ii++) {
+      delete qq[ii];
+    }
   }
 }
@@ -137,20 +140,19 @@
   QString prn(newEph->prn().toString().c_str());
 
-  if (_eph.contains(prn)) {
-    if (newEph->isNewerThan(_eph.value(prn)->last)) {
-      delete _eph.value(prn)->prev;
-      _eph.value(prn)->prev = _eph.value(prn)->last;
-      _eph.value(prn)->last = newEph;
-      ephBufferChanged();
-      return success;
+  const t_eph* ephOld = ephLast(prn);
+
+  if (ephOld == 0 || newEph->isNewerThan(ephOld)) {
+    deque<t_eph*>& qq = _eph[prn];
+    qq.push_back(newEph);
+    if (qq.size() > _maxQueueSize) {
+      delete qq.front();
+      qq.pop_front();
     }
-  }
-  else {
-    _eph.insert(prn, new t_ephPair(newEph));
     ephBufferChanged();
     return success;
   }
-
-  return failure;
+  else {
+    return failure;
+  }
 }
 
Index: /trunk/BNC/src/bncephuser.h
===================================================================
--- /trunk/BNC/src/bncephuser.h	(revision 6442)
+++ /trunk/BNC/src/bncephuser.h	(revision 6443)
@@ -26,4 +26,5 @@
 #define BNCEPHUSER_H
 
+#include <deque>
 #include <QtCore>
 #include <newmat.h>
@@ -32,8 +33,4 @@
 #include "bnctime.h"
 #include "ephemeris.h"
-
-extern "C" {
-#  include "clock_orbit_rtcm.h"
-}
 
 class bncEphUser : public QObject {
@@ -54,5 +51,5 @@
   const t_eph* ephLast(const QString& prn) {
     if (_eph.contains(prn)) {
-      return _eph[prn]->last;
+      return _eph[prn].back();
     }
     return 0;
@@ -61,28 +58,21 @@
   const t_eph* ephPrev(const QString& prn) {
     if (_eph.contains(prn)) {
-      return _eph[prn]->prev;
+      unsigned nn = _eph[prn].size();
+      if (nn > 1) {
+        return _eph[prn].at(nn-2);
+      }
     }
     return 0;
   }
 
+  const QList<QString> prnList() {return _eph.keys();}
+
  protected:
   virtual void ephBufferChanged() {}
 
-  class t_ephPair {
-   public:
-    t_ephPair(t_eph* lastEph) {
-      last = lastEph;
-      prev = 0;
-    }
-    ~t_ephPair() {
-      delete last;
-      delete prev;
-    }
-    t_eph* last;
-    t_eph* prev;
-  };
-
-  QMutex                    _mutex;
-  QMap<QString, t_ephPair*> _eph;
+ private:
+  QMutex                             _mutex;
+  static const unsigned              _maxQueueSize = 5;
+  QMap<QString, std::deque<t_eph*> > _eph;
 };
 
Index: /trunk/BNC/src/combination/bnccomb.cpp
===================================================================
--- /trunk/BNC/src/combination/bnccomb.cpp	(revision 6442)
+++ /trunk/BNC/src/combination/bnccomb.cpp	(revision 6443)
@@ -127,5 +127,5 @@
 // Constructor
 ////////////////////////////////////////////////////////////////////////////
-bncComb::bncComb() : bncEphUser(true) {
+bncComb::bncComb() : _ephUser(true) {
 
   bncSettings settings;
@@ -382,5 +382,7 @@
     // Check the Ephemeris
     //--------------------
-    if (_eph.find(prn) == _eph.end()) {
+    const t_eph* ephLast = _ephUser.ephLast(prn);
+    const t_eph* ephPrev = _ephUser.ephPrev(prn);
+    if (ephLast == 0) {
       emit newMessage("bncComb: eph not found "  + prn.toAscii(), true);
       delete newCorr;
@@ -388,12 +390,10 @@
     }
     else {
-      t_eph* lastEph = _eph[prn]->last;
-      t_eph* prevEph = _eph[prn]->prev;
-      if      (lastEph && lastEph->IOD() == newCorr->_iod) {
-        newCorr->_eph = lastEph;
-      }
-      else if (lastEph && prevEph && prevEph->IOD() == newCorr->_iod) {
-        newCorr->_eph = prevEph;
-        switchToLastEph(lastEph, newCorr);
+      if      (ephLast->IOD() == newCorr->_iod) {
+        newCorr->_eph = ephLast;
+      }
+      else if (ephPrev && ephPrev->IOD() == newCorr->_iod) {
+        newCorr->_eph = ephPrev;
+        switchToLastEph(ephLast, newCorr);
       }
       else {
@@ -1051,5 +1051,9 @@
     cmbCorr* corr = im.next();
     QString  prn  = corr->_prn;
-    if      (_eph.find(prn) == _eph.end()) {
+
+    const t_eph* ephLast = _ephUser.ephLast(prn);
+    const t_eph* ephPrev = _ephUser.ephPrev(prn);
+
+    if      (ephLast == 0) {
       out << "checkOrbit: missing eph (not found) " << corr->_prn << endl;
       delete corr;
@@ -1062,6 +1066,6 @@
     }
     else {
-      if ( corr->_eph == _eph[prn]->last || corr->_eph == _eph[prn]->prev ) {
-        switchToLastEph(_eph[prn]->last, corr);
+      if ( corr->_eph == ephLast || corr->_eph == ephPrev ) {
+        switchToLastEph(ephLast, corr);
       }
       else {
Index: /trunk/BNC/src/combination/bnccomb.h
===================================================================
--- /trunk/BNC/src/combination/bnccomb.h	(revision 6442)
+++ /trunk/BNC/src/combination/bnccomb.h	(revision 6443)
@@ -12,5 +12,5 @@
 class bncAntex;
 
-class bncComb : public bncEphUser  {
+class bncComb : public QObject {
  Q_OBJECT
  public:
@@ -108,4 +108,5 @@
   QVector<cmbCorr*>& corrs() {return _buffer[_resTime].corrs;}
 
+  QMutex                                 _mutex;
   QList<cmbAC*>                          _ACs;
   bncTime                                _resTime;
@@ -123,4 +124,5 @@
   int                                    _cmbSampl;
   QMap<QString, QMap<t_prn, t_orbCorr> > _orbCorrections;
+  bncEphUser                             _ephUser;
 };
 
Index: /trunk/BNC/src/upload/bncephuploadcaster.cpp
===================================================================
--- /trunk/BNC/src/upload/bncephuploadcaster.cpp	(revision 6442)
+++ /trunk/BNC/src/upload/bncephuploadcaster.cpp	(revision 6443)
@@ -61,16 +61,18 @@
   if (_ephUploadCaster) {
     QByteArray outBuffer;
-    QMapIterator<QString, t_ephPair*> it(_eph);
+
+    QListIterator<QString> it(prnList());
     while (it.hasNext()) {
-      it.next();
+      const t_eph* eph = ephLast(it.next());
 
-      t_eph* eph = it.value()->last;
+      const t_ephGPS*     ephGPS     = dynamic_cast<const t_ephGPS*>(eph);
+      const t_ephGlo*     ephGlo     = dynamic_cast<const t_ephGlo*>(eph);
+      const t_ephGal*     ephGal     = dynamic_cast<const t_ephGal*>(eph);
+      const t_ephSBAS*    ephSBAS    = dynamic_cast<const t_ephSBAS*>(eph);
+      const t_ephCompass* ephCompass = dynamic_cast<const t_ephCompass*>(eph);
+
       unsigned char Array[80];
       int size = 0;
-      t_ephGPS*     ephGPS     = dynamic_cast<t_ephGPS*>(eph);
-      t_ephGlo*     ephGlo     = dynamic_cast<t_ephGlo*>(eph);
-      t_ephGal*     ephGal     = dynamic_cast<t_ephGal*>(eph);
-      t_ephSBAS*    ephSBAS    = dynamic_cast<t_ephSBAS*>(eph);
-      t_ephCompass* ephCompass = dynamic_cast<t_ephCompass*>(eph);
+
       if (ephGPS) {
         size = t_ephEncoder::RTCM3(*ephGPS, Array);
