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