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

Last change on this file since 8077 was 8077, checked in by stuerze, 7 years ago

minor changes

File size: 11.2 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));
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 if (newAntMap) {
69 delete newAntMap;
70 }
71 if (newFrqMap) {
72 delete newFrqMap;
73 }
74}
75
76// Print
77////////////////////////////////////////////////////////////////////////////
78void bncAntex::print() const {
79 QMapIterator<QString, t_antMap*> itAnt(_maps);
80 while (itAnt.hasNext()) {
81 itAnt.next();
82 t_antMap* map = itAnt.value();
83 cout << map->antName.toAscii().data() << endl;
84 cout << " " << map->zen1 << " " << map->zen2 << " " << map->dZen << endl;
85 QMapIterator<t_frequency::type, t_frqMap*> itFrq(map->frqMap);
86 while (itFrq.hasNext()) {
87 itFrq.next();
88 const t_frqMap* frqMap = itFrq.value();
89 cout << " " << frqMap->neu[0] << " "
90 << frqMap->neu[1] << " "
91 << frqMap->neu[2] << endl;
92 cout << " " << frqMap->pattern.t();
93 }
94 cout << endl;
95 }
96}
97
98// Print
99////////////////////////////////////////////////////////////////////////////
100QString bncAntex::pcoSinexString(const std::string& antName, t_frequency::type frqType) {
101
102 if (antName.find("NULLANTENNA") != string::npos) {
103 return QString(" ------ ------ ------");
104 }
105
106 QString antNameQ = antName.c_str();
107 if (_maps.find(antNameQ) == _maps.end()) {
108 return QString(" ------ ------ ------");
109 }
110
111 t_antMap* map = _maps[antNameQ];
112 if (map->frqMap.find(frqType) == map->frqMap.end()) {
113 return QString(" ------ ------ ------");
114 }
115
116 t_frqMap* frqMap = map->frqMap[frqType];
117
118 QString u, n,e;
119 u.sprintf("%+6.4f" ,frqMap->neu[2]); if (u.mid(1,1) == "0") {u.remove(1,1);}
120 n.sprintf("%+6.4f" ,frqMap->neu[0]); if (n.mid(1,1) == "0") {n.remove(1,1);}
121 e.sprintf("%+6.4f" ,frqMap->neu[1]); if (e.mid(1,1) == "0") {e.remove(1,1);}
122
123 return QString(" %1 %2 %3").arg(u).arg(n).arg(e);
124}
125
126// Read ANTEX File
127////////////////////////////////////////////////////////////////////////////
128t_irc bncAntex::readFile(const QString& fileName) {
129
130 QFile inFile(fileName);
131 inFile.open(QIODevice::ReadOnly | QIODevice::Text);
132
133 QTextStream in(&inFile);
134
135 newAntMap = 0;
136 newFrqMap = 0;
137
138 while ( !in.atEnd() ) {
139 QString line = in.readLine();
140
141 // Start of Antenna
142 // ----------------
143 if (line.indexOf("START OF ANTENNA") == 60) {
144 if (newAntMap) {
145 delete newAntMap;
146 return failure;
147 }
148 else {
149 delete newAntMap;
150 newAntMap = new t_antMap();
151 }
152 }
153
154 // End of Antenna
155 // --------------
156 else if (line.indexOf("END OF ANTENNA") == 60) {
157 if (newAntMap) {
158 if (_maps.contains(newAntMap->antName)) {
159 delete _maps[newAntMap->antName];
160 }
161 _maps[newAntMap->antName] = newAntMap;
162 newAntMap = 0;
163 }
164 else {
165 delete newAntMap;
166 return failure;
167 }
168 }
169
170 // Antenna Reading in Progress
171 // ---------------------------
172 else if (newAntMap) {
173 if (line.indexOf("TYPE / SERIAL NO") == 60) {
174 if (line.indexOf("BLOCK I") == 0 ||
175 line.indexOf("GLONASS") == 0 ||
176 line.indexOf("QZSS") == 0 ||
177 line.indexOf("BEIDOU") == 0 ||
178 line.indexOf("GALILEO") == 0 ||
179 line.indexOf("IRNSS") == 0 ){
180 newAntMap->antName = line.mid(20,3);
181 }
182 else {
183 newAntMap->antName = line.mid(0,20);
184 }
185 }
186 else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
187 QTextStream inLine(&line, QIODevice::ReadOnly);
188 inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
189 }
190
191 // Start of Frequency
192 // ------------------
193 else if (line.indexOf("START OF FREQUENCY") == 60) {
194 if (newFrqMap) {
195 delete newFrqMap;
196 delete newAntMap;
197 return failure;
198 }
199 else {
200 newFrqMap = new t_frqMap();
201 }
202 }
203
204 // End of Frequency
205 // ----------------
206 else if (line.indexOf("END OF FREQUENCY") == 60) {
207 if (newFrqMap) {
208 t_frequency::type frqType = t_frequency::dummy;
209 if (line.indexOf("G01") == 3) {
210 frqType = t_frequency::G1;
211 }
212 else if (line.indexOf("G02") == 3) {
213 frqType = t_frequency::G2;
214 }
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 else if (line.indexOf("E01") == 3) {
222 frqType = t_frequency::E1;
223 }
224 else if (line.indexOf("E05") == 3) {
225 frqType = t_frequency::E5;
226 }
227 else if (line.indexOf("E06") == 3) {
228 frqType = t_frequency::E6;
229 }
230 else if (line.indexOf("E07") == 3) {
231 frqType = t_frequency::E7;
232 }
233 else if (line.indexOf("E08") == 3) {
234 frqType = t_frequency::E8;
235 }
236 else if (line.indexOf("J01") == 3) {
237 frqType = t_frequency::J1;
238 }
239 else if (line.indexOf("J02") == 3) {
240 frqType = t_frequency::J2;
241 }
242 else if (line.indexOf("J05") == 3) {
243 frqType = t_frequency::J5;
244 }
245 else if (line.indexOf("J06") == 3) {
246 frqType = t_frequency::J6;
247 }
248 else if (line.indexOf("C02") == 3) {
249 frqType = t_frequency::C2;
250 }
251 else if (line.indexOf("C06") == 3) {
252 frqType = t_frequency::C6;
253 }
254 else if (line.indexOf("C07") == 3) {
255 frqType = t_frequency::C7;
256 }
257 if (frqType != t_frequency::dummy) {
258 if (newAntMap->frqMap.find(frqType) != newAntMap->frqMap.end()) {
259 delete newAntMap->frqMap[frqType];
260 }
261 newAntMap->frqMap[frqType] = newFrqMap;
262 }
263 else {
264 delete newFrqMap;
265 }
266 newFrqMap = 0;
267 }
268 else {
269 delete newAntMap;
270 return failure;
271 }
272 }
273
274 // Frequency Reading in Progress
275 // -----------------------------
276 else if (newFrqMap) {
277 if (line.indexOf("NORTH / EAST / UP") == 60) {
278 QTextStream inLine(&line, QIODevice::ReadOnly);
279 inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
280 newFrqMap->neu[0] *= 1e-3;
281 newFrqMap->neu[1] *= 1e-3;
282 newFrqMap->neu[2] *= 1e-3;
283 }
284 else if (line.indexOf("NOAZI") == 3) {
285 QTextStream inLine(&line, QIODevice::ReadOnly);
286 int nPat = int((newAntMap->zen2-newAntMap->zen1)/newAntMap->dZen) + 1;
287 newFrqMap->pattern.ReSize(nPat);
288 QString dummy;
289 inLine >> dummy;
290 for (int ii = 0; ii < nPat; ii++) {
291 inLine >> newFrqMap->pattern[ii];
292 }
293 newFrqMap->pattern *= 1e-3;
294 }
295 }
296 }
297 }
298 inFile.close();
299 delete newFrqMap;
300 delete newAntMap;
301
302 return success;
303}
304
305// Satellite Antenna Offset
306////////////////////////////////////////////////////////////////////////////
307t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
308 const ColumnVector& xSat, ColumnVector& dx) {
309
310 t_frequency::type frqType = t_frequency::dummy;
311
312 if (prn[0] == 'G') {
313 frqType = t_frequency::G1;
314 }
315 else if (prn[0] == 'R') {
316 frqType = t_frequency::R1;
317 }
318
319 QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn.mid(0,3));
320 if (it != _maps.end()) {
321 t_antMap* map = it.value();
322 if (map->frqMap.find(frqType) != map->frqMap.end()) {
323
324 double* neu = map->frqMap[frqType]->neu;
325
326 // Unit Vectors sz, sy, sx
327 // -----------------------
328 ColumnVector sz = -xSat;
329 sz /= sqrt(DotProduct(sz,sz));
330
331 ColumnVector xSun = BNC_PPP::t_astro::Sun(Mjd);
332 xSun /= sqrt(DotProduct(xSun,xSun));
333
334 ColumnVector sy = crossproduct(sz, xSun);
335 sy /= sqrt(DotProduct(sy,sy));
336
337 ColumnVector sx = crossproduct(sy, sz);
338
339 dx[0] = sx[0] * neu[0] + sy[0] * neu[1] + sz[0] * neu[2];
340 dx[1] = sx[1] * neu[0] + sy[1] * neu[1] + sz[1] * neu[2];
341 dx[2] = sx[2] * neu[0] + sy[2] * neu[1] + sz[2] * neu[2];
342
343 return success;
344 }
345 }
346
347 return failure;
348}
349
350//
351////////////////////////////////////////////////////////////////////////////
352double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
353 double eleSat, double azSat, bool& found) const {
354
355 if (antName.find("NULLANTENNA") != string::npos) {
356 found = true;
357 return 0.0;
358 }
359
360 QString antNameQ = antName.c_str();
361
362 if (_maps.find(antNameQ) == _maps.end()) {
363 found = false;
364 return 0.0;
365 }
366
367 t_antMap* map = _maps[antNameQ];
368 if (map->frqMap.find(frqType) == map->frqMap.end()) {
369 found = false;
370 return 0.0;
371 }
372
373 t_frqMap* frqMap = map->frqMap[frqType];
374
375 double var = 0.0;
376 if (frqMap->pattern.ncols() > 0) {
377 double zenDiff = 999.999;
378 double zenSat = 90.0 - eleSat * 180.0 / M_PI;
379 unsigned iZen = 0;
380 for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
381 iZen += 1;
382 double newZenDiff = fabs(zen - zenSat);
383 if (newZenDiff < zenDiff) {
384 zenDiff = newZenDiff;
385 var = frqMap->pattern(iZen);
386 }
387 }
388 }
389
390 found = true;
391 return var - frqMap->neu[0] * cos(azSat)*cos(eleSat)
392 - frqMap->neu[1] * sin(azSat)*cos(eleSat)
393 - frqMap->neu[2] * sin(eleSat);
394
395}
Note: See TracBrowser for help on using the repository browser.