Index: trunk/BNC/src/bncmain.cpp
===================================================================
--- trunk/BNC/src/bncmain.cpp	(revision 9675)
+++ trunk/BNC/src/bncmain.cpp	(revision 9676)
@@ -256,5 +256,5 @@
       "   cmbMethodFilter {Combination approach [character string: Single-Epoch|Filter]\n"
       "   cmbMaxres       {Clock outlier residuum threshold in meters [floating-point number]\n"
-      "   cmbSampl        {Clock sampling rate [integer number of seconds: 10|20|30|40|50|60]}\n"
+      "   cmbSampl        {Clock sampling rate [integer number of seconds: 0|10|20|30|40|50|60]}\n"
       "   cmbGps          {GPS correction usage [integer number: 0=no,2=yes]}\n"
       "   cmbGlo          {GLONASS correction usage [integer number: 0=no,2=yes]}\n"
Index: trunk/BNC/src/bncwindow.cpp
===================================================================
--- trunk/BNC/src/bncwindow.cpp	(revision 9675)
+++ trunk/BNC/src/bncwindow.cpp	(revision 9676)
@@ -482,5 +482,5 @@
 
   _cmbSamplSpinBox = new QSpinBox;
-  _cmbSamplSpinBox->setMinimum(10);
+  _cmbSamplSpinBox->setMinimum(0);
   _cmbSamplSpinBox->setMaximum(60);
   _cmbSamplSpinBox->setSingleStep(10);
@@ -1267,15 +1267,15 @@
   cmbLayout->addWidget(_cmbSamplSpinBox,                                         6,  7, Qt::AlignRight);
   cmbLayout->addWidget(new QLabel("GNSS"),                                       7,  6, Qt::AlignLeft);
-  cmbLayout->addWidget(new QLabel("GPS (1W/2W)"),                                7,  7);
+  cmbLayout->addWidget(new QLabel("GPS (C1W/C2W)"),                                7,  7);
   cmbLayout->addWidget(_cmbGpsCheckBox,                                          7,  8);
-  cmbLayout->addWidget(new QLabel("GLONASS (1P/2P)"),                            7,  9);
+  cmbLayout->addWidget(new QLabel("GLONASS (C1P/C2P)"),                          7,  9);
   cmbLayout->addWidget(_cmbGloCheckBox,                                          7, 10);
-  cmbLayout->addWidget(new QLabel("Galileo (1C/5Q)"),                            7, 11);
+  cmbLayout->addWidget(new QLabel("Galileo (C1C/C5Q)"),                          7, 11);
   cmbLayout->addWidget(_cmbGalCheckBox,                                          7, 12);
-  cmbLayout->addWidget(new QLabel("Beidou (2I/6I)"),                             7, 13);
+  cmbLayout->addWidget(new QLabel("Beidou (C2I/C6I)"),                           7, 13);
   cmbLayout->addWidget(_cmbBdsCheckBox,                                          7, 14);
-  cmbLayout->addWidget(new QLabel("QZSS (1C/2L)"),                               8,  7);
+  cmbLayout->addWidget(new QLabel("QZSS (C1C/C2L)"),                             8,  7);
   cmbLayout->addWidget(_cmbQzssCheckBox,                                         8,  8);
-  cmbLayout->addWidget(new QLabel("SBAS (1C/5Q)"),                               8,  9);
+  cmbLayout->addWidget(new QLabel("SBAS (C1C/C5Q)"),                             8,  9);
   cmbLayout->addWidget(_cmbSbasCheckBox,                                         8, 10);
   cmbLayout->addWidget(new QLabel("IRNSS"),                                      8, 11);
@@ -1495,5 +1495,5 @@
   _cmbMethodComboBox->setWhatsThis(tr("<p>Select a clock combination approach. Options are 'Single-Epoch' and Kalman 'Filter'.</p><p>It is suggested to use the Kalman filter approach for the purpose of Precise Point Positioning. <i>[key: cmbMethod]</i></p>"));
   _cmbMaxresLineEdit->setWhatsThis(tr("<p>BNC combines all incoming clocks according to specified weights. Individual clock estimates that differ by more than 'Maximal residuum' meters from the average of all clocks will be ignored.<p></p>It is suggested to specify a value of about 0.2 m for the Kalman filter combination approach and a value of about 3.0 meters for the Single-Epoch combination approach.</p><p>Default is a value of '999.0'. <i>[key: cmbMaxres]</i></p>"));
