Index: trunk/BNC/src/PPP/pppClient.cpp
===================================================================
--- trunk/BNC/src/PPP/pppClient.cpp	(revision 10387)
+++ trunk/BNC/src/PPP/pppClient.cpp	(revision 10388)
@@ -67,4 +67,5 @@
     }
   }
+  _offGps = 0.0;
   _offGlo = 0.0;
   _offGal = 0.0;
@@ -301,5 +302,5 @@
       const t_pppSatObs* satObs = obsVector.at(ii);
       char sys = satObs->prn().system();
-      if (satObs->isValid() && 
+      if (satObs->isValid() &&
           (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
         ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
@@ -337,4 +338,58 @@
   return success;
 }
+
+// Compute A Priori Gps Clock Offset
+//////////////////////////////////////////////////////////////////////////////
+double t_pppClient::cmpOffGps(vector<t_pppSatObs*>& obsVector) {
+
+  t_lc::type tLC   = t_lc::dummy;
+  double     offGps = 0.0;
+
+  if (_opt->useSystem('G')) {
+    while (obsVector.size() > 0) {
+      offGps = 0.0;
+      double   maxRes      = 0.0;
+      int      maxResIndex = -1;
+      unsigned nObs        = 0;
+      t_prn    maxResPrn;
+      for (unsigned ii = 0; ii < obsVector.size(); ii++) {
+        const t_pppSatObs* satObs = obsVector.at(ii);
+        if (satObs->prn().system() == 'G') {
+          if (tLC == t_lc::dummy) {
+            tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
+          }
+          if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
+            double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
+            ++nObs;
+            offGps += ll;
+            if (fabs(ll) > fabs(maxRes)) {
+              maxRes      = ll;
+              maxResIndex = ii;
+              maxResPrn   = satObs->prn();
+            }
+          }
+        }
+      }
+
+      if (nObs > 0) {
+        offGps = offGps / nObs;
+      }
+      else {
+        offGps = 0.0;
+      }
+
+      if (fabs(maxRes) > 100.0) {
+        LOG << "t_pppClient::cmpOffGps outlier " << maxResPrn.toString() << " " << maxRes << endl;
+        delete obsVector.at(maxResIndex);
+        obsVector.erase(obsVector.begin() + maxResIndex);
+      }
+      else {
+        break;
+      }
+    }
+  }
+  return offGps;
+}
+
 
 // Compute A Priori Glonass Clock Offset
@@ -443,5 +498,4 @@
   return offGal;
 }
-
 // Compute A Priori BDS Clock Offset
 //////////////////////////////////////////////////////////////////////////////
@@ -638,4 +692,5 @@
     }
 
+    _offGps = cmpOffGps(_obsRover);
     _offGlo = cmpOffGlo(_obsRover);
     _offGal = cmpOffGal(_obsRover);
Index: trunk/BNC/src/PPP/pppClient.h
===================================================================
--- trunk/BNC/src/PPP/pppClient.h	(revision 10387)
+++ trunk/BNC/src/PPP/pppClient.h	(revision 10388)
@@ -36,7 +36,12 @@
   const bncAntex*     antex() const {return _antex;}
   const t_pppStation* staRover() const {return _staRover;}
+  double              offGps() const {return _offGps;}
   double              offGlo() const {return _offGlo;}
   double              offGal() const {return _offGal;}
   double              offBds() const {return _offBds;}
+  void                resetOffGps() {_offGps = 0.0;}
+  void                resetOffGlo() {_offGlo = 0.0;}
+  void                resetOffGal() {_offGal = 0.0;}
+  void                resetOffBds() {_offBds = 0.0;}
 
 
@@ -61,4 +66,5 @@
   t_irc cmpBancroft(const bncTime& epoTime, std::vector<t_pppSatObs*>& obsVector,
                     ColumnVector& xyzc, bool print);
