[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 |
|
---|
| 24 | using namespace std;
|
---|
| 25 |
|
---|
| 26 | // Constructor
|
---|
| 27 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 28 | bncoutf::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;
|
---|
[7506] | 50 | _v3filenames = settings.value("PPP/v3filenames").toBool();
|
---|
[3174] | 51 | }
|
---|
| 52 |
|
---|
| 53 | // Destructor
|
---|
| 54 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 55 | bncoutf::~bncoutf() {
|
---|
| 56 | closeFile();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | // Close the Old RINEX File
|
---|
| 60 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 61 | void bncoutf::closeFile() {
|
---|
| 62 | _out.close();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[3184] | 65 | // Epoch String
|
---|
[3174] | 66 | ////////////////////////////////////////////////////////////////////////////
|
---|
[7506] | 67 | QString 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) {
|
---|
| 74 | sampl++;
|
---|
| 75 | }
|
---|
[3174] | 76 |
|
---|
| 77 | if ( indHlp != -1) {
|
---|
| 78 | int step = intStr.left(indHlp-1).toInt();
|
---|
[7506] | 79 | if (_v3filenames) {
|
---|
| 80 | epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
|
---|
| 81 | } else {
|
---|
| 82 | epoStr += 'A' + datTim.time().hour();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[3174] | 85 | if (datTim.time().minute() >= 60-step) {
|
---|
[7506] | 86 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0')); // M
|
---|
[3174] | 87 | }
|
---|
| 88 | else {
|
---|
| 89 | for (int limit = step; limit <= 60-step; limit += step) {
|
---|
| 90 | if (datTim.time().minute() < limit) {
|
---|
[7506] | 91 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0')); // M
|
---|
[3174] | 92 | break;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
[7506] | 96 |
|
---|
| 97 | if (_v3filenames) {
|
---|
| 98 | epoStr += QString("_%1M").arg(step, 2, 10, QChar('0')); // period
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[4380] | 101 | _numSec = 60 * step;
|
---|
[3174] | 102 | }
|
---|
| 103 | else if (intStr == "1 hour") {
|
---|
[7506] | 104 | int step = intStr.left(indHlp-1).toInt();
|
---|
| 105 | if (_v3filenames) {
|
---|
| 106 | epoStr += QString("%1").arg(datTim.time().hour(), 2, 10, QChar('0')); // H
|
---|
| 107 | epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
|
---|
| 108 | epoStr += QString("_%1H").arg(step+1, 2, 10, QChar('0')); // period
|
---|
| 109 | } else {
|
---|
| 110 | epoStr += 'A' + datTim.time().hour();
|
---|
| 111 | }
|
---|
[4380] | 112 | _numSec = 3600;
|
---|
[3174] | 113 | }
|
---|
| 114 | else {
|
---|
[7506] | 115 | int step = intStr.left(indHlp-1).toInt();
|
---|
| 116 | if (_v3filenames) {
|
---|
| 117 | epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // H
|
---|
| 118 | epoStr += QString("%1").arg(0, 2, 10, QChar('0')); // M
|
---|
| 119 | epoStr += QString("_%1D").arg(step+1, 2, 10, QChar('0')); // period
|
---|
| 120 | } else {
|
---|
| 121 | epoStr = "0";
|
---|
| 122 | }
|
---|
[4380] | 123 | _numSec = 86400;
|
---|
[3174] | 124 | }
|
---|
| 125 |
|
---|
[7506] | 126 | if (_v3filenames) {
|
---|
| 127 | if (sampl < 60) {
|
---|
| 128 | epoStr += QString("_%1S").arg(sampl, 2, 10, QChar('0'));
|
---|
| 129 | }
|
---|
| 130 | else {
|
---|
| 131 | sampl /= 60;
|
---|
| 132 | epoStr += QString("_%1M").arg(sampl, 2, 10, QChar('0'));
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[3174] | 136 | return epoStr;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | // File Name according to RINEX Standards
|
---|
| 140 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 141 | QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
|
---|
[3174] | 142 |
|
---|
| 143 | int dayOfWeek = datTim.date().dayOfWeek();
|
---|
| 144 | if (dayOfWeek == 7) {
|
---|
| 145 | dayOfWeek = 0;
|
---|
| 146 | }
|
---|
[6607] | 147 | int dayOfYear = datTim.date().dayOfYear();
|
---|
| 148 |
|
---|
| 149 | QString yyyy = QString::number(datTim.date().year());
|
---|
[7506] | 150 | QString doy = QString("%1").arg(dayOfYear,3,10, QLatin1Char('0'));
|
---|
[3191] | 151 | QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
|
---|
[7506] | 152 | QString epoStr = epochStr(datTim, _intr, _sampl);
|
---|
| 153 | QString baseName = _sklBaseName;
|
---|
[5985] | 154 | baseName.replace("${GPSWD}", gpswd);
|
---|
[7506] | 155 | baseName.replace("${V3}" , QString("_U_%1%2").arg(yyyy).arg(doy));
|
---|
| 156 |
|
---|
[3184] | 157 | return _path + baseName + epoStr + _extension;
|
---|
[3174] | 158 | }
|
---|
| 159 |
|
---|
[3184] | 160 | // Re-Open Output File
|
---|
[3174] | 161 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 162 | t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
|
---|
[3174] | 163 |
|
---|
| 164 | if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
|
---|
| 165 | return failure;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
|
---|
| 169 |
|
---|
[3184] | 170 | QString newFileName = resolveFileName(GPSweek, datTim);
|
---|
| 171 |
|
---|
[3174] | 172 | // Close the file
|
---|
| 173 | // --------------
|
---|
[3184] | 174 | if (newFileName != _fName) {
|
---|
[3174] | 175 | closeFile();
|
---|
| 176 | _headerWritten = false;
|
---|
[3184] | 177 | _fName = newFileName;
|
---|
[3174] | 178 | }
|
---|
| 179 |
|
---|
[3184] | 180 | // Re-Open File, Write Header
|
---|
| 181 | // --------------------------
|
---|
[3174] | 182 | if (!_headerWritten) {
|
---|
| 183 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[3184] | 184 | if (_append && QFile::exists(_fName)) {
|
---|
| 185 | _out.open(_fName.toAscii().data(), ios::out | ios::app);
|
---|
[3174] | 186 | }
|
---|
| 187 | else {
|
---|
[3184] | 188 | _out.open(_fName.toAscii().data());
|
---|
[3174] | 189 | writeHeader(datTim);
|
---|
| 190 | }
|
---|
| 191 | _headerWritten = true;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | return success;
|
---|
| 195 | }
|
---|
[3184] | 196 |
|
---|
| 197 | // Write String
|
---|
| 198 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 199 | t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
|
---|
| 200 | reopen(GPSweek, GPSweeks);
|
---|
| 201 | _out << str.toAscii().data();
|
---|
| 202 | _out.flush();
|
---|
| 203 | return success;
|
---|
| 204 | }
|
---|