-  _cmbSamplSpinBox->setWhatsThis(tr("<p>Select a combination Sampling interval for the clocks. Clock corrections will be produced following that interval.</p><p>A value of 10 sec may be an appropriate choice. <i>[key: cmbSampl]</i></p>"));
+  _cmbSamplSpinBox->setWhatsThis(tr("<p>Select a combination Sampling interval for the clocks. Clock corrections will be produced following that interval.</p><p>A value of 10 sec may be an appropriate choice. A value of zero '0' tells BNC to use all available samples. <i>[key:  ]</i></p>"));
   _cmbGpsCheckBox->setWhatsThis(tr("<p>GPS clock corrections shall be combined. <i>[key: cmbGps]</i></p>"));
   _cmbGloCheckBox->setWhatsThis(tr("<p>GLONASS clock corrections shall be combined; GPS Broadcast ephemeris and corrections are required. <i>[key: cmbGlo]</i></p>"));
Index: trunk/BNC/src/combination/bnccomb.cpp
===================================================================
--- trunk/BNC/src/combination/bnccomb.cpp	(revision 9675)
+++ trunk/BNC/src/combination/bnccomb.cpp	(revision 9676)
@@ -21,4 +21,5 @@
 
 #include "bnccomb.h"
+#include <combination/bncbiassnx.h>
 #include "bnccore.h"
 #include "upload/bncrtnetdecoder.h"
@@ -130,5 +131,5 @@
   _cmbSampl = settings.value("cmbSampl").toInt();
   if (_cmbSampl <= 0) {
-    _cmbSampl = 10;
+    _cmbSampl = 5;
   }
   _useGps = (Qt::CheckState(settings.value("cmbGps").toInt()) == Qt::Checked) ? true : false;
@@ -286,4 +287,22 @@
   }
 
+
+  // Bias SINEX File
+  // ---------------
+  _bsx = 0;
+  QString bsxFileName = settings.value("cmbBsxFile").toString();
+  if (!bsxFileName.isEmpty()) {
+    _bsx = new bncBiasSnx();
+    if (_bsx->readFile(bsxFileName) != success) {
+      emit newMessage("wrong Bias SINEX file", true);
+      delete _bsx;
+      _bsx = 0;
+    }
+  }
+  if (_bsx) {
+    _nextShotTimeBsx = QTime(23, 59, 59, 999);
+  }
+
+
   // Maximal Residuum
   // ----------------
@@ -306,4 +325,5 @@
   }
   delete _antex;
+  delete _bsx;
   QMapIterator<char, unsigned> itSys(_cmbSysPrn);
   while (itSys.hasNext()) {
@@ -321,4 +341,24 @@
 
 }
+
+void bncComb::slotReadBiasSnxFile() {
+  bncSettings settings;
+  QString bsxFileName = settings.value("cmbBsxFile").toString();
+  if (!bsxFileName.isEmpty()) {
+    _bsx = new bncBiasSnx();
+  }
+
+  if (_bsx->readFile(bsxFileName) != success) {
+    emit newMessage("wrong Bias SINEX file", true);
+    delete _bsx;
+    _bsx = 0;
+  }
+#ifdef BNC_DEBUG_CMB
+  else {
+    emit newMessage("Successfully read Bias SINEX file", true);
+  }
+#endif
+}
+
 
 // Remember orbit corrections
@@ -358,5 +398,5 @@
 }
 
