source: ntrip/trunk/BNC/bncrinex.cpp@ 4041

Last change on this file since 4041 was 3723, checked in by mervart, 13 years ago
File size: 30.5 KB
RevLine 
[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>
[2695]45#include <sstream>
[75]46
[300]47#include <QtCore>
48#include <QUrl>
49#include <QString>
50
[73]51#include "bncrinex.h"
[157]52#include "bncapp.h"
[82]53#include "bncutils.h"
[126]54#include "bncconst.h"
[298]55#include "bnctabledlg.h"
[301]56#include "bncgetthread.h"
[3337]57#include "bncnetqueryv1.h"
[1858]58#include "bncnetqueryv2.h"
[1535]59#include "bncsettings.h"
[2012]60#include "bncversion.h"
[2492]61#include "rtcm3torinex.h"
[75]62
63using namespace std;
64
[73]65// Constructor
66////////////////////////////////////////////////////////////////////////////
[408]67bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
[3525]68 const QByteArray& latitude, const QByteArray& longitude,
69 const QByteArray& nmea, const QByteArray& ntripVersion) {
[1387]70
[408]71 _statID = statID;
[336]72 _mountPoint = mountPoint;
[366]73 _latitude = latitude;
74 _longitude = longitude;
75 _nmea = nmea;
[1639]76 _ntripVersion = ntripVersion;
[77]77 _headerWritten = false;
[369]78 _reconnectFlag = false;
[656]79 _reloadTable = false;
80 _reloadDone = false;
[132]81
[1535]82 bncSettings settings;
[132]83 _rnxScriptName = settings.value("rnxScript").toString();
84 expandEnvVar(_rnxScriptName);
[153]85
[2012]86 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
[319]87#ifdef WIN32
88 _userName = QString("${USERNAME}");
89#else
[158]90 _userName = QString("${USER}");
[319]91#endif
[157]92 expandEnvVar(_userName);
[158]93 _userName = _userName.leftJustified(20, ' ', true);
[539]94
95 if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
96 _rinexVers = 3;
97 }
98 else {
99 _rinexVers = 2;
100 }
[1044]101
102 _approxPos[0] = _approxPos[1] = _approxPos[2] = 0.0;
[3528]103
104 _samplingRate = settings.value("rnxSampl").toInt();
[73]105}
106
107// Destructor
108////////////////////////////////////////////////////////////////////////////
109bncRinex::~bncRinex() {
[1535]110 bncSettings settings;
[698]111 if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
[843]112 _out << "> 4 1" << endl;
[698]113 _out << "END OF FILE" << endl;
114 }
[77]115 _out.close();
[73]116}
117
[420]118// Download Skeleton Header File
119////////////////////////////////////////////////////////////////////////////
120t_irc bncRinex::downloadSkeleton() {
121
122 t_irc irc = failure;
123
124 QStringList table;
[3335]125 bncTableDlg::getFullTable(_ntripVersion, _mountPoint.host(),
126 _mountPoint.port(), table, _reloadTable);
[420]127 QString net;
128 QStringListIterator it(table);
129 while (it.hasNext()) {
130 QString line = it.next();
131 if (line.indexOf("STR") == 0) {
132 QStringList tags = line.split(";");
[1495]133 if (tags.size() > 7) {
134 if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
135 net = tags.at(7);
136 break;
137 }
[420]138 }
139 }
140 }
141 QString sklDir;
[1495]142 if (!net.isEmpty()) {
143 it.toFront();
144 while (it.hasNext()) {
145 QString line = it.next();
146 if (line.indexOf("NET") == 0) {
147 QStringList tags = line.split(";");
148 if (tags.size() > 6) {
149 if (tags.at(1) == net) {
150 sklDir = tags.at(6).trimmed();
151 break;
152 }
153 }
154 }
[420]155 }
156 }
157 if (!sklDir.isEmpty() && sklDir != "none") {
158 QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
159 if (url.port() == -1) {
160 url.setPort(80);
161 }
162
[3337]163 bncNetQuery* query;
164 if (_ntripVersion == "2s") {
165 query = new bncNetQueryV2(true);
166 }
167 else if (_ntripVersion == "2") {
168 query = new bncNetQueryV2(false);
169 }
170 else {
171 query = new bncNetQueryV1;
172 }
173
[1386]174 QByteArray outData;
[3337]175 query->waitForRequestResult(url, outData);
176 if (query->status() == bncNetQuery::finished) {
[1386]177 _headerLines.clear();
178 bool firstLineRead = false;
179 QTextStream in(outData);
180 QString line = in.readLine();
181 while ( !line.isNull() ) {
[1348]182 if (line.indexOf("MARKER NAME") != -1) {
183 irc = success;
184 }
185 if (line.indexOf("RINEX VERSION") != -1) {
186 if (_rinexVers == 3) {
187 _headerLines.append(" 3.00 OBSERVATION DATA"
188 " M (MIXED)"
189 " RINEX VERSION / TYPE");
[556]190 }
[1348]191 else {
192 _headerLines.append(" 2.11 OBSERVATION DATA"
193 " M (MIXED)"
194 " RINEX VERSION / TYPE");
[421]195 }
[1348]196 _headerLines.append("PGM / RUN BY / DATE");
197 firstLineRead = true;
198 }
199 else if (firstLineRead) {
200 if (line.indexOf("END OF HEADER") != -1) {
201 _headerLines.append("# / TYPES OF OBSERV");
202 if (_rinexVers == 2) {
203 _headerLines.append(
204 QString(" 1 1").leftJustified(60, ' ', true) +
205 "WAVELENGTH FACT L1/2");
[421]206 }
[1348]207 _headerLines.append("TIME OF FIRST OBS");
208 _headerLines.append( line );
209 break;
[421]210 }
[420]211 else {
[1348]212 _headerLines.append( line );
[420]213 }
214 }
[1386]215 line = in.readLine();
[420]216 }
[1386]217 }
218 else {
[3337]219 delete query;
[1386]220 return failure;
[420]221 }
[3337]222 delete query;
223 }
[1386]224
[420]225 return irc;
226}
227
[82]228// Read Skeleton Header File
229////////////////////////////////////////////////////////////////////////////
230void bncRinex::readSkeleton() {
231
[420]232 // Read the local file
233 // -------------------
[276]234 QFile skl(_sklName);
[82]235 if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
[422]236 _headerLines.clear();
[82]237 QTextStream in(&skl);
238 while ( !in.atEnd() ) {
239 _headerLines.append( in.readLine() );
240 if (_headerLines.last().indexOf("END OF HEADER") != -1) {
241 break;
242 }
243 }
244 }
[298]245
[420]246 // Read downloaded file
247 // --------------------
[2376]248 else if ( _ntripVersion != "N" && _ntripVersion != "UN" &&
249 _ntripVersion != "S" ) {
[1154]250 QDate currDate = currentDateAndTimeGPS().date();
[420]251 if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
252 if ( downloadSkeleton() == success) {
253 _skeletonDate = currDate;
[656]254 _reloadDone = false;
[298]255 }
[656]256 else {
257 if(!_reloadDone) {
258 _reloadTable = true;
259 if ( downloadSkeleton() == success) {
260 _skeletonDate = currDate;
261 }
262 _reloadTable = false;
263 _reloadDone = true;
264 }
265 }
[298]266 }
267 }
[82]268}
269
[647]270// Next File Epoch (static)
[82]271////////////////////////////////////////////////////////////////////////////
[647]272QString bncRinex::nextEpochStr(const QDateTime& datTim,
273 const QString& intStr, QDateTime* nextEpoch) {
[82]274
[647]275 QString epoStr;
[82]276
[129]277 QTime nextTime;
278 QDate nextDate;
279
[204]280 int indHlp = intStr.indexOf("min");
281
282 if ( indHlp != -1) {
283 int step = intStr.left(indHlp-1).toInt();
[127]284 char ch = 'A' + datTim.time().hour();
[647]285 epoStr = ch;
[204]286 if (datTim.time().minute() >= 60-step) {
[647]287 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
[199]288 if (datTim.time().hour() < 23) {
289 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
290 nextDate = datTim.date();
291 }
292 else {
293 nextTime.setHMS(0, 0, 0);
294 nextDate = datTim.date().addDays(1);
295 }
296 }
297 else {
[204]298 for (int limit = step; limit <= 60-step; limit += step) {
299 if (datTim.time().minute() < limit) {
[647]300 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
[204]301 nextTime.setHMS(datTim.time().hour(), limit, 0);
302 nextDate = datTim.date();
303 break;
304 }
[199]305 }
306 }
307 }
[127]308 else if (intStr == "1 hour") {
309 char ch = 'A' + datTim.time().hour();
[647]310 epoStr = ch;
[129]311 if (datTim.time().hour() < 23) {
312 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
313 nextDate = datTim.date();
314 }
315 else {
316 nextTime.setHMS(0, 0, 0);
317 nextDate = datTim.date().addDays(1);
318 }
[127]319 }
320 else {
[647]321 epoStr = "0";
[129]322 nextTime.setHMS(0, 0, 0);
323 nextDate = datTim.date().addDays(1);
[127]324 }
[82]325
[647]326 if (nextEpoch) {
327 *nextEpoch = QDateTime(nextDate, nextTime);
328 }
329
330 return epoStr;
331}
332
333// File Name according to RINEX Standards
334////////////////////////////////////////////////////////////////////////////
335void bncRinex::resolveFileName(const QDateTime& datTim) {
336
[1535]337 bncSettings settings;
[647]338 QString path = settings.value("rnxPath").toString();
339 expandEnvVar(path);
340
341 if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
342 path += QDir::separator();
343 }
344
345 QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
346 &_nextCloseEpoch);
347
[183]348 QString ID4 = _statID.left(4);
349
350 // Check name conflict
351 // -------------------
352 QString distStr;
353 int num = 0;
354 QListIterator<QString> it(settings.value("mountPoints").toStringList());
355 while (it.hasNext()) {
356 QString mp = it.next();
357 if (mp.indexOf(ID4) != -1) {
358 ++num;
359 }
360 }
361 if (num > 1) {
362 distStr = "_" + _statID.mid(4);
363 }
364
[276]365 QString sklExt = settings.value("rnxSkel").toString();
366 if (!sklExt.isEmpty()) {
367 _sklName = path + ID4 + distStr + "." + sklExt;
368 }
369
[183]370 path += ID4 +
[127]371 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
[276]372 hlpStr + distStr + datTim.toString(".yyO");
[82]373
374 _fName = path.toAscii();
375}
376
[77]377// Write RINEX Header
378////////////////////////////////////////////////////////////////////////////
[3525]379void bncRinex::writeHeader(const QByteArray& format, const QDateTime& datTim,
[267]380 const QDateTime& datTimNom) {
[77]381
[1535]382 bncSettings settings;
[356]383
[77]384 // Open the Output File
385 // --------------------
[267]386 resolveFileName(datTimNom);
[260]387
388 // Append to existing file and return
389 // ----------------------------------
390 if ( QFile::exists(_fName) ) {
[369]391 if (_reconnectFlag ||
392 Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
[260]393 _out.open(_fName.data(), ios::app);
394 _out.setf(ios::showpoint | ios::fixed);
395 _headerWritten = true;
[369]396 _reconnectFlag = false;
[260]397 return;
398 }
399 }
400
[82]401 _out.open(_fName.data());
[85]402 _out.setf(ios::showpoint | ios::fixed);
[77]403
[82]404 // Copy Skeleton Header
405 // --------------------
[276]406 readSkeleton();
[82]407 if (_headerLines.size() > 0) {
[3723]408 bool typesOfObservationsWritten = false;
[82]409 QStringListIterator it(_headerLines);
410 while (it.hasNext()) {
411 QString line = it.next();
[157]412 if (line.indexOf("PGM / RUN BY / DATE") != -1) {
[552]413 if (_rinexVers == 3) {
[1154]414 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[552]415 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
416 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
417 }
418 else {
[1154]419 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[552]420 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
421 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
422 }
[157]423 }
[3723]424 else if ( !typesOfObservationsWritten &&
425 (line.indexOf("# / TYPES OF OBSERV") != -1 ||
426 line.indexOf("SYS / # / OBS TYPES") != -1) ) {
427 typesOfObservationsWritten = true;
[545]428 if (_rinexVers == 3) {
[2703]429 _out << "G 20 C1C L1C D1C S1C C1W L1W D1W S1W C2P L2P D2P S2P C2X SYS / # / OBS TYPES" << endl;
430 _out << " L2X D2X S2X C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
431 _out << "R 16 C1C L1C D1C S1C C1P L1P D1P S1P C2P L2P D2P S2P C2C SYS / # / OBS TYPES" << endl;
432 _out << " L2C D2C S2C SYS / # / OBS TYPES" << endl;
433 _out << "S 8 C1C L1C D1C S1C C1W L1W D1W S1W SYS / # / OBS TYPES" << endl;
434 _out << "E 8 C1 L1 D1 S1 C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
[545]435 }
436 else {
[2690]437 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2"
[545]438 " # / TYPES OF OBSERV" << endl;
439 }
[82]440 }
441 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
[125]442 _out << datTim.toString(" yyyy MM dd"
443 " hh mm ss.zzz0000").toAscii().data();
[553]444 _out << " GPS TIME OF FIRST OBS" << endl;
[3525]445 QString hlp = (format.left(6) + QString(" %1").arg(_mountPoint.host() +
[337]446 _mountPoint.path())).leftJustified(60, ' ', true);
[156]447 _out << hlp.toAscii().data() << "COMMENT" << endl;
[82]448 }
[689]449 else if (line.indexOf("MARKER NAME") != -1) {
450 if (_rinexVers == 3) {
451 _out << line.toAscii().data() << endl;
452 _out << setw(71) << "GEODETIC MARKER TYPE" << endl;
453 }
454 else {
455 _out << line.toAscii().data() << endl;
456 }
457 }
[82]458 else {
459 _out << line.toAscii().data() << endl;
460 }
461 }
462 }
[78]463
[82]464 // Write Dummy Header
465 // ------------------
466 else {
467 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
468
[545]469 if (_rinexVers == 3) {
470 _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
[1154]471 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[552]472 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
473 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
[545]474 }
475 else {
476 _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
[1154]477 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[552]478 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
479 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
[545]480 }
[86]481 _out.setf(ios::left);
[82]482 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
[689]483 if (_rinexVers == 3) {
484 _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
485 }
[354]486 _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
[82]487 _out << setw(20) << "unknown"
488 << setw(20) << "unknown"
489 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
490 _out << setw(20) << "unknown"
491 << setw(20) << "unknown"
492 << setw(20) << " " << "ANT # / TYPE" << endl;
[86]493 _out.unsetf(ios::left);
[1044]494 _out << setw(14) << setprecision(4) << _approxPos[0]
495 << setw(14) << setprecision(4) << _approxPos[1]
496 << setw(14) << setprecision(4) << _approxPos[2]
[82]497 << " " << "APPROX POSITION XYZ" << endl;
498 _out << setw(14) << setprecision(4) << antennaNEU[0]
499 << setw(14) << setprecision(4) << antennaNEU[1]
500 << setw(14) << setprecision(4) << antennaNEU[2]
501 << " " << "ANTENNA: DELTA H/E/N" << endl;
[544]502 if (_rinexVers == 3) {
[2703]503 _out << "G 20 C1C L1C D1C S1C C1W L1W D1W S1W C2P L2P D2P S2P C2X SYS / # / OBS TYPES" << endl;
504 _out << " L2X D2X S2X C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
505 _out << "R 16 C1C L1C D1C S1C C1P L1P D1P S1P C2P L2P D2P S2P C2C SYS / # / OBS TYPES" << endl;
506 _out << " L2C D2C S2C SYS / # / OBS TYPES" << endl;
507 _out << "S 8 C1C L1C D1C S1C C1W L1W D1W S1W SYS / # / OBS TYPES" << endl;
508 _out << "E 8 C1 L1 D1 S1 C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
[544]509 }
510 else {
511 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
[2690]512 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2 # / TYPES OF OBSERV" << endl;
[544]513 }
514 _out << datTim.toString(" yyyy MM dd"
[125]515 " hh mm ss.zzz0000").toAscii().data();
[553]516 _out << " GPS TIME OF FIRST OBS" << endl;
[3525]517 QString hlp = (format.left(6) + QString(" %1").arg(_mountPoint.host() +
[337]518 _mountPoint.path())).leftJustified(60, ' ', true);
[156]519 _out << hlp.toAscii().data() << "COMMENT" << endl;
[366]520
[410]521 if (_nmea == "yes") {
522 hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
[366]523 _out << hlp.toAscii().data() << "COMMENT" << endl; }
524
[82]525 _out << " END OF HEADER" << endl;
526 }
[78]527
[77]528 _headerWritten = true;
529}
530
[73]531// Stores Observation into Internal Array
532////////////////////////////////////////////////////////////////////////////
[2711]533void bncRinex::deepCopy(t_obs obs) {
534 _obs.push_back(obs);
[73]535}
536
537// Write One Epoch into the RINEX File
538////////////////////////////////////////////////////////////////////////////
[3525]539void bncRinex::dumpEpoch(const QByteArray& format, long maxTime) {
[73]540
[160]541 // Select observations older than maxTime
542 // --------------------------------------
[2711]543 QList<t_obs> dumpList;
544 QMutableListIterator<t_obs> mIt(_obs);
[160]545 while (mIt.hasNext()) {
[2711]546 t_obs obs = mIt.next();
547 if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
[622]548 dumpList.push_back(obs);
[160]549 mIt.remove();
550 }
551 }
552
[75]553 // Easy Return
554 // -----------
[160]555 if (dumpList.isEmpty()) {
[75]556 return;
557 }
558
559 // Time of Epoch
560 // -------------
[2711]561 const t_obs& fObs = dumpList.first();
562 QDateTime datTim = dateAndTimeFromGPSweek(fObs.GPSWeek, fObs.GPSWeeks);
563 QDateTime datTimNom = dateAndTimeFromGPSweek(fObs.GPSWeek,
564 floor(fObs.GPSWeeks+0.5));
[75]565
[130]566 // Close the file
567 // --------------
[267]568 if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
[130]569 closeFile();
570 _headerWritten = false;
571 }
572
[78]573 // Write RINEX Header
574 // ------------------
575 if (!_headerWritten) {
[3525]576 writeHeader(format, datTim, datTimNom);
[78]577 }
578
[2711]579 double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
[75]580
[1044]581 // Epoch header line: RINEX Version 3
582 // ----------------------------------
[540]583 if (_rinexVers == 3) {
584 _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
585 << setw(10) << setprecision(7) << sec
586 << " " << 0 << setw(3) << dumpList.size() << endl;
[74]587 }
[1044]588 // Epoch header line: RINEX Version 2
589 // ----------------------------------
[540]590 else {
591 _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
592 << setw(10) << setprecision(7) << sec
593 << " " << 0 << setw(3) << dumpList.size();
[1044]594
[2711]595 QListIterator<t_obs> it(dumpList); int iSat = 0;
[540]596 while (it.hasNext()) {
597 iSat++;
[2711]598 const t_obs& obs = it.next();
599 _out << obs.satSys << setw(2) << obs.satNum;
[540]600 if (iSat == 12 && it.hasNext()) {
601 _out << endl << " ";
602 iSat = 0;
603 }
604 }
[77]605 _out << endl;
[1044]606 }
607
[2711]608 QListIterator<t_obs> it(dumpList);
[1044]609 while (it.hasNext()) {
[2711]610 const t_obs& obs = it.next();
[1044]611
612 // Cycle slips detection
613 // ---------------------
[2711]614 QString prn = QString("%1%2").arg(obs.satSys)
615 .arg(obs.satNum, 2, 10, QChar('0'));
[1044]616
617 char lli1 = ' ';
618 char lli2 = ' ';
[2688]619 char lli5 = ' ';
[2711]620 if ( obs.slip_cnt_L1 >= 0 ) {
[1044]621 if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
[2711]622 _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
[2682]623 lli1 = '1';
[1044]624 }
625 }
626
[2711]627 if ( obs.slip_cnt_L2 >= 0 ) {
[1044]628 if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
[2711]629 _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
[2682]630 lli2 = '1';
[1044]631 }
632 }
633
[2711]634 if ( obs.slip_cnt_L5 >= 0 ) {
[2688]635 if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
[2711]636 _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
[2688]637 lli5 = '1';
638 }
639 }
640
[2711]641 _slip_cnt_L1[prn] = obs.slip_cnt_L1;
642 _slip_cnt_L2[prn] = obs.slip_cnt_L2;
643 _slip_cnt_L5[prn] = obs.slip_cnt_L5;
[1044]644
645 // RINEX Version 3
646 // ---------------
647 if (_rinexVers == 3) {
[3341]648 _out << rinexSatLine(obs, lli1, lli2, lli5);
[2696]649 _out << endl;
[1044]650 }
651
652 // RINEX Version 2
653 // ---------------
654 else {
[2715]655 _out << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
656 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[2711]657 << setw(14) << setprecision(3) << obs.L1() << lli1 << ' '
658 << setw(14) << setprecision(3) << obs.S1() << ' ' << ' '
[2715]659 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' ' << endl
660 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
[2711]661 << setw(14) << setprecision(3) << obs.L2() << lli2 << ' '
[2715]662 << setw(14) << setprecision(3) << obs.S2() << endl;
[540]663 }
[75]664 }
665
[77]666 _out.flush();
[73]667}
668
[130]669// Close the Old RINEX File
670////////////////////////////////////////////////////////////////////////////
671void bncRinex::closeFile() {
[698]672 if (_rinexVers == 3) {
[843]673 _out << "> 4 1" << endl;
[698]674 _out << "END OF FILE" << endl;
675 }
[130]676 _out.close();
[132]677 if (!_rnxScriptName.isEmpty()) {
[1523]678 qApp->thread()->wait(100);
[435]679#ifdef WIN32
680 QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
681#else
[475]682 QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
[435]683#endif
[436]684
[132]685 }
[130]686}
[2695]687
688// One Line in RINEX v3 (static)
689////////////////////////////////////////////////////////////////////////////
[3341]690string bncRinex::rinexSatLine(const t_obs& obs, char lli1, char lli2,
691 char lli5) {
[2695]692 ostringstream str;
693 str.setf(ios::showpoint | ios::fixed);
694
[2711]695 if (obs.satSys == 'G') { // GPS
696 str << obs.satSys
697 << setw(2) << setfill('0') << obs.satNum << setfill(' ')
698 << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[3341]699 << setw(14) << setprecision(3) << obs.L1C
700 << lli1 << ' ';
[2831]701 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]702 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
703 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[3341]704 << setw(14) << setprecision(3) << obs.L1P
705 << lli1 << ' ';
[2831]706 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
[2711]707 << setw(14) << setprecision(3) << obs.S1P << ' ' << ' '
708 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
[3341]709 << setw(14) << setprecision(3) << obs.L2P
710 << lli2 << ' ';
[2831]711 str << setw(14) << setprecision(3) << obs.D2P << ' ' << ' '
[2711]712 << setw(14) << setprecision(3) << obs.S2P << ' ' << ' '
713 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' '
[3341]714 << setw(14) << setprecision(3) << obs.L2C
715 << lli2 << ' ';
[2831]716 str << setw(14) << setprecision(3) << obs.D2C << ' ' << ' '
[2711]717 << setw(14) << setprecision(3) << obs.S2C << ' ' << ' '
718 << setw(14) << setprecision(3) << obs.C5 << ' ' << ' '
[3341]719 << setw(14) << setprecision(3) << obs.L5
720 << lli5 << ' ';
[2831]721 str << setw(14) << setprecision(3) << obs.D5 << ' ' << ' '
[2711]722 << setw(14) << setprecision(3) << obs.S5;
[2695]723 }
[2711]724 else if (obs.satSys == 'R') { // Glonass
725 str << obs.satSys
[2834]726 << setw(2) << setfill('0') << obs.satNum << setfill(' ');
727 str << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[3341]728 << setw(14) << setprecision(3) << obs.L1C
729 << lli1 << ' ';
[2831]730 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]731 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
732 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[3341]733 << setw(14) << setprecision(3) << obs.L1P
734 << lli1 << ' ';
[2831]735 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
[2711]736 << setw(14) << setprecision(3) << obs.S1P << ' ' << ' '
737 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
[3341]738 << setw(14) << setprecision(3) << obs.L2P
739 << lli2 << ' ';
[2831]740 str << setw(14) << setprecision(3) << obs.D2P << ' ' << ' '
[2711]741 << setw(14) << setprecision(3) << obs.S2P << ' ' << ' '
742 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' '
[3341]743 << setw(14) << setprecision(3) << obs.L2C
744 << lli2 << ' ';
[2831]745 str << setw(14) << setprecision(3) << obs.D2C << ' ' << ' '
[2711]746 << setw(14) << setprecision(3) << obs.S2C;
[2695]747 }
[2711]748 else if (obs.satSys == 'S') { // SBAS
749 str << obs.satSys
750 << setw(2) << setfill('0') << obs.satNum << setfill(' ')
751 << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[3341]752 << setw(14) << setprecision(3) << obs.L1C
753 << lli1 << ' ';
[2831]754 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]755 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
756 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[3341]757 << setw(14) << setprecision(3) << obs.L1P
758 << lli1 << ' ';
[2831]759 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
[2711]760 << setw(14) << setprecision(3) << obs.S1P;
[2695]761 }
[2711]762 else if (obs.satSys == 'E') { // Galileo
763 str << obs.satSys
764 << setw(2) << setfill('0') << obs.satNum << setfill(' ')
765 << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[3341]766 << setw(14) << setprecision(3) << obs.L1C
767 << lli1 << ' ';
[2831]768 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]769 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
770 << setw(14) << setprecision(3) << obs.C5 << ' ' << ' '
[3341]771 << setw(14) << setprecision(3) << obs.L5
772 << lli5 << ' ';
[2831]773 str << setw(14) << setprecision(3) << obs.D5 << ' ' << ' '
[2711]774 << setw(14) << setprecision(3) << obs.S5;
[2695]775 }
776 return str.str();
777}
[3324]778
[3344]779//
780////////////////////////////////////////////////////////////////////////////
781string bncRinex::obsToStr(double val, int width, int precision) {
[3326]782 if (val != 0.0) {
783 ostringstream str;
784 str.setf(ios::showpoint | ios::fixed);
[3344]785 str << setw(width) << setprecision(precision) << val;
[3326]786 return str.str();
787 }
788 else {
789 return "0.0";
790 }
791}
792
[3324]793// One Line in ASCII (Internal) Format
794////////////////////////////////////////////////////////////////////////////
795string bncRinex::asciiSatLine(const t_obs& obs) {
796
797 ostringstream str;
798 str.setf(ios::showpoint | ios::fixed);
799
[3325]800 str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
801
[3344]802 if (obs.satSys == 'R') { // Glonass
803 str << ' ' << setw(2) << obs.slotNum;
804 }
805 else {
806 str << " ";
807 }
808
[3324]809 if (obs.satSys == 'G') { // GPS
[3343]810 if (obs.has1C()) {
[3344]811 str << " 1C "
[3343]812 << obsToStr(obs.C1) << ' '
813 << obsToStr(obs.L1C) << ' '
814 << obsToStr(obs.D1C) << ' '
[3344]815 << obsToStr(obs.S1C, 8, 3) << ' '
[3343]816 << setw(2) << obs.slip_cnt_L1;
817 }
818 if (obs.has1P()) {
[3344]819 str << " 1W "
[3343]820 << obsToStr(obs.P1) << ' '
821 << obsToStr(obs.L1P) << ' '
822 << obsToStr(obs.D1P) << ' '
[3344]823 << obsToStr(obs.S1P, 8, 3) << ' '
[3343]824 << setw(2) << obs.slip_cnt_L1;
825 }
826 if (obs.has2P()) {
[3344]827 str << " 2P "
[3343]828 << obsToStr(obs.P2) << ' '
829 << obsToStr(obs.L2P) << ' '
830 << obsToStr(obs.D2P) << ' '
[3344]831 << obsToStr(obs.S2P, 8, 3) << ' '
[3343]832 << setw(2) << obs.slip_cnt_L2;
833 }
834 if (obs.has2C()) {
[3344]835 str << " 2X "
[3343]836 << obsToStr(obs.C2) << ' '
837 << obsToStr(obs.L2C) << ' '
838 << obsToStr(obs.D2C) << ' '
[3344]839 << obsToStr(obs.S2C, 8, 3) << ' '
[3343]840 << setw(2) << obs.slip_cnt_L2;
841 }
842 if (obs.has5C()) {
[3344]843 str << " 5C "
[3343]844 << obsToStr(obs.C5) << ' '
845 << obsToStr(obs.L5) << ' '
846 << obsToStr(obs.D5) << ' '
[3344]847 << obsToStr(obs.S5, 8, 3) << ' '
[3343]848 << setw(2) << obs.slip_cnt_L5;
849 }
[3324]850 }
851 else if (obs.satSys == 'R') { // Glonass
[3343]852 if (obs.has1C()) {
[3344]853 str << " 1C "
[3343]854 << obsToStr(obs.C1) << ' '
855 << obsToStr(obs.L1C) << ' '
856 << obsToStr(obs.D1C) << ' '
[3344]857 << obsToStr(obs.S1C, 8, 3) << ' '
[3343]858 << setw(2) << obs.slip_cnt_L1;
859 }
860 if (obs.has1P()) {
[3344]861 str << " 1P "
[3343]862 << obsToStr(obs.P1) << ' '
863 << obsToStr(obs.L1P) << ' '
864 << obsToStr(obs.D1P) << ' '
[3344]865 << obsToStr(obs.S1P, 8, 3) << ' '
[3343]866 << setw(2) << obs.slip_cnt_L1;
867 }
868 if (obs.has2P()) {
[3344]869 str << " 2P "
[3343]870 << obsToStr(obs.P2) << ' '
871 << obsToStr(obs.L2P) << ' '
872 << obsToStr(obs.D2P) << ' '
[3344]873 << obsToStr(obs.S2P, 8, 3) << ' '
[3343]874 << setw(2) << obs.slip_cnt_L2;
875 }
876 if (obs.has2C()) {
[3344]877 str << " 2C "
[3343]878 << obsToStr(obs.C2) << ' '
879 << obsToStr(obs.L2C) << ' '
880 << obsToStr(obs.D2C) << ' '
[3344]881 << obsToStr(obs.S2C, 8, 3) << ' '
[3343]882 << setw(2) << obs.slip_cnt_L2;
883 }
[3324]884 }
885 else if (obs.satSys == 'S') { // SBAS
[3343]886 if (obs.has1C()) {
[3344]887 str << " 1C "
[3343]888 << obsToStr(obs.C1) << ' '
889 << obsToStr(obs.L1C) << ' '
890 << obsToStr(obs.D1C) << ' '
[3344]891 << obsToStr(obs.S1C, 8, 3) << ' '
[3343]892 << setw(2) << obs.slip_cnt_L1;
893 }
894 if (obs.has1P()) {
[3344]895 str << " 1W "
[3343]896 << obsToStr(obs.P1) << ' '
897 << obsToStr(obs.L1P) << ' '
898 << obsToStr(obs.D1P) << ' '
[3344]899 << obsToStr(obs.S1P, 8, 3) << ' '
[3343]900 << setw(2) << obs.slip_cnt_L1;
901 }
[3324]902 }
903 else if (obs.satSys == 'E') { // Galileo
[3343]904 if (obs.has1C()) {
905 str << " 1C "
906 << obsToStr(obs.C1) << ' '
907 << obsToStr(obs.L1C) << ' '
908 << obsToStr(obs.D1C) << ' '
[3344]909 << obsToStr(obs.S1C, 8, 3) << ' '
[3343]910 << setw(2) << obs.slip_cnt_L1;
911 }
912 if (obs.has5C()) {
[3344]913 str << " 5C "
[3343]914 << obsToStr(obs.C5) << ' '
915 << obsToStr(obs.L5) << ' '
916 << obsToStr(obs.D5) << ' '
[3344]917 << obsToStr(obs.S5, 8, 3) << ' '
[3343]918 << setw(2) << obs.slip_cnt_L5;
919 }
[3324]920 }
921 return str.str();
922}
Note: See TracBrowser for help on using the repository browser.