source: ntrip/trunk/BNC/rinex/reqcedit.cpp@ 3999

Last change on this file since 3999 was 3999, checked in by mervart, 12 years ago
File size: 7.2 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: t_reqcEdit
30 *
31 * Purpose: Edit/Concatenate RINEX Files
32 *
33 * Author: L. Mervart
34 *
35 * Created: 11-Apr-2012
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include "reqcedit.h"
43#include "bncapp.h"
44#include "bncsettings.h"
45#include "rnxnavfile.h"
46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
52
53 bncSettings settings;
54
55 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
56 _outObsFileName = settings.value("reqcOutObsFile").toString();
57 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
58 _outNavFileName = settings.value("reqcOutNavFile").toString();
59 _rnxVersion = settings.value("reqcRnxVersion").toDouble();
60 _samplingRate = settings.value("reqcSampling").toInt();
61 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
62 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
63}
64
65// Destructor
66////////////////////////////////////////////////////////////////////////////
67t_reqcEdit::~t_reqcEdit() {
68 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
69 delete _rnxObsFiles[ii];
70 }
71}
72
73//
74////////////////////////////////////////////////////////////////////////////
75void t_reqcEdit::run() {
76
77 editObservations();
78
79 editEphemerides();
80
81 bncApp* app = (bncApp*) qApp;
82 if ( app->mode() != bncApp::interactive) {
83 app->exit(0);
84 }
85 else {
86 emit finished();
87 deleteLater();
88 }
89}
90
91//
92////////////////////////////////////////////////////////////////////////////
93void t_reqcEdit::editObservations() {
94
95 // Initialize input observation files, sort them according to start time
96 // ---------------------------------------------------------------------
97 QStringListIterator it(_obsFileNames);
98 while (it.hasNext()) {
99 QString fileName = it.next();
100 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
101 _rnxObsFiles.append(rnxObsFile);
102 }
103 qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
104 t_rnxObsFile::earlierStartTime);
105
106 // Initialize output observation file
107 // ----------------------------------
108 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
109
110 // Loop over all input observation files
111 // -------------------------------------
112 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
113 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
114 if (ii == 0) {
115 outObsFile.setHeader(obsFile->header(), _rnxVersion);
116 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
117 outObsFile.setStartTime(_begTime);
118 }
119 editRnxObsHeader(outObsFile);
120 outObsFile.writeHeader();
121 }
122 t_rnxObsFile::t_rnxEpo* epo = 0;
123 while ( (epo = obsFile->nextEpoch()) != 0) {
124 if (_begTime.valid() && epo->tt < _begTime) {
125 continue;
126 }
127 if (_endTime.valid() && epo->tt > _endTime) {
128 break;
129 }
130
131 if (_samplingRate == 0 ||
132 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
133 applyLLI(obsFile, epo);
134 outObsFile.writeEpoch(epo);
135 }
136 else {
137 rememberLLI(obsFile, epo);
138 }
139 }
140 }
141}
142
143// Change RINEX Header Content
144////////////////////////////////////////////////////////////////////////////
145void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
146
147 bncSettings settings;
148
149 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
150 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
151 if (oldMarkerName.isEmpty() ||
152 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
153 obsFile.setMarkerName(newMarkerName);
154 }
155
156 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
157 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
158 if (oldAntennaName.isEmpty() ||
159 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
160 obsFile.setAntennaName(newAntennaName);
161 }
162
163 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
164 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
165 if (oldReceiverType.isEmpty() ||
166 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
167 obsFile.setReceiverType(newReceiverType);
168 }
169}
170
171//
172////////////////////////////////////////////////////////////////////////////
173void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
174 const t_rnxObsFile::t_rnxEpo* epo) {
175
176 if (_samplingRate == 0) {
177 return;
178 }
179
180 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
181 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
182 char sys = rnxSat.satSys;
183 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
184
185 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
186 if (!_lli[prn].contains(iType)) {
187 _lli[prn][iType] = 0;
188 }
189 if (rnxSat.lli[iType] & 1) {
190 _lli[prn][iType] |= 1;
191 }
192 }
193 }
194}
195
196//
197////////////////////////////////////////////////////////////////////////////
198void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
199 t_rnxObsFile::t_rnxEpo* epo) {
200
201 if (_samplingRate == 0) {
202 return;
203 }
204
205 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
206 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
207 char sys = rnxSat.satSys;
208 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
209
210 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
211 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
212 rnxSat.lli[iType] |= 1;
213 }
214 }
215 }
216
217 _lli.clear();
218}
219
220//
221////////////////////////////////////////////////////////////////////////////
222void t_reqcEdit::editEphemerides() {
223
224 QStringListIterator it(_navFileNames);
225 while (it.hasNext()) {
226 QString fileName = it.next();
227 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
228 }
229
230}
Note: See TracBrowser for help on using the repository browser.