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

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

* empty log message *

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