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