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

Last change on this file since 85 was 85, checked in by mervart, 18 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::showpoint | ios::fixed);
106
107 // Copy Skeleton Header
108 // --------------------
109 if (_headerLines.size() > 0) {
110 QStringListIterator it(_headerLines);
111 while (it.hasNext()) {
112 QString line = it.next();
113 if (line.indexOf("# / TYPES OF OBSERV") != -1) {
114 _out << " 4 P1 P2 L1 L2"
115 " # / TYPES OF OBSERV" << endl;
116 }
117 else if (line.indexOf("TIME OF FIRST OBS") != -1) {
118 _out << setw(6) << cti.year
119 << setw(6) << cti.month
120 << setw(6) << cti.day
121 << setw(6) << cti.hour
122 << setw(6) << cti.minute
123 << setw(13) << setprecision(7) << second
124 << " TIME OF FIRST OBS" << endl;
125 }
126 else {
127 _out << line.toAscii().data() << endl;
128 }
129 }
130 }
131
132 // Write Dummy Header
133 // ------------------
134 else {
135 double approxPos[3]; approxPos[0] = approxPos[1] = approxPos[2] = 0.0;
136 double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
137
138 _out << " 2.10 OBSERVATION DATA G (GPS) RINEX VERSION / TYPE" << endl;
139 _out << "BNC LM 27-Aug-2006 PGM / RUN BY / DATE" << endl;
140 _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
141 _out << setw(60) << "BKG" << "OBSERVER / AGENCY" << endl;
142 _out << setw(20) << "unknown"
143 << setw(20) << "unknown"
144 << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
145 _out << setw(20) << "unknown"
146 << setw(20) << "unknown"
147 << setw(20) << " " << "ANT # / TYPE" << endl;
148 _out << setw(14) << setprecision(4) << approxPos[0]
149 << setw(14) << setprecision(4) << approxPos[1]
150 << setw(14) << setprecision(4) << approxPos[2]
151 << " " << "APPROX POSITION XYZ" << endl;
152 _out << setw(14) << setprecision(4) << antennaNEU[0]
153 << setw(14) << setprecision(4) << antennaNEU[1]
154 << setw(14) << setprecision(4) << antennaNEU[2]
155 << " " << "ANTENNA: DELTA H/E/N" << endl;
156 _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
157 _out << " 4 P1 P2 L1 L2 # / TYPES OF OBSERV" << endl;
158 _out << setw(6) << cti.year
159 << setw(6) << cti.month
160 << setw(6) << cti.day
161 << setw(6) << cti.hour
162 << setw(6) << cti.minute
163 << setw(13) << setprecision(7) << second
164 << " " << "TIME OF FIRST OBS" << endl;
165 _out << " END OF HEADER" << endl;
166 }
167
168 _headerWritten = true;
169}
170
171// Stores Observation into Internal Array
172////////////////////////////////////////////////////////////////////////////
173void bncRinex::deepCopy(const Observation* obs) {
174 Observation* newObs = new Observation();
175 memcpy(newObs, obs, sizeof(*obs));
176 _obs.push_back(newObs);
177}
178
179// Write One Epoch into the RINEX File
180////////////////////////////////////////////////////////////////////////////
181void bncRinex::dumpEpoch() {
182
183 // Easy Return
184 // -----------
185 if (_obs.isEmpty()) {
186 return;
187 }
188
189 // Time of Epoch
190 // -------------
191 struct converttimeinfo cti;
192 Observation* firstObs = *_obs.begin();
193 converttime(&cti, firstObs->GPSWeek, firstObs->GPSWeeks);
194
195 // Write RINEX Header
196 // ------------------
197 if (!_headerWritten) {
198 writeHeader(cti, cti.second + fmod(firstObs->sec, 1.0));
199 }
200
201 _out << setw(3) << cti.year%100
202 << setw(3) << cti.month
203 << setw(3) << cti.day
204 << setw(3) << cti.hour
205 << setw(3) << cti.minute
206 << setw(11) << setprecision(7)
207 << cti.second + fmod(firstObs->sec, 1.0)
208 << " " << 0 << setw(3) << _obs.size();
209
210 QListIterator<Observation*> it(_obs); int iSat = 0;
211 while (it.hasNext()) {
212 iSat++;
213 Observation* ob = it.next();
214 _out << " " << setw(2) << int(ob->SVPRN);
215 if (iSat == 12 && it.hasNext()) {
216 _out << endl << " ";
217 iSat = 0;
218 }
219 }
220 _out << endl;
221
222 static const double const_c = 299792458.0;
223 static const double const_freq1 = 1575420000.0;
224 static const double const_freq2 = 1227600000.0;
225 static const double const_lambda1 = const_c / const_freq1;
226 static const double const_lambda2 = const_c / const_freq2;
227
228 it.toFront();
229 while (it.hasNext()) {
230 Observation* ob = it.next();
231
232 char lli = ' ';
233 char snr = ' ';
234 _out << setw(14) << setprecision(3) << ob->C1 << lli << snr;
235 _out << setw(14) << setprecision(3) << ob->P2 << lli << snr;
236 _out << setw(14) << setprecision(3) << ob->L1 / const_lambda1 << lli << snr;
237 _out << setw(14) << setprecision(3) << ob->L2 / const_lambda2 << lli << snr;
238 _out << endl;
239
240 delete ob;
241 }
242
243 _out.flush();
244 _obs.clear();
245}
246
Note: See TracBrowser for help on using the repository browser.