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

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

revert some changes

File size: 12.8 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, n,e;
114 u.sprintf("%+6.4f" ,frqMap->neu[2]); if (u.mid(1,1) == "0") {u.remove(1,1);}
115 n.sprintf("%+6.4f" ,frqMap->neu[0]); if (n.mid(1,1) == "0") {n.remove(1,1);}
116 e.sprintf("%+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// Read ANTEX File
122////////////////////////////////////////////////////////////////////////////
123t_irc bncAntex::readFile(const QString& fileName) {
124
125 QFile inFile(fileName);
126 inFile.open(QIODevice::ReadOnly | QIODevice::Text);
127
128 QTextStream in(&inFile);
129
130 t_antMap* newAntMap = 0;
131 t_frqMap* newFrqMap = 0;
132
133 while ( !in.atEnd() ) {
134 QString line = in.readLine();
135
136 // Start of Antenna
137 // ----------------
138 if (line.indexOf("START OF ANTENNA") == 60) {
139 if (newAntMap) {
140 delete newAntMap;
141 return failure;
142 }
143 else {
144 delete newAntMap;
145 newAntMap = new t_antMap();
146 }
147 }
148
149 // End of Antenna
150 // --------------
151 else if (line.indexOf("END OF ANTENNA") == 60) {
152 if (newAntMap) {
153 if (_maps.contains(newAntMap->antName)) {
154 delete _maps[newAntMap->antName];
155 }
156 _maps[newAntMap->antName] = newAntMap;
157 newAntMap = 0;
158 }
159 else {
160 delete newAntMap;
161 return failure;
162 }
163 }
164
165 // Antenna Reading in Progress
166 // ---------------------------
167 else if (newAntMap) {
168 if (line.indexOf("TYPE / SERIAL NO") == 60) {
169 if (line.indexOf("BLOCK I") == 0 ||
170 line.indexOf("GLONASS") == 0 ||
171 line.indexOf("QZSS") == 0 ||
172 line.indexOf("BEIDOU") == 0 ||
173 line.indexOf("GALILEO") == 0 ||
174 line.indexOf("IRNSS") == 0 ){
175 newAntMap->antName = line.mid(20,3);
176 }
177 else {
178 newAntMap->antName = line.mid(0,20);
179 }
180 }
181 else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
182 QTextStream inLine(&line, QIODevice::ReadOnly);
183 inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
184 }
185
186 // Start of Frequency
187 // ------------------
188 else if (line.indexOf("START OF FREQUENCY") == 60) {
189 if (newFrqMap) {
190 delete newFrqMap;
191 delete newAntMap;
192 return failure;
193 }
194 else {
195 newFrqMap = new t_frqMap();
196 }
197 }
198
199 // End of Frequency
200 // ----------------
201 else if (line.indexOf("END OF FREQUENCY") == 60) {
202 if (newFrqMap) {
203 t_frequency::type frqType = t_frequency::dummy;
204 // GPS
205 if (line.indexOf("G01") == 3) {
206 frqType = t_frequency::G1;
207 }
208 else if (line.indexOf("G02") == 3) {
209 frqType = t_frequency::G2;
210 }
211 else if (line.indexOf("G05") == 3) {
212 frqType = t_frequency::G5;
213 }
214 // GLONASS
215 else if (line.indexOf("R01") == 3) {
216 frqType = t_frequency::R1;
217 }
218 else if (line.indexOf("R02") == 3) {
219 frqType = t_frequency::R2;
220 }
221 // Galileo
222 else if (line.indexOf("E01") == 3) {
223 frqType = t_frequency::E1;
224 }
225 else if (line.indexOf("E05") == 3) {
226 frqType = t_frequency::E5;
227 }
228 else if (line.indexOf("E06") == 3) {
229 frqType = t_frequency::E6;
230 }
231 else if (line.indexOf("E07") == 3) {
232 frqType = t_frequency::E7;
233 }
234 else if (line.indexOf("E08") == 3) {
235 frqType = t_frequency::E8;
236 }
237 // QZSS
238 else if (line.indexOf("J01") == 3) {
239 frqType = t_frequency::J1;
240 }
241 else if (line.indexOf("J02") == 3) {
242 frqType = t_frequency::J2;
243 }
244 else if (line.indexOf("J05") == 3) {
245 frqType = t_frequency::J5;
246 }
247 else if (line.indexOf("J06") == 3) {
248 frqType = t_frequency::J6;
249 }
250 // BDS
251 else if (line.indexOf("C01") == 3) {
252 frqType = t_frequency::C1;
253 }
254 else if (line.indexOf("C02") == 3) {
255 frqType = t_frequency::C2;
256 }
257 else if (line.indexOf("C06") == 3) {
258 frqType = t_frequency::C6;
259 }
260 else if (line.indexOf("C07") == 3) {
261 frqType = t_frequency::C7;
262 }
263 if (frqType != t_frequency::dummy) {
264 if (newAntMap->frqMap.find(frqType) != newAntMap->frqMap.end()) {
265 delete newAntMap->frqMap[frqType];
266 }
267 newAntMap->frqMap[frqType] = newFrqMap;
268 }
269 else {
270 delete newFrqMap;
271 }
272 newFrqMap = 0;
273 }
274 else {
275 delete newAntMap;
276 return failure;
277 }
278 }
279
280 // Frequency Reading in Progress
281 // -----------------------------
282 else if (newFrqMap) {
283 if (line.indexOf("NORTH / EAST / UP") == 60) {
284 QTextStream inLine(&line, QIODevice::ReadOnly);
285 inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
286 newFrqMap->neu[0] *= 1e-3;
287 newFrqMap->neu[1] *= 1e-3;
288 newFrqMap->neu[2] *= 1e-3;
289 }
290 else if (line.indexOf("NOAZI") == 3) {
291 QTextStream inLine(&line, QIODevice::ReadOnly);
292 int nPat = int((newAntMap->zen2-newAntMap->zen1)/newAntMap->dZen) + 1;
293 newFrqMap->pattern.ReSize(nPat);
294 QString dummy;
295 inLine >> dummy;
296 for (int ii = 0; ii < nPat; ii++) {
297 inLine >> newFrqMap->pattern[ii];
298 }
299 newFrqMap->pattern *= 1e-3;
300 }
301 }
302 }
303 }
304 inFile.close();
305 delete newFrqMap;
306 delete newAntMap;
307
308 return success;
309}
310
311// Satellite Antenna Offset
312////////////////////////////////////////////////////////////////////////////
313t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
314 const ColumnVector& xSat, ColumnVector& dx) {
315
316 t_frequency::type frqType = t_frequency::dummy;
317
318 if (prn[0] == 'G') {
319 frqType = t_frequency::G1;
320 }
321 else if (prn[0] == 'R') {
322 frqType = t_frequency::R1;
323 }
324 else if (prn[0] == 'E') {
325 frqType = t_frequency::E1;
326 }
327 else if (prn[0] == 'C') {
328 frqType = t_frequency::C2;
329 }
330 else if (prn[0] == 'S') {
331 frqType = t_frequency::S1;
332 }
333 else if (prn[0] == 'J') {
334 frqType = t_frequency::J1;
335 }
336 else if (prn[0] == 'I') {
337 frqType = t_frequency::I5;
338 }
339
340 QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn.mid(0,3));
341 if (it != _maps.end()) {
342 t_antMap* map = it.value();
343 if (map->frqMap.find(frqType) != map->frqMap.end()) {
344
345 double* neu = map->frqMap[frqType]->neu;
346
347 // Unit Vectors sz, sy, sx
348 // -----------------------
349 ColumnVector sz = -xSat;
350 sz /= sqrt(DotProduct(sz,sz));
351
352 ColumnVector xSun = BNC_PPP::t_astro::Sun(Mjd);
353 xSun /= sqrt(DotProduct(xSun,xSun));
354
355 ColumnVector sy = crossproduct(sz, xSun);
356 sy /= sqrt(DotProduct(sy,sy));
357
358 ColumnVector sx = crossproduct(sy, sz);
359
360 dx[0] = sx[0] * neu[0] + sy[0] * neu[1] + sz[0] * neu[2];
361 dx[1] = sx[1] * neu[0] + sy[1] * neu[1] + sz[1] * neu[2];
362 dx[2] = sx[2] * neu[0] + sy[2] * neu[1] + sz[2] * neu[2];
363
364 return success;
365 }
366 }
367
368 return failure;
369}
370
371//
372////////////////////////////////////////////////////////////////////////////
373double bncAntex::satCorr(const QString& prn, t_frequency::type frqType,
374 double elTx, double azTx, bool& found) const {
375
376 if (_maps.find(prn.mid(0,3)) == _maps.end()) {
377 found = false;
378 return 0.0;
379 };
380
381 t_antMap* map = _maps[prn.mid(0,3)];
382
383 if (map->frqMap.find(frqType) == map->frqMap.end()) {
384 found = false;
385 return 0.0;
386 };
387
388 t_frqMap* frqMap = map->frqMap[frqType];
389
390 double var = 0.0;
391 if (frqMap->pattern.ncols() > 0) {
392 double zenDiff = 999.999;
393 double zenTx = 90.0 - elTx * 180.0 / M_PI;
394 unsigned iZen = 0;
395 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
396 iZen += 1;
397 double newZenDiff = fabs(zen - zenTx);
398 if (newZenDiff < zenDiff) {
399 zenDiff = newZenDiff;
400 var = frqMap->pattern(iZen);
401 }
402 }
403 }
404
405 found = true;
406 return var - frqMap->neu[0] * cos(azTx)*cos(elTx)
407 - frqMap->neu[1] * sin(azTx)*cos(elTx)
408 - frqMap->neu[2] * sin(elTx);
409
410}
411
412//
413////////////////////////////////////////////////////////////////////////////
414double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
415 double eleSat, double azSat, bool& found) const {
416
417 if (antName.find("NULLANTENNA") != string::npos) {
418 found = true;
419 return 0.0;
420 }
421
422 QString antNameQ = antName.c_str();
423
424 if (_maps.find(antNameQ) == _maps.end()) {
425 found = false;
426 return 0.0;
427 }
428
429 t_antMap* map = _maps[antNameQ];
430 if (map->frqMap.find(frqType) == map->frqMap.end()) {
431 found = false;
432 return 0.0;
433 }
434
435 t_frqMap* frqMap = map->frqMap[frqType];
436
437 double var = 0.0;
438 if (frqMap->pattern.ncols() > 0) {
439 double zenDiff = 999.999;
440 double zenSat = 90.0 - eleSat * 180.0 / M_PI;
441 unsigned iZen = 0;
442 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
443 iZen += 1;
444 double newZenDiff = fabs(zen - zenSat);
445 if (newZenDiff < zenDiff) {
446 zenDiff = newZenDiff;
447 var = frqMap->pattern(iZen);
448 }
449 }
450 }
451
452 found = true;
453 return var - frqMap->neu[0] * cos(azSat)*cos(eleSat)
454 - frqMap->neu[1] * sin(azSat)*cos(eleSat)
455 - frqMap->neu[2] * sin(eleSat);
456
457}
Note: See TracBrowser for help on using the repository browser.