[3901] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: t_reqcEdit
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Edit/Concatenate RINEX Files
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 11-Apr-2012
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
| 42 | #include "reqcedit.h"
|
---|
[3972] | 43 | #include "bncapp.h"
|
---|
[3901] | 44 | #include "bncsettings.h"
|
---|
| 45 |
|
---|
| 46 | using namespace std;
|
---|
| 47 |
|
---|
[4229] | 48 | const double rnxV2 = 2.11;
|
---|
| 49 | const double rnxV3 = 3.01;
|
---|
| 50 |
|
---|
[3901] | 51 | // Constructor
|
---|
| 52 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 53 | t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
|
---|
| 54 |
|
---|
| 55 | bncSettings settings;
|
---|
| 56 |
|
---|
| 57 | _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
|
---|
| 58 | _outObsFileName = settings.value("reqcOutObsFile").toString();
|
---|
[3999] | 59 | _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
|
---|
| 60 | _outNavFileName = settings.value("reqcOutNavFile").toString();
|
---|
[4010] | 61 | int version = settings.value("reqcRnxVersion").toInt();
|
---|
| 62 | if (version < 3) {
|
---|
[4229] | 63 | _rnxVersion = rnxV2;
|
---|
[4010] | 64 | }
|
---|
| 65 | else {
|
---|
[4229] | 66 | _rnxVersion = rnxV3;
|
---|
[4010] | 67 | }
|
---|
[3981] | 68 | _samplingRate = settings.value("reqcSampling").toInt();
|
---|
[3989] | 69 | _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
|
---|
| 70 | _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
|
---|
[3901] | 71 | }
|
---|
| 72 |
|
---|
| 73 | // Destructor
|
---|
| 74 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 75 | t_reqcEdit::~t_reqcEdit() {
|
---|
| 76 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 77 | delete _rnxObsFiles[ii];
|
---|
| 78 | }
|
---|
[4001] | 79 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 80 | delete _ephs[ii];
|
---|
| 81 | }
|
---|
[3901] | 82 | }
|
---|
| 83 |
|
---|
| 84 | //
|
---|
| 85 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 86 | void t_reqcEdit::run() {
|
---|
[3998] | 87 |
|
---|
| 88 | editObservations();
|
---|
[3901] | 89 |
|
---|
[3998] | 90 | editEphemerides();
|
---|
| 91 |
|
---|
| 92 | bncApp* app = (bncApp*) qApp;
|
---|
| 93 | if ( app->mode() != bncApp::interactive) {
|
---|
| 94 | app->exit(0);
|
---|
| 95 | }
|
---|
| 96 | else {
|
---|
| 97 | emit finished();
|
---|
| 98 | deleteLater();
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[4254] | 102 | // Initialize input observation files, sort them according to start time
|
---|
[3998] | 103 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4254] | 104 | void t_reqcEdit::initRnxObsFiles(const QStringList& obsFileNames,
|
---|
| 105 | QVector<t_rnxObsFile*>& rnxObsFiles) {
|
---|
[3998] | 106 |
|
---|
[4254] | 107 | QStringListIterator it(obsFileNames);
|
---|
[3901] | 108 | while (it.hasNext()) {
|
---|
| 109 | QString fileName = it.next();
|
---|
[4080] | 110 | if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
|
---|
| 111 | QFileInfo fileInfo(fileName);
|
---|
| 112 | QDir dir = fileInfo.dir();
|
---|
| 113 | QStringList filters; filters << fileInfo.fileName();
|
---|
| 114 | QListIterator<QFileInfo> it(dir.entryInfoList(filters));
|
---|
| 115 | while (it.hasNext()) {
|
---|
| 116 | QString filePath = it.next().filePath();
|
---|
| 117 | t_rnxObsFile* rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
|
---|
[4254] | 118 | rnxObsFiles.append(rnxObsFile);
|
---|
[4080] | 119 | }
|
---|
| 120 | }
|
---|
| 121 | else {
|
---|
| 122 | t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
|
---|
[4254] | 123 | rnxObsFiles.append(rnxObsFile);
|
---|
[4080] | 124 | }
|
---|
[3901] | 125 | }
|
---|
[4254] | 126 | qStableSort(rnxObsFiles.begin(), rnxObsFiles.end(),
|
---|
[3901] | 127 | t_rnxObsFile::earlierStartTime);
|
---|
[4254] | 128 | }
|
---|
[3901] | 129 |
|
---|
[4254] | 130 | //
|
---|
| 131 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 132 | void t_reqcEdit::editObservations() {
|
---|
| 133 |
|
---|
| 134 | // Easy Exit
|
---|
| 135 | // ---------
|
---|
| 136 | if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
|
---|
| 137 | return;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles);
|
---|
| 141 |
|
---|
[3901] | 142 | // Initialize output observation file
|
---|
| 143 | // ----------------------------------
|
---|
| 144 | t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
|
---|
| 145 |
|
---|
| 146 | // Loop over all input observation files
|
---|
| 147 | // -------------------------------------
|
---|
| 148 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 149 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
| 150 | if (ii == 0) {
|
---|
[3956] | 151 | outObsFile.setHeader(obsFile->header(), _rnxVersion);
|
---|
[3992] | 152 | if (_begTime.valid() && _begTime > outObsFile.startTime()) {
|
---|
| 153 | outObsFile.setStartTime(_begTime);
|
---|
| 154 | }
|
---|
[4112] | 155 | if (_samplingRate > outObsFile.interval()) {
|
---|
| 156 | outObsFile.setInterval(_samplingRate);
|
---|
| 157 | }
|
---|
[3982] | 158 | editRnxObsHeader(outObsFile);
|
---|
[4117] | 159 | bncSettings settings;
|
---|
[4114] | 160 | QMap<QString, QString> txtMap;
|
---|
[4117] | 161 | QString runBy = settings.value("reqcRunBy").toString();
|
---|
| 162 | if (!runBy.isEmpty()) {
|
---|
| 163 | txtMap["RUN BY"] = runBy;
|
---|
| 164 | }
|
---|
| 165 | QString comment = settings.value("reqcComment").toString();
|
---|
| 166 | if (!comment.isEmpty()) {
|
---|
| 167 | txtMap["COMMENT"] = comment;
|
---|
| 168 | }
|
---|
[4137] | 169 | outObsFile.writeHeader(&txtMap);
|
---|
[3901] | 170 | }
|
---|
[4054] | 171 | else {
|
---|
| 172 | outObsFile.checkNewHeader(obsFile->header());
|
---|
| 173 | }
|
---|
[3994] | 174 | t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
[3901] | 175 | while ( (epo = obsFile->nextEpoch()) != 0) {
|
---|
[3993] | 176 | if (_begTime.valid() && epo->tt < _begTime) {
|
---|
| 177 | continue;
|
---|
| 178 | }
|
---|
| 179 | if (_endTime.valid() && epo->tt > _endTime) {
|
---|
| 180 | break;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | if (_samplingRate == 0 ||
|
---|
| 184 | fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
|
---|
[3995] | 185 | applyLLI(obsFile, epo);
|
---|
[3990] | 186 | outObsFile.writeEpoch(epo);
|
---|
| 187 | }
|
---|
[3994] | 188 | else {
|
---|
[3995] | 189 | rememberLLI(obsFile, epo);
|
---|
[3994] | 190 | }
|
---|
[3901] | 191 | }
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
[3982] | 194 |
|
---|
| 195 | // Change RINEX Header Content
|
---|
| 196 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3985] | 197 | void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
|
---|
[3982] | 198 |
|
---|
[3983] | 199 | bncSettings settings;
|
---|
| 200 |
|
---|
| 201 | QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
|
---|
| 202 | QString newMarkerName = settings.value("reqcNewMarkerName").toString();
|
---|
[4090] | 203 | if (!newMarkerName.isEmpty()) {
|
---|
| 204 | if (oldMarkerName.isEmpty() ||
|
---|
| 205 | QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
|
---|
| 206 | obsFile.setMarkerName(newMarkerName);
|
---|
| 207 | }
|
---|
[3985] | 208 | }
|
---|
| 209 |
|
---|
[3983] | 210 | QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
|
---|
| 211 | QString newAntennaName = settings.value("reqcNewAntennaName").toString();
|
---|
[4090] | 212 | if (!newAntennaName.isEmpty()) {
|
---|
| 213 | if (oldAntennaName.isEmpty() ||
|
---|
| 214 | QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
|
---|
| 215 | obsFile.setAntennaName(newAntennaName);
|
---|
| 216 | }
|
---|
[3985] | 217 | }
|
---|
[3983] | 218 |
|
---|
[3985] | 219 | QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
|
---|
| 220 | QString newReceiverType = settings.value("reqcNewReceiverName").toString();
|
---|
[4090] | 221 | if (!newReceiverType.isEmpty()) {
|
---|
| 222 | if (oldReceiverType.isEmpty() ||
|
---|
| 223 | QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
|
---|
| 224 | obsFile.setReceiverType(newReceiverType);
|
---|
| 225 | }
|
---|
[3985] | 226 | }
|
---|
[3982] | 227 | }
|
---|
[3994] | 228 |
|
---|
| 229 | //
|
---|
| 230 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3995] | 231 | void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
|
---|
| 232 | const t_rnxObsFile::t_rnxEpo* epo) {
|
---|
[3994] | 233 |
|
---|
[3995] | 234 | if (_samplingRate == 0) {
|
---|
| 235 | return;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
| 239 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
| 240 | char sys = rnxSat.satSys;
|
---|
[3997] | 241 | QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
|
---|
| 242 |
|
---|
[3995] | 243 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
[3997] | 244 | if (!_lli[prn].contains(iType)) {
|
---|
| 245 | _lli[prn][iType] = 0;
|
---|
[3996] | 246 | }
|
---|
| 247 | if (rnxSat.lli[iType] & 1) {
|
---|
[3997] | 248 | _lli[prn][iType] |= 1;
|
---|
[3996] | 249 | }
|
---|
[3995] | 250 | }
|
---|
| 251 | }
|
---|
[3994] | 252 | }
|
---|
| 253 |
|
---|
| 254 | //
|
---|
| 255 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3995] | 256 | void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
|
---|
| 257 | t_rnxObsFile::t_rnxEpo* epo) {
|
---|
[3996] | 258 |
|
---|
| 259 | if (_samplingRate == 0) {
|
---|
[3995] | 260 | return;
|
---|
| 261 | }
|
---|
[3996] | 262 |
|
---|
| 263 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
| 264 | t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
| 265 | char sys = rnxSat.satSys;
|
---|
[3997] | 266 | QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
|
---|
| 267 |
|
---|
[3996] | 268 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
[3997] | 269 | if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
|
---|
[3996] | 270 | rnxSat.lli[iType] |= 1;
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | _lli.clear();
|
---|
[3994] | 276 | }
|
---|
[3998] | 277 |
|
---|
[4256] | 278 | /// Read All Ephemerides
|
---|
[3998] | 279 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4256] | 280 | void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
|
---|
| 281 | QVector<t_eph*>& ephs) {
|
---|
[3998] | 282 |
|
---|
[4256] | 283 | QStringListIterator it(navFileNames);
|
---|
[3999] | 284 | while (it.hasNext()) {
|
---|
| 285 | QString fileName = it.next();
|
---|
[4081] | 286 | if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
|
---|
| 287 | QFileInfo fileInfo(fileName);
|
---|
| 288 | QDir dir = fileInfo.dir();
|
---|
| 289 | QStringList filters; filters << fileInfo.fileName();
|
---|
| 290 | QListIterator<QFileInfo> it(dir.entryInfoList(filters));
|
---|
| 291 | while (it.hasNext()) {
|
---|
| 292 | QString filePath = it.next().filePath();
|
---|
[4256] | 293 | appendEphemerides(filePath, ephs);
|
---|
[4000] | 294 | }
|
---|
| 295 | }
|
---|
[4081] | 296 | else {
|
---|
[4256] | 297 | appendEphemerides(fileName, ephs);
|
---|
[4081] | 298 | }
|
---|
[3999] | 299 | }
|
---|
[4256] | 300 | qStableSort(ephs.begin(), ephs.end(), t_eph::earlierTime);
|
---|
| 301 | }
|
---|
[3999] | 302 |
|
---|
[4256] | 303 | //
|
---|
| 304 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 305 | void t_reqcEdit::editEphemerides() {
|
---|
| 306 |
|
---|
| 307 | // Easy Exit
|
---|
| 308 | // ---------
|
---|
| 309 | if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
|
---|
| 310 | return;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[4257] | 313 | // Read Ephemerides
|
---|
| 314 | // ----------------
|
---|
[4256] | 315 | t_reqcEdit::readEphemerides(_navFileNames, _ephs);
|
---|
| 316 |
|
---|
[4229] | 317 | // Check Satellite Systems
|
---|
| 318 | // -----------------------
|
---|
| 319 | bool haveGPS = false;
|
---|
| 320 | bool haveGlonass = false;
|
---|
| 321 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 322 | const t_eph* eph = _ephs[ii];
|
---|
| 323 | if (eph->type() == t_eph::GPS) {
|
---|
| 324 | haveGPS = true;
|
---|
| 325 | }
|
---|
| 326 | else if (eph->type() == t_eph::GLONASS) {
|
---|
| 327 | haveGlonass = true;
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 |
|
---|
[4007] | 331 | // Initialize output navigation file
|
---|
| 332 | // ---------------------------------
|
---|
[4004] | 333 | t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
|
---|
[4229] | 334 |
|
---|
| 335 | outNavFile.setGlonass(haveGlonass);
|
---|
| 336 |
|
---|
| 337 | if (haveGPS && haveGlonass) {
|
---|
| 338 | outNavFile.setVersion(rnxV3);
|
---|
| 339 | }
|
---|
| 340 | else {
|
---|
| 341 | outNavFile.setVersion(_rnxVersion);
|
---|
| 342 | }
|
---|
| 343 |
|
---|
[4221] | 344 | bncSettings settings;
|
---|
| 345 | QMap<QString, QString> txtMap;
|
---|
| 346 | QString runBy = settings.value("reqcRunBy").toString();
|
---|
| 347 | if (!runBy.isEmpty()) {
|
---|
| 348 | txtMap["RUN BY"] = runBy;
|
---|
| 349 | }
|
---|
| 350 | QString comment = settings.value("reqcComment").toString();
|
---|
| 351 | if (!comment.isEmpty()) {
|
---|
| 352 | txtMap["COMMENT"] = comment;
|
---|
| 353 | }
|
---|
[4229] | 354 |
|
---|
[4221] | 355 | outNavFile.writeHeader(&txtMap);
|
---|
[4009] | 356 |
|
---|
[4004] | 357 | // Loop over all ephemerides
|
---|
| 358 | // -------------------------
|
---|
| 359 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 360 | const t_eph* eph = _ephs[ii];
|
---|
[4229] | 361 | outNavFile.writeEph(eph);
|
---|
[4004] | 362 | }
|
---|
[3998] | 363 | }
|
---|
[4081] | 364 |
|
---|
| 365 | //
|
---|
| 366 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4256] | 367 | void t_reqcEdit::appendEphemerides(const QString& fileName,
|
---|
| 368 | QVector<t_eph*>& ephs) {
|
---|
[4081] | 369 |
|
---|
| 370 | t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
|
---|
| 371 | for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
|
---|
| 372 | t_eph* eph = rnxNavFile.ephs()[ii];
|
---|
| 373 | bool isNew = true;
|
---|
[4256] | 374 | for (int iOld = 0; iOld < ephs.size(); iOld++) {
|
---|
| 375 | const t_eph* ephOld = ephs[iOld];
|
---|
[4236] | 376 | if (ephOld->prn() == eph->prn() && ephOld->TOC() == eph->TOC()) {
|
---|
[4081] | 377 | isNew = false;
|
---|
| 378 | break;
|
---|
| 379 | }
|
---|
| 380 | }
|
---|
| 381 | if (isNew) {
|
---|
| 382 | if (eph->type() == t_eph::GPS) {
|
---|
[4256] | 383 | ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
|
---|
[4081] | 384 | }
|
---|
| 385 | else if (eph->type() == t_eph::GLONASS) {
|
---|
[4256] | 386 | ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
|
---|
[4081] | 387 | }
|
---|
| 388 | else if (eph->type() == t_eph::Galileo) {
|
---|
[4256] | 389 | ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
|
---|
[4081] | 390 | }
|
---|
| 391 | }
|
---|
| 392 | }
|
---|
| 393 | }
|
---|