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

Last change on this file since 7047 was 6607, checked in by stuerze, 10 years ago

some gui preparation for sinex_tro file output

File size: 4.4 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}
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
64// Epoch String
65////////////////////////////////////////////////////////////////////////////
66QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr) {
67
68 QString epoStr;
69
70 int indHlp = intStr.indexOf("min");
71
72 if ( indHlp != -1) {
73 int step = intStr.left(indHlp-1).toInt();
74 char ch = 'A' + datTim.time().hour();
75 epoStr = QString("_") + ch;
76 if (datTim.time().minute() >= 60-step) {
77 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
78 }
79 else {
80 for (int limit = step; limit <= 60-step; limit += step) {
81 if (datTim.time().minute() < limit) {
82 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
83 break;
84 }
85 }
86 }
87 _numSec = 60 * step;
88 }
89 else if (intStr == "1 hour") {
90 char ch = 'A' + datTim.time().hour();
91 epoStr = QString("_") + ch;
92 _numSec = 3600;
93 }
94 else {
95 epoStr = "";
96 _numSec = 86400;
97 }
98
99 return epoStr;
100}
101
102// File Name according to RINEX Standards
103////////////////////////////////////////////////////////////////////////////
104QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
105
106 int dayOfWeek = datTim.date().dayOfWeek();
107 if (dayOfWeek == 7) {
108 dayOfWeek = 0;
109 }
110 int dayOfYear = datTim.date().dayOfYear();
111
112 QString yyyy = QString::number(datTim.date().year());
113 QString doy = QString("%1%2").arg(dayOfYear,3,10, QLatin1Char('0')).arg(0);
114 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
115 QString epoStr = epochStr(datTim, _intr);
116 QString baseName = _sklBaseName;
117 baseName.replace("${GPSWD}", gpswd);
118 baseName.replace("${DATE}" , datTim.date().toString(Qt::ISODate));
119 baseName.replace("${DOY}" , doy);
120 _extension.replace("${YY}" , yyyy.right(2));
121 return _path + baseName + epoStr + _extension;
122}
123
124// Re-Open Output File
125////////////////////////////////////////////////////////////////////////////
126t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
127
128 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
129 return failure;
130 }
131
132 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
133
134 QString newFileName = resolveFileName(GPSweek, datTim);
135
136 // Close the file
137 // --------------
138 if (newFileName != _fName) {
139 closeFile();
140 _headerWritten = false;
141 _fName = newFileName;
142 }
143
144 // Re-Open File, Write Header
145 // --------------------------
146 if (!_headerWritten) {
147 _out.setf(ios::showpoint | ios::fixed);
148 if (_append && QFile::exists(_fName)) {
149 _out.open(_fName.toAscii().data(), ios::out | ios::app);
150 }
151 else {
152 _out.open(_fName.toAscii().data());
153 writeHeader(datTim);
154 }
155 _headerWritten = true;
156 }
157
158 return success;
159}
160
161// Write String
162////////////////////////////////////////////////////////////////////////////
163t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
164 reopen(GPSweek, GPSweeks);
165 _out << str.toAscii().data();
166 _out.flush();
167 return success;
168}
Note: See TracBrowser for help on using the repository browser.