Index: trunk/BNC/src/combination/bnccomb.cpp
===================================================================
--- trunk/BNC/src/combination/bnccomb.cpp	(revision 11212)
+++ trunk/BNC/src/combination/bnccomb.cpp	(revision 11218)
@@ -43,4 +43,8 @@
 
 const double sigObs        =   0.05;
+
+// level of the combined clocks (regularization condition, see createAmat)
+const double CLK_LEVEL_TAU    = 3600.0; // [s] relaxation of the sum to zero
+const double CLK_LEVEL_MAXGAP =   60.0; // [s] longer gap: sum set to zero again
 
 using namespace std;
@@ -1177,4 +1181,8 @@
   // --------------------------------------
   if (irc == success) {
+    if (_method == filter) {
+      _prevClk[sys].clear();
+      _prevClkTime[sys] = epoTime;
+    }
     for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
       cmbParam* pp = _params[sys][iPar-1];
@@ -1184,4 +1192,9 @@
           // set clock result
           masterCorr[pp->prn]->_dClkResult = pp->xx / t_CST::c;
+          if (_method == filter && masterCorr[pp->prn]->_eph) {
+            t_prevClk& prev = _prevClk[sys][pp->prn];
+            prev.clk = pp->xx;
+            prev.iod = masterCorr[pp->prn]->_eph->IOD();
+          }
           // Add Code Biases from SINEX File
           if (_bsx) {
@@ -2170,13 +2183,65 @@
   }
 
-  // Regularization
-  // --------------
+  // Regularization: level of the combined clocks
+  // ---------------------------------------------
+  // The sum of the combined clocks over the satellites of the epoch is not
+  // fixed to zero in each epoch: a satellite missing in one epoch (e.g. its
+  // correction of the master AC refers to an ephemeris not yet received, at
+  // the BDS ephemeris change every hour) shifted all other clocks of the
+  // system by its clock divided by the number of satellites (BDS: up to 1 m).
+  // Instead, the sum over the satellites also combined in the previous epoch
+  // keeps its value (continuity), relaxing to zero with CLK_LEVEL_TAU, so
+  // that the clocks stay referred to the broadcast clocks in the long run
+  // and a permanent change of the satellites shifts them only slowly. A
+  // previous clock of another ephemeris is converted to the current one
+  // (as in switchToLastEph). Without a previous epoch (start, gap longer
+  // than CLK_LEVEL_MAXGAP) the sum is zero.
+  QSet<int> presetRows;  // conditions with their value set here
   if (_method == filter) {
     const double Ph = 1.e6;
     PP(nObs+1) = Ph;
+    const bncTime epoTime = corrs(sys)[0]->_time;
+    const double  dtPrev  = _prevClkTime[sys].valid() ? epoTime - _prevClkTime[sys] : -1.0;
+    const bool    cont    = dtPrev > 0.0 && dtPrev <= CLK_LEVEL_MAXGAP;
+    double target  = 0.0;
+    int    nCommon = 0;
+    QList<int> allClk;
     for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
       cmbParam* pp = _params[sys][iPar-1];
       if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
            pp->type == cmbParam::clkSat ) {
+        allClk << iPar;
+        if (!cont || !_prevClk[sys].contains(pp->prn) || !masterCorr.contains(pp->prn)) {
+          continue;
+        }
+        const t_prevClk& prev = _prevClk[sys][pp->prn];
+        const t_eph*     eph  = masterCorr[pp->prn]->_eph;
+        double prevClk = prev.clk;
+        if (eph->IOD() != prev.iod) {
+          const t_eph* ephOld = 0;
+          for (const t_eph* ee : {(const t_eph*)_ephUser.ephLast(pp->prn), (const t_eph*)_ephUser.ephPrev(pp->prn)}) {
+            if (ee && ee != eph && ee->IOD() == prev.iod) {
+              ephOld = ee;
+            }
+          }
+          ColumnVector xcNew(6), xcOld(6), vv(3);
+          if (!ephOld ||
+              eph->getCrd(epoTime, xcNew, vv, false) != success ||
+              ephOld->getCrd(epoTime, xcOld, vv, false) != success) {
+            continue;
+          }
+          prevClk -= (xcNew(4) - xcOld(4)) * t_CST::c;
+        }
+        AA(nObs+1, iPar) = 1.0;
+        target += prevClk;
+        ++nCommon;
+      }
+    }
+    if (nCommon > 0) {
+      ll(nObs+1) = (1.0 - min(1.0, dtPrev / CLK_LEVEL_TAU)) * target - DotProduct(AA.Row(nObs+1), x0);
+      presetRows.insert(1);
+    }
+    else {
+      for (int iPar : allClk) {
         AA(nObs+1, iPar) = 1.0;
       }
@@ -2290,5 +2355,5 @@
     // filter. Exception: incomplete nominal datum of a satellite (see above).
     for (int iCon = 1; iCon <= nCon; iCon++) {
-      if (!incrementRows.contains(iCon)) {
+      if (!incrementRows.contains(iCon) && !presetRows.contains(iCon)) {
         ll(nObs+iCon) = -DotProduct(AA.Row(nObs+iCon), x0);
       }
