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

Last change on this file since 3337 was 3337, checked in by mervart, 13 years ago
File size: 30.7 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,
[366]68 const QByteArray& format, const QByteArray& latitude,
[1639]69 const QByteArray& longitude, const QByteArray& nmea,
70 const QByteArray& ntripVersion) {
[1387]71
[408]72 _statID = statID;
[336]73 _mountPoint = mountPoint;
[337]74 _format = format.left(6);
[366]75 _latitude = latitude;
76 _longitude = longitude;
77 _nmea = nmea;
[1639]78 _ntripVersion = ntripVersion;
[77]79 _headerWritten = false;
[369]80 _reconnectFlag = false;
[656]81 _reloadTable = false;
82 _reloadDone = false;
[132]83
[1535]84 bncSettings settings;
[132]85 _rnxScriptName = settings.value("rnxScript").toString();
86 expandEnvVar(_rnxScriptName);
[153]87
[2012]88 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
[319]89#ifdef WIN32
90 _userName = QString("${USERNAME}");
91#else
[158]92 _userName = QString("${USER}");
[319]93#endif
[157]94 expandEnvVar(_userName);
[158]95 _userName = _userName.leftJustified(20, ' ', true);
[539]96
97 if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
98 _rinexVers = 3;
99 }
100 else {
101 _rinexVers = 2;
102 }
[1044]103
104 _approxPos[0] = _approxPos[1] = _approxPos[2] = 0.0;
[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////////////////////////////////////////////////////////////////////////////
[267]379void bncRinex::writeHeader(const QDateTime& datTim,
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) {
408 QStringListIterator it(_headerLines);
409 while (it.hasNext()) {
410 QString line = it.next();
[157]411 if (line.indexOf("PGM / RUN BY / DATE") != -1) {
[552]412 if (_rinexVers == 3) {
[1154]413 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[552]414 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
415 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
416 }
417 else {
[1154]418 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[552]419 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
420 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
421 }
[157]422 }
423 else if (line.indexOf("# / TYPES OF OBSERV") != -1) {
[545]424 if (_rinexVers == 3) {
[2703]425 _out << "G 20 C1C L1C D1C S1C C1W L1W D1W S1W C2P L2P D2P S2P C2X SYS / # / OBS TYPES" << endl;
426 _out << " L2X D2X S2X C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
427 _out << "R 16 C1C L1C D1C S1C C1P L1P D1P S1P C2P L2P D2P S2P C2C SYS / # / OBS TYPES" << endl;
428 _out << " L2C D2C S2C SYS / # / OBS TYPES" << endl;
429 _out << "S 8 C1C L1C D1C S1C C1W L1W D1W S1W SYS / # / OBS TYPES" << endl;
430 _out << "E 8 C1 L1 D1 S1 C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
[545]431 }
432 else {
[2690]433 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2"
[545]434 " # / TYPES OF OBSERV" << endl;
435 }
[82]436 }
437 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
[125]438 _out << datTim.toString(" yyyy MM dd"
439 " hh mm ss.zzz0000").toAscii().data();
[553]440 _out << " GPS TIME OF FIRST OBS" << endl;
[337]441 QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
442 _mountPoint.path())).leftJustified(60, ' ', true);
[156]443 _out << hlp.toAscii().data() << "COMMENT" << endl;
[82]444 }
[689]445 else if (line.indexOf("MARKER NAME") != -1) {
446 if (_rinexVers == 3) {
447 _out << line.toAscii().data() << endl;
448 _out << setw(71) << "GEODETIC MARKER TYPE" << endl;
449 }
450 else {
451 _out << line.toAscii().data() << endl;
452 }
453 }
[82]454 else {
455 _out << line.toAscii().data() << endl;
456 }
457 }
458 }
[78]459
[82]460 // Write Dummy Header
461 // ------------------
462 else {
463 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
464
[545]465 if (_rinexVers == 3) {
466 _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
[1154]467 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[552]468 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
469 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
[545]470 }
471 else {
472 _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
[1154]473 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[552]474 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
475 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
[545]476 }
[86]477 _out.setf(ios::left);
[82]478 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
[689]479 if (_rinexVers == 3) {
480 _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
481 }
[354]482 _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
[82]483 _out << setw(20) << "unknown"
484 << setw(20) << "unknown"
485 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
486 _out << setw(20) << "unknown"
487 << setw(20) << "unknown"
488 << setw(20) << " " << "ANT # / TYPE" << endl;
[86]489 _out.unsetf(ios::left);
[1044]490 _out << setw(14) << setprecision(4) << _approxPos[0]
491 << setw(14) << setprecision(4) << _approxPos[1]
492 << setw(14) << setprecision(4) << _approxPos[2]
[82]493 << " " << "APPROX POSITION XYZ" << endl;
494 _out << setw(14) << setprecision(4) << antennaNEU[0]
495 << setw(14) << setprecision(4) << antennaNEU[1]
496 << setw(14) << setprecision(4) << antennaNEU[2]
497 << " " << "ANTENNA: DELTA H/E/N" << endl;
[544]498 if (_rinexVers == 3) {
[2703]499 _out << "G 20 C1C L1C D1C S1C C1W L1W D1W S1W C2P L2P D2P S2P C2X SYS / # / OBS TYPES" << endl;
500 _out << " L2X D2X S2X C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
501 _out << "R 16 C1C L1C D1C S1C C1P L1P D1P S1P C2P L2P D2P S2P C2C SYS / # / OBS TYPES" << endl;
502 _out << " L2C D2C S2C SYS / # / OBS TYPES" << endl;
503 _out << "S 8 C1C L1C D1C S1C C1W L1W D1W S1W SYS / # / OBS TYPES" << endl;
504 _out << "E 8 C1 L1 D1 S1 C5 L5 D5 S5 SYS / # / OBS TYPES" << endl;
[544]505 }
506 else {
507 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
[2690]508 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2 # / TYPES OF OBSERV" << endl;
[544]509 }
510 _out << datTim.toString(" yyyy MM dd"
[125]511 " hh mm ss.zzz0000").toAscii().data();
[553]512 _out << " GPS TIME OF FIRST OBS" << endl;
[552]513 QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
[337]514 _mountPoint.path())).leftJustified(60, ' ', true);
[156]515 _out << hlp.toAscii().data() << "COMMENT" << endl;
[366]516
[410]517 if (_nmea == "yes") {
518 hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
[366]519 _out << hlp.toAscii().data() << "COMMENT" << endl; }
520
[82]521 _out << " END OF HEADER" << endl;
522 }
[78]523
[77]524 _headerWritten = true;
525}
526
[73]527// Stores Observation into Internal Array
528////////////////////////////////////////////////////////////////////////////
[2711]529void bncRinex::deepCopy(t_obs obs) {
530 _obs.push_back(obs);
[73]531}
532
533// Write One Epoch into the RINEX File
534////////////////////////////////////////////////////////////////////////////
[160]535void bncRinex::dumpEpoch(long maxTime) {
[73]536
[160]537 // Select observations older than maxTime
538 // --------------------------------------
[2711]539 QList<t_obs> dumpList;
540 QMutableListIterator<t_obs> mIt(_obs);
[160]541 while (mIt.hasNext()) {
[2711]542 t_obs obs = mIt.next();
543 if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
[622]544 dumpList.push_back(obs);
[160]545 mIt.remove();
546 }
547 }
548
[75]549 // Easy Return
550 // -----------
[160]551 if (dumpList.isEmpty()) {
[75]552 return;
553 }
554
555 // Time of Epoch
556 // -------------
[2711]557 const t_obs& fObs = dumpList.first();
558 QDateTime datTim = dateAndTimeFromGPSweek(fObs.GPSWeek, fObs.GPSWeeks);
559 QDateTime datTimNom = dateAndTimeFromGPSweek(fObs.GPSWeek,
560 floor(fObs.GPSWeeks+0.5));
[75]561
[130]562 // Close the file
563 // --------------
[267]564 if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
[130]565 closeFile();
566 _headerWritten = false;
567 }
568
[78]569 // Write RINEX Header
570 // ------------------
571 if (!_headerWritten) {
[267]572 writeHeader(datTim, datTimNom);
[78]573 }
574
[2711]575 double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
[75]576
[1044]577 // Epoch header line: RINEX Version 3
578 // ----------------------------------
[540]579 if (_rinexVers == 3) {
580 _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
581 << setw(10) << setprecision(7) << sec
582 << " " << 0 << setw(3) << dumpList.size() << endl;
[74]583 }
[1044]584 // Epoch header line: RINEX Version 2
585 // ----------------------------------
[540]586 else {
587 _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
588 << setw(10) << setprecision(7) << sec
589 << " " << 0 << setw(3) << dumpList.size();
[1044]590
[2711]591 QListIterator<t_obs> it(dumpList); int iSat = 0;
[540]592 while (it.hasNext()) {
593 iSat++;
[2711]594 const t_obs& obs = it.next();
595 _out << obs.satSys << setw(2) << obs.satNum;
[540]596 if (iSat == 12 && it.hasNext()) {
597 _out << endl << " ";
598 iSat = 0;
599 }
600 }
[77]601 _out << endl;
[1044]602 }
603
[2711]604 QListIterator<t_obs> it(dumpList);
[1044]605 while (it.hasNext()) {
[2711]606 const t_obs& obs = it.next();
[1044]607
608 // Cycle slips detection
609 // ---------------------
[2711]610 QString prn = QString("%1%2").arg(obs.satSys)
611 .arg(obs.satNum, 2, 10, QChar('0'));
[1044]612
613 char lli1 = ' ';
614 char lli2 = ' ';
[2688]615 char lli5 = ' ';
[2711]616 if ( obs.slip_cnt_L1 >= 0 ) {
[1044]617 if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
[2711]618 _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
[2682]619 lli1 = '1';
[1044]620 }
621 }
622
[2711]623 if ( obs.slip_cnt_L2 >= 0 ) {
[1044]624 if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
[2711]625 _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
[2682]626 lli2 = '1';
[1044]627 }
628 }
629
[2711]630 if ( obs.slip_cnt_L5 >= 0 ) {
[2688]631 if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
[2711]632 _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
[2688]633 lli5 = '1';
634 }
635 }
636
[2711]637 _slip_cnt_L1[prn] = obs.slip_cnt_L1;
638 _slip_cnt_L2[prn] = obs.slip_cnt_L2;
639 _slip_cnt_L5[prn] = obs.slip_cnt_L5;
[1044]640
641 // RINEX Version 3
642 // ---------------
643 if (_rinexVers == 3) {
[2831]644 _out << rinexSatLine(obs, true, lli1, lli2, lli5);
[2696]645 _out << endl;
[1044]646 }
647
648 // RINEX Version 2
649 // ---------------
650 else {
[2715]651 _out << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
652 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[2711]653 << setw(14) << setprecision(3) << obs.L1() << lli1 << ' '
654 << setw(14) << setprecision(3) << obs.S1() << ' ' << ' '
[2715]655 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' ' << endl
656 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
[2711]657 << setw(14) << setprecision(3) << obs.L2() << lli2 << ' '
[2715]658 << setw(14) << setprecision(3) << obs.S2() << endl;
[540]659 }
[75]660 }
661
[77]662 _out.flush();
[73]663}
664
[130]665// Close the Old RINEX File
666////////////////////////////////////////////////////////////////////////////
667void bncRinex::closeFile() {
[698]668 if (_rinexVers == 3) {
[843]669 _out << "> 4 1" << endl;
[698]670 _out << "END OF FILE" << endl;
671 }
[130]672 _out.close();
[132]673 if (!_rnxScriptName.isEmpty()) {
[1523]674 qApp->thread()->wait(100);
[435]675#ifdef WIN32
676 QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
677#else
[475]678 QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
[435]679#endif
[436]680
[132]681 }
[130]682}
[2695]683
684// One Line in RINEX v3 (static)
685////////////////////////////////////////////////////////////////////////////
[2831]686string bncRinex::rinexSatLine(const t_obs& obs, bool usells,
[2695]687 char lli1, char lli2, char lli5) {
688 ostringstream str;
689 str.setf(ios::showpoint | ios::fixed);
690
[2711]691 if (obs.satSys == 'G') { // GPS
692 str << obs.satSys
693 << setw(2) << setfill('0') << obs.satNum << setfill(' ')
694 << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[2831]695 << setw(14) << setprecision(3) << obs.L1C;
696 if (usells) {
697 str << lli1 << ' ';
698 }
699 else {
700 str << ' ' << obs.slip_cnt_L1 << ' ';
701 }
702 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]703 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
704 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[2831]705 << setw(14) << setprecision(3) << obs.L1P;
706 if (usells) {
707 str << lli1 << ' ';
708 }
709 else {
710 str << ' ' << obs.slip_cnt_L1 << ' ';
711 }
712 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
[2711]713 << setw(14) << setprecision(3) << obs.S1P << ' ' << ' '
714 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
[2831]715 << setw(14) << setprecision(3) << obs.L2P;
716 if (usells) {
717 str << lli2 << ' ';
718 }
719 else {
720 str << ' ' << obs.slip_cnt_L2 << ' ';
721 }
722 str << setw(14) << setprecision(3) << obs.D2P << ' ' << ' '
[2711]723 << setw(14) << setprecision(3) << obs.S2P << ' ' << ' '
724 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' '
[2831]725 << setw(14) << setprecision(3) << obs.L2C;
726 if (usells) {
727 str << lli2 << ' ';
728 }
729 else {
730 str << ' ' << obs.slip_cnt_L2 << ' ';
731 }
732 str << setw(14) << setprecision(3) << obs.D2C << ' ' << ' '
[2711]733 << setw(14) << setprecision(3) << obs.S2C << ' ' << ' '
734 << setw(14) << setprecision(3) << obs.C5 << ' ' << ' '
[2831]735 << setw(14) << setprecision(3) << obs.L5;
736 if (usells) {
737 str << lli5 << ' ';
738 }
739 else {
740 str << ' ' << obs.slip_cnt_L5 << ' ';
741 }
742 str << setw(14) << setprecision(3) << obs.D5 << ' ' << ' '
[2711]743 << setw(14) << setprecision(3) << obs.S5;
[2695]744 }
[2711]745 else if (obs.satSys == 'R') { // Glonass
746 str << obs.satSys
[2834]747 << setw(2) << setfill('0') << obs.satNum << setfill(' ');
748 if (!usells) {
749 str << ' ' << obs.slotNum << ' ';
750 }
751
752 str << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[2831]753 << setw(14) << setprecision(3) << obs.L1C;
754 if (usells) {
755 str << lli1 << ' ';
756 }
757 else {
758 str << ' ' << obs.slip_cnt_L1 << ' ';
759 }
760 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]761 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
762 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[2831]763 << setw(14) << setprecision(3) << obs.L1P;
764 if (usells) {
765 str << lli1 << ' ';
766 }
767 else {
768 str << ' ' << obs.slip_cnt_L1 << ' ';
769 }
770 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
[2711]771 << setw(14) << setprecision(3) << obs.S1P << ' ' << ' '
772 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
[2831]773 << setw(14) << setprecision(3) << obs.L2P;
774 if (usells) {
775 str << lli2 << ' ';
776 }
777 else {
778 str << ' ' << obs.slip_cnt_L2 << ' ';
779 }
780 str << setw(14) << setprecision(3) << obs.D2P << ' ' << ' '
[2711]781 << setw(14) << setprecision(3) << obs.S2P << ' ' << ' '
782 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' '
[2831]783 << setw(14) << setprecision(3) << obs.L2C;
784 if (usells) {
785 str << lli2 << ' ';
786 }
787 else {
788 str << ' ' << obs.slip_cnt_L2 << ' ';
789 }
790 str << setw(14) << setprecision(3) << obs.D2C << ' ' << ' '
[2711]791 << setw(14) << setprecision(3) << obs.S2C;
[2695]792 }
[2711]793 else if (obs.satSys == 'S') { // SBAS
794 str << obs.satSys
795 << setw(2) << setfill('0') << obs.satNum << setfill(' ')
796 << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[2831]797 << setw(14) << setprecision(3) << obs.L1C;
798 if (usells) {
799 str << lli1 << ' ';
800 }
801 else {
802 str << ' ' << obs.slip_cnt_L1 << ' ';
803 }
804 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]805 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
806 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
[2831]807 << setw(14) << setprecision(3) << obs.L1P;
808 if (usells) {
809 str << lli1 << ' ';
810 }
811 else {
812 str << ' ' << obs.slip_cnt_L1 << ' ';
813 }
814 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
[2711]815 << setw(14) << setprecision(3) << obs.S1P;
[2695]816 }
[2711]817 else if (obs.satSys == 'E') { // Galileo
818 str << obs.satSys
819 << setw(2) << setfill('0') << obs.satNum << setfill(' ')
820 << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
[2831]821 << setw(14) << setprecision(3) << obs.L1C;
822 if (usells) {
823 str << lli1 << ' ';
824 }
825 else {
826 str << ' ' << obs.slip_cnt_L1 << ' ';
827 }
828 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
[2711]829 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
830 << setw(14) << setprecision(3) << obs.C5 << ' ' << ' '
[2831]831 << setw(14) << setprecision(3) << obs.L5;
832 if (usells) {
833 str << lli5 << ' ';
834 }
835 else {
836 str << ' ' << obs.slip_cnt_L5 << ' ';
837 }
838 str << setw(14) << setprecision(3) << obs.D5 << ' ' << ' '
[2711]839 << setw(14) << setprecision(3) << obs.S5;
[2695]840 }
841 return str.str();
842}
[3324]843
[3326]844string obsToStr(double val) {
845 if (val != 0.0) {
846 ostringstream str;
847 str.setf(ios::showpoint | ios::fixed);
848 str << setw(14) << setprecision(3) << val;
849 return str.str();
850 }
851 else {
852 return "0.0";
853 }
854}
855
[3324]856// One Line in ASCII (Internal) Format
857////////////////////////////////////////////////////////////////////////////
858string bncRinex::asciiSatLine(const t_obs& obs) {
859
860 ostringstream str;
861 str.setf(ios::showpoint | ios::fixed);
862
[3325]863 str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
864
[3324]865 if (obs.satSys == 'G') { // GPS
[3326]866 str << " 1C "
867 << obsToStr(obs.C1) << ' '
868 << obsToStr(obs.L1C) << ' '
869 << obsToStr(obs.D1C) << ' '
870 << obsToStr(obs.S1C) << ' '
[3325]871 << setw(2) << obs.slip_cnt_L1;
872 str << " 1W "
[3326]873 << obsToStr(obs.P1) << ' '
874 << obsToStr(obs.L1P) << ' '
875 << obsToStr(obs.D1P) << ' '
876 << obsToStr(obs.S1P) << ' '
[3325]877 << setw(2) << obs.slip_cnt_L1;
878 str << " 2P "
[3326]879 << obsToStr(obs.P2) << ' '
880 << obsToStr(obs.L2P) << ' '
881 << obsToStr(obs.D2P) << ' '
882 << obsToStr(obs.S2P) << ' '
[3325]883 << setw(2) << obs.slip_cnt_L2;
884 str << " 2X "
[3326]885 << obsToStr(obs.C2) << ' '
886 << obsToStr(obs.L2C) << ' '
887 << obsToStr(obs.D2C) << ' '
888 << obsToStr(obs.S2C) << ' '
[3325]889 << setw(2) << obs.slip_cnt_L2;
[3326]890 str << " 5C "
891 << obsToStr(obs.C5) << ' '
892 << obsToStr(obs.L5) << ' '
893 << obsToStr(obs.D5) << ' '
894 << obsToStr(obs.S5) << ' '
[3325]895 << setw(2) << obs.slip_cnt_L5;
[3324]896 }
897 else if (obs.satSys == 'R') { // Glonass
[3326]898 str << ' ' << setw(2) << obs.slotNum;
[3325]899 str << " 1C "
[3326]900 << obsToStr(obs.C1) << ' '
901 << obsToStr(obs.L1C) << ' '
902 << obsToStr(obs.D1C) << ' '
903 << obsToStr(obs.S1C) << ' '
[3325]904 << setw(2) << obs.slip_cnt_L1;
905 str << " 1P "
[3326]906 << obsToStr(obs.P1) << ' '
907 << obsToStr(obs.L1P) << ' '
908 << obsToStr(obs.D1P) << ' '
909 << obsToStr(obs.S1P) << ' '
[3325]910 << setw(2) << obs.slip_cnt_L1;
911 str << " 2P "
[3326]912 << obsToStr(obs.P2) << ' '
913 << obsToStr(obs.L2P) << ' '
914 << obsToStr(obs.D2P) << ' '
915 << obsToStr(obs.S2P) << ' '
[3325]916 << setw(2) << obs.slip_cnt_L2;
917 str << " 2C "
[3326]918 << obsToStr(obs.C2) << ' '
919 << obsToStr(obs.L2C) << ' '
920 << obsToStr(obs.D2C) << ' '
921 << obsToStr(obs.S2C) << ' '
[3325]922 << setw(2) << obs.slip_cnt_L2;
[3324]923 }
924 else if (obs.satSys == 'S') { // SBAS
[3325]925 str << " 1C "
[3326]926 << obsToStr(obs.C1) << ' '
927 << obsToStr(obs.L1C) << ' '
928 << obsToStr(obs.D1C) << ' '
929 << obsToStr(obs.S1C) << ' '
[3325]930 << setw(2) << obs.slip_cnt_L1;
931 str << " 1W "
[3326]932 << obsToStr(obs.P1) << ' '
933 << obsToStr(obs.L1P) << ' '
934 << obsToStr(obs.D1P) << ' '
935 << obsToStr(obs.S1P) << ' '
[3325]936 << setw(2) << obs.slip_cnt_L1;
[3324]937 }
938 else if (obs.satSys == 'E') { // Galileo
[3325]939 str << " 1C "
[3326]940 << obsToStr(obs.C1) << ' '
941 << obsToStr(obs.L1C) << ' '
942 << obsToStr(obs.D1C) << ' '
943 << obsToStr(obs.S1C) << ' '
[3325]944 << setw(2) << obs.slip_cnt_L1;
[3326]945 str << " 5C "
946 << obsToStr(obs.C5) << ' '
947 << obsToStr(obs.L5) << ' '
948 << obsToStr(obs.D5) << ' '
949 << obsToStr(obs.S5) << ' '
[3325]950 << setw(2) << obs.slip_cnt_L5;
[3324]951 }
952 return str.str();
953}
Note: See TracBrowser for help on using the repository browser.