source: ntrip/trunk/BNC/src/PPP/pppParlist.cpp@ 5917

Last change on this file since 5917 was 5917, checked in by mervart, 10 years ago
File size: 11.3 KB
Line 
1
2// Part of BNC, a utility for retrieving decoding and
3// converting GNSS data streams from NTRIP broadcasters.
4//
5// Copyright (C) 2007
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: t_pppParlist
31 *
32 * Purpose: List of estimated parameters
33 *
34 * Author: L. Mervart
35 *
36 * Created: 29-Jul-2014
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42#include <cmath>
43#include <iostream>
44#include <sstream>
45#include <iomanip>
46#include <algorithm>
47#include <newmatio.h>
48
49#include "pppParlist.h"
50#include "pppSatObs.h"
51#include "pppStation.h"
52#include "bncutils.h"
53#include "bncconst.h"
54#include "pppClient.h"
55
56using namespace BNC_PPP;
57using namespace std;
58
59// Constructor
60////////////////////////////////////////////////////////////////////////////
61t_pppParam::t_pppParam(e_type type, const t_prn& prn, t_lc::type tLC,
62 const vector<t_pppSatObs*>* obsVector) {
63
64 _type = type;
65 _prn = prn;
66 _tLC = tLC;
67 _x0 = 0.0;
68 _indexOld = -1;
69 _indexNew = -1;
70 _noise = 0.0;
71 _ambInfo = 0;
72
73 switch (_type) {
74 case crdX:
75 _epoSpec = true;
76 _sigma0 = OPT->_aprSigCrd[0];
77 break;
78 case crdY:
79 _epoSpec = true;
80 _sigma0 = OPT->_aprSigCrd[1];
81 break;
82 case crdZ:
83 _epoSpec = true;
84 _sigma0 = OPT->_aprSigCrd[2];
85 break;
86 case clkR:
87 _epoSpec = true;
88 _sigma0 = 1000.0;
89 break;
90 case amb:
91 _ambInfo = new t_ambInfo();
92 if (obsVector) {
93 for (unsigned ii = 0; ii < obsVector->size(); ii++) {
94 const t_pppSatObs* obs = obsVector->at(ii);
95 if (obs->prn() == _prn) {
96 double offGG = 0;
97 if (_prn.system() == 'R' && tLC != t_lc::MW) {
98 offGG = PPP_CLIENT->offGG();
99 }
100 _x0 = floor((obs->obsValue(tLC) - offGG - obs->cmpValue(tLC)) / obs->lambda(tLC) + 0.5);
101 break;
102 }
103 }
104 }
105 _epoSpec = false;
106 _sigma0 = 100.0;
107 break;
108 case trp:
109 _epoSpec = false;
110 _sigma0 = OPT->_aprSigTrp;
111 _noise = OPT->_noiseTrp;
112 break;
113 }
114}
115
116// Destructor
117////////////////////////////////////////////////////////////////////////////
118t_pppParam::~t_pppParam() {
119 delete _ambInfo;
120}
121
122//
123////////////////////////////////////////////////////////////////////////////
124double t_pppParam::partial(const bncTime& /* epoTime */, const t_pppSatObs* obs,
125 const t_lc::type& tLC) const {
126
127 // Special Case - Melbourne-Wuebbena
128 // ---------------------------------
129 if (tLC == t_lc::MW && _type != amb) {
130 return 0.0;
131 }
132
133 const t_pppStation* sta = PPP_CLIENT->staRover();
134 ColumnVector rhoV = sta->xyzApr() - obs->xc().Rows(1,3);
135
136 switch (_type) {
137 case crdX:
138 return (sta->xyzApr()[0] - obs->xc()[0]) / rhoV.norm_Frobenius();
139 case crdY:
140 return (sta->xyzApr()[1] - obs->xc()[1]) / rhoV.norm_Frobenius();
141 case crdZ:
142 return (sta->xyzApr()[2] - obs->xc()[2]) / rhoV.norm_Frobenius();
143 case clkR:
144 return 1.0;
145 case amb:
146 if (obs->prn() == _prn) {
147 if (tLC == _tLC) {
148 return (obs->lambda(tLC));
149 }
150 else if (tLC == t_lc::lIF && _tLC == t_lc::MW) {
151 return obs->lambda(t_lc::lIF) * obs->lambda(t_lc::MW) / obs->lambda(t_lc::l2);
152 }
153 else {
154 ColumnVector coeff(4);
155 obs->lc(tLC, 0.0, 0.0, 0.0, 0.0, &coeff);
156 if (_tLC == t_lc::l1) {
157 return obs->lambda(t_lc::l1) * coeff(1);
158 }
159 else if (_tLC == t_lc::l2) {
160 return obs->lambda(t_lc::l2) * coeff(2);
161 }
162 }
163 }
164 return 0.0;
165 case trp:
166 return 1.0 / sin(obs->eleSat());
167 }
168
169 return 0.0;
170}
171
172//
173////////////////////////////////////////////////////////////////////////////
174string t_pppParam::toString() const {
175 stringstream ss;
176 switch (_type) {
177 case crdX:
178 ss << "CRD_X";
179 break;
180 case crdY:
181 ss << "CRD_Y";
182 break;
183 case crdZ:
184 ss << "CRD_Z";
185 break;
186 case clkR:
187 ss << "CLK ";
188 break;
189 case amb:
190 ss << "AMB " << left << setw(3) << t_lc::toString(_tLC) << right << ' ' << _prn.toString();
191 break;
192 case trp:
193 ss << "TRP ";
194 break;
195 }
196 return ss.str();
197}
198
199// Constructor
200////////////////////////////////////////////////////////////////////////////
201t_pppParlist::t_pppParlist() {
202}
203
204// Destructor
205////////////////////////////////////////////////////////////////////////////
206t_pppParlist::~t_pppParlist() {
207 for (unsigned ii = 0; ii < _params.size(); ii++) {
208 delete _params[ii];
209 }
210}
211
212//
213////////////////////////////////////////////////////////////////////////////
214t_irc t_pppParlist::set(const bncTime& epoTime, const std::vector<t_pppSatObs*>& obsVector) {
215
216 // Remove some Parameters
217 // ----------------------
218 vector<t_pppParam*>::iterator it = _params.begin();
219 while (it != _params.end()) {
220 t_pppParam* par = *it;
221
222 bool remove = false;
223
224 if (par->epoSpec()) {
225 remove = true;
226 }
227
228 else if (par->type() == t_pppParam::amb) {
229 if (par->lastObsTime().valid() && (epoTime - par->lastObsTime() > 120.0)) {
230 remove = true;
231 }
232 }
233
234 else if (par->type() == t_pppParam::amb) {
235 if (par->lastObsTime().valid() && (epoTime - par->lastObsTime() > 3600.0)) {
236 remove = true;
237 }
238 }
239
240 if (remove) {
241 delete par;
242 it = _params.erase(it);
243 }
244 else {
245 ++it;
246 }
247 }
248
249 // Check whether parameters have observations
250 // ------------------------------------------
251 for (unsigned ii = 0; ii < _params.size(); ii++) {
252 t_pppParam* par = _params[ii];
253 if (par->prn() == 0) {
254 par->setLastObsTime(epoTime);
255 if (par->firstObsTime().undef()) {
256 par->setFirstObsTime(epoTime);
257 }
258 }
259 else {
260 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
261 const t_pppSatObs* satObs = obsVector[jj];
262 if (satObs->prn() == par->prn()) {
263 par->setLastObsTime(epoTime);
264 if (par->firstObsTime().undef()) {
265 par->setFirstObsTime(epoTime);
266 }
267 break;
268 }
269 }
270 }
271 }
272
273 // Required Set of Parameters
274 // --------------------------
275 vector<t_pppParam*> required;
276
277 // Coordinates
278 // -----------
279 required.push_back(new t_pppParam(t_pppParam::crdX, t_prn(), t_lc::dummy));
280 required.push_back(new t_pppParam(t_pppParam::crdY, t_prn(), t_lc::dummy));
281 required.push_back(new t_pppParam(t_pppParam::crdZ, t_prn(), t_lc::dummy));
282
283 // Receiver Clock
284 // --------------
285 required.push_back(new t_pppParam(t_pppParam::clkR, t_prn(), t_lc::dummy));
286
287 // Troposphere
288 // -----------
289 if (OPT->estTrp()) {
290 required.push_back(new t_pppParam(t_pppParam::trp, t_prn(), t_lc::dummy));
291 }
292
293 // Ambiguities
294 // -----------
295 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
296 const t_pppSatObs* satObs = obsVector[jj];
297 const vector<t_lc::type>& ambLCs = OPT->ambLCs(satObs->prn().system());
298 for (unsigned ii = 0; ii < ambLCs.size(); ii++) {
299 required.push_back(new t_pppParam(t_pppParam::amb, satObs->prn(), ambLCs[ii], &obsVector));
300 }
301 }
302
303 // Check if all required parameters are present
304 // --------------------------------------------
305 for (unsigned ii = 0; ii < required.size(); ii++) {
306 t_pppParam* parReq = required[ii];
307
308 bool found = false;
309 for (unsigned jj = 0; jj < _params.size(); jj++) {
310 t_pppParam* parOld = _params[jj];
311 if (parOld->isEqual(parReq)) {
312 found = true;
313 break;
314 }
315 }
316 if (found) {
317 delete parReq;
318 }
319 else {
320 _params.push_back(parReq);
321 }
322 }
323
324 // Set Parameter Indices
325 // ---------------------
326 sort(_params.begin(), _params.end(), t_pppParam::sortFunction);
327
328 for (unsigned ii = 0; ii < _params.size(); ii++) {
329 t_pppParam* par = _params[ii];
330 par->setIndex(ii);
331 for (unsigned jj = 0; jj < obsVector.size(); jj++) {
332 const t_pppSatObs* satObs = obsVector[jj];
333 if (satObs->prn() == par->prn()) {
334 par->setAmbEleSat(satObs->eleSat());
335 par->stepAmbNumEpo();
336 }
337 }
338 }
339
340 return success;
341}
342
343//
344////////////////////////////////////////////////////////////////////////////
345void t_pppParlist::printResult(const bncTime& epoTime, const SymmetricMatrix& QQ,
346 const ColumnVector& xx) const {
347
348 string epoTimeStr = string(epoTime);
349
350 LOG << endl;
351
352 t_pppParam* parX = 0;
353 t_pppParam* parY = 0;
354 t_pppParam* parZ = 0;
355 for (unsigned ii = 0; ii < _params.size(); ii++) {
356 t_pppParam* par = _params[ii];
357 if (par->type() == t_pppParam::crdX) {
358 parX = par;
359 }
360 else if (par->type() == t_pppParam::crdY) {
361 parY = par;
362 }
363 else if (par->type() == t_pppParam::crdZ) {
364 parZ = par;
365 }
366 else {
367 int ind = par->indexNew();
368 LOG << epoTimeStr << ' ' << par->toString() << ' '
369 << setw(10) << setprecision(4) << par->x0() << ' '
370 << showpos << setw(10) << setprecision(4) << xx[ind] << noshowpos << " +- "
371 << setw(8) << setprecision(4) << sqrt(QQ[ind][ind]);
372 if (par->type() == t_pppParam::amb) {
373 LOG << " el = " << setw(6) << setprecision(2) << par->ambEleSat() * 180.0 / M_PI
374 << " epo = " << setw(4) << par->ambNumEpo();
375 }
376 LOG << endl;
377 }
378 }
379
380 if (parX && parY && parZ) {
381 const t_pppStation* sta = PPP_CLIENT->staRover();
382
383 ColumnVector xyz(3);
384 xyz[0] = xx[parX->indexNew()];
385 xyz[1] = xx[parY->indexNew()];
386 xyz[2] = xx[parZ->indexNew()];
387
388 ColumnVector neu(3);
389 xyz2neu(sta->ellApr().data(), xyz.data(), neu.data());
390
391 SymmetricMatrix QQxyz = QQ.SymSubMatrix(1,3);
392
393 SymmetricMatrix QQneu(3);
394 covariXYZ_NEU(QQxyz, sta->ellApr().data(), QQneu);
395
396 LOG << epoTimeStr
397 << " X = " << setprecision(4) << sta->xyzApr()[0] + xyz[0] << " +- "
398 << setprecision(4) << sqrt(QQxyz[0][0])
399
400 << " Y = " << setprecision(4) << sta->xyzApr()[1] + xyz[1] << " +- "
401 << setprecision(4) << sqrt(QQxyz[1][1])
402
403 << " Z = " << setprecision(4) << sta->xyzApr()[2] + xyz[2] << " +- "
404 << setprecision(4) << sqrt(QQxyz[2][2])
405
406 << " dN = " << setprecision(4) << neu[0] << " +- "
407 << setprecision(4) << sqrt(QQneu[0][0])
408
409 << " dE = " << setprecision(4) << neu[1] << " +- "
410 << setprecision(4) << sqrt(QQneu[1][1])
411
412 << " dU = " << setprecision(4) << neu[2] << " +- "
413 << setprecision(4) << sqrt(QQneu[2][2]);
414 LOG << endl;
415 }
416}
417
Note: See TracBrowser for help on using the repository browser.