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

Last change on this file since 6398 was 6331, checked in by mervart, 10 years ago
File size: 4.1 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 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
111 QString epoStr = epochStr(datTim, _intr);
112 QString baseName = _sklBaseName;
113 baseName.replace("${GPSWD}", gpswd);
114 baseName.replace("${DATE}", datTim.date().toString(Qt::ISODate));
115
116 return _path + baseName + epoStr + _extension;
117}
118
119// Re-Open Output File
120////////////////////////////////////////////////////////////////////////////
121t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
122
123 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
124 return failure;
125 }
126
127 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
128
129 QString newFileName = resolveFileName(GPSweek, datTim);
130
131 // Close the file
132 // --------------
133 if (newFileName != _fName) {
134 closeFile();
135 _headerWritten = false;
136 _fName = newFileName;
137 }
138
139 // Re-Open File, Write Header
140 // --------------------------
141 if (!_headerWritten) {
142 _out.setf(ios::showpoint | ios::fixed);
143 if (_append && QFile::exists(_fName)) {
144 _out.open(_fName.toAscii().data(), ios::out | ios::app);
145 }
146 else {
147 _out.open(_fName.toAscii().data());
148 writeHeader(datTim);
149 }
150 _headerWritten = true;
151 }
152
153 return success;
154}
155
156// Write String
157////////////////////////////////////////////////////////////////////////////
158t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
159 reopen(GPSweek, GPSweeks);
160 _out << str.toAscii().data();
161 _out.flush();
162 return success;
163}
Note: See TracBrowser for help on using the repository browser.