source: ntrip/trunk/BNC/src/bncrinex.cpp@ 4387

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