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