Index: trunk/BNC/src/combination/bnccomb.cpp
===================================================================
--- trunk/BNC/src/combination/bnccomb.cpp	(revision 9546)
+++ trunk/BNC/src/combination/bnccomb.cpp	(revision 9635)
@@ -18,4 +18,5 @@
 #include <iomanip>
 #include <sstream>
+#include <map>
 
 #include "bnccomb.h"
@@ -472,21 +473,4 @@
     }
 
-    // Check satellite code biases
-    // ----------------------------
-    if (!_satCodeBiases.contains(acName)) {
-      delete newCorr;
-      continue;
-    }
-    else {
-      QMap<t_prn, t_satCodeBias>& storage = _satCodeBiases[acName];
-      if (!storage.contains(clkCorr._prn)) {
-        delete newCorr;
-        continue;
-      }
-      else {
-        newCorr->_satCodeBias = storage[clkCorr._prn];
-      }
-    }
-
     // Check the Ephemeris
     //--------------------
@@ -520,4 +504,43 @@
         continue;
       }
+    }
+
+    // Check satellite code biases
+    // ----------------------------
+    if (!_satCodeBiases.contains(acName)) {
+      delete newCorr;
+      continue;
+    }
+    else {
+      QMap<t_prn, t_satCodeBias>& storage = _satCodeBiases[acName];
+      if (!storage.contains(clkCorr._prn)) {
+        delete newCorr;
+        continue;
+      }
+      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));
+          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;
+            }
+          }
+        }
+        map<t_frequency::type, double> codeCoeff;
+        double channel = double(newCorr->_eph->slotNum());
+        t_lcRefSig::coeff(sys, t_lcRefSig::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;
     }
 
@@ -597,6 +620,6 @@
   QTextStream out(&_log, QIODevice::WriteOnly);
 
-  out << endl <<           "Combination: " << sys << endl
-      << "--------------------------------" << endl;
+  out << "\n" <<           "Combination: " << sys << "\n"
+      << "--------------------------------" << "\n";
 
   // Observation Statistics
@@ -617,5 +640,5 @@
       }
     }
-    out << AC->name.toLatin1().data() << ": " << AC->numObs[sys] << endl;
+    out << AC->name.toLatin1().data() << ": " << AC->numObs[sys] << "\n";
   }
 
@@ -629,5 +652,5 @@
     ++_masterMissingEpochs[sys];
     if (_masterMissingEpochs[sys] < switchMasterAfterGap) {
-      out << "Missing Master, Epoch skipped" << endl;
+      out << "Missing Master, Epoch skipped" << "\n";
       _buffer[sys].remove(_resTime);
       emit newMessage(_log, false);
@@ -644,5 +667,5 @@
               << AC->name.toLatin1().data()   << " "
               << _resTime.datestr().c_str()    << " "
-              << _resTime.timestr().c_str()    << endl;
+              << _resTime.timestr().c_str()    << "\n";
           _masterOrbitAC[sys] = AC->name;
           break;
@@ -682,5 +705,5 @@
       out.setRealNumberPrecision(4);
       out << pp->toString(sys) << " "
-          << pp->xx << " +- " << sqrt(_QQ[sys](pp->index,pp->index)) << endl;
+          << pp->xx << " +- " << sqrt(_QQ[sys](pp->index,pp->index)) << "\n";
       out.setFieldWidth(0);
     }
@@ -762,10 +785,10 @@
       }
 
-      out << "  Outlier" << endl;
+      out << "  Outlier" << "\n";
       _QQ[sys] = QQ_sav;
       corrs(sys).remove(maxResIndex-1);
     }
     else {
-      out << "  OK" << endl;
+      out << "  OK" << "\n";
       out.setRealNumberNotation(QTextStream::FixedNotation);
       out.setRealNumberPrecision(4);
@@ -776,5 +799,5 @@
             << corr->_acName << ' ' << corr->_prn.mid(0,3);
         out.setFieldWidth(10);
-        out <<  " res = " << vv[ii] << endl;
+        out <<  " res = " << vv[ii] << "\n";
         out.setFieldWidth(0);
       }
@@ -807,9 +830,9 @@
       out << "Full Clock " << corr->_prn.mid(0,3) << " " << corr->_iod << " ";
       out.setFieldWidth(14);
-      out << (xc(4) + corr->_dClkResult) * t_CST::c << endl;
+      out << (xc(4) + corr->_dClkResult) * t_CST::c << "\n";
       out.setFieldWidth(0);
     }
     else {
-      out << "bncComb::printResuls bug" << endl;
+      out << "bncComb::printResuls bug" << "\n";
     }
   }
@@ -958,5 +981,5 @@
     }
 
-    ll(iObs) = corr->_clkCorr._dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
+    ll(iObs) = (corr->_clkCorr._dClk * t_CST::c - corr->_codeBiasIF) - DotProduct(AA.Row(iObs), x0);
   }
 
@@ -1117,5 +1140,5 @@
     }
     catch (Exception& exc) {
-      out << exc.what() << endl;
+      out << exc.what() << "\n";
       return failure;
     }
@@ -1130,10 +1153,10 @@
 
     if (maxRes > _MAXRES) {
-      out << "  Outlier" << endl;
+      out << "  Outlier" << "\n";
       delete corrs(sys)[maxResIndex-1];
       corrs(sys).remove(maxResIndex-1);
     }
     else {
-      out << "  OK" << endl;
+      out << "  OK" << "\n";
       out.setRealNumberNotation(QTextStream::FixedNotation);
       out.setRealNumberPrecision(3);
@@ -1144,5 +1167,5 @@
             << corr->_acName << ' ' << corr->_prn.mid(0,3);
         out.setFieldWidth(6);
-        out << " res = " << vv[ii] << endl;
+        out << " res = " << vv[ii] << "\n";
         out.setFieldWidth(0);
       }
