[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 | *
|
---|
| 14 | * Changes:
|
---|
| 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 |
|
---|
| 37 | QFileInfo fileInfo(sklFileName);
|
---|
| 38 | _path = fileInfo.absolutePath() + QDir::separator();
|
---|
| 39 | _sklBaseName = fileInfo.baseName();
|
---|
| 40 | _extension = fileInfo.completeSuffix();
|
---|
| 41 |
|
---|
[3174] | 42 | expandEnvVar(_path);
|
---|
[3184] | 43 | if (!_extension.isEmpty()) {
|
---|
| 44 | _extension = "." + _extension;
|
---|
[3174] | 45 | }
|
---|
[3184] | 46 |
|
---|
| 47 | _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
|
---|
[3174] | 48 | }
|
---|
| 49 |
|
---|
| 50 | // Destructor
|
---|
| 51 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 52 | bncoutf::~bncoutf() {
|
---|
| 53 | closeFile();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // Close the Old RINEX File
|
---|
| 57 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 58 | void bncoutf::closeFile() {
|
---|
| 59 | _out.close();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[3184] | 62 | // Epoch String
|
---|
[3174] | 63 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 64 | QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr) {
|
---|
[3174] | 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 | }
|
---|
[4380] | 85 | _numSec = 60 * step;
|
---|
[3174] | 86 | }
|
---|
| 87 | else if (intStr == "1 hour") {
|
---|
| 88 | char ch = 'A' + datTim.time().hour();
|
---|
| 89 | epoStr = QString("_") + ch;
|
---|
[4380] | 90 | _numSec = 3600;
|
---|
[3174] | 91 | }
|
---|
| 92 | else {
|
---|
| 93 | epoStr = "";
|
---|
[4380] | 94 | _numSec = 86400;
|
---|
[3174] | 95 | }
|
---|
| 96 |
|
---|
| 97 | return epoStr;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | // File Name according to RINEX Standards
|
---|
| 101 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 102 | QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
|
---|
[3174] | 103 |
|
---|
| 104 | int dayOfWeek = datTim.date().dayOfWeek();
|
---|
| 105 | if (dayOfWeek == 7) {
|
---|
| 106 | dayOfWeek = 0;
|
---|
| 107 | }
|
---|
[3191] | 108 | QString gpswd = QString("%1%2").arg(GPSweek).arg(dayOfWeek);
|
---|
[3261] | 109 | QString baseName = _sklBaseName; baseName.replace("${GPSWD}", gpswd);
|
---|
[3184] | 110 | QString epoStr = epochStr(datTim, _intr);
|
---|
[3174] | 111 |
|
---|
[3184] | 112 | return _path + baseName + epoStr + _extension;
|
---|
[3174] | 113 | }
|
---|
| 114 |
|
---|
[3184] | 115 | // Re-Open Output File
|
---|
[3174] | 116 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3184] | 117 | t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
|
---|
[3174] | 118 |
|
---|
| 119 | if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
|
---|
| 120 | return failure;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
|
---|
| 124 |
|
---|
[3184] | 125 | QString newFileName = resolveFileName(GPSweek, datTim);
|
---|
| 126 |
|
---|
[3174] | 127 | // Close the file
|
---|
| 128 | // --------------
|
---|
[3184] | 129 | if (newFileName != _fName) {
|
---|
[3174] | 130 | closeFile();
|
---|
| 131 | _headerWritten = false;
|
---|
[3184] | 132 | _fName = newFileName;
|
---|
[3174] | 133 | }
|
---|
| 134 |
|
---|
[3184] | 135 | // Re-Open File, Write Header
|
---|
| 136 | // --------------------------
|
---|
[3174] | 137 | if (!_headerWritten) {
|
---|
| 138 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[3184] | 139 | if (_append && QFile::exists(_fName)) {
|
---|
| 140 | _out.open(_fName.toAscii().data(), ios::out | ios::app);
|
---|
[3174] | 141 | }
|
---|
| 142 | else {
|
---|
[3184] | 143 | _out.open(_fName.toAscii().data());
|
---|
[3174] | 144 | writeHeader(datTim);
|
---|
| 145 | }
|
---|
| 146 | _headerWritten = true;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | return success;
|
---|
| 150 | }
|
---|
[3184] | 151 |
|
---|
| 152 | // Write String
|
---|
| 153 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 154 | t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
|
---|
| 155 | reopen(GPSweek, GPSweeks);
|
---|
| 156 | _out << str.toAscii().data();
|
---|
| 157 | _out.flush();
|
---|
| 158 | return success;
|
---|
| 159 | }
|
---|