[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>
|
---|
[75] | 45 |
|
---|
[300] | 46 | #include <QtCore>
|
---|
| 47 | #include <QUrl>
|
---|
| 48 | #include <QString>
|
---|
| 49 |
|
---|
[73] | 50 | #include "bncrinex.h"
|
---|
[157] | 51 | #include "bncapp.h"
|
---|
[82] | 52 | #include "bncutils.h"
|
---|
[126] | 53 | #include "bncconst.h"
|
---|
[298] | 54 | #include "bnctabledlg.h"
|
---|
[301] | 55 | #include "bncgetthread.h"
|
---|
[1858] | 56 | #include "bncnetqueryv2.h"
|
---|
[1535] | 57 | #include "bncsettings.h"
|
---|
[2012] | 58 | #include "bncversion.h"
|
---|
[223] | 59 | #include "RTCM3/rtcm3torinex.h"
|
---|
[75] | 60 |
|
---|
| 61 | using namespace std;
|
---|
| 62 |
|
---|
[73] | 63 | // Constructor
|
---|
| 64 | ////////////////////////////////////////////////////////////////////////////
|
---|
[408] | 65 | bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
|
---|
[366] | 66 | const QByteArray& format, const QByteArray& latitude,
|
---|
[1639] | 67 | const QByteArray& longitude, const QByteArray& nmea,
|
---|
| 68 | const QByteArray& ntripVersion) {
|
---|
[1387] | 69 |
|
---|
[408] | 70 | _statID = statID;
|
---|
[336] | 71 | _mountPoint = mountPoint;
|
---|
[337] | 72 | _format = format.left(6);
|
---|
[366] | 73 | _latitude = latitude;
|
---|
| 74 | _longitude = longitude;
|
---|
| 75 | _nmea = nmea;
|
---|
[1639] | 76 | _ntripVersion = ntripVersion;
|
---|
[77] | 77 | _headerWritten = false;
|
---|
[369] | 78 | _reconnectFlag = false;
|
---|
[656] | 79 | _reloadTable = false;
|
---|
| 80 | _reloadDone = false;
|
---|
[132] | 81 |
|
---|
[1535] | 82 | bncSettings settings;
|
---|
[132] | 83 | _rnxScriptName = settings.value("rnxScript").toString();
|
---|
| 84 | expandEnvVar(_rnxScriptName);
|
---|
[153] | 85 |
|
---|
[2012] | 86 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
[319] | 87 | #ifdef WIN32
|
---|
| 88 | _userName = QString("${USERNAME}");
|
---|
| 89 | #else
|
---|
[158] | 90 | _userName = QString("${USER}");
|
---|
[319] | 91 | #endif
|
---|
[157] | 92 | expandEnvVar(_userName);
|
---|
[158] | 93 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
[539] | 94 |
|
---|
| 95 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
---|
| 96 | _rinexVers = 3;
|
---|
| 97 | }
|
---|
| 98 | else {
|
---|
| 99 | _rinexVers = 2;
|
---|
| 100 | }
|
---|
[1044] | 101 |
|
---|
| 102 | _approxPos[0] = _approxPos[1] = _approxPos[2] = 0.0;
|
---|
[73] | 103 | }
|
---|
| 104 |
|
---|
| 105 | // Destructor
|
---|
| 106 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 107 | bncRinex::~bncRinex() {
|
---|
[622] | 108 | QListIterator<p_obs> it(_obs);
|
---|
[607] | 109 | while (it.hasNext()) {
|
---|
| 110 | delete it.next();
|
---|
| 111 | }
|
---|
[1535] | 112 | bncSettings settings;
|
---|
[698] | 113 | if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
|
---|
[843] | 114 | _out << "> 4 1" << endl;
|
---|
[698] | 115 | _out << "END OF FILE" << endl;
|
---|
| 116 | }
|
---|
[77] | 117 | _out.close();
|
---|
[73] | 118 | }
|
---|
| 119 |
|
---|
[420] | 120 | // Download Skeleton Header File
|
---|
| 121 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 122 | t_irc bncRinex::downloadSkeleton() {
|
---|
| 123 |
|
---|
| 124 | t_irc irc = failure;
|
---|
| 125 |
|
---|
| 126 | QStringList table;
|
---|
| 127 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(),
|
---|
[1376] | 128 | table, _reloadTable);
|
---|
[420] | 129 | QString net;
|
---|
| 130 | QStringListIterator it(table);
|
---|
| 131 | while (it.hasNext()) {
|
---|
| 132 | QString line = it.next();
|
---|
| 133 | if (line.indexOf("STR") == 0) {
|
---|
| 134 | QStringList tags = line.split(";");
|
---|
[1495] | 135 | if (tags.size() > 7) {
|
---|
| 136 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
---|
| 137 | net = tags.at(7);
|
---|
| 138 | break;
|
---|
| 139 | }
|
---|
[420] | 140 | }
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | QString sklDir;
|
---|
[1495] | 144 | if (!net.isEmpty()) {
|
---|
| 145 | it.toFront();
|
---|
| 146 | while (it.hasNext()) {
|
---|
| 147 | QString line = it.next();
|
---|
| 148 | if (line.indexOf("NET") == 0) {
|
---|
| 149 | QStringList tags = line.split(";");
|
---|
| 150 | if (tags.size() > 6) {
|
---|
| 151 | if (tags.at(1) == net) {
|
---|
| 152 | sklDir = tags.at(6).trimmed();
|
---|
| 153 | break;
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
[420] | 157 | }
|
---|
| 158 | }
|
---|
| 159 | if (!sklDir.isEmpty() && sklDir != "none") {
|
---|
| 160 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
---|
| 161 | if (url.port() == -1) {
|
---|
| 162 | url.setPort(80);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[1858] | 165 | bncNetQueryV2 query;
|
---|
[1386] | 166 | QByteArray outData;
|
---|
| 167 | query.waitForRequestResult(url, outData);
|
---|
| 168 | if (query.status() == bncNetQuery::finished) {
|
---|
| 169 | _headerLines.clear();
|
---|
| 170 | bool firstLineRead = false;
|
---|
| 171 | QTextStream in(outData);
|
---|
| 172 | QString line = in.readLine();
|
---|
| 173 | while ( !line.isNull() ) {
|
---|
[1348] | 174 | if (line.indexOf("MARKER NAME") != -1) {
|
---|
| 175 | irc = success;
|
---|
| 176 | }
|
---|
| 177 | if (line.indexOf("RINEX VERSION") != -1) {
|
---|
| 178 | if (_rinexVers == 3) {
|
---|
| 179 | _headerLines.append(" 3.00 OBSERVATION DATA"
|
---|
| 180 | " M (MIXED)"
|
---|
| 181 | " RINEX VERSION / TYPE");
|
---|
[556] | 182 | }
|
---|
[1348] | 183 | else {
|
---|
| 184 | _headerLines.append(" 2.11 OBSERVATION DATA"
|
---|
| 185 | " M (MIXED)"
|
---|
| 186 | " RINEX VERSION / TYPE");
|
---|
[421] | 187 | }
|
---|
[1348] | 188 | _headerLines.append("PGM / RUN BY / DATE");
|
---|
| 189 | firstLineRead = true;
|
---|
| 190 | }
|
---|
| 191 | else if (firstLineRead) {
|
---|
| 192 | if (line.indexOf("END OF HEADER") != -1) {
|
---|
| 193 | _headerLines.append("# / TYPES OF OBSERV");
|
---|
| 194 | if (_rinexVers == 2) {
|
---|
| 195 | _headerLines.append(
|
---|
| 196 | QString(" 1 1").leftJustified(60, ' ', true) +
|
---|
| 197 | "WAVELENGTH FACT L1/2");
|
---|
[421] | 198 | }
|
---|
[1348] | 199 | _headerLines.append("TIME OF FIRST OBS");
|
---|
| 200 | _headerLines.append( line );
|
---|
| 201 | break;
|
---|
[421] | 202 | }
|
---|
[420] | 203 | else {
|
---|
[1348] | 204 | _headerLines.append( line );
|
---|
[420] | 205 | }
|
---|
| 206 | }
|
---|
[1386] | 207 | line = in.readLine();
|
---|
[420] | 208 | }
|
---|
[1386] | 209 | }
|
---|
| 210 | else {
|
---|
| 211 | return failure;
|
---|
[420] | 212 | }
|
---|
[1386] | 213 |
|
---|
[420] | 214 | }
|
---|
| 215 | return irc;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[82] | 218 | // Read Skeleton Header File
|
---|
| 219 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 220 | void bncRinex::readSkeleton() {
|
---|
| 221 |
|
---|
[420] | 222 | // Read the local file
|
---|
| 223 | // -------------------
|
---|
[276] | 224 | QFile skl(_sklName);
|
---|
[82] | 225 | if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
|
---|
[422] | 226 | _headerLines.clear();
|
---|
[82] | 227 | QTextStream in(&skl);
|
---|
| 228 | while ( !in.atEnd() ) {
|
---|
| 229 | _headerLines.append( in.readLine() );
|
---|
| 230 | if (_headerLines.last().indexOf("END OF HEADER") != -1) {
|
---|
| 231 | break;
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
[298] | 235 |
|
---|
[420] | 236 | // Read downloaded file
|
---|
| 237 | // --------------------
|
---|
[2376] | 238 | else if ( _ntripVersion != "N" && _ntripVersion != "UN" &&
|
---|
| 239 | _ntripVersion != "S" ) {
|
---|
[1154] | 240 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
[420] | 241 | if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
|
---|
| 242 | if ( downloadSkeleton() == success) {
|
---|
| 243 | _skeletonDate = currDate;
|
---|
[656] | 244 | _reloadDone = false;
|
---|
[298] | 245 | }
|
---|
[656] | 246 | else {
|
---|
| 247 | if(!_reloadDone) {
|
---|
| 248 | _reloadTable = true;
|
---|
| 249 | if ( downloadSkeleton() == success) {
|
---|
| 250 | _skeletonDate = currDate;
|
---|
| 251 | }
|
---|
| 252 | _reloadTable = false;
|
---|
| 253 | _reloadDone = true;
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
[298] | 256 | }
|
---|
| 257 | }
|
---|
[82] | 258 | }
|
---|
| 259 |
|
---|
[647] | 260 | // Next File Epoch (static)
|
---|
[82] | 261 | ////////////////////////////////////////////////////////////////////////////
|
---|
[647] | 262 | QString bncRinex::nextEpochStr(const QDateTime& datTim,
|
---|
| 263 | const QString& intStr, QDateTime* nextEpoch) {
|
---|
[82] | 264 |
|
---|
[647] | 265 | QString epoStr;
|
---|
[82] | 266 |
|
---|
[129] | 267 | QTime nextTime;
|
---|
| 268 | QDate nextDate;
|
---|
| 269 |
|
---|
[204] | 270 | int indHlp = intStr.indexOf("min");
|
---|
| 271 |
|
---|
| 272 | if ( indHlp != -1) {
|
---|
| 273 | int step = intStr.left(indHlp-1).toInt();
|
---|
[127] | 274 | char ch = 'A' + datTim.time().hour();
|
---|
[647] | 275 | epoStr = ch;
|
---|
[204] | 276 | if (datTim.time().minute() >= 60-step) {
|
---|
[647] | 277 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
|
---|
[199] | 278 | if (datTim.time().hour() < 23) {
|
---|
| 279 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 280 | nextDate = datTim.date();
|
---|
| 281 | }
|
---|
| 282 | else {
|
---|
| 283 | nextTime.setHMS(0, 0, 0);
|
---|
| 284 | nextDate = datTim.date().addDays(1);
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 | else {
|
---|
[204] | 288 | for (int limit = step; limit <= 60-step; limit += step) {
|
---|
| 289 | if (datTim.time().minute() < limit) {
|
---|
[647] | 290 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
|
---|
[204] | 291 | nextTime.setHMS(datTim.time().hour(), limit, 0);
|
---|
| 292 | nextDate = datTim.date();
|
---|
| 293 | break;
|
---|
| 294 | }
|
---|
[199] | 295 | }
|
---|
| 296 | }
|
---|
| 297 | }
|
---|
[127] | 298 | else if (intStr == "1 hour") {
|
---|
| 299 | char ch = 'A' + datTim.time().hour();
|
---|
[647] | 300 | epoStr = ch;
|
---|
[129] | 301 | if (datTim.time().hour() < 23) {
|
---|
| 302 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 303 | nextDate = datTim.date();
|
---|
| 304 | }
|
---|
| 305 | else {
|
---|
| 306 | nextTime.setHMS(0, 0, 0);
|
---|
| 307 | nextDate = datTim.date().addDays(1);
|
---|
| 308 | }
|
---|
[127] | 309 | }
|
---|
| 310 | else {
|
---|
[647] | 311 | epoStr = "0";
|
---|
[129] | 312 | nextTime.setHMS(0, 0, 0);
|
---|
| 313 | nextDate = datTim.date().addDays(1);
|
---|
[127] | 314 | }
|
---|
[82] | 315 |
|
---|
[647] | 316 | if (nextEpoch) {
|
---|
| 317 | *nextEpoch = QDateTime(nextDate, nextTime);
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | return epoStr;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | // File Name according to RINEX Standards
|
---|
| 324 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 325 | void bncRinex::resolveFileName(const QDateTime& datTim) {
|
---|
| 326 |
|
---|
[1535] | 327 | bncSettings settings;
|
---|
[647] | 328 | QString path = settings.value("rnxPath").toString();
|
---|
| 329 | expandEnvVar(path);
|
---|
| 330 |
|
---|
| 331 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
---|
| 332 | path += QDir::separator();
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
|
---|
| 336 | &_nextCloseEpoch);
|
---|
| 337 |
|
---|
[183] | 338 | QString ID4 = _statID.left(4);
|
---|
| 339 |
|
---|
| 340 | // Check name conflict
|
---|
| 341 | // -------------------
|
---|
| 342 | QString distStr;
|
---|
| 343 | int num = 0;
|
---|
| 344 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 345 | while (it.hasNext()) {
|
---|
| 346 | QString mp = it.next();
|
---|
| 347 | if (mp.indexOf(ID4) != -1) {
|
---|
| 348 | ++num;
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | if (num > 1) {
|
---|
| 352 | distStr = "_" + _statID.mid(4);
|
---|
| 353 | }
|
---|
| 354 |
|
---|
[276] | 355 | QString sklExt = settings.value("rnxSkel").toString();
|
---|
| 356 | if (!sklExt.isEmpty()) {
|
---|
| 357 | _sklName = path + ID4 + distStr + "." + sklExt;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[183] | 360 | path += ID4 +
|
---|
[127] | 361 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[276] | 362 | hlpStr + distStr + datTim.toString(".yyO");
|
---|
[82] | 363 |
|
---|
| 364 | _fName = path.toAscii();
|
---|
| 365 | }
|
---|
| 366 |
|
---|
[77] | 367 | // Write RINEX Header
|
---|
| 368 | ////////////////////////////////////////////////////////////////////////////
|
---|
[267] | 369 | void bncRinex::writeHeader(const QDateTime& datTim,
|
---|
| 370 | const QDateTime& datTimNom) {
|
---|
[77] | 371 |
|
---|
[1535] | 372 | bncSettings settings;
|
---|
[356] | 373 |
|
---|
[77] | 374 | // Open the Output File
|
---|
| 375 | // --------------------
|
---|
[267] | 376 | resolveFileName(datTimNom);
|
---|
[260] | 377 |
|
---|
| 378 | // Append to existing file and return
|
---|
| 379 | // ----------------------------------
|
---|
| 380 | if ( QFile::exists(_fName) ) {
|
---|
[369] | 381 | if (_reconnectFlag ||
|
---|
| 382 | Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
[260] | 383 | _out.open(_fName.data(), ios::app);
|
---|
| 384 | _out.setf(ios::showpoint | ios::fixed);
|
---|
| 385 | _headerWritten = true;
|
---|
[369] | 386 | _reconnectFlag = false;
|
---|
[260] | 387 | return;
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
| 390 |
|
---|
[82] | 391 | _out.open(_fName.data());
|
---|
[85] | 392 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[77] | 393 |
|
---|
[82] | 394 | // Copy Skeleton Header
|
---|
| 395 | // --------------------
|
---|
[276] | 396 | readSkeleton();
|
---|
[82] | 397 | if (_headerLines.size() > 0) {
|
---|
| 398 | QStringListIterator it(_headerLines);
|
---|
| 399 | while (it.hasNext()) {
|
---|
| 400 | QString line = it.next();
|
---|
[157] | 401 | if (line.indexOf("PGM / RUN BY / DATE") != -1) {
|
---|
[552] | 402 | if (_rinexVers == 3) {
|
---|
[1154] | 403 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
[552] | 404 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
| 405 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
| 406 | }
|
---|
| 407 | else {
|
---|
[1154] | 408 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[552] | 409 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
| 410 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
| 411 | }
|
---|
[157] | 412 | }
|
---|
| 413 | else if (line.indexOf("# / TYPES OF OBSERV") != -1) {
|
---|
[545] | 414 | if (_rinexVers == 3) {
|
---|
[689] | 415 | // Changed declaration of data types, consistent with Rinex3 Perlt
|
---|
| 416 | _out << "G 10 C1C C1P L1C S1C C2X C2P L2X S2X L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 417 | _out << "R 10 C1C C1P L1C S1C C2C C2P L2C S2C L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 418 | _out << "S 3 C1C L1C S1C SYS / # / OBS TYPES" << endl;
|
---|
[545] | 419 | }
|
---|
| 420 | else {
|
---|
| 421 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2"
|
---|
| 422 | " # / TYPES OF OBSERV" << endl;
|
---|
| 423 | }
|
---|
[82] | 424 | }
|
---|
| 425 | else if (line.indexOf("TIME OF FIRST OBS") != -1) {
|
---|
[125] | 426 | _out << datTim.toString(" yyyy MM dd"
|
---|
| 427 | " hh mm ss.zzz0000").toAscii().data();
|
---|
[553] | 428 | _out << " GPS TIME OF FIRST OBS" << endl;
|
---|
[337] | 429 | QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
---|
| 430 | _mountPoint.path())).leftJustified(60, ' ', true);
|
---|
[156] | 431 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
---|
[82] | 432 | }
|
---|
[689] | 433 | // Added header line for Rinex3 regarding mandatory MARKER TYPE field Perlt
|
---|
| 434 | else if (line.indexOf("MARKER NAME") != -1) {
|
---|
| 435 | if (_rinexVers == 3) {
|
---|
| 436 | _out << line.toAscii().data() << endl;
|
---|
| 437 | _out << setw(71) << "GEODETIC MARKER TYPE" << endl;
|
---|
| 438 | }
|
---|
| 439 | else {
|
---|
| 440 | _out << line.toAscii().data() << endl;
|
---|
| 441 | }
|
---|
| 442 | // End
|
---|
| 443 | }
|
---|
[82] | 444 | else {
|
---|
| 445 | _out << line.toAscii().data() << endl;
|
---|
| 446 | }
|
---|
| 447 | }
|
---|
| 448 | }
|
---|
[78] | 449 |
|
---|
[82] | 450 | // Write Dummy Header
|
---|
| 451 | // ------------------
|
---|
| 452 | else {
|
---|
| 453 | double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
|
---|
| 454 |
|
---|
[545] | 455 | if (_rinexVers == 3) {
|
---|
| 456 | _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
|
---|
[1154] | 457 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
[552] | 458 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
| 459 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
[545] | 460 | }
|
---|
| 461 | else {
|
---|
| 462 | _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
|
---|
[1154] | 463 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[552] | 464 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
| 465 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
[545] | 466 | }
|
---|
[86] | 467 | _out.setf(ios::left);
|
---|
[82] | 468 | _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
|
---|
[689] | 469 | // Added header line for Rinex3 regarding mandatory MARKER TYPE field Perlt
|
---|
| 470 | if (_rinexVers == 3) {
|
---|
| 471 | _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
|
---|
| 472 | }
|
---|
| 473 | // End
|
---|
[354] | 474 | _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
|
---|
[82] | 475 | _out << setw(20) << "unknown"
|
---|
| 476 | << setw(20) << "unknown"
|
---|
| 477 | << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
|
---|
| 478 | _out << setw(20) << "unknown"
|
---|
| 479 | << setw(20) << "unknown"
|
---|
| 480 | << setw(20) << " " << "ANT # / TYPE" << endl;
|
---|
[86] | 481 | _out.unsetf(ios::left);
|
---|
[1044] | 482 | _out << setw(14) << setprecision(4) << _approxPos[0]
|
---|
| 483 | << setw(14) << setprecision(4) << _approxPos[1]
|
---|
| 484 | << setw(14) << setprecision(4) << _approxPos[2]
|
---|
[82] | 485 | << " " << "APPROX POSITION XYZ" << endl;
|
---|
| 486 | _out << setw(14) << setprecision(4) << antennaNEU[0]
|
---|
| 487 | << setw(14) << setprecision(4) << antennaNEU[1]
|
---|
| 488 | << setw(14) << setprecision(4) << antennaNEU[2]
|
---|
| 489 | << " " << "ANTENNA: DELTA H/E/N" << endl;
|
---|
[544] | 490 | if (_rinexVers == 3) {
|
---|
[689] | 491 | // Changed declaration of data types, consistent with Rinex3 Perlt
|
---|
| 492 | _out << "G 10 C1C C1P L1C S1C C2X C2P L2X S2X L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 493 | _out << "R 10 C1C C1P L1C S1C C2C C2P L2C S2C L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 494 | _out << "S 3 C1C L1C S1C SYS / # / OBS TYPES" << endl;
|
---|
[544] | 495 |
|
---|
| 496 | }
|
---|
| 497 | else {
|
---|
| 498 | _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
|
---|
| 499 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2 # / TYPES OF OBSERV" << endl;
|
---|
| 500 | }
|
---|
| 501 | _out << datTim.toString(" yyyy MM dd"
|
---|
[125] | 502 | " hh mm ss.zzz0000").toAscii().data();
|
---|
[553] | 503 | _out << " GPS TIME OF FIRST OBS" << endl;
|
---|
[552] | 504 | QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
---|
[337] | 505 | _mountPoint.path())).leftJustified(60, ' ', true);
|
---|
[156] | 506 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
---|
[366] | 507 |
|
---|
[410] | 508 | if (_nmea == "yes") {
|
---|
| 509 | hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
|
---|
[366] | 510 | _out << hlp.toAscii().data() << "COMMENT" << endl; }
|
---|
| 511 |
|
---|
[82] | 512 | _out << " END OF HEADER" << endl;
|
---|
| 513 | }
|
---|
[78] | 514 |
|
---|
[77] | 515 | _headerWritten = true;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
[73] | 518 | // Stores Observation into Internal Array
|
---|
| 519 | ////////////////////////////////////////////////////////////////////////////
|
---|
[622] | 520 | void bncRinex::deepCopy(const p_obs obs) {
|
---|
| 521 | p_obs newObs = new t_obs();
|
---|
[626] | 522 | memcpy(&newObs->_o, &obs->_o, sizeof(t_obsInternal));
|
---|
[74] | 523 | _obs.push_back(newObs);
|
---|
[73] | 524 | }
|
---|
| 525 |
|
---|
| 526 | // Write One Epoch into the RINEX File
|
---|
| 527 | ////////////////////////////////////////////////////////////////////////////
|
---|
[160] | 528 | void bncRinex::dumpEpoch(long maxTime) {
|
---|
[73] | 529 |
|
---|
[160] | 530 | // Select observations older than maxTime
|
---|
| 531 | // --------------------------------------
|
---|
[622] | 532 | QList<p_obs> dumpList;
|
---|
| 533 | QMutableListIterator<p_obs> mIt(_obs);
|
---|
[160] | 534 | while (mIt.hasNext()) {
|
---|
[622] | 535 | p_obs obs = mIt.next();
|
---|
| 536 | if (obs->_o.GPSWeek * 7*24*3600 + obs->_o.GPSWeeks < maxTime - 0.05) {
|
---|
| 537 | dumpList.push_back(obs);
|
---|
[160] | 538 | mIt.remove();
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
| 541 |
|
---|
[75] | 542 | // Easy Return
|
---|
| 543 | // -----------
|
---|
[160] | 544 | if (dumpList.isEmpty()) {
|
---|
[75] | 545 | return;
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | // Time of Epoch
|
---|
| 549 | // -------------
|
---|
[622] | 550 | p_obs fObs = *dumpList.begin();
|
---|
| 551 | QDateTime datTim = dateAndTimeFromGPSweek(fObs->_o.GPSWeek, fObs->_o.GPSWeeks);
|
---|
| 552 | QDateTime datTimNom = dateAndTimeFromGPSweek(fObs->_o.GPSWeek,
|
---|
| 553 | floor(fObs->_o.GPSWeeks+0.5));
|
---|
[75] | 554 |
|
---|
[130] | 555 | // Close the file
|
---|
| 556 | // --------------
|
---|
[267] | 557 | if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
|
---|
[130] | 558 | closeFile();
|
---|
| 559 | _headerWritten = false;
|
---|
| 560 | }
|
---|
| 561 |
|
---|
[78] | 562 | // Write RINEX Header
|
---|
| 563 | // ------------------
|
---|
| 564 | if (!_headerWritten) {
|
---|
[267] | 565 | writeHeader(datTim, datTimNom);
|
---|
[78] | 566 | }
|
---|
| 567 |
|
---|
[622] | 568 | double sec = double(datTim.time().second()) + fmod(fObs->_o.GPSWeeks,1.0);
|
---|
[75] | 569 |
|
---|
[1044] | 570 | // Epoch header line: RINEX Version 3
|
---|
| 571 | // ----------------------------------
|
---|
[540] | 572 | if (_rinexVers == 3) {
|
---|
| 573 | _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
|
---|
| 574 | << setw(10) << setprecision(7) << sec
|
---|
| 575 | << " " << 0 << setw(3) << dumpList.size() << endl;
|
---|
[74] | 576 | }
|
---|
[1044] | 577 | // Epoch header line: RINEX Version 2
|
---|
| 578 | // ----------------------------------
|
---|
[540] | 579 | else {
|
---|
| 580 | _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
|
---|
| 581 | << setw(10) << setprecision(7) << sec
|
---|
| 582 | << " " << 0 << setw(3) << dumpList.size();
|
---|
[1044] | 583 |
|
---|
[622] | 584 | QListIterator<p_obs> it(dumpList); int iSat = 0;
|
---|
[540] | 585 | while (it.hasNext()) {
|
---|
| 586 | iSat++;
|
---|
[622] | 587 | p_obs obs = it.next();
|
---|
| 588 | _out << obs->_o.satSys << setw(2) << obs->_o.satNum;
|
---|
[540] | 589 | if (iSat == 12 && it.hasNext()) {
|
---|
| 590 | _out << endl << " ";
|
---|
| 591 | iSat = 0;
|
---|
| 592 | }
|
---|
| 593 | }
|
---|
[77] | 594 | _out << endl;
|
---|
[1044] | 595 | }
|
---|
| 596 |
|
---|
| 597 | QListIterator<p_obs> it(dumpList);
|
---|
| 598 | while (it.hasNext()) {
|
---|
| 599 | p_obs obs = it.next();
|
---|
| 600 |
|
---|
| 601 | // Cycle slips detection
|
---|
| 602 | // ---------------------
|
---|
| 603 | int prn = 0;
|
---|
| 604 | switch (obs->_o.satSys) {
|
---|
| 605 | case 'G': prn = obs->_o.satNum; break;
|
---|
| 606 | case 'R': prn = obs->_o.satNum + 200; break;
|
---|
| 607 | default: prn = obs->_o.satNum;
|
---|
| 608 | }
|
---|
| 609 |
|
---|
| 610 | char lli1 = ' ';
|
---|
| 611 | char lli2 = ' ';
|
---|
| 612 | if ( obs->_o.slip_cnt_L1 >= 0 ) {
|
---|
| 613 | if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
|
---|
| 614 | _slip_cnt_L1.find(prn).value() != obs->_o.slip_cnt_L1 ) {
|
---|
| 615 | lli1 = '1';
|
---|
| 616 | }
|
---|
| 617 | }
|
---|
| 618 | else if ( obs->_o.lock_timei_L1 >= 0 ) {
|
---|
| 619 | if ( _lock_timei_L1.find(prn) != _lock_timei_L1.end() &&
|
---|
| 620 | _lock_timei_L1.find(prn).value() != obs->_o.lock_timei_L1 ) {
|
---|
| 621 | lli1 = '1';
|
---|
| 622 | }
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | if ( obs->_o.slip_cnt_L2 >= 0 ) {
|
---|
| 626 | if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
|
---|
| 627 | _slip_cnt_L2.find(prn).value() != obs->_o.slip_cnt_L2 ) {
|
---|
| 628 | lli2 = '1';
|
---|
| 629 | }
|
---|
| 630 | }
|
---|
| 631 | else if ( obs->_o.lock_timei_L2 >= 0 ) {
|
---|
| 632 | if ( _lock_timei_L2.find(prn) != _lock_timei_L2.end() &&
|
---|
| 633 | _lock_timei_L2.find(prn).value() != obs->_o.lock_timei_L2 ) {
|
---|
| 634 | lli2 = '1';
|
---|
| 635 | }
|
---|
| 636 | }
|
---|
| 637 |
|
---|
| 638 | _slip_cnt_L1[prn] = obs->_o.slip_cnt_L1;
|
---|
| 639 | _slip_cnt_L2[prn] = obs->_o.slip_cnt_L2;
|
---|
| 640 |
|
---|
| 641 | _lock_timei_L1[prn] = obs->_o.lock_timei_L1;
|
---|
| 642 | _lock_timei_L2[prn] = obs->_o.lock_timei_L2;
|
---|
| 643 |
|
---|
| 644 | // RINEX Version 3
|
---|
| 645 | // ---------------
|
---|
| 646 | if (_rinexVers == 3) {
|
---|
| 647 | char sbasflag = 'S';
|
---|
| 648 | // Changed data output, C1P, C2C|X, L2C|X, S2C|X added. Changed Output for SBAS Perlt
|
---|
| 649 | if (sbasflag != obs->_o.satSys) {
|
---|
| 650 | _out << obs->_o.satSys
|
---|
| 651 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
---|
| 652 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
---|
| 653 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
---|
| 654 | << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
| 655 | << setw(1) << obs->_o.SNR1
|
---|
| 656 | << setw(14) << setprecision(3) << obs->_o.S1 << " "
|
---|
| 657 | << setw(14) << setprecision(3) << obs->_o.C2 << " "
|
---|
| 658 | << setw(14) << setprecision(3) << obs->_o.P2 << " " ;
|
---|
| 659 | if ((obs->_o.C2 != 0.0) && (obs->_o.P2 == 0.0)) {
|
---|
| 660 | _out << setw(14) << setprecision(3) << obs->_o.L2 << lli2
|
---|
| 661 | << setw(1) << obs->_o.SNR2
|
---|
| 662 | << setw(14) << setprecision(3) << obs->_o.S2 << " "
|
---|
| 663 | << " 0.000 0.000 ";
|
---|
| 664 | }
|
---|
| 665 | else {
|
---|
| 666 | _out << " 0.000 0.000 "
|
---|
| 667 | << setw(14) << setprecision(3) << obs->_o.L2 << " "
|
---|
| 668 | << setw(1) << obs->_o.SNR2
|
---|
| 669 | << setw(14) << setprecision(3) << obs->_o.S2;
|
---|
| 670 | }
|
---|
| 671 | _out << endl;
|
---|
| 672 | }
|
---|
| 673 | else {
|
---|
| 674 | _out << obs->_o.satSys
|
---|
| 675 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
---|
| 676 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
---|
| 677 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
---|
| 678 | << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
| 679 | << setw(1) << obs->_o.SNR1
|
---|
| 680 | << setw(14) << setprecision(3) << obs->_o.S1 << endl;
|
---|
| 681 | }
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | // RINEX Version 2
|
---|
| 685 | // ---------------
|
---|
| 686 | else {
|
---|
[540] | 687 | char lli = ' ';
|
---|
| 688 | char snr = ' ';
|
---|
[622] | 689 | _out << setw(14) << setprecision(3) << obs->_o.C1 << lli << snr;
|
---|
| 690 | _out << setw(14) << setprecision(3) << obs->_o.C2 << lli << snr;
|
---|
| 691 | _out << setw(14) << setprecision(3) << obs->_o.P1 << lli << snr;
|
---|
| 692 | _out << setw(14) << setprecision(3) << obs->_o.P2 << lli << snr;
|
---|
[1044] | 693 | _out << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
[622] | 694 | << setw(1) << obs->_o.SNR1 << endl;
|
---|
[1044] | 695 | _out << setw(14) << setprecision(3) << obs->_o.L2 << lli2
|
---|
[622] | 696 | << setw(1) << obs->_o.SNR2;
|
---|
| 697 | _out << setw(14) << setprecision(3) << obs->_o.S1 ;
|
---|
| 698 | _out << setw(16) << setprecision(3) << obs->_o.S2 ;
|
---|
[540] | 699 | _out << endl;
|
---|
| 700 | }
|
---|
[1044] | 701 |
|
---|
| 702 | delete obs;
|
---|
[75] | 703 | }
|
---|
| 704 |
|
---|
[77] | 705 | _out.flush();
|
---|
[73] | 706 | }
|
---|
| 707 |
|
---|
[130] | 708 | // Close the Old RINEX File
|
---|
| 709 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 710 | void bncRinex::closeFile() {
|
---|
[698] | 711 | if (_rinexVers == 3) {
|
---|
[843] | 712 | _out << "> 4 1" << endl;
|
---|
[698] | 713 | _out << "END OF FILE" << endl;
|
---|
| 714 | }
|
---|
[130] | 715 | _out.close();
|
---|
[132] | 716 | if (!_rnxScriptName.isEmpty()) {
|
---|
[1523] | 717 | qApp->thread()->wait(100);
|
---|
[435] | 718 | #ifdef WIN32
|
---|
| 719 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
---|
| 720 | #else
|
---|
[475] | 721 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
---|
[435] | 722 | #endif
|
---|
[436] | 723 |
|
---|
[132] | 724 | }
|
---|
[130] | 725 | }
|
---|