+  double cmpOffGps(std::vector<t_pppSatObs*>& obsVector);
   double cmpOffGlo(std::vector<t_pppSatObs*>& obsVector);
   double cmpOffGal(std::vector<t_pppSatObs*>& obsVector);
@@ -73,4 +79,5 @@
   bncAntex*                 _antex;
   t_pppFilter*              _filter;
+  double                    _offGps;
   double                    _offGlo;
   double                    _offGal;
Index: trunk/BNC/src/PPP/pppFilter.cpp
===================================================================
--- trunk/BNC/src/PPP/pppFilter.cpp	(revision 10387)
+++ trunk/BNC/src/PPP/pppFilter.cpp	(revision 10388)
@@ -310,4 +310,6 @@
   string epoTimeStr = string(_epoTime);
   const vector<t_pppParam*> &params = _parlist->params();
+  int maxNumberOfReset =  (2.0 * obsVector.size()) - 2.0;
+  int numberOfReset = 0;
 
   for (unsigned ii = 0; ii < LCs.size(); ii++) {
@@ -347,5 +349,5 @@
 
         // Check Pre-Fit Residuals
-        /* -----------------------
+        // -----------------------
         else {
           ColumnVector AA(params.size());
@@ -358,9 +360,12 @@
 
           if (fabs(vv) > SLIP) {
+            numberOfReset++;
             LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
                 << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
-            resetAmb(obs->prn(), obsVector, tLC);
-          }
-        }*/
+            if (numberOfReset < maxNumberOfReset) {
+              resetAmb(obs->prn(), obsVector, tLC);
+            }
+          }
+        }
       }
     }
Index: trunk/BNC/src/PPP/pppParlist.cpp
===================================================================
--- trunk/BNC/src/PPP/pppParlist.cpp	(revision 10387)
+++ trunk/BNC/src/PPP/pppParlist.cpp	(revision 10388)
@@ -74,4 +74,8 @@
          const t_pppSatObs* obs = obsVector->at(ii);
          if (obs->prn() == _prn) {
+           double offGps = 0.0;
+           if (_prn.system() == 'G' && tLC != t_lc::MW) {
+             offGps = PPP_CLIENT->offGps();
+           }
            double offGlo = 0.0;
            if (_prn.system() == 'R' && tLC != t_lc::MW) {
@@ -86,9 +90,14 @@
              offBds = PPP_CLIENT->offBds();
            }
-           _x0 = floor((obs->obsValue(tLC) - offGlo - offGal - offBds - obs->cmpValue(tLC)) / obs->lambda(tLC) + 0.5);
+           _x0 = floor((obs->obsValue(tLC) - offGps - offGlo - offGal - offBds - obs->cmpValue(tLC)) / obs->lambda(tLC) + 0.5);
            break;
          }
        }
      }
+     break;
+   case offGps:
+     _epoSpec = true;
+     _sigma0  = OPT->_aprSigClkOff;
+     _x0      = PPP_CLIENT->offGps();
      break;
    case offGlo:
@@ -171,4 +180,7 @@
     if (tLC == t_lc::GIM) {return 0.0;}
     return 1.0;
+  case offGps:
+    if (tLC == t_lc::GIM) {return 0.0;}
+    return (obs->prn().system() == 'G') ? 1.0 : 0.0;
   case offGlo:
     if (tLC == t_lc::GIM) {return 0.0;}
@@ -298,4 +310,7 @@
   case rClk:
     ss << "REC_CLK     ";
+    break;
+  case offGps:
+    ss << "OFF_GPS     ";
     break;
   case offGlo:
@@ -401,4 +416,13 @@
   }
 
+  // check which systems have observations
+  // -------------------------------------
+  _usedSystems['G'] = _usedSystems['R'] = _usedSystems['E'] = _usedSystems['C'] = 0;
+  for (unsigned jj = 0; jj < obsVector.size(); jj++) {
+    const t_pppSatObs* satObs = obsVector[jj];
+    char sys = satObs->prn().system();
+    _usedSystems[sys]++;
+  }
+
   // Check whether parameters have observations
   // ------------------------------------------
