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

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