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

Last change on this file since 7571 was 7571, checked in by stuerze, 8 years ago

small bug fixed in sinex antenna string generation

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