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

Last change on this file since 10206 was 10130, checked in by stuerze, 16 months ago
File size: 13.5 KB
Line 
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 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <newmatio.h>
43
44#include "bncantex.h"
45#include "pppModel.h"
46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51bncAntex::bncAntex() {
52}
53
54// Constructor
55////////////////////////////////////////////////////////////////////////////
56bncAntex::bncAntex(const char* fileName) {
57 readFile(QString(fileName));//print();
58}
59
60// Destructor
61////////////////////////////////////////////////////////////////////////////
62bncAntex::~bncAntex() {
63 QMapIterator<QString, t_antMap*> it(_maps);
64 while (it.hasNext()) {
65 it.next();
66 delete it.value();
67 }
68}
69
70// Print
71////////////////////////////////////////////////////////////////////////////
72void bncAntex::print() const {
73 QMapIterator<QString, t_antMap*> itAnt(_maps);
74 while (itAnt.hasNext()) {
75 itAnt.next();
76 t_antMap* map = itAnt.value();
77 cout << map->antName.toLatin1().data() << endl;
78 cout << " " << map->zen1 << " " << map->zen2 << " " << map->dZen << endl;
79 QMapIterator<t_frequency::type, t_frqMap*> itFrq(map->frqMap);
80 while (itFrq.hasNext()) {
81 itFrq.next();
82 const t_frqMap* frqMap = itFrq.value();
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();
88 }
89 cout << endl;
90 }
91}
92
93// Print
94////////////////////////////////////////////////////////////////////////////
95QString bncAntex::pcoSinexString(const std::string& antName, t_frequency::type frqType) {
96
97 if (antName.find("NULLANTENNA") != string::npos) {
98 return QString(" ------ ------ ------");
99 }
100
101 QString antNameQ = antName.c_str();
102 if (_maps.find(antNameQ) == _maps.end()) {
103 return QString(" ------ ------ ------");
104 }
105
106 t_antMap* map = _maps[antNameQ];
107 if (map->frqMap.find(frqType) == map->frqMap.end()) {
108 return QString(" ------ ------ ------");
109 }
110
111 t_frqMap* frqMap = map->frqMap[frqType];
112
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);}
116
117 return QString(" %1 %2 %3").arg(u).arg(n).arg(e);
118}
119
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
137// Read ANTEX File
138////////////////////////////////////////////////////////////////////////////
139t_irc bncAntex::readFile(const QString& fileName) {
140
141 QFile inFile(fileName);
142 inFile.open(QIODevice::ReadOnly | QIODevice::Text);
143
144 QTextStream in(&inFile);
145
146 t_antMap* newAntMap = 0;
147 t_frqMap* newFrqMap = 0;
148
149 while ( !in.atEnd() ) {
150 QString line = in.readLine();
151
152 // Start of Antenna
153 // ----------------
154 if (line.indexOf("START OF ANTENNA") == 60) {
155 if (newAntMap) {
156 delete newAntMap;
157 return failure;
158 }
159 else {
160 delete newAntMap;
161 newAntMap = new t_antMap();
162 }
163 }
164
165 // End of Antenna
166 // --------------
167 else if (line.indexOf("END OF ANTENNA") == 60) {
168 if (newAntMap) {
169 if (_maps.contains(newAntMap->antName)) {
170 delete _maps[newAntMap->antName];
171 }
172 _maps[newAntMap->antName] = newAntMap;
173 newAntMap = 0;
174 }
175 else {
176 delete newAntMap;
177 return failure;
178 }
179 }
180
181 // Antenna Reading in Progress
182 // ---------------------------
183 else if (newAntMap) {
184 if (line.indexOf("TYPE / SERIAL NO") == 60) {
185 if (line.indexOf("BLOCK I") == 0 ||
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 ){
191 newAntMap->antName = line.mid(20,3);
192 }
193 else {
194 newAntMap->antName = line.mid(0,20);
195 }
196 }
197 else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
198 QTextStream inLine(&line, QIODevice::ReadOnly);
199 inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
200 }
201 else if (line.indexOf("SINEX CODE") == 60) {
202 QTextStream inLine(&line, QIODevice::ReadOnly);
203 inLine >> newAntMap->snxCode;
204 }
205
206 // Start of Frequency
207 // ------------------
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
219 // End of Frequency
220 // ----------------
221 else if (line.indexOf("END OF FREQUENCY") == 60) {
222 if (newFrqMap) {
223 t_frequency::type frqType = t_frequency::dummy;
224 // GPS
225 if (line.indexOf("G01") == 3) {
226 frqType = t_frequency::G1;
227 }
228 else if (line.indexOf("G02") == 3) {
229 frqType = t_frequency::G2;
230 }
231 else if (line.indexOf("G05") == 3) {
232 frqType = t_frequency::G5;
233 }
234 // GLONASS
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 }
241 // Galileo
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 }
257 // QZSS
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 }
270 // BDS
271 else if (line.indexOf("C01") == 3) {
272 frqType = t_frequency::C1;
273 }
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 }
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 }
289 else {
290 delete newFrqMap;
291 }
292 newFrqMap = 0;
293 }
294 else {
295 delete newAntMap;
296 return failure;
297 }
298 }
299
300 // Frequency Reading in Progress
301 // -----------------------------
302 else if (newFrqMap) {
303 if (line.indexOf("NORTH / EAST / UP") == 60) {
304 QTextStream inLine(&line, QIODevice::ReadOnly);
305 inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
306 newFrqMap->neu[0] *= 1e-3;
307 newFrqMap->neu[1] *= 1e-3;
308 newFrqMap->neu[2] *= 1e-3;
309 }
310 else if (line.indexOf("NOAZI") == 3) {
311 QTextStream inLine(&line, QIODevice::ReadOnly);
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 }
319 newFrqMap->pattern *= 1e-3;
320 }
321 }
322 }
323 }
324 inFile.close();
325 delete newFrqMap;
326 delete newAntMap;
327
328 return success;
329}
330
331// Satellite Antenna Offset
332////////////////////////////////////////////////////////////////////////////
333t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
334 const ColumnVector& xSat, ColumnVector& dx) {
335
336 t_frequency::type frqType = t_frequency::dummy;
337
338 if (prn[0] == 'G') {
339 frqType = t_frequency::G1;
340 }
341 else if (prn[0] == 'R') {
342 frqType = t_frequency::R1;
343 }
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 }
359
360 QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn.mid(0,3));
361 if (it != _maps.end()) {
362 t_antMap* map = it.value();
363 if (map->frqMap.find(frqType) != map->frqMap.end()) {
364
365 double* neu = map->frqMap[frqType]->neu;
366
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));
374
375 ColumnVector sy = crossproduct(sz, xSun);
376 sy /= sqrt(DotProduct(sy,sy));
377
378 ColumnVector sx = crossproduct(sy, sz);
379
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];
383
384 return success;
385 }
386 }
387
388 return failure;
389}
390
391//
392////////////////////////////////////////////////////////////////////////////
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////////////////////////////////////////////////////////////////////////////
434double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
435 double eleSat, double azSat, bool& found) const {
436
437 if (antName.find("NULLANTENNA") != string::npos) {
438 found = true;
439 return 0.0;
440 }
441
442 QString antNameQ = antName.c_str();
443
444 if (_maps.find(antNameQ) == _maps.end()) {
445 found = false;
446 return 0.0;
447 }
448
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;
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
477}
Note: See TracBrowser for help on using the repository browser.