[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();
|
---|
| 114 | t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
|
---|
| 115 | _rnxObsFiles.append(rnxObsFile);
|
---|
| 116 | }
|
---|
| 117 | qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
|
---|
| 118 | t_rnxObsFile::earlierStartTime);
|
---|
| 119 |
|
---|
| 120 | // Initialize output observation file
|
---|
| 121 | // ----------------------------------
|
---|
| 122 | t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
|
---|
| 123 |
|
---|
| 124 | // Loop over all input observation files
|
---|
| 125 | // -------------------------------------
|
---|
| 126 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 127 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
| 128 | if (ii == 0) {
|
---|
[3956] | 129 | outObsFile.setHeader(obsFile->header(), _rnxVersion);
|
---|
[3992] | 130 | if (_begTime.valid() && _begTime > outObsFile.startTime()) {
|
---|
| 131 | outObsFile.setStartTime(_begTime);
|
---|
| 132 | }
|
---|
[3982] | 133 | editRnxObsHeader(outObsFile);
|
---|
[3901] | 134 | outObsFile.writeHeader();
|
---|
| 135 | }
|
---|
[4054] | 136 | else {
|
---|
| 137 | outObsFile.checkNewHeader(obsFile->header());
|
---|
| 138 | }
|
---|
[3994] | 139 | t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
[3901] | 140 | while ( (epo = obsFile->nextEpoch()) != 0) {
|
---|
[3993] | 141 | if (_begTime.valid() && epo->tt < _begTime) {
|
---|
| 142 | continue;
|
---|
| 143 | }
|
---|
| 144 | if (_endTime.valid() && epo->tt > _endTime) {
|
---|
| 145 | break;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | if (_samplingRate == 0 ||
|
---|
| 149 | fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
|
---|
[3995] | 150 | applyLLI(obsFile, epo);
|
---|
[3990] | 151 | outObsFile.writeEpoch(epo);
|
---|
| 152 | }
|
---|
[3994] | 153 | else {
|
---|
[3995] | 154 | rememberLLI(obsFile, epo);
|
---|
[3994] | 155 | }
|
---|
[3901] | 156 | }
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
[3982] | 159 |
|
---|
| 160 | // Change RINEX Header Content
|
---|
| 161 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3985] | 162 | void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
|
---|
[3982] | 163 |
|
---|
[3983] | 164 | bncSettings settings;
|
---|
| 165 |
|
---|
| 166 | QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
|
---|
| 167 | QString newMarkerName = settings.value("reqcNewMarkerName").toString();
|
---|
[3985] | 168 | if (oldMarkerName.isEmpty() ||
|
---|
| 169 | QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
|
---|
| 170 | obsFile.setMarkerName(newMarkerName);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[3983] | 173 | QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
|
---|
| 174 | QString newAntennaName = settings.value("reqcNewAntennaName").toString();
|
---|
[3985] | 175 | if (oldAntennaName.isEmpty() ||
|
---|
| 176 | QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
|
---|
| 177 | obsFile.setAntennaName(newAntennaName);
|
---|
| 178 | }
|
---|
[3983] | 179 |
|
---|
[3985] | 180 | QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
|
---|
| 181 | QString newReceiverType = settings.value("reqcNewReceiverName").toString();
|
---|
| 182 | if (oldReceiverType.isEmpty() ||
|
---|
| 183 | QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
|
---|
| 184 | obsFile.setReceiverType(newReceiverType);
|
---|
| 185 | }
|
---|
[3982] | 186 | }
|
---|
[3994] | 187 |
|
---|
| 188 | //
|
---|
| 189 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3995] | 190 | void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
|
---|
| 191 | const t_rnxObsFile::t_rnxEpo* epo) {
|
---|
[3994] | 192 |
|
---|
[3995] | 193 | if (_samplingRate == 0) {
|
---|
| 194 | return;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
| 198 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
| 199 | char sys = rnxSat.satSys;
|
---|
[3997] | 200 | QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
|
---|
| 201 |
|
---|
[3995] | 202 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
[3997] | 203 | if (!_lli[prn].contains(iType)) {
|
---|
| 204 | _lli[prn][iType] = 0;
|
---|
[3996] | 205 | }
|
---|
| 206 | if (rnxSat.lli[iType] & 1) {
|
---|
[3997] | 207 | _lli[prn][iType] |= 1;
|
---|
[3996] | 208 | }
|
---|
[3995] | 209 | }
|
---|
| 210 | }
|
---|
[3994] | 211 | }
|
---|
| 212 |
|
---|
| 213 | //
|
---|
| 214 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3995] | 215 | void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
|
---|
| 216 | t_rnxObsFile::t_rnxEpo* epo) {
|
---|
[3996] | 217 |
|
---|
| 218 | if (_samplingRate == 0) {
|
---|
[3995] | 219 | return;
|
---|
| 220 | }
|
---|
[3996] | 221 |
|
---|
| 222 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
| 223 | t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
| 224 | char sys = rnxSat.satSys;
|
---|
[3997] | 225 | QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
|
---|
| 226 |
|
---|
[3996] | 227 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
[3997] | 228 | if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
|
---|
[3996] | 229 | rnxSat.lli[iType] |= 1;
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | _lli.clear();
|
---|
[3994] | 235 | }
|
---|
[3998] | 236 |
|
---|
| 237 | //
|
---|
| 238 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 239 | void t_reqcEdit::editEphemerides() {
|
---|
| 240 |
|
---|
[4013] | 241 | // Easy Exit
|
---|
| 242 | // ---------
|
---|
| 243 | if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
|
---|
| 244 | return;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[4000] | 247 | // Read All Ephemerides
|
---|
| 248 | // --------------------
|
---|
[3999] | 249 | QStringListIterator it(_navFileNames);
|
---|
| 250 | while (it.hasNext()) {
|
---|
| 251 | QString fileName = it.next();
|
---|
| 252 | t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
|
---|
[4000] | 253 | for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
|
---|
[4038] | 254 | t_eph* eph = rnxNavFile.ephs()[ii];
|
---|
| 255 | bool isNew = true;
|
---|
| 256 | for (int iOld = 0; iOld < _ephs.size(); iOld++) {
|
---|
| 257 | const t_eph* ephOld = _ephs[iOld];
|
---|
| 258 | if (ephOld->prn() == eph->prn() && ephOld->IOD() == eph->IOD()) {
|
---|
| 259 | isNew = false;
|
---|
| 260 | break;
|
---|
| 261 | }
|
---|
[4000] | 262 | }
|
---|
[4038] | 263 | if (isNew) {
|
---|
| 264 | if (eph->type() == t_eph::GPS) {
|
---|
| 265 | _ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
|
---|
| 266 | }
|
---|
| 267 | else if (eph->type() == t_eph::GLONASS) {
|
---|
| 268 | _ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
|
---|
| 269 | }
|
---|
| 270 | else if (eph->type() == t_eph::Galileo) {
|
---|
| 271 | _ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
|
---|
| 272 | }
|
---|
[4000] | 273 | }
|
---|
| 274 | }
|
---|
[3999] | 275 | }
|
---|
[4003] | 276 | qStableSort(_ephs.begin(), _ephs.end(), t_eph::earlierTime);
|
---|
[3999] | 277 |
|
---|
[4007] | 278 | // Initialize output navigation file
|
---|
| 279 | // ---------------------------------
|
---|
[4004] | 280 | t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
|
---|
[4009] | 281 | outNavFile.setVersion(_rnxVersion);
|
---|
| 282 | outNavFile.writeHeader();
|
---|
| 283 |
|
---|
[4004] | 284 | // Loop over all ephemerides
|
---|
| 285 | // -------------------------
|
---|
| 286 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 287 | const t_eph* eph = _ephs[ii];
|
---|
[4010] | 288 | if (eph->type() == t_eph::GPS || _rnxVersion >= 3.0) {
|
---|
| 289 | outNavFile.writeEph(eph);
|
---|
| 290 | }
|
---|
[4004] | 291 | }
|
---|
[3998] | 292 | }
|
---|