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

Last change on this file since 4010 was 4010, checked in by mervart, 12 years ago
File size: 8.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 // Initialize input observation files, sort them according to start time
104 // ---------------------------------------------------------------------
105 QStringListIterator it(_obsFileNames);
106 while (it.hasNext()) {
107 QString fileName = it.next();
108 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
109 _rnxObsFiles.append(rnxObsFile);
110 }
111 qStableSort(_rnxObsFiles.begin(), _rnxObsFiles.end(),
112 t_rnxObsFile::earlierStartTime);
113
114 // Initialize output observation file
115 // ----------------------------------
116 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
117
118 // Loop over all input observation files
119 // -------------------------------------
120 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
121 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
122 if (ii == 0) {
123 outObsFile.setHeader(obsFile->header(), _rnxVersion);
124 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
125 outObsFile.setStartTime(_begTime);
126 }
127 editRnxObsHeader(outObsFile);
128 outObsFile.writeHeader();
129 }
130 t_rnxObsFile::t_rnxEpo* epo = 0;
131 while ( (epo = obsFile->nextEpoch()) != 0) {
132 if (_begTime.valid() && epo->tt < _begTime) {
133 continue;
134 }
135 if (_endTime.valid() && epo->tt > _endTime) {
136 break;
137 }
138
139 if (_samplingRate == 0 ||
140 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
141 applyLLI(obsFile, epo);
142 outObsFile.writeEpoch(epo);
143 }
144 else {
145 rememberLLI(obsFile, epo);
146 }
147 }
148 }
149}
150
151// Change RINEX Header Content
152////////////////////////////////////////////////////////////////////////////
153void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
154
155 bncSettings settings;
156
157 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
158 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
159 if (oldMarkerName.isEmpty() ||
160 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
161 obsFile.setMarkerName(newMarkerName);
162 }
163
164 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
165 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
166 if (oldAntennaName.isEmpty() ||
167 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
168 obsFile.setAntennaName(newAntennaName);
169 }
170
171 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
172 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
173 if (oldReceiverType.isEmpty() ||
174 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
175 obsFile.setReceiverType(newReceiverType);
176 }
177}
178
179//
180////////////////////////////////////////////////////////////////////////////
181void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
182 const t_rnxObsFile::t_rnxEpo* epo) {
183
184 if (_samplingRate == 0) {
185 return;
186 }
187
188 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
189 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
190 char sys = rnxSat.satSys;
191 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
192
193 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
194 if (!_lli[prn].contains(iType)) {
195 _lli[prn][iType] = 0;
196 }
197 if (rnxSat.lli[iType] & 1) {
198 _lli[prn][iType] |= 1;
199 }
200 }
201 }
202}
203
204//
205////////////////////////////////////////////////////////////////////////////
206void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
207 t_rnxObsFile::t_rnxEpo* epo) {
208
209 if (_samplingRate == 0) {
210 return;
211 }
212
213 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
214 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
215 char sys = rnxSat.satSys;
216 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
217
218 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
219 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
220 rnxSat.lli[iType] |= 1;
221 }
222 }
223 }
224
225 _lli.clear();
226}
227
228//
229////////////////////////////////////////////////////////////////////////////
230void t_reqcEdit::editEphemerides() {
231
232 // Read All Ephemerides
233 // --------------------
234 QStringListIterator it(_navFileNames);
235 while (it.hasNext()) {
236 QString fileName = it.next();
237 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
238 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
239 t_eph* eph = rnxNavFile.ephs()[ii];
240 if (eph->type() == t_eph::GPS) {
241 _ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
242 }
243 else if (eph->type() == t_eph::GLONASS) {
244 _ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
245 }
246 else if (eph->type() == t_eph::Galileo) {
247 _ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
248 }
249 }
250 }
251 qStableSort(_ephs.begin(), _ephs.end(), t_eph::earlierTime);
252
253 // Initialize output navigation file
254 // ---------------------------------
255 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
256 outNavFile.setVersion(_rnxVersion);
257 outNavFile.writeHeader();
258
259 // Loop over all ephemerides
260 // -------------------------
261 for (int ii = 0; ii < _ephs.size(); ii++) {
262 const t_eph* eph = _ephs[ii];
263 if (eph->type() == t_eph::GPS || _rnxVersion >= 3.0) {
264 outNavFile.writeEph(eph);
265 }
266 }
267}
Note: See TracBrowser for help on using the repository browser.