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