[280] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
[464] | 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
[280] | 3 | //
|
---|
[464] | 4 | // Copyright (C) 2007
|
---|
[280] | 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
[464] | 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
[280] | 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.
|
---|
[73] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
[93] | 26 | * BKG NTRIP Client
|
---|
[73] | 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncRinex
|
---|
| 30 | *
|
---|
| 31 | * Purpose: writes RINEX files
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 27-Aug-2006
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[292] | 41 | #include <stdlib.h>
|
---|
[300] | 42 | #include <iostream>
|
---|
[75] | 43 | #include <iomanip>
|
---|
[221] | 44 | #include <math.h>
|
---|
[2695] | 45 | #include <sstream>
|
---|
[75] | 46 |
|
---|
[300] | 47 | #include <QtCore>
|
---|
| 48 | #include <QUrl>
|
---|
| 49 | #include <QString>
|
---|
| 50 |
|
---|
[73] | 51 | #include "bncrinex.h"
|
---|
[157] | 52 | #include "bncapp.h"
|
---|
[82] | 53 | #include "bncutils.h"
|
---|
[126] | 54 | #include "bncconst.h"
|
---|
[298] | 55 | #include "bnctabledlg.h"
|
---|
[301] | 56 | #include "bncgetthread.h"
|
---|
[3337] | 57 | #include "bncnetqueryv1.h"
|
---|
[1858] | 58 | #include "bncnetqueryv2.h"
|
---|
[1535] | 59 | #include "bncsettings.h"
|
---|
[2012] | 60 | #include "bncversion.h"
|
---|
[2492] | 61 | #include "rtcm3torinex.h"
|
---|
[75] | 62 |
|
---|
| 63 | using namespace std;
|
---|
| 64 |
|
---|
[73] | 65 | // Constructor
|
---|
| 66 | ////////////////////////////////////////////////////////////////////////////
|
---|
[408] | 67 | bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
|
---|
[3525] | 68 | const QByteArray& latitude, const QByteArray& longitude,
|
---|
| 69 | const QByteArray& nmea, const QByteArray& ntripVersion) {
|
---|
[1387] | 70 |
|
---|
[408] | 71 | _statID = statID;
|
---|
[336] | 72 | _mountPoint = mountPoint;
|
---|
[366] | 73 | _latitude = latitude;
|
---|
| 74 | _longitude = longitude;
|
---|
| 75 | _nmea = nmea;
|
---|
[1639] | 76 | _ntripVersion = ntripVersion;
|
---|
[77] | 77 | _headerWritten = false;
|
---|
[369] | 78 | _reconnectFlag = false;
|
---|
[132] | 79 |
|
---|
[1535] | 80 | bncSettings settings;
|
---|
[132] | 81 | _rnxScriptName = settings.value("rnxScript").toString();
|
---|
| 82 | expandEnvVar(_rnxScriptName);
|
---|
[153] | 83 |
|
---|
[2012] | 84 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
[319] | 85 | #ifdef WIN32
|
---|
| 86 | _userName = QString("${USERNAME}");
|
---|
| 87 | #else
|
---|
[158] | 88 | _userName = QString("${USER}");
|
---|
[319] | 89 | #endif
|
---|
[157] | 90 | expandEnvVar(_userName);
|
---|
[158] | 91 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
[539] | 92 |
|
---|
| 93 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
---|
| 94 | _rinexVers = 3;
|
---|
| 95 | }
|
---|
| 96 | else {
|
---|
| 97 | _rinexVers = 2;
|
---|
| 98 | }
|
---|
[1044] | 99 |
|
---|
| 100 | _approxPos[0] = _approxPos[1] = _approxPos[2] = 0.0;
|
---|
[3528] | 101 |
|
---|
| 102 | _samplingRate = settings.value("rnxSampl").toInt();
|
---|
[4390] | 103 |
|
---|
| 104 | // Initialize RINEX v3 Types
|
---|
| 105 | // -------------------------
|
---|
[4423] | 106 | _rnxTypes['G'] << "C1C" << "L1C" << "D1C" << "S1C"
|
---|
| 107 | << "C1P" << "L1P" << "D1P" << "S1P"
|
---|
| 108 | << "C2C" << "L2C" << "D2C" << "S2C"
|
---|
| 109 | << "C2P" << "L2P" << "D2P" << "S2P"
|
---|
[4402] | 110 | << "C5" << "D5" << "L5" << "S5";
|
---|
[4390] | 111 |
|
---|
[4423] | 112 | _rnxTypes['R'] << "C1C" << "L1C" << "D1C" << "S1C"
|
---|
| 113 | << "C1P" << "L1P" << "D1P" << "S1P"
|
---|
| 114 | << "C2C" << "L2C" << "D2C" << "S2C"
|
---|
| 115 | << "C2P" << "L2P" << "D2P" << "S2P";
|
---|
[4390] | 116 |
|
---|
[4402] | 117 | _rnxTypes['E'] << "C1" << "L1" << "D1" << "S1"
|
---|
| 118 | << "C5" << "L5" << "D5" << "S5"
|
---|
| 119 | << "C6" << "L6" << "D6" << "S6"
|
---|
| 120 | << "C7" << "L7" << "D7" << "S7"
|
---|
| 121 | << "C8" << "L8" << "D8" << "S8";
|
---|
[4390] | 122 |
|
---|
[4423] | 123 | _rnxTypes['J'] << "C1" << "L1" << "D1" << "S1"
|
---|
| 124 | << "C2" << "L2" << "D2" << "S2"
|
---|
| 125 | << "C5" << "L5" << "D5" << "S5"
|
---|
| 126 | << "C6" << "D6" << "L6" << "S6";
|
---|
[4402] | 127 |
|
---|
[4423] | 128 | _rnxTypes['S'] << "C1" << "L1" << "D1" << "S1"
|
---|
| 129 | << "C5" << "L5" << "D5" << "S5";
|
---|
[4390] | 130 |
|
---|
[4423] | 131 | _rnxTypes['C'] << "C2" << "L2" << "D2" << "S2"
|
---|
| 132 | << "C6" << "L6" << "D6" << "S6"
|
---|
| 133 | << "C7" << "L7" << "D7" << "S7";
|
---|
[73] | 134 | }
|
---|
| 135 |
|
---|
| 136 | // Destructor
|
---|
| 137 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 138 | bncRinex::~bncRinex() {
|
---|
[1535] | 139 | bncSettings settings;
|
---|
[698] | 140 | if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
|
---|
[843] | 141 | _out << "> 4 1" << endl;
|
---|
[698] | 142 | _out << "END OF FILE" << endl;
|
---|
| 143 | }
|
---|
[77] | 144 | _out.close();
|
---|
[73] | 145 | }
|
---|
| 146 |
|
---|
[420] | 147 | // Download Skeleton Header File
|
---|
| 148 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 149 | t_irc bncRinex::downloadSkeleton() {
|
---|
| 150 |
|
---|
| 151 | t_irc irc = failure;
|
---|
| 152 |
|
---|
| 153 | QStringList table;
|
---|
[3335] | 154 | bncTableDlg::getFullTable(_ntripVersion, _mountPoint.host(),
|
---|
[4481] | 155 | _mountPoint.port(), table, true);
|
---|
[420] | 156 | QString net;
|
---|
| 157 | QStringListIterator it(table);
|
---|
| 158 | while (it.hasNext()) {
|
---|
| 159 | QString line = it.next();
|
---|
| 160 | if (line.indexOf("STR") == 0) {
|
---|
| 161 | QStringList tags = line.split(";");
|
---|
[1495] | 162 | if (tags.size() > 7) {
|
---|
| 163 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
---|
| 164 | net = tags.at(7);
|
---|
| 165 | break;
|
---|
| 166 | }
|
---|
[420] | 167 | }
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | QString sklDir;
|
---|
[1495] | 171 | if (!net.isEmpty()) {
|
---|
| 172 | it.toFront();
|
---|
| 173 | while (it.hasNext()) {
|
---|
| 174 | QString line = it.next();
|
---|
| 175 | if (line.indexOf("NET") == 0) {
|
---|
| 176 | QStringList tags = line.split(";");
|
---|
| 177 | if (tags.size() > 6) {
|
---|
| 178 | if (tags.at(1) == net) {
|
---|
| 179 | sklDir = tags.at(6).trimmed();
|
---|
| 180 | break;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
[420] | 184 | }
|
---|
| 185 | }
|
---|
| 186 | if (!sklDir.isEmpty() && sklDir != "none") {
|
---|
| 187 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
---|
| 188 | if (url.port() == -1) {
|
---|
| 189 | url.setPort(80);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[3337] | 192 | bncNetQuery* query;
|
---|
| 193 | if (_ntripVersion == "2s") {
|
---|
| 194 | query = new bncNetQueryV2(true);
|
---|
| 195 | }
|
---|
| 196 | else if (_ntripVersion == "2") {
|
---|
| 197 | query = new bncNetQueryV2(false);
|
---|
| 198 | }
|
---|
| 199 | else {
|
---|
| 200 | query = new bncNetQueryV1;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[1386] | 203 | QByteArray outData;
|
---|
[3337] | 204 | query->waitForRequestResult(url, outData);
|
---|
| 205 | if (query->status() == bncNetQuery::finished) {
|
---|
[4481] | 206 | irc = success;
|
---|
[1386] | 207 | QTextStream in(outData);
|
---|
[4481] | 208 | _header.read(&in);
|
---|
[420] | 209 | }
|
---|
[4481] | 210 |
|
---|
[3337] | 211 | delete query;
|
---|
| 212 | }
|
---|
[1386] | 213 |
|
---|
[420] | 214 | return irc;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
[82] | 217 | // Read Skeleton Header File
|
---|
| 218 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 219 | void bncRinex::readSkeleton() {
|
---|
| 220 |
|
---|
[420] | 221 | // Read the local file
|
---|
| 222 | // -------------------
|
---|
[276] | 223 | QFile skl(_sklName);
|
---|
[82] | 224 | if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
|
---|
| 225 | QTextStream in(&skl);
|
---|
[4481] | 226 | _header.read(&in);
|
---|
[82] | 227 | }
|
---|
[298] | 228 |
|
---|
[420] | 229 | // Read downloaded file
|
---|
| 230 | // --------------------
|
---|
[2376] | 231 | else if ( _ntripVersion != "N" && _ntripVersion != "UN" &&
|
---|
| 232 | _ntripVersion != "S" ) {
|
---|
[1154] | 233 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
[420] | 234 | if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
|
---|
[4481] | 235 | downloadSkeleton();
|
---|
| 236 | _skeletonDate = currDate;
|
---|
[298] | 237 | }
|
---|
| 238 | }
|
---|
[82] | 239 | }
|
---|
| 240 |
|
---|
[647] | 241 | // Next File Epoch (static)
|
---|
[82] | 242 | ////////////////////////////////////////////////////////////////////////////
|
---|
[647] | 243 | QString bncRinex::nextEpochStr(const QDateTime& datTim,
|
---|
| 244 | const QString& intStr, QDateTime* nextEpoch) {
|
---|
[82] | 245 |
|
---|
[647] | 246 | QString epoStr;
|
---|
[82] | 247 |
|
---|
[129] | 248 | QTime nextTime;
|
---|
| 249 | QDate nextDate;
|
---|
| 250 |
|
---|
[204] | 251 | int indHlp = intStr.indexOf("min");
|
---|
| 252 |
|
---|
| 253 | if ( indHlp != -1) {
|
---|
| 254 | int step = intStr.left(indHlp-1).toInt();
|
---|
[127] | 255 | char ch = 'A' + datTim.time().hour();
|
---|
[647] | 256 | epoStr = ch;
|
---|
[204] | 257 | if (datTim.time().minute() >= 60-step) {
|
---|
[647] | 258 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
|
---|
[199] | 259 | if (datTim.time().hour() < 23) {
|
---|
| 260 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 261 | nextDate = datTim.date();
|
---|
| 262 | }
|
---|
| 263 | else {
|
---|
| 264 | nextTime.setHMS(0, 0, 0);
|
---|
| 265 | nextDate = datTim.date().addDays(1);
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 | else {
|
---|
[204] | 269 | for (int limit = step; limit <= 60-step; limit += step) {
|
---|
| 270 | if (datTim.time().minute() < limit) {
|
---|
[647] | 271 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
|
---|
[204] | 272 | nextTime.setHMS(datTim.time().hour(), limit, 0);
|
---|
| 273 | nextDate = datTim.date();
|
---|
| 274 | break;
|
---|
| 275 | }
|
---|
[199] | 276 | }
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
[127] | 279 | else if (intStr == "1 hour") {
|
---|
| 280 | char ch = 'A' + datTim.time().hour();
|
---|
[647] | 281 | epoStr = ch;
|
---|
[129] | 282 | if (datTim.time().hour() < 23) {
|
---|
| 283 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 284 | nextDate = datTim.date();
|
---|
| 285 | }
|
---|
| 286 | else {
|
---|
| 287 | nextTime.setHMS(0, 0, 0);
|
---|
| 288 | nextDate = datTim.date().addDays(1);
|
---|
| 289 | }
|
---|
[127] | 290 | }
|
---|
| 291 | else {
|
---|
[647] | 292 | epoStr = "0";
|
---|
[129] | 293 | nextTime.setHMS(0, 0, 0);
|
---|
| 294 | nextDate = datTim.date().addDays(1);
|
---|
[127] | 295 | }
|
---|
[82] | 296 |
|
---|
[647] | 297 | if (nextEpoch) {
|
---|
| 298 | *nextEpoch = QDateTime(nextDate, nextTime);
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | return epoStr;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | // File Name according to RINEX Standards
|
---|
| 305 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 306 | void bncRinex::resolveFileName(const QDateTime& datTim) {
|
---|
| 307 |
|
---|
[1535] | 308 | bncSettings settings;
|
---|
[647] | 309 | QString path = settings.value("rnxPath").toString();
|
---|
| 310 | expandEnvVar(path);
|
---|
| 311 |
|
---|
| 312 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
---|
| 313 | path += QDir::separator();
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
|
---|
| 317 | &_nextCloseEpoch);
|
---|
| 318 |
|
---|
[183] | 319 | QString ID4 = _statID.left(4);
|
---|
| 320 |
|
---|
| 321 | // Check name conflict
|
---|
| 322 | // -------------------
|
---|
| 323 | QString distStr;
|
---|
| 324 | int num = 0;
|
---|
| 325 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 326 | while (it.hasNext()) {
|
---|
| 327 | QString mp = it.next();
|
---|
| 328 | if (mp.indexOf(ID4) != -1) {
|
---|
| 329 | ++num;
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
| 332 | if (num > 1) {
|
---|
| 333 | distStr = "_" + _statID.mid(4);
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[276] | 336 | QString sklExt = settings.value("rnxSkel").toString();
|
---|
| 337 | if (!sklExt.isEmpty()) {
|
---|
| 338 | _sklName = path + ID4 + distStr + "." + sklExt;
|
---|
| 339 | }
|
---|
| 340 |
|
---|
[183] | 341 | path += ID4 +
|
---|
[127] | 342 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[276] | 343 | hlpStr + distStr + datTim.toString(".yyO");
|
---|
[82] | 344 |
|
---|
| 345 | _fName = path.toAscii();
|
---|
| 346 | }
|
---|
| 347 |
|
---|
[77] | 348 | // Write RINEX Header
|
---|
| 349 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3525] | 350 | void bncRinex::writeHeader(const QByteArray& format, const QDateTime& datTim,
|
---|
[267] | 351 | const QDateTime& datTimNom) {
|
---|
[77] | 352 |
|
---|
[1535] | 353 | bncSettings settings;
|
---|
[356] | 354 |
|
---|
[77] | 355 | // Open the Output File
|
---|
| 356 | // --------------------
|
---|
[267] | 357 | resolveFileName(datTimNom);
|
---|
[260] | 358 |
|
---|
| 359 | // Append to existing file and return
|
---|
| 360 | // ----------------------------------
|
---|
| 361 | if ( QFile::exists(_fName) ) {
|
---|
[369] | 362 | if (_reconnectFlag ||
|
---|
| 363 | Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
[260] | 364 | _out.open(_fName.data(), ios::app);
|
---|
| 365 | _out.setf(ios::showpoint | ios::fixed);
|
---|
| 366 | _headerWritten = true;
|
---|
[369] | 367 | _reconnectFlag = false;
|
---|
[260] | 368 | return;
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 |
|
---|
[82] | 372 | _out.open(_fName.data());
|
---|
[85] | 373 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[77] | 374 |
|
---|
[82] | 375 | // Copy Skeleton Header
|
---|
| 376 | // --------------------
|
---|
[276] | 377 | readSkeleton();
|
---|
[78] | 378 |
|
---|
[4481] | 379 | QByteArray headerLines;
|
---|
| 380 | QTextStream outHlp(&headerLines);
|
---|
| 381 | _header.write(&outHlp);
|
---|
| 382 | outHlp.flush();
|
---|
| 383 | _out << headerLines.data();
|
---|
[4406] | 384 |
|
---|
[77] | 385 | _headerWritten = true;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
[73] | 388 | // Stores Observation into Internal Array
|
---|
| 389 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2711] | 390 | void bncRinex::deepCopy(t_obs obs) {
|
---|
| 391 | _obs.push_back(obs);
|
---|
[73] | 392 | }
|
---|
| 393 |
|
---|
| 394 | // Write One Epoch into the RINEX File
|
---|
| 395 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3525] | 396 | void bncRinex::dumpEpoch(const QByteArray& format, long maxTime) {
|
---|
[73] | 397 |
|
---|
[160] | 398 | // Select observations older than maxTime
|
---|
| 399 | // --------------------------------------
|
---|
[2711] | 400 | QList<t_obs> dumpList;
|
---|
| 401 | QMutableListIterator<t_obs> mIt(_obs);
|
---|
[160] | 402 | while (mIt.hasNext()) {
|
---|
[2711] | 403 | t_obs obs = mIt.next();
|
---|
| 404 | if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
|
---|
[622] | 405 | dumpList.push_back(obs);
|
---|
[160] | 406 | mIt.remove();
|
---|
| 407 | }
|
---|
| 408 | }
|
---|
| 409 |
|
---|
[75] | 410 | // Easy Return
|
---|
| 411 | // -----------
|
---|
[160] | 412 | if (dumpList.isEmpty()) {
|
---|
[75] | 413 | return;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | // Time of Epoch
|
---|
| 417 | // -------------
|
---|
[2711] | 418 | const t_obs& fObs = dumpList.first();
|
---|
| 419 | QDateTime datTim = dateAndTimeFromGPSweek(fObs.GPSWeek, fObs.GPSWeeks);
|
---|
| 420 | QDateTime datTimNom = dateAndTimeFromGPSweek(fObs.GPSWeek,
|
---|
| 421 | floor(fObs.GPSWeeks+0.5));
|
---|
[75] | 422 |
|
---|
[130] | 423 | // Close the file
|
---|
| 424 | // --------------
|
---|
[267] | 425 | if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
|
---|
[130] | 426 | closeFile();
|
---|
| 427 | _headerWritten = false;
|
---|
| 428 | }
|
---|
| 429 |
|
---|
[78] | 430 | // Write RINEX Header
|
---|
| 431 | // ------------------
|
---|
| 432 | if (!_headerWritten) {
|
---|
[3525] | 433 | writeHeader(format, datTim, datTimNom);
|
---|
[78] | 434 | }
|
---|
| 435 |
|
---|
[2711] | 436 | double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
|
---|
[75] | 437 |
|
---|
[1044] | 438 | // Epoch header line: RINEX Version 3
|
---|
| 439 | // ----------------------------------
|
---|
[540] | 440 | if (_rinexVers == 3) {
|
---|
| 441 | _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
|
---|
| 442 | << setw(10) << setprecision(7) << sec
|
---|
| 443 | << " " << 0 << setw(3) << dumpList.size() << endl;
|
---|
[74] | 444 | }
|
---|
[1044] | 445 | // Epoch header line: RINEX Version 2
|
---|
| 446 | // ----------------------------------
|
---|
[540] | 447 | else {
|
---|
| 448 | _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
|
---|
| 449 | << setw(10) << setprecision(7) << sec
|
---|
| 450 | << " " << 0 << setw(3) << dumpList.size();
|
---|
[1044] | 451 |
|
---|
[2711] | 452 | QListIterator<t_obs> it(dumpList); int iSat = 0;
|
---|
[540] | 453 | while (it.hasNext()) {
|
---|
| 454 | iSat++;
|
---|
[2711] | 455 | const t_obs& obs = it.next();
|
---|
| 456 | _out << obs.satSys << setw(2) << obs.satNum;
|
---|
[540] | 457 | if (iSat == 12 && it.hasNext()) {
|
---|
| 458 | _out << endl << " ";
|
---|
| 459 | iSat = 0;
|
---|
| 460 | }
|
---|
| 461 | }
|
---|
[77] | 462 | _out << endl;
|
---|
[1044] | 463 | }
|
---|
| 464 |
|
---|
[2711] | 465 | QListIterator<t_obs> it(dumpList);
|
---|
[1044] | 466 | while (it.hasNext()) {
|
---|
[2711] | 467 | const t_obs& obs = it.next();
|
---|
[1044] | 468 |
|
---|
| 469 | // Cycle slips detection
|
---|
| 470 | // ---------------------
|
---|
[2711] | 471 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 472 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
[1044] | 473 |
|
---|
| 474 | char lli1 = ' ';
|
---|
| 475 | char lli2 = ' ';
|
---|
[2688] | 476 | char lli5 = ' ';
|
---|
[2711] | 477 | if ( obs.slip_cnt_L1 >= 0 ) {
|
---|
[1044] | 478 | if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
|
---|
[2711] | 479 | _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
|
---|
[2682] | 480 | lli1 = '1';
|
---|
[1044] | 481 | }
|
---|
| 482 | }
|
---|
| 483 |
|
---|
[2711] | 484 | if ( obs.slip_cnt_L2 >= 0 ) {
|
---|
[1044] | 485 | if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
|
---|
[2711] | 486 | _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
|
---|
[2682] | 487 | lli2 = '1';
|
---|
[1044] | 488 | }
|
---|
| 489 | }
|
---|
| 490 |
|
---|
[2711] | 491 | if ( obs.slip_cnt_L5 >= 0 ) {
|
---|
[2688] | 492 | if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
|
---|
[2711] | 493 | _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
|
---|
[2688] | 494 | lli5 = '1';
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 |
|
---|
[2711] | 498 | _slip_cnt_L1[prn] = obs.slip_cnt_L1;
|
---|
| 499 | _slip_cnt_L2[prn] = obs.slip_cnt_L2;
|
---|
| 500 | _slip_cnt_L5[prn] = obs.slip_cnt_L5;
|
---|
[1044] | 501 |
|
---|
| 502 | // RINEX Version 3
|
---|
| 503 | // ---------------
|
---|
| 504 | if (_rinexVers == 3) {
|
---|
[3341] | 505 | _out << rinexSatLine(obs, lli1, lli2, lli5);
|
---|
[2696] | 506 | _out << endl;
|
---|
[1044] | 507 | }
|
---|
| 508 |
|
---|
| 509 | // RINEX Version 2
|
---|
| 510 | // ---------------
|
---|
| 511 | else {
|
---|
[4403] | 512 | _out << setw(14) << setprecision(3) << obs.measdata("C1", _rinexVers) << ' ' << ' '
|
---|
| 513 | << setw(14) << setprecision(3) << obs.measdata("P1", _rinexVers) << ' ' << ' '
|
---|
| 514 | << setw(14) << setprecision(3) << obs.measdata("L1", _rinexVers) << lli1 << ' '
|
---|
| 515 | << setw(14) << setprecision(3) << obs.measdata("S1", _rinexVers) << ' ' << ' '
|
---|
| 516 | << setw(14) << setprecision(3) << obs.measdata("C2", _rinexVers) << ' ' << ' ' << endl
|
---|
| 517 | << setw(14) << setprecision(3) << obs.measdata("P2", _rinexVers) << ' ' << ' '
|
---|
| 518 | << setw(14) << setprecision(3) << obs.measdata("L2", _rinexVers) << lli2 << ' '
|
---|
| 519 | << setw(14) << setprecision(3) << obs.measdata("S2", _rinexVers) << endl;
|
---|
[540] | 520 | }
|
---|
[75] | 521 | }
|
---|
| 522 |
|
---|
[77] | 523 | _out.flush();
|
---|
[73] | 524 | }
|
---|
| 525 |
|
---|
[130] | 526 | // Close the Old RINEX File
|
---|
| 527 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 528 | void bncRinex::closeFile() {
|
---|
[698] | 529 | if (_rinexVers == 3) {
|
---|
[843] | 530 | _out << "> 4 1" << endl;
|
---|
[698] | 531 | _out << "END OF FILE" << endl;
|
---|
| 532 | }
|
---|
[130] | 533 | _out.close();
|
---|
[132] | 534 | if (!_rnxScriptName.isEmpty()) {
|
---|
[1523] | 535 | qApp->thread()->wait(100);
|
---|
[435] | 536 | #ifdef WIN32
|
---|
| 537 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
---|
| 538 | #else
|
---|
[475] | 539 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
---|
[435] | 540 | #endif
|
---|
[436] | 541 |
|
---|
[132] | 542 | }
|
---|
[130] | 543 | }
|
---|
[2695] | 544 |
|
---|
[4391] | 545 | // One Line in RINEX v3
|
---|
[2695] | 546 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3341] | 547 | string bncRinex::rinexSatLine(const t_obs& obs, char lli1, char lli2,
|
---|
| 548 | char lli5) {
|
---|
[2695] | 549 | ostringstream str;
|
---|
| 550 | str.setf(ios::showpoint | ios::fixed);
|
---|
| 551 |
|
---|
[4384] | 552 | str << obs.satSys
|
---|
| 553 | << setw(2) << setfill('0') << obs.satNum << setfill(' ');
|
---|
| 554 |
|
---|
[4391] | 555 | const QVector<QString>& types = _rnxTypes[obs.satSys];
|
---|
| 556 | for (int ii = 0; ii < types.size(); ii++) {
|
---|
[4408] | 557 | double value = obs.measdata(types[ii], _rinexVers);
|
---|
| 558 | str << setw(14) << setprecision(3) << value;
|
---|
| 559 | if (value != 0.0 && types[ii].indexOf("L1") == 0) {
|
---|
| 560 | str << lli1 << ' ';
|
---|
[4407] | 561 | }
|
---|
[4408] | 562 | else if (value != 0.0 && types[ii].indexOf("L2") == 0) {
|
---|
| 563 | str << lli2 << ' ';
|
---|
[4407] | 564 | }
|
---|
[4408] | 565 | else if (value != 0.0 && types[ii].indexOf("L5") == 0) {
|
---|
| 566 | str << lli5 << ' ';
|
---|
[4407] | 567 | }
|
---|
| 568 | else {
|
---|
[4408] | 569 | str << " ";
|
---|
[4407] | 570 | }
|
---|
[2695] | 571 | }
|
---|
[4389] | 572 |
|
---|
[2695] | 573 | return str.str();
|
---|
| 574 | }
|
---|
[3324] | 575 |
|
---|
[3344] | 576 | //
|
---|
| 577 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 578 | string bncRinex::obsToStr(double val, int width, int precision) {
|
---|
[3326] | 579 | if (val != 0.0) {
|
---|
| 580 | ostringstream str;
|
---|
| 581 | str.setf(ios::showpoint | ios::fixed);
|
---|
[3344] | 582 | str << setw(width) << setprecision(precision) << val;
|
---|
[3326] | 583 | return str.str();
|
---|
| 584 | }
|
---|
| 585 | else {
|
---|
| 586 | return "0.0";
|
---|
| 587 | }
|
---|
| 588 | }
|
---|
| 589 |
|
---|
[3324] | 590 | // One Line in ASCII (Internal) Format
|
---|
| 591 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 592 | string bncRinex::asciiSatLine(const t_obs& obs) {
|
---|
| 593 |
|
---|
| 594 | ostringstream str;
|
---|
| 595 | str.setf(ios::showpoint | ios::fixed);
|
---|
| 596 |
|
---|
[3325] | 597 | str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
|
---|
| 598 |
|
---|
[3344] | 599 | if (obs.satSys == 'R') { // Glonass
|
---|
| 600 | str << ' ' << setw(2) << obs.slotNum;
|
---|
| 601 | }
|
---|
| 602 | else {
|
---|
| 603 | str << " ";
|
---|
| 604 | }
|
---|
| 605 |
|
---|
[4403] | 606 | float rnxVers = 3.0;
|
---|
| 607 |
|
---|
[4391] | 608 | if (obs.satSys == 'G') { // GPS
|
---|
| 609 | str << " 1C "
|
---|
[4403] | 610 | << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
|
---|
| 611 | << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
|
---|
| 612 | << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
|
---|
| 613 | << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
|
---|
[4391] | 614 | << setw(2) << obs.slip_cnt_L1;
|
---|
[4403] | 615 | str << " 1P "
|
---|
| 616 | << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
|
---|
| 617 | << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
|
---|
| 618 | << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
|
---|
| 619 | << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 620 | << setw(2) << obs.slip_cnt_L1;
|
---|
| 621 | str << " 2P "
|
---|
[4403] | 622 | << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
|
---|
| 623 | << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
|
---|
| 624 | << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
|
---|
| 625 | << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 626 | << setw(2) << obs.slip_cnt_L2;
|
---|
| 627 | str << " 5C "
|
---|
[4403] | 628 | << obsToStr(obs.measdata("C5", rnxVers)) << ' '
|
---|
| 629 | << obsToStr(obs.measdata("L5", rnxVers)) << ' '
|
---|
| 630 | << obsToStr(obs.measdata("D5", rnxVers)) << ' '
|
---|
| 631 | << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
|
---|
[4391] | 632 | << setw(2) << obs.slip_cnt_L5;
|
---|
[3324] | 633 | }
|
---|
[4391] | 634 | else if (obs.satSys == 'R') { // Glonass
|
---|
| 635 | str << " 1C "
|
---|
[4403] | 636 | << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
|
---|
| 637 | << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
|
---|
| 638 | << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
|
---|
| 639 | << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
|
---|
[4391] | 640 | << setw(2) << obs.slip_cnt_L1;
|
---|
| 641 | str << " 1P "
|
---|
[4403] | 642 | << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
|
---|
| 643 | << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
|
---|
| 644 | << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
|
---|
| 645 | << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 646 | << setw(2) << obs.slip_cnt_L1;
|
---|
| 647 | str << " 2P "
|
---|
[4403] | 648 | << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
|
---|
| 649 | << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
|
---|
| 650 | << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
|
---|
| 651 | << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 652 | << setw(2) << obs.slip_cnt_L2;
|
---|
| 653 | str << " 2C "
|
---|
[4403] | 654 | << obsToStr(obs.measdata("C2C", rnxVers)) << ' '
|
---|
| 655 | << obsToStr(obs.measdata("L2C", rnxVers)) << ' '
|
---|
| 656 | << obsToStr(obs.measdata("D2C", rnxVers)) << ' '
|
---|
| 657 | << obsToStr(obs.measdata("S2C", rnxVers), 8, 3) << ' '
|
---|
[4391] | 658 | << setw(2) << obs.slip_cnt_L2;
|
---|
| 659 | }
|
---|
| 660 | else if (obs.satSys == 'E') { // Galileo
|
---|
| 661 | str << " 1C "
|
---|
[4403] | 662 | << obsToStr(obs.measdata("C1", rnxVers)) << ' '
|
---|
| 663 | << obsToStr(obs.measdata("L1", rnxVers)) << ' '
|
---|
| 664 | << obsToStr(obs.measdata("D1", rnxVers)) << ' '
|
---|
| 665 | << obsToStr(obs.measdata("S1", rnxVers), 8, 3) << ' '
|
---|
[4391] | 666 | << setw(2) << obs.slip_cnt_L1;
|
---|
[4389] | 667 |
|
---|
[4391] | 668 | str << " 5C "
|
---|
[4403] | 669 | << obsToStr(obs.measdata("C5", rnxVers)) << ' '
|
---|
| 670 | << obsToStr(obs.measdata("L5", rnxVers)) << ' '
|
---|
| 671 | << obsToStr(obs.measdata("D5", rnxVers)) << ' '
|
---|
| 672 | << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
|
---|
[4391] | 673 | << setw(2) << obs.slip_cnt_L5;
|
---|
| 674 | }
|
---|
[3324] | 675 | return str.str();
|
---|
| 676 | }
|
---|