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