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