| 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 |
|
|---|
| 47 | using namespace std;
|
|---|
| 48 |
|
|---|
| 49 | // Constructor
|
|---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 51 | bncAntex::bncAntex() {
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | // Constructor
|
|---|
| 55 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 56 | bncAntex::bncAntex(const char* fileName) {
|
|---|
| 57 | readFile(QString(fileName));
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | // Destructor
|
|---|
| 61 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 62 | bncAntex::~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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 72 | void 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 | // Read ANTEX File
|
|---|
| 93 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 94 | t_irc bncAntex::readFile(const QString& fileName) {
|
|---|
| 95 |
|
|---|
| 96 | QFile inFile(fileName);
|
|---|
| 97 | inFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
|---|
| 98 |
|
|---|
| 99 | QTextStream in(&inFile);
|
|---|
| 100 |
|
|---|
| 101 | t_antMap* newAntMap = 0;
|
|---|
| 102 | t_frqMap* newFrqMap = 0;
|
|---|
| 103 |
|
|---|
| 104 | while ( !in.atEnd() ) {
|
|---|
| 105 | QString line = in.readLine();
|
|---|
| 106 |
|
|---|
| 107 | // Start of Antenna
|
|---|
| 108 | // ----------------
|
|---|
| 109 | if (line.indexOf("START OF ANTENNA") == 60) {
|
|---|
| 110 | if (newAntMap) {
|
|---|
| 111 | delete newAntMap;
|
|---|
| 112 | return failure;
|
|---|
| 113 | }
|
|---|
| 114 | else {
|
|---|
| 115 | delete newAntMap;
|
|---|
| 116 | newAntMap = new t_antMap();
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // End of Antenna
|
|---|
| 121 | // --------------
|
|---|
| 122 | else if (line.indexOf("END OF ANTENNA") == 60) {
|
|---|
| 123 | if (newAntMap) {
|
|---|
| 124 | if (_maps.contains(newAntMap->antName)) {
|
|---|
| 125 | delete _maps[newAntMap->antName];
|
|---|
| 126 | }
|
|---|
| 127 | _maps[newAntMap->antName] = newAntMap;
|
|---|
| 128 | newAntMap = 0;
|
|---|
| 129 | }
|
|---|
| 130 | else {
|
|---|
| 131 | delete newAntMap;
|
|---|
| 132 | return failure;
|
|---|
| 133 | }
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | // Antenna Reading in Progress
|
|---|
| 137 | // ---------------------------
|
|---|
| 138 | else if (newAntMap) {
|
|---|
| 139 | if (line.indexOf("TYPE / SERIAL NO") == 60) {
|
|---|
| 140 | if (line.indexOf("BLOCK I") == 0 ||
|
|---|
| 141 | line.indexOf("GLONASS") == 0) {
|
|---|
| 142 | newAntMap->antName = line.mid(20,3);
|
|---|
| 143 | }
|
|---|
| 144 | else {
|
|---|
| 145 | newAntMap->antName = line.mid(0,20);
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 | else if (line.indexOf("ZEN1 / ZEN2 / DZEN") == 60) {
|
|---|
| 149 | QTextStream inLine(&line, QIODevice::ReadOnly);
|
|---|
| 150 | inLine >> newAntMap->zen1 >> newAntMap->zen2 >> newAntMap->dZen;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | // Start of Frequency
|
|---|
| 154 | // ------------------
|
|---|
| 155 | else if (line.indexOf("START OF FREQUENCY") == 60) {
|
|---|
| 156 | if (newFrqMap) {
|
|---|
| 157 | delete newFrqMap;
|
|---|
| 158 | delete newAntMap;
|
|---|
| 159 | return failure;
|
|---|
| 160 | }
|
|---|
| 161 | else {
|
|---|
| 162 | newFrqMap = new t_frqMap();
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | // End of Frequency
|
|---|
| 167 | // ----------------
|
|---|
| 168 | else if (line.indexOf("END OF FREQUENCY") == 60) {
|
|---|
| 169 | if (newFrqMap) {
|
|---|
| 170 | t_frequency::type frqType = t_frequency::dummy;
|
|---|
| 171 | if (line.indexOf("G01") == 3) {
|
|---|
| 172 | frqType = t_frequency::G1;
|
|---|
| 173 | }
|
|---|
| 174 | else if (line.indexOf("G02") == 3) {
|
|---|
| 175 | frqType = t_frequency::G2;
|
|---|
| 176 | }
|
|---|
| 177 | else if (line.indexOf("R01") == 3) {
|
|---|
| 178 | frqType = t_frequency::R1;
|
|---|
| 179 | }
|
|---|
| 180 | else if (line.indexOf("R02") == 3) {
|
|---|
| 181 | frqType = t_frequency::R2;
|
|---|
| 182 | }
|
|---|
| 183 | if (frqType != t_frequency::dummy) {
|
|---|
| 184 | if (newAntMap->frqMap.find(frqType) != newAntMap->frqMap.end()) {
|
|---|
| 185 | delete newAntMap->frqMap[frqType];
|
|---|
| 186 | }
|
|---|
| 187 | newAntMap->frqMap[frqType] = newFrqMap;
|
|---|
| 188 | }
|
|---|
| 189 | else {
|
|---|
| 190 | delete newFrqMap;
|
|---|
| 191 | }
|
|---|
| 192 | newFrqMap = 0;
|
|---|
| 193 | }
|
|---|
| 194 | else {
|
|---|
| 195 | delete newAntMap;
|
|---|
| 196 | return failure;
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | // Frequency Reading in Progress
|
|---|
| 201 | // -----------------------------
|
|---|
| 202 | else if (newFrqMap) {
|
|---|
| 203 | if (line.indexOf("NORTH / EAST / UP") == 60) {
|
|---|
| 204 | QTextStream inLine(&line, QIODevice::ReadOnly);
|
|---|
| 205 | inLine >> newFrqMap->neu[0] >> newFrqMap->neu[1] >> newFrqMap->neu[2];
|
|---|
| 206 | newFrqMap->neu[0] *= 1e-3;
|
|---|
| 207 | newFrqMap->neu[1] *= 1e-3;
|
|---|
| 208 | newFrqMap->neu[2] *= 1e-3;
|
|---|
| 209 | }
|
|---|
| 210 | else if (line.indexOf("NOAZI") == 3) {
|
|---|
| 211 | QTextStream inLine(&line, QIODevice::ReadOnly);
|
|---|
| 212 | int nPat = int((newAntMap->zen2-newAntMap->zen1)/newAntMap->dZen) + 1;
|
|---|
| 213 | newFrqMap->pattern.ReSize(nPat);
|
|---|
| 214 | QString dummy;
|
|---|
| 215 | inLine >> dummy;
|
|---|
| 216 | for (int ii = 0; ii < nPat; ii++) {
|
|---|
| 217 | inLine >> newFrqMap->pattern[ii];
|
|---|
| 218 | }
|
|---|
| 219 | newFrqMap->pattern *= 1e-3;
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | delete newFrqMap;
|
|---|
| 226 | delete newAntMap;
|
|---|
| 227 |
|
|---|
| 228 | return success;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | // Satellite Antenna Offset
|
|---|
| 232 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 233 | t_irc bncAntex::satCoMcorrection(const QString& prn, double Mjd,
|
|---|
| 234 | const ColumnVector& xSat, ColumnVector& dx) {
|
|---|
| 235 |
|
|---|
| 236 | t_frequency::type frqType = t_frequency::dummy;
|
|---|
| 237 | if (prn[0] == 'G') {
|
|---|
| 238 | frqType = t_frequency::G1;
|
|---|
| 239 | }
|
|---|
| 240 | else if (prn[0] == 'R') {
|
|---|
| 241 | frqType = t_frequency::R1;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | QMap<QString, t_antMap*>::const_iterator it = _maps.find(prn);
|
|---|
| 245 | if (it != _maps.end()) {
|
|---|
| 246 | t_antMap* map = it.value();
|
|---|
| 247 | if (map->frqMap.find(frqType) != map->frqMap.end()) {
|
|---|
| 248 |
|
|---|
| 249 | double* neu = map->frqMap[frqType]->neu;
|
|---|
| 250 |
|
|---|
| 251 | // Unit Vectors sz, sy, sx
|
|---|
| 252 | // -----------------------
|
|---|
| 253 | ColumnVector sz = -xSat;
|
|---|
| 254 | sz /= sqrt(DotProduct(sz,sz));
|
|---|
| 255 |
|
|---|
| 256 | ColumnVector xSun = BNC_PPP::t_astro::Sun(Mjd);
|
|---|
| 257 | xSun /= sqrt(DotProduct(xSun,xSun));
|
|---|
| 258 |
|
|---|
| 259 | ColumnVector sy = crossproduct(sz, xSun);
|
|---|
| 260 | sy /= sqrt(DotProduct(sy,sy));
|
|---|
| 261 |
|
|---|
| 262 | ColumnVector sx = crossproduct(sy, sz);
|
|---|
| 263 |
|
|---|
| 264 | dx[0] = sx[0] * neu[0] + sy[0] * neu[1] + sz[0] * neu[2];
|
|---|
| 265 | dx[1] = sx[1] * neu[0] + sy[1] * neu[1] + sz[1] * neu[2];
|
|---|
| 266 | dx[2] = sx[2] * neu[0] + sy[2] * neu[1] + sz[2] * neu[2];
|
|---|
| 267 |
|
|---|
| 268 | return success;
|
|---|
| 269 | }
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | return failure;
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | //
|
|---|
| 276 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 277 | double bncAntex::rcvCorr(const string& antName, t_frequency::type frqType,
|
|---|
| 278 | double eleSat, double /* azSat */, bool& found) const {
|
|---|
| 279 |
|
|---|
| 280 | if (antName.find("NULLANTENNA") != string::npos) {
|
|---|
| 281 | found = true;
|
|---|
| 282 | return 0.0;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | QString antNameQ = antName.c_str();
|
|---|
| 286 |
|
|---|
| 287 | if (_maps.find(antNameQ) == _maps.end()) {
|
|---|
| 288 | found = false;
|
|---|
| 289 | return 0.0;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | t_antMap* map = _maps[antNameQ];
|
|---|
| 293 |
|
|---|
| 294 | if (map->frqMap.find(frqType) == map->frqMap.end()) {
|
|---|
| 295 | found = false;
|
|---|
| 296 | return 0.0;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | t_frqMap* frqMap = map->frqMap[frqType];
|
|---|
| 300 |
|
|---|
| 301 | double var = 0.0;
|
|---|
| 302 | if (frqMap->pattern.ncols() > 0) {
|
|---|
| 303 | double zenDiff = 999.999;
|
|---|
| 304 | double zenSat = 90.0 - eleSat * 180.0 / M_PI;
|
|---|
| 305 | unsigned iZen = 0;
|
|---|
| 306 | for (double zen = map->zen1; zen <= map->zen2; zen += map->dZen) {
|
|---|
| 307 | iZen += 1;
|
|---|
| 308 | double newZenDiff = fabs(zen - zenSat);
|
|---|
| 309 | if (newZenDiff < zenDiff) {
|
|---|
| 310 | zenDiff = newZenDiff;
|
|---|
| 311 | var = frqMap->pattern(iZen);
|
|---|
| 312 | }
|
|---|
| 313 | }
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | found = true;
|
|---|
| 317 | return var - frqMap->neu[2] * sin(eleSat);
|
|---|
| 318 | }
|
|---|