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