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

Last change on this file since 9448 was 9418, checked in by stuerze, 4 years ago


File size: 5.9 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 sampl++;
75 }
76
77 if ( indHlp != -1) {
78 int step = intStr.left(indHlp-1).toInt();
79 if (!_v2filenames) {
80 epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
81 } else {
82 epoStr += 'A' + datTim.time().hour();
83 }
84
85 if (datTim.time().minute() >= 60-step) {
86 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0')); // M
87 }
88 else {
89 for (int limit = step; limit <= 60-step; limit += step) {
90 if (datTim.time().minute() < limit) {
91 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0')); // M
92 break;
93 }
94 }
95 }
96
97 if (!_v2filenames) {
98 epoStr += QString("_%1M").arg(step, 2, 10, QChar('0')); // period
99 }
100
101 _numSec = 60 * step;
102 }
103 else if (intStr == "1 hour") {
104 int step = intStr.left(indHlp-1).toInt();
105 if (!_v2filenames) {
106 epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
107 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
108 epoStr += QString("_%1H").arg(step+1, 2, 10, QChar('0')); // period
109 } else {
110 epoStr += 'A' + datTim.time().hour();
111 }
112 _numSec = 3600;
113 }
114 else {
115 int step = intStr.left(indHlp-1).toInt();
116 if (!_v2filenames) {
117 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // H
118 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
119 epoStr += QString("_%1D").arg(step+1, 2, 10, QChar('0')); // period
120 }
121 _numSec = 86400;
122 }
123
124 if (!_v2filenames) {
125 if (sampl < 60) {
126 epoStr += QString("_%1S").arg(sampl, 2, 10, QChar('0'));
127 }
128 else {
129 sampl /= 60;
130 epoStr += QString("_%1M").arg(sampl, 2, 10, QChar('0'));
131 }
132 }
133
134 return epoStr;
135}
136
137// File Name according to RINEX Standards
138////////////////////////////////////////////////////////////////////////////
139QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
140
141 int dayOfWeek = datTim.date().dayOfWeek();
142 if (dayOfWeek == 7) {
143 dayOfWeek = 0;
144 }
145 int dayOfYear = datTim.date().dayOfYear();
146
147 QString yyyy = QString::number(datTim.date().year());
148 QString doy = QString("%1").arg(dayOfYear,3,10, QLatin1Char('0'));
149 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
150 QString epoStr = epochStr(datTim, _intr, _sampl);
151 QString baseName = _sklBaseName;
152 baseName.replace("${GPSWD}", gpswd);
153 baseName.replace("${V3OBS}" , QString("_U_%1%2").arg(yyyy).arg(doy));
154 baseName.replace("${V3PROD}", QString("_%1%2").arg(yyyy).arg(doy));
155 QString addition = "";
156 if (_extension.contains("sp3") || _extension.contains("SP3")) {
157 addition = QString("_ORB");
158 }
159 if (_extension.contains("clk") || _extension.contains("CLK")) {
160 addition = QString("_CLK");
161 }
162 if (_extension.count(".") == 2) {
163 _extension.replace(0,1,"_");
164 }
165
166 return _path + baseName + epoStr + addition + _extension;
167}
168
169// Re-Open Output File
170////////////////////////////////////////////////////////////////////////////
171t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
172
173 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
174 return failure;
175 }
176
177 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
178
179 QString newFileName = resolveFileName(GPSweek, datTim);
180
181 // Close the file
182 // --------------
183 if (newFileName != _fName) {
184 closeFile();
185 _headerWritten = false;
186 _fName = newFileName;
187 }
188
189 // Re-Open File, Write Header
190 // --------------------------
191 if (!_headerWritten) {
192 _out.setf(ios::showpoint | ios::fixed);
193 if (_append && QFile::exists(_fName)) {
194 _out.open(_fName.toLatin1().data(), ios::out | ios::app);
195 }
196 else {
197 _out.open(_fName.toLatin1().data());
198 writeHeader(datTim);
199 }
200 if (_out.is_open()) {
201 _headerWritten = true;
202 }
203 }
204
205 return success;
206}
207
208// Write String
209////////////////////////////////////////////////////////////////////////////
210t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
211 reopen(GPSweek, GPSweeks);
212 _out << str.toLatin1().data();
213 _out.flush();
214 return success;
215}
Note: See TracBrowser for help on using the repository browser.