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

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