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

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

minor changes

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