Index: trunk/BNC/combination/bnccomb.cpp
===================================================================
--- trunk/BNC/combination/bnccomb.cpp	(revision 3028)
+++ trunk/BNC/combination/bnccomb.cpp	(revision 3029)
@@ -190,4 +190,6 @@
   }
 
+  newCorr->AC = AC->name;
+   
   // Reject delayed corrections
   // --------------------------
@@ -197,6 +199,6 @@
   }
 
-  // Check the IOD
-  //--------------
+  // Check the Ephemeris
+  //--------------------
   if (_eph.find(newCorr->prn) == _eph.end()) {
     delete newCorr;
@@ -206,13 +208,16 @@
     t_eph* lastEph = _eph[newCorr->prn]->last;
     t_eph* prevEph = _eph[newCorr->prn]->prev;
-    if (prevEph && prevEph->IOD() == newCorr->iod) {
-      switchToLastEph(AC->name, lastEph, prevEph, newCorr);
-    }
-    else if (!lastEph || lastEph->IOD() != newCorr->iod) {
+    if      (lastEph && lastEph->IOD() == newCorr->iod) {
+      newCorr->eph = lastEph;
+    }
+    else if (prevEph && prevEph->IOD() == newCorr->iod) {
+      newCorr->eph = prevEph;
+    }
+    else {
       delete newCorr;
       return;
     }
-    newCorr->eph = lastEph;
-  }
+  }
+    
 
   // Process all older Epochs (if there are any)
@@ -357,15 +362,14 @@
 // Change the correction so that it refers to last received ephemeris 
 ////////////////////////////////////////////////////////////////////////////
-void bncComb::switchToLastEph(const QString& ACname, const t_eph* lastEph, 
-                              const t_eph* prevEph, t_corr* newCorr) {
+void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
 
   ColumnVector oldXC(4);
   ColumnVector oldVV(3);
-  prevEph->position(newCorr->tt.gpsw(), newCorr->tt.gpssec(), 
-                    oldXC.data(), oldVV.data());
+  corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(), 
+                      oldXC.data(), oldVV.data());
 
   ColumnVector newXC(4);
   ColumnVector newVV(3);
-  lastEph->position(newCorr->tt.gpsw(), newCorr->tt.gpssec(), 
+  lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(), 
                     newXC.data(), newVV.data());
 
@@ -380,28 +384,26 @@
   XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
 
-  newCorr->iod = lastEph->IOD();
-  newCorr->rao    -= dRAO;
-  newCorr->dotRao -= dDotRAO;
-  newCorr->dClk   -= dC;
-
-  QString msg = "switch " + newCorr->prn 
-    + QString(" %1 -> %2 %3").arg(prevEph->IOD(),3)
+  QString msg = "switch " + corr->prn 
+    + QString(" %1 -> %2 %3").arg(corr->iod,3)
     .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
 
-  // Check/change the static offset parameters
-  // -----------------------------------------
-  for (int iPar = 1; iPar <= _params.size(); iPar++) {
-    cmbParam* pp = _params[iPar-1];
-    if (pp->type == cmbParam::Sat_offset &&
-        pp->prn  == newCorr->prn         &&
-        pp->AC   == ACname) {
-      if (pp->iod != lastEph->IOD()) {
-        pp->iod = lastEph->IOD();
-        msg += " need corr ";
-      }
-    }
-  }
-
   emit newMessage(msg.toAscii(), false);
+
+  corr->iod     = lastEph->IOD();
+  corr->eph     = lastEph;
+  corr->rao    -= dRAO;
+  corr->dotRao -= dDotRAO;
+  corr->dClk   -= dC;
+
+//  for (int iPar = 1; iPar <= _params.size(); iPar++) {
+//    cmbParam* pp = _params[iPar-1];
+//    if (pp->type == cmbParam::Sat_offset           &&
+//        pp->prn == corr->prn && pp->AC == corr->AC) {
+//      if (pp->iod != corr->iod) {
+//        pp->xx  += dC * t_CST::c;
+//        pp->iod = corr->iod;
+//      }
+//    }
+//  }
 }
 
@@ -452,8 +454,24 @@
   while (itEpo.hasNext()) {
     cmbEpoch* epo = itEpo.next();
-    QMapIterator<QString, t_corr*> itCorr(epo->corr);
+    QMutableMapIterator<QString, t_corr*> itCorr(epo->corr);
     while (itCorr.hasNext()) {
       itCorr.next();
-      ++nObs;
+      t_corr* corr = itCorr.value();
+
+      // Switch to new ephemeris
+      // -----------------------
+      t_eph* lastEph = _eph[corr->prn]->last;
+      if (lastEph == corr->eph) {      
+        ++nObs;
+      }
+      else {
+        if (corr->eph == _eph[corr->prn]->prev) {
+          switchToLastEph(lastEph, corr);
+          ++nObs;
+        }
+        else {
+          itCorr.remove();
+        }
+      }
     }
   }
@@ -528,5 +546,5 @@
     it.next();
     t_corr* corr = it.value();
-    t_eph* eph = corr->eph;
+    const t_eph* eph = corr->eph;
     if (eph) {
       double xx, yy, zz, cc;
