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

Last change on this file since 125 was 125, checked in by mervart, 18 years ago

* empty log message *

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