source: ntrip/trunk/BNC/bncrinex.cpp@ 154

Last change on this file since 154 was 154, checked in by mervart, 19 years ago

* empty log message *

File size: 9.6 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncRinex
7 *
8 * Purpose: writes RINEX files
9 *
10 * Author: L. Mervart
11 *
12 * Created: 27-Aug-2006
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <QSettings>
19#include <QDir>
20#include <QDate>
21#include <QFile>
22#include <QTextStream>
23#include <iomanip>
24
25#include "bncrinex.h"
26#include "bncutils.h"
27#include "bncconst.h"
28
29using namespace std;
30
31// Constructor
32////////////////////////////////////////////////////////////////////////////
33bncRinex::bncRinex(const char* StatID) {
34 _statID = StatID;
35 _headerWritten = false;
36 readSkeleton();
37
38 QSettings settings;
39 _rnxScriptName = settings.value("rnxScript").toString();
40 expandEnvVar(_rnxScriptName);
41
42 // Find the corresponding mountPoint
43 // ---------------------------------
44 QListIterator<QString> it(settings.value("mountPoints").toStringList());
45 while (it.hasNext()) {
46 QString hlp = it.next();
47 if (hlp.indexOf(_statID) != -1) {
48 _mountPoint = hlp;
49 break;
50 }
51 }
52}
53
54// Destructor
55////////////////////////////////////////////////////////////////////////////
56bncRinex::~bncRinex() {
57 _out.close();
58}
59
60// Read Skeleton Header File
61////////////////////////////////////////////////////////////////////////////
62void bncRinex::readSkeleton() {
63
64 // Resolve Skeleton File Name
65 // --------------------------
66 QSettings settings;
67 QString sklName = settings.value("rnxPath").toString();
68 expandEnvVar(sklName);
69 if ( sklName[sklName.length()-1] != QDir::separator() ) {
70 sklName += QDir::separator();
71 }
72 sklName += _statID.left(4) + "." + settings.value("rnxSkel").toString();
73
74 // Read the File
75 // -------------
76 QFile skl(sklName);
77 if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
78 QTextStream in(&skl);
79 while ( !in.atEnd() ) {
80 _headerLines.append( in.readLine() );
81 if (_headerLines.last().indexOf("END OF HEADER") != -1) {
82 break;
83 }
84 }
85 }
86}
87
88// File Name according to RINEX Standards
89////////////////////////////////////////////////////////////////////////////
90void bncRinex::resolveFileName(const QDateTime& datTim) {
91
92 QSettings settings;
93 QString path = settings.value("rnxPath").toString();
94 expandEnvVar(path);
95
96 if ( path[path.length()-1] != QDir::separator() ) {
97 path += QDir::separator();
98 }
99
100 QString intStr = settings.value("rnxIntr").toString();
101 QString hlpStr;
102
103 QTime nextTime;
104 QDate nextDate;
105
106 if (intStr == "15 min") {
107 char ch = 'A' + datTim.time().hour();
108 hlpStr = ch;
109 if (datTim.time().minute() < 15) {
110 hlpStr += "00";
111 nextTime.setHMS(datTim.time().hour(), 15, 0);
112 nextDate = datTim.date();
113 }
114 else if (datTim.time().minute() < 30) {
115 hlpStr += "15";
116 nextTime.setHMS(datTim.time().hour(), 30, 0);
117 nextDate = datTim.date();
118 }
119 else if (datTim.time().minute() < 45) {
120 hlpStr += "30";
121 nextTime.setHMS(datTim.time().hour(), 45, 0);
122 nextDate = datTim.date();
123 }
124 else {
125 hlpStr += "45";
126 if (datTim.time().hour() < 23) {
127 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
128 nextDate = datTim.date();
129 }
130 else {
131 nextTime.setHMS(0, 0, 0);
132 nextDate = datTim.date().addDays(1);
133 }
134 }
135 }
136 else if (intStr == "1 hour") {
137 char ch = 'A' + datTim.time().hour();
138 hlpStr = ch;
139 if (datTim.time().hour() < 23) {
140 nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
141 nextDate = datTim.date();
142 }
143 else {
144 nextTime.setHMS(0, 0, 0);
145 nextDate = datTim.date().addDays(1);
146 }
147 }
148 else {
149 hlpStr = "0";
150 nextTime.setHMS(0, 0, 0);
151 nextDate = datTim.date().addDays(1);
152 }
153 _nextCloseEpoch = QDateTime(nextDate, nextTime);
154
155 path += _statID.left(4) +
156 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
157 hlpStr +
158 datTim.toString(".yyO");
159
160 _fName = path.toAscii();
161}
162
163// Write RINEX Header
164////////////////////////////////////////////////////////////////////////////
165void bncRinex::writeHeader(const QDateTime& datTim) {
166
167 // Open the Output File
168 // --------------------
169 resolveFileName(datTim);
170 _out.open(_fName.data());
171 _out.setf(ios::showpoint | ios::fixed);
172
173 // Copy Skeleton Header
174 // --------------------
175 if (_headerLines.size() > 0) {
176 QStringListIterator it(_headerLines);
177 while (it.hasNext()) {
178 QString line = it.next();
179 if (line.indexOf("# / TYPES OF OBSERV") != -1) {
180 _out << " 4 P1 P2 L1 L2"
181 " # / TYPES OF OBSERV" << endl;
182 }
183 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
184 _out << datTim.toString(" yyyy MM dd"
185 " hh mm ss.zzz0000").toAscii().data();
186 _out << " TIME OF FIRST OBS" << endl;
187 QString hlp = "GENERATED FROM STREAM" + _mountPoint;
188 hlp.fill(' ', 59);
189 _out << hlp.toAscii().data() << "COMMENT" << endl;
190 }
191 else {
192 _out << line.toAscii().data() << endl;
193 }
194 }
195 }
196
197 // Write Dummy Header
198 // ------------------
199 else {
200 double approxPos[3]; approxPos[0] = approxPos[1] = approxPos[2] = 0.0;
201 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
202
203 _out << " 2.10 OBSERVATION DATA G (GPS) RINEX VERSION / TYPE" << endl;
204 _out << "BNC LM 27-Aug-2006 PGM / RUN BY / DATE" << endl;
205 _out.setf(ios::left);
206 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
207 _out << setw(60) << "BKG" << "OBSERVER / AGENCY" << endl;
208 _out << setw(20) << "unknown"
209 << setw(20) << "unknown"
210 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
211 _out << setw(20) << "unknown"
212 << setw(20) << "unknown"
213 << setw(20) << " " << "ANT # / TYPE" << endl;
214 _out.unsetf(ios::left);
215 _out << setw(14) << setprecision(4) << approxPos[0]
216 << setw(14) << setprecision(4) << approxPos[1]
217 << setw(14) << setprecision(4) << approxPos[2]
218 << " " << "APPROX POSITION XYZ" << endl;
219 _out << setw(14) << setprecision(4) << antennaNEU[0]
220 << setw(14) << setprecision(4) << antennaNEU[1]
221 << setw(14) << setprecision(4) << antennaNEU[2]
222 << " " << "ANTENNA: DELTA H/E/N" << endl;
223 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
224 _out << " 4 P1 P2 L1 L2 # / TYPES OF OBSERV" << endl;
225 _out << datTim.toString(" yyyy MM dd"
226 " hh mm ss.zzz0000").toAscii().data();
227 _out << " " << "TIME OF FIRST OBS" << endl;
228 QString hlp = "GENERATED FROM STREAM" + _mountPoint;
229 hlp.fill(' ', 59);
230 _out << hlp.toAscii().data() << "COMMENT" << endl;
231 _out << " END OF HEADER" << endl;
232 }
233
234 _headerWritten = true;
235}
236
237// Stores Observation into Internal Array
238////////////////////////////////////////////////////////////////////////////
239void bncRinex::deepCopy(const Observation* obs) {
240 Observation* newObs = new Observation();
241 memcpy(newObs, obs, sizeof(*obs));
242 _obs.push_back(newObs);
243}
244
245// Write One Epoch into the RINEX File
246////////////////////////////////////////////////////////////////////////////
247void bncRinex::dumpEpoch() {
248
249 // Easy Return
250 // -----------
251 if (_obs.isEmpty()) {
252 return;
253 }
254
255 // Time of Epoch
256 // -------------
257 Observation* firstObs = *_obs.begin();
258
259 QDateTime datTim = dateAndTimeFromGPSweek( firstObs->GPSWeek,
260 firstObs->GPSWeeks +
261 fmod(firstObs->sec, 1.0) );
262
263 // Close the file
264 // --------------
265 if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
266 closeFile();
267 _headerWritten = false;
268 }
269
270 // Write RINEX Header
271 // ------------------
272 if (!_headerWritten) {
273 writeHeader(datTim);
274 }
275
276 _out << datTim.toString(" yy MM dd hh mm ss.zzz0000").toAscii().data()
277 << " " << 0 << setw(3) << _obs.size();
278
279 QListIterator<Observation*> it(_obs); int iSat = 0;
280 while (it.hasNext()) {
281 iSat++;
282 Observation* ob = it.next();
283 _out << " " << setw(2) << int(ob->SVPRN);
284 if (iSat == 12 && it.hasNext()) {
285 _out << endl << " ";
286 iSat = 0;
287 }
288 }
289 _out << endl;
290
291 it.toFront();
292 while (it.hasNext()) {
293 Observation* ob = it.next();
294
295 char lli = ' ';
296 char snr = ' ';
297 _out << setw(14) << setprecision(3) << ob->C1 << lli << snr;
298 _out << setw(14) << setprecision(3) << ob->P2 << lli << snr;
299 _out << setw(14) << setprecision(3) << ob->L1 / t_CST::lambda1 << lli << snr;
300 _out << setw(14) << setprecision(3) << ob->L2 / t_CST::lambda2 << lli << snr;
301 _out << endl;
302
303 delete ob;
304 }
305
306 _out.flush();
307 _obs.clear();
308}
309
310// Close the Old RINEX File
311////////////////////////////////////////////////////////////////////////////
312void bncRinex::closeFile() {
313 _out.close();
314 if (!_rnxScriptName.isEmpty()) {
315 _rnxScript.start(_rnxScriptName, QStringList() << _fName);
316 }
317}
Note: See TracBrowser for help on using the repository browser.