[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 |
|
---|
| 48 | // Constructor
|
---|
| 49 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 50 | t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
|
---|
| 51 |
|
---|
| 52 | bncSettings settings;
|
---|
| 53 |
|
---|
| 54 | _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
|
---|
| 55 | _outObsFileName = settings.value("reqcOutObsFile").toString();
|
---|
[3999] | 56 | _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
|
---|
| 57 | _outNavFileName = settings.value("reqcOutNavFile").toString();
|
---|
[4010] | 58 | int version = settings.value("reqcRnxVersion").toInt();
|
---|
| 59 | if (version < 3) {
|
---|
| 60 | _rnxVersion = 2.11;
|
---|
| 61 | }
|
---|
| 62 | else {
|
---|
| 63 | _rnxVersion = 3.01;
|
---|
| 64 | }
|
---|
[3981] | 65 | _samplingRate = settings.value("reqcSampling").toInt();
|
---|
[3989] | 66 | _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
|
---|
| 67 | _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
|
---|
[3901] | 68 | }
|
---|
| 69 |
|
---|
| 70 | // Destructor
|
---|
| 71 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 72 | t_reqcEdit::~t_reqcEdit() {
|
---|
| 73 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 74 | delete _rnxObsFiles[ii];
|
---|
| 75 | }
|
---|
[4001] | 76 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 77 | delete _ephs[ii];
|
---|
| 78 | }
|
---|
[3901] | 79 | }
|
---|
| 80 |
|
---|
| 81 | //
|
---|
| 82 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 83 | void t_reqcEdit::run() {
|
---|
[3998] | 84 |
|
---|
| 85 | editObservations();
|
---|
[3901] | 86 |
|
---|
[3998] | 87 | editEphemerides();
|
---|
| 88 |
|
---|
| 89 | bncApp* app = (bncApp*) qApp;
|
---|
| 90 | if ( app->mode() != bncApp::interactive) {
|
---|
| 91 | app->exit(0);
|
---|
| 92 | }
|
---|
| 93 | else {
|
---|
| 94 | emit finished();
|
---|
| 95 | deleteLater();
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | //
|
---|
| 100 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 101 | void t_reqcEdit::editObservations() {
|
---|
| 102 |
|
---|
[4013] | 103 | // Easy Exit
|
---|
| 104 | // ---------
|
---|
| 105 | if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
|
---|
| 106 | return;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[3901] | 109 | // Initialize input observation files, sort them according to start time
|
---|
| 110 | // ---------------------------------------------------------------------
|
---|
| 111 | QStringListIterator it(_obsFileNames);
|
---|
| 112 | while (it.hasNext()) {
|
---|
| 113 | QString fileName = it.next();
|
---|
[4080] | 114 | if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
|
---|
| 115 | QFileInfo fileInfo(fileName);
|
---|
| 116 | QDir dir = fileInfo.dir();
|
---|
| 117 | QStringList filters; filters << fileInfo.fileName();
|
---|
| 118 | QListIterator<QFileInfo> it(dir.entryInfoList(filters));
|
---|
| 119 | while (it.hasNext()) {
|
---|
| 120 | QString filePath = it.next().filePath();
|
---|
| 121 | t_rnxObsFile* rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
|
---|
| 122 | _rnxObsFiles.append(rnxObsFile);
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | else {
|
---|
| 126 | t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
|
---|
| 127 | _rnxObsFiles.append(rnxObsFile);
|
---|
| 128 | }
|
---|
[3901] | 129 | }
|
---|
| 130 | qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
|
---|
| 131 | t_rnxObsFile::earlierStartTime);
|
---|
| 132 |
|
---|
| 133 | // Initialize output observation file
|
---|
| 134 | // ----------------------------------
|
---|
| 135 | t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
|
---|
| 136 |
|
---|
| 137 | // Loop over all input observation files
|
---|
| 138 | // -------------------------------------
|
---|
| 139 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 140 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
| 141 | if (ii == 0) {
|
---|
[3956] | 142 | outObsFile.setHeader(obsFile->header(), _rnxVersion);
|
---|
[3992] | 143 | if (_begTime.valid() && _begTime > outObsFile.startTime()) {
|
---|
| 144 | outObsFile.setStartTime(_begTime);
|
---|
| 145 | }
|
---|
[4112] | 146 | if (_samplingRate > outObsFile.interval()) {
|
---|
| 147 | outObsFile.setInterval(_samplingRate);
|
---|
| 148 | }
|
---|
[3982] | 149 | editRnxObsHeader(outObsFile);
|
---|
[4117] | 150 | bncSettings settings;
|
---|
[4114] | 151 | QMap<QString, QString> txtMap;
|
---|
[4117] | 152 | QString runBy = settings.value("reqcRunBy").toString();
|
---|
| 153 | if (!runBy.isEmpty()) {
|
---|
| 154 | txtMap["RUN BY"] = runBy;
|
---|
| 155 | }
|
---|
| 156 | QString comment = settings.value("reqcComment").toString();
|
---|
| 157 | if (!comment.isEmpty()) {
|
---|
| 158 | txtMap["COMMENT"] = comment;
|
---|
| 159 | }
|
---|
[4137] | 160 | outObsFile.writeHeader(&txtMap);
|
---|
[3901] | 161 | }
|
---|
[4054] | 162 | else {
|
---|
| 163 | outObsFile.checkNewHeader(obsFile->header());
|
---|
| 164 | }
|
---|
[3994] | 165 | t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
[3901] | 166 | while ( (epo = obsFile->nextEpoch()) != 0) {
|
---|
[3993] | 167 | if (_begTime.valid() && epo->tt < _begTime) {
|
---|
| 168 | continue;
|
---|
| 169 | }
|
---|
| 170 | if (_endTime.valid() && epo->tt > _endTime) {
|
---|
| 171 | break;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | if (_samplingRate == 0 ||
|
---|
| 175 | fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
|
---|
[3995] | 176 | applyLLI(obsFile, epo);
|
---|
[3990] | 177 | outObsFile.writeEpoch(epo);
|
---|
| 178 | }
|
---|
[3994] | 179 | else {
|
---|
[3995] | 180 | rememberLLI(obsFile, epo);
|
---|
[3994] | 181 | }
|
---|
[3901] | 182 | }
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
[3982] | 185 |
|
---|
| 186 | // Change RINEX Header Content
|
---|
| 187 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3985] | 188 | void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
|
---|
[3982] | 189 |
|
---|
[3983] | 190 | bncSettings settings;
|
---|
| 191 |
|
---|
| 192 | QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
|
---|
| 193 | QString newMarkerName = settings.value("reqcNewMarkerName").toString();
|
---|
[4090] | 194 | if (!newMarkerName.isEmpty()) {
|
---|
| 195 | if (oldMarkerName.isEmpty() ||
|
---|
| 196 | QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
|
---|
| 197 | obsFile.setMarkerName(newMarkerName);
|
---|
| 198 | }
|
---|
[3985] | 199 | }
|
---|
| 200 |
|
---|
[3983] | 201 | QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
|
---|
| 202 | QString newAntennaName = settings.value("reqcNewAntennaName").toString();
|
---|
[4090] | 203 | if (!newAntennaName.isEmpty()) {
|
---|
| 204 | if (oldAntennaName.isEmpty() ||
|
---|
| 205 | QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
|
---|
| 206 | obsFile.setAntennaName(newAntennaName);
|
---|
| 207 | }
|
---|
[3985] | 208 | }
|
---|
[3983] | 209 |
|
---|
[3985] | 210 | QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
|
---|
| 211 | QString newReceiverType = settings.value("reqcNewReceiverName").toString();
|
---|
[4090] | 212 | if (!newReceiverType.isEmpty()) {
|
---|
| 213 | if (oldReceiverType.isEmpty() ||
|
---|
| 214 | QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
|
---|
| 215 | obsFile.setReceiverType(newReceiverType);
|
---|
| 216 | }
|
---|
[3985] | 217 | }
|
---|
[3982] | 218 | }
|
---|
[3994] | 219 |
|
---|
| 220 | //
|
---|
| 221 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3995] | 222 | void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
|
---|
| 223 | const t_rnxObsFile::t_rnxEpo* epo) {
|
---|
[3994] | 224 |
|
---|
[3995] | 225 | if (_samplingRate == 0) {
|
---|
| 226 | return;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
| 230 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
| 231 | char sys = rnxSat.satSys;
|
---|
[3997] | 232 | QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
|
---|
| 233 |
|
---|
[3995] | 234 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
[3997] | 235 | if (!_lli[prn].contains(iType)) {
|
---|
| 236 | _lli[prn][iType] = 0;
|
---|
[3996] | 237 | }
|
---|
| 238 | if (rnxSat.lli[iType] & 1) {
|
---|
[3997] | 239 | _lli[prn][iType] |= 1;
|
---|
[3996] | 240 | }
|
---|
[3995] | 241 | }
|
---|
| 242 | }
|
---|
[3994] | 243 | }
|
---|
| 244 |
|
---|
| 245 | //
|
---|
| 246 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3995] | 247 | void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
|
---|
| 248 | t_rnxObsFile::t_rnxEpo* epo) {
|
---|
[3996] | 249 |
|
---|
| 250 | if (_samplingRate == 0) {
|
---|
[3995] | 251 | return;
|
---|
| 252 | }
|
---|
[3996] | 253 |
|
---|
| 254 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
| 255 | t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
| 256 | char sys = rnxSat.satSys;
|
---|
[3997] | 257 | QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
|
---|
| 258 |
|
---|
[3996] | 259 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
[3997] | 260 | if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
|
---|
[3996] | 261 | rnxSat.lli[iType] |= 1;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | _lli.clear();
|
---|
[3994] | 267 | }
|
---|
[3998] | 268 |
|
---|
| 269 | //
|
---|
| 270 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 271 | void t_reqcEdit::editEphemerides() {
|
---|
| 272 |
|
---|
[4013] | 273 | // Easy Exit
|
---|
| 274 | // ---------
|
---|
| 275 | if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
|
---|
| 276 | return;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[4000] | 279 | // Read All Ephemerides
|
---|
| 280 | // --------------------
|
---|
[3999] | 281 | QStringListIterator it(_navFileNames);
|
---|
| 282 | while (it.hasNext()) {
|
---|
| 283 | QString fileName = it.next();
|
---|
[4081] | 284 | if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
|
---|
| 285 | QFileInfo fileInfo(fileName);
|
---|
| 286 | QDir dir = fileInfo.dir();
|
---|
| 287 | QStringList filters; filters << fileInfo.fileName();
|
---|
| 288 | QListIterator<QFileInfo> it(dir.entryInfoList(filters));
|
---|
| 289 | while (it.hasNext()) {
|
---|
| 290 | QString filePath = it.next().filePath();
|
---|
| 291 | appendEphemerides(filePath);
|
---|
[4000] | 292 | }
|
---|
| 293 | }
|
---|
[4081] | 294 | else {
|
---|
| 295 | appendEphemerides(fileName);
|
---|
| 296 | }
|
---|
[3999] | 297 | }
|
---|
[4003] | 298 | qStableSort(_ephs.begin(), _ephs.end(), t_eph::earlierTime);
|
---|
[3999] | 299 |
|
---|
[4007] | 300 | // Initialize output navigation file
|
---|
| 301 | // ---------------------------------
|
---|
[4004] | 302 | t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
|
---|
[4009] | 303 | outNavFile.setVersion(_rnxVersion);
|
---|
| 304 | outNavFile.writeHeader();
|
---|
| 305 |
|
---|
[4004] | 306 | // Loop over all ephemerides
|
---|
| 307 | // -------------------------
|
---|
| 308 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 309 | const t_eph* eph = _ephs[ii];
|
---|
[4010] | 310 | if (eph->type() == t_eph::GPS || _rnxVersion >= 3.0) {
|
---|
| 311 | outNavFile.writeEph(eph);
|
---|
| 312 | }
|
---|
[4004] | 313 | }
|
---|
[3998] | 314 | }
|
---|
[4081] | 315 |
|
---|
| 316 | //
|
---|
| 317 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 318 | void t_reqcEdit::appendEphemerides(const QString& fileName) {
|
---|
| 319 |
|
---|
| 320 | t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
|
---|
| 321 | for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
|
---|
| 322 | t_eph* eph = rnxNavFile.ephs()[ii];
|
---|
| 323 | bool isNew = true;
|
---|
| 324 | for (int iOld = 0; iOld < _ephs.size(); iOld++) {
|
---|
| 325 | const t_eph* ephOld = _ephs[iOld];
|
---|
| 326 | if (ephOld->prn() == eph->prn() && ephOld->IOD() == eph->IOD()) {
|
---|
| 327 | isNew = false;
|
---|
| 328 | break;
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 | if (isNew) {
|
---|
| 332 | if (eph->type() == t_eph::GPS) {
|
---|
| 333 | _ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
|
---|
| 334 | }
|
---|
| 335 | else if (eph->type() == t_eph::GLONASS) {
|
---|
| 336 | _ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
|
---|
| 337 | }
|
---|
| 338 | else if (eph->type() == t_eph::Galileo) {
|
---|
| 339 | _ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
| 343 | }
|
---|