66 using namespace StringUtils;
73 const string GDCconfiguration::GDCVersion = string(
"6.3 12/15/2015");
80 void GDCconfiguration::setParameter(std::string cmd)
94 if (cmd.substr(0, 2) ==
"DC")
100 string::size_type
pos = cmd.find_first_of(
",=:");
101 if (
pos == string::npos)
107 label = cmd.substr(0,
pos);
109 value.erase(0,
pos + 1);
112 setParameter(label,
asDouble(value));
118 catch (std::exception& e)
120 Exception E(
"std except: " +
string(e.what()));
133 void GDCconfiguration::setParameter(
const std::string& label,
double value)
137 if (CFG.find(label) == CFG.end())
144 if (CFG[
"Debug"] > 0)
146 *(p_oflog) <<
"GDCconfiguration::setParameter sets " << label
147 <<
" to " << value << endl;
156 catch (std::exception& e)
158 Exception E(
"std except: " +
string(e.what()));
171 void GDCconfiguration::DisplayParameterUsage(ostream& os,
bool advanced)
175 os <<
"GNSSTk Discontinuity Corrector (GDC) v." << GDCVersion
181 map<string, double>::const_iterator it;
182 for (it = CFG.begin(); it != CFG.end(); it++)
184 if (CFGdescription[it->first][0] ==
'*')
190 <<
"=" << it->second;
192 << CFGdescription[it->first]
197 os <<
" Advanced options:\n";
198 for (it = CFG.begin(); it != CFG.end(); it++)
200 if (CFGdescription[it->first][0] !=
'*')
206 <<
"=" << it->second;
208 << CFGdescription[it->first].substr(2)
217 catch (std::exception& e)
219 Exception E(
"std except: " +
string(e.what()));
230 #define setcfg(a, b, c) \
233 CFGdescription[#a] = c; \
243 setcfg(ResetUnique, 0,
"if non-zero, reset the unique number to zero");
247 "nominal timestep of data (seconds) [required - no default!]");
249 "level of diagnostic output to log, from 0(none) to 7(extreme)");
250 setcfg(useCA1, 0,
"use L1 C/A code pseudorange (C1) ()");
251 setcfg(useCA2, 0,
"use L2 C/A code pseudorange (C2) ()");
253 "maximum allowed time gap within a segment (seconds)");
254 setcfg(MinPts, 13,
"minimum number of good points in phase segment ()");
256 "expected WL sigma (WL cycle) [NB = ~0.83*p-range noise(m)]");
258 "expected maximum variation in GF phase in time DT (meters)");
261 "if 0, output Y,M,D,H,M,S else: W,SoW in edit cmds (log uses "
264 "if non-zero, include delete commands in the output cmd list");
270 "* change in raw R-Ph that triggers bias reset (m)");
273 "* delete segments with sig(WL) > this * WLSigma ()");
276 "* sliding window width for WL slip detection = 10+this/dt) (points)");
278 "* minimum segment size for WL small slip search (WLWindowWidth)");
280 "* minimum delta(WL) that produces an obvious slip (WLSigma)");
281 setcfg(WLNSigmaStrip, 3.5,
282 "* delete points with WL > this * computed sigma ()");
283 setcfg(WLNptsOutlierStats, 200,
284 "* maximum segment size to use robust outlier detection (pts)");
285 setcfg(WLRobustWeightLimit, 0.35,
286 "* minimum good weight in robust outlier detection (0<wt<=1)");
290 "* minimum separating WL slips and end of segment, else edit (pts)");
291 setcfg(WLSlipSize, 0.9,
"* minimum WL slip size (WL wavelengths)");
293 "* minimum amount WL slip must exceed noise (WL wavelengths)");
294 setcfg(WLSlipSeparation, 2.5,
295 "* minimum excess/noise ratio of WL slip ()");
298 "* minimum segment length for GF small slip detection (pts)");
301 "* minimum separating GF slips and end of segment, else edit (pts)");
303 "* minimum delta(GF) that produces an obvious slip (GFVariation)");
304 setcfg(GFSlipOutlier, 5,
"* minimum GF outlier magnitude/noise ratio ()");
305 setcfg(GFSlipSize, 0.8,
"* minimum GF slip size (5.4cm wavelengths)");
306 setcfg(GFSlipStepToNoise, 0.1,
"* maximum GF slip step/noise ratio ()");
307 setcfg(GFSlipToStep, 3,
"* minimum GF slip magnitude/step ratio ()");
308 setcfg(GFSlipToNoise, 3,
"* minimum GF slip magnitude/noise ratio ()");
311 "* maximum number of points on each side to fix GF slips ()");
312 setcfg(GFFixDegree, 3,
"* degree of polynomial used to fix GF slips ()");
315 "* limit on RMS fit residuals to fix GF slips, else delete (5.4cm)");
317 "* if non-zero, skip small GF slips unless there is a WL slip");
323 catch (std::exception& e)
325 Exception E(
"std except: " +
string(e.what()));
357 Segment() : nbeg(0), nend(0), npts(0), nseg(0), bias1(0.0), bias2(0.0)
394 explicit Slip(
int in) : index(in), NWL(0), N1(0) {}
406 static const unsigned short FIX;
424 int linearCombinations();
434 int detectObviousSlips(
string which);
440 int firstDifferences(
string which);
445 void WLcomputeStats(list<Segment>::iterator& it);
450 void WLsigmaStrip(list<Segment>::iterator& it);
456 int WLstatSweep(list<Segment>::iterator& it,
int width);
464 int detectWLsmallSlips();
476 bool foundWLsmallSlip(list<Segment>::iterator& it,
int i);
481 int fixAllSlips(
string which);
486 void fixOneSlip(list<Segment>::iterator& kt,
string which);
490 void WLslipFix(list<Segment>::iterator& left,
491 list<Segment>::iterator& right);
507 int GFphaseResiduals(list<Segment>::iterator& it);
513 int detectGFsmallSlips();
536 bool foundGFsmallSlip(
int i,
int nseg,
int iend,
int ibeg,
537 deque<int>& pastIn, deque<int>& futureIn,
542 void GFslipFix(list<Segment>::iterator& left,
543 list<Segment>::iterator& right);
549 long EstimateGFslipFix(list<Segment>::iterator& left,
550 list<Segment>::iterator& right,
unsigned int nb,
551 unsigned int ne,
long n1);
555 int WLconsistencyCheck();
560 string finish(
int iret,
SatPass& svp, vector<string>& editCmds);
567 list<Segment>::iterator createSegment(list<Segment>::iterator sit,
int ibeg,
568 string msg =
string());
576 string dumpSegments(
string msg,
int level = 2,
bool extra =
false);
581 void deleteSegment(list<Segment>::iterator& it,
string msg =
string());
589 if (CFGdescription[a] ==
string())
591 Exception e(
"cfg(UNKNOWN LABEL) : " + a);
624 #define cfg(a) cfg_func(#a)
625 #define log *(p_oflog)
626 static const int L1 = 0;
627 static const int L2 = 1;
628 static const int P1 = 2;
629 static const int P2 = 3;
630 static const int A1 = 4;
631 static const int A2 = 5;
699 std::vector<std::string>& editCmds,
700 std::string& retMessage,
int GLOn_in)
732 vector<double> newdata(6);
748 oss <<
" Missing required obs types. Require";
749 for (i = 0; i < 4; i++)
753 oss <<
"; found only" << found;
755 retMessage = oss.str();
766 vector<unsigned short>
lli(6),
ssi(6);
767 for (i = 0; i < static_cast<int>(svp.
size()); i++)
769 for (j = 0; j < 6; j++)
790 if (sat.
system == SatelliteSystem::Glonass)
794 if (GLOn < -7 || GLOn > 7)
809 <<
" is returning with error code: failed to find GLONASS "
812 retMessage = oss.str();
822 static const double GLOfreq0L1 = 1602.0e6;
823 static const double GLOdfreqL1 = 562.5e3;
824 static const double GLOfreq0L2 = 1246.0e6;
825 static const double GLOdfreqL2 = 437.5e3;
826 static const double F1oF2 = 9.0 / 7.0;
827 static const double F2oF1 = 7.0 / 9.0;
834 wl1r = 1.0 / (1.0 + F2oF1);
835 wl2r = 1.0 / (1.0 + F1oF2);
849 static const double wlwl_GPS =
851 static const double wlgf_GPS = wl2_GPS - wl1_GPS;
860 wl1r = 1.0 / (1.0 + F2oF1);
861 wl2r = 1.0 / (1.0 + F1oF2);
924 retMessage = gp.
finish(iret, svp, editCmds);
932 catch (std::exception& e)
934 Exception E(
"std except: " +
string(e.what()));
955 vector<string> ot =
sp.getObsTypes();
956 for (i = 0; i < static_cast<int>(ot.size()); i++)
962 vector<double> vdata;
963 vector<unsigned short>
lli,
ssi;
964 for (i = 0; i < static_cast<int>(
sp.size()); i++)
969 for (j = 0; j < static_cast<int>(ot.size()); j++)
971 vdata.push_back(
sp.data(i, ot[j]));
972 lli.push_back(
sp.LLI(i, ot[j]));
973 ssi.push_back(
sp.SSI(i, ot[j]));
989 unsigned int i, Ngood;
990 double biasL1, biasL2, dbias;
991 list<Segment>::iterator it;
997 log <<
"\n======== Beg GNSSTK Discontinuity Corrector " <<
GDCUnique
998 <<
" ================================================\n";
999 log <<
"GNSSTK Discontinuity Corrector Ver. " <<
GDCVersion <<
" Run "
1000 << CurrentTime << endl;
1006 log <<
"Error: data time interval is not set...Abort" << endl;
1011 CFG[
"WLWindowWidth"] = 10 + int(0.5 +
CFG[
"WLWindowWidth"] /
CFG[
"DT"]);
1024 for (ilast = -1, i = 0; i < static_cast<int>(
size()); i++)
1056 ilast = it->nbeg = i;
1062 if (
cfg(DT) * (i - ilast) >
cfg(MaxGap))
1084 biasL1 = biasL2 = 0.0;
1087 for (i = it->nbeg; i <= it->nend; i++)
1096 if (dbias >
cfg(RawBiasLimit))
1098 if (
cfg(Debug) >= 2)
1102 << setprecision(3) << biasL1 <<
" "
1111 if (dbias >
cfg(RawBiasLimit))
1113 if (
cfg(Debug) >= 2)
1117 << setprecision(3) << biasL2 <<
" "
1132 if (it->npts <
static_cast<unsigned int>(
cfg(MinPts)))
1142 if (
cfg(Debug) >= 2)
1157 catch (std::exception& e)
1159 Exception E(
"std except: " +
string(e.what()));
1176 double wlr, wlp, wlbias, gfr, gfp;
1177 list<Segment>::iterator it;
1185 for (i = it->nbeg; i <= it->nend; i++)
1201 wlbias = (wlp - wlr) /
wlwl;
1220 if (
cfg(Debug) >= 2)
1231 catch (std::exception& e)
1233 Exception E(
"std except: " +
string(e.what()));
1251 list<Segment>::iterator it;
1272 if (
cfg(Debug) >= 1 &&
1273 it->npts >=
static_cast<unsigned int>(
cfg(MinPts)))
1277 << setprecision(3) <<
" " << it->WLStats.StdDev() <<
" "
1278 << it->WLStats.Average() <<
" " << it->WLStats.Minimum() <<
" "
1279 << it->WLStats.Maximum() <<
" " << it->npts <<
" " << it->nbeg
1280 <<
" - " << it->nend <<
" " << it->bias1 <<
" " << it->bias2
1285 if (it->WLStats.StdDev() >
cfg(WLNSigmaDelete) *
cfg(WLSigma))
1294 if (
double(it->npts) >=
cfg(WLNWindows) *
int(
cfg(WLWindowWidth)))
1316 if (it->npts <
static_cast<unsigned int>(
cfg(MinPts)))
1322 if (
cfg(Debug) >= 4)
1333 catch (std::exception& e)
1335 Exception E(
"std except: " +
string(e.what()));
1354 const double WLobviousNWLLimit =
cfg(WLobviousLimit) *
cfg(WLSigma);
1355 const double GFobviousNWLLimit =
1356 cfg(GFobviousLimit) *
cfg(GFVariation) /
wlgf;
1357 bool outlier, nogood;
1358 unsigned int i, j, ibad, igood, nok;
1360 double limit, wlbias;
1361 list<Segment>::iterator it;
1370 if (
cfg(Debug) >= 5)
1377 limit = (which == string(
"WL") ? WLobviousNWLLimit : GFobviousNWLLimit);
1382 for (i = 0; i < static_cast<int>(
size()); i++)
1398 learn[string(
"points deleted: ") + which +
1399 string(
" slip outlier")]++;
1405 while (it->nbeg < it->nend && it->nbeg <
static_cast<int>(
size()) &&
1411 while (it->nend > it->nbeg && it->nend > 0 &&
1443 for (
unsigned int j = igood + 1; j < ibad; j++)
1451 log <<
"Warning - found an obvious slip, "
1452 <<
"but marking BAD a point already marked with slip "
1457 learn[string(
"points deleted: ") + which +
1458 string(
" slip outlier")]++;
1464 it =
createSegment(it, ibad, which +
string(
" slip gross"));
1475 long(wlbias + (wlbias > 0 ? 0.5 : -0.5));
1500 catch (std::exception& e)
1502 Exception E(
"std except: " +
string(e.what()));
1524 for (i = 0; i < static_cast<int>(
size()); i++)
1534 if (which ==
string(
"WL"))
1546 else if (which ==
string(
"GF"))
1573 catch (std::exception& e)
1575 Exception E(
"std except: " +
string(e.what()));
1593 it->WLStats.Reset();
1597 for (
unsigned int i = it->nbeg; i <= it->nend; i++)
1608 if (it->npts <
static_cast<unsigned int>(
cfg(MinPts)))
1617 catch (std::exception& e)
1619 Exception E(
"std except: " +
string(e.what()));
1636 bool outlier, haveslip;
1637 unsigned short slip;
1639 unsigned int i, j, k;
1640 double wlbias, nsigma, ave;
1645 if (it->npts <
cfg(WLNptsOutlierStats))
1651 vector<double> vecA1, vecA2;
1655 for (j = i = it->nbeg; i <= it->nend; i++)
1662 vecA1.push_back(wlbias);
1663 vecA2.push_back(0.0);
1668 nsigma =
cfg(WLNSigmaStrip) *
mad;
1674 for (k = 0, i = it->nbeg; i < j; k++, i++)
1681 for (j = i = it->nbeg; i <= it->nend; i++)
1690 if (fabs(wlbias - ave) > nsigma ||
1710 learn[
"points deleted: WL sigma stripping"]++;
1712 it->WLStats.Subtract(wlbias);
1720 if (
cfg(Debug) >= 6)
1724 << setprecision(3) <<
" " << setw(3) <<
spdvector[i].flag
1726 <<
" " << setw(13) << fabs(wlbias - ave) <<
" " << setw(5)
1728 <<
" " << setw(3) << i << (outlier ?
" outlier" :
"");
1731 log <<
" " << setw(13) << it->bias1 <<
" " << setw(13)
1744 nsigma =
cfg(WLNSigmaStrip) * it->WLStats.StdDev();
1747 ave = it->WLStats.Average();
1748 for (i = it->nbeg; i <= it->nend; i++)
1758 if (fabs(wlbias - ave) > nsigma)
1767 learn[
"points deleted: WL sigma stripping"]++;
1769 it->WLStats.Subtract(wlbias);
1783 it->nbeg = slipindex;
1787 if (it->npts <
static_cast<unsigned int>(
cfg(MinPts)))
1794 while (it->nbeg < it->nend && !(
spdvector[it->nbeg].flag &
OK))
1798 while (it->nend > it->nbeg && !(
spdvector[it->nend].flag &
OK))
1808 catch (std::exception& e)
1810 Exception E(
"std except: " +
string(e.what()));
1828 unsigned int iminus, i, iplus, uwidth(width);
1829 double wlbias, test, limit;
1847 iminus = i = iplus = it->nbeg;
1851 while (futureStats.
N() < uwidth && iplus <= it->nend)
1861 for (i = it->nbeg; i <= it->nend; i++)
1870 if (pastStats.
N() > 0 && futureStats.
N() > 0)
1882 if (
cfg(Debug) >= 6)
1886 <<
" " << setw(3) << pastStats.
N() <<
" " << setw(7)
1887 << pastStats.
Average() <<
" " << setw(7) << pastStats.
StdDev()
1888 <<
" " << setw(3) << futureStats.
N() <<
" " << setw(7)
1889 << futureStats.
Average() <<
" " << setw(7)
1890 << futureStats.
StdDev() <<
" " << setw(9)
1892 <<
spdvector[i].data[
A2] <<
" " << setw(9) << wlbias <<
" "
1893 << setw(3) << i << endl;
1899 pastStats.
Add(wlbias);
1901 while (futureStats.
N() < uwidth && iplus <= it->nend)
1910 while (
static_cast<int>(pastStats.
N()) > uwidth && iminus <= it->nend)
1927 catch (std::exception& e)
1929 Exception E(
"std except: " +
string(e.what()));
1947 unsigned int k, nok;
1949 list<Segment>::iterator it;
1953 while (!it->WLsweep)
1961 it->WLStats.Reset();
1964 unsigned int i = it->nbeg;
1966 unsigned int halfwidth =
static_cast<unsigned int>(
cfg(WLSlipEdge));
1970 while (i > it->nend || !it->WLsweep)
1985 it->WLStats.Reset();
1996 it->bias1 = long(wlbias + (wlbias > 0 ? 0.5 : -0.5));
2000 if (nok < halfwidth || (it->npts - nok) < halfwidth)
2005 if (
cfg(Debug) >= 6)
2007 log <<
"too near end " <<
GDCUnique <<
" " << i <<
" " << nok
2008 <<
" " << it->npts - nok <<
" "
2031 it->WLStats.Reset();
2034 it->bias1 = long(wlbias + (wlbias > 0 ? 0.5 : -0.5));
2052 catch (std::exception& e)
2054 Exception E(
"std except: " +
string(e.what()));
2081 const unsigned int minMaxWidth = int(
cfg(WLSlipEdge));
2082 unsigned int j, jp, jm, pass4, pass5, Pass;
2090 bool isSlip =
false, halfCycle =
false;
2094 if (
cfg(Debug) >= 6)
2096 oss <<
"WLslip " <<
GDCUnique <<
" " <<
sat <<
" " << setw(2)
2097 << it->nseg <<
" " << setw(3) << i <<
" "
2100 << fixed << setprecision(2) <<
" step=" << step <<
" lim=" << lim
2103 <<
cfg(WLSlipSize) <<
" (2)"
2109 <<
cfg(WLSlipExcess);
2115 if (step >
cfg(WLSlipSize))
2119 else if (step > 0.45)
2125 if (step - lim >
cfg(WLSlipExcess))
2131 double ratio = (step - lim) / lim;
2132 if (
cfg(Debug) >= 6)
2134 oss <<
" (6)" << ratio << (ratio >
cfg(WLSlipSeparation) ?
">" :
"<=")
2135 <<
cfg(WLSlipSeparation);
2137 if (ratio >
cfg(WLSlipSeparation))
2153 double slope = (step - lim) / (8.0 * minMaxWidth);
2154 j = pass4 = pass5 = 0;
2162 }
while (jp < it->nend && !(
spdvector[jp].flag &
OK));
2185 }
while (jm > it->nbeg && !(
spdvector[jm].flag &
OK));
2202 }
while (++j < minMaxWidth);
2205 if (pass4 >= 2 * minMaxWidth - 1)
2209 if (
cfg(Debug) >= 6)
2211 oss <<
" (4)" << pass4 << (pass4 >= 2 * minMaxWidth - 1 ?
">" :
"<=")
2212 << 2 * minMaxWidth - 2;
2215 if (pass5 >= 2 * minMaxWidth - 1)
2220 if (
cfg(Debug) >= 6)
2222 oss <<
" (5)" << pass5 << (pass5 >= 2 * minMaxWidth - 1 ?
">" :
"<=")
2223 << 2 * minMaxWidth - 2;
2228 if (
cfg(Debug) >= 6)
2230 oss <<
" possible WL slip";
2239 j = 2 * step - int(2 * step + (step > 0.0 ? 0.5 : -0.5));
2240 slope = ::fabs(2 * step -
int(2 * step));
2241 if (j % 2 || slope < 3 * lim)
2246 if (Pass >= 4 && halfCycle && j != 0)
2249 << it->nseg <<
" " << setw(3) << i <<
" "
2251 <<
" Warning - possible half-cycle slip of " << j
2252 <<
" WL half-cycles\n";
2255 if (
cfg(Debug) >= 6)
2257 log << oss.str() << endl;
2265 catch (std::exception& e)
2267 Exception E(
"std except: " +
string(e.what()));
2287 unsigned int i, nmax;
2288 list<Segment>::iterator it, kt;
2313 if (it->npts > nmax)
2332 if (which ==
string(
"WL"))
2335 for (i = kt->nbeg; i <= kt->nend; i++)
2349 for (i = kt->nbeg; i <= kt->nend; i++)
2367 if (
cfg(Debug) >= 3)
2378 catch (std::exception& e)
2380 Exception E(
"std except: " +
string(e.what()));
2403 list<Segment>::iterator left, right;
2436 else if (right ==
SegList.end()
2437 || left->npts >= right->npts)
2449 if (which ==
string(
"WL"))
2458 left->npts += right->npts;
2459 left->nend = right->nend;
2471 catch (std::exception& e)
2473 Exception E(
"std except: " +
string(e.what()));
2486 list<Segment>::iterator& right)
2495 double dwl = right->bias1 + right->WLStats.Average() -
2496 (left->bias1 + left->WLStats.Average());
2497 long nwl = long(dwl + (dwl > 0 ? 0.5 : -0.5));
2499 if (
cfg(Debug) >= 6)
2504 <<
" " << left->nseg <<
"-" << right->nseg << fixed
2505 << setprecision(2) <<
" right: " << right->bias1 <<
" + "
2506 << right->WLStats.Average() <<
" - left: " << left->bias1 <<
" + "
2507 << left->WLStats.Average() <<
" = " << dwl <<
" " << nwl << endl;
2512 for (i = right->nbeg; i <= right->nend; i++)
2524 list<Segment>::iterator it = right;
2525 for (it++; it !=
SegList.end(); it++)
2530 for (i = it->nbeg; i <= it->nend; i++)
2538 Slip newSlip(right->nbeg);
2552 catch (std::exception& e)
2554 Exception E(
"std except: " +
string(e.what()));
2568 list<Segment>::iterator& right)
2573 const unsigned int Npts =
static_cast<unsigned int>(
cfg(GFFixNpts));
2574 unsigned int i, nb, ne,
nl, nr;
2587 while (nb > left->nbeg && i < Npts)
2606 while (ne < right->nend && i < Npts)
2626 dn1 =
spdvector[right->nbeg].data[
L2] - right->bias2 -
2628 n1 = long(dn1 + (dn1 > 0 ? 0.5 : -0.5));
2639 if (fabs(n1 + nadj - dnGFR) > 10. * (Rstats.
StdDev() + Lstats.
StdDev()))
2641 if (
cfg(Debug) >= 6)
2646 << setprecision(2) <<
" dbias(GFR): " << dnGFR
2647 <<
" n1+nadj: " << n1 + nadj;
2650 nadj = long(dnGFR + (dnGFR > 0 ? 0.5 : -0.5)) - n1;
2652 if (
cfg(Debug) >= 6)
2654 log <<
" new n1+nadj: " << n1 + nadj << endl;
2659 if (
cfg(Debug) >= 6)
2664 << fixed << setprecision(2)
2665 <<
" dbias: " << right->bias2 - left->bias2 <<
", dn1: " << dn1
2666 <<
", n1: " << n1 <<
", adj: " << nadj <<
" indexes " << nb <<
" "
2667 << ne <<
" " <<
nl <<
" " << nr <<
" segs " << left->nseg <<
" "
2668 << right->nseg <<
" GFR-GFP:L: " << Lstats.
N() <<
" "
2670 <<
" R: " << Rstats.
N() <<
" " << Rstats.
Average() <<
" "
2671 << Rstats.
StdDev() <<
" tests " << n1 + nadj - dnGFR <<
" "
2676 dn1 += right->bias2 - left->bias2;
2677 n1 = long(dn1 + (dn1 > 0 ? 0.5 : -0.5));
2682 for (i = right->nbeg; i <
static_cast<int>(
size()); i++)
2690 list<Segment>::iterator kt;
2691 for (kt = right; kt !=
SegList.end(); kt++)
2695 list<Slip>::iterator jt;
2697 if (jt->index == right->nbeg)
2704 Slip newSlip(right->nbeg);
2706 newSlip.
msg =
"GF only";
2712 jt->msg += string(
" GF");
2724 catch (std::exception& e)
2726 Exception E(
"std except: " +
string(e.what()));
2740 list<Segment>::iterator& right,
unsigned int nb,
2741 unsigned int ne,
long n1)
2746 unsigned int i, k, in[3];
2747 double rof, rmsrof[3];
2755 for (k = 0; k < 3; k++)
2758 PF[in[k]].
Reset(
int(
cfg(GFFixDegree)));
2765 for (k = 0; k < 3; k++)
2767 if (PF[in[k]].N() > 0)
2773 for (i = nb; i <= ne; i++)
2784 - (i < right->nbeg ? left->bias2 - n1 - (nadj + k - 1)
2793 rmsrof[in[k]] = 0.0;
2794 for (i = nb; i <= ne; i++)
2802 (i < right->nbeg ? left->bias2 - n1 - (nadj + k - 1)
2805 rmsrof[in[k]] += rof * rof;
2807 rmsrof[in[k]] = ::sqrt(rmsrof[in[k]]);
2813 for (quit =
false, k = 0; k < 3; k++)
2814 if (rmsrof[in[k]] >
cfg(GFFixMaxRMS))
2816 log <<
"Warning - large RMS ROF in GF slip fix at in,k = "
2817 << in[k] <<
" " << k <<
" " << rmsrof[in[k]] <<
" abort.\n";
2830 if (rmsrof[in[0]] > rmsrof[in[1]])
2832 if (rmsrof[in[1]] < rmsrof[in[2]])
2850 if (rmsrof[in[1]] < rmsrof[in[2]])
2862 log <<
"Warning - local maximum in RMS residuals in "
2873 if (
cfg(Debug) >= 4)
2875 log <<
"EstimateGFslipFix dump " << endl;
2876 for (i = nb; i <= ne; i++)
2884 <<
spdvector[i].flag << fixed << setprecision(3);
2885 for (k = 0; k < 3; k++)
2888 (i < right->nbeg ? left->bias2 - n1 - (nadj + k - 1)
2902 catch (std::exception& e)
2904 Exception E(
"std except: " +
string(e.what()));
2929 for (first =
true, i = nbeg; i <= nend; i++)
2961 catch (std::exception& e)
2963 Exception E(
"std except: " +
string(e.what()));
2982 list<Segment>::iterator it;
2994 for (i = it->nbeg; i <= it->nend; i++)
3011 if (it->npts <
static_cast<unsigned int>(
cfg(MinPts)))
3045 if (it->npts <
static_cast<unsigned int>(
cfg(MinPts)))
3051 if (
cfg(Debug) >= 4)
3062 catch (std::exception& e)
3064 Exception E(
"std except: " +
string(e.what()));
3083 double fit, rbias, prev, tmp;
3087 ndeg = 2 + int(0.5 + (it->nend - it->nbeg + 1) *
cfg(DT) / 3000.0);
3100 for (i = it->nbeg; i <= it->nend; i++)
3109 if (it->PF.isSingular())
3111 log <<
"Polynomial fit to GF range is singular in segment " << it->nseg
3112 <<
"! .. abort." << endl;
3119 for (i = it->nbeg; i <= it->nend; i++)
3127 fit = it->PF.Evaluate(
spdvector[i].ndt);
3163 catch (std::exception& e)
3165 Exception E(
"std except: " +
string(e.what()));
3182 const unsigned int width =
static_cast<unsigned int>(
cfg(GFSlipWidth));
3183 int i, j, iplus, inew, ifirst, nok;
3184 list<Segment>::iterator it;
3191 if (it->npts < 2 * width + 1)
3204 deque<int> pastIndex, futureIndex;
3206 futureStats.
Reset();
3207 i = inew = ifirst = -1;
3211 for (iplus =
static_cast<int>(it->nbeg);
3212 iplus <= static_cast<int>(it->nend + width); iplus++)
3215 if (iplus <=
static_cast<int>(it->nend) &&
3226 if (
static_cast<int>(futureIndex.size()) == width ||
3227 iplus >
static_cast<int>(it->nend))
3229 inew = futureIndex.front();
3230 futureIndex.pop_front();
3236 if (iplus <=
static_cast<int>(it->nend))
3238 futureIndex.push_back(iplus);
3243 futureIndex.push_back(-1);
3270 learn[
"points deleted: GF outlier"]++;
3276 if (
static_cast<int>(pastIndex.size()) == width)
3278 j = pastIndex.front();
3279 pastIndex.pop_front();
3286 pastIndex.push_back(i);
3295 futureIndex, pastStats, futureStats))
3318 catch (std::exception& e)
3320 Exception E(
"std except: " +
string(e.what()));
3336 if (i < 0 || inew < 0)
3346 if (
cfg(Debug) >= 6)
3348 oss <<
"GFoutlier " <<
GDCUnique <<
" " <<
sat <<
" " << setw(3)
3350 << setprecision(3) <<
" p,fave=" << fabs(pmag) <<
"," << fabs(fmag)
3351 <<
" var=" << var <<
" snr=" << fabs(pmag) / var <<
","
3352 << fabs(fmag) / var;
3360 if (pmag * fmag >= 0)
3364 if (
cfg(Debug) >= 6)
3366 oss <<
" (1)" << (isOut ?
"ok" :
"no");
3374 double noise =
cfg(GFSlipOutlier) * var;
3375 if (fabs(pmag) < noise || fabs(fmag) < noise)
3379 if (
cfg(Debug) >= 6)
3381 oss <<
" (2)" << fabs(pmag) / var <<
"or" << fabs(fmag) / var
3382 << (isOut ?
">=" :
"<") <<
cfg(GFSlipOutlier);
3389 if (
cfg(Debug) >= 6)
3391 oss <<
" possible GF outlier";
3397 if (
cfg(Debug) >= 6)
3399 log << oss.str() << endl;
3408 catch (std::exception& e)
3410 Exception E(
"std except: " +
string(e.what()));
3424 deque<int>& pastIn, deque<int>& futureIn,
3435 double mag, pmag, fmag, pvar, fvar;
3437 pmag = fmag = pvar = fvar = 0.0;
3444 if (futureSt.
N() > 0)
3452 if (futureSt.
N() > 1)
3456 mag = (pmag + fmag) / 2.0;
3458 if (
cfg(Debug) >= 6)
3474 << fixed << setprecision(3) <<
" " << setw(3) << pastSt.
N() <<
" "
3475 << setw(7) << pastSt.
Average() <<
" " << setw(7) << pastSt.
StdDev()
3476 <<
" " << setw(3) << futureSt.
N() <<
" " << setw(7)
3477 << futureSt.
Average() <<
" " << setw(7) << futureSt.
StdDev() <<
" "
3478 << setw(7) << mag <<
" " << setw(7) << ::sqrt(pvar + fvar) <<
" "
3479 << setw(9) <<
spdvector[i].data[
A1] <<
" " << setw(7) << pmag
3480 <<
" " << setw(7) << pvar <<
" " << setw(7) << fmag <<
" "
3481 << setw(7) << fvar <<
" " << setw(3) << i << endl;
3488 const double minMag =
cfg(GFSlipSize);
3490 cfg(GFSlipStepToNoise);
3491 const double MTS =
cfg(GFSlipToStep);
3492 const double MTN =
cfg(GFSlipToNoise);
3493 const int Edge = int(
cfg(GFSlipEdge));
3494 const double RangeCheckLimit = 2 *
cfg(WLSigma) / (0.83 *
wlgf);
3496 const double snr = fabs(pmag - fmag) / ::sqrt(pvar + fvar);
3506 if (
cfg(Debug) >= 6)
3508 oss <<
"GFslip " <<
GDCUnique <<
" " <<
sat <<
" " << nseg <<
" "
3510 << setprecision(3) <<
" mag=" << mag
3517 if (fabs(mag) <= minMag)
3521 if (
cfg(Debug) >= 6)
3523 oss <<
" (1)|" << mag << (isSlip ?
"|>" :
"|<=") << minMag;
3535 if (
cfg(Debug) >= 6)
3537 oss <<
" (2)" << snr << (isSlip ?
">" :
"<=") << STN;
3545 if (fabs(mag) <= MTS * fabs(pmag - fmag))
3549 if (
cfg(Debug) >= 6)
3551 oss <<
" (3)" << fabs(mag / (pmag - fmag)) << (isSlip ?
">" :
"<=")
3560 if (fabs(mag) <= MTN * ::sqrt(pvar + fvar))
3564 if (
cfg(Debug) >= 6)
3566 oss <<
" (4)" << fabs(mag) / ::sqrt(pvar + fvar)
3567 << (isSlip ?
">" :
"<=") << MTN;
3575 if (
static_cast<int>(pastSt.
N()) < Edge ||
3576 static_cast<int>(futureSt.
N()) < Edge + 1)
3580 if (
cfg(Debug) >= 6)
3582 oss <<
" (5)" << pastSt.
N() <<
"," << futureSt.
N()
3583 << (isSlip ?
">" :
"<") << Edge;
3592 if (fabs(mag) > RangeCheckLimit)
3594 double magGFR, mtnGFR;
3596 for (j = 0; j < static_cast<int>(pastIn.size()); j++)
3602 if (futureIn[j] > -1)
3611 if (
cfg(Debug) >= 6)
3613 oss <<
"; GFR-GFP has mag: " << magGFR
3614 <<
", |dmag|: " << fabs(mag - magGFR) <<
" and mag/noise "
3618 if (fabs(mag - magGFR) > fabs(magGFR))
3622 if (
cfg(Debug) >= 6)
3624 oss <<
" (6a)" << fabs(mag - magGFR) << (isSlip ?
"<=" :
">")
3636 if (
cfg(Debug) >= 6)
3638 oss <<
" (6b)" << mtnGFR <<
"><3:can" << (isSlip ?
"" :
"not")
3655 while (j >= ibeg && k < 15)
3666 while (j <= iend && k < 15)
3677 if (
cfg(Debug) >= 6)
3679 oss <<
" (7)1stD(GFP)mag=" << magFD
3680 <<
",noise=" << fdStats.
StdDev()
3681 <<
",snr=" << fabs(magFD) / fdStats.
StdDev()
3682 <<
",maxima=" << fdStats.
Minimum() <<
","
3690 if (
cfg(Debug) >= 6)
3692 oss <<
" (8)skipGFsmall";
3702 oss <<
" possible GF slip";
3706 oss <<
" not a GF slip";
3708 if (
cfg(Debug) >= 6)
3710 log << oss.str() << endl;
3719 catch (std::exception& e)
3721 Exception E(
"std except: " +
string(e.what()));
3740 const int N = 2 * int(
cfg(WLWindowWidth));
3741 double mag, absmag, factor =
wl2 /
wlgf;
3745 for (i = 0; i < static_cast<int>(
size()); i++)
3765 while (k <
static_cast<int>(
size()) &&
3766 static_cast<int>(futureStats.
N()) < N)
3776 while (k >= 0 &&
static_cast<int>(pastStats.
N()) < N)
3792 if (absmag >
cfg(WLSlipSize) && absmag > pastStats.
StdDev() &&
3793 absmag > futureStats.
StdDev())
3796 nwl = long(mag + (mag > 0 ? 0.5 : -0.5));
3804 for (k = i; k < static_cast<int>(
size()); k++)
3821 if (
cfg(Debug) >= 7)
3828 <<
" " << pastStats.
StdDev() <<
" "
3831 <<
" " << futureStats.
StdDev() <<
" "
3844 catch (std::exception& e)
3846 Exception E(
"std except: " +
string(e.what()));
3867 int i, ifirst, ilast, npts;
3868 long N1, N2, prevN1, prevN2;
3869 double slipL1, slipL2, WLbias, GFbias;
3871 list<Slip>::iterator jt;
3886 WLbias = GFbias = slipL1 = slipL2 = 0.0;
3887 prevN1 = prevN2 = 0L;
3889 for (i = 0; i < static_cast<int>(
size()); i++)
3896 if (i ==
static_cast<int>(
size()) - 1)
3915 if (i - ilast > 2 &&
cfg(OutputDeletes) != 0)
3919 ostringstream stst1;
3925 stst1 <<
sat <<
",";
3926 if (
cfg(OutputGPSTime))
3936 stst1 <<
" # begin delete of " <<
asString(i + 1 - ilast)
3939 editCmds.push_back(stst1.str());
3942 ostringstream stst2;
3948 stst2 <<
sat <<
",";
3949 if (
cfg(OutputGPSTime))
3959 stst2 <<
" # end delete of " <<
asString(i + 1 - ilast)
3962 editCmds.push_back(stst2.str());
3964 else if (i - ilast > 1 &&
cfg(OutputDeletes) != 0)
3968 stst <<
"-DS" <<
sat <<
",";
3969 if (
cfg(OutputGPSTime))
3977 editCmds.push_back(stst.str());
3985 if (jt !=
SlipList.end() && i == jt->index)
3989 N2 = jt->N1 - jt->NWL;
3990 slipL1 += double(N1);
3991 slipL2 += double(N2);
3994 if (N1 - prevN1 != 0)
3997 stst <<
"-BD+" <<
sat <<
",L1,";
3998 if (
cfg(OutputGPSTime))
4006 stst <<
"," << N1 - prevN1;
4007 if (!jt->msg.empty())
4009 stst <<
" # " << jt->msg;
4012 editCmds.push_back(stst.str());
4014 if (N2 - prevN2 != 0)
4017 stst <<
"-BD+" <<
sat <<
",L2,";
4018 if (
cfg(OutputGPSTime))
4026 stst <<
"," << N2 - prevN2;
4027 if (!jt->msg.empty())
4029 stst <<
" # " << jt->msg;
4031 editCmds.push_back(stst.str());
4039 if (i >=
static_cast<int>(
size()))
4068 WLbias = (wlp - wlr) /
wlwl;
4072 (wlp - wlr) /
wlwl - WLbias;
4084 SegList.begin()->nend =
static_cast<int>(
size()) - 1;
4088 if (
cfg(Debug) >= 2)
4094 for (i = 0; i < static_cast<int>(editCmds.size()); i++)
4095 if (
cfg(Debug) >= 2)
4097 log <<
"EditCmd: " <<
GDCUnique <<
" " << editCmds[i] << endl;
4103 for (i = 0; i < static_cast<int>(
size()); i++)
4146 for (list<Segment>::iterator it =
SegList.begin(); it !=
SegList.end();
4149 i = (it->nend - it->nbeg + 1);
4151 << it->nseg <<
": " << setw(4) << it->npts <<
"/" << setw(4) << i
4152 <<
" pts, # " << setw(4) << it->nbeg <<
"-" << setw(4) << it->nend
4157 oss << fixed << setprecision(3) <<
" bias(wl)=" << setw(13)
4159 <<
" bias(gf)=" << setw(13) << it->bias2;
4162 ifirst =
static_cast<int>(it->nbeg);
4163 while (ifirst <=
static_cast<int>(it->nend) &&
4169 oss <<
" gap_segs " << setprecision(1) << setw(5) <<
cfg(DT) * i
4170 <<
" s = " << i <<
" pts.";
4172 ilast =
static_cast<int>(it->nend);
4173 while (ilast >=
static_cast<int>(it->nbeg) &&
4184 << setprecision(2) <<
" DT " << fixed << setprecision(2) <<
cfg(DT)
4185 <<
" wavelengths " <<
wl1 * 100.0 <<
" " <<
wl2 * 100.0 <<
" "
4186 <<
wlwl * 100.0 <<
" " <<
wlgf * 100.0;
4187 if (
sat.
system == SatelliteSystem::Glonass)
4189 oss <<
" GLOn " <<
GLOn;
4203 oss <<
" Warning - WL sigma > input (" <<
cfg(WLSigma) <<
")";
4212 <<
" sigma GF variation in meters per DT"
4221 <<
" maximum GF variation in meters per DT"
4227 map<string, int>::const_iterator kt;
4228 for (kt =
learn.begin(); kt !=
learn.end(); kt++)
4230 << kt->second <<
" " << kt->first << endl;
4236 double percent = 100.0 * double(
ngood) / n;
4240 <<
", Pts: " << setw(4) << n <<
" total " << setw(4) <<
ngood
4241 <<
" good " << fixed << setprecision(1) << setw(5) << percent
4250 <<
" is returning with error code: "
4252 ?
"insufficient data"
4254 ?
"required obs types L1,L2,P1/C1,P2 not found"
4256 ?
"singularity in polynomial fit"
4258 ?
"time interval DT was not set"
4261 :
"unknown problem")))))
4265 retMessage = oss.str();
4267 if (
cfg(Debug) >= 2)
4269 log <<
"======== End GNSSTK Discontinuity Corrector " <<
GDCUnique
4270 <<
" ================================================\n";
4280 catch (std::exception& e)
4282 Exception E(
"std except: " +
string(e.what()));
4300 int ibeg,
string msg)
4308 sit->nend = ibeg - 1;
4315 while (sit->nend > sit->nbeg && !(
spdvector[sit->nend].flag &
OK))
4322 s.
npts = sit->npts = 0;
4328 for (i = sit->nbeg; i <= sit->nend; i++)
4336 list<Segment>::iterator skt = sit;
4337 for (skt++; skt !=
SegList.end(); skt++)
4340 if (
cfg(Debug) >= 6)
4344 << s.
nend <<
" biases " << fixed << setprecision(3) << s.
bias1
4345 <<
" " << s.
bias2 << endl;
4348 learn[
"breaks found: " + msg]++;
4350 return SegList.insert(++sit, s);
4356 catch (std::exception& e)
4358 Exception E(
"std except: " +
string(e.what()));
4378 unsigned int i, ifirst;
4380 list<Segment>::iterator it;
4385 oss << label <<
" " <<
GDCUnique <<
" list of Segments ("
4386 <<
SegList.size() <<
"):" << endl;
4399 i = (it->nend - it->nbeg + 1);
4401 oss << label <<
" " <<
GDCUnique <<
" " <<
sat <<
" #" << setw(2)
4402 << it->nseg <<
": " << setw(4) << it->npts <<
"/" << setw(4) << i
4403 <<
" pts, # " << setw(4) << it->nbeg <<
"-" << setw(4) << it->nend
4409 oss << fixed << setprecision(3) <<
" bias(wl)=" << setw(13)
4411 <<
" bias(gf)=" << setw(13) << it->bias2;
4415 while (ifirst <= it->nend && !(
spdvector[ifirst].flag &
OK))
4420 oss <<
" Gap " << setprecision(1) << setw(5) <<
cfg(DT) * i
4421 <<
" s = " << i <<
" pts.";
4424 while (ilast >=
static_cast<int>(it->nbeg) &&
4444 for (i = it->nbeg; i <= it->nend; i++)
4447 oss <<
"DSC" << label <<
" " <<
GDCUnique <<
" " <<
sat <<
" "
4449 << setw(3) <<
spdvector[i].flag << fixed << setprecision(3)
4459 oss <<
" " << setw(13) <<
spdvector[i].data[
A1] <<
" "
4462 oss <<
" " << setw(4) << i;
4465 oss <<
" " << setw(13) << it->bias1
4466 <<
" " << setw(13) << it->bias2;
4480 catch (std::exception& e)
4482 Exception E(
"std except: " +
string(e.what()));
4499 if (
cfg(Debug) >= 6)
4501 log <<
"Delete segment " <<
GDCUnique <<
" " <<
sat <<
" " << it->nseg
4502 <<
" pts " << it->npts <<
" indexes " << it->nbeg <<
" - "
4504 <<
" : " << msg << endl;
4508 for (i = it->nbeg; i <= it->nend; i++)
4512 learn[
"points deleted: " + msg]++;
4516 learn[
"segments deleted: " + msg]++;
4522 catch (std::exception& e)
4524 Exception E(
"std except: " +
string(e.what()));