-// Remember satllite code biases
+// Remember Satellite Code Biases
 ////////////////////////////////////////////////////////////////////////////
 void bncComb::slotNewCodeBiases(QList<t_satCodeBias> satCodeBiases) {
@@ -442,5 +482,7 @@
     // --------------------
     if (_resTime.valid() && clkCorr._time <= _resTime) {
+#ifdef BNC_DEBUG_CMB
       emit newMessage("bncComb: old correction: " + acName.toLatin1() + " " + prn.mid(0,3).toLatin1(), true);
+#endif
       continue;
     }
@@ -478,5 +520,7 @@
     t_eph* ephPrev = _ephUser.ephPrev(prn);
     if (ephLast == 0) {
+#ifdef BNC_DEBUG_CMB
       emit newMessage("bncComb: eph not found for "  + prn.mid(0,3).toLatin1(), true);
+#endif
       delete newCorr;
       continue;
@@ -485,5 +529,7 @@
              ephLast->checkState() == t_eph::outdated ||
              ephLast->checkState() == t_eph::unhealthy) {
-      emit newMessage("bncComb: ephLast not ok for "  + prn.mid(0,3).toLatin1(), true);
+#ifdef BNC_DEBUG_CMB
+      emit newMessage("bncComb: ephLast not ok (checkState: " +  ephLast->checkStateToString().toLatin1() + ") for "  + prn.mid(0,3).toLatin1(), true);
+#endif
       delete newCorr;
       continue;
@@ -499,6 +545,8 @@
       }
       else {
+#ifdef BNC_DEBUG_CMB
         emit newMessage("bncComb: eph not found for "  + prn.mid(0,3).toLatin1() +
                         QString(" with IOD %1").arg(newCorr->_iod).toLatin1(), true);
+#endif
         delete newCorr;
         continue;
@@ -519,28 +567,33 @@
       }
       else {
-        t_satCodeBias& satCodeBias = storage[clkCorr._prn];
-        QMap<t_frequency::type, double> codeBias;
-        for (unsigned ii = 1; ii < t_lcRefSig::cIF; ii++) {
-          t_frequency::type frqType = t_lcRefSig::toFreq(sys,  static_cast<t_lcRefSig::type>(ii));
+        newCorr->_satCodeBias = storage[clkCorr._prn];
+        QMap<t_frequency::type, double> codeBiasesRefSig;
+        for (unsigned ii = 1; ii < cmbRefSig::cIF; ii++) {
+          t_frequency::type frqType = cmbRefSig::toFreq(sys,  static_cast<cmbRefSig::type>(ii));
           char frqNum = t_frequency::toString(frqType)[1];
-          char attrib = t_lcRefSig::toAttrib(sys,  static_cast<t_lcRefSig::type>(ii));
-          QString obsType = QString("%1%2").arg(frqNum).arg(attrib);
-          for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
-            const t_frqCodeBias& bias = satCodeBias._bias[ii];
-            if (obsType.toStdString() == bias._rnxType2ch) {
-              codeBias[frqType] = bias._value;
+          char attrib = cmbRefSig::toAttrib(sys,  static_cast<cmbRefSig::type>(ii));
+          QString rnxType2ch = QString("%1%2").arg(frqNum).arg(attrib);
+          for (unsigned ii = 0; ii < newCorr->_satCodeBias._bias.size(); ii++) {
+            const t_frqCodeBias& bias = newCorr->_satCodeBias._bias[ii];
+            if (rnxType2ch.toStdString() == bias._rnxType2ch) {
+              codeBiasesRefSig[frqType] = bias._value;
             }
           }
         }
+        if (codeBiasesRefSig.size() < 2) {
+          delete newCorr;
+          continue;
+        }
         map<t_frequency::type, double> codeCoeff;
         double channel = double(newCorr->_eph->slotNum());
-        t_lcRefSig::coeff(sys, t_lcRefSig::cIF, channel, codeCoeff);
+        cmbRefSig::coeff(sys, cmbRefSig::cIF, channel, codeCoeff);
         map<t_frequency::type, double>::const_iterator it;
         for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
           t_frequency::type frqType = it->first;
-          newCorr->_codeBiasIF += it->second * codeBias[frqType];
-        }
-      }
-      cout <<  acName.toStdString() << " " << clkCorr._prn.toString().c_str() << " _codeBiasIF: " << newCorr->_codeBiasIF << endl;
+          newCorr->_codeBiasIF += it->second * codeBiasesRefSig[frqType];
+        }
+        newCorr->_satCodeBias._bias.clear();
+      }
+      //cout <<  acName.toStdString() << " " << clkCorr._prn.toString().c_str() << " _codeBiasIF: " << newCorr->_codeBiasIF << endl;
     }
 
@@ -622,4 +675,15 @@
   out << "\n" <<           "Combination: " << sys << "\n"
       << "--------------------------------" << "\n";
+
+  // Re-read Bias SINEX file
+  // -----------------------
+  if (_bsx) {
+    QTime currTime = currentDateAndTimeGPS().time();
+    int ms = currTime.msecsTo(_nextShotTimeBsx);
+    if (ms < 30000) {
+      ms = 30000;
+    }
+    QTimer::singleShot(ms, this, SLOT(slotReadBiasSnxFile()));
+  }
 
   // Observation Statistics