@@ -435,27 +459,44 @@
   required.push_back(new t_pppParam(t_pppParam::crdZ, t_prn(), t_lc::dummy));
 
-  // Receiver Clock
-  // --------------
+  // Receiver Clocks
+  // ---------------
   required.push_back(new t_pppParam(t_pppParam::rClk, t_prn(), t_lc::dummy));
 
   // GLONASS Clock Offset
   // --------------------
-  if ((OPT->useSystem('G') && OPT->useSystem('R')) ||
-      (OPT->useSystem('E') && OPT->useSystem('R')) ||
-      (OPT->useSystem('C') && OPT->useSystem('R')) ) {
+  if ( _usedSystems.value('R')  &&
+      (_usedSystems.value('G') || _usedSystems.value('E') || _usedSystems.value('C'))) {
     required.push_back(new t_pppParam(t_pppParam::offGlo, t_prn(), t_lc::dummy));
+  }
+  else {
+    PPP_CLIENT->resetOffGlo();
   }
 
   // Galileo Clock Offset
   // --------------------
-  if (OPT->useSystem('G') && OPT->useSystem('E')) {
+  if (_usedSystems.value('E') && _usedSystems.value('G') && _usedSystems.value('G') >= OPT->_minObs) {
     required.push_back(new t_pppParam(t_pppParam::offGal, t_prn(), t_lc::dummy));
+  }
+  else {
+    PPP_CLIENT->resetOffGal();
+  }
+
+  // GPS Clock Offset
+  // --------------------
+  if (_usedSystems.value('E') && _usedSystems.value('G') && _usedSystems.value('G') < OPT->_minObs) {
+    required.push_back(new t_pppParam(t_pppParam::offGps, t_prn(), t_lc::dummy));
+  }
+  else {
+    PPP_CLIENT->resetOffGps();
   }
 
   // BDS Clock Offset
   // ----------------
-  if ((OPT->useSystem('G') && OPT->useSystem('C')) ||
-      (OPT->useSystem('E') && OPT->useSystem('C'))) {
+  if (_usedSystems.contains('C')  &&
+      (_usedSystems.contains('G') || _usedSystems.contains('E'))) {
     required.push_back(new t_pppParam(t_pppParam::offBds, t_prn(), t_lc::dummy));
+  }
+  else {
+    PPP_CLIENT->resetOffBds();
   }
 
Index: trunk/BNC/src/PPP/pppParlist.h
===================================================================
--- trunk/BNC/src/PPP/pppParlist.h	(revision 10387)
+++ trunk/BNC/src/PPP/pppParlist.h	(revision 10388)
@@ -14,5 +14,5 @@
 class t_pppParam {
  public:
-  enum e_type {crdX, crdY, crdZ, rClk, offGlo, offGal, offBds, trp, ion, amb,
+  enum e_type {crdX, crdY, crdZ, rClk, offGps, offGlo, offGal, offBds, trp, ion, amb,
                cBiasG1, cBiasR1, cBiasE1, cBiasC1, pBiasG1, pBiasR1, pBiasE1, pBiasC1,
                cBiasG2, cBiasR2, cBiasE2, cBiasC2, pBiasG2, pBiasR2, pBiasE2, pBiasC2};
@@ -104,4 +104,5 @@
   const std::vector<t_pppParam*>& params() const {return _params;}
   std::vector<t_pppParam*>& params() {return _params;}
+  const QMap<char, int>& usedSystems() const {return _usedSystems;}
   void printResult(const bncTime& epoTime, const SymmetricMatrix& QQ,
                    const ColumnVector& xx) const;
@@ -110,4 +111,5 @@
  private:
   std::vector<t_pppParam*> _params;
+  QMap<char, int>          _usedSystems;
 };
 
