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

Last change on this file since 10132 was 10130, checked in by stuerze, 18 months ago
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 }
[2880]68}
69
[7521]70// Print
[2880]71////////////////////////////////////////////////////////////////////////////
[2887]72void bncAntex::print() const {
[6405]73 QMapIterator<QString, t_antMap*> itAnt(_maps);
74 while (itAnt.hasNext()) {
75 itAnt.next();
76 t_antMap* map = itAnt.value();
[8204]77 cout << map->antName.toLatin1().data() << endl;
[2890]78 cout << " " << map->zen1 << " " << map->zen2 << " " << map->dZen << endl;
[6405]79 QMapIterator<t_frequency::type, t_frqMap*> itFrq(map->frqMap);
80 while (itFrq.hasNext()) {
81 itFrq.next();
82 const t_frqMap* frqMap = itFrq.value();
[9598]83 cout << t_frequency::toString(itFrq.key()) << ":\n"
84 << frqMap->neu[0] << " "
85 << frqMap->neu[1] << " "
86 << frqMap->neu[2] << endl;
87 cout << frqMap->pattern.t();
[2890]88 }
89 cout << endl;
[2887]90 }
91}
92
[7521]93// Print
94////////////////////////////////////////////////////////////////////////////
95QString bncAntex::pcoSinexString(const std::string& antName, t_frequency::type frqType) {
96
97 if (antName.find("NULLANTENNA") != string::npos) {
[7848]98 return QString(" ------ ------ ------");
[7521]99 }
100
101 QString antNameQ = antName.c_str();
102 if (_maps.find(antNameQ) == _maps.end()) {
[7848]103 return QString(" ------ ------ ------");
[7521]104 }
105
106 t_antMap* map = _maps[antNameQ];
107 if (map->frqMap.find(frqType) == map->frqMap.end()) {
[7848]108 return QString(" ------ ------ ------");
[7521]109 }
110
111 t_frqMap* frqMap = map->frqMap[frqType];
112
[9675]113 QString u = QString().asprintf("%+6.4f" ,frqMap->neu[2]); if (u.mid(1,1) == "0") {u.remove(1,1);}
114 QString n = QString().asprintf("%+6.4f" ,frqMap->neu[0]); if (n.mid(1,1) == "0") {n.remove(1,1);}
115 QString e = QString().asprintf("%+6.4f" ,frqMap->neu[1]); if (e.mid(1,1) == "0") {e.remove(1,1);}
[7848]116
117 return QString(" %1 %2 %3").arg(u).arg(n).arg(e);
[7521]118}
119
[10130]120// Print
121////////////////////////////////////////////////////////////////////////////
122QString bncAntex::snxCodeSinexString(const std::string& antName) {
123
124 if (antName.find("NULLANTENNA") != string::npos) {
125 return QString(" ----------");
126 }
127
128 QString antNameQ = antName.c_str();
129 if (_maps.find(antNameQ) == _maps.end()) {
130 return QString(" ----------");
131 }
132 else {
133 return QString(" %1").arg(_maps[antNameQ]->snxCode, 10, QLatin1Char(' '));
134 }
135}
136
[2894]137// Read ANTEX File
[2887]138////////////////////////////////////////////////////////////////////////////
[2882]139t_irc bncAntex::readFile(const QString& fileName) {
[2880]140
[2881]141 QFile inFile(fileName);
142 inFile.open(QIODevice::ReadOnly | QIODevice::Text);
143
144 QTextStream in(&inFile);
145
[8078]146 t_antMap* newAntMap = 0;
147 t_frqMap* newFrqMap = 0;
[2888]148
[2881]149 while ( !in.atEnd() ) {
150 QString line = in.readLine();
[7521]151
[2883]152 // Start of Antenna
153 // ----------------
[2882]154 if (line.indexOf("START OF ANTENNA") == 60) {
[2883]155 if (newAntMap) {
156 delete newAntMap;
[2882]157 return failure;
158 }
159 else {
[3295]160 delete newAntMap;
[2883]161 newAntMap = new t_antMap();
[2882]162 }
[7521]163 }
[2881]164
[2883]165 // End of Antenna
166 // --------------
[2882]167 else if (line.indexOf("END OF ANTENNA") == 60) {
[2883]168 if (newAntMap) {
[3542]169 if (_maps.contains(newAntMap->antName)) {
170 delete _maps[newAntMap->antName];
171 }
[2883]172 _maps[newAntMap->antName] = newAntMap;
173 newAntMap = 0;
[2882]174 }
175 else {
[3295]176 delete newAntMap;
[2882]177 return failure;
178 }
179 }
[2883]180
181 // Antenna Reading in Progress
182 // ---------------------------
183 else if (newAntMap) {
184 if (line.indexOf("TYPE / SERIAL NO") == 60) {
[2889]185 if (line.indexOf("BLOCK I") == 0 ||
[7141]186 line.indexOf("GLONASS") == 0 ||
187 line.indexOf("QZSS") == 0 ||
188 line.indexOf("BEIDOU") == 0 ||
189 line.indexOf("GALILEO") == 0 ||
190 line.indexOf("IRNSS") == 0 ){
[2884]191 newAntMap->antName = line.mid(20,3);
192 }
193 else {
194 newAntMap->antName = line.mid(0,20);
195 }
[2883]196 }
197 else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
[2884]198 QTextStream inLine(&line, QIODevice::ReadOnly);
[7521]199 inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
[2883]200 }
[10130]201 else if (line.indexOf("SINEX CODE") == 60) {
202 QTextStream inLine(&line, QIODevice::ReadOnly);
203 inLine >> newAntMap->snxCode;
204 }
[2883]205
[2885]206 // Start of Frequency
207 // ------------------
[2883]208 else if (line.indexOf("START OF FREQUENCY") == 60) {
209 if (newFrqMap) {
210 delete newFrqMap;
211 delete newAntMap;
212 return failure;
213 }
214 else {
215 newFrqMap = new t_frqMap();
216 }
217 }
218
[2885]219 // End of Frequency
220 // ----------------
[2888]221 else if (line.indexOf("END OF FREQUENCY") == 60) {
[2883]222 if (newFrqMap) {
[6405]223 t_frequency::type frqType = t_frequency::dummy;
[8630]224 // GPS
[6405]225 if (line.indexOf("G01") == 3) {
226 frqType = t_frequency::G1;
[2883]227 }
[6405]228 else if (line.indexOf("G02") == 3) {
229 frqType = t_frequency::G2;
[2883]230 }
[8630]231 else if (line.indexOf("G05") == 3) {
232 frqType = t_frequency::G5;
233 }
234 // GLONASS
[6405]235 else if (line.indexOf("R01") == 3) {
236 frqType = t_frequency::R1;
237 }
238 else if (line.indexOf("R02") == 3) {
239 frqType = t_frequency::R2;
240 }
[8630]241 // Galileo
[7144]242 else if (line.indexOf("E01") == 3) {
243 frqType = t_frequency::E1;
244 }
245 else if (line.indexOf("E05") == 3) {
246 frqType = t_frequency::E5;
247 }
248 else if (line.indexOf("E06") == 3) {
249 frqType = t_frequency::E6;
250 }
251 else if (line.indexOf("E07") == 3) {
252 frqType = t_frequency::E7;
253 }
254 else if (line.indexOf("E08") == 3) {
255 frqType = t_frequency::E8;
256 }
[8630]257 // QZSS
[7145]258 else if (line.indexOf("J01") == 3) {
259 frqType = t_frequency::J1;
260 }
261 else if (line.indexOf("J02") == 3) {
262 frqType = t_frequency::J2;
263 }
264 else if (line.indexOf("J05") == 3) {
265 frqType = t_frequency::J5;
266 }
267 else if (line.indexOf("J06") == 3) {
268 frqType = t_frequency::J6;
269 }
[8630]270 // BDS
271 else if (line.indexOf("C01") == 3) {
272 frqType = t_frequency::C1;
273 }
[7144]274 else if (line.indexOf("C02") == 3) {
275 frqType = t_frequency::C2;
276 }
277 else if (line.indexOf("C06") == 3) {
278 frqType = t_frequency::C6;
279 }
280 else if (line.indexOf("C07") == 3) {
281 frqType = t_frequency::C7;
282 }
[6405]283 if (frqType != t_frequency::dummy) {
284 if (newAntMap->frqMap.find(frqType) != newAntMap->frqMap.end()) {
285 delete newAntMap->frqMap[frqType];
286 }
287 newAntMap->frqMap[frqType] = newFrqMap;
288 }
[2883]289 else {
290 delete newFrqMap;
291 }
292 newFrqMap = 0;
293 }
294 else {
295 delete newAntMap;
296 return failure;
297 }
298 }
299
[2885]300 // Frequency Reading in Progress
301 // -----------------------------
[2883]302 else if (newFrqMap) {
[2891]303 if (line.indexOf("NORTH / EAST / UP") == 60) {
[2885]304 QTextStream inLine(&line, QIODevice::ReadOnly);
305 inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
[2894]306 newFrqMap->neu[0] *= 1e-3;
307 newFrqMap->neu[1] *= 1e-3;
308 newFrqMap->neu[2] *= 1e-3;
[2883]309 }
[2884]310 else if (line.indexOf("NOAZI") == 3) {
[2885]311 QTextStream inLine(&line, QIODevice::ReadOnly);
[2886]312 int nPat = int((newAntMap->zen2-newAntMap->zen1)/newAntMap->dZen) + 1;
313 newFrqMap->pattern.ReSize(nPat);
314 QString dummy;
315 inLine >> dummy;
316 for (int ii = 0; ii < nPat; ii++) {
317 inLine >> newFrqMap->pattern[ii];
318 }
[2894]319 newFrqMap->pattern *= 1e-3;
[2884]320 }
[2883]321 }
322 }
[2881]323 }
[7865]324 inFile.close();
[3034]325 delete newFrqMap;
326 delete newAntMap;
327
[2882]328 return success;
[2880]329}
[2894]330
[3052]331// Satellite Antenna Offset
332////////////////////////////////////////////////////////////////////////////
[7521]333t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
[3055]334 const ColumnVector& xSat, ColumnVector& dx) {
335
[6405]336 t_frequency::type frqType = t_frequency::dummy;
[7145]337
[6405]338 if (prn[0] == 'G') {
339 frqType = t_frequency::G1;
340 }
341 else if (prn[0] == 'R') {
342 frqType = t_frequency::R1;
343 }
[9481]344 else if (prn[0] == 'E') {
345 frqType = t_frequency::E1;
346 }
347 else if (prn[0] == 'C') {
348 frqType = t_frequency::C2;
349 }
350 else if (prn[0] == 'S') {
351 frqType = t_frequency::S1;
352 }
353 else if (prn[0] == 'J') {
354 frqType = t_frequency::J1;
355 }
356 else if (prn[0] == 'I') {
357 frqType = t_frequency::I5;
358 }
[6405]359
[6971]360 QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn.mid(0,3));
[3052]361 if (it != _maps.end()) {
362 t_antMap* map = it.value();
[6405]363 if (map->frqMap.find(frqType) != map->frqMap.end()) {
[3055]364
[6405]365 double* neu = map->frqMap[frqType]->neu;
[3055]366
[6405]367 // Unit Vectors sz, sy, sx
368 // -----------------------
369 ColumnVector sz = -xSat;
370 sz /= sqrt(DotProduct(sz,sz));
371
372 ColumnVector xSun = BNC_PPP::t_astro::Sun(Mjd);
373 xSun /= sqrt(DotProduct(xSun,xSun));
[7521]374
[6405]375 ColumnVector sy = crossproduct(sz, xSun);
376 sy /= sqrt(DotProduct(sy,sy));
[7521]377
[6405]378 ColumnVector sx = crossproduct(sy, sz);
[3055]379
[6405]380 dx[0] = sx[0] * neu[0] + sy[0] * neu[1] + sz[0] * neu[2];
381 dx[1] = sx[1] * neu[0] + sy[1] * neu[1] + sz[1] * neu[2];
382 dx[2] = sx[2] * neu[0] + sy[2] * neu[1] + sz[2] * neu[2];
[3055]383
[6405]384 return success;
385 }
[3052]386 }
[6405]387
388 return failure;
[3052]389}
390
[7521]391//
[2894]392////////////////////////////////////////////////////////////////////////////
[9481]393double bncAntex::satCorr(const QString& prn, t_frequency::type frqType,
394 double elTx, double azTx, bool& found) const {
395
396 if (_maps.find(prn.mid(0,3)) == _maps.end()) {
397 found = false;
398 return 0.0;
399 };
400
401 t_antMap* map = _maps[prn.mid(0,3)];
402
403 if (map->frqMap.find(frqType) == map->frqMap.end()) {
404 found = false;
405 return 0.0;
406 };
407
408 t_frqMap* frqMap = map->frqMap[frqType];
409
410 double var = 0.0;
411 if (frqMap->pattern.ncols() > 0) {
412 double zenDiff = 999.999;
413 double zenTx = 90.0 - elTx * 180.0 / M_PI;
414 unsigned iZen = 0;
415 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
416 iZen += 1;
417 double newZenDiff = fabs(zen - zenTx);
418 if (newZenDiff < zenDiff) {
419 zenDiff = newZenDiff;
420 var = frqMap->pattern(iZen);
421 }
422 }
423 }
424
425 found = true;
426 return var - frqMap->neu[0] * cos(azTx)*cos(elTx)
427 - frqMap->neu[1] * sin(azTx)*cos(elTx)
428 - frqMap->neu[2] * sin(elTx);
429
430}
431
432//
433////////////////////////////////////////////////////////////////////////////
[6405]434double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
[6694]435 double eleSat, double azSat, bool& found) const {
[2894]436
[6405]437 if (antName.find("NULLANTENNA") != string::npos) {
[2938]438 found = true;
[6405]439 return 0.0;
[2894]440 }
[6405]441
442 QString antNameQ = antName.c_str();
443
444 if (_maps.find(antNameQ) == _maps.end()) {
[2938]445 found = false;
[6405]446 return 0.0;
[2938]447 }
[2894]448
[6405]449 t_antMap* map = _maps[antNameQ];
450 if (map->frqMap.find(frqType) == map->frqMap.end()) {
451 found = false;
452 return 0.0;
453 }
454
455 t_frqMap* frqMap = map->frqMap[frqType];
456
457 double var = 0.0;
458 if (frqMap->pattern.ncols() > 0) {
459 double zenDiff = 999.999;
460 double zenSat = 90.0 - eleSat * 180.0 / M_PI;
461 unsigned iZen = 0;
462 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
463 iZen += 1;
464 double newZenDiff = fabs(zen - zenSat);
465 if (newZenDiff < zenDiff) {
466 zenDiff = newZenDiff;
467 var = frqMap->pattern(iZen);
468 }
469 }
470 }
471
472 found = true;
[6694]473 return var - frqMap->neu[0] * cos(azSat)*cos(eleSat)
474 - frqMap->neu[1] * sin(azSat)*cos(eleSat)
475 - frqMap->neu[2] * sin(eleSat);
476
[5755]477}
Note: See TracBrowser for help on using the repository browser.