Index: trunk/BNC/src/PPP/pppClient.cpp
===================================================================
--- trunk/BNC/src/PPP/pppClient.cpp	(revision 9304)
+++ trunk/BNC/src/PPP/pppClient.cpp	(revision 9386)
@@ -309,5 +309,5 @@
     }
     if (!std::isnan(maxRes) && maxRes < BLUNDER) {
-      if (print) {
+      if (print && _numEpoProcessing == 1) {
         LOG.setf(ios::fixed);
         LOG << string(epoTime) << " BANCROFT:"        << ' '
@@ -370,6 +370,5 @@
         offGR = 0.0;
       }
-
-      if (fabs(maxRes) > 1000.0) {
+      if (fabs(maxRes) > OPT->_aprSigOGC) {
         LOG << "t_pppClient::cmpOffGR outlier " << maxResPrn.toString() << " " << maxRes << endl;
         delete obsVector.at(maxResIndex);
@@ -424,5 +423,5 @@
       }
 
-      if (fabs(maxRes) > 1000.0) {
+      if (fabs(maxRes) > OPT->_aprSigOGE) {
         LOG << "t_pppClient::cmpOffGE outlier " << maxResPrn.toString() << " " << maxRes << endl;
         delete obsVector.at(maxResIndex);
@@ -477,5 +476,5 @@
       }
 
-      if (fabs(maxRes) > 1000.0) {
+      if (fabs(maxRes) > OPT->_aprSigOGC) {
         LOG << "t_pppClient::cmpOffGC outlier " << maxResPrn.toString() << " " << maxRes << endl;
         delete obsVector.at(maxResIndex);
@@ -529,6 +528,6 @@
     _output->_trpStdev = _filter->trpStdev();
 
-    _output->_numSat     = _filter->numSat();
-    _output->_hDop       = _filter->HDOP();
+    _output->_numSat   = _filter->numSat();
+    _output->_hDop     = _filter->HDOP();
     _output->_error = false;
   }
@@ -593,22 +592,28 @@
 void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
 
-  _historicalRefSats.clear();
   try {
     initOutput(output);
-    int num = 0;
     bool epochReProcessing = false;
-
+    _numEpoProcessing = 0;
     do {
-      num++;
-      if (num == 1) {
-        LOG << "\nPPP of Epoch ";
-        if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
-        LOG << "\n---------------------------------------------------------------\n";
-      }
-
+      _numEpoProcessing++;
+      if (_obsPool->refSatChanged()) {
+        if(_filter->datumTransformation() != success) {
+          return finish(failure);
+        }
+        else {
+          _obsPool->saveLastEpoRefSats();
+        }
+      }
       // Prepare Observations of the Rover
       // ---------------------------------
       if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
         return finish(failure);
+      }
+
+      if (_numEpoProcessing == 1) {
+        LOG << "\nPPP of Epoch ";
+        if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
+        LOG << "\n---------------------------------------------------------------\n";
       }
 
@@ -624,27 +629,19 @@
       }
 
+      if (_opt->_refSatRequired) {
+        if (handleRefSatellites(_obsRover) != success) {
+          _historicalRefSats.clear();
+          return finish(failure);
+        }
+        if (_obsPool->refSatChanged()) {
+            epochReProcessing = true;
+            continue;
+        }
+      }
+
       _offGR = cmpOffGR(_obsRover);
       _offGE = cmpOffGE(_obsRover);
       _offGC = cmpOffGC(_obsRover);
 
-      if (_opt->_refSatRequired) {
-        setRefSatellites(_obsRover);
-        LOG.setf(ios::fixed);
-        QMapIterator<char, t_pppRefSat*> it(_obsPool->getRefSatMap());
-        while (it.hasNext()) {
-          it.next();
-          char   sys = it.key();
-          string prn = it.value()->prn().toString();
-          if (num == 1) {
-            LOG << "set   ";
-          }
-          else {
-            LOG << "reset ";
-          }
-          LOG << string(_epoTimeRover) << " REFSAT  " << sys << ": " << prn << endl;
-        }
-      }
-
-
       // Prepare Pseudo Observations of the Rover
       // ----------------------------------------
@@ -656,13 +653,11 @@
       }
 
-
       // Store last epoch of data
       // ------------------------
       _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
-      _obsPool->setHistoricalRefSatList(_historicalRefSats);
 
       // Process Epoch in Filter
       // -----------------------
-      if (_filter->processEpoch(num) != success) {
+      if (_filter->processEpoch() != success) {
         return finish(failure);
       }
@@ -670,16 +665,12 @@
       // Epoch re-processing required?
       // -----------------------------
-      if (_obsPool->refSatChangeRequired()) {
+      if (_obsPool->refSatChangeRequired()) {//SLIP
         epochReProcessing = true;
         _obsPool->deleteLastEpoch();
-        QMapIterator<char, t_pppRefSat*> it(_obsPool->getRefSatMap());
-        while (it.hasNext()) {
-          it.next();
-          _historicalRefSats.append(it.value()->prn());
-        }
+        setHistoricalRefSats();
       }
       else {
         epochReProcessing = false;
-
+        _historicalRefSats.clear();
       }
     } while (epochReProcessing);
@@ -789,21 +780,31 @@
   // reference satellite definition per system
   for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
-    char system = _opt->systems()[iSys];
+    char sys = _opt->systems()[iSys];
     bool refSatDefined = false;
-    t_pppRefSat* refSat = _obsPool->getRefSatMapElement(system);
+    t_pppRefSat* refSat = _obsPool->getRefSatMapElement(sys);
     for (unsigned ii = 0; ii < obsVector.size(); ii++) {
       t_pppSatObs* satObs = obsVector.at(ii);
-      if (satObs->eleSat() < _opt->_minEle) {continue;}
+      if (satObs->eleSat() < _opt->_minEle) {
+        continue;
+      }
       // reference satellite is unchanged
-      if      (!_obsPool->refSatChangeRequired() &&  refSat->prn() == satObs->prn()) {
+      if      (!_obsPool->refSatChangeRequired(sys) && refSat->prn() == satObs->prn()) {
         refSatDefined = true;
         obsVector[ii]->setAsReference();
+#ifdef BNC_DEBUG_PPP
+        LOG << "=> unchanged refsatprn: "  <<  satObs->prn().toString() << endl;
+#endif
       }
       // reference satellite has changed
-      else if ( _obsPool->refSatChangeRequired() && refSat->prn() != satObs->prn() && !_historicalRefSats.contains(satObs->prn())) {
-        if (satObs->prn().system() == system) {
+      else if ( _obsPool->refSatChangeRequired(sys) &&
+                refSat->prn() != satObs->prn() &&
+                !_historicalRefSats[sys].contains(satObs->prn())) {
+        if (satObs->prn().system() == sys) {
           refSatDefined = true;
           obsVector[ii]->setAsReference();
           refSat->setPrn(satObs->prn());
+#ifdef BNC_DEBUG_PPP
+          LOG << "=> set refsatprn: "  <<  satObs->prn().toString() << endl;
+#endif
         }
       }
@@ -822,7 +823,11 @@
           continue;
         }
-        if (satObs->prn().system() == system) {
+        if (satObs->prn().system() == sys &&
+            !_historicalRefSats[sys].contains(satObs->prn())) {
           obsVector[ii]->setAsReference();
           refSat->setPrn(satObs->prn());
+#ifdef BNC_DEBUG_PPP
+          LOG << " => set refsatprn: "  <<  satObs->prn().toString() << endl;
+#endif
           if (OPT->_pseudoObsIono) {
             refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
@@ -833,7 +838,52 @@
       }
     }
-  }
-  _obsPool->setRefSatChangeRequired(false);
-
+    if (!refSatDefined) {
+      refSat->setPrn(t_prn());
+    }
+    _obsPool->setRefSatChangeRequired(sys, false);
+  }
+}
+
+//
+//////////////////////////////////////////////////////////////////////////////
+t_irc t_pppClient::handleRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
+
+  // set refSats in current epoch
+  // ============================
+  setRefSatellites(obsVector); // current epoch
+  LOG.setf(ios::fixed);
+  QMapIterator<char, t_pppRefSat*> it(_obsPool->getRefSatMap());
+  while (it.hasNext()) {
+    it.next();
+    char  sys = it.key();
+    t_prn prn = it.value()->prn();
+    if (prn.number() == 0) {
+      return failure;
+    }
+    QString str;
+    if (prn == _obsPool->getRefSatMapElementLastEpoch(sys) ||
+               _obsPool->getRefSatMapElementLastEpoch(sys) == t_prn() )  {
+      _obsPool->setRefSatChanged(sys, false);
+      str = " SET   ";
+    }
+    else {
+      _obsPool->setRefSatChanged(sys, true);
+      str = " RESET ";
+    }
+    LOG << string(_epoTimeRover) <<  str.toStdString() << " REFSAT  " << sys << ": " << prn.toString() << endl;
+  }
+  return success;
+}
+
+void t_pppClient::setHistoricalRefSats() {
+  QMapIterator<char, t_pppRefSat*> it(_obsPool->getRefSatMap());
+  while (it.hasNext()) {
+    it.next();
+    t_prn prn = it.value()->prn();
+    char sys = prn.system();
+    if (_obsPool->refSatChangeRequired(sys)){
+      _historicalRefSats[sys].append(prn);
+    }
+  }
 }
 
Index: trunk/BNC/src/PPP/pppClient.h
===================================================================
--- trunk/BNC/src/PPP/pppClient.h	(revision 9304)
+++ trunk/BNC/src/PPP/pppClient.h	(revision 9386)
@@ -64,5 +64,7 @@
   double cmpOffGE(std::vector<t_pppSatObs*>& obsVector);
   double cmpOffGC(std::vector<t_pppSatObs*>& obsVector);
+  t_irc handleRefSatellites(std::vector<t_pppSatObs*>& obsVector);
   void setRefSatellites(std::vector<t_pppSatObs*>& obsVector);
+  void setHistoricalRefSats();
 
   t_output*                 _output;
@@ -81,5 +83,6 @@
   t_tides*                  _tides;
   bool                      _pseudoObsIono;
-  QList<t_prn>              _historicalRefSats;
+  int                       _numEpoProcessing;
+  QMap<char, QList<t_prn>>  _historicalRefSats;
 };
 
Index: trunk/BNC/src/PPP/pppFilter.cpp
===================================================================
--- trunk/BNC/src/PPP/pppFilter.cpp	(revision 9304)
+++ trunk/BNC/src/PPP/pppFilter.cpp	(revision 9386)
@@ -27,5 +27,4 @@
 #include "pppObsPool.h"
 #include "pppStation.h"
-#include "pppClient.h"
 
 using namespace BNC_PPP;
@@ -51,7 +50,6 @@
 // Process Single Epoch
 ////////////////////////////////////////////////////////////////////////////
-t_irc t_pppFilter::processEpoch(int num) {
+t_irc t_pppFilter::processEpoch() {
   _numSat     = 0;
-  _numEpoProcessing = num;
   const double maxSolGap = 60.0;
 
@@ -85,5 +83,9 @@
   _parlist->set(_epoTime, allObs, _obsPool->getRefSatMap());
   const vector<t_pppParam*>& params = _parlist->params();
-
+#ifdef BNC_DEBUG_PPP
+  for (unsigned iPar = 0; iPar < params.size(); iPar++) {
+    LOG << params[iPar]->toString() << endl;
+  }
+#endif
   // Status Vector, Variance-Covariance Matrix
   // -----------------------------------------
@@ -94,6 +96,10 @@
   _xFlt.ReSize(_parlist->nPar()); _xFlt = 0.0;
   _x0.ReSize(_parlist->nPar());   _x0   = 0.0;
+
   for (unsigned ii = 0; ii < params.size(); ii++) {
-    const t_pppParam* par1 = params[ii];
+    t_pppParam* par1 = params[ii];
+    if (QFltOld.size() == 0) {
+      par1->resetIndex();
+    }
     _x0[ii] = par1->x0();
     int iOld = par1->indexOld();
@@ -105,6 +111,6 @@
       _xFlt[ii]     = xFltOld[iOld];
       for (unsigned jj = 0; jj < ii; jj++) {
-        const t_pppParam* par2 = params[jj];
-        int               jOld = par2->indexOld();
+        t_pppParam* par2 = params[jj];
+        int  jOld = par2->indexOld();
         if (jOld >= 0) {
           _QFlt[ii][jj] = QFltOld(iOld+1,jOld+1);
@@ -114,36 +120,4 @@
   }
   predictCovCrdPart(QFltOld);
-
-  // Init Datum Trafo
-  // ----------------------------------------
-  if ((OPT->_obsModelType == OPT->DCMcodeBias   ||
-       OPT->_obsModelType == OPT->DCMphaseBias) &&(_numEpoProcessing == 1))  {
-    _numAllUsedLCs = 0;
-    for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
-      char system = OPT->systems()[iSys];
-      _numAllUsedLCs += OPT->LCs(system).size();
-      if (OPT->_pseudoObsIono && epoch->pseudoObsIono() == false) {
-        _numAllUsedLCs -= 1;  // GIM not used
-        if (OPT->_pseudoObsTropo) { // if no VTEC values /pseudo obs iono then no pseudo obs tropo
-          _numAllUsedLCs -= 1;
-        }
-      }
-      int modifyLCs = 0;
-      if (OPT->_pseudoObsTropo &&
-          OPT->_pseudoObsIono && epoch->pseudoObsIono() == true) {
-        modifyLCs  = -1;
-      }
-      // max Obs
-      int maxObs = allObs.size() * (_numAllUsedLCs + modifyLCs);
-      if (OPT->_pseudoObsIono && epoch->pseudoObsIono() == true) {
-        maxObs -= 1; // pseudo obs iono with respect to refSat
-      }
-      if (OPT->_pseudoObsIono && epoch->pseudoObsIono() == true &&
-          OPT->_pseudoObsTropo) {
-        maxObs += 1;   // pseudo obs tropo once per station
-      }
-      _datumTrafo->initAA(maxObs, _parlist->nPar());
-    }
-  }
 
   // Pre-Process Satellite Systems separately
@@ -154,21 +128,18 @@
     preProcessing = true;
     for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
-      (iSys) ? _datumTrafo->setFirstSystem(false) : _datumTrafo->setFirstSystem(true);
-      char system = OPT->systems()[iSys];
+      char sys = OPT->systems()[iSys];
       if (OPT->_refSatRequired) {
-        _refPrn = (_obsPool->getRefSatMapElement(system))->prn();
-        if (_obsPool->hasHistoricalRefSat(_refPrn)) {
-          LOG << epoTimeStr << " Warning: prevent to process erroneous refSat again!";
-          return failure;
-        }
-      }
-      vector<t_pppSatObs*> obsVector;
+        _refPrn = (_obsPool->getRefSatMapElement(sys))->prn();
+      }
+     vector<t_pppSatObs*> obsVector;
       for (unsigned jj = 0; jj < allObs.size(); jj++) {
-        if (allObs[jj]->prn().system() == system) {
+        if (allObs[jj]->prn().system() == sys) {
           obsVector.push_back(allObs[jj]);
         }
       }
-      if (processSystem(OPT->LCs(system), obsVector, _refPrn,
+      if (processSystem(OPT->LCs(sys), obsVector, _refPrn,
                         epoch->pseudoObsIono(), preProcessing) != success) {
+        _xFlt = xFltOld;
+        _QFlt = QFltOld;
         return failure;
       }
@@ -181,7 +152,6 @@
       return success;
     }
-    else if (!_obsPool->refSatChangeRequired() &&
-             _numEpoProcessing > 1) {
-      datumTransformation(xFltOld, QFltOld);
+    else if (!_obsPool->refSatChangeRequired()) {
+      initDatumTransformation(allObs);
     }
   }
@@ -191,4 +161,5 @@
   preProcessing = false;
   for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
+    (iSys) ? _datumTrafo->setFirstSystem(false) : _datumTrafo->setFirstSystem(true);
     char system = OPT->systems()[iSys];
     if (OPT->_refSatRequired) {
@@ -215,5 +186,7 @@
   _parlist->printResult(_epoTime, _QFlt, _xFlt);
   _lastEpoTimeOK = _epoTime;  // remember time of last successful epoch processing
-
+  if (OPT->_refSatRequired) {
+    _obsPool->saveLastEpoRefSats();
+  }
   return success;
 }
@@ -227,4 +200,5 @@
                                  bool preProcessing) {
   LOG.setf(ios::fixed);
+  char sys = refPrn.system();
 
   // Detect Cycle Slips
@@ -233,6 +207,10 @@
     return failure;
   }
-
-  unsigned usedLCs = LCs.size();
+  if (preProcessing && _obsPool->refSatChangeRequired(sys)) { // from detectCycleSlips()
+#ifdef BNC_DEBUG_PPP
+    LOG << "_obsPool->refSatChangeRequired(" << sys << ") from detectCycleSlips()" << endl;
+#endif
+    return success;
+  }
 
   ColumnVector               xSav       = _xFlt;
@@ -241,24 +219,21 @@
   const vector<t_pppParam*>& params     = _parlist->params();
 
+  unsigned usedLCs     = LCs.size();
+  unsigned realUsedLCs = usedLCs;
   if (OPT->_pseudoObsIono && !pseudoObsIonoAvailable) {
-    usedLCs -= 1;  // GIM not used
-    if (OPT->_pseudoObsTropo) { // if no VTEC values /pseudo obs iono then no pseudo obs tropo
-      usedLCs -= 1;
-    }
-  }
-
-  int modifyLCs = 0;
-  if (OPT->_pseudoObsTropo &&
-      OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
-    modifyLCs  = -1;
+      usedLCs -= 1;  // GIM not used
+  }
+  int hlpLCs = 0;
+  if (OPT->_pseudoObsTropo) {
+    hlpLCs = -1;
+    realUsedLCs -= 1;
   }
   // max Obs
-  unsigned maxObs = obsVector.size() * (usedLCs + modifyLCs);
+  unsigned maxObs = obsVector.size() * (usedLCs + hlpLCs);
+  if (OPT->_pseudoObsTropo) {
+    maxObs += 1;
+  }
   if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
     maxObs -= 1; // pseudo obs iono with respect to refSat
-  }
-  if (OPT->_pseudoObsIono && pseudoObsIonoAvailable &&
-      OPT->_pseudoObsTropo) {
-    maxObs += 1;   // pseudo obs tropo once per station
   }
 
@@ -281,12 +256,14 @@
     vector<t_pppSatObs*> usedObs;
     vector<t_lc::type>   usedTypes;
+
+    // Real Observations
+    // =================
     for (unsigned ii = 0; ii < obsVector.size(); ii++) {
       t_pppSatObs* obs = obsVector[ii];
-      unsigned hlp = ii+1;
       if (!obs->outlier()) {
         for (unsigned jj = 0; jj < usedLCs; jj++) {
           const t_lc::type tLC = LCs[jj];
-          if (tLC == t_lc::GIM &&  obs->isReference()) {continue;}
-          if (tLC == t_lc::Tz0 && hlp != obsVector.size()) {continue;}
+          if (tLC == t_lc::GIM) {continue;}
+          if (tLC == t_lc::Tz0) {continue;}
           ++iObs;
           usedObs.push_back(obs);
@@ -302,10 +279,53 @@
     }
 
-    if ((preProcessing && ! iOutlier) &&
-        (OPT->_obsModelType == OPT->DCMcodeBias || OPT->_obsModelType == OPT->DCMphaseBias)) {
-   	  _datumTrafo->updateIndices(maxObs);
-      _datumTrafo->prepareAA(AA, _numEpoProcessing, _parlist->nPar());
-      if (_obsPool->refSatChangeRequired()) { // from detectCycleSlips()
-        return success;
+    if ((!iOutlier) &&
+        (OPT->_obsModelType == OPT->DCMcodeBias ||
+         OPT->_obsModelType == OPT->DCMphaseBias  ) &&  (!preProcessing)) {
+      _datumTrafo->updateIndices(iObs+1);
+      _datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, _parlist->nPar()), 1);
+    }
+
+    // Pseudo Obs Iono
+    // ================
+    if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
+      for (unsigned ii = 0; ii < obsVector.size(); ii++) {
+        t_pppSatObs* obs = obsVector[ii];
+        if (!obs->outlier()) {
+          for (unsigned jj = 0; jj < usedLCs; jj++) {
+            const t_lc::type tLC = LCs[jj];
+            if (tLC == t_lc::GIM && !obs->isReference()) {
+              ++iObs;
+            } else {continue;}
+            usedObs.push_back(obs);
+            usedTypes.push_back(tLC);
+            for (unsigned iPar = 0; iPar < params.size(); iPar++) {
+              const t_pppParam* par = params[iPar];
+              AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
+            }
+            ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA.Row(iObs+1));
+            PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
+          }
+        }
+      }
+    }
+    // pseudo Obs Tropo
+    // ================
+    if (OPT->_pseudoObsTropo) {
+      for (unsigned ii = 0; ii < obsVector.size(); ii++) {
+        t_pppSatObs* obs = obsVector[ii];
+        if (!obs->isReference()) {continue;}
+        for (unsigned jj = 0; jj < usedLCs; jj++) {
+          const t_lc::type tLC = LCs[jj];
+          if (tLC != t_lc::Tz0) {continue;}
+          ++iObs;
+          usedObs.push_back(obs);
+          usedTypes.push_back(tLC);
+          for (unsigned iPar = 0; iPar < params.size(); iPar++) {
+            const t_pppParam* par = params[iPar];
+            AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
+          }
+          ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA.Row(iObs+1));
+          PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
+        }
       }
     }
@@ -347,9 +367,10 @@
       t_pppSatObs* obs = usedObs[maxOutlierIndex];
       t_pppParam* par = 0;
-      if (!preProcessing) {
-        LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
-            << obs->prn().toString()                        << ' '
-            << setw(8) << setprecision(4) << maxOutlier << endl;
-      }
+#ifdef BNC_DEBUG_PPP
+      LOG << epoTimeStr << " Outlier ("
+          << ((preProcessing) ? "pre-processing) " : "fin-processing) ") << t_lc::toString(maxOutlierLC) << ' '
+          << obs->prn().toString()                        << ' '
+          << setw(8) << setprecision(4) << maxOutlier << endl;
+#endif
       for (unsigned iPar = 0; iPar < params.size(); iPar++) {
         t_pppParam* hlp = params[iPar];
@@ -361,15 +382,23 @@
       }
       if (preProcessing) {
-        if      (par && obs->prn() == refPrn) {
-          _obsPool->setRefSatChangeRequired(true);
-          break;
-        }
-        else if (par && obs->prn() != refPrn) {
-          par->setAmbResetCandidate();
-        }
-      }
-      else {
+        // for refSats  no ambiguity parameter exists
+         if ((obs->prn() == refPrn) &&
+             (t_lc::toString(maxOutlierLC) == "l1" ||
+              t_lc::toString(maxOutlierLC) == "l2") ) {
+           _obsPool->setRefSatChangeRequired(sys, true);
+         }
+         else {
+          if (par) {
+            par->setAmbResetCandidate();
+            obs->setOutlier();
+          }
+          else {
+            obs->setOutlier();
+          }
+        }
+      }
+      else {// fin-processing
         if (par) {
-          if (par->ambResetCandidate() || _obsPool->hasHistoricalRefSat(par->prn())) {
+          if (par->ambResetCandidate()) {
             resetAmb(par->prn(), obsVector, &QSav, &xSav);
           }
@@ -391,11 +420,12 @@
           for (unsigned ii = 0; ii < usedObs.size(); ii++) {
             const t_lc::type tLC = usedTypes[ii];
-            t_pppSatObs*        obs = usedObs[ii];
+            t_pppSatObs* obs = usedObs[ii];
             if (tLC == LCs[jj]) {
               obs->setRes(tLC, vv[ii]);
               LOG << epoTimeStr << " RES "
-                  << left << setw(3) << t_lc::toString(tLC) << right << ' '
-                  << obs->prn().toString().substr(0,3) << ' '
-                  << setw(8) << setprecision(4) << vv[ii] << endl;
+                  << left << setw(3) << t_lc::toString(tLC) << right << ' ';
+              if (t_lc::toString(tLC) == "Tz0") {LOG << sys << "  ";}
+              else {LOG << obs->prn().toString();}
+              LOG << setw(8) << setprecision(4) << vv[ii] << endl;
             }
           }
@@ -405,5 +435,4 @@
     }
   }
-
   return success;
 }
@@ -415,11 +444,8 @@
                                     const t_prn& refPrn,
                                     bool preProcessing) {
-  if (_obsPool->hasHistoricalRefSat(refPrn)) {
-    return success;
-  }
-
-  //double                  SLIP       = 20.0;  // slip threshold
-  double                  SLIP       = 200.0;  // slip threshold deactivated
-  string                  epoTimeStr = string(_epoTime);
+
+  const double SLIP = 20.0;
+  char sys = refPrn.system();
+  string epoTimeStr = string(_epoTime);
   const vector<t_pppParam*>& params  = _parlist->params();
 
@@ -430,9 +456,13 @@
         const t_pppSatObs* obs = obsVector[iObs];
 
-        if (preProcessing && obs->prn() != refPrn) {continue;}
-
         // Check set Slips and Jump Counters
         // ---------------------------------
         bool slip = false;
+
+        // in pre-processing only the reference satellite has to be checked
+        if (preProcessing && obs->prn() != refPrn) {
+          continue;
+        }
+
         if (obs->slip()) {
           LOG << epoTimeStr  << "cycle slip set (obs) " << obs->prn().toString()  << endl;
@@ -460,5 +490,5 @@
         if (slip) {
           if (preProcessing) {
-            _obsPool->setRefSatChangeRequired(true);
+            _obsPool->setRefSatChangeRequired(sys, true);
           }
           else {
@@ -474,15 +504,13 @@
             AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
           }
-
           double ll = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA);
           double vv = DotProduct(AA, _xFlt) - ll;
-
           if (fabs(vv) > SLIP) {
+            LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
+              << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
             if (preProcessing) {
-              _obsPool->setRefSatChangeRequired(true);
+              _obsPool->setRefSatChangeRequired(sys, true);
             }
             else {
-              LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
-                  << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
               resetAmb(obs->prn(), obsVector);
             }
@@ -533,4 +561,24 @@
 }
 
+// Add innfinite noise to iono
+////////////////////////////////////////////////////////////////////////////
+t_irc t_pppFilter::addNoiseToIono(char sys) {
+
+  t_irc irc = failure;
+  vector<t_pppParam*>& params = _parlist->params();
+  for (unsigned iPar = 0; iPar < params.size(); iPar++) {
+    t_pppParam* par = params[iPar];
+    if (par->type() == t_pppParam::ion && par->prn().system() == sys) {
+      int ind = par->indexNew();
+      LOG << string(_epoTime) << " ADD IONO_NOISE TO "  <<  par->prn().toString() << endl;
+      par->setIndex(ind);
+      _QFlt(ind+1,ind+1) += par->sigma0() * par->sigma0();
+      irc = success;
+    }
+  }
+
+  return irc;
+}
+
 // Compute various DOP Values
 ////////////////////////////////////////////////////////////////////////////
@@ -617,27 +665,182 @@
 // Compute datum transformation
 ////////////////////////////////////////////////////////////////////////////
-void t_pppFilter::datumTransformation(const ColumnVector& xFltOld, const SymmetricMatrix& QFltOld) {
+t_irc t_pppFilter::datumTransformation() {
+  t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
+  if (!epoch) {LOG << "!epoch" << endl;
+    return failure;
+  }
+  else {
+    LOG.setf(ios::fixed);
+    LOG << string(epoch->epoTime()) << " DATUM TRANSFORMATION " << endl;
+  }
+  vector<t_pppSatObs*>& allObs = epoch->obsVector();
+
+  // reset old and set new refSats in last epoch (ambiguities)
+  // ========================================================
+  if (resetRefSatellitesLastEpoch(allObs) != true) {
+    return failure;
+  }
+
+  // set AA2
+  // =======
+  _parlist->set(epoch->epoTime(), allObs, _obsPool->getRefSatMap());
+  const vector<t_pppParam*>& params = _parlist->params();
+#ifdef BNC_DEBUG_PPP
+  for (unsigned iPar = 0; iPar < params.size(); iPar++) {
+    LOG << params[iPar]->toString() << "\t\t" << endl;
+  }
+#endif
+  for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
+    (iSys) ? _datumTrafo->setFirstSystem(false) : _datumTrafo->setFirstSystem(true);
+    char sys = OPT->systems()[iSys];
+    t_prn refPrn = (_obsPool->getRefSatMapElement(sys))->prn();
+#ifdef BNC_DEBUG_PPP
+    LOG << "refPrn: " << refPrn.toString() << endl;
+#endif
+    vector<t_pppSatObs*> obsVector;
+    for (unsigned jj = 0; jj < allObs.size(); jj++) {
+      if (allObs[jj]->prn().system() == sys) {
+        obsVector.push_back(allObs[jj]);
+      }
+    }
+
+    vector<t_lc::type> LCs = OPT->LCs(sys);
+    unsigned usedLCs = LCs.size();
+    unsigned realUsedLCs = usedLCs;
+    if (OPT->_pseudoObsIono && !epoch->pseudoObsIono()) {
+        usedLCs -= 1;  // GIM not used
+    }
+    int hlpLCs = 0;
+    if (OPT->_pseudoObsTropo) {
+      hlpLCs = -1;
+      realUsedLCs -= 1;
+    }
+    // max Obs
+    unsigned maxObs = obsVector.size() * (usedLCs + hlpLCs);
+    if (OPT->_pseudoObsTropo) {
+      maxObs += 1;
+    }
+    if (OPT->_pseudoObsIono && epoch->pseudoObsIono()) {
+      maxObs -= 1; // pseudo obs iono with respect to refSat
+    }
+
+    Matrix  AA(maxObs, _parlist->nPar());
+
+    // Real Observations
+    // -----------------
+    int iObs = -1;
+    for (unsigned ii = 0; ii < obsVector.size(); ii++) {
+      t_pppSatObs* obs = obsVector[ii];
+      if (!obs->outlier()) {
+        for (unsigned jj = 0; jj < usedLCs; jj++) {
+          const t_lc::type tLC = LCs[jj];
+          if (tLC == t_lc::GIM) {continue;}
+          if (tLC == t_lc::Tz0) {continue;}
+          ++iObs;
+          for (unsigned iPar = 0; iPar < params.size(); iPar++) {
+            const t_pppParam* par = params[iPar];
+            AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
+          }
+        }
+      }
+    }
+    _datumTrafo->updateIndices(iObs+1);
+    _datumTrafo->prepareAA(AA.SubMatrix(1, iObs+1 , 1, _parlist->nPar()), 2);
+  }
+
+  // Datum Transformation
+  // ====================
+#ifdef BNC_DEBUG_PPP
+      LOG << "AA1\n"; _datumTrafo->printMatrix(_datumTrafo->AA1(), _datumTrafo->obsNum(), _datumTrafo->parNum());
+      LOG << "AA2\n"; _datumTrafo->printMatrix(_datumTrafo->AA2(), _datumTrafo->obsNum(), _datumTrafo->parNum());
+#endif
   Matrix D21 = _datumTrafo->computeTrafoMatrix();
+#ifdef BNC_DEBUG_PPP
+      LOG << "D21" << endl; _datumTrafo->printMatrix(D21, _datumTrafo->parNum(), _datumTrafo->parNum());
+#endif
+  ColumnVector    xFltOld = _xFlt;
+  SymmetricMatrix QFltOld = _QFlt;
+
   _QFlt << D21 * QFltOld * D21.t();
-  _xFlt = D21 * xFltOld;
-}
-
-
-// Reset Ambiguity Parameter (cycle slip)
-////////////////////////////////////////////////////////////////////////////
-t_irc t_pppFilter::addInfiniteNoise(t_pppParam::e_type para) {
-  t_irc irc = failure;
-  vector<t_pppParam*>& params = _parlist->params();
-  for (unsigned iPar = 0; iPar < params.size(); iPar++) {
-    t_pppParam* par = params[iPar];
-    if (par->type() == para) {
-      int ind = par->indexNew();
-      if (ind < 0) {
-        return irc;
-      }
-      _QFlt(ind+1,ind+1) += par->sigma0() * par->sigma0();
-      irc = success;
-    }
-  }
-  return irc;
-}
+  _xFlt =  D21 * xFltOld;
+
+#ifdef BNC_DEBUG_PPP
+  LOG << "xFltOld:\n" << xFltOld << endl;
+  LOG << "xFlt   :\n" << _xFlt   << endl;
+#endif
+
+  // Reset Ambiguities after Datum Transformation
+  // ============================================
+  for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
+    char sys = OPT->systems()[iSys];
+    t_irc irc = resetAmb(_obsPool->getRefSatMapElementLastEpoch(sys), allObs);
+    if (OPT->_obsModelType == OPT->DCMcodeBias) {
+      if (irc == success) {
+        addNoiseToIono(sys);}
+    }
+  }
+
+  // switch AA2 to AA1
+  // =================
+  _datumTrafo->switchAA();
+
+  return success;
+}
+
+// Init datum transformation
+////////////////////////////////////////////////////////////////////////////
+void t_pppFilter::initDatumTransformation(const std::vector<t_pppSatObs*>& allObs) {
+  unsigned realObs = 0;
+  for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
+    char system = OPT->systems()[iSys];
+    int satNum = 0;
+    for (unsigned jj = 0; jj < allObs.size(); jj++) {
+      if (allObs[jj]->prn().system() == system) {
+        satNum++;
+      }
+    }
+    // all LCs
+    unsigned realUsedLCs = OPT->LCs(system).size();
+    // exclude pseudo obs GIM
+    if (OPT->_pseudoObsIono) {
+      realUsedLCs -= 1;
+    }
+    if (OPT->_pseudoObsTropo) {
+      realUsedLCs -= 1;
+    }
+    realObs += satNum * realUsedLCs;
+  }
+  _datumTrafo->setObsNum(realObs);
+  _datumTrafo->setParNum(_parlist->nPar());
+  _datumTrafo->initAA();
+}
+
+//
+//////////////////////////////////////////////////////////////////////////////
+bool t_pppFilter::resetRefSatellitesLastEpoch(std::vector<t_pppSatObs*>& obsVector) {
+
+  bool resetRefSat = false;
+  // reference satellite definition per system
+  for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
+    char sys = OPT->systems()[iSys];
+    t_pppRefSat* refSat = _obsPool->getRefSatMapElement(sys);
+    t_prn newPrn = refSat->prn();
+    t_prn oldPrn = _obsPool->getRefSatMapElementLastEpoch(sys);
+#ifdef BNC_DEBUG_PPP
+    LOG << "oldPrn: " << oldPrn.toString() << " => newPrn: " << newPrn.toString() << endl;
+#endif
+    vector<t_pppSatObs*>::iterator it = obsVector.begin();
+    while (it != obsVector.end()) {
+      t_pppSatObs* satObs = *it;
+      if      (satObs->prn() == newPrn) {
+        resetRefSat = true;
+        satObs->setAsReference();
+      }
+      else if (satObs->prn() == oldPrn) {
+        satObs->resetReference();
+      }
+     it++;
+    }
+  }
+  return resetRefSat;
+}
Index: trunk/BNC/src/PPP/pppFilter.h
===================================================================
--- trunk/BNC/src/PPP/pppFilter.h	(revision 9304)
+++ trunk/BNC/src/PPP/pppFilter.h	(revision 9386)
@@ -8,4 +8,5 @@
 #include "bnctime.h"
 #include "t_prn.h"
+#include "pppClient.h"
 
 namespace BNC_PPP {
@@ -20,7 +21,8 @@
   ~t_pppFilter();
 
-  t_irc processEpoch(int num);
+  t_irc processEpoch();
 
-  void datumTransformation(const ColumnVector& xFltOld, const SymmetricMatrix& QFltOld);
+  t_irc datumTransformation();
+  void initDatumTransformation(const std::vector<t_pppSatObs*>& allObs);
 
   const ColumnVector&    x() const {return _xFlt;}
@@ -81,5 +83,5 @@
     void setFirstSystem(bool firstSys) {_firstSys = firstSys;}
     bool firstSystem() {return _firstSys;}
-    void updateIndices(int maxObs) {
+    void updateIndices(int maxObsSys) {
       if (firstSystem()) {
         initIndices();
@@ -88,36 +90,57 @@
         _firstRow = _lastRow + 1;
       }
-      _lastRow += maxObs;
+      _lastRow += maxObsSys;
+
     };
-    void initAA(int maxObs, int numPar) {
-      _AA1.ReSize(maxObs, numPar); _AA1 = 0.0;
-      _AA2.ReSize(maxObs, numPar); _AA2 = 0.0;
+    void setObsNum(int maxObs) {_maxObs = maxObs;}
+    void setParNum(int numPar) {_numPar = numPar;}
+    int obsNum() {return _maxObs;}
+    int parNum() {return _numPar;}
+    const Matrix& AA1() {return _AA1;}
+    const Matrix& AA2() {return _AA2;}
+
+    void initAA() {
+      _AA1.ReSize(_maxObs, _numPar); _AA1 = 0.0;
+      _AA2.ReSize(_maxObs, _numPar); _AA2 = 0.0;
     }
-    void prepareAA(const Matrix& AA, int numEpoProcessing, int nPar) {
+
+    void prepareAA(const Matrix& AA, int ind) {
       Matrix* Prep = &_AA2;
-      if (numEpoProcessing == 1) {
+      if (ind == 1) {
         Prep = &_AA1;
       }
-      Prep->SubMatrix(_firstRow, _lastRow, 1, nPar) << AA;
+      Prep->SubMatrix(_firstRow, _lastRow, 1, _numPar) << AA;
+    }
+    void switchAA() {
+      _AA1 = _AA2;
+    }
+    Matrix&  getAA(int ind) {
+      if (ind == 1) {
+          return _AA1;
+      }
+      return _AA2;
+    }
+    Matrix computeTrafoMatrix() {
+      Matrix D21 = ((_AA2.t() * _AA2).i()) * _AA2.t() * _AA1;
+      return D21;
+    }
+    void printMatrix(const Matrix& X, int nRow, int nCol) {
+      for (int rr = 0; rr < nRow; rr++) {
+        for (int cc = 0; cc < nCol; cc++) {
+          LOG << setw(6) << setprecision(3) << X[rr][cc] << " ;";
+        }
+        LOG << endl;
+      }
+      LOG << endl;
     }
 
-    Matrix computeTrafoMatrix() {
-      Matrix D21 = (_AA2.t() * _AA2).i() * _AA2.t() * _AA1;
-      return D21;
-    }
-
-    static void printMatrix(const Matrix& X, int nRow, int nCol) {
-      for (int rr = 0; rr < nRow; rr++) {
-        for (int cc = 0; cc < nCol; cc++) {
-          cout << setw(7) << setprecision(4) << X[rr][cc] << " ";
-        }
-        cout << endl;      }
-      cout << endl;
-    }
-    int     _firstRow;
-    int     _lastRow;
-    Matrix  _AA1;
-    Matrix  _AA2;
-    bool    _firstSys;
+    int               _firstRow;
+    int               _lastRow;
+    Matrix            _AA1;
+    Matrix            _AA2;
+    bool              _firstSys;
+    int               _maxObs;
+    int               _numPar;
+    QMap<char, t_prn> _refSatMapPseudoObs;
   };
 
@@ -140,5 +163,7 @@
   void predictCovCrdPart(const SymmetricMatrix& QFltOld);
 
-  t_irc addInfiniteNoise(t_pppParam::e_type para);
+  t_irc addNoiseToIono(char sys);
+
+  bool resetRefSatellitesLastEpoch(std::vector<t_pppSatObs*>& obsVector);
 
   bncTime         _epoTime;
@@ -151,6 +176,4 @@
   t_slip          _slips[t_prn::MAXPRN+1];
   int             _numSat;
-  int             _numEpoProcessing;
-  int             _numAllUsedLCs;
   t_dop           _dop;
   bncTime         _firstEpoTime;
Index: trunk/BNC/src/PPP/pppObsPool.cpp
===================================================================
--- trunk/BNC/src/PPP/pppObsPool.cpp	(revision 9304)
+++ trunk/BNC/src/PPP/pppObsPool.cpp	(revision 9386)
@@ -50,5 +50,9 @@
   }
   _vTec = 0;
-  _refSatChangeRequired = false;
+  _refSatChangeRequiredMap['G'] = false;
+  _refSatChangeRequiredMap['R'] = false;
+  _refSatChangeRequiredMap['E'] = false;
+  _refSatChangeRequiredMap['C'] = false;
+
 }
 
Index: trunk/BNC/src/PPP/pppObsPool.h
===================================================================
--- trunk/BNC/src/PPP/pppObsPool.h	(revision 9304)
+++ trunk/BNC/src/PPP/pppObsPool.h	(revision 9386)
@@ -5,4 +5,5 @@
 #include <deque>
 #include <QMap>
+#include <iostream>
 #include "pppSatObs.h"
 #include "bnctime.h"
@@ -57,7 +58,7 @@
   }
 
-  void initRefSatMapElement(char system) {
-    _refSatMap[system] = new t_pppRefSat();
-  }
+  // RefSatMap of the current epoch
+  // ==============================
+  void initRefSatMapElement(char system) {_refSatMap[system] = new t_pppRefSat();}
   void clearRefSatMap() {
     QMapIterator<char, t_pppRefSat*> it(_refSatMap);
@@ -68,17 +69,59 @@
     _refSatMap.clear();
   }
-  t_pppRefSat* getRefSatMapElement(char system) {
-    return _refSatMap[system];
+  QMap<char, t_pppRefSat*> getRefSatMap() {return _refSatMap;}
+  t_pppRefSat* getRefSatMapElement(char sys) {return _refSatMap[sys];}
+
+
+  // RefSatMap of the last epoch
+  // ===========================
+  QMap<char, t_prn> getRefSatMapLastEpoch() {return _refSatMapLastEpoch;}
+  t_prn getRefSatMapElementLastEpoch(char sys) {return _refSatMapLastEpoch[sys];}
+  void setRefSatMapElementLastEpoch(char sys, t_prn prn) {_refSatMapLastEpoch[sys] = prn;}
+  void saveLastEpoRefSats() {
+    QMapIterator<char, t_pppRefSat*> it(getRefSatMap());
+    while (it.hasNext()) {
+      it.next();
+      t_prn prn = it.value()->prn();
+      setRefSatMapElementLastEpoch(prn.system(), prn);
+    };
   }
-  QMap<char, t_pppRefSat*> getRefSatMap() {return _refSatMap;}
 
-  void setRefSatChangeRequired(bool refSatChangeRequired) {
-    _refSatChangeRequired = refSatChangeRequired;
+  // RefSat change required in current epoch
+  // =======================================
+  void setRefSatChangeRequired(char sys, bool refSatChangeRequired) {
+    _refSatChangeRequiredMap[sys] = refSatChangeRequired;
   }
-  bool refSatChangeRequired() {return _refSatChangeRequired;}
+  bool refSatChangeRequired() {
+    QMapIterator<char, bool> it(_refSatChangeRequiredMap);
+      while (it.hasNext()) {
+        it.next();
+        if (it.value() == true) {
+          return true;
+        }
+      }
+    return false;
+  }
+  bool refSatChangeRequired(char sys) {
+    return _refSatChangeRequiredMap[sys];
+  }
 
-  void setHistoricalRefSatList(QList<t_prn>& historicalRefSats) {_historicalRefSats = historicalRefSats;}
-
-  bool hasHistoricalRefSat(t_prn prn) {return _historicalRefSats.contains(prn);}
+  // RefSat changed in current epoch (different from last epoch)
+  // ===========================================================
+  void setRefSatChanged(char sys, bool refSatChanged) {
+    _refSatChangedMap[sys] = refSatChanged;
+  }
+  bool refSatChanged() {
+    QMapIterator<char, bool> it(_refSatChangedMap);
+      while (it.hasNext()) {
+        it.next();
+        if (it.value() == true) {
+          return true;
+        }
+      }
+    return false;
+  }
+  bool refSatChanged(char sys) {
+    return _refSatChangedMap[sys];
+  }
 
  private:
@@ -88,6 +131,7 @@
   std::deque<t_epoch*>     _epochs;
   QMap<char, t_pppRefSat*> _refSatMap;
-  bool                     _refSatChangeRequired;
-  QList<t_prn>             _historicalRefSats;
+  QMap<char, bool>         _refSatChangeRequiredMap;
+  QMap<char, bool>         _refSatChangedMap;
+  QMap<char, t_prn>        _refSatMapLastEpoch;
 };
 
Index: trunk/BNC/src/PPP/pppParlist.cpp
===================================================================
--- trunk/BNC/src/PPP/pppParlist.cpp	(revision 9304)
+++ trunk/BNC/src/PPP/pppParlist.cpp	(revision 9386)
@@ -94,15 +94,15 @@
    case offGR:
      _epoSpec = true;
-     _sigma0  = 1000.0;
+     _sigma0  = OPT->_aprSigOGR;
      _x0      = PPP_CLIENT->offGR();
      break;
    case offGE:
      _epoSpec = true;
-     _sigma0  = 1000.0;
+     _sigma0  = OPT->_aprSigOGE;
      _x0      = PPP_CLIENT->offGE();
      break;
    case offGC:
      _epoSpec = true;
-     _sigma0  = 1000.0;
+     _sigma0  = OPT->_aprSigOGC;
      _x0      = PPP_CLIENT->offGC();
      break;
@@ -113,19 +113,16 @@
      break;
     case ion:
-     _epoSpec = false;
-     _sigma0  = OPT->_aprSigIon;
-     _noise   = OPT->_noiseIon;
-     break;
-   case cBias1:
-   case cBias2:
-     _epoSpec = false;
+      _epoSpec = true;
+      _sigma0  = OPT->_aprSigIon;
+     break;
+   case cBiasG1:   case cBiasR1:   case cBiasE1:   case cBiasC1:
+   case cBiasG2:   case cBiasR2:   case cBiasE2:   case cBiasC2:
+     _epoSpec = true;
      _sigma0  = OPT->_aprSigCodeBias;
-     _noise   = OPT->_noiseCodeBias;
-     break;
-   case pBias1:
-   case pBias2:
-     _epoSpec = false;
+     break;
+   case pBiasG1:   case pBiasR1:   case pBiasE1:   case pBiasC1:
+   case pBiasG2:   case pBiasR2:   case pBiasE2:   case pBiasC2:
+     _epoSpec = true;
      _sigma0  = OPT->_aprSigPhaseBias;
-     _noise   = OPT->_noisePhaseBias;
      break;
   }
@@ -186,4 +183,5 @@
              (OPT->_obsModelType == OPT->DCMcodeBias  && !obs->isReference()) ||
              (OPT->_obsModelType == OPT->DCMphaseBias && !obs->isReference())   ) {
+
       if (obs->prn() == _prn) {
         if      (tLC == _tLC) {
@@ -236,35 +234,53 @@
     }
     break;
-  case cBias1:
-    if  (tLC == t_lc::c1) {
-      return 1.0;
-    }
-    else {
-      return 0.0;
-    }
-    break;
-  case cBias2:
-     if (tLC == t_lc::c2) {
-      return 1.0;
-    }
-    else {
-      return 0.0;
-    }
-    break;
-  case pBias1:
-    if  (tLC == t_lc::l1) {
-      return 1.0;
-    }
-    else {
-      return 0.0;
-    }
-    break;
-  case pBias2:
-    if  (tLC == t_lc::l2) {
-      return 1.0;
-    }
-    else {
-      return 0.0;
-    }
+  case cBiasG1:
+    if ((obs->prn().system() == 'G') && (tLC == t_lc::c1)) {return 1.0;} else {return 0.0;}
+    break;
+  case cBiasR1:
+    if ((obs->prn().system() == 'R') && (tLC == t_lc::c1)) {return 1.0;} else {return 0.0;}
+    break;
+  case cBiasE1:
+    if ((obs->prn().system() == 'E') && (tLC == t_lc::c1)) {return 1.0;} else {return 0.0;}
+    break;
+  case cBiasC1:
+    if ((obs->prn().system() == 'C') && (tLC == t_lc::c1)) {return 1.0;} else {return 0.0;}
+    break;
+  case cBiasG2:
+    if ((obs->prn().system() == 'G') && (tLC == t_lc::c2)) {return 1.0;} else {return 0.0;}
+    break;
+  case cBiasR2:
+    if ((obs->prn().system() == 'R') && (tLC == t_lc::c2)) {return 1.0;} else {return 0.0;}
+    break;
+  case cBiasE2:
+    if ((obs->prn().system() == 'E') && (tLC == t_lc::c2)) {return 1.0;} else {return 0.0;}
+        break;
+  case cBiasC2:
+    if ((obs->prn().system() == 'C') && (tLC == t_lc::c2)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasG1:
+    if ((obs->prn().system() == 'G') && (tLC == t_lc::l1)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasR1:
+    if ((obs->prn().system() == 'R') && (tLC == t_lc::l1)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasE1:
+    if ((obs->prn().system() == 'E') && (tLC == t_lc::l1)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasC1:
+    if ((obs->prn().system() == 'C') && (tLC == t_lc::l1)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasG2:
+    if ((obs->prn().system() == 'G') && (tLC == t_lc::l2)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasR2:
+    if ((obs->prn().system() == 'R') && (tLC == t_lc::l2)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasE2:
+    if ((obs->prn().system() == 'E') && (tLC == t_lc::l2)) {return 1.0;} else {return 0.0;}
+    break;
+  case pBiasC2:
+    if ((obs->prn().system() == 'C') && (tLC == t_lc::l2)) {return 1.0;} else {return 0.0;}
+    break;
+
   }
   return 0.0;
@@ -286,17 +302,17 @@
     break;
   case clkR:
-    ss << "REC_CLK    ";
+    ss << "REC_CLK     ";
     break;
   case offGR:
-    ss << "OGR        ";
+    ss << "OGR         ";
     break;
   case offGE:
-    ss << "OGE        ";
+    ss << "OGE         ";
     break;
   case offGC:
-    ss << "OGC        ";
+    ss << "OGC         ";
     break;
   case trp:
-    ss << "TRP        ";
+    ss << "TRP         ";
     break;
   case amb:
@@ -306,9 +322,19 @@
     ss << "ION  " << left << setw(3) << t_lc::toString(_tLC) << right << ' ' << _prn.toString();
     break;
-  case cBias1:
-  case cBias2:
-  case pBias1:
-  case pBias2:
-    ss << "BIAS " << left << setw(3) << t_lc::toString(_tLC) << right << ' ' << "REC";
+  case cBiasG1:  case pBiasG1:
+  case cBiasG2:  case pBiasG2:
+    ss << "BIA  " << left << setw(3) << t_lc::toString(_tLC) << right << " G  ";
+    break;
+  case cBiasR1:  case pBiasR1:
+  case cBiasR2:  case pBiasR2:
+    ss << "BIA  " << left << setw(3) << t_lc::toString(_tLC) << right << " R  ";
+    break;
+  case cBiasE1:  case pBiasE1:
+  case cBiasE2:  case pBiasE2:
+    ss << "BIA  " << left << setw(3) << t_lc::toString(_tLC) << right << " E  ";
+    break;
+  case cBiasC1:  case pBiasC1:
+  case cBiasC2:  case pBiasC2:
+    ss << "BIA  " << left << setw(3) << t_lc::toString(_tLC) << right << " C  ";
     break;
   }
@@ -360,6 +386,7 @@
         refPrn = (refSatMap[system])->prn();
       }
-      if ((par->lastObsTime().valid() && (epoTime - par->lastObsTime() > 60.0)) ||
-          ( refPrn == par->prn())) {
+      if ((par->lastObsTime().valid() &&
+          (epoTime - par->lastObsTime() > 60.0)) ||
+          (refPrn == par->prn())) {
         remove = true;
       }
@@ -409,4 +436,46 @@
   required.push_back(new t_pppParam(t_pppParam::crdZ, t_prn(), t_lc::dummy));
 
+  // Receiver Code Biases
+  // --------------------
+  if (OPT->_obsModelType == OPT->DCMcodeBias) {
+    if (OPT->useSystem('G')) {
+      required.push_back(new t_pppParam(t_pppParam::cBiasG1, t_prn(), t_lc::c1));
+      required.push_back(new t_pppParam(t_pppParam::cBiasG2, t_prn(), t_lc::c2));
+    }
+    if (OPT->useSystem('R')) {
+      required.push_back(new t_pppParam(t_pppParam::cBiasR1, t_prn(), t_lc::c1));
+      required.push_back(new t_pppParam(t_pppParam::cBiasR2, t_prn(), t_lc::c2));
+    }
+    if (OPT->useSystem('E')) {
+      required.push_back(new t_pppParam(t_pppParam::cBiasE1, t_prn(), t_lc::c1));
+      required.push_back(new t_pppParam(t_pppParam::cBiasE2, t_prn(), t_lc::c2));
+    }
+    if (OPT->useSystem('C')) {
+      required.push_back(new t_pppParam(t_pppParam::cBiasC1, t_prn(), t_lc::c1));
+      required.push_back(new t_pppParam(t_pppParam::cBiasC2, t_prn(), t_lc::c2));
+    }
+  }
+
+  // Receiver Phase Biases
+  // ---------------------
+  if ((OPT->_obsModelType == OPT->DCMphaseBias) ||
+      (OPT->_obsModelType == OPT->PPPRTK)     ) {
+    if (OPT->useSystem('G')) {
+      required.push_back(new t_pppParam(t_pppParam::pBiasG1, t_prn(), t_lc::l1));
+      required.push_back(new t_pppParam(t_pppParam::pBiasG2, t_prn(), t_lc::l2));
+    }
+    if (OPT->useSystem('R')) {
+      required.push_back(new t_pppParam(t_pppParam::pBiasR1, t_prn(), t_lc::l1));
+      required.push_back(new t_pppParam(t_pppParam::pBiasR2, t_prn(), t_lc::l2));
+    }
+    if (OPT->useSystem('E')) {
+      required.push_back(new t_pppParam(t_pppParam::pBiasE1, t_prn(), t_lc::l1));
+      required.push_back(new t_pppParam(t_pppParam::pBiasE2, t_prn(), t_lc::l2));
+    }
+    if (OPT->useSystem('C')) {
+      required.push_back(new t_pppParam(t_pppParam::pBiasC1, t_prn(), t_lc::l1));
+      required.push_back(new t_pppParam(t_pppParam::pBiasC2, t_prn(), t_lc::l2));
+    }
+  }
   // Receiver Clock
   // --------------
@@ -415,5 +484,5 @@
   // GPS-GLONASS Clock Offset
   // ------------------------
-  if (OPT->useSystem('R')) {
+  if (OPT->useSystem('R') && OPT->useSystem('G')) {
     required.push_back(new t_pppParam(t_pppParam::offGR, t_prn(), t_lc::dummy));
   }
@@ -421,5 +490,5 @@
   // GPS-Galileo Clock Offset
   // ------------------------
-  if (OPT->useSystem('E')) {
+  if (OPT->useSystem('E') && OPT->useSystem('G')) {
     required.push_back(new t_pppParam(t_pppParam::offGE, t_prn(), t_lc::dummy));
   }
@@ -427,5 +496,5 @@
   // GPS-BDS Clock Offset
   // ------------------------
-  if (OPT->useSystem('C')) {
+  if (OPT->useSystem('C') && OPT->useSystem('G')) {
     required.push_back(new t_pppParam(t_pppParam::offGC, t_prn(), t_lc::dummy));
   }
@@ -443,9 +512,8 @@
       OPT->_obsModelType == OPT->DCMphaseBias   ) {
     for (unsigned jj = 0; jj < obsVector.size(); jj++) {
-      const t_pppSatObs*        satObs = obsVector[jj];
+      const t_pppSatObs* satObs = obsVector[jj];
       required.push_back(new t_pppParam(t_pppParam::ion, satObs->prn(), t_lc::dummy));
     }
   }
-
   // Ambiguities
   // -----------
@@ -464,19 +532,4 @@
   }
 
-  // Receiver Code Biases
-  // --------------------
-  if (OPT->_obsModelType == OPT->DCMcodeBias) {
-    required.push_back(new t_pppParam(t_pppParam::cBias1, t_prn(), t_lc::c1));
-    required.push_back(new t_pppParam(t_pppParam::cBias2, t_prn(), t_lc::c2));
-  }
-
-  // Receiver Phase Biases
-  // ---------------------
-  if ((OPT->_obsModelType == OPT->DCMphaseBias) ||
-      (OPT->_obsModelType == OPT->PPPRTK)     ) {
-    required.push_back(new t_pppParam(t_pppParam::pBias1, t_prn(), t_lc::l1));
-    required.push_back(new t_pppParam(t_pppParam::pBias2, t_prn(), t_lc::l2));
-  }
-
   // Check if all required parameters are present
   // --------------------------------------------
Index: trunk/BNC/src/PPP/pppParlist.h
===================================================================
--- trunk/BNC/src/PPP/pppParlist.h	(revision 9304)
+++ trunk/BNC/src/PPP/pppParlist.h	(revision 9386)
@@ -15,8 +15,9 @@
 class t_pppParam {
  public:
-  enum e_type {crdX, crdY, crdZ, clkR, amb, offGR, offGE, offGC, trp, ion, cBias1, cBias2, pBias1, pBias2};
+  enum e_type {crdX, crdY, crdZ, clkR, trp, ion, amb, offGR, offGE, offGC,
+               cBiasG1, cBiasR1, cBiasE1, cBiasC1, pBiasG1, pBiasR1, pBiasE1, pBiasC1,
+               cBiasG2, cBiasR2, cBiasE2, cBiasC2, pBiasG2, pBiasR2, pBiasE2, pBiasC2};
 
-  t_pppParam(e_type type, const t_prn& prn, t_lc::type tLC,
-          const std::vector<t_pppSatObs*>* obsVector = 0);
+  t_pppParam(e_type type, const t_prn& prn, t_lc::type tLC, const std::vector<t_pppSatObs*>* obsVector = 0);
 
   ~t_pppParam();
@@ -33,4 +34,8 @@
     _indexOld = _indexNew;
     _indexNew = indexNew;
+  }
+  void resetIndex() {
+    _indexOld = -1;
+    _indexNew = -1;
   }
   int indexOld() const {return _indexOld;}
Index: trunk/BNC/src/PPP/pppSatObs.cpp
===================================================================
--- trunk/BNC/src/PPP/pppSatObs.cpp	(revision 9304)
+++ trunk/BNC/src/PPP/pppSatObs.cpp	(revision 9386)
@@ -63,5 +63,5 @@
 
   // Select pseudoranges and phase observations
-  // ------------------------------------------
+  // -------------------------------------------
   const string preferredAttrib = "G:12&PWCSLXYN G:5&IQX R:12&PC R:3&IQX E:16&BCX E:578&IQX J:1&SLXCZ J:26&SLX J:5&IQX C:IQX I:ABCX S:1&C S:5&IQX";
 
@@ -296,5 +296,5 @@
 
   if (tLC == t_lc::GIM) {
-    retVal = OPT->_sigmaGIM * OPT->_sigmaGIM;
+    retVal = OPT->_sigmaGIM * OPT->_sigmaGIM + OPT->_sigmaGIM * OPT->_sigmaGIM;
   }
 
@@ -304,9 +304,9 @@
 
   map<t_frequency::type, double>::const_iterator it;
-  for (it = codeCoeff.begin(); it != codeCoeff.end(); it++)   {//qDebug() << "codeCoeff : " << t_frequency::toString(it->first).c_str() << ": " << it->second;
+  for (it = codeCoeff.begin(); it != codeCoeff.end(); it++)   {//cout << "codeCoeff : " << t_frequency::toString(it->first).c_str() << ": " << it->second << endl;
     retVal += it->second * it->second * OPT->_sigmaC1 * OPT->_sigmaC1;
   }
 
-  for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {//qDebug() << "phaseCoeff: " << t_frequency::toString(it->first).c_str()  << ": " << it->second;
+  for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {//cout << "phaseCoeff: " << t_frequency::toString(it->first).c_str()  << ": " << it->second << endl;
     retVal += it->second * it->second * OPT->_sigmaL1 * OPT->_sigmaL1;
   }
@@ -316,6 +316,6 @@
   // De-Weight GLONASS and BDS
   // --------------------------
-  if (_prn.system() == 'R' ||
-      _prn.system() == 'C') {
+  if ((_prn.system() == 'R' && (t_lc::includesCode(tLC) ||  t_lc::includesPhase(tLC))) ||
+      (_prn.system() == 'C' && (t_lc::includesCode(tLC) ||  t_lc::includesPhase(tLC)))) {  
     retVal *= 5.0;
   }
@@ -336,5 +336,5 @@
 //
 ////////////////////////////////////////////////////////////////////////////
-double t_pppSatObs::maxRes(t_lc::type tLC) const {//qDebug() << "t_pppSatObs::maxRes(t_lc::type tLC)";
+double t_pppSatObs::maxRes(t_lc::type tLC) const {
   double retVal = 0.0;
 
@@ -345,17 +345,20 @@
 
   map<t_frequency::type, double>::const_iterator it;
-  for (it = codeCoeff.begin(); it != codeCoeff.end(); it++)   {//qDebug() << "codeCoeff: " << it->first << ": " << it->second;
+  for (it = codeCoeff.begin(); it != codeCoeff.end(); it++)   {//cout << "codeCoeff: " << it->first << ": " << it->second << endl;
     retVal += it->second * it->second * OPT->_maxResC1 * OPT->_maxResC1;
   }
-  for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {//qDebug() << "phaseCoeff: " << it->first << ": " << it->second;
+  for (it = phaseCoeff.begin(); it != phaseCoeff.end(); it++) {//cout << "phaseCoeff: " << it->first << ": " << it->second << endl;
     retVal += it->second * it->second * OPT->_maxResL1 * OPT->_maxResL1;
   }
   if (tLC == t_lc::GIM) {
-    retVal = 3.0 * OPT->_sigmaGIM * OPT->_sigmaGIM;
+    retVal = 3.0 * (OPT->_sigmaGIM * OPT->_sigmaGIM + OPT->_sigmaGIM * OPT->_sigmaGIM);
   }
   if (tLC == t_lc::Tz0) {
     retVal = 3.0 * OPT->_sigmaTz0 * OPT->_sigmaTz0;
   }
-  return sqrt(retVal);
+
+  retVal = sqrt(retVal);
+
+  return retVal;
 }
 
Index: trunk/BNC/src/PPP/pppSatObs.h
===================================================================
--- trunk/BNC/src/PPP/pppSatObs.h	(revision 9304)
+++ trunk/BNC/src/PPP/pppSatObs.h	(revision 9386)
@@ -21,4 +21,5 @@
   bool                isReference() const {return _reference;};
   void                setAsReference() {_reference = true;};
+  void                resetReference() {_reference = false;};
   const t_prn&        prn() const {return _prn;}
   const ColumnVector& xc() const {return _xcSat;}
