Index: trunk/BNC/src/ssrQc.cpp
===================================================================
--- trunk/BNC/src/ssrQc.cpp	(revision 11195)
+++ trunk/BNC/src/ssrQc.cpp	(revision 11212)
@@ -77,4 +77,9 @@
   const double VTEC_GRID_LAT  = 10.0;   // [deg] grid of the VTEC evaluation, latitudes -80 ... 80
   const double VTEC_GRID_LON  = 15.0;   // [deg]
+  const double MW_SAMPL       = 300.0;  // [s] sampling of the Melbourne-Wuebbena check
+  const double MW_MAX_AGE     = 900.0;  // [s] phase biases older than this are not used
+  const int    MW_MIN_SAT     = 4;      // satellites needed for the common offset
+  const double MW_OK          = 0.10;   // [cycles] RMS of the fractional parts: consistent below,
+  const double MW_BAD         = 0.15;   //          not consistent above (uniform: 0.29)
 
   double tKey(const bncTime& tt) {
@@ -253,5 +258,6 @@
            << "Checks: epochs and update intervals, gaps (interval > 2 x max(declared, median)), latency,"
            << " completeness w.r.t. healthy broadcast ephemerides," << endl
-           << "IOD matching, code and phase bias signals, yaw angle, code biases of the reference signals, clock jumps > "
+           << "IOD matching, code and phase bias signals, phase bias indicators, Melbourne-Wuebbena consistency"
+           << " with the other ACs, yaw angle, code biases of the reference signals, clock jumps > "
            << MAX_CLK_JUMP << " m, largest orbit corrections, VTEC models (system V)" << endl
            << "Reference signals of the clocks: " << t_ssrRefSig::currentString().toStdString() << endl;
@@ -311,4 +317,15 @@
     compareEpoch(_nextCmpEpoch);
     _nextCmpEpoch = _nextCmpEpoch + CMP_SAMPL;
+  }
+  // Melbourne-Wuebbena check of the phase biases
+  if (!_pbLast.isEmpty()) {
+    if (!_nextMwCmp.valid()) {
+      double sec = ceil(time.gpssec() / MW_SAMPL) * MW_SAMPL;
+      _nextMwCmp = bncTime(time.gpsw(), sec);
+    }
+    while (time - _nextMwCmp >= CMP_DELAY) {
+      compareMw(_nextMwCmp);
+      _nextMwCmp = _nextMwCmp + MW_SAMPL;
+    }
   }
   // VTEC comparison
