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

Last change on this file since 6018 was 5985, 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 QFileInfo fileInfo(sklFileName);
38 _path = fileInfo.absolutePath() + QDir::separator();
39 _sklBaseName = fileInfo.baseName();
40 _extension = fileInfo.completeSuffix();
41
42 expandEnvVar(_path);
43 if (!_extension.isEmpty()) {
44 _extension = "." + _extension;
45 }
46
47 _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
48}
49
50// Destructor
51////////////////////////////////////////////////////////////////////////////
52bncoutf::~bncoutf() {
53 closeFile();
54}
55
56// Close the Old RINEX File
57////////////////////////////////////////////////////////////////////////////
58void bncoutf::closeFile() {
59 _out.close();
60}
61
62// Epoch String
63////////////////////////////////////////////////////////////////////////////
64QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr) {
65
66 QString epoStr;
67
68 int indHlp = intStr.indexOf("min");
69
70 if ( indHlp != -1) {
71 int step = intStr.left(indHlp-1).toInt();
72 char ch = 'A' + datTim.time().hour();
73 epoStr = QString("_") + ch;
74 if (datTim.time().minute() >= 60-step) {
75 epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
76 }
77 else {
78 for (int limit = step; limit <= 60-step; limit += step) {
79 if (datTim.time().minute() < limit) {
80 epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
81 break;
82 }
83 }
84 }
85 _numSec = 60 * step;
86 }
87 else if (intStr == "1 hour") {
88 char ch = 'A' + datTim.time().hour();
89 epoStr = QString("_") + ch;
90 _numSec = 3600;
91 }
92 else {
93 epoStr = "";
94 _numSec = 86400;
95 }
96
97 return epoStr;
98}
99
100// File Name according to RINEX Standards
101////////////////////////////////////////////////////////////////////////////
102QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
103
104 int dayOfWeek = datTim.date().dayOfWeek();
105 if (dayOfWeek == 7) {
106 dayOfWeek = 0;
107 }
108 QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
109 QString epoStr = epochStr(datTim, _intr);
110 QString baseName = _sklBaseName;
111 baseName.replace("${GPSWD}", gpswd);
112 baseName.replace("${DATE}", datTim.date().toString(Qt::ISODate));
113
114 return _path + baseName + epoStr + _extension;
115}
116
117// Re-Open Output File
118////////////////////////////////////////////////////////////////////////////
119t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
120
121 if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
122 return failure;
123 }
124
125 QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
126
127 QString newFileName = resolveFileName(GPSweek, datTim);
128
129 // Close the file
130 // --------------
131 if (newFileName != _fName) {
132 closeFile();
133 _headerWritten = false;
134 _fName = newFileName;
135 }
136
137 // Re-Open File, Write Header
138 // --------------------------
139 if (!_headerWritten) {
140 _out.setf(ios::showpoint | ios::fixed);
141 if (_append && QFile::exists(_fName)) {
142 _out.open(_fName.toAscii().data(), ios::out | ios::app);
143 }
144 else {
145 _out.open(_fName.toAscii().data());
146 writeHeader(datTim);
147 }
148 _headerWritten = true;
149 }
150
151 return success;
152}
153
154// Write String
155////////////////////////////////////////////////////////////////////////////
156t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
157 reopen(GPSweek, GPSweeks);
158 _out << str.toAscii().data();
159 _out.flush();
160 return success;
161}
Note: See TracBrowser for help on using the repository browser.