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

Last change on this file since 4115 was 4115, checked in by mervart, 12 years ago
File size: 10.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: 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
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
51
52 bncSettings settings;
53
54 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
55 _outObsFileName = settings.value("reqcOutObsFile").toString();
56 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
57 _outNavFileName = settings.value("reqcOutNavFile").toString();
58 int version = settings.value("reqcRnxVersion").toInt();
59 if (version < 3) {
60 _rnxVersion = 2.11;
61 }
62 else {
63 _rnxVersion = 3.01;
64 }
65 _samplingRate = settings.value("reqcSampling").toInt();
66 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
67 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
68}
69
70// Destructor
71////////////////////////////////////////////////////////////////////////////
72t_reqcEdit::~t_reqcEdit() {
73 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
74 delete _rnxObsFiles[ii];
75 }
76 for (int ii = 0; ii < _ephs.size(); ii++) {
77 delete _ephs[ii];
78 }
79}
80
81//
82////////////////////////////////////////////////////////////////////////////
83void t_reqcEdit::run() {
84
85 editObservations();
86
87 editEphemerides();
88
89 bncApp* app = (bncApp*) qApp;
90 if ( app->mode() != bncApp::interactive) {
91 app->exit(0);
92 }
93 else {
94 emit finished();
95 deleteLater();
96 }
97}
98
99//
100////////////////////////////////////////////////////////////////////////////
101void t_reqcEdit::editObservations() {
102
103 // Easy Exit
104 // ---------
105 if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
106 return;
107 }
108
109 // Initialize input observation files, sort them according to start time
110 // ---------------------------------------------------------------------
111 QStringListIterator it(_obsFileNames);
112 while (it.hasNext()) {
113 QString fileName = it.next();
114 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
115 QFileInfo fileInfo(fileName);
116 QDir dir = fileInfo.dir();
117 QStringList filters; filters << fileInfo.fileName();
118 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
119 while (it.hasNext()) {
120 QString filePath = it.next().filePath();
121 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
122 _rnxObsFiles.append(rnxObsFile);
123 }
124 }
125 else {
126 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
127 _rnxObsFiles.append(rnxObsFile);
128 }
129 }
130 qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
131 t_rnxObsFile::earlierStartTime);
132
133 // Initialize output observation file
134 // ----------------------------------
135 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
136
137 // Loop over all input observation files
138 // -------------------------------------
139 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
140 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
141 if (ii == 0) {
142 outObsFile.setHeader(obsFile->header(), _rnxVersion);
143 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
144 outObsFile.setStartTime(_begTime);
145 }
146 if (_samplingRate > outObsFile.interval()) {
147 outObsFile.setInterval(_samplingRate);
148 }
149 editRnxObsHeader(outObsFile);
150 QMap<QString, QString> txtMap;
151 txtMap["RUN BY"] = "BKG";
152 txtMap["COMMENT"] = "First comment line\nSecond comment line";
153 outObsFile.writeHeader(txtMap);
154 }
155 else {
156 outObsFile.checkNewHeader(obsFile->header());
157 }
158 t_rnxObsFile::t_rnxEpo* epo = 0;
159 while ( (epo = obsFile->nextEpoch()) != 0) {
160 if (_begTime.valid() && epo->tt < _begTime) {
161 continue;
162 }
163 if (_endTime.valid() && epo->tt > _endTime) {
164 break;
165 }
166
167 if (_samplingRate == 0 ||
168 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
169 applyLLI(obsFile, epo);
170 outObsFile.writeEpoch(epo);
171 }
172 else {
173 rememberLLI(obsFile, epo);
174 }
175 }
176 }
177}
178
179// Change RINEX Header Content
180////////////////////////////////////////////////////////////////////////////
181void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
182
183 bncSettings settings;
184
185 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
186 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
187 if (!newMarkerName.isEmpty()) {
188 if (oldMarkerName.isEmpty() ||
189 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
190 obsFile.setMarkerName(newMarkerName);
191 }
192 }
193
194 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
195 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
196 if (!newAntennaName.isEmpty()) {
197 if (oldAntennaName.isEmpty() ||
198 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
199 obsFile.setAntennaName(newAntennaName);
200 }
201 }
202
203 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
204 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
205 if (!newReceiverType.isEmpty()) {
206 if (oldReceiverType.isEmpty() ||
207 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
208 obsFile.setReceiverType(newReceiverType);
209 }
210 }
211}
212
213//
214////////////////////////////////////////////////////////////////////////////
215void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
216 const t_rnxObsFile::t_rnxEpo* epo) {
217
218 if (_samplingRate == 0) {
219 return;
220 }
221
222 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
223 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
224 char sys = rnxSat.satSys;
225 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
226
227 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
228 if (!_lli[prn].contains(iType)) {
229 _lli[prn][iType] = 0;
230 }
231 if (rnxSat.lli[iType] & 1) {
232 _lli[prn][iType] |= 1;
233 }
234 }
235 }
236}
237
238//
239////////////////////////////////////////////////////////////////////////////
240void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
241 t_rnxObsFile::t_rnxEpo* epo) {
242
243 if (_samplingRate == 0) {
244 return;
245 }
246
247 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
248 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
249 char sys = rnxSat.satSys;
250 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
251
252 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
253 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
254 rnxSat.lli[iType] |= 1;
255 }
256 }
257 }
258
259 _lli.clear();
260}
261
262//
263////////////////////////////////////////////////////////////////////////////
264void t_reqcEdit::editEphemerides() {
265
266 // Easy Exit
267 // ---------
268 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
269 return;
270 }
271
272 // Read All Ephemerides
273 // --------------------
274 QStringListIterator it(_navFileNames);
275 while (it.hasNext()) {
276 QString fileName = it.next();
277 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
278 QFileInfo fileInfo(fileName);
279 QDir dir = fileInfo.dir();
280 QStringList filters; filters << fileInfo.fileName();
281 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
282 while (it.hasNext()) {
283 QString filePath = it.next().filePath();
284 appendEphemerides(filePath);
285 }
286 }
287 else {
288 appendEphemerides(fileName);
289 }
290 }
291 qStableSort(_ephs.begin(), _ephs.end(), t_eph::earlierTime);
292
293 // Initialize output navigation file
294 // ---------------------------------
295 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
296 outNavFile.setVersion(_rnxVersion);
297 outNavFile.writeHeader();
298
299 // Loop over all ephemerides
300 // -------------------------
301 for (int ii = 0; ii < _ephs.size(); ii++) {
302 const t_eph* eph = _ephs[ii];
303 if (eph->type() == t_eph::GPS || _rnxVersion >= 3.0) {
304 outNavFile.writeEph(eph);
305 }
306 }
307}
308
309//
310////////////////////////////////////////////////////////////////////////////
311void t_reqcEdit::appendEphemerides(const QString& fileName) {
312
313 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
314 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
315 t_eph* eph = rnxNavFile.ephs()[ii];
316 bool isNew = true;
317 for (int iOld = 0; iOld < _ephs.size(); iOld++) {
318 const t_eph* ephOld = _ephs[iOld];
319 if (ephOld->prn() == eph->prn() && ephOld->IOD() == eph->IOD()) {
320 isNew = false;
321 break;
322 }
323 }
324 if (isNew) {
325 if (eph->type() == t_eph::GPS) {
326 _ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
327 }
328 else if (eph->type() == t_eph::GLONASS) {
329 _ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
330 }
331 else if (eph->type() == t_eph::Galileo) {
332 _ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
333 }
334 }
335 }
336}
Note: See TracBrowser for help on using the repository browser.