source: ntrip/trunk/BNC/src/bncantex.cpp

Last change on this file was 10234, checked in by stuerze, 6 months ago

minor changes

File size: 13.5 KB
RevLine 
[2880]1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncAntex
30 *
31 * Purpose: Antenna Phase Centers and Variations from ANTEX File
32 *
33 * Author: L. Mervart
34 *
35 * Created: 26-Jan-2011
36 *
[7521]37 * Changes:
[2880]38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
[2890]42#include <newmatio.h>
[2880]43
44#include "bncantex.h"
[6041]45#include "pppModel.h"
[2880]46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51bncAntex::bncAntex() {
52}
53
[5754]54// Constructor
55////////////////////////////////////////////////////////////////////////////
56bncAntex::bncAntex(const char* fileName) {
[9598]57 readFile(QString(fileName));//print();
[5754]58}
59
[2880]60// Destructor
61////////////////////////////////////////////////////////////////////////////
62bncAntex::~bncAntex() {
[2882]63 QMapIterator<QString, t_antMap*> it(_maps);
64 while (it.hasNext()) {
65 it.next();
66 delete it.value();
67 }
[10234]68 _maps.clear();
[2880]69}
70
[7521]71// Print
[2880]72////////////////////////////////////////////////////////////////////////////
[2887]73void bncAntex::print() const {
[6405]74 QMapIterator<QString, t_antMap*> itAnt(_maps);
75 while (itAnt.hasNext()) {
76 itAnt.next();
77 t_antMap* map = itAnt.value();
[8204]78 cout << map->antName.toLatin1().data() << endl;
[2890]79 cout << " " << map->zen1 << " " << map->zen2 << " " << map->dZen << endl;
[6405]80 QMapIterator<t_frequency::type, t_frqMap*> itFrq(map->frqMap);
81 while (itFrq.hasNext()) {
82 itFrq.next();
83 const t_frqMap* frqMap = itFrq.value();
[9598]84 cout << t_frequency::toString(itFrq.key()) << ":\n"
85 << frqMap->neu[0] << " "
86 << frqMap->neu[1] << " "
87 << frqMap->neu[2] << endl;
88 cout << frqMap->pattern.t();
[2890]89 }
90 cout << endl;
[2887]91 }
92}
93
[7521]94// Print
95////////////////////////////////////////////////////////////////////////////
96QString bncAntex::pcoSinexString(const std::string& antName, t_frequency::type frqType) {
97
98 if (antName.find("NULLANTENNA") != string::npos) {
[7848]99 return QString(" ------ ------ ------");
[7521]100 }
101
102 QString antNameQ = antName.c_str();
103 if (_maps.find(antNameQ) == _maps.end()) {
[7848]104 return QString(" ------ ------ ------");
[7521]105 }
106
107 t_antMap* map = _maps[antNameQ];
108 if (map->frqMap.find(frqType) == map->frqMap.end()) {
[7848]109 return QString(" ------ ------ ------");
[7521]110 }
111
112 t_frqMap* frqMap = map->frqMap[frqType];
113
[9675]114 QString u = QString().asprintf("%+6.4f" ,frqMap->neu[2]); if (u.mid(1,1) == "0") {u.remove(1,1);}
115 QString n = QString().asprintf("%+6.4f" ,frqMap->neu[0]); if (n.mid(1,1) == "0") {n.remove(1,1);}
116 QString e = QString().asprintf("%+6.4f" ,frqMap->neu[1]); if (e.mid(1,1) == "0") {e.remove(1,1);}
[7848]117
118 return QString(" %1 %2 %3").arg(u).arg(n).arg(e);
[7521]119}
120
[10130]121// Print
122////////////////////////////////////////////////////////////////////////////
123QString bncAntex::snxCodeSinexString(const std::string& antName) {
124
125 if (antName.find("NULLANTENNA") != string::npos) {
126 return QString(" ----------");
127 }
128
129 QString antNameQ = antName.c_str();
130 if (_maps.find(antNameQ) == _maps.end()) {
131 return QString(" ----------");
132 }
133 else {
134 return QString(" %1").arg(_maps[antNameQ]->snxCode, 10, QLatin1Char(' '));
135 }
136}
137
[2894]138// Read ANTEX File
[2887]139////////////////////////////////////////////////////////////////////////////
[2882]140t_irc bncAntex::readFile(const QString& fileName) {
[2880]141
[2881]142 QFile inFile(fileName);
143 inFile.open(QIODevice::ReadOnly | QIODevice::Text);
144
145 QTextStream in(&inFile);
146
[8078]147 t_antMap* newAntMap = 0;
148 t_frqMap* newFrqMap = 0;
[2888]149
[2881]150 while ( !in.atEnd() ) {
151 QString line = in.readLine();
[7521]152
[2883]153 // Start of Antenna
154 // ----------------
[2882]155 if (line.indexOf("START OF ANTENNA") == 60) {
[2883]156 if (newAntMap) {
157 delete newAntMap;
[2882]158 return failure;
159 }
160 else {
[3295]161 delete newAntMap;
[2883]162 newAntMap = new t_antMap();
[2882]163 }
[7521]164 }
[2881]165
[2883]166 // End of Antenna
167 // --------------
[2882]168 else if (line.indexOf("END OF ANTENNA") == 60) {
[2883]169 if (newAntMap) {
[3542]170 if (_maps.contains(newAntMap->antName)) {
171 delete _maps[newAntMap->antName];
172 }
[2883]173 _maps[newAntMap->antName] = newAntMap;
174 newAntMap = 0;
[2882]175 }
176 else {
[3295]177 delete newAntMap;
[2882]178 return failure;
179 }
180 }
[2883]181
182 // Antenna Reading in Progress
183 // ---------------------------
184 else if (newAntMap) {
185 if (line.indexOf("TYPE / SERIAL NO") == 60) {
[2889]186 if (line.indexOf("BLOCK I") == 0 ||
[7141]187 line.indexOf("GLONASS") == 0 ||
188 line.indexOf("QZSS") == 0 ||
189 line.indexOf("BEIDOU") == 0 ||
190 line.indexOf("GALILEO") == 0 ||
191 line.indexOf("IRNSS") == 0 ){
[2884]192 newAntMap->antName = line.mid(20,3);
193 }
194 else {
195 newAntMap->antName = line.mid(0,20);
196 }
[2883]197 }
198 else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
[2884]199 QTextStream inLine(&line, QIODevice::ReadOnly);
[7521]200 inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
[2883]201 }
[10130]202 else if (line.indexOf("SINEX CODE") == 60) {
203 QTextStream inLine(&line, QIODevice::ReadOnly);
204 inLine >> newAntMap->snxCode;
205 }
[2883]206
[2885]207 // Start of Frequency
208 // ------------------
[2883]209 else if (line.indexOf("START OF FREQUENCY") == 60) {
210 if (newFrqMap) {
211 delete newFrqMap;
212 delete newAntMap;
213 return failure;
214 }
215 else {
216 newFrqMap = new t_frqMap();
217 }
218 }
219
[2885]220 // End of Frequency
221 // ----------------
[2888]222 else if (line.indexOf("END OF FREQUENCY") == 60) {
[2883]223 if (newFrqMap) {
[6405]224 t_frequency::type frqType = t_frequency::dummy;
[8630]225 // GPS
[6405]226 if (line.indexOf("G01") == 3) {
227 frqType = t_frequency::G1;
[2883]228 }
[6405]229 else if (line.indexOf("G02") == 3) {
230 frqType = t_frequency::G2;
[2883]231 }
[8630]232 else if (line.indexOf("G05") == 3) {
233 frqType = t_frequency::G5;
234 }
235 // GLONASS
[6405]236 else if (line.indexOf("R01") == 3) {
237 frqType = t_frequency::R1;
238 }
239 else if (line.indexOf("R02") == 3) {
240 frqType = t_frequency::R2;
241 }
[8630]242 // Galileo
[7144]243 else if (line.indexOf("E01") == 3) {
244 frqType = t_frequency::E1;
245 }
246 else if (line.indexOf("E05") == 3) {
247 frqType = t_frequency::E5;
248 }
249 else if (line.indexOf("E06") == 3) {
250 frqType = t_frequency::E6;
251 }
252 else if (line.indexOf("E07") == 3) {
253 frqType = t_frequency::E7;
254 }
255 else if (line.indexOf("E08") == 3) {
256 frqType = t_frequency::E8;
257 }
[8630]258 // QZSS
[7145]259 else if (line.indexOf("J01") == 3) {
260 frqType = t_frequency::J1;
261 }
262 else if (line.indexOf("J02") == 3) {
263 frqType = t_frequency::J2;
264 }
265 else if (line.indexOf("J05") == 3) {
266 frqType = t_frequency::J5;
267 }
268 else if (line.indexOf("J06") == 3) {
269 frqType = t_frequency::J6;
270 }
[8630]271 // BDS
272 else if (line.indexOf("C01") == 3) {
273 frqType = t_frequency::C1;
274 }
[7144]275 else if (line.indexOf("C02") == 3) {
276 frqType = t_frequency::C2;
277 }
278 else if (line.indexOf("C06") == 3) {
279 frqType = t_frequency::C6;
280 }
281 else if (line.indexOf("C07") == 3) {
282 frqType = t_frequency::C7;
283 }
[6405]284 if (frqType != t_frequency::dummy) {
285 if (newAntMap->frqMap.find(frqType) != newAntMap->frqMap.end()) {
286 delete newAntMap->frqMap[frqType];
287 }
288 newAntMap->frqMap[frqType] = newFrqMap;
289 }
[2883]290 else {
291 delete newFrqMap;
292 }
293 newFrqMap = 0;
294 }
295 else {
296 delete newAntMap;
297 return failure;
298 }
299 }
300
[2885]301 // Frequency Reading in Progress
302 // -----------------------------
[2883]303 else if (newFrqMap) {
[2891]304 if (line.indexOf("NORTH / EAST / UP") == 60) {
[2885]305 QTextStream inLine(&line, QIODevice::ReadOnly);
306 inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
[2894]307 newFrqMap->neu[0] *= 1e-3;
308 newFrqMap->neu[1] *= 1e-3;
309 newFrqMap->neu[2] *= 1e-3;
[2883]310 }
[2884]311 else if (line.indexOf("NOAZI") == 3) {
[2885]312 QTextStream inLine(&line, QIODevice::ReadOnly);
[2886]313 int nPat = int((newAntMap->zen2-newAntMap->zen1)/newAntMap->dZen) + 1;
314 newFrqMap->pattern.ReSize(nPat);
315 QString dummy;
316 inLine >> dummy;
317 for (int ii = 0; ii < nPat; ii++) {
318 inLine >> newFrqMap->pattern[ii];
319 }
[2894]320 newFrqMap->pattern *= 1e-3;
[2884]321 }
[2883]322 }
323 }
[2881]324 }
[7865]325 inFile.close();
[3034]326 delete newFrqMap;
327 delete newAntMap;
328
[2882]329 return success;
[2880]330}
[2894]331
[3052]332// Satellite Antenna Offset
333////////////////////////////////////////////////////////////////////////////
[7521]334t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
[3055]335 const ColumnVector& xSat, ColumnVector& dx) {
336
[6405]337 t_frequency::type frqType = t_frequency::dummy;
[7145]338
[6405]339 if (prn[0] == 'G') {
340 frqType = t_frequency::G1;
341 }
342 else if (prn[0] == 'R') {
343 frqType = t_frequency::R1;
344 }
[9481]345 else if (prn[0] == 'E') {
346 frqType = t_frequency::E1;
347 }
348 else if (prn[0] == 'C') {
349 frqType = t_frequency::C2;
350 }
351 else if (prn[0] == 'S') {
352 frqType = t_frequency::S1;
353 }
354 else if (prn[0] == 'J') {
355 frqType = t_frequency::J1;
356 }
357 else if (prn[0] == 'I') {
358 frqType = t_frequency::I5;
359 }
[6405]360
[6971]361 QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn.mid(0,3));
[3052]362 if (it != _maps.end()) {
363 t_antMap* map = it.value();
[6405]364 if (map->frqMap.find(frqType) != map->frqMap.end()) {
[3055]365
[6405]366 double* neu = map->frqMap[frqType]->neu;
[3055]367
[6405]368 // Unit Vectors sz, sy, sx
369 // -----------------------
370 ColumnVector sz = -xSat;
371 sz /= sqrt(DotProduct(sz,sz));
372
373 ColumnVector xSun = BNC_PPP::t_astro::Sun(Mjd);
374 xSun /= sqrt(DotProduct(xSun,xSun));
[7521]375
[6405]376 ColumnVector sy = crossproduct(sz, xSun);
377 sy /= sqrt(DotProduct(sy,sy));
[7521]378
[6405]379 ColumnVector sx = crossproduct(sy, sz);
[3055]380
[6405]381 dx[0] = sx[0] * neu[0] + sy[0] * neu[1] + sz[0] * neu[2];
382 dx[1] = sx[1] * neu[0] + sy[1] * neu[1] + sz[1] * neu[2];
383 dx[2] = sx[2] * neu[0] + sy[2] * neu[1] + sz[2] * neu[2];
[3055]384
[6405]385 return success;
386 }
[3052]387 }
[6405]388
389 return failure;
[3052]390}
391
[7521]392//
[2894]393////////////////////////////////////////////////////////////////////////////
[9481]394double bncAntex::satCorr(const QString& prn, t_frequency::type frqType,
395 double elTx, double azTx, bool& found) const {
396
397 if (_maps.find(prn.mid(0,3)) == _maps.end()) {
398 found = false;
399 return 0.0;
400 };
401
402 t_antMap* map = _maps[prn.mid(0,3)];
403
404 if (map->frqMap.find(frqType) == map->frqMap.end()) {
405 found = false;
406 return 0.0;
407 };
408
409 t_frqMap* frqMap = map->frqMap[frqType];
410
411 double var = 0.0;
412 if (frqMap->pattern.ncols() > 0) {
413 double zenDiff = 999.999;
414 double zenTx = 90.0 - elTx * 180.0 / M_PI;
415 unsigned iZen = 0;
416 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
417 iZen += 1;
418 double newZenDiff = fabs(zen - zenTx);
419 if (newZenDiff < zenDiff) {
420 zenDiff = newZenDiff;
421 var = frqMap->pattern(iZen);
422 }
423 }
424 }
425
426 found = true;
427 return var - frqMap->neu[0] * cos(azTx)*cos(elTx)
428 - frqMap->neu[1] * sin(azTx)*cos(elTx)
429 - frqMap->neu[2] * sin(elTx);
430
431}
432
433//
434////////////////////////////////////////////////////////////////////////////
[6405]435double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
[6694]436 double eleSat, double azSat, bool& found) const {
[2894]437
[6405]438 if (antName.find("NULLANTENNA") != string::npos) {
[2938]439 found = true;
[6405]440 return 0.0;
[2894]441 }
[6405]442
443 QString antNameQ = antName.c_str();
444
445 if (_maps.find(antNameQ) == _maps.end()) {
[2938]446 found = false;
[6405]447 return 0.0;
[2938]448 }
[2894]449
[6405]450 t_antMap* map = _maps[antNameQ];
451 if (map->frqMap.find(frqType) == map->frqMap.end()) {
452 found = false;
453 return 0.0;
454 }
455
456 t_frqMap* frqMap = map->frqMap[frqType];
457
458 double var = 0.0;
459 if (frqMap->pattern.ncols() > 0) {
460 double zenDiff = 999.999;
461 double zenSat = 90.0 - eleSat * 180.0 / M_PI;
462 unsigned iZen = 0;
463 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
464 iZen += 1;
465 double newZenDiff = fabs(zen - zenSat);
466 if (newZenDiff < zenDiff) {
467 zenDiff = newZenDiff;
468 var = frqMap->pattern(iZen);
469 }
470 }
471 }
472
473 found = true;
[6694]474 return var - frqMap->neu[0] * cos(azSat)*cos(eleSat)
475 - frqMap->neu[1] * sin(azSat)*cos(eleSat)
476 - frqMap->neu[2] * sin(eleSat);
477
[5755]478}
Note: See TracBrowser for help on using the repository browser.