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

Last change on this file since 82 was 82, checked in by mervart, 20 years ago

* empty log message *

File size: 7.8 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * Bernese 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 "RTCM3/rtcm3torinex.h"
28
29using namespace std;
30
31// Constructor
32////////////////////////////////////////////////////////////////////////////
33bncRinex::bncRinex(const char* StatID) {
34 _statID = StatID;
35 _headerWritten = false;
36 readSkeleton();
37}
38
39// Destructor
40////////////////////////////////////////////////////////////////////////////
41bncRinex::~bncRinex() {
42 _out.close();
43}
44
45// Read Skeleton Header File
46////////////////////////////////////////////////////////////////////////////
47void bncRinex::readSkeleton() {
48
49 // Resolve Skeleton File Name
50 // --------------------------
51 QSettings settings;
52 QString sklName = settings.value("rnxPath").toString();
53 expandEnvVar(sklName);
54 if ( sklName[sklName.length()-1] != QDir::separator() ) {
55 sklName += QDir::separator();
56 }
57 sklName += _statID.left(4) + "." + settings.value("rnxSkel").toString();
58
59 // Read the File
60 // -------------
61 QFile skl(sklName);
62 if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
63 QTextStream in(&skl);
64 while ( !in.atEnd() ) {
65 _headerLines.append( in.readLine() );
66 if (_headerLines.last().indexOf("END OF HEADER") != -1) {
67 break;
68 }
69 }
70 }
71}
72
73// File Name according to RINEX Standards
74////////////////////////////////////////////////////////////////////////////
75void bncRinex::resolveFileName(struct converttimeinfo& cti) {
76
77 QSettings settings;
78 QString path = settings.value("rnxPath").toString();
79 expandEnvVar(path);
80
81 if ( path[path.length()-1] != QDir::separator() ) {
82 path += QDir::separator();
83 }
84
85 QDate date(cti.year, cti.month, cti.day);
86
87 QChar ch = '0';
88
89 path += _statID.left(4) +
90 QString("%1%2.%3O").arg(date.dayOfYear(), 3, 10, QChar('0'))
91 .arg(ch)
92 .arg(date.year() % 100, 2, 10, QChar('0'));
93
94 _fName = path.toAscii();
95}
96
97// Write RINEX Header
98////////////////////////////////////////////////////////////////////////////
99void bncRinex::writeHeader(struct converttimeinfo& cti, double second) {
100
101 // Open the Output File
102 // --------------------
103 resolveFileName(cti);
104 _out.open(_fName.data());
105 _out.setf(ios::fixed);
106 _out.setf(ios::left);
107
108
109 // Copy Skeleton Header
110 // --------------------
111 if (_headerLines.size() > 0) {
112 QStringListIterator it(_headerLines);
113 while (it.hasNext()) {
114 QString line = it.next();
115 if (line.indexOf("# / TYPES OF OBSERV") != -1) {
116 _out << " 4 P1 P2 L1 L2"
117 " # / TYPES OF OBSERV" << endl;
118 }
119 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
120 _out << setw(6) << cti.year
121 << setw(6) << cti.month
122 << setw(6) << cti.day
123 << setw(6) << cti.hour
124 << setw(6) << cti.minute
125 << setw(13) << setprecision(7) << second
126 << " TIME OF FIRST OBS" << endl;
127 }
128 else {
129 _out << line.toAscii().data() << endl;
130 }
131 }
132 }
133
134 // Write Dummy Header
135 // ------------------
136 else {
137 double approxPos[3]; approxPos[0] = approxPos[1] = approxPos[2] = 0.0;
138 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
139
140 _out << " 2.10 OBSERVATION DATA G (GPS) RINEX VERSION / TYPE" << endl;
141 _out << "BNC LM 27-Aug-2006 PGM / RUN BY / DATE" << endl;
142 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
143 _out << setw(60) << "BKG" << "OBSERVER / AGENCY" << endl;
144 _out << setw(20) << "unknown"
145 << setw(20) << "unknown"
146 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
147 _out << setw(20) << "unknown"
148 << setw(20) << "unknown"
149 << setw(20) << " " << "ANT # / TYPE" << endl;
150 _out.unsetf(ios::left);
151 _out << setw(14) << setprecision(4) << approxPos[0]
152 << setw(14) << setprecision(4) << approxPos[1]
153 << setw(14) << setprecision(4) << approxPos[2]
154 << " " << "APPROX POSITION XYZ" << endl;
155 _out << setw(14) << setprecision(4) << antennaNEU[0]
156 << setw(14) << setprecision(4) << antennaNEU[1]
157 << setw(14) << setprecision(4) << antennaNEU[2]
158 << " " << "ANTENNA: DELTA H/E/N" << endl;
159 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
160 _out << " 4 P1 P2 L1 L2 # / TYPES OF OBSERV" << endl;
161 _out << setw(6) << cti.year
162 << setw(6) << cti.month
163 << setw(6) << cti.day
164 << setw(6) << cti.hour
165 << setw(6) << cti.minute
166 << setw(13) << setprecision(7) << second
167 << " " << "TIME OF FIRST OBS" << endl;
168 _out << " END OF HEADER" << endl;
169 }
170
171 _headerWritten = true;
172}
173
174// Stores Observation into Internal Array
175////////////////////////////////////////////////////////////////////////////
176void bncRinex::deepCopy(const Observation* obs) {
177 Observation* newObs = new Observation();
178 memcpy(newObs, obs, sizeof(*obs));
179 _obs.push_back(newObs);
180}
181
182// Write One Epoch into the RINEX File
183////////////////////////////////////////////////////////////////////////////
184void bncRinex::dumpEpoch() {
185
186 // Easy Return
187 // -----------
188 if (_obs.isEmpty()) {
189 return;
190 }
191
192 // Time of Epoch
193 // -------------
194 struct converttimeinfo cti;
195 Observation* firstObs = *_obs.begin();
196 converttime(&cti, firstObs->GPSWeek, firstObs->GPSWeeks);
197
198 // Write RINEX Header
199 // ------------------
200 if (!_headerWritten) {
201 writeHeader(cti, cti.second + fmod(firstObs->sec, 1.0));
202 }
203
204 _out.setf(std::ios::fixed);
205
206 _out << setw(3) << cti.year%100
207 << setw(3) << cti.month
208 << setw(3) << cti.day
209 << setw(3) << cti.hour
210 << setw(3) << cti.minute
211 << setw(11) << setprecision(7)
212 << cti.second + fmod(firstObs->sec, 1.0)
213 << " " << 0 << setw(3) << _obs.size();
214
215 QListIterator<Observation*> it(_obs); int iSat = 0;
216 while (it.hasNext()) {
217 iSat++;
218 Observation* ob = it.next();
219 _out << " " << setw(2) << int(ob->SVPRN);
220 if (iSat == 12 && it.hasNext()) {
221 _out << endl << " ";
222 iSat = 0;
223 }
224 }
225 _out << endl;
226
227 static const double const_c = 299792458.0;
228 static const double const_freq1 = 1575420000.0;
229 static const double const_freq2 = 1227600000.0;
230 static const double const_lambda1 = const_c / const_freq1;
231 static const double const_lambda2 = const_c / const_freq2;
232
233 it.toFront();
234 while (it.hasNext()) {
235 Observation* ob = it.next();
236
237 char lli = ' ';
238 char snr = ' ';
239 _out << setw(14) << setprecision(3) << ob->C1 << lli << snr;
240 _out << setw(14) << setprecision(3) << ob->P2 << lli << snr;
241 _out << setw(14) << setprecision(3) << ob->L1 / const_lambda1 << lli << snr;
242 _out << setw(14) << setprecision(3) << ob->L2 / const_lambda2 << lli << snr;
243 _out << endl;
244
245 delete ob;
246 }
247
248 _out.flush();
249 _obs.clear();
250}
251
Note: See TracBrowser for help on using the repository browser.