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

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