@@ -696,5 +760,15 @@
       if (pp->type == cmbParam::clkSat) {
         if (resCorr.find(pp->prn) != resCorr.end()) {
+          // set clock result
           resCorr[pp->prn]->_dClkResult = pp->xx / t_CST::c;
+          // Add Code Biases from SINEX File
+          if (_bsx) {
+            map<t_frequency::type, double> codeCoeff;
+            double channel = double(resCorr[pp->prn]->_eph->slotNum());
+            cmbRefSig::coeff(sys, cmbRefSig::cIF, channel, codeCoeff);
+            t_frequency::type fType1 = cmbRefSig::toFreq(sys, cmbRefSig::c1);
+            t_frequency::type fType2 = cmbRefSig::toFreq(sys, cmbRefSig::c2);
+            _bsx->determineSsrSatCodeBiases(pp->prn.mid(0,3), codeCoeff[fType1], codeCoeff[fType2], resCorr[pp->prn]->_satCodeBias);
+          }
         }
       }
@@ -836,4 +910,5 @@
       out << "bncComb::printResuls bug" << "\n";
     }
+    out.flush();
   }
 }
@@ -845,6 +920,6 @@
   QList<t_orbCorr> orbCorrections;
   QList<t_clkCorr> clkCorrections;
-
-  QString     outLines;
+  QList<t_satCodeBias> satCodeBiasList;
+
   unsigned year, month, day, hour, minute;
   double   sec;
@@ -852,6 +927,6 @@
   _resTime.civil_time(hour, minute, sec);
 
-  outLines.sprintf("*  %4d %2d %2d %d %d %12.8f\n",
-                   year, month, day, hour, minute, sec);
+  QString outLines = QString().asprintf("*  %4d %2d %2d %d %d %12.8f\n",
+                                        year, month, day, hour, minute, sec);
 
   QMapIterator<QString, cmbCorr*> it(resCorr);
@@ -859,9 +934,9 @@
     it.next();
     cmbCorr* corr = it.value();
-
+    // ORBIT
     t_orbCorr orbCorr(corr->_orbCorr);
     orbCorr._staID = "INTERNAL";
     orbCorrections.push_back(orbCorr);
-
+    // CLOCK
     t_clkCorr clkCorr(corr->_clkCorr);
     clkCorr._staID      = "INTERNAL";
@@ -892,36 +967,35 @@
 
     outLines += corr->_prn.mid(0,3);
-    QString hlp;
-    hlp.sprintf(" APC 3 %15.4f %15.4f %15.4f"
-                " Clk 1 %15.4f"
-                " Vel 3 %15.4f %15.4f %15.4f"
-                " CoM 3 %15.4f %15.4f %15.4f\n",
-                xc(1), xc(2), xc(3),
-                xc(4) *  t_CST::c,
-                vv(1), vv(2), vv(3),
-                xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
+    QString hlp = QString().asprintf(" APC 3 %15.4f %15.4f %15.4f"
+                  " Clk 1 %15.4f"
+                  " Vel 3 %15.4f %15.4f %15.4f"
+                  " CoM 3 %15.4f %15.4f %15.4f",
+                  xc(1), xc(2), xc(3),
+                  xc(4) *  t_CST::c,
+                  vv(1), vv(2), vv(3),
+                  xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
     outLines += hlp;
-
-    QString line;
-    int messageType   = _ssrCorr->COTYPE_GPSCOMBINED;
-    int updateInt     = 0;
-    line.sprintf("%d %d %d %.1f %s"
-                 "   %lu"
-                 "   %8.3f %8.3f %8.3f %8.3f"
-                 "   %10.5f %10.5f %10.5f %10.5f"
-                 "   %10.5f INTERNAL",
-                 messageType, updateInt, _resTime.gpsw(), _resTime.gpssec(),
-                 corr->_prn.mid(0,3).toLatin1().data(),
-                 corr->_iod,
-                 corr->_dClkResult * t_CST::c,
-                 corr->_orbCorr._xr[0],
-                 corr->_orbCorr._xr[1],
-                 corr->_orbCorr._xr[2],
-                 0.0,
-                 corr->_orbCorr._dotXr[0],
-                 corr->_orbCorr._dotXr[1],
-                 corr->_orbCorr._dotXr[2],
-                 0.0);
-
+    hlp.clear();
+
+    // CODE BIASES
+    t_satCodeBias satCodeBias(corr->_satCodeBias);
+    satCodeBias._staID = "INTERNAL";
+    satCodeBiasList.push_back(satCodeBias);
+
+    if (satCodeBias._bias.size()) {
+      hlp = QString().asprintf(" CodeBias %2lu", satCodeBias._bias.size());
+      outLines += hlp;
+      hlp.clear();
+      for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
+        const t_frqCodeBias& frqCodeBias = satCodeBias._bias[ii];
+        if (!frqCodeBias._rnxType2ch.empty()) {
+          hlp = QString().asprintf(" %s%10.6f", frqCodeBias._rnxType2ch.c_str(), frqCodeBias._value);
+          outLines += hlp;
+          hlp.clear();
+        }
+      }
+    }
+    outLines += "\n";
+    //cout << outLines.toStdString();
     delete corr;
   }
