Index: trunk/BNC/src/ssrQc.cpp
===================================================================
--- trunk/BNC/src/ssrQc.cpp	(revision 11212)
+++ trunk/BNC/src/ssrQc.cpp	(revision 11214)
@@ -259,5 +259,6 @@
            << " completeness w.r.t. healthy broadcast ephemerides," << endl
            << "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 > "
+           << " with the other ACs, yaw angle, code biases of the reference signals,"
+           << " code biases of APC and CoM streams, clock jumps > "
            << MAX_CLK_JUMP << " m, largest orbit corrections, VTEC models (system V)" << endl
            << "Reference signals of the clocks: " << t_ssrRefSig::currentString().toStdString() << endl;
@@ -457,4 +458,5 @@
       storeHist(&corr, 0);
     }
+    _orbFormat[QString::fromStdString(corr._staID)] = corr._ssrFormat;
     if (!selected(corr._staID)) continue;
     QString prn = QString::fromStdString(corr._prn.toString());
@@ -979,4 +981,105 @@
       }
       deviating(compare(1, QString()), QString("the median of the other ACs (at least %1 solutions)").arg(MIN_VOTE));
+    }
+  }
+}
+
+// Code biases of an APC stream compared with the CoM stream of the same
+// solution and format (SSRA00GMV0 / SSRC00GMV0), IGS-SSR and old RTCM-SSR
+// only (new RTCM-SSR carries its own satellite antenna model, and the
+// reference point is left to the provider). Following the IGS SSR
+// convention, users of an APC stream reduce the satellite PCOs of all
+// frequencies by the PCO of the reference frequency themselves, so the code
+// biases of both streams have to be equal. Differences equal to
+// z(f) - z(ref) of the ANTEX file show frequency-dependent PCO differences in
+// the biases of the APC stream, which such users apply twice (ionosphere-free
+// combination of the reference signal biases z(IF) - z(ref) instead of 0).
+////////////////////////////////////////////////////////////////////////////
+void t_ssrQc::compareApcComBiases(const QString& staID, char sys, const bncTime& tt, QStringList& lines) {
+  const double MAX_DIFF = 0.02;  // [m] equal biases (resolution 0.01 m, slightly different epochs)
+  if (!staID.startsWith("SSRA")) {
+    return;
+  }
+  const QString comID = "SSRC" + staID.mid(4);
+  if (!_cbLast.contains(staID) || !_cbLast.contains(comID)) {
+    return;
+  }
+  // format of the latest orbit corrections (IGS-SSR: ssrUnknown)
+  if (_orbFormat.value(staID, ssrUnknown) == ssrRtcmNew || _orbFormat.value(comID, ssrUnknown) == ssrRtcmNew) {
+    return;
+  }
+  // reference frequency of the APC (IGS SSR v1.00, table 2)
+  t_frequency::type refFrq;
+  switch (sys) {
+    case 'G': refFrq = t_frequency::G1; break;
+    case 'R': refFrq = t_frequency::R1; break;
+    case 'E': refFrq = t_frequency::E1; break;
+    case 'C': refFrq = t_frequency::C2; break;
+    case 'J': refFrq = t_frequency::J1; break;
+    case 'S': refFrq = t_frequency::S1; break;
+    case 'I': refFrq = t_frequency::I5; break;
+    default: return;
+  }
+  QSet<QString> sats;
+  unsigned numBias = 0, numPco = 0;
+  double   sumSqr = 0.0, sumSqrRes = 0.0, maxDiff = 0.0;
+  QString  maxStr;
+  const QMap<QString, QMap<QString, double> >& apc = _cbLast[staID];
+  const QMap<QString, QMap<QString, double> >& com = _cbLast[comID];
+  for (auto itP = apc.constBegin(); itP != apc.constEnd(); ++itP) {
+    const QString& prn = itP.key();
+    if (prn[0].toLatin1() != sys || !com.contains(prn)) {
+      continue;
+    }
+    const QMap<QString, double>& bc = com[prn];
+    for (auto itS = itP.value().constBegin(); itS != itP.value().constEnd(); ++itS) {
+      const QString& sig = itS.key();
+      if (!bc.contains(sig) || sig.isEmpty()) {
+        continue;
+      }
+      double diff = itS.value() - bc[sig];
+      sats.insert(prn);
+      numBias++;
+      sumSqr += diff * diff;
+      if (fabs(diff) > fabs(maxDiff)) {
+        maxDiff = diff;
+        maxStr  = QString("%1 C%2").arg(prn).arg(sig);
+      }
+      if (_antex) {
+        // satCorr() at nadir 0 (PCV pattern at zenith 0 of the satellite) gives -z(f)
+        bool foundF = false, foundR = false;
+        double corrF = _antex->satCorr(prn, t_frequency::toFreq(sys, sig[0].toLatin1()), M_PI / 2.0, 0.0, foundF, tt);
+        double corrR = _antex->satCorr(prn, refFrq, M_PI / 2.0, 0.0, foundR, tt);
+        if (foundF && foundR) {
+          double res = diff - (corrR - corrF);   // expected z(f) - z(ref)
+          sumSqrRes += res * res;
+          numPco++;
+        }
+      }
+    }
+  }
+  if (numBias == 0) {
+    return;
+  }
+  double rms = sqrt(sumSqr / numBias);
+  if (fabs(maxDiff) <= MAX_DIFF) {
+    lines << QString("code biases equal to those of the CoM stream %1 (%2 satellites, %3 biases)")
+             .arg(comID).arg(sats.size()).arg(numBias);
+    return;
+  }
+  lines << QString("code biases differ from those of the CoM stream %1: RMS %2 m, max %3 m (%4) "
+                   "(%5 satellites, %6 biases)")
+           .arg(comID).arg(rms, 0, 'f', 3).arg(maxDiff, 0, 'f', 3).arg(maxStr).arg(sats.size()).arg(numBias);
+  if (numPco > 0) {
+    double rmsRes = sqrt(sumSqrRes / numPco);
+    if (rmsRes < MAX_DIFF || rmsRes < 0.2 * rms) {
+      lines << QString("code bias differences APC - CoM equal the satellite PCO differences z(f) - z(ref) of the "
+                       "ANTEX file (RMS of the residuals %1 m, %2 biases): frequency-dependent PCOs in the biases "
+                       "of the APC stream, applied twice by users reducing the PCOs by the PCO of the reference "
+                       "frequency (IGS SSR convention)").arg(rmsRes, 0, 'f', 3).arg(numPco);
+    }
+    else {
+      lines << QString("code bias differences APC - CoM not explained by the satellite PCO differences of the "
+                       "ANTEX file (RMS of the residuals %1 m, %2 biases)").arg(rmsRes, 0, 'f', 3).arg(numPco);
     }
   }
@@ -1819,4 +1922,5 @@
       }
       compareCodeBiases(staID, sys, lines);
+      compareApcComBiases(staID, sys, endTime, lines);
       if (_phaseSignals.contains(staSys)) {
         QStringList sigs = _phaseSignals[staSys].values();