@@ -1172,10 +1195,10 @@
 
     if      (ephLast == 0) {
-      out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << endl;
+      out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << "\n";
       delete corr;
       im.remove();
     }
     else if (corr->_eph == 0) {
-      out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << endl;
+      out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << "\n";
       delete corr;
       im.remove();
@@ -1186,5 +1209,5 @@
       }
       else {
-        out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << endl;
+        out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << "\n";
         delete corr;
         im.remove();
@@ -1268,5 +1291,5 @@
               << prn.mid(0,3).toLatin1().data()           << " "
               << corr->_iod                     << " "
-              << norm                           << endl;
+              << norm                           << "\n";
           delete corr;
           im.remove();
@@ -1301,5 +1324,5 @@
       out << "Provider ID changed: AC " << AC->name.toLatin1().data()   << " "
           << _resTime.datestr().c_str()    << " "
-          << _resTime.timestr().c_str()    << endl;
+          << _resTime.timestr().c_str()    << "\n";
       break;
     }
Index: trunk/BNC/src/combination/bnccomb.h
===================================================================
--- trunk/BNC/src/combination/bnccomb.h	(revision 9546)
+++ trunk/BNC/src/combination/bnccomb.h	(revision 9635)
@@ -4,7 +4,9 @@
 
 #include <fstream>
+#include <map>
 #include <newmat.h>
 #include "bncephuser.h"
 #include "satObs.h"
+#include "bncconst.h"
 #include "../RTCM3/clock_and_orbit/clock_orbit_rtcm.h"
 #include "../RTCM3/clock_and_orbit/clock_orbit_igs.h"
@@ -80,4 +82,5 @@
       _iod        = 0;
       _dClkResult = 0.0;
+      _codeBiasIF   = 0.0;
     }
     ~cmbCorr() {}
@@ -90,4 +93,5 @@
     t_satCodeBias _satCodeBias;
     QString       _acName;
+    double        _codeBiasIF;
     double        _dClkResult;
     ColumnVector  _diffRao;
@@ -106,4 +110,84 @@
     QVector<cmbCorr*> corrs;
   };
+
+  class t_lcRefSig {
+   public:
+    enum type {dummy = 0, c1, c2, cIF};
+
+    static t_frequency::type toFreq(char sys, type tt) {
+      switch (tt) {
+      case c1:
+        if      (sys == 'G') return t_frequency::G1;
+        else if (sys == 'R') return t_frequency::R1;
+        else if (sys == 'E') return t_frequency::E1;
+        else if (sys == 'C') return t_frequency::C2;
+        else if (sys == 'J') return t_frequency::J1;
+        else if (sys == 'S') return t_frequency::S1;
+        else                 return t_frequency::dummy;
+      case c2:
+        if      (sys == 'G') return t_frequency::G2;
+        else if (sys == 'R') return t_frequency::R2;
+        else if (sys == 'E') return t_frequency::E5;
+        else if (sys == 'C') return t_frequency::C6;
+        else if (sys == 'J') return t_frequency::J2;
+        else if (sys == 'S') return t_frequency::S5;
+        else                 return t_frequency::dummy;
+      case dummy:
+      case cIF:
+        return t_frequency::dummy;
+      }
+      return t_frequency::dummy;
+    }
+
+    static char toAttrib(char sys, type LC) {
+      switch (LC) {
+        case c1:
+          if      (sys == 'G') return 'W';
+          else if (sys == 'R') return 'P';
+          else if (sys == 'E') return 'C';
+          else if (sys == 'C') return 'I';
+          else if (sys == 'J') return 'C';
+          else if (sys == 'S') return 'C';
+          break;
+        case c2:
+          if      (sys == 'G') return 'W';
+          else if (sys == 'R') return 'P';
+          else if (sys == 'E') return 'Q';
+          else if (sys == 'C') return 'I';
+          else if (sys == 'J') return 'L';
+          else if (sys == 'S') return 'Q';
+          break;
+      case dummy:
+      case cIF:
+        return '_';
+        break;
+      }
+      return '_';
+    }
+
+      static void coeff(char sys, type tLC, double channel, std::map<t_frequency::type, double>& codeCoeff)  {
+      codeCoeff.clear();
+      t_frequency::type fType1 = toFreq(sys, c1);
+      t_frequency::type fType2 = toFreq(sys, c2);
+      double f1 = t_CST::freq(fType1, channel);
+      double f2 = t_CST::freq(fType2, channel);
+      switch (tLC) {
+        case c1:
+          codeCoeff[fType1] = 1.0;
+          return;
+        case c2:
+          codeCoeff[fType2] = 1.0;
+          return;
+        case cIF:
+          codeCoeff[fType1] =  f1 * f1 / (f1 * f1 - f2 * f2);
+          codeCoeff[fType2] = -f2 * f2 / (f1 * f1 - f2 * f2);
+          return;
+        case t_lcRefSig::dummy:
+          return;
+      }
+      return;
+    }
+  };
+
 
   void  processEpoch(char sys);
@@ -134,4 +218,5 @@
   e_method                                   _method;
   int                                        _cmbSampl;
+  QString                                    _cmbRefAttributes;
   QMap<QString, QMap<t_prn, t_orbCorr> >     _orbCorrections;
   QMap<QString, QMap<t_prn, t_satCodeBias> > _satCodeBiases;
