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

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

minor changes

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