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