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

Last change on this file since 4472 was 4423, checked in by mervart, 12 years ago
File size: 27.6 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 {
479 _out << line.toAscii().data() << endl;
480 }
481 }
482 }
483
484 // Write Dummy Header
485 // ------------------
486 else {
487 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
488
489 if (_rinexVers == 3) {
490 _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
491 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
492 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
493 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
494 }
495 else {
496 _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
497 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
498 _out << _pgmName.toAscii().data() << _userName.toAscii().data()
499 << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
500 }
501 _out.setf(ios::left);
502 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
503 if (_rinexVers == 3) {
504 _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
505 }
506 _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
507 _out << setw(20) << "unknown"
508 << setw(20) << "unknown"
509 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
510 _out << setw(20) << "unknown"
511 << setw(20) << "unknown"
512 << setw(20) << " " << "ANT # / TYPE" << endl;
513 _out.unsetf(ios::left);
514 _out << setw(14) << setprecision(4) << _approxPos[0]
515 << setw(14) << setprecision(4) << _approxPos[1]
516 << setw(14) << setprecision(4) << _approxPos[2]
517 << " " << "APPROX POSITION XYZ" << endl;
518 _out << setw(14) << setprecision(4) << antennaNEU[0]
519 << setw(14) << setprecision(4) << antennaNEU[1]
520 << setw(14) << setprecision(4) << antennaNEU[2]
521 << " " << "ANTENNA: DELTA H/E/N" << endl;
522
523 writeObsTypes();
524
525 _out << datTim.toString(" yyyy MM dd"
526 " hh mm ss.zzz0000").toAscii().data();
527 _out << " GPS TIME OF FIRST OBS" << endl;
528 QString hlp = (format.left(6) + QString(" %1").arg(_mountPoint.host() +
529 _mountPoint.path())).leftJustified(60, ' ', true);
530 _out << hlp.toAscii().data() << "COMMENT" << endl;
531
532 if (_nmea == "yes") {
533 hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
534 _out << hlp.toAscii().data() << "COMMENT" << endl; }
535
536 _out << " END OF HEADER" << endl;
537 }
538
539 _headerWritten = true;
540}
541
542//
543////////////////////////////////////////////////////////////////////////////
544void bncRinex::writeObsTypes() {
545 if (_rinexVers == 3) {
546 QMapIterator<char, QVector<QString> > it(_rnxTypes);
547 while (it.hasNext()) {
548 it.next();
549 char sys = it.key();
550 const QVector<QString>& types = it.value();
551 QString hlp;
552 QTextStream(&hlp) << QString("%1 %2").arg(sys).arg(types.size(), 3);
553 for (int ii = 0; ii < types.size(); ii++) {
554 QTextStream(&hlp) << QString(" %1").arg(types[ii], -3);
555 if ((ii+1) % 13 == 0 || ii == types.size()-1) {
556 _out << QString(hlp.leftJustified(60) + "SYS / # / OBS TYPES\n").toAscii().data();
557 hlp = QString().leftJustified(6);
558 }
559 }
560 }
561 }
562 else {
563 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
564 _out << " 8 C1 P1 L1 S1 C2 P2 L2 S2 # / TYPES OF OBSERV" << endl;
565 }
566}
567
568// Stores Observation into Internal Array
569////////////////////////////////////////////////////////////////////////////
570void bncRinex::deepCopy(t_obs obs) {
571 _obs.push_back(obs);
572}
573
574// Write One Epoch into the RINEX File
575////////////////////////////////////////////////////////////////////////////
576void bncRinex::dumpEpoch(const QByteArray& format, long maxTime) {
577
578 // Select observations older than maxTime
579 // --------------------------------------
580 QList<t_obs> dumpList;
581 QMutableListIterator<t_obs> mIt(_obs);
582 while (mIt.hasNext()) {
583 t_obs obs = mIt.next();
584 if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
585 dumpList.push_back(obs);
586 mIt.remove();
587 }
588 }
589
590 // Easy Return
591 // -----------
592 if (dumpList.isEmpty()) {
593 return;
594 }
595
596 // Time of Epoch
597 // -------------
598 const t_obs& fObs = dumpList.first();
599 QDateTime datTim = dateAndTimeFromGPSweek(fObs.GPSWeek, fObs.GPSWeeks);
600 QDateTime datTimNom = dateAndTimeFromGPSweek(fObs.GPSWeek,
601 floor(fObs.GPSWeeks+0.5));
602
603 // Close the file
604 // --------------
605 if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
606 closeFile();
607 _headerWritten = false;
608 }
609
610 // Write RINEX Header
611 // ------------------
612 if (!_headerWritten) {
613 writeHeader(format, datTim, datTimNom);
614 }
615
616 double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
617
618 // Epoch header line: RINEX Version 3
619 // ----------------------------------
620 if (_rinexVers == 3) {
621 _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
622 << setw(10) << setprecision(7) << sec
623 << " " << 0 << setw(3) << dumpList.size() << endl;
624 }
625 // Epoch header line: RINEX Version 2
626 // ----------------------------------
627 else {
628 _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
629 << setw(10) << setprecision(7) << sec
630 << " " << 0 << setw(3) << dumpList.size();
631
632 QListIterator<t_obs> it(dumpList); int iSat = 0;
633 while (it.hasNext()) {
634 iSat++;
635 const t_obs& obs = it.next();
636 _out << obs.satSys << setw(2) << obs.satNum;
637 if (iSat == 12 && it.hasNext()) {
638 _out << endl << " ";
639 iSat = 0;
640 }
641 }
642 _out << endl;
643 }
644
645 QListIterator<t_obs> it(dumpList);
646 while (it.hasNext()) {
647 const t_obs& obs = it.next();
648
649 // Cycle slips detection
650 // ---------------------
651 QString prn = QString("%1%2").arg(obs.satSys)
652 .arg(obs.satNum, 2, 10, QChar('0'));
653
654 char lli1 = ' ';
655 char lli2 = ' ';
656 char lli5 = ' ';
657 if ( obs.slip_cnt_L1 >= 0 ) {
658 if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
659 _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
660 lli1 = '1';
661 }
662 }
663
664 if ( obs.slip_cnt_L2 >= 0 ) {
665 if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
666 _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
667 lli2 = '1';
668 }
669 }
670
671 if ( obs.slip_cnt_L5 >= 0 ) {
672 if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
673 _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
674 lli5 = '1';
675 }
676 }
677
678 _slip_cnt_L1[prn] = obs.slip_cnt_L1;
679 _slip_cnt_L2[prn] = obs.slip_cnt_L2;
680 _slip_cnt_L5[prn] = obs.slip_cnt_L5;
681
682 // RINEX Version 3
683 // ---------------
684 if (_rinexVers == 3) {
685 _out << rinexSatLine(obs, lli1, lli2, lli5);
686 _out << endl;
687 }
688
689 // RINEX Version 2
690 // ---------------
691 else {
692 _out << setw(14) << setprecision(3) << obs.measdata("C1", _rinexVers) << ' ' << ' '
693 << setw(14) << setprecision(3) << obs.measdata("P1", _rinexVers) << ' ' << ' '
694 << setw(14) << setprecision(3) << obs.measdata("L1", _rinexVers) << lli1 << ' '
695 << setw(14) << setprecision(3) << obs.measdata("S1", _rinexVers) << ' ' << ' '
696 << setw(14) << setprecision(3) << obs.measdata("C2", _rinexVers) << ' ' << ' ' << endl
697 << setw(14) << setprecision(3) << obs.measdata("P2", _rinexVers) << ' ' << ' '
698 << setw(14) << setprecision(3) << obs.measdata("L2", _rinexVers) << lli2 << ' '
699 << setw(14) << setprecision(3) << obs.measdata("S2", _rinexVers) << endl;
700 }
701 }
702
703 _out.flush();
704}
705
706// Close the Old RINEX File
707////////////////////////////////////////////////////////////////////////////
708void bncRinex::closeFile() {
709 if (_rinexVers == 3) {
710 _out << "> 4 1" << endl;
711 _out << "END OF FILE" << endl;
712 }
713 _out.close();
714 if (!_rnxScriptName.isEmpty()) {
715 qApp->thread()->wait(100);
716#ifdef WIN32
717 QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
718#else
719 QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
720#endif
721
722 }
723}
724
725// One Line in RINEX v3
726////////////////////////////////////////////////////////////////////////////
727string bncRinex::rinexSatLine(const t_obs& obs, char lli1, char lli2,
728 char lli5) {
729 ostringstream str;
730 str.setf(ios::showpoint | ios::fixed);
731
732 str << obs.satSys
733 << setw(2) << setfill('0') << obs.satNum << setfill(' ');
734
735 const QVector<QString>& types = _rnxTypes[obs.satSys];
736 for (int ii = 0; ii < types.size(); ii++) {
737 double value = obs.measdata(types[ii], _rinexVers);
738 str << setw(14) << setprecision(3) << value;
739 if (value != 0.0 && types[ii].indexOf("L1") == 0) {
740 str << lli1 << ' ';
741 }
742 else if (value != 0.0 && types[ii].indexOf("L2") == 0) {
743 str << lli2 << ' ';
744 }
745 else if (value != 0.0 && types[ii].indexOf("L5") == 0) {
746 str << lli5 << ' ';
747 }
748 else {
749 str << " ";
750 }
751 }
752
753 return str.str();
754}
755
756//
757////////////////////////////////////////////////////////////////////////////
758string bncRinex::obsToStr(double val, int width, int precision) {
759 if (val != 0.0) {
760 ostringstream str;
761 str.setf(ios::showpoint | ios::fixed);
762 str << setw(width) << setprecision(precision) << val;
763 return str.str();
764 }
765 else {
766 return "0.0";
767 }
768}
769
770// One Line in ASCII (Internal) Format
771////////////////////////////////////////////////////////////////////////////
772string bncRinex::asciiSatLine(const t_obs& obs) {
773
774 ostringstream str;
775 str.setf(ios::showpoint | ios::fixed);
776
777 str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
778
779 if (obs.satSys == 'R') { // Glonass
780 str << ' ' << setw(2) << obs.slotNum;
781 }
782 else {
783 str << " ";
784 }
785
786 float rnxVers = 3.0;
787
788 if (obs.satSys == 'G') { // GPS
789 str << " 1C "
790 << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
791 << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
792 << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
793 << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
794 << setw(2) << obs.slip_cnt_L1;
795 str << " 1P "
796 << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
797 << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
798 << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
799 << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
800 << setw(2) << obs.slip_cnt_L1;
801 str << " 2P "
802 << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
803 << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
804 << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
805 << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
806 << setw(2) << obs.slip_cnt_L2;
807 str << " 5C "
808 << obsToStr(obs.measdata("C5", rnxVers)) << ' '
809 << obsToStr(obs.measdata("L5", rnxVers)) << ' '
810 << obsToStr(obs.measdata("D5", rnxVers)) << ' '
811 << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
812 << setw(2) << obs.slip_cnt_L5;
813 }
814 else if (obs.satSys == 'R') { // Glonass
815 str << " 1C "
816 << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
817 << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
818 << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
819 << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
820 << setw(2) << obs.slip_cnt_L1;
821 str << " 1P "
822 << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
823 << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
824 << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
825 << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
826 << setw(2) << obs.slip_cnt_L1;
827 str << " 2P "
828 << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
829 << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
830 << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
831 << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
832 << setw(2) << obs.slip_cnt_L2;
833 str << " 2C "
834 << obsToStr(obs.measdata("C2C", rnxVers)) << ' '
835 << obsToStr(obs.measdata("L2C", rnxVers)) << ' '
836 << obsToStr(obs.measdata("D2C", rnxVers)) << ' '
837 << obsToStr(obs.measdata("S2C", rnxVers), 8, 3) << ' '
838 << setw(2) << obs.slip_cnt_L2;
839 }
840 else if (obs.satSys == 'E') { // Galileo
841 str << " 1C "
842 << obsToStr(obs.measdata("C1", rnxVers)) << ' '
843 << obsToStr(obs.measdata("L1", rnxVers)) << ' '
844 << obsToStr(obs.measdata("D1", rnxVers)) << ' '
845 << obsToStr(obs.measdata("S1", rnxVers), 8, 3) << ' '
846 << setw(2) << obs.slip_cnt_L1;
847
848 str << " 5C "
849 << obsToStr(obs.measdata("C5", rnxVers)) << ' '
850 << obsToStr(obs.measdata("L5", rnxVers)) << ' '
851 << obsToStr(obs.measdata("D5", rnxVers)) << ' '
852 << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
853 << setw(2) << obs.slip_cnt_L5;
854 }
855 return str.str();
856}
Note: See TracBrowser for help on using the repository browser.