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

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

some renaming regarding long product filenames

File size: 6.2 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;
[3174]50}
51
52// Destructor
53////////////////////////////////////////////////////////////////////////////
54bncoutf::~bncoutf() {
55 closeFile();
56}
57
58// Close the Old RINEX File
59////////////////////////////////////////////////////////////////////////////
60void bncoutf::closeFile() {
61 _out.close();
62}
63
[3184]64// Epoch String
[3174]65////////////////////////////////////////////////////////////////////////////
[7506]66QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr,
67 int sampl) {
[3174]68
[7506]69 QString epoStr = "";
[3174]70
71 int indHlp = intStr.indexOf("min");
[7506]72 if (!sampl) {
[9655]73 if (_sklBaseName.contains("V3PROD") &&
[9944]74 (_extension.contains("BIA") ||
75 _extension.contains("SP3") ||
76 _extension.contains("CLK"))) {
[9652]77 sampl +=5;
78 } else {
79 sampl++;
80 }
[7506]81 }
[3174]82
83 if ( indHlp != -1) {
84 int step = intStr.left(indHlp-1).toInt();
[9783]85 epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
[7506]86
[3174]87 if (datTim.time().minute() >= 60-step) {
[7506]88 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0')); // M
[3174]89 }
90 else {
91 for (int limit = step; limit <= 60-step; limit += step) {
92 if (datTim.time().minute() < limit) {
[7506]93 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0')); // M
[3174]94 break;
95 }
96 }
97 }
[9783]98 epoStr += QString("_%1M").arg(step, 2, 10, QChar('0')); // period
[7506]99
[4380]100 _numSec = 60 * step;
[3174]101 }
102 else if (intStr == "1 hour") {
[7506]103 int step = intStr.left(indHlp-1).toInt();
[9783]104 epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
105 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
106 epoStr += QString("_%1H").arg(step+1, 2, 10, QChar('0')); // period
[4380]107 _numSec = 3600;
[3174]108 }
109 else {
[7506]110 int step = intStr.left(indHlp-1).toInt();
[9783]111 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // H
112 epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
113 epoStr += QString("_%1D").arg(step+1, 2, 10, QChar('0')); // period
[4380]114 _numSec = 86400;
[3174]115 }
116
[9783]117
118 if (sampl < 60) {
119 epoStr += QString("_%1S").arg(sampl, 2, 10, QChar('0'));
[7506]120 }
[9783]121 else {
122 sampl /= 60;
123 epoStr += QString("_%1M").arg(sampl, 2, 10, QChar('0'));
124 }
[7506]125
[3174]126 return epoStr;
127}
128
129// File Name according to RINEX Standards
130////////////////////////////////////////////////////////////////////////////
[3184]131QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
[3174]132
133 int dayOfWeek = datTim.date().dayOfWeek();
134 if (dayOfWeek == 7) {
135 dayOfWeek = 0;
136 }
[6607]137 int dayOfYear = datTim.date().dayOfYear();
138
139 QString yyyy = QString::number(datTim.date().year());
[7506]140 QString doy = QString("%1").arg(dayOfYear,3,10, QLatin1Char('0'));
[3191]141 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
[7506]142 QString epoStr = epochStr(datTim, _intr, _sampl);
143 QString baseName = _sklBaseName;
[5985]144 baseName.replace("${GPSWD}", gpswd);
[9418]145 baseName.replace("${V3OBS}" , QString("_U_%1%2").arg(yyyy).arg(doy));
146 baseName.replace("${V3PROD}", QString("_%1%2").arg(yyyy).arg(doy));
147 QString addition = "";
[9942]148 if (_extension.contains("SP3")) {
[9418]149 addition = QString("_ORB");
150 }
[9942]151 if (_extension.contains("CLK")) {
[9418]152 addition = QString("_CLK");
153 }
[9942]154 if (_extension.contains("BIA")) {
[9652]155 addition = QString("_ABS");
156 }
[9942]157 if (_extension.contains("TRO")) {
[9889]158 QString site = baseName.left(9);
159 bncSettings settings;
160 QString ac = settings.value("PPP/snxtroAc").toString();
161 QString sol = settings.value("PPP/snxtroSol").toString();
162 baseName.replace(0,3,ac);
163 baseName.replace(3,1,sol);
164 baseName.replace(4,3,"DEM");
165 baseName.replace(7,3,"RTS");
166 addition = QString("_%1_TRO").arg(site);
167 }
[9418]168 if (_extension.count(".") == 2) {
169 _extension.replace(0,1,"_");
170 }
[9158]171
[9418]172 return _path + baseName + epoStr + addition + _extension;
[3174]173}
174
[3184]175// Re-Open Output File
[3174]176////////////////////////////////////////////////////////////////////////////
[3184]177t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
[3174]178
179 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
180 return failure;
181 }
182
183 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
184
[3184]185 QString newFileName = resolveFileName(GPSweek, datTim);
186
[3174]187 // Close the file
188 // --------------
[3184]189 if (newFileName != _fName) {
[3174]190 closeFile();
191 _headerWritten = false;
[3184]192 _fName = newFileName;
[3174]193 }
194
[3184]195 // Re-Open File, Write Header
196 // --------------------------
[3174]197 if (!_headerWritten) {
198 _out.setf(ios::showpoint | ios::fixed);
[3184]199 if (_append && QFile::exists(_fName)) {
[8204]200 _out.open(_fName.toLatin1().data(), ios::out | ios::app);
[3174]201 }
202 else {
[8204]203 _out.open(_fName.toLatin1().data());
[3174]204 writeHeader(datTim);
205 }
[7657]206 if (_out.is_open()) {
207 _headerWritten = true;
208 }
[3174]209 }
210
211 return success;
212}
[3184]213
214// Write String
215////////////////////////////////////////////////////////////////////////////
216t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
217 reopen(GPSweek, GPSweeks);
[8204]218 _out << str.toLatin1().data();
[3184]219 _out.flush();
220 return success;
221}
[9652]222
223QString bncoutf::agencyFromFileName() {
224 return QString("%1").arg(_sklBaseName.left(3));
225}
Note: See TracBrowser for help on using the repository browser.