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
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
105// Destructor
106////////////////////////////////////////////////////////////////////////////
107bncRinex::~bncRinex() {
108 bncSettings settings;
109 if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
110 _out << "> 4 1" << endl;
111 _out << "END OF FILE" << endl;
112 }
113 _out.close();
114}
115
116// Download Skeleton Header File
117////////////////////////////////////////////////////////////////////////////
118t_irc bncRinex::downloadSkeleton() {
119
120 t_irc irc = failure;
121
122 QStringList table;
123 bncTableDlg::getFullTable(_ntripVersion, _mountPoint.host(),
124 _mountPoint.port(), table, _reloadTable);
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(";");
131 if (tags.size() > 7) {
132 if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
133 net = tags.at(7);
134 break;
135 }
136 }
137 }
138 }
139 QString sklDir;
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 }
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
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
172 QByteArray outData;
173 query->waitForRequestResult(url, outData);
174 if (query->status() == bncNetQuery::finished) {
175 _headerLines.clear();
176 bool firstLineRead = false;
177 QTextStream in(outData);
178 QString line = in.readLine();
179 while ( !line.isNull() ) {
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");
188 }
189 else {
190 _headerLines.append(" 2.11 OBSERVATION DATA"
191 " M (MIXED)"
192 " RINEX VERSION / TYPE");
193 }
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");
204 }
205 _headerLines.append("TIME OF FIRST OBS");
206 _headerLines.append( line );
207 break;
208 }
209 else {
210 _headerLines.append( line );
211 }
212 }
213 line = in.readLine();
214 }
215 }
216 else {
217 delete query;
218 return failure;
219 }
220 delete query;
221 }
222
223 return irc;
224}
225
226// Read Skeleton Header File
227////////////////////////////////////////////////////////////////////////////
228void bncRinex::readSkeleton() {
229
230 // Read the local file
231 // -------------------
232 QFile skl(_sklName);
233 if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
234 _headerLines.clear();
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 }
243
244 // Read downloaded file
245 // --------------------
246 else if ( _ntripVersion != "N" && _ntripVersion != "UN" &&
247 _ntripVersion != "S" ) {
248 QDate currDate = currentDateAndTimeGPS().date();
249 if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
250 if ( downloadSkeleton() == success) {
251 _skeletonDate = currDate;
252 _reloadDone = false;
253 }
254 else {
255 if(!_reloadDone) {
256 _reloadTable = true;
257 if ( downloadSkeleton() == success) {
258 _skeletonDate = currDate;
259 }
260 _reloadTable = false;
261 _reloadDone = true;
262 }
263 }
264 }
265 }
266}
267
268// Next File Epoch (static)
269////////////////////////////////////////////////////////////////////////////
270QString bncRinex::nextEpochStr(const QDateTime& datTim,
271 const QString& intStr, QDateTime* nextEpoch) {
272
273 QString epoStr;
274
275 QTime nextTime;
276 QDate nextDate;
277
278 int indHlp = intStr.indexOf("min");
279
280 if ( indHlp != -1) {
281 int step = intStr.left(indHlp-1).toInt();
282 char ch = 'A' + datTim.time().hour();
283 epoStr = ch;
284 if (datTim.time().minute() >= 60-step) {
285 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
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 {
296 for (int limit = step; limit <= 60-step; limit += step) {
297 if (datTim.time().minute() < limit) {
298 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
299 nextTime.setHMS(datTim.time().hour(), limit, 0);
300 nextDate = datTim.date();
301 break;
302 }
303 }
304 }
305 }
306 else if (intStr == "1 hour") {
307 char ch = 'A' + datTim.time().hour();
308 epoStr = ch;
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 }
317 }
318 else {
319 epoStr = "0";
320 nextTime.setHMS(0, 0, 0);
321 nextDate = datTim.date().addDays(1);
322 }
323
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
335 bncSettings settings;
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
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
363 QString sklExt = settings.value("rnxSkel").toString();
364 if (!sklExt.isEmpty()) {
365 _sklName = path + ID4 + distStr + "." + sklExt;
366 }
367
368 path += ID4 +
369 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
370 hlpStr + distStr + datTim.toString(".yyO");
371
372 _fName = path.toAscii();
373}
374
375// Write RINEX Header
376////////////////////////////////////////////////////////////////////////////
377void bncRinex::writeHeader(const QByteArray& format, const QDateTime& datTim,
378 const QDateTime& datTimNom) {
379
380 bncSettings settings;
381
382 // Open the Output File
383 // --------------------
384 resolveFileName(datTimNom);
385
386 // Append to existing file and return
387 // ----------------------------------
388 if ( QFile::exists(_fName) ) {
389 if (_reconnectFlag ||
390 Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
391 _out.open(_fName.data(), ios::app);
392 _out.setf(ios::showpoint | ios::fixed);
393 _headerWritten = true;
394 _reconnectFlag = false;
395 return;
396 }
397 }
398
399 _out.open(_fName.data());
400 _out.setf(ios::showpoint | ios::fixed);
401
402 // Copy Skeleton Header
403 // --------------------
404 readSkeleton();
405 if (_headerLines.size() > 0) {
406 QStringListIterator it(_headerLines);
407 while (it.hasNext()) {
408 QString line = it.next();
409 if (line.indexOf("PGM / RUN BY / DATE") != -1) {
410 if (_rinexVers == 3) {
411 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
412 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
413 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
414 }
415 else {
416 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
417 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
418 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
419 }
420 }
421 else if (line.indexOf("# / TYPES OF OBSERV") != -1) {
422 if (_rinexVers == 3) {
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;
429 }
430 else {
431 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2"
432 " # / TYPES OF OBSERV" << endl;
433 }
434 }
435 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
436 _out << datTim.toString(" yyyy MM dd"
437 " hh mm ss.zzz0000").toAscii().data();
438 _out << " GPS TIME OF FIRST OBS" << endl;
439 QString hlp = (format.left(6) + QString(" %1").arg(_mountPoint.host() +
440 _mountPoint.path())).leftJustified(60, ' ', true);
441 _out << hlp.toAscii().data() << "COMMENT" << endl;
442 }
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 }
452 else {
453 _out << line.toAscii().data() << endl;
454 }
455 }
456 }
457
458 // Write Dummy Header
459 // ------------------
460 else {
461 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
462
463 if (_rinexVers == 3) {
464 _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
465 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
466 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
467 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
468 }
469 else {
470 _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
471 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
472 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
473 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
474 }
475 _out.setf(ios::left);
476 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
477 if (_rinexVers == 3) {
478 _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
479 }
480 _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
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;
487 _out.unsetf(ios::left);
488 _out << setw(14) << setprecision(4) << _approxPos[0]
489 << setw(14) << setprecision(4) << _approxPos[1]
490 << setw(14) << setprecision(4) << _approxPos[2]
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;
496 if (_rinexVers == 3) {
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;
503 }
504 else {
505 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
506 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2 # / TYPES OF OBSERV" << endl;
507 }
508 _out << datTim.toString(" yyyy MM dd"
509 " hh mm ss.zzz0000").toAscii().data();
510 _out << " GPS TIME OF FIRST OBS" << endl;
511 QString hlp = (format.left(6) + QString(" %1").arg(_mountPoint.host() +
512 _mountPoint.path())).leftJustified(60, ' ', true);
513 _out << hlp.toAscii().data() << "COMMENT" << endl;
514
515 if (_nmea == "yes") {
516 hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
517 _out << hlp.toAscii().data() << "COMMENT" << endl; }
518
519 _out << " END OF HEADER" << endl;
520 }
521
522 _headerWritten = true;
523}
524
525// Stores Observation into Internal Array
526////////////////////////////////////////////////////////////////////////////
527void bncRinex::deepCopy(t_obs obs) {
528 _obs.push_back(obs);
529}
530
531// Write One Epoch into the RINEX File
532////////////////////////////////////////////////////////////////////////////
533void bncRinex::dumpEpoch(const QByteArray& format, long maxTime) {
534
535 // Select observations older than maxTime
536 // --------------------------------------
537 QList<t_obs> dumpList;
538 QMutableListIterator<t_obs> mIt(_obs);
539 while (mIt.hasNext()) {
540 t_obs obs = mIt.next();
541 if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
542 dumpList.push_back(obs);
543 mIt.remove();
544 }
545 }
546
547 // Easy Return
548 // -----------
549 if (dumpList.isEmpty()) {
550 return;
551 }
552
553 // Time of Epoch
554 // -------------
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));
559
560 // Close the file
561 // --------------
562 if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
563 closeFile();
564 _headerWritten = false;
565 }
566
567 // Write RINEX Header
568 // ------------------
569 if (!_headerWritten) {
570 writeHeader(format, datTim, datTimNom);
571 }
572
573 double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
574
575 // Epoch header line: RINEX Version 3
576 // ----------------------------------
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;
581 }
582 // Epoch header line: RINEX Version 2
583 // ----------------------------------
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();
588
589 QListIterator<t_obs> it(dumpList); int iSat = 0;
590 while (it.hasNext()) {
591 iSat++;
592 const t_obs& obs = it.next();
593 _out << obs.satSys << setw(2) << obs.satNum;
594 if (iSat == 12 && it.hasNext()) {
595 _out << endl << " ";
596 iSat = 0;
597 }
598 }
599 _out << endl;
600 }
601
602 QListIterator<t_obs> it(dumpList);
603 while (it.hasNext()) {
604 const t_obs& obs = it.next();
605
606 // Cycle slips detection
607 // ---------------------
608 QString prn = QString("%1%2").arg(obs.satSys)
609 .arg(obs.satNum, 2, 10, QChar('0'));
610
611 char lli1 = ' ';
612 char lli2 = ' ';
613 char lli5 = ' ';
614 if ( obs.slip_cnt_L1 >= 0 ) {
615 if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
616 _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
617 lli1 = '1';
618 }
619 }
620
621 if ( obs.slip_cnt_L2 >= 0 ) {
622 if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
623 _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
624 lli2 = '1';
625 }
626 }
627
628 if ( obs.slip_cnt_L5 >= 0 ) {
629 if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
630 _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
631 lli5 = '1';
632 }
633 }
634
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;
638
639 // RINEX Version 3
640 // ---------------
641 if (_rinexVers == 3) {
642 _out << rinexSatLine(obs, lli1, lli2, lli5);
643 _out << endl;
644 }
645
646 // RINEX Version 2
647 // ---------------
648 else {
649 _out << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
650 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
651 << setw(14) << setprecision(3) << obs.L1() << lli1 << ' '
652 << setw(14) << setprecision(3) << obs.S1() << ' ' << ' '
653 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' ' << endl
654 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
655 << setw(14) << setprecision(3) << obs.L2() << lli2 << ' '
656 << setw(14) << setprecision(3) << obs.S2() << endl;
657 }
658 }
659
660 _out.flush();
661}
662
663// Close the Old RINEX File
664////////////////////////////////////////////////////////////////////////////
665void bncRinex::closeFile() {
666 if (_rinexVers == 3) {
667 _out << "> 4 1" << endl;
668 _out << "END OF FILE" << endl;
669 }
670 _out.close();
671 if (!_rnxScriptName.isEmpty()) {
672 qApp->thread()->wait(100);
673#ifdef WIN32
674 QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
675#else
676 QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
677#endif
678
679 }
680}
681
682// One Line in RINEX v3 (static)
683////////////////////////////////////////////////////////////////////////////
684string bncRinex::rinexSatLine(const t_obs& obs, char lli1, char lli2,
685 char lli5) {
686 ostringstream str;
687 str.setf(ios::showpoint | ios::fixed);
688
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 << ' ' << ' '
693 << setw(14) << setprecision(3) << obs.L1C
694 << lli1 << ' ';
695 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
696 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
697 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
698 << setw(14) << setprecision(3) << obs.L1P
699 << lli1 << ' ';
700 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
701 << setw(14) << setprecision(3) << obs.S1P << ' ' << ' '
702 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
703 << setw(14) << setprecision(3) << obs.L2P
704 << lli2 << ' ';
705 str << setw(14) << setprecision(3) << obs.D2P << ' ' << ' '
706 << setw(14) << setprecision(3) << obs.S2P << ' ' << ' '
707 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' '
708 << setw(14) << setprecision(3) << obs.L2C
709 << lli2 << ' ';
710 str << setw(14) << setprecision(3) << obs.D2C << ' ' << ' '
711 << setw(14) << setprecision(3) << obs.S2C << ' ' << ' '
712 << setw(14) << setprecision(3) << obs.C5 << ' ' << ' '
713 << setw(14) << setprecision(3) << obs.L5
714 << lli5 << ' ';
715 str << setw(14) << setprecision(3) << obs.D5 << ' ' << ' '
716 << setw(14) << setprecision(3) << obs.S5;
717 }
718 else if (obs.satSys == 'R') { // Glonass
719 str << obs.satSys
720 << setw(2) << setfill('0') << obs.satNum << setfill(' ');
721 str << setw(14) << setprecision(3) << obs.C1 << ' ' << ' '
722 << setw(14) << setprecision(3) << obs.L1C
723 << lli1 << ' ';
724 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
725 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
726 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
727 << setw(14) << setprecision(3) << obs.L1P
728 << lli1 << ' ';
729 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
730 << setw(14) << setprecision(3) << obs.S1P << ' ' << ' '
731 << setw(14) << setprecision(3) << obs.P2 << ' ' << ' '
732 << setw(14) << setprecision(3) << obs.L2P
733 << lli2 << ' ';
734 str << setw(14) << setprecision(3) << obs.D2P << ' ' << ' '
735 << setw(14) << setprecision(3) << obs.S2P << ' ' << ' '
736 << setw(14) << setprecision(3) << obs.C2 << ' ' << ' '
737 << setw(14) << setprecision(3) << obs.L2C
738 << lli2 << ' ';
739 str << setw(14) << setprecision(3) << obs.D2C << ' ' << ' '
740 << setw(14) << setprecision(3) << obs.S2C;
741 }
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 << ' ' << ' '
746 << setw(14) << setprecision(3) << obs.L1C
747 << lli1 << ' ';
748 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
749 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
750 << setw(14) << setprecision(3) << obs.P1 << ' ' << ' '
751 << setw(14) << setprecision(3) << obs.L1P
752 << lli1 << ' ';
753 str << setw(14) << setprecision(3) << obs.D1P << ' ' << ' '
754 << setw(14) << setprecision(3) << obs.S1P;
755 }
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 << ' ' << ' '
760 << setw(14) << setprecision(3) << obs.L1C
761 << lli1 << ' ';
762 str << setw(14) << setprecision(3) << obs.D1C << ' ' << ' '
763 << setw(14) << setprecision(3) << obs.S1C << ' ' << ' '
764 << setw(14) << setprecision(3) << obs.C5 << ' ' << ' '
765 << setw(14) << setprecision(3) << obs.L5
766 << lli5 << ' ';
767 str << setw(14) << setprecision(3) << obs.D5 << ' ' << ' '
768 << setw(14) << setprecision(3) << obs.S5;
769 }
770 return str.str();
771}
772
773//
774////////////////////////////////////////////////////////////////////////////
775string bncRinex::obsToStr(double val, int width, int precision) {
776 if (val != 0.0) {
777 ostringstream str;
778 str.setf(ios::showpoint | ios::fixed);
779 str << setw(width) << setprecision(precision) << val;
780 return str.str();
781 }
782 else {
783 return "0.0";
784 }
785}
786
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
794 str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
795
796 if (obs.satSys == 'R') { // Glonass
797 str << ' ' << setw(2) << obs.slotNum;
798 }
799 else {
800 str << " ";
801 }
802
803 if (obs.satSys == 'G') { // GPS
804 if (obs.has1C()) {
805 str << " 1C "
806 << obsToStr(obs.C1) << ' '
807 << obsToStr(obs.L1C) << ' '
808 << obsToStr(obs.D1C) << ' '
809 << obsToStr(obs.S1C, 8, 3) << ' '
810 << setw(2) << obs.slip_cnt_L1;
811 }
812 if (obs.has1P()) {
813 str << " 1W "
814 << obsToStr(obs.P1) << ' '
815 << obsToStr(obs.L1P) << ' '
816 << obsToStr(obs.D1P) << ' '
817 << obsToStr(obs.S1P, 8, 3) << ' '
818 << setw(2) << obs.slip_cnt_L1;
819 }
820 if (obs.has2P()) {
821 str << " 2P "
822 << obsToStr(obs.P2) << ' '
823 << obsToStr(obs.L2P) << ' '
824 << obsToStr(obs.D2P) << ' '
825 << obsToStr(obs.S2P, 8, 3) << ' '
826 << setw(2) << obs.slip_cnt_L2;
827 }
828 if (obs.has2C()) {
829 str << " 2X "
830 << obsToStr(obs.C2) << ' '
831 << obsToStr(obs.L2C) << ' '
832 << obsToStr(obs.D2C) << ' '
833 << obsToStr(obs.S2C, 8, 3) << ' '
834 << setw(2) << obs.slip_cnt_L2;
835 }
836 if (obs.has5C()) {
837 str << " 5C "
838 << obsToStr(obs.C5) << ' '
839 << obsToStr(obs.L5) << ' '
840 << obsToStr(obs.D5) << ' '
841 << obsToStr(obs.S5, 8, 3) << ' '
842 << setw(2) << obs.slip_cnt_L5;
843 }
844 }
845 else if (obs.satSys == 'R') { // Glonass
846 if (obs.has1C()) {
847 str << " 1C "
848 << obsToStr(obs.C1) << ' '
849 << obsToStr(obs.L1C) << ' '
850 << obsToStr(obs.D1C) << ' '
851 << obsToStr(obs.S1C, 8, 3) << ' '
852 << setw(2) << obs.slip_cnt_L1;
853 }
854 if (obs.has1P()) {
855 str << " 1P "
856 << obsToStr(obs.P1) << ' '
857 << obsToStr(obs.L1P) << ' '
858 << obsToStr(obs.D1P) << ' '
859 << obsToStr(obs.S1P, 8, 3) << ' '
860 << setw(2) << obs.slip_cnt_L1;
861 }
862 if (obs.has2P()) {
863 str << " 2P "
864 << obsToStr(obs.P2) << ' '
865 << obsToStr(obs.L2P) << ' '
866 << obsToStr(obs.D2P) << ' '
867 << obsToStr(obs.S2P, 8, 3) << ' '
868 << setw(2) << obs.slip_cnt_L2;
869 }
870 if (obs.has2C()) {
871 str << " 2C "
872 << obsToStr(obs.C2) << ' '
873 << obsToStr(obs.L2C) << ' '
874 << obsToStr(obs.D2C) << ' '
875 << obsToStr(obs.S2C, 8, 3) << ' '
876 << setw(2) << obs.slip_cnt_L2;
877 }
878 }
879 else if (obs.satSys == 'S') { // SBAS
880 if (obs.has1C()) {
881 str << " 1C "
882 << obsToStr(obs.C1) << ' '
883 << obsToStr(obs.L1C) << ' '
884 << obsToStr(obs.D1C) << ' '
885 << obsToStr(obs.S1C, 8, 3) << ' '
886 << setw(2) << obs.slip_cnt_L1;
887 }
888 if (obs.has1P()) {
889 str << " 1W "
890 << obsToStr(obs.P1) << ' '
891 << obsToStr(obs.L1P) << ' '
892 << obsToStr(obs.D1P) << ' '
893 << obsToStr(obs.S1P, 8, 3) << ' '
894 << setw(2) << obs.slip_cnt_L1;
895 }
896 }
897 else if (obs.satSys == 'E') { // Galileo
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.has5C()) {
907 str << " 5C "
908 << obsToStr(obs.C5) << ' '
909 << obsToStr(obs.L5) << ' '
910 << obsToStr(obs.D5) << ' '
911 << obsToStr(obs.S5, 8, 3) << ' '
912 << setw(2) << obs.slip_cnt_L5;
913 }
914 }
915 return str.str();
916}
Note: See TracBrowser for help on using the repository browser.