From 35ff145bca9f5a4bd7e25b5b09b68375bbe84afe Mon Sep 17 00:00:00 2001
From: Tim Everett <tim.everett3@gmail.com>
Date: Tue, 20 Aug 2019 18:20:01 -0600
Subject: [PATCH] - Change outlier threshold to apply directly to phase instead
 of code observations.  For code observations, an adjustment from the phase
 thereshold is used - Add freq option "l1+l2+e5b" as equal to "l1+l2" for
 compatibility with previous version of demo5 code

---
 src/options.c |  2 +-
 src/rtkpos.c  | 19 +++++++++----------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/options.c b/src/options.c
index 1d18d41..60fc709 100644
--- a/src/options.c
+++ b/src/options.c
@@ -40,7 +40,7 @@ static char snrmask_[NFREQ][1024];
 /* system options table ------------------------------------------------------*/
 #define SWTOPT  "0:off,1:on"
 #define MODOPT  "0:single,1:dgps,2:kinematic,3:static,4:static-start,5:movingbase,6:fixed,7:ppp-kine,8:ppp-static,9:ppp-fixed"
-#define FRQOPT  "1:l1,2:l1+l2,3:l1+l2+l5,4:l1+l2+l5+l6"
+#define FRQOPT  "1:l1,2:l1+l2,3:l1+l2+l5,4:l1+l2+l5+l6,2:l1+l2+e5b"
 #define TYPOPT  "0:forward,1:backward,2:combined"
 #define IONOPT  "0:off,1:brdc,2:sbas,3:dual-freq,4:est-stec,5:ionex-tec,6:qzs-brdc,7:qzs-lex,8:stec"
 #define TRPOPT  "0:off,1:saas,2:sbas,3:est-ztd,4:est-ztdgrad,5:ztd"
diff --git a/src/rtkpos.c b/src/rtkpos.c
index 29ae04d..5f780c4 100644
--- a/src/rtkpos.c
+++ b/src/rtkpos.c
@@ -1364,17 +1364,16 @@ static int ddres(rtk_t *rtk, const nav_t *nav, const obsd_t *obs, double dt, con
 
                 /* if residual too large, flag as outlier */
                 k=IB(sat[j],frq,opt);
-				if (rtk->P[k+rtk->nx*k]<SQR(rtk->opt.std[0]/2)) {  /* skip check if bias just intialized */
-                    threshadj=code?1:opt->eratio[frq]; /* adjust threshold by error stdev ratio */
-                    if (opt->maxinno>0.0&&fabs(v[nv])>opt->maxinno/threshadj) {
-                        if (!code) {
-                            rtk->ssat[sat[j]-1].vsat[frq]=0;
-                            rtk->ssat[sat[j]-1].rejc[frq]++;
-                        }
-                        errmsg(rtk,"outlier rejected (sat=%3d-%3d %s%d v=%.3f)\n",
-                                sat[i],sat[j],code?"P":"L",frq+1,v[nv]);
-                        continue;
+                /* adjust threshold by error stdev ratio unless phase bias just initialized*/
+                threshadj=code||(rtk->P[k+rtk->nx*k]>SQR(rtk->opt.std[0]/2))?opt->eratio[frq]:1;
+                if (opt->maxinno>0.0&&fabs(v[nv])>opt->maxinno*threshadj) {
+                    if (!code) {
+                        rtk->ssat[sat[j]-1].vsat[frq]=0;
+                        rtk->ssat[sat[j]-1].rejc[frq]++;
                     }
+                    errmsg(rtk,"outlier rejected (sat=%3d-%3d %s%d v=%.3f)\n",
+                            sat[i],sat[j],code?"P":"L",frq+1,v[nv]);
+                    continue;
                 }
 
                 /* single-differenced measurement error variances */
-- 
GitLab