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

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