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

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