@@ -941,4 +1015,7 @@
     emit newOrbCorrections(orbCorrections);
     emit newClkCorrections(clkCorrections);
+  }
+  if (satCodeBiasList.size()) {
+    emit newCodeBiases(satCodeBiasList);
   }
 }
Index: trunk/BNC/src/combination/bnccomb.h
===================================================================
--- trunk/BNC/src/combination/bnccomb.h	(revision 9675)
+++ trunk/BNC/src/combination/bnccomb.h	(revision 9676)
@@ -15,4 +15,5 @@
 class bncSP3;
 class bncAntex;
+class bncBiasSnx;
 
 class bncComb : public QObject {
@@ -29,4 +30,8 @@
   void slotNewClkCorrections(QList<t_clkCorr> clkCorrections);
   void slotNewCodeBiases(QList<t_satCodeBias> satCodeBiases);
+
+
+ private slots:
+  void slotReadBiasSnxFile();
 
  signals:
@@ -82,18 +87,18 @@
       _iod        = 0;
       _dClkResult = 0.0;
-      _codeBiasIF   = 0.0;
+      _codeBiasIF = 0.0;
     }
     ~cmbCorr() {}
-    QString       _prn;
-    bncTime       _time;
-    unsigned long _iod;
-    t_eph*        _eph;
-    t_orbCorr     _orbCorr;
-    t_clkCorr     _clkCorr;
-    t_satCodeBias _satCodeBias;
-    QString       _acName;
-    double        _codeBiasIF;
-    double        _dClkResult;
-    ColumnVector  _diffRao;
+    QString        _prn;
+    bncTime        _time;
+    unsigned long  _iod;
+    t_eph*         _eph;
+    t_orbCorr      _orbCorr;
+    t_clkCorr      _clkCorr;
+    t_satCodeBias  _satCodeBias;
+    QString        _acName;
+    double         _codeBiasIF;
+    double         _dClkResult;
+    ColumnVector   _diffRao;
     QString ID() {return _acName + "_" + _prn;}
   };
@@ -111,5 +116,5 @@
   };
 
-  class t_lcRefSig {
+  class cmbRefSig {
    public:
     enum type {dummy = 0, c1, c2, cIF};
@@ -183,5 +188,5 @@
           codeCoeff[fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
           return;
-        case t_lcRefSig::dummy:
+        case cmbRefSig::dummy:
           return;
       }
@@ -213,4 +218,6 @@
   QByteArray                                 _log;
   bncAntex*                                  _antex;
+  bncBiasSnx*                                _bsx;
+  QTime                                      _nextShotTimeBsx;
   double                                     _MAXRES;
   QMap<char, QString>                        _masterOrbitAC;
Index: trunk/BNC/src/src.pri
===================================================================
--- trunk/BNC/src/src.pri	(revision 9675)
+++ trunk/BNC/src/src.pri	(revision 9676)
@@ -34,4 +34,5 @@
 #debug:DEFINES   += BNC_DEBUG_PPP
 #debug:DEFINES   += BNC_DEBUG_SSR
+#debug:DEFINES   += BNC_DEBUG_CMB
 
 # Include Path
@@ -79,5 +80,5 @@
           rinex/availplot.h        rinex/eleplot.h                    \
           rinex/dopplot.h          orbComp/sp3Comp.h                  \
-          combination/bnccomb.h
+          combination/bnccomb.h combination/bncbiassnx.h
 
 HEADERS       += serial/qextserialbase.h serial/qextserialport.h
@@ -118,5 +119,5 @@
           rinex/availplot.cpp      rinex/eleplot.cpp                  \
           rinex/dopplot.cpp        orbComp/sp3Comp.cpp                \
-          combination/bnccomb.cpp
+          combination/bnccomb.cpp combination/bncbiassnx.cpp
 
 SOURCES       += serial/qextserialbase.cpp serial/qextserialport.cpp
