source: ntrip/trunk/BNC/src/bncoutf.cpp@ 9652

Last change on this file since 9652 was 9652, checked in by stuerze, 2 years ago

Bias SINEX file can be written now during SSR upload

File size: 6.2 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Server
4 * -------------------------------------------------------------------------
5 *
6 * Class: bncoutf
7 *
8 * Purpose: Basis Class for File-Writers
9 *
10 * Author: L. Mervart
11 *
12 * Created: 25-Apr-2008
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <math.h>
19#include <iomanip>
20
21#include "bncoutf.h"
22#include "bncsettings.h"
23
24using namespace std;
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
28bncoutf::bncoutf(const QString& sklFileName, const QString& intr, int sampl) {
29
30 bncSettings settings;
31
32 _headerWritten = false;
33 _sampl = sampl;
34 _intr = intr;
35 _numSec = 0;
36
37 if (! sklFileName.isEmpty()) {
38 QFileInfo fileInfo(sklFileName);
39 _path = fileInfo.absolutePath() + QDir::separator();
40 _sklBaseName = fileInfo.baseName();
41 _extension = fileInfo.completeSuffix();
42
43 expandEnvVar(_path);
44 if (!_extension.isEmpty()) {
45 _extension = "." + _extension;
46 }
47 }
48
49 _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
50 _v2filenames = settings.value("PPP/v2filenames").toBool();
51}
52
53// Destructor
54////////////////////////////////////////////////////////////////////////////
55bncoutf::~bncoutf() {
56 closeFile();
57}
58
59// Close the Old RINEX File
60////////////////////////////////////////////////////////////////////////////
61void bncoutf::closeFile() {
62 _out.close();
63}
64
65// Epoch String
66////////////////////////////////////////////////////////////////////////////
67QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr,
68 int sampl) {
69
70 QString epoStr = "";
71
72 int indHlp = intStr.indexOf("min");
73 if (!sampl) {
74 if (_sklBaseName.contains("V3PROD")){
75 sampl +=5;
76 } else {
77 sampl++;
78 }
79 }
80
81 if ( indHlp != -1) {
82 int step = intStr.left(indHlp-1).toInt();
83 if (!_v2filenames) {
84 epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
85 } else {
86 epoStr += 'A' + datTim.time().hour();
87 }
88
89 if (datTim.time().minute() >= 60-step) {
90 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0')); // M
91 }
92 else {
93 for (int limit = step; limit <= 60-step; limit += step) {
94 if (datTim.time().minute() < limit) {
95 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0')); // M
96 break;
97 }
98 }
99 }
100
101 if (!_v2filenames) {
102 epoStr += QString("_%1M").arg(step, 2, 10, QChar('0')); // period
103 }
104
105 _numSec = 60 * step;
106 }
107 else if (intStr == "1 hour") {
108 int step = intStr.left(indHlp-1).toInt();
109 if (!_v2filenames) {
110 epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
111 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
112 epoStr += QString("_%1H").arg(step+1, 2, 10, QChar('0')); // period
113 } else {
114 epoStr += 'A' + datTim.time().hour();
115 }
116 _numSec = 3600;
117 }
118 else {
119 int step = intStr.left(indHlp-1).toInt();
120 if (!_v2filenames) {
121 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // H
122 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
123 epoStr += QString("_%1D").arg(step+1, 2, 10, QChar('0')); // period
124 }
125 _numSec = 86400;
126 }
127
128 if (!_v2filenames) {
129 if (sampl < 60) {
130 epoStr += QString("_%1S").arg(sampl, 2, 10, QChar('0'));
131 }
132 else {
133 sampl /= 60;
134 epoStr += QString("_%1M").arg(sampl, 2, 10, QChar('0'));
135 }
136 }
137
138 return epoStr;
139}
140
141// File Name according to RINEX Standards
142////////////////////////////////////////////////////////////////////////////
143QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
144
145 int dayOfWeek = datTim.date().dayOfWeek();
146 if (dayOfWeek == 7) {
147 dayOfWeek = 0;
148 }
149 int dayOfYear = datTim.date().dayOfYear();
150
151 QString yyyy = QString::number(datTim.date().year());
152 QString doy = QString("%1").arg(dayOfYear,3,10, QLatin1Char('0'));
153 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
154 QString epoStr = epochStr(datTim, _intr, _sampl);
155 QString baseName = _sklBaseName;
156 baseName.replace("${GPSWD}", gpswd);
157 baseName.replace("${V3OBS}" , QString("_U_%1%2").arg(yyyy).arg(doy));
158 baseName.replace("${V3PROD}", QString("_%1%2").arg(yyyy).arg(doy));
159 QString addition = "";
160 if (_extension.contains("sp3") || _extension.contains("SP3")) {
161 addition = QString("_ORB");
162 }
163 if (_extension.contains("clk") || _extension.contains("CLK")) {
164 addition = QString("_CLK");
165 }
166 if (_extension.contains("bia") || _extension.contains("BIA")) {
167 addition = QString("_ABS");
168 }
169 if (_extension.count(".") == 2) {
170 _extension.replace(0,1,"_");
171 }
172
173 return _path + baseName + epoStr + addition + _extension;
174}
175
176// Re-Open Output File
177////////////////////////////////////////////////////////////////////////////
178t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
179
180 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
181 return failure;
182 }
183
184 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
185
186 QString newFileName = resolveFileName(GPSweek, datTim);
187
188 // Close the file
189 // --------------
190 if (newFileName != _fName) {
191 closeFile();
192 _headerWritten = false;
193 _fName = newFileName;
194 }
195
196 // Re-Open File, Write Header
197 // --------------------------
198 if (!_headerWritten) {
199 _out.setf(ios::showpoint | ios::fixed);
200 if (_append && QFile::exists(_fName)) {
201 _out.open(_fName.toLatin1().data(), ios::out | ios::app);
202 }
203 else {
204 _out.open(_fName.toLatin1().data());
205 writeHeader(datTim);
206 }
207 if (_out.is_open()) {
208 _headerWritten = true;
209 }
210 }
211
212 return success;
213}
214
215// Write String
216////////////////////////////////////////////////////////////////////////////
217t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
218 reopen(GPSweek, GPSweeks);
219 _out << str.toLatin1().data();
220 _out.flush();
221 return success;
222}
223
224QString bncoutf::agencyFromFileName() {
225 return QString("%1").arg(_sklBaseName.left(3));
226}
Note: See TracBrowser for help on using the repository browser.