@@ -545,16 +562,45 @@
   QMutexLocker locker(&_mutex);
   for (const t_satPhaseBias& bias : phaseBiases) {
+    QString staID = QString::fromStdString(bias._staID);
+    QString prn   = QString::fromStdString(bias._prn.toString());
+    // latest biases for the Melbourne-Wuebbena check (also as other AC)
+    if (!_excluded.contains(staID) || staID == _reference) {
+      t_pbLast& pl = _pbLast[staID][prn];
+      pl.time = bias._time;
+      pl.values.clear();
+      for (const t_frqPhaseBias& frqBias : bias._bias) {
+        pl.values[QString::fromStdString(frqBias._rnxType2ch)] = frqBias._value;
+      }
+    }
     if (!selected(bias._staID)) continue;
     checkInterval(bias._time);
-    newEpoch(bias._staID, bias._prn.system(), PBIAS, bias._time, bias._updateInt,
-             QString::fromStdString(bias._prn.toString()));
-    QString staSys = QString("%1 %2").arg(bias._staID.c_str()).arg(bias._prn.system());
+    newEpoch(bias._staID, bias._prn.system(), PBIAS, bias._time, bias._updateInt, prn);
+    QString staSys = QString("%1 %2").arg(staID).arg(bias._prn.system());
+    t_satStat& stat = _satStat[staID + ' ' + prn];
+    t_pbIndStat& ind = _pbIndStat[staSys];
+    ind.numRec++;
+    ind.format[(bias._ssrFormat == ssrRtcmNew) ? "new RTCM-SSR" :
+               (bias._ssrFormat == ssrRtcmOld) ? "old RTCM-SSR" : "IGS-SSR"]++;
+    if (bias._ssrFormat != ssrRtcmNew) {  // new RTCM-SSR: no consistency indicators
+      ind.dispInd[bias._dispBiasConsistInd]++;
+      ind.mwInd[bias._MelbWuebConsistInd]++;
+    }
+    bool jumped = false;  // counted once per record, not per signal
     for (const t_frqPhaseBias& frqBias : bias._bias) {
-      _phaseSignals[staSys].insert(QString::fromStdString(frqBias._rnxType2ch));
+      QString sig = QString::fromStdString(frqBias._rnxType2ch);
+      _phaseSignals[staSys].insert(sig);
+      ind.intInd[sig][frqBias._fixIndicator]++;
+      ind.wlInd[sig][frqBias._fixWideLaneIndicator]++;
+      QString jumpKey = staID + ' ' + prn + ' ' + sig;
+      if (_pbJumpLast.contains(jumpKey) && _pbJumpLast[jumpKey] != frqBias._jumpCounter) {
+        jumped = true;
+      }
+      _pbJumpLast[jumpKey] = frqBias._jumpCounter;
+    }
+    if (jumped) {
+      stat.pbJumps++;
     }
     // Yaw angle: new RTCM-SSR has an indicator, old RTCM-SSR and IGS-SSR always
     // carry the field, providers without attitude information send zeros
-    t_satStat& stat = _satStat[QString::fromStdString(bias._staID) + ' ' +
-                               QString::fromStdString(bias._prn.toString())];
     stat.numPB++;
     bool yawProvided = (bias._ssrFormat == ssrRtcmNew) ? (bias._satYawInfoInd != 0)
@@ -570,4 +616,111 @@
       yl.yaw  = bias._yaw;
       yl.rate = bias._yawRate;
+    }
+  }
+}
+
+// Melbourne-Wuebbena combination of the phase and code biases of the
+// reference signals of a stream and satellite in wide-lane cycles:
+//   (f1 b_L1 - f2 b_L2) / (f1 - f2) - (f1 b_C1 + f2 b_C2) / (f1 + f2)
+// The phase bias of a frequency is that of the reference signal or, if not
+// provided, of another signal of the frequency; the code biases are those
+// of the reference signals (as used for the clocks and a combination; with
+// the code bias of the phase signal instead, e.g. C1C for CNES' L1C, CNES and
+// NRCan agreed less on 2026-10-02)
+////////////////////////////////////////////////////////////////////////////
+bool t_ssrQc::mwBias(const QString& staID, const QString& prn, char sys, const bncTime& tt, double& mwCyc) {
+  QString sig1, sig2;
+  t_frequency::type frq1, frq2;
+  if (sys == 'R' || !refSignals(sys, sig1, sig2, frq1, frq2)) {
+    return false;  // GLONASS FDMA: no integer wide-lane ambiguities between satellites
+  }
+  if (!_pbLast.value(staID).contains(prn) || !_cbLast.value(staID).contains(prn)) {
+    return false;
+  }
+  const t_pbLast& pl = _pbLast[staID][prn];
+  if (fabs(tt - pl.time) > MW_MAX_AGE) {
+    return false;
+  }
+  const QMap<QString, double>& cb = _cbLast[staID][prn];
+  auto biases = [&pl, &cb](const QString& sig, double& phase, double& code) {
+    QString used;
+    if (pl.values.contains(sig)) {
+      used = sig;
+    }
+    else {
+      QMapIterator<QString, double> it(pl.values);
+      while (it.hasNext()) {
+        it.next();
+        if (it.key()[0] == sig[0]) {
+          used = it.key();
+          break;
+        }
+      }
+    }
+    if (used.isEmpty()) {
+      return false;
+    }
+    if (!cb.contains(sig)) {
+      return false;
+    }
+    phase = pl.values[used];
+    code  = cb[sig];
+    return true;
+  };
+  double pb1, pb2, cb1, cb2;
+  if (!biases(sig1, pb1, cb1) || !biases(sig2, pb2, cb2)) {
+    return false;
+  }
+  double f1 = t_CST::freq(frq1, 0);
+  double f2 = t_CST::freq(frq2, 0);
+  double mw = (f1 * pb1 - f2 * pb2) / (f1 - f2) - (f1 * cb1 + f2 * cb2) / (f1 + f2);
+  mwCyc = mw / (t_CST::c / (f1 - f2));
+  return true;
+}
+
+// Melbourne-Wuebbena check of one epoch: per pair of streams of different
+// ACs and system, the fractional parts of the MW differences of the
+// satellites about their common (circular mean) offset
+////////////////////////////////////////////////////////////////////////////
+void t_ssrQc::compareMw(const bncTime& tt) {
+  QStringList streams = _pbLast.keys();
+  for (const QString& staA : streams) {
+    if (!selected(staA.toStdString())) continue;
+    for (const QString& staB : streams) {
+      if (staB == staA || !votes(staB) || acOf(staB) == acOf(staA)) continue;
+      QMap<char, QMap<QString, double> > diff;  // system, PRN: MW difference [cycles]
+      for (const QString& prn : _pbLast[staA].keys()) {
+        char   sys = prn[0].toLatin1();
+        double mwA, mwB;
+        if (mwBias(staA, prn, sys, tt, mwA) && mwBias(staB, prn, sys, tt, mwB)) {
+          diff[sys][prn] = mwA - mwB;
+        }
+      }
+      QMapIterator<char, QMap<QString, double> > itSys(diff);
+      while (itSys.hasNext()) {
+        itSys.next();
+        const QMap<QString, double>& dd = itSys.value();
+        if (dd.size() < MW_MIN_SAT) continue;
+        double sSin = 0.0, sCos = 0.0;
+        for (double val : dd) {
+          sSin += sin(2.0 * M_PI * val);
+          sCos += cos(2.0 * M_PI * val);
+        }
+        double offset = atan2(sSin, sCos) / (2.0 * M_PI);
+        t_mwStat& ms = _mwStat[staA][staB][itSys.key()];
+        ms.numEpo++;
+        ms.offset = offset;
+        QMapIterator<QString, double> itD(dd);
+        while (itD.hasNext()) {
+          itD.next();
+          double res = itD.value() - offset;
+          res -= floor(res + 0.5);   // fractional part in [-0.5, 0.5)
+          ms.numRes++;
+          ms.sRes2 += res * res;
+          QPair<unsigned, double>& sr = ms.satRes[itD.key()];
+          sr.first++;
+          sr.second += res * res;
+        }
+      }
     }
   }
@@ -1537,5 +1690,5 @@
       double maxEarly = 0.0;
       QMap<QString, unsigned> missOrb, missClk, missCB, missPB, iodUnknown, unhealthy, noEph,
-                              jumps, missRef, noYaw, yawPartly;
+                              jumps, missRef, noYaw, yawPartly, pbJumps;
       unsigned numPB = 0, numYaw = 0, yawSats = 0;
       double maxRadial = 0.0, maxAlongCross = 0.0;
@@ -1576,4 +1729,5 @@
         if (stat.noEph)        noEph[prn]      = stat.noEph;
         if (stat.clkJumps)     jumps[prn]      = stat.clkJumps;
+        if (stat.pbJumps)      pbJumps[prn]    = stat.pbJumps;
         if (stat.maxRadial > maxRadial) {
           maxRadial    = stat.maxRadial;
@@ -1670,4 +1824,94 @@
         lines << "phase bias signals: " + sigs.join(" ");
       }
+      if (_pbIndStat.contains(staSys)) {
+        const t_pbIndStat& ind = _pbIndStat[staSys];
+        // value list "1" or "0 (12 %), 1 (88 %)"
+        auto values = [](const QMap<int, unsigned>& counts) {
+          unsigned total = 0;
+          for (unsigned nn : counts) total += nn;
+          QStringList parts;
+          QMapIterator<int, unsigned> it(counts);
+          while (it.hasNext()) {
+            it.next();
+            parts << ((counts.size() == 1) ? QString::number(it.key())
+                                           : QString("%1 (%2 %)").arg(it.key())
+                                             .arg(100.0 * it.value() / total, 0, 'f', 0));
+          }
+          return parts.join(", ");
+        };
+        QStringList formats = ind.format.keys();
+        QString line = "phase bias format and indicators: " + formats.join("/");
+        if (!ind.mwInd.isEmpty()) {
+          line += QString(", dispersive bias consistency indicator %1, MW consistency indicator %2")
+                  .arg(values(ind.dispInd)).arg(values(ind.mwInd));
+        }
+        else {
+          line += " (no consistency indicators)";
+        }
+        lines << line;
+        QStringList sigParts;
+        QMapIterator<QString, QMap<int, unsigned> > itSig(ind.intInd);
+        while (itSig.hasNext()) {
+          itSig.next();
+          sigParts << QString("%1 integer %2 / wide-lane %3").arg(itSig.key())
+                      .arg(values(itSig.value())).arg(values(ind.wlInd.value(itSig.key())));
+        }
+        if (!sigParts.isEmpty()) {
+          lines << "phase bias integer / wide-lane integer indicators: " + sigParts.join("; ");
+        }
+        addSats("phase bias discontinuity counter changes", pbJumps);
+      }
+      bool mwAny = false;
+      for (const QMap<char, t_mwStat>& mm : _mwStat.value(staID)) {
+        mwAny = mwAny || mm.contains(sys);
+      }
+      QString mwSig1, mwSig2;
+      t_frequency::type mwFrq1, mwFrq2;
+      if (mwAny && refSignals(sys, mwSig1, mwSig2, mwFrq1, mwFrq2)) {
+        // phase signals used (see mwBias)
+        QStringList used;
+        QStringList pSigs = _phaseSignals.value(staSys).values();
+        pSigs.sort();
+        for (const QString& sig : {mwSig1, mwSig2}) {
+          QString uu = pSigs.contains(sig) ? sig : QString();
+          for (const QString& ps : pSigs) {
+            if (uu.isEmpty() && ps[0] == sig[0]) uu = ps;
+          }
+          used << "L" + uu;
+        }
+        lines << QString("MW check: phase biases %1 with the code biases C%2 C%3 of the reference signals, "
+                         "wide-lane cycles (%4 m)")
+                 .arg(used.join(" ")).arg(mwSig1).arg(mwSig2)
+                 .arg(t_CST::c / (t_CST::freq(mwFrq1, 0) - t_CST::freq(mwFrq2, 0)), 0, 'f', 3);
+      }
+      if (_mwStat.contains(staID)) {
+        QMapIterator<QString, QMap<char, t_mwStat> > itOther(_mwStat[staID]);
+        while (itOther.hasNext()) {
+          itOther.next();
+          if (!itOther.value().contains(sys)) continue;
+          const t_mwStat& ms = itOther.value()[sys];
+          if (ms.numRes == 0) continue;
+          double rms = sqrt(ms.sRes2 / ms.numRes);
+          QString verdict = (rms < MW_OK)  ? "consistent (integer wide-lane biases)" :
+                            (rms > MW_BAD) ? "NOT consistent" : "not clearly consistent";
+          lines << QString("MW biases vs. %1 (%2 epochs, %3 satellites): fractional parts about the "
+                           "common offset %4 cycles: RMS %5 cycles, %6")
+                   .arg(itOther.key()).arg(ms.numEpo).arg(ms.satRes.size())
+                   .arg(ms.offset, 0, 'f', 2).arg(rms, 0, 'f', 3).arg(verdict);
+          QStringList dev;
+          QMapIterator<QString, QPair<unsigned, double> > itS(ms.satRes);
+          while (itS.hasNext()) {
+            itS.next();
+            double rmsSat = sqrt(itS.value().second / itS.value().first);
+            if (rmsSat > MW_BAD) {
+              dev << QString("%1(%2)").arg(itS.key()).arg(rmsSat, 0, 'f', 2);
+            }
+          }
+          if (!dev.isEmpty() && rms < MW_BAD) {
+            lines << QString("MW biases vs. %1: satellites with RMS > %2 cycles: %3")
+                     .arg(itOther.key()).arg(MW_BAD, 0, 'f', 2).arg(dev.join(" "));
+          }
+        }
+      }
       if (numPB) {
         if (numYaw == 0) {
@@ -1768,4 +2012,6 @@
   _cmpEpochs.clear();
   _attEvents.clear();
+  _pbIndStat.clear();
+  _mwStat.clear();
   for (QMap<QString, t_vtecStat>::iterator it = _vtecStat.begin(); it != _vtecStat.end(); ++it) {
     t_vtecStat fresh;
